📄 ovfile.c
字号:
{
int rc;
char *fn;
fn = fname(fp); /* in case show-all active */
if (fp->flags & DIR) /* special case if file is a DIR */
rc = rmdir(fn); /* try to remove a directory */
else
rc = unlink(fn); /* delete a file */
free(fn);
if (rc) /* delete okay? */
show_error(SHOW_DOS,0,3,"Unable to erase ",fp->name,": ");
return(rc == 0);
}
/******************************************************************************
R E N _ C U R
******************************************************************************/
ren_cur() { /* rename (or move) the current file */
int rc;
register FILE_ENT *fp;
char *newname, fn[MAX_NAMELEN+1];
static char ptxt[] = "Enter new file name or directory name for ";
char *fnp, *target, *todir, *tofn, *dirp, pmsg[sizeof(ptxt)+MAX_NAMELEN+1];
fp = &files[cw.curidx];
strcpy(pmsg,ptxt); /* build prompt string */
strcat(pmsg,strcpy(fn,fp->name));
newname = strupr(prompt("Rename current file",pmsg,NULL,0,MAX_REPLY));
if (strlen(newname) == 0)
return;
/* figure out the full target name, the dir, and the fn */
rc = isadir(dirp=fp->dirp,newname); /* need to know if this is a dir name */
target = parsepath(dirp,fn,newname,rc,&todir,&tofn);
fnp = fname(fp); /* from name */
rc = rename(fnp,target); /* rename/move it */
if (rc == 0) { /* rename okay? */
/* note: fn is a local array instead of a pointer to fp->name because
add2windows() may shift the entries in files[] around thereby making
fp->name point to the wrong file - same goes for local dirp */
add2windows(todir,tofn,fp); /* add to new window(s) */
delfromwins(dirp,fn); /* del from old window(s) */
} else /* unable to rename */
show_error(SHOW_DOS,0,3,"Unable to rename ",fn,": ");
free(target); /* release temp strings */
free(todir);
free(tofn);
free(fnp);
}
/******************************************************************************
R E N _ T A G
******************************************************************************/
ren_tag() { /* rename (move) all tagged files to another dir */
int i, rc;
register FILE_ENT *fp;
char *newdir, *fnp, *target, *todir, *dirp, fn[MAX_NAMELEN+1];
if (cw.num_tagged == 0) /* are there any tagged files? */
show_error(0,NONE_TAGGED,1,none_tagged);
newdir = strupr(prompt("Move tagged files","Enter new directory name",
NULL,0,MAX_REPLY));
if (strlen(newdir) == 0)
return;
/* the name given must be a directory name */
if (!isadir(cw.dirbuf,newdir))
show_error(0,MUST_BE_DIR,1,mustbedir);
/* Okay, move the tagged files */
for (i = 0, fp = files; i < cw.nfiles && !brkout(); i++, fp++)
if (fp->flags & TAGGED) { /* this file tagged? */
/* figure out the target names */
dirp = fp->dirp;
target = parsepath(dirp,strcpy(fn,fp->name),newdir,1,&todir,NULL);
fnp = fname(fp); /* from name */
rc = rename(fnp,target); /* move the file */
if (rc == 0) { /* move okay? */
/* note: fn is a local array instead of a pointer to fp->name 'cause
add2windows() may shift the entries in files[] around thereby making
fp->name point to the wrong file */
add2windows(todir,fn,fp); /* add to new window(s) */
delfromwins(dirp,fn); /* del from old window(s) */
} else /* error, unable to rename/move this file */
show_error(SHOW_DOS,0,3,"Unable to move ",fn,": ");
free(target); /* must be tough on malloc & friends */
free(todir);
free(fnp);
}
}
/******************************************************************************
L O G I N
*****************************************************************************/
login() { /* login to another directory */
char *new_dir, *todir;
new_dir = prompt(NULL,"Login to which drive/directory? ",NULL,0,MAX_REPLY);
/* if they give a relative dir spec and showall is in effect, we want
the relative dir spec to be relative to the current file's dir, not
the current dir */
if (strlen(todir = new_dir)) {
if (cw.showall && cw.curidx < cw.nfiles)
parsepath(files[cw.curidx].dirp,"",new_dir,1,&todir,NULL);
switch_dir(todir);
if (todir != new_dir) /* free mem if parsepath called */
free(todir);
}
}
/******************************************************************************
** S W I T C H _ D I R **
*****************************************************************************/
switch_dir(dir) /* change the current directory */
char *dir;
{
int rc;
register DRIVE_ENT *dp;
if ((rc = change_dir(dir)) == 0) { /* dir switched okay? */
if (cw.showall) /* turn off showall mode if it was */
showoff(); /* in effect in this window */
getcwd(cw.dirbuf,MAX_PATHLEN); /* get the current dir name */
initdrive(*cw.dirbuf); /* (re)init DRIVE_ENT for this drive */
getfiles(); /* load the files[] structure */
adjust_window(); /* resize window data */
update_header(); /* update the header */
update_window(1); /* and the window data */
} else { /* can't switch, tell user */
show_error(SHOW_DOS,0,3,"Can't change to ",dir,": ");
}
return(rc);
}
/*****************************************************************************
I N I T D R I V E
*****************************************************************************/
initdrive(drive) /* initialize DRIVE_ENT for 'drive' */
int drive;
{
register DRIVE_ENT *dp;
dp = findrive(*cw.dirbuf); /* get DRIVE_ENT address 4 drive */
cw.drivep = dp; /* keep address in window block */
get_set_vol(dp->volbuf,NULL); /* get the new volume name */
getvolsiz(*cw.dirbuf,&dp->vol_size, /* and the volume size stats */
&dp->vol_free,&dp->clustersiz);/* incase they are different */
}
/******************************************************************************
F I N D R I V E
*****************************************************************************/
DRIVE_ENT *
findrive(drive) /* find or allocate a DRIVE_ENT for drive */
int drive;
{
register DRIVE_ENT *dp, *ldp = NULL;
dp = drvlst; /* try to find the DRIVE_ENT in the */
while (dp != NULL) { /* linked list of DRIVE_ENTs */
if (dp->drive == drive)
break;
ldp = dp;
dp = dp->next;
}
if (dp == NULL) { /* allocate a new DRIVE_ENT */
dp = (DRIVE_ENT *) Malloc(sizeof(DRIVE_ENT));
dp->next = NULL;
dp->drive = drive;
if (ldp)
ldp->next = dp;
else
drvlst = dp;
}
return(dp);
}
/*****************************************************************************
F I N D I R
*****************************************************************************/
char *
findir(dir) /* find a dirlst entry that matches dir */
char *dir;
{
register int i;
register char **dp;
for (dp = dirlst, i = diridx; i; i--, dp++)
if (strcmp(dir,*dp) == 0)
return(*dp);
return(""); /* better never happen! */
}
/******************************************************************************
** S E T _ V O L **
*****************************************************************************/
set_vol() { /* set the volume label */
char *label;
label = prompt("Set volume label","Enter new volume label: ",NULL,0,11);
if (strlen(label) == 0)
return;
get_set_vol(cw.drivep->volbuf,label); /* one call to set it */
get_set_vol(cw.drivep->volbuf,NULL); /* another to see what comes back */
gotorc(VOL_ROW,1); /* display volume label */
out_str(cw.drivep->volbuf,11,' ');
}
/*****************************************************************************
M A T C H _ N A M E
*****************************************************************************/
match_name(np,pp) /* determine if file name matched pattern */
register char *np, *pp;
{
/* Why you might ask is this code like this, well..., I have plans to port
this code to a system that has file names up to 79 characters long, and
I thought this type of code would be easier to port than something that
knew MS-DOS names are 8+3 */
while (*np) {
if (*np == *pp) /* name char match pattern? */
goto match;
else
if (*np == '.') { /* watch to switches to the */
while (*pp == '*' || *pp == '?') /* extension, the pattern */
pp++; /* must have one also */
if (*pp != '.')
return(0); /* no pattern ext, no match */
goto match;
} else
if (*pp == '*') { /* allow wildcards */
np++; /* NOTE: doesn't advance the */
continue; /* pattern pointer */
} else
if (*pp == '?')
goto match;
else
return(0); /* don't match, not wild */
match:
np++; /* chars match, advance */
pp++;
}
/* the name string matched so far, make sure the pattern only has
wildcards left (if anything) */
while (*pp)
if (*pp != '*' && *pp != '?' && *pp != '.')
return(0);
else
pp++;
return(1); /* A MATCH! */
}
/*****************************************************************************
P A C K F I L E S
*****************************************************************************/
packfiles() { /* pack the files structure */
FILE_ENT *endp;
register FILE_ENT *p, *q;
p = q = files;
endp = &files[cw.nfiles];
while (q < endp)
if (*p->name) {
if (p == q)
p = ++q;
else
p++;
} else
if (*q->name == '\0')
q++;
else {
*p++ = *q;
*q->name = '\0';
q++;
}
cw.nfiles = p - files; /* new # of files in files[] */
}
/*****************************************************************************
F N A M E
*****************************************************************************/
char * ALTCALL
fname(fp) /* return the address of a file name */
register FILE_ENT *fp;
{
return(dirplus(fp,fp->name)); /* maybe this routine is too simple */
}
/*****************************************************************************
D I R P L U S
*****************************************************************************/
char *
dirplus(fp,pp) /* return a string which is the files dir + whatever */
register FILE_ENT *fp;
char *pp;
{
register char *dp;
if (cw.showall) {
dp = (char *) Malloc(strlen(fp->dirp)+strlen(pp)+2);
strcpy(dp,fp->dirp);
if (dp[strlen(dp)-1] != '\\')
strcat(dp,"\\");
strcat(dp,pp);
return(dp);
} else
return(Strdup(pp));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -