Nickolay.info. . HTML |
, - (, ). - , , 1-5, , , ( 7).
lex2html.exe lexicon_file html_file
/* "" HTML. 1-5 . DOS Windows-1251 "" HTML <,>,&." Borland C++ 3.1 Options: [X] Unsigned characters */ #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STR 128 char Str[MAX_STR]; void Error (int Code) { // char *Msg[]={ "", "Lexicon 2 HTML converter. Run me:\n lex2html.exe lexicon_file html_file", "File open error", "File operation error", "No memory" }; cprintf ("\r\n Returned: %d:\r\n %s!\r\n Press ENTER...", Code,Msg[Code]); fflush (stdin); getch(); fcloseall(); window (1,1,80,25); clrscr(); exit (Code); } //////////// FILE *Open(char *Name, char *Mode) { // FILE *f; f=fopen (Name,Mode); if (f==NULL) Error (2); return f; } int Close (FILE *f) { // return (fclose (f)); } char *ReadStr (FILE *f, char *Str) { // char *Ptr=fgets (Str,MAX_STR,f); int l=strlen(Str)-1; while ((Str[l]=='\n') || (Str[l]=='\r')) Str[l--]='\0'; return Ptr; } int WriteStr (FILE *f, char *Str) { // int i; i=fputs (Str,f); fputs ("\n",f); return (i); } //////////// // HTML Windows: char *Dos= "", *Win= " "; #define MAX_RECURSE 3 /* */ void Convert (char *s,char *d) { char *Tag[]={ "", "<i>", "<b>", "<b><i>", "<sub>", "<sup>" }, *Tag2[]={ "", "</i>", "</b>", "</i></b>", "</sub>", "</sup>" }; int i,k,j=0,l=strlen (s),Fonts=0; char c,Font[MAX_RECURSE],UnLine=0; d[0]='\0'; for (i=0; i<l; i++) { // c=s[i]; switch (c) { case 0xFF: // c=s[i+1]; if ((c>='0') && (c<'6')) { // for (k=Fonts-1; k>=0; k--) { // - strcat (d,Tag2[Font[k]]); j+=strlen(Tag2[Font[k]]); } Fonts=0; c-=48; strcat (d,Tag[c]); j+=strlen(Tag[c]); i++; Font[Fonts++]=c; //, } else if (c=='_') { // strcat (d,"<u>"); j+=3; i++; UnLine=1; } else if (c=='.') { // strcat (d,"</u>"); j+=4; i++; UnLine=0; } else if (c=='7') { // c=s[i+2]; i+=2; //!!! switch (c) { case 'e': strcat (d,"&infty;"); j+=7; break; // //...!!! default: strcat (d," "); j+=1; break; // - . } } else { // goto DEFAULT; } break; case '"': strcat (d,"""); j+=6; break; case '<': strcat (d,"<"); j+=4; break; case '>': strcat (d,">"); j+=4; break; case '&': strcat (d,"&"); j+=5; break; default: DEFAULT: if (c>127) c=Win[c-128]; // Windows! d[j++]=c; d[j]='\0'; break; } } for (k=Fonts-1; k>=0; k--) { // - strcat (d,Tag2[Font[k]]); } if (UnLine) strcat (d,"</u>"); // } int main (int argc, char *argv[]) { FILE *f,*w; char Str2[MAX_STR*3]; if (argc>1) { if ((argv[1][0]=='/') || (argv[1][0]=='?')) Error (1); else f=Open(argv[1],"rt"); } else Error (1); if (argc>2) w=Open(argv[2],"wt"); else Error (1); WriteStr (w,"<HTML><HEAD><TITLE>"); WriteStr (w,argv[2]); WriteStr (w,"</TITLE></HEAD><BODY><PRE>"); while (!feof(f)) { ReadStr (f,Str); Convert (Str,Str2); WriteStr (w,Str2); } WriteStr (w,"</PRE></BODY></HTML>"); Close (w); Close (f); Error (0); return 0; }