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

📄 support.c

📁 一个dos操作系统DRDOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
skipinc:
	    ;
	}			/* loop till end of while */	

	*dest='\0';		/* add terminator to dest */
}


/*.pa*/
/*
 *	Read a character from the console. The ABORT flag determines
 *	whether a ^C will abort the command or be treated as a negative
 *	reponse. DEF determines the default value that yes() will use.
 *
 */

EXTERN BYTE FAR * CDECL farptr(BYTE *);

#define	YES_CHAR	(*farptr(YES_NO+0))
#define	NO_CHAR		(*farptr(YES_NO+1))

GLOBAL BOOLEAN yes(abort, def)
BOOLEAN abort, def;
{
BYTE	yn;

#if defined(CDOSTMP)
	yn = (BYTE) bdos(C_RAWIO, 0xFD);	/* Input a character and */
	if(abort && yn == 0x03)			/* check for Control-C   */
	    int_break();
#else
	yn = (BYTE) msdos((abort ? MS_C_NOECHO : MS_C_RAWIN), NULL);	 
#endif						/* read the response	*/
	if(yn >= ' ')				/* If its printable then*/
	    putc(yn);				/* display the charcter */
	crlf(); 				/* new line		*/
	if(def) 				/* Now using the correct*/
	    return((yn & 0xdf) != NO_CHAR);	/* default value return */
	else					/* process the users	*/
	    return((yn & 0xdf) == YES_CHAR);	/* input and return.	*/
}

/*
 *	ONOFF scans the command line for [=](ON|OFF) and returns
 *	YES, NO or FAILURE 
 */
GLOBAL WORD onoff(cmd)
BYTE *cmd;
{

	cmd = deblank(cmd);			/* Deblank the string and    */
	if (*cmd == '=')			/* remove optional '='	     */
	    cmd = deblank(cmd+1);

	sprintf(heap(), "%s", MSG_ON);		/* Check for ON		    */
	if(!strnicmp(cmd, heap(), strlen(heap())))
	    if (*(deblank (cmd + strlen(heap()))) == 0)	/* end of line?	    */
		return YES;

	sprintf(heap(), "%s", MSG_OFF);		/* Check for OFF	    */
	if(!strnicmp(cmd, heap(), strlen(heap())))
	    if (*(deblank (cmd + strlen(heap()))) == 0)	/* end of line?	    */
		return NO;

	return FAILURE;
}

GLOBAL VOID syntax()
{
	eprintf(MSG_SYNTAX);
	crlfflg = YES;
}

GLOBAL VOID crlf()
{
	printf("\n");
}

GLOBAL VOID putc(c)
BYTE	c;
{
	printf("%c", c);
}


GLOBAL VOID puts(s)
BYTE	*s;
{
	printf("%s",s);
}


GLOBAL VOID c_write(s, l)
BYTE	*s;
UWORD	 l;
{
	ms_x_write (err_flag ? STDERR : STDOUT, s, l);
}


GLOBAL WORD e_check(ret)
REG WORD    ret;
{
REG BYTE   *s;

    if (ret >= 0)			/* if no error code */
	return ret; 			/* it's O.K. */

    if (ret == ED_GENFAIL) ret = extended_error();

    crlfflg = YES;			/* Force a CR LF after the error    */

    switch (ret)
    {
	case ED_ROOM:	  /* Force ED_ROOM to return File Not Found msg */
	case ED_FILE:	  s = ERR02;	break;	/* File Not Found Error	*/
	case -1:
	case ED_PATH:	  s = ERR03;	break;	/* Path Not Found	*/
	case ED_HANDLE:	  s = ERR04;	break;	/* Too many Open Files	*/
	case ED_ACCESS:	  s = ERR05;	break;	/* Access denied	*/
	case ED_MEMORY:	  s = ERR08;	break;	/* Insufficient Memory	*/
	case ED_ENVIRON:  s = MSG_ENVERR;break;	/* Invalid Environment	*/
	case ED_DRIVE:	  s = ERR15;	break;	/* Invalid Drive Spec	*/
	case ED_PROTECT:  s = ERR19;	break;	/* Write Protect Disk	*/
	case ED_SHAREFAIL:s = ERR20;	break;	/* Sharing Conflict	*/
	default:
	    if(ret==ED_FAIL)
	 		 {s = ERR83;	break;} /* Physical Media - FAILED */
	    if(ret==ED_PASSWORD)
			 {s = ERR86;	break;}	/* Invalid Password	*/
#if defined(CDOS) || defined(CDOSTMP)
	    if(ret==(-255))
	    		 {s = ERR_RSC;	break;}	/* Resource is not Available */
#endif
	    if (ED_NET >= ret && ret > ED_NETPWD)
		      {s = MSG_NETWORK;	break;}	/* Network Error	*/

	    s = MSG_INTERNAL; break;		/* Internal Error	*/
    }

    eprintf(s, 0-ret);
    eprintf("\n");
    return ret;
}

#if 0
MLOCAL BYTE *err_tab[] =  { NULLPTR,	/* 01 - Invalid Function Code	*/
			    err02,	/* 02 - File Not Found Error	*/
			    err03,	/* 03 - Path Not Found		*/
			    err04,	/* 04 - Too many Open Files	*/
			    err05,	/* 05 - Access denied		*/
			    NULLPTR,	/* 06 - Invalid Handle		*/
			    NULLPTR,	/* 07 - Invalid Memory Cntl Blk */
			    err08,	/* 08 - Insufficient Memory	*/
			    NULLPTR,	/* 09 - Invalid Memory Cntl Blk */
			    msg_enverr, /* 10 - Invalid Environment	*/
			    NULLPTR,	/* 11 - Invalid Format		*/
			    NULLPTR,	/* 12 - Invalid Access Code	*/
			    NULLPTR,	/* 13 - Invalid Data		*/
			    NULLPTR,	/* 14 - Unused Error Code	*/
			    err15,	/* 15 - Invalid Drive Spec	*/
			    err20,	/* 20 - Sharing Conflict	*/
			    err83,	/* 83 - Physical Media - FAILED */
			    err86,	/* 86 - Invalid Password	*/
			    err_rsc};	/* Resource is not Available	*/

GLOBAL WORD e_check(ret)
REG WORD    ret;
{
REG WORD    error;			/* Local copy of the error code */

	if (ret >= 0)			/* if no error code */
	    return ret; 		/* it's O.K. */

	crlfflg = YES;			/* Force a CR LF after the error    */
	error = ret;			/* message has been displayed	    */
	if(error == ED_ROOM) 		/* Force ED_ROOM to return File Not */
	    error = ED_FILE;		/* found message.		    */

	if(error < ED_DRIVE) {		/* Check for error codes which have */
	    if(error == ED_SHAREFAIL)	/* been remapped so save space	    */
		error = (-16);

	    if(error == ED_FAIL)	/* Check for FAIL		    */
	        error = (-17);

	    if(error == ED_PASSWORD)	/* Password Error		    */
	        error = (-18);
	}

	error = -error;
	if(error <= sizeof(err_tab)/sizeof(BYTE *) && err_tab[error-1])
	    eprintf(err_tab[error-1]);
	else
	    eprintf("Internal Error Code %03d", error);

	return ret;
}
#endif

GLOBAL BOOLEAN UNC(char *path) {
	if (*path == '\\' && path[1] == '\\') return TRUE;
	if (!*(path++) || !*(path++)) return FALSE;
	while (*path) if (*(path++) == ':') return TRUE;
	return FALSE;
}


GLOBAL BYTE * d_check(path)
REG BYTE *path;
{

	ddrive = -1;				/* return -1 for UNC names  */
	if (UNC(path)) return(path);
	ddrive = drive;				/* if no drive is specified */
	if(!*path || path[1] != ':')		/* then DDRIVE is set to    */
	    return(path);			/* the default drive.	    */

	ddrive = toupper(path[0]) - 'A';	/* Otherwise the requested  */
	path += 2;				/* drive is selected and    */
						/* range checked	    */
	if(ddrive == drive)			/* If the requested drive is*/
	    return(path); 			/* the default drive is OK. */

/*
 *	If TRUE the D_CHECK only range checks the selected drive and
 *	returns a pointer to the next element of the path. If FALSE
 *	the drive is phyically selected.
 */
#if TRUE
	if(!INVALID_DRV(ddrive))
	    return(path);
#else
	if(!INVALID_DRV(ddrive) && ms_drv_set(ddrive) == ddrive) {
	    ms_drv_set(drive);			/* Restore Original Drive   */
	    return(path);			/* and return Path	    */
	}
#endif
	e_check(ED_DRIVE);			/* Print an error message   */
	return (NULL);				/* and return a NULLPTR	    */
}


GLOBAL BOOLEAN f_check(cmd, fchars, farray, ignore)
REG BYTE *cmd;
BYTE	 *fchars;
UWORD	 *farray;
BOOLEAN  ignore;		/* Ignore Illegal Options */
{
	BYTE 	*s, *flg_start;
	BOOLEAN	 flg_skip, flg_error;
	BYTE	 c;

	*farray = 0;		/* assume none of the flags present */

	while(*cmd) {
	    if(*cmd++ != *switchar)
	        continue;

	    flg_start = cmd - 1;		/* Save switchar offset	    */
	    flg_skip = FALSE;			/* No Chars skipped	    */
	    flg_error = TRUE;			/* Assume first char is bad */
	    FOREVER {
	        c = tolower(*cmd);		/* Scan the string till the */
		if(!((c>='a' && c<='z')||(c>='0' && c<='9')))
		    break;			/* first non-alpha character*/

		if((s=(BYTE *)strchr(fchars, c))) {/* check each char against  */
		    *farray |= 1 << (s-fchars); /* options string passed by */
		    strcpy(cmd, cmd+1); 	/* the calling routine.	    */
		    flg_error = FALSE;		/* Reset error flag and set */
		}				/* correct flag bit.	    */
		else {
		    flg_skip = flg_error = TRUE;/* On error set flg_skip and*/
		    if(!ignore)			/* break out of the loop if */
		        break;			/* ignore is FALSE.	    */
		    cmd++;
		}
	    }

	    if(!flg_skip)			/* If all characters have    */
	        *flg_start = ' ';		/* been used then remove '/' */

	    if(flg_error && !ignore) {		/* If an invalid char and    */
		eprintf(MSG_BADOPT, *switchar, c); /* ignore is FALSE then    */
		crlfflg = YES;			/* print the error message   */
		return FAILURE;
	    }
	}
	return SUCCESS;
}


GLOBAL BOOLEAN nofiles(path, attrib, exist, append_stardotstar)
REG BYTE *path; 		/* Search Path		*/
WORD	 attrib;		/* Search Attributes	*/
BOOLEAN  exist; 		/* Must files exist	*/
BOOLEAN  append_stardotstar;
{
	REG BYTE *cp;
	DTA	search;
	WORD	ret;

	if ((cp = d_check (path)) == NULLPTR)	/* if bad drive letter */
	    return FAILURE;			/*    don't do it */

	if (!*fptr(cp)) {			/* If only a path has been */
	    strcat(cp, d_slash_stardotstar+3);	/* specified expand to *.* */
	}
	else if(!iswild (cp))			/* else is it path or file? */
	{					/* wild cards imply files */
	    ret = ms_x_first(path, ATTR_ALL, &search);	/* get attributes */

	    if(ret == ED_ROOM)
	        ret = ED_FILE;

	    if (ret < 0)			/* if any errors	     */
		if(!exist && (ret == ED_FILE || ret == ED_PATH)) {
						/* If file does not exist and*/
						/* this is NOT an error...   */
		    if (append_stardotstar) {
		        append_slash(path);	/* "DIR .." on NOVELL drives */
		        strcat(path, d_slash_stardotstar+3);
					   	/* requires that we append   */
						/* "*.*" here                */
		    }
		    return SUCCESS;		/* return OK.                */
		}
		else {
		    e_check (ret);		/* otherwise print message   */
		    return FAILURE;		/* no files found	     */
		}

	    if (search.fattr & ATTR_DIR) {	/* if path names directory   */
		append_slash(path); 		/* make it all files in it   */
		strcat(path, d_slash_stardotstar+3);
	    }
	    
	    if(!exist)				/* Must we check the file(s) */
		return SUCCESS; 		/* exist. If no return	     */
	}

	ret = ms_x_first(path, attrib, &search);  /* Search for the file     */

	if(ret < 0)				/* Check the error returned  */
	    if(!exist && (ret==ED_FILE || ret==ED_ROOM)) /* If file does not exist but*/
		return SUCCESS; 		/* this is not an error then */
	    else {				/* return Ok.		     */
		e_check (ret);			/* otherwise print message   */
		return FAILURE; 		/* no files found	     */
	    }

	return SUCCESS;
}

/*
 *	Check if FILENAME can be opened in Read Only mode and return the
 *	result. The file is then closed
 */
GLOBAL BOOLEAN file_exist(filename)
BYTE *filename;
{
BYTE filebuf[MAX_PATHLEN];
WORD h;

	get_filename(filebuf, filename, NO);
	if((h = ms_x_open(filebuf, OPEN_READ)) > 0) {
	    ms_x_close(h);
	    return TRUE;
	}

	return FALSE;	     
}

/*
 *	Check if the handle passed to this routine is open on a FILE
 *	or a DEVICE.
 */
GLOBAL BOOLEAN isdev(handle)
UWORD handle;
{
	return (0x0080 & ms_x_ioctl(handle) ? TRUE : FALSE);
}

/*
 *	If the string that has been passed doesn't end with a '\' add one
 */
GLOBAL	append_slash(s)
BYTE	*s;
{
BYTE	lastchar;
    while (*s) {
    	lastchar = *s;
	if (dbcs_lead(*s))		/* is this first of a DBCS pair? */
	    s++;
	s++;
    }
    if ((lastchar != '\\') && (lastchar != '/'))
	strcat(s, pathchar);		/* append a slash */
}


GLOBAL	VOID prompt_exec()
{
	BYTE	temp[128];
	
	if (!env_scan("PEXEC=",temp)) docmd(temp,TRUE);
}

GLOBAL	VOID optional_line(line)
BYTE	*line;
{
	BYTE	c;
	BYTE	*s;	

	if (*line == 13 || *line == 10 || *line == 0) return;

	if (*line == '?') strcpy(line,line+1);

	if (*line == '\"') {
	    s = line+1;
	    while (*s && *s != '\"') putc(*s++);	    
	    s++;
	    strcpy(line,s);
	}
	else printf(MSG_OPTLINE,line);
	
	if (!yes(NO,NO)) *line = 0;

	/*printf("\n");*/
	
}

⌨️ 快捷键说明

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