Use stdbool instead of homebrewed boolean

This commit is contained in:
bapt 2015-05-05 08:15:10 +00:00
parent 09ff591b15
commit c5d7e189d1
3 changed files with 64 additions and 69 deletions

View File

@ -31,9 +31,7 @@
* $FreeBSD$ * $FreeBSD$
*/ */
typedef int boolean; extern bool _escaped; /* if last character was an escape */
extern boolean _escaped; /* if last character was an escape */
extern char *s_start; /* start of the current string */ extern char *s_start; /* start of the current string */
extern char *l_acmbeg; /* string introducing a comment */ extern char *l_acmbeg; /* string introducing a comment */
extern char *l_acmend; /* string ending a comment */ extern char *l_acmend; /* string ending a comment */
@ -45,11 +43,11 @@ extern char *l_combeg; /* string introducing a comment */
extern char *l_comend; /* string ending a comment */ extern char *l_comend; /* string ending a comment */
extern char l_escape; /* character used to escape characters */ extern char l_escape; /* character used to escape characters */
extern char *l_keywds[]; /* keyword table address */ extern char *l_keywds[]; /* keyword table address */
extern boolean l_onecase; /* upper and lower case are equivalent */ extern bool l_onecase; /* upper and lower case are equivalent */
extern char *l_prcbeg; /* regular expr for procedure begin */ extern char *l_prcbeg; /* regular expr for procedure begin */
extern char *l_strbeg; /* delimiter for string constant */ extern char *l_strbeg; /* delimiter for string constant */
extern char *l_strend; /* delimiter for string constant */ extern char *l_strend; /* delimiter for string constant */
extern boolean l_toplex; /* procedures only defined at top lex level */ extern bool l_toplex; /* procedures only defined at top lex level */
extern const char *language; /* the language indicator */ extern const char *language; /* the language indicator */
#include <sys/cdefs.h> #include <sys/cdefs.h>

View File

@ -44,19 +44,18 @@ static const char sccsid[] = "@(#)regexp.c 8.1 (Berkeley) 6/6/93";
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include "extern.h" #include "extern.h"
#define FALSE 0
#define TRUE !(FALSE)
#define NIL 0 #define NIL 0
static void expconv(void); static void expconv(void);
boolean _escaped; /* true if we are currently _escaped */ bool _escaped; /* true if we are currently x_escaped */
char *s_start; /* start of string */ char *s_start; /* start of string */
boolean l_onecase; /* true if upper and lower equivalent */ bool l_onecase; /* true if upper and lower equivalent */
#define makelower(c) (isupper((c)) ? tolower((c)) : (c)) #define makelower(c) (isupper((c)) ? tolower((c)) : (c))
@ -352,13 +351,13 @@ expmatch (register char *s, register char *re, register char *mstring)
{ {
register char *cs; /* the current symbol */ register char *cs; /* the current symbol */
register char *ptr,*s1; /* temporary pointer */ register char *ptr,*s1; /* temporary pointer */
boolean matched; /* a temporary boolean */ bool matched; /* a temporary bool */
/* initial conditions */ /* initial conditions */
if (re == NIL) if (re == NIL)
return (NIL); return (NIL);
cs = re; cs = re;
matched = FALSE; matched = false;
/* loop till expression string is exhausted (or at least pretty tired) */ /* loop till expression string is exhausted (or at least pretty tired) */
while (*cs) { while (*cs) {
@ -464,12 +463,12 @@ expmatch (register char *s, register char *re, register char *mstring)
*s1 == '~' || *s1 == '~' ||
/* C++ scope operator */ /* C++ scope operator */
(strlen(s1) > 1 && *s1 == ':' && s1[1] == ':' && (strlen(s1) > 1 && *s1 == ':' && s1[1] == ':' &&
(s1++, TRUE)))) (s1++, true))))
return (NIL); return (NIL);
if (*s1 == '\\') if (*s1 == '\\')
_escaped = _escaped ? FALSE : TRUE; _escaped = _escaped ? false : true;
else else
_escaped = FALSE; _escaped = false;
} while (*s1++); } while (*s1++);
return (NIL); return (NIL);
@ -497,9 +496,9 @@ expmatch (register char *s, register char *re, register char *mstring)
return (NIL); return (NIL);
} }
if (*s1 == '\\') if (*s1 == '\\')
_escaped = _escaped ? FALSE : TRUE; _escaped = _escaped ? false : true;
else else
_escaped = FALSE; _escaped = false;
} while (*s1++); } while (*s1++);
return (NIL); return (NIL);

View File

@ -47,13 +47,12 @@ static const char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93";
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "pathnames.h" #include "pathnames.h"
#include "extern.h" #include "extern.h"
#define FALSE 0
#define TRUE !(FALSE)
#define NIL 0 #define NIL 0
#define STANDARD 0 #define STANDARD 0
#define ALTERNATE 1 #define ALTERNATE 1
@ -70,8 +69,8 @@ static const char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93";
#define PSMAX 20 /* size of procedure name stacking */ #define PSMAX 20 /* size of procedure name stacking */
static int iskw(char *); static int iskw(char *);
static boolean isproc(char *); static bool isproc(char *);
static void putKcp(char *, char *, boolean); static void putKcp(char *, char *, bool);
static void putScp(char *); static void putScp(char *);
static void putcp(int); static void putcp(int);
static int tabs(char *, char *); static int tabs(char *, char *);
@ -81,13 +80,13 @@ static int width(char *, char *);
* The state variables * The state variables
*/ */
static boolean filter = FALSE; /* act as a filter (like eqn) */ static bool filter = false; /* act as a filter (like eqn) */
static boolean inchr; /* in a string constant */ static bool inchr; /* in a string constant */
static boolean incomm; /* in a comment of the primary type */ static bool incomm; /* in a comment of the primary type */
static boolean idx = FALSE; /* form an index */ static bool idx = false; /* form an index */
static boolean instr; /* in a string constant */ static bool instr; /* in a string constant */
static boolean nokeyw = FALSE; /* no keywords being flagged */ static bool nokeyw = false; /* no keywords being flagged */
static boolean pass = FALSE; /* static bool pass = false; /*
* when acting as a filter, pass indicates * when acting as a filter, pass indicates
* whether we are currently processing * whether we are currently processing
* input. * input.
@ -100,7 +99,7 @@ static char * defsfile[2] = { _PATH_VGRINDEFS, 0 };
static int margin; static int margin;
static int plstack[PSMAX]; /* the procedure nesting level stack */ static int plstack[PSMAX]; /* the procedure nesting level stack */
static char pname[BUFSIZ+1]; static char pname[BUFSIZ+1];
static boolean prccont; /* continue last procedure */ static bool prccont; /* continue last procedure */
static int psptr; /* the stack index of the current procedure */ static int psptr; /* the stack index of the current procedure */
static char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */ static char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */
@ -122,7 +121,7 @@ char *l_nocom; /* regexp for non-comments */
char *l_prcbeg; /* regular expr for procedure begin */ char *l_prcbeg; /* regular expr for procedure begin */
char *l_strbeg; /* delimiter for string constant */ char *l_strbeg; /* delimiter for string constant */
char *l_strend; /* delimiter for string constant */ char *l_strend; /* delimiter for string constant */
boolean l_toplex; /* procedures only defined at top lex level */ bool l_toplex; /* procedures only defined at top lex level */
const char *language = "c"; /* the language indicator */ const char *language = "c"; /* the language indicator */
#define ps(x) printf("%s", x) #define ps(x) printf("%s", x)
@ -158,7 +157,7 @@ main(int argc, char **argv)
/* act as a filter like eqn */ /* act as a filter like eqn */
if (!strcmp(argv[0], "-f")) { if (!strcmp(argv[0], "-f")) {
filter++; filter = true;
argv[0] = argv[argc-1]; argv[0] = argv[argc-1];
argv[argc-1] = strdup("-"); argv[argc-1] = strdup("-");
continue; continue;
@ -172,13 +171,13 @@ main(int argc, char **argv)
/* build an index */ /* build an index */
if (!strcmp(argv[0], "-x")) { if (!strcmp(argv[0], "-x")) {
idx++; idx = true;
argv[0] = strdup("-n"); argv[0] = strdup("-n");
} }
/* indicate no keywords */ /* indicate no keywords */
if (!strcmp(argv[0], "-n")) { if (!strcmp(argv[0], "-n")) {
nokeyw++; nokeyw = true;
argc--, argv++; argc--, argv++;
continue; continue;
} }
@ -235,7 +234,7 @@ main(int argc, char **argv)
exit(0); exit(0);
} }
if (cgetustr(defs, "kw", &cp) == -1) if (cgetustr(defs, "kw", &cp) == -1)
nokeyw = TRUE; nokeyw = true;
else { else {
char **cpp; char **cpp;
@ -280,10 +279,10 @@ main(int argc, char **argv)
/* initialize the program */ /* initialize the program */
incomm = FALSE; incomm = false;
instr = FALSE; instr = false;
inchr = FALSE; inchr = false;
_escaped = FALSE; _escaped = false;
blklevel = 0; blklevel = 0;
for (psptr=0; psptr<PSMAX; psptr++) { for (psptr=0; psptr<PSMAX; psptr++) {
pstack[psptr][0] = '\0'; pstack[psptr][0] = '\0';
@ -319,12 +318,12 @@ main(int argc, char **argv)
if (buf[0] == '.') { if (buf[0] == '.') {
printf("%s", buf); printf("%s", buf);
if (!strncmp (buf+1, "vS", 2)) if (!strncmp (buf+1, "vS", 2))
pass = TRUE; pass = true;
if (!strncmp (buf+1, "vE", 2)) if (!strncmp (buf+1, "vE", 2))
pass = FALSE; pass = false;
continue; continue;
} }
prccont = FALSE; prccont = false;
if (!filter || pass) if (!filter || pass)
putScp(buf); putScp(buf);
else else
@ -361,7 +360,7 @@ putScp(os)
char *nocomptr; /* end of a non-comment delimiter */ char *nocomptr; /* end of a non-comment delimiter */
s_start = os; /* remember the start for expmatch */ s_start = os; /* remember the start for expmatch */
_escaped = FALSE; _escaped = false;
if (nokeyw || incomm || instr) if (nokeyw || incomm || instr)
goto skip; goto skip;
if (isproc(s)) { if (isproc(s)) {
@ -393,7 +392,7 @@ putScp(os)
if ((nocomptr <= comptr || comptr == NIL) if ((nocomptr <= comptr || comptr == NIL)
&& (nocomptr <= acmptr || acmptr == NIL)) { && (nocomptr <= acmptr || acmptr == NIL)) {
/* continue after non-comment */ /* continue after non-comment */
putKcp (s, nocomptr-1, FALSE); putKcp (s, nocomptr-1, false);
s = nocomptr; s = nocomptr;
continue; continue;
} }
@ -405,9 +404,9 @@ putScp(os)
&& (comptr < chrptr || chrptr == NIL) && (comptr < chrptr || chrptr == NIL)
&& (comptr < blksptr || blksptr == NIL) && (comptr < blksptr || blksptr == NIL)
&& (comptr < blkeptr || blkeptr == NIL)) { && (comptr < blkeptr || blkeptr == NIL)) {
putKcp (s, comptr-1, FALSE); putKcp (s, comptr-1, false);
s = comptr; s = comptr;
incomm = TRUE; incomm = true;
comtype = STANDARD; comtype = STANDARD;
if (s != os) if (s != os)
ps ("\\c"); ps ("\\c");
@ -421,9 +420,9 @@ putScp(os)
&& (acmptr < chrptr || chrptr == NIL) && (acmptr < chrptr || chrptr == NIL)
&& (acmptr < blksptr || blksptr == NIL) && (acmptr < blksptr || blksptr == NIL)
&& (acmptr < blkeptr || blkeptr == NIL)) { && (acmptr < blkeptr || blkeptr == NIL)) {
putKcp (s, acmptr-1, FALSE); putKcp (s, acmptr-1, false);
s = acmptr; s = acmptr;
incomm = TRUE; incomm = true;
comtype = ALTERNATE; comtype = ALTERNATE;
if (s != os) if (s != os)
ps ("\\c"); ps ("\\c");
@ -436,9 +435,9 @@ putScp(os)
if ((strptr < chrptr || chrptr == NIL) if ((strptr < chrptr || chrptr == NIL)
&& (strptr < blksptr || blksptr == NIL) && (strptr < blksptr || blksptr == NIL)
&& (strptr < blkeptr || blkeptr == NIL)) { && (strptr < blkeptr || blkeptr == NIL)) {
putKcp (s, strptr-1, FALSE); putKcp(s, strptr-1, false);
s = strptr; s = strptr;
instr = TRUE; instr = true;
continue; continue;
} }
@ -446,16 +445,16 @@ putScp(os)
if (chrptr != NIL) if (chrptr != NIL)
if ((chrptr < blksptr || blksptr == NIL) if ((chrptr < blksptr || blksptr == NIL)
&& (chrptr < blkeptr || blkeptr == NIL)) { && (chrptr < blkeptr || blkeptr == NIL)) {
putKcp (s, chrptr-1, FALSE); putKcp(s, chrptr-1, false);
s = chrptr; s = chrptr;
inchr = TRUE; inchr = true;
continue; continue;
} }
/* end of a lexical block */ /* end of a lexical block */
if (blkeptr != NIL) { if (blkeptr != NIL) {
if (blkeptr < blksptr || blksptr == NIL) { if (blkeptr < blksptr || blksptr == NIL) {
putKcp (s, blkeptr - 1, FALSE); putKcp(s, blkeptr - 1, false);
s = blkeptr; s = blkeptr;
if (blklevel > 0 /* sanity */) if (blklevel > 0 /* sanity */)
blklevel--; blklevel--;
@ -469,7 +468,7 @@ putScp(os)
/* see if we should print the last proc name */ /* see if we should print the last proc name */
if (--psptr >= 0) if (--psptr >= 0)
prccont = TRUE; prccont = true;
else else
psptr = -1; psptr = -1;
} }
@ -479,7 +478,7 @@ putScp(os)
/* start of a lexical block */ /* start of a lexical block */
if (blksptr != NIL) { if (blksptr != NIL) {
putKcp (s, blksptr - 1, FALSE); putKcp(s, blksptr - 1, false);
s = blksptr; s = blksptr;
blklevel++; blklevel++;
continue; continue;
@ -492,17 +491,17 @@ putScp(os)
if (((comtype == STANDARD) && (comptr != NIL)) || if (((comtype == STANDARD) && (comptr != NIL)) ||
((comtype == ALTERNATE) && (acmptr != NIL))) { ((comtype == ALTERNATE) && (acmptr != NIL))) {
if (comtype == STANDARD) { if (comtype == STANDARD) {
putKcp (s, comptr-1, TRUE); putKcp(s, comptr-1, true);
s = comptr; s = comptr;
} else { } else {
putKcp (s, acmptr-1, TRUE); putKcp(s, acmptr-1, true);
s = acmptr; s = acmptr;
} }
incomm = FALSE; incomm = false;
ps("\\c\n'-C\n"); ps("\\c\n'-C\n");
continue; continue;
} else { } else {
putKcp (s, s + strlen(s) -1, TRUE); putKcp(s, s + strlen(s) -1, true);
s = s + strlen(s); s = s + strlen(s);
continue; continue;
} }
@ -510,12 +509,12 @@ putScp(os)
/* check for end of string */ /* check for end of string */
} else if (instr) { } else if (instr) {
if ((strptr = expmatch (s, l_strend, dummy)) != NIL) { if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
putKcp (s, strptr-1, TRUE); putKcp(s, strptr-1, true);
s = strptr; s = strptr;
instr = FALSE; instr = false;
continue; continue;
} else { } else {
putKcp (s, s+strlen(s)-1, TRUE); putKcp(s, s+strlen(s)-1, true);
s = s + strlen(s); s = s + strlen(s);
continue; continue;
} }
@ -523,19 +522,19 @@ putScp(os)
/* check for end of character string */ /* check for end of character string */
} else if (inchr) { } else if (inchr) {
if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) { if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
putKcp (s, chrptr-1, TRUE); putKcp(s, chrptr-1, true);
s = chrptr; s = chrptr;
inchr = FALSE; inchr = false;
continue; continue;
} else { } else {
putKcp (s, s+strlen(s)-1, TRUE); putKcp(s, s+strlen(s)-1, true);
s = s + strlen(s); s = s + strlen(s);
continue; continue;
} }
} }
/* print out the line */ /* print out the line */
putKcp (s, s + strlen(s) -1, FALSE); putKcp(s, s + strlen(s) -1, false);
s = s + strlen(s); s = s + strlen(s);
} while (*s); } while (*s);
} }
@ -546,7 +545,7 @@ putScp(os)
* force: true if we should force nokeyw * force: true if we should force nokeyw
*/ */
static void static void
putKcp (char *start, char *end, boolean force) putKcp(char *start, char *end, bool force)
{ {
int i; int i;
int xfld = 0; int xfld = 0;
@ -687,15 +686,15 @@ putcp(c)
/* /*
* look for a process beginning on this line * look for a process beginning on this line
*/ */
static boolean static bool
isproc(char *s) isproc(char *s)
{ {
pname[0] = '\0'; pname[0] = '\0';
if (!l_toplex || blklevel == 0) if (!l_toplex || blklevel == 0)
if (expmatch (s, l_prcbeg, pname) != NIL) { if (expmatch (s, l_prcbeg, pname) != NIL) {
return (TRUE); return (true);
} }
return (FALSE); return (false);
} }
@ -716,4 +715,3 @@ iskw(register char *s)
return (i); return (i);
return (0); return (0);
} }