⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comint.c

📁 一个dos操作系统DRDOS的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	    				/* Otherwise ignore the command     */

#if	defined(CPM)			/* Clean-Up the CPM disk handling   */
	    cpm_de_init();		/* code before we terminate.	    */
#endif
	    restore_error_mode();
	    restore_term_addr();	/* restore the PSP terminate address*/
	    ms_x_exit(err_ret);		/* If we return from the EXIT call  */
	    execed = NO;		/* then this must be the root	    */
	    printf("Hello\n");
	}				/* process. Invoked without '/P'    */
#endif
}


GLOBAL VOID CDECL cmd_md(s)
REG BYTE *s;
{
	/*BYTE	 path[MAX_FILELEN];*/

	crlfflg = YES;
#if 0
	get_filename(path, deblank(s), FALSE);	/* Pathname  */

	if(!d_check(path))
	    return;
#endif
	if((ret = ms_x_mkdir(s)) != 0) {	/* if any errors occurred    */
	    if (ret == ED_DRIVE)		/* if invalid drive	     */
		e_check(ret);			/*    then say so	     */
	    else				/* else use standard formula */
		eprintf(MSG_MKDIR);		/* Unable to create directory*/
	    return;
	}

	crlfflg = NO;
}


/*.pa*/
/*
 *	PATH [[d:]path[[;[d:]path]..]] | [;]
 *
 *	Display or set the command search path in environment.
 */
GLOBAL BYTE msg_patheq [] = "PATH=";	/* Static Environment String   */

GLOBAL VOID CDECL cmd_path(path)
REG BYTE *path;
{
	REG BYTE *s;
#if !STACK
	BYTE	 sbuf[MAX_ENVLEN];
#endif

	zap_spaces(path);		/* Remove all white space	    */
	if(!*path) {
	    if(env_scan(msg_patheq, s = (BYTE *)heap()))
		printf(MSG_PATH);		/* If no path exists then    */
	    else {				/* display "NO PATH" otherwise */
		printf(msg_patheq);		/* display the current path  */
		/*printf("%.122s\n",s);*/
		printf(path_template,s);
	    }
	    crlfflg = YES;
	    return;
	}

	if(*path == '=' || *path == ';')/* Skip Leading '=' or ';' chars    */
	    path++;			/* then set the PATH		    */

#if STACK
	s = stack(strlen(msg_patheq) + strlen(path) + 1);
#else
	s = &sbuf[0];
#endif
	strcpy(s, msg_patheq);		/* build command line for "SET"   */
	strcat(s, strupr(path));
	cmd_set(s); 			/* set new path using "SET"	    */
}

GLOBAL VOID CDECL cmd_pause(msg)
BYTE	*msg;
{
BYTE	c;

	if (*msg) printf("%s\n",msg);

	batch_close();			/* Close Any Batch files in case */
					/* the user is going to swap the */
					/* disk with the batch file.	 */
	printf(MSG_PAUSE);		/* prompt to hit any key	*/

#if defined(CDOSTMP)
	c =(BYTE) bdos(C_RAWIO, 0xFD);	/* Get a character from console */

	if ((c==0) ||(dbcs_lead(c)))
	    bdos(C_RAWIO, 0xFD);	/* skip second byte in DBCS pair */
#else
	c = (BYTE) msdos(MS_C_RAWIN, 0);/* Get a character from console */
	if ((c==0) || (dbcs_lead(c)))
	    msdos(MS_C_RAWIN, 0);	/* skip second byte in DBCS pair */
#endif

	sprintf(heap(), "%s", MSG_PAUSE);	/* Copy MSG_PAUSE into  */
	printf("\r%*s\r", strlen(heap()), "");  /* Data Segment and 	*/
						/* then calculate length*/

	if(c == 0x03)			/* Control C Check		*/
	    int_break();
}

/*
 *	This PAUSE command will output the prompt string to STDOUT regardless
 *	of its destination. However it will ensure that the character is read
 *	from the console device by "POKING" the PSP.
 */
GLOBAL VOID CDECL cmd_stdin_pause(void)
{
UWORD	in_h,stderr_h;
BYTE	c;

	batch_close();			/* Close Any Batch files in case */
					/* the user is going to swap the */
					/* disk with the batch file.	 */
	printf(MSG_PAUSE);		/* prompt to hit any key	*/

	stderr_h = psp_poke(STDERR,1);
	in_h = psp_poke(STDIN, stderr_h); /* Get the Real Console		*/
	psp_poke(STDERR,stderr_h);

#if defined(CDOSTMP)
	c =(BYTE) bdos(C_RAWIO, 0xFD);	/* Get a character from console */

	if ((c==0) ||(dbcs_lead(c)))
	    bdos(C_RAWIO, 0xFD);	/* skip second byte in DBCS pair */
#else
	c = (BYTE) msdos(MS_C_RAWIN, 0);/* Get a character from console */
	if ((c==0) || (dbcs_lead(c)))
	    msdos(MS_C_RAWIN, 0);	/* skip second byte in DBCS pair */
#endif

	psp_poke(STDIN, in_h);		/* restore original handle 	*/

	sprintf(heap(), "%s", MSG_PAUSE);	/* Copy MSG_PAUSE into  */
	printf("\r%*s\r", strlen(heap()), "");  /* Data Segment and 	*/
						/* then calculate length*/

	if(c == 0x03)			/* Control C Check		*/
	    int_break();
}

#if !defined(NOXBATCH) && (defined(CDOS) || defined(CDOSTMP))
/*
 *	The PAUSE command will output the prompt string to STDOUT regardless
 *	of its destination. However it will ensure that the character is read
 *	from the console device by "POKING" the PSP.
 */
GLOBAL VOID CDECL cmd_pauseerr()
{
        BOOLEAN  err_save;

        err_save=err_flag;
	err_flag = TRUE;
        cmd_pause();
	err_flag = err_save;
}
#endif
/*RG-02-end*/

/*.pa*/
/*
 *	PROMPT [prompt-text]
 *
 *	Set the system prompt as specified by the prompt text if no 
 *	prompt text is specified then the default $n$g is used.
 */
GLOBAL BYTE msg_prmeq  [] = "PROMPT=";	/* Static Environment String */

GLOBAL VOID CDECL cmd_prompt(s)
REG BYTE    *s;
{
	REG BYTE *bp;
#if !STACK
	BYTE	 bpbuf[MAX_ENVLEN];
#endif

	if (!*s)			/* if no string */
	    s = DEFAULT_PROMPT; 	/* use the default */

	while ((*s == '=') || (*s == ' ')) s++;

#if STACK
	bp = stack(strlen(msg_prmeq) + strlen(s) + 1);
#else
	bp = &bpbuf[0];
#endif
	strcpy(bp, msg_prmeq);		/* environment variable */
	strcat(bp, s);			/* add new value */
	cmd_set(bp);			/* update environment */
}


GLOBAL VOID CDECL cmd_rem ()
{
	crlfflg = 0;
/* Make sure REM turns off pipes too */
/* You can't do this !!!!! MSDOS allows "REM | DIR" etc - IJ */
#if 0
	pipe_in=pipe_out=NO;
#endif
}



#define	REN_CHECK	(flags & 1)

GLOBAL VOID CDECL cmd_ren(s)
REG BYTE *s;
{
	BYTE	 srcfile[MAX_FILELEN], dstfile[MAX_FILELEN];
	BYTE	 pattern[MAX_FILELEN-MAX_PATHLEN];  
	BYTE	 *enddir;
#if defined(PASSWORD)
	BYTE	*password;
#endif
	DTA	 search;
	UWORD	flags;
	WORD	attr;
#if !STACK
	BYTE	passbuf[MAX_FILELEN];
#endif
        char lastchar;
        unsigned length;

	if(f_check(s, "c", &flags, NO))		/* Check the selected flags */
	    return;				/* and return on error	    */

	s = get_filename(srcfile, deblank(s), TRUE);	/* Source Filename  */

	s = get_filename(dstfile, deblank(s), TRUE);	/* Destination File */

	length = strlen(dstfile);
	lastchar = dstfile[ length-1];
        
	if (dbcs_expected()){
	 if ( (length > 2) && (!dbcs_lead(dstfile[length-2])) ){
/*
		if ( (lastchar == ':') || (lastchar == '\\') ){
*/
		if (lastchar == ':'){
		printf(msg_invalid_file);
		return;
		}
	 }
	}
	else{
/*
	if ( (lastchar == ':') || (lastchar == '\\') ){
*/
	if (lastchar == ':'){
		printf(msg_invalid_file);
		return;
	    }
	}

	if (!iswild(srcfile)) {
	    attr = ms_x_chmod(srcfile,0,0);
	    if ((attr > 0) && (attr & ATTR_DIR)) {

		/* Don't try to rename directories. Leave it to RENDIR. */

		printf(MSG_USE_RENDIR);
		return;
	    }
	}

	if(nofiles(srcfile, ATTR_ALL, YES, NO))	/* if no source files then  */
	    return;				/* error message and stop   */

	if(nofiles(dstfile, ATTR_ALL, NO, NO))	/* Check the Destination    */
	    return;				/* path exists		    */

	if(fptr(srcfile) != srcfile && fptr(dstfile) == dstfile) {
	    strcpy(heap(), dstfile);		/* If no path is specified  */
	    strip_path(srcfile, dstfile);	/* on the NewFile then force*/
	    strcat(dstfile, heap());		/* use the OldFile Path.    */
						/* Because of the Holy Grail*/
	}					/* of MS-DOS compatiblity.  */

	enddir = fptr(srcfile); 		/* Isolate source filename  */
#if defined(PASSWORD)
	password = strchr(enddir, *pwdchar);	/* Check for Source password*/
	if(password) {				/* and save in internal buf.*/
#if STACK
	    password = stack(strlen(password)+1);
#else
	    password = &passbuf[0];
#endif
	    strcpy(password, strchr(enddir, *pwdchar));
	}
#endif

	strcpy(pattern, fptr(dstfile)); 	/* Save the destination	    */
						/* match pattern.	    */

	ms_x_first (srcfile, (ATTR_STD&(~ATTR_SYS)), &search);
	do {
	    strcpy(enddir, search.fname);	/* append file name to path */

	    if(REN_CHECK) {			/* confirm option active?   */
		printf(MSG_ERAQ, srcfile);	/* then prompt the user and */
		if(!yes(YES, NO))		/* act on the reponse	    */
		    continue;
	    }

	    strcpy(fptr(dstfile), pattern);	/* Assert the Destination   */
	    repwild(srcfile, dstfile);		/* pattern.		    */

#if defined(PASSWORD)
	    if(password)			/* Append the password to   */
		strcat(srcfile, password);	/* the sorce file if one    */
						/* has been specified.	    */
#endif

	    if((ret = ms_x_rename(srcfile, dstfile)) < 0) {
		crlfflg = YES;
#if defined(CDOSTMP) || defined(CDOS)
		if((ret == ED_ACCESS) &&
		   (ms_x_first(dstfile, ATTR_ALL, &search) >= 0))
#else
		if(ret == ED_ACCESS)
#endif
		    eprintf(MSG_REN);
		else
		    e_check(ret);
		return;
	    }
	} while(!ms_x_next(&search));		/* get the next file */
}


/*.pa*/
/*
 *
 */
GLOBAL VOID CDECL cmd_rd(s)
REG BYTE *s;
{
	/*BYTE	 path[MAX_FILELEN];*/

	crlfflg = YES;
#if 0
	get_filename(path, deblank(s), FALSE);	/* Pathname  */

	if(!d_check(path))
	    return;
#endif
	if((ret = ms_x_rmdir(s)) != 0) {	/* if can't remove directory */
	    if(ret == ED_DIR || ret == ED_FILE || ret == ED_ACCESS)
	    					/* because its in use by     */	
		eprintf(MSG_RMDIR);		/* by another process or is  */
	    else				/* empty then print special  */
		e_check(ret);			/* message other wise use    */
	    return;				/* standard error handler    */
	}

	crlfflg = NO;
}


GLOBAL VOID CDECL cmd_set(s)
BYTE *s;
{
	BYTE	 c;
	REG BYTE *key;
	BYTE	*t;
	WORD	 i;

	if(!*s) {				/* if no cmd, display env */
	    for(i=0; !env_entry(key = (BYTE *)heap(), i); i++) {
	        puts(key);			/* Print the Environment   */	
		crlf();				/* variables directly to   */
	    }					/* avoid size problems.	   */
	    return;
	}
					/* else need to set env var */

	/* msdos removes leading blanks, commas, semicolons and equal signs,
	but keeps spaces in the variable name (SPR 770044) JBM */

/*	remove any spaces before the equals sign
	key = s;
	while (*s && (*s != '=')) {
		if (*s == 32 || *s == 9) {
			t = s;
			while (*t++) *(t-1) = *t;
		}
		if (*s == '=') break;
		s++;
	}
*/
	key = s;
	while (*s && (*s == 0x20 || *s == 0x09 || *s == ',' || *s == ';' || *s == '=')) {
		t = s;
		while (*t++) *(t-1) = *t;
	}

	s = key;
	while (*s && (*s != '='))	/* look for end of variable */
	    s ++;

	if (!*s || key == s) {		/* If no key has been specified */
	    syntax();			/* or the '=' is missing return */
	    return;
	}				/* a syntax error.		*/
	
	s++;

#if 0
	/* msdos doesn't do this */

	/* remove any space after the equals sign */
	while (*s == 32 || *s == 9) {
		t = s;
		while (*t++) *(t-1) = *t;
	}
#endif

	c = *s;				/* Save Character		*/
	*s = '\0';			/* terminate keyword		*/
	strupr (key);			/* make keyword upper case	 */
	if(env_del(key) < 0) {		/* remove it first		*/
	    printf(MSG_ENVERR); 	/* check for an error.		*/
	    crlfflg = YES;
	    return;
	}
	if((*s-- = c) != 0) {		/* Add the definition to the end*/
					/* of the environment if the new*/
	    if(env_ins(key)) {		/* definition is not NULL	*/
		printf(MSG_ENVFULL);	/* check for an error.		*/
		crlfflg = YES;
		return;
	    }
	}
}


/*.pa*/
/*
 *	Displays or Sets the current system time 
 */
#define	TIME_CON	(flags & 1)

GLOBAL VOID CDECL cmd_time(s)
REG BYTE *s;
{
	BYTE	buffer[18];			/* Local Input Buffer */
	UWORD	flags;				/* Continuous Display	*/

	if(f_check (s, "c", &flags, NO))	/* Check for valid Flags    */
	    return;

	if(TIME_CON) {
	    crlfflg = YES;
	    printf(CUR_TIME);			/* Display the Message */ 

	    FOREVER {
		disp_systime ();		/* Display the Current Time  */
		printf("\b\b\b\b\b\b\b\b\b\b\b"); /* BackSpace over the Time */
#if defined(CDOSTMP)
		if(bdos(C_RAWIO, 0xFE)) 	/* check for a character     */
		    return;			/* and return if one typed   */
#else
		if(msdos(MS_C_STAT, 0) & 0xFF) { /*  Check for a character   */
		    msdos(MS_C_RAWIN, 0xFF);	 /* read it and return to the*/
		    return;			 /* main routine.	     */
		}
#endif
	    }
	}

	if(*s) {
	    if (check_time(s))
		return;
	    printf(INV_TIME);
	}
	else {
	    printf(CUR_TIME);
	    disp_systime ();
	}

	FOREVER {
	    printf (NEW_TIME);
	    buffer[0] = sizeof(buffer)-2;	/* Set maximum string length */
	    system(MS_C_READSTR, buffer);
	    crlf ();

	    if (!buffer[1])			/* Check for 0 length input */
		return; 			/* and return if so */

	    buffer[buffer[1]+2] = '\0';
	    if (check_time (buffer+2))
		return;

	    printf (INV_TIME);
	}
}

/*.pa*/
/*
 *
 */
GLOBAL VOID CDECL cmd_truename(s)
REG BYTE *s;
{
	BYTE	 path[MAX_FILELEN];

	*path = 0;

	/* expand path, current directory if none specified */
	if (*s)
		ret = ms_x_expand(path, s);
	else
		ret = ms_x_expand(path, ".");

	/* if we get an error report it, otherwise display expanded path */
	if (ret)
		e_check(ret);
	else
		printf(path);
}


/*
 *	Parse the string pointed to by s and check for a valid date
 *	specification. If the time has been specified correctly then
 *	set the system time.
 */
MLOCAL BYTE    hour_sep[] = ":.";
MLOCAL BYTE    sec_sep[]  = ".,";

MLOCAL BOOLEAN check_time(s)
BYTE *s;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -