mugc@utecfa.UUCP (ModemUserGroupChairman) (08/15/86)
The following little program (disklist.c) is a simple disk directory lister. I'm posting it for a friend. The program works as follows: upon startup, it will ask you for the name of the source drive (which it will read and catalog), and the name of the destination drive (on which it will create a file called disklist which will contain directory listing). Every time the directory listing is written out, it will prompt you to insert another disk; hitting the "yummy" button will repeat the process and hitting the "burp" button will get you out of the program. If the disk being listed has no name, you will be prompted if you would like to name it. The program will descend the directory tree and list files under the appropriate folders. The disklist file has the following format. DIRECTORY LISTING Created on - 86/08/14 at - 21:13:46 DISK NUMBER: 001 VOLUME: utilities3 XLISP.TOS 60928 86/07/09 22:24:58 COMLSP.LSP 8346 86/07/09 22:28:42 DISKLIST.PRG 6328 86/08/12 21:32:38 WTERM.PRG 9046 86/08/03 11:38:18 KEYCODE.PRG 7092 86/09/08 20:34:48 ... etc Remember to set the time correctly before running the program or the header line will be off. Hope you find it useful in maintaining disk catalogs. Regards, anees munshi ------------------SNIP------CUT---kaatna hei to kaatyea------------------ #include "osbind.h" struct dta { char reserved[21]; char fab; unsigned time; unsigned date; long size; char name[]; }; struct dta *dta_ptr; struct line { char name[50]; char size[10]; char date[10]; char time[10]; }; struct line *line_ptr; unsigned sys_time, sys_date; int contrl[ 12 ], intin[ 256 ], ptsin[ 256 ], intout[ 256 ], ptsout[ 256 ], workin[]={ 1,1,1,1,1,1,1,1,1,1,2 }, workout[ 57 ], handle, i, j, k = 0, file_handle, button, ret; char path[100], volume[100], drive[3], crlf[2], realdta[44], realline[81], out_filename[12], disk_no[4], alert0[120], alert1[]="[3][ Select the drive to read from... ][ A | B | D ]", alert2[]="[3][ Select the drive to write to... ][ A | B | D ]", alert3[]="[3][ Feed me disk # ][ Yummy | Burp! ]", alert4[120]; long strlen(string) char *string; { char *string_pointer = string; while ( *string_pointer ) ++string_pointer; return ((long) string_pointer - string ); } char * strcat(s, t) char s[], t[]; { int i, j; i = j = 0; while(s[i] != '\0') /* find end of s */ i++; while((s[i++] = t[j++]) != '\0'); /* copy t */ } char strcpy(s, t) char *s, *t; { while(*s++ = *t++); } strequ ( str1, str2 ) char str1[], str2[]; { int i = 0, answer; while( str1[i] == str2[i] && str1[i] != '\0' && str2[i] != '\0' ) ++i; if( str1[i] == '\0' && str2[i] == '\0' ) answer = 1; else answer = 0; return( answer ); } itoa (n, s) char s[]; int n; { int i; i = 2; strcpy(s, "000"); do { s[i--] = (n % 10) + '0'; } while ((n /= 10) > 0); } ltoa (n, s) char s[10]; long n; { long n2; int i; n2 = n; i = 9; do { s[i--] = n2 - ((n2 / 10) * 10) + '0'; } while ((n2 /= 10) > 0); } itodate (idate, date) unsigned idate; char date[10]; { unsigned yy, mm, dd; yy = (idate >> 9 & 0x7F) + 80; mm = idate >> 5 & 0xF; dd = idate & 0x1F; date[2] = (yy/10) + '\060'; date[3] = (yy%10) + '\060'; date[4] = '/'; date[5] = (mm/10) + '\060'; date[6] = (mm%10) + '\060'; date[7] = '/'; date[8] = (dd/10) + '\060'; date[9] = (dd%10) + '\060'; } itotime (itime, time) unsigned itime; char time[10]; { unsigned hrs, mins, secs; hrs = itime >> 11 & 0x1F; mins = itime >> 5 & 0x3F; secs = (itime & 0x1F) << 1; time[2] = (hrs/10) + '\060'; time[3] = (hrs%10) + '\060'; time[4] = ':'; time[5] = (mins/10) + '\060'; time[6] = (mins%10) + '\060'; time[7] = ':'; time[8] = (secs/10) + '\060'; time[9] = (secs%10) + '\060'; } /*************************************************/ main() { initialize(); do { itoa(++k, disk_no); alert3[20] = disk_no[0]; alert3[21] = disk_no[1]; alert3[22] = disk_no[2]; button = form_alert(1, alert3); if (button != 2) read_the_directory(); } while( button != 2 ); terminate(); } /*************************************************/ /*************************************************/ initialize() { char today[10], totime[10]; appl_init(); handle=graf_handle( &i, &i, &i, &i ); v_opnvwk( workin, &handle, workout ); dta_ptr = &realdta; line_ptr = &realline; Fsetdta(dta_ptr); crlf[0] = 0x0d; crlf[1] = 0x0a; strcpy(alert0,"[1]"); strcat(alert0,"[ Disk Directory Listing |"); strcat(alert0, " Utility |"); strcat(alert0, " written by: Robert Ritter |"); strcat(alert0, " July, 1986 ]"); strcat(alert0, "[Good Stuff]"); form_alert(1, alert0); strcpy( alert4, "[3]" ); strcat( alert4, "[ This disk is not labeled. |"); strcat( alert4, " Do you want to enter one now? ][ Yes | No ]"); button = form_alert(1, alert1); switch(button){ case(1): strcpy(drive, "A:"); break; case(2): strcpy(drive, "B:"); break; case(3): strcpy(drive, "D:"); break; } button = form_alert(3, alert2); switch(button){ case(1): strcpy(out_filename, "A:disklist"); break; case(2): strcpy(out_filename, "B:disklist"); break; case(3): strcpy(out_filename, "D:disklist"); break; } file_handle = Fcreate(out_filename, 0); sys_time = Tgettime(); sys_date = Tgetdate(); itotime(sys_time, totime); itodate(sys_date, today); Fwrite(file_handle, 32L, "DIRECTORY LISTING Created on - "); Fwrite(file_handle, 10L, today); Fwrite(file_handle, 7L, " at - "); Fwrite(file_handle, 10L, totime); Fwrite(file_handle, 2L, crlf); Fwrite(file_handle, 2L, crlf); } /*************************************************/ /*************************************************/ do_label(my_path) char *my_path; { char vol_name[13], path_name[15]; int this_button; int i; char c; char line[80]; ret = Fsfirst(my_path,0x08); /* get the volume label */ Fwrite(file_handle, 13L, "DISK NUMBER: "); Fwrite(file_handle, 3L, disk_no); if(ret == 0) strcpy( vol_name, dta_ptr->name ); else { strcpy( vol_name, "NOT NAMED" ); this_button = form_alert(1, alert4); if (this_button == 1) { /* prompt and get the user's request */ graf_mouse(256,0x0L); /* hide the mouse */ Cursconf(0,0); /* hide the cursor */ Cursconf(2,0); /* set cursor to blink */ strcpy(line,"Enter the volume name: "); v_gtext(handle,240,180,line); strcpy( vol_name, "____________"); strcpy( line, vol_name); v_gtext(handle,240,205,line); Cursconf(1,0); /* show the cursor */ vs_curaddress(handle,13,31); i = 0; while ( (c = evnt_keybd() & 0x7F) != 0x0D ) { if ((c == 0x08)||(c == 0x7F)){ /* oops, user wants a correction */ i = i - 1; vol_name[i] = '_'; } else if ( i <= 11 ){ vol_name[i] = c; i = i + 1; } strcpy(line,vol_name); Cursconf(0,0); /* hide the cursor */ v_gtext(handle,240,205,line); Cursconf(1,0); /* show the cursor */ vs_curaddress(handle,13,(31+i)); } vol_name[i] = '\0'; graf_mouse(257,0x0L); /* show the mouse */ Cursconf(0,0); /* hide the cursor */ strcpy( path_name, drive ); strcat( path_name, vol_name ); Fcreate( path_name, 0x08 ); } } Fwrite(file_handle, 11L, " VOLUME: "); Fwrite(file_handle, strlen(vol_name), vol_name); Fwrite(file_handle, 2L, crlf); Fwrite(file_handle, 2L, crlf); } /*************************************************/ /*************************************************/ read_the_directory() { char thispath[100], cur_dir[100]; strcpy(path, drive); strcpy( thispath, path ); strcat( thispath, "\\*.*" ); do_label(thispath); ret = Fsfirst(thispath,0x10); /* get the first item on the volume */ while (ret == 0) { if (dta_ptr->fab == 0x10) /* found a directory */ {if ( (!strequ( dta_ptr->name, "." )) && (!strequ( dta_ptr->name, ".." )) ) { strcpy(cur_dir,dta_ptr->name); dir_write(path,cur_dir); /* follow the directory */ ret = Fsfirst(thispath,0x10); /*return to start of previous path */ while ((ret == 0) && (!strequ(dta_ptr->name, cur_dir))) ret = Fsnext(); } } else dta_write(drive); /* write the filename */ ret = Fsnext(); /* now walk the rest of the structure */ } Fwrite(file_handle, 2L, crlf); Fwrite(file_handle, 2L, crlf); } /*************************************************/ /*************************************************/ dta_write(path) char *path; { for(i=0; i<80; i++) realline[i] = ' '; strcpy(line_ptr->name, path); strcat(line_ptr->name, "\\"); strcat(line_ptr->name, dta_ptr->name); line_ptr->name[0] = ' '; line_ptr->name[1] = ' '; line_ptr->name[2] = ' '; ltoa(dta_ptr->size, line_ptr->size); itodate(dta_ptr->date, line_ptr->date); itotime(dta_ptr->time, line_ptr->time); Fwrite(file_handle, 80L, line_ptr); Fwrite(file_handle, 2L, crlf); } /*************************************************/ /*************************************************/ dir_write(cur_path,directory) char *cur_path, *directory; { auto char new_path[100], thispath[100], cur_dir[100]; Fwrite(file_handle, 2L, crlf); Fwrite(file_handle, 12L, " DIRECTORY: "); Fwrite(file_handle, strlen(directory), directory); Fwrite(file_handle, 2L, crlf); strcpy( new_path, cur_path ); strcat( new_path, "\\" ); strcat( new_path, directory ); strcpy( thispath, new_path); strcat( thispath, "\\*.*"); ret = Fsfirst(thispath,0x10); /* get this new path started */ while (ret == 0) { if (dta_ptr->fab == 0x10) /* found a directory */ {if ( (!strequ( dta_ptr->name, "." )) && (!strequ( dta_ptr->name, ".." )) ) { strcpy(cur_dir,dta_ptr->name); dir_write(new_path,cur_dir); /* follow the directory */ ret = Fsfirst(thispath,0x10); /*return to start of previous path */ while ((ret == 0) && (!strequ(dta_ptr->name, cur_dir))) ret = Fsnext(); } } else dta_write(new_path); /* write the filename */ ret = Fsnext(); /* now walk the rest of the structure */ } Fwrite(file_handle, 2L, crlf); } /*************************************************/ /*************************************************/ terminate() { v_clsvwk( handle ); appl_exit(); } /*************************************************/ ----------------------and again--------------fir-se---------------- -- Anees Munshi @ University of Toronto Engineering Comp. Facility :A {allegra,ihnp4,linus,decvax}!utzoo!utcsri!utecfa!mugc {allegra,ihnp4,linus,decvax}!utzoo!utcsri!utecfb!munshi