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

📄 comint.c

📁 一个dos操作系统DRDOS的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
{
	SYSTIME time;
	WORD	hour, min, sec, hsec;

	min = sec = hsec = 0;		/* Seconds and Hundredths are optional */
					/* and default to zero when omitted */
	zap_spaces(s);			/* Remove all spaces from command   */

	if (!getdigit (&hour, &s))
	    return NO;

	while(*s) {				/* if more than HH */
	    if (!strchr(hour_sep,*s)) return NO;	/* Check for Minute */
	    s++;
	    if (!getdigit (&min, &s)) return NO;

	    if (!*s) break;
	    
	    if (!strchr(hour_sep,*s)) break;	/* Check for Seconds */
	    s++;
	    if (!getdigit (&sec, &s)) break;

	    if (!*s) break;
	    
	    if (!strchr(sec_sep,*s)) break;
	    s++;
	    if (!getdigit (&hsec, &s)) break;

	    break;
	}
	
	if (*s) {
	    *s = toupper(*s);
	    if (*s == 'P' && hour != 12) hour += 12;
            if (*s == 'A' && hour == 12) hour = 0;
	}
	
	time.hour = hour;
	time.min  = min;
	time.sec  = sec;
	time.hsec = hsec;

	return !ms_settime(&time);
}

#define BUFSIZE 256		/* SHOW_FILE buffer size	*/

MLOCAL VOID show_crlf(paging)
BOOLEAN paging;
{
	crlf();
	if(paging && (--linesleft == 0)) {
	    cmd_pause("");
	    linesleft = page_len - 1;
	}
}

/*
 *	Read from channel h until the first Control-Z or the endof file
 *	has been reached. The display is paged if the PAGE_MODE flag is
 *	true otherwise the information is displayed continuous using
 *	the standard flow control.
 */
/*RG-00-make this one public*/
/* MLOCAL VOID show_file(h, paging) */
VOID show_file(h, paging)
/*RG-00-end*/
UWORD h;		/* Channel for File access */
BOOLEAN paging; 	/* Page Mode Flag	   */
{
	BYTE FAR *cp;			/* pointer to end of path	  */
	BYTE FAR *ptr;			/* temporary address for printing */
	BYTE FAR *buf;			/* Input Buffer 		  */
	UWORD bufsize;
	WORD	 n;
	/*BOOLEAN  lfflg = NO;*/	/* Last character a LineFeed	  */
	BOOLEAN  eof = FALSE;		/* End of File Flag		  */
	UWORD	scr_width;
	UWORD	nchars    = 0;
	UWORD	stderr_h,in_h;

	scr_width = get_scr_width();

	mem_alloc(&show_file_buf,&bufsize,BUFSIZE,BUFSIZE);
	buf = show_file_buf;
	
	while (!eof && (n = far_read (h, buf, BUFSIZE)) > 0) {

	    cp = ptr = buf;
	    while (n) { 			/* while more data	*/

		while (n &&			/* while more data	*/
		      (*cp != 0x1a) &&		/* and not EOF Char	*/
		      (*cp != '\n') &&		/* and Linefeed Char	*/
		      (nchars<scr_width)) {     
			if (*cp == 9) nchars = (nchars&-8)+7;
			n--; cp++; nchars++;	/* count chars, next	*/
		}

		if (cp != ptr) {		/* if any ordinary data */
		    far_write(STDOUT, ptr, (UWORD) (cp-ptr));
		    				/* write to CON:        */
		    ptr = cp;			/* flush the rest	*/
		    /*lfflg = NO;*/
		}

		if(n == 0)			/* if end of data	*/
		    break;

		if(*cp == 0x1a) {		/* If ^Z then set	*/
		    eof = TRUE; 		/* EOF flag to TRUE	*/
		    break;			/* and stop printing	*/
		}

		if (*cp == '\n') {		
		    ms_x_write(STDOUT,"\n",1);	/* Display a LF	*/
		    /*lfflg = YES;*/		/* Set the LineFeed Flag*/
		    n--;			/* count LF		*/
		    ptr = ++cp;			/* point past it	*/
		}

	        if(paging && (--linesleft == 0)) {

		    cmd_stdin_pause();

		    linesleft = page_len - 1;
		}
	        nchars = 0;
	    }
	}

	mem_free(&show_file_buf);
}

/*.pa*/
/*
 *
 */
#define	TYPE_PAGE	(flags & 1)

GLOBAL VOID CDECL cmd_type(cmd)
REG BYTE *cmd;
{
	WORD 	ret, h;			/* file handle			  */
	BYTE	path[MAX_FILELEN];	/* Path and File Name		  */
	BYTE	*files;			/* pointer to file spec 	  */
#if defined(PASSWORD)
	BYTE	*password;
#endif
	DTA	search; 		/* Local Search Buffer		  */
	UWORD	flags;			/* only one switch permitted	  */
	BOOLEAN wild_flag = FALSE;	/* Wild Card Type		  */
	BYTE	passbuf[MAX_FILELEN];

	if(f_check(cmd, "p", &flags, NO))       /* if any bad flags */
	    return;				/*    don't do it */

	get_filename(path, deblank(cmd), YES);	/* Extract the Filename     */

	if(d_check(path) == NULLPTR)		/* Check if the specified   */
	    return;				/* drive is valid	    */

	files = fptr(path);			/* isolate the filename     */
#if defined(PASSWORD)
	password = strchr(files, *pwdchar);	/* Check for Source password*/
	if(password) {				/* and save in internal buf.*/
	    strcpy(passbuf, password);
	    *password = 0;			/* discard path password */
	    password = &passbuf[0];		/* and use local copy */
	}
#endif

	if(iswild(files))
	    wild_flag = TRUE;

	linesleft = page_len - 1;		/* Initialize the paging     */
						/* variable used by SHOW_?   */

	/*
	 *	For wild card searches we must initialise search.fname
	 *	with an initial ms_x_first for the DO/WHILE loop.
	 */

	if (wild_flag) {
	    search.fattr = ATTR_STD;
	    ret = ms_x_first(path, ATTR_STD, &search);

	    if (ret < 0) {
	    	e_check(ret);		/* if we can't find anything */
		return;			/* we'd better say so */
	    }
	}

	do {
	    if (wild_flag)
		strcpy(files, search.fname);  	/* make it full pathname     */
	    strcpy(heap(), path);

#if defined(PASSWORD)
	    if(password)
	        strcat(heap(), password);
#endif

	    h = ms_x_open(heap(), OPEN_READ);	/* Open file in sharing mode */
	    if(h == ED_SHAREFAIL || h == ED_ACCESS)	/* if fails with a   */
	        h = ms_x_open(heap(), 0);	/* sharing violation then try*/
						/* opening with compatibilty */
	    if(h < 0) {				/* mode.		     */
		e_check(h);
		return;
	    }

	    if (wild_flag) {		/* if wild card type		*/
		strupr(path);		/* Display UpperCase Filename	*/
		show_crlf(TYPE_PAGE);	/* Print a CRLF with PAGING flag*/
		revon(); printf ("%s:", path); revoff();
		show_crlf(TYPE_PAGE);	/* Print a CRLF with PAGING flag*/
	    }

	    show_file(h, TYPE_PAGE);	/* Output the File to the Screen */
	    ms_x_close(h);		/* Close the File */
	} while (wild_flag && (ms_x_next(&search) >= 0));
}

/*
 *	Displays the data read from Channel 0 until the end of file or 
 *	Control-Z. If no output redirection is inforce then MORE pages
 *	the display using the CMD_PAUSE function.
 *
 *	MORE will only enable PAGING if the output device is the CONSOLE
 *	otherwise paging is disabled.
 */
GLOBAL VOID CDECL cmd_more()
{
	linesleft = page_len -1;		/* Set the Page length and */
	show_file(STDIN, YES);			/* display STDIN till EOF  */
						/* or a Control-Z	   */
}

/*.pa*/
/*
 *
 */
GLOBAL VOID CDECL cmd_ver()
{
	printf(MSG_VERSION, (env_scan("VER=", heap()) ? "" : heap()));
	printf(MSG_CPYRIGHT);
#if !defined(FINAL)
	if(!env_scan("BETA=", heap()))
	    printf("%s\n", heap());
#endif
}

GLOBAL VOID CDECL cmd_vol(path)
BYTE *path;
{
	BYTE	*s;
	BYTE	temp[7];
	DTA	search;
	WORD	ret,i;
	BYTE	label[12];
	
	strcpy(temp,d_slash_stardotstar);
	
	if ((path = d_check(path)) == 0)
	    return;
	if (ddrive == -1) return;

	temp[0] = (BYTE) (ddrive+'A');

	ret = ms_x_first(temp, ATTR_LBL, &search);
	if (ret == ED_DRIVE)
	    e_check(ret);		/* display error if invalid drive */
	else {	
	    printf(MSG_LBL, ddrive+'A');

	    if (ret)
		printf(MSG_NOLBL);
	    else {
		s = search.fname;
		for (i = 0; *s && (i < 8); i++)
		    label[i] = (*s == '.') ? ' ' : *s++;

		if (*s == '.') s++;       /* if there was a '.' skip it */
		for (; *s && (i < 11); ) label[i++] = *s++; /* copy the rest */
		label[i] = '\0';	        /* null terminate label */

		printf(MSG_OKLBL, label);
	    }
	    crlf();
	}
}

/*.pa*/
/*
 *
 */
GLOBAL VOID CDECL cmd_delq(path)		  /* erase files with query */
BYTE	*path;
{
	erase (path, YES);		/* erase files, confirm deletes */
}

EXTERN BYTE FAR * CDECL farptr(BYTE *);
#define	YES_CHAR	(*farptr(YES_NO+0))
#define	NO_CHAR		(*farptr(YES_NO+1))

#define	ERASE_CONFIRM	(flags & 3)
#define	ERASE_SYS	(flags & 4)

MLOCAL VOID erase(s, confirm)
BYTE *s;
BOOLEAN  confirm;
{
	BYTE	path[MAX_FILELEN];		/* FileName Buffer	    */
	BYTE	answer[20];			/* Yes/No string	    */
	BYTE 	*files;				/* pointer to file spec	    */
#if defined(PASSWORD)
	BYTE	*password;
#endif
	UWORD	flags;				/* only one switch permitted*/
	DTA	search; 			/* Local Search Buffer	    */
	UWORD	attr;				/* Erase Search Attributes  */
#if !STACK
	BYTE	passbuf[MAX_FILELEN];
#endif
#if !(defined (CDOSTMP))
	BYTE	savepath[MAX_PATHLEN+1];
	BYTE	newpath[MAX_PATHLEN+2];		/* including trailing \	    */
	BYTE	fcb[37];
	WORD	ret;
	WORD	i;
#endif

	if(f_check(s, "cps", &flags, NO))     	/* if any bad flags return  */
	    return;

	get_filename(path, s, YES);		/* Extract the Filename	    */
	if(strlen(path) == 0) {			/* and check for 0 length   */
	    printf(MSG_NEEDFILE);		/* path caused by invalid   */
	    crlfflg = YES;			/* filename characters in   */
	    return;				/* the command line.	    */
	}

	if ((strcmp(path,dotdot+1) == 0) || (strcmp(path,dotdot) == 0)) {
		strcat(path,d_slash_stardotstar+2);
	}

/* Neil's bodge */
/* del d:. should be the same as del d:*.* */
	if (strlen(path)==3 && path[1] == ':' && path[2] == '.') {
	    path[2] = 0;
	    strcat(path,d_slash_stardotstar+3);
	}
/* end of Neil's bodge */

	attr = ATTR_STD & ~ATTR_SYS;		/* Prevent SYS files from   */
	attr |= ERASE_SYS ? ATTR_SYS : 0;	/* being deleted unless the */
						/* /S option is specified.  */

	if(nofiles(path, attr, YES, YES))	/* if no files or error	    */
	    return;				/*    then we can't do this */

	files = fptr(path);			/* isolate the filename	    */

#if defined(PASSWORD)
	password = strchr(files, *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(files, *pwdchar));
	}
#endif

	confirm |= ERASE_CONFIRM;	/* DELQ implies "/c" switch */
	if (!confirm &&			/* if not confirming anyway */
	    (!strncmp(files, "*", 1)&&	/* and all files specified  */
	    strstr(files, ".*")))	/* ie * at start of name & ext */
	{
	    printf(MSG_ERAALL); 	  /* "Are you sure (Y/N)? " */
	    answer[0] = sizeof(answer)-2; /* max. one character	  */
	    answer[1] = 0;		  /* no command recall permitted */
	    system (MS_C_READSTR, answer);/* read the response */
	    crlf();
	    if ((answer[2] & 0xdf) != YES_CHAR) {
	    	crlfflg = YES;		/* if not 'Y' or 'y' given */
		return;			/* then return		  */
	    }
	}

	if(!confirm && ERASE_SYS &&	/* If no confirmation is required */
#if !(defined (CDOSTMP))
	   !iswild(path) &&		/* and this is an ambigous file   */
#endif
	   !ms_x_unlink(path))		/* specification and all the files*/
	    return;			/* are deleted without error then */
					/* return to the calling function */
					/* otherwise delete files	  */
					/* individually.		  */

#if !(defined (CDOSTMP))
/*	use fcb delete if no confirm and system files are not to be	  */
/*	deleted, since it's much quicker. Any problems, go and do it the  */
/*	standard way so we can report on problem files.			  */

	d_check (path);
	if (ddrive != -1 && (!confirm) && (!ERASE_SYS)
#if defined(PASSWORD)
		&& (!password)
#endif
	) {
	    if (!d_check (path))
	        return;

	    if ((ms_f_parse (fcb, files, 0)) < 0) /* set up fname in fcb  */
	        goto fcbdel_end;
	    *fcb = ddrive+1;

	    strcpy (savepath, "d:\\");	/* get curpath on relevant drive  */
	    *savepath = ddrive + 'A';
	    ms_x_curdir (ddrive+1, savepath+3);
	    
	    strncpy (newpath, path, files - path);
	    				/* extract new path		*/
	    newpath[files - path] = '\0';

	    if ((i = strlen (newpath)) > (newpath[1] == ':' ? 3 : 1))
	        newpath[--i] = '\0';	/* remove trailing backslash	*/
	
	    if (! ((i == 0) || ((i == 2) && (newpath[1] == ':'))) )
	        if (ms_x_chdir (newpath))
		    goto fcbdel_end;
	
	    ret = ms_f_delete (fcb);
	    ms_x_chdir (savepath);
	    
	    if (!ret)
	        return;			/* all done			  */
fcbdel_end:
	    ;
	}
#endif
	    
	if (ms_x_first(path, attr, &search)) return;
	do {
	    strcpy(files, search.fname);	/* make it full file name */
	    strcpy(heap(), path);		/* copy to an internal    */
#if defined(PASSWORD)
	    if(password)			/* buffer and append the  */
		strcat(heap(), password);	/* password if present	  */
#endif

	    if(confirm) {
		printf(MSG_ERAQ, path);
		if(!yes(YES, NO))
		    continue;
	    }

	    if((ret = ms_x_unlink(heap())) != 0) {
		printf(MSG_ERA, path);
		e_check(ret);
		crlf();
	    }
	} while (!ms_x_next (&search));
}

#if defined(DOSPLUS)
/*
 *	The HILOAD command accepts a trailing command line.
 *	It will attempt to execute the command line, running any programs
 *	specified in high memory.
 */
GLOBAL VOID CDECL cmd_hiload(s)
REG BYTE *s;
{
int	region, i;

	s = deblank(s);
	if (*s == 0) {
	    printf(msg_inop);
	    return;
	}
	
	global_in_hiload++;
	
	if (global_in_hiload == 1) {
	    global_link  = get_upper_memory_link();
	    global_strat = get_alloc_strategy();
	    region = 1;

	    set_upper_memory_link(1);

	    /* Look out for /L:r1[,s1][;r2[,s2]...] */
	    /* We parse r1, and discard the rest */

	    if ((s[0]==*switchar)&&(toupper(s[1])=='L')&&(s[2]==':')&&isdigit(s[3])){
		region = s[3]-'0';	/* assume region is 1 digit */
		s += 4;			/* skip what we parsed */
		while ((*s==';') || (*s==',') || isdigit(*s))
			s++;
		s = deblank(s);		/* deblank rest of line */
	    }

	    /* discard any /S we find (really we should minimise) */
	    if ((s[0]==*switchar) && (toupper(s[1])=='S')) {
		s += 2;			/* skip the /S */
		s = deblank(s);		/* deblank rest of line */
	    }

	    /* only bother if we have upper memory and are forcing location */
	    if ((region > 1) && (get_upper_memory_link() != 0)) {
		set_alloc_strategy(0x40);	/* First fit high only */
		for(i=1;i<region;i++)		/* allocate regions to skip */
			hidden_umb[i] = alloc_region();
	    }
	
	    set_alloc_strategy(0x80);	/* First fit high */
	}
	
	docmd(s,YES);			/* call normal code */

	if (global_in_hiload == 1) {
	    for(i=1;i<10;i++) {		/* free up any UMB's we have */
		if (hidden_umb[i]) {
			free_region(hidden_umb[i]);
			hidden_umb[i] = 0;
		}
	    }

	    set_upper_memory_link(global_link);
	    set_alloc_strategy(global_strat);
	}
	global_in_hiload --;		/* all back as before */
}

#endif


⌨️ 快捷键说明

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