home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
CPM68K
/
XLU68K.LBR
/
LUADD.CQ
/
LUADD.C
Wrap
Text File
|
2000-06-30
|
9KB
|
381 lines
/* -*-c,save-*- */
/*
* luadd.c - LU add file functions
* Robert Heller. Created: Sat Nov 8, 1986 20:38:41.92
* Last Mod:
*
* (c) Copyright 1986 by Robert Heller
* All Rights Reserved
*
*
*/
#include <stdio.h> /* STD I/O defs */
#include <ctype.h> /* char type defs */
#include <osif.h> /* O/S defs */
#include "ludef.h" /* ludefs */
#include "luvars.h" /* lu variables */
/* linked list - for file name list */
typedef struct names {
char *nm_name;
struct names *nm_next;
} NAMES,*NAMESP;
lu_add(argcc,argvv)
FAST int *argcc;
FAST char ***argvv;
{
FAST int in_fd;
FAST char *p, *q;
FAST int i,j;
long int offset;
LOCAL char sectbuff[SECTSIZE];
FAST int nsect,isect;
#ifdef CRCCHEKC
unsigned short int crc,calcrc();
#endif
FAST NAMES *filenames,*fn;
NAMES *dirlook();
char *strchr();
if (!lu_openp) {
fprintf(stderr,"lu: library file not open!\n");
while (*argcc > 0 && ***argvv != '-') {
*argcc -= 1;
*argvv += 1;
}
return;
}
while (*argcc > 0 && ***argvv != '-') {
p = **argvv;
filenames = dirlook(p);
*argcc -= 1;
*argvv += 1;
for (fn = filenames; fn != NULL; fn = fn->nm_next) {
p = strchr(fn->nm_name,':');
if (p == NULL) p = fn->nm_name;
else p++;
for (i=1; i<lu_slots && lu_dire[i].lu_stat != UNUSED; i++)
if (lu_dire[i].lu_stat == ACTIVE &&
fmatch(p,lu_dire[i].lu_name)) break;
if (i >= lu_slots || lu_dire[i].lu_stat == UNUSED)
for (i = 1; i<lu_slots && lu_dire[i].lu_stat == ACTIVE; i++) ;
if (i >= lu_slots) {
fprintf(stderr,"lu: directory full\n");
freenm(filenames);
return;
}
lseek(lu_fd,0L,2);
offset = tell(lu_fd);
q = fn->nm_name;
if (*(q+1) == ':') q += 2;
for (p = lu_dire[i].lu_name, j=0;
j<8 && *q != '.' && *q != '\0';
p++, q++, j++) *p = *q;
while (j++ < 8) *p++ = ' ';
if (*q == '.') q++;
for (j=0; j<3 && *q != '\0'; j++, q++, p++) *p = *q;
while (j++ < 3) *p++ = ' ';
lu_dire[i].lu_off = offset / SECTSIZE;
lu_dire[i].lu_len = 0;
lu_dire[i].lu_crc = 0;
for (j=0,p=lu_dire[i].lu_fill;j<14;j++,p++) *p = '\0';
#ifdef CRCCHEKC
crc = 0;
#endif
in_fd = xopen(fn->nm_name,OPEN_RO);
if (in_fd == FAILURE) {
perror("lu: add file open error");
fprintf(stderr,"lu: could not open %s\n",fn->nm_name);
goto next_file;
}
for (isect = 0;
(nsect = read(in_fd,sectbuff,SECTSIZE)) == SECTSIZE;
isect++) {
nsect = write(lu_fd,sectbuff,SECTSIZE);
if (nsect != SECTSIZE) {
perror("lu: library write error");
freenm(filenames);
close(in_fd);
return;
}
#ifdef CRCCHEKC
crc = calcrc(crc,sectbuff,SECTSIZE);
#endif
}
lu_dire[i].lu_stat = ACTIVE;
printf("%s added, %d sectors\n",fn->nm_name,isect);
lu_dire[i].lu_len = isect;
#ifdef CRCCHEKC
lu_dire[i].lu_crc = crc;
#endif
lu_modp = TRUE;
close(in_fd);
close(lu_fd);
lu_fd = lopen(lu_libr,OPEN_RW);
next_file:
}
freenm(filenames);
}
#ifdef CRCCHEKC
if (lu_modp) {
lu_dire[0].lu_crc = 0;
lu_dire[0].lu_crc = calcrc(0,&lu_dire[0],lu_slots * sizeof(LUDIR));
}
#endif
}
lu_asq(argcc,argvv)
FAST int *argcc;
FAST char ***argvv;
{
FAST int in_fd;
FAST char *p, *q;
FAST int i,j;
long int offset;
LOCAL char sectbuff[SECTSIZE];
LOCAL char sqname[20];
char *strchr();
FAST int nsect,isect;
#ifdef CRCCHEKC
unsigned short int crc,calcrc();
#endif
FAST NAMES *filenames,*fn;
NAMES *dirlook();
char *strchr();
if (!lu_openp) {
fprintf(stderr,"lu: library file not open!\n");
while (*argcc > 0 && ***argvv != '-') {
*argcc -= 1;
*argvv += 1;
}
return;
}
while (*argcc > 0 && ***argvv != '-') {
p = **argvv;
filenames = dirlook(p);
*argcc -= 1;
*argvv += 1;
for (fn = filenames; fn != NULL; fn = fn->nm_next) {
q = fn->nm_name;
if (*(q+1) == ':') q += 2;
strcpy(sqname,q);
p = strchr(sqname,'.');
if (p == NULL) {
strcat(sqname,". ");
p = strchr(sqname,'.');
}
else strcat(p," ");
p++;
if (*p == ' ') *p='Q';
p++;
*p++ = 'Q';
if (*p == ' ') *p = '\0';
else *++p = '\0';
for (i=1; i<lu_slots && lu_dire[i].lu_stat != UNUSED; i++)
if (lu_dire[i].lu_stat == ACTIVE &&
fmatch(sqname,lu_dire[i].lu_name)) break;
if (i >= lu_slots || lu_dire[i].lu_stat == UNUSED)
for (i = 1; i<lu_slots && lu_dire[i].lu_stat == ACTIVE; i++) ;
if (i >= lu_slots) {
fprintf(stderr,"lu: directory fill\n");
freenm(filenames);
return;
}
lseek(lu_fd,0L,2);
offset = tell(lu_fd);
q = sqname;
for (p = lu_dire[i].lu_name, j=0;
j<8 && *q != '.' && *q != '\0';
p++, q++, j++) *p = *q;
while (j++ < 8) *p++ = ' ';
if (*q == '.') q++;
for (j=0; j<3 && *q != '\0'; j++, q++, p++) *p = *q;
while (j++ < 3) *p++ = ' ';
lu_dire[i].lu_off = offset / SECTSIZE;
lu_dire[i].lu_len = 0;
lu_dire[i].lu_crc = 0;
for (j=0,p=lu_dire[i].lu_fill;j<14;j++,p++) *p = '\0';
#ifdef CRCCHEKC
crc = 0;
#endif
p = mktemp("sqxxxxxx");
squeeze(fn->nm_name,p);
in_fd = xopen(p,OPEN_RO);
if (in_fd == FAILURE) {
perror("lu: add file open error");
fprintf(stderr,"lu: could not open temp file %s\n",p);
goto next_file;
}
for (isect = 0;
(nsect = read(in_fd,sectbuff,SECTSIZE)) == SECTSIZE;
isect++) {
nsect = write(lu_fd,sectbuff,SECTSIZE);
if (nsect != SECTSIZE) {
perror("lu: library write error");
freenm(filenames);
close(in_fd);
return;
}
#ifdef CRCCHEKC
crc = calcrc(crc,sectbuff,SECTSIZE);
#endif
}
lu_dire[i].lu_stat = ACTIVE;
printf("%s added, %d sectors\n",sqname,isect);
lu_dire[i].lu_len = isect;
#ifdef CRCCHEKC
lu_dire[i].lu_crc = crc;
#endif
lu_modp = TRUE;
close(in_fd);
close(lu_fd);
lu_fd = lopen(lu_libr,OPEN_RW);
unlink(p);
next_file:
}
freenm(filenames);
}
#ifdef CRCCHEKC
if (lu_modp) {
lu_dire[0].lu_crc = 0;
lu_dire[0].lu_crc = calcrc(0,&lu_dire[0],lu_slots * sizeof(LUDIR));
}
#endif
}
static NAMES *dirlook(wname)
FAST char *wname;
{
LOCAL struct {
char dr;
char xf[8];
char t[3];
char fill[20];
} searbk[4];
LOCAL struct fcbtab fcb;
FAST char *p, *q;
char *strchr();
LOCAL char nbuff[20];
FAST int status,i;
FAST int drv;
FAST int curuser,user;
FAST NAMES *list;
NAMES *orderin();
user = curuser = __OSIF(USER, 0x00FF);
drv = 0;
list = NULL;
p = strchr(wname,':');
if (p != NULL) {
for (q=wname;isdigit(*q) && q < p; q++) ;
if (q == p) {
*p = '\0';
user = atoi(wname);
*p = ':';
if (user < 0 || user > 15) return(NULL);
}
else {
drv = toupper(*wname);
drv -= '@';
if (drv < 1 || drv > 16) return(NULL);
}
p++;
}
else p = wname;
fcb.drive = drv;
q = fcb.fname;
for (i=0;
i<8 && *p != '.' && *p != '\0' && *p != '*';
i++, q++, p++) *q = toupper(*p);
if (*p == '*') {
while(i++ < 8) *q++ = '?';
p++;
}
else while (i++ < 8) *q++ = ' ';
if (*p == '.') p++;
q = fcb.ftype;
for (i=0;
i<3 && *p != '\0' && *p != '*';
i++, q++, p++) *q = toupper(*p);
if (*p == '*') {
while(i++ < 3) *q++ = '?';
p++;
}
else while (i++ < 3) *q++ = ' ';
if (user != curuser) __OSIF(USER,user);
__OSIF(SETDMA,&searbk[0]);
status = __OSIF(SEARCHF, &fcb);
while (status != 0x00FF) {
if (user != curuser) {
sprintf(nbuff,"%d:",user);
p = strchr(nbuff,':');
p++;
}
else if (drv != 0) {
nbuff[0] = drv+'@';
nbuff[1] = ':';
p = (&nbuff[2]);
}
else p = nbuff;
q = searbk[status].xf;
for (i=0; ((*q & 0x7F) != ' ' && i<8); i++, p++, q++) *p = *q & 0x7F;
*p++ = '.';
q = searbk[status].t;
for (i=0; ((*q & 0x7F) != ' ' && i<3); i++, p++, q++) *p = *q & 0x7F;
*p = '\0';
list = orderin(nbuff,list);
status = __OSIF(SEARCHN, 0L);
}
__OSIF(USER, curuser);
return(list);
}
NAMESP cons(nm,nml)
FAST char *nm;
FAST NAMESP nml;
{
FAST char *p;
FAST int len;
char *calloc();
FAST NAMESP newnl;
p = calloc(strlen(nm)+1,sizeof(char));
if (p == NULL) {perror("xdir");abort(0);}
strcpy(p,nm);
newnl = (NAMESP) calloc(1,sizeof(NAMES));
if (newnl == NULL) {perror("xdir");abort(0);}
newnl->nm_name = p;
newnl->nm_next = nml;
return(newnl);
}
NAMESP orderin(innm,nlist)
FAST char *innm;
FAST NAMESP nlist;
{
FAST NAMESP newnl,p,q;
if (nlist == NULL) return(cons(innm,nlist));
else if (strcmp(innm,nlist->nm_name) < 0) return(cons(innm,nlist));
else {
p = nlist;
q = nlist->nm_next;
while (q != NULL && !(strcmp(innm,q->nm_name) < 0)) {
p=q;q=p->nm_next;
}
p->nm_next = cons(innm,q);
return(nlist);
}
}
freenm(flist)
FAST NAMES *flist;
{
FAST NAMES *nlist;
for (;flist != NULL; flist = nlist) {
nlist = flist->nm_next;
free(flist->nm_name);
free(flist);
}
}