📄 popdos.c
字号:
/* =====================================================
*
* POPDOS.C - Pops a directory from the directory stack.
*
*
*
* Copyright(c): Martti Ylikoski. 1992
*
* Programmer: Martti Ylikoski
* Created: 3.3.1992
* Version: 1.0
*
* ====================================================== */
#include <stdio.h>
#include <string.h>
#include "list.h"
static char *progname ;
static char *deffile = "C:\\dirserv.dat" ;
int main(int argc, char * argv[])
{
HNDLIST *lhandle ;
int i, actioncode, popid, found ;
char * buf, fbuff[125], *tmp ;
unsigned long buflen ;
FILE *fp ;
progname = argv[0] ;
popid = 1 ;
if ( (tmp = getenv("DIRSERV")) != NULL)
deffile = tmp ;
if (argc == 2 && (strcmpi(argv[1], "-q") == 0
|| strcmpi(argv[1], "/q") == 0))
{
unlink (deffile) ;
printf("Directory stack server removed. \n") ;
return( 0 ) ;
}
if (argc == 2)
popid = atoi(argv[1]) ;
if ((lhandle = ListInit()) == NULL)
{
printf("Error in ListInit\nExit\n") ;
return( 1 ) ;
}
if ((fp = fopen (deffile, "r")) == NULL)
{
// printf("%s : error opening file %s.\nExit\n", progname, deffile) ;
printf("No directory stack - stay in current directory \n") ;
return( 0 ) ; /* no file = empty stack */
}
while (fgets(fbuff, sizeof(fbuff), fp ) != NULL)
{
ListAdd(lhandle, fbuff, strlen(fbuff)+1) ; /* +1 because we store also \0 */
}
fclose (fp) ;
i = 1 ;
if (ListLast(lhandle)!= LIST_OK) /* empty list */
return( 0 ) ;
found = 0 ;
while ( ListReturn(lhandle, &buf, &buflen) == LIST_OK)
{
if ( i == popid)
{
printf("Found %s", buf) ;
buf[strlen(buf)-1] = '\0' ; /* mask \n away */
if (_chdrive(buf[0]-'A'+1)== -1)
{
printf("Error setting new drive \nExit\n") ;
return( 1 ) ;
}
if (chdir(&buf[2]) != 0)
{
printf("Error setting new directory \nExit\n") ;
return( 1 ) ;
}
found = 1 ;
ListDel(lhandle) ; /* remove the current entry */
}
i++ ;
if ( ListPrior(lhandle) == LIST_ERR_BEG_LIST)
break ;
}
if (found == 1) /* we found a directory, we must update the stack file */
{
if ((fp = fopen (deffile, "w")) == NULL)
{
printf("%s : error opening file %s.\nExit\n", progname, deffile) ;
return( 1 ) ;
}
if (ListFirst(lhandle) != LIST_OK)
{
fclose(fp) ;
unlink(deffile) ;
return( 0 ) ;
}
do
{
ListReturn(lhandle, &buf, &buflen) ;
fputs(buf, fp) ;
} while (ListNext(lhandle) != LIST_ERR_END_LIST) ;
fclose (fp) ;
}
return( 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -