ref: 2537e65c9654edeacfb99ffa33c3b220294e2303
parent: 945538cfba3ce64d505ed4e944a21a8d5b85ebb8
author: Ali Gholami Rudi <[email protected]>
date: Fri Nov 23 17:08:30 EST 2012
tr: support quoted arguments
--- a/tr.c
+++ b/tr.c
@@ -163,10 +163,22 @@
static char *arg_normal(char *s, int len)
{
char *e = s + len - 1;
+ int quoted = 0;
int c;
while ((c = cp_next()) == ' ')
;
- while (s < e && c > 0 && c != ' ' && c != '\n') {
+ if (c == '"') {
+ quoted = 1;
+ c = cp_next();
+ }
+ while (s < e && c > 0 && c != '\n') {
+ if (!quoted && c == ' ')
+ break;
+ if (quoted && c == '"') {
+ c = cp_next();
+ if (c != '"')
+ break;
+ }
*s++ = c;
c = cp_next();
}