8000 minix/commands/byacc/output.c at v3.1.0 · lgqgood/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
executable file
·
1210 lines (1047 loc) · 22.2 KB

output.c

File metadata and controls

executable file
·
1210 lines (1047 loc) · 22.2 KB
register FILE *in, *out;
fclose(text_file);
text_file = fopen(text_file_name, "r");
if (text_file == NULL)
open_error(text_file_name);
in = text_file;
if ((c = getc(in)) == EOF)
return;
out = code_file;
if (c == '\n')
++outline;
putc(c, out);
while ((c = getc(in)) != EOF)
{
if (c == '\n')
++outline;
putc(c, out);
}
if (!lflag)
fprintf(out, line_format, ++outline + 1, code_file_name);
}
output_debug()
{
register int i, j, k, max;
char **symnam, *s;
++outline;
fprintf(code_file, "#define YYFINAL %d\n", final_state);
outline += 3;
fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
tflag);
if (rflag)
fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
tflag);
max = 0;
for (i = 2; i < ntokens; ++i)
if (symbol_value[i] > max)
max = symbol_value[i];
++outline;
fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
symnam = (char **) MALLOC((max+1)*sizeof(char *));
if (symnam == 0) no_space();
/* Note that it is not necessary to initialize the element */
/* symnam[max]. */
for (i = 0; i < max; ++i)
symnam[i] = 0;
for (i = ntokens - 1; i >= 2; --i)
symnam[symbol_value[i]] = symbol_name[i];
symnam[0] = "end-of-file";
if (!rflag) ++outline;
fprintf(output_file, "#if YYDEBUG\nchar *%sname[] = {", symbol_prefix);
j = 80;
for (i = 0; i <= max; ++i)
{
if (s = symnam[i])
{
if (s[0] == '"')
{
k = 7;
while (*++s != '"')
{
++k;
if (*s == '\\')
{
k += 2;
if (*++s == '\\')
++k;
}
}
j += k;
if (j > 80)
{
if (!rflag) ++outline;
putc('\n', output_file);
j = k;
}
fprintf(output_file, "\"\\\"");
s = symnam[i];
while (*++s != '"')
{
if (*s == '\\')
{
fprintf(output_file, "\\\\");
if (*++s == '\\')
fprintf(output_file, "\\\\");
else
putc(*s, output_file);
}
else
putc(*s, output_file);
}
fprintf(output_file, "\\\"\",");
}
else if (s[0] == '\'')
{
if (s[1] == '"')
{
j += 7;
if (j > 80)
{
if (!rflag) ++outline;
putc('\n', output_file);
j = 7;
}
fprintf(output_file, "\"'\\\"'\",");
}
else
{
k = 5;
while (*++s != '\'')
{
++k;
if (*s == '\\')
{
k += 2;
if (*++s == '\\')
++k;
}
}
j += k;
if (j > 80)
{
if (!rflag) ++outline;
putc('\n', output_file);
j = k;
}
fprintf(output_file, "\"'");
s = symnam[i];
while (*++s != '\'')
{
if (*s == '\\')
{
fprintf(output_file, "\\\\");
if (*++s == '\\')
fprintf(output_file, "\\\\");
else
putc(*s, output_file);
}
else
putc(*s, output_file);
}
fprintf(output_file, "'\",");
}
}
else
{
k = strlen(s) + 3;
j += k;
if (j > 80)
{
if (!rflag) ++outline;
putc('\n', output_file);
j = k;
}
putc('"', output_file);
do { putc(*s, output_file); } while (*++s);
fprintf(output_file, "\",");
}
}
else
{
j += 2;
if (j > 80)
0