More PEP8 compliancy.
[samba.git] / source4 / lib / policy / lex.l
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) 2006 Wilco Baan Hofman <wilco@baanhofman.nl>
4    Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21
22 %{
23 #include "includes.h"
24 #include "lib/policy/parse_adm.h"
25 void error_message (const char *format, ...);
26 int yyparse (void);
27
28 static int lineno = 1;
29 static bool utf16 = false;
30
31 #define YY_INPUT(buf,result,max_size) \
32 { \
33         if (utf16) { \
34                 uint16_t v; \
35                 if (fread(&v, 2, 1, yyin) < 1) \
36                         result = YY_NULL; \
37                 else \
38                         result = push_codepoint(buf, v); \
39         } else { \
40                 int c = getc(yyin); \
41                 result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
42         } \
43 }
44
45 %}
46
47 %%
48
49 ACTIONLIST { return ACTIONLIST; }
50 CATEGORY { return CATEGORY; }
51 CHECKBOX { return CHECKBOX; }
52 CLASS { return CLASS; }
53 DELETE { return DEL; }
54 DEFAULT { return DEFAULT; }
55 DROPDOWNLIST { return DROPDOWNLIST; }
56 EDITTEXT { return EDITTEXT; }
57 END { return END; }
58 EXPLAIN { return EXPLAIN; }
59 ITEMLIST { return ITEMLIST; }
60 KEYNAME { return KEYNAME; }
61 MACHINE { return CLASS_MACHINE; }
62 MIN { return MINIMUM; }
63 MAX { return MAXIMUM; }
64 NAME { return NAME; }
65 NUMERIC { return NUMERIC; }
66 PART { return PART; }
67 POLICY { return POLICY; }
68 REQUIRED { return REQUIRED; }
69 SPIN { return SPIN; }
70 SUPPORTED { return SUPPORTED; }
71 TEXT { return TEXT; }
72 USER { return CLASS_USER; }
73 VALUE { return VALUE; }
74 VALUENAME { return VALUENAME; }
75 VALUEON { return VALUEON; }
76 VALUEOFF { return VALUEOFF; }
77 =               { return EQUALS; }
78 \[strings\]     { return STRINGSSECTION; }
79
80 [0-9]+ {
81         char *e, *y = yytext;
82         yylval.integer = strtol((const char *)yytext, &e, 0);
83         if(e == y)
84                 error_message("malformed constant (%s)", yytext);
85         else
86                 return INTEGER;
87                 }
88
89 [A-Za-z\\{}][{}\-\\A-Za-z0-9_]* { 
90         yylval.text = strdup ((const char *)yytext);
91         return LITERAL;
92         }
93
94 "!!"[A-Za-z][-A-Za-z0-9_]*  {
95         yylval.text = strdup ((const char *)yytext);
96         return LOOKUPLITERAL;
97         }
98 [ \t]+
99 \n                      { lineno++; }
100 ;[^\n]*\n               { lineno++; }
101 \"([^\n]+)\n            { lineno++; yylval.text = strdup((const char *)yytext); return LITERAL; }
102 %%
103
104 #ifndef yywrap /* XXX */
105 int
106 yywrap () 
107 {
108      return 1;
109 }
110 #endif
111
112
113 void
114 error_message (const char *format, ...)
115 {
116         va_list args;
117
118         va_start (args, format);
119         fprintf (stderr, "%d:", lineno);
120         vfprintf (stderr, format, args);
121         va_end (args);
122 }
123
124 struct adm_file *adm_read_file(const char *file)
125 {
126         uint8_t c[2];
127         yyin = fopen(file, "r");
128         if (yyin == NULL)
129                 return NULL;
130
131         c[0] = getc(yyin);
132         c[1] = getc(yyin);
133         if (c[0] == 0xff && c[1] == 0xfe) {
134                 utf16 = true;
135         } else {
136                 rewind(yyin);
137         }
138
139         yyparse();
140
141         return NULL; /* FIXME */
142 }