| 1 |
/* |
| 2 |
* $Id: awk.c 443 2006-05-30 04:37:13Z darren $ |
| 3 |
* |
| 4 |
* Copyright (c) 2000-2002, Darren Hiebert |
| 5 |
* |
| 6 |
* This source code is released for free distribution under the terms of the |
| 7 |
* GNU General Public License. |
| 8 |
* |
| 9 |
* This module contains functions for generating tags for AWK functions. |
| 10 |
*/ |
| 11 |
|
| 12 |
/* |
| 13 |
* INCLUDE FILES |
| 14 |
*/ |
| 15 |
#include "general.h" /* must always come first */ |
| 16 |
|
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
#include "parse.h" |
| 20 |
#include "read.h" |
| 21 |
#include "vstring.h" |
| 22 |
|
| 23 |
/* |
| 24 |
* DATA DEFINITIONS |
| 25 |
*/ |
| 26 |
typedef enum eAwkKinds { |
| 27 |
K_FUNCTION |
| 28 |
} awkKind; |
| 29 |
|
| 30 |
static kindOption AwkKinds [] = { |
| 31 |
{ TRUE, 'f', "function", "functions" } |
| 32 |
}; |
| 33 |
|
| 34 |
/* |
| 35 |
* FUNCTION DEFINITIONS |
| 36 |
*/ |
| 37 |
|
| 38 |
static void findAwkTags (void) |
| 39 |
{ |
| 40 |
vString *name = vStringNew (); |
| 41 |
const unsigned char *line; |
| 42 |
|
| 43 |
while ((line = fileReadLine ()) != NULL) |
| 44 |
{ |
| 45 |
if (strncmp ((const char*) line, "function", (size_t) 8) == 0 && |
| 46 |
isspace ((int) line [8])) |
| 47 |
{ |
| 48 |
const unsigned char *cp = line + 8; |
| 49 |
|
| 50 |
while (isspace ((int) *cp)) |
| 51 |
++cp; |
| 52 |
while (isalnum ((int) *cp) || *cp == '_') |
| 53 |
{ |
| 54 |
vStringPut (name, (int) *cp); |
| 55 |
++cp; |
| 56 |
} |
| 57 |
vStringTerminate (name); |
| 58 |
while (isspace ((int) *cp)) |
| 59 |
++cp; |
| 60 |
if (*cp == '(') |
| 61 |
makeSimpleTag (name, AwkKinds, K_FUNCTION); |
| 62 |
vStringClear (name); |
| 63 |
if (*cp != '\0') |
| 64 |
++cp; |
| 65 |
} |
| 66 |
} |
| 67 |
vStringDelete (name); |
| 68 |
} |
| 69 |
|
| 70 |
extern parserDefinition* AwkParser () |
| 71 |
{ |
| 72 |
static const char *const extensions [] = { "awk", "gawk", "mawk", NULL }; |
| 73 |
parserDefinition* def = parserNew ("Awk"); |
| 74 |
def->kinds = AwkKinds; |
| 75 |
def->kindCount = KIND_COUNT (AwkKinds); |
| 76 |
def->extensions = extensions; |
| 77 |
def->parser = findAwkTags; |
| 78 |
return def; |
| 79 |
} |
| 80 |
|
| 81 |
/* vi:set tabstop=4 shiftwidth=4: */ |