/* System: Structured text retrieval tool sgrep. Module: main.c Author: Pekka Kilpeläinen & Jani Jaakkola Description: Command line parsing. All work is done elsewhere pattern matching, evaluation and output Version history: Original version February 1995 by JJ & PK Copyright: University of Helsinki, Dept. of Computer Science */ #include #include #include #include #include #include #include "sgrep.h" #if HAVE_SYS_TIMES_H #include #endif #if HAVE_UNISTD_H #include #endif extern int index_main(SgrepData *,int argc, char **argv); /* * struct for list of expression strings ( or files ) to be executed */ enum ExpressionType { E_FILE,E_TEXT }; struct Expression { enum ExpressionType type; /* If this is a file, or command line */ char *expr; /* Pointer to either filename or expression */ struct Expression *next; }; void show_stats(); void show_times(); int get_options(char *[]); void add_command(char *); SgrepString *read_expressions(SgrepData *sgrep, struct Expression *expression_list); int environ_options(); int run_stream(FileList *files, ParseTreeNode *, struct PHRASE_NODE *p_list); int run_one_by_one(FileList *files, ParseTreeNode *, struct PHRASE_NODE *p_list); void create_constant_lists(); void delete_constant_lists(); /* * Global variables used inside main.c . These are mainly used for storing * information about given options */ SgrepData *sgrep; int have_stats=0; /* Should we show statistics in the end (-T) */ int have_times=0; /* Should we show info about used time in the end (-t) */ int display_count=0; /* Should we display only count of matching regions (-c) */ int no_output=0; /* Should we supress normal output (-q) */ int show_expr=0; /* only show expression, don't execute it (-P) */ /* Which preprocessor to use (-p) */ char *preprocessor=DEFAULT_PREPROCESSOR; int read_sgreprc=1; /* are we going to read sgreprc (-n) */ char *option_space=NULL; /* Allocated if SGREPOPT is used */ /* List of expressions */ struct Expression *last_expression=NULL; int num_file_list_files=0; char *file_list_files[MAX_FILE_LIST_FILES]; #if HAVE_TIMES /* * Struct for time information */ struct time_points { struct tms start; struct tms parsing; struct tms acsearch; struct tms eval; struct tms output; } tps; #else #define CALC_TIME(X) /* Nothing */ #define times(X) /* Nothing */ #endif /* * Struct for options */ struct OptionData { char opt; char *have_param; char *what_does; }; /* * List & description of options * If you add more options, add the descriptions here. Put the implementation * of option in get_options() */ const struct OptionData option_data[]= { { 'a',NULL,"act as a filter" }, #if 0 { 'C',NULL,"display copyright notice" }, #endif { 'c',NULL,"display only count of matching regions" }, { 'D',NULL,"obsolete synonym for -v"}, { 'd',NULL,"don't do concat on result list"}, { 'h',NULL,"help (means this text)" }, { 'i',NULL,"ignore case distinctions in phrases" }, { 'I',NULL,"switches to indexing mode, when given as first option" }, { 'l',NULL,"long output format" }, { 'N',NULL,"don't add trailing newline" }, { 'n',NULL,"don't read $HOME/"USER_SGREPRC" or "SYSTEM_SGREPRC}, { 'P',NULL,"show preprocessed expression, don't execute it." }, { 'q',NULL,"supress normal output" }, /* { 'R',NULL,"recurse into subdirectories" }, */ { 'S',NULL,"stream mode (regions extend across files)"}, { 's',NULL,"short output format" }, { 'T',NULL,"show statistics about what was done" }, #if HAVE_TIMES { 't',NULL,"show information about time spent"}, #endif { 'V',NULL,"display version information" }, { 'v',NULL,"verbose mode. Shows what is going on"}, { 'e',"","execute expression (after preprocessing)" }, { 'f',"","read expression from file" }, { 'F',"","read list of input files from instead of command line" }, { 'g',"