(argcv_scan): Improved scanning.
Showing
1 changed file
with
16 additions
and
28 deletions
... | @@ -40,7 +40,6 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, | ... | @@ -40,7 +40,6 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, |
40 | int *start, int *end, int *save) | 40 | int *start, int *end, int *save) |
41 | { | 41 | { |
42 | int i = 0; | 42 | int i = 0; |
43 | int expect_delim; | ||
44 | 43 | ||
45 | for (;;) | 44 | for (;;) |
46 | { | 45 | { |
... | @@ -54,46 +53,35 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, | ... | @@ -54,46 +53,35 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, |
54 | i++; | 53 | i++; |
55 | *start = i; | 54 | *start = i; |
56 | 55 | ||
57 | switch (command[i]) | 56 | if (!isdelim (command[i], delim)) |
58 | { | 57 | { |
59 | case '"': | 58 | while (i < len) |
60 | case '\'': | ||
61 | while (++i < len | ||
62 | && (command[i] != command[*start] | ||
63 | || command[i-1] == '\\')) | ||
64 | ; | ||
65 | if (i < len) /* found matching quote */ | ||
66 | break; | ||
67 | /*FALLTHRU*/ default: | ||
68 | if (isdelim (command[i], delim)) | ||
69 | break; | ||
70 | /* Skip until next whitespace character or end of line. Honor | ||
71 | escaped whitespace. */ | ||
72 | expect_delim = 0; | ||
73 | while (++i < len) | ||
74 | { | 59 | { |
75 | if (expect_delim) | 60 | if (command[i] == '\\') |
76 | { | 61 | { |
77 | if (command[i-1] != '\\' && command[i] == expect_delim) | 62 | if (++i == len) |
78 | expect_delim = 0; | 63 | break; |
79 | else | 64 | i++; |
80 | continue; | 65 | continue; |
81 | } | 66 | } |
82 | 67 | ||
83 | if (command[i-1] != '\\') | ||
84 | { | ||
85 | if (command[i] == '\'' || command[i] == '"') | 68 | if (command[i] == '\'' || command[i] == '"') |
86 | expect_delim = command[i]; | 69 | { |
70 | int j; | ||
71 | for (j = i+1; j < len && command[j] != command[i]; j++) | ||
72 | if (command[j] == '\\') | ||
73 | j++; | ||
74 | if (j < len) | ||
75 | i = j+1; | ||
76 | else | ||
77 | i++; | ||
78 | } | ||
87 | else if (isws (command[i]) || isdelim (command[i], delim)) | 79 | else if (isws (command[i]) || isdelim (command[i], delim)) |
88 | break; | 80 | break; |
89 | } | ||
90 | else | 81 | else |
91 | i++; /* skip the escaped character */ | 82 | i++; /* skip the escaped character */ |
92 | } | 83 | } |
93 | if (expect_delim) | ||
94 | i--; | 84 | i--; |
95 | i--; | ||
96 | break; | ||
97 | } | 85 | } |
98 | 86 | ||
99 | *end = i; | 87 | *end = i; | ... | ... |
-
Please register or sign in to post a comment