File: asp.c

package info (click to toggle)
exuberant-ctags 1%3A5.2.2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,060 kB
  • ctags: 2,074
  • sloc: ansic: 14,358; makefile: 150; sh: 59
file content (169 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
*   $Id: asp.c,v 1.4 2002/02/16 19:53:16 darren Exp $
*
*   Copyright (c) 2000, Patrick Dehne <patrick@steidle.net>
*
*   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 the ASP (Active
*   Server Pages) web page scripting language.
*/

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

#include <string.h>

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

/*
*   DATA DEFINITIONS
*/
typedef enum {
    K_FUNCTION, K_SUB
} aspKind;

static kindOption AspKinds [] = {
    { TRUE, 'f', "function", "functions"},
    { TRUE, 's', "sub", "subroutines"}
};

/*
*   FUNCTION DEFINITIONS
*/

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

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

	while (*cp != '\0')
	{
	    /* jump over whitespace */
	    while (isspace ((int)*cp))
		cp++;

	    /* jump over strings */
	    if (*cp == '"')
	    {
		cp++;
		while (*cp!='"' && *cp!='\0')
		    cp++;
	    }

	    /* jump over comments */ 
	    else if (*cp == '\'')		    
		break;
	    
	    /* jump over end function/sub lines */
	    else if (strncasecmp ((const char*) cp, "end", (size_t) 3)== 0)
	    {
		cp += 3;
		if (isspace ((int)*cp))
		{
		    while (isspace ((int)*cp))
			++cp;

		    if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
		    {
			cp+=8;
			break;
		    }

		    else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
		    {
			cp+=3;
			break;
		    }
		}
	    }

	    /* jump over exit function/sub lines */
	    else if (strncasecmp ((const char*) cp, "exit", (size_t) 4)==0)
	    {
		cp += 4;
		if (isspace ((int) *cp))
		{
		    while (isspace ((int) *cp))
			++cp;

		    if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
		    {
			cp+=8;
			break;
		    }

		    else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
		    {
			cp+=3;
			break;
		    }
		}
	    }

	    /* function? */
	    else if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
	    {
		cp += 8;

		if (isspace ((int) *cp))
		{
		    while (isspace ((int) *cp))
			++cp;
		    while (isalnum ((int) *cp)  ||  *cp == '_')
		    {
			vStringPut (name, (int) *cp);
			++cp;
		    }
		    vStringTerminate (name);
		    makeSimpleTag (name, AspKinds, K_FUNCTION);
		    vStringClear (name);
		}
	    }

	    /* sub? */
	    else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
	    {
		cp += 3;
		if (isspace ((int) *cp))
		{
		    while (isspace ((int) *cp))
			++cp;
		    while (isalnum ((int) *cp)  ||  *cp == '_')
		    {
			vStringPut (name, (int) *cp);
			++cp;
		    }
		    vStringTerminate (name);
		    makeSimpleTag (name, AspKinds, K_SUB);
		    vStringClear (name);
		}
	    }

	    /* nothing relevant */
	    else if (*cp != '\0')
		cp++;
	}
    }
    vStringDelete (name);
}

extern parserDefinition* AspParser (void)
{
    static const char *const extensions [] = { "asp", "asa", NULL };
    parserDefinition* def = parserNew ("Asp");
    def->kinds      = AspKinds;
    def->kindCount  = KIND_COUNT (AspKinds);
    def->extensions = extensions;
    def->parser     = findAspTags;
    return def;
}