cp: direct all internal guest console messages to sclp
[hvf.git] / cp / nucleus / direct_lexer.l
blobb74310c6b31fdf2a660d69bce14b5c779b21641f
1 /*
2  * (C) Copyright 2007-2019  Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3  *
4  * This file is released under the GPLv2.  See the COPYING file for more
5  * details.
6  */
8 #include <util.h>
9 #include <ebcdic.h>
10 #include <lexer.h>
11 #include <directory.h>
12 #include <sclp.h>
14 #include "direct_grammar.h"
16 static int __fill(struct lexer *lexer, int n)
18         char buf[CONFIG_LRECL];
19         int end, i;
20         int ret;
22         if (unlikely(!lexer->init)) {
23                 /* look up the directory file */
24                 lexer->file = edf_lookup(lexer->fs, sysconf.direct_fn, sysconf.direct_ft);
25                 if (IS_ERR(lexer->file))
26                         return PTR_ERR(lexer->file);
28                 if ((lexer->file->FST.LRECL != CONFIG_LRECL) ||
29                     (lexer->file->FST.RECFM != FSTDFIX))
30                         return -EINVAL;
32                 lexer->recoff = 0;
33                 lexer->buflen = sizeof(lexer->buf);
34                 lexer->filllen = 0;
36                 lexer->init = 1;
37         }
39         if (lexer->recoff) {
40                 lexer->filllen -= lexer->recoff;
41                 memmove(lexer->buf, &lexer->buf[lexer->recoff], lexer->filllen);
42                 lexer->recoff = 0;
43         }
45         assert(lexer->filllen < CONFIG_LRECL);
47         ret = edf_read_rec(lexer->file, buf, lexer->recno++);
48         if (ret)
49                 return ret;
51         ebcdic2ascii((u8*) buf, CONFIG_LRECL);
52         ascii2upper((u8*) buf, CONFIG_LRECL);
54         /* find the last non-blank */
55         for(end=CONFIG_LRECL-1; end>=0; end--)
56                 if (buf[end] != ' ')
57                         break;
59         for(i=0; (i<CONFIG_LRECL) && (i<end+1); i++)
60                 lexer->buf[lexer->filllen+i] = buf[i];
62         lexer->buf[lexer->filllen+i] = '\n';
63         lexer->filllen += i+1;
65         return 0;
67 #define YYFILL(n)       do { \
68                                 int ret; \
69                                 int off = cur - &lexer->buf[lexer->recoff]; \
70                                 ret = __fill(lexer, (n)); \
71                                 if (ret && !(lexer->filllen - lexer->recoff)) \
72                                         return ret; \
73                                 cur = &lexer->buf[off]; \
74                         } while(0)
75 #define YYRETURN(x)     do { \
76                                 lexer->recoff = cur - lexer->buf; \
77                                 return (x); \
78                         } while(0)
79 #define YYSKIP()        do { \
80                                 lexer->recoff = cur - lexer->buf; \
81                                 goto next; \
82                         } while(0)
83 int direct_lex(void *data, void *yyval)
85         struct lexer *lexer = data;
86         YYSTYPE *val = yyval;
87         char *cur;
89 next:
90         cur = &lexer->buf[lexer->recoff];
92         /*!re2c
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                 "USER"          { YYRETURN(USER); }
99                 "MACHINE"       { YYRETURN(MACHINE); }
100                 "STORAGE"       { YYRETURN(STORAGE); }
101                 "CONSOLE"       { YYRETURN(CONSOLE); }
102                 "SPOOL"         { YYRETURN(SPOOL); }
103                 "READER"        { YYRETURN(READER); }
104                 "PUNCH"         { YYRETURN(PUNCH); }
105                 "PRINT"         { YYRETURN(PRINT); }
106                 "MDISK"         { YYRETURN(MDISK); }
107                 [0-9]+[KMGTP]   { hex(&lexer->buf[lexer->recoff], cur-1, &val->num);
108                                   bcd2dec(val->num, &val->num);
109                                   switch(*(cur-1)) {
110                                         case 'P': val->num *= 1024;
111                                         case 'T': val->num *= 1024;
112                                         case 'G': val->num *= 1024;
113                                         case 'M': val->num *= 1024;
114                                         case 'K': val->num *= 1024;
115                                   }
117                                   YYRETURN(STORSPEC);
118                                 }
119                 [0-9A-F]+       { hex(&lexer->buf[lexer->recoff], cur, &val->num);
120                                   YYRETURN(NUM);
121                                 }
122                 [A-Z]+          { int len;
123                                   len = cur-&lexer->buf[lexer->recoff];
124                                   memcpy(lexer->retbuf, &lexer->buf[lexer->recoff], len);
125                                   lexer->retbuf[len] = '\0';
126                                   val->ptr = strdup(lexer->retbuf, ZONE_NORMAL);
127                                   YYRETURN(WORD);
128                                 }
129                 [ \t]+          { YYSKIP(); }
130         */