summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorragge <ragge>2010-02-25 15:49:00 +0000
committerragge <ragge>2010-02-25 15:49:00 +0000
commit53102bf9fdca6424c2e4872ad15625628f612198 (patch)
tree9b47b67f3ae31fdff72e4923656d7dd4bc58d4ac
parentc89b3b9d6a960b3a1f2064acd6820d26b3153ee8 (diff)
Fix const usage. From Iain Hibbert.
-rw-r--r--cpp.c86
-rw-r--r--cpp.h26
-rw-r--r--cpy.y4
-rw-r--r--token.c13
4 files changed, 66 insertions, 63 deletions
diff --git a/cpp.c b/cpp.c
index aac6129..769f692 100644
--- a/cpp.c
+++ b/cpp.c
@@ -167,7 +167,7 @@ usch *stringbuf = sbf;
#define FIND 0
#define ENTER 1
-static void expdef(usch *proto, struct recur *, int gotwarn);
+static void expdef(const usch *proto, struct recur *, int gotwarn);
void define(void);
static int canexpand(struct recur *, struct symtab *np);
void include(void);
@@ -175,8 +175,8 @@ void include_next(void);
void line(void);
void flbuf(void);
void usage(void);
-usch *xstrdup(char *str);
-usch *prtprag(usch *opb);
+usch *xstrdup(const char *str);
+const usch *prtprag(const usch *opb);
int
@@ -186,7 +186,7 @@ main(int argc, char **argv)
struct incs *w, *w2;
struct symtab *nl;
register int ch;
- usch *fn1, *fn2;
+ const usch *fn1, *fn2;
#ifdef TIMING
struct timeval t1, t2;
@@ -262,11 +262,11 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- filloc = lookup((usch *)"__FILE__", ENTER);
- linloc = lookup((usch *)"__LINE__", ENTER);
- pragloc = lookup((usch *)"_Pragma", ENTER);
- filloc->value = linloc->value = (usch *)""; /* Just something */
- pragloc->value = (usch *)"";
+ filloc = lookup((const usch *)"__FILE__", ENTER);
+ linloc = lookup((const usch *)"__LINE__", ENTER);
+ pragloc = lookup((const usch *)"_Pragma", ENTER);
+ filloc->value = linloc->value = (const usch *)""; /* Just something */
+ pragloc->value = (const usch *)"";
if (tflag == 0) {
time_t t = time(NULL);
@@ -275,22 +275,22 @@ main(int argc, char **argv)
/*
* Manually move in the predefined macros.
*/
- nl = lookup((usch *)"__TIME__", ENTER);
+ nl = lookup((const usch *)"__TIME__", ENTER);
savch(0); savch('"'); n[19] = 0; savstr(&n[11]); savch('"');
savch(OBJCT);
nl->value = stringbuf-1;
- nl = lookup((usch *)"__DATE__", ENTER);
+ nl = lookup((const usch *)"__DATE__", ENTER);
savch(0); savch('"'); n[24] = n[11] = 0; savstr(&n[4]);
savstr(&n[20]); savch('"'); savch(OBJCT);
nl->value = stringbuf-1;
- nl = lookup((usch *)"__STDC__", ENTER);
+ nl = lookup((const usch *)"__STDC__", ENTER);
savch(0); savch('1'); savch(OBJCT);
nl->value = stringbuf-1;
- nl = lookup((usch *)"__STDC_VERSION__", ENTER);
- savch(0); savstr((usch *)"199901L"); savch(OBJCT);
+ nl = lookup((const usch *)"__STDC_VERSION__", ENTER);
+ savch(0); savstr((const usch *)"199901L"); savch(OBJCT);
nl->value = stringbuf-1;
}
@@ -322,7 +322,7 @@ main(int argc, char **argv)
fn1 = fn2 = (usch *)argv[0];
} else {
fn1 = NULL;
- fn2 = (usch *)"";
+ fn2 = (const usch *)"";
}
if (pushfile(fn1, fn2, 0, NULL))
error("cannot open %s", argv[0]);
@@ -381,7 +381,7 @@ gotident(struct symtab *nl)
c = sloscan();
}
if (c != EXPAND) {
- unpstr((usch *)yytext);
+ unpstr((const usch *)yytext);
if (ss2 != stringbuf)
unpstr(ss2);
unpstr(nl->namep);
@@ -497,7 +497,7 @@ bad: error("bad line directive");
* Return 1 on success.
*/
static int
-fsrch(usch *fn, int idx, struct incs *w)
+fsrch(const usch *fn, int idx, struct incs *w)
{
int i;
@@ -627,7 +627,7 @@ getcmnt(void)
if (c == '*') {
c = cinput();
if (c == '/') {
- savstr((usch *)"*/");
+ savstr((const usch *)"*/");
return;
}
cunput(c);
@@ -641,7 +641,7 @@ getcmnt(void)
* Compare two replacement lists, taking in account comments etc.
*/
static int
-cmprepl(usch *o, usch *n)
+cmprepl(const usch *o, const usch *n)
{
for (; *o; o--, n--) {
/* comment skip */
@@ -905,7 +905,7 @@ id: savstr((usch *)yytext);
#ifdef CPP_DEBUG
if (dflag) {
- usch *w = np->value;
+ const usch *w = np->value;
printf("!define: ");
if (*w == OBJCT)
@@ -1038,7 +1038,8 @@ struct symtab *sp;
struct recur *rp;
{
struct recur rp2;
- register usch *vp, *cp, *obp;
+ register const usch *vp, *cp;
+ register usch *obp;
int c, nl;
DPRINT(("subst: %s\n", sp->namep));
@@ -1208,7 +1209,7 @@ expmac(struct recur *rp)
stringbuf = och;
continue; /* New longer identifier */
}
- unpstr((usch *)yytext);
+ unpstr((const usch *)yytext);
if (orgexp == -1)
cunput(EXPAND);
else if (orgexp == -2)
@@ -1255,7 +1256,7 @@ expmac(struct recur *rp)
if (stksv)
savstr(stksv);
} else {
- unpstr((usch *)yytext);
+ unpstr((const usch *)yytext);
if (stksv)
unpstr(stksv);
savstr(nl->namep);
@@ -1303,13 +1304,14 @@ def: default:
* result is written on top of heap
*/
void
-expdef(usch *vp, struct recur *rp, int gotwarn)
+expdef(const usch *vp, struct recur *rp, int gotwarn)
{
- usch **args, *sptr, *ap, *bp, *sp;
+ const usch **args, *ap, *bp, *sp;
+ usch *sptr;
int narg, c, i, plev, snuff, instr;
int ellips = 0;
- DPRINT(("expdef rp %s\n", (rp ? (char *)rp->sp->namep : "")));
+ DPRINT(("expdef rp %s\n", (rp ? (const char *)rp->sp->namep : "")));
if ((c = sloscan()) != '(')
error("got %c, expected (", c);
if (vp[1] == VARG) {
@@ -1366,7 +1368,7 @@ expdef(usch *vp, struct recur *rp, int gotwarn)
savch('\0');
}
if (ellips)
- args[i] = (usch *)"";
+ args[i] = (const usch *)"";
if (ellips && c != ')') {
args[i] = stringbuf;
plev = 0;
@@ -1435,7 +1437,7 @@ expdef(usch *vp, struct recur *rp, int gotwarn)
} else if (sp[-1] == GCCARG) {
ap = args[narg];
if (ap[0] == 0)
- ap = (usch *)"0";
+ ap = (const usch *)"0";
bp = ap;
sp--;
#endif
@@ -1488,7 +1490,7 @@ expdef(usch *vp, struct recur *rp, int gotwarn)
}
usch *
-savstr(usch *str)
+savstr(const usch *str)
{
usch *rv = stringbuf;
@@ -1515,9 +1517,9 @@ canexpand(struct recur *rp, struct symtab *np)
}
void
-unpstr(usch *c)
+unpstr(const usch *c)
{
- usch *d = c;
+ const usch *d = c;
while (*d)
d++;
@@ -1545,7 +1547,7 @@ putch(int ch)
}
void
-putstr(usch *s)
+putstr(const usch *s)
{
for (; *s; s++) {
if (*s == PRAGS) {
@@ -1585,7 +1587,7 @@ num2str(int num)
* saves result on heap.
*/
usch *
-sheap(char *fmt, ...)
+sheap(const char *fmt, ...)
{
va_list ap;
usch *op = stringbuf;
@@ -1658,7 +1660,7 @@ static int numsyms;
* Allocate a symtab struct and store the string.
*/
static struct symtab *
-getsymtab(usch *str)
+getsymtab(const usch *str)
{
struct symtab *sp = malloc(sizeof(struct symtab));
@@ -1667,7 +1669,7 @@ getsymtab(usch *str)
sp->namep = savstr(str);
savch('\0');
sp->value = NULL;
- sp->file = ifiles ? ifiles->orgfn : (usch *)"<initial>";
+ sp->file = ifiles ? ifiles->orgfn : (const usch *)"<initial>";
sp->line = ifiles ? ifiles->lineno : 0;
return sp;
}
@@ -1677,12 +1679,12 @@ getsymtab(usch *str)
* Only do full string matching, no pointer optimisations.
*/
struct symtab *
-lookup(usch *key, int enterf)
+lookup(const usch *key, int enterf)
{
struct symtab *sp;
struct tree *w, *new, *last;
int len, cix, bit, fbit, svbit, ix, bitno;
- usch *k, *m, *sm;
+ const usch *k, *m, *sm;
/* Count full string length */
for (k = key, len = 0; *k; k++, len++)
@@ -1779,7 +1781,7 @@ lookup(usch *key, int enterf)
}
usch *
-xstrdup(char *str)
+xstrdup(const char *str)
{
size_t len = strlen(str)+1;
usch *rv;
@@ -1790,13 +1792,13 @@ xstrdup(char *str)
return rv;
}
-usch *
-prtprag(usch *s)
+const usch *
+prtprag(const usch *s)
{
int ch;
s++;
- putstr((usch *)"\n#pragma ");
+ putstr((const usch *)"\n#pragma ");
while (*s != PRAGE) {
if (*s == 'L')
s++;
@@ -1812,7 +1814,7 @@ prtprag(usch *s)
putch(*s);
}
}
- putstr((usch *)"\n");
+ putstr((const usch *)"\n");
prtline();
return ++s;
}
diff --git a/cpp.h b/cpp.h
index 2b3ad22..c32ffd5 100644
--- a/cpp.h
+++ b/cpp.h
@@ -70,8 +70,8 @@ extern int ofd;
/* definition for include file info */
struct includ {
struct includ *next;
- usch *fname; /* current fn, changed if #line found */
- usch *orgfn; /* current fn, not changed */
+ const usch *fname; /* current fn, changed if #line found */
+ const usch *orgfn; /* current fn, not changed */
int lineno;
int infil;
usch *curptr;
@@ -80,15 +80,15 @@ struct includ {
usch *buffer;
int idx;
void *incs;
- usch *fn;
+ const usch *fn;
usch bbuf[NAMEMAX+CPPBUF+1];
} *ifiles;
/* Symbol table entry */
struct symtab {
- usch *namep;
- usch *value;
- usch *file;
+ const usch *namep;
+ const usch *value;
+ const usch *file;
int line;
};
@@ -117,11 +117,11 @@ struct nd {
struct recur; /* not used outside cpp.c */
int subst(struct symtab *, struct recur *);
-struct symtab *lookup(usch *namep, int enterf);
+struct symtab *lookup(const usch *namep, int enterf);
usch *gotident(struct symtab *nl);
int slow; /* scan slowly for new tokens */
-int pushfile(usch *fname, usch *fn, int idx, void *incs);
+int pushfile(const usch *fname, const usch *fn, int idx, void *incs);
void popfile(void);
void prtline(void);
int yylex(void);
@@ -132,15 +132,15 @@ char *curfile(void);
void setline(int);
void setfile(char *);
int yyparse(void);
-void yyerror(char *);
-void unpstr(usch *);
-usch *savstr(usch *str);
+void yyerror(const char *);
+void unpstr(const usch *);
+usch *savstr(const usch *str);
void savch(int c);
void mainscan(void);
void putch(int);
-void putstr(usch *s);
+void putstr(const usch *s);
void line(void);
-usch *sheap(char *fmt, ...);
+usch *sheap(const char *fmt, ...);
void xwarning(usch *);
void xerror(usch *);
#ifdef HAVE_CPP_VARARG_MACRO_GCC
diff --git a/cpy.y b/cpy.y
index d226c2e..4d1a70b 100644
--- a/cpy.y
+++ b/cpy.y
@@ -65,7 +65,7 @@
#include "cpp.h"
-void yyerror(char *);
+void yyerror(const char *);
int yylex(void);
int setd(int l, int r);
@@ -201,7 +201,7 @@ term:
%%
void
-yyerror(char *err)
+yyerror(const char *err)
{
error(err);
}
diff --git a/token.c b/token.c
index 599da58..f0496b4 100644
--- a/token.c
+++ b/token.c
@@ -632,7 +632,8 @@ msdos: if ((c = inpch()) == '\n') {
static void
prinit(struct initar *it, struct includ *ic)
{
- char *a, *pre, *post;
+ const char *pre, *post;
+ char *a;
if (it->next)
prinit(it->next, ic);
@@ -673,7 +674,7 @@ prinit(struct initar *it, struct includ *ic)
* Return 0 on success, -1 if file to be included is not found.
*/
int
-pushfile(usch *file, usch *fn, int idx, void *incs)
+pushfile(const usch *file, const usch *fn, int idx, void *incs)
{
extern struct initar *initar;
struct includ ibuf;
@@ -684,14 +685,14 @@ pushfile(usch *file, usch *fn, int idx, void *incs)
ic->next = ifiles;
if (file != NULL) {
- if ((ic->infil = open((char *)file, O_RDONLY)) < 0)
+ if ((ic->infil = open((const char *)file, O_RDONLY)) < 0)
return -1;
ic->orgfn = ic->fname = file;
if (++inclevel > MAX_INCLEVEL)
error("Limit for nested includes exceeded");
} else {
ic->infil = 0;
- ic->orgfn = ic->fname = (usch *)"<stdin>";
+ ic->orgfn = ic->fname = (const usch *)"<stdin>";
}
ic->buffer = ic->bbuf+NAMEMAX;
ic->curptr = ic->buffer;
@@ -1052,7 +1053,7 @@ pragmastmt(void)
if (sloscan() != WSPACE)
error("bad pragma");
if (!flslvl)
- putstr((usch *)"#pragma ");
+ putstr((const usch *)"#pragma ");
do {
c = inch();
if (!flslvl)
@@ -1106,7 +1107,7 @@ chktg()
}
static struct {
- char *name;
+ const char *name;
void (*fun)(void);
} ppd[] = {
{ "ifndef", ifndefstmt },