home *** CD-ROM | disk | FTP | other *** search
- ;/* LdirHTML v1.0 Mark Weller (c)2000
- dcc -o LdirHTML Ldirhtml.c date.o
- quit
- */
-
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <sys/dir.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #define LAH_PROGRAM "LdirHTML v1.0 - Mark Weller (c)2000"
- #define LAH_MAXPATH 255
- #define LAH_MAXFILE 31
- #define LAH_DIRHTML "dir.html"
- #define LAH_SUBHTML "sub.html"
- #define LAH_ON 1
- #define LAH_OFF 0
-
- int IsFileValid(char *);
- int IsDir(char *,char *);
- char *GetFileSize(char *,char *,char *);
- void Usage(char *);
-
-
- main(int argc,char *argv[])
- {
- struct DateStamp Date; /*-(amiga)store system datestamp-*/
- UBYTE todaydate[82]; /*-(amiga)store system time -*/
-
- DIR *dirp;
- struct direct *dp;
- char *name;
-
- char fsize[30];
-
- char gdir[LAH_MAXPATH];
- char dirhtml_file[LAH_MAXPATH];
- char subhtml_file[LAH_MAXPATH];
- char sub_path[LAH_MAXPATH];
-
- int temp_cnt = 0;
- int t_border = 0; /*-html table border size-*/
-
- FILE *dirfile;
- FILE *subfile;
-
- /*-command line switches-*/
- int v_switch = LAH_OFF; /*-verbose-*/
-
- gdir[0] ='\0';
- dirhtml_file[0] = '\0';
- subhtml_file[0] = '\0';
- sub_path[0] = '\0';
-
-
- switch(argc)
- {
- case 4 :
- case 3 : if(argv[1][0] == '-')
- {
- for(temp_cnt = 0;temp_cnt != strlen(argv[1]);temp_cnt++)
- {
- switch(argv[1][temp_cnt])
- {
- case '-' : break;
- case 'v' : v_switch = LAH_ON; break;
- case 'b' : if(argc == 4)
- {
- t_border = atoi(argv[3]);
- }
- else { Usage(NULL); } break;
- }
- }
-
- name = argv[2];
- }
- else
- {
- Usage(NULL);
- }
- break;
- case 2 : name = argv[1]; break;
- case 1 : Usage(NULL); break;
- }
-
-
- if ((dirp = opendir(name)) == NULL) {
- Usage("Can't open directory ?");
- }
-
- /*-(amiga)get todays date-*/
- DateStamp(&Date); /*-get system date/time -*/
- DateString(todaydate,&Date,5); /*- 5 = dd/mm/yyy -*/
-
-
- /*-create dir.html-*/
- strcpy(dirhtml_file,name);
- AddPart(dirhtml_file,LAH_DIRHTML); /*-(amiga) join path + file-*/
-
-
- if(!(dirfile = fopen(dirhtml_file,"w")))
- {
- closedir(dirp);
- Usage("Can't create dir.html file ?");
- }
- /*-create header for dir.html-*/
-
- fprintf(dirfile,"<HTML>\n");
- fprintf(dirfile," <HEAD>\n");
- fprintf(dirfile," <TITLE>Directory File Listing</TITLE>\n");
- fprintf(dirfile," </HEAD>\n\n");
- fprintf(dirfile," <BODY>\n");
- fprintf(dirfile," <!-- Created on %s using %s -->\n",todaydate,LAH_PROGRAM);
- fprintf(dirfile," <!-- DIRECTORY INDEX STARTS HERE -->\n\n");
- fprintf(dirfile," <H3><HR ALIGN=LEFT>%s Files</H3>Created on %s <BR>\n",name,todaydate);
- fprintf(dirfile," <TABLE BORDER=%d WIDTH=100%%>\n",t_border);
-
- /*-create sub.html-*/
- strcpy(subhtml_file,name);
- AddPart(subhtml_file,LAH_SUBHTML);
-
- if(!(subfile = fopen(subhtml_file,"w")))
- {
- closedir(dirp);
- fclose(dirfile);
- Usage("Can't create sub.html file ?");
- }
- /*-create header for sub.html-*/
-
- fprintf(subfile,"<HTML>\n");
- fprintf(subfile," <HEAD>\n");
- fprintf(subfile," <TITLE>Sub Directory Listing</TITLE>\n");
- fprintf(subfile," </HEAD>\n\n");
- fprintf(subfile," <BODY>\n");
- fprintf(subfile," <!-- Created on %s using %s -->\n",todaydate,LAH_PROGRAM);
- fprintf(subfile," <!-- SUB DIRECTORY INDEX STARTS HERE -->\n\n");
- fprintf(subfile," <H3><HR ALIGN=LEFT>%s Sub Directories</H3>Created on %s <BR> \n",name,todaydate);
- fprintf(subfile," <TABLE BORDER=%d WIDTH=100%%>\n",t_border);
-
-
- if(v_switch == LAH_ON)
- {
- printf("------------------------------------------------\n");
- printf("%s\n",LAH_PROGRAM);
- printf("------------------------------------------------\n");
- printf("Directory : %s\n",name);
- printf("TableBorderSize : %d\n\n",t_border);
- }
-
-
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
- {
- if(IsDir(name,dp->d_name) == 1) /*-Not Sub Directory-*/
- {
- if(IsFileValid(dp->d_name) == 1)
- {
- fsize[0] ='\0';
- GetFileSize(name,dp->d_name,fsize);
- fprintf(dirfile," <TR>\n");
- fprintf(dirfile," <TD WIDTH=10%%><LEFT>%s</TD>\n",fsize);
- fprintf(dirfile," <TD WIDTH=90%%><LEFT><A HREF=%c%s%c>%s</A></TD>\n",'"',dp->d_name,'"',dp->d_name);
- fprintf(dirfile," </TR>\n");
-
- if(v_switch == LAH_ON)
- {
- printf("%6s - %50s -> dir.html\n",fsize,dp->d_name);
- }
- }
- }
- else
- {
- /*-sub directory-*/
- strcpy(sub_path,name);
- AddPart(sub_path,dp->d_name);
-
- fprintf(subfile," <TR>\n");
- fprintf(subfile," <TD WIDTH=100%%><LEFT><A HREF=%c%s/dir.html%c>%s</A></TD>\n",'"',dp->d_name,'"',sub_path);
- fprintf(subfile," </TR>\n");
-
- if(v_switch == LAH_ON)
- {
- printf("%59s -> sub.html\n",sub_path);
- }
-
- sub_path[0] = '\0';
- }
- }
-
- closedir(dirp);
-
- if(v_switch == LAH_ON)
- printf("------------------------------------------------\n");
-
- /*- Create end for dir.html -*/
- fprintf(dirfile," </TABLE> <BR>\n");
- fprintf(dirfile," <TABLE BORDER=0 WIDTH=100%%>\n");
- fprintf(dirfile," <TR>\n");
- fprintf(dirfile," <TD WIDTH=100%%><LEFT><A HREF=%csub.html%c>Sub Directories</A></TD>\n",'"','"');
- fprintf(dirfile," </TR>\n");
- fprintf(dirfile," </TABLE>\n");
- fprintf(dirfile," <!-- END OF DIRECTORY INDEX ARCHIVE -->\n");
- fprintf(dirfile," <H3><HR ALIGN=LEFT></H3>\n");
- fprintf(dirfile," </BODY>\n");
- fprintf(dirfile,"</HTML>\n");
- fclose(dirfile);
-
- /*- Create end for dir.html -*/
- fprintf(subfile," </TABLE>\n");
- fprintf(subfile," <!-- END OF SUB DIRECTORY INDEX -->\n");
- fprintf(subfile," <H3><HR ALIGN=LEFT></H3>\n");
- fprintf(subfile," </BODY>\n");
- fprintf(subfile,"</HTML>\n");
- fclose(subfile);
-
- exit(0);
- }
-
-
-
- void Usage(char *mess)
- {
- printf("----------------------------------------\n");
-
- if(mess)
- {
- printf("mess:%s\n",mess);
- printf("----------------------------------------\n");
- }
-
- printf("%s\n",LAH_PROGRAM);
- printf("----------------------------------------\n");
- printf("USAGE: LdirHTML <-vb> [directory] <table border size>\n\n");
- printf("Chosen options: -\n");
- printf(" v = verbose - displays output\n");
- printf(" b = set table border size (default = 0)\n");
- printf("example: LdirHTML -vb Work: 2\n");
- printf(" this will create dir.html of work: file contents & sub.html\n");
- printf(" of work: sub directorys & the tables border size of 2 \n");
- printf(" and display the output.\n");
- printf("----------------------------------------\n");
- printf("See LdirHTML.readme for more information.\n");
- printf("----------------------------------------\n");
-
- exit(0);
- }
-
- char *GetFileSize(char *dname,char *fname,char *fsize)
- {
-
- struct stat load_stat;
- char gfile_buff[255];
- int size = 0;
- int rem = 0;
- int ssize= 0;
-
- gfile_buff[0]='\0';
- strcpy(gfile_buff,dname);
- AddPart(gfile_buff,fname);
-
- stat(gfile_buff,&load_stat);
-
- ssize = (int)load_stat.st_size;
-
- if(ssize < 1024)
- {
- sprintf(fsize,"%db",ssize); /*bytes*/
- }
- else
- {
- size = ssize / 1024;
- if(size < 1024)
- {
- sprintf(fsize,"%dKb",size); /*kbytes*/
- }
- else
- {
- rem = size % 1024;
- if(rem < 100) rem = 1; else rem /= 100;
-
- sprintf(fsize,"%d.%dMb",size / 1024,rem); /*Mbytes*/
- }
- }
-
- }
-
- int IsDir(char *dname,char *fname)
- {
-
- struct stat load_stat;
- char gfile_buff[255];
-
- gfile_buff[0]='\0';
- strcpy(gfile_buff,dname);
- AddPart(gfile_buff,fname);
-
- stat(gfile_buff,&load_stat);
-
- if(S_ISDIR(load_stat.st_mode) != 0)
- return(0);
- else
- return(1);
- }
-
-
- IsFileValid(char *fname)
- {
- char temp_name[LAH_MAXFILE];
- int result = 1;
-
- strcpy(temp_name,fname);
-
- if(strcmp(temp_name,LAH_DIRHTML) == 0) { result = 0; }
- else { if(strcmp(temp_name,LAH_SUBHTML) == 0) { result = 0; } }
- return(result);
- }
-