Changeset 902 in MondoRescue for branches/stable/mindi-busybox/editors/sed.c


Ignore:
Timestamp:
Oct 25, 2006, 12:41:23 AM (17 years ago)
Author:
Bruno Cornec
Message:

mindi-busybox now uses busybox 1.2.2 (Thanks Rob for that last update and good lucck for your future projects).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/editors/sed.c

    r821 r902  
    5959*/
    6060
    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>
    6761#include "busybox.h"
    6862#include "xregex.h"
     
    9589} sed_cmd_t;
    9690
    97 static const char bad_format_in_subst[] =
    98     "bad format in substitution expression";
    9991static const char *const semicolon_whitespace = "; \n\r\t\v";
    10092
     
    176168/* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */
    177169
    178 static void parse_escapes(char *dest, const char *string, int len, char from, char to)
     170static void parse_escapes(char *dest, char *string, int len, char from, char to)
    179171{
    180172    int i=0;
     
    193185}
    194186
    195 static char *copy_parsing_escapes(const char *string, int len)
     187static char *copy_parsing_escapes(char *string, int len)
    196188{
    197189    char *dest=xmalloc(len+1);
     
    206198 * beginning at a specified index and returns the index of the next regular
    207199 * expression delimiter (typically a forward * slash ('/')) not preceded by
    208  * a backslash ('\').
     200 * a backslash ('\').  A negative delimiter disables square bracket checking.
    209201 */
    210 static int index_of_next_unescaped_regexp_delim(const char delimiter,
    211     const char *str)
     202static int index_of_next_unescaped_regexp_delim(int delimiter, char *str)
    212203{
    213204    int bracket = -1;
     
    216207    char ch;
    217208
     209    if (delimiter < 0) {
     210        bracket--;
     211        delimiter *= -1;
     212    }
     213
    218214    for (; (ch = str[idx]); idx++) {
    219         if (bracket != -1) {
     215        if (bracket >= 0) {
    220216            if (ch == ']' && !(bracket == idx - 1 || (bracket == idx - 2
    221217                    && str[idx - 1] == '^')))
     
    225221        else if (ch == '\\')
    226222            escaped = 1;
    227         else if (ch == '[')
     223        else if (bracket == -1 && ch == '[')
    228224            bracket = idx;
    229225        else if (ch == delimiter)
     
    232228
    233229    /* 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);
    235231}
    236232
     
    238234 *  Returns the index of the third delimiter
    239235 */
    240 static int parse_regex_delim(const char *cmdstr, char **match, char **replace)
    241 {
    242     const char *cmdstr_ptr = cmdstr;
     236static int parse_regex_delim(char *cmdstr, char **match, char **replace)
     237{
     238    char *cmdstr_ptr = cmdstr;
    243239    char delimiter;
    244240    int idx = 0;
     
    246242    /* verify that the 's' or 'y' is followed by something.  That something
    247243     * (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");
    249246    delimiter = *(cmdstr_ptr++);
    250247
    251248    /* save the match string */
    252249    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     }
    256250    *match = copy_parsing_escapes(cmdstr_ptr, idx);
    257251
    258252    /* save the replacement string */
    259253    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);
    264255    *replace = copy_parsing_escapes(cmdstr_ptr, idx);
    265256
     
    288279        else delimiter = '/';
    289280        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);
    294282        *regex = (regex_t *) xmalloc(sizeof(regex_t));
    295283        xregcomp(*regex, temp, bbg.regex_type|REG_NEWLINE);
    296284        free(temp);
    297285        /* Move position to next character after last delimiter */
    298         pos+=(next+1);
     286        pos += (next+1);
    299287    }
    300288    return pos - my_str;
     
    302290
    303291/* Grab a filename.  Whitespace at start is skipped, then goes to EOL. */
    304 static int parse_file_cmd(sed_cmd_t *sed_cmd, const char *filecmdstr, char **retval)
     292static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval)
    305293{
    306294    int start = 0, idx, hack=0;
     
    319307}
    320308
    321 static int parse_subst_cmd(sed_cmd_t *const sed_cmd, char *substr)
     309static int parse_subst_cmd(sed_cmd_t *sed_cmd, char *substr)
    322310{
    323311    int cflags = bbg.regex_type;
     
    570558}
    571559
    572 static void do_subst_w_backrefs(const char *line, const char *replace)
     560static void do_subst_w_backrefs(char *line, char *replace)
    573561{
    574562    int i,j;
     
    640628        if(sed_cmd->which_match && sed_cmd->which_match!=match_count) {
    641629            for(i=0;i<bbg.regmatch[0].rm_eo;i++)
    642                 pipe_putc(oldline[i]);
     630                pipe_putc(*(oldline++));
    643631            continue;
    644632        }
     
    670658
    671659/* Set command pointer to point to this label.  (Does not handle null label.) */
    672 static sed_cmd_t *branch_to(const char *label)
     660static sed_cmd_t *branch_to(char *label)
    673661{
    674662    sed_cmd_t *sed_cmd;
Note: See TracChangeset for help on using the changeset viewer.