/* Splits a file into separate files according to a marker (.bp); adds title, header, and paragraph html markers; makes previous/next anchors; appends a section of text to the end; makes a table of contents. */ /* Instructions for use: This program works well for long documents possessing natural breaks in the text (a newsletter, for example). At each point where you would like a new WWW page to begin, insert a .bp on the line directly above the desired break point. The marker should be on a line by itself, and there are no restrictions concerning where on the line it should be placed. split_to_html splits the file at the desired breakpoints, inserts the user-defined title, inserts as the header the line following the marker, converts the file to simple html, makes previous/next anchors, appends a section of text to the end, and makes a table of contents. This program has been written for UNC; you will need to edit the fprintf statements so that they contain information for your site. */ /* Maria Winslow : winslow@cs.unc.edu */ /* last modified 3/29/95 */ /* Modified by Judy Hallman 6/3/96 */ /* Changed graphics */ #include #include #include /* number of files generated */ int num_files = 0; /* buffer string for input */ char inbuf [255]; /* current line */ char line [200]; /* current output file */ char output [50] = "file."; /* name of title user wants on each page */ char title [200]; /* filenames */ FILE *infileptr; FILE *outfileptr; FILE *headerptr; /* next and previous pointers */ char previous [50]; char next [50]; /************************** get_file **************************************/ void get_file () { printf ("Enter filename to be processed.\n\n"); gets (inbuf); if ( (infileptr = fopen (inbuf, "r") ) == NULL) printf ("UNABLE TO OPEN FILE\n\n"),exit (1); } /* end of get_file */ /**************************************************************************/ void main () { /* get the file to be procesed */ get_file (); /* get the name of the title the user wants for each page */ printf ("Enter a title to be placed on each individual page.\n\n"); gets (title); /* open header file */ headerptr = fopen ("file.header.html", "w"); fprintf (headerptr, " %s \n", title); fputs ("\n \n", headerptr); fputs ("\n
\"\"
\n", headerptr); fprintf (headerptr, "

%s

\n\n\n
    \n\n", title); /* open first output file */ sprintf (output, "file.%d.html", num_files); outfileptr = fopen (output, "w"); /* go through the file, skipping blank lines */ while (fgets (line, 199, infileptr) != NULL) { if (strstr (line, ".bp") != NULL) { fputs ("

    \"\"

    ", outfileptr); sprintf (next, "file.%d.html", num_files + 1); fprintf (outfileptr, "
    \n Next topic\n",next); if (num_files > 1) { sprintf (previous, "file.%d.html", num_files - 1); fprintf (outfileptr, "
    \n Previous topic",previous); } fprintf (outfileptr, "
    \n Beginning of Document

    "); fputs (" \"\"To UNC-CH Home Page

    ", outfileptr); num_files++; fclose (outfileptr); sprintf (output, "file.%d.html", num_files); outfileptr = fopen (output, "w"); /* get the next line */ fgets (line, 199, infileptr); if (strcmp(line, "\n") == 0) /* skip blank lines, looking for the header line */ while ((strcmp(line, "\n") == 0) && fgets (line, 199, infileptr) != NULL); /* make first line the header/title */ /* chop the newline */ line[strlen(line)-1] = '\0'; fputs (" ", outfileptr); fputs (title, outfileptr); fputs (" \n\n", outfileptr); fputs ("\n \n", outfileptr); fputs ("

    ", outfileptr); fputs (line, outfileptr); fputs ("

    \n

    \n\n", outfileptr); fputs ("

  • ", headerptr); fputs (line, headerptr); fputs ("\n\n", headerptr); } else if (!strcmp (line, "\n")) fputs ("

    \n", outfileptr); else fputs (line, outfileptr); } /* end of while */ system ("rm file.0.html"); system ("mv file.header.html index.html"); fclose (infileptr); if (num_files > 1) { sprintf (previous, "file.%d.html", num_files - 1); fprintf (outfileptr, "
    \n Previous topic",previous); } fprintf (outfileptr, "
    \n Beginning of Document

    "); fputs (" \"\"To UNC-CH Home Page

    ", outfileptr); fclose (outfileptr); fputs ("

\n\n", headerptr); fputs ("
\"\"

\n", headerptr); fputs (" \"\"To UNC-CH Home Page

", headerptr); fclose (headerptr); } /* end of main */