~ubuntu-branches/ubuntu/utopic/geany/utopic

« back to all changes in this revision

Viewing changes to .pc/20_debian_control_tags.patch/tagmanager/conf.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*
 
3
*   Copyright (c) 2000-2001, Darren Hiebert
 
4
*
 
5
*   This source code is released for free distribution under the terms of the
 
6
*   GNU General Public License.
 
7
*
 
8
*   This module contains functions for generating tags for config files.
 
9
*/
 
10
 
 
11
/*
 
12
*   INCLUDE FILES
 
13
*/
 
14
#include "general.h"    /* must always come first */
 
15
 
 
16
#include <ctype.h>
 
17
 
 
18
#include "parse.h"
 
19
#include "read.h"
 
20
#include "vstring.h"
 
21
 
 
22
/*
 
23
*   DATA DEFINITIONS
 
24
*/
 
25
typedef enum {
 
26
    K_SECTION,
 
27
    K_KEY
 
28
} confKind;
 
29
 
 
30
static kindOption ConfKinds [] = {
 
31
    { TRUE, 'n', "namespace",  "sections"},
 
32
    { TRUE, 'm', "macro", "keys"}
 
33
};
 
34
 
 
35
/*
 
36
*   FUNCTION DEFINITIONS
 
37
*/
 
38
 
 
39
static boolean isIdentifier (int c)
 
40
{
 
41
    /* allow whitespace within keys and sections */
 
42
    return (boolean)(isalnum (c) || isspace (c) ||  c == '_');
 
43
}
 
44
 
 
45
static void findConfTags (void)
 
46
{
 
47
    vString *name = vStringNew ();
 
48
    vString *scope = vStringNew ();
 
49
    const unsigned char *line;
 
50
 
 
51
    while ((line = fileReadLine ()) != NULL)
 
52
    {
 
53
                const unsigned char* cp = line;
 
54
                boolean possible = TRUE;
 
55
 
 
56
                if (isspace ((int) *cp) || *cp == '#' || (*cp != '\0' && *cp == '/' && *(cp+1) == '/'))
 
57
                        continue;
 
58
 
 
59
                /* look for a section */
 
60
                if (*cp != '\0' && *cp == '[')
 
61
                {
 
62
                        ++cp;
 
63
                        while (*cp != '\0' && *cp != ']')
 
64
                        {
 
65
                                vStringPut (name, (int) *cp);
 
66
                                ++cp;
 
67
                        }
 
68
                        vStringTerminate (name);
 
69
                        makeSimpleTag (name, ConfKinds, K_SECTION);
 
70
                        /* remember section name */
 
71
                        vStringCopy (scope, name);
 
72
                        vStringTerminate (scope);
 
73
                        vStringClear (name);
 
74
                        continue;
 
75
                }
 
76
 
 
77
                while (*cp != '\0')
 
78
                {
 
79
                        /*  We look for any sequence of identifier characters following a white space */
 
80
                        if (possible && isIdentifier ((int) *cp))
 
81
                        {
 
82
                                while (isIdentifier ((int) *cp))
 
83
                                {
 
84
                                        vStringPut (name, (int) *cp);
 
85
                                        ++cp;
 
86
                                }
 
87
                                vStringTerminate (name);
 
88
                                vStringStripTrailing (name);
 
89
                                while (isspace ((int) *cp))
 
90
                                        ++cp;
 
91
                                if (*cp == '=')
 
92
                                {
 
93
                                        if (vStringLength (scope) > 0)
 
94
                                                makeSimpleScopedTag (name, ConfKinds, K_KEY,
 
95
                                                        "section", vStringValue(scope), NULL);
 
96
                                        else
 
97
                                                makeSimpleTag (name, ConfKinds, K_KEY);
 
98
                                }
 
99
                                vStringClear (name);
 
100
                        }
 
101
                        else if (isspace ((int) *cp))
 
102
                                possible = TRUE;
 
103
                        else
 
104
                                possible = FALSE;
 
105
 
 
106
                        if (*cp != '\0')
 
107
                                ++cp;
 
108
                }
 
109
    }
 
110
    vStringDelete (name);
 
111
    vStringDelete (scope);
 
112
}
 
113
 
 
114
extern parserDefinition* ConfParser (void)
 
115
{
 
116
    static const char *const patterns [] = { "*.ini", "*.conf", NULL };
 
117
    static const char *const extensions [] = { "conf", NULL };
 
118
    parserDefinition* const def = parserNew ("Conf");
 
119
    def->kinds      = ConfKinds;
 
120
    def->kindCount  = KIND_COUNT (ConfKinds);
 
121
    def->patterns   = patterns;
 
122
    def->extensions = extensions;
 
123
    def->parser     = findConfTags;
 
124
    return def;
 
125
}
 
126
 
 
127
/* vi:set tabstop=8 shiftwidth=4: */