/* A Program to Convert Wordstar files to HTML format. v. 3, Apr 13, 1999 syntax is: WS_HTM src dst where src, dst are filespecs ---------------------------------------------------------------- environment: MS-DOS, using MIX Power C compiler (superset of Microsoft C, Borland Turbo C), however, should be extremely portable. ----------------------------------------------------------------- This program is in the public domain, and may be used for any purpose whatsover, without permission or notification, but it is offered "as-is" without any warrentee, express or implied. ----------------------------------------------------------------- To convert Wordstar 3/4 to HTML. I suggest you use Wordstar's internal filters to convert Wordstar 5 and subsequent to Wordstar 4, then use my program to go the rest of the way. Andrew D. Todd 1249 Pineview Dr., Apt 4 Morgantown, WV 26505 U46A8@WVNVM.WVNET.EDU */ #include #include #include #include #include int is_attr[10]; main(int argc, char *argv[]) { int status, f_in, f_out; char c, c_s; char e_string[80]; /* define the names of the state counters */ int bold_attr = 0; int doub_attr = 1; int undl_attr = 2; int sup_attr = 3; int sub_attr = 4; /*and zero them*/ is_attr[bold_attr] = 0; is_attr[doub_attr] = 0; is_attr[undl_attr] = 0; is_attr[sup_attr] = 0; is_attr[sub_attr] = 0; /*get the file names*/ if( argc < 3 ) { printf(" \nBoth Source and Destination Files Needed\n"); _exit(3); } f_in = open(argv[1], O_RDONLY|O_BINARY); if(f_in == -1) { printf(" \n%s Does Not Exist\n", argv[1]); _exit(4); } f_out = open(argv[2], O_WRONLY|O_CREAT|O_EXCL|O_BINARY, S_IREAD|S_IWRITE); if( f_out == -1) { strcpy(&e_string, " \nDestination File "); strcat(&e_string, argv[2]); strcat(&e_string, " Invalid\n"); perror(&e_string); _exit(5); } /*create a header */ put_line(f_out, ""); put_line(f_out, ""); put_line(f_out, ""); put_line(f_out, ""); /*and now do the conversion */ for(;;) /* Do for the whole file */ { status = read(f_in, &c, 1); c_s = c & '\x7f'; if(status != 1) break; else if( isprint(c)) send_char(f_out, c); /*PRINTABLE*/ else if( isprint(c_s)) send_char(f_out, c_s); /* PRINTABLE WITH HIGH BIT */ else if( c == '\r') { write(f_out, "\r\n

", 5); /*HARD CARRIAGE RETURN*/ is_attr[bold_attr] = 0; is_attr[doub_attr] = 0; is_attr[undl_attr] = 0; is_attr[sup_attr] = 0; is_attr[sub_attr] = 0; /* makes the assumption that special attributes dont persist across a CR */ } else if( c == '\x8d') write(f_out, "\r\n", 2); /*SOFT CARRIAGE RETURN*/ else if( c == '\x02') flip_attr(bold_attr, f_out, "", ""); else if( c == '\x04') flip_attr(doub_attr, f_out, "", ""); else if( c == '\x13') flip_attr(undl_attr, f_out, "", ""); else if( c == '\x14') flip_attr(sup_attr, f_out, "", ""); else if( c == '\x16') flip_attr(sub_attr, f_out, "", ""); else { } } /* now add the tail and close*/ put_line(f_out, ""); put_line(f_out, ""); close(f_in); close(f_out); _exit(0); } flip_attr(int this_attr, int f_out, char *beg_str, char *end_str) { if(is_attr[this_attr]) { is_attr[this_attr] = 0; write(f_out, end_str, strlen(end_str)); } else { is_attr[this_attr] = 1; write(f_out, beg_str, strlen(beg_str)); } } send_char(int f_out, char c) { char *send_str; if(c == "\"") strcpy(send_str, """); else if(c == "&") strcpy(send_str, "&"); else if(c == "<") strcpy(send_str, "<"); else if(c == ">") strcpy(send_str, ">"); else { send_str[0] = c; send_str[1] = '\0'; } /*always*/ write(f_out, send_str, strlen(send_str)); } put_line(int f_out, char *line_str) { write(f_out, line_str, strlen(line_str)); write(f_out, "\r\n", 2); }