main.c

来自「Dos6.0」· C语言 代码 · 共 712 行 · 第 1/2 页

C
712
字号
;/*
; *                      Microsoft Confidential
; *                      Copyright (C) Microsoft Corporation 1991
; *                      All Rights Reserved.
; */

#include <common.h>
#include <filemgr.h>
#include <text.h>
#include <menus.h>
#include <prot.h>
#include <time.h>
#include <direct.h>

extern GlobalIdle(void);
extern TOKEN Get_Identifier_Token(char far *identifier);
extern void Shell_TTY_Out(char *str);
extern void Get_CWD(char *);

extern BOOL AddTask(char far *programname, char far *parameters,char far *defaulttitle,TOKEN properties);

struct CountryBuffer {
    int Date_Format;
    char Currency_Symbol[5];
    char Thousands_Sep[2];
    char Decimal_Sep[2];
    char Date_Sep[2];
    char Time_Sep[2];
    char Currency_Pos;
    char Num_Decimals;
    char Time_Format;
    long Case_Mapping;
    char Data_Sep[2];
    char Reserved[10];
} ;
struct CountryBuffer NationData;

MSG     msg;
INST    ginst;
INGD    gingd;
INDV    gindv;
BOOL    gisgraph = FALSE ;
INCH    cinch;

BOOL gfStillInitializing; /* used in allocs to bail if we're gonna toast */
BOOL gfScreenModeChanged; /* used to restore screen in case we bail out early */
BOOL gfSwapHandlerInstalled;

char gStartUpDir[1+MAX_PATH];
char gStartInDir[1+MAX_PATH];
int gStartUpDirEnd; /* location where the NULL goes in the above name */

BOOL gBeeps_On; /* Whether to have Beeps turned on or not on error */

gBeeps_On = TRUE ;

extern MENUINFO MainMenuBar;
extern MENUINFO FileMgrMenuBar;
extern BYTE ErrorCrit;

extern VOID setmenubar(MENUINFO *amenu,PWND towind);
extern BOOL GetInternationalData(void);
extern void InstallSwapHandler(void) ;
extern void     PrintHelpText(void);
extern VOID SetUpExitToDos(void); /* see init.c */
extern BOOL AsynchUpdateTreeList(void);

VOID DeleteBatchFile(void);

extern WND ViewWind;
extern BOOL gMouseDown;
extern BYTE gMouseX;    /* X value of last mouse-down */
extern BYTE gMouseY;    /* Y value of last mouse-down */

/* INTERNATIONALIZE HERE!
 * We still don't have international am/pm symbols
*/
/*
 * sets up datestr to be in format ' 00-00-00 '
 * sets up timestr to be in format ' 12:20 am '
 *
 * if force is not set, and time (minutes) has not changed, returns
 * false and does not format strings.
 * if force is set, formats strings and returns true
 * if force is not set, and time has changed, formats strings and returns true
 */

#define NumToAsc(num,str) (temp=(num)/10, *(str++)=(char)((temp%10)+'0'), *(str++)=(char)((num)-temp*10+'0'))

BOOL FAR Get_Date_and_Time_Strings(unsigned int theDate, unsigned int theTime,
      char *datestr, char *timestr, BOOL force)
{
    static struct tm lasttime;
    struct tm temptime, *newtime;
    time_t long_time;
    register int temp;
    int date1, date2, date3;  /* for international date order */

    if(!theDate && !theTime) {
	time(&long_time);
	newtime = localtime(&long_time);
    } else {
	temptime.tm_year = 80 + (theDate>>0x09);
	temptime.tm_mon  = ((theDate>>0x05)&0x0f) - 1;
	temptime.tm_mday = theDate&0x1f;
	temptime.tm_hour = theTime>>0x0b;
	temptime.tm_min  = (theTime>>0x05)&0x3f;
#if 0 /* We don't use the seconds */
	temptime.tm_sec  = 2*(theTime&0x1f);
#endif

	newtime = &temptime;
	goto FormatDateAndTime;
    }

    if (force || (newtime->tm_min != lasttime.tm_min))
    {
	lasttime = *newtime;
FormatDateAndTime:
	if(datestr) {
	    if(NationData.Date_Format == 1) {
		date1 = newtime->tm_mday;
		date2 = newtime->tm_mon + 1;
		date3 = newtime->tm_year;
	    } else if(NationData.Date_Format == 2) {
		date1 = newtime->tm_year;
		date2 = newtime->tm_mon + 1;
		date3 = newtime->tm_mday;
	    } else {
		date1 = newtime->tm_mon + 1;
		date2 = newtime->tm_mday;
		date3 = newtime->tm_year;
	    }

	    NumToAsc(date1, datestr);
	    *(datestr++) = *NationData.Date_Sep;
	    NumToAsc(date2, datestr);
	    *(datestr++) = *NationData.Date_Sep;
	    NumToAsc(date3, datestr);
	}

	if(timestr) {
	    if(NationData.Time_Format&0x01) { /* A 24-hour clock */
		timestr[5] = ' ';
		NumToAsc(newtime->tm_hour, timestr);
	    } else { /* A 12-hour clock */
		temp = newtime->tm_hour;
		if(temp < 12) {
		    if(temp == 0)
			temp = 12;
		    timestr[5] = 'a';
		} else {
		    if(temp != 12)
			temp = temp - 12;
		    timestr[5] = 'p';
		}
		if((temp/10)>0)
		    *(timestr++) = (char) ((temp/10) + '0');
		else
		    *(timestr++) = (char) ' ';
		*(timestr++) = (char) ((temp%10) + '0');
	    }
	    *(timestr++) = *NationData.Time_Sep;
	    NumToAsc(newtime->tm_min, timestr);
	}

	return(TRUE);
    } else {
       return(FALSE);
    }
}

/*
 * draw the top title bar--
 */
VOID FAR UpdateMainTitleBar(char *szTitle)
{
    char *titlestring;
    int i;
    WORD len;
    WORD titlestart;
    char padded[100];

	 titlestring = szTitle ;

    len = strlen(titlestring);
    titlestart = axMac/2 - len/2;
    for(i=0;i<axMac;i++)
    {
		padded[i] = ' ';
    }
    FEnableMouseNest(FALSE);

    TextOut(&MainWind,(RX) 0,(RY) 0, padded,titlestart,isaHilite);
	 TextOut(&MainWind,(RX) titlestart,0,titlestring,len,isaHilite);
    TextOut(&MainWind,(RX) titlestart+len,(RY)0, padded,axMac-(titlestart+len),isaHilite);
    if (gisgraph)
    {
	if(CHEIGHT > SMALLHEIGHT)
	{
	     SetAreaPat(0);
	     SetLinePat(1);
	     SetColor(0,0x7FFF);
	     Move(0,CHEIGHT-1);
	     Draw((axMac)*CWIDTH,CHEIGHT-1);
	}
    }
    FEnableMouseNest(TRUE);
}

VOID FAR PauseBeforeScreenErase(VOID)
{
#ifndef NOLOADER
    if(Get_KeyWord_Assignment(TK_SAVESTATE,TK_PAUSE) != TK_DISABLED)
    {
	if (GET_WAIT_FLAG())
	{
		 /* clear out keyboard buffer */
		 while(kbhit())
			getch();

		 Shell_TTY_Out(szPressAKey);
		 /* wait for key to be hit */
	    while(!kbhit())
				;
		 /* eat key */
	    getch();
	}
	Set_KeyWord_Assignment(TK_SAVESTATE,TK_PAUSE,TK_ENABLED);
    }
#endif
}


VOID ParseCommandLine(void)
{
    char far *commandline;
    char lastfound=0;
    char tstr[256], *szWhichRes;
    TOKEN tkRes;

#ifndef NOLOADER
    if(GET_WAIT_FLAG())
	return;

	/*      We use the previous bytes to store pause flag status, a far pointer, etc
	 *      See loader.asm for exact details.
	 */
	commandline = GET_COMMAND_PTR()+9;
#if 0
	printf("%d, ", *(commandline-2)) ;
	printf("%d, ", *(commandline-1)) ;
	printf("%d, ", *commandline) ;
	printf("%d, ", *(commandline+1)) ;
	printf("%d, ", *(commandline+2)) ;
	printf("%d, ", *(commandline+3)) ;
	printf("\n") ;
	getchar() ;
#endif
    for( ; ; ++commandline) {
	switch(*commandline) {
	case('\0'):
	case('\r'):
	    goto AllDone;
	    break;

	case('/'):
	    ++commandline;
	    switch(lastfound=(char)toupper(*commandline)) {
	    case 'T':
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_SCREENMODE, TK_TEXT);
		break;

	    case 'G':
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_SCREENMODE,TK_GRAPHICS);
		break ;

#ifdef ERICLIKESBEEPCONTROL
	    case 'B' : // /BEEP
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_BEEP, TK_ENABLED);
		break ;

	    case 'N' : // /NOBEEP
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_BEEP, TK_DISABLED);
		break ;
#else
	    case 'B' :
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_FORCEMONO, TK_ENABLED);
		break ;
#endif

#ifdef SWAPMOUSESWITCH
	    case 'S' : // /SWAPMOUSE
		Set_KeyWord_Assignment(TK_SAVESTATE, TK_SWAPMOUSE,
			Get_KeyWord_Assignment(TK_SAVESTATE, TK_SWAPMOUSE)
			== TK_DISABLED ? TK_ENABLED : TK_DISABLED);
				break ;
#endif
#if 0
	    case '?' : // /HELP
	    case 'H' :
#endif
	    default  :
		PrintHelpText();
		SetUpExitToDos();
		exit(0);
	    }
	    break;

	case(':'):
	    ++commandline;
	    switch(lastfound) {
	    case 'G':
	    case 'T':
		switch(toupper(*commandline)) {
		case 'L':
		    tkRes = TK_LOWRES;
		    goto MakeKeyword;

		case 'M':
		    tkRes = TK_MEDIUMRES;
		    goto MakeKeyword;

		case 'H':
		    tkRes = TK_HIGHRES;
		    goto MakeKeyword;

MakeKeyword:
		    strfcpy(tstr, Get_Token_Identifier(tkRes));
		    for(szWhichRes=tstr; *szWhichRes; ++szWhichRes)
			/*do nothing */ ;
		    for(++commandline; *commandline>='0' && *commandline<='9';
			    ++commandline)
			*(szWhichRes++) = *commandline;
		    *szWhichRes = '\0';

		    Set_KeyWord_Assignment(TK_SAVESTATE, TK_RESOLUTION,
			    Get_Identifier_Token(tstr));
		    break;

		default:
		    break;
		}
				break;

	    default:
		break;
	    }

		    lastfound = 0;
	    break;

	default:
	    break;
	}
    }

⌨️ 快捷键说明

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