/* * dbin.cc * * C++ utility routines for the dbin package: see dbin.lex * * N.B. The Strings class from the CLHEP library is used. * * Torre Wenaus 04/01/1994 * * Modifications: * 8/21/95 T. Wenaus Mod history started * 8/21/95 TW Strings class removed from dbin generated code. * 8/22/95 TW Strings class removed from dbinc.cc * * November 1995: some clean up to be able to run this code and * standard dbin simulateneously.. * Make some routine & variable static, and change the name of routine * called from the outside, following the Nirvana/mcfio conventions. * */ #include #include #include #include #include "mcf_ntuBldDbinc.h" #include "mcf_ntubld_db.h" static void dbin_debug(); static void lineparse(); static void dbinparse(char* str, char* typ, char* nam, char* var, char* com, char* dim); static void getmembers(long nmems); static void getvalues(); static char* stlower(char*); static void chrcat(char* str, char chr); static char* token(char** str, char* sep); static int testsep(char chr, char *sep); static void mcf_ntubld_interpret(); static char varname[40], objname[40], curstruct[40]; static char chvalues[500], *values, dim[20]; static char tok1[30], tok2[30], tok3[100], com[100]; static char line[1000]; static int n_instance_line_title, n_instance_header, n_instance_variable; static double dvar[100]; static float rvar[100]; static char chvar[100][80]; static char dbpath[FILENAME_MAX+1], filename[FILENAME_MAX+1]; static long nvars, morevalues, n_templates; static long inc_depth, n_instance, debug_on; static int isl; static long n_significant, lnlen=0; static FILE *inFile, *curFile1, *curFile2, *curFile3, *curFile4, *curFile5; static const char *fnamep; static void dbin_getrec(char* fname[],void (*)(void)); static void dbin_getrec(char* fname[],void (*interpret)(void)) { char chr; int istat; long inc_depth_old = 0; const int nchmx = 300; /* ** Start be intializing all these globals, to be able to call this routine ** more than once.. */ inc_depth = 0; n_instance = 0; lnlen = 0; /* extract path from filename */ strcpy(filename,*fname); if (strrchr(filename,'/') != NULL) { strcpy(dbpath,filename); *(strrchr(dbpath,'/')+1)='\0'; } else { dbpath[0] = '\0'; } /* open file */ inFile = fopen(*fname,"r"); if (inFile == NULL) { fprintf(stdout,"Error opening %s\n",*fname); return; } else { if (debug_on) fprintf(stdout,"Opened %s\n",*fname); } /* read a line */ while (inc_depth>=0) { istat=1; while (istat!=EOF) { if (inc_depth > inc_depth_old) /* need to open new file */ { long ifstat; ifstat=1; fnamep = (const char *)filename; if (inc_depth==1) {curFile1 = fopen(fnamep,"r"); if (curFile1==NULL) { fprintf(stdout,"Error opening %s\n",fnamep); ifstat=0; } else { if (debug_on) fprintf(stdout,"Opened %s\n",fnamep); } } if (inc_depth==2) {curFile2 = fopen(fnamep,"r"); if (curFile2==NULL) { fprintf(stdout,"Error opening %s\n",fnamep); ifstat=0; } else { if (debug_on) fprintf(stdout,"Opened %s\n",fnamep); } } if (inc_depth==3) {curFile3 = fopen(fnamep,"r"); if (curFile3==NULL) { fprintf(stdout,"Error opening %s\n",fnamep); ifstat=0; } else { if (debug_on) fprintf(stdout,"Opened %s\n",fnamep); } } if (inc_depth==4) {curFile4 = fopen(fnamep,"r"); if (curFile4==NULL) { fprintf(stdout,"Error opening %s\n",fnamep); ifstat=0; } else { if (debug_on) fprintf(stdout,"Opened %s\n",fnamep); } } if (inc_depth==5) {curFile5 = fopen(fnamep,"r"); if (curFile5==NULL) { fprintf(stdout,"Error opening %s\n",fnamep); ifstat=0; } else { if (debug_on) fprintf(stdout,"Opened %s\n",fnamep); } } } inc_depth_old = inc_depth; if (inc_depth==0) istat=fgetc(inFile); if (inc_depth==1) istat=fgetc(curFile1); if (inc_depth==2) istat=fgetc(curFile2); if (inc_depth==3) istat=fgetc(curFile3); if (inc_depth==4) istat=fgetc(curFile4); if (inc_depth==5) istat=fgetc(curFile5); chr = istat; if (chr == '\t') chr = ' '; /* remove tabs */ if (chr == '\n') { /* line is complete; process it */ if (morevalues == 1) { /* line extension containing values */ /* if final significant char is '/', mark next line as values continuation */ int i; isl=0; for (i=0;i= 'A' && st[i] <= 'Z') st[i] = st[i] + 'a' - 'A'; i++; } return st; } /****************************************************************************/ static char* token(char** str, char* sep) { int i=0; char *if1=NULL, *if2=NULL, *strend = *str + strlen(*str); /* if1 = rel. pointer to 1st token char */ i=0; while (if1 == NULL && i