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

📄 support.c

📁 一个dos操作系统DRDOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
;    File              : $Workfile: SUPPORT.C$
;
;    Description       :
;
;    Original Author   : DIGITAL RESEARCH
;
;    Last Edited By    : $CALDERA$
;
;-----------------------------------------------------------------------;
;    Copyright Work of Caldera, Inc. All Rights Reserved.
;      
;    THIS WORK IS A COPYRIGHT WORK AND CONTAINS CONFIDENTIAL,
;    PROPRIETARY AND TRADE SECRET INFORMATION OF CALDERA, INC.
;    ACCESS TO THIS WORK IS RESTRICTED TO (I) CALDERA, INC. EMPLOYEES
;    WHO HAVE A NEED TO KNOW TO PERFORM TASKS WITHIN THE SCOPE OF
;    THEIR ASSIGNMENTS AND (II) ENTITIES OTHER THAN CALDERA, INC. WHO
;    HAVE ACCEPTED THE CALDERA OPENDOS SOURCE LICENSE OR OTHER CALDERA LICENSE
;    AGREEMENTS. EXCEPT UNDER THE EXPRESS TERMS OF THE CALDERA LICENSE
;    AGREEMENT NO PART OF THIS WORK MAY BE USED, PRACTICED, PERFORMED,
;    COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED, ABRIDGED,
;    CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, RECAST,
;    TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF
;    CALDERA, INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT
;    AUTHORIZATION COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND
;    CIVIL LIABILITY.
;-----------------------------------------------------------------------;
;
;    *** Current Edit History ***
;    *** End of Current Edit History ***
;
;    $Log$
;
;    ENDLOG
*/

/*
	File		SUPPORT.C
	Title		SUPPORT routines for command.com 

Revision History:-
==================

Date       Description
-----------------------------------------------------------------------------
10 Apr 86  EQU function now makes a case independant match.
29 Apr 86  Single $ preceeds the screen control variables
           Fix bug where if the last character of a screen control
           variable was an octal character it was not printed
 6 May 86  yes() now requires a default to be specified previously
           it assumed the default was NO.
21 May 86  Fixed bug with yes() function when default is NO.
22 May 86  Allow the screen control codes to be patched to longer strings
           Upd`te ZAP_SPACES to delete all white space
Version 1.2
===========
31 Jul 86  Conditionally remove functions that cannot be fully supported
           in a CDOS version of COMMAND.COM
 4 Aug 86  ANSI C compatibility MSC /W1
30 Oct 86  FREE_DRIVE now forces the drive to point to the root
           directory of the current drive.
17 Feb 87  Rewrote repwild() function to fix minor problems 
   Aug 87  Make all routines PASCAL calling convention  (for Concurrent 6)
26 Oct 87  Update the F_CHECK routine to support multiple switches ie
           "/wc" as well as "/w /c".
27 Oct 87  Stop F_CHECK from forcing the input line to lower case.
10 Nov 87  Modify F_CHECK flag zapping
18 Nov 87  Prevent GET_FILENAME copying a filename > than MAX_PATHLEN
16 Dec 87  Update D_CHECK to make fewer system calls.
29 Feb 88  Tidy the REPWILD routine - No Functional Change
15 Mar 88  Use ANSI Escape sequences for DOS Plus
27 Apr 88  Restore Range check to D_CHECK routine
25 May 88  Print a CR after a CLS to reset the current column count.
26 May 88  Change the Default HighLight and LowLight strings to NULL
           for DOSPLUS. 
27 May 88  Added string undefs.
23 Jun 88  Add new ONOFF function for XXX [=] ON|OFF parsing 
28 Jun 88  Correct bug in YES routine for FAR messages
 1 Jul 88  Support Control-C from YES for TMP.
 6 Jul 88  Support the CON:filename syntax for COPY.
19 Sep 88  Enhance error checking on the F_CHECK routine. Now traps the
           condition when switchar is at the end of the line.
 1 Dec 88  Convert all path parsing routines to be KANJI friendly.
21 Dec 88  Add generic ISDEV routine to SUPPORT.C
21 Dec 88  "*" to "*.*" conversion moved to CMD_DIR. 
18 Apr 89  c_write: write to STDERR if err_flag set
6 Jun 89   Correct GET_FILENAME to parse path passwords.
6 Jun 89   echo: check for endline after on/off.
10 Aug 89  get rid of sysdate_fmt (year does not need to be %04d, which
           upsets Japanese day)
10 Aug 89  day_name_len for day_names array elements
22 Aug 89  Japanese dayname comes after date
           Remove day_name_len & work out length from array.
11 Sep 89  strupr(), strlwr() and stricmp() are now Kanji aware.
           toupper() is now in DOSIF.ASM and uses international routine.
16 Oct 89  Kanji specific routines replaced with DBCS routines.
30 Oct 89  "Internal Error" moved to message.c (and no longer resident)
15 Dec 89  errors 50-72 give "Network error" rather than "Internal error"
6-Mar-90   Watcom C v 7.0
13-Mar-90  Output CR/LF after errors
4-May-90   append_slash added
4-May-90   get_filename stops at ';' unless followed by pathchar(s)
           ("append;" bug)
20-Sep-90  Created skip_char() and copy_char().
           Created is_blank() and amended deblank(), zap_spaces(),
           is_filechar() and is_pathchar() to use it.
13-Mar-91  changed nofiles() function to cope with DIR.. on NOVELL drives.
18-Mar-91  tolower() ( and therefore strlwr() ) is now aware of TURKISH
           capital I's with dots. 
6-Aug-91   prompt_exec() function no longer uses the heap. This screwed us
           up if the file to be execed was a batch file.
09-Jun-92  is_pathchar and d_check now cope with drive '[', etc, as used
           by some novell applications. See also INVALID_DRV in command.h.
18-Jun-92  Added optional_line() function for '?' support in batch files.
-----------------------------------------------------------------------------
*/

#include	"defines.h"
#include	<setjmp.h>
/*#include	<string.h>*/

#if defined(MWC) && defined(strlen)
#undef strcmp			/* These are defined as macros in string.h */
#undef strcpy			/* which are expaneded in line under */
#undef strlen			/* Metaware C. These undefs avoid this. */
#endif

#include	<portab.h>
#include	<mserror.h>
#if defined(CDOSTMP)
#include	<ccpm.h>
#include	<sysdat.h>
#endif

#include	"command.h"
#include	"toupper.h"
#include	"dosif.h"
#include	"global.h"
#include	"dos.h"

EXTERN jmp_buf break_env;

EXTERN VOID CDECL printf(BYTE *, ...);
EXTERN VOID CDECL eprintf(BYTE *, ...);
EXTERN VOID CDECL sprintf(BYTE *, BYTE *, ...);
#if defined(CDOSTMP)
EXTERN VOID CDECL int_break(VOID);		/* COM.C Internal Break */
#endif

MLOCAL VOID screen(BYTE *, BYTE *);
MLOCAL VOID outs(BYTE *);
GLOBAL VOID crlf(VOID);
GLOBAL VOID putc(BYTE);
GLOBAL VOID c_write(BYTE *, UWORD);
GLOBAL BYTE * fptr(BYTE *);
GLOBAL BYTE * day_names(UWORD);

/*.pa*/
/*
 *	The following screen control sequences can be redefined or removed
 *	by entries in the environment or the OEM can patch these areas in the
 *	COMMAND.COM object and change the default values.
 *
 */
#define CLS_KEY 	"$CLS=" 	/* CLS entry in environment	    */
#define REVON_KEY	"$ON="		/* REVON entry in environment	    */
#define REVOFF_KEY	"$OFF=" 	/* REVOFF entry in environment	    */

#ifdef DOSPLUS
/*
 *	For DOSPLUS the default screen control sequences are for an
 *	ANSI Terminal (IBM Sub-Set).
 */
#define CLS_DEF 	"\033[2J\0***"	/* Default CLS string "ESC [2J"*/
#define REVON_DEF	"\0********"	/* Default REVON string NULL   */
#define REVOFF_DEF	"\0********"	/* Default REVOFF string NULL  */

EXTERN BOOLEAN CDECL int10_cls(VOID);	/* Dirty Clear Screen Subroutine    */
#else
/*
 *	For Concurrent DOS the default screen control sequences are for a
 *	standard VT52 Terminal.
 */
#define CLS_DEF 	"\033E\0*****"	/* Default CLS string "ESC E"	    */
#define REVON_DEF	"\033p\0*****"	/* Default REVON string "ESC p"     */
#define REVOFF_DEF	"\033q\0*****"	/* Default REVOFF string "ESC q"    */
#endif
					/* Invalid FileName Characters as   */
					/* specified by the IBM DOS Tech    */
					/* Reference Page 6-96 "func 29"    */
MLOCAL BYTE	invalid_filechar[] = "*?\\.:;,=+<>|/\"[]";

/*.pa*/
/*
 *	TIME AND DATE SUPPORT ROUTINES
 *	==============================
 *
 *	The following routines print the TIME and DATE using the international
 *	data. Two sets of routines are provided to display the SYSTEM Time and
 *	Date the second routine displays FILE based time and date.
 */
MLOCAL BYTE	date_fmt []    = "%2d%c%02d%c%02d";

GLOBAL VOID disp_filetime(time)
unsigned time;
{
	WORD	h, m;
	BYTE	ap;
	
	ap = ' ';			/* assume no AM/PM used */
	h = (time >> 11);
	m = (time >> 5) & 0x3f;
	if (country.ampm == 0)		/* if anglo saxon fashion */
	{				/* need to convert things */
	    ap = 'a';			/* assume morning */
	    if (h == 0) 		/* 00:00 through 00:59 */
		h = 12; 		/*    is special... */
	    else if (h >= 12)		/* test if afternoon */
	    {
		ap = 'p';		/* mark as afternoon */
		if (h > 12)		/* if 13:00 through 23:59 */
		    h -= 12;		/* need to make " 1:00p" */
	    }
	}

	printf ("%2d%c%02d%c",
		h, country.dtime[0],	/* print hour, delimiter */
		m, ap); 		/* print minute, am/pm (if enabled) */
}

GLOBAL VOID disp_filedate(date)
unsigned date;
{
	WORD	y, m, d;
	WORD	b;

	y = ((date >> 9) + 80)%100;
	m = (date >> 5) & 0x0f;
	d = date & 0x1f;
	b = country.ddate[0];

	switch (country.dt_fmt)
	{
	 case 1:			/* European format dd/mm/yy */
	    printf (date_fmt, d,b,m,b,y);
	    break;

	 case 2:			/* Japanese format yy/mm/dd */
	    printf (date_fmt, y,b,m,b,d);
	    break;

	 default:			/* US format mm/dd/yy for the rest*/
	    printf (date_fmt, m,b,d,b,y);
	    break;

	};
}

GLOBAL VOID disp_systime()
{
	SYSTIME  time;
	WORD	b = country.dtime[0];
		
	ms_gettime(&time);
	printf ("%2d%c%02d%c%02d.%02d",
		time.hour, b,		/* print hour, delimiter */
		time.min, b,		/* print minute, delimiter */
		time.sec, time.hsec);	/* Print the second and Hundredths */
}


/* Return address of null terminated day name, given index (day). */

GLOBAL BYTE * day_names(day)
UWORD	day;			/* day of week: 0=sunday, 1=monday, .. */
{
    switch (day)
    {
    case 0:	return SUN_D;
    case 1:	return MON_D;
    case 2:	return TUE_D;
    case 3:	return WED_D;
    case 4:	return THU_D;
    case 5:	return FRI_D;
    default:	break;
    }

    return SAT_D;
}


GLOBAL VOID disp_sysdate()
{
	SYSDATE date;
	WORD	y, m, d;
	WORD	b;

	ms_getdate(&date);		/* Get the current date */
	y = date.year;
	m = date.month;
	d = date.day;
	b = country.ddate[0];

	if (country.dt_fmt != 2)	/* Japanese day comes after date */
	    printf("%s ", day_names(date.dow));
	
	switch (country.dt_fmt)
	{
	 case 1:			/* European format dd/mm/yy */
	    printf (date_fmt, d,b,m,b,y);
	    break;

	 case 2:			/* Japanese format yy/mm/dd */
	    printf (date_fmt, y,b,m,b,d);
	    printf(" %s", day_names(date.dow));
	    break;

	 default:			/* US format mm/dd/yy for the rest*/
	    printf (date_fmt, m,b,d,b,y);
	    break;
	};
}

/*.pa*/
/*
 *	Screen handling routines to CLEAR the screen and emphasise text
*/

GLOBAL VOID CDECL cmd_cls()
{
#if defined(DOSPLUS)
 	if(!int10_cls())			/* If no console device is */
	    screen(CLS_KEY, CLS_DEF);		/* active use the default  */
						/* $CLS string.		   */
#else						/* For Concurrent DOS never*/
	screen(CLS_KEY, CLS_DEF);		/* use INT 10		   */
#endif						/* Finally print a CR to   */
	putc('\r');				/* reset the internal	   */
						/* Column count.	   */
}

GLOBAL VOID revon()
{
	screen(REVON_KEY, REVON_DEF);
}

GLOBAL VOID revoff()
{
	screen(REVOFF_KEY, REVOFF_DEF);
}

MLOCAL VOID screen(key, def)
BYTE	*key;		/* Key name to match in the environment */
BYTE	*def;		/* Default string to output if no match */
{
REG BYTE *cp;

	if(!env_scan(key, cp = (BYTE *)heap()))
					/* and then search for the key  */
	    outs(cp);			/* output the string on a match */
	else				/* otherwise use the default	*/
	    printf(def);		/* supplied on entry		*/
}

/*
 *	This string output function will output a string containing
 *	a C format imbedded Octal number. This is mainly used for the
 *	CLS function.
 */
MLOCAL VOID outs(s)
BYTE *s;
{
BYTE	b = 0;
REG WORD f = 0;

	for(; *s; s++) {
		if(f) { 			/* Generating an OCTAL number*/
		    if(*s >= '0' && *s < '8') { /* check for a valid number  */
			b <<= 3;		/* and flush the buffer if it*/
			b += *s - '0';		/* is illegal. Otherwise add */
		    }				/* to the buffer and flush   */
		    else {			/* after three characters    */
			if(f != 3)
			    putc(b);
			putc(*s);
			f = 0;
			continue;
		    }

		    if(f-- == 1)
			putc(b);

		    continue;
		}

		if(*s == '\\') {
		    f = 3;		/* Initialise the Character count */
		    b = 0;		/* Zero the display value	  */
		    continue;
		}

		putc(*s);
	}

	if(f && b)
	    putc(b);
}


/*.pa*/
/*
 *	GENERAL PURPOSE STRING MANIPULATION ROUTINES
 *	============================================
 *
 */
GLOBAL BYTE tolower(b)
BYTE b;
{
	if (b==0x8D) return('i'); /* For turkish dotted capital I */
	return((b < 'A' || b > 'Z') ? b : b + 0x20);
}

GLOBAL BOOLEAN isdigit(b)
BYTE b;
{
	return (b >= '0' && b <= '9');
}

GLOBAL BYTE * skip_char(s)
REG BYTE *s;
{
	s++;
	if (dbcs_lead(*(s - 1)) && *s >= ' ')
	    s++;
	return(s);

⌨️ 快捷键说明

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