From 96992f770aa8d0ae59a783501cd03e556231ab8b Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 2 Nov 2010 17:55:32 +0000 Subject: [PATCH] use the type `bool' instead of `unsigned char' in the numparam world --- ChangeLog | 10 ++++ src/frontend/numparam/general.h | 35 +++++++------- src/frontend/numparam/mystring.c | 48 +++++++++--------- src/frontend/numparam/numparam.h | 8 +-- src/frontend/numparam/spicenum.c | 2 +- src/frontend/numparam/xpressn.c | 83 ++++++++++++++++---------------- 6 files changed, 99 insertions(+), 87 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddca71f32..9cfac98d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-11-02 Robert Larice + * src/frontend/numparam/general.h , + * src/frontend/numparam/mystring.c , + * src/frontend/numparam/numparam.h , + * src/frontend/numparam/spicenum.c , + * src/frontend/numparam/xpressn.c : + use the type `bool' instead of `unsigned char' in the numparam world + bool currently is `unsigned char', plan to change to `int' for better + type comaptibility with `C' boolean expressions + 2010-11-02 Robert Larice * src/frontend/inpcom.c , * src/frontend/parser/lexical.c , diff --git a/src/frontend/numparam/general.h b/src/frontend/numparam/general.h index 556f67536..cf23099cb 100644 --- a/src/frontend/numparam/general.h +++ b/src/frontend/numparam/general.h @@ -6,6 +6,7 @@ the function code is in 'mystring.c' . */ #include "dstring.h" +#include "bool.h" #define Use(x) x=0;x=x #define Uses(s) s=s @@ -23,23 +24,23 @@ typedef char string[258]; void sfix( SPICE_DSTRINGPTR dstr_p, int len) ; char * pscopy( SPICE_DSTRINGPTR s, char * a, int i,int j); char * pscopy_up( SPICE_DSTRINGPTR s, char * a, int i,int j); -unsigned char scopyd( SPICE_DSTRINGPTR a, SPICE_DSTRINGPTR b); -unsigned char scopys( SPICE_DSTRINGPTR a, char *b); -unsigned char scopy_up( SPICE_DSTRINGPTR a, char *str) ; -unsigned char scopy_lower( SPICE_DSTRINGPTR a, char *str) ; -unsigned char ccopy( SPICE_DSTRINGPTR a, char c); -unsigned char sadd( SPICE_DSTRINGPTR s, char * t); -unsigned char nadd( SPICE_DSTRINGPTR s, long n); -unsigned char cadd( SPICE_DSTRINGPTR s, char c); -unsigned char naddll( SPICE_DSTRINGPTR s, long long n); -unsigned char cins( SPICE_DSTRINGPTR s, char c); -unsigned char sins( SPICE_DSTRINGPTR s, char * t); +bool scopyd( SPICE_DSTRINGPTR a, SPICE_DSTRINGPTR b); +bool scopys( SPICE_DSTRINGPTR a, char *b); +bool scopy_up( SPICE_DSTRINGPTR a, char *str) ; +bool scopy_lower( SPICE_DSTRINGPTR a, char *str) ; +bool ccopy( SPICE_DSTRINGPTR a, char c); +bool sadd( SPICE_DSTRINGPTR s, char * t); +bool nadd( SPICE_DSTRINGPTR s, long n); +bool cadd( SPICE_DSTRINGPTR s, char c); +bool naddll( SPICE_DSTRINGPTR s, long long n); +bool cins( SPICE_DSTRINGPTR s, char c); +bool sins( SPICE_DSTRINGPTR s, char * t); int cpos( char c, char *s); int spos_( char * sub, char * s); int ci_prefix( register char *p, register char *s ); int length(char * s); -unsigned char steq(char * s, char * t); -unsigned char stne(char * s, char * t); +bool steq(char * s, char * t); +bool stne(char * s, char * t); int scompare(char * a, char * b); int ord(char c); int pred(int i); @@ -54,10 +55,10 @@ char upcase(char c); char lowcase(char c); int hi(long w); int lo(long w); -unsigned char odd(long x); -unsigned char alfa(char c); -unsigned char num(char c); -unsigned char alfanum(char c); +bool odd(long x); +bool alfa(char c); +bool num(char c); +bool alfanum(char c); char * stupcase( char * s); /***** primitive input-output ***/ diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index 2fe87296a..ca002c299 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -161,7 +161,7 @@ length (char *s) /* ----------------------------------------------------------------- * Function: add string t to dynamic string dstr_p. * ----------------------------------------------------------------- */ -unsigned char +bool sadd ( SPICE_DSTRINGPTR dstr_p, char *t) { spice_dstring_append( dstr_p, t, -1 ) ; @@ -171,7 +171,7 @@ sadd ( SPICE_DSTRINGPTR dstr_p, char *t) /* ----------------------------------------------------------------- * Function: add character c to dynamic string dstr_p. * ----------------------------------------------------------------- */ -unsigned char +bool cadd ( SPICE_DSTRINGPTR dstr_p, char c) { char tmp_str[2] ; @@ -184,7 +184,7 @@ cadd ( SPICE_DSTRINGPTR dstr_p, char c) /* ----------------------------------------------------------------- * Function: insert character c at front of dynamic string dstr_p * ----------------------------------------------------------------- */ -unsigned char +bool cins ( SPICE_DSTRINGPTR dstr_p, char c) { int i ; @@ -203,7 +203,7 @@ cins ( SPICE_DSTRINGPTR dstr_p, char c) /* ----------------------------------------------------------------- * Function: insert string t at front of dynamic string dstr_p * ----------------------------------------------------------------- */ -unsigned char +bool sins ( SPICE_DSTRINGPTR dstr_p, char *t) { int i ; @@ -254,7 +254,7 @@ upcase (char c) * Create copy of the dynamic string. Dynamic strings are always NULL * terminated. * ----------------------------------------------------------------- */ -unsigned char +bool scopyd(SPICE_DSTRINGPTR s, SPICE_DSTRINGPTR t) /* returns success flag */ { spice_dstring_reinit( s ) ; @@ -266,7 +266,7 @@ scopyd(SPICE_DSTRINGPTR s, SPICE_DSTRINGPTR t) /* returns success flag */ * Create copy of the string in the dynamic string. Dynamic strings * are always NULLterminated. * ----------------------------------------------------------------- */ -unsigned char +bool scopys(SPICE_DSTRINGPTR s, char *t) /* returns success flag */ { spice_dstring_reinit( s ) ; @@ -278,7 +278,7 @@ scopys(SPICE_DSTRINGPTR s, char *t) /* returns success flag */ * Create an upper case copy of a string and store it in a dynamic string. * Dynamic strings are always NULL * terminated. * ----------------------------------------------------------------- */ -unsigned char +bool scopy_up (SPICE_DSTRINGPTR dstr_p, char *str) /* returns success flag */ { char up[2] ; /* short string */ @@ -297,7 +297,7 @@ scopy_up (SPICE_DSTRINGPTR dstr_p, char *str) /* returns success flag */ * Create a lower case copy of a string and store it in a dynamic string. * Dynamic strings are always NULL * terminated. * ----------------------------------------------------------------- */ -unsigned char +bool scopy_lower (SPICE_DSTRINGPTR dstr_p, char *str) /* returns success flag */ { char low[2] ; /* short string */ @@ -312,7 +312,7 @@ scopy_lower (SPICE_DSTRINGPTR dstr_p, char *str) /* returns success flag */ return 1 ; /* Dstrings expand to any length */ } -unsigned char +bool ccopy ( SPICE_DSTRINGPTR dstr_p, char c) /* returns success flag */ { char *s_p ; /* current string */ @@ -396,7 +396,7 @@ succ (int i) return (++i); } -unsigned char +bool nadd ( SPICE_DSTRINGPTR dstr_p, long n) /* append a decimal integer to a string */ { @@ -439,7 +439,7 @@ nadd ( SPICE_DSTRINGPTR dstr_p, long n) return 1 ; } -unsigned char +bool naddll (SPICE_DSTRINGPTR dstr_p, long long n) /* append a decimal integer (but a long long) to a string */ { @@ -520,7 +520,7 @@ scompare (char *a, char *b) return k; } -unsigned char +bool steq (char *a, char *b) /* string a==b test */ { unsigned short j = 0; @@ -530,7 +530,7 @@ steq (char *a, char *b) /* string a==b test */ return ((a[j] == 0) && (b[j] == 0)) /* string equality test */ ; } -unsigned char +bool stne (char *s, char *t) { return scompare (s, t) != 0; @@ -557,20 +557,20 @@ lowcase (char c) return c; } -unsigned char +bool alfa (char c) { return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || c == '_' || c == '[' || c == ']'; } -unsigned char +bool num (char c) { return (c >= '0') && (c <= '9'); } -unsigned char +bool alfanum (char c) { return alfa (c) || ((c >= '0') && (c <= '9')); @@ -616,7 +616,7 @@ freadi (FILE * f) /* reads next integer, but returns 0 if none found. */ { long z = 0; - unsigned char minus = 0; + bool minus = 0; char c; do @@ -774,7 +774,7 @@ strif (long i, int f, SPICE_DSTRINGPTR dstr_p) } } -unsigned char +bool odd (long x) { return (x & 1); @@ -787,7 +787,7 @@ vali (char *s, long *i) { int k = 0, digit = 0, ls; long z = 0; - unsigned char minus = 0, ok = 1; + bool minus = 0, ok = 1; char c; ls = length (s); @@ -825,13 +825,13 @@ vali (char *s, long *i) return k; /* one beyond error position */ } -static unsigned char -match (char *s, char *t, int n, int tstart, unsigned char testcase) +static bool +match (char *s, char *t, int n, int tstart, bool testcase) { /* returns 0 if ( tstart is out of range. But n may be 0 ? */ /* 1 if s matches t[tstart...tstart+n] */ int i, j, lt; - unsigned char ok; + bool ok; char a, b; i = 0; j = tstart; @@ -862,7 +862,7 @@ posi (char *sub, char *s, int opt) /* opt=1: like Turbo Pascal Pos, but case insensitive */ /* opt=2: position in space separated wordlist for scanners */ int a, b, k, j; - unsigned char ok, tstcase; + bool ok, tstcase; SPICE_DSTRING tstr ; ok = 0; @@ -992,7 +992,7 @@ ival (char *s, int *err) { int k = 0, digit = 0, ls; long z = 0; - unsigned char minus = 0, ok = 1; + bool minus = 0, ok = 1; char c; ls = length (s); diff --git a/src/frontend/numparam/numparam.h b/src/frontend/numparam/numparam.h index a9d439921..055e5e234 100644 --- a/src/frontend/numparam/numparam.h +++ b/src/frontend/numparam/numparam.h @@ -64,11 +64,11 @@ typedef struct _ttdico { void initdico(tdico * dico); int donedico(tdico * dico); void dico_free_entry( entry *entry_p ) ; -unsigned char defsubckt( tdico *dico, char * s, int w, char categ); +bool defsubckt( tdico *dico, char * s, int w, char categ); int findsubckt( tdico *dico, char * s, SPICE_DSTRINGPTR subname); -unsigned char nupa_substitute( tdico *dico, char * s, char * r, unsigned char err); -unsigned char nupa_assignment( tdico *dico, char * s, char mode); -unsigned char nupa_subcktcall( tdico *dico, char * s, char * x, unsigned char err); +bool nupa_substitute( tdico *dico, char * s, char * r, bool err); +bool nupa_assignment( tdico *dico, char * s, char mode); +bool nupa_subcktcall( tdico *dico, char * s, char * x, bool err); void nupa_subcktexit( tdico *dico); tdico * nupa_fetchinstance(void); char getidtype( tdico *d, char * s); diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index cc605cc2b..462481a35 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -830,7 +830,7 @@ nupa_eval (char *s, int linenum, int orig_linenum) char c, keep, *ptr; unsigned int i; SPICE_DSTRING subname ; /* dynamic string for subcircuit name */ - unsigned char err = 1; + bool err = 1; spice_dstring_init(&subname) ; dicoS->srcline = linenum; diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index 8577bdafc..12c7cd4af 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -134,7 +134,7 @@ mathfunction (int f, double z, double x) return y; } -static unsigned char +static bool message (tdico * dic, char *s) /* record 'dic' should know about source file and line */ { @@ -344,9 +344,9 @@ getidtype (tdico * d, char *s) } static double -fetchnumentry (tdico * dico, char *t, unsigned char *perr) +fetchnumentry (tdico * dico, char *t, bool *perr) { - unsigned char err = *perr; + bool err = *perr; double u; entry *entry_p ; /* hash table entry */ SPICE_DSTRING s ; /* dynamic string */ @@ -409,7 +409,7 @@ attrib (tdico *dico_p, NGHASHPTR htable_p, char *t, char op) return entry_p ; } -static unsigned char +static bool define (tdico * dico, char *t, /* identifier to define */ char op, /* option */ @@ -428,7 +428,7 @@ define (tdico * dico, we mark each id with its subckt level, and warn if write at higher one. */ char c; - unsigned char err, warn; + bool err, warn; entry *entry_p ; /* spice table entry */ SPICE_DSTRING vartemp ; /* vairable temp */ NGHASHPTR htable_p ; /* hash table */ @@ -495,14 +495,14 @@ define (tdico * dico, return err; } -unsigned char +bool defsubckt (tdico * dico, char *s, int w, char categ) /* called on 1st pass of spice source code, to enter subcircuit (categ=U) and model (categ=O) names */ { SPICE_DSTRING ustr ; /* temp user string */ - unsigned char err; + bool err; int i, j, ls; ls = length (s); i = 0; @@ -577,10 +577,10 @@ findsubckt (tdico * dico, char *s, SPICE_DSTRINGPTR subname) static int deffuma ( /* define function or macro entry. */ tdico * dico, char *t, char tpe, unsigned short bufstart, - unsigned char *pjumped, unsigned char *perr) + unsigned char *pjumped, bool *perr) { unsigned char jumped = *pjumped; - unsigned char err = *perr; + bool err = *perr; /* if not jumped, define new function or macro, returns index to buffferstart if jumped, return index to existing function */ @@ -631,7 +631,7 @@ keyword ( SPICE_DSTRINGPTR keys_p, SPICE_DSTRINGPTR tstr_p) /* return 0 if t not found in list keys, else the ordinal number */ unsigned char i, j, k; int lt, lk; - unsigned char ok; + bool ok; char *t ; char *keys ; lt = spice_dstring_length(tstr_p) ; @@ -672,7 +672,7 @@ parseunit (double x, char *s) { double u = 0; SPICE_DSTRING t ; - unsigned char isunit; + bool isunit; isunit = 1; spice_dstring_init(&t) ; @@ -710,7 +710,7 @@ fetchid (char *s, SPICE_DSTRINGPTR t, int ls, int i) /* copy next identifier from s into t, advance and return scan index i */ { char c; - unsigned char ok; + bool ok; c = s[i - 1]; while ((!alfa (c)) && (i < ls)) @@ -740,15 +740,15 @@ fetchid (char *s, SPICE_DSTRINGPTR t, int ls, int i) } static double -exists (tdico * d, char *s, int *pi, unsigned char *perror) +exists (tdico * d, char *s, int *pi, bool *perror) /* check if s in simboltable 'defined': expect (ident) and return 0 or 1 */ { - unsigned char error = *perror; + bool error = *perror; int i = *pi; double x; int ls; char c; - unsigned char ok; + bool ok; SPICE_DSTRING t ; ls = length (s); @@ -795,10 +795,10 @@ exists (tdico * d, char *s, int *pi, unsigned char *perror) } static double -fetchnumber (tdico * dico, char *s, int ls, int *pi, unsigned char *perror) +fetchnumber (tdico * dico, char *s, int ls, int *pi, bool *perror) /* parse a Spice number in string s */ { - unsigned char error = *perror; + bool error = *perror; int i = *pi; int k, err; char d; @@ -883,7 +883,7 @@ fetchoperator (tdico * dico, char *s, int ls, int *pi, unsigned char *pstate, unsigned char *plevel, - unsigned char *perror) + bool *perror) /* grab an operator from string s and advance scan index pi. each operator has: one-char alias, precedence level, new interpreter state. */ @@ -891,7 +891,7 @@ fetchoperator (tdico * dico, int i = *pi; unsigned char state = *pstate; unsigned char level = *plevel; - unsigned char error = *perror; + bool error = *perror; char c, d; SPICE_DSTRING vstr ; c = s[i - 1]; @@ -996,12 +996,12 @@ static char opfunctkey (tdico * dico, unsigned char kw, char c, unsigned char *pstate, unsigned char *plevel, - unsigned char *perror) + bool *perror) /* handle operator and built-in keywords */ { unsigned char state = *pstate; unsigned char level = *plevel; - unsigned char error = *perror; + bool error = *perror; /*if kw operator keyword, c=token*/ switch (kw) { /* & | ~ DIV MOD Defined */ @@ -1143,7 +1143,7 @@ operate (char op, double x, double y) } static double -formula (tdico * dico, char *s, unsigned char *perror) +formula (tdico * dico, char *s, bool *perror) { /* Expression parser. s is a formula with parentheses and math ops +-* / ... @@ -1155,8 +1155,8 @@ formula (tdico * dico, char *s, unsigned char *perror) Allowed transitions: 1->2->(3,1) and 3->(3,1). */ typedef enum {nprece=9} _nnprece; /* maximal nb of precedence levels */ - unsigned char error = *perror; - unsigned char negate = 0; + bool error = *perror; + bool negate = 0; unsigned char state, oldstate, topop, ustack, level, kw, fu; double u = 0.0, v, w = 0.0; double accu[nprece + 1]; @@ -1164,7 +1164,7 @@ formula (tdico * dico, char *s, unsigned char *perror) char uop[nprece + 1]; int i, k, ls, natom, arg2, arg3; char c, d; - unsigned char ok; + bool ok; SPICE_DSTRING tstr ; spice_dstring_init(&tstr) ; @@ -1378,7 +1378,7 @@ fmttype (double x) /* find out the "natural" type of format for number x */ double ax, dx; int rx; - unsigned char isint, astronomic; + bool isint, astronomic; ax = absf (x); isint = 0; astronomic = 0; @@ -1403,7 +1403,7 @@ fmttype (double x) return 'P'; } -static unsigned char +static bool evaluate (tdico * dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) { /* transform t to result q. mode 0: expression, mode 1: simple variable */ @@ -1411,8 +1411,8 @@ evaluate (tdico * dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) int j, lq; char dt, fmt; entry *entry_p ; - unsigned char numeric, done, nolookup; - unsigned char err; + bool numeric, done, nolookup; + bool err; SPICE_DSTRING vstr ; spice_dstring_init(&vstr) ; @@ -1493,12 +1493,12 @@ evaluate (tdico * dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) } #if 0 -static unsigned char -scanline (tdico * dico, char *s, char *r, unsigned char err) +static bool +scanline (tdico * dico, char *s, char *r, bool err) /* scan host code line s for macro substitution. r=result line */ { int i, k, ls, level, nd, nnest; - unsigned char spice3; + bool spice3; char c, d; Strbig (Llen, q); Strbig (Llen, t); @@ -1754,7 +1754,7 @@ insertnumber (tdico * dico, int i, char *s, SPICE_DSTRINGPTR ustr_p) SPICE_DSTRING vstr ; /* dynamic string */ SPICE_DSTRING mstr ; /* dynamic string */ char *v_p ; /* value of vstr dyna string */ - unsigned char found; + bool found; int ls, k; long long accu; ls = length (s); @@ -1820,8 +1820,9 @@ insertnumber (tdico * dico, int i, char *s, SPICE_DSTRINGPTR ustr_p) } return i; } -unsigned char -nupa_substitute (tdico * dico, char *s, char *r, unsigned char err) + +bool +nupa_substitute (tdico * dico, char *s, char *r, bool err) /* s: pointer to original source line. r: pointer to result line, already heavily modified wrt s anywhere we find a 10-char numstring in r, substitute it. @@ -1988,7 +1989,7 @@ getexpress (char *s, SPICE_DSTRINGPTR tstr_p, int *pi) int i = *pi; int ia, ls, level; char c, d, tpe; - unsigned char comment = 0; + bool comment = 0; ls = length (s); ia = i + 1; @@ -2062,7 +2063,7 @@ getexpress (char *s, SPICE_DSTRINGPTR tstr_p, int *pi) return tpe; } -unsigned char +bool nupa_assignment (tdico * dico, char *s, char mode) /* is called for all 'Param' lines of the input file. is also called for the params: section of a subckt . @@ -2073,7 +2074,7 @@ nupa_assignment (tdico * dico, char *s, char mode) /* s has the format: ident = expression; ident= expression ... */ int i, j, ls; unsigned char key; - unsigned char error, err; + bool error, err; char dtype; int wval = 0; double rval = 0.0; @@ -2148,8 +2149,8 @@ nupa_assignment (tdico * dico, char *s, char mode) return error; } -unsigned char -nupa_subcktcall (tdico * dico, char *s, char *x, unsigned char err) +bool +nupa_subcktcall (tdico * dico, char *s, char *x, bool err) /* s= a subckt define line, with formal params. x= a matching subckt call line, with actual params */ @@ -2164,7 +2165,7 @@ nupa_subcktcall (tdico * dico, char *s, char *x, unsigned char err) char *buf, *token; char *t_p ; char *u_p ; - unsigned char found; + bool found; spice_dstring_init(&subname) ; spice_dstring_init(&tstr) ; spice_dstring_init(&ustr) ;