Changeset View
Changeset View
Standalone View
Standalone View
gnu/usr.bin/grep/grep.c
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
/* If nonzero, use mmap if possible. */ | /* If nonzero, use mmap if possible. */ | ||||
static int mmap_option; | static int mmap_option; | ||||
/* If zero, output nulls after filenames. */ | /* If zero, output nulls after filenames. */ | ||||
static int filename_mask; | static int filename_mask; | ||||
/* If nonzero, use grep_color marker. */ | /* If nonzero, use grep_color marker. */ | ||||
static int color_option; | static int color_option = 2; | ||||
/* If nonzero, show only the part of a line matching the expression. */ | /* If nonzero, show only the part of a line matching the expression. */ | ||||
static int only_matching; | static int only_matching; | ||||
/* The color string used. The user can overwrite it using the environment | /* The color string used. The user can overwrite it using the environment | ||||
variable GREP_COLOR. The default is to print red. */ | variable GREP_COLOR. The default is to print red. */ | ||||
static const char *grep_color = "01;31"; | static const char *grep_color = "01;31"; | ||||
▲ Show 20 Lines • Show All 1,580 Lines • ▼ Show 20 Lines | break; | ||||
color_option = 0; | color_option = 0; | ||||
else if(!strcasecmp(optarg, "auto") || !strcasecmp(optarg, "tty") || | else if(!strcasecmp(optarg, "auto") || !strcasecmp(optarg, "tty") || | ||||
!strcasecmp(optarg, "if-tty")) | !strcasecmp(optarg, "if-tty")) | ||||
color_option = 2; | color_option = 2; | ||||
else | else | ||||
show_help = 1; | show_help = 1; | ||||
} else | } else | ||||
color_option = 2; | color_option = 2; | ||||
if(color_option == 2) { | |||||
if(isatty(STDOUT_FILENO) && getenv("TERM") && | |||||
strcmp(getenv("TERM"), "dumb")) | |||||
color_option = 1; | |||||
else | |||||
color_option = 0; | |||||
} | |||||
break; | break; | ||||
case EXCLUDE_OPTION: | case EXCLUDE_OPTION: | ||||
if (!excluded_patterns) | if (!excluded_patterns) | ||||
excluded_patterns = new_exclude (); | excluded_patterns = new_exclude (); | ||||
add_exclude (excluded_patterns, optarg); | add_exclude (excluded_patterns, optarg); | ||||
break; | break; | ||||
Show All 26 Lines | #endif | ||||
break; | break; | ||||
default: | default: | ||||
usage (2); | usage (2); | ||||
break; | break; | ||||
} | } | ||||
if(color_option == 2) { | |||||
0mp: You've got style(9) issues. | |||||
0mpUnsubmitted Not Done Inline ActionsActually, this is not really style(9)-compliant file as I look at it now... Why this if statement had to be moved to a different place? 0mp: Actually, this is not really style(9)-compliant file as I look at it now...
Why this if… | |||||
if(isatty(STDOUT_FILENO) && getenv("TERM") && | |||||
strcmp(getenv("TERM"), "dumb")) | |||||
color_option = 1; | |||||
else | |||||
color_option = 0; | |||||
} | |||||
/* POSIX.2 says that -q overrides -l, which in turn overrides the | /* POSIX.2 says that -q overrides -l, which in turn overrides the | ||||
other output options. */ | other output options. */ | ||||
if (exit_on_match) | if (exit_on_match) | ||||
list_files = 0; | list_files = 0; | ||||
if (exit_on_match | list_files) | if (exit_on_match | list_files) | ||||
{ | { | ||||
count_matches = 0; | count_matches = 0; | ||||
done_on_match = 1; | done_on_match = 1; | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |
You've got style(9) issues.