aboutsummaryrefslogtreecommitdiff
path: root/miscutils/less.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 23:21:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 23:21:47 +0000
commitf0ed376eda5d5c25d270e5100a881fb2d801bee6 (patch)
tree79166b700c497fbe798b6031e5bbff97e0933573 /miscutils/less.c
parent670a6626cabc1498f32b35f959591f8621d8447e (diff)
downloadbusybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.tar.gz
busybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.tar.bz2
busybox-w32-f0ed376eda5d5c25d270e5100a881fb2d801bee6.zip
remove bb_printf and the like
Diffstat (limited to 'miscutils/less.c')
-rw-r--r--miscutils/less.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 11f1d8baa..de97ba6b9 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -76,7 +76,7 @@ static int num_files = 1;
76static int past_eof; 76static int past_eof;
77 77
78/* Command line options */ 78/* Command line options */
79static unsigned long flags; 79static unsigned flags;
80#define FLAG_E 1 80#define FLAG_E 1
81#define FLAG_M (1<<1) 81#define FLAG_M (1<<1)
82#define FLAG_m (1<<2) 82#define FLAG_m (1<<2)
@@ -185,12 +185,12 @@ static void clear_line(void)
185/* This adds line numbers to every line, as the -N flag necessitates */ 185/* This adds line numbers to every line, as the -N flag necessitates */
186static void add_linenumbers(void) 186static void add_linenumbers(void)
187{ 187{
188 char current_line[256];
189 int i; 188 int i;
190 189
191 for (i = 0; i <= num_flines; i++) { 190 for (i = 0; i <= num_flines; i++) {
192 safe_strncpy(current_line, flines[i], 256); 191 char *new = xasprintf("%5d %s", i + 1, flines[i]);
193 flines[i] = xasprintf("%5d %s", i + 1, current_line); 192 free(flines[i]);
193 flines[i] = new;
194 } 194 }
195} 195}
196 196
@@ -206,7 +206,7 @@ static void data_readlines(void)
206 strcpy(current_line, ""); 206 strcpy(current_line, "");
207 fgets(current_line, 256, fp); 207 fgets(current_line, 256, fp);
208 if (fp != stdin) 208 if (fp != stdin)
209 xferror(fp, filename); 209 die_if_ferror(fp, filename);
210 flines = xrealloc(flines, (i+1) * sizeof(char *)); 210 flines = xrealloc(flines, (i+1) * sizeof(char *));
211 flines[i] = xstrdup(current_line); 211 flines[i] = xstrdup(current_line);
212 } 212 }
@@ -243,13 +243,18 @@ static void m_status_print(void)
243 if (!past_eof) { 243 if (!past_eof) {
244 if (!line_pos) { 244 if (!line_pos) {
245 if (num_files > 1) 245 if (num_files > 1)
246 printf("%s%s %s%i%s%i%s%i-%i/%i ", HIGHLIGHT, filename, "(file ", current_file, " of ", num_files, ") lines ", line_pos + 1, line_pos + height - 1, num_flines + 1); 246 printf("%s%s %s%i%s%i%s%i-%i/%i ", HIGHLIGHT,
247 filename, "(file ", current_file, " of ", num_files, ") lines ",
248 line_pos + 1, line_pos + height - 1, num_flines + 1);
247 else { 249 else {
248 printf("%s%s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1); 250 printf("%s%s lines %i-%i/%i ", HIGHLIGHT,
251 filename, line_pos + 1, line_pos + height - 1,
252 num_flines + 1);
249 } 253 }
250 } 254 }
251 else { 255 else {
252 printf("%s %s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1); 256 printf("%s %s lines %i-%i/%i ", HIGHLIGHT, filename,
257 line_pos + 1, line_pos + height - 1, num_flines + 1);
253 } 258 }
254 259
255 if (line_pos == num_flines - height + 2) { 260 if (line_pos == num_flines - height + 2) {
@@ -263,7 +268,8 @@ static void m_status_print(void)
263 } 268 }
264 } 269 }
265 else { 270 else {
266 printf("%s%s lines %i-%i/%i (END) ", HIGHLIGHT, filename, line_pos + 1, num_flines + 1, num_flines + 1); 271 printf("%s%s lines %i-%i/%i (END) ", HIGHLIGHT, filename,
272 line_pos + 1, num_flines + 1, num_flines + 1);
267 if ((num_files > 1) && (current_file != num_files)) 273 if ((num_files > 1) && (current_file != num_files))
268 printf("- Next: %s", files[current_file]); 274 printf("- Next: %s", files[current_file]);
269 printf("%s", NORMAL); 275 printf("%s", NORMAL);
@@ -300,7 +306,8 @@ static void status_print(void)
300 if (!line_pos) { 306 if (!line_pos) {
301 printf("%s%s %s", HIGHLIGHT, filename, NORMAL); 307 printf("%s%s %s", HIGHLIGHT, filename, NORMAL);
302 if (num_files > 1) 308 if (num_files > 1)
303 printf("%s%s%i%s%i%s%s", HIGHLIGHT, "(file ", current_file, " of ", num_files, ")", NORMAL); 309 printf("%s%s%i%s%i%s%s", HIGHLIGHT, "(file ",
310 current_file, " of ", num_files, ")", NORMAL);
304 } 311 }
305 else if (line_pos == num_flines - height + 2) { 312 else if (line_pos == num_flines - height + 2) {
306 printf("%s%s %s", HIGHLIGHT, "(END)", NORMAL); 313 printf("%s%s %s", HIGHLIGHT, "(END)", NORMAL);
@@ -602,7 +609,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
602 insert_highlights if action = 1, or has the escape sequences 609 insert_highlights if action = 1, or has the escape sequences
603 removed if action = 0, and then the line is returned. */ 610 removed if action = 0, and then the line is returned. */
604 int match_status; 611 int match_status;
605 char *line2 = (char *) xmalloc((sizeof(char) * (strlen(line) + 1)) + 64); 612 char *line2 = xmalloc((sizeof(char) * (strlen(line) + 1)) + 64);
606 char *growline = ""; 613 char *growline = "";
607 regmatch_t match_structs; 614 regmatch_t match_structs;
608 615
@@ -616,10 +623,16 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
616 match_found = 1; 623 match_found = 1;
617 624
618 if (action) { 625 if (action) {
619 growline = xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL); 626 growline = xasprintf("%s%.*s%s%.*s%s", growline,
627 match_structs.rm_so, line2, HIGHLIGHT,
628 match_structs.rm_eo - match_structs.rm_so,
629 line2 + match_structs.rm_so, NORMAL);
620 } 630 }
621 else { 631 else {
622 growline = xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so); 632 growline = xasprintf("%s%.*s%.*s", growline,
633 match_structs.rm_so - 4, line2,
634 match_structs.rm_eo - match_structs.rm_so,
635 line2 + match_structs.rm_so);
623 } 636 }
624 637
625 line2 += match_structs.rm_eo; 638 line2 += match_structs.rm_eo;