int fm_search(char *pattern, int pat_len, char *infile_name) { void fatal_error(char *); void read_prologue(bwi_out *); bwi_out s_main; bwi_out *s = &s_main; int num_occ,sp,ep; Report_occ = 0; Locate_occ = 0; Display_occ = 0; Oneline_report = 0; Type_mem_ops = EXT_MEM; Cache_percentage = 0; if (check_bwi_suffix(infile_name) == 0) fatal_error("The file name must end with .bwi -main-\n"); my_open_file(infile_name); init_bwi_cache(); read_prologue(s); num_occ = bwsearch(s, pattern, pat_len, &sp, &ep); my_fclose(Infile); return num_occ; }
static void load_xcode(void) { FILE *fp; int xcode_version; int filemode; initialize_colorize(); fprintf(stderr, "LOADING: %s\n", mudconf.hcode_db); fp = my_open_file(mudconf.hcode_db, "rb", &filemode); if (!fp) { fprintf(stderr, "ERROR: %s not found.\n", mudconf.hcode_db); return; } fread(&xcode_version, sizeof(xcode_version), 1, fp); if (xcode_version != XCODE_MAGIC) { fprintf(stderr, "LOADING: %s (skipped xcodetree - version difference: 0x%08X vs 0x%08X)\n", mudconf.hcode_db, xcode_version, XCODE_MAGIC); return; } if (!load_btdb()) { /* TODO: We could be more graceful about this... */ exit(EXIT_FAILURE); } rb_walk(xcode_tree, WALK_INORDER, load_update1, fp); rb_walk(xcode_tree, WALK_INORDER, load_update2, NULL); rb_walk(xcode_tree, WALK_INORDER, load_update3, NULL); rb_walk(xcode_tree, WALK_INORDER, load_update4, NULL); /* Read in autopilot data */ rb_walk(xcode_tree, WALK_INORDER, load_autopilot_data, NULL); if (!feof(fp)) loadrepairs(fp); my_close_file(fp, &filemode); fprintf(stderr, "LOADING: %s (done)\n", mudconf.hcode_db); #ifdef BT_ADVANCED_ECON load_econdb(); #endif heartbeat_init(); }
char *fm_geturl(int url_id,char *infile_name) { char *url_txt; void get_url_byid(int Url_id, char **url); Type_mem_ops = EXT_MEM; Cache_percentage = 0; Report_position=0; if (check_bwi_suffix(infile_name) == 0) fatal_error("The file name must end with .bwi -main-\n"); my_open_file(infile_name); init_bwi_cache(); get_url_byid(url_id, &url_txt); my_fclose(Infile); return(url_txt); }
int fm_getid(char *url,char *infile_name) { int url_id; void get_id_byurl(char *url, int *Url_id); Type_mem_ops = EXT_MEM; Cache_percentage = 0; Report_position=0; if (check_bwi_suffix(infile_name) == 0) fatal_error("The file name must end with .bwi -main-\n"); my_open_file(infile_name); init_bwi_cache(); get_id_byurl(url, &url_id); my_fclose(Infile); return(url_id); }
void SaveSpecialObjects(int i) { FILE *fp; int filemode; int xcode_version = XCODE_MAGIC; char target[LBUF_SIZE]; switch (i) { case DUMP_KILLED: sprintf(target, "%s.KILLED", mudconf.hcode_db); break; case DUMP_CRASHED: sprintf(target, "%s.CRASHED", mudconf.hcode_db); break; default: /* RESTART / normal */ sprintf(target, "%s.tmp", mudconf.hcode_db); break; } if (!save_btdb()) { /* TODO: We could be more graceful about this... */ exit(EXIT_FAILURE); } fp = my_open_file(target, "wb", &filemode); if(!fp) { log_perror("SAV", "FAIL", "Opening new hcode-save file", target); SendDB("ERROR occured during opening of new hcode-savefile."); return; } fwrite(&xcode_version, sizeof(xcode_version), 1, fp); /* Then, check each xcode thing for stuff */ rb_walk(xcode_tree, WALK_INORDER, save_maps_func, fp); /* Save autopilot data */ /* GoThruTree(xcode_tree, save_autopilot_data); */ saverepairs(fp); my_close_file(fp, &filemode); if (i == DUMP_RESTART || i == DUMP_NORMAL) { if (rename(mudconf.hcode_db, tprintf("%s.prev", mudconf.hcode_db)) < 0) { log_perror("SAV", "FAIL", "Renaming old hcode-save file ", target); SendDB("ERROR occured during renaming of old hcode save-file."); } if (rename(target, mudconf.hcode_db) < 0) { log_perror("SAV", "FAIL", "Renaming new hcode-save file ", target); SendDB("ERROR occured during renaming of new hcode save-file."); } } /* TODO: This used to report the number of entries saved. */ SendDB("Hcode saved."); #ifdef BT_ADVANCED_ECON save_econdb(target, i); #endif }
// --------------------------------------------------- // ----------- Main procedure for the bwsearch tool // --------------------------------------------------- int main(int argc, char *argv[]) { int getopt(int argc, char * const *argv, const char *options); void unbwi(char *); void multi_search(char *); void single_search(char *, int); extern char *optarg; extern int optind, opterr, optopt; char *infile_name, *pattern; int c, num_opt, pattern_from_file, multiple_search,decompress; if(argc<3) { fprintf(stderr, "Usage:\n\t%s ",argv[0]); fprintf(stderr,"-d [-x 1|2|3] [-c perc] bwifile \n"); fprintf(stderr,"to decompress a file, or\n\t%s ",argv[0]); fprintf(stderr,"[-lmoprv][-x 1|2|3][-s len][-c perc] pattern bwifile\n"); fprintf(stderr,"to search a pattern. "); fprintf(stderr,"Valid options are:\n"); fprintf(stderr,"\t-d decompress file\n"); fprintf(stderr,"\t-l locate occurrences\n"); fprintf(stderr,"\t-m multiple search (kills option -osr)\n"); fprintf(stderr,"\t-o one line report (kills options -rls)\n"); fprintf(stderr,"\t-p *pattern* gives the pattern file name\n"); fprintf(stderr,"\t-r report the position of the occurrences\n"); fprintf(stderr,"\t-s display len chars sourronding each occ "); fprintf(stderr,"(kills options -rl)\n"); fprintf(stderr,"\t-v produces a verbose output\n"); fprintf(stderr,"\t-c percentage of cached buckets (default 0)\n"); fprintf(stderr,"\t-x data access: 1=Ext, 2=Mmap, 3=In (default 1)\n\n"); exit(1); } /* ----------------- read options --------------------- */ Verbose=0; infile_name=NULL; num_opt = opterr=0; pattern_from_file = 0; multiple_search = 0; Type_mem_ops = EXT_MEM; Cache_percentage = 0; Report_occ = 0; Locate_occ = 0; Display_occ = 0; Oneline_report = 0; decompress = 0; while ((c=getopt(argc, argv, "dlomrpvs:c:x:")) != -1) { switch (c) { case 'd': decompress=1; case 'v': Verbose++; break; case 'l': Locate_occ=1; break; case 'r': Report_occ=1; break; case 'x': Type_mem_ops = atoi(optarg); break; case 's': Display_occ = atoi(optarg); break; case 'c': Cache_percentage = atof(optarg); break; case 'p': pattern_from_file = 1; break; case 'm': multiple_search = 1; break; case 'o': Oneline_report = 1; break; case '?': fprintf(stderr,"Unknown option: %c -main-\n", optopt); exit(1); } num_opt++; } if(decompress) { /* ------- read filename only ----- */ infile_name = (char *) argv[optind]; pattern = NULL; } else { /* ------- read pattern and filename --------- */ if(optind!=argc-2) { fprintf(stderr,"You must supply a pattern and a filename! -main-\n"); exit(1); } else { pattern = (char *) argv[optind++]; infile_name = (char *) argv[optind]; } if(strlen(pattern)<=0) { fprintf(stderr,"Invalid pattern -main-\n"); exit(1); } } if((Cache_percentage < 0) || (Cache_percentage > 1)) { fprintf(stderr,"Cache percentage must be in [0,1] -main-\n"); exit(1); } if(strlen(infile_name)<=0) { fprintf(stderr,"Invalid file name -main-\n"); exit(1); } if (check_bwi_suffix(infile_name) == 0){ fprintf(stderr,"The file name must end with .bwi -main-\n"); exit(1); } if(Report_occ) Locate_occ = 1; // report implies locate if(Display_occ) Report_occ=Locate_occ = 0; //display text kills report and locate if(Oneline_report) { Display_occ=Report_occ=Locate_occ = 0; } if(Verbose>1) { fprintf(stderr,"\n*****************************************************"); fprintf(stderr,"\n bwsearch Ver 1.0\n"); fprintf(stderr,"Created on %s at %s from %s\n",__DATE__,__TIME__,__FILE__); fprintf(stderr,"*****************************************************\n"); } if(Verbose) { fprintf(stderr,"Command line: "); for(c=0;c<argc;c++) fprintf(stderr,"%s ",argv[c]); fprintf(stderr,"\n"); } /* ----- Hilights the type of memory management ------ */ if(Verbose) switch(Type_mem_ops) { case EXT_MEM: fprintf(stderr,"Memory management: via fopen, fread, getc, ...\n"); break; case EXT_MMAP: fprintf(stderr,"Memory management: via mmap() system call ...\n"); break; case IN_MEM: fprintf(stderr,"Memory management: internal memory ...\n"); break; default: fprintf(stderr,"Error: -- type mem ops --\n"); exit(1); break; } /* --------- open input file ------------- */ my_open_file(infile_name); /* --------- Initialize the Cache System ------------- */ init_bwi_cache(); if(decompress) unbwi(infile_name); else if(multiple_search) multi_search(pattern); else single_search(pattern,pattern_from_file); /* --------- Report Cache Usage Information ------------- */ if (Verbose) report_bwi_cache_usage(); my_fclose(Infile); return 0; }
// ----------------------------------------------- // ----------- main procedure for xml search ----- // ----------------------------------------------- int main(int argc, char *argv[]) { int getopt(int argc, char * const *argv, const char *options); void unbwi(char *); void xml_search(char *, int, char *); extern char *optarg; extern int optind, opterr; char *infile_name, *pattern, *tag; int c, num_opt, pattern_from_file; if(argc<3) { fprintf(stderr, "Usage:\n\t%s ",argv[0]); fprintf(stderr,"[-prv] [-x 1|2|3] [-c perc] [-w 0|1|2|3]"); fprintf(stderr,"[-t tag] pattern bwifile\n"); fprintf(stderr,"Valid options are:\n"); fprintf(stderr,"\t-p *pattern* gives the pattern file name\n"); fprintf(stderr,"\t-r report row # and position of the occurrences\n"); fprintf(stderr,"\t-v produces a verbose output\n"); fprintf(stderr,"\t-C only count occurrences\n"); fprintf(stderr,"\t-c percentage of cached buckets (default 0)\n"); fprintf(stderr,"\t-t enclosing tag (default none)\n"); fprintf(stderr,"\t-w word search: 0=Subs 1=Pfx 2=Sfx "); fprintf(stderr,"3=FullWord (default 0)\n"); fprintf(stderr,"\t-x data access: 1=Ext, 2=Mmap, 3=In (default 1)\n\n"); fprintf(stderr,"The command line was: "); for(c=0;c<argc;c++) fprintf(stderr,"%s ",argv[c]); fprintf(stderr,"\n\n"); exit(1); } /* ----------------- read options --------------------- */ Verbose=0; infile_name=NULL; num_opt = opterr=0; pattern_from_file = 0; Type_mem_ops = EXT_MEM; Cache_percentage = 0; Report_rows = 0; Word_search = 0; Count_only = 0; tag = NULL; while ((c=getopt(argc, argv, "rpvCc:t:w:x:")) != -1) { switch (c) { case 'v': Verbose++; break; case 'r': Report_rows=1; break; case 'x': Type_mem_ops = atoi(optarg); break; case 'w': Word_search = atoi(optarg); break; case 'C': Count_only = 1; break; case 'c': Cache_percentage = atof(optarg); break; case 'p': pattern_from_file = 1; break; case 't': tag = optarg; break; case '?': fprintf(stderr,"Unknown option: %c -main-\n", c); exit(1); } num_opt++; } /* ------- read pattern and filename --------- */ if(optind!=argc-2) { fprintf(stderr,"You must supply a pattern and a filename! -main-\n"); exit(1); } else { pattern = (char *) argv[optind++]; infile_name = (char *) argv[optind]; } if(strlen(pattern)<=0) { fprintf(stderr,"Invalid pattern -main-\n"); exit(1); } if((Cache_percentage < 0) || (Cache_percentage > 1)) { fprintf(stderr,"Cache percentage must be in [0,1] -main-\n"); exit(1); } if(strlen(infile_name)<=0) { fprintf(stderr,"Invalid file name -main-\n"); exit(1); } if (check_bwi_suffix(infile_name) == 0){ fprintf(stderr,"The file name must end with .bwi -main-\n"); exit(1); } if((Word_search<0) || (Word_search>3)) fatal_error("Invalid word search option -main-\n"); if((Type_mem_ops<1) || (Type_mem_ops>3)) fatal_error("Invalid data access option -main-\n"); if(Verbose>1) { fprintf(stderr,"\n*****************************************************"); fprintf(stderr,"\n bwxml Ver 1.0\n"); fprintf(stderr,"Created on %s at %s from %s\n",__DATE__,__TIME__,__FILE__); fprintf(stderr,"*****************************************************\n"); } if(Verbose) { fprintf(stderr,"Command line: "); for(c=0;c<argc;c++) fprintf(stderr,"%s ",argv[c]); fprintf(stderr,"\n"); } /* ----- Hilights the type of memory management ------ */ if(Verbose) switch(Type_mem_ops) { case EXT_MEM: fprintf(stderr,"Memory management: via fopen, fread, getc, ...\n"); break; case EXT_MMAP: fprintf(stderr,"Memory management: via mmap() system call ...\n"); break; case IN_MEM: fprintf(stderr,"Memory management: internal memory ...\n"); break; default: fprintf(stderr,"Error: -- type mem ops --\n"); exit(1); break; } /* --------- open input file ------------- */ my_open_file(infile_name); /* --------- Initialize the Cache System ------------- */ init_bwi_cache(); xml_search(pattern,pattern_from_file,tag); /* --------- Report Cache Usage Information ------------- */ if (Verbose) report_bwi_cache_usage(); my_fclose(Infile); return 0; }