| 45 |
|
|
| 46 |
typedef struct option_item { |
typedef struct option_item { |
| 47 |
int one_char; |
int one_char; |
| 48 |
char *long_name; |
const char *long_name; |
| 49 |
char *help_text; |
const char *help_text; |
| 50 |
} option_item; |
} option_item; |
| 51 |
|
|
| 52 |
static option_item optionlist[] = { |
static option_item optionlist[] = { |
| 85 |
|
|
| 86 |
typedef DIR directory_type; |
typedef DIR directory_type; |
| 87 |
|
|
| 88 |
int |
static int |
| 89 |
isdirectory(char *filename) |
isdirectory(char *filename) |
| 90 |
{ |
{ |
| 91 |
struct stat statbuf; |
struct stat statbuf; |
| 94 |
return ((statbuf.st_mode & S_IFMT) == S_IFDIR)? '/' : 0; |
return ((statbuf.st_mode & S_IFMT) == S_IFDIR)? '/' : 0; |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
directory_type * |
static directory_type * |
| 98 |
opendirectory(char *filename) |
opendirectory(char *filename) |
| 99 |
{ |
{ |
| 100 |
return opendir(filename); |
return opendir(filename); |
| 101 |
} |
} |
| 102 |
|
|
| 103 |
char * |
static char * |
| 104 |
readdirectory(directory_type *dir) |
readdirectory(directory_type *dir) |
| 105 |
{ |
{ |
| 106 |
for (;;) |
for (;;) |
| 113 |
return NULL; /* Keep compiler happy; never executed */ |
return NULL; /* Keep compiler happy; never executed */ |
| 114 |
} |
} |
| 115 |
|
|
| 116 |
void |
static void |
| 117 |
closedirectory(directory_type *dir) |
closedirectory(directory_type *dir) |
| 118 |
{ |
{ |
| 119 |
closedir(dir); |
closedir(dir); |
| 320 |
*************************************************/ |
*************************************************/ |
| 321 |
|
|
| 322 |
static int |
static int |
| 323 |
grep_or_recurse(char *filename, BOOL recurse, BOOL show_filenames, |
grep_or_recurse(char *filename, BOOL dir_recurse, BOOL show_filenames, |
| 324 |
BOOL only_one_at_top) |
BOOL only_one_at_top) |
| 325 |
{ |
{ |
| 326 |
int rc = 1; |
int rc = 1; |
| 330 |
/* If the file is a directory and we are recursing, scan each file within it. |
/* If the file is a directory and we are recursing, scan each file within it. |
| 331 |
The scanning code is localized so it can be made system-specific. */ |
The scanning code is localized so it can be made system-specific. */ |
| 332 |
|
|
| 333 |
if ((sep = isdirectory(filename)) != 0 && recurse) |
if ((sep = isdirectory(filename)) != 0 && dir_recurse) |
| 334 |
{ |
{ |
| 335 |
char buffer[1024]; |
char buffer[1024]; |
| 336 |
char *nextfile; |
char *nextfile; |
| 347 |
{ |
{ |
| 348 |
int frc; |
int frc; |
| 349 |
sprintf(buffer, "%.512s%c%.128s", filename, sep, nextfile); |
sprintf(buffer, "%.512s%c%.128s", filename, sep, nextfile); |
| 350 |
frc = grep_or_recurse(buffer, recurse, TRUE, FALSE); |
frc = grep_or_recurse(buffer, dir_recurse, TRUE, FALSE); |
| 351 |
if (frc == 0 && rc == 1) rc = 0; |
if (frc == 0 && rc == 1) rc = 0; |
| 352 |
} |
} |
| 353 |
|
|