Changeset 902 in MondoRescue for branches/stable/mindi-busybox/editors/sed.c
- Timestamp:
- Oct 25, 2006, 12:41:23 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/editors/sed.c
r821 r902 59 59 */ 60 60 61 #include <stdio.h>62 #include <unistd.h> /* for getopt() */63 #include <errno.h>64 #include <ctype.h> /* for isspace() */65 #include <stdlib.h>66 #include <string.h>67 61 #include "busybox.h" 68 62 #include "xregex.h" … … 95 89 } sed_cmd_t; 96 90 97 static const char bad_format_in_subst[] =98 "bad format in substitution expression";99 91 static const char *const semicolon_whitespace = "; \n\r\t\v"; 100 92 … … 176 168 /* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */ 177 169 178 static void parse_escapes(char *dest, c onst char *string, int len, char from, char to)170 static void parse_escapes(char *dest, char *string, int len, char from, char to) 179 171 { 180 172 int i=0; … … 193 185 } 194 186 195 static char *copy_parsing_escapes(c onst char *string, int len)187 static char *copy_parsing_escapes(char *string, int len) 196 188 { 197 189 char *dest=xmalloc(len+1); … … 206 198 * beginning at a specified index and returns the index of the next regular 207 199 * expression delimiter (typically a forward * slash ('/')) not preceded by 208 * a backslash ('\'). 200 * a backslash ('\'). A negative delimiter disables square bracket checking. 209 201 */ 210 static int index_of_next_unescaped_regexp_delim(const char delimiter, 211 const char *str) 202 static int index_of_next_unescaped_regexp_delim(int delimiter, char *str) 212 203 { 213 204 int bracket = -1; … … 216 207 char ch; 217 208 209 if (delimiter < 0) { 210 bracket--; 211 delimiter *= -1; 212 } 213 218 214 for (; (ch = str[idx]); idx++) { 219 if (bracket != -1) {215 if (bracket >= 0) { 220 216 if (ch == ']' && !(bracket == idx - 1 || (bracket == idx - 2 221 217 && str[idx - 1] == '^'))) … … 225 221 else if (ch == '\\') 226 222 escaped = 1; 227 else if ( ch == '[')223 else if (bracket == -1 && ch == '[') 228 224 bracket = idx; 229 225 else if (ch == delimiter) … … 232 228 233 229 /* if we make it to here, we've hit the end of the string */ 234 return -1;230 bb_error_msg_and_die("unmatched '%c'",delimiter); 235 231 } 236 232 … … 238 234 * Returns the index of the third delimiter 239 235 */ 240 static int parse_regex_delim(c onst char *cmdstr, char **match, char **replace)241 { 242 c onst char *cmdstr_ptr = cmdstr;236 static int parse_regex_delim(char *cmdstr, char **match, char **replace) 237 { 238 char *cmdstr_ptr = cmdstr; 243 239 char delimiter; 244 240 int idx = 0; … … 246 242 /* verify that the 's' or 'y' is followed by something. That something 247 243 * (typically a 'slash') is now our regexp delimiter... */ 248 if (*cmdstr == '\0') bb_error_msg_and_die(bad_format_in_subst); 244 if (*cmdstr == '\0') 245 bb_error_msg_and_die("bad format in substitution expression"); 249 246 delimiter = *(cmdstr_ptr++); 250 247 251 248 /* save the match string */ 252 249 idx = index_of_next_unescaped_regexp_delim(delimiter, cmdstr_ptr); 253 if (idx == -1) {254 bb_error_msg_and_die(bad_format_in_subst);255 }256 250 *match = copy_parsing_escapes(cmdstr_ptr, idx); 257 251 258 252 /* save the replacement string */ 259 253 cmdstr_ptr += idx + 1; 260 idx = index_of_next_unescaped_regexp_delim(delimiter, cmdstr_ptr); 261 if (idx == -1) { 262 bb_error_msg_and_die(bad_format_in_subst); 263 } 254 idx = index_of_next_unescaped_regexp_delim(-delimiter, cmdstr_ptr); 264 255 *replace = copy_parsing_escapes(cmdstr_ptr, idx); 265 256 … … 288 279 else delimiter = '/'; 289 280 next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); 290 if (next == -1) 291 bb_error_msg_and_die("unterminated match expression"); 292 293 temp=copy_parsing_escapes(pos,next); 281 temp = copy_parsing_escapes(pos,next); 294 282 *regex = (regex_t *) xmalloc(sizeof(regex_t)); 295 283 xregcomp(*regex, temp, bbg.regex_type|REG_NEWLINE); 296 284 free(temp); 297 285 /* Move position to next character after last delimiter */ 298 pos +=(next+1);286 pos += (next+1); 299 287 } 300 288 return pos - my_str; … … 302 290 303 291 /* Grab a filename. Whitespace at start is skipped, then goes to EOL. */ 304 static int parse_file_cmd(sed_cmd_t *sed_cmd, c onst char *filecmdstr, char **retval)292 static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval) 305 293 { 306 294 int start = 0, idx, hack=0; … … 319 307 } 320 308 321 static int parse_subst_cmd(sed_cmd_t * constsed_cmd, char *substr)309 static int parse_subst_cmd(sed_cmd_t *sed_cmd, char *substr) 322 310 { 323 311 int cflags = bbg.regex_type; … … 570 558 } 571 559 572 static void do_subst_w_backrefs(c onst char *line, constchar *replace)560 static void do_subst_w_backrefs(char *line, char *replace) 573 561 { 574 562 int i,j; … … 640 628 if(sed_cmd->which_match && sed_cmd->which_match!=match_count) { 641 629 for(i=0;i<bbg.regmatch[0].rm_eo;i++) 642 pipe_putc( oldline[i]);630 pipe_putc(*(oldline++)); 643 631 continue; 644 632 } … … 670 658 671 659 /* Set command pointer to point to this label. (Does not handle null label.) */ 672 static sed_cmd_t *branch_to(c onst char *label)660 static sed_cmd_t *branch_to(char *label) 673 661 { 674 662 sed_cmd_t *sed_cmd;
Note:
See TracChangeset
for help on using the changeset viewer.