Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / tagmanager / php.c
blobfa3c0ba81e5706bdfa489c61c860ff8d1b5054e3
1 /*
2 * $Id$
4 * Copyright (c) 2000, Jesus Castagnetto <jmcastagnetto@zkey.com>
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 the PHP web page
10 * scripting language. Only recognizes functions and classes, not methods or
11 * variables.
13 * Parsing PHP defines by Pavel Hlousek <pavel.hlousek@seznam.cz>, Apr 2003.
17 * INCLUDE FILES
19 #include "general.h" /* must always come first */
21 #include <string.h>
23 #include "parse.h"
24 #include "read.h"
25 #include "vstring.h"
28 * DATA DEFINITIONS
30 typedef enum {
31 K_CLASS, K_DEFINE, K_FUNCTION, K_VARIABLE
32 } phpKind;
34 static kindOption PhpKinds [] = {
35 { TRUE, 'c', "class", "classes" },
36 { TRUE, 'd', "define", "constant definitions" },
37 { TRUE, 'f', "function", "functions" },
38 { TRUE, 'v', "variable", "variables" }
42 * FUNCTION DEFINITIONS
45 static boolean isLetter(const int c)
47 return (boolean)(isalpha(c) || (c >= 127 && c <= 255));
50 static boolean isVarChar1(const int c)
52 return (boolean)(isLetter (c) || c == '_');
55 static boolean isVarChar(const int c)
57 return (boolean)(isVarChar1 (c) || isdigit (c));
60 static void findPhpTags (void)
62 vString *name = vStringNew ();
63 const unsigned char *line;
65 while ((line = fileReadLine ()) != NULL)
67 const unsigned char *cp = line;
69 while (isspace (*cp))
70 cp++;
72 if (*(const char*)cp == '$' && isVarChar1 (*(const char*)(cp+1)))
74 cp += 1;
75 vStringClear (name);
76 while (isVarChar ((int) *cp))
78 vStringPut (name, (int) *cp);
79 ++cp;
81 while (isspace ((int) *cp))
82 ++cp;
83 if (*(const char*) cp == '=')
85 vStringTerminate (name);
86 makeSimpleTag (name, PhpKinds, K_VARIABLE);
87 vStringClear (name);
90 else if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
91 isspace ((int) cp [8]))
93 cp += 8;
95 while (isspace ((int) *cp))
96 ++cp;
98 if (*cp == '&') /* skip reference character */
99 cp++;
101 vStringClear (name);
102 while (isalnum ((int) *cp) || *cp == '_')
104 vStringPut (name, (int) *cp);
105 ++cp;
107 vStringTerminate (name);
108 makeSimpleTag (name, PhpKinds, K_FUNCTION);
109 vStringClear (name);
111 else if (strncmp ((const char*) cp, "class", (size_t) 5) == 0 &&
112 isspace ((int) cp [5]))
114 cp += 5;
116 while (isspace ((int) *cp))
117 ++cp;
118 vStringClear (name);
119 while (isalnum ((int) *cp) || *cp == '_')
121 vStringPut (name, (int) *cp);
122 ++cp;
124 vStringTerminate (name);
125 makeSimpleTag (name, PhpKinds, K_CLASS);
126 vStringClear (name);
128 else if (strncmp ((const char*) cp, "define", (size_t) 6) == 0 &&
129 ! isalnum ((int) cp [6]))
131 cp += 6;
133 while (isspace ((int) *cp))
134 ++cp;
135 if (*cp != '(')
136 continue;
137 ++cp;
139 while (isspace ((int) *cp))
140 ++cp;
141 if ((*cp == '\'') || (*cp == '"'))
142 ++cp;
143 else if (! ((*cp == '_') || isalnum ((int) *cp)))
144 continue;
146 vStringClear (name);
147 while (isalnum ((int) *cp) || *cp == '_')
149 vStringPut (name, (int) *cp);
150 ++cp;
152 vStringTerminate (name);
153 makeSimpleTag (name, PhpKinds, K_DEFINE);
154 vStringClear (name);
157 vStringDelete (name);
160 extern parserDefinition* PhpParser (void)
162 static const char *const extensions [] = { "php", "php3", "phtml", NULL };
163 parserDefinition* def = parserNew ("PHP");
164 def->kinds = PhpKinds;
165 def->kindCount = KIND_COUNT (PhpKinds);
166 def->extensions = extensions;
167 def->parser = findPhpTags;
168 return def;
171 /* vi:set tabstop=4 shiftwidth=4: */