~ubuntu-branches/ubuntu/trusty/ifmail/trusty

« back to all changes in this revision

Viewing changes to .pc/fix_flex/ifcico/flaglex.l

  • Committer: Package Import Robot
  • Author(s): Marco d'Itri
  • Date: 2012-05-14 05:17:39 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120514051739-86alcr4jvx2ses6v
Tags: 2.14tx8.10-21
* Do not use perl4 modules. (Closes: #659423)
* Added support for dpkg-buildflags and hardening.
* Package converted to source format 3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include "ftn.h"
 
5
#include "lutil.h"
 
6
#include "nodelist.h"
 
7
 
 
8
static char *yyPTR = NULL;
 
9
static int yyBUFL;
 
10
 
 
11
#ifndef yywrap
 
12
#define yywrap() 1
 
13
#endif
 
14
 
 
15
#ifdef FLEX_SCANNER
 
16
 
 
17
#undef YY_INPUT
 
18
#define YY_INPUT(buf,result,max_size) \
 
19
        if ((yyPTR == NULL) || (*yyPTR == '\0')) \
 
20
        { \
 
21
                debug(13,"YY_INPUT unavail, %d reqd",max_size); \
 
22
                result=YY_NULL; \
 
23
        } \
 
24
        else \
 
25
        { \
 
26
                yyBUFL=strlen(yyPTR); \
 
27
                debug(13,"YY_INPUT \"%s\" (%d) avail, %d reqd",\
 
28
                        yyPTR,yyBUFL,max_size); \
 
29
                if (yyBUFL > max_size) yyBUFL=max_size; \
 
30
                memcpy(buf,yyPTR,yyBUFL); \
 
31
                yyPTR += yyBUFL; \
 
32
                result=yyBUFL; \
 
33
        }
 
34
 
 
35
#else /* this is most probably native lex? */
 
36
 
 
37
#undef input
 
38
#undef output
 
39
#undef unput
 
40
 
 
41
#define input() (((yyPTR == NULL) || (*yyPTR == '\0'))?NULL:*yyPTR++)
 
42
#define output(c)
 
43
#define unput(c) (*--yyPTR = (c))
 
44
 
 
45
#endif
 
46
 
 
47
int flagfor(char *);
 
48
int chkaddr(char*);
 
49
int chktime(char*);
 
50
int yylval;
 
51
%}
 
52
 
 
53
Blank           [ \t\n]+
 
54
Speed           [Ss][Pp][Ee][Ee][Dd]
 
55
Phone           [Pp][Hh][Oo][Nn][Ee]
 
56
Time            [Tt][Ii][Mm][Ee]
 
57
Address         [Aa][Dd][Dd][Rr][Ee][Ss][Ss]
 
58
Sun             [Ss][Uu][Nn]
 
59
Mon             [Mm][Oo][Nn]
 
60
Tue             [Tt][Uu][Ee]
 
61
Wed             [Ww][Ee][Dd]
 
62
Thu             [Tt][Hh][Uu]
 
63
Fri             [Ff][Rr][Ii]
 
64
Sat             [Ss][Aa][Tt]
 
65
Any             [Aa][Nn][Yy]
 
66
Wk              [Ww][Kk]
 
67
We              [Ww][Ee]
 
68
Eq              ==
 
69
Ne              !=
 
70
Gt              \>
 
71
Ge              \>=
 
72
Lt              \<
 
73
Le              \<=
 
74
And             \&
 
75
Or              \|
 
76
Not             \!
 
77
Xor             [Xx][Oo][Rr]
 
78
Lb              \(
 
79
Rb              \)
 
80
Comma           \,
 
81
Asterisk        \*
 
82
Dow             ({Sun}|{Mon}|{Tue}|{Wed}|{Thu}|{Fri}|{Sat}|{Any}|{Wk}|{We})
 
83
Hour            (([0-1][0-9])|(2[0-3]))
 
84
Minute          [0-5][0-9]
 
85
Decimal         [1-9][0-9]*
 
86
Numeric         [0-9][0-9]*
 
87
Phstr           [0-9-]*-[0-9-]*
 
88
Ident           [A-Za-z][A-Za-z0-9]*
 
89
Timestr         {Dow}({Hour}{Minute}\-{Hour}{Minute})?
 
90
Addrstr         (({Decimal}|\*):)?({Decimal}|\*)\/({Numeric}|\*)(.({Numeric}|\*))?(@({Ident}|\*))?
 
91
%%
 
92
{Blank}         ;
 
93
{Decimal}       {debug(13,"Decimal: \"%s\"",yytext);yylval=strtol(yytext,NULL,0);return(NUMBER);}
 
94
{Timestr}       {debug(13,"Timestr: \"%s\"",yytext);yylval=chktime(yytext);return(TIMESTR);}
 
95
{Phstr}         {debug(13,"Phstr: \"%s\"",yytext);yylval=PHSTR;return(PHSTR);}
 
96
{Eq}            {yylval=EQ;return(AROP);}
 
97
{Ne}            {yylval=NE;return(AROP);}
 
98
{Gt}            {yylval=GT;return(AROP);}
 
99
{Ge}            {yylval=GE;return(AROP);}
 
100
{Lt}            {yylval=LT;return(AROP);}
 
101
{Le}            {yylval=LE;return(AROP);}
 
102
{And}           {yylval=AND;return(LOGOP);}
 
103
{Or}            {yylval=OR;return(LOGOP);}
 
104
{Not}           {yylval=NOT;return(NOT);}
 
105
{Xor}           {yylval=XOR;return(LOGOP);}
 
106
{Lb}            {yylval=LB;return(LB);}
 
107
{Rb}            {yylval=RB;return(RB);}
 
108
{Comma}         {yylval=COMMA;return(COMMA);}
 
109
{Asterisk}      {yylval=ASTERISK;return(ASTERISK);}
 
110
{Speed}         {yylval=SPEED;return(SPEED);}
 
111
{Phone}         {yylval=PHONE;return(PHONE);}
 
112
{Time}          {yylval=TIME;return(TIME);}
 
113
{Address}       {yylval=ADDRESS;return(ADDRESS);}
 
114
{Ident}         {debug(13,"Ident: \"%s\"",yytext);yylval=flagfor(yytext);return(IDENT);}
 
115
{Addrstr}       {debug(13,"Addrstr: \"%s\"",yytext);yylval=chkaddr(yytext);return(ADDRSTR);}
 
116
%%
 
117
 
 
118
int flagfor(str)
 
119
char *str;
 
120
{
 
121
        int i;
 
122
 
 
123
        debug(13,"flagfor \"%s\"",str);
 
124
        for (i=0;fkey[i].key;i++)
 
125
                if (strcasecmp(str,fkey[i].key) == 0) return fkey[i].flag;
 
126
        return -1;
 
127
}
 
128
 
 
129
int chkaddr(str)
 
130
char *str;
 
131
{
 
132
        faddr *addr;
 
133
        int rc=1;
 
134
 
 
135
        if ((addr=parsefnode(str)) == NULL)
 
136
        {
 
137
                logerr("unparsable address \"%s\" in expression",str);
 
138
                return 0;
 
139
        }
 
140
        debug(13,"chkaddr: does spec %s match remote address ?",
 
141
                ascfnode(addr,0x1f));
 
142
        if ((addr->domain) && (nodebuf->addr.domain) && 
 
143
            (strcasecmp(addr->domain,nodebuf->addr.domain) != 0))
 
144
                rc=0;
 
145
        if (((int)addr->zone != -1)  &&(addr->zone != 0) &&
 
146
                (addr->zone != nodebuf->addr.zone)) rc=0;
 
147
        if (((int)addr->net != -1) && (addr->net != nodebuf->addr.net)) rc=0;
 
148
        if (((int)addr->node != -1) && (addr->node != nodebuf->addr.node)) rc=0;
 
149
        if (((int)addr->point != -1) && (addr->point != nodebuf->addr.point)) rc=0;
 
150
        tidy_faddr(addr);
 
151
        return rc;
 
152
}
 
153
 
 
154
int chktime(str)
 
155
char *str;
 
156
{
 
157
        int h1,h2,m1,m2,beg,end,cur,dayok,day;
 
158
 
 
159
        if (strncasecmp(str,"Sun",3) == 0) day=0;
 
160
        else if (strncasecmp(str,"Mon",3) == 0) day=1;
 
161
        else if (strncasecmp(str,"Tue",3) == 0) day=2;
 
162
        else if (strncasecmp(str,"Wed",3) == 0) day=3;
 
163
        else if (strncasecmp(str,"Thu",3) == 0) day=4;
 
164
        else if (strncasecmp(str,"Fri",3) == 0) day=5;
 
165
        else if (strncasecmp(str,"Sat",3) == 0) day=6;
 
166
        else if (strncasecmp(str,"Any",3) == 0) day=-1;
 
167
        else if (strncasecmp(str,"Wk",2) == 0) day=-2;
 
168
        else if (strncasecmp(str,"We",2) == 0) day=-3;
 
169
        else day=-4;
 
170
 
 
171
        debug(13,"chkday: does day %d match spec %d ?",now->tm_wday,day);
 
172
        if (day >= 0) dayok=(now->tm_wday == day);
 
173
        else switch (day)
 
174
        {
 
175
        case -3: dayok=((now->tm_wday == 0) || (now->tm_wday == 6)); break;
 
176
        case -2: dayok=((now->tm_wday != 0) && (now->tm_wday != 6)); break;
 
177
        case -1: dayok=1; break;
 
178
        default: logerr("internal error: chkday got %d",day); dayok=0; break;
 
179
        }
 
180
 
 
181
        if (dayok == 0) return 0;
 
182
 
 
183
        while (*str && ((*str < '0') || (*str > '9'))) str++;
 
184
        if (*str == '\0')
 
185
        {
 
186
                return 1;
 
187
        }
 
188
        if (sscanf(str,"%02d%02d-%02d%02d",&h1,&m1,&h2,&m2) != 4)
 
189
        {
 
190
                logerr("invalid time string \"%s\" in expression",str);
 
191
                return 0;
 
192
        }
 
193
        debug(13,"chktime: is %02d:%02d between %02d:%02d and %02d:%02d ?",
 
194
                now->tm_hour,now->tm_min,h1,m1,h2,m2);
 
195
        cur=now->tm_hour*60+now->tm_min;
 
196
        beg=h1*60+m1;
 
197
        end=h2*60+m2;
 
198
        if (end > beg)
 
199
        {
 
200
                return ((cur >= beg) && (cur <= end));
 
201
        }
 
202
        else
 
203
        {
 
204
                return ((cur >= beg) || (cur <= end));
 
205
        }
 
206
}