diff options
author | Marc Espie <espie@cvs.openbsd.org> | 1999-12-16 16:41:43 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 1999-12-16 16:41:43 +0000 |
commit | 187eaef221933174b3243421f178461acc5bcc8f (patch) | |
tree | 6fc825dbe4e171a09ee446ede723d87098232bd8 /usr.bin/make | |
parent | e0e493a9c8a6bc69440e9a2e1dae99bad58ef80b (diff) |
Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/buf.c | 46 | ||||
-rw-r--r-- | usr.bin/make/buf.h | 10 | ||||
-rw-r--r-- | usr.bin/make/cond.c | 12 | ||||
-rw-r--r-- | usr.bin/make/for.c | 6 | ||||
-rw-r--r-- | usr.bin/make/main.c | 7 | ||||
-rw-r--r-- | usr.bin/make/parse.c | 8 | ||||
-rw-r--r-- | usr.bin/make/var.c | 30 |
7 files changed, 42 insertions, 77 deletions
diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 3daef93fd1a..1a104899cfb 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.9 1999/12/16 16:27:12 espie Exp $ */ +/* $OpenBSD: buf.c,v 1.10 1999/12/16 16:41:41 espie Exp $ */ /* $NetBSD: buf.c,v 1.9 1996/12/31 17:53:21 christos Exp $ */ /* @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: buf.c,v 1.9 1999/12/16 16:27:12 espie Exp $"; +static char rcsid[] = "$OpenBSD: buf.c,v 1.10 1999/12/16 16:41:41 espie Exp $"; #endif #endif /* not lint */ @@ -149,30 +149,6 @@ Buf_AddChars(bp, numBytes, bytesPtr) /*- *----------------------------------------------------------------------- - * Buf_GetAll -- - * Get all the available data at once. - * - * Results: - * A pointer to the data and the number of chars available. - * - *----------------------------------------------------------------------- - */ -char * -Buf_GetAll(bp, numBytesPtr) - Buffer bp; - size_t *numBytesPtr; -{ - - if (numBytesPtr != NULL) { - *numBytesPtr = bp->inPtr - bp->outPtr; - } - - *bp->inPtr = 0; - return (bp->outPtr); -} - -/*- - *----------------------------------------------------------------------- * Buf_Reset - * Throw away all chars in a buffer. * @@ -192,24 +168,6 @@ Buf_Reset(bp) /*- *----------------------------------------------------------------------- - * Buf_Size -- - * Returns the number of chars in the given buffer. Doesn't include - * the null-terminating char. - * - * Results: - * The number of chars. - * - *----------------------------------------------------------------------- - */ -int -Buf_Size(buf) - Buffer buf; -{ - return (buf->inPtr - buf->outPtr); -} - -/*- - *----------------------------------------------------------------------- * Buf_Init -- * Initialize a buffer. If no initial size is given, a reasonable * default is used. diff --git a/usr.bin/make/buf.h b/usr.bin/make/buf.h index 37c74321430..3531ad92bd7 100644 --- a/usr.bin/make/buf.h +++ b/usr.bin/make/buf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.h,v 1.8 1999/12/16 16:27:12 espie Exp $ */ +/* $OpenBSD: buf.h,v 1.9 1999/12/16 16:41:41 espie Exp $ */ /* $NetBSD: buf.h,v 1.7 1996/12/31 17:53:22 christos Exp $ */ /* @@ -81,10 +81,14 @@ void Buf_AddChars __P((Buffer, size_t, const char *)); /* Buf_AddInterval -- Add characters between pointers s and e to buffer. */ #define Buf_AddInterval(b, s, e) Buf_AddChars((b), (e) - (s), (s)) +/* Buf_Retrieve -- Retrieve data from a buffer, as a NULL terminated string. */ +#define Buf_Retrieve(bp) (*(bp)->inPtr = '\0', (bp)->outPtr) + +/* Buf_Size -- Return the number of chars in the given buffer. + * Doesn't include the null-terminating char. */ +#define Buf_Size(bp) ((size_t)((bp)->inPtr - (bp)->outPtr)) -char *Buf_GetAll __P((Buffer, size_t *)); void Buf_Reset __P((Buffer)); -int Buf_Size __P((Buffer)); Buffer Buf_Init __P((size_t)); void Buf_Destroy __P((Buffer, Boolean)); void Buf_ReplaceLastChar __P((Buffer, char)); diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c index 562e6b73d8d..10be8276770 100644 --- a/usr.bin/make/cond.c +++ b/usr.bin/make/cond.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cond.c,v 1.7 1999/12/09 18:18:24 espie Exp $ */ +/* $OpenBSD: cond.c,v 1.8 1999/12/16 16:41:41 espie Exp $ */ /* $NetBSD: cond.c,v 1.7 1996/11/06 17:59:02 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: cond.c,v 1.7 1999/12/09 18:18:24 espie Exp $"; +static char rcsid[] = "$OpenBSD: cond.c,v 1.8 1999/12/16 16:41:41 espie Exp $"; #endif #endif /* not lint */ @@ -246,7 +246,8 @@ CondGetArg(linePtr, argPtr, func, parens) } Buf_AddChar(buf, '\0'); - *argPtr = Buf_GetAll(buf, &argLen); + *argPtr = Buf_Retrieve(buf); + argLen = Buf_Size(buf); Buf_Destroy(buf, FALSE); while (*cp == ' ' || *cp == '\t') { @@ -556,7 +557,8 @@ CondToken(doEval) Buf_AddChar(buf, *condExpr); Buf_AddChar(buf, '\0'); - lhs = Buf_GetAll(buf, &varSpecLen); + lhs = Buf_Retrieve(buf); + varSpecLen = Buf_Size(buf); Buf_Destroy(buf, FALSE); doFree = TRUE; @@ -653,7 +655,7 @@ do_string_compare: Buf_AddChar(buf, '\0'); - string = Buf_GetAll(buf, NULL); + string = Buf_Retrieve(buf); Buf_Destroy(buf, FALSE); if (DEBUG(COND)) { diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index 7274e0ed873..f2541465003 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -1,4 +1,4 @@ -/* $OpenBSD: for.c,v 1.8 1999/12/09 18:18:24 espie Exp $ */ +/* $OpenBSD: for.c,v 1.9 1999/12/16 16:41:41 espie Exp $ */ /* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */ /* @@ -65,7 +65,7 @@ #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: for.c,v 1.8 1999/12/09 18:18:24 espie Exp $"; +static char rcsid[] = "$OpenBSD: for.c,v 1.9 1999/12/16 16:41:41 espie Exp $"; #endif #endif /* not lint */ @@ -278,7 +278,7 @@ ForExec(namep, argp) Var_Set(arg->var, name, VAR_GLOBAL); if (DEBUG(FOR)) (void) fprintf(stderr, "--- %s = %s\n", arg->var, name); - Parse_FromString(Var_Subst(arg->var, Buf_GetAll(arg->buf, NULL), + Parse_FromString(Var_Subst(arg->var, Buf_Retrieve(arg->buf), VAR_GLOBAL, FALSE), arg->lineno); Var_Delete(arg->var, VAR_GLOBAL); diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index b5822fe7e9f..fdb8d9710b1 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.20 1999/12/09 18:20:06 espie Exp $ */ +/* $OpenBSD: main.c,v 1.21 1999/12/16 16:41:41 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* @@ -49,7 +49,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.20 1999/12/09 18:20:06 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.21 1999/12/16 16:41:41 espie Exp $"; #endif #endif /* not lint */ @@ -1004,7 +1004,8 @@ Cmd_Exec(cmd, err) while(((pid = wait(&status)) != cpid) && (pid >= 0)) continue; - res = Buf_GetAll(buf, &length); + res = Buf_Retrieve(buf); + length = Buf_Size(buf); Buf_Destroy(buf, FALSE); if (cc == -1) diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 379efa743fb..80b8383ef70 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.26 1999/12/16 16:27:12 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.27 1999/12/16 16:41:42 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: parse.c,v 1.26 1999/12/16 16:27:12 espie Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.27 1999/12/16 16:41:42 espie Exp $"; #endif #endif /* not lint */ @@ -2131,7 +2131,7 @@ ParseSkipLine(skip) } Buf_AddChar(buf, '\0'); - line = Buf_GetAll(buf, NULL); + line = Buf_Retrieve(buf); lineno++; /* allow for non-newline terminated lines while skipping */ if (line[0] == '.') @@ -2340,7 +2340,7 @@ test_char: Buf_AddChar(buf, lastc); } Buf_AddChar(buf, '\0'); - line = Buf_GetAll(buf, NULL); + line = Buf_Retrieve(buf); Buf_Destroy(buf, FALSE); /* diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index bdaaec45622..01faa29604f 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.20 1999/12/16 16:27:13 espie Exp $ */ +/* $OpenBSD: var.c,v 1.21 1999/12/16 16:41:42 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: var.c,v 1.20 1999/12/16 16:27:13 espie Exp $"; +static char rcsid[] = "$OpenBSD: var.c,v 1.21 1999/12/16 16:41:42 espie Exp $"; #endif #endif /* not lint */ @@ -544,7 +544,7 @@ Var_Append (name, val, ctxt) if (DEBUG(VAR)) { printf("%s:%s = %s\n", ctxt->name, name, - Buf_GetAll(v->val, NULL)); + Buf_Retrieve(v->val)); } } @@ -597,11 +597,10 @@ Var_Value(name, ctxt) { Var *v; - v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); - if (v != (Var *) NIL) { - char *p = Buf_GetAll(v->val, NULL); - return p; - } else + v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); + if (v != NULL) + return Buf_Retrieve(v->val); + else return NULL; } @@ -1280,7 +1279,7 @@ VarModify (str, modProc, datum) free(as); free(av); Buf_AddChar(buf, '\0'); - str = Buf_GetAll(buf, NULL); + str = Buf_Retrieve(buf); Buf_Destroy(buf, FALSE); return (str); } @@ -1379,7 +1378,8 @@ VarGetPattern(ctxt, err, tstr, delim, flags, length, pattern) } else { *tstr = ++cp; - cp = Buf_GetAll(buf, length); + cp = Buf_Retrieve(buf); + *length = Buf_Size(buf); *length -= 1; /* Don't count the NULL */ Buf_Destroy(buf, FALSE); return cp; @@ -1415,7 +1415,7 @@ VarQuote(str) Buf_AddChar(buf, *str); } Buf_AddChar(buf, '\0'); - str = Buf_GetAll(buf, NULL); + str = Buf_Retrieve(buf); Buf_Destroy(buf, FALSE); return str; } @@ -1575,7 +1575,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) * the only one who sets these things and we sure don't * but nested invocations in them... */ - val = Buf_GetAll(v->val, NULL); + val = Buf_Retrieve(v->val); if (str[3] == 'D') { val = VarModify(val, VarHead, (ClientData)0); @@ -1679,7 +1679,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) * been dynamically-allocated, so it will need freeing when we * return. */ - str = Buf_GetAll(v->val, NULL); + str = Buf_Retrieve(v->val); if (strchr (str, '$') != (char *)NULL) { str = Var_Subst(NULL, str, ctxt, err); *freePtr = TRUE; @@ -2258,7 +2258,7 @@ Var_Subst (var, str, ctxt, undefErr) } Buf_AddChar(buf, '\0'); - str = Buf_GetAll(buf, NULL); + str = Buf_Retrieve(buf); Buf_Destroy(buf, FALSE); return (str); } @@ -2343,7 +2343,7 @@ VarPrintVar (vp, dummy) ClientData dummy; { Var *v = (Var *) vp; - printf ("%-16s = %s\n", v->name, Buf_GetAll(v->val, NULL)); + printf ("%-16s = %s\n", v->name, Buf_Retrieve(v->val)); return (dummy ? 0 : 0); } |