2008-06-29 13:08:24 +00:00
|
|
|
#include <stdio.h>
|
2009-04-16 19:03:22 +00:00
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
2009-04-18 21:25:23 +00:00
|
|
|
#include <stdlib.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
#include <string.h>
|
2009-04-18 14:13:13 +00:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
# include <strings.h>
|
|
|
|
#else
|
|
|
|
# define strncasecmp strnicmp
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
2009-04-16 19:03:22 +00:00
|
|
|
#include <assert.h>
|
2009-04-27 19:27:29 +00:00
|
|
|
#include <unistd.h> /* read */
|
|
|
|
#include <sys/stat.h> /* fstat */
|
|
|
|
#include <fcntl.h> /* open */
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
#include "xml.h"
|
|
|
|
|
|
|
|
static const char *_static_root = "/";
|
2008-07-06 11:34:50 +00:00
|
|
|
static const char *_static_element = "*";
|
2008-06-29 13:08:24 +00:00
|
|
|
static unsigned int _fcount = 0;
|
|
|
|
static char **_filenames = 0;
|
|
|
|
static char *_element = 0;
|
|
|
|
static char *_value = 0;
|
|
|
|
static char *_root = 0;
|
|
|
|
static char *_print = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
static char *_attribute = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
static int print_filenames = 0;
|
|
|
|
|
|
|
|
static void free_and_exit(int i);
|
|
|
|
|
2009-04-27 19:27:29 +00:00
|
|
|
#define USE_BUFFER 0
|
2009-04-20 17:05:03 +00:00
|
|
|
#define NODE_NAME_LEN 256
|
|
|
|
#define STRING_LEN 2048
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
#define SHOW_NOVAL(opt) \
|
|
|
|
{ \
|
|
|
|
printf("option '%s' requires a value\n\n", (opt)); \
|
|
|
|
free_and_exit(-1); \
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_help ()
|
|
|
|
{
|
|
|
|
printf("usage: xmlgrep [options] [file ...]\n\n");
|
|
|
|
printf("Options:\n");
|
|
|
|
printf("\t-h\t\tshow this help message\n");
|
2009-04-16 19:03:22 +00:00
|
|
|
printf("\t-a <string>\tprint this attribute as the output\n");
|
2008-06-29 13:08:24 +00:00
|
|
|
printf("\t-e <id>\t\tshow sections that contain this element\n");
|
|
|
|
printf("\t-p <id>\t\tprint this element as the output\n");
|
|
|
|
printf("\t-r <path>\tspecify the XML search root\n");
|
2009-04-16 19:03:22 +00:00
|
|
|
printf("\t-v <string>\tfilter sections that contain this vale\n\n");
|
2008-06-29 13:08:24 +00:00
|
|
|
printf(" To print the contents of the 'type' element of the XML section ");
|
2009-04-16 19:03:22 +00:00
|
|
|
printf("that begins\n at '/printer/output' use the following command:\n\n");
|
|
|
|
printf("\txmlgrep -r /printer/output -p type sample.xml\n\n");
|
|
|
|
printf(" To filter 'output' elements under '/printer' that have attribute");
|
|
|
|
printf(" 'n' set to '1'\n use the following command:\n\n");
|
|
|
|
printf("\txmlgrep -r /printer -p output -a n -v 1 sample.xml\n\n");
|
2008-06-29 13:08:24 +00:00
|
|
|
printf(" To filter out sections that contain the 'driver' element with ");
|
2009-04-16 19:03:22 +00:00
|
|
|
printf("'generic' as\n it's value use the following command:");
|
2008-06-29 13:08:24 +00:00
|
|
|
printf("\n\n\txmlgrep -r /printer/output -e driver -v generic sample.xml");
|
|
|
|
printf("\n\n");
|
|
|
|
free_and_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-16 19:03:22 +00:00
|
|
|
free_and_exit(int ret)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-06-30 12:00:40 +00:00
|
|
|
if (_root && _root != _static_root) free(_root);
|
2008-07-06 11:34:50 +00:00
|
|
|
if (_element && _element != _static_element) free(_element);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (_value) free(_value);
|
|
|
|
if (_print) free(_print);
|
2009-04-16 19:03:22 +00:00
|
|
|
if (_attribute) free(_attribute);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (_filenames)
|
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
unsigned int i;
|
2008-06-29 13:08:24 +00:00
|
|
|
for (i=0; i < _fcount; i++)
|
|
|
|
{
|
|
|
|
if (_filenames[i])
|
|
|
|
{
|
|
|
|
if (print_filenames) printf("%s\n", _filenames[i]);
|
|
|
|
free(_filenames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(_filenames);
|
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
exit(ret);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
parse_option(char **args, int n, int max)
|
|
|
|
{
|
|
|
|
char *opt, *arg = 0;
|
2009-04-16 19:03:22 +00:00
|
|
|
unsigned int alen = 0;
|
|
|
|
unsigned int olen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
opt = args[n];
|
2009-04-16 19:03:22 +00:00
|
|
|
if (strncmp(opt, "--", 2) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
opt++;
|
|
|
|
|
|
|
|
if ((arg = strchr(opt, '=')) != NULL)
|
|
|
|
{
|
|
|
|
*arg++ = 0;
|
|
|
|
}
|
|
|
|
else if (++n < max)
|
|
|
|
{
|
|
|
|
arg = args[n];
|
|
|
|
#if 0
|
|
|
|
if (arg && arg[0] == '-')
|
|
|
|
arg = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
olen = strlen(opt);
|
|
|
|
if (strncmp(opt, "-help", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
show_help();
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
else if (strncmp(opt, "-root", olen) == 0)
|
|
|
|
{
|
|
|
|
if (arg == 0) SHOW_NOVAL(opt);
|
|
|
|
alen = strlen(arg)+1;
|
2009-05-01 08:00:17 +00:00
|
|
|
if (_root) free(_root);
|
2009-04-16 19:03:22 +00:00
|
|
|
_root = malloc(alen);
|
|
|
|
memcpy(_root, arg, alen);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (strncmp(opt, "-element", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
if (arg == 0) SHOW_NOVAL(opt);
|
2009-04-16 19:03:22 +00:00
|
|
|
alen = strlen(arg)+1;
|
2009-05-01 08:00:17 +00:00
|
|
|
if (_element) free(_element);
|
2009-04-16 19:03:22 +00:00
|
|
|
_element = malloc(alen);
|
|
|
|
memcpy(_element, arg, alen);
|
2008-06-29 13:08:24 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
else if (strncmp(opt, "-value", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
if (arg == 0) SHOW_NOVAL(opt);
|
2009-04-16 19:03:22 +00:00
|
|
|
alen = strlen(arg)+1;
|
2009-05-01 08:00:17 +00:00
|
|
|
if (_value) free(_value);
|
2009-04-16 19:03:22 +00:00
|
|
|
_value = malloc(alen);
|
|
|
|
memcpy(_value, arg, alen);
|
2008-06-29 13:08:24 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
else if (strncmp(opt, "-print", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
if (arg == 0) SHOW_NOVAL(opt);
|
2009-04-16 19:03:22 +00:00
|
|
|
alen = strlen(arg)+1;
|
2009-05-01 08:00:17 +00:00
|
|
|
if (_print) free(_print);
|
2009-04-16 19:03:22 +00:00
|
|
|
_print = malloc(alen);
|
|
|
|
memcpy(_print, arg, alen);
|
2008-06-29 13:08:24 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
else if (strncmp(opt, "-attribute", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
if (arg == 0) SHOW_NOVAL(opt);
|
2009-04-16 19:03:22 +00:00
|
|
|
alen = strlen(arg)+1;
|
2009-05-01 08:00:17 +00:00
|
|
|
if (_attribute) free(_attribute);
|
2009-04-16 19:03:22 +00:00
|
|
|
_attribute = malloc(alen);
|
|
|
|
memcpy(_attribute, arg, alen);
|
2008-06-29 13:08:24 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2009-04-16 19:03:22 +00:00
|
|
|
else if (strncmp(opt, "-list-filenames", olen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{ /* undocumented test argument */
|
|
|
|
print_filenames = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (opt[0] == '-')
|
|
|
|
{
|
|
|
|
printf("Unknown option %s\n", opt);
|
|
|
|
free_and_exit(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = _fcount++;
|
|
|
|
if (_filenames == 0)
|
|
|
|
{
|
|
|
|
_filenames = (char **)malloc(sizeof(char*));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char **ptr = (char **)realloc(_filenames, _fcount*sizeof(char*));
|
|
|
|
if (ptr == 0)
|
|
|
|
{
|
|
|
|
printf("Out of memory.\n\n");
|
|
|
|
free_and_exit(-1);
|
|
|
|
}
|
|
|
|
_filenames = ptr;
|
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
alen = strlen(opt)+1;
|
|
|
|
_filenames[pos] = malloc(alen);
|
|
|
|
memcpy(_filenames[pos], opt, alen);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void walk_the_tree(size_t num, void *xid, char *tree)
|
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
unsigned int i, no_elements;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
if (!tree) /* last node from the tree */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
void *xmid = xmlMarkId(xid);
|
|
|
|
if (xmid && _print)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
no_elements = xmlNodeGetNum(xid, _print);
|
2008-07-06 11:34:50 +00:00
|
|
|
for (i=0; i<no_elements; i++)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
if (xmlNodeGetPos(xid, xmid, _print, i) != 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-05-05 12:50:00 +00:00
|
|
|
char *value;
|
2008-07-21 12:32:22 +00:00
|
|
|
|
2009-05-05 12:50:00 +00:00
|
|
|
value = xmlGetString(xmid);
|
|
|
|
if (_value && _attribute && value)
|
2009-04-16 19:03:22 +00:00
|
|
|
{
|
|
|
|
if (!xmlAttributeCompareString(xmid, _attribute, _value))
|
|
|
|
{
|
|
|
|
printf("%s: <%s %s=\"%s\">%s</%s>\n",
|
|
|
|
_filenames[num], _print, _attribute, _value,
|
|
|
|
value, _print);
|
|
|
|
}
|
2009-05-05 12:50:00 +00:00
|
|
|
if (value) free(value);
|
2009-04-16 19:03:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s: <%s>%s</%s>\n",
|
|
|
|
_filenames[num], _print, value, _print);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
free(xmid);
|
|
|
|
}
|
|
|
|
else if (xmid && _value)
|
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
no_elements = xmlNodeGetNum(xmid, _element);
|
2008-07-06 11:34:50 +00:00
|
|
|
for (i=0; i<no_elements; i++)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
if (xmlNodeGetPos(xid, xmid, _element, i) != 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-20 17:05:03 +00:00
|
|
|
char nodename[NODE_NAME_LEN];
|
2008-07-21 12:32:22 +00:00
|
|
|
|
2009-04-20 17:05:03 +00:00
|
|
|
xmlNodeCopyName(xmid, (char *)&nodename, NODE_NAME_LEN);
|
2008-07-21 12:32:22 +00:00
|
|
|
if (xmlCompareString(xmid, _value) == 0)
|
|
|
|
{
|
|
|
|
printf("%s: <%s>%s</%s>\n",
|
|
|
|
_filenames[num], nodename, _value, nodename);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
free(xmid);
|
|
|
|
}
|
|
|
|
else if (xmid && _element)
|
|
|
|
{
|
2009-04-20 17:05:03 +00:00
|
|
|
char parentname[NODE_NAME_LEN];
|
2008-07-21 12:32:22 +00:00
|
|
|
|
2009-04-20 17:05:03 +00:00
|
|
|
xmlNodeCopyName(xid, (char *)&parentname, NODE_NAME_LEN);
|
2008-07-21 12:32:22 +00:00
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
no_elements = xmlNodeGetNum(xmid, _element);
|
2008-07-21 12:32:22 +00:00
|
|
|
for (i=0; i<no_elements; i++)
|
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
if (xmlNodeGetPos(xid, xmid, _element, i) != 0)
|
2008-07-21 12:32:22 +00:00
|
|
|
{
|
2009-04-20 17:05:03 +00:00
|
|
|
char nodename[NODE_NAME_LEN];
|
2008-07-21 12:32:22 +00:00
|
|
|
|
2009-04-20 17:05:03 +00:00
|
|
|
xmlNodeCopyName(xmid, (char *)&nodename, NODE_NAME_LEN);
|
|
|
|
if (!strncasecmp((char*)&nodename, _element, NODE_NAME_LEN))
|
2008-07-21 12:32:22 +00:00
|
|
|
{
|
2009-04-20 17:05:03 +00:00
|
|
|
char value[NODE_NAME_LEN];
|
|
|
|
xmlCopyString(xmid, (char *)&value, NODE_NAME_LEN);
|
2008-07-21 12:32:22 +00:00
|
|
|
printf("%s: <%s> <%s>%s</%s> </%s>\n",
|
|
|
|
_filenames[num], parentname, nodename, value,
|
|
|
|
nodename, parentname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
else printf("Error executing xmlMarkId\n");
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
else if (xid) /* walk the rest of the tree */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
char *elem, *next;
|
2008-06-29 13:08:24 +00:00
|
|
|
void *xmid;
|
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
elem = tree;
|
|
|
|
if (*elem == '/') elem++;
|
|
|
|
|
|
|
|
next = strchr(elem, '/');
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
xmid = xmlMarkId(xid);
|
|
|
|
if (xmid)
|
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
*next++ = 0;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
no_elements = xmlNodeGetNum(xid, elem);
|
2008-07-06 11:34:50 +00:00
|
|
|
for (i=0; i<no_elements; i++)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2009-04-16 19:03:22 +00:00
|
|
|
if (xmlNodeGetPos(xid, xmid, elem, i) != 0)
|
2008-07-06 11:34:50 +00:00
|
|
|
walk_the_tree(num, xmid, next);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 19:03:22 +00:00
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
*--next = '/';
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
free(xmid);
|
|
|
|
}
|
|
|
|
else printf("Error executing xmlMarkId\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void grep_file(unsigned num)
|
|
|
|
{
|
2008-06-30 07:30:02 +00:00
|
|
|
void *xid;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-06-30 07:30:02 +00:00
|
|
|
xid = xmlOpen(_filenames[num]);
|
|
|
|
if (xid)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-06-30 07:30:02 +00:00
|
|
|
void *xrid = xmlMarkId(xid);
|
2009-04-18 21:25:23 +00:00
|
|
|
int r = 0;
|
2009-04-20 16:46:39 +00:00
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
walk_the_tree(num, xrid, _root);
|
2009-04-18 21:25:23 +00:00
|
|
|
|
2009-04-20 16:46:39 +00:00
|
|
|
r = xmlErrorGetNo(xrid, 0);
|
|
|
|
if (r)
|
|
|
|
{
|
2009-04-25 09:54:28 +00:00
|
|
|
size_t n = xmlErrorGetLineNo(xrid, 0);
|
2009-04-27 16:54:46 +00:00
|
|
|
size_t c = xmlErrorGetColumnNo(xrid, 0);
|
2009-04-27 19:27:29 +00:00
|
|
|
const char *s = xmlErrorGetString(xrid, 1); /* clear the error */
|
2009-04-27 16:54:46 +00:00
|
|
|
printf("%s: at line %u, column %u: '%s'\n",_filenames[num], n,c, s);
|
2009-04-20 16:46:39 +00:00
|
|
|
}
|
2009-04-18 21:25:23 +00:00
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
free(xrid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error reading file '%s'\n", _filenames[num]);
|
|
|
|
}
|
|
|
|
|
2008-06-30 07:30:02 +00:00
|
|
|
xmlClose(xid);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 19:27:29 +00:00
|
|
|
|
|
|
|
void grep_file_buffer(unsigned num)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
void *xid, *buf;
|
|
|
|
int fd, res;
|
|
|
|
|
|
|
|
fd = open(_filenames[num], O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
printf("read error opening file '%s'\n", _filenames[num]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fstat(fd, &st);
|
|
|
|
buf = malloc(st.st_size);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
printf("unable to allocate enough memory for reading.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = read(fd, buf, st.st_size);
|
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
printf("unable to read from file '%s'.\n", _filenames[num]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
xid = xmlInitBuffer(buf, st.st_size);
|
|
|
|
if (xid)
|
|
|
|
{
|
|
|
|
void *xrid = xmlMarkId(xid);
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
walk_the_tree(num, xrid, _root);
|
|
|
|
|
|
|
|
r = xmlErrorGetNo(xrid, 0);
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
size_t n = xmlErrorGetLineNo(xrid, 0);
|
|
|
|
size_t c = xmlErrorGetColumnNo(xrid, 0);
|
|
|
|
const char *s = xmlErrorGetString(xrid, 1); /* clear the error */
|
|
|
|
printf("%s: at line %u, column %u: '%s'\n",_filenames[num], n,c, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(xrid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error reading file '%s'\n", _filenames[num]);
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlClose(xid);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2009-04-27 19:27:29 +00:00
|
|
|
unsigned int u;
|
2009-04-20 16:46:39 +00:00
|
|
|
int i;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
show_help();
|
|
|
|
|
|
|
|
for (i=1; i<argc;)
|
|
|
|
{
|
|
|
|
int ret = parse_option(argv, i, argc);
|
|
|
|
i += ret;
|
|
|
|
}
|
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
if (_root == 0) _root = (char *)_static_root;
|
|
|
|
if (_element == 0) _element = (char *)_static_element;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2009-04-27 19:27:29 +00:00
|
|
|
for (u=0; u<_fcount; u++)
|
|
|
|
#if USE_BUFFER
|
|
|
|
grep_file_buffer(u);
|
|
|
|
#else
|
|
|
|
grep_file(u);
|
|
|
|
#endif
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
free_and_exit(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|