int main(int argc, char **argv) { signed char op; parserinfo_ls_t pinfo; struct option longopts[] = { { "version", 0, NULL, LS_VERSION }, { "help", 0, NULL, LS_HELP }, { "attributes", 0, NULL, LS_ATTRIBUTES }, { 0 } }; progname = "xml-ls"; inputfile = ""; inputline = 0; if( create_parserinfo_ls(&pinfo) ) { while( (op = getopt_long(argc, argv, "a", longopts, NULL)) > -1 ) { set_option_ls(op, optarg, &pinfo); } init_signal_handling(SIGNALS_DEFAULT); init_file_handling(); open_stdout(); puts_stdout(get_headwrap()); puts_stdout(get_open_root()); stdparse(MAXFILES, argv + optind, (stdparserinfo_t *)&pinfo); putc_stdout('\n'); puts_stdout(get_close_root()); puts_stdout(get_footwrap()); close_stdout(); exit_file_handling(); exit_signal_handling(); free_parserinfo_ls(&pinfo); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { signed char op; parserinfo_cut_t pinfo; struct option longopts[] = { { "version", 0, NULL, CUT_VERSION }, { "help", 0, NULL, CUT_HELP }, { 0 } }; progname = "xml-cut"; inputfile = ""; inputline = 0; if( create_parserinfo_cut(&pinfo) ) { while( (op = getopt_long(argc, argv, "c:f:t:", longopts, NULL)) > -1 ) { set_option_cut(op, optarg, &pinfo); } sanity_check(&pinfo); init_signal_handling(SIGNALS_DEFAULT); init_file_handling(); output_wrapper_start(&pinfo); stdparse(MAXFILES, argv + optind, (stdparserinfo_t *)&pinfo); output_wrapper_end(&pinfo); exit_file_handling(); exit_signal_handling(); free_parserinfo_cut(&pinfo); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { regex_count_t k; FILE *input; signed char op; void (*preprocess_fun)(void) = NULL; void (*postprocess_fun)(void) = NULL; progname = "mailinspect"; inputfile = "stdin"; inputline = 0; /* set up internationalization */ if( !setlocale(LC_ALL, "") ) { errormsg(E_WARNING, "could not set locale, internationalization disabled\n"); } else { if( u_options & (1<<U_OPTION_VERBOSE) ) { errormsg(E_WARNING, "international locales not supported\n"); } } #if defined(HAVE_GETPAGESIZE) system_pagesize = getpagesize(); #endif if( system_pagesize == -1 ) { system_pagesize = BUFSIZ; } /* parse the options */ while( (op = getopt(argc, argv, "c:g:G:iIjo:p:s:VzZ")) > -1 ) { switch(op) { case 'j': m_options |= (1<<M_OPTION_CASEN); break; case 'I': u_options |= (1<<U_OPTION_INTERACTIVE); break; case 'V': fprintf(stdout, "mailinspect version %s\n", VERSION); fprintf(stdout, COPYBLURB, "mailinspect"); exit(1); break; case 'z': u_options |= (1<<U_OPTION_REVSORT); break; case 'o': if( !*optarg ) { errormsg(E_ERROR, "you need a number with the -o switch\n"); usage(argv); exit(0); } u_options |= (1<<U_OPTION_SCORES); if( (emails.score_type = atoi(optarg)) >= MAX_SCORES ) { emails.score_type = 0; } break; case 'p': if( !*optarg ) { errormsg(E_ERROR, "you need a number with the -p switch\n"); usage(argv); exit(0); } u_options |= (1<<U_OPTION_FORMAT); if( (emails.index_format = atoi(optarg)) >= MAX_FORMATS ) { emails.index_format = 0; } break; case 'c': if( cat_count >= 1 ) { errormsg(E_WARNING, "maximum reached, category ignored\n"); } else { u_options |= (1<<U_OPTION_CLASSIFY); cat[cat_count].fullfilename = sanitize_path(optarg, ""); if( !*optarg ) { errormsg(E_ERROR, "category needs a name\n"); usage(argv); exit(0); } if( !load_category(&cat[cat_count]) ) { errormsg(E_FATAL, "could not load category %s\n", cat[cat_count].fullfilename); } sanitize_model_options(&m_options, &m_cp, &cat[cat_count]); cat_count++; } break; case 'G': case 'g': tagre_inclex[tagre_count] = (op == 'g') ? TAGRE_INCLUDE : TAGRE_EXCLUDE; if( regcomp(&tagre[tagre_count].regex, optarg, regcomp_flags) != 0 ) { errormsg(E_WARNING, "could not compile regular expression '%s', ignored\n", optarg); } else { tagre[tagre_count].string = optarg; tagre_count++; } break; case 'i': m_options |= (1<<M_OPTION_I18N); #if defined HAVE_LANGINFO_H if( !strcmp(nl_langinfo(CODESET), "UTF-8") ) { errormsg(E_WARNING, "you have UTF-8, so -i is not needed.\n"); } #endif break; case 's': execute_command = optarg; break; default: break; } } /* end option processing */ /* consistency checks */ if( !(u_options & (1<<U_OPTION_CLASSIFY)) ) { errormsg(E_ERROR, "please use -c option\n"); usage(argv); exit(0); } if( !(u_options & (1<<U_OPTION_FORMAT)) ) { if( u_options & (1<<U_OPTION_INTERACTIVE) ) { emails.index_format = 1; } else { emails.index_format = 0; } } if( !(u_options & (1<<U_OPTION_SCORES)) ) { emails.score_type = 0; } if( m_options & (1<<M_OPTION_CASEN) ) { regcomp_flags = REG_EXTENDED|REG_NOSUB; } else { regcomp_flags = REG_EXTENDED|REG_NOSUB|REG_ICASE; } /* setup */ if( m_options & (1<<M_OPTION_CALCENTROPY) ) { init_empirical(&empirical, default_max_tokens, default_max_hash_bits); /* sets cached to zero */ } init_file_handling(); init_emails(); /* now do processing */ if( preprocess_fun ) { (*preprocess_fun)(); } /* now process the first file on the command line */ if( (optind > -1) && *(argv + optind) ) { /* if it's a filename, process it */ if( (input = fopen(argv[optind], "rb")) ) { if( cat[0].model_num_docs == 0 ) { errormsg(E_WARNING, "category %s was not created for emails." " Messages may not be sorted optimally.\n", cat[0].filename); } if( u_options & (1<<U_OPTION_INTERACTIVE) ) { fprintf(stderr, "Reading %s, please wait...\n", argv[optind]); } emails.filename = argv[optind]; read_mbox_and_sort_list(input); fclose(input); if( u_options & (1<<U_OPTION_REVSORT) ) { reverse_sort(); } if( u_options & (1<<U_OPTION_INTERACTIVE) ) { #if defined COMPILE_INTERACTIVE_MODE display_results_interactively(); #else errormsg(E_ERROR, "\n" " sorry, interactive mode not available.\n" " Make sure you have libslang and libreadline\n" " on your system and reconfigure/recompile.\n"); #endif } else { if( execute_command ) { pipe_all_to_command(execute_command); } else { display_results(stdout); } } } else { errormsg(E_ERROR, "couldn't open %s\n", argv[optind]); usage(argv); exit(0); } } else { errormsg(E_ERROR, "no mbox file specified.\n"); usage(argv); exit(0); } if( postprocess_fun ) { (*postprocess_fun)(); } cleanup_file_handling(); for(k = 0; k < regex_count; k++) { regfree(&re[k].regex); } for(k = 0; k < antiregex_count; k++) { regfree(&re[k+MAX_RE].regex); } exit(1); }
int main(int argc, char **argv) { signed char op; parserinfo_mv_t pinfo; filelist_t fl; struct option longopts[] = { { "version", 0, NULL, MV_VERSION }, { "help", 0, NULL, MV_HELP }, { "write-files", 0, NULL, MV_FILES }, { "prepend", 0, NULL, MV_PREPEND }, { "replace", 0, NULL, MV_REPLACE }, { "append", 0, NULL, MV_APPEND }, { 0 } }; progname = "xml-mv"; inputfile = ""; inputline = 0; if( create_parserinfo_mv(&pinfo) ) { while( (op = getopt_long(argc, argv, "", longopts, NULL)) > -1 ) { set_option_mv(op, optarg, &pinfo); } init_signal_handling(SIGNALS_DEFAULT); init_file_handling(); init_tempfile_handling(); init_rollback_handling(); if( !checkflag(pinfo.rcm.flags,RCM_CP_PREPEND|RCM_CP_APPEND) ) { setflag(&pinfo.rcm.flags,RCM_CP_APPEND); setflag(&pinfo.rcm.flags,RCM_CP_REPLACE); } if( create_filelist(&fl, -1, argv + optind, FILELIST_MIN2) ) { pinfo.files = getfiles_filelist(&fl); pinfo.xpaths = getxpaths_filelist(&fl); pinfo.n = getsize_filelist(&fl); if( pinfo.n < 2 ) { errormsg(E_FATAL, "no target specified (try --help).\n"); } pinfo.target = pinfo.files[pinfo.n - 1]; pinfo.tpaths = pinfo.xpaths[pinfo.n - 1]; if( !checkflag(pinfo.rcm.flags,RCM_WRITE_FILES) ) { /* When --write-files is not selected, we cannot write * to the files on the command line. So we use the following * trick to implement moves within the target file (last on command * line): we replace all instances of the target with a common * tempfile, which we can write to as required. The first instance * of the target is not replaced, since it must be read (to copy * its contents into the tempfile). */ substitute_target(&pinfo); } if( stdparse2(pinfo.n - 1, pinfo.files, pinfo.xpaths, &pinfo.std) ) { if( reinit_parserinfo_mv(&pinfo) ) { /* output always to stdout */ setflag(&pinfo.rcm.flags, RCM_CP_OUTPUT); clearflag(&pinfo.rcm.flags, RCM_RM_OUTPUT); stdparse2(1, &pinfo.files[pinfo.n - 1], &pinfo.xpaths[pinfo.n - 1], &pinfo.std); } } free_filelist(&fl); } exit_rollback_handling(); exit_tempfile_handling(); exit_file_handling(); exit_signal_handling(); free_parserinfo_mv(&pinfo); } return EXIT_SUCCESS; }