main.c
来自「Dos6.0」· C语言 代码 · 共 712 行 · 第 1/2 页
C
712 行
AllDone:
;
#endif
}
extern char far * cdecl GET_STARTUP_NAME(VOID);
VOID FAR SetUpStartUpDirectory(VOID)
{
#ifndef NOLOADER
strfcpy(gStartUpDir,GET_STARTUP_NAME());
gStartUpDirEnd=FindLastComponent(gStartUpDir);
gStartUpDir[gStartUpDirEnd]= 0;
#else
strcpy(gStartUpDir,".\\");
gStartUpDirEnd=2;
#endif
Get_CWD(gStartInDir);
}
extern char *gpszNonSwap ;
/*
* This is where all background tasking is done, so it should
* be called often.
*/
VOID MainIdle(void)
{
static int arbitrarycounter;
/* Add more idle procs here if required.
*/
#ifdef PROF
ClockOn();
#endif
/* note we need to call both idles always!
* thus, the & must be & and not && so it
* won't short circuit!
*/
if(gMouseDown && m_fPerformingViewFile()) {
ViewWindProc(&ViewWind, WM_MOUSEIDLE, 1,
((DWORD)gMouseY<<24) | ((DWORD)gMouseX<<16));
}
if (FileMgrIdle() & StartProgramsIdle() & AsynchUpdateTreeList())
{
GlobalIdle(); /* Tell the world we're idle */
}
/*
* We poll the time to see if it changed. But we
* don't really need to do it all the time, so
* we use "arbitrarycounter" to determine if we should
* check to see if we should update it. Assumes we
* are idle 64k times a minute
*/
if (arbitrarycounter++ == 0)
MessageBar(gpszNonSwap, isaMenu,FALSE);
#ifdef PROF
ClockOff();
#endif
fPollKeyboard=TRUE;
}
WORD gCnx = cnxNull;
/*
* Called by CW during menu and dialog idle time
*/
WORD FARPUBLIC RspAppIdle(WORD cnx,DWORD Lparam)
{
if(cnx == cnxDialog)
{
PDLG pdlg = (PDLG)LOWORD(Lparam);
if (pdlg->pfnDlg != NULL)
{
/* send dlmIdle to appropriate dialog proc */
(*pdlg->pfnDlg)(dlmIdle, 0, 0, 0, 0);
}
}
gCnx = cnx;
/*
* do not idle when in a critcal dialog!
*/
if( ErrorCrit == 0xFF)
{
MainIdle();
}
gCnx = cnxNull;
return(rspContinue);
}
/*
* we don't use the standard argv handling, so why
* have it around?
*/
void cdecl _setargv(void)
{
}
#if 0
void cdecl _setenvp(void)
{
static char * foo;
foo = environ;
unlink("foo");
}
#endif
/* WARNING
* this is a replacement for the C call malloc. This SHOULD NEVER BE
* CALLED IN YOUR CODE! This function is called at startup by
* C-runtime to setup the environment. Since we don't want to carry
* around a bunch of code we don't use, we just use our own allocation
* Note that this memory is never freed! This is very important, since
* the freework function can tromp
* The real malloc sucks in about .5k of code
*/
void * cdecl malloc(unsigned int s)
{
return(PbAllocWork(s));
}
BOOL gfEarlyExit = FALSE ;
extern Dos_Version(void);
void VersionCheck(void)
{
/* Perform version check!! We use the new "int 2f" issued by the BIOS
* to swap disks on a single floppy system -- "A:", "B:" on 1 physical drive
*/
if (Dos_Version() < MIN_MAJOR_VERSION)
{
Shell_TTY_Out(szIncorrectDosVersion) ;
gfEarlyExit = TRUE ;
DoExit() ;
}
}
extern WORD GetLastScanCode(void);
/*
* Looks for '!' signature in the ROM, followed 18 bytes later by
* '01' which is the ROM BIOS version number.
* Thus, this will only detect Tandy's with version 1.0 ROM.
*/
#define IsTandy1000 ( (*((BYTE FAR *)0xf000c000L) == 0x21) && (*((WORD FAR *)0xf000c012L) == 0x3130))
/*
* The Tandy 1000 returns some strange keyboard messages, so we have to
* trap them and change them to the correct messages. GetLastScanCode
* helps us determine what the correct message is, but it will return
* useless values if a modifier key is changed, so we have to store the
* last useful value in wSaveScanCode.
*/
VOID FAR PASCAL Tandy1000KeyboardHook(WORD message, WORD wParam, DWORD lParam)
{
static WORD wSaveScanCode = 0;
WORD wLastScanCode;
#if 0
char buf[80];
if(message == WM_CHAR)
com1("\nWM_CHAR ");
else if(message == WM_KEYUP)
com1("\nWM_KEYUP ");
else if(message == WM_KEYDOWN)
com1("\nWM_KEYDOWN ");
else {
sprintf(buf, "\n%-10d ", message);
com1(buf);
}
sprintf(buf, "%04x 0x%04x 0x%04x ", wParam, HIWORD(lParam),
GetLastScanCode()&0xff7f);
com1(buf);
if(message==WM_CHAR && !(wParam&0xff00)) {
buf[0] = LOBYTE(wParam);
buf[1] = '\0';
com1(buf);
}
#endif
if(message == WM_CHAR) {
switch(wParam) {
case(VK_HOME):
wLastScanCode = GetLastScanCode()&0x7f;
if(wLastScanCode == 0x47 || wLastScanCode == 0x58)
wSaveScanCode = wLastScanCode;
if(wSaveScanCode == 0x47)
wParam = '\\';
break;
case(VK_LEFT):
wLastScanCode = GetLastScanCode()&0x7f;
if(wLastScanCode == 0x4b || wLastScanCode == 0x2b)
wSaveScanCode = wLastScanCode;
if(wSaveScanCode == 0x4b)
wParam = '|';
break;
case(VK_UP):
wLastScanCode = GetLastScanCode()&0x7f;
if(wLastScanCode == 0x48 || wLastScanCode == 0x29)
wSaveScanCode = wLastScanCode;
if(wSaveScanCode == 0x48)
wParam = '~';
break;
case(VK_DOWN):
wLastScanCode = GetLastScanCode()&0x7f;
if(wLastScanCode == 0x50 || wLastScanCode == 0x4a)
wSaveScanCode = wLastScanCode;
if(wSaveScanCode == 0x50)
wParam = '`';
break;
case('-'):
wLastScanCode = GetLastScanCode()&0x7f;
if(wLastScanCode == 0x58 || wLastScanCode == 0x0c)
wSaveScanCode = wLastScanCode;
if(wSaveScanCode == 0x58)
wParam = VK_HOME;
break;
}
}
InsertKeyboardMessage(message, wParam, lParam);
}
#ifdef HASHHITTEST
char b1[80];
extern int ghashhits;
extern int ghashmisses;
extern int ghashnotpresent;
extern int gnohashnotpresent;
#endif
extern VOID Do_Read_Ini_File(void);
/*
** Main program
*/
void cdecl main(int argc, char *argv[])
{
UnReferenced(argc) ;
UnReferenced(argv) ;
/* Get information on the country we're in... */
GetInternationalData();
/* In case we bail out because of low memory situations, we want to
* restore the screen to appropriate state before quitting in case we
* modified the screen mode.
*/
gfScreenModeChanged = FALSE;
/* The following field is used to determine whether to bail out or not in
* a low memory situation. If we run out of memory when we are initializing
* we will bail out.
*/
gfStillInitializing = TRUE;
/* used to de-install swap handler on exitting the shell */
gfSwapHandlerInstalled = FALSE ;
VersionCheck() ;
SetUpStartUpDirectory();
/*
* parse the shell.ini file
*/
Do_Read_Ini_File();
/* if we are returning from a program, we must pause before
* we initialize the screen so the user can read the output
* of the last program
*/
PauseBeforeScreenErase();
if (!InitializeShell())
DoExit();
//if(IsTandy1000) check is disfunctional, so we used an ini switch
if(Get_KeyWord_Assignment(TK_SAVESTATE,TK_TANDY1000) == TK_ENABLED)
HookKeyboardMessage(TRUE, Tandy1000KeyboardHook);
/* Allocate memory for the OutOfMemory Dialog Box HCAB structure now.
* When we are actually, out of memory, we may not be able to allocate
* enuf memory to put up the dialog box. This way, we are guaranteed to
* atleast be able to say: "Out Of Memory" in a neat dialog box!
*/
if (!AllocateHcabForOutOfMem())
DoExit();
/* Set up the collating table for sorts to be done later! */
SetCollatingTable() ;
/* If we have to use the collating sort, set sort functions to the
* collating sorts!
*/
if (!FDoQuickCompare())
{
SortFnArr[SORT_NAME] = name_cmp ;
SortFnArr[SORT_EXT] = ext_cmp ;
/* This is the variable that is used to call the sort function! Update
* it correctly.
*/
if (*SortCmp == quick_name_cmp)
{
*SortCmp = name_cmp ;
}
else if (*SortCmp == quick_ext_cmp)
{
*SortCmp = ext_cmp ;
}
}
InstallSwapHandler() ;
/*
* WARNING taskmaninit must happen first!
*/
DeleteBatchFile();
gfSwapHandlerInstalled = TRUE ;
gfStillInitializing = FALSE;
#ifdef HASHHITTEST
ErrorCrit = 34;
itoa(ghashhits, b1, 10);
strcat(b1, "\n");
itoa(ghashmisses, b1+strlen(b1), 10);
strcat(b1, "\n");
itoa(gnohashnotpresent, b1+strlen(b1), 10);
ShellMessageBox("HASH RESULTS", b1);
ErrorCrit = 0xFF;
#endif
/*
* Handle messages (keyboard,mouse)
*/
MainIdle();
while (1)
{
if (PeekMessage(&msg))
{
DispatchMessage(&msg);
}
else
{
MainIdle();
}
fPollKeyboard=TRUE;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?