/************************************************************************* * * (c) Copyright 1992 - 1995 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: * * Purpose: * * Author: John Burton * * Date: 3/24/95 * ************************************************************************* * * Modification History: * * $Log$ * ************************************************************************* * * Revision Control Information: * *************************************************************************/ static char rcsid[] = "$Id$"; static char rcsrev[] = "$Revision$"; /************************************************************************* * * Include Files * *************************************************************************/ #include #include #include "ctype.h" #include "s3_machdep.h" #include "s3_defines.h" #include "s3_typedefs.h" #include "s3_externals.h" #include "s3_globals.h" #include "s3_parser.tab.h" /************************************************************************* * * Global Variables * *************************************************************************/ int is_in(char c, char *s) { int i = 0; while(*s) if(*s++ == c) return 1; return 0; } char *downcase(char *s) { char *temp; temp = s; while(*temp) { *temp = (isupper(*temp)) ? tolower(*temp) : *temp; temp++; } return s; } void write_header(FILE *fp,char *fname) { int i; char *datetimestr; char *username; long now; #ifdef _AIX extern char *getlogin(); #endif time(&now); datetimestr = ctime(&now); username = getlogin(); i = strlen(datetimestr); while((i>=0) && (datetimestr[i] != '\n')) i--; if(i > 0) datetimestr[i] = ' '; fprintf(fp,"/*-------------------------------------------------------------------------------\n"); fprintf(fp," * \n"); fprintf(fp," * \n"); fprintf(fp," * \n"); fprintf(fp," * (c) Copyright 1992 - 1995 by G & A Technical Software, Inc., \n"); fprintf(fp," * 28 Research Drive, Hampton, Virginia, 23666. \n"); fprintf(fp," * \n"); fprintf(fp," * All Rights Reserved. No part of this software or publication may be \n"); fprintf(fp," * reproduced, stored in a retrieval system, or transmitted, in any form \n"); fprintf(fp," * or by any means, electronic, mechanical, photocopying, recording, or \n"); fprintf(fp," * otherwise without the prior written permission of G & A Technical \n"); fprintf(fp," * Software, Inc. \n"); fprintf(fp," * \n"); fprintf(fp," * \n"); fprintf(fp," * \n"); fprintf(fp," * This file was generated by %s \n",progname); fprintf(fp," * \n"); fprintf(fp," * File: %s \n",fname); fprintf(fp," * User: %s \n",username); fprintf(fp," * Date: %s \n",datetimestr); fprintf(fp," * \n"); fprintf(fp," *-------------------------------------------------------------------------------*/\n\n"); fprintf(fp,"#include \n\n"); fprintf(fp,"#define PNODE 0x504E\n"); fprintf(fp,"#define CFUNC 0x4346\n"); fprintf(fp,"#define CSUBR 0x4353\n"); fprintf(fp,"#define DFUNC 0x4446\n"); fprintf(fp,"#define DSUBR 0x4453\n"); fprintf(fp,"#define FFUNC 0x4646\n"); fprintf(fp,"#define FSUBR 0x4653\n"); fprintf(fp,"#define OTHER 0x4F54\n"); fprintf(fp,"#define ENODE 0x4FFF\n"); fprintf(fp,"#define UNDEFINED -1\n\n"); fprintf(fp,"typedef double real;\n\n"); fprintf(fp,"typedef unsigned char byte;\n"); fprintf(fp,"typedef unsigned short word;\n"); fprintf(fp,"typedef unsigned long dword;\n\n"); fprintf(fp,"typedef float real4;\n"); fprintf(fp,"typedef double real8;\n\n"); fprintf(fp,"typedef struct {\n"); fprintf(fp," float r;\n"); fprintf(fp," float i;\n"); fprintf(fp,"} complex;\n\n"); fprintf(fp,"typedef struct {\n"); fprintf(fp," double r;\n"); fprintf(fp," double i;\n"); fprintf(fp,"} dbl_complex;\n\n"); fprintf(fp,"typedef struct {\n"); fprintf(fp,"char *name;\n"); fprintf(fp,"int type;\n"); fprintf(fp,"void (*function)();\n"); fprintf(fp,"int NDS;\n"); fprintf(fp,"} ststr;\n\n"); } void printcproto(FILE *fp, int nds, DataSet **dl) { int i, j; DataSet *ds; int type; int nd; for(i=0;itype; nd = dl[i]->NDIMS; if(i>0) fprintf(fp,", "); switch(type) { case BYTE : case CHAR : fprintf(fp,"char"); break; case STRING : fprintf(fp,"char"); break; case CONST : case INT : fprintf(fp,"int"); break; case REAL : fprintf(fp,"float"); break; case DREAL : fprintf(fp,"double"); break; case COMP : fprintf(fp,"complex"); break; case DCOMP : fprintf(fp,"dbl_complex"); break; } if(nd > 0) { fprintf(fp," "); for(j=0;jtype; nd = dl[i]->NDIMS; if(i>0) fprintf(fp,", "); switch(type) { case BYTE : case CHAR : fprintf(fp,"char"); break; case STRING : strings++; fprintf(fp,"char"); break; case CONST : case INT : fprintf(fp,"int"); break; case REAL : fprintf(fp,"float"); break; case DREAL : fprintf(fp,"double"); break; case COMP : fprintf(fp,"complex"); break; case DCOMP : fprintf(fp,"dbl_complex"); break; } fprintf(fp," *"); } if(strings > 0) fprintf(fp,", ..."); } void s3_outputproto(FILE *fpout, EMT_struct *emt_info, PCT_struct *pct_info) { int i, j, nds, len, ne; int type; ST_entry *ste,*entry; DataSet **dl; char buffo[64],bufft[64]; char *tstr,*outstr; char *suffix,*usuffix; char *ntstr = "NULL"; /*-------------------------------------------------------------------------*/ /*-- output the function prototypes --*/ /*-------------------------------------------------------------------------*/ #ifdef _NO_UNDERSCORE suffix = strsave(" "); usuffix = strsave(" "); #elif _F2C_SUFFIX suffix = strsave("_ "); usuffix = strsave("__ "); #else suffix = strsave("_ "); usuffix = strsave("_ "); #endif for(j=0;jnexe;j++) { entry = emt_info->exe_list[j]; tstr = bufft; outstr = buffo; type = entry->en.type; nds = entry->en.NDS; dl = (DataSet **)entry->en.dslist; tstr = strcpy(tstr,entry->en.name); switch(entry->en.type) { case CSUBR : fprintf(fpout,"extern void %s(",tstr); /* printcproto(fpout,nds,dl); */ fprintf(fpout," );\n"); break; case FSUBR : tstr = downcase(tstr); if(is_in('_',tstr) != 0) tstr = strcat(tstr,usuffix); else tstr = strcat(tstr,suffix); fprintf(fpout,"extern void %s(",tstr); /* printfproto(fpout,nds,dl); */ fprintf(fpout," );\n"); break; case CFUNC : fprintf(fpout,"extern int %s(",tstr); /* printcproto(fpout,nds,dl); */ fprintf(fpout," );\n"); break; case FFUNC : tstr = downcase(tstr); if(is_in('_',tstr) != 0) tstr = strcat(tstr,usuffix); else tstr = strcat(tstr,suffix); fprintf(fpout,"extern int %s(",tstr); /* printfproto(fpout,nds,dl); */ fprintf(fpout," );\n"); break; } } fprintf(fpout,"\n\n\nststr user_routines[] = {\n"); for(j=0;jnpct;j++) { entry = pct_info->pct_list[j]; outstr = strcat(strcpy(outstr,"\""),entry->pn.name); outstr = strcat(outstr,"\""); fprintf(fpout,"%-16s,PNODE, (void (*)())",outstr); fprintf(fpout,"\"%s\",%3d,\n",entry->pn.filename,entry->pn.NDS); } for(j=0;jnexe;j++) { entry = emt_info->exe_list[j]; tstr = bufft; outstr = buffo; tstr = strcpy(tstr,entry->en.name); tstr = downcase(tstr); len = strlen(entry->en.name) + 3; nds = entry->en.NDS; outstr = strcat(strcpy(outstr,"\""),entry->en.name); outstr = strcat(outstr,"\""); switch(entry->en.type) { case CSUBR : fprintf(fpout,"%-16s,CSUBR, (void (*)())",outstr); fprintf(fpout,"%-16s,%3d",tstr,nds); break; case FSUBR : fprintf(fpout,"%-16s,FSUBR, (void (*)())",outstr); if(is_in('_',tstr) != 0) tstr = strcat(tstr,usuffix); else tstr = strcat(tstr,suffix); fprintf(fpout,"%-16s,%3d",tstr,nds); break; case CFUNC : fprintf(fpout,"%-16s,CFUNC, (int (*)())",outstr); fprintf(fpout,"%-16s,%3d",tstr,nds); break; case FFUNC : fprintf(fpout,"%-16s,FFUNC, (int (*)())",outstr); if(is_in('_',tstr) != 0) tstr = strcat(tstr,usuffix); else tstr = strcat(tstr,suffix); fprintf(fpout,"%-16s,%3d",tstr,nds); break; } if(j+1nexe) fprintf(fpout,",\n"); } fprintf(fpout,"\n };\n\n"); } void s3_setup_static(EMT_struct *emt_info, PCT_struct *pct_info,char *basename) { int i,i2; char *main_file, *blk_data_file, *blk_data; FILE *fpmain, *fpinc, *fpblk, *fppct; main_file = strsave2(strsave2("s3_",basename),".c"); fprintf(stderr,"Opening %s for writing\n",main_file); if((fpmain = fopen(main_file,"w")) == NULL) s3_error(SYS,"Cannot open file %s for writing",main_file); write_header(fpmain,main_file); s3_outputproto(fpmain,emt_info,pct_info); fprintf(fpmain,"\n\nint s3_n_user_routines()\n"); fprintf(fpmain," {\n"); fprintf(fpmain,"int temp;\n"); fprintf(fpmain,"\n"); fprintf(fpmain,"temp = sizeof(user_routines)/sizeof(ststr);\n"); fprintf(fpmain,"\n"); fprintf(fpmain,"return temp;\n"); fprintf(fpmain,"}\n\n"); fprintf(fpmain,"int main(int argc, char **argv)\n"); fprintf(fpmain,"{\n"); fprintf(fpmain," extern int s3_static_main(int argc, char **argv);\n"); fprintf(fpmain," return(s3_static_main(argc,argv));\n"); fprintf(fpmain,"}\n"); fclose(fpmain); s3_compile_static(basename); }