From c4e0fddf5b10117177461c3a91f0680acbc648c0 Mon Sep 17 00:00:00 2001 From: eck Date: Tue, 16 Jan 1990 15:21:15 +0000 Subject: [PATCH] MINIX squeezing with strings, fixed small preprocessor bug --- lang/cem/cemcom.ansi/code.c | 13 ++++++++++--- lang/cem/cemcom.ansi/code.str | 2 +- lang/cem/cemcom.ansi/domacro.c | 8 +++++++- lang/cem/cemcom.ansi/ival.g | 13 +++++++++---- lang/cem/cemcom.ansi/program.g | 2 +- lang/cem/cemcom.ansi/replace.c | 1 + 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lang/cem/cemcom.ansi/code.c b/lang/cem/cemcom.ansi/code.c index dd1ad154f..2d40ed68a 100644 --- a/lang/cem/cemcom.ansi/code.c +++ b/lang/cem/cemcom.ansi/code.c @@ -98,12 +98,21 @@ def_strings(sc) struct string_cst *sc1 = sc; C_df_dlb(sc->sc_dlb); - str_cst(sc->sc_value, sc->sc_len); + str_cst(sc->sc_value, sc->sc_len, 1); /* string in rom */ sc = sc->next; + free(sc1->sc_value); free_string_cst(sc1); } } +/* flush_strings() is called from program.g after each external definition */ +flush_strings() { + if (str_list) { + def_strings(str_list); + str_list = 0; + } +} + end_code() { /* end_code() performs the actions to be taken when closing @@ -113,8 +122,6 @@ end_code() /* floating point used */ C_ms_flt(); } - def_strings(str_list); - str_list = 0; C_ms_src((int)(LineNumber - 2), FileName); C_close(); } diff --git a/lang/cem/cemcom.ansi/code.str b/lang/cem/cemcom.ansi/code.str index 6fa088c95..926fb2567 100644 --- a/lang/cem/cemcom.ansi/code.str +++ b/lang/cem/cemcom.ansi/code.str @@ -14,7 +14,7 @@ struct string_cst { /* storing string constants */ extern struct string_cst *str_list; -/* ALLOCDEF "string_cst" 10 */ +/* ALLOCDEF "string_cst" 5 */ #define LVAL 0 #define RVAL 1 diff --git a/lang/cem/cemcom.ansi/domacro.c b/lang/cem/cemcom.ansi/domacro.c index 5c602323a..72866465c 100644 --- a/lang/cem/cemcom.ansi/domacro.c +++ b/lang/cem/cemcom.ansi/domacro.c @@ -765,6 +765,12 @@ do_line(l) SkipToNewLine(); LineNumber = l; /* the number of the next input line */ - if (t == STRING) /* is there a filespecifier? */ + if (t == STRING) { /* is there a filespecifier? */ + extern char *source; /* defined in main.c */ + + if (FileName != source) { /* source points into argv */ + free(FileName); + } FileName = tk.tk_bts; + } } diff --git a/lang/cem/cemcom.ansi/ival.g b/lang/cem/cemcom.ansi/ival.g index 487d71e58..e6c185b0a 100644 --- a/lang/cem/cemcom.ansi/ival.g +++ b/lang/cem/cemcom.ansi/ival.g @@ -596,25 +596,30 @@ ch_array(tpp, ex) *to++ = *from++; } free(ex->SG_VALUE); - str_cst(s, length); + str_cst(s, length, 0); /* a string, but not in rom */ free(s); } /* As long as some parts of the pipeline cannot handle very long string constants, string constants are written out in chunks */ -str_cst(str, len) +str_cst(str, len, inrom) register char *str; register int len; + int inrom; { int chunksize = ((127 + (int) word_size) / (int) word_size) * (int) word_size; while (len > chunksize) { - C_con_scon(str, (arith) chunksize); + if (inrom) + C_rom_scon(str, (arith) chunksize); + else C_con_scon(str, (arith) chunksize); len -= chunksize; str += chunksize; } - C_con_scon(str, (arith) len); + if (inrom) + C_rom_scon(str, (arith) len); + else C_con_scon(str, (arith) len); } #ifndef NOBITFIELD diff --git a/lang/cem/cemcom.ansi/program.g b/lang/cem/cemcom.ansi/program.g index 0e180e6bd..e50865db1 100644 --- a/lang/cem/cemcom.ansi/program.g +++ b/lang/cem/cemcom.ansi/program.g @@ -150,7 +150,7 @@ external_definition } function(&Ds, &Dc) ] - {remove_declarator(&Dc);} + {remove_declarator(&Dc); flush_strings(); } ; non_function(register struct decspecs *ds; register struct declarator *dc;) diff --git a/lang/cem/cemcom.ansi/replace.c b/lang/cem/cemcom.ansi/replace.c index 7fae3a96d..61a734612 100644 --- a/lang/cem/cemcom.ansi/replace.c +++ b/lang/cem/cemcom.ansi/replace.c @@ -204,6 +204,7 @@ expand_defined(repl) if (parens && ch != ')') error(") missing"); if (!parens || ch != ')') UnGetChar(); add2repl(repl, (id && id->id_macro) ? '1' : '0'); + add2repl(repl, ' '); } newarg(args) -- 2.34.1