// genthumb.c, written by: Prem Sobel, 2004 Mar 11 #include #include #include #include static int num_row=5, num_col=6; // default static int width=128, height=80; // default static mod_col=0, mod_row=0, num_page=1; static struct _finddata_t fileinfo; static FILE *fp_page; static char page_name[32]; static char Usage[] = "Usage: genthumb [-L] [-P] [-S] [-c4] [-c5] [-c6]\n" " -L : width=128, height=80 (default)\n" " -P : width=80, height=128\n" " -S : width=80, height=80\n" " -c4 : 4 col, or pix per row\n" " -c5 : 5 col, or pix per row\n" " -c6 : 6 col, or pix per row (default)\n" " -r3 : 3 rows\n" " -r4 : 4 rows\n" " -r5 : 5 rows (default)\n" " -r6 : 6 rows\n" ; // ----------------------------------------------------------------------- static char str[100]; void error(char *msg) { fprintf(stderr, "*** %s\n", msg); exit(1); } // ----------------------------------------------------------------------- void open_page(void) { sprintf(page_name, "page%03d.html", num_page); fp_page = fopen(page_name,"w"); if(!fp_page) { sprintf(str, "Unable to open file %s", page_name); error(str); } fprintf(fp_page, "\n"); fprintf(fp_page, "\nPage %03d\n", num_page); fprintf(fp_page, "\n\n"); fprintf(fp_page, "

Page %03d

\n\n", num_page); fprintf(fp_page, "\n\n"); fprintf(fp_page, "\n"); num_page++; } // ----------------------------------------------------------------------- void close_page(void) { if(!fp_page) return; if(mod_col) fprintf(fp_page, "\n\n"); mod_col=mod_row=0; fprintf(fp_page, "
\n\n \n\n"); fclose(fp_page); fp_page=0; } // ----------------------------------------------------------------------- void add_pix(char *pix_fn) { if(!fp_page) { open_page(); } // take care of rows in fp if(++mod_col>num_col) { fprintf(fp_page, "\n\n"); mod_col=1; if(++mod_row>=num_row) { close_page(); open_page(); fprintf(fp_page, "\n"); } } fprintf(fp_page, "\n", pix_fn); fprintf(fp_page, " \n", pix_fn, width, height); } // ----------------------------------------------------------------------- void do_extension(char *ext) { // open current directory and look for files ending: *ext long h, num=0; h = _findfirst(ext, &fileinfo); if(h>=0) { add_pix(fileinfo.name); while(!_findnext(h, &fileinfo)) { add_pix(fileinfo.name); } } _findclose(h); } // ----------------------------------------------------------------------- int main(int argc,char *argv[]) { int n, m, k; FILE *fp; /* --- examine command line arguments --- */ for(n=1; n6)) error(Usage); num_col=m; case 'r': m=argv[n][++k]-'0'; if((m<3)||(m>6)) error(Usage); num_row=m; goto L; /* case 'f': if(argv[n][k+1]) file_name=&argv[n][k+1]; else if(m=0,++n0) close_page(); // generate index web page fp = fopen("index.html","w"); if(!fp) error("Unable to create file: index.html"); fprintf(fp, "\n"); fprintf(fp, "\nPage Index\n"); fprintf(fp, "\n\n"); fprintf(fp, "

Page Index

\n\n"); fprintf(fp, "\n"); mod_col=0; for(n=1; n\n"); fprintf(fp,"\n", n, n); if(++mod_col>=10) { fprintf(fp,"\n\n"); mod_col=0; } } if(mod_col) fprintf(fp, "\n\n"); fprintf(fp, "
Page%03d
\n\n\n\n"); fclose(fp); return 0; } // -----------------------------------------------------------------------