aboutsummaryrefslogtreecommitdiff
path: root/miscutils/less.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-08-03 15:41:12 +0000
committerRob Landley <rob@landley.net>2006-08-03 15:41:12 +0000
commitd921b2ecc0d294ad4bf8c7458fc52a60c28727d2 (patch)
treee4a2769349867c441cf2983d83097bb66701a733 /miscutils/less.c
parent6dce0b6fa79f2d4bb7e9d90e1fbc0f6beb25f855 (diff)
downloadbusybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.tar.gz
busybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.tar.bz2
busybox-w32-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.zip
Remove bb_ prefixes from xfuncs.c (and a few other places), consolidate
things like xasprintf() into xfuncs.c, remove xprint_file_by_name() (it only had one user), clean up lots of #includes... General cleanup pass. What I've been doing for the last couple days. And it conflicts! I've removed httpd.c from this checkin due to somebody else touching that file. It builds for me. I have to catch a bus. (Now you know why I'm looking forward to Mercurial.)
Diffstat (limited to 'miscutils/less.c')
-rw-r--r--miscutils/less.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 596490483..9dd9b9e56 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -31,12 +31,6 @@
31*/ 31*/
32 32
33#include "busybox.h" 33#include "busybox.h"
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <termios.h>
38#include <unistd.h>
39#include <ctype.h>
40 34
41#ifdef CONFIG_FEATURE_LESS_REGEXP 35#ifdef CONFIG_FEATURE_LESS_REGEXP
42#include "xregex.h" 36#include "xregex.h"
@@ -196,7 +190,7 @@ static void add_linenumbers(void)
196 190
197 for (i = 0; i <= num_flines; i++) { 191 for (i = 0; i <= num_flines; i++) {
198 safe_strncpy(current_line, flines[i], 256); 192 safe_strncpy(current_line, flines[i], 256);
199 flines[i] = bb_xasprintf("%5d %s", i + 1, current_line); 193 flines[i] = xasprintf("%5d %s", i + 1, current_line);
200 } 194 }
201} 195}
202 196
@@ -206,15 +200,15 @@ static void data_readlines(void)
206 char current_line[256]; 200 char current_line[256];
207 FILE *fp; 201 FILE *fp;
208 202
209 fp = (inp_stdin) ? stdin : bb_xfopen(filename, "r"); 203 fp = (inp_stdin) ? stdin : xfopen(filename, "r");
210 flines = NULL; 204 flines = NULL;
211 for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) { 205 for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
212 strcpy(current_line, ""); 206 strcpy(current_line, "");
213 fgets(current_line, 256, fp); 207 fgets(current_line, 256, fp);
214 if (fp != stdin) 208 if (fp != stdin)
215 bb_xferror(fp, filename); 209 xferror(fp, filename);
216 flines = xrealloc(flines, (i+1) * sizeof(char *)); 210 flines = xrealloc(flines, (i+1) * sizeof(char *));
217 flines[i] = bb_xstrdup(current_line); 211 flines[i] = xstrdup(current_line);
218 } 212 }
219 num_flines = i - 2; 213 num_flines = i - 2;
220 214
@@ -226,7 +220,7 @@ static void data_readlines(void)
226 fclose(fp); 220 fclose(fp);
227 221
228 if (inp == NULL) 222 if (inp == NULL)
229 inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin; 223 inp = (inp_stdin) ? xfopen(CURRENT_TTY, "r") : stdin;
230 224
231 if (flags & FLAG_N) 225 if (flags & FLAG_N)
232 add_linenumbers(); 226 add_linenumbers();
@@ -357,12 +351,12 @@ static void buffer_init(void)
357 /* Fill the buffer until the end of the file or the 351 /* Fill the buffer until the end of the file or the
358 end of the buffer is reached */ 352 end of the buffer is reached */
359 for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) { 353 for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
360 buffer[i] = bb_xstrdup(flines[i]); 354 buffer[i] = xstrdup(flines[i]);
361 } 355 }
362 356
363 /* If the buffer still isn't full, fill it with blank lines */ 357 /* If the buffer still isn't full, fill it with blank lines */
364 for (; i < (height - 1); i++) { 358 for (; i < (height - 1); i++) {
365 buffer[i] = bb_xstrdup(""); 359 buffer[i] = xstrdup("");
366 } 360 }
367} 361}
368 362
@@ -376,7 +370,7 @@ static void buffer_down(int nlines)
376 line_pos += nlines; 370 line_pos += nlines;
377 for (i = 0; i < (height - 1); i++) { 371 for (i = 0; i < (height - 1); i++) {
378 free(buffer[i]); 372 free(buffer[i]);
379 buffer[i] = bb_xstrdup(flines[line_pos + i]); 373 buffer[i] = xstrdup(flines[line_pos + i]);
380 } 374 }
381 } 375 }
382 else { 376 else {
@@ -386,7 +380,7 @@ static void buffer_down(int nlines)
386 line_pos += 1; 380 line_pos += 1;
387 for (i = 0; i < (height - 1); i++) { 381 for (i = 0; i < (height - 1); i++) {
388 free(buffer[i]); 382 free(buffer[i]);
389 buffer[i] = bb_xstrdup(flines[line_pos + i]); 383 buffer[i] = xstrdup(flines[line_pos + i]);
390 } 384 }
391 } 385 }
392 } 386 }
@@ -407,7 +401,7 @@ static void buffer_up(int nlines)
407 line_pos -= nlines; 401 line_pos -= nlines;
408 for (i = 0; i < (height - 1); i++) { 402 for (i = 0; i < (height - 1); i++) {
409 free(buffer[i]); 403 free(buffer[i]);
410 buffer[i] = bb_xstrdup(flines[line_pos + i]); 404 buffer[i] = xstrdup(flines[line_pos + i]);
411 } 405 }
412 } 406 }
413 else { 407 else {
@@ -417,7 +411,7 @@ static void buffer_up(int nlines)
417 line_pos -= 1; 411 line_pos -= 1;
418 for (i = 0; i < (height - 1); i++) { 412 for (i = 0; i < (height - 1); i++) {
419 free(buffer[i]); 413 free(buffer[i]);
420 buffer[i] = bb_xstrdup(flines[line_pos + i]); 414 buffer[i] = xstrdup(flines[line_pos + i]);
421 } 415 }
422 } 416 }
423 } 417 }
@@ -439,10 +433,10 @@ static void buffer_up(int nlines)
439 for (i = 0; i < (height - 1); i++) { 433 for (i = 0; i < (height - 1); i++) {
440 free(buffer[i]); 434 free(buffer[i]);
441 if (i < tilde_line - nlines + 1) 435 if (i < tilde_line - nlines + 1)
442 buffer[i] = bb_xstrdup(flines[line_pos + i]); 436 buffer[i] = xstrdup(flines[line_pos + i]);
443 else { 437 else {
444 if (line_pos >= num_flines - height + 2) 438 if (line_pos >= num_flines - height + 2)
445 buffer[i] = bb_xstrdup("~\n"); 439 buffer[i] = xstrdup("~\n");
446 } 440 }
447 } 441 }
448 } 442 }
@@ -461,7 +455,7 @@ static void buffer_line(int linenum)
461 else if (linenum < (num_flines - height - 2)) { 455 else if (linenum < (num_flines - height - 2)) {
462 for (i = 0; i < (height - 1); i++) { 456 for (i = 0; i < (height - 1); i++) {
463 free(buffer[i]); 457 free(buffer[i]);
464 buffer[i] = bb_xstrdup(flines[linenum + i]); 458 buffer[i] = xstrdup(flines[linenum + i]);
465 } 459 }
466 line_pos = linenum; 460 line_pos = linenum;
467 buffer_print(); 461 buffer_print();
@@ -470,9 +464,9 @@ static void buffer_line(int linenum)
470 for (i = 0; i < (height - 1); i++) { 464 for (i = 0; i < (height - 1); i++) {
471 free(buffer[i]); 465 free(buffer[i]);
472 if (linenum + i < num_flines + 2) 466 if (linenum + i < num_flines + 2)
473 buffer[i] = bb_xstrdup(flines[linenum + i]); 467 buffer[i] = xstrdup(flines[linenum + i]);
474 else 468 else
475 buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n"); 469 buffer[i] = xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
476 } 470 }
477 line_pos = linenum; 471 line_pos = linenum;
478 /* Set past_eof so buffer_down and buffer_up act differently */ 472 /* Set past_eof so buffer_down and buffer_up act differently */
@@ -508,7 +502,7 @@ static void examine_file(void)
508 newline_offset = strlen(filename) - 1; 502 newline_offset = strlen(filename) - 1;
509 filename[newline_offset] = '\0'; 503 filename[newline_offset] = '\0';
510 504
511 files[num_files] = bb_xstrdup(filename); 505 files[num_files] = xstrdup(filename);
512 current_file = num_files + 1; 506 current_file = num_files + 1;
513 num_files++; 507 num_files++;
514 508
@@ -612,7 +606,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
612 char *growline = ""; 606 char *growline = "";
613 regmatch_t match_structs; 607 regmatch_t match_structs;
614 608
615 line2 = bb_xstrdup(line); 609 line2 = xstrdup(line);
616 610
617 match_found = 0; 611 match_found = 0;
618 match_status = regexec(pattern, line2, 1, &match_structs, 0); 612 match_status = regexec(pattern, line2, 1, &match_structs, 0);
@@ -622,17 +616,17 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
622 match_found = 1; 616 match_found = 1;
623 617
624 if (action) { 618 if (action) {
625 growline = bb_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); 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 } 620 }
627 else { 621 else {
628 growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so); 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);
629 } 623 }
630 624
631 line2 += match_structs.rm_eo; 625 line2 += match_structs.rm_eo;
632 match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL); 626 match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
633 } 627 }
634 628
635 growline = bb_xasprintf("%s%s", growline, line2); 629 growline = xasprintf("%s%s", growline, line2);
636 630
637 return (match_found ? growline : line); 631 return (match_found ? growline : line);
638 632
@@ -679,7 +673,7 @@ static void regex_process(void)
679 /* Get rid of all the highlights we added previously */ 673 /* Get rid of all the highlights we added previously */
680 for (i = 0; i <= num_flines; i++) { 674 for (i = 0; i <= num_flines; i++) {
681 current_line = process_regex_on_line(flines[i], &old_pattern, 0); 675 current_line = process_regex_on_line(flines[i], &old_pattern, 0);
682 flines[i] = bb_xstrdup(current_line); 676 flines[i] = xstrdup(current_line);
683 } 677 }
684 } 678 }
685 old_pattern = pattern; 679 old_pattern = pattern;
@@ -693,7 +687,7 @@ static void regex_process(void)
693 /* Run the regex on each line of the current file here */ 687 /* Run the regex on each line of the current file here */
694 for (i = 0; i <= num_flines; i++) { 688 for (i = 0; i <= num_flines; i++) {
695 current_line = process_regex_on_line(flines[i], &pattern, 1); 689 current_line = process_regex_on_line(flines[i], &pattern, 1);
696 flines[i] = bb_xstrdup(current_line); 690 flines[i] = xstrdup(current_line);
697 if (match_found) { 691 if (match_found) {
698 match_lines = xrealloc(match_lines, (j + 1) * sizeof(int)); 692 match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
699 match_lines[j] = i; 693 match_lines[j] = i;
@@ -864,7 +858,7 @@ static void save_input_to_file(void)
864 fgets(current_line, 256, inp); 858 fgets(current_line, 256, inp);
865 current_line[strlen(current_line) - 1] = '\0'; 859 current_line[strlen(current_line) - 1] = '\0';
866 if (strlen(current_line) > 1) { 860 if (strlen(current_line) > 1) {
867 fp = bb_xfopen(current_line, "w"); 861 fp = xfopen(current_line, "w");
868 for (i = 0; i < num_flines; i++) 862 for (i = 0; i < num_flines; i++)
869 fprintf(fp, "%s", flines[i]); 863 fprintf(fp, "%s", flines[i]);
870 fclose(fp); 864 fclose(fp);