2 * $Id: make.c 751 2010-02-27 17:41:57Z elliotth $
4 * Copyright (c) 2000-2005, 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 makefiles.
15 #include "general.h" /* must always come first */
32 static kindOption MakeKinds
[] = {
33 { TRUE
, 'm', "macro", "macros"}
37 * FUNCTION DEFINITIONS
40 static int nextChar (void)
52 static void skipLine (void)
57 while (c
!= EOF
&& c
!= '\n');
62 static int skipToNonWhite (void)
67 while (c
!= '\n' && isspace (c
));
71 static boolean
isIdentifier (int c
)
73 return (boolean
)(c
!= '\0' && (isalnum (c
) || strchr (".-_", c
) != NULL
));
76 static void readIdentifier (const int first
, vString
*const id
)
80 while (isIdentifier (c
))
86 vStringTerminate (id
);
89 static void skipToMatch (const char *const pair
)
91 const int begin
= pair
[0], end
= pair
[1];
92 const unsigned long inputLineNumber
= getInputLineNumber ();
96 while (matchLevel
> 0)
103 else if (c
== '\n' || c
== EOF
)
107 verbose ("%s: failed to find match for '%c' at line %lu\n",
108 getInputFileName (), begin
, inputLineNumber
);
111 static void findMakeTags (void)
113 vString
*name
= vStringNew ();
114 boolean newline
= TRUE
;
115 boolean in_define
= FALSE
;
116 boolean in_rule
= FALSE
;
117 boolean variable_possible
= TRUE
;
120 while ((c
= nextChar ()) != EOF
)
128 skipLine (); /* skip rule */
134 variable_possible
= (boolean
)(!in_rule
);
139 else if (isspace (c
))
149 variable_possible
= TRUE
;
152 else if (variable_possible
&& isIdentifier (c
))
154 readIdentifier (c
, name
);
155 if (strcmp (vStringValue (name
), "endef") == 0)
159 else if (strcmp (vStringValue (name
), "define") == 0 &&
163 c
= skipToNonWhite ();
164 readIdentifier (c
, name
);
165 makeSimpleTag (name
, MakeKinds
, K_MACRO
);
169 if (strcmp(vStringValue (name
), "export") == 0 &&
172 c
= skipToNonWhite ();
173 readIdentifier (c
, name
);
175 c
= skipToNonWhite ();
176 if (strchr (":?+", c
) != NULL
)
178 boolean append
= (boolean
)(c
== '+');
192 makeSimpleTag (name
, MakeKinds
, K_MACRO
);
199 variable_possible
= FALSE
;
201 vStringDelete (name
);
204 extern parserDefinition
* MakefileParser (void)
206 static const char *const patterns
[] = { "[Mm]akefile", "GNUmakefile", NULL
};
207 static const char *const extensions
[] = { "mak", "mk", NULL
};
208 parserDefinition
* const def
= parserNew ("Make");
209 def
->kinds
= MakeKinds
;
210 def
->kindCount
= KIND_COUNT (MakeKinds
);
211 def
->patterns
= patterns
;
212 def
->extensions
= extensions
;
213 def
->parser
= findMakeTags
;
217 /* vi:set tabstop=4 shiftwidth=4: */