Merge pull request #47 from brunompena/get_arg-single_quote

Add logic for single quote arguments (verbatim)
This commit is contained in:
Daniel Beer 2018-02-28 13:47:52 +13:00 committed by GitHub
commit d54d6ec6c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 11 deletions

View File

@ -60,6 +60,8 @@ char *get_arg(char **text)
goto out; goto out;
else if (*end == '"') else if (*end == '"')
qstate = 1; qstate = 1;
else if (*end == '\'')
qstate = 2;
else else
*(rewrite++) = *end; *(rewrite++) = *end;
break; break;
@ -67,15 +69,27 @@ char *get_arg(char **text)
case 1: /* In quotes */ case 1: /* In quotes */
if (*end == '"') if (*end == '"')
qstate = 0; qstate = 0;
else if (*end == '\'')
qstate = 3;
else if (*end == '\\') else if (*end == '\\')
qstate = 2; qstate = 4;
else else
*(rewrite++) = *end; *(rewrite++) = *end;
break; break;
case 2: /* Backslash */ case 2: /* In quote (verbatim) */
case 3:
if (*end == '\'')
qstate -= 2;
else
*(rewrite++) = *end;
break;
case 4: /* Backslash */
if (*end == '\\') if (*end == '\\')
*(rewrite++) = '\\'; *(rewrite++) = '\\';
else if (*end == '\'')
*(rewrite++) = '\'';
else if (*end == 'n') else if (*end == 'n')
*(rewrite++) = '\n'; *(rewrite++) = '\n';
else if (*end == 'r') else if (*end == 'r')
@ -83,24 +97,24 @@ char *get_arg(char **text)
else if (*end == 't') else if (*end == 't')
*(rewrite++) = '\t'; *(rewrite++) = '\t';
else if (*end >= '0' && *end <= '3') { else if (*end >= '0' && *end <= '3') {
qstate = 30; qstate = 50;
qval = *end - '0'; qval = *end - '0';
} else if (*end == 'x') { } else if (*end == 'x') {
qstate = 40; qstate = 60;
qval = 0; qval = 0;
} else } else
*(rewrite++) = *end; *(rewrite++) = *end;
if (qstate == 2) if (qstate == 4)
qstate = 1; qstate = 1;
break; break;
case 30: /* Octal */ case 50: /* Octal */
case 31: case 51:
if (*end >= '0' && *end <= '7') if (*end >= '0' && *end <= '7')
qval = (qval << 3) | (*end - '0'); qval = (qval << 3) | (*end - '0');
if (qstate == 31) { if (qstate == 51) {
*(rewrite++) = qval; *(rewrite++) = qval;
qstate = 1; qstate = 1;
} else { } else {
@ -108,8 +122,8 @@ char *get_arg(char **text)
} }
break; break;
case 40: /* Hex */ case 60: /* Hex */
case 41: case 61:
if (isdigit(*end)) if (isdigit(*end))
qval = (qval << 4) | (*end - '0'); qval = (qval << 4) | (*end - '0');
else if (isupper(*end)) else if (isupper(*end))
@ -117,7 +131,7 @@ char *get_arg(char **text)
else if (islower(*end)) else if (islower(*end))
qval = (qval << 4) | (*end - 'a' + 10); qval = (qval << 4) | (*end - 'a' + 10);
if (qstate == 41) { if (qstate == 61) {
*(rewrite++) = qval; *(rewrite++) = qval;
qstate = 1; qstate = 1;
} else { } else {