2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
13 #include "config.tab.h"
15 static int __fill(struct lexer *lexer, int n)
17 char buf[CONFIG_LRECL];
21 if (unlikely(!lexer->init)) {
22 /* look up the config file */
23 lexer->file = edf_lookup(lexer->fs, CONFIG_FILE_NAME, CONFIG_FILE_TYPE);
24 if (IS_ERR(lexer->file))
25 return PTR_ERR(lexer->file);
27 if ((lexer->file->FST.LRECL != CONFIG_LRECL) ||
28 (lexer->file->FST.RECFM != FSTDFIX))
32 lexer->buflen = sizeof(lexer->buf);
39 lexer->filllen -= lexer->recoff;
40 memmove(lexer->buf, &lexer->buf[lexer->recoff], lexer->filllen);
44 assert(lexer->filllen < CONFIG_LRECL);
46 ret = edf_read_rec(lexer->file, buf, lexer->recno++);
50 ebcdic2ascii((u8*) buf, CONFIG_LRECL);
51 ascii2upper((u8*) buf, CONFIG_LRECL);
53 /* find the last non-blank */
54 for(end=CONFIG_LRECL-1; end>=0; end--)
58 for(i=0; (i<CONFIG_LRECL) && (i<end+1); i++)
59 lexer->buf[lexer->filllen+i] = buf[i];
61 lexer->buf[lexer->filllen+i] = '\n';
62 lexer->filllen += i+1;
67 #define YYFILL(n) do { \
69 int off = cur - &lexer->buf[lexer->recoff]; \
70 ret = __fill(lexer, (n)); \
71 if (ret && !(lexer->filllen - lexer->recoff)) \
73 cur = &lexer->buf[off]; \
75 #define YYRETURN(x) do { \
76 lexer->recoff = cur - lexer->buf; \
79 #define YYSKIP() do { \
80 lexer->recoff = cur - lexer->buf; \
83 int config_lex(void *data, void *yyval)
85 struct lexer *lexer = data;
90 cur = &lexer->buf[lexer->recoff];
93 re2c:define:YYCTYPE = "char";
94 re2c:define:YYCURSOR = cur;
95 re2c:define:YYLIMIT = &lexer->buf[lexer->filllen];
96 "\n" { YYRETURN(NLINE); }
97 "*" [^\n]* { YYRETURN(COMMENT); }
98 "DIRECTORY" { YYRETURN(DIRECTORY); }
99 "OPERATOR" { YYRETURN(OPERATOR); }
100 "RDEV" { YYRETURN(RDEV); }
101 "LOGO" { YYRETURN(LOGO); }
102 "CONSOLE" { YYRETURN(CONSOLE); }
103 "USERID" { YYRETURN(USERID); }
104 "LOCAL" { YYRETURN(LOCAL); }
105 [0-9A-F]+ { hex(&lexer->buf[lexer->recoff], cur, &val->num);
109 len = cur-&lexer->buf[lexer->recoff];
110 memcpy(lexer->retbuf, &lexer->buf[lexer->recoff], len);
111 lexer->retbuf[len] = '\0';
112 val->ptr = strdup(lexer->retbuf, ZONE_NORMAL);