1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Turn warnings on,

Add missing prototypes,
Make local functions static,
Sort extern.h by file,
Constify all char * that can be,
Copy temp file name so that eval does not modify its arguments.
This commit is contained in:
espie 1999-11-17 15:34:13 +00:00
parent 1ba4a53a2f
commit bb34cd6c7e
8 changed files with 138 additions and 112 deletions

View File

@ -1,10 +1,12 @@
# $OpenBSD: Makefile,v 1.4 1999/09/14 08:21:32 espie Exp $
# $OpenBSD: Makefile,v 1.5 1999/11/17 15:34:13 espie Exp $
# -DEXTENDED
# if you want the paste & spaste macros.
PROG= m4
CFLAGS+=-DEXTENDED
CFLAGS+=-DEXTENDED
CFLAGS+=-W -Wall -Wstrict-prototypes \
-Wno-unused -Wno-char-subscripts -Wno-sign-compare
SRCS= eval.c expr.c look.c main.c misc.c gnum4.c
MAN= m4.1

View File

@ -1,4 +1,4 @@
/* $OpenBSD: eval.c,v 1.19 1999/11/17 14:57:21 espie Exp $ */
/* $OpenBSD: eval.c,v 1.20 1999/11/17 15:34:13 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
static char rcsid[] = "$OpenBSD: eval.c,v 1.19 1999/11/17 14:57:21 espie Exp $";
static char rcsid[] = "$OpenBSD: eval.c,v 1.20 1999/11/17 15:34:13 espie Exp $";
#endif
#endif /* not lint */
@ -65,6 +65,18 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.19 1999/11/17 14:57:21 espie Exp $";
#include "extern.h"
#include "pathnames.h"
static void dodefn __P((const char *));
static void dopushdef __P((const char *, const char *));
static void dodump __P((const char *[], int));
static void doifelse __P((const char *[], int));
static int doincl __P((const char *));
static int dopaste __P((const char *));
static void dochq __P((const char *[], int));
static void dochc __P((const char *[], int));
static void dodiv __P((int));
static void doundiv __P((const char *[], int));
static void dosub __P((const char *[], int));
static void map __P((char *, const char *, const char *, const char *));
/*
* eval - evaluate built-in macros.
* argc - number of elements in argv.
@ -86,7 +98,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.19 1999/11/17 14:57:21 espie Exp $";
void
eval(argv, argc, td)
char *argv[];
const char *argv[];
int argc;
int td;
{
@ -299,12 +311,16 @@ eval(argv, argc, td)
*/
if (argc > 2) {
int fd;
char *temp;
temp = xstrdup(argv[2]);
fd = mkstemp(argv[2]);
fd = mkstemp(temp);
if (fd == -1)
err(1, "couldn't make temp file %s", argv[2]);
close(fd);
pbstr(argv[2]);
pbstr(temp);
free(temp);
}
break;
@ -391,11 +407,11 @@ char *dumpfmt = "`%s'\t`%s'\n"; /* format string for dumpdef */
*/
void
expand(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
char *t;
char *p;
const char *t;
const char *p;
int n;
int argno;
@ -462,8 +478,8 @@ expand(argv, argc)
*/
void
dodefine(name, defn)
char *name;
char *defn;
const char *name;
const char *defn;
{
ndptr p;
@ -486,9 +502,9 @@ dodefine(name, defn)
* dodefn - push back a quoted definition of
* the given name.
*/
void
static void
dodefn(name)
char *name;
const char *name;
{
ndptr p;
@ -506,10 +522,10 @@ dodefn(name)
* hash bucket, it hides a previous definition from
* lookup.
*/
void
static void
dopushdef(name, defn)
char *name;
char *defn;
const char *name;
const char *defn;
{
ndptr p;
@ -530,9 +546,9 @@ dopushdef(name, defn)
* table to stderr. If nothing is specified, the entire
* hash table is dumped.
*/
void
static void
dodump(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
int n;
@ -554,9 +570,9 @@ dodump(argv, argc)
/*
* doifelse - select one of two alternatives - loop.
*/
void
static void
doifelse(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
cycle {
@ -576,9 +592,9 @@ doifelse(argv, argc)
/*
* doinclude - include a given file.
*/
int
static int
doincl(ifile)
char *ifile;
const char *ifile;
{
if (ilevel + 1 == MAXINP)
errx(1, "too many include files.");
@ -595,9 +611,9 @@ doincl(ifile)
* dopaste - include a given file without any
* macro processing.
*/
int
static int
dopaste(pfile)
char *pfile;
const char *pfile;
{
FILE *pf;
int c;
@ -615,9 +631,9 @@ dopaste(pfile)
/*
* dochq - change quote characters
*/
void
static void
dochq(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
if (argc > 2) {
@ -641,9 +657,9 @@ dochq(argv, argc)
/*
* dochc - change comment characters
*/
void
static void
dochc(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
if (argc > 2) {
@ -665,7 +681,7 @@ dochc(argv, argc)
/*
* dodivert - divert the output to a temporary file
*/
void
static void
dodiv(n)
int n;
{
@ -690,9 +706,9 @@ dodiv(n)
* doundivert - undivert a specified output, or all
* other outputs, in numerical order.
*/
void
static void
doundiv(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
int ind;
@ -715,12 +731,12 @@ doundiv(argv, argc)
/*
* dosub - select substring
*/
void
static void
dosub(argv, argc)
char *argv[];
const char *argv[];
int argc;
{
char *ap, *fc, *k;
const char *ap, *fc, *k;
int nc;
if (argc < 5)
@ -767,14 +783,14 @@ dosub(argv, argc)
* about 5 times faster than any algorithm that makes multiple passes over
* destination string.
*/
void
static void
map(dest, src, from, to)
char *dest;
char *src;
char *from;
char *to;
const char *src;
const char *from;
const char *to;
{
char *tmp;
const char *tmp;
unsigned char sch, dch;
static unsigned char mapvec[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: expr.c,v 1.9 1999/11/15 22:12:00 espie Exp $ */
/* $OpenBSD: expr.c,v 1.10 1999/11/17 15:34:13 espie Exp $ */
/* $NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $ */
/*
@ -41,14 +41,17 @@
#if 0
static char sccsid[] = "@(#)expr.c 8.2 (Berkeley) 4/29/95";
#else
static char rcsid[] = "$OpenBSD: expr.c,v 1.9 1999/11/15 22:12:00 espie Exp $";
static char rcsid[] = "$OpenBSD: expr.c,v 1.10 1999/11/17 15:34:13 espie Exp $";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <stddef.h>
#include <stdio.h>
#include "mdef.h"
#include "extern.h"
/*
* expression evaluator: performs a standard recursive
@ -104,7 +107,7 @@ static char rcsid[] = "$OpenBSD: expr.c,v 1.9 1999/11/15 22:12:00 espie Exp $";
#define DECIMAL 10
#define HEX 16
static char *nxtch; /* Parser scan pointer */
static const char *nxtch; /* Parser scan pointer */
static int query __P((void));
static int lor __P((void));
@ -121,7 +124,7 @@ static int constant __P((void));
static int num __P((void));
static int geteqrel __P((void));
static int skipws __P((void));
static void experr __P((char *));
static void experr __P((const char *));
/*
* For longjmp
@ -139,7 +142,7 @@ static jmp_buf expjump;
int
expr(expbuf)
char *expbuf;
const char *expbuf;
{
int rval;
@ -611,7 +614,7 @@ skipws()
*/
static void
experr(msg)
char *msg;
const char *msg;
{
printf("m4: %s in expr.\n", msg);
longjmp(expjump, -1);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.10 1999/09/14 08:35:16 espie Exp $ */
/* $OpenBSD: extern.h,v 1.11 1999/11/17 15:34:13 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@ -39,39 +39,38 @@
* @(#)extern.h 8.1 (Berkeley) 6/6/93
*/
char *xalloc __P((unsigned long));
int expr __P((char *));
ndptr addent __P((char *));
void chrsave __P((int));
void dochc __P((char *[], int));
void dochq __P((char *[], int));
void dodefine __P((char *, char *));
void dodefn __P((char *));
void dodiv __P((int));
void dodump __P((char *[], int));
void doifelse __P((char *[], int));
int doincl __P((char *));
int dopaste __P((char *));
void dopushdef __P((char *, char *));
void dosub __P((char *[], int));
void doundiv __P((char *[], int));
void eval __P((char *[], int, int));
void expand __P((char *[], int));
void getdiv __P((int));
char *xstrdup __P((const char *));
int hash __P((char *));
ptrdiff_t indx __P((const char *, const char *));
void killdiv __P((void));
ndptr lookup __P((char *));
void map __P((char *, char *, char *, char *));
void onintr __P((int));
void pbnum __P((int));
void pbstr __P((char *));
void putback __P((int));
void remhash __P((char *, int));
void usage __P((void));
void initspaces __P((void));
char *compute_prevep __P((void));
/* eval.c */
extern void eval __P((const char *[], int, int));
extern void expand __P((const char *[], int));
extern void dodefine __P((const char *, const char *));
/* expr.c */
extern int expr __P((const char *));
/* gnum4.c */
extern void addtoincludepath __P((const char *dirname));
extern FILE *fopen_trypath __P((const char *filename));
/* look.c */
extern ndptr addent __P((const char *));
extern int hash __P((const char *));
extern ndptr lookup __P((const char *));
extern void remhash __P((const char *, int));
/* misc.c */
extern void chrsave __P((int));
extern char *compute_prevep __P((void));
extern void getdiv __P((int));
extern ptrdiff_t indx __P((const char *, const char *));
extern void initspaces __P((void));
extern void killdiv __P((void));
extern void onintr __P((int));
extern void pbnum __P((int));
extern void pbstr __P((const char *));
extern void putback __P((int));
extern char *xalloc __P((size_t));
extern char *xstrdup __P((const char *));
extern void usage __P((void));
extern ndptr hashtab[]; /* hash table for macros etc. */
extern stae mstack[]; /* stack of m4 machine */
@ -94,6 +93,3 @@ extern char *null; /* as it says.. just a null. */
extern char rquote[]; /* right quote character (') */
extern char scommt[]; /* start character for comment */
/* gnum4.c */
extern FILE *fopen_trypath __P((const char *filename));
extern void addtoincludepath __P((const char *dirname));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: gnum4.c,v 1.2 1999/09/14 08:35:16 espie Exp $ */
/* $OpenBSD: gnum4.c,v 1.3 1999/11/17 15:34:13 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@ -52,9 +52,13 @@ struct path_entry {
struct path_entry *next;
} *first, *last;
static struct path_entry *new_path_entry __P((const char *));
static void ensure_m4path __P((void));
static FILE *dopath __P((const char *));
static struct path_entry *
new_path_entry(dirname)
char *dirname;
const char *dirname;
{
struct path_entry *n;
@ -110,7 +114,8 @@ ensure_m4path()
static
FILE *
dopath(const char *filename)
dopath(filename)
const char *filename;
{
char path[MAXPATHLEN];
struct path_entry *pe;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: look.c,v 1.4 1999/09/14 08:35:16 espie Exp $ */
/* $OpenBSD: look.c,v 1.5 1999/11/17 15:34:13 espie Exp $ */
/*
* Copyright (c) 1989, 1993
@ -55,9 +55,11 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
#include "stdd.h"
#include "extern.h"
static void freent __P((ndptr));
int
hash(name)
char *name;
const char *name;
{
unsigned long h = 0;
while (*name)
@ -70,7 +72,7 @@ hash(name)
*/
ndptr
lookup(name)
char *name;
const char *name;
{
ndptr p;
@ -86,7 +88,7 @@ lookup(name)
*/
ndptr
addent(name)
char *name;
const char *name;
{
int h;
ndptr p;
@ -116,7 +118,7 @@ freent(p)
*/
void
remhash(name, all)
char *name;
const char *name;
int all;
{
int h;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.17 1999/09/14 08:35:16 espie Exp $ */
/* $OpenBSD: main.c,v 1.18 1999/11/17 15:34:13 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$OpenBSD: main.c,v 1.17 1999/09/14 08:35:16 espie Exp $";
static char rcsid[] = "$OpenBSD: main.c,v 1.18 1999/11/17 15:34:13 espie Exp $";
#endif
#endif /* not lint */
@ -138,8 +138,12 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
extern int optind;
extern char *optarg;
void macro();
void initkwds();
static void macro __P((void));
static void initkwds __P((void));
static ndptr inspect __P((char *));
static int do_look_ahead __P((int, const char *));
int main __P((int, char *[]));
int
main(argc,argv)
@ -225,8 +229,6 @@ main(argc,argv)
return 0;
}
ndptr inspect();
/*
* Look ahead (at most MAXCCHARS characters) for `token'.
* (on input `t == token[0]')
@ -234,10 +236,10 @@ ndptr inspect();
* Returns 1 if `token' present; copied to output.
* 0 if `token' not found; all characters pushed back
*/
int
static int
do_look_ahead(t, token)
int t;
char *token;
const char *token;
{
int i;
@ -262,7 +264,7 @@ do_look_ahead(t, token)
/*
* macro - the work horse..
*/
void
static void
macro()
{
char token[MAXTOK], chars[2];
@ -397,9 +399,9 @@ macro()
errx(1, "internal stack overflow");
if (CALTYP == MACRTYPE)
expand((char **) mstack+fp+1, sp-fp);
expand((const char **) mstack+fp+1, sp-fp);
else
eval((char **) mstack+fp+1, sp-fp, CALTYP);
eval((const char **) mstack+fp+1, sp-fp, CALTYP);
ep = PREVEP; /* flush strspace */
sp = PREVSP; /* previous sp.. */
@ -430,7 +432,7 @@ macro()
* consider only those starting with _ or A-Za-z. This is a
* combo with lookup to speed things up.
*/
ndptr
static ndptr
inspect(tp)
char *tp;
{
@ -461,7 +463,7 @@ inspect(tp)
* keyword strings, since we simply use the static pointers
* within keywrds block.
*/
void
static void
initkwds()
{
size_t i;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: misc.c,v 1.13 1999/11/17 14:51:05 espie Exp $ */
/* $OpenBSD: misc.c,v 1.14 1999/11/17 15:34:13 espie Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$OpenBSD: misc.c,v 1.13 1999/11/17 14:51:05 espie Exp $";
static char rcsid[] = "$OpenBSD: misc.c,v 1.14 1999/11/17 15:34:13 espie Exp $";
#endif
#endif /* not lint */
@ -73,8 +73,8 @@ pbent *bp; /* first available character */
static pbent *endpbb; /* end of push-back buffer */
static void enlarge_bufspace();
static void enlarge_strspace();
static void enlarge_bufspace __P((void));
static void enlarge_strspace __P((void));
/*
* find the index of second str in the first str.
*/
@ -110,7 +110,7 @@ putback(c)
*/
void
pbstr(s)
char *s;
const char *s;
{
size_t n;
@ -205,7 +205,7 @@ void enlarge_bufspace()
*/
void
chrsave(c)
char c;
int c;
{
if (ep >= endest)
enlarge_strspace();
@ -269,7 +269,7 @@ killdiv()
char *
xalloc(n)
unsigned long n;
size_t n;
{
char *p = malloc(n);