ugpete@sunybcs (Peter Theobald) (02/26/88)
<Line-eaters? We aint got no stinkin' line-eaters!> Here is the program I wrote to make printouts from DirMaster data files. Since I haven't seen anything in binaries or sources for a long time I'm just going to post the whole source file (~190 lines). The program is made for Unix. Porting it to Amy is left as an exercise for the reader (don't you HATE it when they say that??) The program accepts many options for various output formats. They are all documented in the source code. Type 'dirprint' with no options or filenames to get a quick explanation of the options. Cut off everything above the cut line, and don't forget to remove my .signature from the bottom. Enjoy, Pete /*---------------cut everything from here and above--------------------- */ /* Peter Theobald 2/15/88 Dirprint 1.0 System: Unix Directory printer. Takes DirMaster data files and outputs them in a more readable format. Usage: dirprint [options] <DirMaster-File> options: -v <Volume name> print only entries on this volume for multi-word volume names, enclose in quotes -d <n> print only to this depth ( -d 0 prints only volume names ) -p print page breaks (^L) between volumes -t "Title line" print this header at top future options: <Volume name> can be a regular expression (wild cards) or a list of names/expressions. -f <filter-file> filters output against list of unwanted files in <filter-file>. Each line has one filename expression. eg: *.info *-Handler c/failat c/if fonts/* It is case-insensitive, allows regular expressions, and can match full path- names. */ #include <stdio.h> #define Volume 0 #define Directory 1 #define File 2 main(argc, argv) int argc; char *argv[]; { int depth, i,e, page ; char infile[80], volname[80], title[80]; FILE *infp = stdin, *fopen(); strcpy(title," Master directory of Amiga disks"); volname[0]= '\0'; infile[0]= '\0'; depth = 10000; page =0; i = 1; if (argc==1) { usage(argv[0]); exit(0); } while (--argc) { if (*argv[i]=='-') { switch (*(argv[i]+1)) { case 'd': e=sscanf(argv[i+1],"%d",&depth); fprintf(stderr,"depth: %d\n",depth); argc--; i++; if (e != 1) { fprintf(stderr, "**Error in depth specification.\n"); usage(argv[0]); exit(1); } break; case 'v': strcpy(volname,argv[i+1]); fprintf(stderr,"volume: %s\n",volname); argc--; i++; break; case 'p': page = 1; break; case 't': strcpy(title,argv[i+1]); argc--; i++; break; default: fprintf(stderr,"**Error, unknown option.\n"); usage(argv[0]); exit(1); break; } } else { e=sscanf(argv[i],"%s",infile); fprintf(stderr,"DM file: %s\n",infile); if (e != 1) { fprintf(stderr, "**Error in DirMaster file specification.\n"); usage(argv[0]); exit(1); } } i++; } if (*infile != '\0') infp = fopen(infile,"r"); printf("\n\n%s\n\n\n",title); print(infp, depth, volname, page); } print(in, depth, volname, pflag) FILE *in; int depth, pflag; char *volname; { int i, j, k, max_records, type, level, size, date, ok, header; char name[80], *datetos(); header=0; if (*volname == '\0') ok = 1; else ok = 0; fscanf(in,"%*d/%d",&max_records); for (i=0; i<max_records; i++) { fscanf(in,"%d/%d/%d/%d/%[^\n]",&type,&level,&size,&date,name); if ((type == Volume)&&(*volname!='\0')) ok = !strcmp(volname,name); if ((level<=depth) && ok) { if (level>0) for (j=0; j<level; j++) printf(" "); if ((type == Volume)&&(depth>0)) {if (pflag && header!=0) printf("\014\n"); header=1; printf( "\n-------------------------------------------\n\n"); } if ((type == Directory)||(type == Volume)) { k = strlen(name); name[k] = (type==Volume)? ':' : '/'; name[k+1]='\0'; } printf("%-20s %6d %s\n",name,size,datetos(date)); } } } char * datetos(day) int day; { static char stamp[64]; static char dim[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static char *Month[12] = { "Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug","Sep","Oct","Nov","Dec" }; register long month, year, scr; year = 1978; while (day >= (scr = ((year&3)|!(year%100)) ? 365 : 366)) { ++year; day -= scr; } dim[1] = ((year&3)|!(year%100)) ? 28 : 29; for (month = 0; day >= dim[month]; (day -= dim[month]), ++month); sprintf(stamp, "%2ld %s %4ld", day + 1, Month[month], year); return (stamp); } usage(progname) char *progname; { fprintf(stderr,"Usage: %s [options] <DirMaster-file>\n",progname); fprintf(stderr,"Options: -v <volume-name> print only that disk\n"); fprintf(stderr," (enclose in quotes for two or more words)\n"); fprintf(stderr," -d <n> print only to depth n\n"); fprintf(stderr," (-d 0 prints ONLY volume names)\n"); fprintf(stderr," -p page break(^L) between volumes\n"); fprintf(stderr," -t \042Title line\042 print header at top\n"); fprintf(stderr,"\n"); } /* -----------cut off everything from here down----------------- */ Peter Theobald SUNY/Buffalo Computer Science internet: ugpete@cs.buffalo.edu bitnet: ugpete@sunybcs.BITNET uucp: ..!{ames,boulder,decvax,rutgers}!sunybcs!ugpete csnet: ugpete@buffalo.CSNET