ash: replace xstrdup (shell shall not die)
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 25 Feb 2007 02:37:49 +0000 (02:37 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 25 Feb 2007 02:37:49 +0000 (02:37 -0000)
grep: fix mis-indented block

findutils/grep.c
shell/ash.c

index f4652fa72da1b87e6c4be999e7c91b1d525be9c8..c1cb7dd0cc88d34eb49efd87af2df9e38d29b28f 100644 (file)
@@ -84,7 +84,7 @@ static int last_line_printed;
 static llist_t *pattern_head;   /* growable list of patterns to match */
 static const char *cur_file;    /* the current file we are reading */
 
-typedef struct GREP_LIST_DATA {
+typedef struct grep_list_data_t {
        char *pattern;
        regex_t preg;
 #define PATTERN_MEM_A 1
@@ -162,68 +162,68 @@ static int grep_file(FILE *file)
                        if (BE_QUIET || PRINT_FILES_WITHOUT_MATCHES)
                                return -1;
 
-                               /* keep track of matches */
-                               nmatches++;
+                       /* keep track of matches */
+                       nmatches++;
 
-                               /* if we're just printing filenames, we stop after the first match */
-                               if (PRINT_FILES_WITH_MATCHES)
-                                       break;
+                       /* if we're just printing filenames, we stop after the first match */
+                       if (PRINT_FILES_WITH_MATCHES)
+                               break;
 
-                               /* print the matched line */
-                               if (PRINT_MATCH_COUNTS == 0) {
+                       /* print the matched line */
+                       if (PRINT_MATCH_COUNTS == 0) {
 #if ENABLE_FEATURE_GREP_CONTEXT
-                                       int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
-
-                                       /* if we were told to print 'before' lines and there is at least
-                                        * one line in the circular buffer, print them */
-                                       if (lines_before && before_buf[prevpos] != NULL) {
-                                               int first_buf_entry_line_num = linenum - lines_before;
-
-                                               /* advance to the first entry in the circular buffer, and
-                                                * figure out the line number is of the first line in the
-                                                * buffer */
-                                               idx = curpos;
-                                               while (before_buf[idx] == NULL) {
-                                                       idx = (idx + 1) % lines_before;
-                                                       first_buf_entry_line_num++;
-                                               }
-
-                                               /* now print each line in the buffer, clearing them as we go */
-                                               while (before_buf[idx] != NULL) {
-                                                       print_line(before_buf[idx], first_buf_entry_line_num, '-');
-                                                       free(before_buf[idx]);
-                                                       before_buf[idx] = NULL;
-                                                       idx = (idx + 1) % lines_before;
-                                                       first_buf_entry_line_num++;
-                                               }
+                               int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
+
+                               /* if we were told to print 'before' lines and there is at least
+                                * one line in the circular buffer, print them */
+                               if (lines_before && before_buf[prevpos] != NULL) {
+                                       int first_buf_entry_line_num = linenum - lines_before;
+
+                                       /* advance to the first entry in the circular buffer, and
+                                        * figure out the line number is of the first line in the
+                                        * buffer */
+                                       idx = curpos;
+                                       while (before_buf[idx] == NULL) {
+                                               idx = (idx + 1) % lines_before;
+                                               first_buf_entry_line_num++;
                                        }
 
-                                       /* make a note that we need to print 'after' lines */
-                                       print_n_lines_after = lines_after;
-#endif
-                                       if (option_mask32 & GREP_OPT_o) {
-                                               line[regmatch.rm_eo] = '\0';
-                                               print_line(line + regmatch.rm_so, linenum, ':');
-                                       } else {
-                                               print_line(line, linenum, ':');
+                                       /* now print each line in the buffer, clearing them as we go */
+                                       while (before_buf[idx] != NULL) {
+                                               print_line(before_buf[idx], first_buf_entry_line_num, '-');
+                                               free(before_buf[idx]);
+                                               before_buf[idx] = NULL;
+                                               idx = (idx + 1) % lines_before;
+                                               first_buf_entry_line_num++;
                                        }
                                }
+
+                               /* make a note that we need to print 'after' lines */
+                               print_n_lines_after = lines_after;
+#endif
+                               if (option_mask32 & GREP_OPT_o) {
+                                       line[regmatch.rm_eo] = '\0';
+                                       print_line(line + regmatch.rm_so, linenum, ':');
+                               } else {
+                                       print_line(line, linenum, ':');
+                               }
                        }
+               }
 #if ENABLE_FEATURE_GREP_CONTEXT
-                       else { /* no match */
-                               /* Add the line to the circular 'before' buffer */
-                               if (lines_before) {
-                                       free(before_buf[curpos]);
-                                       before_buf[curpos] = xstrdup(line);
-                                       curpos = (curpos + 1) % lines_before;
-                               }
+               else { /* no match */
+                       /* Add the line to the circular 'before' buffer */
+                       if (lines_before) {
+                               free(before_buf[curpos]);
+                               before_buf[curpos] = xstrdup(line);
+                               curpos = (curpos + 1) % lines_before;
                        }
+               }
 
-                       /* if we need to print some context lines after the last match, do so */
-                       if (print_n_lines_after && (last_line_printed != linenum)) {
-                               print_line(line, linenum, '-');
-                               print_n_lines_after--;
-                       }
+               /* if we need to print some context lines after the last match, do so */
+               if (print_n_lines_after && (last_line_printed != linenum)) {
+                       print_line(line, linenum, '-');
+                       print_n_lines_after--;
+               }
 #endif /* ENABLE_FEATURE_GREP_CONTEXT */
                free(line);
        }
index 8e8577ad6d6859ee8fe731f0120ca065f57cb0f3..371b5d9c3a3975ae1f98a5da2eedd98eaee43e01 100644 (file)
@@ -2156,7 +2156,7 @@ putprompt(const char *s)
 {
        if (ENABLE_ASH_EXPAND_PRMT) {
                free((char*)cmdedit_prompt);
-               cmdedit_prompt = xstrdup(s);
+               cmdedit_prompt = ckstrdup(s);
                return;
        }
        cmdedit_prompt = s;
@@ -11033,7 +11033,7 @@ dotcmd(int argc, char **argv)
        int status = 0;
 
        for (sp = cmdenviron; sp; sp = sp->next)
-               setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
+               setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
 
        if (argc >= 2) {        /* That's what SVR2 does */
                char *fullname;