//----------------------------------------------------------------- // This file, user-calls.i, serves as the main program for your // application. Treat it as if it were the file main.c. // Put all your global variables here. Put all your function // calls inside the user_calls function at the indicated position. //----------------------------------------------------------------- #include "comppp.h" #include #include char *tmpfname() { char *r; static i = 1000000; r = new char[42]; sprintf(r,"notmod/tmp/compp-%d",i); i++; return r; } void out_of_store() { cerr << "Demeter: operator new failed, out of store.\n"; exit( 1 ); } #ifndef __GNUC__ extern PF set_new_handler( PF ); #else extern "C" PF set_new_handler( PF ); #endif extern int _demeter_hash(const char* classname); int greeting = _demeter_hash("Greeting"); char *GEN_DIR = getenv("GEN_DIR"); extern void transform(Vertex_Comma_list*,FILE*,FILE*,char*,char*); int nosuffixFlag = 0; int main( int argc, char *argv[],char *envp[] ) //----------------------------------------------------------------- // To show you an example of Demeter's generic function library, // some of the generic functions are included below. To program // for your own needs you can delete all or parts of this code. //----------------------------------------------------------------- { enum input_kind { single_file, multiple_files }; FILE *sourcefile,*targetfile; char *sourcefilename = ""; char *modulename, *cdgraph, targetfilename[256]; int i,j; input_kind flag = single_file; int parsed = 0; set_new_handler( &out_of_store ); if (argc > 1) { if (strcmp(argv[1],"nosuffix") == 0) { argv++; argc--; nosuffixFlag = 1; } } switch (argc) { case 1: case 2: abort_with_help(); break; case 3: cdgraph = argv[1]; modulename = argv[2]; sourcefile = stdin; break; case 4: cdgraph = argv[1]; modulename = argv[2]; break; case 5: abort_with_help(); break; default: cdgraph = argv[1]; modulename = argv[2]; if (strcmp(argv[3],"-p")!=0) abort_with_help(); flag = multiple_files; } Demeter_in *iDemeter_in; Vertex_Comma_list * classtable; if (flag == single_file) { iDemeter_in = new Demeter_in(); iDemeter_in =(Demeter_in*)iDemeter_in->g_parse(cdgraph); classtable = new Vertex_Comma_list(); iDemeter_in->addclasses(classtable); sourcefile = xfopen(argv[3],"r"); sourcefilename = argv[3]; transform(classtable,sourcefile,stdout,modulename,sourcefilename); } else { i = 5; struct stat stbuf1; struct stat stbuf2; while (i < argc) { sourcefilename = argv[i]; //strip basename j = strlen(sourcefilename)-1; while ( (j != 0) && (sourcefilename[j] != '/') ) j--; if (sourcefilename[j] == '/') j++; sprintf(targetfilename,"%s/%s",argv[4],sourcefilename+j); if (stat(sourcefilename,&stbuf1) == 0) { if (stat(targetfilename,&stbuf2) == 0) { if ( (stbuf1.st_mtime <= stbuf2.st_mtime) && (stbuf1.st_ctime <= stbuf2.st_ctime)) { i++; continue; } } else { if (errno != ENOENT) { cerr << toolname << ": unable to open " << targetfilename << endl; perror(targetfilename); exit(1); } } } else { cerr << toolname << ": unable to open " << sourcefilename << endl; perror(sourcefilename); exit(1); } char * tmp = tmpfname(); sourcefile = xfopen(sourcefilename,"r"); targetfile = xfopen(tmp,"w"); if (parsed==0) { iDemeter_in = new Demeter_in(); if( (Demeter_in*)iDemeter_in->g_parse(cdgraph) == NULL ) { cout << "comp-pp: error in g_parse" << endl; exit(1); } classtable = new Vertex_Comma_list(); iDemeter_in->addclasses(classtable); parsed = 1; } transform(classtable,sourcefile,targetfile,modulename,sourcefilename); fclose(targetfile); fclose(sourcefile); mv_if_change(mv_interactive,tmp,targetfilename); free(tmp); i++; } } return (0); }