diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-09-22 10:23:03 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-09-22 10:23:03 +0000 |
commit | 9742b7e58016b3bf9197fb17a1820582bdf311fb (patch) | |
tree | dd5b21071c586860a07db952474ab78b82d89033 /usr.bin/make | |
parent | 4d5f4442c51a6c709703b7cc56b5fd143a46ec69 (diff) |
reindent
Diffstat (limited to 'usr.bin/make')
-rw-r--r-- | usr.bin/make/lowparse.c | 446 |
1 files changed, 225 insertions, 221 deletions
diff --git a/usr.bin/make/lowparse.c b/usr.bin/make/lowparse.c index 6fafc03d98c..3983988129f 100644 --- a/usr.bin/make/lowparse.c +++ b/usr.bin/make/lowparse.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: lowparse.c,v 1.20 2007/09/17 09:28:36 espie Exp $ */ +/* $OpenBSD: lowparse.c,v 1.21 2007/09/22 10:23:02 espie Exp $ */ /* low-level parsing functions. */ @@ -53,19 +53,19 @@ static LIST fileNames; /* file names to free at end */ /* Input stream structure, file or string. */ typedef struct { - const char *fname; /* Name of file */ - unsigned long lineno; /* Line number */ - FILE *F; /* Open stream, or NULL if pure string. */ - char *str; /* Input string, if F == NULL. */ - - /* Line buffer. */ - char *ptr; /* Where we are. */ - char *end; /* Don't overdo it. */ + const char *fname; /* Name of file */ + unsigned long lineno; /* Line number */ + FILE *F; /* Open stream, or NULL if pure string. */ + char *str; /* Input string, if F == NULL. */ + + /* Line buffer. */ + char *ptr; /* Where we are. */ + char *end; /* Don't overdo it. */ } IFile; -static IFile *current; /* IFile being parsed. */ +static IFile *current; /* IFile being parsed. */ -static LIST input_stack; /* Stack of IFiles waiting to be parsed +static LIST input_stack; /* Stack of IFiles waiting to be parsed * (includes and loop reparses) */ /* IFile ctors. @@ -84,7 +84,8 @@ static void free_ifile(IFile *); /* Handling basic character reading. * c = ParseReadc(); * New character c from current input stream, or EOF at end of stream. */ -#define ParseReadc() current->ptr < current->end ? *current->ptr++ : newline() +#define ParseReadc() \ + current->ptr < current->end ? *current->ptr++ : newline() /* len = newline(); * Guts for ParseReadc. Grabs a new line off fgetln when we have * consumed the current line and returns its length. Or EOF at end of @@ -110,205 +111,206 @@ static int ParseSkipEmptyLines(Buffer); static IFile * new_ifile(const char *name, FILE *stream) { - IFile *ifile; + IFile *ifile; #if 0 - Lst_AtEnd(&fileNames, name); + Lst_AtEnd(&fileNames, name); #endif - ifile = emalloc(sizeof(*ifile)); - ifile->fname = name; - ifile->str = NULL; - /* Naturally enough, we start reading at line 0. */ - ifile->lineno = 0; - ifile->F = stream; - ifile->ptr = ifile->end = NULL; - return ifile; + ifile = emalloc(sizeof(*ifile)); + ifile->fname = name; + ifile->str = NULL; + /* Naturally enough, we start reading at line 0. */ + ifile->lineno = 0; + ifile->F = stream; + ifile->ptr = ifile->end = NULL; + return ifile; } static void free_ifile(IFile *ifile) { - if (ifile->F && fileno(ifile->F) != STDIN_FILENO) - (void)fclose(ifile->F); - free(ifile->str); - /* Note we can't free the file names yet, as they are embedded in GN for - * error reports. */ - free(ifile); + if (ifile->F && fileno(ifile->F) != STDIN_FILENO) + (void)fclose(ifile->F); + free(ifile->str); + /* Note we can't free the file names yet, as they are embedded in GN + * for error reports. */ + free(ifile); } static IFile * new_istring(char *str, const char *name, unsigned long lineno) { - IFile *ifile; - - ifile = emalloc(sizeof(*ifile)); - /* No malloc, name is always taken from an already existing ifile */ - ifile->fname = name; - ifile->F = NULL; - /* Strings are used in for loops, so we need to reset the line counter - * to an appropriate value. */ - ifile->lineno = lineno; - ifile->ptr = ifile->str = str; - ifile->end = str + strlen(str); - return ifile; + IFile *ifile; + + ifile = emalloc(sizeof(*ifile)); + /* No malloc, name is always taken from an already existing ifile */ + ifile->fname = name; + ifile->F = NULL; + /* Strings are used in for loops, so we need to reset the line counter + * to an appropriate value. */ + ifile->lineno = lineno; + ifile->ptr = ifile->str = str; + ifile->end = str + strlen(str); + return ifile; } void Parse_FromString(char *str, unsigned long lineno) { - if (DEBUG(FOR)) - (void)fprintf(stderr, "%s\n----\n", str); + if (DEBUG(FOR)) + (void)fprintf(stderr, "%s\n----\n", str); - if (current != NULL) - Lst_Push(&input_stack, current); - current = new_istring(str, current->fname, lineno); + if (current != NULL) + Lst_Push(&input_stack, current); + current = new_istring(str, current->fname, lineno); } void Parse_FromFile(const char *name, FILE *stream) { - if (current != NULL) - Lst_Push(&input_stack, current); - current = new_ifile(name, stream); + if (current != NULL) + Lst_Push(&input_stack, current); + current = new_ifile(name, stream); } bool Parse_NextFile(void) { - if (current != NULL) - free_ifile(current); - current = (IFile *)Lst_Pop(&input_stack); - return current != NULL; + if (current != NULL) + free_ifile(current); + current = (IFile *)Lst_Pop(&input_stack); + return current != NULL; } static int newline(void) { - size_t len; + size_t len; - if (current->F) { - current->ptr = fgetln(current->F, &len); - if (current->ptr) { - current->end = current->ptr + len; - return *current->ptr++; - } else { - current->end = NULL; + if (current->F) { + current->ptr = fgetln(current->F, &len); + if (current->ptr) { + current->end = current->ptr + len; + return *current->ptr++; + } else { + current->end = NULL; + } } - } - return EOF; + return EOF; } static int skiptoendofline(void) { - if (current->F) { - if (current->end - current->ptr > 1) - current->ptr = current->end - 1; - if (*current->ptr == '\n') - return *current->ptr++; - return EOF; - } else { - int c; + if (current->F) { + if (current->end - current->ptr > 1) + current->ptr = current->end - 1; + if (*current->ptr == '\n') + return *current->ptr++; + return EOF; + } else { + int c; - do { - c = ParseReadc(); - } while (c != '\n' && c != EOF); - return c; - } + do { + c = ParseReadc(); + } while (c != '\n' && c != EOF); + return c; + } } char * Parse_ReadNextConditionalLine(Buffer linebuf) { - int c; + int c; /* If first char isn't dot, skip to end of line, handling \ */ - while ((c = ParseReadc()) != '.') { - for (;c != '\n'; c = ParseReadc()) { - if (c == '\\') { - c = ParseReadc(); - if (c == '\n') - current->lineno++; - } - if (c == EOF) { - Parse_Error(PARSE_FATAL, "Unclosed conditional"); - return NULL; - } + while ((c = ParseReadc()) != '.') { + for (;c != '\n'; c = ParseReadc()) { + if (c == '\\') { + c = ParseReadc(); + if (c == '\n') + current->lineno++; + } + if (c == EOF) { + Parse_Error(PARSE_FATAL, + "Unclosed conditional"); + return NULL; + } + } + current->lineno++; } - current->lineno++; - } /* This is the line we need to copy */ - return Parse_ReadUnparsedLine(linebuf, "conditional"); + return Parse_ReadUnparsedLine(linebuf, "conditional"); } static void ParseFoldLF(Buffer linebuf, int c) { - for (;;) { - if (c == '\n') { - current->lineno++; - break; - } - if (c == EOF) - break; - Buf_AddChar(linebuf, c); - c = ParseReadc(); - while (c == '\\') { - c = ParseReadc(); - if (c == '\n') { - Buf_AddSpace(linebuf); - current->lineno++; - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - } else { - Buf_AddChar(linebuf, '\\'); - if (c == '\\') { - Buf_AddChar(linebuf, '\\'); - c = ParseReadc(); + for (;;) { + if (c == '\n') { + current->lineno++; + break; + } + if (c == EOF) + break; + Buf_AddChar(linebuf, c); + c = ParseReadc(); + while (c == '\\') { + c = ParseReadc(); + if (c == '\n') { + Buf_AddSpace(linebuf); + current->lineno++; + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + } else { + Buf_AddChar(linebuf, '\\'); + if (c == '\\') { + Buf_AddChar(linebuf, '\\'); + c = ParseReadc(); + } + break; + } } - break; - } } - } } char * Parse_ReadUnparsedLine(Buffer linebuf, const char *type) { - int c; - - Buf_Reset(linebuf); - c = ParseReadc(); - if (c == EOF) { - Parse_Error(PARSE_FATAL, "Unclosed %s", type); - return NULL; - } + int c; - /* Handle '\' at beginning of line, since \\n needs special treatment */ - while (c == '\\') { + Buf_Reset(linebuf); c = ParseReadc(); - if (c == '\n') { - current->lineno++; - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - } else { - Buf_AddChar(linebuf, '\\'); - if (c == '\\') { - Buf_AddChar(linebuf, '\\'); + if (c == EOF) { + Parse_Error(PARSE_FATAL, "Unclosed %s", type); + return NULL; + } + + /* Handle '\' at beginning of line, since \\n needs special treatment */ + while (c == '\\') { c = ParseReadc(); - } - break; + if (c == '\n') { + current->lineno++; + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + } else { + Buf_AddChar(linebuf, '\\'); + if (c == '\\') { + Buf_AddChar(linebuf, '\\'); + c = ParseReadc(); + } + break; + } } - } - ParseFoldLF(linebuf, c); + ParseFoldLF(linebuf, c); - return Buf_Retrieve(linebuf); + return Buf_Retrieve(linebuf); } /* This is a fairly complex function, but without it, we could not skip @@ -316,71 +318,72 @@ Parse_ReadUnparsedLine(Buffer linebuf, const char *type) static int ParseSkipEmptyLines(Buffer linebuf) { - int c; /* the current character */ + int c; /* the current character */ - for (;;) { - Buf_Reset(linebuf); - c = ParseReadc(); - /* Strip leading spaces, fold on '\n' */ - if (c == ' ') { - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - while (c == '\\') { + for (;;) { + Buf_Reset(linebuf); c = ParseReadc(); - if (c == '\n') { - current->lineno++; - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - } else { - Buf_AddChar(linebuf, '\\'); - if (c == '\\') { - Buf_AddChar(linebuf, '\\'); - c = ParseReadc(); - } - if (c == EOF) - return '\n'; - else - return c; + /* Strip leading spaces, fold on '\n' */ + if (c == ' ') { + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + while (c == '\\') { + c = ParseReadc(); + if (c == '\n') { + current->lineno++; + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + } else { + Buf_AddChar(linebuf, '\\'); + if (c == '\\') { + Buf_AddChar(linebuf, '\\'); + c = ParseReadc(); + } + if (c == EOF) + return '\n'; + else + return c; + } + } + assert(c != '\t'); } - } - assert(c != '\t'); - } - if (c == '#') - c = skiptoendofline(); - /* Almost identical to spaces, except this occurs after comments - * have been taken care of, and we keep the tab itself. */ - if (c == '\t') { - Buf_AddChar(linebuf, '\t'); - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - while (c == '\\') { - c = ParseReadc(); - if (c == '\n') { - current->lineno++; - do { - c = ParseReadc(); - } while (c == ' ' || c == '\t'); - } else { - Buf_AddChar(linebuf, '\\'); - if (c == '\\') { - Buf_AddChar(linebuf, '\\'); - c = ParseReadc(); - } - if (c == EOF) - return '\n'; - else - return c; + if (c == '#') + c = skiptoendofline(); + /* Almost identical to spaces, except this occurs after + * comments have been taken care of, and we keep the tab + * itself. */ + if (c == '\t') { + Buf_AddChar(linebuf, '\t'); + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + while (c == '\\') { + c = ParseReadc(); + if (c == '\n') { + current->lineno++; + do { + c = ParseReadc(); + } while (c == ' ' || c == '\t'); + } else { + Buf_AddChar(linebuf, '\\'); + if (c == '\\') { + Buf_AddChar(linebuf, '\\'); + c = ParseReadc(); + } + if (c == EOF) + return '\n'; + else + return c; + } + } } - } + if (c == '\n') + current->lineno++; + else + return c; } - if (c == '\n') - current->lineno++; - else - return c; - } } /* Parse_ReadNormalLine removes beginning and trailing blanks (but keeps @@ -396,45 +399,45 @@ ParseSkipEmptyLines(Buffer linebuf) char * Parse_ReadNormalLine(Buffer linebuf) { - int c; /* the current character */ + int c; /* the current character */ - c = ParseSkipEmptyLines(linebuf); + c = ParseSkipEmptyLines(linebuf); - if (c == EOF) - return NULL; - else { - ParseFoldLF(linebuf, c); - Buf_KillTrailingSpaces(linebuf); - return Buf_Retrieve(linebuf); - } + if (c == EOF) + return NULL; + else { + ParseFoldLF(linebuf, c); + Buf_KillTrailingSpaces(linebuf); + return Buf_Retrieve(linebuf); + } } unsigned long Parse_Getlineno(void) { - return current ? current->lineno : 0; + return current ? current->lineno : 0; } const char * Parse_Getfilename(void) { - return current ? current->fname : NULL; + return current ? current->fname : NULL; } #ifdef CLEANUP void LowParse_Init(void) { - Static_Lst_Init(&input_stack); - current = NULL; + Static_Lst_Init(&input_stack); + current = NULL; } void LowParse_End(void) { - Lst_Destroy(&input_stack, NOFREE); /* Should be empty now */ + Lst_Destroy(&input_stack, NOFREE); /* Should be empty now */ #if 0 - Lst_Destroy(&fileNames, (SimpleProc)free); + Lst_Destroy(&fileNames, (SimpleProc)free); #endif } #endif @@ -443,13 +446,14 @@ LowParse_End(void) void Parse_ReportErrors(void) { - if (fatal_errors) { + if (fatal_errors) { #ifdef CLEANUP - while (Parse_NextFile()) - ; + while (Parse_NextFile()) + ; #endif - fprintf(stderr, "Fatal errors encountered -- cannot continue\n"); - exit(1); - } else - assert(current == NULL); + fprintf(stderr, + "Fatal errors encountered -- cannot continue\n"); + exit(1); + } else + assert(current == NULL); } |