1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-04 09:09:56 +00:00

Convert several typedefs from beeing pointers to structs to be the structs

itself. This will ease constification (think of what 'const Ptr foo'
means if Ptr is a pointer to a struct).

Submitted by:	Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
Hartmut Brandt 2005-02-02 07:36:18 +00:00
parent 0fac1537a2
commit ab9e1eb050
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=141133
11 changed files with 95 additions and 88 deletions

View File

@ -96,7 +96,7 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
void
Buf_OvAddByte(Buffer bp, Byte byte)
Buf_OvAddByte(Buffer *bp, Byte byte)
{
bp->left = 0;
@ -125,7 +125,7 @@ Buf_OvAddByte(Buffer bp, Byte byte)
*-----------------------------------------------------------------------
*/
void
Buf_AddBytes(Buffer bp, size_t numBytes, const Byte *bytesPtr)
Buf_AddBytes(Buffer *bp, size_t numBytes, const Byte *bytesPtr)
{
BufExpand(bp, numBytes);
@ -154,7 +154,7 @@ Buf_AddBytes(Buffer bp, size_t numBytes, const Byte *bytesPtr)
*-----------------------------------------------------------------------
*/
void
Buf_UngetByte(Buffer bp, Byte byte)
Buf_UngetByte(Buffer *bp, Byte byte)
{
if (bp->outPtr != bp->buffer) {
@ -204,7 +204,7 @@ Buf_UngetByte(Buffer bp, Byte byte)
*-----------------------------------------------------------------------
*/
void
Buf_UngetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
Buf_UngetBytes(Buffer *bp, size_t numBytes, Byte *bytesPtr)
{
if ((size_t)(bp->outPtr - bp->buffer) >= numBytes) {
@ -246,7 +246,7 @@ Buf_UngetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
*-----------------------------------------------------------------------
*/
int
Buf_GetByte(Buffer bp)
Buf_GetByte(Buffer *bp)
{
int res;
@ -277,7 +277,7 @@ Buf_GetByte(Buffer bp)
*-----------------------------------------------------------------------
*/
int
Buf_GetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
Buf_GetBytes(Buffer *bp, size_t numBytes, Byte *bytesPtr)
{
if ((size_t)(bp->inPtr - bp->outPtr) < numBytes)
@ -308,7 +308,7 @@ Buf_GetBytes(Buffer bp, size_t numBytes, Byte *bytesPtr)
*-----------------------------------------------------------------------
*/
Byte *
Buf_GetAll(Buffer bp, size_t *numBytesPtr)
Buf_GetAll(Buffer *bp, size_t *numBytesPtr)
{
if (numBytesPtr != NULL)
@ -331,7 +331,7 @@ Buf_GetAll(Buffer bp, size_t *numBytesPtr)
*-----------------------------------------------------------------------
*/
void
Buf_Discard(Buffer bp, size_t numBytes)
Buf_Discard(Buffer *bp, size_t numBytes)
{
if ((size_t)(bp->inPtr - bp->outPtr) <= numBytes) {
@ -357,7 +357,7 @@ Buf_Discard(Buffer bp, size_t numBytes)
*-----------------------------------------------------------------------
*/
size_t
Buf_Size(Buffer buf)
Buf_Size(Buffer *buf)
{
return (buf->inPtr - buf->outPtr);
@ -378,10 +378,10 @@ Buf_Size(Buffer buf)
*
*-----------------------------------------------------------------------
*/
Buffer
Buffer *
Buf_Init(size_t size)
{
Buffer bp; /* New Buffer */
Buffer *bp; /* New Buffer */
bp = emalloc(sizeof(*bp));
@ -410,7 +410,7 @@ Buf_Init(size_t size)
*-----------------------------------------------------------------------
*/
void
Buf_Destroy(Buffer buf, Boolean freeData)
Buf_Destroy(Buffer *buf, Boolean freeData)
{
if (freeData)
@ -433,7 +433,7 @@ Buf_Destroy(Buffer buf, Boolean freeData)
*-----------------------------------------------------------------------
*/
void
Buf_ReplaceLastByte(Buffer buf, Byte byte)
Buf_ReplaceLastByte(Buffer *buf, Byte byte)
{
if (buf->inPtr == buf->outPtr)
Buf_AddByte(buf, byte);

View File

@ -73,24 +73,24 @@ typedef struct Buffer {
Byte *buffer; /* The buffer itself */
Byte *inPtr; /* Place to write to */
Byte *outPtr; /* Place to read from */
} *Buffer;
} Buffer;
/* Buf_AddByte adds a single byte to a buffer. */
#define Buf_AddByte(bp, byte) \
(void)(--(bp)->left <= 0 ? Buf_OvAddByte((bp), (byte)), 1 : \
(*(bp)->inPtr++ = (byte), *(bp)->inPtr = 0), 1)
void Buf_OvAddByte(Buffer, Byte);
void Buf_AddBytes(Buffer, size_t, const Byte *);
void Buf_UngetByte(Buffer, Byte);
void Buf_UngetBytes(Buffer, size_t, Byte *);
int Buf_GetByte(Buffer);
int Buf_GetBytes(Buffer, size_t, Byte *);
Byte *Buf_GetAll(Buffer, size_t *);
void Buf_Discard(Buffer, size_t);
size_t Buf_Size(Buffer);
Buffer Buf_Init(size_t);
void Buf_Destroy(Buffer, Boolean);
void Buf_ReplaceLastByte(Buffer, Byte);
void Buf_OvAddByte(Buffer *, Byte);
void Buf_AddBytes(Buffer *, size_t, const Byte *);
void Buf_UngetByte(Buffer *, Byte);
void Buf_UngetBytes(Buffer *, size_t, Byte *);
int Buf_GetByte(Buffer *);
int Buf_GetBytes(Buffer *, size_t, Byte *);
Byte *Buf_GetAll(Buffer *, size_t *);
void Buf_Discard(Buffer *, size_t);
size_t Buf_Size(Buffer *);
Buffer *Buf_Init(size_t);
void Buf_Destroy(Buffer *, Boolean);
void Buf_ReplaceLastByte(Buffer *, Byte);
#endif /* buf_h_a61a6812 */

View File

@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdlib.h>
#include "buf.h"
#include "cond.h"
#include "dir.h"
#include "globals.h"
@ -189,7 +190,7 @@ CondGetArg(char **linePtr, char **argPtr, char *func, Boolean parens)
{
char *cp;
size_t argLen;
Buffer buf;
Buffer *buf;
cp = *linePtr;
if (parens) {
@ -536,7 +537,7 @@ CondToken(Boolean doEval)
if (!isspace((unsigned char)*condExpr) &&
strchr("!=><", *condExpr) == NULL) {
Buffer buf;
Buffer *buf;
char *cp;
buf = Buf_Init(0);
@ -605,7 +606,7 @@ CondToken(Boolean doEval)
char *string;
char *cp, *cp2;
int qt;
Buffer buf;
Buffer *buf;
do_string_compare:
if (((*op != '!') && (*op != '=')) || (op[1] != '=')) {

View File

@ -75,14 +75,14 @@ __FBSDID("$FreeBSD$");
static int forLevel = 0; /* Nesting level */
static char *forVar; /* Iteration variable */
static Buffer forBuf; /* Commands in loop */
static Buffer *forBuf; /* Commands in loop */
static Lst forLst; /* List of items */
/*
* State of a for loop.
*/
typedef struct _For {
Buffer buf; /* Unexpanded buffer */
Buffer *buf; /* Unexpanded buffer */
char* var; /* Index name */
Lst lst; /* List of variables */
int lineno; /* Line # */
@ -117,7 +117,7 @@ For_Eval(char *line)
if (forLevel == 0) {
Buffer buf;
Buffer *buf;
size_t varlen;
for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)

View File

@ -77,6 +77,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "arch.h"
#include "buf.h"
#include "compat.h"
#include "config.h"
#include "dir.h"
@ -1020,7 +1021,7 @@ Cmd_Exec(char *cmd, char **error)
int pid; /* PID from wait() */
char *res; /* result */
int status; /* command exit status */
Buffer buf; /* buffer to store the result */
Buffer *buf; /* buffer to store the result */
char *cp;
size_t blen;
ssize_t rcnt;

View File

@ -2012,7 +2012,7 @@ ParseSkipLine(int skip, int keep_newline)
char *line;
int c, lastc;
size_t lineLength = 0;
Buffer buf;
Buffer *buf;
buf = Buf_Init(MAKE_BSIZE);
@ -2083,7 +2083,7 @@ ParseSkipLine(int skip, int keep_newline)
static char *
ParseReadLine(void)
{
Buffer buf; /* Buffer for current line */
Buffer *buf; /* Buffer for current line */
int c; /* the current character */
int lastc; /* The most-recent character */
Boolean semiNL; /* treat semi-colons as newlines */

View File

@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include "buf.h"
#include "globals.h"
#include "str.h"
#include "util.h"
@ -507,7 +508,7 @@ Str_SYSVMatch(const char *word, const char *pattern, int *len)
*-----------------------------------------------------------------------
*/
void
Str_SYSVSubst(Buffer buf, const char *pat, const char *src, int len)
Str_SYSVSubst(Buffer *buf, const char *pat, const char *src, int len)
{
const char *m;

View File

@ -41,9 +41,10 @@
#ifndef str_h_44db59e6
#define str_h_44db59e6
#include "buf.h"
#include "sprite.h"
struct Buffer;
/*
* These constants are all used by the Str_Concat function to decide how the
* final string should look. If STR_ADDSPACE is given, a space will be
@ -61,6 +62,6 @@ char *MAKEFLAGS_quote(const char *);
char **MAKEFLAGS_break(const char *, int *);
int Str_Match(const char *, const char *);
const char *Str_SYSVMatch(const char *, const char *, int *);
void Str_SYSVSubst(Buffer, const char *, const char *, int);
void Str_SYSVSubst(struct Buffer *, const char *, const char *, int);
#endif /* str_h_44db59e6 */

View File

@ -143,7 +143,7 @@ static void VarDelete(void *);
static char *VarGetPattern(GNode *, int, char **, int, int *, size_t *,
VarPattern *);
static char *VarModify(char *,
Boolean (*)(const char *, Boolean, Buffer, void *),
Boolean (*)(const char *, Boolean, Buffer *, void *),
void *);
static int VarPrintVar(void *, void *);
@ -580,10 +580,10 @@ Var_Value(char *name, GNode *ctxt, char **frp)
*-----------------------------------------------------------------------
*/
static char *
VarModify(char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *),
VarModify(char *str, Boolean (*modProc)(const char *, Boolean, Buffer *, void *),
void *datum)
{
Buffer buf; /* Buffer for the new string */
Buffer *buf; /* Buffer for the new string */
Boolean addSpace; /* TRUE if need to add a space to the
* buffer before adding the trimmed
* word */
@ -624,7 +624,7 @@ VarModify(char *str, Boolean (*modProc)(const char *, Boolean, Buffer, void *),
static char *
VarSortWords(char *str, int (*cmp)(const void *, const void *))
{
Buffer buf;
Buffer *buf;
char **av;
int ac, i;
@ -674,7 +674,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
size_t *length, VarPattern *pattern)
{
char *cp;
Buffer buf = Buf_Init(0);
Buffer *buf = Buf_Init(0);
size_t junk;
if (length == NULL)
@ -785,7 +785,7 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags,
char *
Var_Quote(const char *str)
{
Buffer buf;
Buffer *buf;
/* This should cover most shells :-( */
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
char *ret;
@ -930,7 +930,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
}
} else {
/* build up expanded variable name in this buffer */
Buffer buf = Buf_Init(MAKE_BSIZE);
Buffer *buf = Buf_Init(MAKE_BSIZE);
startc = str[1];
endc = startc == '(' ? ')' : '}';
@ -1212,7 +1212,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
{
VarPattern pattern;
char del;
Buffer buf; /* Buffer for patterns */
Buffer *buf; /* Buffer for patterns */
pattern.flags = 0;
del = tstr[1];
@ -1457,7 +1457,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
}
case 'L':
if (tstr[1] == endc || tstr[1] == ':') {
Buffer buf;
Buffer *buf;
buf = Buf_Init(MAKE_BSIZE);
for (cp = str; *cp ; cp++)
Buf_AddByte(buf, (Byte)tolower(*cp));
@ -1497,7 +1497,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
/*FALLTHRU*/
case 'U':
if (tstr[1] == endc || tstr[1] == ':') {
Buffer buf;
Buffer *buf;
buf = Buf_Init(MAKE_BSIZE);
for (cp = str; *cp ; cp++)
Buf_AddByte(buf, (Byte)toupper(*cp));
@ -1722,7 +1722,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, size_t *lengthPtr,
char *
Var_Subst(char *var, char *str, GNode *ctxt, Boolean undefErr)
{
Buffer buf; /* Buffer for forming things */
Buffer *buf; /* Buffer for forming things */
char *val; /* Value to substitute for a variable */
size_t length; /* Length of the variable invocation */
Boolean doFree; /* Set true if val should be freed */

View File

@ -44,22 +44,25 @@
#include <regex.h>
#include "buf.h"
#include "config.h"
struct GNode;
struct Buffer;
typedef struct Var {
char *name; /* the variable's name */
Buffer val; /* its value */
int flags; /* miscellaneous status flags */
#define VAR_IN_USE 1 /* Variable's value currently being used.
* Used to avoid recursion */
#define VAR_FROM_ENV 2 /* Variable comes from the environment */
#define VAR_JUNK 4 /* Variable is a junk variable that
* should be destroyed when done with
* it. Used by Var_Parse for undefined,
* modified variables */
char *name; /* the variable's name */
struct Buffer *val; /* its value */
int flags; /* miscellaneous status flags */
#define VAR_IN_USE 1 /* Variable's value currently being used.
* Used to avoid recursion */
#define VAR_FROM_ENV 2 /* Variable comes from the environment */
#define VAR_JUNK 4 /* Variable is a junk variable that
* should be destroyed when done with
* it. Used by Var_Parse for undefined,
* modified variables */
} Var;
/* Var*Pattern flags */
@ -71,19 +74,19 @@ typedef struct Var {
#define VAR_NOSUBST 0x20 /* don't expand vars in VarGetPattern */
typedef struct {
char *lhs; /* String to match */
size_t leftLen; /* Length of string */
char *rhs; /* Replacement string (w/ &'s removed) */
size_t rightLen; /* Length of replacement */
int flags;
char *lhs; /* String to match */
size_t leftLen; /* Length of string */
char *rhs; /* Replacement string (w/ &'s removed) */
size_t rightLen; /* Length of replacement */
int flags;
} VarPattern;
typedef struct {
regex_t re;
int nsub;
regmatch_t *matches;
char *replace;
int flags;
regex_t re;
int nsub;
regmatch_t *matches;
char *replace;
int flags;
} VarREPattern;
/*
@ -94,17 +97,17 @@ void VarREError(int, regex_t *, const char *);
/*
* var_modify.c
*/
Boolean VarHead(const char *, Boolean, Buffer, void *);
Boolean VarTail(const char *, Boolean, Buffer, void *);
Boolean VarSuffix(const char *, Boolean, Buffer, void *);
Boolean VarRoot(const char *, Boolean, Buffer, void *);
Boolean VarMatch(const char *, Boolean, Buffer, void *);
Boolean VarHead(const char *, Boolean, struct Buffer *, void *);
Boolean VarTail(const char *, Boolean, struct Buffer *, void *);
Boolean VarSuffix(const char *, Boolean, struct Buffer *, void *);
Boolean VarRoot(const char *, Boolean, struct Buffer *, void *);
Boolean VarMatch(const char *, Boolean, struct Buffer *, void *);
#ifdef SYSVVARSUB
Boolean VarSYSVMatch(const char *, Boolean, Buffer, void *);
Boolean VarSYSVMatch(const char *, Boolean, struct Buffer *, void *);
#endif
Boolean VarNoMatch(const char *, Boolean, Buffer, void *);
Boolean VarRESubstitute(const char *, Boolean, Buffer, void *);
Boolean VarSubstitute(const char *, Boolean, Buffer, void *);
Boolean VarNoMatch(const char *, Boolean, struct Buffer *, void *);
Boolean VarRESubstitute(const char *, Boolean, struct Buffer *, void *);
Boolean VarSubstitute(const char *, Boolean, struct Buffer *, void *);
void Var_Delete(char *, struct GNode *);
void Var_Set(char *, char *, struct GNode *);

View File

@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
Boolean
VarHead(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
VarHead(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
{
char *slash;
char *buffer;
@ -113,7 +113,7 @@ VarHead(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
*-----------------------------------------------------------------------
*/
Boolean
VarTail(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
VarTail(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
{
const char *slash;
@ -145,7 +145,7 @@ VarTail(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
*-----------------------------------------------------------------------
*/
Boolean
VarSuffix(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
VarSuffix(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
{
const char *dot;
@ -176,7 +176,7 @@ VarSuffix(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
*-----------------------------------------------------------------------
*/
Boolean
VarRoot(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
VarRoot(const char *word, Boolean addSpace, Buffer *buf, void *dummy __unused)
{
char *buffer;
char *dot;
@ -213,7 +213,7 @@ VarRoot(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
*-----------------------------------------------------------------------
*/
Boolean
VarMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern)
VarMatch(const char *word, Boolean addSpace, Buffer *buf, void *pattern)
{
if (Str_Match(word, pattern)) {
@ -244,7 +244,7 @@ VarMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern)
*-----------------------------------------------------------------------
*/
Boolean
VarSYSVMatch(const char *word, Boolean addSpace, Buffer buf, void *patp)
VarSYSVMatch(const char *word, Boolean addSpace, Buffer *buf, void *patp)
{
int len;
const char *ptr;
@ -282,7 +282,7 @@ VarSYSVMatch(const char *word, Boolean addSpace, Buffer buf, void *patp)
*-----------------------------------------------------------------------
*/
Boolean
VarNoMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern)
VarNoMatch(const char *word, Boolean addSpace, Buffer *buf, void *pattern)
{
if (!Str_Match(word, pattern)) {
@ -311,7 +311,7 @@ VarNoMatch(const char *word, Boolean addSpace, Buffer buf, void *pattern)
*-----------------------------------------------------------------------
*/
Boolean
VarSubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp)
VarSubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
{
size_t wordLen; /* Length of word */
const char *cp; /* General pointer */
@ -474,7 +474,7 @@ VarSubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp)
*-----------------------------------------------------------------------
*/
Boolean
VarRESubstitute(const char *word, Boolean addSpace, Buffer buf, void *patternp)
VarRESubstitute(const char *word, Boolean addSpace, Buffer *buf, void *patternp)
{
VarREPattern *pat;
int xrv;