Pass WARNS=3

This commit is contained in:
christos 2003-07-14 18:19:11 +00:00
parent c9df1b829c
commit 6a7d20bb25
19 changed files with 372 additions and 347 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.26 2002/01/27 01:50:54 reinoud Exp $
# $NetBSD: Makefile,v 1.27 2003/07/14 18:19:11 christos Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
CPPFLAGS+= -I${.CURDIR}
@ -11,7 +11,7 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \
lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
.PATH: ${.CURDIR}/lst.lib
WARNS=2
WARNS=3
WFORMAT= 1
.if make(install)
SUBDIR= PSD.doc

View File

@ -1,4 +1,4 @@
/* $NetBSD: arch.c,v 1.36 2003/06/02 21:49:00 matt Exp $ */
/* $NetBSD: arch.c,v 1.37 2003/07/14 18:19:11 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: arch.c,v 1.36 2003/06/02 21:49:00 matt Exp $";
static char rcsid[] = "$NetBSD: arch.c,v 1.37 2003/07/14 18:19:11 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: arch.c,v 1.36 2003/06/02 21:49:00 matt Exp $");
__RCSID("$NetBSD: arch.c,v 1.37 2003/07/14 18:19:11 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -140,7 +140,7 @@ static int ArchFindArchive(ClientData, ClientData);
static void ArchFree(ClientData);
#endif
static struct ar_hdr *ArchStatMember(char *, char *, Boolean);
static FILE *ArchFindMember(char *, char *, struct ar_hdr *, char *);
static FILE *ArchFindMember(char *, char *, struct ar_hdr *, const char *);
#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
#define SVR4ARCHIVES
static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
@ -817,7 +817,8 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch)
*-----------------------------------------------------------------------
*/
static FILE *
ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr, char *mode)
ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr,
const char *mode)
{
FILE * arch; /* Stream to archive */
int size; /* Size of archive member */

View File

@ -1,4 +1,4 @@
/* $NetBSD: compat.c,v 1.44 2002/06/15 18:24:56 wiz Exp $ */
/* $NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: compat.c,v 1.44 2002/06/15 18:24:56 wiz Exp $";
static char rcsid[] = "$NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: compat.c,v 1.44 2002/06/15 18:24:56 wiz Exp $");
__RCSID("$NetBSD: compat.c,v 1.45 2003/07/14 18:19:11 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -168,7 +168,7 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
int cpid; /* Child actually found */
ReturnStatus retstat; /* Status of fork */
LstNode cmdNode; /* Node where current command is located */
char **av; /* Argument vector for thing to exec */
const char **av; /* Argument vector for thing to exec */
int argc; /* Number of arguments in av or 0 if not
* dynamically allocated */
Boolean local; /* TRUE if command should be executed
@ -259,7 +259,7 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
* -e flag as well as -c if it's supposed to exit when it hits an
* error.
*/
static char *shargv[4] = { _PATH_BSHELL };
static const char *shargv[4] = { _PATH_BSHELL };
if (DEBUG(SHELL))
shargv[1] = (errCheck ? "-exc" : "-xc");
@ -275,7 +275,7 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
* No meta-characters, so no need to exec a shell. Break the command
* into words to form an argument vector we can execute.
*/
av = brk_string(cmd, &argc, TRUE, &bp);
av = (const char **)brk_string(cmd, &argc, TRUE, &bp);
}
local = TRUE;
@ -290,9 +290,9 @@ CompatRunCommand(ClientData cmdp, ClientData gnp)
if (cpid == 0) {
Check_Cwd(av);
if (local)
(void)execvp(av[0], av);
(void)execvp(av[0], (char *const *)UNCONST(av));
else
(void)execv(av[0], av);
(void)execv(av[0], (char *const *)UNCONST(av));
execError("exec", av[0]);
_exit(1);
}
@ -546,7 +546,7 @@ cohorts:
void
Compat_Run(Lst targs)
{
char *cp; /* Pointer to string of shell meta-characters */
const char *cp; /* Pointer to string of shell meta-characters */
GNode *gn = NULL;/* Current root target */
int errors; /* Number of targets not remade due to errors */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.15 2003/04/17 15:57:52 sjg Exp $ */
/* $NetBSD: cond.c,v 1.16 2003/07/14 18:19:11 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: cond.c,v 1.15 2003/04/17 15:57:52 sjg Exp $";
static char rcsid[] = "$NetBSD: cond.c,v 1.16 2003/07/14 18:19:11 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: cond.c,v 1.15 2003/04/17 15:57:52 sjg Exp $");
__RCSID("$NetBSD: cond.c,v 1.16 2003/07/14 18:19:11 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -107,7 +107,7 @@ typedef enum {
* last two fields are stored in condInvert and condDefProc, respectively.
*/
static void CondPushBack(Token);
static int CondGetArg(char **, char **, char *, Boolean);
static int CondGetArg(char **, char **, const char *, Boolean);
static Boolean CondDoDefined(int, char *);
static int CondStrMatch(ClientData, ClientData);
static Boolean CondDoMake(int, char *);
@ -121,7 +121,7 @@ static Token CondF(Boolean);
static Token CondE(Boolean);
static struct If {
char *form; /* Form of if */
const char *form; /* Form of if */
int formlen; /* Length of form */
Boolean doNot; /* TRUE if default function should be negated */
Boolean (*defProc)(int, char *); /* Default function to apply */
@ -189,7 +189,7 @@ CondPushBack(Token t)
*-----------------------------------------------------------------------
*/
static int
CondGetArg(char **linePtr, char **argPtr, char *func, Boolean parens)
CondGetArg(char **linePtr, char **argPtr, const char *func, Boolean parens)
{
char *cp;
int argLen;
@ -618,8 +618,8 @@ CondToken(Boolean doEval)
}
break;
default:
op = "!=";
rhs = "0";
op = UNCONST("!=");
rhs = UNCONST("0");
goto do_compare;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.35 2002/11/26 06:12:59 sjg Exp $ */
/* $NetBSD: dir.c,v 1.36 2003/07/14 18:19:11 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: dir.c,v 1.35 2002/11/26 06:12:59 sjg Exp $";
static char rcsid[] = "$NetBSD: dir.c,v 1.36 2003/07/14 18:19:11 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: dir.c,v 1.35 2002/11/26 06:12:59 sjg Exp $");
__RCSID("$NetBSD: dir.c,v 1.36 2003/07/14 18:19:11 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -210,15 +210,15 @@ static Hash_Table mtimes; /* Results of doing a last-resort stat in
static int DirFindName(ClientData, ClientData);
static int DirMatchFiles(char *, Path *, Lst);
static void DirExpandCurly(char *, char *, Lst, Lst);
static void DirExpandInt(char *, Lst, Lst);
static int DirMatchFiles(const char *, Path *, Lst);
static void DirExpandCurly(const char *, const char *, Lst, Lst);
static void DirExpandInt(const char *, Lst, Lst);
static int DirPrintWord(ClientData, ClientData);
static int DirPrintDir(ClientData, ClientData);
static char *DirLookup(Path *, char *, char *, Boolean);
static char *DirLookupSubdir(Path *, char *);
static char *DirFindDot(Boolean, char *, char *);
static char *DirLookupAbs(Path *, char *, char *);
static char *DirLookup(Path *, const char *, const char *, Boolean);
static char *DirLookupSubdir(Path *, const char *);
static char *DirFindDot(Boolean, const char *, const char *);
static char *DirLookupAbs(Path *, const char *, const char *);
/*-
*-----------------------------------------------------------------------
@ -494,7 +494,7 @@ Dir_HasWildcards(char *name)
*-----------------------------------------------------------------------
*/
static int
DirMatchFiles(char *pattern, Path *p, Lst expansions)
DirMatchFiles(const char *pattern, Path *p, Lst expansions)
{
Hash_Search search; /* Index into the directory's table */
Hash_Entry *entry; /* Current entry in the table */
@ -548,19 +548,19 @@ DirMatchFiles(char *pattern, Path *p, Lst expansions)
*-----------------------------------------------------------------------
*/
static void
DirExpandCurly(char *word, char *brace, Lst path, Lst expansions)
DirExpandCurly(const char *word, const char *brace, Lst path, Lst expansions)
{
char *end; /* Character after the closing brace */
char *cp; /* Current position in brace clause */
char *start; /* Start of current piece of brace clause */
const char *end; /* Character after the closing brace */
const char *cp; /* Current position in brace clause */
const char *start; /* Start of current piece of brace clause */
int bracelevel; /* Number of braces we've seen. If we see a
* right brace when this is 0, we've hit the
* end of the clause. */
char *file; /* Current expansion */
char *file; /* Current expansion */
int otherLen; /* The length of the other pieces of the
* expansion (chars before and after the
* clause in 'word') */
char *cp2; /* Pointer for checking for wildcards in
char *cp2; /* Pointer for checking for wildcards in
* expansion before calling Dir_Expand */
start = brace+1;
@ -660,7 +660,7 @@ DirExpandCurly(char *word, char *brace, Lst path, Lst expansions)
*-----------------------------------------------------------------------
*/
static void
DirExpandInt(char *word, Lst path, Lst expansions)
DirExpandInt(const char *word, Lst path, Lst expansions)
{
LstNode ln; /* Current node */
Path *p; /* Directory in the node */
@ -717,9 +717,9 @@ DirPrintWord(ClientData word, ClientData dummy)
*-----------------------------------------------------------------------
*/
void
Dir_Expand(char *word, Lst path, Lst expansions)
Dir_Expand(const char *word, Lst path, Lst expansions)
{
char *cp;
const char *cp;
if (DEBUG(DIR)) {
printf("expanding \"%s\"...", word);
@ -762,9 +762,9 @@ Dir_Expand(char *word, Lst path, Lst expansions)
* all the components up to the one with a wildcard.
*/
sc = cp[1];
cp[1] = '\0';
((char *)UNCONST(cp))[1] = '\0';
dirpath = Dir_FindFile(word, path);
cp[1] = sc;
((char *)UNCONST(cp))[1] = sc;
/*
* dirpath is null if can't find the leading component
* XXX: Dir_FindFile won't find internal components.
@ -825,7 +825,7 @@ Dir_Expand(char *word, Lst path, Lst expansions)
*-----------------------------------------------------------------------
*/
static char *
DirLookup(Path *p, char *name, char *cp, Boolean hasSlash)
DirLookup(Path *p, const char *name, const char *cp, Boolean hasSlash)
{
char *file; /* the current filename to check */
@ -864,7 +864,7 @@ DirLookup(Path *p, char *name, char *cp, Boolean hasSlash)
*-----------------------------------------------------------------------
*/
static char *
DirLookupSubdir(Path *p, char *name)
DirLookupSubdir(Path *p, const char *name)
{
struct stat stb; /* Buffer for stat, if necessary */
Hash_Entry *entry; /* Entry for mtimes table */
@ -922,10 +922,10 @@ DirLookupSubdir(Path *p, char *name)
*-----------------------------------------------------------------------
*/
static char *
DirLookupAbs(Path *p, char *name, char *cp)
DirLookupAbs(Path *p, const char *name, const char *cp)
{
char *p1; /* pointer into p->name */
char *p2; /* pointer into name */
const char *p2; /* pointer into name */
if (DEBUG(DIR)) {
printf("%s...", p->name);
@ -949,7 +949,7 @@ DirLookupAbs(Path *p, char *name, char *cp)
printf("must be here but isn't -- returning\n");
}
/* Return empty string: terminates search */
return "";
return estrdup("");
}
if (DEBUG(DIR)) {
@ -977,7 +977,7 @@ DirLookupAbs(Path *p, char *name, char *cp)
*-----------------------------------------------------------------------
*/
static char *
DirFindDot(Boolean hasSlash, char *name, char *cp)
DirFindDot(Boolean hasSlash, const char *name, const char *cp)
{
if (Hash_FindEntry (&dot->files, cp) != (Hash_Entry *)NULL) {
@ -1024,12 +1024,12 @@ DirFindDot(Boolean hasSlash, char *name, char *cp)
*-----------------------------------------------------------------------
*/
char *
Dir_FindFile(char *name, Lst path)
Dir_FindFile(const char *name, Lst path)
{
LstNode ln; /* a list element */
char *file; /* the current filename to check */
Path *p; /* current path member */
char *cp; /* index of first slash, if any */
const char *cp; /* index of first slash, if any */
Boolean hasLastDot = FALSE; /* true we should search dot last */
Boolean hasSlash; /* true if 'name' contains a / */
struct stat stb; /* Buffer for stat, if necessary */
@ -1398,7 +1398,7 @@ Dir_AddDir(Lst path, const char *name)
struct dirent *dp; /* entry in directory */
if (strcmp(name, ".DOTLAST") == 0) {
ln = Lst_Find (path, (ClientData)name, DirFindName);
ln = Lst_Find (path, (ClientData)UNCONST(name), DirFindName);
if (ln != NILLNODE)
return (Path *) Lst_Datum(ln);
else {
@ -1408,7 +1408,7 @@ Dir_AddDir(Lst path, const char *name)
}
if (path)
ln = Lst_Find (openDirectories, (ClientData)name, DirFindName);
ln = Lst_Find (openDirectories, (ClientData)UNCONST(name), DirFindName);
if (ln != NILLNODE) {
p = (Path *)Lst_Datum (ln);
if (Lst_Member(path, (ClientData)p) == NILLNODE) {
@ -1503,10 +1503,10 @@ Dir_CopyDir(ClientData p)
*-----------------------------------------------------------------------
*/
char *
Dir_MakeFlags(char *flag, Lst path)
Dir_MakeFlags(const char *flag, Lst path)
{
char *str; /* the string which will be returned */
char *tstr; /* the current directory preceded by 'flag' */
char *s1, *s2;/* the current directory preceded by 'flag' */
LstNode ln; /* the node of the current directory */
Path *p; /* the structure describing the current directory */
@ -1515,8 +1515,10 @@ Dir_MakeFlags(char *flag, Lst path)
if (Lst_Open (path) == SUCCESS) {
while ((ln = Lst_Next (path)) != NILLNODE) {
p = (Path *) Lst_Datum (ln);
tstr = str_concat (flag, p->name, 0);
str = str_concat (str, tstr, STR_ADDSPACE | STR_DOFREE);
s2 = str_concat (flag, p->name, 0);
str = str_concat (s1 = str, s2, STR_ADDSPACE);
free(s1);
free(s2);
}
Lst_Close (path);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.h,v 1.8 2002/11/26 06:13:00 sjg Exp $ */
/* $NetBSD: dir.h,v 1.9 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -60,11 +60,11 @@ void Dir_InitDot(void);
void Dir_End(void);
void Dir_SetPATH(void);
Boolean Dir_HasWildcards(char *);
void Dir_Expand(char *, Lst, Lst);
char *Dir_FindFile(char *, Lst);
void Dir_Expand(const char *, Lst, Lst);
char *Dir_FindFile(const char *, Lst);
int Dir_MTime(GNode *);
Path *Dir_AddDir(Lst, const char *);
char *Dir_MakeFlags(char *, Lst);
char *Dir_MakeFlags(const char *, Lst);
void Dir_ClearPath(Lst);
void Dir_Concat(Lst, Lst);
void Dir_PrintDirectories(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: for.c,v 1.13 2002/06/15 18:24:56 wiz Exp $ */
/* $NetBSD: for.c,v 1.14 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@ -34,14 +34,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: for.c,v 1.13 2002/06/15 18:24:56 wiz Exp $";
static char rcsid[] = "$NetBSD: for.c,v 1.14 2003/07/14 18:19:12 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: for.c,v 1.13 2002/06/15 18:24:56 wiz Exp $");
__RCSID("$NetBSD: for.c,v 1.14 2003/07/14 18:19:12 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -117,7 +117,7 @@ ForAddVar(const char *data, size_t len)
int varlen;
buf = Buf_Init(0);
Buf_AddBytes(buf, len, (Byte *) data);
Buf_AddBytes(buf, len, (Byte *)UNCONST(data));
accumFor.nvars++;
accumFor.vars = erealloc(accumFor.vars, accumFor.nvars*sizeof(char *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: hash.c,v 1.10 2002/06/15 18:24:56 wiz Exp $ */
/* $NetBSD: hash.c,v 1.11 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: hash.c,v 1.10 2002/06/15 18:24:56 wiz Exp $";
static char rcsid[] = "$NetBSD: hash.c,v 1.11 2003/07/14 18:19:12 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: hash.c,v 1.10 2002/06/15 18:24:56 wiz Exp $");
__RCSID("$NetBSD: hash.c,v 1.11 2003/07/14 18:19:12 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -184,11 +184,11 @@ Hash_DeleteTable(Hash_Table *t)
*/
Hash_Entry *
Hash_FindEntry(Hash_Table *t, char *key)
Hash_FindEntry(Hash_Table *t, const char *key)
{
Hash_Entry *e;
unsigned h;
char *p;
const char *p;
for (h = 0, p = key; *p;)
h = (h << 5) - h + *p++;
@ -225,11 +225,11 @@ Hash_FindEntry(Hash_Table *t, char *key)
*/
Hash_Entry *
Hash_CreateEntry(Hash_Table *t, char *key, Boolean *newPtr)
Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr)
{
Hash_Entry *e;
unsigned h;
char *p;
const char *p;
int keylen;
struct Hash_Entry **hp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: hash.h,v 1.6 2002/06/15 18:24:56 wiz Exp $ */
/* $NetBSD: hash.h,v 1.7 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -109,8 +109,8 @@ typedef struct Hash_Search {
void Hash_InitTable(Hash_Table *, int);
void Hash_DeleteTable(Hash_Table *);
Hash_Entry *Hash_FindEntry(Hash_Table *, char *);
Hash_Entry *Hash_CreateEntry(Hash_Table *, char *, Boolean *);
Hash_Entry *Hash_FindEntry(Hash_Table *, const char *);
Hash_Entry *Hash_CreateEntry(Hash_Table *, const char *, Boolean *);
void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
Hash_Entry *Hash_EnumNext(Hash_Search *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.76 2003/04/08 17:46:59 christos Exp $ */
/* $NetBSD: job.c,v 1.77 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: job.c,v 1.76 2003/04/08 17:46:59 christos Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.77 2003/07/14 18:19:12 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.76 2003/04/08 17:46:59 christos Exp $");
__RCSID("$NetBSD: job.c,v 1.77 2003/07/14 18:19:12 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -223,7 +223,7 @@ static Shell *commandShell = &shells[DEFSHELL];/* this is the shell to
* commands in the Makefile.
* It is set by the
* Job_ParseShell function */
static char *shellPath = NULL, /* full pathname of
static const char *shellPath = NULL, /* full pathname of
* executable image */
*shellName = NULL, /* last component of shell */
*shellArgv = NULL; /* Custom shell args */
@ -254,7 +254,7 @@ static int readyfd(Job *);
STATIC GNode *lastNode; /* The node for which output was most recently
* produced. */
STATIC char *targFmt; /* Format string to use to head output from a
STATIC const char *targFmt; /* Format string to use to head output from a
* job when it's not the most-recent job heard
* from */
static Job tokenWaitJob; /* token wait pseudo-job */
@ -332,7 +332,7 @@ static int JobRestart(Job *);
static int JobStart(GNode *, int, Job *);
static char *JobOutput(Job *, char *, char *, int);
static void JobDoOutput(Job *, Boolean);
static Shell *JobMatchShell(char *);
static Shell *JobMatchShell(const char *);
static void JobInterrupt(int, int);
static void JobRestartJobs(void);
static void JobTokenAdd(void);
@ -629,7 +629,7 @@ JobPrintCommand(ClientData cmdp, ClientData jobp)
Boolean errOff = FALSE; /* true if we turned error checking
* off before printing the command
* and need to turn it back on */
char *cmdTemplate; /* Template to use when printing the
const char *cmdTemplate; /* Template to use when printing the
* command */
char *cmdStart; /* Start of expanded command */
char *cmd = (char *) cmdp;
@ -1224,7 +1224,7 @@ Job_Touch(GNode *gn, Boolean silent)
*-----------------------------------------------------------------------
*/
Boolean
Job_CheckCommands(GNode *gn, void (*abortProc)(char *, ...))
Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...))
{
if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) &&
((gn->type & OP_LIB) == 0 || Lst_IsEmpty(gn->children))) {
@ -1518,9 +1518,9 @@ static void
JobMakeArgv(Job *job, char **argv)
{
int argc;
static char args[10]; /* For merged arguments */
static char args[10]; /* For merged arguments */
argv[0] = shellName;
argv[0] = UNCONST(shellName);
argc = 1;
if ((commandShell->exit && (*commandShell->exit != '-')) ||
@ -1544,11 +1544,11 @@ JobMakeArgv(Job *job, char **argv)
}
} else {
if (!(job->flags & JOB_IGNERR) && commandShell->exit) {
argv[argc] = commandShell->exit;
argv[argc] = UNCONST(commandShell->exit);
argc++;
}
if (!(job->flags & JOB_SILENT) && commandShell->echo) {
argv[argc] = commandShell->echo;
argv[argc] = UNCONST(commandShell->echo);
argc++;
}
}
@ -2729,7 +2729,7 @@ Job_Empty(void)
*-----------------------------------------------------------------------
*/
static Shell *
JobMatchShell(char *name)
JobMatchShell(const char *name)
{
Shell *sh;
@ -2802,14 +2802,15 @@ Job_ParseShell(char *line)
}
if (shellArgv)
free(shellArgv);
free(UNCONST(shellArgv));
memset((Address)&newShell, 0, sizeof(newShell));
/*
* Parse the specification by keyword
*/
words = brk_string(line, &argc, TRUE, &shellArgv);
words = brk_string(line, &argc, TRUE, &path);
shellArgv = path;
for (path = NULL, argv = words; argc != 0; argc--, argv++) {
if (strncmp(*argv, "path=", 5) == 0) {
@ -2878,7 +2879,7 @@ Job_ParseShell(char *line)
shellPath = path;
path = strrchr(path, '/');
if (path == NULL) {
path = shellPath;
path = UNCONST(shellPath);
} else {
path += 1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.h,v 1.17 2002/11/16 22:22:23 gson Exp $ */
/* $NetBSD: job.h,v 1.18 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -207,28 +207,28 @@ typedef struct Job {
* anyway as is and if it causes an error, so be it.
*/
typedef struct Shell {
char *name; /* the name of the shell. For Bourne and C
const char *name; /* the name of the shell. For Bourne and C
* shells, this is used only to find the
* shell description when used as the single
* source of a .SHELL target. For user-defined
* shells, this is the full path of the shell.
*/
Boolean hasEchoCtl; /* True if both echoOff and echoOn defined */
char *echoOff; /* command to turn off echo */
char *echoOn; /* command to turn it back on again */
char *noPrint; /* command to skip when printing output from
const char *echoOff; /* command to turn off echo */
const char *echoOn; /* command to turn it back on again */
const char *noPrint; /* command to skip when printing output from
* shell. This is usually the command which
* was executed to turn off echoing */
int noPLen; /* length of noPrint command */
Boolean hasErrCtl; /* set if can control error checking for
* individual commands */
char *errCheck; /* string to turn error checking on */
char *ignErr; /* string to turn off error checking */
const char *errCheck; /* string to turn error checking on */
const char *ignErr; /* string to turn off error checking */
/*
* command-line flags
*/
char *echo; /* echo commands */
char *exit; /* exit on error */
const char *echo; /* echo commands */
const char *exit; /* exit on error */
} Shell;
extern int job_pipe[2]; /* token pipe for jobs. */
@ -252,7 +252,7 @@ extern Lst stoppedJobs; /* List of jobs that are stopped or didn't
#endif
void Job_Touch(GNode *, Boolean);
Boolean Job_CheckCommands(GNode *, void (*abortProc )(char *, ...));
Boolean Job_CheckCommands(GNode *, void (*abortProc )(const char *, ...));
void Job_CatchChildren(Boolean);
void Job_CatchOutput(void);
void Job_Make(GNode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.88 2003/05/10 19:21:40 jmmv Exp $ */
/* $NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,7 +39,7 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: main.c,v 1.88 2003/05/10 19:21:40 jmmv Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.88 2003/05/10 19:21:40 jmmv Exp $");
__RCSID("$NetBSD: main.c,v 1.89 2003/07/14 18:19:12 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -522,7 +522,7 @@ main(int argc, char **argv)
char *p1, *path, *pwd;
char mdpath[MAXPATHLEN];
char *machine = getenv("MACHINE");
char *machine_arch = getenv("MACHINE_ARCH");
const char *machine_arch = getenv("MACHINE_ARCH");
char *syspath = getenv("MAKESYSPATH");
Lst sysMkPath; /* Path of sys.mk */
char *cp = NULL, *start;
@ -809,10 +809,10 @@ main(int argc, char **argv)
if (ln != NILLNODE)
Fatal("%s: cannot open %s.", progname,
(char *)Lst_Datum(ln));
} else if (!ReadMakefile("makefile", NULL))
(void)ReadMakefile("Makefile", NULL);
} else if (!ReadMakefile(UNCONST("makefile"), NULL))
(void)ReadMakefile(UNCONST("Makefile"), NULL);
(void)ReadMakefile(".depend", NULL);
(void)ReadMakefile(UNCONST(".depend"), NULL);
Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
if (p1)
@ -1044,7 +1044,8 @@ Check_Cwd_av(int ac, char **av, int copy)
{
static char *make[4];
static char *cur_dir = NULL;
char *cp, **mp;
char **mp;
char *cp;
int is_cmd, next_cmd;
int i;
int n;
@ -1146,9 +1147,10 @@ Check_Cwd_av(int ac, char **av, int copy)
}
char *
Check_Cwd_Cmd(char *cmd)
Check_Cwd_Cmd(const char *cmd)
{
char *cp, *bp, **av;
char *cp, *bp;
char **av;
int ac;
if (Check_Cwd_Off)
@ -1174,7 +1176,7 @@ Check_Cwd_Cmd(char *cmd)
}
void
Check_Cwd(char **argv)
Check_Cwd(const char **argv)
{
char *cp;
int ac;
@ -1187,7 +1189,7 @@ Check_Cwd(char **argv)
if (ac == 3 && *argv[1] == '-') {
cp = Check_Cwd_Cmd(argv[2]);
} else {
cp = Check_Cwd_av(ac, argv, 0);
cp = Check_Cwd_av(ac, UNCONST(argv), 0);
}
if (cp) {
chdir(cp);
@ -1207,9 +1209,9 @@ Check_Cwd(char **argv)
* The string must be freed by the caller.
*/
char *
Cmd_Exec(char *cmd, char **err)
Cmd_Exec(const char *cmd, const char **err)
{
char *args[4]; /* Args for invoking the shell */
const char *args[4]; /* Args for invoking the shell */
int fds[2]; /* Pipe streams */
int cpid; /* Child PID */
int pid; /* PID from wait() */
@ -1256,7 +1258,7 @@ Cmd_Exec(char *cmd, char **err)
(void) dup2(fds[1], 1);
(void) close(fds[1]);
(void) execv(_PATH_BSHELL, args);
(void) execv(_PATH_BSHELL, UNCONST(args));
_exit(1);
/*NOTREACHED*/
@ -1340,7 +1342,7 @@ bad:
*/
/* VARARGS */
void
Error(char *fmt, ...)
Error(const char *fmt, ...)
{
va_list ap;
@ -1365,7 +1367,7 @@ Error(char *fmt, ...)
*/
/* VARARGS */
void
Fatal(char *fmt, ...)
Fatal(const char *fmt, ...)
{
va_list ap;
@ -1400,7 +1402,7 @@ Fatal(char *fmt, ...)
*/
/* VARARGS */
void
Punt(char *fmt, ...)
Punt(const char *fmt, ...)
{
va_list ap;
@ -1536,7 +1538,7 @@ execError(const char *af, const char *av)
int i = 0;
struct iovec iov[8];
#define IOADD(s) \
(void)(iov[i].iov_base = (s), \
(void)(iov[i].iov_base = UNCONST(s), \
iov[i].iov_len = strlen(iov[i].iov_base), \
i++)
#else
@ -1545,9 +1547,9 @@ execError(const char *af, const char *av)
IOADD(progname);
IOADD(": ");
IOADD((char *)af);
IOADD(af);
IOADD("(");
IOADD((char *)av);
IOADD(av);
IOADD(") failed (");
IOADD(strerror(errno));
IOADD(")\n");
@ -1582,7 +1584,7 @@ PrintAddr(ClientData a, ClientData b)
void
PrintOnError(char *s)
PrintOnError(const char *s)
{
char tmp[64];

View File

@ -1,4 +1,4 @@
/* $NetBSD: make.h,v 1.45 2003/03/14 05:19:43 thorpej Exp $ */
/* $NetBSD: make.h,v 1.46 2003/07/14 18:19:12 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -265,8 +265,7 @@ typedef struct GNode {
* Str_Concat returns.
*/
#define STR_ADDSPACE 0x01 /* add a space when Str_Concat'ing */
#define STR_DOFREE 0x02 /* free source strings after concatenation */
#define STR_ADDSLASH 0x04 /* add a slash when Str_Concat'ing */
#define STR_ADDSLASH 0x02 /* add a slash when Str_Concat'ing */
/*
* Error levels for parsing. PARSE_FATAL means the process cannot continue
@ -400,10 +399,21 @@ void Make_HandleUse(GNode *, GNode *);
void Make_Update(GNode *);
void Make_DoAllVar(GNode *);
Boolean Make_Run(Lst);
char * Check_Cwd_Cmd(char *);
void Check_Cwd(char **);
void PrintOnError(char *);
char * Check_Cwd_Cmd(const char *);
void Check_Cwd(const char **);
void PrintOnError(const char *);
void Main_ExportMAKEFLAGS(Boolean);
Boolean Main_SetObjdir(const char *);
#ifdef __GNUC__
#define UNCONST(ptr) ({ \
union __unconst { \
const void *__cp; \
void *__p; \
} __d; \
__d.__cp = ptr, __d.__p; })
#else
#define UNCONST(ptr) (void *)(ptr)
#endif
#endif /* _MAKE_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.27 2002/06/15 18:24:57 wiz Exp $ */
/* $NetBSD: nonints.h,v 1.28 2003/07/14 18:19:13 christos Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -72,11 +72,11 @@ void For_Run(void);
/* main.c */
void Main_ParseArgLine(char *);
int main(int, char **);
char *Cmd_Exec(char *, char **);
void Error(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
void Fatal(char *, ...)
char *Cmd_Exec(const char *, const char **);
void Error(const char *, ...) __attribute__((__format__(__printf__, 1, 2)));
void Fatal(const char *, ...)
__attribute__((__format__(__printf__, 1, 2),__noreturn__));
void Punt(char *, ...)
void Punt(const char *, ...)
__attribute__((__format__(__printf__, 1, 2),__noreturn__));
void DieHorribly(void) __attribute__((__noreturn__));
int PrintAddr(ClientData, ClientData);
@ -89,24 +89,24 @@ int eunlink(const char *);
void execError(const char *, const char *);
/* parse.c */
void Parse_Error(int, char *, ...)
void Parse_Error(int, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
Boolean Parse_AnyExport(void);
Boolean Parse_IsVar(char *);
void Parse_DoVar(char *, GNode *);
void Parse_AddIncludeDir(char *);
void Parse_File(char *, FILE *);
void Parse_File(const char *, FILE *);
void Parse_Init(void);
void Parse_End(void);
void Parse_FromString(char *);
Lst Parse_MainName(void);
/* str.c */
char *str_concat(char *, char *, int);
char **brk_string(char *, int *, Boolean, char **);
char *Str_FindSubstring(char *, char *);
int Str_Match(char *, char *);
char *Str_SYSVMatch(char *, char *, int *len);
char *str_concat(const char *, const char *, int);
char **brk_string(const char *, int *, Boolean, char **);
char *Str_FindSubstring(const char *, const char *);
int Str_Match(const char *, const char *);
char *Str_SYSVMatch(const char *, const char *, int *len);
void Str_SYSVSubst(Buffer, char *, char *, int);
/* suff.c */
@ -129,8 +129,8 @@ void Suff_PrintAll(void);
void Targ_Init(void);
void Targ_End(void);
Lst Targ_List(void);
GNode *Targ_NewGN(char *);
GNode *Targ_FindNode(char *, int);
GNode *Targ_NewGN(const char *);
GNode *Targ_FindNode(const char *, int);
Lst Targ_FindList(Lst, int);
Boolean Targ_Ignore(GNode *);
Boolean Targ_Silent(GNode *);
@ -143,15 +143,15 @@ void Targ_PrintGraph(int);
void Targ_Propagate(void);
/* var.c */
void Var_Delete(char *, GNode *);
void Var_Set(char *, char *, GNode *, int);
void Var_Append(char *, char *, GNode *);
Boolean Var_Exists(char *, GNode *);
char *Var_Value(char *, GNode *, char **);
char *Var_Parse(char *, GNode *, Boolean, int *, Boolean *);
char *Var_Subst(char *, char *, GNode *, Boolean);
char *Var_GetTail(char *);
char *Var_GetHead(char *);
void Var_Delete(const char *, GNode *);
void Var_Set(const char *, const char *, GNode *, int);
void Var_Append(const char *, const char *, GNode *);
Boolean Var_Exists(const char *, GNode *);
char *Var_Value(const char *, GNode *, char **);
char *Var_Parse(const char *, GNode *, Boolean, int *, Boolean *);
char *Var_Subst(const char *, const char *, GNode *, Boolean);
char *Var_GetTail(const char *);
char *Var_GetHead(const char *);
void Var_Init(void);
void Var_End(void);
void Var_Dump(GNode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.92 2003/03/23 22:48:35 sjg Exp $ */
/* $NetBSD: parse.c,v 1.93 2003/07/14 18:19:13 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: parse.c,v 1.92 2003/03/23 22:48:35 sjg Exp $";
static char rcsid[] = "$NetBSD: parse.c,v 1.93 2003/07/14 18:19:13 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: parse.c,v 1.92 2003/03/23 22:48:35 sjg Exp $");
__RCSID("$NetBSD: parse.c,v 1.93 2003/07/14 18:19:13 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -206,7 +206,7 @@ static GNode *predecessor;
* keyword is used as a source ("0" if the keyword isn't special as a source)
*/
static struct {
char *name; /* Name of keyword */
const char *name; /* Name of keyword */
ParseSpecial spec; /* Type when used as a target */
int op; /* Operator when used as a source */
} parseKeywords[] = {
@ -260,9 +260,9 @@ typedef struct {
} SpecialSrc;
static int ParseIsEscaped(const char *, const char *);
static void ParseErrorInternal(char *, size_t, int, char *, ...)
static void ParseErrorInternal(char *, size_t, int, const char *, ...)
__attribute__((__format__(__printf__, 4, 5)));
static void ParseVErrorInternal(char *, size_t, int, char *, va_list)
static void ParseVErrorInternal(char *, size_t, int, const char *, va_list)
__attribute__((__format__(__printf__, 4, 0)));
static int ParseFindKeyword(char *);
static int ParseLinkSrc(ClientData, ClientData);
@ -370,7 +370,7 @@ ParseFindKeyword(char *str)
*/
/* VARARGS */
static void
ParseVErrorInternal(char *cfname, size_t clineno, int type, char *fmt,
ParseVErrorInternal(char *cfname, size_t clineno, int type, const char *fmt,
va_list ap)
{
static Boolean fatal_warning_error_printed = FALSE;
@ -378,7 +378,8 @@ ParseVErrorInternal(char *cfname, size_t clineno, int type, char *fmt,
(void)fprintf(stderr, "%s: \"", progname);
if (*cfname != '/') {
char *cp, *dir;
char *cp;
const char *dir;
/*
* Nothing is more anoying than not knowing which Makefile
@ -421,7 +422,7 @@ ParseVErrorInternal(char *cfname, size_t clineno, int type, char *fmt,
*/
/* VARARGS */
static void
ParseErrorInternal(char *cfname, size_t clineno, int type, char *fmt, ...)
ParseErrorInternal(char *cfname, size_t clineno, int type, const char *fmt, ...)
{
va_list ap;
@ -443,7 +444,7 @@ ParseErrorInternal(char *cfname, size_t clineno, int type, char *fmt, ...)
*/
/* VARARGS */
void
Parse_Error(int type, char *fmt, ...)
Parse_Error(int type, const char *fmt, ...)
{
va_list ap;
@ -1674,7 +1675,8 @@ Parse_DoVar(char *line, GNode *ctxt)
Var_Set(line, cp, ctxt, 0);
} else if (type == VAR_SHELL) {
char *res, *err;
char *res;
const char *err;
if (strchr(cp, '$') != NULL) {
/*
@ -2672,7 +2674,7 @@ ParseFinishLine(void)
*---------------------------------------------------------------------
*/
void
Parse_File(char *name, FILE *stream)
Parse_File(const char *name, FILE *stream)
{
char *cp, /* pointer into the line */
*line; /* the line we're working on */
@ -2680,7 +2682,7 @@ Parse_File(char *name, FILE *stream)
inLine = FALSE;
fatals = 0;
curFile.fname = name;
curFile.fname = UNCONST(name);
curFile.F = stream;
curFile.lineno = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: str.c,v 1.18 2002/06/15 18:24:57 wiz Exp $ */
/* $NetBSD: str.c,v 1.19 2003/07/14 18:19:13 christos Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: str.c,v 1.18 2002/06/15 18:24:57 wiz Exp $";
static char rcsid[] = "$NetBSD: str.c,v 1.19 2003/07/14 18:19:13 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: str.c,v 1.18 2002/06/15 18:24:57 wiz Exp $");
__RCSID("$NetBSD: str.c,v 1.19 2003/07/14 18:19:13 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -62,7 +62,7 @@ __RCSID("$NetBSD: str.c,v 1.18 2002/06/15 18:24:57 wiz Exp $");
* the resulting string in allocated space.
*/
char *
str_concat(char *s1, char *s2, int flags)
str_concat(const char *s1, const char *s2, int flags)
{
int len1, len2;
char *result;
@ -89,11 +89,6 @@ str_concat(char *s1, char *s2, int flags)
/* copy second string plus EOS into place */
memcpy(result + len1, s2, len2 + 1);
/* free original strings */
if (flags & STR_DOFREE) {
(void)free(s1);
(void)free(s2);
}
return(result);
}
@ -108,10 +103,11 @@ str_concat(char *s1, char *s2, int flags)
* the first word is always the value of the .MAKE variable.
*/
char **
brk_string(char *str, int *store_argc, Boolean expand, char **buffer)
brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
{
int argc, ch;
char inquote, *p, *start, *t;
char inquote, *start, *t;
const char *p;
int len;
int argmax = 50, curlen = 0;
char **argv = (char **)emalloc((argmax + 1) * sizeof(char *));
@ -239,9 +235,9 @@ done: argv[argc] = (char *)NULL;
* Side effects: None.
*/
char *
Str_FindSubstring(char *string, char *substring)
Str_FindSubstring(const char *string, const char *substring)
{
char *a, *b;
const char *a, *b;
/*
* First scan quickly through the two strings looking for a single-
@ -255,13 +251,13 @@ Str_FindSubstring(char *string, char *substring)
a = string;
for (;;) {
if (*b == 0)
return(string);
return UNCONST(string);
if (*a++ != *b++)
break;
}
b = substring;
}
return((char *) NULL);
return NULL;
}
/*
@ -276,7 +272,7 @@ Str_FindSubstring(char *string, char *substring)
* Side effects: None.
*/
int
Str_Match(char *string, char *pattern)
Str_Match(const char *string, const char *pattern)
{
char c2;
@ -384,16 +380,16 @@ thisCharOK: ++pattern;
*-----------------------------------------------------------------------
*/
char *
Str_SYSVMatch(char *word, char *pattern, int *len)
Str_SYSVMatch(const char *word, const char *pattern, int *len)
{
char *p = pattern;
char *w = word;
char *m;
const char *p = pattern;
const char *w = word;
const char *m;
if (*p == '\0') {
/* Null pattern is the whole string */
*len = strlen(w);
return w;
return UNCONST(w);
}
if ((m = strchr(p, '%')) != NULL) {
@ -407,7 +403,7 @@ Str_SYSVMatch(char *word, char *pattern, int *len)
if (*++p == '\0') {
/* No more pattern, return the rest of the string */
*len = strlen(w);
return w;
return UNCONST(w);
}
}
@ -417,7 +413,7 @@ Str_SYSVMatch(char *word, char *pattern, int *len)
do
if (strcmp(p, w) == 0) {
*len = w - m;
return m;
return UNCONST(m);
}
while (*w++ != '\0');

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.40 2002/12/05 15:56:52 scw Exp $ */
/* $NetBSD: suff.c,v 1.41 2003/07/14 18:19:13 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: suff.c,v 1.40 2002/12/05 15:56:52 scw Exp $";
static char rcsid[] = "$NetBSD: suff.c,v 1.41 2003/07/14 18:19:13 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
__RCSID("$NetBSD: suff.c,v 1.40 2002/12/05 15:56:52 scw Exp $");
__RCSID("$NetBSD: suff.c,v 1.41 2003/07/14 18:19:13 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -1796,7 +1796,8 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
char *eoarch; /* End of archive portion */
char *eoname; /* End of member portion */
GNode *mem; /* Node for member */
static char *copy[] = { /* Variables to be copied from the member node */
static const char *copy[] = {
/* Variables to be copied from the member node */
TARGET, /* Must be first */
PREFIX, /* Must be second */
};
@ -2359,7 +2360,8 @@ SuffFindDeps(GNode *gn, Lst slst)
LstNode ln;
Suff *s;
ln = Lst_Find (sufflist, (ClientData)LIBSUFF, SuffSuffHasNameP);
ln = Lst_Find (sufflist, (ClientData)UNCONST(LIBSUFF),
SuffSuffHasNameP);
if (gn->suffix)
gn->suffix->refCount--;
if (ln != NILLNODE) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.28 2002/06/15 18:24:58 wiz Exp $ */
/* $NetBSD: targ.c,v 1.29 2003/07/14 18:19:13 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: targ.c,v 1.28 2002/06/15 18:24:58 wiz Exp $";
static char rcsid[] = "$NetBSD: targ.c,v 1.29 2003/07/14 18:19:13 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: targ.c,v 1.28 2002/06/15 18:24:58 wiz Exp $");
__RCSID("$NetBSD: targ.c,v 1.29 2003/07/14 18:19:13 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -195,14 +195,14 @@ Targ_List(void)
*-----------------------------------------------------------------------
*/
GNode *
Targ_NewGN(char *name)
Targ_NewGN(const char *name)
{
GNode *gn;
gn = (GNode *) emalloc (sizeof (GNode));
gn->name = estrdup (name);
gn->uname = NULL;
gn->path = (char *) 0;
gn->path = NULL;
if (name[0] == '-' && name[1] == 'l') {
gn->type = OP_LIB;
} else {
@ -296,7 +296,7 @@ TargFreeGN(ClientData gnp)
*-----------------------------------------------------------------------
*/
GNode *
Targ_FindNode(char *name, int flags)
Targ_FindNode(const char *name, int flags)
{
GNode *gn; /* node in that element */
Hash_Entry *he; /* New or used hash entry for node */

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.72 2003/05/22 18:20:10 christos Exp $ */
/* $NetBSD: var.c,v 1.73 2003/07/14 18:19:13 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: var.c,v 1.72 2003/05/22 18:20:10 christos Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.73 2003/07/14 18:19:13 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.72 2003/05/22 18:20:10 christos Exp $");
__RCSID("$NetBSD: var.c,v 1.73 2003/07/14 18:19:13 christos Exp $");
#endif
#endif /* not lint */
#endif
@ -169,9 +169,9 @@ typedef struct Var {
#define VAR_NO_EXPORT 0x01 /* do not export */
typedef struct {
char *lhs; /* String to match */
int leftLen; /* Length of string */
char *rhs; /* Replacement string (w/ &'s removed) */
const char *lhs; /* String to match */
int leftLen; /* Length of string */
const char *rhs; /* Replacement string (w/ &'s removed) */
int rightLen; /* Length of replacement */
int flags;
} VarPattern;
@ -195,8 +195,8 @@ typedef struct {
} VarREPattern;
#endif
static Var *VarFind(char *, GNode *, int);
static void VarAdd(char *, char *, GNode *);
static Var *VarFind(const char *, GNode *, int);
static void VarAdd(const char *, const char *, GNode *);
static Boolean VarHead(GNode *, char *, Boolean, Buffer, ClientData);
static Boolean VarTail(GNode *, char *, Boolean, Buffer, ClientData);
static Boolean VarSuffix(GNode *, char *, Boolean, Buffer, ClientData);
@ -212,18 +212,20 @@ static Boolean VarRESubstitute(GNode *, char *, Boolean, Buffer, ClientData);
#endif
static Boolean VarSubstitute(GNode *, char *, Boolean, Buffer, ClientData);
static Boolean VarLoopExpand(GNode *, char *, Boolean, Buffer, ClientData);
static char *VarGetPattern(GNode *, int, char **, int, int *, int *,
static char *VarGetPattern(GNode *, int, const char **, int, int *, int *,
VarPattern *);
static char *VarQuote(char *);
static char *VarChangeCase(char *, int);
static char *VarModify(GNode *, char *, Boolean (*)(GNode *, char *, Boolean,
Buffer, ClientData),
ClientData);
static char *VarSort(char *);
static char *VarUniq(char *);
static char *VarModify(GNode *, const char *,
Boolean (*)(GNode *, char *, Boolean, Buffer, ClientData),
ClientData);
static char *VarSort(const char *);
static char *VarUniq(const char *);
static int VarWordCompare(const void *, const void *);
static void VarPrintVar(ClientData);
#define WR(a) ((char *)UNCONST(a))
/*-
*-----------------------------------------------------------------------
* VarFind --
@ -247,7 +249,7 @@ static void VarPrintVar(ClientData);
*-----------------------------------------------------------------------
*/
static Var *
VarFind(char *name, GNode *ctxt, int flags)
VarFind(const char *name, GNode *ctxt, int flags)
{
Hash_Entry *var;
Var *v;
@ -357,7 +359,7 @@ VarFind(char *name, GNode *ctxt, int flags)
*-----------------------------------------------------------------------
*/
static void
VarAdd(char *name, char *val, GNode *ctxt)
VarAdd(const char *name, const char *val, GNode *ctxt)
{
Var *v;
int len;
@ -367,7 +369,7 @@ VarAdd(char *name, char *val, GNode *ctxt)
len = val ? strlen(val) : 0;
v->val = Buf_Init(len+1);
Buf_AddBytes(v->val, len, (Byte *)val);
Buf_AddBytes(v->val, len, (const Byte *)val);
v->flags = 0;
@ -393,7 +395,7 @@ VarAdd(char *name, char *val, GNode *ctxt)
*-----------------------------------------------------------------------
*/
void
Var_Delete(char *name, GNode *ctxt)
Var_Delete(const char *name, GNode *ctxt)
{
Hash_Entry *ln;
@ -440,10 +442,10 @@ Var_Delete(char *name, GNode *ctxt)
*-----------------------------------------------------------------------
*/
void
Var_Set(char *name, char *val, GNode *ctxt, int flags)
Var_Set(const char *name, const char *val, GNode *ctxt, int flags)
{
Var *v;
char *cp = name;
const char *cp = name;
/*
* We only look for a variable in the given context since anything set
@ -459,7 +461,7 @@ Var_Set(char *name, char *val, GNode *ctxt, int flags)
VarAdd (name, val, ctxt);
} else {
Buf_Discard(v->val, Buf_Size(v->val));
Buf_AddBytes(v->val, strlen(val), (Byte *)val);
Buf_AddBytes(v->val, strlen(val), (const Byte *)val);
if (DEBUG(VAR)) {
printf("%s:%s = %s\n", ctxt->name, name, val);
@ -483,7 +485,7 @@ Var_Set(char *name, char *val, GNode *ctxt, int flags)
Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
}
if (name != cp)
free(name);
free(UNCONST(name));
}
/*-
@ -514,11 +516,11 @@ Var_Set(char *name, char *val, GNode *ctxt, int flags)
*-----------------------------------------------------------------------
*/
void
Var_Append(char *name, char *val, GNode *ctxt)
Var_Append(const char *name, const char *val, GNode *ctxt)
{
Var *v;
Hash_Entry *h;
char *cp = name;
const char *cp = name;
if ((name = strchr(cp, '$'))) {
name = Var_Subst(NULL, cp, ctxt, 0);
@ -531,7 +533,7 @@ Var_Append(char *name, char *val, GNode *ctxt)
VarAdd (name, val, ctxt);
} else {
Buf_AddByte(v->val, (Byte)' ');
Buf_AddBytes(v->val, strlen(val), (Byte *)val);
Buf_AddBytes(v->val, strlen(val), (const Byte *)val);
if (DEBUG(VAR)) {
printf("%s:%s = %s\n", ctxt->name, name,
@ -551,7 +553,7 @@ Var_Append(char *name, char *val, GNode *ctxt)
}
}
if (name != cp)
free(name);
free(UNCONST(name));
}
/*-
@ -572,7 +574,7 @@ Var_Append(char *name, char *val, GNode *ctxt)
*-----------------------------------------------------------------------
*/
Boolean
Var_Exists(char *name, GNode *ctxt)
Var_Exists(const char *name, GNode *ctxt)
{
Var *v;
@ -605,7 +607,7 @@ Var_Exists(char *name, GNode *ctxt)
*-----------------------------------------------------------------------
*/
char *
Var_Value(char *name, GNode *ctxt, char **frp)
Var_Value(const char *name, GNode *ctxt, char **frp)
{
Var *v;
@ -666,7 +668,7 @@ VarHead(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
* If no directory part, give . (q.v. the POSIX standard)
*/
if (addSpace) {
Buf_AddBytes(buf, 2, (Byte *)" .");
Buf_AddBytes(buf, 2, (const Byte *)" .");
} else {
Buf_AddByte(buf, (Byte)'.');
}
@ -975,7 +977,7 @@ VarSubstitute(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
}
addSpace = TRUE;
Buf_AddBytes(buf, pattern->rightLen,
(Byte *)pattern->rhs);
(const Byte *)pattern->rhs);
}
pattern->flags |= VAR_SUB_MATCHED;
} else if (pattern->flags & VAR_MATCH_END) {
@ -993,7 +995,8 @@ VarSubstitute(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
}
addSpace = TRUE;
}
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs);
Buf_AddBytes(buf, pattern->rightLen,
(const Byte *)pattern->rhs);
Buf_AddBytes(buf, wordLen - pattern->leftLen,
(Byte *)(word + pattern->leftLen));
pattern->flags |= VAR_SUB_MATCHED;
@ -1025,8 +1028,9 @@ VarSubstitute(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
}
addSpace = TRUE;
}
Buf_AddBytes(buf, cp - word, (Byte *)word);
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs);
Buf_AddBytes(buf, cp - word, (const Byte *)word);
Buf_AddBytes(buf, pattern->rightLen,
(const Byte *)pattern->rhs);
pattern->flags |= VAR_SUB_MATCHED;
} else {
/*
@ -1058,8 +1062,9 @@ VarSubstitute(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
Buf_AddByte(buf, (Byte)' ');
addSpace = FALSE;
}
Buf_AddBytes(buf, cp-word, (Byte *)word);
Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs);
Buf_AddBytes(buf, cp-word, (const Byte *)word);
Buf_AddBytes(buf, pattern->rightLen,
(const Byte *)pattern->rhs);
wordLen -= (cp - word) + pattern->leftLen;
word = cp + pattern->leftLen;
if (wordLen == 0) {
@ -1183,7 +1188,7 @@ VarRESubstitute(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
else if ((*rp == '&') ||
((*rp == '\\') && isdigit((unsigned char)rp[1]))) {
int n;
char *subbuf;
const char *subbuf;
int sublen;
char errstr[3];
@ -1319,9 +1324,9 @@ VarLoopExpand(GNode *ctx, char *word, Boolean addSpace, Buffer buf,
*-----------------------------------------------------------------------
*/
static char *
VarModify(GNode *ctx, char *str, Boolean (*modProc)(GNode *, char *, Boolean,
Buffer, ClientData),
ClientData datum)
VarModify(GNode *ctx, const char *str,
Boolean (*modProc)(GNode *, char *, Boolean, Buffer, ClientData),
ClientData datum)
{
Buffer buf; /* Buffer for the new string */
Boolean addSpace; /* TRUE if need to add a space to the
@ -1343,16 +1348,16 @@ VarModify(GNode *ctx, char *str, Boolean (*modProc)(GNode *, char *, Boolean,
free(av);
Buf_AddByte (buf, '\0');
str = (char *)Buf_GetAll (buf, (int *)NULL);
as = (char *)Buf_GetAll (buf, (int *)NULL);
Buf_Destroy (buf, FALSE);
return (str);
return (as);
}
static int
VarWordCompare(const void *a, const void *b)
{
int r = strcmp(*(char **)a, *(char **)b);
int r = strcmp(*(const char **)a, *(const char **)b);
return r;
}
@ -1373,7 +1378,7 @@ VarWordCompare(const void *a, const void *b)
*-----------------------------------------------------------------------
*/
static char *
VarSort(char *str)
VarSort(const char *str)
{
Buffer buf; /* Buffer for the new string */
char **av; /* word list [first word does not count] */
@ -1397,9 +1402,9 @@ VarSort(char *str)
free(av);
Buf_AddByte (buf, '\0');
str = (char *)Buf_GetAll (buf, (int *)NULL);
as = (char *)Buf_GetAll (buf, (int *)NULL);
Buf_Destroy (buf, FALSE);
return (str);
return (as);
}
@ -1420,7 +1425,7 @@ VarSort(char *str)
*-----------------------------------------------------------------------
*/
static char *
VarUniq(char *str)
VarUniq(const char *str)
{
Buffer buf; /* Buffer for new string */
char **av; /* List of words to affect */
@ -1447,9 +1452,9 @@ VarUniq(char *str)
free(av);
Buf_AddByte(buf, '\0');
str = (char *)Buf_GetAll(buf, (int *)NULL);
as = (char *)Buf_GetAll(buf, (int *)NULL);
Buf_Destroy(buf, FALSE);
return str;
return as;
}
@ -1476,10 +1481,10 @@ VarUniq(char *str)
*-----------------------------------------------------------------------
*/
static char *
VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
VarGetPattern(GNode *ctxt, int err, const char **tstr, int delim, int *flags,
int *length, VarPattern *pattern)
{
char *cp;
const char *cp;
Buffer buf = Buf_Init(0);
int junk;
if (length == NULL)
@ -1526,7 +1531,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
free(cp2);
cp += len - 1;
} else {
char *cp2 = &cp[1];
const char *cp2 = &cp[1];
if (*cp2 == '(' || *cp2 == '{') {
/*
@ -1546,7 +1551,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
--depth;
}
}
Buf_AddBytes(buf, cp2 - cp, (Byte *)cp);
Buf_AddBytes(buf, cp2 - cp, (const Byte *)cp);
cp = --cp2;
} else
Buf_AddByte(buf, (Byte) *cp);
@ -1554,7 +1559,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
}
}
else if (pattern && *cp == '&')
Buf_AddBytes(buf, pattern->leftLen, (Byte *)pattern->lhs);
Buf_AddBytes(buf, pattern->leftLen, (const Byte *)pattern->lhs);
else
Buf_AddByte(buf, (Byte) *cp);
}
@ -1567,11 +1572,12 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
return NULL;
}
else {
char *rstr;
*tstr = ++cp;
cp = (char *) Buf_GetAll(buf, length);
rstr = (char *) Buf_GetAll(buf, length);
*length -= 1; /* Don't count the NULL */
Buf_Destroy(buf, FALSE);
return cp;
return rstr;
}
}
@ -1670,12 +1676,12 @@ VarChangeCase(char *str, int upper)
*-----------------------------------------------------------------------
*/
char *
Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
Var_Parse(const char *str, GNode *ctxt, Boolean err, int *lengthPtr,
Boolean *freePtr)
{
char *tstr; /* Pointer into str */
Var *v; /* Variable in invocation */
char *cp; /* Secondary pointer into str (place marker
const char *tstr; /* Pointer into str */
Var *v; /* Variable in invocation */
const char *cp; /* Secondary pointer into str (place marker
* for tstr) */
Boolean haveModifier;/* TRUE if have modifiers for the variable */
char endc; /* Ending character when variable in parens
@ -1685,8 +1691,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
int cnt; /* Used to count brace pairs when variable in
* in parens or braces */
int vlen; /* Length of variable name */
char *start;
char delim;
const char *start;
char delim;
char *nstr;
Boolean dynamic; /* TRUE if the variable is local and we're
* expanding it in a non-local context. This
* is done to support dynamic sources. The
@ -1723,13 +1730,13 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
*/
switch (str[1]) {
case '@':
return("$(.TARGET)");
return UNCONST("$(.TARGET)");
case '%':
return("$(.ARCHIVE)");
return UNCONST("$(.ARCHIVE)");
case '*':
return("$(.PREFIX)");
return UNCONST("$(.PREFIX)");
case '!':
return("$(.MEMBER)");
return UNCONST("$(.MEMBER)");
}
}
/*
@ -1785,7 +1792,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
*lengthPtr = tstr - str;
return (var_Error);
}
*tstr = '\0';
*WR(tstr) = '\0';
Buf_AddByte(buf, (Byte) '\0');
str = Buf_GetAll(buf, (int *) NULL);
vlen = strlen(str);
@ -1835,7 +1842,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
*/
*freePtr = TRUE;
*lengthPtr = tstr-start+1;
*tstr = endc;
*WR(tstr) = endc;
Buf_Destroy (buf, TRUE);
return(val);
}
@ -1889,14 +1896,14 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
* now.
*/
*lengthPtr = tstr - start + 1;
*tstr = endc;
*WR(tstr) = endc;
if (dynamic) {
str = emalloc(*lengthPtr + 1);
strncpy(str, start, *lengthPtr);
str[*lengthPtr] = '\0';
char *pstr = emalloc(*lengthPtr + 1);
strncpy(pstr, start, *lengthPtr);
pstr[*lengthPtr] = '\0';
*freePtr = TRUE;
Buf_Destroy (buf, TRUE);
return(str);
return(pstr);
} else {
Buf_Destroy (buf, TRUE);
return (err ? var_Error : varNoError);
@ -1907,7 +1914,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
* so kludge up a Var structure for the modifications
*/
v = (Var *) emalloc(sizeof(Var));
v->name = str;
v->name = UNCONST(str);
v->val = Buf_Init(1);
v->flags = VAR_JUNK;
Buf_Destroy (buf, FALSE);
@ -1932,9 +1939,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
* been dynamically-allocated, so it will need freeing when we
* return.
*/
str = (char *)Buf_GetAll(v->val, (int *)NULL);
if (strchr (str, '$') != (char *)NULL) {
str = Var_Subst(NULL, str, ctxt, err);
nstr = (char *)Buf_GetAll(v->val, (int *)NULL);
if (strchr (nstr, '$') != (char *)NULL) {
nstr = Var_Subst(NULL, nstr, ctxt, err);
*freePtr = TRUE;
}
@ -2005,17 +2012,18 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
* ::!=<cmd> Assigns output of <cmd> as the new value of
* variable.
*/
if ((str != (char *)NULL) && haveModifier) {
if ((nstr != (char *)NULL) && haveModifier) {
/*
* Skip initial colon while putting it back.
*/
*tstr++ = ':';
*WR(tstr) = ':';
tstr++;
while (*tstr && *tstr != endc) {
char *newStr; /* New value to return */
char termc; /* Character which terminated scan */
if (DEBUG(VAR)) {
printf("Applying :%c to \"%s\"\n", *tstr, str);
printf("Applying :%c to \"%s\"\n", *tstr, nstr);
}
switch (*tstr) {
case ':':
@ -2024,7 +2032,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
(tstr[2] == '=' &&
(tstr[1] == '!' || tstr[1] == '+' || tstr[1] == '?'))) {
GNode *v_ctxt; /* context where v belongs */
char *emsg;
const char *emsg;
VarPattern pattern;
int how;
@ -2061,7 +2069,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
NULL, &pattern.rightLen, NULL)) == NULL) {
if (v->flags & VAR_JUNK) {
free(v->name);
v->name = str;
v->name = nstr;
}
goto cleanup;
}
@ -2075,7 +2083,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
case '!':
newStr = Cmd_Exec (pattern.rhs, &emsg);
if (emsg)
Error (emsg, str);
Error (emsg, nstr);
else
Var_Set(v->name, newStr, v_ctxt, 0);
if (newStr)
@ -2091,9 +2099,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
if (v->flags & VAR_JUNK) {
free(v->name);
v->name = str;
v->name = nstr;
}
free(pattern.rhs);
free(UNCONST(pattern.rhs));
newStr = var_Error;
break;
}
@ -2120,7 +2128,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
loop.err = err;
loop.ctxt = ctxt;
newStr = VarModify(ctxt, str, VarLoopExpand,
newStr = VarModify(ctxt, nstr, VarLoopExpand,
(ClientData)&loop);
free(loop.tvar);
free(loop.str);
@ -2183,7 +2191,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
newStr = (char *)Buf_GetAll(buf, (int *)NULL);
Buf_Destroy(buf, FALSE);
} else {
newStr = str;
newStr = nstr;
Buf_Destroy(buf, TRUE);
}
break;
@ -2214,7 +2222,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
case '!':
{
char *emsg;
const char *emsg;
VarPattern pattern;
pattern.flags = 0;
@ -2225,9 +2233,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
NULL, &pattern.rightLen, NULL)) == NULL)
goto cleanup;
newStr = Cmd_Exec (pattern.rhs, &emsg);
free(pattern.rhs);
free(UNCONST(pattern.rhs));
if (emsg)
Error (emsg, str);
Error (emsg, nstr);
termc = *cp;
delim = '\0';
if (v->flags & VAR_JUNK) {
@ -2240,7 +2248,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
if (tstr[1] != endc && tstr[1] != ':') {
if (tstr[2] == endc || tstr[2] == ':') {
if (tstr[1] == 'u' || tstr[1] == 'l') {
newStr = VarChangeCase (str, (tstr[1] == 'u'));
newStr = VarChangeCase (nstr, (tstr[1] == 'u'));
cp = tstr + 2;
termc = *cp;
}
@ -2278,7 +2286,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
}
termc = *cp;
*cp = '\0';
*WR(cp) = '\0';
if (copy) {
/*
* Need to compress the \:'s out of the pattern, so
@ -2300,7 +2308,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
*cp2 = '\0';
} else {
pattern = &tstr[1];
pattern = UNCONST(&tstr[1]);
}
if ((cp2 = strchr(pattern, '$'))) {
cp2 = pattern;
@ -2310,9 +2318,9 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
copy = TRUE;
}
if (*tstr == 'M' || *tstr == 'm') {
newStr = VarModify(ctxt, str, VarMatch, (ClientData)pattern);
newStr = VarModify(ctxt, nstr, VarMatch, (ClientData)pattern);
} else {
newStr = VarModify(ctxt, str, VarNoMatch,
newStr = VarModify(ctxt, nstr, VarNoMatch,
(ClientData)pattern);
}
if (copy) {
@ -2364,14 +2372,14 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
termc = *cp;
newStr = VarModify(ctxt, str, VarSubstitute,
newStr = VarModify(ctxt, nstr, VarSubstitute,
(ClientData)&pattern);
/*
* Free the two strings.
*/
free(pattern.lhs);
free(pattern.rhs);
free(UNCONST(pattern.lhs));
free(UNCONST(pattern.rhs));
break;
}
case '?':
@ -2405,11 +2413,11 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
}
if (value) {
newStr = pattern.lhs;
free(pattern.rhs);
newStr = UNCONST(pattern.lhs);
free(UNCONST(pattern.rhs));
} else {
newStr = pattern.rhs;
free(pattern.lhs);
newStr = UNCONST(pattern.rhs);
free(UNCONST(pattern.lhs));
}
break;
}
@ -2466,7 +2474,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
pattern.nsub = 10;
pattern.matches = emalloc(pattern.nsub *
sizeof(regmatch_t));
newStr = VarModify(ctxt, str, VarRESubstitute,
newStr = VarModify(ctxt, nstr, VarRESubstitute,
(ClientData) &pattern);
regfree(&pattern.re);
free(pattern.replace);
@ -2476,7 +2484,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
#endif
case 'Q':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarQuote (str);
newStr = VarQuote (nstr);
cp = tstr + 1;
termc = *cp;
break;
@ -2484,7 +2492,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'T':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarModify(ctxt, str, VarTail, (ClientData)0);
newStr = VarModify(ctxt, nstr, VarTail, (ClientData)0);
cp = tstr + 1;
termc = *cp;
break;
@ -2492,7 +2500,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'H':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarModify(ctxt, str, VarHead, (ClientData)0);
newStr = VarModify(ctxt, nstr, VarHead, (ClientData)0);
cp = tstr + 1;
termc = *cp;
break;
@ -2500,7 +2508,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'E':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarModify(ctxt, str, VarSuffix, (ClientData)0);
newStr = VarModify(ctxt, nstr, VarSuffix, (ClientData)0);
cp = tstr + 1;
termc = *cp;
break;
@ -2508,7 +2516,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'R':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarModify(ctxt, str, VarRoot, (ClientData)0);
newStr = VarModify(ctxt, nstr, VarRoot, (ClientData)0);
cp = tstr + 1;
termc = *cp;
break;
@ -2516,7 +2524,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'O':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarSort (str);
newStr = VarSort (nstr);
cp = tstr + 1;
termc = *cp;
break;
@ -2524,7 +2532,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
/*FALLTHRU*/
case 'u':
if (tstr[1] == endc || tstr[1] == ':') {
newStr = VarUniq (str);
newStr = VarUniq (nstr);
cp = tstr + 1;
termc = *cp;
break;
@ -2533,10 +2541,10 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
#ifdef SUNSHCMD
case 's':
if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
char *errstr;
newStr = Cmd_Exec (str, &errstr);
if (errstr)
Error (errstr, str);
const char *emsg;
newStr = Cmd_Exec (nstr, &emsg);
if (emsg)
Error (emsg, nstr);
cp = tstr + 2;
termc = *cp;
break;
@ -2585,8 +2593,8 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
continue;
pattern.lhs = tstr;
pattern.leftLen = cp - tstr;
*cp++ = '\0';
*WR(cp) = '\0';
cp++;
pattern.rhs = cp;
cnt = 1;
while (cnt) {
@ -2598,20 +2606,20 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
cp++;
}
pattern.rightLen = cp - pattern.rhs;
*cp = '\0';
*WR(cp) = '\0';
/*
* SYSV modifications happen through the whole
* string. Note the pattern is anchored at the end.
*/
newStr = VarModify(ctxt, str, VarSYSVMatch,
newStr = VarModify(ctxt, nstr, VarSYSVMatch,
(ClientData)&pattern);
/*
* Restore the nulled characters
*/
pattern.lhs[pattern.leftLen] = '=';
pattern.rhs[pattern.rightLen] = endc;
*WR(&pattern.lhs[pattern.leftLen]) = '=';
*WR(&pattern.rhs[pattern.rightLen]) = endc;
termc = endc;
} else
#endif
@ -2630,12 +2638,12 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
printf("Result is \"%s\"\n", newStr);
}
if (newStr != str) {
if (newStr != nstr) {
if (*freePtr) {
free (str);
free (nstr);
}
str = newStr;
if (str != var_Error && str != varNoError) {
nstr = newStr;
if (nstr != var_Error && nstr != varNoError) {
*freePtr = TRUE;
} else {
*freePtr = FALSE;
@ -2644,22 +2652,23 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
if (termc == '\0') {
Error("Unclosed variable specification for %s", v->name);
} else if (termc == ':') {
*cp++ = termc;
*WR(cp) = termc;
cp++;
} else {
*cp = termc;
*WR(cp) = termc;
}
tstr = cp;
}
*lengthPtr = tstr - start + 1;
} else {
*lengthPtr = tstr - start + 1;
*tstr = endc;
*WR(tstr) = endc;
}
if (v->flags & VAR_FROM_ENV) {
Boolean destroy = FALSE;
if (str != (char *)Buf_GetAll(v->val, (int *)NULL)) {
if (nstr != (char *)Buf_GetAll(v->val, (int *)NULL)) {
destroy = TRUE;
} else {
/*
@ -2668,7 +2677,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
*/
*freePtr = TRUE;
}
if (str != (char *)Buf_GetAll(v->val, (int *)NULL))
if (nstr != (char *)Buf_GetAll(v->val, (int *)NULL))
Buf_Destroy(v->val, destroy);
free((Address)v->name);
free((Address)v);
@ -2680,29 +2689,29 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr,
*/
if (!(v->flags & VAR_KEEP)) {
if (*freePtr) {
free(str);
free(nstr);
}
*freePtr = FALSE;
if (dynamic) {
str = emalloc(*lengthPtr + 1);
strncpy(str, start, *lengthPtr);
str[*lengthPtr] = '\0';
nstr = emalloc(*lengthPtr + 1);
strncpy(nstr, start, *lengthPtr);
nstr[*lengthPtr] = '\0';
*freePtr = TRUE;
} else {
str = var_Error;
nstr = var_Error;
}
}
if (str != (char *)Buf_GetAll(v->val, (int *)NULL))
if (nstr != (char *)Buf_GetAll(v->val, (int *)NULL))
Buf_Destroy(v->val, TRUE);
free((Address)v->name);
free((Address)v);
}
return (str);
return (nstr);
cleanup:
*lengthPtr = cp - start + 1;
if (*freePtr)
free(str);
free(nstr);
if (delim != '\0')
Error("Unclosed substitution for %s (%c missing)",
v->name, delim);
@ -2730,7 +2739,7 @@ cleanup:
*-----------------------------------------------------------------------
*/
char *
Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
Var_Subst(const char *var, const char *str, GNode *ctxt, Boolean undefErr)
{
Buffer buf; /* Buffer for forming things */
char *val; /* Value to substitute for a variable */
@ -2758,18 +2767,18 @@ Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
* Skip as many characters as possible -- either to the end of
* the string or to the next dollar sign (variable invocation).
*/
char *cp;
const char *cp;
for (cp = str++; *str != '$' && *str != '\0'; str++)
continue;
Buf_AddBytes(buf, str - cp, (Byte *)cp);
Buf_AddBytes(buf, str - cp, (const Byte *)cp);
} else {
if (var != NULL) {
int expand;
for (;;) {
if (str[1] != '(' && str[1] != '{') {
if (str[1] != *var || strlen(var) > 1) {
Buf_AddBytes(buf, 2, (Byte *) str);
Buf_AddBytes(buf, 2, (const Byte *)str);
str += 2;
expand = FALSE;
}
@ -2778,7 +2787,7 @@ Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
break;
}
else {
char *p;
const char *p;
/*
* Scan up to the end of the variable name.
@ -2793,7 +2802,7 @@ Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
* the nested one
*/
if (*p == '$') {
Buf_AddBytes(buf, p - str, (Byte *) str);
Buf_AddBytes(buf, p - str, (const Byte *)str);
str = p;
continue;
}
@ -2806,7 +2815,7 @@ Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
*/
for (;*p != '$' && *p != '\0'; p++)
continue;
Buf_AddBytes(buf, p - str, (Byte *) str);
Buf_AddBytes(buf, p - str, (const Byte *)str);
str = p;
expand = FALSE;
}
@ -2872,9 +2881,9 @@ Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
}
Buf_AddByte (buf, '\0');
str = (char *)Buf_GetAll (buf, (int *)NULL);
val = (char *)Buf_GetAll (buf, (int *)NULL);
Buf_Destroy (buf, FALSE);
return (str);
return (val);
}
/*-