/************************************************************* * AUSHAENGE.C * * generate HTML file with links to all files in a directory * *************************************************************/ #include #include #include #include #include #define SCRIPT "http://www.fim.uni-linz.ac.at/scripts_pub/aushaenge.exe" #define ARCHIVEFLAG "archiv" #define DIRECTORY "e:\\http\\aushaenge\\*.*" /* which directory to list */ #define HTTPPATH "http://www.fim.uni-linz.ac.at/aushaenge/" /* and URL */ #define ARCHIVEDIR "e:\\http\\aushaenge\\archiv\\*.*" /* archive directory */ #define HTTPARCHIVE "http://www.fim.uni-linz.ac.at/aushaenge/archiv/" /* and URL */ #define MAXFILES 1000 /* maximum number of files (for sorting reasons) */ #define MAXFILELEN 60 /* maximum length of a filename in the list */ char files[MAXFILES][MAXFILELEN]; /* array of file names */ int fcount=0; /* number of files in array */ /* change occurences of "from" in "s" to "into" */ void Translate (char *s,char from,char into) { while (*s) { if (*s==from) *s=into; s++; } } /* generate the standard HTML prolog */ void Header (char *title,char *header) { printf("Content-type: text/html\n\n"); printf("\n\n"); printf("\n"); printf(" %s\n",title); printf("\n\n"); printf("\n"); printf(" "); printf(" "); printf("
\n\n"); printf("

%s

\n",header); printf("
\n\n"); } /* enumerate the files */ void ListFiles (char *dir) { long hFile; struct _finddata_t c_file; if ((hFile=_findfirst(dir,&c_file))!=-1L) { do { if (c_file.attrib==_A_ARCH || c_file.attrib==_A_NORMAL) strncpy(files[fcount++],c_file.name,MAXFILELEN); } while (_findnext(hFile,&c_file)==0 && fcount0) qsort((void *)files,fcount,MAXFILELEN,compare); printf("
    \n"); for (i=0;i4 && stricmp(file+strlen(file)-5,".html")==0) file[strlen(file)-5]=0; /* filename has leading date? */ if (strlen(file)>6 && file[0]=='9' && file[6]==' ') { /* put date on end and in braces */ char buf[MAXFILELEN]; file[6]=0; sprintf(date," (%c%c.%c%c.%c%c)",file[4],file[5],file[2],file[3],file[0],file[1]); strcpy(buf,file+7); strcpy(file,buf); } else *date=0; /* add file to list */ printf("
  • %s%s\n",url,files[i],file,date); } printf("
\n\n"); } /* generate the standard HTML epilog */ void Footer (int linkToArchive) { char date[100],time[100]; if (linkToArchive) printf("Archivierte Aushänge\n",SCRIPT,ARCHIVEFLAG); else printf("Zurück zu den aktuellen Aushängen\n",SCRIPT); printf("
\n"); printf(" \n"); printf(" %s %s\n",_strdate(date),_strtime(time)); printf(" \n"); printf("\n\n"); printf("\n"); } int main (int argc,char **argv) { if (argc==2 && strcmp(argv[1],ARCHIVEFLAG)==0) { Header("FIM - Schwarzes Brett","Archivierte Aushänge"); ListFiles(ARCHIVEDIR); CreateList(HTTPARCHIVE); Footer(0); } else { Header("FIM - Schwarzes Brett","Aushänge am schwarzen Brett"); ListFiles(DIRECTORY); CreateList(HTTPPATH); Footer(1); } return 0; }