/* HTM_LIST This program is a companion program for HTM_LINK. It's purpose is to create a template "make file," listing the files in a directory, which can then be modified with a text-editor before running HTM_LINK. ---------------------------------------------------------------- Andrew D. Todd 1249 Pineview Dr., Apt 4 Morgantown, WV 26505 adtodd@mail.wvnet.edu http://rowboats-sd-ca.com/ --------------------------------------------------------------- usage: htm_link path_spec where path_spec is the filespec for the make file ---------------------------------------------------------------- environment: MS-DOS, using MIX Power C compiler (superset of Microsoft C, Borland Turbo C), however, should be extremely portable. ----------------------------------------------------------------- This program is in the public domain, and may be used for any purpose whatsover, without permission or notification, but it is offered "as-is" without any warrentee, express or implied. ----------------------------------------------------------------- */ /*=======================================================================*/ #include #include #include #include #include typedef struct { char fn_ext[13]; } FILE_ENTRY; FILE_ENTRY file_table[100]; main(int argc, char *argv[]) { FILE *fp_o; int n_files; char file_spec_o[256]; if(argc == 2) strcpy(file_spec_o, argv[1]); else { perror( "there should be one argument-- \n\ a path to the directory \n\ where the makefile will be generated" ); exit(8); } complete_path_spec(file_spec_o); strcat(file_spec_o, "makeform.txt"); n_files = list_all_chaps(argv[1]); fp_o = fopen(file_spec_o, "w"); fprintf( fp_o, "BOOK#t_c_fn_ext#author#,book_title#\n" ); fprintf( fp_o, "HOME#home_url_str#\n" ); qsort(file_table, n_files ,sizeof(FILE_ENTRY), strcmp); enter_all_chaps(n_files, fp_o); fclose(fp_o); } /*========================================================*/ int list_all_chaps(char *dir_path) { struct ffblk file_data; int n_files; char file_spec[256]; strcpy(file_spec, dir_path); complete_path_spec(file_spec); strcat(file_spec, "*.*"); n_files = 0; if( findfirst(file_spec, &file_data, FA_NORMAL) == 0 ) { strcpy(file_table[n_files].fn_ext, file_data.ff_name); n_files++; while(findnext(&file_data) == 0) { strcpy(file_table[n_files].fn_ext, file_data.ff_name); n_files++; } } return(n_files); } enter_all_chaps(int n_files, FILE *fp_o) { int i; for(i = 0; i < n_files; i++) enter_a_line(fp_o, file_table[i].fn_ext); } /*=======================================================*/ complete_path_spec(char *path_spec) { int path_spec_len; path_spec_len=strlen(path_spec); if(path_spec[path_spec_len-1] != '\\') strcat(path_spec, "\\"); } /*====================================================*/ enter_a_line(FILE *fp_o, char *chap_fn_ext) { char n_chap_fn_ext[20], chap_num[40], *p_in_chap_num; strcpy(n_chap_fn_ext, chap_fn_ext); strlwr(n_chap_fn_ext); strcpy(chap_num, chap_fn_ext); p_in_chap_num= strchr(chap_num, '.'); if( p_in_chap_num != NULL) *p_in_chap_num = '\0'; fprintf( fp_o, "CHAP#%s# #%s#h#\n", n_chap_fn_ext, chap_num ); } /* Generate an output line to file pointer fp_o, using the file name and extension, chap_fn_ext. The file name is copied into the chapter number field as a first approximation */ /*===========================================================*/