]> git.pld-linux.org Git - packages/ctags.git/blob - ctags-5.8-css.patch
fix build with modern gcc/glibc
[packages/ctags.git] / ctags-5.8-css.patch
1 diff -up ctags-5.8/css.c.me ctags-5.8/css.c
2 --- ctags-5.8/css.c.me  2012-02-08 13:59:35.000000000 +0100
3 +++ ctags-5.8/css.c     2012-02-08 13:55:16.000000000 +0100
4 @@ -0,0 +1,226 @@
5 +/***************************************************************************
6 + * css.c
7 + * Character-based parser for Css definitions
8 + * Author - Iago Rubio <iagorubio(at)users.sourceforge.net>
9 + **************************************************************************/
10 +#include "general.h"
11 +
12 +#include <string.h> 
13 +#include <ctype.h> 
14 +
15 +#include "parse.h" 
16 +#include "read.h" 
17 +
18 +
19 +typedef enum eCssKinds {
20 +    K_NONE = -1, K_CLASS, K_SELECTOR, K_ID
21 +} cssKind;
22 +
23 +static kindOption CssKinds [] = {
24 +    { TRUE, 'c', "class", "classes" },
25 +    { TRUE, 's', "selector",  "selectors"  },
26 +    { TRUE, 'i', "id",  "identities"  }
27 +};
28 +
29 +typedef enum _CssParserState {  // state of parsing
30 +  P_STATE_NONE,         // default state
31 +  P_STATE_IN_COMMENT,     // into a comment, only multi line in CSS
32 +  P_STATE_IN_SINGLE_STRING, // into a single quoted string
33 +  P_STATE_IN_DOUBLE_STRING, // into a double quoted string
34 +  P_STATE_IN_DEFINITION,    // on the body of the style definition, nothing for us
35 +  P_STATE_IN_MEDIA,     // on a @media declaration, can be multi-line
36 +  P_STATE_IN_IMPORT,      // on a @import declaration, can be multi-line
37 +  P_STATE_IN_NAMESPACE,   // on a @namespace declaration  
38 +  P_STATE_IN_PAGE,      // on a @page declaration
39 +  P_STATE_IN_FONTFACE,    // on a @font-face declaration
40 +  P_STATE_AT_END        // end of parsing
41 +} CssParserState;
42 +
43 +static void makeCssSimpleTag( vString *name, cssKind kind, boolean delete )
44 +{
45 +  vStringTerminate (name);
46 +  makeSimpleTag (name, CssKinds, kind);
47 +  vStringClear (name);
48 +  if( delete )
49 +    vStringDelete (name);
50 +}
51 +
52 +static boolean isCssDeclarationAllowedChar( const unsigned char *cp )
53 +{
54 +  return  isalnum ((int) *cp) ||
55 +      isspace ((int) *cp) ||
56 +      *cp == '_' || // allowed char
57 +      *cp == '-' || // allowed char     
58 +      *cp == '+' ||   // allow all sibling in a single tag
59 +      *cp == '>' ||   // allow all child in a single tag 
60 +      *cp == '{' ||   // allow the start of the declaration
61 +      *cp == '.' ||   // allow classes and selectors
62 +      *cp == ',' ||   // allow multiple declarations
63 +      *cp == ':' ||   // allow pseudo classes
64 +      *cp == '*' ||   // allow globs as P + *
65 +      *cp == '#';   // allow ids 
66 +}
67 +
68 +static CssParserState parseCssDeclaration( const unsigned char **position, cssKind kind )
69 +{
70 +  vString *name = vStringNew ();
71 +  const unsigned char *cp = *position;
72 +
73 +  // pick to the end of line including children and sibling
74 +  // if declaration is multiline go for the next line 
75 +  while ( isCssDeclarationAllowedChar(cp) || 
76 +      *cp == '\0' )   // track the end of line into the loop
77 +  {
78 +    if( (int) *cp == '\0' )
79 +    { 
80 +      cp = fileReadLine ();
81 +      if( cp == NULL ){
82 +        makeCssSimpleTag(name, kind, TRUE);
83 +        *position = cp;
84 +        return P_STATE_AT_END;
85 +      }
86 +    }
87 +    else if( *cp == ',' )
88 +    {
89 +      makeCssSimpleTag(name, kind, TRUE);
90 +      *position = ++cp;
91 +      return P_STATE_NONE;
92 +    }
93 +    else if( *cp == '{' )
94 +    {
95 +      makeCssSimpleTag(name, kind, TRUE);
96 +      *position = ++cp;
97 +      return P_STATE_IN_DEFINITION;
98 +    }
99 +
100 +    vStringPut (name, (int) *cp);
101 +    ++cp;
102 +  }
103 +  
104 +  makeCssSimpleTag(name, kind, TRUE);
105 +  *position = cp;
106 +
107 +  return P_STATE_NONE;
108 +}
109 +
110 +static CssParserState parseCssLine( const unsigned char *line, CssParserState state )
111 +{
112 +  vString *aux;
113 +
114 +  while( *line != '\0' ) // fileReadLine returns NULL terminated strings
115 +  {
116 +    while (isspace ((int) *line))
117 +      ++line;
118 +    switch( state )
119 +    {
120 +      case P_STATE_NONE:
121 +        // pick first char if alphanumeric is a selector
122 +        if( isalnum ((int) *line) )
123 +          state = parseCssDeclaration( &line, K_SELECTOR );
124 +        else if( *line == '.' ) // a class
125 +          state = parseCssDeclaration( &line, K_CLASS );
126 +        else if( *line == '#' ) // an id
127 +          state = parseCssDeclaration( &line, K_ID );
128 +        else if( *line == '@' ) // at-rules, we'll ignore them
129 +        {
130 +          ++line;
131 +          aux = vStringNew();
132 +          while( !isspace((int) *line) )
133 +          {
134 +            vStringPut (aux, (int) *line);
135 +            ++line;         
136 +          }
137 +          vStringTerminate (aux);
138 +          if( strcmp( aux->buffer, "media" ) == 0 )
139 +            state = P_STATE_IN_MEDIA;
140 +          else if ( strcmp( aux->buffer, "import" ) == 0 )
141 +            state = P_STATE_IN_IMPORT;
142 +          else if ( strcmp( aux->buffer, "namespace" ) == 0 )
143 +            state = P_STATE_IN_NAMESPACE; 
144 +          else if ( strcmp( aux->buffer, "page" ) == 0 )
145 +            state = P_STATE_IN_PAGE;
146 +          else if ( strcmp( aux->buffer, "font-face" ) == 0 )
147 +            state = P_STATE_IN_FONTFACE;
148 +          vStringDelete (aux);
149 +        }
150 +        else if( *line == '*' && *(line-1) == '/' ) // multi-line comment
151 +          state = P_STATE_IN_COMMENT;
152 +      break;
153 +      case P_STATE_IN_COMMENT:
154 +        if( *line == '/' && *(line-1) == '*')
155 +          state = P_STATE_NONE;
156 +      break;
157 +      case  P_STATE_IN_SINGLE_STRING: 
158 +        if( *line == '\'' && *(line-1) != '\\' )
159 +          state = P_STATE_IN_DEFINITION; // PAGE, FONTFACE and DEFINITION are treated the same way
160 +      break;
161 +      case  P_STATE_IN_DOUBLE_STRING:
162 +        if( *line=='"' && *(line-1) != '\\' )
163 +          state = P_STATE_IN_DEFINITION; // PAGE, FONTFACE and DEFINITION are treated the same way
164 +      break;
165 +      case  P_STATE_IN_MEDIA:
166 +        // skip to start of media body or line end
167 +        while( *line != '{' )
168 +        {
169 +          if( *line == '\0' )
170 +            break;
171 +          ++line;
172 +        }
173 +        if( *line == '{' )
174 +            state = P_STATE_NONE;
175 +      break;
176 +      case  P_STATE_IN_IMPORT:
177 +      case  P_STATE_IN_NAMESPACE:
178 +        // skip to end of declaration or line end
179 +        while( *line != ';' )
180 +        {
181 +          if( *line == '\0' )
182 +            break;
183 +          ++line;
184 +        }
185 +        if( *line == ';' )
186 +          state = P_STATE_NONE;
187 +      break;
188 +      case P_STATE_IN_PAGE:
189 +      case P_STATE_IN_FONTFACE:
190 +      case P_STATE_IN_DEFINITION:
191 +        if( *line == '}' )
192 +          state = P_STATE_NONE;
193 +        else if( *line == '\'' )
194 +          state = P_STATE_IN_SINGLE_STRING;
195 +        else if( *line == '"' )
196 +          state = P_STATE_IN_DOUBLE_STRING;
197 +      break;
198 +      case P_STATE_AT_END:
199 +        return state;
200 +      break;
201 +    }   
202 +    line++;
203 +  }
204 +  return state;
205 +}
206 +
207 +static void findCssTags (void)
208 +{
209 +    const unsigned char *line;
210 +  CssParserState state = P_STATE_NONE;
211 +
212 +    while ( (line = fileReadLine ()) != NULL )
213 +    {
214 +    state = parseCssLine( line, state );
215 +    if( state==P_STATE_AT_END ) return;
216 +    }    
217 +}
218 +
219 +/* parser definition */
220 +extern parserDefinition* CssParser (void)
221 +{
222 +    static const char *const extensions [] = { "css", NULL };
223 +    parserDefinition* def = parserNew ("CSS");
224 +    def->kinds      = CssKinds;
225 +    def->kindCount  = KIND_COUNT (CssKinds);
226 +    def->extensions = extensions;
227 +    def->parser     = findCssTags;
228 +    return def;
229 +}
230 +
231 diff -up ctags-5.8/parsers.h.me ctags-5.8/parsers.h
232 --- ctags-5.8/parsers.h.me      2012-02-08 13:56:46.000000000 +0100
233 +++ ctags-5.8/parsers.h 2012-02-08 13:57:25.000000000 +0100
234 @@ -26,6 +26,7 @@
235         CppParser, \
236         CsharpParser, \
237         CobolParser, \
238 +       CssParser, \
239         DosBatchParser, \
240         EiffelParser, \
241         ErlangParser, \
242 diff -up ctags-5.8/source.mak.me ctags-5.8/source.mak
243 --- ctags-5.8/source.mak.me     2012-02-08 13:58:02.000000000 +0100
244 +++ ctags-5.8/source.mak        2012-02-08 13:58:42.000000000 +0100
245 @@ -17,6 +17,7 @@ SOURCES = \
246         beta.c \
247         c.c \
248         cobol.c \
249 +       css.c \
250         dosbatch.c \
251         eiffel.c \
252         entry.c \
253 @@ -79,6 +80,7 @@ OBJECTS = \
254         beta.$(OBJEXT) \
255         c.$(OBJEXT) \
256         cobol.$(OBJEXT) \
257 +       css.$(OBJEXT) \
258         dosbatch.$(OBJEXT) \
259         eiffel.$(OBJEXT) \
260         entry.$(OBJEXT) \
This page took 0.086696 seconds and 3 git commands to generate.