61 |
#include "libbb.h" |
#include "libbb.h" |
62 |
#include "xregex.h" |
#include "xregex.h" |
63 |
|
|
64 |
|
enum { |
65 |
|
OPT_in_place = 1 << 0, |
66 |
|
}; |
67 |
|
|
68 |
/* Each sed command turns into one of these structures. */ |
/* Each sed command turns into one of these structures. */ |
69 |
typedef struct sed_cmd_s { |
typedef struct sed_cmd_s { |
70 |
/* Ordered by alignment requirements: currently 36 bytes on x86 */ |
/* Ordered by alignment requirements: currently 36 bytes on x86 */ |
942 |
|
|
943 |
if (matched) { |
if (matched) { |
944 |
/* once matched, "n,xxx" range is dead, disabling it */ |
/* once matched, "n,xxx" range is dead, disabling it */ |
945 |
if (sed_cmd->beg_line > 0) |
if (sed_cmd->beg_line > 0 |
946 |
|
&& !(option_mask32 & OPT_in_place) /* but not for -i */ |
947 |
|
) { |
948 |
sed_cmd->beg_line = -2; |
sed_cmd->beg_line = -2; |
949 |
|
} |
950 |
sed_cmd->in_match = !( |
sed_cmd->in_match = !( |
951 |
/* has the ending line come, or is this a single address command? */ |
/* has the ending line come, or is this a single address command? */ |
952 |
(sed_cmd->end_line ? |
(sed_cmd->end_line ? |
992 |
} |
} |
993 |
|
|
994 |
/* actual sedding */ |
/* actual sedding */ |
995 |
|
//bb_error_msg("pattern_space:'%s' next_line:'%s' cmd:%c", |
996 |
|
//pattern_space, next_line, sed_cmd->cmd); |
997 |
switch (sed_cmd->cmd) { |
switch (sed_cmd->cmd) { |
998 |
|
|
999 |
/* Print line number */ |
/* Print line number */ |
1120 |
{ |
{ |
1121 |
int len; |
int len; |
1122 |
/* If no next line, jump to end of script and exit. */ |
/* If no next line, jump to end of script and exit. */ |
1123 |
|
/* http://www.gnu.org/software/sed/manual/sed.html: |
1124 |
|
* "Most versions of sed exit without printing anything |
1125 |
|
* when the N command is issued on the last line of |
1126 |
|
* a file. GNU sed prints pattern space before exiting |
1127 |
|
* unless of course the -n command switch has been |
1128 |
|
* specified. This choice is by design." |
1129 |
|
*/ |
1130 |
if (next_line == NULL) { |
if (next_line == NULL) { |
1131 |
free(next_line); |
//goto discard_line; |
1132 |
next_line = NULL; |
goto discard_commands; /* GNU behavior */ |
|
goto discard_line; |
|
1133 |
} |
} |
1134 |
/* Append next_line, read new next_line. */ |
/* Append next_line, read new next_line. */ |
1135 |
len = strlen(pattern_space); |
len = strlen(pattern_space); |
1285 |
int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1286 |
int sed_main(int argc UNUSED_PARAM, char **argv) |
int sed_main(int argc UNUSED_PARAM, char **argv) |
1287 |
{ |
{ |
|
enum { |
|
|
OPT_in_place = 1 << 0, |
|
|
}; |
|
1288 |
unsigned opt; |
unsigned opt; |
1289 |
llist_t *opt_e, *opt_f; |
llist_t *opt_e, *opt_f; |
1290 |
int status = EXIT_SUCCESS; |
int status = EXIT_SUCCESS; |
1304 |
opt_e = opt_f = NULL; |
opt_e = opt_f = NULL; |
1305 |
opt_complementary = "e::f::" /* can occur multiple times */ |
opt_complementary = "e::f::" /* can occur multiple times */ |
1306 |
"nn"; /* count -n */ |
"nn"; /* count -n */ |
1307 |
|
/* -i must be first, to match OPT_in_place definition */ |
1308 |
opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, |
opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, |
1309 |
&G.be_quiet); /* counter for -n */ |
&G.be_quiet); /* counter for -n */ |
1310 |
//argc -= optind; |
//argc -= optind; |