Skip to content
Snippets Groups Projects
Commit 2bc8a3b7 authored by slevy's avatar slevy
Browse files

Add interactive mode (kiraserver -i) to simplify debugging.

parent 5f4e83f8
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,9 @@
/*
* $Log$
* Revision 1.13 2002/05/12 19:17:59 slevy
* Add interactive mode (kiraserver -i) to simplify debugging.
*
* Revision 1.12 2002/05/12 09:16:22 slevy
* More debugging code.
*
......@@ -276,6 +279,7 @@ struct state {
int port;
int lsock;
int verbose;
int use_stdin;
} curstate = { ST_POINT, 0, 0.0 };
void kira_invalidate( struct dyndata *dd, struct stuff *st ) {
......@@ -554,7 +558,11 @@ speck *add_speck(pdyn *b, pdyn *top, int addr, speck *sp, specklist *sl, worldst
sp->val[SPECK_RINGSIZE] = 0;
sl->nspecks++;
sp = NextSpeck(sp, sl, 1);
if(sl->nspecks < ww->maxstars) {
sp = NextSpeck(sp, sl, 1);
} else {
msg("add_speck overflow! %d >= %d", sl->nspecks, ww->maxstars);
}
return sp;
}
......@@ -954,6 +962,10 @@ int scanopt(char *opt, char *arg) {
curstate.verbose = atoi(arg);
return 1;
case 'i':
curstate.use_stdin = 1;
return 1;
case 'y':
curstate.type = atoi(arg);
return 1;
......@@ -1088,7 +1100,7 @@ int serveonce(char *req, FILE *outf)
for(optp = eqp; isalpha(optp[-1]); optp--)
;
argp = eqp+1;
cp = strchr(argp, '&');
cp = strpbrk(argp, ";&");
if(cp) {
eqp = cp+1;
*cp = '\0';
......@@ -1265,7 +1277,7 @@ main(int argc, char *argv[])
curstate.has_T0 = 0;
curstate.port = 3400;
while((c = getopt(argc, argv, "T:r:t:y:g:m:c:o:p:v:")) != EOF) {
while((c = getopt(argc, argv, "T:r:t:y:g:m:c:o:p:v:i")) != EOF) {
opt[0] = c;
opt[1] = '\0';
if(c == 'y') strcpy(opt, "type");
......@@ -1285,6 +1297,7 @@ Options:\n\
-o treestyle(1 vs 2) (default -o 2 for create_interpolated_tree2)
-p portno listen for HTTP connections on that TCP port\n\
-v verbose(0 vs 1) server logs requests to its own stdout
-i read from stdin, write to stdout (else be a network server)\n\
", progname);
exit(1);
}
......@@ -1292,15 +1305,52 @@ Options:\n\
/* Ignore SIGPIPE signals -- don't crash if a caller disconnects. */
signal(SIGPIPE, SIG_IGN);
msg("Listening on port %d", curstate.port);
int lsock = serverlisten( curstate.port );
if(lsock < 0)
if(curstate.use_stdin) {
msg("Reading %s", argv[optind]);
kira_open( &curstate.st->dyn, curstate.st, argv[optind], curstate.verbose );
int eofs = 0;
char req[512];
fprintf(stderr, "Type ? for help\n");
for(;;) {
fprintf(stderr, "\n>> ");
if(fgets(req, sizeof(req), stdin) == NULL) {
if(++eofs >= 3) break; /* quit if 3 successive EOFs */
continue;
} else {
eofs = 0;
}
if(req[0] == 'q')
break;
if(req[0] == '?' || req[0] == 'h') {
printf("Usage: each line of input yields one starlab lookup,\n\
after applying all options given on that line. Unchanged settings persist.\n\
Options take the form <keyletter>=<value> and may be separated by \"&\" or \";\"\n\
t=<time> simulation time\n\
o=<treestyle> o=1 => create_interpolated_tree, o=2 => ...tree2. Default o=2.\n\
T=<16-numbers> apply 4x4 transformation\n\
speck dump ASCII specks (default just summary information)\n\
q quit\n\
");
} else {
serveonce( req, stdout );
}
}
exit(1);
msg("Reading %s", argv[optind]);
kira_open( &curstate.st->dyn, curstate.st, argv[optind], 0 );
} else {
/* be a network server */
msg("Listening on port %d", curstate.port);
int lsock = serverlisten( curstate.port );
if(lsock < 0)
exit(1);
msg("Ready.");
serverloop( lsock );
msg("Reading %s", argv[optind]);
kira_open( &curstate.st->dyn, curstate.st, argv[optind], curstate.verbose );
msg("Ready.");
serverloop( lsock );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment