mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Mention the opengroup sed reference, add a check which is disabled at present.
This commit is contained in:
parent
505bd0f15a
commit
d5eadea970
@ -41,6 +41,8 @@
|
|||||||
- no pattern space hold space storing / swapping (x, etc.)
|
- no pattern space hold space storing / swapping (x, etc.)
|
||||||
- no labels / branching (: label, b, t, and friends)
|
- no labels / branching (: label, b, t, and friends)
|
||||||
- and lots, lots more.
|
- and lots, lots more.
|
||||||
|
|
||||||
|
Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -419,9 +421,20 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd
|
|||||||
sed_cmd->invert = 1;
|
sed_cmd->invert = 1;
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
|
#ifdef SED_FEATURE_STRICT_CHECKING
|
||||||
|
/* According to the spec
|
||||||
|
* It is unspecified whether <blank>s can follow a '!' character,
|
||||||
|
* and conforming applications shall not follow a '!' character
|
||||||
|
* with <blank>s.
|
||||||
|
*/
|
||||||
|
if (isblank(cmdstr[idx]) {
|
||||||
|
error_msg_and_die("blank follows '!'");
|
||||||
|
}
|
||||||
|
#else
|
||||||
/* skip whitespace before the command */
|
/* skip whitespace before the command */
|
||||||
while (isspace(cmdstr[idx]))
|
while (isspace(cmdstr[idx]))
|
||||||
idx++;
|
idx++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* last part (mandatory) will be a command */
|
/* 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
|
|||||||
error_msg_and_die("missing command");
|
error_msg_and_die("missing command");
|
||||||
sed_cmd->cmd = cmdstr[idx];
|
sed_cmd->cmd = cmdstr[idx];
|
||||||
|
|
||||||
/* if it was a single-letter command that takes no arguments (such as 'p'
|
switch (sed_cmd->cmd) {
|
||||||
* or 'd') all we need to do is increment the index past that command */
|
/* if it was a single-letter command that takes no arguments (such as 'p'
|
||||||
if (strchr("pd=", sed_cmd->cmd)) {
|
* or 'd') all we need to do is increment the index past that command */
|
||||||
idx++;
|
case 'p':
|
||||||
}
|
case 'd':
|
||||||
/* handle (s)ubstitution command */
|
case '=':
|
||||||
else if (sed_cmd->cmd == 's') {
|
idx++;
|
||||||
idx += parse_subst_cmd(sed_cmd, &cmdstr[idx]);
|
break;
|
||||||
}
|
/* handle (s)ubstitution command */
|
||||||
/* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
|
case 's':
|
||||||
else if (strchr("aic", sed_cmd->cmd)) {
|
idx += parse_subst_cmd(sed_cmd, &cmdstr[idx]);
|
||||||
if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c')
|
break;
|
||||||
error_msg_and_die("only a beginning address can be specified for edit commands");
|
/* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
|
||||||
idx += parse_edit_cmd(sed_cmd, &cmdstr[idx]);
|
case 'a':
|
||||||
}
|
case 'i':
|
||||||
/* handle file cmds: (r)ead */
|
case 'c':
|
||||||
else if (sed_cmd->cmd == 'r') {
|
if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c') {
|
||||||
if (sed_cmd->end_line || sed_cmd->end_match)
|
error_msg_and_die("only a beginning address can be specified for edit commands");
|
||||||
error_msg_and_die("Command only uses one address");
|
}
|
||||||
idx += parse_file_cmd(sed_cmd, &cmdstr[idx]);
|
idx += parse_edit_cmd(sed_cmd, &cmdstr[idx]);
|
||||||
}
|
break;
|
||||||
else {
|
/* handle file cmds: (r)ead */
|
||||||
error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
|
case 'r':
|
||||||
|
if (sed_cmd->end_line || sed_cmd->end_match) {
|
||||||
|
error_msg_and_die("Command only uses one address");
|
||||||
|
}
|
||||||
|
idx += parse_file_cmd(sed_cmd, &cmdstr[idx]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* give back whatever's left over */
|
/* give back whatever's left over */
|
||||||
|
Loading…
Reference in New Issue
Block a user