~ubuntu-branches/ubuntu/utopic/exuberant-ctags/utopic

« back to all changes in this revision

Viewing changes to sh.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2004-03-30 11:56:40 UTC
  • Revision ID: james.westby@ubuntu.com-20040330115640-0u2eq56u65zf53il
Tags: upstream-5.5.4
ImportĀ upstreamĀ versionĀ 5.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*   $Id: sh.c,v 1.4 2003/06/11 04:53:12 darren Exp $
 
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 scripts for the
 
10
*   Bourne shell (and its derivatives, the Korn and Z shells).
 
11
*/
 
12
 
 
13
/*
 
14
*   INCLUDE FILES
 
15
*/
 
16
#include "general.h"    /* must always come first */
 
17
 
 
18
#include <string.h>
 
19
 
 
20
#include "parse.h"
 
21
#include "read.h"
 
22
#include "routines.h"
 
23
#include "vstring.h"
 
24
 
 
25
/*
 
26
*   DATA DEFINITIONS
 
27
*/
 
28
typedef enum {
 
29
    K_FUNCTION
 
30
} shKind;
 
31
 
 
32
static kindOption ShKinds [] = {
 
33
    { TRUE, 'f', "function", "functions"}
 
34
};
 
35
 
 
36
/*
 
37
*   FUNCTION DEFINITIONS
 
38
*/
 
39
 
 
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
 
42
 *  needle.
 
43
 */
 
44
static boolean hackReject (const vString* const tagName)
 
45
{
 
46
    const char *const scriptName = baseFilename (vStringValue (File.name));
 
47
    boolean result = (boolean) (strcmp (scriptName, "configure") == 0  &&
 
48
                               strcmp (vStringValue (tagName), "main") == 0);
 
49
    return result;
 
50
}
 
51
 
 
52
static void findShTags (void)
 
53
{
 
54
    vString *name = vStringNew ();
 
55
    const unsigned char *line;
 
56
 
 
57
    while ((line = fileReadLine ()) != NULL)
 
58
    {
 
59
        const unsigned char* cp = line;
 
60
        boolean functionFound = FALSE;
 
61
 
 
62
        if (line [0] == '#')
 
63
            continue;
 
64
 
 
65
        while (isspace (*cp))
 
66
            cp++;
 
67
        if (strncmp ((const char*) cp, "function", (size_t) 8) == 0  &&
 
68
            isspace ((int) cp [8]))
 
69
        {
 
70
            functionFound = TRUE;
 
71
            cp += 8;
 
72
            if (! isspace ((int) *cp))
 
73
                continue;
 
74
            while (isspace ((int) *cp))
 
75
                ++cp;
 
76
        }
 
77
        if (! isalnum ((int) *cp))
 
78
            continue;
 
79
        while (isalnum ((int) *cp)  ||  *cp == '_')
 
80
        {
 
81
            vStringPut (name, (int) *cp);
 
82
            ++cp;
 
83
        }
 
84
        vStringTerminate (name);
 
85
        while (isspace ((int) *cp))
 
86
            ++cp;
 
87
        if (*cp++ == '(')
 
88
        {
 
89
            while (isspace ((int) *cp))
 
90
                ++cp;
 
91
            if (*cp == ')'  && ! hackReject (name))
 
92
                functionFound = TRUE;
 
93
        }
 
94
        if (functionFound)
 
95
            makeSimpleTag (name, ShKinds, K_FUNCTION);
 
96
        vStringClear (name);
 
97
    }
 
98
    vStringDelete (name);
 
99
}
 
100
 
 
101
extern parserDefinition* ShParser (void)
 
102
{
 
103
    static const char *const extensions [] = {
 
104
        "sh", "SH", "bsh", "bash", "ksh", "zsh", NULL
 
105
    };
 
106
    parserDefinition* def = parserNew ("Sh");
 
107
    def->kinds      = ShKinds;
 
108
    def->kindCount  = KIND_COUNT (ShKinds);
 
109
    def->extensions = extensions;
 
110
    def->parser     = findShTags;
 
111
    return def;
 
112
}
 
113
 
 
114
/* vi:set tabstop=8 shiftwidth=4: */