diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-09 02:39:29 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-09 02:39:29 +0000 |
commit | a69098b5643d2c902de05563918d810ef93a7d43 (patch) | |
tree | 18e5f162335e444d3eb8f267cc3cf619251aafaf | |
parent | 7728ad43614187172155ab898a46cfe55195ba02 (diff) | |
download | busybox-w32-a69098b5643d2c902de05563918d810ef93a7d43.tar.gz busybox-w32-a69098b5643d2c902de05563918d810ef93a7d43.tar.bz2 busybox-w32-a69098b5643d2c902de05563918d810ef93a7d43.zip |
Mention the opengroup sed reference, add a check which is disabled at present.
git-svn-id: svn://busybox.net/trunk/busybox@6720 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | editors/sed.c | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/editors/sed.c b/editors/sed.c index 08c56a06d..b17c8c794 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -41,6 +41,8 @@ | |||
41 | - no pattern space hold space storing / swapping (x, etc.) | 41 | - no pattern space hold space storing / swapping (x, etc.) |
42 | - no labels / branching (: label, b, t, and friends) | 42 | - no labels / branching (: label, b, t, and friends) |
43 | - and lots, lots more. | 43 | - and lots, lots more. |
44 | |||
45 | Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html | ||
44 | */ | 46 | */ |
45 | 47 | ||
46 | #include <stdio.h> | 48 | #include <stdio.h> |
@@ -419,9 +421,20 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd | |||
419 | sed_cmd->invert = 1; | 421 | sed_cmd->invert = 1; |
420 | idx++; | 422 | idx++; |
421 | 423 | ||
424 | #ifdef SED_FEATURE_STRICT_CHECKING | ||
425 | /* According to the spec | ||
426 | * It is unspecified whether <blank>s can follow a '!' character, | ||
427 | * and conforming applications shall not follow a '!' character | ||
428 | * with <blank>s. | ||
429 | */ | ||
430 | if (isblank(cmdstr[idx]) { | ||
431 | error_msg_and_die("blank follows '!'"); | ||
432 | } | ||
433 | #else | ||
422 | /* skip whitespace before the command */ | 434 | /* skip whitespace before the command */ |
423 | while (isspace(cmdstr[idx])) | 435 | while (isspace(cmdstr[idx])) |
424 | idx++; | 436 | idx++; |
437 | #endif | ||
425 | } | 438 | } |
426 | 439 | ||
427 | /* last part (mandatory) will be a command */ | 440 | /* last part (mandatory) will be a command */ |
@@ -429,29 +442,36 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd | |||
429 | error_msg_and_die("missing command"); | 442 | error_msg_and_die("missing command"); |
430 | sed_cmd->cmd = cmdstr[idx]; | 443 | sed_cmd->cmd = cmdstr[idx]; |
431 | 444 | ||
432 | /* if it was a single-letter command that takes no arguments (such as 'p' | 445 | switch (sed_cmd->cmd) { |
433 | * or 'd') all we need to do is increment the index past that command */ | 446 | /* if it was a single-letter command that takes no arguments (such as 'p' |
434 | if (strchr("pd=", sed_cmd->cmd)) { | 447 | * or 'd') all we need to do is increment the index past that command */ |
435 | idx++; | 448 | case 'p': |
436 | } | 449 | case 'd': |
437 | /* handle (s)ubstitution command */ | 450 | case '=': |
438 | else if (sed_cmd->cmd == 's') { | 451 | idx++; |
439 | idx += parse_subst_cmd(sed_cmd, &cmdstr[idx]); | 452 | break; |
440 | } | 453 | /* handle (s)ubstitution command */ |
441 | /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ | 454 | case 's': |
442 | else if (strchr("aic", sed_cmd->cmd)) { | 455 | idx += parse_subst_cmd(sed_cmd, &cmdstr[idx]); |
443 | if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') | 456 | break; |
444 | error_msg_and_die("only a beginning address can be specified for edit commands"); | 457 | /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ |
445 | idx += parse_edit_cmd(sed_cmd, &cmdstr[idx]); | 458 | case 'a': |
446 | } | 459 | case 'i': |
447 | /* handle file cmds: (r)ead */ | 460 | case 'c': |
448 | else if (sed_cmd->cmd == 'r') { | 461 | if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') { |
449 | if (sed_cmd->end_line || sed_cmd->end_match) | 462 | error_msg_and_die("only a beginning address can be specified for edit commands"); |
450 | error_msg_and_die("Command only uses one address"); | 463 | } |
451 | idx += parse_file_cmd(sed_cmd, &cmdstr[idx]); | 464 | idx += parse_edit_cmd(sed_cmd, &cmdstr[idx]); |
452 | } | 465 | break; |
453 | else { | 466 | /* handle file cmds: (r)ead */ |
454 | error_msg_and_die("Unsupported command %c", sed_cmd->cmd); | 467 | case 'r': |
468 | if (sed_cmd->end_line || sed_cmd->end_match) { | ||
469 | error_msg_and_die("Command only uses one address"); | ||
470 | } | ||
471 | idx += parse_file_cmd(sed_cmd, &cmdstr[idx]); | ||
472 | break; | ||
473 | default: | ||
474 | error_msg_and_die("Unsupported command %c", sed_cmd->cmd); | ||
455 | } | 475 | } |
456 | 476 | ||
457 | /* give back whatever's left over */ | 477 | /* give back whatever's left over */ |