/*
* Lar - LU format library file maintainer
* by Stephen C. Hemminger
* linus!sch or sch@Mitre-Bedford
*
* Usage: lar key library [files] ...
*
* Key functions are:
* u - Update, add files to library
* t - Table of contents
* e - Extract files from library
* p - Print files in library
* d - Delete files in library
* r - Reorginize library
* Other keys:
* v - Verbose
*
* This program is public domain software, no warranty intended or
* implied.
*
* DESCRPTION
* Lar is a Unix program to manipulate CP/M LU format libraries.
* The original CP/M library program LU is the product
* of Gary P. Novosielski. The primary use of lar is to combine several
* files together for upload/download to a personal computer.
*
* PORTABILITY
* The code is modeled after the Software tools archive program,
* and is setup for Version 7 Unix. It does not make any assumptions
* about byte ordering, explict and's and shift's are used.
* If you have a dumber C compiler, you may have to recode new features
* like structure assignment, typedef's and enumerated types.
*
* BUGS/MISFEATURES
* The biggest problem is text files, the programs tries to detect
* text files vs. binaries by checking for non-Ascii (8th bit set) chars.
* If the file is text then it will throw away Control-Z chars which
* CP/M puts on the end. All files in library are padded with Control-Z
* at the end to the CP/M sector size if necessary.
*
* No effort is made to handle the difference between CP/M and Unix
* end of line chars. CP/M uses Cr/Lf and Unix just uses Lf.
* The solution is just to use the Unix command sed when necessary.
*
* * Unix is a trademark of Bell Labs.
* ** CP/M is a trademark of Digital Research.
*/
/* convert word to int */
#define wtoi(w) ( (w.hibyte<<8) + w.lobyte)
#define itow(dst,src) dst.hibyte = (src & 0xff00) >> 8;\
dst.lobyte = src & 0xff;
struct ludir { /* Internal library ldir structure */
unsigned char l_stat; /* status of file */
char l_name[8]; /* name */
char l_ext[3]; /* extension */
word l_off; /* offset in library */
word l_len; /* lengty of file */
char l_fill[16]; /* pad to 32 bytes */
} ldir[MAXFILES];
int errcnt, nfiles, nslots;
bool verbose = false;
char *cmdname;
char *getname(), *sprintf();
int update(), reorg(), table(), extract(), print(), delete();
main (argc, argv)
int argc;
char **argv;
{
register char *flagp;
char *aname; /* name of library file */
int (*function)() = NULL; /* function to do on library */
/* set the function to be performed, but detect conflicts */
#define setfunc(val) if(function != NULL) conflict(); else function = val
cmdname = argv[0];
if (argc < 3)
help ();
aname = argv[2];
filenames (argc, argv);
for(flagp = argv[1]; *flagp; flagp++)
switch (*flagp) {
case 'u':
setfunc(update);
break;
case 't':
setfunc(table);
break;
case 'e':
setfunc(extract);
break;
case 'p':
setfunc(print);
break;
case 'd':
setfunc(delete);
break;
case 'r':
setfunc(reorg);
break;
case 'v':
verbose = true;
break;
default:
help ();
}
if(function == NULL) {
fprintf(stderr,"No function key letter specified\n");
help();
}
(*function)(aname);
}
/* print error message and exit */
help () {
fprintf (stderr, "Usage: %s {utepdr}[v] library [files] ...\n", cmdname);
fprintf (stderr, "Functions are:\n\tu - Update, add files to library\n");
fprintf (stderr, "\tt - Table of contents\n");
fprintf (stderr, "\te - Extract files from library\n");
fprintf (stderr, "\tp - Print files in library\n");
fprintf (stderr, "\td - Delete files in library\n");
fprintf (stderr, "\tr - Reorginize library\n");
for (;;) {
printf ("Number of slots to allocate: ");
if (fgets (line, 80, stdin) == NULL)
error ("Eof when reading input");
nslots = atoi (line);
if (nslots < 1)
printf ("Must have at least one!\n");
else if (nslots > MAXFILES)
printf ("Too many slots\n");
else
break;
}