Skip to content

Commit

Permalink
Adjust lex processing in generic for newer lex (flex & Co.).
Browse files Browse the repository at this point in the history
The hack to replace the getc() in the input does not work anymore due
to structural changes in the generated code (buffering in lex.yy.c).

This needs to implement lex specific tell() and seek() functions. See
https://stackoverflow.com/questions/44266589 for a detailed discussion
of the problem.
  • Loading branch information
olebole committed Oct 5, 2017
1 parent 6506985 commit 0ff4449
Show file tree
Hide file tree
Showing 6 changed files with 2,049 additions and 816 deletions.
188 changes: 0 additions & 188 deletions unix/boot/generic/chario.c

This file was deleted.

19 changes: 8 additions & 11 deletions unix/boot/generic/generic.c
Expand Up @@ -18,7 +18,7 @@

#define input lex_input
#define unput lex_unput
extern char yytext[];
extern char *yytext;
extern int yyleng;
extern FILE *yyin;
extern FILE *yyout;
Expand All @@ -45,14 +45,11 @@ char type_char;
int pass_output = 1;
int clobber = NO;

extern long k_ftell (FILE *cx_i);
extern FILE *k_fopen (char *fname, char *mode);
extern int k_fseek (FILE *cx_i, long offset, int type);
extern int k_fclose (FILE *cx_i);

extern int yylex (void);
extern int lex_input (void);
extern void lex_unput (int ch);
extern long lex_tell (void);
extern void lex_seek (long fpos);


char *make_typed_filename (char *template, char type_char);
Expand Down Expand Up @@ -136,7 +133,7 @@ int main (int argc, char *argv[])

for (n=0; n < nfiles; n++) {
strcpy (input_file, files[n]);
yyin = k_fopen (input_file, "r");
yyin = fopen (input_file, "r");
if (yyin == NULL) {
fprintf (stderr, "Cannot open input file '%s'\n", input_file);
continue;
Expand Down Expand Up @@ -218,10 +215,10 @@ int main (int argc, char *argv[])
yylex(); /* do it */

fclose (fp);
k_fseek (yyin,0L,0);
lex_seek (0L);
}

k_fclose (yyin);
fclose (yyin);
}

exit (OSOK);
Expand Down Expand Up @@ -525,7 +522,7 @@ do_for (void)
fp->f_prevtype = type_char;
strcpy (fp->f_types, types);
fp->f_curtype = fp->f_types;
fp->f_fpos = k_ftell (yyin);
fp->f_fpos = lex_tell();

type_char = *(fp->f_curtype)++;
set_type_string (type_char);
Expand All @@ -549,7 +546,7 @@ do_endfor (void)
fp = &forstk[forlev];
if ((type_char = *(fp->f_curtype)++) != EOS) {
set_type_string (type_char);
k_fseek (yyin, fp->f_fpos, 0);
lex_seek (fp->f_fpos);
} else {
type_char = fp->f_prevtype;
set_type_string (type_char);
Expand Down
7 changes: 0 additions & 7 deletions unix/boot/generic/lex.sed

This file was deleted.

0 comments on commit 0ff4449

Please sign in to comment.