-
Notifications
You must be signed in to change notification settings - Fork 1
/
quote_removal.c
56 lines (50 loc) · 1.01 KB
/
quote_removal.c
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
/*
** quote_removal.c for zssh
**
** Made by Matthieu Lucotte
** Login <[email protected]>
**
** 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(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(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(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++;
}
}