#include #include #include #include #include #define FALSE 0 #define TRUE !0 /* extern vvvvv */ unsigned char statpage; unsigned char trace; unsigned char ansi; unsigned char local; unsigned char remote; unsigned char time_limit; typedef struct mstart { int section; char subopt[50]; char headline[70]; fpos_t artbegin; fpos_t artlen; int filler; } MSTART; typedef struct mstaridx { char mm[10][40]; MSTART art[50]; } MSTARIDX; int mstar(void); int readstar(char *msfile); int starticle(FILE *mp, MSTART *idx); int main(int argc, char *argv[], char *envp[]) { return(makehtml(argv[1])); } int makehtml(char *msfile) { /* type 101 */ unsigned char c; FILE *mp; FILE *mpi; FILE *hp; char msindex[80]; char htmfile[80]; MSTARIDX mstardex; unsigned char section = 0; unsigned char option = 0; strlwr(msfile); strcpy(msindex,msfile); memcpy(strstr(msindex,".ms"),".idx",5); if((mp = fopen(msfile,"rb")) == NULL) return(1); /* create/read index and initialize article pointers */ memset(&mstardex,'\0',sizeof(MSTARIDX)); if((mpi = fopen(msindex,"rb")) == NULL) { if((mpi = fopen(msindex,"wb")) == NULL) return(1); printf("\r\nCreating new index file..."); section = 0; option = 0; while(!feof(mp)) { unsigned char ch; ch = fgetc(mp); if (ch > 6) continue; switch(ch) { fpos_t artend; case 1: fgets(mstardex.mm[section], 40, mp); section++; break; case 2: fgets(mstardex.art[option].subopt, 50, mp); mstardex.art[option].section = section; break; case 3: fgets(mstardex.art[option].headline, 70, mp); break; case 5: fgetpos(mp, &mstardex.art[option].artbegin); break; case 6: mstardex.art[option].artlen = fgetpos(mp, &artend) - mstardex.art[option].artbegin; option++; break; default: break; } } /* while */ fwrite(&mstardex,sizeof(MSTARIDX),1,mpi); } else { unsigned char count; fread(&mstardex,sizeof(MSTARIDX),1,mpi); for(count=0;count<10;count++) { if(strlen(mstardex.mm[count])) section++; } for(count=0;count<50;count++) { if(strlen(mstardex.art[count].subopt)) option++; } } fclose(mpi); strcpy(htmfile,msfile); memcpy(strstr(htmfile,".ms"),".html",5); if((hp = fopen(htmfile,"wb")) == NULL) return(1); do { char a, b; /* let user select one, and call function */ printf("\r\nMorning Star main menu\r\n\r\n"); fprintf(hp, "\r\n",htmfile); fprintf(hp, "\r\n"); fprintf(hp, "\r\n\r\n Morning Star (%s)\r\n", htmfile); /* insert other head stuff here */ fprintf(hp, "\r\n\r\n"); fprintf(hp, "

Morning Star magazine

\r\n(Created from %s)
\r\n", msfile); /* H2 heading here */ /* SECTIONS */ for (a = 0; a < section; a++) { FILE *sp; char sectfile[80]; char sectID[6]; char sdrive[4], sdir[80], sname[9], sext[4]; strcpy(sectfile, msfile); fnsplit(sectfile,sdrive,sdir,sname,sext); sectID[0] = 'a'+ a; if(strlen(sname) < 8) strncat(sname,sectID,1); else sname[7] = sectID[0]; fnmerge(sectfile,"","",sname,".html"); if (strlen(mstardex.mm[a])) { char entry[80]; sscanf(mstardex.mm[a],"%[^\r\n]",entry); printf("\n%c %s", 'a'+ a, mstardex.mm[a]); fprintf(hp, "

%s

\r\n", sectfile, entry); /* mstardex.mm[a]); */ /* OPEN SECTION FILE AND CREATE HTM */ sp = fopen(sectfile,"wb"); fprintf(sp, "",sectfile); fprintf(sp, ""); fprintf(sp, "\r\n\r\nMorning Star %s (%s)\r\n", entry, sectfile); /* mstardex.mm[a] */ fprintf(sp, "\r\n\r\n"); fprintf(sp, "

Morning Star %s

\r\n(Created from %s)
\r\n", entry, msfile); /* mstardex.mm[a] */ /* CONTENTS */ fprintf(sp, "\r\n"); for (b = 0; b < option; b++) { if (mstardex.art[b].section == a+1) { if (strlen(mstardex.art[b].headline)) { char entry[80]; sscanf(mstardex.art[b].subopt,"%[^\r\n]",entry); printf("\n\t(%d) %s", b, mstardex.art[b].subopt); fprintf(sp, "

%s

\r\n", b, entry); /* mstardex.art[b].headline); */ /* ADD author, etc. */ } } } fprintf(sp, "

Return to Main Menu

\r\n", htmfile); for (b = 0; b < option; b++) { /* ARTICLES */ if (mstardex.art[b].section == a+1) { if (strlen(mstardex.art[b].headline)) { printf("\n\t(%d) %s", b, mstardex.art[b].headline); fprintf(sp, "\r\n\r\n", b); htmsection(mp, &mstardex.art[b], sp); fprintf(sp, "\r\n
\r\n
Top of file
\r\n"); } } } /* CLOSE HTM SECTION FILE */ fprintf(sp, "Morning Star HTML \"%s\" converted from \"%s\" with HTMStar
\r\n", sectfile, msfile); fprintf(sp, "HTMStar was written by Dana Bell (dbell@gower.net).\r\n"); fprintf(sp, "\r\n"); fclose(sp); } } fprintf(hp, "Morning Star HTML \"%s\" converted from \"%s\" with HTMStar
\r\n", htmfile, msfile); fprintf(hp, "HTMStar was written by Dana Bell (dbell@gower.net).\r\n"); fprintf(hp, "\r\n"); fclose(hp); } while (FALSE); /* ONLY ONCE */ fclose(mp); return(1); } int htmsection(FILE *mp, MSTART *idx, FILE *sp) { int j = 0; unsigned char eoa = FALSE; #define PAGES 100 fpos_t page[PAGES]; char entry[80]; sscanf(idx->headline,"%[^\r\n]",entry); /* printf("\tincluding article \"%s\".", entry ); return(0); */ for (j=0;jartbegin, SEEK_SET); printf("Reading %s\r\n", idx->headline); fprintf(sp, "

%s

\r\n", entry); /* idx->headline); */ /* ALSO display author, etc. */ while(!eoa) { int ch; unsigned char pcheck = FALSE; unsigned int maxlines; if (!page[j]) fgetpos(mp, &page[j]); do { ch = fgetc(mp); if(ch==6) { eoa = TRUE; break; } /* putchar(ch); */ if (ch == '\r') continue; if (ch == '\n') { if (pcheck) { fprintf(sp,"

\r\n"); pcheck = FALSE; } else { fprintf(sp,"
\r\n"); pcheck = TRUE; } continue; } pcheck = FALSE; if (ch == '<') { fprintf(sp,"<"); continue; } if (ch == '>') { fprintf(sp,">"); continue; } if (ch == '&') { fprintf(sp,"&"); continue; } fputc(ch, sp); } while (TRUE); /* get user input */ } return(1); }