~ubuntu-branches/ubuntu/lucid/graphviz/lucid-updates

« back to all changes in this revision

Viewing changes to lib/cgraph/scan.l

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: scan.l,v 1.1 2007/10/28 17:53:39 north Exp $ $Revision: 1.1 $ */
 
1
/* $Id: scan.l,v 1.4 2008/02/04 22:47:45 erg Exp $ $Revision: 1.4 $ */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
27
27
static char* InputFile;
28
28
static Agdisc_t *Disc;
29
29
static void     *Ifile;
 
30
static int graphType;
30
31
 
31
32
  /* Reset line number */
32
33
void agreadline(int n) { line_num = n; }
39
40
 * requires pushing back whatever was previously read.
40
41
 * There probably is a right way of doing this.
41
42
 */
42
 
void aglexinit(Agdisc_t *disc, void *ifile) { Disc = disc; Ifile = ifile;}
 
43
void aglexinit(Agdisc_t *disc, void *ifile) { Disc = disc; Ifile = ifile; graphType = 0;}
43
44
 
44
45
#ifndef YY_INPUT
45
46
#define YY_INPUT(buf,result,max_size) \
82
83
        yylval.str = (char*)agstrdup_html(Ag_G_global,Sbuf);
83
84
}
84
85
 
 
86
static void
 
87
storeFileName (char* fname, int len)
 
88
{
 
89
    static int cnt;
 
90
    static char* buf;
 
91
 
 
92
    if (len > cnt) {
 
93
        if (cnt) buf = (char*)realloc (buf, len+1);
 
94
        else buf = (char*)malloc (len+1);
 
95
        cnt = len;
 
96
    }
 
97
    strcpy (buf, fname);
 
98
    InputFile = buf;
 
99
}
 
100
 
 
101
/* ppDirective:
 
102
 * Process a possible preprocessor line directive.
 
103
 * yytext = #.*
 
104
 */
 
105
static void ppDirective ()
 
106
{
 
107
    int r, cnt, lineno;
 
108
    char buf[2];
 
109
    char* s = yytext + 1;  /* skip initial # */
 
110
 
 
111
    if (strncmp(s, "line", 4) == 0) s += 4;
 
112
    r = sscanf(s, "%d %1[\"]%n", &lineno, buf, &cnt);
 
113
    if (r > 0) { /* got line number */ 
 
114
        line_num = lineno - 1;
 
115
        if (r > 1) { /* saw quote */
 
116
            char* p = s + cnt;
 
117
            char* e = p;
 
118
            while (*e && (*e != '"')) e++; 
 
119
            if (e != p) {
 
120
                *e = '\0';
 
121
                storeFileName (p, e-p);
 
122
            }
 
123
        }
 
124
    }
 
125
}
 
126
 
85
127
/* chkNum:
86
128
 * The regexp for NUMBER allows a terminating letter.
87
129
 * This way we can catch a number immediately followed by a name
124
166
<comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
125
167
<comment>"*"+"/"                BEGIN(INITIAL);
126
168
"//".*                                  /* ignore C++-style comments */
 
169
^"#".*                                  ppDirective ();
127
170
"#".*                                   /* ignore shell-like comments */
128
171
[ \t\r]                                 /* ignore whitespace */
129
172
"node"                                  return(T_node);                 /* see tokens in agcanonstr */
130
173
"edge"                                  return(T_edge);
131
 
"graph"                                 return(T_graph);
132
 
"digraph"                               return(T_digraph);
 
174
"graph"                                 if (!graphType) graphType = T_graph; return(T_graph);
 
175
"digraph"                               if (!graphType) graphType = T_digraph; return(T_digraph);
133
176
"strict"                                return(T_strict);
134
177
"subgraph"                              return(T_subgraph);
135
 
"->"|"--"                               return(T_edgeop);
 
178
"->"                            if (graphType == T_digraph) return(T_edgeop); else return('-');
 
179
"--"                            if (graphType == T_graph) return(T_edgeop); else return('-');
136
180
{NAME}                                  { yylval.str = (char*)agstrdup(Ag_G_global,yytext); return(T_atom); }
137
181
{NUMBER}                                { if (chkNum()) yyless(yyleng-1); yylval.str = (char*)agstrdup(Ag_G_global,yytext); return(T_atom); }
138
182
["]                                             BEGIN(qstring); beginstr();
151
195
{
152
196
        char    buf[BUFSIZ];
153
197
        if (InputFile)
154
 
                sprintf(buf,"%s:%d: %s in line %d near '%s'",InputFile, line_num,
 
198
                sprintf(buf,"%s:%d: %s in line %d near '%s'\n",InputFile, line_num,
155
199
                        str,line_num,yytext);
156
200
        else
157
 
                sprintf(buf," %s in line %d near '%s'", str,line_num,yytext);
 
201
                sprintf(buf," %s in line %d near '%s'\n", str,line_num,yytext);
158
202
        agerr(AGWARN,buf);
159
203
}
160
204
/* must be here to see flex's macro defns */