summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cppsetup.c9
-rw-r--r--def.h31
-rw-r--r--imakemdep.h2
-rw-r--r--include.c16
-rw-r--r--main.c39
-rw-r--r--parse.c8
-rw-r--r--pr.c8
7 files changed, 54 insertions, 59 deletions
diff --git a/cppsetup.c b/cppsetup.c
index b598670..5824253 100644
--- a/cppsetup.c
+++ b/cppsetup.c
@@ -29,10 +29,11 @@ in this Software without prior written authorization from The Open Group.
#include "def.h"
#include "ifparser.h"
+
struct _parse_data {
struct filepointer *filep;
struct inclist *inc;
- char *filename;
+ const char *filename;
const char *line;
};
@@ -41,7 +42,7 @@ my_if_errors (IfParser *ip, const char *cp, const char *expecting)
{
struct _parse_data *pd = (struct _parse_data *) ip->data;
int lineno = pd->filep->f_line;
- char *filename = pd->filename;
+ const char *filename = pd->filename;
char prefix[300];
int prefixlen;
int i;
@@ -111,8 +112,8 @@ my_eval_variable (IfParser *ip, const char *var, int len)
}
int
-cppsetup(char *filename,
- char *line,
+cppsetup(const char *filename,
+ const char *line,
struct filepointer *filep,
struct inclist *inc)
{
diff --git a/def.h b/def.h
index 2b60651..ca37e73 100644
--- a/def.h
+++ b/def.h
@@ -120,7 +120,7 @@ struct inclist {
};
struct filepointer {
- char *f_name;
+ const char *f_name;
char *f_p;
char *f_base;
char *f_end;
@@ -133,21 +133,23 @@ struct filepointer {
#include <stdlib.h>
-char *copy(char *str);
-int match(char *str, char **list);
-char *base_name(char *file);
+#define copy(s) strdup(s)
+int match(const char *str, const char * const *list);
+char *base_name(const char *file);
char *getnextline(struct filepointer *fp);
struct symtab **slookup(char *symbol, struct inclist *file);
struct symtab **isdefined(char *symbol, struct inclist *file,
struct inclist **srcfile);
struct symtab **fdefined(char *symbol, struct inclist *file,
struct inclist **srcfile);
-struct filepointer *getfile(char *file);
+struct filepointer *getfile(const char *file);
void included_by(struct inclist *ip,
struct inclist *newfile);
-struct inclist *newinclude(char *newfile, char *incstring);
+struct inclist *newinclude(const char *newfile,
+ const char *incstring);
void inc_clean (void);
-struct inclist *inc_path(char *file, char *include, int type);
+struct inclist *inc_path(const char *file, const char *include,
+ int type);
void freefile(struct filepointer *fp);
@@ -160,19 +162,20 @@ int find_includes(struct filepointer *filep,
int recursion, boolean failOK);
void recursive_pr_include(struct inclist *head,
- char *file, char *base);
+ const char *file,
+ const char *base);
void add_include(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
- char *include, int type,
+ const char *include, int type,
boolean failOK);
-int cppsetup(char *filename,
- char *line,
+int cppsetup(const char *filename,
+ const char *line,
struct filepointer *filep,
struct inclist *inc);
-extern void fatalerr(char *, ...);
-extern void warning(char *, ...);
-extern void warning1(char *, ...);
+extern void fatalerr(const char *, ...);
+extern void warning(const char *, ...);
+extern void warning1(const char *, ...);
diff --git a/imakemdep.h b/imakemdep.h
index c4533e1..60222a2 100644
--- a/imakemdep.h
+++ b/imakemdep.h
@@ -48,7 +48,7 @@ in this Software without prior written authorization from The Open Group.
#undef DEF_STRINGIFY
#define DEF_EVALUATE(__x) #__x
#define DEF_STRINGIFY(_x) DEF_EVALUATE(_x)
-struct symtab predefs[] = {
+const struct symtab predefs[] = {
#ifdef apollo
{"apollo", "1"},
#endif
diff --git a/include.c b/include.c
index 65ce783..53935c5 100644
--- a/include.c
+++ b/include.c
@@ -31,14 +31,14 @@ in this Software without prior written authorization from The Open Group.
extern struct inclist inclist[ MAXFILES ],
*inclistp, *inclistnext;
-extern char *includedirs[ ],
- **includedirsnext;
+extern const char *includedirs[ ],
+ **includedirsnext;
extern char *notdotdot[ ];
extern boolean show_where_not;
extern boolean warn_multiple;
static boolean
-isdot(char *p)
+isdot(const char *p)
{
if(p && *p++ == '.' && *p++ == '\0')
return(TRUE);
@@ -46,7 +46,7 @@ isdot(char *p)
}
static boolean
-isdotdot(char *p)
+isdotdot(const char *p)
{
if(p && *p++ == '.' && *p++ == '.' && *p++ == '\0')
return(TRUE);
@@ -54,7 +54,7 @@ isdotdot(char *p)
}
static boolean
-issymbolic(char *dir, char *component)
+issymbolic(const char *dir, const char *component)
{
#ifdef S_IFLNK
struct stat st;
@@ -153,7 +153,7 @@ remove_dotdot(char *path)
* Add an include file to the list of those included by 'file'.
*/
struct inclist *
-newinclude(char *newfile, char *incstring)
+newinclude(const char *newfile, const char *incstring)
{
register struct inclist *ip;
@@ -235,10 +235,10 @@ inc_clean (void)
}
struct inclist *
-inc_path(char *file, char *include, int type)
+inc_path(const char *file, const char *include, int type)
{
static char path[ BUFSIZ ];
- register char **pp, *p;
+ register const char **pp, *p;
register struct inclist *ip;
struct stat st;
diff --git a/main.c b/main.c
index 6ae60f0..802ef3d 100644
--- a/main.c
+++ b/main.c
@@ -66,9 +66,9 @@ int _debugmask;
#define DASH_INC_PRE "#include \""
#define DASH_INC_POST "\""
-char *ProgramName;
+const char *ProgramName;
-char *directives[] = {
+const char * const directives[] = {
"if",
"ifdef",
"ifndef",
@@ -97,7 +97,7 @@ struct inclist inclist[ MAXFILES ],
maininclist;
static char *filelist[ MAXFILES ];
-char *includedirs[ MAXDIRS + 1 ],
+const char *includedirs[ MAXDIRS + 1 ],
**includedirsnext = includedirs;
char *notdotdot[ MAXDIRS ];
static int cmdinc_count = 0;
@@ -114,7 +114,7 @@ boolean show_where_not = FALSE;
boolean warn_multiple = FALSE;
static void setfile_cmdinc(struct filepointer *filep, long count, char **list);
-static void redirect(char *line, char *makefile);
+static void redirect(const char *line, const char *makefile);
static
#ifdef RETSIGTYPE
@@ -156,12 +156,12 @@ int
main(int argc, char *argv[])
{
char **fp = filelist;
- char **incp = includedirs;
+ const char **incp = includedirs;
char *p;
struct inclist *ip;
char *makefile = NULL;
struct filepointer *filecontent;
- struct symtab *psymp = predefs;
+ const struct symtab *psymp = predefs;
char *endmarker = NULL;
char *defincdir = NULL;
char **undeflist = NULL;
@@ -550,7 +550,7 @@ elim_cr(char *buf, int sz)
#endif
struct filepointer *
-getfile(char *file)
+getfile(const char *file)
{
int fd;
struct filepointer *content;
@@ -600,16 +600,8 @@ freefile(struct filepointer *fp)
free(fp);
}
-char *copy(char *str)
-{
- char *p = (char *)malloc(strlen(str) + 1);
-
- strcpy(p, str);
- return(p);
-}
-
int
-match(char *str, char **list)
+match(const char *str, const char * const *list)
{
int i;
@@ -750,11 +742,10 @@ done:
* Strip the file name down to what we want to see in the Makefile.
* It will have objprefix and objsuffix around it.
*/
-char *base_name(char *file)
+char *base_name(const char *in_file)
{
char *p;
-
- file = copy(file);
+ char *file = copy(in_file);
for(p=file+strlen(file); p>file && *p != '.'; p--) ;
if (*p == '.')
@@ -785,8 +776,8 @@ int rename (char *from, char *to)
}
#endif /* NEED_RENAME */
-void
-redirect(char *line, char *makefile)
+static void
+redirect(const char *line, const char *makefile)
{
struct stat st;
FILE *fdin, *fdout;
@@ -856,7 +847,7 @@ redirect(char *line, char *makefile)
}
void
-fatalerr(char *msg, ...)
+fatalerr(const char *msg, ...)
{
va_list args;
fprintf(stderr, "%s: error: ", ProgramName);
@@ -867,7 +858,7 @@ fatalerr(char *msg, ...)
}
void
-warning(char *msg, ...)
+warning(const char *msg, ...)
{
va_list args;
fprintf(stderr, "%s: warning: ", ProgramName);
@@ -877,7 +868,7 @@ warning(char *msg, ...)
}
void
-warning1(char *msg, ...)
+warning1(const char *msg, ...)
{
va_list args;
va_start(args, msg);
diff --git a/parse.c b/parse.c
index 5248293..36dc558 100644
--- a/parse.c
+++ b/parse.c
@@ -28,12 +28,12 @@ in this Software without prior written authorization from The Open Group.
#include "def.h"
-extern char *directives[];
+extern const char * const directives[];
extern struct inclist inclist[ MAXFILES ],
*inclistnext,
maininclist;
-extern char *includedirs[ ],
- **includedirsnext;
+extern const char *includedirs[ ],
+ **includedirsnext;
static int deftype (char *line, struct filepointer *filep,
struct inclist *file_red, struct inclist *file,
@@ -555,7 +555,7 @@ find_includes(struct filepointer *filep, struct inclist *file,
struct inclist *file_red, int recursion, boolean failOK)
{
struct inclist *inclistp;
- char **includedirsp;
+ const char **includedirsp;
register char *line;
register int type;
boolean recfailOK;
diff --git a/pr.c b/pr.c
index 5d0e1c4..dd9ee6e 100644
--- a/pr.c
+++ b/pr.c
@@ -39,7 +39,7 @@ extern boolean show_where_not;
void
add_include(struct filepointer *filep, struct inclist *file,
- struct inclist *file_red, char *include, int type,
+ struct inclist *file_red, const char *include, int type,
boolean failOK)
{
register struct inclist *newfile;
@@ -75,9 +75,9 @@ add_include(struct filepointer *filep, struct inclist *file,
}
static void
-pr(struct inclist *ip, char *file, char *base)
+pr(struct inclist *ip, const char *file, const char *base)
{
- static char *lastfile;
+ static const char *lastfile;
static int current_len;
register int len, i;
char buf[ BUFSIZ ];
@@ -110,7 +110,7 @@ pr(struct inclist *ip, char *file, char *base)
}
void
-recursive_pr_include(struct inclist *head, char *file, char *base)
+recursive_pr_include(struct inclist *head, const char *file, const char *base)
{
int i;