~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to tagmanager/css.c

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2009-05-29 21:22:54 UTC
  • mfrom: (1.3.1 upstream) (3.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: james.westby@ubuntu.com-20090529212254-cx6t2a7itgii3p5f
Tags: 0.17-1
* New upstream release
* 20_add_debdiff_as_diff_type.dpatch renamed as
  20_add_debian_specific_filetypes.dpatch, 
  - add .dpatch as a diff filetype
  - add control as a conf filetype
* 20_change_gpl_location.dpatch freshen
* add 20_debian_control_tags.dpatch better handling of debian/control files.
  Thanks to Enrico Tröger. (Closes: #520776)
* debian/copyright Add Frank Lanitz, update years

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * css.c
3
3
 * Character-based parser for Css definitions
4
4
 * Author - Iago Rubio <iagorubio(at)users.sourceforge.net>
 
5
 *        - Bronisław Białek <after89(at)gmail.com>
5
6
 **************************************************************************/
6
7
#include "general.h"
7
8
 
13
14
 
14
15
 
15
16
typedef enum eCssKinds {
16
 
    K_NONE = -1, K_CLASS, K_SELECTOR, K_ID
 
17
    K_NONE = -1, K_SELECTOR, K_ID, K_CLASS
17
18
} cssKind;
18
19
 
19
20
static kindOption CssKinds [] = {
20
 
    { TRUE, 'c', "class", "classes" },
21
 
    { TRUE, 's', "selector",  "selectors"  },
22
 
    { TRUE, 'v', "variable",  "identities"  }
 
21
    { TRUE, 's', "struct",  "selectors"  },
 
22
    { TRUE, 'v', "variable",  "identities"  },
 
23
    { TRUE, 'c', "class", "classes" }
23
24
};
24
25
 
25
26
typedef enum _CssParserState {  /* state of parsing */
61
62
                        *cp == '#';             /* allow ids */
62
63
}
63
64
 
64
 
static CssParserState parseCssDeclaration( const unsigned char **position, cssKind kind )
 
65
static CssParserState parseCssDeclaration( const unsigned char **position, cssKind kind, const char *aname)
65
66
{
 
67
        const unsigned char *cp = *position;
66
68
        vString *name = vStringNew ();
67
 
        const unsigned char *cp = *position;
 
69
        vStringCopyS(name, aname);
68
70
 
69
71
        /* pick to the end of line including children and sibling
70
72
         * if declaration is multiline go for the next line */
71
73
        while ( isCssDeclarationAllowedChar(cp) ||
72
74
                        *cp == '\0' )   /* track the end of line into the loop */
73
75
        {
74
 
                if( (int) *cp == '\0' )
75
 
                {
76
 
                        cp = fileReadLine ();
77
 
                        if( cp == NULL ){
78
 
                                makeCssSimpleTag(name, kind, TRUE);
79
 
                                *position = cp;
80
 
                                return P_STATE_AT_END;
81
 
                        }
82
 
                }
83
 
                else if( *cp == ',' )
 
76
                if( *cp == ',' )
84
77
                {
85
78
                        makeCssSimpleTag(name, kind, TRUE);
86
 
                        *position = ++cp;
 
79
                        *position = cp;
87
80
                        return P_STATE_NONE;
88
81
                }
89
 
                else if( *cp == '{' )
90
 
                {
 
82
                else if( *cp == '{' || *cp == '\0' )
 
83
                { /* assume that line end is the same as a starting definition (i.e. the { is on the next line */
91
84
                        makeCssSimpleTag(name, kind, TRUE);
92
 
                        *position = ++cp;
 
85
                        *position = cp;
93
86
                        return P_STATE_IN_DEFINITION;
94
87
                }
95
88
 
106
99
static CssParserState parseCssLine( const unsigned char *line, CssParserState state )
107
100
{
108
101
        vString *aux;
 
102
        vString *stack = vStringNew ();
109
103
 
110
104
        while( *line != '\0' ) /* fileReadLine returns NULL terminated strings */
111
105
        {
112
 
                while (isspace ((int) *line))
 
106
                vStringClear (stack);
 
107
                while (state == P_STATE_NONE &&
 
108
                        (isspace ((int) *line) || isalnum ((int) *line) || ( *line == '*' && *(line-1) != '/' )))
 
109
                {
 
110
                        if ((stack->length > 0 && isspace((int) *line)) || isalnum ((int) *line) || *line == '*') {
 
111
                                vStringPut(stack, (int) *line);
 
112
                        }
 
113
 
113
114
                        ++line;
 
115
                }
 
116
                vStringTerminate (stack);
 
117
 
114
118
                switch( state )
115
119
                {
116
120
                        case P_STATE_NONE:
117
 
                                /* pick first char if alphanumeric is a selector */
118
 
                                if( isalnum ((int) *line) )
119
 
                                        state = parseCssDeclaration( &line, K_SELECTOR );
120
 
                                else if( *line == '.' ) /* a class */
121
 
                                        state = parseCssDeclaration( &line, K_CLASS );
 
121
                                if( *line == '.' ) /* a class */
 
122
                                        state = parseCssDeclaration( &line, K_CLASS, vStringValue(stack) );
122
123
                                else if( *line == '#' ) /* an id */
123
 
                                        state = parseCssDeclaration( &line, K_ID );
 
124
                                        state = parseCssDeclaration( &line, K_ID, vStringValue(stack) );
124
125
                                else if( *line == '@' ) /* at-rules, we'll ignore them */
125
126
                                {
126
127
                                        ++line;
145
146
                                }
146
147
                                else if( *line == '*' && *(line-1) == '/' ) /* multi-line comment */
147
148
                                        state = P_STATE_IN_COMMENT;
 
149
                                else if ( stack->length > 0 )
 
150
                                        state = parseCssDeclaration( &line, K_SELECTOR, vStringValue(stack) );
 
151
 
148
152
                        break;
149
153
                        case P_STATE_IN_COMMENT:
150
154
                                if( *line == '/' && *(line-1) == '*')
184
188
                        case P_STATE_IN_PAGE:
185
189
                        case P_STATE_IN_FONTFACE:
186
190
                        case P_STATE_IN_DEFINITION:
 
191
                                if( *line == '\0' )
 
192
                                        line = fileReadLine ();
187
193
                                if( *line == '}' )
188
194
                                        state = P_STATE_NONE;
189
195
                                else if( *line == '\'' )
198
204
                if (line == NULL) return P_STATE_AT_END;
199
205
                line++;
200
206
        }
 
207
        vStringDelete (stack);
 
208
 
201
209
        return state;
202
210
}
203
211