File: quote_removal.c

package info (click to toggle)
zssh 1.5c.debian.1-3.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 384 kB
  • sloc: ansic: 2,045; sh: 184; makefile: 168
file content (66 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 ** quote_removal.c for zssh
 ** 
 ** Made by Matthieu Lucotte
 ** Login   <gounter@users.sourceforge.net>
 ** 
 ** Started on  Thu Jun 29 19:10:43 2000 Matthieu Lucotte
 ** Last update Sat Oct  6 23:53:06 2001 Matthieu Lucotte
 */

#include "zssh.h"

int		pc_remove_backslash(str,i)
char		*str;
int		*i;
{
   if (str[*i] != '\\')
      return (0);
   str_shift(str,*i,1);
   if (!str[*i])
      return (-1);
   (*i)++;
   return (1);
}

int		pc_remove_double_chr(str,i,chr)
char		*str;
int		*i;
char		chr;
{
   str_shift(str,*i,1);
   while (str[*i] && str[*i] != chr)
      if (pc_remove_backslash(str,i) <= 0)
	 (*i)++;
   if (!str[*i])
      return (-1);
   str_shift(str,*i,1);
   return (1);
}

void		pc_quote_removal(av,ac)
char		**av;
int		*ac;
{
   int		i;
   int		j;
   char		*str;
   
   for (i = 0;i < *ac;i++)
      if ((str = av[i]))
      {
	 if (!strcmp(str,"#"))
	 {
	    op_shift(av + i,*ac - i - 1);
	    *ac = i + 1;
	 }
	 else
	    for (j = 0;str[j];)
	       if (str[j] == '"' || str[j] == '\'')
		  pc_remove_double_chr(str, &j, str[j]);
	       else
		  if (pc_remove_backslash(str, &j) <= 0)
		     j++;
      }
}