\n");
return 1;
}
if ((in = fopen(_argv[1], "rt")) == NULL)
{
fprintf(stderr,
"Cannot open input file.\n");
return 1;
}
fprintf(stdout, "");
mode = START;
while (!feof(in) && progress)
{
echo = 1;
prevc = c;
c = fgetc(in);
if (c=='/' && (mode < REM1))
{
saved_mode = mode;
mode = REM1;
}
switch (mode)
{
case REM1:
echo = 0;
mode = REM2;
break;
case REM2:
if (c=='/')
{
if (saved_mode == DEFINE)
{
set_mode(OFF, MODE_DEFINE);
}
mode = REM_END;
set_mode(ON, MODE_REMARK_EOL);
}
else if (c=='*')
{
if (saved_mode == DEFINE)
{
set_mode(OFF, MODE_DEFINE);
}
mode = REM_STAR;
set_mode(ON, MODE_REMARK);
}
else
{
mode = saved_mode;
}
printf("/");
break;
case REM_END:
if (c=='\n')
{
set_mode(OFF, MODE_REMARK_EOL);
}
break;
case REM_STAR:
if (c=='*')
{
mode = REM_STAR_1;
}
break;
case REM_STAR_1:
if (c=='/')
{
mode = INLINE;
fprintf(stdout,"/");
echo = 0;
set_mode(OFF, MODE_REMARK);
}
else mode = REM_STAR;
break;
case START:
if (c=='#')
{
mode = DEFINE;
set_mode(ON, MODE_DEFINE);
break;
}
else if (c==' ') break;
mode = INLINE;
// and continue in next case
case INLINE:
if (c=='"' && //
prevc != 0x27 && //
prevc != '\\') //
{
set_mode(ON, MODE_STRING);
mode = STRING;
}
break;
case STRING:
if (c=='"' && prevc != '\\')
{
print_char_html('"');
set_mode(OFF, MODE_STRING);
echo = 0;
mode = INLINE;
}
break;
case DEFINE:
if (c=='\n')
{
set_mode(OFF, MODE_DEFINE);
}
break;
}
if (echo && //
(mode == INLINE || //
(mode!=INLINE && //
bufidx))) //
{
buf[bufidx++] = c;
buf[bufidx] = 0;
if (is_delimeter(c))
{
kw = 0;
if (bufidx>2)
{
kw = is_keyword(buf);
}
if (kw)
{
set_mode(ON, MODE_KEYWORD);
}
tmpc = buf[bufidx-1];
buf[bufidx-1] = 0;
fprintf(stdout,"%s",buf);
if (kw)
{
set_mode(OFF, MODE_KEYWORD);
}
print_char_html(tmpc);
bufidx = 0;
buf[0] = 0;
}
}
else if (echo) print_char_html(c);
if (c=='\n' && mode != REM_STAR)
{
mode = START;
}
}
fclose(in);
fprintf(stdout,"
\n");
fprintf(stdout,
"\n");
fprintf(stdout,
"\n");
return 0;
}