/* pruncl.c - Processes unclassified links into web pages. Copyright (c) 1998-2002 L. David Baron This Version: 2002-05-09 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The GNU General Public License is available at http://www.gnu.org/copyleft/gpl.html The author can be contacted at dbaron@fas.harvard.edu (until 2002) or 1068 Harvard Yard Mail Center Cambridge MA, 02138-7500, USA (until the end of May 1999) The documentation for this program is available at: http://dbaron.org/input/ */ #include #include #include /* #define LOCDTD */ #define LINKSFILE "/home/d/dbaron/public_html/dbaron.org/input/unclass.txt" #define LINKSLINESIZE 3000 #define CATSFILE "/home/d/dbaron/public_html/dbaron.org/input/classif.html" #define CATLEN 9 #define CATLINELEN 400 #define TITLELEN 300 #define FNAMELEN 150 #define SHORTFNAMELEN 35 #define OFNAMEP "/home/d/dbaron/public_html/dbaron.org/links/" #define IFNAMEP "/home/d/dbaron/public_html/dbaron.org/input/" #define INDFNAME "/home/d/dbaron/public_html/dbaron.org/links/fullindex" #define INCLINELEN 500 FILE * CatsFile, * OutFile, *HdrFile, *IndFile; char curcat[CATLEN] = "\0"; char shortfname[SHORTFNAMELEN]; int LFileLine=0; int CFileLine=0; int catsize; int newcat=1; int nCount; int wfile=0; int satfile=0; int firstfile=1; char curftitle[TITLELEN]; int firstonpage; /* not needed anymore? */ int ulstarted=0; int level, prevlevel; /* for printheader */ FILE * startindfile ( const char * title) { FILE * outf; char fname[FNAMELEN]; FILE *mfile; char mfilename[FNAMELEN]; char theline[CATLINELEN]; strcpy(fname,INDFNAME); strcat(fname,".html"); outf = fopen(fname, "w"); strcpy(mfilename,INDFNAME); strcat(mfilename,".meta"); #if defined(LOCDTD) fprintf(outf,"\n"); #else fprintf(outf,"\n"); #endif fprintf(outf,"\n"); fprintf(outf,"\n\n"); fprintf(outf,"\n"); /* fprintf(outf,"\n"); */ fprintf(outf,"David Baron's %s of Links\n", title); mfile = fopen(mfilename,"a"); fclose(mfile); mfile = fopen(mfilename,"r"); fgets(theline, CATLINELEN, mfile); while (!feof(mfile)) { fprintf(outf,"%s", theline); fgets(theline, CATLINELEN, mfile); } fclose(mfile); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n\n\n"); fprintf(outf,"

%s

\n", title); fprintf(outf,"\n\n
    \n"); return outf; } FILE * startfile ( const char * title) { FILE * outf; char fname[FNAMELEN]; char hdrfname[FNAMELEN]; char theline[CATLINELEN]; char * pos1; FILE *mfile; char mfilename[FNAMELEN]; level=0; wfile = ( curcat[0] == 'w' ); satfile = (wfile && ((curcat[1]=='s') || (curcat[1]=='l'))); if ( wfile ) { strcpy(curftitle, "W"); } else { strcpy(curftitle, ""); } strcat(curftitle,title); pos1 = strchr(curftitle, ' '); if (pos1 != NULL ) { *pos1 = '\0'; } strcpy(shortfname, curftitle); strcat(shortfname, ".html"); if (! firstfile) { fprintf(IndFile, "\n"); } else { firstfile = 0; } if (! strcmp(curcat, "w") ) { firstfile = 1; } fprintf(IndFile, "
  • %s [%s]", shortfname, title, curcat); strcpy(fname,OFNAMEP); strcat(fname,curftitle); strcat(fname,".html"); strcpy(hdrfname,OFNAMEP); /*if ( wfile ) { strcat(hdrfname, "W"); }*/ strcat(hdrfname,curftitle); strcat(hdrfname,".hdr"); strcpy(mfilename,OFNAMEP); /*if ( wfile ) { strcat(mfilename, "W"); }*/ strcat(mfilename,curftitle); strcat(mfilename,".meta"); outf = fopen(fname,"w"); if ( satfile ) { #if defined(LOCDTD) fprintf(outf,"\n"); #else fprintf(outf,"\n"); #endif } else { #if defined(LOCDTD) fprintf(outf,"\n"); #else fprintf(outf,"\n"); #endif } fprintf(outf,"\n"); fprintf(outf,"\n\n"); fprintf(outf,"\n"); /* fprintf(outf,"\n"); */ if (satfile) { fprintf(outf,"IWSIC - %s\n", title); } else { fprintf(outf,"David Baron's %s Links\n", title); } mfile = fopen(mfilename,"a"); fclose(mfile); mfile = fopen(mfilename,"r"); fgets(theline, CATLINELEN, mfile); while (!feof(mfile)) { fprintf(outf,"%s", theline); fgets(theline, CATLINELEN, mfile); } fclose(mfile); if ( wfile ) { if ( satfile ) { /* IWSIC Page */ fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); } else { /* Weather Page */ fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); } } else { /* Links Page */ fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); fprintf(outf,"\n"); } fprintf(outf,"\n\n\n"); if (satfile) { fprintf(outf,"

    %s

    \n", title); fprintf(outf,"

    ...a part of the International Weather Satellite Imagery Center.

    \n"); } else { fprintf(outf,"

    %s

    \n", title); } fprintf(outf,"
    \n"); HdrFile = fopen(hdrfname,"a"); fclose(HdrFile); HdrFile = fopen(hdrfname,"r"); fgets(theline, CATLINELEN, HdrFile); while (!feof(HdrFile)) { fprintf(outf,"%s", theline); fgets(theline, CATLINELEN, HdrFile); } fclose(HdrFile); fprintf(outf,"
    \n"); firstonpage=1; ulstarted=0; HdrFile = fopen(hdrfname,"w"); return outf; } void endfile ( FILE * outf) { if (outf != IndFile ) { fprintf(outf,"
\n\n"); } fprintf(outf,"
\n"); fprintf(outf,"

\"Valid

\n

",curftitle); if ( wfile ) { fprintf(outf,"(Back to "); if (satfile) { fprintf(outf,"IWSIC,\n"); fprintf(outf,"Weather,\n"); } else { fprintf(outf,"Weather,\n"); } } else { fprintf(outf,"(Back to Links,\n"); } fprintf(outf,"L. David Baron)"); fprintf(outf,"

\n

LDB,\n"); fprintf(outf,"dbaron@fas.harvard.edu

\n"); fprintf(outf,"\n"); /* fprintf(outf,""); */ if (outf != IndFile) { fclose(HdrFile); } fclose(outf); } void printheader ( const char * title ) { /* prints the title and prints to the headers file*/ int notlink; char title2[TITLELEN]; char *pos1; char *htitle; char *hrefname; if ((!firstonpage) && (ulstarted)) {fprintf(OutFile, "\n");} ulstarted=0; firstonpage=0; /* Make title2 the first word of title */ strcpy(title2,title); pos1 = strchr(title2, ' '); if (pos1 != NULL ) { *pos1 = '\0'; } prevlevel=level; level=strlen(curcat)-wfile; if ( prevlevel >= level) { fprintf(HdrFile, "\n"); fprintf(IndFile, "\n"); } notlink = strncmp(title,"%s [%s]",htitle, curcat); fprintf(IndFile, "
  • %s [%s]",htitle, curcat); /* XXX Fix this */ } else { if ( notlink ) { fprintf(IndFile, "
  • %s [%s]", shortfname, hrefname, title,curcat); if (satfile) { fprintf(HdrFile, "
  • %s [%s]",hrefname, title,curcat); } else { fprintf(HdrFile, "
  • %s [%s]",hrefname, title,curcat); } } else { /* these are links to separate files within the headers */ fprintf(HdrFile, "
  • %s [%s]",title, curcat); fprintf(IndFile, "
  • %s [%s]",title, curcat); /* no problem */ } } if (notlink) { if (level <= 6) { fprintf(OutFile, "\n%s\n", level, hrefname, title, level); } else { fprintf(OutFile, "\n\n", level, hrefname, title); } } else { if (level <= 6) { fprintf(OutFile, "\n%s\n", level, title, level); } else { fprintf(OutFile, "\n
    %s
    \n", level, title); } } } void getcattostart () { /* sets the category heading to the first one, reads CatsFile * and opens and writes to OutFile */ char theline[CATLINELEN]; char thetitle[TITLELEN]; char * curpos; char * pos2; do { CFileLine++; fgets(theline,CATLINELEN,CatsFile); } while ( (! feof(CatsFile)) && (strstr(theline, "'); if (curpos == NULL ) { fprintf(stderr, "CatsFile (%s) line %d:\n Error: No > on \n"); } else { fprintf(HdrFile,"\n
      \n"); } fprintf(IndFile,"\n
        \n"); } else { while (strstr(theline, "\n
      \n"); fprintf(IndFile,"\n
    \n"); /*if (( strlen(curcat) - wfile) == 1) { fprintf(HdrFile,"\n"); } else { fprintf(HdrFile,"
  • \n"); }*/ } } curpos = strstr(theline,"'); if (curpos == NULL ) { fprintf(stderr, "CatsFile (%s) line %d:\n Error: No > on 0) { fprintf(stderr, "LinksFile (%s) line %d:\n Error: Invalid Category or categories not sorted\nTerminating.\n", LINKSFILE, LFileLine); exit(1); } else { nextcat(); } } } void printlink (const char * thelink) { firstonpage=0; /* in case of links before headers*/ if (newcat) { fprintf(OutFile, "\n"); fprintf(IndFile,"\n\n"); } fprintf(IndFile,"\n\n"); fprintf(IndFile,"\n\n"); endfile(OutFile); wfile = 0; strcpy(curftitle, "fullindex"); endfile(IndFile); fclose(LinksFile); fclose(CatsFile); return(0); }