2
* $Id: sh.c,v 1.4 2003/06/11 04:53:12 darren Exp $
4
* Copyright (c) 2000-2002, Darren Hiebert
6
* This source code is released for free distribution under the terms of the
7
* GNU General Public License.
9
* This module contains functions for generating tags for scripts for the
10
* Bourne shell (and its derivatives, the Korn and Z shells).
16
#include "general.h" /* must always come first */
32
static kindOption ShKinds [] = {
33
{ TRUE, 'f', "function", "functions"}
37
* FUNCTION DEFINITIONS
40
/* Reject any tag "main" from a file named "configure". These appear in
41
* here-documents in GNU autoconf scripts and will add a haystack to the
44
static boolean hackReject (const vString* const tagName)
46
const char *const scriptName = baseFilename (vStringValue (File.name));
47
boolean result = (boolean) (strcmp (scriptName, "configure") == 0 &&
48
strcmp (vStringValue (tagName), "main") == 0);
52
static void findShTags (void)
54
vString *name = vStringNew ();
55
const unsigned char *line;
57
while ((line = fileReadLine ()) != NULL)
59
const unsigned char* cp = line;
60
boolean functionFound = FALSE;
67
if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
68
isspace ((int) cp [8]))
72
if (! isspace ((int) *cp))
74
while (isspace ((int) *cp))
77
if (! isalnum ((int) *cp))
79
while (isalnum ((int) *cp) || *cp == '_')
81
vStringPut (name, (int) *cp);
84
vStringTerminate (name);
85
while (isspace ((int) *cp))
89
while (isspace ((int) *cp))
91
if (*cp == ')' && ! hackReject (name))
95
makeSimpleTag (name, ShKinds, K_FUNCTION);
101
extern parserDefinition* ShParser (void)
103
static const char *const extensions [] = {
104
"sh", "SH", "bsh", "bash", "ksh", "zsh", NULL
106
parserDefinition* def = parserNew ("Sh");
107
def->kinds = ShKinds;
108
def->kindCount = KIND_COUNT (ShKinds);
109
def->extensions = extensions;
110
def->parser = findShTags;
114
/* vi:set tabstop=8 shiftwidth=4: */