Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 116 lines (102 sloc) 2.485 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/*
* $Id: sh.c 443 2006-05-30 04:37:13Z darren $
*
* Copyright (c) 2000-2002, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License.
*
* This module contains functions for generating tags for scripts for the
* Bourne shell (and its derivatives, the Korn and Z shells).
*/

/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */

#include <string.h>

#include "parse.h"
#include "read.h"
#include "routines.h"
#include "vstring.h"

/*
* DATA DEFINITIONS
*/
typedef enum {
K_FUNCTION
} shKind;

static kindOption ShKinds [] = {
{ TRUE, 'f', "function", "functions"}
};

/*
* FUNCTION DEFINITIONS
*/

/* Reject any tag "main" from a file named "configure". These appear in
* here-documents in GNU autoconf scripts and will add a haystack to the
* needle.
*/
static boolean hackReject (const vString* const tagName)
{
const char *const scriptName = baseFilename (vStringValue (File.name));
boolean result = (boolean) (
strcmp (scriptName, "configure") == 0 &&
strcmp (vStringValue (tagName), "main") == 0);
return result;
}

static void findShTags (void)
{
vString *name = vStringNew ();
const unsigned char *line;

while ((line = fileReadLine ()) != NULL)
{
const unsigned char* cp = line;
boolean functionFound = FALSE;

if (line [0] == '#')
continue;

while (isspace (*cp))
cp++;
if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
isspace ((int) cp [8]))
{
functionFound = TRUE;
cp += 8;
if (! isspace ((int) *cp))
continue;
while (isspace ((int) *cp))
++cp;
}
if (! (isalnum ((int) *cp) || *cp == '_'))
continue;
while (isalnum ((int) *cp) || *cp == '_')
{
vStringPut (name, (int) *cp);
++cp;
}
vStringTerminate (name);
while (isspace ((int) *cp))
++cp;
if (*cp++ == '(')
{
while (isspace ((int) *cp))
++cp;
if (*cp == ')' && ! hackReject (name))
functionFound = TRUE;
}
if (functionFound)
makeSimpleTag (name, ShKinds, K_FUNCTION);
vStringClear (name);
}
vStringDelete (name);
}

extern parserDefinition* ShParser (void)
{
static const char *const extensions [] = {
"sh", "SH", "bsh", "bash", "ksh", "zsh", NULL
};
parserDefinition* def = parserNew ("Sh");
def->kinds = ShKinds;
def->kindCount = KIND_COUNT (ShKinds);
def->extensions = extensions;
def->parser = findShTags;
return def;
}

/* vi:set tabstop=4 shiftwidth=4: */
Something went wrong with that request. Please try again.