ash: replace xstrdup (shell shall not die)

grep: fix mis-indented block
This commit is contained in:
Denis Vlasenko
2007-02-25 02:37:49 +00:00
parent 018e085d44
commit 4222ae440a
2 changed files with 52 additions and 52 deletions

View File

@@ -84,7 +84,7 @@ static int last_line_printed;
static llist_t *pattern_head; /* growable list of patterns to match */ static llist_t *pattern_head; /* growable list of patterns to match */
static const char *cur_file; /* the current file we are reading */ static const char *cur_file; /* the current file we are reading */
typedef struct GREP_LIST_DATA { typedef struct grep_list_data_t {
char *pattern; char *pattern;
regex_t preg; regex_t preg;
#define PATTERN_MEM_A 1 #define PATTERN_MEM_A 1
@@ -162,68 +162,68 @@ static int grep_file(FILE *file)
if (BE_QUIET || PRINT_FILES_WITHOUT_MATCHES) if (BE_QUIET || PRINT_FILES_WITHOUT_MATCHES)
return -1; return -1;
/* keep track of matches */ /* keep track of matches */
nmatches++; nmatches++;
/* if we're just printing filenames, we stop after the first match */ /* if we're just printing filenames, we stop after the first match */
if (PRINT_FILES_WITH_MATCHES) if (PRINT_FILES_WITH_MATCHES)
break; break;
/* print the matched line */ /* print the matched line */
if (PRINT_MATCH_COUNTS == 0) { if (PRINT_MATCH_COUNTS == 0) {
#if ENABLE_FEATURE_GREP_CONTEXT #if ENABLE_FEATURE_GREP_CONTEXT
int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1; int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
/* if we were told to print 'before' lines and there is at least /* if we were told to print 'before' lines and there is at least
* one line in the circular buffer, print them */ * one line in the circular buffer, print them */
if (lines_before && before_buf[prevpos] != NULL) { if (lines_before && before_buf[prevpos] != NULL) {
int first_buf_entry_line_num = linenum - lines_before; int first_buf_entry_line_num = linenum - lines_before;
/* advance to the first entry in the circular buffer, and /* advance to the first entry in the circular buffer, and
* figure out the line number is of the first line in the * figure out the line number is of the first line in the
* buffer */ * buffer */
idx = curpos; idx = curpos;
while (before_buf[idx] == NULL) { while (before_buf[idx] == NULL) {
idx = (idx + 1) % lines_before; idx = (idx + 1) % lines_before;
first_buf_entry_line_num++; 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++;
}
} }
/* make a note that we need to print 'after' lines */ /* now print each line in the buffer, clearing them as we go */
print_n_lines_after = lines_after; 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 #endif
if (option_mask32 & GREP_OPT_o) { if (option_mask32 & GREP_OPT_o) {
line[regmatch.rm_eo] = '\0'; line[regmatch.rm_eo] = '\0';
print_line(line + regmatch.rm_so, linenum, ':'); print_line(line + regmatch.rm_so, linenum, ':');
} else { } else {
print_line(line, linenum, ':'); print_line(line, linenum, ':');
}
} }
} }
}
#if ENABLE_FEATURE_GREP_CONTEXT #if ENABLE_FEATURE_GREP_CONTEXT
else { /* no match */ else { /* no match */
/* Add the line to the circular 'before' buffer */ /* Add the line to the circular 'before' buffer */
if (lines_before) { if (lines_before) {
free(before_buf[curpos]); free(before_buf[curpos]);
before_buf[curpos] = xstrdup(line); before_buf[curpos] = xstrdup(line);
curpos = (curpos + 1) % lines_before; curpos = (curpos + 1) % lines_before;
}
} }
}
/* if we need to print some context lines after the last match, do so */ /* if we need to print some context lines after the last match, do so */
if (print_n_lines_after && (last_line_printed != linenum)) { if (print_n_lines_after && (last_line_printed != linenum)) {
print_line(line, linenum, '-'); print_line(line, linenum, '-');
print_n_lines_after--; print_n_lines_after--;
} }
#endif /* ENABLE_FEATURE_GREP_CONTEXT */ #endif /* ENABLE_FEATURE_GREP_CONTEXT */
free(line); free(line);
} }

View File

@@ -2156,7 +2156,7 @@ putprompt(const char *s)
{ {
if (ENABLE_ASH_EXPAND_PRMT) { if (ENABLE_ASH_EXPAND_PRMT) {
free((char*)cmdedit_prompt); free((char*)cmdedit_prompt);
cmdedit_prompt = xstrdup(s); cmdedit_prompt = ckstrdup(s);
return; return;
} }
cmdedit_prompt = s; cmdedit_prompt = s;
@@ -11033,7 +11033,7 @@ dotcmd(int argc, char **argv)
int status = 0; int status = 0;
for (sp = cmdenviron; sp; sp = sp->next) 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 */ if (argc >= 2) { /* That's what SVR2 does */
char *fullname; char *fullname;