* from: main.c,v 2.4 88/09/19 12:55:13 nhall Exp
* rewrite the command line stuff altogether - it's kludged beyond
* belief (as is the rest of the code...)
* DISCLAIMER DISCLAIMER DISCLAIMER
* This code is such a kludge that I don't want to put my name on it.
* It was a ridiculously fast hack and needs rewriting.
* However it does work...
FILE *statefile
, *actfile
, *eventfile_h
, *statevalfile
;
FILE *infile
, *astringfile
;
char *astringfile_name
= DEBUGFILE
;
char *actfile_name
= ACTFILE
;
char *statefile_name
= STATEFILE
;
char *statevalfile_name
= STATEVALFILE
;
char *eventfile_h_name
= EVENTFILE_H
;
char kerneldirname
[50] = "\0";
"usage: %s <transition file> {-D<debug options>} <other options>\n",
fprintf(stderr
, "\t<other options> is any combination of:\n");
fprintf(stderr
, "\t\t-A<action file name>\n");
fprintf(stderr
, "\t\t-E<event file name>\n");
fprintf(stderr
, "\t\t-S<state file name>\n");
fprintf(stderr
, "\t\t-I<initial values file name>\n");
fprintf(stderr
, "\t\t-X<debugging file name>\n");
fprintf(stderr
, "\t\t-K<directory name>\n");
"\tThese names do NOT include the suffices (.c, .h)\n");
"\t\t-D<options> to turn on debug options for xebec itself\n");
fprintf(stderr
, "\t-<nn> for levels of debugging output\n");
fprintf(stderr
, "\t\t<nn> ranges from 1 to 3, 1 is default(everything)\n");
fprintf(stderr
, "\t\t-T to print transitions\n");
fprintf(stderr
, "\t\t-e to print list of combinations of\n");
fprintf(stderr
, "\t\t\t [event,old_state] that produce protocol errors\n");
fprintf(stderr
, "\t\t-g include profiling code in driver\n");
register int lenp
= strlen(proto
);
fprintf(OUT
, "openfiles %s\n",proto
);
junk = Malloc( 2 + lenp + strlen(X/**/_name) );\
(void) sprintf(junk, "%s_", proto);\
X/**/_name = strcat(junk, X/**/_name);\
X = fopen(X/**/_name, "w");\
{ fprintf(stderr,"Open failed: %s\n", "X"); Exit(-1); }\
fprintf(X, "/* %cHeader%c */\n",'$', '$' );\
fprintf(X, "/* %cSource%c */\n",'$', '$' );
"#ifndef _NFILE\n#include <stdio.h>\n#endif _NFILE\n" );
"#ifndef lint\nstatic char *rcsid = \"$Header/**/$\";\n#endif lint\n");
FakeFilename(actfile
, Transfilename
, lineno
);
FakeFilename(actfile
, Transfilename
, lineno
);
fprintf(actfile
, "#include \"%s%s\"\n", kerneldirname
, statevalfile_name
);
FakeFilename(actfile
, Transfilename
, lineno
);
initsets(eventfile_h
, statefile
);
fprintf(stdout
, "including: %s, f=0x%x", f
,f
);
fprintf(stdout
, "derived: %s", f
);
FakeFilename(file
, Transfilename
, lineno
);
FakeFilename(actfile
, Transfilename
, lineno
);
fprintf(actfile
, "\n#include \"%s%s\"\n", kerneldirname
, eventfile_h_name
);
fprintf(actfile
, "\n#include \"%s\"\n", astringfile_name
);
FakeFilename(actfile
, Transfilename
, lineno
);
extern int FirstEventAttribute
;
extern int Nevents
, Nstates
;
fprintf(stdout
, "infile = %s\n",argv
[1]);
infile
= fopen(argv
[1], "r");
if(argc
> 2) while(i
< argc
) {
if(argv
[i
][j
] == '-') j
++;
actfile_name
= Malloc( strlen(name
)+4);
actfile_name
= (char *)strcpy(actfile_name
,name
);
strcat(actfile_name
, ".c");
fprintf(stdout
, "debugging file is %s\n",actfile_name
);
fprintf(OUT
, "option %c file %s\n",c
, &argv
[i
][j
+1]);
(void) strcpy(kerneldirname
,&argv
[i
][++j
]);
astringfile_name
= Malloc( strlen(name
)+4);
astringfile_name
= (char *)strcpy(astringfile_name
,name
);
strcat(astringfile_name
, ".c");
fprintf(OUT
, "option %c, astringfile name %s\n",c
, name
);
eventfile_h_name
= Malloc( strlen(name
)+4);
eventfile_h_name
= (char *)strcpy(eventfile_h_name
,name
);
strcat(eventfile_h_name
, ".h");
fprintf(stdout
, "event files is %s\n",eventfile_h_name
);
statevalfile_name
= Malloc( strlen(name
)+4 );
statevalfile_name
= (char *)strcpy(statevalfile_name
,name
);
strcat(statevalfile_name
, ".init");
fprintf(stdout
, "state table initial values file is %s\n",statevalfile_name
);
statefile_name
= Malloc( strlen(name
)+4);
statefile_name
= (char *)strcpy(statefile_name
,name
);
strcat(statefile_name
, ".h");
fprintf(stdout
, "state file is %s\n",statefile_name
);
debug
['X']= (int)argv
[i
][j
] - (int) '0';
fprintf(OUT
, "value of debug['X'] is 0x%x,%d\n", debug
['X'],
while( c
= argv
[i
][++j
] ) {
fprintf(OUT
, "debugging on");
if(debug
['X']) fprintf(OUT
,
" - overrides any -%d flags used\n", debug
['X']);
fprintf(OUT
, "debug %c\n",c
);
fprintf(stdout
, "Profiling\n");
fprintf(stdout
, "Protocol error table:\n");
fprintf(stdout
, "Transitions:\n");
fprintf(OUT
, "Option K overrides option X\n");
if(strlen(kerneldirname
)<1) {
fprintf(OUT
, "K option: dir name too short!\n");
c
= (char *) Malloc(strlen(kerneldirname
)+6) ;
fprintf(OUT
, "Cannot allocate %d bytes for kerneldirname\n",
strlen(kerneldirname
+ 6) );
fprintf(OUT
, "kerneldirname is %s\n", kerneldirname
);
(void) strcat(c
, kerneldirname
);
strcpy(kerneldirname
, c
);
if( !FirstEventAttribute
)
fprintf(eventfile_h
, "\t}ev_union;\n");
fprintf(eventfile_h
, "};/* end struct event */\n");
fprintf(eventfile_h
, "\n#define %s_NEVENTS 0x%x\n", protocol
, Nevents
);
"\n#define ATTR(X)ev_union.%s/**/X/**/\n",EV_PREFIX
);
(void) fclose(eventfile_h
);
/* {{ */ fprintf(actfile
, "\t}\nreturn 0;\n}\n"); /* end switch; end action() */
fprintf(astringfile
, "};\n");
(void) fclose(astringfile
);
(void) fclose(statevalfile
);
fprintf(statefile
, "\n#define %s_NSTATES 0x%x\n", protocol
, Nstates
);
(void) fclose(statefile
);
fprintf(stdout
, "%d seconds\n", finish
- start
);
fprintf(stderr
, "Error at line %d\n",lineno
);
if(transno
) fprintf(stderr
, "Transition number %d\n",transno
);
(void) fflush(statefile
);
(void) fflush(eventfile_h
);
"*PCB <string> <optional: SYNONYM synonymstring>\n",
"<optional: *INCLUDE {\n<C source>\n} >\n",
"*TRANSITIONS <string>\n",
FakeFilename(outfile
, name
, l
)
fprintf(outfile, "\n\n\n\n# line %d \"%s\"\n", l, name);