📄 comint.c
字号:
#if defined(CDOS) || defined(CDOSTMP)
if(f_check(s, "db", &flags, NO)) /* Check for Flags if any are */
#else
if(f_check(s, "d", &flags, NO)) /* Check for Flags if any are */
#endif
return; /* invalid then don't do it */
s = deblank(strlwr(s)); /* Deblank after the Flag Check */
if(!*s) { /* If the command line is blank */
login = logical_drvs(); /* then display the assignments */
/* for all the logical drives */
for(drv = 0; drv < 26; drv++, login >>= 1)
if(login & 1L) {
sprintf(root,"%c:\\", drv+'A');
ms_x_expand(cp, root);
/*RG-03*/
#if !defined(NOXBATCH) && (defined(CDOS) || defined(CDOSTMP))
if(SUBST_BAT)
printf("SUBST %c: %s\n", drv + 'A',cp);
else
#endif
/*RG-03-end*/
printf("%c: => %s\n", drv + 'A',cp);
}
return;
}
if(*(s+1) == ':') { /* Check for a drive specifier */
ddrive = *s - 'a'; /* Get the drive letter and check */
s = deblank(s+2); /* that it is a valid drive and */
/* is not the LOAD Drive. */
if(INVALID_DRV(ddrive)) {
e_check(ED_DRIVE);
return;
}
}
else {
syntax(); /* If no drive is specified then */
return; /* return after displaying a */
} /* syntax error message */
#if defined(DOSPLUS)
if(network_drvs() & (1L << ddrive)) { /* if requested drive is */
eprintf(MSG_NETSUBST); /* remote then complain */
return; /* and don't do anything */
}
#endif
sprintf(cp, "%c:=", ddrive+'A'); /* Prepare CHDIR command */
if(!SUBST_DEL) { /* Check for the Delete Flag */
strcat(cp, s);
if((s = d_check(s)) == 0) /* Abort if an illegal drive */
return; /* is selected. */
if(!*s) { /* If no PATH is specified then */
printf(MSG_INOP); /* display display error message. */
return;
}
}
e_check(ms_x_chdir(cp)); /* Make the drive Assignment */
}
#endif
/*.pa*/
/*
* DATE [DD/MM/YY]
*
* Display or Set the current date making full use of the DOS
* international system call.
*/
GLOBAL VOID CDECL cmd_date(s)
BYTE *s;
{
BYTE buffer[18]; /* Local Input Buffer */
if (*s) {
if(check_date(s))
return;
printf (INV_DATE);
}
else {
printf (CUR_DATE);
disp_sysdate();
}
FOREVER {
printf (NEW_DATE, date_format(country.dt_fmt));
buffer[0] = sizeof(buffer) -2; /* Set maximum string length */
system(MS_C_READSTR, buffer);
crlf ();
if (buffer[1] == 0) /* Check for 0 length input */
return; /* and return if so */
buffer [buffer[1]+2] = '\0';
if (check_date (buffer+2))
return;
printf (INV_DATE);
}
}
MLOCAL BYTE * date_format(fmt)
UWORD fmt;
{
switch (fmt)
{
case 1: return EURO_DATE;
case 2: return JAP_DATE;
default: break;
}
return US_DATE;
}
/*
* Parse the string pointed to by s and check for a valid date
* specification. If the date has been specified correctly then
* set the system date.
*/
MLOCAL BYTE date_sep[] = "/.-";
MLOCAL BOOLEAN check_date(s)
BYTE *s;
{
SYSDATE date;
WORD p1, p2, p3; /* Input Parameters */
deblank(s); /* Remove spaces */
if (!getdigit (&p1, &s) ||
!strchr(date_sep, *s++) ||
!getdigit (&p2, &s) ||
!strchr(date_sep, *s++) ||
!getdigit (&p3, &s))
{
return NO;
}
switch (country.dt_fmt) {
case 1: /* European Format dd/mm/yy */
date.day = p1;
date.month = p2;
date.year = p3;
break;
case 2: /* Japanese Format yy/mm/dd */
date.day = p3;
date.month = p2;
date.year = p1;
break;
default: /* US Format mm/dd/yy */
date.day = p2;
date.month = p1;
date.year = p3;
break;
}
if (date.year >= 80 && date.year <= 99)
date.year += 1900;
return !ms_setdate(&date);
}
/*.pa*/
/*
* DEL [d:][path][filename][.ext]
*
* Erase a file(s) as specified by the path if no path is given
* erase all files on the default|specified drive.
*/
GLOBAL VOID CDECL cmd_del(path)
BYTE *path;
{
erase (path, NO); /* erase files, don't confirm */
}
#define DIR_DIR (0x0001) /* Display Directory Files */
#define DIR_SYS (0x0002) /* Display System Files */
#define DIR_ALL (0x0004) /* Display ALL Files */
#define DIR_WIDE (0x0008) /* Wide Directory Listing */
#define DIR_LONG (0x0010) /* Long Directory Listing */
#define DIR_PAGE (0x0020) /* Page Output */
#define DIR_REM (0x0040) /* Remember these Options */
#define DIR_CHANGE (0x0080) /* Change the Default Opts */
#define DIR_NOPAGE (0x0100) /* No Paging of Output */
#define DIR_2COLS (0x0200) /* double column listing */
#define OPT(x) (flags & x) /* Return Flag Conditions */
MLOCAL UWORD dir_default = DIR_DIR | DIR_LONG;
MLOCAL UWORD dir_flags(flags)
REG UWORD flags;
{
if(OPT(DIR_NOPAGE)) /* Force DIR_PAGE to be cleared */
flags &= ~DIR_PAGE; /* if NOPAGE has be selected */
if(OPT(DIR_LONG)) { /* Force DIR_WIDE to be cleared */
flags &= ~DIR_WIDE; /* if the LONG format has been */
flags &= ~DIR_2COLS; /* selected. */
}
if(OPT(DIR_2COLS)) {
flags &= ~DIR_LONG;
flags &= ~DIR_WIDE;
}
if(page_wid < 76) /* Check the screen is wide */
flags &= ~DIR_WIDE; /* enough to display directory */
if(page_wid < 78)
flags &= ~DIR_2COLS;
if(OPT(DIR_DIR))
flags &= ~DIR_SYS;
/* Check if the new options */
if(OPT((DIR_CHANGE|DIR_REM))) { /* should become the default */
dir_default = flags & ~(DIR_CHANGE|DIR_REM);
}
if (flags) return(flags);
else return(dir_default);
}
GLOBAL VOID CDECL cmd_dir (cmd)
REG BYTE *cmd;
{
WORD nfiles, system, others, i;
LONG nfree = 0L;
DTA search;
BYTE path[MAX_FILELEN];
BYTE s[MAX_PATHLEN], temp[3];
BYTE *ext, *memory;
UWORD free, secsiz, nclust;
UWORD flags;
if(f_check (cmd, "dsawlprcn2", &flags, NO)) /* if any bad flags */
return; /* don't do it */
flags = dir_flags(flags); /* Manipulate the flags to remove */
/* duplication and conflicts */
if(OPT(DIR_CHANGE)) /* Just change the default values */
return; /* then return to the caller */
get_filename(path, deblank(cmd), YES); /* Extract the filename */
if (path[0]=='.' && path[1]=='.' && path[2]=='.' && path[3]=='\0')
{
path[0]='*';
path[2]='\0';
}
if (d_check(path) == NULLPTR) return;/* get out now if invalid drive */
if (ddrive != -1)
{
strcpy(s,"d:"); s[0] = (BYTE) (ddrive + 'A');
append_slash(s);
ms_x_curdir(ddrive+1,s+3); /* get the current dir */
}
else
ms_x_expand(s,path);
ext = fptr(path);
if(*ext == '.' && strcmp(dotdot+1, ext) && strcmp(dotdot, ext)) {
strcpy(heap(), ext);
strcpy(ext, "*");
strcat(ext, heap());
}
#if defined(PASSWORD)
*(BYTE *)heap() = '\0'; /* Remove the Password */
memory = strchr(ext, *pwdchar); /* if one has been used */
if(memory) { /* and save on the heap */
strcpy(heap(), memory);
*memory = '\0';
}
#endif
while(*ext && !strchr(ext, '.')) { /* If a filename has been */
if(!iswild(ext)) { /* specified and it does not*/
#if defined(PASSWORD)
if (ddrive != -1 && ms_x_chdir(s) < 0) {
/* if cd to current dir fails then current dir must be password */
/* protected. So let's do the next bit the non-novell way. */
/* This method of determining if the user has specified a directory */
/* DOES NOT work on NOVELL drives. */
ret = ms_x_chmod(path, 0, 0); /* contain a '.'. Skip if */
if(ret > 0 && (ret & ATTR_DIR)) /* a path was specified. */
break; /* Otherwise append ".*". */
}
else {
#endif
/* This method of determining if the user has specified a directory */
/* DOES work on NOVELL drives. */
/* But not when the current directory is password protected! */
#if defined(PASSWORD)
if (memory) strcpy(memory,heap()); /* reattach password */
#endif
if (ddrive != -1)
{
ret = ms_x_chdir(path); /* try to cd to path specified */
#if defined(PASSWORD)
if (memory) *memory = 0; /* remove password again */
#endif
if (ret >= 0) { /* if there wasn't an error... */
ms_x_chdir(s); /* ...restore original directory... */
break; /* ...and get the hell out */
}
}
else
{
ret = ms_x_chmod(path,0,0);
if (ret >= 0 && (ret & ATTR_DIR)) break;
}
#if defined(PASSWORD)
}
#endif
}
strcat(ext, ".*"); /* append ".*" to pathname */
}
#if defined(PASSWORD)
strcat(ext, heap()); /* Reattach the Password */
#endif
if(nofiles(path, ATTR_ALL, NO, YES)) /* if no files/dirs or error*/
return; /* then we can't do this */
if (ddrive != -1)
{
strcpy (temp, "d:"); /* Display the drive Volume */
temp[0] = (BYTE) (ddrive+'A'); /* label using the VOL command */
cmd_vol(temp);
}
else
show_crlf(OPT(DIR_PAGE));
#if 0
/* this has been done earlier */
strcpy(s, "d:"); s[0] = (BYTE) (ddrive + 'A');
append_slash(s);
ms_x_curdir(ddrive+1, s+3); /* Get the current dir */
#endif
strip_path(path, memory = (BYTE *)heap());/* Get the Path Spec and */
if((i = strlen(memory)) > /* Remove the Trailing */
(memory[1] == ':' ? 3 : 1)) /* Path Character. */
memory[--i] = '\0';
if(i == 0 || (i == 2 && memory[1] == ':')) {
printf (MSG_DIR, temp, s+3); /* DIR of current Directory */
}
else
{
if (ddrive == -1 || ms_x_chdir(s) < 0) { /* assume this means pword protected */
ext = memory+strlen(memory)+1;
ms_x_expand(ext,memory);
if (ddrive != -1)
printf(MSG_DIR, temp, ext+3);
else
printf(MSG_DIR,"",ext+1);
}
else {
ms_x_chdir(memory); /* Change the directory */
ms_x_curdir(ddrive+1, memory); /* Get the current directory */
ms_x_chdir(s); /* Restore the directory */
printf (MSG_DIR, temp, memory);
}
}
others = 0; /* assume no SYS/DIR files */
nfiles = 0; /* initialize file count */
linesleft = page_len - 4; /* lines until pause */
system = OPT(DIR_SYS) ? ATTR_SYS : 0;
ret = ms_x_first(path, ATTR_ALL, &search);
if(!ret && (search.fattr & ATTR_DEV)) /* Check if the user has */
ret = ED_FILE; /* specified a device then */
/* generate an error. */
while(!ret) {
if(!OPT(DIR_ALL) && (search.fattr & ATTR_SYS) != system) {
/* not the correct file type*/
others++; /* remember others do exist */
ret = ms_x_next(&search); /* get the next file and */
continue; /* continue the display */
}
ext = strchr(search.fname, '.'); /* Get the file extension */
if(ext && ext != search.fname) /* set the extension to NULL*/
*ext++ = '\0'; /* if no '.' exists or this */
else /* is the ".." or "." entry.*/
ext = "";
if(OPT(DIR_WIDE)) {
if ((nfiles % 5) == 0)
show_crlf(OPT(DIR_PAGE));
printf ("%c:%c%-9s%-3s",
(nfiles % 5) ? ' ' : ddrive + 'A',
(search.fattr & ATTR_DIR) ? *pathchar : ' ',
search.fname, ext);
}
else {
if (OPT(DIR_2COLS)) {
if ((nfiles % 2) == 0) show_crlf(OPT(DIR_PAGE));
}
else
show_crlf(OPT(DIR_PAGE));
printf("%-9s%-3s", search.fname, ext);
if (search.fattr & ATTR_DIR)
printf(" <DIR> ");
else
printf ("%9lu", search.fsize);
if(search.fdate) { /* if timestamp exists */
printf (" "); disp_filedate (search.fdate);
printf (" "); disp_filetime (search.ftime);
if ((OPT(DIR_2COLS)) && (nfiles%2 == 0)) printf (" ");
}
else {
if ((OPT(DIR_2COLS)) && (nfiles%2 == 0)) printf("\t\t\t");
}
}
nfiles ++;
ret = ms_x_next(&search);
}
if(others + nfiles == 0) { /* If no matching files then exit */
e_check(ED_FILE); /* after displaying File Not Found */
}
if(ddrive != -1 && (ret = ms_drv_space(ddrive+1, &free, &secsiz, &nclust)) < 0) {
/*e_check(ED_PATH);*/
/*return;*/
ret = 0; /* This prevents 'Invalid directory...' when looking */
/* at a PNW login drive. */
}
show_crlf(OPT(DIR_PAGE));
nfree = (LONG)ret * (LONG)free * (LONG)secsiz;
if (ddrive != -1)
printf ("%9d %s%10ld %s", nfiles, MSG_FILES, nfree, MSG_FREE);
else
printf ("%9d %s", nfiles, MSG_FILES);
show_crlf(OPT(DIR_PAGE));
if(others) /* if others do exist, tell them */
printf (MSG_EXIST, system ? MSG_NSYS : MSG_NDIR);
}
GLOBAL VOID CDECL cmd_echo(s, o)
REG BYTE *s; /* Deblanked Command Line */
REG BYTE *o; /* Original Untainted Commmand */
{
if (*o) o++; /* delete 1 whitespace or */
/* punctuation char from the*/
/* original command line */
s = deblank(s);
switch(onoff(s)) { /* if "ECHO=on/off" */
case YES: /* ECHO = ON */
echoflg = ECHO_ON;
break;
case NO: /* ECHO = OFF */
echoflg = ECHO_OFF;
break;
default:
if(*s || (o != s && batchflg)) { /* if command line */
puts(o); /* display string */
crlf();
}
else
printf (MSG_ECHO, /* print current */
echoflg ? MSG_ON : MSG_OFF); /* echo status */
break;
}
}
#if !defined(NOXBATCH) && (defined(CDOS) || defined(CDOSTMP))
/*RG-02-*/
GLOBAL VOID CDECL cmd_echoerr(s, o)
REG BYTE *s; /* Deblanked Command Line */
REG BYTE *o; /* Original Untainted Commmand */
{
BOOLEAN err_save;
err_save=err_flag;
err_flag = TRUE;
cmd_echo(s,o);
err_flag = err_save;
}
#endif
/*RG-02-end*/
GLOBAL VOID CDECL cmd_exit(cmd)
BYTE *cmd;
{
err_ret = 0;
if(*deblank(cmd)) /* If a number has be */
check_num(cmd, 0, 255, &err_ret); /* specified use this for */
/* the exit code. */
if(batchflg) { /* If processing a batch file */
batch_end(); /* then exit batch file */
#if defined(CDOSTMP)
return;
#endif
}
#if defined(CDOSTMP)
bdos(C_DETACH, 0); /* Allow another process to attach */
bdos(P_DISPATCH, 0); /* to the console if they are */
bdos(C_ATTACH, 0); /* waiting in the background. */
#else
if(execed) { /* If command.com has been execed */
*parent_psp = save_parent;
ms_set_break(break_flag); /* then return to the invoking prog */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -