📄 jd.c
字号:
/*
* JD.C - Jump Directory. Move quickly to specified directory.
*
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 8.6.1991
* VERSION: 1.0
*
*/
//#undef MSDOS
#ifdef MSDOS
#include <dos.h>
#define TRUE 1
#define FALSE 0
#endif
#ifndef MSDOS
#define INCL_DOS
#define INCL_KBD
#include <os2.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <direct.h>
#include <errno.h>
#include <ctype.h>
/* TOOLS/2 defines */
#ifndef MSDOS
#include <monout.h>
#endif
#include <dirscan.h>
typedef struct {
char cmdopt[3] ;
int flag ;
} TABLE_ENTRY ;
#ifdef MSDOS
TABLE_ENTRY findflags[6] = {
"+H", _A_HIDDEN,
"+D", _A_SUBDIR,
"+S", _A_SYSTEM,
"+N", _A_NORMAL,
"+R", _A_RDONLY,
"+A", _A_ARCH
} ;
#endif
#ifndef MSDOS
TABLE_ENTRY findflags[6] = {
"+H", FILE_HIDDEN,
"+D", FILE_DIRECTORY,
"+S", FILE_SYSTEM,
"+N", FILE_NORMAL,
"+R", FILE_READONLY,
"+A", FILE_ARCHIVED
} ;
#endif
static char *dirspec ;
static char *progname ;
static char *dirs[20] ;
static int dcount = 0 ;
static char *command[100] ;
static int ccount = 0 ;
static char *files[100] ;
static int ffound = FALSE ;
static int no_default = FALSE ;
#ifdef MSDOS
unsigned findattr = _A_NORMAL ;
#endif
#ifndef MSDOS
static USHORT findattr = FILE_NORMAL ;
#endif
int JD_work( char *fname ) ;
/* local prototypes */
void out_ddir( char *fname) ;
int main(int argc, char *argv[])
{
int i, j, k, fcount ;
char *p ;
char curdir[80], buf[100] ;
#ifdef MSDOS
int ret ;
unsigned curdrive, numdrives ;
#endif
#ifndef MSDOS
USHORT ret ;
USHORT curdirlen ;
USHORT curdrive ;
ULONG tmp ;
#endif
int DownCnt = SC_RECURSIVE ;
int sc_flags = SC_BEFORESUBDIRS ;
progname = argv[0] ;
fcount = 0 ;
ccount = 0 ;
if (argc > 2 || argc == 2 && strcmpi(argv[1], "-?") == 0)
{
printf("usage: %s directory \n", progname) ;
return( 1 ) ;
}
puts("JD - Jump to a Directory. Copyright (C) Martti Ylikoski, 1990, 1991. Version 1.0") ;
puts("USAGE: JD directory\n") ;
if (argc == 1)
return( 1 ) ;
no_default = TRUE ;
/* Note! how to handle hidden directories ? */
#ifdef MSDOS
findattr |= _A_SUBDIR ;
#endif
#ifndef MSDOS
findattr |= FILE_DIRECTORY ;
#endif
if (fcount == 0)
{
fcount = 1 ;
files[0] = "*.*" ;
}
if (strlen(argv[1]) >=2 && argv[1][1] == ':')
{
#ifdef MSDOS
if (( ret = _dos_setdrive( (unsigned)toupper((int)argv[1][0]) -'A'+ 1, &numdrives)) != 0 )
#endif
#ifndef MSDOS
if (( ret = DosSelectDisk(toupper((int)argv[1][0]) -'A'+ 1)) != 0 )
#endif
{
fprintf(stderr,"%s cannot change to disk %c\n", progname, argv[1][0]) ;
fprintf(stderr, "Exiting...\n") ;
return( 1 ) ;
}
argv[1] += 2 ;
}
if (chdir(argv[1]) == 0)
{
#ifndef MSDOS
DosQCurDisk (&curdrive, &tmp) ;
curdirlen = sizeof(curdir) ;
DosQCurDir(curdrive, curdir, &curdirlen ) ;
buf[0] = 'A' + curdrive -1 ;
strcpy(&buf[1], ":\\") ;
strcat(buf,curdir) ;
#endif
// printf("Found dir %s\n", argv[1]) ;
#ifndef MSDOS
out_ddir(buf) ;
#endif
return( 0 ) ;
}
dirspec = argv[1] ;
if (( p = strrchr(argv[1], (int) '\\')) == NULL )
{
chdir("\\") ;
DirScan( fcount, &files[0], findattr, no_default, NULL, NULL, JD_work, DownCnt, sc_flags ) ;
}
else
{
char tmp[180] ;
strncpy(tmp, argv[1], (size_t) (strlen(argv[1])-strlen(p))) ;
if (chdir(tmp) != 0)
{
fprintf(stderr,"%s cannot change to dir %c\n", progname, tmp) ;
fprintf(stderr, "Exiting...\n") ;
return( 1 ) ;
}
dirspec = p + 1 ;
DirScan( fcount, &files[0], findattr, no_default, NULL, NULL, JD_work, DownCnt, sc_flags ) ;
}
if (ffound == FALSE)
puts("Directory not found.") ;
return( 0 ) ;
}
int JD_work( char *fname )
{
int i, len ;
char *p, *p1 ;
char sysbuf[256], *p2 ;
char t1[126], t2[126] ;
if (fname[strlen(fname)-1] == '.')
return( 0 ) ;
/* seach for basename */
if ((p = strrchr(fname, (int) '\\')) == NULL)
p = fname ;
else
p ++ ; /* past the last '\' char */
for (i = 0 ; i < strlen(p) ; i++)
t1[i] = toupper(p[i]) ;
t1[i] = '\0' ;
for(i = 0 ; i < strlen(dirspec); i++)
t2[i] = toupper(dirspec[i]) ;
t2[i] = '\0' ;
len = strlen(t2) ;
if ( strncmp(t1, t2, (size_t) len) == 0)
{
/* printf("Seaching for %s\n", dirspec) ; */
ffound = TRUE ;
out_ddir(fname) ;
return( 1 ) ;
}
else
return( 0 ) ;
}
void out_ddir( char *fname)
{
char bufdrive[3], buf[512] ;
#ifdef MSDOS
chdir(fname) ;
return ;
#endif
#ifndef MSDOS
if (strlen(fname) >= 2 && fname[1] == ':') /* drive information present */
{
bufdrive[0] = fname[0] ;
bufdrive[1] = fname[1] ;
bufdrive[2] = '\r' ;
MonPlayStr(bufdrive, MON_STR) ;
fname += 2 ; /* scan past the drive information */
}
strcpy(buf,"cd ") ;
strcat(buf, fname) ;
strcat(buf,"\r") ;
MonPlayStr(buf, MON_STR) ;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -