From 4e605553de654897c5b127fd0bb3e1b1dfbf5823 Mon Sep 17 00:00:00 2001 From: arno Date: Fri, 5 May 2000 11:07:10 +0000 Subject: [PATCH] * src/sconvert.c src/frontend/circuits.c src/frontend/circuits.h src/frontend/inp.c src/frontend/inpcom.c src/include/fteext.h src/parser/front.c: ANSIfication, removed some empty functions. --- src/frontend/circuits.c | 23 +- src/frontend/circuits.h | 2 - src/frontend/inp.c | 198 +++++----- src/frontend/inpcom.c | 9 +- src/include/fteext.h | 2 - src/parser/front.c | 793 ++++++++++++++++++++-------------------- src/sconvert.c | 302 ++++++++------- 7 files changed, 641 insertions(+), 688 deletions(-) diff --git a/src/frontend/circuits.c b/src/frontend/circuits.c index c0afbffca..b2250af0d 100644 --- a/src/frontend/circuits.c +++ b/src/frontend/circuits.c @@ -3,11 +3,8 @@ Copyright 1990 Regents of the University of California. All rights reserved. Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group **********/ -/* - * - * Routines for dealing with the circuit database. This is currently - * unimplemented. - */ +/* Routines for dealing with the circuit database. This is currently + * unimplemented. */ #include "ngspice.h" #include "cpdefs.h" @@ -19,16 +16,9 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group struct circ *ft_curckt = NULL; /* The default active circuit. */ struct circ *ft_circuits = NULL; -struct subcirc *ft_subcircuits = NULL; /* Now stuff to deal with circuits */ - -void -ft_setccirc(char *name) -{ -} - /* Add a circuit to the circuit list */ void @@ -38,12 +28,3 @@ ft_newcirc(struct circ *ckt) ft_circuits = ckt; return; } - -/* Add a new subcircuit to the subcircuit list */ - - -void -ft_newsubcirc(struct subcirc *sckt) -{ -} - diff --git a/src/frontend/circuits.h b/src/frontend/circuits.h index 842c6ca62..9fad52a8d 100644 --- a/src/frontend/circuits.h +++ b/src/frontend/circuits.h @@ -7,9 +7,7 @@ #define CIRCUITS_H_INCLUDED -void ft_setccirc(char *name); void ft_newcirc(struct circ *ckt); -void ft_newsubcirc(struct subcirc *sckt); #endif diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 5841dbb99..1eff7c211 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -71,8 +71,9 @@ com_listing(wordlist *wl) return; } + static char * -upper(register char *string) +upper(char *string) { static char buf[BSIZE_SP]; @@ -89,11 +90,10 @@ upper(register char *string) } -/* Provide an input listing on the specified file of the given - * card deck. The listing should be of either LS_PHYSICAL or LS_LOGICAL - * or LS_DECK lines as specified by the type parameter. - */ +/* Provide an input listing on the specified file of the given card + * deck. The listing should be of either LS_PHYSICAL or LS_LOGICAL or + * LS_DECK lines as specified by the type parameter. */ void inp_list(FILE *file, struct line *deck, struct line *extras, int type) { @@ -105,9 +105,10 @@ inp_list(FILE *file, struct line *deck, struct line *extras, int type) if (useout) out_init(); - (void) cp_getvar("renumber", VT_BOOL, (char *) &renumber); + cp_getvar("renumber", VT_BOOL, (char *) &renumber); if (type == LS_LOGICAL) { -top1: for (here = deck; here; here = here->li_next) { +top1: + for (here = deck; here; here = here->li_next) { if (renumber) here->li_linenum = i; i++; @@ -119,10 +120,7 @@ top1: for (here = deck; here; here = here->li_next) { sprintf(out_pbuf, "%6d : %s\n", here->li_linenum, upper(here->li_line)); - out_send(out_pbuf); -/* out_printf("%6d : %s\n", - here->li_linenum, - upper(here->li_line)); */ + out_send(out_pbuf); } else fprintf(file, "%6d : %s\n", here->li_linenum, @@ -141,13 +139,13 @@ top1: for (here = deck; here; here = here->li_next) { goto top1; } if (useout) { -/* out_printf("%6d : .end\n", i); */ sprintf(out_pbuf, "%6d : .end\n", i); out_send(out_pbuf); } else fprintf(file, "%6d : .end\n", i); } else if ((type == LS_PHYSICAL) || (type == LS_DECK)) { -top2: for (here = deck; here; here = here->li_next) { +top2: + for (here = deck; here; here = here->li_next) { if ((here->li_actual == NULL) || (here == deck)) { if (renumber) here->li_linenum = i; @@ -158,28 +156,28 @@ top2: for (here = deck; here; here = here->li_next) { if (type == LS_PHYSICAL) { if (useout) { sprintf(out_pbuf, "%6d : %s\n", - here->li_linenum, - upper(here->li_line)); - out_send(out_pbuf); + here->li_linenum, + upper(here->li_line)); + out_send(out_pbuf); } else fprintf(file, "%6d : %s\n", - here->li_linenum, - upper(here->li_line)); + here->li_linenum, + upper(here->li_line)); } else { if (useout) out_printf("%s\n", - upper(here->li_line)); + upper(here->li_line)); else fprintf(file, "%s\n", - upper(here->li_line)); + upper(here->li_line)); } if (here->li_error && (type == LS_PHYSICAL)) { if (useout) out_printf("%s\n", - here->li_error); + here->li_error); else fprintf(file, "%s\n", - here->li_error); + here->li_error); } } else { for (there = here->li_actual; there; @@ -191,13 +189,13 @@ top2: for (here = deck; here; here = here->li_next) { if (type == LS_PHYSICAL) { if (useout) { sprintf(out_pbuf, "%6d : %s\n", - there->li_linenum, - upper(there->li_line)); - out_send(out_pbuf); + there->li_linenum, + upper(there->li_line)); + out_send(out_pbuf); } else fprintf(file, "%6d : %s\n", - there->li_linenum, - upper(there->li_line)); + there->li_linenum, + upper(there->li_line)); } else { if (useout) out_printf("%s\n", @@ -242,12 +240,11 @@ top2: for (here = deck; here; here = here->li_next) { return; } -/* The routine to source a spice input deck. We read the deck in, take out - * the front-end commands, and create a CKT structure. Also we filter out - * the following cards: .save, .width, .four, .print, and .plot, to perform - * after the run is over. - */ +/* The routine to source a spice input deck. We read the deck in, take + * out the front-end commands, and create a CKT structure. Also we + * filter out the following cards: .save, .width, .four, .print, and + * .plot, to perform after the run is over. */ void inp_spsource(FILE *fp, bool comfile, char *filename) { @@ -263,7 +260,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename) inp_readall(fp, &deck); if (!deck) { /* MW. We must close fp always when returning */ - (void) fclose(fp); + fclose(fp); return; } @@ -280,11 +277,10 @@ inp_spsource(FILE *fp, bool comfile, char *filename) } fclose(fp); - /* Now save the IO context and start a new control set. After - * we are done with the source we'll put the old file descriptors - * back. I guess we could use a FILE stack, but since this routine - * is recursive anyway. - */ + /* Now save the IO context and start a new control set. After we + * are done with the source we'll put the old file descriptors + * back. I guess we could use a FILE stack, but since this + * routine is recursive anyway. */ lastin = cp_curin; lastout = cp_curout; lasterr = cp_curerr; @@ -294,13 +290,11 @@ inp_spsource(FILE *fp, bool comfile, char *filename) cp_pushcontrol(); - /* We should now go through the deck and execute front-end + /* We should now go through the deck and execute front-end * commands and remove them. Front-end commands are enclosed by - * the cards .control and .endc, unless comfile - * is TRUE, in which case every line must be a front-end command. - * There are too many problems with matching the first word on - * the line. - */ + * the cards .control and .endc, unless comfile is TRUE, in which + * case every line must be a front-end command. There are too + * many problems with matching the first word on the line. */ ld = deck; if (comfile) { /* This is easy. */ @@ -311,9 +305,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename) if (!ciprefix(".control", dd->li_line) && !ciprefix(".endc", dd->li_line)) { if (dd->li_line[0] == '*') - (void) cp_evloop(dd->li_line + 2); + cp_evloop(dd->li_line + 2); else - (void) cp_evloop(dd->li_line); + cp_evloop(dd->li_line); } tfree(dd->li_line); tfree(dd); @@ -326,7 +320,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename) ld = dd; continue; } - (void) strncpy(name, dd->li_line, BSIZE_SP); + strncpy(name, dd->li_line, BSIZE_SP); for (s = name; *s && isspace(*s); s++) ; for (t = s; *t && !isspace(*t); t++) @@ -338,8 +332,8 @@ inp_spsource(FILE *fp, bool comfile, char *filename) tfree(dd->li_line); tfree(dd); if (commands) - fprintf(cp_err, - "Warning: redundant .control card\n"); + fprintf(cp_err, + "Warning: redundant .control card\n"); else commands = TRUE; } else if (ciprefix(".endc", dd->li_line)) { @@ -366,18 +360,21 @@ inp_spsource(FILE *fp, bool comfile, char *filename) ld->li_next = dd->li_next; tfree(dd); } else if (!*dd->li_line) { - /* So blank lines in com files don't get - * considered as circuits. - */ + /* So blank lines in com files don't get considered as + * circuits. */ ld->li_next = dd->li_next; tfree(dd->li_line); tfree(dd); } else { inp_casefix(s); inp_casefix(dd->li_line); - if (eq(s, ".width") || ciprefix(".four", s) || eq(s, ".plot") - || eq(s, ".print") || eq(s, ".save") - || eq(s, ".op") || eq(s, ".tf")) + if (eq(s, ".width") + || ciprefix(".four", s) + || eq(s, ".plot") + || eq(s, ".print") + || eq(s, ".save") + || eq(s, ".op") + || eq(s, ".tf")) { if (end) { end->wl_next = alloc(struct wordlist); @@ -401,33 +398,26 @@ inp_spsource(FILE *fp, bool comfile, char *filename) /* There is something left after the controls. */ fprintf(cp_out, "\nCircuit: %s\n\n", tt); - /* Now expand subcircuit macros. Note that we have to - * fix the case before we do this but after we - * deal with the commands. - */ - if (!cp_getvar("nosubckt", VT_BOOL, (char *) - &nosubckts)) - deck->li_next = inp_subcktexpand(deck-> - li_next); + /* Now expand subcircuit macros. Note that we have to fix + * the case before we do this but after we deal with the + * commands. */ + if (!cp_getvar("nosubckt", VT_BOOL, (char *) &nosubckts)) + deck->li_next = inp_subcktexpand(deck->li_next); deck->li_actual = realdeck; inp_dodeck(deck, tt, wl_first, FALSE, options, filename); } /* Now that the deck is loaded, do the commands */ if (controls) { - for (end = wl = wl_reverse(controls); wl; - wl = wl->wl_next) - (void) cp_evloop(wl->wl_word); - + for (end = wl = wl_reverse(controls); wl; wl = wl->wl_next) + cp_evloop(wl->wl_word); + wl_free(end); - /* MW. Memory leak fixed here */ - } } /* Now reset everything. Pop the control stack, and fix up the IO - * as it was before the source. - */ + * as it was before the source. */ cp_popcontrol(); cp_curin = lastin; @@ -436,14 +426,14 @@ inp_spsource(FILE *fp, bool comfile, char *filename) return; } -/* This routine is cut in half here because com_rset has to do what follows - * also. End is the list of commands we execute when the job is finished: - * we only bother with this if we might be running in batch mode, since - * it isn't much use otherwise. - */ +/* This routine is cut in half here because com_rset has to do what + * follows also. End is the list of commands we execute when the job + * is finished: we only bother with this if we might be running in + * batch mode, since it isn't much use otherwise. */ void -inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, struct line *options, char *filename) +inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, + struct line *options, char *filename) { struct circ *ct; struct line *dd; @@ -454,8 +444,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, struct line * bool noparse, ii; /* First throw away any old error messages there might be and fix - * the case of the lines. - */ + * the case of the lines. */ for (dd = deck; dd; dd = dd->li_next) { if (dd->li_error) { tfree(dd->li_error); @@ -473,7 +462,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, struct line * } ft_curckt = ct = alloc(struct circ); } - (void) cp_getvar("noparse", VT_BOOL, (char *) &noparse); + cp_getvar("noparse", VT_BOOL, (char *) &noparse); if (!noparse) ckt = if_inpdeck(deck, &tab); else @@ -501,19 +490,18 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, struct line * } while (p && *p); } - /* Add this circuit to the circuit list. If reuse is TRUE then - * use the ft_curckt structure. - */ - + /* Add this circuit to the circuit list. If reuse is TRUE then use + * the ft_curckt structure. */ if (!reuse) { /* Be sure that ci_devices and ci_nodes are valid */ ft_curckt->ci_devices = cp_kwswitch(CT_DEVNAMES, (char *) NULL); - (void) cp_kwswitch(CT_DEVNAMES, ft_curckt->ci_devices); + cp_kwswitch(CT_DEVNAMES, ft_curckt->ci_devices); ft_curckt->ci_nodes = cp_kwswitch(CT_NODENAMES, (char *) NULL); - (void) cp_kwswitch(CT_NODENAMES, ft_curckt->ci_nodes); + cp_kwswitch(CT_NODENAMES, ft_curckt->ci_nodes); ft_newcirc(ct); - /* ft_setccirc(); */ ft_curckt = ct; + /* Assign current circuit */ + ft_curckt = ct; } ct->ci_name = tt; ct->ci_deck = deck; @@ -576,11 +564,10 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, struct line * return; } -/* Edit and re-load the current input deck. Note that if these commands are - * used on a non-unix machine, they will leave spice.tmp junk files lying - * around. - */ +/* Edit and re-load the current input deck. Note that if these + * commands are used on a non-unix machine, they will leave spice.tmp + * junk files lying around. */ void com_edit(wordlist *wl) { @@ -620,8 +607,9 @@ com_edit(wordlist *wl) inp_list(fp, ft_curckt->ci_deck, ft_curckt->ci_options, LS_DECK); fprintf(cp_err, - "Warning: editing a temporary file -- circuit not saved\n"); - (void) fclose(fp); + "Warning: editing a temporary file -- " + "circuit not saved\n"); + fclose(fp); } else if (!ft_curckt) { if (!(fp = fopen(filename, "w"))) { perror(filename); @@ -629,7 +617,7 @@ com_edit(wordlist *wl) return; } fprintf(fp, "SPICE 3 test deck\n"); - (void) fclose(fp); + fclose(fp); } if (!doedit(filename)) { cp_interactive = inter; @@ -643,11 +631,11 @@ com_edit(wordlist *wl) } inp_spsource(fp, FALSE, permfile ? filename : (char *) NULL); - /* (void) fclose(fp); */ + /* fclose(fp); */ /* MW. inp_spsource already closed fp */ if (ft_curckt && !ft_curckt->ci_filename) - (void) unlink(filename); + unlink(filename); } cp_interactive = inter; @@ -656,7 +644,7 @@ com_edit(wordlist *wl) fprintf(cp_out, "run circuit? "); fflush(cp_out); - (void) fgets(buf, BSIZE_SP, stdin); + fgets(buf, BSIZE_SP, stdin); if (buf[0] != 'n') { fprintf(cp_out, "running circuit\n"); com_run(NULL); @@ -677,10 +665,10 @@ doedit(char *filename) if (Def_Editor && *Def_Editor) editor = Def_Editor; else - editor = "/usr/ucb/vi"; + editor = "/usr/bin/vi"; } } - (void) sprintf(buf, "%s %s", editor, filename); + sprintf(buf, "%s %s", editor, filename); return (system(buf) ? FALSE : TRUE); } @@ -710,17 +698,17 @@ com_source(wordlist *wl) while (wl) { if (!(tp = inp_pathopen(wl->wl_word, "r"))) { perror(wl->wl_word); - (void) fclose(fp); + fclose(fp); cp_interactive = TRUE; - (void) unlink(tempfile); + unlink(tempfile); return; } while ((i = fread(buf, 1, BSIZE_SP, tp)) > 0) - (void) fwrite(buf, 1, i, fp); - (void) fclose(tp); + fwrite(buf, 1, i, fp); + fclose(tp); wl = wl->wl_next; } - (void) fseek(fp, (long) 0, 0); + fseek(fp, (long) 0, 0); } else fp = inp_pathopen(wl->wl_word, "r"); if (fp == NULL) { @@ -737,7 +725,7 @@ com_source(wordlist *wl) inp_spsource(fp, FALSE, tempfile ? (char *) NULL : wl->wl_word); cp_interactive = inter; if (tempfile) - (void) unlink(tempfile); + unlink(tempfile); return; } diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index bef3c6203..06739ae31 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -242,8 +242,9 @@ inp_readall(FILE *fp, struct line **data) return; } + void -inp_casefix(register char *string) +inp_casefix(char *string) { #ifdef HAVE_CTYPE_H if (string) @@ -254,8 +255,10 @@ inp_casefix(register char *string) #endif if (*string == '"') { *string++ = ' '; - while (*string && *string != '"') string++; - if (*string == '"') *string = ' '; + while (*string && *string != '"') + string++; + if (*string == '"') + *string = ' '; } if (!isspace(*string) && !isprint(*string)) *string = '_'; diff --git a/src/include/fteext.h b/src/include/fteext.h index d808a2209..8c0489b87 100644 --- a/src/include/fteext.h +++ b/src/include/fteext.h @@ -64,9 +64,7 @@ extern void dbfree( ); extern struct circ *ft_curckt; extern struct circ *ft_circuits; extern struct subcirc *ft_subcircuits; -extern void ft_setccirc(); extern void ft_newcirc(); -extern void ft_newsubcirc(); /* clip.c */ diff --git a/src/parser/front.c b/src/parser/front.c index 8852ec84c..efaea65ba 100644 --- a/src/parser/front.c +++ b/src/parser/front.c @@ -11,10 +11,8 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group #include "cpdefs.h" #include "front.h" -/* Return values from doblock(). I am assuming that nobody will use these - * characters in a string. - */ - +/* Return values from doblock(). I am assuming that nobody will use + * these characters in a string. */ #define NORMAL '\001' #define BROKEN '\002' #define CONTINUED '\003' @@ -22,8 +20,8 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group #define BROKEN_STR "\002" #define CONTINUED_STR "\003" -/* Are we waiting for a command? This lets (void) signal handling be -more clever. */ +/* Are we waiting for a command? This lets signal handling be + * more clever. */ bool cp_cwait = FALSE; char *cp_csep = ";"; @@ -32,18 +30,19 @@ bool cp_dounixcom = FALSE; - -#define CO_UNFILLED 0 -#define CO_STATEMENT 1 -#define CO_WHILE 2 -#define CO_DOWHILE 3 -#define CO_IF 4 -#define CO_FOREACH 5 -#define CO_BREAK 6 -#define CO_CONTINUE 7 -#define CO_LABEL 8 -#define CO_GOTO 9 -#define CO_REPEAT 10 +enum co_command { + CO_UNFILLED, + CO_STATEMENT, + CO_WHILE, + CO_DOWHILE, + CO_IF, + CO_FOREACH, + CO_BREAK, + CO_CONTINUE, + CO_LABEL, + CO_GOTO, + CO_REPEAT +}; /* We have to keep the control structures in a stack, so that when we do * a 'source', we can push a fresh set onto the top... Actually there have @@ -66,13 +65,13 @@ static void dodump(struct control *cc); static int stackp = 0; -/* If there is an argument, give this to cshpar to use instead of stdin. In - * a few places, we call cp_evloop again if it returns 1 and exit (or close - * a file) if it returns 0... Because of the way sources are done, we can't - * allow the control structures to get blown away every time we return -- - * probably every time we type source at the keyboard and every time a - * source returns to keyboard input is ok though -- use ft_controlreset. - */ +/* If there is an argument, give this to cshpar to use instead of + * stdin. In a few places, we call cp_evloop again if it returns 1 and + * exit (or close a file) if it returns 0... Because of the way + * sources are done, we can't allow the control structures to get + * blown away every time we return -- probably every time we type + * source at the keyboard and every time a source returns to keyboard + * input is ok though -- use ft_controlreset. */ static char *noredirect[] = { "stop", NULL } ; /* Only one?? */ @@ -95,225 +94,218 @@ cp_evloop(char *string) cend[stackp]->co_type = CO_UNFILLED; for (;;) { - wlist = getcommand(string); - if (wlist == NULL) { /* End of file or end of user input. */ - if (cend[stackp]->co_parent && !string) { - cp_resetcontrol(); - continue; - } else - return (0); - } - if ((wlist->wl_word == NULL) || (*wlist->wl_word == '\0')) { - /* User just typed return. */ - if (string) - return (1); - else { - cp_event--; - continue; - } - } + wlist = getcommand(string); + if (wlist == NULL) { /* End of file or end of user input. */ + if (cend[stackp]->co_parent && !string) { + cp_resetcontrol(); + continue; + } else + return (0); + } + if ((wlist->wl_word == NULL) || (*wlist->wl_word == '\0')) { + /* User just typed return. */ + if (string) + return (1); + else { + cp_event--; + continue; + } + } - /* Just a check... */ - for (ww = wlist; ww; ww = ww->wl_next) - if (!ww->wl_word) { - fprintf(cp_err, - "cp_evloop: Internal Error: NULL word pointer\n"); - continue; - } + /* Just a check... */ + for (ww = wlist; ww; ww = ww->wl_next) + if (!ww->wl_word) { + fprintf(cp_err, + "cp_evloop: Internal Error: NULL word pointer\n"); + continue; + } - /* Add this to the control structure list. If cend->co_type - * is CO_UNFILLED, the last line was the beginning of a - * block, and this is the unfilled first statement. - */ - if (cend[stackp] && (cend[stackp]->co_type != CO_UNFILLED)) { - cend[stackp]->co_next = alloc(struct control); + /* Add this to the control structure list. If cend->co_type is + * CO_UNFILLED, the last line was the beginning of a block, + * and this is the unfilled first statement. */ + if (cend[stackp] && (cend[stackp]->co_type != CO_UNFILLED)) { + cend[stackp]->co_next = alloc(struct control); ZERO(cend[stackp]->co_next, struct control); - cend[stackp]->co_next->co_prev = cend[stackp]; - cend[stackp]->co_next->co_parent = - cend[stackp]->co_parent; - cend[stackp] = cend[stackp]->co_next; - } else if (!cend[stackp]) { - control[stackp] = cend[stackp] = alloc(struct control); + cend[stackp]->co_next->co_prev = cend[stackp]; + cend[stackp]->co_next->co_parent = + cend[stackp]->co_parent; + cend[stackp] = cend[stackp]->co_next; + } else if (!cend[stackp]) { + control[stackp] = cend[stackp] = alloc(struct control); ZERO(cend[stackp], struct control); } - if (eq(wlist->wl_word, "while")) { - cend[stackp]->co_type = CO_WHILE; - cend[stackp]->co_cond = wlist->wl_next; - if (!cend[stackp]->co_cond) { - fprintf(stderr, - "Error: missing while condition.\n"); - } - newblock; - } else if (eq(wlist->wl_word, "dowhile")) { - cend[stackp]->co_type = CO_DOWHILE; - cend[stackp]->co_cond = wlist->wl_next; - if (!cend[stackp]->co_cond) { - fprintf(stderr, - "Error: missing dowhile condition.\n"); - } - newblock; - } else if (eq(wlist->wl_word, "repeat")) { - cend[stackp]->co_type = CO_REPEAT; - if (!wlist->wl_next) { - cend[stackp]->co_numtimes = -1; - } else { - char *s; - double *dd; - wlist = cp_variablesubst(cp_bquote( - cp_doglob(wl_copy(wlist)))); - s = wlist->wl_next->wl_word; + if (eq(wlist->wl_word, "while")) { + cend[stackp]->co_type = CO_WHILE; + cend[stackp]->co_cond = wlist->wl_next; + if (!cend[stackp]->co_cond) { + fprintf(stderr, + "Error: missing while condition.\n"); + } + newblock; + } else if (eq(wlist->wl_word, "dowhile")) { + cend[stackp]->co_type = CO_DOWHILE; + cend[stackp]->co_cond = wlist->wl_next; + if (!cend[stackp]->co_cond) { + fprintf(stderr, + "Error: missing dowhile condition.\n"); + } + newblock; + } else if (eq(wlist->wl_word, "repeat")) { + cend[stackp]->co_type = CO_REPEAT; + if (!wlist->wl_next) { + cend[stackp]->co_numtimes = -1; + } else { + char *s; + double *dd; + wlist = cp_variablesubst(cp_bquote( + cp_doglob(wl_copy(wlist)))); + s = wlist->wl_next->wl_word; - dd = ft_numparse(&s, FALSE); - if (dd) { - if (*dd < 0) { - fprintf(cp_err, - "Error: can't repeat a negative number of times\n"); - *dd = 0.0; - } - cend[stackp]->co_numtimes = (int) *dd; - } else - fprintf(cp_err, - "Error: bad repeat argument %s\n", - wlist->wl_next->wl_word); - } - newblock; - } else if (eq(wlist->wl_word, "if")) { - cend[stackp]->co_type = CO_IF; - cend[stackp]->co_cond = wlist->wl_next; - if (!cend[stackp]->co_cond) { - fprintf(stderr, - "Error: missing if condition.\n"); - } - newblock; - } else if (eq(wlist->wl_word, "foreach")) { - cend[stackp]->co_type = CO_FOREACH; - if (wlist->wl_next) { - wlist = wlist->wl_next; - cend[stackp]->co_foreachvar = - copy(wlist->wl_word); - wlist = wlist->wl_next; - } else - fprintf(stderr, - "Error: missing foreach variable.\n"); - wlist = cp_doglob(wlist); - cend[stackp]->co_text = wl_copy(wlist); - newblock; - } else if (eq(wlist->wl_word, "label")) { - cend[stackp]->co_type = CO_LABEL; - if (wlist->wl_next) { - cend[stackp]->co_text = wl_copy(wlist->wl_next); - /* I think of everything, don't I? */ - cp_addkword(CT_LABEL, wlist->wl_next->wl_word); - if (wlist->wl_next->wl_next) - fprintf(cp_err, - "Warning: ignored extra junk after label.\n"); - } else - fprintf(stderr, "Error: missing label.\n"); - } else if (eq(wlist->wl_word, "goto")) { - /* Incidentally, this won't work if the values 1 and - * 2 ever get to be valid character pointers -- I - * think it's reasonably safe to assume they aren't... - */ - cend[stackp]->co_type = CO_GOTO; - if (wlist->wl_next) { - cend[stackp]->co_text = wl_copy(wlist->wl_next); - if (wlist->wl_next->wl_next) - fprintf(cp_err, - "Warning: ignored extra junk after goto.\n"); - } else - fprintf(stderr, "Error: missing label.\n"); - } else if (eq(wlist->wl_word, "continue")) { - cend[stackp]->co_type = CO_CONTINUE; - if (wlist->wl_next) { - cend[stackp]->co_numtimes = scannum(wlist-> - wl_next->wl_word); - if (wlist->wl_next->wl_next) - fprintf(cp_err, - "Warning: ignored extra junk after continue %d.\n", - cend[stackp]->co_numtimes); - } else - cend[stackp]->co_numtimes = 1; - } else if (eq(wlist->wl_word, "break")) { - cend[stackp]->co_type = CO_BREAK; - if (wlist->wl_next) { - cend[stackp]->co_numtimes = scannum(wlist-> - wl_next->wl_word); - if (wlist->wl_next->wl_next) - fprintf(cp_err, - "Warning: ignored extra junk after break %d.\n", - cend[stackp]->co_numtimes); - } else - cend[stackp]->co_numtimes = 1; - } else if (eq(wlist->wl_word, "end")) { - /* Throw away this thing. */ - if (!cend[stackp]->co_parent) { - fprintf(stderr, "Error: no block to end.\n"); - cend[stackp]->co_type = CO_UNFILLED; - } else if (cend[stackp]->co_prev) { - cend[stackp]->co_prev->co_next = NULL; - x = cend[stackp]; - cend[stackp] = cend[stackp]->co_parent; - tfree(x); - } else { - x = cend[stackp]; - cend[stackp] = cend[stackp]->co_parent; - cend[stackp]->co_children = NULL; - tfree(x); - } - } else if (eq(wlist->wl_word, "else")) { - if (!cend[stackp]->co_parent || - (cend[stackp]->co_parent->co_type != - CO_IF)) { - fprintf(stderr, "Error: misplaced else.\n"); - cend[stackp]->co_type = CO_UNFILLED; - } else { - if (cend[stackp]->co_prev) - cend[stackp]->co_prev->co_next = NULL; - else - cend[stackp]->co_parent->co_children = - NULL; - cend[stackp]->co_parent->co_elseblock = - cend[stackp]; - cend[stackp]->co_prev = NULL; - } - } else { - cend[stackp]->co_type = CO_STATEMENT; - cend[stackp]->co_text = wlist; - } - if (!cend[stackp]->co_parent) { - x = cend[stackp]; - /* We have to toss this do-while loop in here so - * that gotos at the top level will work. - */ - do { - i = doblock(x, &nn); - switch (*i) { - case NORMAL: - break; - case BROKEN: - fprintf(cp_err, - "Error: break not in loop or too many break levels given\n"); - break; - case CONTINUED: - fprintf(cp_err, - "Error: continue not in loop or too many continue levels given\n"); - break; - default: - x = findlabel(i, - control[stackp]); - if (!x) - fprintf(cp_err, - "Error: label %s not found\n", - i); - } - if (x) - x = x->co_next; - } while (x); - } - if (string) - return (1); /* The return value is irrelevant. */ + dd = ft_numparse(&s, FALSE); + if (dd) { + if (*dd < 0) { + fprintf(cp_err, + "Error: can't repeat a negative number of times\n"); + *dd = 0.0; + } + cend[stackp]->co_numtimes = (int) *dd; + } else + fprintf(cp_err, + "Error: bad repeat argument %s\n", + wlist->wl_next->wl_word); + } + newblock; + } else if (eq(wlist->wl_word, "if")) { + cend[stackp]->co_type = CO_IF; + cend[stackp]->co_cond = wlist->wl_next; + if (!cend[stackp]->co_cond) { + fprintf(stderr, + "Error: missing if condition.\n"); + } + newblock; + } else if (eq(wlist->wl_word, "foreach")) { + cend[stackp]->co_type = CO_FOREACH; + if (wlist->wl_next) { + wlist = wlist->wl_next; + cend[stackp]->co_foreachvar = + copy(wlist->wl_word); + wlist = wlist->wl_next; + } else + fprintf(stderr, + "Error: missing foreach variable.\n"); + wlist = cp_doglob(wlist); + cend[stackp]->co_text = wl_copy(wlist); + newblock; + } else if (eq(wlist->wl_word, "label")) { + cend[stackp]->co_type = CO_LABEL; + if (wlist->wl_next) { + cend[stackp]->co_text = wl_copy(wlist->wl_next); + /* I think of everything, don't I? */ + cp_addkword(CT_LABEL, wlist->wl_next->wl_word); + if (wlist->wl_next->wl_next) + fprintf(cp_err, + "Warning: ignored extra junk after label.\n"); + } else + fprintf(stderr, "Error: missing label.\n"); + } else if (eq(wlist->wl_word, "goto")) { + /* Incidentally, this won't work if the values 1 and 2 ever get + * to be valid character pointers -- I think it's reasonably + * safe to assume they aren't... */ + cend[stackp]->co_type = CO_GOTO; + if (wlist->wl_next) { + cend[stackp]->co_text = wl_copy(wlist->wl_next); + if (wlist->wl_next->wl_next) + fprintf(cp_err, + "Warning: ignored extra junk after goto.\n"); + } else + fprintf(stderr, "Error: missing label.\n"); + } else if (eq(wlist->wl_word, "continue")) { + cend[stackp]->co_type = CO_CONTINUE; + if (wlist->wl_next) { + cend[stackp]->co_numtimes = scannum(wlist-> + wl_next->wl_word); + if (wlist->wl_next->wl_next) + fprintf(cp_err, + "Warning: ignored extra junk after continue %d.\n", + cend[stackp]->co_numtimes); + } else + cend[stackp]->co_numtimes = 1; + } else if (eq(wlist->wl_word, "break")) { + cend[stackp]->co_type = CO_BREAK; + if (wlist->wl_next) { + cend[stackp]->co_numtimes = scannum(wlist-> + wl_next->wl_word); + if (wlist->wl_next->wl_next) + fprintf(cp_err, + "Warning: ignored extra junk after break %d.\n", + cend[stackp]->co_numtimes); + } else + cend[stackp]->co_numtimes = 1; + } else if (eq(wlist->wl_word, "end")) { + /* Throw away this thing. */ + if (!cend[stackp]->co_parent) { + fprintf(stderr, "Error: no block to end.\n"); + cend[stackp]->co_type = CO_UNFILLED; + } else if (cend[stackp]->co_prev) { + cend[stackp]->co_prev->co_next = NULL; + x = cend[stackp]; + cend[stackp] = cend[stackp]->co_parent; + tfree(x); + } else { + x = cend[stackp]; + cend[stackp] = cend[stackp]->co_parent; + cend[stackp]->co_children = NULL; + tfree(x); + } + } else if (eq(wlist->wl_word, "else")) { + if (!cend[stackp]->co_parent || + (cend[stackp]->co_parent->co_type != + CO_IF)) { + fprintf(stderr, "Error: misplaced else.\n"); + cend[stackp]->co_type = CO_UNFILLED; + } else { + if (cend[stackp]->co_prev) + cend[stackp]->co_prev->co_next = NULL; + else + cend[stackp]->co_parent->co_children = NULL; + cend[stackp]->co_parent->co_elseblock = cend[stackp]; + cend[stackp]->co_prev = NULL; + } + } else { + cend[stackp]->co_type = CO_STATEMENT; + cend[stackp]->co_text = wlist; + } + if (!cend[stackp]->co_parent) { + x = cend[stackp]; + /* We have to toss this do-while loop in here so + * that gotos at the top level will work. + */ + do { + i = doblock(x, &nn); + switch (*i) { + case NORMAL: + break; + case BROKEN: + fprintf(cp_err, + "Error: break not in loop or too many break levels given\n"); + break; + case CONTINUED: + fprintf(cp_err, + "Error: continue not in loop or too many continue levels given\n"); + break; + default: + x = findlabel(i, control[stackp]); + if (!x) + fprintf(cp_err, "Error: label %s not found\n", i); + } + if (x) + x = x->co_next; + } while (x); + } + if (string) + return (1); /* The return value is irrelevant. */ } } @@ -340,18 +332,17 @@ doblock(struct control *bl, int *num) int nn; switch (bl->co_type) { - - case CO_WHILE: + case CO_WHILE: while (bl->co_cond && cp_isTRUE(bl->co_cond)) { for (ch = bl->co_children; ch; ch = cn) { cn = ch->co_next; i = doblock(ch, &nn); switch (*i) { - case NORMAL: + case NORMAL: break; - case BROKEN: /* Break. */ + case BROKEN: /* Break. */ if (nn < 2) return (NORMAL_STR); else { @@ -359,7 +350,7 @@ doblock(struct control *bl, int *num) return (BROKEN_STR); } - case CONTINUED: /* Continue. */ + case CONTINUED: /* Continue. */ if (nn < 2) { cn = NULL; break; @@ -368,7 +359,7 @@ doblock(struct control *bl, int *num) return (CONTINUED_STR); } - default: + default: cn = findlabel(i, bl->co_children); if (!cn) return (i); @@ -377,17 +368,17 @@ doblock(struct control *bl, int *num) } break; - case CO_DOWHILE: + case CO_DOWHILE: do { for (ch = bl->co_children; ch; ch = cn) { cn = ch->co_next; i = doblock(ch, &nn); switch (*i) { - case NORMAL: + case NORMAL: break; - case BROKEN: /* Break. */ + case BROKEN: /* Break. */ if (nn < 2) return (NORMAL_STR); else { @@ -395,7 +386,7 @@ doblock(struct control *bl, int *num) return (BROKEN_STR); } - case CONTINUED: /* Continue. */ + case CONTINUED: /* Continue. */ if (nn < 2) { cn = NULL; break; @@ -404,7 +395,7 @@ doblock(struct control *bl, int *num) return (CONTINUED_STR); } - default: + default: cn = findlabel(i, bl->co_children); if (!cn) return (i); @@ -413,9 +404,9 @@ doblock(struct control *bl, int *num) } while (bl->co_cond && cp_isTRUE(bl->co_cond)); break; - case CO_REPEAT: + case CO_REPEAT: while ((bl->co_numtimes > 0) || - (bl->co_numtimes == -1)) { + (bl->co_numtimes == -1)) { if (bl->co_numtimes != -1) bl->co_numtimes--; for (ch = bl->co_children; ch; ch = cn) { @@ -423,10 +414,10 @@ doblock(struct control *bl, int *num) i = doblock(ch, &nn); switch (*i) { - case NORMAL: + case NORMAL: break; - case BROKEN: /* Break. */ + case BROKEN: /* Break. */ if (nn < 2) return (NORMAL_STR); else { @@ -434,7 +425,7 @@ doblock(struct control *bl, int *num) return (BROKEN_STR); } - case CONTINUED: /* Continue. */ + case CONTINUED: /* Continue. */ if (nn < 2) { cn = NULL; break; @@ -443,7 +434,7 @@ doblock(struct control *bl, int *num) return (CONTINUED_STR); } - default: + default: cn = findlabel(i, bl->co_children); if (!cn) return (i); @@ -452,14 +443,14 @@ doblock(struct control *bl, int *num) } break; - case CO_IF: + case CO_IF: if (bl->co_cond && cp_isTRUE(bl->co_cond)) { for (ch = bl->co_children; ch; ch = cn) { cn = ch->co_next; i = doblock(ch, &nn); if (*i > 2) { cn = findlabel(i, - bl->co_children); + bl->co_children); if (!cn) return (i); } else if (*i != NORMAL) { @@ -473,7 +464,7 @@ doblock(struct control *bl, int *num) i = doblock(ch, &nn); if (*i > 2) { cn = findlabel(i, - bl->co_elseblock); + bl->co_elseblock); if (!cn) return (i); } else if (*i != NORMAL) { @@ -484,20 +475,20 @@ doblock(struct control *bl, int *num) } break; - case CO_FOREACH: - for (wl = cp_variablesubst(cp_bquote(cp_doglob(wl_copy(bl-> - co_text)))); wl; wl = wl->wl_next) { - cp_vset(bl->co_foreachvar, VT_STRING, - wl->wl_word); + case CO_FOREACH: + for (wl = cp_variablesubst(cp_bquote(cp_doglob(wl_copy(bl->co_text)))); + wl; + wl = wl->wl_next) { + cp_vset(bl->co_foreachvar, VT_STRING, wl->wl_word); for (ch = bl->co_children; ch; ch = cn) { cn = ch->co_next; i = doblock(ch, &nn); switch (*i) { - case NORMAL: + case NORMAL: break; - case BROKEN: /* Break. */ + case BROKEN: /* Break. */ if (nn < 2) return (NORMAL_STR); else { @@ -505,7 +496,7 @@ doblock(struct control *bl, int *num) return (BROKEN_STR); } - case CONTINUED: /* Continue. */ + case CONTINUED: /* Continue. */ if (nn < 2) { cn = NULL; break; @@ -514,7 +505,7 @@ doblock(struct control *bl, int *num) return (CONTINUED_STR); } - default: + default: cn = findlabel(i, bl->co_children); if (!cn) return (i); @@ -523,7 +514,7 @@ doblock(struct control *bl, int *num) } break; - case CO_BREAK: + case CO_BREAK: if (bl->co_numtimes > 0) { *num = bl->co_numtimes; return (BROKEN_STR); @@ -533,7 +524,7 @@ doblock(struct control *bl, int *num) return (NORMAL_STR); } - case CO_CONTINUE: + case CO_CONTINUE: if (bl->co_numtimes > 0) { *num = bl->co_numtimes; return (CONTINUED_STR); @@ -543,32 +534,34 @@ doblock(struct control *bl, int *num) return (NORMAL_STR); } - case CO_GOTO: + case CO_GOTO: wl = cp_variablesubst(cp_bquote(cp_doglob( - wl_copy(bl->co_text)))); + wl_copy(bl->co_text)))); return (wl->wl_word); - case CO_LABEL: - /* Do nothing. */ - break; + case CO_LABEL: + /* Do nothing. */ + break; - case CO_STATEMENT: + case CO_STATEMENT: docommand(wl_copy(bl->co_text)); break; - case CO_UNFILLED: + case CO_UNFILLED: /* There was probably an error here... */ fprintf(cp_err, "Warning: ignoring previous error\n"); break; - default: + default: fprintf(cp_err, - "doblock: Internal Error: bad block type %d\n", - bl->co_type); + "doblock: Internal Error: bad block type %d\n", + bl->co_type); return (NORMAL_STR); } return (NORMAL_STR); } + + static struct control * findlabel(char *s, struct control *ct) { @@ -580,8 +573,8 @@ findlabel(char *s, struct control *ct) return (ct); } -/* This blows away the control structures... */ +/* This blows away the control structures... */ void cp_resetcontrol(void) { @@ -590,12 +583,12 @@ cp_resetcontrol(void) /* We probably should free the control structures... */ control[0] = cend[0] = NULL; stackp = 0; - (void) cp_kwswitch(CT_LABEL, (char *) NULL); + cp_kwswitch(CT_LABEL, (char *) NULL); return; } -/* Push or pop a new control structure set... */ +/* Push or pop a new control structure set... */ void cp_popcontrol(void) { @@ -608,6 +601,7 @@ cp_popcontrol(void) return; } + void cp_pushcontrol(void) { @@ -624,8 +618,8 @@ cp_pushcontrol(void) return; } -/* And this returns to the top level (for use in the interrupt handlers). */ +/* And this returns to the top level (for use in the interrupt handlers). */ void cp_toplevel(void) { @@ -636,10 +630,9 @@ cp_toplevel(void) return; } -/* Note that we only do io redirection when we get to here - we also - * postpone some other things until now. - */ +/* Note that we only do io redirection when we get to here - we also + * postpone some other things until now. */ static void docommand(register wordlist *wlist) { @@ -653,12 +646,11 @@ docommand(register wordlist *wlist) if (cp_debug) { printf("docommand "); wl_print(wlist, stdout); - (void) putc('\n', stdout); + putc('\n', stdout); } /* Do all the things that used to be done by cshpar when the line - * was read... - */ + * was read... */ wlist = cp_variablesubst(wlist); pwlist(wlist, "After variable substitution"); @@ -711,7 +703,7 @@ docommand(register wordlist *wlist) for (i = 0; cp_coms[i].co_comname; i++) { /* strcmp(cp_coms[i].co_comname, s) ... */ for (t = cp_coms[i].co_comname, r = s; *t && *r; - t++, r++) + t++, r++) if (*t != *r) break; if (!*t && !*r) @@ -727,12 +719,12 @@ docommand(register wordlist *wlist) if (cp_dounixcom && cp_unixcom(wlist)) goto out; fprintf(cp_err,"%s: no such command available in %s\n", - s, cp_program); + s, cp_program); goto out; - /* If it's there but spiceonly, and this is nutmeg, error. */ + /* If it's there but spiceonly, and this is nutmeg, error. */ } else if (!cp_coms[i].co_func && ft_nutmeg && - (cp_coms[i].co_spiceonly)) { + (cp_coms[i].co_spiceonly)) { fprintf(cp_err,"%s: command available only in spice\n", s); goto out; @@ -748,11 +740,11 @@ docommand(register wordlist *wlist) (*command->co_func) (lcom); } else { if (nargs < command->co_minargs) { - if (command->co_argfn) { - (*command->co_argfn) (wlist->wl_next, command); - } else { - fprintf(cp_err, "%s: too few args.\n", s); - } + if (command->co_argfn) { + (*command->co_argfn) (wlist->wl_next, command); + } else { + fprintf(cp_err, "%s: too few args.\n", s); + } } else if (nargs > command->co_maxargs) { fprintf(cp_err, "%s: too many args.\n", s); } else @@ -760,7 +752,7 @@ docommand(register wordlist *wlist) } /* Now fix the pointers and advance wlist. */ -out: wlist->wl_prev = ee; + out: wlist->wl_prev = ee; if (nextc) { if (nextc->wl_prev) nextc->wl_prev->wl_next = nextc; @@ -777,10 +769,9 @@ out: wlist->wl_prev = ee; return; } -/* Get a command. This does all the bookkeeping things like turning - * command completion on and off... - */ +/* Get a command. This does all the bookkeeping things like turning + * command completion on and off... */ static wordlist * getcommand(char *string) { @@ -812,13 +803,13 @@ getcommand(char *string) if (cp_debug) { printf("getcommand "); wl_print(wlist, stdout); - (void) putc('\n', stdout); + putc('\n', stdout); } return (wlist); } -/* This is also in cshpar.c ... */ +/* This is also in cshpar.c ... */ static void pwlist(wordlist *wlist, char *name) { @@ -847,7 +838,7 @@ com_cdump(wordlist *wl) return; } -#define tab(num) for (i = 0; i < num; i++) (void) putc(' ', cp_out); +#define tab(num) for (i = 0; i < num; i++) putc(' ', cp_out); static void dodump(struct control *cc) @@ -856,104 +847,104 @@ dodump(struct control *cc) struct control *tc; switch (cc->co_type) { - case CO_UNFILLED: - tab(indent); - fprintf(cp_out, "(unfilled)\n"); - break; - case CO_STATEMENT: - tab(indent); - wl_print(cc->co_text, cp_out); - (void) putc('\n', cp_out); - break; - case CO_WHILE: - tab(indent); - fprintf(cp_out, "while "); - wl_print(cc->co_cond, cp_out); - (void) putc('\n', cp_out); - indent += 8; - for (tc = cc->co_children; tc; tc = tc->co_next) - dodump(tc); - indent -= 8; - tab(indent); - fprintf(cp_out, "end\n"); - break; - case CO_REPEAT: - tab(indent); - fprintf(cp_out, "repeat "); - if (cc->co_numtimes != -1) - fprintf(cp_out, "%d\n", cc->co_numtimes); - else - (void) putc('\n', cp_out); - indent += 8; - for (tc = cc->co_children; tc; tc = tc->co_next) - dodump(tc); - indent -= 8; - tab(indent); - fprintf(cp_out, "end\n"); - break; - case CO_DOWHILE: - tab(indent); - fprintf(cp_out, "dowhile "); - wl_print(cc->co_cond, cp_out); - (void) putc('\n', cp_out); - indent += 8; - for (tc = cc->co_children; tc; tc = tc->co_next) - dodump(tc); - indent -= 8; - tab(indent); - fprintf(cp_out, "end\n"); - break; - case CO_IF: - tab(indent); - fprintf(cp_out, "if "); - wl_print(cc->co_cond, cp_out); - (void) putc('\n', cp_out); - indent += 8; - for (tc = cc->co_children; tc; tc = tc->co_next) - dodump(tc); - indent -= 8; - tab(indent); - fprintf(cp_out, "end\n"); - break; - case CO_FOREACH: - tab(indent); - fprintf(cp_out, "foreach %s ", cc->co_foreachvar); - wl_print(cc->co_text, cp_out); - (void) putc('\n', cp_out); - indent += 8; - for (tc = cc->co_children; tc; tc = tc->co_next) - dodump(tc); - indent -= 8; - tab(indent); - fprintf(cp_out, "end\n"); - break; - case CO_BREAK: - tab(indent); - if (cc->co_numtimes != 1) - fprintf(cp_out, "break %d\n", cc->co_numtimes); - else - fprintf(cp_out, "break\n"); - break; - case CO_CONTINUE: - tab(indent); - if (cc->co_numtimes != 1) - fprintf(cp_out, "continue %d\n", - cc->co_numtimes); - else - fprintf(cp_out, "continue\n"); - break; - case CO_LABEL: - tab(indent); - fprintf(cp_out, "label %s\n", cc->co_text->wl_word); - break; - case CO_GOTO: - tab(indent); - fprintf(cp_out, "goto %s\n", cc->co_text->wl_word); - break; - default: - tab(indent); - fprintf(cp_out, "bad type %d\n", cc->co_type); - break; + case CO_UNFILLED: + tab(indent); + fprintf(cp_out, "(unfilled)\n"); + break; + case CO_STATEMENT: + tab(indent); + wl_print(cc->co_text, cp_out); + putc('\n', cp_out); + break; + case CO_WHILE: + tab(indent); + fprintf(cp_out, "while "); + wl_print(cc->co_cond, cp_out); + putc('\n', cp_out); + indent += 8; + for (tc = cc->co_children; tc; tc = tc->co_next) + dodump(tc); + indent -= 8; + tab(indent); + fprintf(cp_out, "end\n"); + break; + case CO_REPEAT: + tab(indent); + fprintf(cp_out, "repeat "); + if (cc->co_numtimes != -1) + fprintf(cp_out, "%d\n", cc->co_numtimes); + else + putc('\n', cp_out); + indent += 8; + for (tc = cc->co_children; tc; tc = tc->co_next) + dodump(tc); + indent -= 8; + tab(indent); + fprintf(cp_out, "end\n"); + break; + case CO_DOWHILE: + tab(indent); + fprintf(cp_out, "dowhile "); + wl_print(cc->co_cond, cp_out); + putc('\n', cp_out); + indent += 8; + for (tc = cc->co_children; tc; tc = tc->co_next) + dodump(tc); + indent -= 8; + tab(indent); + fprintf(cp_out, "end\n"); + break; + case CO_IF: + tab(indent); + fprintf(cp_out, "if "); + wl_print(cc->co_cond, cp_out); + putc('\n', cp_out); + indent += 8; + for (tc = cc->co_children; tc; tc = tc->co_next) + dodump(tc); + indent -= 8; + tab(indent); + fprintf(cp_out, "end\n"); + break; + case CO_FOREACH: + tab(indent); + fprintf(cp_out, "foreach %s ", cc->co_foreachvar); + wl_print(cc->co_text, cp_out); + putc('\n', cp_out); + indent += 8; + for (tc = cc->co_children; tc; tc = tc->co_next) + dodump(tc); + indent -= 8; + tab(indent); + fprintf(cp_out, "end\n"); + break; + case CO_BREAK: + tab(indent); + if (cc->co_numtimes != 1) + fprintf(cp_out, "break %d\n", cc->co_numtimes); + else + fprintf(cp_out, "break\n"); + break; + case CO_CONTINUE: + tab(indent); + if (cc->co_numtimes != 1) + fprintf(cp_out, "continue %d\n", + cc->co_numtimes); + else + fprintf(cp_out, "continue\n"); + break; + case CO_LABEL: + tab(indent); + fprintf(cp_out, "label %s\n", cc->co_text->wl_word); + break; + case CO_GOTO: + tab(indent); + fprintf(cp_out, "goto %s\n", cc->co_text->wl_word); + break; + default: + tab(indent); + fprintf(cp_out, "bad type %d\n", cc->co_type); + break; } return; } diff --git a/src/sconvert.c b/src/sconvert.c index 1ff4ee425..38774d0ed 100644 --- a/src/sconvert.c +++ b/src/sconvert.c @@ -32,127 +32,6 @@ char *cp_program = "sconvert"; /* doesn't get used, but some unused routine in some file references it */ char out_pbuf[BSIZE_SP]; -static void oldwrite(); -static struct plot *oldread(); -static char *fixdate(); - -int -main(ac, av) - char **av; -{ - char *sf, *af; - char buf[BSIZE_SP]; - char t, f; - struct plot *pl; - int i; - char *infile; - char *outfile; - FILE *fp; - cp_in = stdin; - cp_out = stdout; - cp_err = stderr; - cp_curin = stdin; - cp_curout = stdout; - cp_curerr = stderr; - - switch (ac) { - case 5: - sf = av[2]; - af = av[4]; - f = *av[1]; - t = *av[3]; - break; - - case 3: - f = *av[1]; - t = *av[2]; - /* This is a pain, but there is no choice */ - sf = infile = smktemp("scin"); - af = outfile = smktemp("scout"); - if (!(fp = fopen(infile, "w"))) { - perror(infile); - exit(EXIT_BAD); - } - while ((i = fread(buf, 1, sizeof(buf), stdin))) - (void) fwrite(buf, 1, i, fp); - (void) fclose(fp); - break; - - case 1: printf("Input file: "); - (void) fflush(stdout); - (void) fgets(buf, BSIZE_SP, stdin); - sf = copy(buf); - printf("Input type: "); - (void) fflush(stdout); - (void) fgets(buf, BSIZE_SP, stdin); - f = buf[0]; - printf("Output file: "); - (void) fflush(stdout); - (void) fgets(buf, BSIZE_SP, stdin); - af = copy(buf); - printf("Output type: "); - (void) fflush(stdout); - (void) fgets(buf, BSIZE_SP, stdin); - t = buf[0]; - break; - default: - fprintf(cp_err, - "Usage: %s fromtype fromfile totype tofile,\n", - cp_program); - fprintf(cp_err, "\twhere types are o, b, or a\n"); - fprintf(cp_err, - "\tor, %s fromtype totype, used as a filter.\n", - cp_program); - exit(EXIT_BAD); - } - switch(f) { - case 'o' : - pl = oldread(sf); - break; - - case 'b' : - case 'a' : - pl = raw_read(sf); - break; - - default: - fprintf(cp_err, "Types are o, a, or b\n"); - exit(EXIT_BAD); - } - if (!pl) - exit(EXIT_BAD); - - switch(t) { - case 'o' : - oldwrite(af, FALSE, pl); - break; - - case 'b' : - raw_write(af, pl, FALSE, TRUE); - break; - - case 'a' : - raw_write(af, pl, FALSE, FALSE); - break; - - default: - fprintf(cp_err, "Types are o, a, or b\n"); - exit(EXIT_BAD); - } - if (ac == 3) { - /* Gotta finish this stuff up */ - if (!(fp = fopen(outfile, "r"))) { - perror(outfile); - exit(EXIT_BAD); - } - while ((i = fread(buf, 1, sizeof(buf), fp))) - (void) fwrite(buf, 1, i, stdout); - (void) fclose(fp); - (void) unlink(infile); - (void) unlink(outfile); - } - exit(EXIT_NORMAL); -} #define tfread(ptr, siz, nit, fp) if (fread((char *) (ptr), (siz), \ (nit), (fp)) != (nit)) { \ @@ -164,9 +43,23 @@ main(ac, av) fprintf(cp_err, "Write error\n"); \ return; } +static char * +fixdate(char *date) +{ + char buf[20]; + int i; + + (void) strcpy(buf, date); + for (i = 17; i > 8; i--) + buf[i] = buf[i - 1]; + buf[8] = ' '; + buf[18] = '\0'; + return (copy(buf)); +} + + static struct plot * -oldread(name) - char *name; +oldread(char *name) { struct plot *pl; char buf[BSIZE_SP]; @@ -288,11 +181,9 @@ oldread(name) return (pl); } + static void -oldwrite(name, app, pl) - char *name; - bool app; - struct plot *pl; +oldwrite(char *name, bool app, struct plot *pl) { short four = 4, k; struct dvec *v; @@ -404,37 +295,140 @@ oldwrite(name, app, pl) return; } -static char * -fixdate(date) - char *date; -{ - char buf[20]; - int i; - (void) strcpy(buf, date); - for (i = 17; i > 8; i--) - buf[i] = buf[i - 1]; - buf[8] = ' '; - buf[18] = '\0'; - return (copy(buf)); +int +main(int ac, char **av) +{ + char *sf, *af; + char buf[BSIZE_SP]; + char t, f; + struct plot *pl; + int i; + char *infile = NULL; + char *outfile = NULL; + FILE *fp; + cp_in = stdin; + cp_out = stdout; + cp_err = stderr; + cp_curin = stdin; + cp_curout = stdout; + cp_curerr = stderr; + + switch (ac) { + case 5: + sf = av[2]; + af = av[4]; + f = *av[1]; + t = *av[3]; + break; + + case 3: + f = *av[1]; + t = *av[2]; + /* This is a pain, but there is no choice */ + sf = infile = smktemp("scin"); + af = outfile = smktemp("scout"); + if (!(fp = fopen(infile, "w"))) { + perror(infile); + exit(EXIT_BAD); + } + while ((i = fread(buf, 1, sizeof(buf), stdin))) + (void) fwrite(buf, 1, i, fp); + (void) fclose(fp); + break; + + case 1: printf("Input file: "); + (void) fflush(stdout); + (void) fgets(buf, BSIZE_SP, stdin); + sf = copy(buf); + printf("Input type: "); + (void) fflush(stdout); + (void) fgets(buf, BSIZE_SP, stdin); + f = buf[0]; + printf("Output file: "); + (void) fflush(stdout); + (void) fgets(buf, BSIZE_SP, stdin); + af = copy(buf); + printf("Output type: "); + (void) fflush(stdout); + (void) fgets(buf, BSIZE_SP, stdin); + t = buf[0]; + break; + default: + fprintf(cp_err, + "Usage: %s fromtype fromfile totype tofile,\n", + cp_program); + fprintf(cp_err, "\twhere types are o, b, or a\n"); + fprintf(cp_err, + "\tor, %s fromtype totype, used as a filter.\n", + cp_program); + exit(EXIT_BAD); + } + switch(f) { + case 'o' : + pl = oldread(sf); + break; + + case 'b' : + case 'a' : + pl = raw_read(sf); + break; + + default: + fprintf(cp_err, "Types are o, a, or b\n"); + exit(EXIT_BAD); + } + if (!pl) + exit(EXIT_BAD); + + switch(t) { + case 'o' : + oldwrite(af, FALSE, pl); + break; + + case 'b' : + raw_write(af, pl, FALSE, TRUE); + break; + + case 'a' : + raw_write(af, pl, FALSE, FALSE); + break; + + default: + fprintf(cp_err, "Types are o, a, or b\n"); + exit(EXIT_BAD); + } + if (ac == 3) { + /* Gotta finish this stuff up */ + if (!(fp = fopen(outfile, "r"))) { + perror(outfile); + exit(EXIT_BAD); + } + while ((i = fread(buf, 1, sizeof(buf), fp))) + (void) fwrite(buf, 1, i, stdout); + (void) fclose(fp); + (void) unlink(infile); + (void) unlink(outfile); + } + exit(EXIT_NORMAL); } -void cp_pushcontrol() { } -void cp_popcontrol() { } -void out_init() { } -void cp_doquit() { exit(0); } -/* ARGSUSED */ void cp_usrvars(v1, v2) struct variable **v1, **v2; { return; } -/* ARGSUSED */ int cp_evloop(s) char *s; { return (0); } -/* ARGSUSED */ void cp_ccon(o) bool o; { } -/* ARGSUSED */ char *if_errstring(c) int c; { return ("error"); } +void cp_pushcontrol(void) { } +void cp_popcontrol(void) { } +void out_init(void) { } +void cp_doquit(void) { exit(0); } +void cp_usrvars(struct variable **v1, struct variable **v2) { return; } +int cp_evloop(char *s) { return (0); } +void cp_ccon(bool o) { } +char *if_errstring(int c) { return ("error"); } #ifndef out_printf -/* VARARGS1 ARGSUSED */ void out_printf(fmt, args) char *fmt; { } +void out_printf(char *fmt, int args) { } #endif -/* ARGSUSED */ void out_send(string) char *string; {} -/* ARGSUSED */ struct variable * cp_enqvar(word) char *word; { return (NULL); } -/* ARGSUSED */ struct dvec *vec_get(word) char *word; { return (NULL); } -/* ARGSUSED */ void cp_ccom(w, b, e) wordlist *w; char *b; bool e; { return; } -/* ARGSUSED */ int cp_usrset(v, i) struct variable *v; bool i;{return(US_OK); } +void out_send(char *string) {} +struct variable * cp_enqvar(char *word) { return (NULL); } +struct dvec *vec_get(char *word) { return (NULL); } +void cp_ccom(wordlist *w, char *b, bool e) { return; } +int cp_usrset(struct variable *v, bool i) { return(US_OK); } int disptype; -void XtDispatchEvent(pev) char *pev; {} +void XtDispatchEvent(char *pev) { }