diff --git a/src/frontend/control.c b/src/frontend/control.c index 7dfc9af5a..3b181a659 100644 --- a/src/frontend/control.c +++ b/src/frontend/control.c @@ -616,11 +616,14 @@ cp_evloop(char *string) char *i; int nn; -#define newblock cend[stackp]->co_children = alloc(struct control); \ - ZERO(cend[stackp]->co_children,struct control), \ - cend[stackp]->co_children->co_parent = cend[stackp]; \ - cend[stackp] = cend[stackp]->co_children; \ - cend[stackp]->co_type = CO_UNFILLED; +#define newblock \ + do { \ + cend[stackp]->co_children = alloc(struct control); \ + ZERO(cend[stackp]->co_children, struct control); \ + cend[stackp]->co_children->co_parent = cend[stackp]; \ + cend[stackp] = cend[stackp]->co_children; \ + cend[stackp]->co_type = CO_UNFILLED; \ + } while(0) for (;;) { wlist = getcommand(string); diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 5f97477be..c06c5ac26 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -39,7 +39,11 @@ Author: 1985 Wayne A. Christopher #include "numparam/numpaif.h" -#define line_free(line, flag) { line_free_x(line, flag); line = NULL; } +#define line_free(line, flag) \ + do { \ + line_free_x(line, flag); \ + line = NULL; \ + } while(0) static char *upper(register char *string); static bool doedit(char *filename); diff --git a/src/frontend/plotting/clip.c b/src/frontend/plotting/clip.c index 64c4f9609..64f4379f2 100644 --- a/src/frontend/plotting/clip.c +++ b/src/frontend/plotting/clip.c @@ -23,18 +23,27 @@ Author: 1982 Giles Billingsley #define CODEMINY 2 #define CODEMAXX 4 #define CODEMAXY 8 -#define CODE(x,y,c) c = 0;\ - if (x < l)\ - c = CODEMINX;\ - else if (x > r)\ - c = CODEMAXX;\ - if (y < b)\ - c |= CODEMINY;\ - else if (y > t)\ - c |= CODEMAXY; +#define CODE(x, y, c) \ + do { \ + c = 0; \ + if (x < l) \ + c = CODEMINX; \ + else if (x > r) \ + c = CODEMAXX; \ + if (y < b) \ + c |= CODEMINY; \ + else if (y > t) \ + c |= CODEMAXY; \ + } while(0) + +#define SWAPINT(a, b) \ + do { \ + int xxxx = (a); \ + (a) = (b); \ + (b) = xxxx; \ + } while(0) -#define SWAPINT(a, b) { int xxxx = (a); (a) = (b); (b) = xxxx; } /* clip_line will clip a line to a rectangular area. The returned * value is 'TRUE' if the line is out of the AOI (therefore does not @@ -51,8 +60,8 @@ clip_line(int *pX1, int *pY1, int *pX2, int *pY2, int l, int b, int r, int t) int x = 0, y = 0; int c,c1,c2; - CODE(x1,y1,c1) - CODE(x2,y2,c2) + CODE(x1,y1,c1); + CODE(x2,y2,c2); while (c1 || c2) { if (c1 & c2) return (TRUE); /* Line is invisible. */ @@ -74,11 +83,11 @@ clip_line(int *pX1, int *pY1, int *pX2, int *pY2, int l, int b, int r, int t) if (c == c1) { x1 = x; y1 = y; - CODE(x,y,c1) + CODE(x,y,c1); } else { x2 = x; y2 = y; - CODE(x,y,c2) + CODE(x,y,c2); } } *pX1 = x1; diff --git a/src/frontend/plotting/graphdb.c b/src/frontend/plotting/graphdb.c index 74ea37ec5..dbf75f1d8 100644 --- a/src/frontend/plotting/graphdb.c +++ b/src/frontend/plotting/graphdb.c @@ -46,9 +46,13 @@ static GBUCKET GBucket[NUMGBUCKETS]; static int RunningId = 1; /* initialize graph structure */ -#define SETGRAPH(pgraph, id) (pgraph)->graphid = (id); \ - (pgraph)->degree = 1; \ - (pgraph)->linestyle = -1 +#define SETGRAPH(pgraph, id) \ + do { \ + (pgraph)->graphid = (id); \ + (pgraph)->degree = 1; \ + (pgraph)->linestyle = -1; \ + } while(0) + /* returns NULL on error */ diff --git a/src/frontend/plotting/plot5.c b/src/frontend/plotting/plot5.c index 3d4b4bc2d..c4046254d 100644 --- a/src/frontend/plotting/plot5.c +++ b/src/frontend/plotting/plot5.c @@ -12,8 +12,12 @@ Copyright 1990 Regents of the University of California. All rights reserved. static FILE *plotfile; -#define putsi(a) putc((char) (a), plotfile); \ - putc((char) ((a) >> 8), plotfile) +#define putsi(a) \ + do { \ + putc((char) (a), plotfile); \ + putc((char) ((a) >> 8), plotfile); \ + } while(0) + #define SOLID 0 static char *linestyle[] = { "solid", "dotted", "longdashed", "shortdashed", diff --git a/src/frontend/plotting/x11.c b/src/frontend/plotting/x11.c index e7a9e791d..11b227180 100644 --- a/src/frontend/plotting/x11.c +++ b/src/frontend/plotting/x11.c @@ -344,9 +344,13 @@ handle_wm_messages(Widget w, XtPointer client_data, XEvent *ev, Boolean *cont) /* Recover from bad NewViewPort call. */ -#define RECOVERNEWVIEWPORT() tfree(graph);\ - graph = NULL; - /* need to do this or else DestroyGraph will free it again */ +#define RECOVERNEWVIEWPORT() \ + do { \ + tfree(graph); \ + graph = NULL; \ + } while(0) +/* need to do this or else DestroyGraph will free it again */ + /* NewViewport is responsible for filling in graph->viewport */ int diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index 4990e7c90..b199d7f13 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -272,9 +272,32 @@ raw_write(char *name, struct plot *pl, bool app, bool binary) * and that the variables precede the values. */ -#define skip(s) while (*(s) && !isspace(*(s)))(s)++; while (isspace(*(s)))(s)++ -#define nonl(s) r = (s); while (*r && (*r != '\n')) r++; *r = '\0' -#define getout {fprintf(cp_err,"Error: bad rawfile\n point %d, var %s\n load aborted\n", i, v->v_name); return (NULL);} +#define SKIP(s) \ + do { \ + while (*(s) && !isspace(*(s))) \ + (s)++; \ + while (isspace(*(s))) \ + (s)++; \ + } while(0) + +#define NONL(s) \ + do { \ + r = (s); \ + while (*r && (*r != '\n')) \ + r++; \ + *r = '\0'; \ + } while(0) + +#define GETOUT() \ + do { \ + fprintf(cp_err, \ + "Error: bad rawfile\n" \ + " point %d, var %s\n" \ + " load aborted\n", \ + i, v->v_name); \ + return (NULL); \ + } while(0) + struct plot * raw_read(char *name) { @@ -316,18 +339,18 @@ raw_read(char *name) { /* Figure out what this line is... */ if (ciprefix("title:", buf)) { s = buf; - skip(s); - nonl(s); + SKIP(s); + NONL(s); title = copy(s); } else if (ciprefix("date:", buf)) { s = buf; - skip(s); - nonl(s); + SKIP(s); + NONL(s); date = copy(s); } else if (ciprefix("plotname:", buf)) { s = buf; - skip(s); - nonl(s); + SKIP(s); + NONL(s); if (curpl) { /* reverse commands list */ for (wl=curpl->pl_commands, curpl->pl_commands=NULL; wl && @@ -349,7 +372,7 @@ raw_read(char *name) { nvars = npoints = 0; } else if (ciprefix("flags:", buf)) { s = buf; - skip(s); + SKIP(s); while ((t = gettok(&s)) != NULL) { if (cieq(t, "real")) flags |= VF_REAL; @@ -366,13 +389,13 @@ raw_read(char *name) { } } else if (ciprefix("no. variables:", buf)) { s = buf; - skip(s); - skip(s); + SKIP(s); + SKIP(s); nvars = scannum(s); } else if (ciprefix("no. points:", buf)) { s = buf; - skip(s); - skip(s); + SKIP(s); + SKIP(s); npoints = scannum(s); } else if (ciprefix("dimensions:", buf)) { if (npoints == 0) { @@ -381,7 +404,7 @@ raw_read(char *name) { continue; } s = buf; - skip(s); + SKIP(s); if (atodims(s, dims, &numdims)) { /* Something's wrong. */ fprintf(cp_err, "Warning: syntax error in dimensions, ignored.\n"); @@ -407,8 +430,8 @@ raw_read(char *name) { } else if (ciprefix("command:", buf)) { /* Note that we reverse these commands eventually... */ s = buf; - skip(s); - nonl(s); + SKIP(s); + NONL(s); if (curpl) { curpl->pl_commands = wl_cons(copy(s), curpl->pl_commands); wl = curpl->pl_commands; @@ -419,8 +442,8 @@ raw_read(char *name) { (void) cp_evloop(s); } else if (ciprefix("option:", buf)) { s = buf; - skip(s); - nonl(s); + SKIP(s); + NONL(s); if (curpl) { wl = cp_lexer(s); for (vv = curpl->pl_env; vv && vv->va_next; @@ -441,7 +464,7 @@ raw_read(char *name) { break; } s = buf; - skip(s); + SKIP(s); if (!*s) { (void) fgets(buf, BSIZE_SP, fp); s = buf; @@ -593,22 +616,22 @@ raw_read(char *name) { if (flags & VF_REAL) { if (fscanf(fp, " %lf", &v->v_realdata[i]) != 1) - getout + GETOUT(); } else { if (fscanf(fp, " %lf, %lf", &realpart(v->v_compdata[i]), &imagpart(v->v_compdata[i])) != 2) - getout + GETOUT(); } } else if (raw_padded) { if (flags & VF_REAL) { if (fscanf(fp, " %lf", &junk) != 1) - getout + GETOUT(); } else { if (fscanf(fp, " %lf, %lf", &junk, &junk) != 2) - getout + GETOUT(); } } } @@ -619,27 +642,27 @@ raw_read(char *name) { if (flags & VF_REAL) { if (fread(&v->v_realdata[i], sizeof (double), 1, fp) != 1) - getout + GETOUT(); } else { if (fread(&v->v_compdata[i].cx_real, sizeof (double), 1, fp) != 1) - getout + GETOUT(); if (fread(&v->v_compdata[i].cx_imag, sizeof (double), 1, fp) != 1) - getout + GETOUT(); } } else if (raw_padded) { if (flags & VF_REAL) { if (fread(&junk, sizeof (double), 1, fp) != 1) - getout; + GETOUT(); } else { if (fread(&junk, sizeof (double), 1, fp) != 1) - getout + GETOUT(); if (fread(&junk, sizeof (double), 1, fp) != 1) - getout + GETOUT(); } } } @@ -648,7 +671,7 @@ raw_read(char *name) { } else { s = buf; if (is_ascii) { - skip(s); + SKIP(s); } if (*s) { fprintf(cp_err, diff --git a/src/frontend/runcoms2.c b/src/frontend/runcoms2.c index 107cc7f38..4f9d273ab 100644 --- a/src/frontend/runcoms2.c +++ b/src/frontend/runcoms2.c @@ -27,7 +27,13 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group #define RAWBUF_SIZE 32768 extern char rawfileBuf[RAWBUF_SIZE]; extern void line_free_x(struct line * deck, bool recurse); -#define line_free(line,flag) { line_free_x(line,flag); line = NULL; } + +#define line_free(line, flag) \ + do { \ + line_free_x(line, flag); \ + line = NULL; \ + } while(0) + /* Continue a simulation. If there is non in progress, this is the * equivalent of "run". diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index fafcbe005..e46333853 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -74,7 +74,13 @@ Modified: 2000 AlansFixes #include "numparam/numpaif.h" extern void line_free_x(struct line * deck, bool recurse); -#define line_free(line, flag) { line_free_x(line, flag); line = NULL; } + +#define line_free(line, flag) \ + do { \ + line_free_x(line, flag); \ + line = NULL; \ + } while(0) + /* ----- static declarations ----- */ struct subs;