📄 ovdir.c
字号:
while ((dp = dp->parent) && dp != &root) {
(*bp)++; /* tell caller # levels backed up */
if (dp->sibling)
return(dp->sibling);
}
return(NULL); /* no more dir ents to be found */
}
/******************************************************************************
D I R _ M O V E
*****************************************************************************/
dir_move(move_cmd) /* move the directory pointer around */
int move_cmd;
{
int moved = TO_NONE;
int redisplayed = FALSE;
register struct dir_ent *last_dir, *cdp;
last_dir = cdp = curdir; /* remember where we are/were and fast ptr */
switch (move_cmd) {
case RIGHT:
if (cdp->subdir) {
cdp = cdp->subdir;
moved = TO_SUBDIR;
} else
if (cdp->sibling) {
cdp = cdp->sibling;
moved = TO_SIBLING;
}
/* stuff about parents goes here */
break;
case LEFT:
if (cdp->prev_sib) {
cdp = cdp->prev_sib;
moved = TO_SIBLING;
} else
if (cdp->parent) {
cdp = cdp->parent;
moved = TO_PARENT;
}
break;
case UP:
if (cdp->prev_sib) {
cdp = cdp->prev_sib;
moved = TO_SIBLING;
}
break;
case DOWN:
if (cdp->sibling) {
cdp = cdp->sibling;
moved = TO_SIBLING;
}
break;
case HOME:
cdp = &root;
moved = TO_ROOT;
break;
case GOPAR:
if (cdp->parent) {
cdp = cdp->parent;
moved = TO_PARENT;
}
break;
}
curdir = cdp; /* assign it */
/* adjust and redisplay the pathname as the user moves the dir pointer */
if (moved != TO_NONE)
update_dirpath(moved);
/* display a different section of dir tree if current isn't displayed */
if (adj_dir_dis()) { /* is adjustment needed? */
dir_distree(); /* display the tree */
redisplayed = TRUE; /* save a disp_dir_name() call */
}
/* deselect the last dir if the dir pointer moved and the last one
is still on the screen and the entire tree wasn't redisplayed */
if (!redisplayed && last_dir != curdir &&
dir_on_screen(last_dir->row,last_dir->col))
disp_dir_name(last_dir,last_dir == logdir ? DIS_TAGD : DIS_NORM);
/* select (highlight) a new dir entry if pointer moved and the tree
wasn't redisplayed */
if (last_dir != curdir && !redisplayed) {
disp_dir_name(curdir,DIS_HIGH);
}
}
/******************************************************************************
** D I R _ L O G I N **
*****************************************************************************/
dir_login() { /* login the dir selected by the dir pointer */
/* switch to selected dir, if can't switch, user may have changed
disks, force a scan of the disk for dirs */
if (switch_dir(dirpath) != 0) /* switch to the selected dir */
last_drive = ' ';
dir_exit(); /* exit the dir display mode */
}
/******************************************************************************
** D I R _ R M D I R **
*****************************************************************************/
dir_rmdir() { /* remove the dir selected by the dir pointer */
int moveto;
register struct dir_ent *cdp;
cdp = curdir; /* try to reduce code size */
/* don't even let user try to delete the root or current directories */
if (cdp->col == 0 || strcmp(dirpath,cw.dirbuf) == 0)
show_error(0,CANT_RMDIR,3,"You can't delete the ",(cdp->col == 0) ? "root" :
"current"," directory!");
/* use DOS to acutally remove the directory */
if (rmdir(dirpath) != 0)
show_error(SHOW_DOS,CANT_RMDIR,1,"Unable to remove dir: ");
/* Okay, the dir is gone, now remove it from the dir tree */
if (cdp->prev_sib) /* make prev sib -> */
cdp->prev_sib->sibling = cdp->sibling; /* next sib */
if (cdp->sibling) { /* next sib -> */
cdp->sibling->prev_sib = cdp->prev_sib; /* prev sib && */
if (cdp->parent->subdir == cdp) /* parent -> */
cdp->parent->subdir = cdp->sibling; /* next sib */
}
if (cdp->prev_sib == NULL && cdp->sibling == NULL) /* parent has no */
cdp->parent->subdir = NULL; /* more sub's */
/* when deleting a subdirectory, try to make a sibling the current dir,
if none, go back to parent */
if (cdp->sibling) {
curdir = cdp->sibling;
moveto = TO_SIBLING;
} else
if (cdp->prev_sib) {
curdir = cdp->prev_sib;
moveto = TO_SIBLING;
} else {
curdir = cdp->parent;
moveto = TO_PARENT;
}
update_vol_stats(); /* should be more free space now */
update_dirpath(moveto); /* show user what the dir pathname is */
free((char *)cdp); /* release mem used by the dir entry */
dir_mark(); /* reassign row/column values for remaining dir's */
adj_dir_dis(); /* make sure the current dir will display */
dir_distree(); /* redisplay updated dir tree */
}
/******************************************************************************
** D I R _ M K D I R **
*****************************************************************************/
dir_mkdir() { /* make a subdirectory in the selected dir */
int rc;
char *name, *dirend;
register struct dir_ent *ndp, *ldp;
/* ask user what to call the new directory */
name = strupr(prompt(NULL,"Enter the new subdirectory name: ",NULL,0,12));
if (strlen(name) == 0)
return;
/* update dirpath to include the users new name */
dirend = dirpath + strlen(dirpath); /* remember current dirpath end */
if (*(dirend-1) != '\\')
strcat(dirend,"\\");
strcat(dirend,name); /* add users dir name */
/* use DOS to acutally make the directory */
rc = mkdir(dirpath); /* create it */
*dirend = '\0'; /* fixup dirpath */
if (rc != 0)
show_error(SHOW_DOS,CANT_MKDIR,1,"Unable to make dir: ");
/* Okay, the dir is created, now make a dir_ent and add it to the dir tree */
ndp = (struct dir_ent *) Malloc(sizeof(struct dir_ent));
strcpy(ndp->name,name);
ndp->subdir = NULL;
ndp->sibling = NULL;
ndp->parent = curdir;
if (ldp = curdir->subdir) { /* any sibs to new dir? */
while (ldp->sibling) /* find end of sib list */
ldp = ldp->sibling;
ndp->prev_sib = ldp; /* new one is last */
ldp->sibling = ndp;
} else {
ndp->prev_sib = NULL; /* no sibs */
curdir->subdir = ndp; /* parent now has subdir */
}
update_vol_stats(); /* less free space now */
dir_mark(); /* assign new row/col values */
dir_distree(); /* redisplay dir tree */
}
/******************************************************************************
** U P D A T E _ D I R P A T H **
*****************************************************************************/
static int
update_dirpath(moved) /* update & redisplay dir path */
int moved;
{
char *cp;
switch (moved) {
case TO_SUBDIR: /* moved to a subdir */
if (curdir->col != 1) /* append a \ if parent wasn't root */
strcat(dirpath,"\\");
strcat(dirpath,curdir->name); /* append the subdirectory name */
break;
case TO_SIBLING: /* moved to a sibling */
*(strrchr(dirpath,'\\')+1) = '\0';
strcat(dirpath,curdir->name);
break;
case TO_PARENT: /* moved to parent */
cp = strrchr(dirpath,'\\');
if (curdir->col == 0)
++cp;
*cp = '\0';
break;
case TO_ROOT: /* moved to the root */
dirpath[3] = '\0';
break;
}
gotorc(VOL_ROW,PATH_COL+1);
out_str(dirpath,65,' ');
}
/*****************************************************************************
A D J _ D I R _ D I S
*****************************************************************************/
adj_dir_dis() { /* make sure current dir ent will be on screen */
register int r, c;
/* adjust bounds and redisplay dir tree if the current entry is not
displayed */
r = curdir->row; c = curdir->col; /* cutout a level of indirection */
if (!dir_on_screen(r,c)) {
if (r >= drend) /* current below display? */
drbase = r - NAME_ROWS + 1;
else
if (r < drbase) /* current above display? */
drbase = r;
if (c >= dcend) /* current right of display? */
dcbase = c - DCOLS + 1;
else
if (c < dcbase) /* current left of display? */
dcbase = c;
drend = drbase + NAME_ROWS; /* reset display end markers */
dcend = dcbase + DCOLS;
return(1); /* tell caller to redisplay */
}
return(0); /* no adjustment needed */
}
/*****************************************************************************
F I N D I R
*****************************************************************************/
static struct dir_ent *
findir() { /* find the current dir_ent */
register char *lcp;
char *cp = cw.dirbuf+3;
char dirname[MAX_NAMELEN+2];
register struct dir_ent *dp = &root;
*dirpath = '\0';
strncat(dirpath,cw.dirbuf,3); /* roots better be the same */
while (strcmp(dirpath,cw.dirbuf) != 0) { /* have we found it yet? */
/* haven't found it yet, go down another dir level, also do some
protective error checks, I don't feel real secure 'bout this yet */
if (dp == NULL || (dp = dp->subdir) == NULL || (lcp = cp) == NULL)
return(&root); /* shouldn't happen, but... */
if (cp = strchr(cp+1,'\\')) { /* isolate the next dir level */
*dirname = '\0'; /* in cw.dirbuf */
strncat(dirname,lcp,cp-lcp);
} else
strcpy(dirname,lcp); /* this must be the last level */
strcat(dirpath,dirname); /* add dir name to full path */
if (*(lcp = dirname) == '\\') /* 1st doesn't have leading \ */
lcp++; /* others do */
/* check all siblings at this level until we find it (or run out?) */
while (dp && strcmp(lcp,dp->name) != 0)
dp = dp->sibling;
}
return(dp); /* this should be the one */
}
/*****************************************************************************
D I R _ O N _ S C R E E N
*****************************************************************************/
static int
dir_on_screen(r,c) /* determine if dir name is displayed */
register int r, c;
{
return(r >= drbase && r < drend && c >= dcbase && c < dcend);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -