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

📄 com.c

📁 一个dos操作系统DRDOS的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	    eprintf(MSG_BADOS);			/* and quit if it is not 5.0 */
	    ms_x_exit(-1);			/* or Above		     */
	}
#endif

#if defined(DOSPLUS)

	batchptr_off = (VOID *) &batch;
	batchflg_off = (VOID *) &batchflg;
	echoflg_off  = (VOID *) &echoflg;

	envsize = get_original_envsize();	/* BAP - sets envsize to */
						/* same as original COMMAND */
	if ((envsize < 128) || (envsize > 32752)) envsize = 256; /* shouldn't really need this */

	parent_psp = MK_FP(_psp, 0x16);		/* our parental PSP is here  */
	ret = ioctl_ver();			/* Get the BDOS Version No.  */

	if(ret < 0x1071) {			/* Abort if this is not DOS  */
	    eprintf(MSG_BADOS);			/* PLUS with a BDOS version  */
	    if ((*parent_psp) && (*parent_psp != _psp))
		ms_x_exit(-1);			/* abort unless root process */
	    while(1){};
	}

#if 0
#if defined(DLS)
	dls_msg_crit();				/* init crit error messages  */
#endif
#endif

#endif

#if defined(CDOSTMP)
	console = (UBYTE) bdos(C_GET, 0) + 1;	/* CDOS Console No. + 1	    */
	execed = NO;				/* COMMAND.RSP not EXECED    */
	err_ret = 0;				/* Initial Error Code 0000   */

#else
	execed = YES;				/* Assume we have been loaded*/
						/* from the command line     */
	break_flag = ms_set_break(NO);		/* Get the Current Break Flag*/
	err_ret = ms_x_wait();			/* Get the completion code   */
						/* for process's that cause  */
						/* COMMAND.COM to be reloaded*/

	init_switchar();			/* initialise switchar and   */
						/* pathchar		     */
#endif

	drive = ms_drv_get();	 		/* get default drive.	     */
	country.code = ms_s_country(&country);	/* Initialise the Country data*/
	in_handle = psp_poke(STDIN, 0xFF);	/* Get the standard input    */
	psp_poke(STDIN, in_handle);		/* and save internally	     */

	out_handle = psp_poke(STDOUT, 0xFF);	/* Get the standard Output   */
	psp_poke(STDOUT, out_handle);		/* and save internally	     */

	for(ret=5;ret<20;ms_x_close(ret++));	/* close handles 5-20	     */

	if(initflg)				/* is this a warm boot?	     */
	    return;				/* Yes then QUIT	     */

	initflg = YES;				/* there's only one 1st time */
	cflag = 0;				/* Clear the switch variable */

#if !defined(CDOSTMP)
	/*
	 *
	 *	COMMAND.COM
	 *	The following command line formats must be supported for
	 *	applications that exec the command processor.
	 *
	 *	COMMAND /CCOPY filex filey	FrameWork Install
	 *	COMMAND /C DIR *.* /P		Procomm directory option
	 *	COMMAND /C=DIR *.*
	 *
	 *	These varients prevent support for multiple options and
	 *	force the option scanning to be halted at the first command
	 *
	 *	COMMAND /T - TSR support for CDOS
	 *
	 *	We are auto-invoking COMMAND after detecting a TSR, so
	 *	try and inherit any open batch files.
	 *
	 */

	s = (BYTE *) heap_get(128); /* allocate some heap memory */

	FOREVER {
	    cmd = deblank(cmd);			/* Deblank the command line  */
	    if((*cmd == '\0') || (*cmd == *switchar))
		break;				/* stop at option or end     */

	    cmd = get_filename(s, cmd, NO);

	    if(strlen(s)) {			/* look for Loadpath/STDIO */
		if((ret = ms_x_open(s, OPEN_RW)) >= 0) {
		    if(isdev(ret)) {
			strcat(kbdptr,"ctty ");	/* if its a R/W device put */
			strcat(kbdptr, s);	/* CTTY <dev> into buffer  */
			strcat(kbdptr,"!");
		    }
		    else			/* otherwise its an error  */
			eprintf(MSG_LOADPATH);	/*  an invalid loadpath    */
		    ms_x_close(ret);		/* Close the handle */
		}
		else {
		    append_slash(s);		/* user specified loadpath   */
		    get_reload_file();		/* get reload_file on heap   */
		    strcat(s, fptr(heap()));
		    if(file_exist(s)) {		/* append existing load file */
		    	ms_x_expand(heap(), s);
		    	set_reload_file();	/* copy heap to reload_file  */
		    }
		    else {			/* Print an error message if */
			eprintf(MSG_LOADPATH);	/* an invalid path used.     */
			lferror = 1;
			break;
		    }
		}
	    }
	    else {
	        eprintf(MSG_LOADPATH);
		break;
	    }
	}

	heap_set(s);	/* free up heap memory */

	c_option = FALSE;
	k_option = FALSE;
	FOREVER {
	    cmd = deblank(cmd);			/* Deblank the command line  */
	    if(*cmd != *switchar)		/* Stop the option check if  */
		break;				/* the next character is not */
	    cmd++;				/* a switch character.	     */
	    c = toupper(*cmd++);
	    switch(c) {
/*RG-05-*/
#if (defined(CDOS)||defined(DOSPLUS)) && !defined(NOHELP)
  		case 'H':			/* Support /H Help Option	     */
		case '?':			/* Support /? Help Option	     */
		    cflag |= 2;
                    cmd_ver();
                    crlf();
                    printf(HELP_COM);
		    ms_x_exit(0);
		    break;
#endif
/*RG-05-end*/
		case 'C':			/* Support /C Option	     */
		    echoflg  = ECHO_OFF;	/* Don't issue CR LF	     */
		    c_option = TRUE;
		case 'K':
		    k_option = TRUE;
		    cmd = deblank(cmd);
		    if (*cmd == '=') {
		    	cmd++;			/* Skip optional '='         */
		        cmd = deblank(cmd);
		    }
		    
		    cflag |= 2;
		    break;

		case 'N':
			n_option = TRUE;
			break;

		case 'P':			/* Support /P Option	     */
		    cflag |= 1;
		    if (*cmd == ':') {		/* See if a different fname  */
		    	cmd++;			/* has been specified for    */
			ret = 0;		/* AUTOEXEC.BAT.             */
		    	while ((*cmd > 32) && (ret < 12))
				autoexec_name[ret++] = *cmd++;
		    	autoexec_name[ret] = 0;
			while (*cmd > 32) cmd++;
		    }
		    break;

		case 'E':			/* Environment Option */
		    if(*cmd != ':')		/* Check for /E:nnn   */
		        break;
		    cmd++;	
		    if(getdigit(&ret, &cmd) && ret > 128 && ret < 32752)
		        envsize = ret;
		    break;

#if defined(CDOS)
		case 'T':			/* TSR support */
		    cflag |= 5;
		    inherit_TMP_state();	/* inherit batch files etc */
		    break;
#endif

#if defined(DOSPLUS)
		case 'T':
		    inherit_parent_state();
		    break;
#endif


#if defined(DOSPLUS)
		case 'M':			/* relocate resident portion */
		    c = toupper(*cmd++);
		    if (c == 'H') prh_function = 1;
		    if (c == 'U') prh_function = 2;
		    if (c == 'L') prh_function = -1;
		    break;

		case 'D':
		    no_timedate = TRUE;
		    break;
#endif

		case '\0':			/* Treat the NULL character */
		    cmd--;			/* specially in case some of*/
		    break;			/* the following command "/"*/

		default:			/* Skip invalid options.    */
		    break;
	    }
	}
#if defined(DOSPLUS)
/* We cannot allow COMMAND to go into upper memory unless "/P" has also */
/* been given. If we do the memory won't be freed up on exit */

	switch(prh_function) {
  		case 0:	/* try high, upper, then low */
			if(COMMAND_P)
				put_resident_high(0);
			else
				put_resident_high(1);
			break;
		case 1:	/* try high, then low */
			put_resident_high(1);
			break;
		case 2:	/* try upper, then low */
			if(COMMAND_P)
				put_resident_high(2);
			break;
		default:/* try low */
			break;
	}
#endif

	master_env(envsize);			/* Allocate the master 	     */
						/* environment of ENVSIZE    */
						/* bytes in length	     */
#if 0
	/*
	 *	If no COMSPEC has been defined or it is different from
	 *	the RELOAD_FILE specification then update COMSPEC.
	 */
	if(env_scan(msg_comspec, heap()) || stricmp(heap(), reload_file)) {
	    sprintf(buf, "%s%s", msg_comspec, reload_file);
	    cmd_set(buf);
	}
#else
	/* BAP changed this */
	get_reload_file();
	if(env_scan(msg_comspec,heap())) {
	    sprintf(buf,"%s%s",msg_comspec,heap());
	    cmd_set(buf);
	}
#endif

#if defined(DOSPLUS)
	save_parent = *parent_psp;
	*parent_psp = _psp;			/* Always do this */

	    if(COMMAND_P) {			/* Action the /P flag for   */
		execed = NO;			/* DOSPLUS.COM		    */

		PATH_DIR[0] = drive + 'A';	/* if DRDOS directory exists */
		ret = ms_x_chmod(PATH_DIR, ATTR_ALL, 0);
		if ((ret > 0) && (ret & 0x10)) {/* point the path at it */
			sprintf(buf, SET_PATH, PATH_DIR);
			cmd_set(buf);
		}
		cmd_set(SET_PROMPT);
		cmd_set(SET_OS);
		cmd_set(SET_VER);
#if !defined(FINAL)
		cmd_set(SET_BETA);
#endif
	        install_perm();			/* Install Backdoor entry    */
	    }

	/* process the environment created by config.sys */
	process_config_env();
#endif

#endif

	FOREVER {
	    if(execed) {	/* If this is a transient  */
		if (!lferror)
		    strcat(kbdptr, cmd);	/* command processor then  */
		ret = FALSE;			/* get the command line and*/
		break;				/* ignore AUTOEXEC.BAT.	   */
	    }

	    /* Check for the presence of STARTnnn.BAT in the root   */
	    /* of the boot disk if not found check for AUTOEXEC	    */
	    /* if neither are present then if this is console 0	    */
	    /* and this is < 1987 ask for the date. 		    */

#if defined(CDOSTMP) 
            vc_data(&vc_base, &vc_num, &pc_num);	/* Get VC Data	    */
	    vc_num = console - vc_base;			/* Relative VC Num  */
	    sprintf(heap(), "!start%02d%1d.bat", pc_num, vc_num);
	    if((ret = file_exist(heap()+1)) == 0) {
	        strcpy(heap(), "!autoexec.bat");
		ret = file_exist(heap()+1);
	    }

	    if(ret != 0) { 	
		strcat(kbdptr, heap());
		sprintf(heap(), " %d %d %d", console, pc_num, vc_num);
		strcat(kbdptr, heap());
		break;
	    }

#else
	    strcpy(heap(), "!");
	    strcat(heap(), autoexec_name);
	    if((ret = file_exist(heap()+1)) != 0) {
		if (boot_key_scan_code != 0x3f00 /*F5*/)
		    strcat(kbdptr,heap());
		break;
	    } else {
		boot_key_scan_code = 0;
	    }
#endif	

#if defined(DOSPLUS)
	    if (!no_timedate && *autoexec_name!=0)
	        strcat(kbdptr, "!date!time");
#else
	    ms_getdate(&date);
	    if(console == 1 && date.year < 1987)
		strcat(kbdptr, "!date!time");
#endif
	    break;
	}
#if defined(CDOS) && !defined(CPM)
	    if(COMMAND_P)			/* Action the /P flag for   */
		execed = NO;			/* CDOS.COM to disable EXIT */
#endif

#if 0
	if(COMMAND_C) {				/* Append EXIT if COMMAND.COM*/
	    strcat(kbdptr, "!exit 0");		/* is just used to execute a */
	}					/* a command.		     */
#endif

#if !defined(CDOSTMP)
#if 0
	else { 
#else
	if(!COMMAND_C) {
#endif
#if defined(DOSPLUS)
	    if (*autoexec_name != 0) {
	        cmd_ver();			/* display the signon	     */
		
 	        printf(MSG_OEMCPYRT);
	        crlf();
		    }
#else
	    if(!COMMAND_T) {			/* if it's CDOS TSR support  */
		cmd_ver();			/* don't display signon      */
		crlf();
	    }
#endif

	}
#endif
}

/*
 *	The following function is called to clean up COMMAND.COM after 
 *	an internal or external command has been executed. The major areas
 *	to be handled by this function are:-
 *
 *	1)	Control-C termination for Batch file termination
 *	2)	I/O Redirection
 *	3)	Hiloading off
 */
MLOCAL VOID cmd_cleanup()
{
BYTE	cmdbuf[128];
#if 0
	hiload_set(NO);				/* HILOADing off now */
#endif
	
	if(err_ret == BREAK_EXIT ||		/* Check for Control-C	     */
	    err_ret == ERROR_EXIT) {		/* or Critical Error Exit    */

	    if(pipe_out) {			/* If a Pipe'ed command is   */	
		pipe_out = NO;			/* is aborted then absorb    */
		getcmd(cmdbuf);			/* the second command.	     */
		crlf();
	    }

	    if(batchflg) {
		eprintf(MSG_BATTERM);		/* Processing a BATCH file   */
		err_flag = TRUE;		/* ask if the uses wishes to */
		if(yes(NO, YES))		/* to abort this batch job   */
		    batch_endall();		/* Close ALL batch files     */
		err_flag = FALSE;
	    }
	    else if(for_flag)			/* If processing a FOR	     */
		for_end();			/* command outside a batch   */
	}					/* file then abort it.	     */

	err_ret &= 0x00FF;			/* Mask the Termination      */
						/* condition this should only*/
						/* be tested once.	     */

		/*
		 * After the termination of a Batch file or a Program then
		 * the relevant redirection is removed. If the redirection
		 * was instigated because of the PIPE facility then the
		 * correct clean up code is executed.
		 */

	while(in_flag & REDIR_ACTIVE) { /* Is Redirection Active     */
	    if((in_flag & REDIR_BATCH) && batchflg)
		break;

	    if((in_flag & REDIR_FOR) && for_flag)
		break;

	    ms_x_close(STDIN); 			/* Close the Redirected File */
	    psp_poke(STDIN, in_handle);		/* Restore original Handle   */
	    
	    if(pipe_in) {
		pipe_in = NO;
		ms_x_unlink(old_pipe);
		heap_set(old_pipe);
	    }

	    in_flag = NULL;
	}

	while(out_flag & REDIR_ACTIVE) {	/* Is Redirection Active     */
	    if((out_flag & REDIR_BATCH) && batchflg)
		break;

	    if((out_flag & REDIR_FOR) && for_flag)
		break;

	    ms_x_close(STDOUT);			/* Close the Redirected File */
	    psp_poke(STDOUT, out_handle);	/* Restore original Handle   */

	    if(pipe_out) {

⌨️ 快捷键说明

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