/************************************************************************* * * (c) Copyright 1992,1993,1994 by G & A Technical Software, Inc., * 28 Research Drive, Hampton, Virginia, 23666. * * All Rights Reserved. No part of this software or publication may be * reproduced, stored in a retrieval system, or transmitted, in any form * or by any means, electronic, mechanical, photocopying, recording, or * otherwise without the prior written permission of G & A Technical * Software, Inc. * ************************************************************************* * * Filename: s3_main.c * * Purpose: Main program for s3exec * * Author: John Burton * * Date: 5/31/94 * ************************************************************************* * * Modification History: * * $Log: s3_main.c,v $ * Revision 2.1 1994/07/08 17:52:23 jcburt * Updated typedefs, defines and function protypes to allow recursive * parsing of pct files. Enabled use of sub-PDT files and scoping of * datasets. Datasets used in a pct must be defined either in the * associated pdt file or the pdt file associated with the direct * ancestors of the current pct file. * * DataSet functions and subroutines now have an additional parameter * passed to them, indicating the number of parameters passed in the * dataset list, i.e. was: function(DataSet **dl) * now: function(int nargs, DataSet **dl) * Parameters passed to the dataset routines from the PCT level are all * still contained in the dataset list, nargs is during the function or * subroutine call from s3_exec_enode * * Revision 2.0.0.1 1994/06/28 18:48:27 jcburt * S3 Version 2.0 Initial Source * * * Revision 1.5 1993/09/09 17:54:54 jcburt * Initial Production Release of s3 * * Revision 1.2 1992/12/01 18:22:05 jcburt * added rcsid character string * ************************************************************************* * * Revision Control Information: * *************************************************************************/ static char rcsid[] = "$Id: s3_main.c,v 2.1 1994/07/08 17:52:23 jcburt Exp $"; static char rcsrev[] = "$Revision: 2.1 $"; /************************************************************************* * * Include Files * *************************************************************************/ #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include "s3_machdep.h" #include #include /************************************************************************* * * Defines and Macros * *************************************************************************/ #define FACTOR CLOCKS_PER_SEC /************************************************************************* * * Global Variables * *************************************************************************/ int convert = FALSE; /************************************************************************* * * Module: usage * * Description: Describes the command line interface if the program * is called improperly * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ void usage() { fprintf(fperr,"Usage: %s [-bdefnpsv] [-c controlfile] [infile [outfile]] \n",progname); fprintf(fperr," -b : perform array bounds checking\n"); fprintf(fperr," -c : read control file data from controlfile\n"); fprintf(fperr," -d : generate debugging output\n"); fprintf(fperr," -e : generate an executable link for the S3 program\n"); fprintf(fperr," -f : generate F77 source for PDT/PCT files (under construction)\n"); fprintf(fperr," -n : do not recompile/relink modules\n"); fprintf(fperr," -On : Compile with Optimize switch set to level n\n"); fprintf(fperr," -p : generate execution profile\n"); fprintf(fperr," -s : creates statically linked executable\n"); fprintf(fperr," -q : quiet, all output is piped to outfile or /dev/null if outfile is not specified\n"); fprintf(fperr," -v : generate verbose operation description\n"); fprintf(fperr," infile : input filename (default stdin)\n"); fprintf(fperr," outfile : output filename (default stdout)\n"); } /************************************************************************* * * Module: main * * Description: Main driver routine for s3exec * * Syntax: * * Inputs: * * Outputs: * * Returns: * * Modules Called: * *************************************************************************/ main(argc, argv) int argc; char **argv; { extern int optind; extern char *optarg; PCT_struct *pct; PDT_struct *pdt; EMT_struct *emt; int Static = FALSE; int profile = FALSE; int setup = FALSE; int quiet = FALSE; int runonly = FALSE; int pid; int c,i,wcount; char buff[128]; char *basename; char *tempname,*sp = NULL; char *confilename = NULL; char *outfile = NULL; ST_entry *temp; Pnode *pptr; char instr[32]; double t1,t2; /*------------------------------------------------------------------------*/ /*-- Parse the command line --*/ /*------------------------------------------------------------------------*/ /* mallopt(M_MXFAST,0); */ fpout_inc = stdout; fpout_main = stdout; fpout_blk_data = stdout; fpout = stdout; fpin = stdin; fperr = stderr; sp = strrchr(argv[0],'/'); if(sp == NULL) tempname = strsave(argv[0]); else tempname = strsave(&sp[1]); while((c = getopt(argc, argv, "bc:defnO:psqv")) != EOF) switch(c) { case 'b': bounds = TRUE; Fflags = (Fflags == NULL) ? strsave(BOUNDS_flags) : strsave2(Fflags,strsave2(" ",BOUNDS_flags)); break; case 'c': confilename = strsave(optarg); Global_Control_File = TRUE; break; case 'd': Compile_Method = DEBUG; Cflags = (Cflags == NULL) ? strsave(CC_DEBUG) : strsave2(Cflags,strsave2(" ",CC_DEBUG)); Fflags = (Fflags == NULL) ? strsave(FC_DEBUG) : strsave2(Fflags,strsave2(" ",FC_DEBUG)); break; case 'e': setup = TRUE; break; case 'f': convert = TRUE; break; case 'n': Check_Modules = FALSE; break; case 'O': OPT_flags = strsave2("-O",optarg); Cflags = (Cflags == NULL) ? strsave(CC_OPT) : strsave2(Cflags,strsave2(" ",CC_OPT)); Fflags = (Fflags == NULL) ? strsave(FC_OPT) : strsave2(Fflags,strsave2(" ",FC_OPT)); break; case 'p': profile = TRUE; Cflags = (Cflags == NULL) ? strsave(PROF_flags) : strsave2(Cflags,strsave2(" ",PROF_flags)); Fflags = (Fflags == NULL) ? strsave(PROF_flags) : strsave2(Fflags,strsave2(" ",PROF_flags)); break; case 's': Link_Method = NORMAL; break; case 'q': quiet = TRUE; break; case 'v': verbose = TRUE; logfile = strsave(tempname); logfile = stringcat(logfile,".log"); break; case '?': usage(); exit(1); } if(Cflags == NULL) Cflags = strsave(OPT_flags); if(Fflags == NULL) Fflags = strsave(OPT_flags); if(strcmp(tempname,"s3exec") != 0) { runonly = TRUE; basename = strsave(tempname); Check_Modules = !Check_Modules; if(optind < argc) outfile = strsave(argv[optind]); } else if(optind < argc) { basename = strsave(argv[optind]); optind++; if(optind < argc) outfile = strsave(argv[optind]); } else s3_error(LOC,"No S3 file specified"); if(logfile == NULL) logfile = strsave("/dev/null"); if(outfile != NULL) { if((fpout = fopen(outfile,"w")) == NULL) s3_error(SYS,"Unable to open output file %s",outfile); fperr = fpout; if(quiet) { dup2(fileno(fpout),fileno(stdout)); dup2(fileno(fperr),fileno(stderr)); } } else if(quiet) { if((fpout = fopen("/dev/null","w")) == NULL) s3_error(SYS,"Unable to open /dev/null for output"); fperr = fpout; dup2(fileno(fpout),fileno(stdout)); dup2(fileno(fperr),fileno(stderr)); } /*------------------------------------------------------------------------*/ /*-- Read the data file and do your thing --*/ /*------------------------------------------------------------------------*/ /* setbuf(stdin,(char *)NULL); */ pid = getppid(); t1 = (double) clock(); s3_dml_init(argv[0]); s3_init_s3executive(basename); s3_init_parser_emt(basename); if((emt = s3_parse_emt_file(emtfilename)) == NULL) s3_error(LOC,"Too many parse warnings occurred for %s - execution aborted",emtfilename); if((Link_Method == DYNAMIC)&&(!convert)) { s3_setup_shared_library(basename); if(!runonly) s3_compile_dynamic_modules(emt); s3_load_dynamic_modules(emt); } if((pdt = s3_parse_pdt_file(pdtfilename)) == NULL) s3_error(LOC,"Too many parse warnings occurred for %s - execution aborted",pdtfilename); if((pct = s3_parse_pct_file(pctfilename,Static)) == NULL) s3_error(LOC,"Too many parse warnings occurred for %s - execution aborted",pctfilename); if(Global_Control_File) { if(s3_parse_control_file(confilename)) s3_error(LOC,"Too many parse warnings occurred for %s - execution aborted",confilename); Global_Control_File = FALSE; } if(setup) { sprintf(buff,"ln -s /usr/local/bin/s3exec %s",basename); system(buff); } else if(convert) { s3tof77(pct,pdt,basename); } else if(Link_Method == NORMAL) { s3_setup_static(emt,pct,basename); } else { t2 = (double) clock(); temp = s3_add_symbol("init_pcp"); temp->ss.type = OTHER; temp->ss.count = 1; temp->ss.qtime = ((t2-t1)/FACTOR); /* if(debug) s3_list_symbol_table(fperr); */ t1 = (double) clock(); i = s3_exec_pnode((Pnode *)(pct->main_pct)); t2 = (double) clock(); temp = s3_get_symbol(basename); temp->ss.count += 1; temp->ss.qtime += ((t2-t1)/FACTOR); if(Link_Method == DYNAMIC) s3_unload_dynamic_modules(emt); if(profile) s3_print_exe_profile(fpout); } exit(0); }