aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-25 02:37:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-25 02:37:49 +0000
commit4222ae440a3c73ce5481b7b0e2db0da229fa76aa (patch)
treeae43daa4fa56c238740ee64b603dfef1574b6050
parent018e085d44206305f1d20e0111236f96f8d78c80 (diff)
downloadbusybox-w32-4222ae440a3c73ce5481b7b0e2db0da229fa76aa.tar.gz
busybox-w32-4222ae440a3c73ce5481b7b0e2db0da229fa76aa.tar.bz2
busybox-w32-4222ae440a3c73ce5481b7b0e2db0da229fa76aa.zip
ash: replace xstrdup (shell shall not die)
grep: fix mis-indented block
-rw-r--r--findutils/grep.c104
-rw-r--r--shell/ash.c4
2 files changed, 54 insertions, 54 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index f4652fa72..c1cb7dd0c 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -84,7 +84,7 @@ static int last_line_printed;
84static llist_t *pattern_head; /* growable list of patterns to match */ 84static llist_t *pattern_head; /* growable list of patterns to match */
85static const char *cur_file; /* the current file we are reading */ 85static const char *cur_file; /* the current file we are reading */
86 86
87typedef struct GREP_LIST_DATA { 87typedef struct grep_list_data_t {
88 char *pattern; 88 char *pattern;
89 regex_t preg; 89 regex_t preg;
90#define PATTERN_MEM_A 1 90#define PATTERN_MEM_A 1
@@ -162,68 +162,68 @@ static int grep_file(FILE *file)
162 if (BE_QUIET || PRINT_FILES_WITHOUT_MATCHES) 162 if (BE_QUIET || PRINT_FILES_WITHOUT_MATCHES)
163 return -1; 163 return -1;
164 164
165 /* keep track of matches */ 165 /* keep track of matches */
166 nmatches++; 166 nmatches++;
167 167
168 /* if we're just printing filenames, we stop after the first match */ 168 /* if we're just printing filenames, we stop after the first match */
169 if (PRINT_FILES_WITH_MATCHES) 169 if (PRINT_FILES_WITH_MATCHES)
170 break; 170 break;
171 171
172 /* print the matched line */ 172 /* print the matched line */
173 if (PRINT_MATCH_COUNTS == 0) { 173 if (PRINT_MATCH_COUNTS == 0) {
174#if ENABLE_FEATURE_GREP_CONTEXT 174#if ENABLE_FEATURE_GREP_CONTEXT
175 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1; 175 int prevpos = (curpos == 0) ? lines_before - 1 : curpos - 1;
176 176
177 /* if we were told to print 'before' lines and there is at least 177 /* if we were told to print 'before' lines and there is at least
178 * one line in the circular buffer, print them */ 178 * one line in the circular buffer, print them */
179 if (lines_before && before_buf[prevpos] != NULL) { 179 if (lines_before && before_buf[prevpos] != NULL) {
180 int first_buf_entry_line_num = linenum - lines_before; 180 int first_buf_entry_line_num = linenum - lines_before;
181 181
182 /* advance to the first entry in the circular buffer, and 182 /* advance to the first entry in the circular buffer, and
183 * figure out the line number is of the first line in the 183 * figure out the line number is of the first line in the
184 * buffer */ 184 * buffer */
185 idx = curpos; 185 idx = curpos;
186 while (before_buf[idx] == NULL) { 186 while (before_buf[idx] == NULL) {
187 idx = (idx + 1) % lines_before; 187 idx = (idx + 1) % lines_before;
188 first_buf_entry_line_num++; 188 first_buf_entry_line_num++;
189 }
190
191 /* now print each line in the buffer, clearing them as we go */
192 while (before_buf[idx] != NULL) {
193 print_line(before_buf[idx], first_buf_entry_line_num, '-');
194 free(before_buf[idx]);
195 before_buf[idx] = NULL;
196 idx = (idx + 1) % lines_before;
197 first_buf_entry_line_num++;
198 }
199 } 189 }
200 190
201 /* make a note that we need to print 'after' lines */ 191 /* now print each line in the buffer, clearing them as we go */
202 print_n_lines_after = lines_after; 192 while (before_buf[idx] != NULL) {
203#endif 193 print_line(before_buf[idx], first_buf_entry_line_num, '-');
204 if (option_mask32 & GREP_OPT_o) { 194 free(before_buf[idx]);
205 line[regmatch.rm_eo] = '\0'; 195 before_buf[idx] = NULL;
206 print_line(line + regmatch.rm_so, linenum, ':'); 196 idx = (idx + 1) % lines_before;
207 } else { 197 first_buf_entry_line_num++;
208 print_line(line, linenum, ':');
209 } 198 }
210 } 199 }
200
201 /* make a note that we need to print 'after' lines */
202 print_n_lines_after = lines_after;
203#endif
204 if (option_mask32 & GREP_OPT_o) {
205 line[regmatch.rm_eo] = '\0';
206 print_line(line + regmatch.rm_so, linenum, ':');
207 } else {
208 print_line(line, linenum, ':');
209 }
211 } 210 }
211 }
212#if ENABLE_FEATURE_GREP_CONTEXT 212#if ENABLE_FEATURE_GREP_CONTEXT
213 else { /* no match */ 213 else { /* no match */
214 /* Add the line to the circular 'before' buffer */ 214 /* Add the line to the circular 'before' buffer */
215 if (lines_before) { 215 if (lines_before) {
216 free(before_buf[curpos]); 216 free(before_buf[curpos]);
217 before_buf[curpos] = xstrdup(line); 217 before_buf[curpos] = xstrdup(line);
218 curpos = (curpos + 1) % lines_before; 218 curpos = (curpos + 1) % lines_before;
219 }
220 } 219 }
220 }
221 221
222 /* if we need to print some context lines after the last match, do so */ 222 /* if we need to print some context lines after the last match, do so */
223 if (print_n_lines_after && (last_line_printed != linenum)) { 223 if (print_n_lines_after && (last_line_printed != linenum)) {
224 print_line(line, linenum, '-'); 224 print_line(line, linenum, '-');
225 print_n_lines_after--; 225 print_n_lines_after--;
226 } 226 }
227#endif /* ENABLE_FEATURE_GREP_CONTEXT */ 227#endif /* ENABLE_FEATURE_GREP_CONTEXT */
228 free(line); 228 free(line);
229 } 229 }
diff --git a/shell/ash.c b/shell/ash.c
index 8e8577ad6..371b5d9c3 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2156,7 +2156,7 @@ putprompt(const char *s)
2156{ 2156{
2157 if (ENABLE_ASH_EXPAND_PRMT) { 2157 if (ENABLE_ASH_EXPAND_PRMT) {
2158 free((char*)cmdedit_prompt); 2158 free((char*)cmdedit_prompt);
2159 cmdedit_prompt = xstrdup(s); 2159 cmdedit_prompt = ckstrdup(s);
2160 return; 2160 return;
2161 } 2161 }
2162 cmdedit_prompt = s; 2162 cmdedit_prompt = s;
@@ -11033,7 +11033,7 @@ dotcmd(int argc, char **argv)
11033 int status = 0; 11033 int status = 0;
11034 11034
11035 for (sp = cmdenviron; sp; sp = sp->next) 11035 for (sp = cmdenviron; sp; sp = sp->next)
11036 setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED); 11036 setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
11037 11037
11038 if (argc >= 2) { /* That's what SVR2 does */ 11038 if (argc >= 2) { /* That's what SVR2 does */
11039 char *fullname; 11039 char *fullname;