/* * selectTag - select a tag from a list of possible tags */ static vi_rc selectTag( FILE *f, char *str, char *buff, char *fname ) { int tagcnt; char **taglist; int i; int whichtag; char tag[MAX_STR]; tagcnt = 0; taglist = NULL; for( ;; ) { RemoveLeadingSpaces( buff ); taglist = MemReAlloc( taglist, sizeof( char * ) * (tagcnt + 1) ); AddString( &taglist[tagcnt], buff ); i = 0; while( !isspace( taglist[tagcnt][i] ) ) { i++; } taglist[tagcnt][i] = 0; tagcnt++; if( fgets( buff, MAX_STR, f ) == NULL ) { break; } if( NextWord1( buff, tag ) <= 0 ) { continue; } if( EditFlags.IgnoreTagCase ) { i = stricmp( str, tag ); } else { i = strcmp( str, tag ); } if( i ) { break; } } fclose( f ); if( EditFlags.TagPrompt && EditFlags.WindowsStarted && tagcnt > 1 ) { whichtag = PickATag( tagcnt, taglist, str ); if( whichtag < 0 ) { return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } } else { whichtag = 0; } taglist[whichtag][strlen( taglist[whichtag] )] = ' '; strcpy( buff, taglist[whichtag] ); MemFreeList( tagcnt, taglist ); if( NextWord1( buff, fname ) <= 0 ) { return( ERR_INVALID_TAG_FOUND ); } buff[strlen( buff ) - 1] = 0; RemoveLeadingSpaces( buff ); if( buff[0] == 0 ) { return( ERR_INVALID_TAG_FOUND ); } return( ERR_NO_ERR ); } /* selectTag */
/* * DeleteResidentScripts - delete the resident list */ void DeleteResidentScripts( void ) { resident *tmp, *tmp_next; sfile *curr, *next; for( tmp = resHead; tmp != NULL; ) { tmp_next = tmp->next; MemFreeList( tmp->lab.cnt, tmp->lab.name ); MemFree( tmp->lab.pos ); curr = tmp->sf; while( curr != NULL ) { next = curr->next; MemFree( curr->data ); MemFree( curr->arg1 ); MemFree( curr->arg2 ); MemFree( curr ); curr = next; } MemFree( tmp->fn ); MemFree( tmp ); tmp = tmp_next; } } /* DeleteResidentScripts */
WINEXPORT BOOL CALLBACK GrepListProc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) { static char **fileList; static int fileCount; HWND list_box; char tmp[MAX_STR]; WORD cmd; switch( msg ) { case WM_INITDIALOG: list_box = GetDlgItem( dlg, ID_FILE_LIST ); SendMessage( list_box, WM_SETFONT, (WPARAM)FontHandle( dirw_info.text.font ), 0L ); MySprintf( tmp, "Files Containing \"%s\"", sString ); SetWindowText( dlg, tmp ); fileList = (char **)MemAlloc( sizeof( char * ) * MAX_FILES ); fileCount = initList( list_box, (char *)lparam, fileList ); if( fileCount == 0 ) { /* tell him that there are no matches and close down? */ Message1( "String \"%s\" not found", sString ); EndDialog( dlg, DO_NOT_CLEAR_MESSAGE_WINDOW ); } else { SendMessage( list_box, LB_SETCURSEL, 0, 0L ); BringWindowToTop( dlg ); SetFocus( dlg ); } break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case ID_FILE_LIST: if( GET_WM_COMMAND_CMD( wparam, lparam ) == LBN_DBLCLK ) { getOneFile( dlg, fileList, &fileCount, TRUE ); } break; case ID_EDIT: case ID_GOTO: getOneFile( dlg, fileList, &fileCount, cmd == ID_GOTO ); break; case ID_GETALL: getAllFiles( dlg, fileList, &fileCount ); break; case IDCANCEL: EndDialog( dlg, ERR_NO_ERR ); return( TRUE ); } break; case WM_DESTROY: MemFreeList( fileCount, fileList ); break; } return( FALSE ); } /* GrepListProc */
/* * finiSource - release language variables */ static void finiSource( labels *lab, vlist *vl, sfile *sf, undo_stack *atomic ) { sfile *curr, *tmp; info *cinfo; if( lab != NULL ) { MemFreeList( lab->cnt, lab->name ); MemFree( lab->pos ); } VarListDelete( vl ); curr = sf; while( curr != NULL ) { tmp = curr->next; MemFree( curr->data ); MemFree( curr->arg1 ); MemFree( curr->arg2 ); MemFree( curr ); curr = tmp; } /* * make sure this undo stack is still around */ if( atomic != NULL ) { for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { if( atomic == cinfo->UndoStack ) { break; } } if( cinfo != NULL ) { EndUndoGroup( atomic ); } } } /* finiSource */
/* * EditFileFromList - edit from file in current active list */ vi_rc EditFileFromList( void ) { int i, tmp, j, n = 0, fcnt; window_id optwin; bool repeat = true; info *cinfo; char **list, modchar; vi_key evlist[4] = { VI_KEY( F1 ), VI_KEY( F2 ), VI_KEY( F3 ), VI_KEY( DUMMY ) }; bool show_lineno; window_info wi; selectitem si; vi_rc rc; /* * set up options for file list */ memcpy( &wi, &extraw_info, sizeof( window_info ) ); wi.x1 = 2; wi.x2 = 19; rc = DisplayExtraInfo( &wi, &optwin, fileOpts, NUM_OPTS ); if( rc != ERR_NO_ERR ) { return( rc ); } while( repeat ) { /* * set up for this pass */ repeat = false; MoveWindowToFrontDammit( optwin, false ); SaveCurrentInfo(); /* * allocate a buffer for strings, add strings */ list = (char **) MemAlloc( GimmeFileCount() * sizeof( char * ) ); for( j = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next, ++j ) { list[j] = MemAlloc( strlen( cinfo->CurrentFile->name ) + 3 ); if( cinfo->CurrentFile->modified ) { modchar = '*'; } else { modchar = ' '; } MySprintf( list[j], "%c %s", modchar, cinfo->CurrentFile->name ); } fcnt = j; tmp = filelistw_info.y2; i = filelistw_info.y2 - filelistw_info.y1 + 1; if( filelistw_info.has_border ) { i -= 2; } if( j < i ) { filelistw_info.y2 -= ( i - j ); } show_lineno = true; /* * get file */ if( n + 1 > j ) { n = j - 1; } memset( &si, 0, sizeof( si ) ); si.wi = &filelistw_info; si.title = "Current Files"; si.list = list; si.maxlist = j; si.num = n; si.retevents = evlist; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = n + 1; si.eiw = optwin; rc = SelectItem( &si ); n = si.num; if( rc == ERR_NO_ERR ) { if( n >= 0 ) { cinfo = InfoHead; for( j = 0; j < n; ++j ) { cinfo = cinfo->next; } BringUpFile( cinfo, true ); switch( si.event ) { case VI_KEY( DUMMY ): case VI_KEY( F1 ): break; case VI_KEY( F2 ): rc = NextFile(); if( rc <= ERR_NO_ERR ) { repeat = true; } break; case VI_KEY( F3 ): rc = SaveAndExit( NULL ); if( rc <= ERR_NO_ERR ) { repeat = true; } break; } } } filelistw_info.y2 = tmp; MemFreeList( fcnt, list ); } /* * get rid of option stuff */ CloseAWindow( optwin ); return( rc ); } /* EditFileFromList */
/* * EditFile - read a file into text */ vi_rc EditFile( char *name, bool dammit ) { char *fn, **list, *currfn; int i, cnt, ocnt; int j, len; window_id wn = NO_WINDOW; char cdir[FILENAME_MAX]; info *ci, *il; bool usedir = false; char mask[FILENAME_MAX]; bool reset_dir; int index; char *altname = NULL; vi_rc rc; fn = MemAlloc( FILENAME_MAX ); /* * get file name */ strcpy( cdir, CurrentDirectory ); reset_dir = false; RemoveLeadingSpaces( name ); if( name[0] == '$' ) { EliminateFirstN( name, 1 ); usedir = true; } fn[0] = 0; // if( NextWord1( name, fn ) <= 0 ) if( GetStringWithPossibleQuote2( name, fn, false ) != ERR_NO_ERR ) { usedir = true; mask[0] = '*'; mask[1] = 0; } if( usedir ) { if( EditFlags.ExMode ) { MemFree( fn ); return( ERR_INVALID_IN_EX_MODE ); } len = strlen( fn ); if( len > 0 ) { i = len - 1; strcpy( mask, fn ); cnt = 0; while( i >= 0 ) { if( fn[i] == FILE_SEP ) { for( j = i + 1; j <= len; j++ ) { mask[j - (i + 1)] = fn[j]; } cnt = i; break; } i--; } fn[cnt] = 0; } if( fn[0] != 0 ) { rc = SelectFileOpen( fn, &fn, mask, true ); } else { #ifdef __WIN__ if( name[0] == '\0' ) { altname = MemAlloc( 1000 ); rc = SelectFileOpen( CurrentDirectory, &altname, mask, true ); NextWord1( altname, fn ); // if multiple, kill path if( isMultipleFiles( altname ) ) { NextWord1( altname, fn ); // get 1st name } } else { rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); } #else rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); #endif } if( altname ) { name = altname; } if( rc != ERR_NO_ERR || fn[0] == 0 ) { MemFree( fn ); SetCWD( cdir ); return( rc ); } } /* * loop through all files */ rc = ERR_NO_ERR; EditFlags.WatchForBreak = true; #ifdef __WIN__ ToggleHourglass( true ); #endif do { if( IsDirectory( fn ) ) { if( EditFlags.ExMode ) { rc = ERR_INVALID_IN_EX_MODE; reset_dir = true; break; } rc = SelectFileOpen( fn, &fn, "*", false ); if( rc != ERR_NO_ERR ) { reset_dir = true; break; } if( fn[0] == 0 ) { reset_dir = true; rc = ERR_NO_ERR; break; } } currfn = fn; ocnt = cnt = ExpandFileNames( currfn, &list ); if( !cnt ) { cnt = 1; } else { currfn = list[0]; } /* * loop through all expanded files */ index = 1; while( cnt > 0 ) { cnt--; /* * quit current file if ! specified, else just save current state */ if( dammit ) { ci = InfoHead; if( CurrentInfo == ci ) { ci = ci->next; } RemoveFromAutoSaveList(); #ifdef __WIN__ CloseAChildWindow( CurrentWindow ); #else CloseAWindow( CurrentWindow ); #endif FreeUndoStacks(); FreeMarkList(); FreeEntireFile( CurrentFile ); MemFree( DeleteLLItem( (ss **)&InfoHead, (ss **)&InfoTail, (ss *)CurrentInfo ) ); CurrentInfo = NULL; CurrentWindow = NO_WINDOW; } else { ci = CurrentInfo; SaveCurrentInfo(); wn = CurrentWindow; } /* * see if new file is already being edited */ SaveCurrentInfo(); for( il = InfoHead; il != NULL; il = il->next ) { if( SameFile( il->CurrentFile->name, currfn ) ) { break; } if( strcmp( CurrentDirectory, il->CurrentFile->home ) ) { /* directory has changed -- check with full path * note that this will fail if an absolute path * was specified thus we do the regular check first */ char path[FILENAME_MAX]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( il->CurrentFile->name, drive, dir, fname, ext ); if( !strlen( drive ) ) { _splitpath( il->CurrentFile->home, drive, NULL, NULL, NULL ); } if( !strlen( dir ) ) { _splitpath( il->CurrentFile->home, NULL, dir, NULL, NULL ); } else if( dir[0] != '\\' ) { char dir2[_MAX_DIR]; _splitpath( il->CurrentFile->home, NULL, dir2, NULL, NULL ); strcat( dir2, dir ); strcpy( dir, dir2 ); } _makepath( path, drive, dir, fname, ext ); if( SameFile( path, currfn ) ) { break; } } } if( il != NULL ) { BringUpFile( il, true ); } else { /* * file not edited, go get it */ rc = NewFile( currfn, false ); if( rc != ERR_NO_ERR && rc != NEW_FILE ) { RestoreInfo( ci ); DCDisplayAllLines(); break; } if( !dammit ) { InactiveWindow( wn ); } if( EditFlags.BreakPressed ) { break; } } if( cnt > 0 ) { currfn = list[index]; index++; } } if( ocnt > 0 ) { MemFreeList( ocnt, list ); } if( EditFlags.BreakPressed ) { ClearBreak(); break; } } while( NextWord1( name, fn ) > 0 ); if( altname ) { MemFree( altname ); } MemFree( fn ); #ifdef __WIN__ ToggleHourglass( false ); #endif EditFlags.WatchForBreak = false; if( reset_dir ) { SetCWD( cdir ); } return( rc ); } /* EditFile */
/* * Set - set editor control variable */ vi_rc Set( char *name ) { char fn[MAX_STR]; vi_rc rc = ERR_NO_ERR; int j, i; #ifndef VICOMP #ifndef __WIN__ int tmp, tc; char **vals = NULL; char **list; int longest; #endif #endif /* * get item to set */ #ifndef VICOMP msgFlag = FALSE; if( !EditFlags.ScriptIsCompiled ) { #endif RemoveLeadingSpaces( name ); j = strlen( name ); for( i = 0; i < j; i++ ) { if( name[i] == '=' || name[i] == ',' ) { name[i] = ' '; } } #ifndef VICOMP } #endif if( NextWord1( name, fn ) <=0 ) { #ifndef VICOMP if( !EditFlags.WindowsStarted ) { return( ERR_NO_ERR ); } #ifndef __WIN__ tc = getSetInfo( &vals, &list, &longest ); tmp = setw_info.y2; i = setw_info.y2 - setw_info.y1 + 1; if( setw_info.has_border ) { i -= 2; } if( tc < i ) { setw_info.y2 -= (i - tc); } rc = SelectItemAndValue( &setw_info, "Settings", list, tc, SettingSelected, 1, vals, longest + 3 ); setw_info.y2 = tmp; MemFreeList( tc, vals ); MemFreeList( tc, list ); ReDisplayScreen(); #endif #endif /* VICOMP */ return( rc ); } else { #ifndef VICOMP if( !EditFlags.Starting) { msgFlag = TRUE; } #endif do { #ifndef VICOMP if( !EditFlags.ScriptIsCompiled ) { #endif if( tolower( fn[0] ) == 'n' && tolower( fn[1] ) == 'o' ) { EliminateFirstN( fn, 2 ); i = -1; } else { i = 1; } j = Tokenize( SetTokens1, fn, FALSE ); if( j == TOK_INVALID ) { j = Tokenize( SetTokens2a, fn, FALSE ); if( j == TOK_INVALID ) { j = Tokenize( SetTokens2, fn, FALSE ); if( j == TOK_INVALID ) { return( ERR_INVALID_SET_COMMAND ); } } j += SET1_T_; } j *= i; #ifndef VICOMP } else { j = atoi( fn ); } #endif i = TRUE; rc = processSetToken( j, name, &i, FALSE ); if( rc > ERR_NO_ERR ) { break; } RemoveLeadingSpaces( name ); } while( NextWord1( name, fn ) > 0 ); #ifndef VICOMP if( msgFlag ) { putMessage(); } #endif return( rc ); } } /* Set */
/* * doInitializeEditor - do just that */ static void doInitializeEditor( int argc, char *argv[] ) { int i, arg, cnt, ocnt, startcnt = 0; srcline sline; int k, j; char tmp[FILENAME_MAX], c[1]; char buff[MAX_STR], file[MAX_STR], **list; char cmd[MAX_STR * 2]; char *parm; char *startup[MAX_STARTUP]; char *startup_parms[MAX_STARTUP]; vi_rc rc; vi_rc rc1; /* * Make sure WATCOM is setup and if it is not, make a best guess. */ watcom_setup_env(); /* * If EDPATH is not set, use system default %WATCOM%\EDDAT. */ if( getenv( "EDPATH" ) == NULL ) { char *watcom; watcom = getenv( "WATCOM" ); if( watcom != NULL ) { char edpath[FILENAME_MAX]; sprintf( edpath, "%s%c%s", watcom, FILE_SEP, "eddat" ); if( setenv( "EDPATH", edpath, 0 ) != 0 ) { /* * Bail out silently on error, as we will get error message later on. */ } } } /* * misc. set up */ MaxMemFree = MemSize(); StaticStart(); FTSInit(); BoundDataInit(); EditFlags.Starting = true; InitCommandLine(); ChkExtendedKbd(); SSInitBeforeConfig(); GetCWD1( &HomeDirectory ); GetCWD1( &CurrentDirectory ); SetCWD( HomeDirectory ); if( cfgFN == NULL ){ cfgFN = DupString( CFG_NAME ); } checkFlags( &argc, argv, startup, startup_parms, &startcnt ); ScreenInit(); SetWindowSizes(); EditFlags.ClockActive = false; SetInterrupts(); #ifdef __WIN__ InitClrPick(); InitFtPick(); SubclassGenericInit(); CursorOp( COP_INIT ); #else InitColors(); #endif InitSavebufs(); InitKeyMaps(); /* * initial configuration */ EditVars.Majick = MemStrDup( "()~@" ); EditVars.FileEndString = MemStrDup( "[END_OF_FILE]" ); MatchInit(); SetGadgetString( NULL ); WorkLine = MemAlloc( sizeof( line ) + EditVars.MaxLine + 2 ); WorkLine->len = -1; sline = 0; if( cfgFN[0] != 0 ) { c[0] = 0; rc = Source( cfgFN, c, &sline ); if( rc == ERR_FILE_NOT_FOUND ) { #ifdef __WIN__ CloseStartupDialog(); MessageBox( (HWND)NULLHANDLE, "Could not locate configuration information; please make sure your EDPATH environment variable is set correctly", EditorName, MB_OK ); ExitEditor( -1 ); #else rc = ERR_NO_ERR; #endif } } else { rc = ERR_NO_ERR; } if( wantNoReadEntireFile ) { EditFlags.ReadEntireFile = false; } VerifyTmpDir(); while( LostFileCheck() ); HookScriptCheck(); if( EditFlags.Quiet ) { EditFlags.Spinning = false; EditFlags.Clock = false; } ExtendedMemoryInit(); /* * more misc. setup */ if( EditVars.WordDefn == NULL ) { EditVars.WordDefn = DupString( &WordDefnDefault[6] ); InitWordSearch( EditVars.WordDefn ); } if( EditVars.WordAltDefn == NULL ) { EditVars.WordAltDefn = DupString( WordDefnDefault ); } if( EditVars.TagFileName == NULL ) { EditVars.TagFileName = DupString( "tags" ); } DotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) ); AltDotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) ); DotCmd = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) ); SwapBlockInit( EditVars.MaxSwapBlocks ); ReadBuffer = MemAlloc( MAX_IO_BUFFER + 6 ); WriteBuffer = MemAlloc( MAX_IO_BUFFER + 6 ); FindHistInit( EditVars.FindHist.max ); FilterHistInit( EditVars.FilterHist.max ); CLHistInit( EditVars.CLHist.max ); LastFilesHistInit( EditVars.LastFilesHist.max ); GetClockStart(); GetSpinStart(); SelRgnInit(); SSInitAfterConfig(); #if defined( VI_RCS ) ViRCSInit(); #endif /* * create windows */ StartWindows(); InitMouse(); rc1 = NewMessageWindow(); if( rc1 != ERR_NO_ERR ) { FatalError( rc1 ); } DoVersion(); rc1 = InitMenu(); if( rc1 != ERR_NO_ERR ) { FatalError( rc1 ); } EditFlags.SpinningOurWheels = true; EditFlags.ClockActive = true; EditFlags.DisplayHold = true; rc1 = NewStatusWindow(); if( rc1 != ERR_NO_ERR ) { FatalError( rc1 ); } EditFlags.DisplayHold = false; MaxMemFreeAfterInit = MemSize(); /* * look for a tag: if there is one, set it up as the file to start */ EditFlags.WatchForBreak = true; if( cTag != NULL && !EditFlags.NoInitialFileLoad ) { #if defined( __NT__ ) && !defined( __WIN__ ) { if( !EditFlags.Quiet ) { SetConsoleActiveScreenBuffer( OutputHandle ); } } #endif rc1 = LocateTag( cTag, file, buff ); cFN = file; if( rc1 != ERR_NO_ERR ) { if( rc1 == ERR_TAG_NOT_FOUND ) { Error( GetErrorMsg( rc1 ), cTag ); ExitEditor( 0 ); } FatalError( rc1 ); } } /* * start specified file(s) */ cmd[0] = 'e'; cmd[1] = 0; arg = argc - 1; k = 1; while( !EditFlags.NoInitialFileLoad ) { if( cFN == nullFN && !EditFlags.UseNoName ) { break; } #ifdef __NT__ { int k2; int arg2; char path[_MAX_PATH]; int found; int fd; size_t len; size_t len1; char *p; /* * check for the existence of a file name containing spaces, and open it if * there is one */ len = _MAX_PATH - 1; found = 0; p = path; arg2 = arg; for( k2 = k; argv[k2] != NULL; ) { len1 = strlen( argv[k2] ); if( len1 > len ) break; memcpy( p, argv[k2], len1 ); p += len1; *p = '\0'; len -= len1; --arg2; ++k2; fd = open( path, O_RDONLY ); if( fd != -1 ) { close( fd ); k = k2; arg = arg2; found = 1; break; } *p++ = ' '; } if( found ) { #ifndef __UNIX__ len1 = strlen( path ); if( path[len1 - 1] == '.' ) path[len1 - 1] = '\0'; #endif rc1 = NewFile( path, false ); if( rc1 != ERR_NO_ERR ) { FatalError( rc1 ); } cFN = argv[k]; if( arg < 1 ) { break; } continue; } } #endif strcat( cmd, SingleBlank ); strcat( cmd, cFN ); ocnt = cnt = ExpandFileNames( cFN, &list ); if( cnt == 0 ) { cnt = 1; } else { cFN = list[0]; } for( j = 0; j < cnt; j++ ) { rc1 = NewFile( cFN, false ); if( rc1 != ERR_NO_ERR && rc1 != NEW_FILE ) { FatalError( rc1 ); } if( EditFlags.BreakPressed ) { break; } if( cnt > 0 && j < cnt - 1 ) { cFN = list[j + 1]; } } if( ocnt > 0 ) { MemFreeList( ocnt, list ); } if( EditFlags.BreakPressed ) { ClearBreak(); break; } k++; arg--; if( cTag != NULL || arg < 1 ) { break; } cFN = argv[k]; } if( EditFlags.StdIOMode ) { rc1 = NewFile( "stdio", false ); if( rc1 != ERR_NO_ERR ) { FatalError( rc1 ); } } EditFlags.WatchForBreak = false; EditFlags.Starting = false; /* * if there was a tag, do the appropriate search */ if( cTag != NULL && !EditFlags.NoInitialFileLoad ) { if( buff[0] != '/' ) { i = atoi( buff ); rc1 = GoToLineNoRelCurs( i ); } else { rc1 = FindTag( buff ); } if( rc1 > 0 ) { Error( GetErrorMsg( rc1 ) ); } } /* * try to run startup file */ if( EditFlags.RecoverLostFiles ) { startcnt = 0; } for( i = 0; i < startcnt; i++ ) { GetFromEnv( startup[i], tmp ); ReplaceString( &cfgFN, tmp ); if( cfgFN[0] != 0 ) { if( startup_parms[i] != NULL ) { parm = startup_parms[i]; } else { c[0] = 0; parm = c; } #if defined( __NT__ ) && !defined( __WIN__ ) { if( !EditFlags.Quiet ) { SetConsoleActiveScreenBuffer( OutputHandle ); } } #endif sline = 0; rc = Source( cfgFN, parm, &sline ); } } if( rc > ERR_NO_ERR ) { Error( "%s on line %u of \"%s\"", GetErrorMsg( rc ), sline, cfgFN ); } if( argc == 1 ) { LoadHistory( NULL ); } else { LoadHistory( cmd ); } if( EditVars.GrepDefault == NULL ) { EditVars.GrepDefault = DupString( "*.(c|h)" ); } if( goCmd[0] != 0 ) { KeyAddString( goCmd ); } if( keysToPush != NULL ) { KeyAddString( keysToPush ); } #ifdef __WIN__ if( lineToGoTo != 0 ) { SetCurrentLine( lineToGoTo ); NewCursor( CurrentWindow, EditVars.NormalCursorType ); } #endif AutoSaveInit(); HalfPageLines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) / 2 - 1; #if defined( _M_X64 ) VarAddGlobalStr( "OSX64", "1" ); #elif defined( _M_IX86 ) && !defined( _M_I86 ) VarAddGlobalStr( "OS386", "1" ); #endif if( EditVars.StatusString == NULL ) { EditVars.StatusString = DupString( "L:$6L$nC:$6C" ); } UpdateStatusWindow(); #ifdef __WIN__ if( CurrentInfo == NULL ) { // no file loaded - screen is disconcertenly empty - reassure DisplayFileStatus(); } #endif NewCursor( CurrentWindow, EditVars.NormalCursorType ); #if defined( __NT__ ) && !defined( __WIN__ ) { SetConsoleActiveScreenBuffer( OutputHandle ); } #endif } /* doInitializeEditor */
/* * doGREP - perform GREP on a specified file */ static vi_rc doGREP( char *dirlist ) { int i, clist, n = 0; window_id wn, optwin; char **list; window_info tw, wi; vi_key evlist[4] = { VI_KEY( F1 ), VI_KEY( F2 ), VI_KEY( F3 ), VI_KEY( DUMMY ) }; int s, e, cnt; bool show_lineno; selectitem si; vi_rc rc; /* * prepare list array */ list = (char **) MemAlloc( sizeof( char *) * MAX_FILES ); /* * create info. window */ rc = NewWindow( &wn, dirw_info.x1, dirw_info.y1 + 4, dirw_info.x2, dirw_info.y1 + 6, 1, dirw_info.border_color1, dirw_info.border_color2, &dirw_info.text ); if( rc != ERR_NO_ERR ) { MemFree( list ); return( rc ); } WindowTitle( wn, "File Being Searched" ); clist = initList( wn, dirlist, list ); /* * got list of matches, so lets select an item, shall we? */ CloseAWindow( wn ); rc = ERR_NO_ERR; if( clist ) { /* * define display window dimensions */ memcpy( &tw, &dirw_info, sizeof( window_info ) ); tw.x1 = 14; tw.x2 = EditVars.WindMaxWidth - 2; i = tw.y2 - tw.y1 + 1; if( tw.has_border ) { i -= 2; } if( clist < i ) { tw.y2 -= ( i - clist ); } if( clist > i ) { show_lineno = TRUE; } else { show_lineno = FALSE; } /* * build options window */ memcpy( &wi, &extraw_info, sizeof( window_info ) ); wi.x1 = 0; wi.x2 = 13; rc = DisplayExtraInfo( &wi, &optwin, EditOpts, NumEditOpts ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * process selections */ for( ;; ) { if( n + 1 > clist ) { n = clist - 1; } memset( &si, 0, sizeof( si ) ); si.wi = &tw; si.title = "Files With Matches"; si.list = list; si.maxlist = clist; si.num = n; si.retevents = evlist; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = n + 1; si.eiw = optwin; rc = SelectItem( &si ); n = si.num; if( rc != ERR_NO_ERR || n < 0 ) { break; } if( si.event == VI_KEY( F3 ) ) { s = 0; e = clist - 1; } else { s = e = n; } for( cnt = s; cnt <= e; cnt++ ) { rc = getFile( list[cnt] ); if( rc != ERR_NO_ERR ) { break; } } if( rc != ERR_NO_ERR || si.event == VI_KEY( DUMMY ) || si.event == VI_KEY( F1 ) || si.event == VI_KEY( F3 ) ) { break; } MemFree( list[n] ); for( i = n; i < clist - 1; i++ ) { list[i] = list[i + 1]; } clist--; if( clist == 0 ) { break; } MoveWindowToFrontDammit( optwin, FALSE ); } CloseAWindow( optwin ); } else if( rc == ERR_NO_ERR ) { Message1( "String \"%s\" not found", sString ); rc = DO_NOT_CLEAR_MESSAGE_WINDOW; } /* * cleanup */ MemFreeList( clist, list ); return( rc ); } /* DoFGREP */
WINEXPORT BOOL CALLBACK GrepListProc95( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) { static char **fileList; static int fileCount; HWND list_box; char tmp[MAX_STR]; WORD cmd; LVCOLUMN lvc; LVITEM lvi; RECT rc; switch( msg ) { case WM_INITDIALOG: list_box = GetDlgItem( dlg, ID_FILE_LIST ); SendMessage( list_box, WM_SETFONT, (WPARAM)FontHandle( dirw_info.text.font ), 0L ); MySprintf( tmp, "Files Containing \"%s\"", sString ); SetWindowText( dlg, tmp ); rc.left = 0; rc.right = 70; MapDialogRect( dlg, &rc ); lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.cx = rc.right; lvc.pszText = "File Name"; lvc.iSubItem = 0; SendMessage( list_box, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc ); lvc.cx = rc.right * 3; lvc.pszText = "Line"; lvc.iSubItem = 1; SendMessage( list_box, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc ); fileList = (char **)MemAlloc( sizeof( char * ) * MAX_FILES ); fileCount = initList( list_box, (char *)lparam, fileList ); if( fileCount == 0 ) { Message1( "String \"%s\" not found", sString ); EndDialog( dlg, DO_NOT_CLEAR_MESSAGE_WINDOW ); } else { lvi.stateMask = LVIS_SELECTED; lvi.state = LVIS_SELECTED; SendMessage( list_box, LVM_SETITEMSTATE, 0, (LPARAM)&lvi ); BringWindowToTop( dlg ); SetFocus( dlg ); } break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case ID_EDIT: case ID_GOTO: getOneFile( dlg, fileList, &fileCount, cmd == ID_GOTO ); break; case ID_GETALL: getAllFiles( dlg, fileList, &fileCount ); break; case IDCANCEL: EndDialog( dlg, ERR_NO_ERR ); return( TRUE ); } break; case WM_NOTIFY: if( ((NMHDR *)lparam)->code == NM_DBLCLK ) { getOneFile( dlg, fileList, &fileCount, TRUE ); } break; case WM_DESTROY: MemFreeList( fileCount, fileList ); break; } return( FALSE ); } /* GrepListProc95 */
/* * EditFile - read a file into text */ vi_rc EditFile( const char *name, bool dammit ) { char *fn, **list, *currfn; int i, cnt, ocnt; int j, len; window_id wid = NO_WINDOW; char cdir[FILENAME_MAX]; info *ci, *il; bool usedir = false; char mask[FILENAME_MAX]; bool reset_dir; int index; #ifdef __WIN__ char *altname = NULL; #endif vi_rc rc; fn = MemAlloc( FILENAME_MAX ); /* * get file name */ strcpy( cdir, CurrentDirectory ); reset_dir = false; name = SkipLeadingSpaces( name ); if( name[0] == '$' ) { ++name; usedir = true; } fn[0] = '\0'; // if( NextWord1FN( name, fn ) <= 0 ) if( GetStringWithPossibleQuote2( &name, fn, false ) != ERR_NO_ERR ) { usedir = true; mask[0] = '*'; mask[1] = '\0'; } if( usedir ) { if( EditFlags.ExMode ) { MemFree( fn ); return( ERR_INVALID_IN_EX_MODE ); } len = strlen( fn ); if( len > 0 ) { strcpy( mask, fn ); cnt = 0; for( i = len; i-- > 0; ) { if( fn[i] == FILE_SEP ) { for( j = i + 1; j <= len; j++ ) { mask[j - (i + 1)] = fn[j]; } cnt = i; break; } } fn[cnt] = '\0'; } if( fn[0] != '\0' ) { rc = SelectFileOpen( fn, &fn, mask, true ); } else { #ifdef __WIN__ if( name[0] == '\0' ) { altname = MemAlloc( 1000 ); rc = SelectFileOpen( CurrentDirectory, &altname, mask, true ); name = GetNextFileName( altname, fn ); // if multiple, kill path if( isMultipleFiles( name ) ) { name = GetNextFileName( name, fn ); // get 1st name } } else { rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); } #else rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); #endif } if( rc != ERR_NO_ERR || fn[0] == '\0' ) { MemFree( fn ); SetCWD( cdir ); return( rc ); } } /* * loop through all files */ rc = ERR_NO_ERR; EditFlags.WatchForBreak = true; #ifdef __WIN__ ToggleHourglass( true ); #endif do { if( IsDirectory( fn ) ) { if( EditFlags.ExMode ) { rc = ERR_INVALID_IN_EX_MODE; reset_dir = true; break; } rc = SelectFileOpen( fn, &fn, "*", false ); if( rc != ERR_NO_ERR ) { reset_dir = true; break; } if( fn[0] == '\0' ) { reset_dir = true; rc = ERR_NO_ERR; break; } } currfn = fn; ocnt = cnt = ExpandFileNames( currfn, &list ); if( !cnt ) { cnt = 1; } else { currfn = list[0]; } /* * loop through all expanded files */ index = 1; while( cnt > 0 ) { cnt--; /* * quit current file if ! specified, else just save current state */ if( dammit ) { ci = InfoHead; if( CurrentInfo == ci ) { ci = ci->next; } RemoveFromAutoSaveList(); #ifdef __WIN__ CloseAChildWindow( current_window_id ); #else CloseAWindow( current_window_id ); #endif FreeUndoStacks(); FreeMarkList(); FreeEntireFile( CurrentFile ); MemFree( DeleteLLItem( (ss **)&InfoHead, (ss **)&InfoTail, (ss *)CurrentInfo ) ); CurrentInfo = NULL; current_window_id = NO_WINDOW; } else { ci = CurrentInfo; SaveCurrentInfo(); wid = current_window_id; } /* * see if new file is already being edited */ SaveCurrentInfo(); for( il = InfoHead; il != NULL; il = il->next ) { if( SameFile( il->CurrentFile->name, currfn ) ) { break; } if( strcmp( CurrentDirectory, il->CurrentFile->home ) ) { /* directory has changed -- check with full path * note that this will fail if an absolute path * was specified thus we do the regular check first */ char path[FILENAME_MAX]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; size_t path_len; _splitpath( il->CurrentFile->name, drive, dir, fname, ext ); if( drive[0] == '\0' ) { _splitpath( il->CurrentFile->home, drive, NULL, NULL, NULL ); } strcpy( path, il->CurrentFile->home ); path_len = strlen( path ); if( path_len-- > 0 ) { #ifdef __UNIX__ if( path[path_len] != FILE_SEP ) { #else if( path[path_len] != DRV_SEP && path[path_len] != FILE_SEP ) { #endif strcat( path, FILE_SEP_STR ); } } if( dir[0] == '\0' ) { _splitpath( path, NULL, dir, NULL, NULL ); } else if( dir[0] != FILE_SEP ) { char dir2[_MAX_DIR]; _splitpath( path, NULL, dir2, NULL, NULL ); strcat( dir2, dir ); strcpy( dir, dir2 ); } _makepath( path, drive, dir, fname, ext ); if( SameFile( path, currfn ) ) { break; } } } if( il != NULL ) { BringUpFile( il, true ); } else { /* * file not edited, go get it */ rc = NewFile( currfn, false ); if( rc != ERR_NO_ERR && rc != NEW_FILE ) { RestoreInfo( ci ); DCDisplayAllLines(); break; } if( !dammit ) { InactiveWindow( wid ); } if( EditFlags.BreakPressed ) { break; } } if( cnt > 0 ) { currfn = list[index]; index++; } } if( ocnt > 0 ) { MemFreeList( ocnt, list ); } if( EditFlags.BreakPressed ) { ClearBreak(); break; } name = GetNextFileName( name, fn ); } while( *fn != '\0' ); #ifdef __WIN__ if( altname != NULL ) { MemFree( altname ); } #endif MemFree( fn ); #ifdef __WIN__ ToggleHourglass( false ); #endif EditFlags.WatchForBreak = false; if( reset_dir ) { SetCWD( cdir ); } return( rc ); } /* EditFile */ #ifndef __WIN__ static const char *fileOpts[] = { (const char *)"<F1> Go To", (const char *)"<F2> Quit", (const char *)"<F3> Save & Quit" }; static const vi_key fileopts_evlist[] = { VI_KEY( F1 ), VI_KEY( F2 ), VI_KEY( F3 ), VI_KEY( DUMMY ) }; /* * EditFileFromList - edit from file in current active list */ vi_rc EditFileFromList( void ) { int i, tmp, j, n = 0, fcnt; window_id wid; bool repeat = true; info *cinfo; char **list, modchar; bool show_lineno; window_info wi; selectitem si; vi_rc rc; /* * set up options for file list */ memcpy( &wi, &extraw_info, sizeof( window_info ) ); wi.area.x1 = 2; wi.area.x2 = 19; rc = DisplayExtraInfo( &wi, &wid, fileOpts, sizeof( fileOpts ) / sizeof( fileOpts[0] ) ); if( rc != ERR_NO_ERR ) { return( rc ); } while( repeat > 0 ) { /* * set up for this pass */ repeat = false; MoveWindowToFrontDammit( wid, false ); SaveCurrentInfo(); /* * allocate a buffer for strings, add strings */ list = (char **) MemAlloc( GimmeFileCount() * sizeof( char * ) ); for( j = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next, ++j ) { list[j] = MemAlloc( strlen( cinfo->CurrentFile->name ) + 3 ); if( cinfo->CurrentFile->modified ) { modchar = '*'; } else { modchar = ' '; } MySprintf( list[j], "%c %s", modchar, cinfo->CurrentFile->name ); } fcnt = j; tmp = filelistw_info.area.y2; i = filelistw_info.area.y2 - filelistw_info.area.y1 + 1; if( filelistw_info.has_border ) { i -= 2; } if( j < i ) { filelistw_info.area.y2 -= ( i - j ); } show_lineno = true; /* * get file */ if( n + 1 > j ) { n = j - 1; } memset( &si, 0, sizeof( si ) ); si.wi = &filelistw_info; si.title = "Current Files"; si.list = list; si.maxlist = j; si.num = n; si.retevents = fileopts_evlist; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = n + 1; si.eiw = wid; rc = SelectItem( &si ); n = si.num; if( rc == ERR_NO_ERR ) { if( n >= 0 ) { cinfo = InfoHead; for( j = 0; j < n; ++j ) { cinfo = cinfo->next; } BringUpFile( cinfo, true ); switch( si.event ) { case VI_KEY( DUMMY ): case VI_KEY( F1 ): break; case VI_KEY( F2 ): rc = NextFile(); if( rc <= ERR_NO_ERR ) { repeat = true; } break; case VI_KEY( F3 ): rc = SaveAndExit( NULL ); if( rc <= ERR_NO_ERR ) { repeat = true; } break; } } } filelistw_info.area.y2 = tmp; MemFreeList( fcnt, list ); } /* * get rid of option stuff */ CloseAWindow( wid ); return( rc ); } /* EditFileFromList */