int PASCAL WinMain( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show ) { char buffer[PATH_MAX]; #if !defined( __WATCOMC__ ) && defined( __NT__ ) _argc = __argc; _argv = __argv; #endif EXEName = _cmdname( buffer ); InstanceHandle = inst; showHow = show; prev = prev; cmdline = cmdline; InitMem(); #ifndef __NT__ if( prev != NULL && !HasShare() ) { MessageBox( NULLHANDLE, "SHARE.EXE must be loaded before starting Windows in order to run multiple instances of the editor", EditorName, MB_OK ); MyGetInstanceData( (unsigned short) prev, (void near *) &Root, sizeof( Root ) ); SetFocus( Root ); return( 0 ); } #endif Comspec = getenv( "COMSPEC" ); #ifdef __NT__ VarAddGlobalStr( "OS", "winnt" ); #else VarAddGlobalStr( "OS", "win" ); #endif SetConfigFileName( CFG_NAME ); ReadProfile(); ShowStartupDialog(); initApplication(); if( !initInstance() ) { return( 0 ); } InitializeEditor(); SetSaveConfig(); if( !BAD_ID( CurrentWindow ) ) { SetFocus( Root ); } SetWindowCursorForReal(); ResizeRoot(); EditMain(); FiniMem(); return( 0 ); } /* WinMain */
/* * GetInitialFileName - prompt the user for an initial file */ char *GetInitialFileName( void ) { char *path = MemAlloc( FILENAME_MAX ); char *ptr; vi_rc rc; CloseStartupDialog(); path[0] = '\0'; rc = SelectFileOpen( "", &path, NULL, false ); ShowStartupDialog(); if( rc == ERR_NO_ERR && path[0] != '\0' ) { ptr = DupString( path ); } else { ptr = NULL; } MemFree( path ); return( ptr ); } /* GetInitialFileName */
/* * LostFileCheck - check if there are any lost files out there */ bool LostFileCheck( void ) { char path[FILENAME_MAX]; vi_key key; char ch; int off; int handle; MakeTmpPath( path, lockFileName ); off = strlen( path ) - 5; for( ch = START_CHAR; ch <= END_CHAR; ch++ ) { path[off] = ch; handle = sopen3( path, O_RDONLY | O_TEXT, SH_DENYRW ); if( handle > 0 ) { MakeTmpPath( path, checkFileName ); path[off] = ch; if( access( path, F_OK ) == -1 ) { MakeTmpPath( path, lockFileName ); path[off] = ch; close( handle ); handle = -1; remove( path ); } else { break; } } } if( handle > 0 ) { close( handle ); if( !EditFlags.RecoverLostFiles ) { if( !EditFlags.IgnoreLostFiles ) { #ifdef __WIN__ CloseStartupDialog(); key = GetAutosaveResponse(); handleKey( key ); ShowStartupDialog(); return( TRUE ); #else SetPosToMessageLine(); MyPrintf( "Files have been lost since your last session, do you wish to:\n" ); MyPrintf( "\ti)gnore\n\tr)ecover\n\tq)uit\n" ); for( ;; ) { key = GetKeyboard(); if( handleKey( key ) ) { return( TRUE ); } } #endif } else { remove( path ); return( FALSE ); } } } else { if( EditFlags.RecoverLostFiles ) { EditFlags.RecoverLostFiles = FALSE; EditFlags.NoInitialFileLoad = FALSE; } } return( FALSE ); } /* LostFileCheck */