Browse Source

* src/sconvert.c src/frontend/circuits.c src/frontend/circuits.h


			
			
				pre-master-46
			
			
		
arno 26 years ago
parent
commit
4e605553de
  1. 23
      src/frontend/circuits.c
  2. 2
      src/frontend/circuits.h
  3. 160
      src/frontend/inp.c
  4. 9
      src/frontend/inpcom.c
  5. 2
      src/include/fteext.h
  6. 129
      src/parser/front.c
  7. 298
      src/sconvert.c

23
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)
{
}

2
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

160
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++;
@ -120,9 +121,6 @@ top1: for (here = deck; here; here = here->li_next) {
here->li_linenum,
upper(here->li_line));
out_send(out_pbuf);
/* out_printf("%6d : %s\n",
here->li_linenum,
upper(here->li_line)); */
} 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;
@ -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;
@ -296,11 +292,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename)
/* 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++)
@ -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;
}

9
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 = '_';

2
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 */

129
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?? */
@ -122,10 +121,9 @@ cp_evloop(char *string)
}
/* 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.
*/
/* 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);
@ -212,10 +210,9 @@ cp_evloop(char *string)
} 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...
*/
/* 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);
@ -272,10 +269,8 @@ cp_evloop(char *string)
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_parent->co_children = NULL;
cend[stackp]->co_parent->co_elseblock = cend[stackp];
cend[stackp]->co_prev = NULL;
}
} else {
@ -301,12 +296,9 @@ cp_evloop(char *string)
"Error: continue not in loop or too many continue levels given\n");
break;
default:
x = findlabel(i,
control[stackp]);
x = findlabel(i, control[stackp]);
if (!x)
fprintf(cp_err,
"Error: label %s not found\n",
i);
fprintf(cp_err, "Error: label %s not found\n", i);
}
if (x)
x = x->co_next;
@ -340,7 +332,6 @@ doblock(struct control *bl, int *num)
int nn;
switch (bl->co_type) {
case CO_WHILE:
while (bl->co_cond && cp_isTRUE(bl->co_cond)) {
for (ch = bl->co_children; ch; ch = cn) {
@ -485,10 +476,10 @@ 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);
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);
@ -569,6 +560,8 @@ doblock(struct control *bl, int *num)
}
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");
@ -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)
@ -863,13 +854,13 @@ dodump(struct control *cc)
case CO_STATEMENT:
tab(indent);
wl_print(cc->co_text, cp_out);
(void) putc('\n', cp_out);
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);
putc('\n', cp_out);
indent += 8;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
@ -883,7 +874,7 @@ dodump(struct control *cc)
if (cc->co_numtimes != -1)
fprintf(cp_out, "%d\n", cc->co_numtimes);
else
(void) putc('\n', cp_out);
putc('\n', cp_out);
indent += 8;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
@ -895,7 +886,7 @@ dodump(struct control *cc)
tab(indent);
fprintf(cp_out, "dowhile ");
wl_print(cc->co_cond, cp_out);
(void) putc('\n', cp_out);
putc('\n', cp_out);
indent += 8;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
@ -907,7 +898,7 @@ dodump(struct control *cc)
tab(indent);
fprintf(cp_out, "if ");
wl_print(cc->co_cond, cp_out);
(void) putc('\n', cp_out);
putc('\n', cp_out);
indent += 8;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);
@ -919,7 +910,7 @@ dodump(struct control *cc)
tab(indent);
fprintf(cp_out, "foreach %s ", cc->co_foreachvar);
wl_print(cc->co_text, cp_out);
(void) putc('\n', cp_out);
putc('\n', cp_out);
indent += 8;
for (tc = cc->co_children; tc; tc = tc->co_next)
dodump(tc);

298
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;
int
main(int ac, char **av)
{
char buf[20];
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;
(void) strcpy(buf, date);
for (i = 17; i > 8; i--)
buf[i] = buf[i - 1];
buf[8] = ' ';
buf[18] = '\0';
return (copy(buf));
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) { }
Loading…
Cancel
Save