%{ #include FILE *out; char outname[32]="anon"; int use_stdout= 1; int part=0; void init_html (void) {char name [32]; if (use_stdout && part==0) out= stdout; else { if (part) sprintf(name, "%s_%d.html", outname, part); else sprintf(name, "%s.html", outname); out=fopen(name,"w"); } fprintf(out,"\n"); fprintf(out,"%cHTML>%cTITLE>WARNING: AUTOMATICALLY CONVERTED FROM ROFF\n",'<','<'); } void end_html (void) { fprintf(out,"\n"); fclose(out); } void do_break (char yytext[]) /* yytext = [ UPN|-]+\n */ {int done= 0; while (!done) { switch (yytext[0]) { case 'U': fprintf(out,"UP\n", outname); break; case 'P': if (part-1) fprintf(out,"PREVIOUS\n", outname, part-1); else fprintf(out,"PREVIOUS\n", outname); break; case 'N': fprintf(out,"NEXT\n", outname, part+1); break; case '-': fprintf(out,"
\n"); break; case '|': end_html(); part++; init_html(); break; case ' ': break; case '\n': default: done= 1; } yytext++; } } enum font {R, I, B}; int font= R; char *at_eoln= NULL; void eoln (char *s) { if (at_eoln) { fprintf(out,"%s", at_eoln); at_eoln= NULL; } else if (s) fprintf(out,"%s", s); } %} %s PRE TAB EQ SKIP SKIPTOEOLN %% .*\n {BEGIN (INITIAL);} ^\.de.*\n {BEGIN (SKIP);} ^\.\.\n {BEGIN (INITIAL);} .*\n ; ^\.nf {fprintf(out,"
"); BEGIN (PRE);}
^\.DS.*$		{fprintf(out,"
"); BEGIN (PRE);}
^\.fi			{fprintf(out,"
"); BEGIN (INITIAL);}
^\.DE			{fprintf(out,"
"); BEGIN (INITIAL);} ^\.TS\n {fprintf(out,"
"); BEGIN (TAB);}
^.*\.\n			{BEGIN (PRE);}
^.*\n			;
^\.T&\n			{BEGIN (TAB);}
^\.TE\n			{fprintf(out,"
"); BEGIN (INITIAL);} \\\(ua {fprintf(out,"^");} \\\(bu {fprintf(out,"*");} \\\(dg {fprintf(out,"+");} \\\(sc {fprintf(out,"$");} \\\(bv {fprintf(out,"|");} \\\(mi {fprintf(out,"-");} \\\(em {fprintf(out,"-");} \\\(da {fprintf(out,"v");} \\\(\*\* {fprintf(out,"*");} \\\(fm {fprintf(out,"'");} \\e {fprintf(out,"\\");} \\0 {fprintf(out," ");} \\& ; \\f[0-9]+ ; \\f\(.. ; \\s[-+]?[0-9]+ ; \\\| ; \\\*\(\[\. {fprintf(out,"[");} \\\*\(\.\] {fprintf(out,"]");} \\fB$ {fprintf(out,"

"); font= B;} \\fB {fprintf(out,""); font= B;} ^\.B\n {fprintf(out,"\n"); font= B;} ^\.ft\ B {fprintf(out,"\n"); font= B;} \\fI$ {fprintf(out,"

"); font= I;} \\fI {fprintf(out,""); font= I;} ^\.I\n {fprintf(out,""); font= I;} ^\.ft\ I {fprintf(out,""); font= I;} ^".I " {char *s="\n"; at_eoln= s; fprintf(out,"");} ^".B " {char *s="\n"; at_eoln= s; fprintf(out,"");} ^".ul"\n {char *s="\n"; at_eoln= s; fprintf(out,"");} \\fP$|\\fR$ {if (font==B) fprintf(out,"

"); else if (font==I) fprintf(out,"

"); font= R;} \\fP|\\fR {if (font==B) fprintf(out,""); else if (font==I) fprintf(out,""); font= R;} ^\.R\n|^\.P\n {if (font==B) fprintf(out,""); else if (font==I) fprintf(out,""); font= R;} ^\.ft\ R|^\.ft\ P {if (font==B) fprintf(out,""); else if (font==I) fprintf(out,""); font= R;} \\. {fprintf(out,"%s", yytext+1);} \\\(.. {fprintf(out,"%s", yytext+2);} \\\*\. ; \\\*\(.. ; \< {fprintf(out,"<");} \> {fprintf(out,">");} \& {fprintf(out,"&");} \" {fprintf(out,""");}

.				{/* ^.*\n */ fprintf(out,"%s", yytext);}

^\.\\\"HTML-BREAK[ UPN|-]+\n	{do_break(yytext+13);}

^\.\\\"HTML-OFF\n	{BEGIN (EQ);}
^\.\\\"HTML.*\n	{fprintf(out,"%s", yytext+7);}
^\.EQ\n		{BEGIN (EQ);}
^\.EN\n			{BEGIN (INITIAL);}
^\.\\\"HTML-ON\n		{BEGIN (INITIAL);}
^.*\n			;
^\.\\\".*\n			;

^".ds CH \\fB\\s+2"	{char *s="\n"; at_eoln= s; fprintf(out,"

"); /*redundant & silly!*/} \\s0\\fP\n {eoln(NULL);/*redundant & silly!*/} ^".ds [F " {char *s=".\n"; at_eoln= s; fprintf(out,"

");} ^".ds [V " {char *s=",\n"; at_eoln= s; fprintf(out,"vol. ");} ^".ds [N " {char *s=",\n"; at_eoln= s; fprintf(out,"no. ");} ^".ds [P " {char *s=",\n"; at_eoln= s; fprintf(out,"no. ");} ^".ds [D " {char *s=".\n"; at_eoln= s;} ^".ds [". {char *s=",\n"; at_eoln= s;} ^".as [".\ \" {char *s=",\n"; at_eoln= s;} ^".]".*\n ; ^".ds" {BEGIN (SKIPTOEOLN);} ^".nr".*\n ; ^".ta".*\n ; ^\.TA ; ^".2C".*\n ; ^".bp"\n {fprintf(out,"
\n");} ^".br"\n {fprintf(out,"
\n");} ^" " {fprintf(out,"
\n ");} ^(\.LP\n)+ {fprintf(out,"

\n");} ^(\.PP\n)+ {fprintf(out,"

\n");} ^\.IP.*\n {int i= yyleng-2; while(isdigit(yytext[i])) {yytext[i]= 0; i--;} /* BUT WHAT IF THERE IS ONLY A NUMBER? */ if (yytext[4]=='"') { while(yytext[i]!='"') {yytext[i]= 0; i--;} yytext[i]=0; fprintf(out,"

%s\n", yytext+5); }else fprintf(out,"

%s\n", yytext+4); } ^\.TL\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.AU.*\n {fprintf(out,"Authors:\n");} ^\.SH\n\.nf\n {fprintf(out,"
"); BEGIN (PRE);}
^\.SH\n\.ce.*\n	{char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.SH\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.NH\ [1]\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.NH\ [2]\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.NH\ [3456]\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.NH\n {char *s="

\n"; at_eoln=s; fprintf(out,"

");} ^\.LG\n ; ^\.SM\n ; ^\n+ {eoln(NULL); fprintf(out,"

\n");} \n {eoln("\n");} ^\.sp.*\n {fprintf(out,"

\n");} ^\.SP.*\n {fprintf(out,"

\n");} ^\.RS ; ^\.RE ; ^\.KS ; ^\.KE ; ^\.ce.*\n ; ^\.c\n ; ^\.ns\n ; ^\.ND ; ^\.MH\n ; ^\.RP\n ; ^\.AI\n ; ^\.AB\n {fprintf(out,"

Abstract

\n");} ^\.hc.*\n ; ^\.bd.*\n ; ^\.if.*\n ; ^\.in.*\n ; ^\.tr.*\n ; ^\.SG.*\n ; ^\.CS.*\n ; ^\.OK\n {fprintf(out,"

Keywords:\n");} ^\.[A-Z]S.* {fprintf(out,"

\n");} ^\.[A-Z]E.* {fprintf(out,"

\n");} ^".BX "\".*\"$ {yytext[yyleng-1]=0; fprintf(out,"[%s]",yytext+5);} ^\.BX.*$ {fprintf(out,"[%s]", yytext+3);} . {fprintf(out,"%s", yytext);} %% int yywrap() {return 1;} int main (int argc, char *argv[]) {int ok= 1; if (argc>2) ok= 0; else if (argc==2) { if (argv[1][0]=='-' || strchr(argv[1],'.')) ok= 0; else { use_stdout= 0; strcpy(outname, argv[1]); } } if (!ok) { printf ("ms2html expects at most one parameter, a name.\n"); printf ("This name should not start with a '-', or contain a '.'\n"); return 0; } init_html(); yy_flex_debug= 0; yylex(); end_html(); return 0; }