[BusyBox] -A patch to bb 0.49
Richard June
rjune at imagestream-is.com
Thu Feb 1 21:13:27 UTC 2001
Matt Kraai wrote:
[snip]
>
>> --- grep.c Wed Jan 31 12:18:00 2001
>> +++ grep.c.new Wed Jan 31 12:17:26 2001
>> @@ -33,6 +33,10 @@
>> extern int optind; /* in unistd.h */
>> extern int errno; /* for use with strerror() */
>>
>> +#ifdef LINES_BEFORE_AFTER
>> +extern char *optarg;
>> +#endif /* LINES_BEFORE_AFTER */
>> +
>> /* options */
>> static int ignore_case = 0;
>> static int print_filename = 0;
>> @@ -42,6 +46,10 @@
>> static int invert_search = 0;
>> static int suppress_err_msgs = 0;
>>
>> +#ifdef LINES_BEFORE_AFTER
>> +static int lines = 0;
>> +#endif /* LINES_BEFORE_AFTER */
>> +
>> /* globals */
>> static regex_t regex; /* storage space for compiled regular expression */
>> static int matched; /* keeps track of whether we ever matched */
>> @@ -69,7 +77,8 @@
>> int nmatches = 0;
>>
>> while ((line = get_line_from_file(file)) != NULL) {
>> - chomp(line);
>> + if (line[strlen(line)-1] == '\n')
>> + line[strlen(line)-1] = '\0';
>
>
> Please revert this change. The strlen style isn't correct, and it
> is also bigger.
done, I need to remember, cvs update, *then* fiddle with things. :-)
[snip]
>
>> + linenum++;
>> + print_matched_line(line, linenum);
>> + }
>> + }
>> +#else
>> print_matched_line(line, linenum);
>> +#endif /* LINES_BEFORE_AFTER */
>> }
>>
>> free(line);
>> @@ -116,7 +153,7 @@
>> int reflags;
>>
>> /* do normal option parsing */
>> - while ((opt = getopt(argc, argv, "iHhnqvsc")) > 0) {
>> + while ((opt = getopt(argc, argv, "iHhnqvscA:")) > 0) {
>> switch (opt) {
>> case 'i':
>> ignore_case++;
>> @@ -142,6 +179,11 @@
>> case 'c':
>> print_count_only++;
>> break;
>> +#ifdef LINES_BEFORE_AFTER
>> + case 'A':
>> + lines = atoi(optarg);
>> + break;
>> +#endif /* LINES_BEFORE_AFTER */
>
>
> I don't know for sure, but I personally think that this should use
> parse_number with the null suffix list. That way, constructs like
>
> grep -A 23sds pattern
>
> will be complained about rather than silently ignored. See tail.c
> for an example of how to do this (though I should probably move
> the null_suffixes structure into utility.c).
>
Hmmm, hafta look at that, really strtol is probably a bit better as it
will do error checking and make sure that it's actually dealing with a
number. easy enough to do though.
More information about the busybox
mailing list