/* * setWText - set window text color */ static vi_rc setWText( const char *data ) { int tc1, tc2, tc3; char token[MAX_STR]; if( wInfo == NULL ) { return( ERR_WIND_INVALID ); } data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc1 = atoi( token ); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc2 = atoi( token ); tc3 = FONT_DEFAULT; data = GetNextWord1( data, token ); if( *token != '\0' ) { tc3 = atoi( token ); } setStyle( &wInfo->text, tc1, tc2, tc3 ); /* want an SE_TEXT entry when SS turned off - steal it from here */ if( wInfo == &editw_info ) { setStyle( &SEType[SE_TEXT], tc1, tc2, tc3 ); } return( ERR_NO_ERR ); } /* setWText */
/* * setSyntaxStyle - set syntax style color */ static vi_rc setSyntaxStyle( syntax_element style, const char *data ) { int tc1, tc2, tc3; char token[MAX_STR]; if( wInfo != &editw_info ) { return( ERR_WIND_INVALID ); } data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc1 = atoi( token ); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc2 = atoi( token ); tc3 = FONT_DEFAULTBOLD; data = GetNextWord1( data, token ); if( *token != '\0' ) { tc3 = atoi( token ); } setStyle( &SEType[style], tc1, tc2, tc3 ); return( ERR_NO_ERR ); }
/* * setWHilite - set window hilighting color */ static vi_rc setWHilite( const char *data ) { int tc1, tc2, tc3; char token[MAX_STR]; if( wInfo == NULL ) { return( ERR_WIND_INVALID ); } data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc1 = atoi( token ); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } tc2 = atoi( token ); tc3 = FONT_DEFAULTBOLD; data = GetNextWord1( data, token ); if( *token != '\0' ) { tc3 = atoi( token ); } setStyle( &wInfo->hilight, tc1, tc2, tc3 ); return( ERR_NO_ERR ); } /* setWHilite */
/* * LocateCmd - parse a locate command (format: locate r,c[,len]) */ vi_rc LocateCmd( const char *data ) { char tmp[MAX_STR]; linenum r; int c; int len; #ifdef __WIN__ if( BAD_ID( current_window_id ) ) { return( ERR_INVALID_LOCATE ); } #endif data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_INVALID_LOCATE ); } r = atol( tmp ); data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_INVALID_LOCATE ); } c = atoi( tmp ); // real selection length while( isspace( *data ) ) { data++; } len = 0; if( *data != 0 ) { data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_INVALID_LOCATE ); } len = atoi( tmp ); } GoToLineNoRelCurs( r ); c = RealColumnOnCurrentLine( c ); GoToColumnOnCurrentLine( c + len ); #ifdef __WIN__ // likely only called by dde, which doesn't use event loop, // so must ensure cache ok and set cursor here DCInvalidateAllLines(); DCDisplayAllLines(); DCUpdate(); SetWindowCursor(); SetWindowCursorForReal(); #endif if( len > 0 ) { SetSelRegionCols( CurrentPos.line, c, c + len - 1 ); } return( ERR_NO_ERR ); } /* LocateCmd */
/* * DeleteFromToolBar - delete an item from the toolbar */ vi_rc DeleteFromToolBar( const char *data ) { char buffer[MAX_STR]; int index; ss *p; GetNextWord1( data, buffer ); index = atoi( buffer ); // index should be (base 1) index of tool in list if( index > 0 ) { p = toolBarHead; while( p != NULL ) { index -= 1; if( index == 0 ) { break; } p = p->next; } if( p ) { tool_item *item = (tool_item *)p; ToolBarDeleteItem( toolBar, item->id ); DeleteLLItem( &toolBarHead, &toolBarTail, p ); if( item->bmp != NULL ) { DeleteObject( item->bmp ); } return( ERR_NO_ERR ); } } return( ERR_INVALID_MENU ); } /* DeleteFromToolBar */
/* * SetSavebufNumber - set savebuf number from a string */ vi_rc SetSavebufNumber( const char *data ) { char st[MAX_STR]; SavebufNumber = NO_SAVEBUF; data = GetNextWord1( data, st ); if( st[0] != '\0' ) { if( st[1] != '\0' ) { Error( GetErrorMsg( ERR_INVALID_SAVEBUF), st[0] ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } #ifdef __WIN__ if( st[0] == '0' ) { SavebufNumber = CLIPBOARD_SAVEBUF; } else { #endif if( st[0] >= '1' && st[0] <= '9' ) { SavebufNumber = st[0] - '1'; } else if( st[0] >= 'a' && st[0] <= 'z' ) { SavebufNumber = st[0] - 'a' + MAX_SAVEBUFS; } else { Error( GetErrorMsg( ERR_INVALID_SAVEBUF), st[0] ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } #ifdef __WIN__ } #endif } return( ERR_NO_ERR ); } /* SetSavebufNumber */
static bool getByte( BYTE *dest, const char **data ) { char tmp[MAX_STR]; *data = GetNextWord1( *data, tmp ); if( *tmp == '\0' ) { return( false ); } *dest = (BYTE)atoi( tmp ); return( true ); }
static bool getInt( STUPIDNTINT *dest, const char **data ) { char tmp[MAX_STR]; *data = GetNextWord1( *data, tmp ); if( *tmp == '\0' ) { return( false ); } *dest = atoi( tmp ); return( true ); }
/* * GetHDDEDATA - get a HDDEDATA from a string */ static bool GetHDDEDATA( const char **str, HDDEDATA *res ) { char hdlstr[MAX_STR]; *str = GetNextWord1( *str, hdlstr ); if( *hdlstr == '\0' ) { return( false ); } *res = (HDDEDATA)strtoul( hdlstr, NULL, 10 ); return( true ); } /* GetHDDEDATA */
/* * getVarName - extract a variable name from a command */ static bool getVarName( const char **str, char *tmp1, vlist *vl ) { char tmp[MAX_INPUT_LINE]; *str = GetNextWord1( *str, tmp ); if( *tmp == '\0' ) { return( false ); } if( !VarName( tmp1, tmp, vl ) ) { return( false ); } return( true ); } /* getVarName */
/* * setWBorder - set window border */ static vi_rc setWBorder( const char *data ) { int btype, bc1, bc2; bool has_border; char token[MAX_STR]; if( wInfo == NULL ) { return( ERR_WIND_INVALID ); } data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } btype = atoi( token ); has_border = ( btype >= 0 ); data = GetNextWord1( data, token ); if( *token == '\0' ) { if( !has_border ) { wInfo->has_border = false; return( ERR_NO_ERR ); } return( ERR_INVALID_WINDOW_SETUP ); } bc1 = atoi( token ); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } bc2 = atoi( token ); wInfo->has_border = has_border; wInfo->border_color1 = bc1; wInfo->border_color2 = bc2; return( ERR_NO_ERR ); } /* setWBorder */
/* * setGenericAlias - define an alias/abbreviation */ static vi_rc setGenericAlias( const char *what, alias_list **head, alias_list **tail ) { alias_list *curr; char str[MAX_STR]; what = GetNextWord1( what, str ); if( *str == '\0' ) { return( ERR_INVALID_ALIAS ); } what = SkipLeadingSpaces( what ); /* * see if alias is already in list: if so, and there is expansion data, * then replace the data, else delete the item */ for( curr = *head; curr != NULL; curr = curr->next ) { if( strcmp( str, curr->alias ) == 0 ) { MemFree( curr->expand ); if( *what == '\0' ) { MemFree( curr->alias ); MemFree( DeleteLLItem( (ss **)head, (ss **)tail, (ss *)curr ) ); } else { curr->expand = DupString( what ); } } } /* * add the new item */ curr = MemAlloc( sizeof( alias_list ) ); curr->alias = DupString( str ); curr->expand = DupString( what ); AddLLItemAtEnd( (ss **)head, (ss **)tail, (ss *)curr ); Message1( "%s set to \"%s\"", str, what ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* setGenericAlias */
/* * ColorFind - find string and color it */ vi_rc ColorFind( const char *data, find_type findfl ) { vi_rc rc; int len; char *buff; i_mark pos; /* * get search string and flags */ buff = StaticAlloc(); GetNextWord1( data, buff ); if( *buff == '\0' ) { StaticFree( buff ); return( ERR_INVALID_FIND_CMD ); } /* * go get the match */ GoToLineNoRelCurs( 1 ); rc = GetFind( buff, &pos, &len, FINDFL_FORWARD | findfl ); if( rc == ERR_NO_ERR ) { pos.column += 1; JumpTo( &pos ); DCUpdate(); #ifndef __WIN__ // Windows selects instead HiliteAColumnRange( pos.line, pos.column, pos.column + len - 1 ); #endif EditFlags.ResetDisplayLine = true; } StaticFree( buff ); return( rc ); } /* ColorFind */
/* * setWDimension - set window dimension */ static vi_rc setWDimension( const char *data ) { int x1, y1, x2, y2; char token[MAX_STR]; jmp_buf jmpaddr; int i; int x, y; if( wInfo == NULL ) { return( ERR_WIND_INVALID ); } i = setjmp( jmpaddr ); if( i != 0 ) { return( (vi_rc)i ); } data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } StartExprParse( token, jmpaddr ); x1 = GetConstExpr(); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } StartExprParse( token, jmpaddr ); y1 = GetConstExpr(); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } StartExprParse( token, jmpaddr ); x2 = GetConstExpr(); data = GetNextWord1( data, token ); if( *token == '\0' ) { return( ERR_INVALID_WINDOW_SETUP ); } StartExprParse( token, jmpaddr ); y2 = GetConstExpr(); if( x1 < 0 || y1 < 0 ) { return( ERR_INVALID_WINDOW_SETUP ); } x = x2 - x1; y = y2 - y1; if( x < 0 || y < 0 ) { return( ERR_INVALID_WINDOW_SETUP ); } if( x >= EditVars.WindMaxWidth || y >= EditVars.WindMaxHeight ) { return( ERR_INVALID_WINDOW_SETUP ); } wInfo->x1 = x1; wInfo->y1 = y1; wInfo->x2 = x2; wInfo->y2 = y2; return( ERR_NO_ERR ); } /* setWDimension */
/* * ProcessEx - process an ex command */ vi_rc ProcessEx( linenum n1, linenum n2, bool n2f, int tkn, const char *data ) { vi_rc rc = ERR_INVALID_COMMAND, i; char word[MAX_STR]; linenum addr, tlines; fcb *cfcb; line *cline; fcb_list fcblist; GetNextWord1( data, word ); data = word; if( GetAddress( &data, &addr ) != ERR_NO_ERR ) { addr = -1; } tlines = n2 - n1 + 1; switch( tkn ) { case EX_T_APPEND: if( !EditFlags.ExMode ) { return( ERR_ONLY_VALID_IN_EX_MODE ); } if( !n2f ) { rc = Append( n1, true ); } break; case EX_T_CHANGE: if( !EditFlags.ExMode ) { return( ERR_ONLY_VALID_IN_EX_MODE ); } StartUndoGroup( UndoStack ); rc = DeleteLineRange( n1, n2, 0 ); if( rc != ERR_NO_ERR ) { EndUndoGroup( UndoStack ); break; } rc = Append( n1 - 1, false ); if( rc != ERR_NO_ERR ) { EndUndoGroup( UndoStack ); break; } break; case EX_T_COPY: if( addr < 0 || IsPastLastLine( addr ) ) { return( ERR_INVALID_ADDRESS ); } i = GetCopyOfLineRange( n1, n2, &fcblist ); if( i ) { break; } rc = InsertLines( addr, &fcblist, UndoStack ); GoToLineNoRelCurs( addr ); if( rc == ERR_NO_ERR ) { Message1( strCmmsg, tlines, "copied", addr ); } break; case EX_T_INSERT: if( !EditFlags.ExMode ) { return( ERR_ONLY_VALID_IN_EX_MODE ); } if( !n2f ) { rc = Append( n1 - 1, true ); } break; case EX_T_JOIN: if( SaveAndResetFilePos( n1 ) != ERR_NO_ERR ) { rc = ERR_NO_SUCH_LINE; break; } if( tlines == 1 ) { n2 = n1 + 1; tlines = 2; } SetRepeatCount( tlines - 1 ); rc = JoinCurrentLineToNext(); RestoreCurrentFilePos(); GoToLineNoRelCurs( n1 ); if( rc == ERR_NO_ERR ) { Message1( "lines %l to %l joined", n1, n2 ); } break; case EX_T_LIST: if( !EditFlags.ExMode ) { return( ERR_ONLY_VALID_IN_EX_MODE ); } for( rc = CGimmeLinePtr( n1, &cfcb, &cline ); rc == ERR_NO_ERR; rc = CGimmeNextLinePtr( &cfcb, &cline ) ) { if( EditFlags.LineNumbers ) { MyPrintf( "%M %s\n", n1, cline->data ); } else { MyPrintf( "%s\n", cline->data ); } if( n1 >= n2 ) { break; } n1++; } break; case EX_T_MARK: rc = SetGenericMark( n1, 1, C2VIKEY( word[0] ) ); break; case EX_T_MOVE: if( addr < 0 || IsPastLastLine( addr ) ) { return( ERR_INVALID_ADDRESS ); } SavebufNumber = WORK_SAVEBUF; StartUndoGroup( UndoStack ); rc = DeleteLineRange( n1, n2, SAVEBUF_FLAG ); if( SavebufNumber != WORK_SAVEBUF ) { /* if this changes, the command will fail * this could be caused by checking out a read-only file * so fix the deleted text and give an error message */ DoUndo(); return( ERR_INVALID_COMMAND ); } if( rc != ERR_NO_ERR ) { EndUndoGroup( UndoStack ); break; } if( addr > n2 ) { addr -= tlines; } else if( addr >= n1 && addr <= n2 ) { addr = n1; } rc = InsertLines( addr, &WorkSavebuf->u.fcbs, UndoStack ); EndUndoGroup( UndoStack ); GoToLineNoRelCurs( addr ); if( rc == ERR_NO_ERR ) { Message1( strCmmsg, tlines, "moved", addr ); } break; case EX_T_UNDO: rc = DoUndo(); break; case EX_T_UNDO_DMT: rc = DoUndoUndo(); break; case EX_T_EQUALS: Message1( "%l", n1 ); rc = ERR_NO_ERR; break; case EX_T_VERSION: rc = DoVersion(); break; case EX_T_VISUAL: case EX_T_VISUAL_DMT: if( EditFlags.LineDisplay ) { ScreenPage( -1 ); EditFlags.ExMode = false; EditFlags.LineDisplay = false; EditFlags.ClockActive = true; ReDisplayScreen(); DoVersion(); } if( word[0] != '\0' ) { rc = EditFile( word, ( tkn == EX_T_VISUAL_DMT ) ); } else { rc = ERR_NO_ERR; } break; } return( rc ); } /* ProcessEx */
/* * RunCommandLine - run a command line command */ vi_rc RunCommandLine( const char *cmdl ) { int i, x, y, x2, y2; bool n1f, n2f; int tkn, flag; bool test1; linenum n1, n2; char st[FILENAME_MAX]; info *cinfo; long val; jmp_buf jmpaddr; vi_rc rc; const char *data; /* * parse command string */ tkn = TOK_INVALID; rc = ParseCommandLine( cmdl, &n1, &n1f, &n2, &n2f, &tkn, &data ); if( rc != ERR_NO_ERR ) { return( rc ); } if( !n2f ) { if( !n1f ) { n1 = n2 = CurrentPos.line; } else { n2 = n1; } } /* * process tokens */ rc = ERR_INVALID_COMMAND; test1 = n1f || n2f; switch( tkn ) { case PCL_T_ABOUT: rc = DoAboutBox(); break; case PCL_T_PUSH: rc = PushFileStackAndMsg(); break; case PCL_T_POP: rc = PopFileStack(); break; case PCL_T_EXECUTE: data = SkipLeadingSpaces( data ); if( *data != '\0' ) { key_map scr; rc = AddKeyMap( &scr, data ); if( rc != ERR_NO_ERR ) { break; } rc = RunKeyMap( &scr, 1L ); MemFree( scr.data ); } break; case PCL_T_DELETEMENU: rc = DoMenuDelete( data ); break; case PCL_T_DELETEMENUITEM: rc = DoItemDelete( data ); break; case PCL_T_ADDMENUITEM: rc = AddMenuItem( data ); break; case PCL_T_MAXIMIZE: rc = MaximizeCurrentWindow(); break; case PCL_T_MINIMIZE: rc = MinimizeCurrentWindow(); break; case PCL_T_EXITFILESONLY: if( !ExitWithPrompt( false, false ) ) { rc = ERR_EXIT_ABORTED; } else { rc = ERR_NO_ERR; } break; case PCL_T_EXITALL: if( !ExitWithPrompt( true, false ) ) { rc = ERR_EXIT_ABORTED; } else { rc = ERR_NO_ERR; } break; case PCL_T_QUITALL: ExitWithVerify(); rc = ERR_NO_ERR; break; case PCL_T_KEYADD: data = SkipLeadingSpaces( data ); KeyAddString( data ); rc = ERR_NO_ERR; break; case PCL_T_UNALIAS: rc = UnAlias( data ); break; case PCL_T_UNABBREV: rc = UnAbbrev( data ); break; case PCL_T_UNMAP: case PCL_T_UNMAP_DMT: flag = MAPFLAG_MESSAGE + MAPFLAG_UNMAP; if( tkn == PCL_T_UNMAP_DMT ) { flag |= MAPFLAG_DAMMIT; } rc = MapKey( flag, data ); break; case PCL_T_EVAL: data = Expand( dataBuff, data, NULL ); i = setjmp( jmpaddr ); if( i != 0 ) { rc = (vi_rc)i; } else { StartExprParse( data, jmpaddr ); val = GetConstExpr(); ltoa( val, st, EditVars.Radix ); Message1( "%s", st ); rc = ERR_NO_ERR; } break; case PCL_T_COMPILE: case PCL_T_SOURCE: case PCL_T_LOAD: { char *tstr; srcline sline; data = GetNextWord1( data, st ); if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; break; } if( tkn == PCL_T_COMPILE ) { EditFlags.CompileScript = true; if( st[0] == '-' ) { if( st[1] == 'a' || st[1] == 'A' ) { EditFlags.CompileAssignments = true; if( st[1] == 'A' ) { EditFlags.CompileAssignmentsDammit = true; } data = GetNextWord1( data, st); if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; break; } } } } if( tkn == PCL_T_LOAD ) { EditFlags.LoadResidentScript = true; } sline = 0; rc = Source( st, data, &sline ); EditFlags.LoadResidentScript = false; EditFlags.CompileScript = false; EditFlags.CompileAssignments = false; EditFlags.CompileAssignmentsDammit = false; if( EditFlags.SourceScriptActive ) { LastError = rc; } if( rc > ERR_NO_ERR ) { Error( "%s on line %u of \"%s\"", GetErrorMsg( rc ), sline, st ); } else { if( rc != DO_NOT_CLEAR_MESSAGE_WINDOW ) { if( tkn != PCL_T_SOURCE ) { if( tkn == PCL_T_LOAD ) { tstr = strLoad; } else { tstr = strCompile; } Message1( "Script \"%s\" %s, %u lines generated, %d errors", st, tstr, sline, SourceErrCount ); rc = DO_NOT_CLEAR_MESSAGE_WINDOW; } } } break; } case PCL_T_GENCONFIG: #ifndef __WIN__ data = GetNextWord1( data,st ); if( *st != '\0' ) { rc = GenerateConfiguration( st, true ); } else { rc = GenerateConfiguration( NULL, true ); } #else { bool temp = EditFlags.SaveConfig; EditFlags.SaveConfig = true; WriteProfile(); EditFlags.SaveConfig = temp; rc = ERR_NO_ERR; } #endif break; case PCL_T_COMPRESS: rc = CompressWhiteSpace(); break; case PCL_T_EXPAND: rc = ExpandWhiteSpace(); break; case PCL_T_SHOVE: rc = Shift( n1, n2, '>', true ); break; case PCL_T_SUCK: rc = Shift( n1, n2, '<', true ); break; case PCL_T_FILES: if( EditFlags.LineDisplay ) { rc = DisplayFileStatus(); } else { rc = EditFileFromList(); } break; case PCL_T_NEXT: rc = RotateFileForward(); break; case PCL_T_PREV: rc = RotateFileBackwards(); break; case PCL_T_HELP: rc = DoHelp( data ); break; case PCL_T_VIEW: case PCL_T_VIEW_DMT: EditFlags.ViewOnly = true; case PCL_T_EDIT: case PCL_T_EDIT_DMT: rc = EditFile( data, ( tkn == PCL_T_VIEW_DMT || tkn == PCL_T_EDIT_DMT ) ); EditFlags.ViewOnly = false; break; case PCL_T_OPEN: rc = OpenWindowOnFile( data ); break; case PCL_T_HIDE: case PCL_T_HIDE_DMT: rc = HideLineRange( n1, n2, ( tkn == PCL_T_HIDE_DMT ) ); break; case PCL_T_DELETE: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } if( SelRgn.selected && !EditFlags.LineBased ) { AddSelRgnToSavebufAndDelete(); rc = ERR_NO_ERR; // @ may have turned this on - it is now definitely off SelRgn.selected = false; } else { rc = DeleteLineRange( n1, n2, SAVEBUF_FLAG ); } if( rc == ERR_NO_ERR ) { DCDisplayAllLines(); LineDeleteMessage( n1, n2 ); } break; case PCL_T_SAVEANDEXIT: data = GetNextWord1( data, st ); if( *st == '\0' ) { rc = SaveAndExit( st ); } else { rc = SaveAndExit( NULL ); } break; case PCL_T_PUT: case PCL_T_PUT_DMT: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } rc = SaveAndResetFilePos( n1 ); if( rc == ERR_NO_ERR ) { if( tkn == PCL_T_PUT ) { rc = InsertSavebufAfter(); } else { rc = InsertSavebufBefore(); } RestoreCurrentFilePos(); } break; case PCL_T_YANK: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } if( SelRgn.selected && !EditFlags.LineBased ) { rc = YankSelectedRegion(); // @ may have turned this on - it is now definitely off SelRgn.selected = false; } else { rc = YankLineRange( n1, n2 ); } break; case PCL_T_SUBSTITUTE: rc = Substitute( n1, n2, data ); break; case PCL_T_GLOBAL: case PCL_T_GLOBAL_DMT: if( !test1 ) { n1 = 1; rc = CFindLastLine( &n2 ); if( rc != ERR_NO_ERR ) { break; } } rc = Global( n1,n2, data, ( tkn == PCL_T_GLOBAL_DMT ) ); break; case PCL_T_WRITEQUIT: if( CurrentFile == NULL ) { rc = NextFile(); } else { CurrentFile->modified = true; data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = SaveAndExit( st ); } else { rc = SaveAndExit( NULL ); } } break; case PCL_T_WRITE: case PCL_T_WRITE_DMT: data = GetNextWord1( data, st ); if( test1 ) { if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; } else { rc = SaveFile( st, n1, n2, ( tkn == PCL_T_WRITE_DMT ) ); } } else { if( st[0] != '\0' ) { #ifdef __WIN__ if( st[0] == '?' && st[1] == '\0' ) { rc = SaveFileAs(); break; } else { rc = SaveFile( st, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); } #else rc = SaveFile( st, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); #endif } else { rc = SaveFile( NULL, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); if( rc == ERR_NO_ERR ) { Modified( false ); } } } break; case PCL_T_READ: rc = ReadAFile( n1, data ); break; case PCL_T_QUIT: #ifdef __WIN__ rc = CurFileExitOptionSaveChanges(); #else rc = NextFile(); #endif break; case PCL_T_QUIT_DMT: rc = NextFileDammit(); break; case PCL_T_DATE: GetDateTimeString( st ); Message1( st ); rc = DO_NOT_CLEAR_MESSAGE_WINDOW; break; case PCL_T_CD: data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = SetCWD( st ); } else { rc = ERR_NO_ERR; } if( rc == ERR_NO_ERR ) { Message1( "Current directory is %s",CurrentDirectory ); } break; case PCL_T_SHELL: EVIL_SHELL: { #if defined( __NT__ ) && !defined( __WIN__ ) ExecCmd( NULL, NULL, NULL ); #else char foo[FILENAME_MAX]; strcpy( foo, Comspec ); ExecCmd( NULL, NULL, foo ); #endif DoVersion(); rc = ERR_NO_ERR; } break; case PCL_T_SYSTEM: if( n1f && n2f ) { rc = DoGenericFilter( n1, n2, data ); } else { data = SkipLeadingSpaces( data ); if( *data == '\0' ) { goto EVIL_SHELL; } ExecCmd( NULL, NULL, data ); rc = ERR_NO_ERR; } break; case PCL_T_RESIZE: rc = ResizeCurrentWindowWithKeys(); break; case PCL_T_TILE: data = GetNextWord1( data, st ); if( st[0] != '\0' ) { if( st[0] == 'v' ) { y = 1; for( x = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { x++; } } else if( st[0] == 'h' ) { x = 1; for( y = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { y++; } } else { x = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } else { y = atoi( st ); } } } else { x = EditVars.MaxWindowTileX; y = EditVars.MaxWindowTileY; } if( x > 0 && y > 0) { rc = WindowTile( x, y ); } break; case PCL_T_CASCADE: rc = WindowCascade(); break; case PCL_T_MOVEWIN: rc = MoveCurrentWindowWithKeys(); break; case PCL_T_TAG: data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = TagHunt( st ); } break; case PCL_T_FGREP: { bool ci; data = SkipLeadingSpaces( data ); ci = EditFlags.CaseIgnore; if( data[0] == '-' ) { if( data[1] == 'c' ) { ci = false; data += 2; data = SkipLeadingSpaces( data ); rc = GetStringWithPossibleQuote( &data, st ); } else if( data[1] == 'i' ) { ci = true; data += 2; data = SkipLeadingSpaces( data ); rc = GetStringWithPossibleQuote( &data, st ); } else if( data[1] == 'f' ) { data += 2; data = SkipLeadingSpaces( data ); #ifdef __WIN__ // call fancy grep window { fancy_find *ff; /* ff will be set to point at a static fancy find struct * in the snoop module */ char snoopbuf[FILENAME_MAX]; if( !GetSnoopStringDialog( &ff ) ) { return( ERR_NO_ERR ); } strcpy( snoopbuf, ff->path ); /* assume no string means current directory */ if( strlen( snoopbuf ) && snoopbuf[strlen( snoopbuf ) - 1] != '\\' ){ strcat( snoopbuf, "\\" ); } MySprintf( st, "%s", ff->find ); strcat( snoopbuf, ff->ext ); ci = ff->case_ignore; if( !ff->use_regexp ) { //MakeExpressionNonRegular( st ); rc = DoFGREP( snoopbuf, st, ci ); } else { rc = DoEGREP( snoopbuf, st ); } break; } #endif } } else { rc = GetStringWithPossibleQuote( &data, st ); } if( rc != ERR_NO_STRING ) { rc = DoFGREP( data, st, ci ); } } break; case PCL_T_EGREP: rc = GetStringWithPossibleQuote( &data, st ); if( rc != ERR_NO_STRING ) { rc = DoEGREP( data, st ); } break; case PCL_T_SIZE: data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } x = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } y = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } x2 = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } y2 = atoi( st ); rc = CurrentWindowResize( x, y, x2, y2 ); break; case PCL_T_ECHO: data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } rc = ERR_NO_ERR; if( !stricmp( st, "on" ) ) { EditFlags.EchoOn = true; break; } else if( !stricmp( st, "off" ) ) { EditFlags.EchoOn = false; break; } x = atoi( st ); data = SkipLeadingSpaces( data ); /* * FIXME: This is not good - I will definately have to * fix this code up. But right now I have to get the * editor ready for tomorrow. Brad. */ if( data[0] == '"' || data[0] == '/' ) { GetStringWithPossibleQuote( &data, st ); if( x > 2 ) { /* this is obviously a sick individual */ Error( "Invalid Echo" ); } else if( x == 1 ) { Message1( st ); } else if( x == 2 ) { Message2( st ); } // DisplayLineInWindow( MessageWindow, x, st ); } else { if( x > 2 ) { /* this is obviously a sick individual */ Error( "Invalid Echo" ); } else if( x == 1 ) { Message1( data ); } else if( x == 2 ) { Message2( data ); } // DisplayLineInWindow( MessageWindow, x, data ); } break; #ifdef VI_RCS case PCL_T_CHECKOUT: rc = ERR_NO_ERR; #ifdef __WINDOWS__ if( isOS2() ) break; // OS/2 shell returns before checkout finishes #endif if( CurrentFile != NULL ) { rc = ViRCSCheckout( rc ); } break; case PCL_T_CHECKIN: if( CurrentFile != NULL ) { rc = ViRCSCheckin( rc ); } break; #endif default: if( tkn >= 1000 ) { rc = ProcessEx( n1, n2, n2f, tkn - 1000, data ); break; } rc = TryCompileableToken( tkn, data, true ); if( rc != NOT_COMPILEABLE_TOKEN ) { break; } rc = ProcessWindow( tkn, data ); if( rc >= ERR_NO_ERR ) { break; } case TOK_INVALID: if( n1f && !n2f ) { if( !n1 ) { n1 = 1; } MemorizeCurrentContext(); rc = GoToLineNoRelCurs( n1 ); if( rc == ERR_NO_ERR ) { GoToColumnOnCurrentLine( 1 ); if( EditFlags.LineDisplay ) { MyPrintf( "%s\n", CurrentLine->data ); } } return( rc ); } rc = ERR_INVALID_COMMAND; break; } if( rc == ERR_NO_ERR ) { rc = DO_NOT_CLEAR_MESSAGE_WINDOW; } return( rc ); } /* RunCommandLine */
/* * AutoSaveInit - initialize for auto-save */ void AutoSaveInit( void ) { char path[FILENAME_MAX]; char path2[FILENAME_MAX]; char as_path[FILENAME_MAX]; char asl_path[FILENAME_MAX]; int len; int cnt; FILE *f; int pid; int ch; int handle; int off; // int old_len; int i; char *p; /* * initialize tmpname */ #ifdef __UNIX__ strcpy( currTmpName,"aaaaaaaaaaaa.tmp" ); #else strcpy( currTmpName,"aaaaaaaa.tmp" ); #endif pid = getpid(); itoa( pid, path, 36 ); len = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len], path, len ); #ifdef __QNX__ { int len2, len3; int nid, uid; nid = getnid(); itoa( nid, path, 36 ); len2 = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len - len2], path, len2 ); uid = getuid(); itoa( uid, path, 36 ); len3 = strlen( path ); memcpy( &currTmpName[TMP_FNAME_LEN - len - len2 - len3], path, len3 ); memcpy( &checkFileName[EXTRA_EXT_OFF], path, len3 ); memcpy( &checkFileTmpName[EXTRA_EXT_OFF], path, len3 ); memcpy( &lockFileName[EXTRA_EXT_OFF], path, len3 ); } #endif /* * check if we need to recover lost files */ if( EditFlags.RecoverLostFiles ) { cnt = 0; MakeTmpPath( as_path, checkFileName ); MakeTmpPath( asl_path, lockFileName ); off = strlen( as_path ) - 5; for( ch = START_CHAR; ch <= END_CHAR; ch++ ) { as_path[off] = ch; asl_path[off] = ch; handle = sopen3( as_path, O_RDONLY | O_TEXT, SH_DENYRW ); if( handle < 0 ) { continue; } f = fdopen( handle, "r" ); if( f != NULL ) { while( (p = fgets( path2, FILENAME_MAX, f )) != NULL ) { for( i = strlen( p ); i && isWSorCtrlZ( p[i - 1] ); --i ) { p[i - 1] = '\0'; } p = GetNextWord1( p, path ); p = SkipLeadingSpaces( p ); NewFile( path, false ); ReplaceString( &(CurrentFile->name), p ); SetFileWindowTitle( CurrentWindow, CurrentInfo, true ); FileSPVAR(); CurrentFile->modified = true; CurrentFile->check_readonly = true; FTSRunCmds( p ); cnt++; } fclose( f ); remove( as_path ); } else { close( handle ); } remove( asl_path ); } if( cnt == 0 ) { MyPrintf( "No files recovered!\n" ); ExitEditor( -1 ); } Message1( "%d files recovered", cnt ); } if( EditVars.AutoSaveInterval == 0 ) { return; } // old_len = strlen( lockFileName ); MakeTmpPath( path, lockFileName ); len = strlen( path ) - strlen( lockFileName ); off = len + CHAR_OFF; for( ch = START_CHAR; ch <= END_CHAR; ch++ ) { path[off] = ch; lockFileHandle = sopen4( path, O_CREAT | O_TRUNC | O_RDWR | O_TEXT, SH_DENYRW, PMODE_RW ); if( lockFileHandle > 0 ) { break; } } if( lockFileHandle < 0 ) { // MyPrintf( "Too many editors running!\n" ); MyPrintf( "Error opening temp file - '%s'\n", strerror( errno ) ); ExitEditor( -1 ); } lockFileName[CHAR_OFF] = ch; checkFileName[CHAR_OFF] = ch; checkFileTmpName[CHAR_OFF] = ch; } /* AutoSaveInit */
/* * SrcAssign - assign a value to a variable */ vi_rc SrcAssign( const char *data, vlist *vl ) { int i, j, k, l; long val; bool rxflag = false; bool envflag = false; bool setflag = false; bool expflag = false; bool timeflag = false; bool lnumflag = false; char tmp[MAX_SRC_LINE], tmp1[MAX_SRC_LINE], name[MAX_SRC_LINE]; const char *v1; char *t; vars *v; jmp_buf jmpaddr; time_t tod; bool check_end; char tmpstr[MAX_STR]; /* * get assign syntax : * ASSIGN %v = /v1/(r)($)(@)(x)(l)(t) * possible v1: * strlen %a * strchr %a ch * substr %a n1 n2 */ data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( !VarName( name, tmp, vl ) ) { return( ERR_SRC_INVALID_ASSIGN ); } data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( stricmp( tmp, "=" ) != 0 ) { return( ERR_SRC_INVALID_ASSIGN ); } data = SkipLeadingSpaces( data ); if( data[0] == '/' || data[0] == '"' ) { check_end = false; if( data[0] == '"' ) { data = GetNextWord( data, tmp, SingleQuote ); if( data[0] == '"' ) { check_end = true; } } else { data = GetNextWord( data, tmp, SingleSlash ); if( data[0] == '/' ) { check_end = true; } } if( check_end ) { for( ++data; data[0] != '\0'; data++ ) { switch( data[0] ) { case 't': timeflag = true; break; case 'r': rxflag = true; break; case '$': envflag = true; break; case '@': setflag = true; break; case 'x': expflag = true; break; case 'l': lnumflag = true; break; } } } Expand( tmp1, tmp, vl ); } else { data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } j = Tokenize( StrTokens, tmp, false ); if( j != TOK_INVALID ) { data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } if( !VarName( tmp1, tmp, vl ) ) { return( ERR_SRC_INVALID_ASSIGN ); } v = VarFind( tmp1, vl ); switch( j ) { case STR_T_STRLEN: if( v != NULL ) { sprintf( tmp1, "%d", v->len ); } else { strcpy( tmp1, "0" ); } break; case STR_T_SUBSTR: data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); i = atoi( tmp1 ) - 1; data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); j = atoi( tmp1 ) - 1; if( v == NULL ) { tmp1[0] = '\0'; break; } if( j >= v->len || i < 0 ) { tmp1[0] = '\0'; } else { l = 0; for( k = i; k <= j; k++ ) { tmp1[l++] = v->value[k]; } tmp1[l] = '\0'; } break; case STR_T_STRCHR: data = GetNextWord1( data, tmp ); if( *tmp == '\0' ) { return( ERR_SRC_INVALID_ASSIGN ); } Expand( tmp1, tmp, vl ); if( v == NULL ) { j = -1; } else { t = strchr( v->value, tmp1[0] ); if( t != NULL ) { j = t - v->value; } else { j = -1; } j++; } sprintf( tmp1, "%d", j ); break; } } else { Expand( tmp1, tmp, vl ); } } /* * regular expression subs. */ if( rxflag && CurrentRegularExpression != NULL ) { RegSub( CurrentRegularExpression, tmp1, tmp, CurrentPos.line ); strcpy( tmp1, tmp ); } /* * special processing */ if( envflag ) { v1 = getenv( tmp1 ); if( v1 == NULL ) { v1 = ""; } } else if( setflag ) { v1 = GetASetVal( tmp1, tmpstr ); } else if( timeflag ) { tod = time( NULL ); strftime( tmp, sizeof( tmp ), tmp1, localtime( &tod ) ); v1 = tmp; } else if( expflag || lnumflag ) { i = setjmp( jmpaddr ); if( i != 0 ) { return( (vi_rc)i ); } StartExprParse( tmp1, jmpaddr ); val = GetConstExpr(); if( lnumflag ) { fcb *cfcb; line *cline; vi_rc rc; rc = CGimmeLinePtr( val, &cfcb, &cline ); v1 = cline->data; if( rc != ERR_NO_ERR ) { v1 = ""; } } else { v1 = ltoa( val, tmp1, EditVars.Radix ); } } else { v1 = tmp1; } VarAddStr( name, v1, vl ); return( ERR_NO_ERR ); } /* SrcAssign */
/* * RemoveFromAutoSaveList - take a file that we are quitting out of the list */ void RemoveFromAutoSaveList( void ) { FILE *f, *f2; char as_path[FILENAME_MAX]; char as2_path[FILENAME_MAX]; char path[FILENAME_MAX]; char path2[FILENAME_MAX]; char data[FILENAME_MAX]; // bool found; int i; char *p; if( EditVars.AutoSaveInterval == 0 ) { return; } if( CurrentFile == NULL ) { return; } if( !CurrentFile->been_autosaved ) { return; } MakeTmpPath( as_path, checkFileName ); MakeTmpPath( as2_path, checkFileTmpName ); GetCurrentFilePath( path ); // found = false; f = fopen( as_path, "r" ); if( f == NULL ) { return; } f2 = fopen( as2_path, "w" ); if( f2 == NULL ) { fclose( f ); return; } while( (p = fgets( path2, FILENAME_MAX, f )) != NULL ) { for( i = strlen( p ); i && isWSorCtrlZ( p[i - 1] ); --i ) { p[i - 1] = '\0'; } p = GetNextWord1( p, data ); p = SkipLeadingSpaces( p ); if( strcmp( path, p ) == 0 ) { p = MakeTmpPath( path2, CurrentFile->as_name ); if( strcmp( data, p ) == 0 ) { // found = true; remove( p ); while( fgets( data, FILENAME_MAX, f ) != NULL ) { for( i = strlen( data ); i && isWSorCtrlZ( data[i - 1] ); --i ) { data[i - 1] = '\0'; } MyFprintf( f2, "%s\n", data ); } break; } } MyFprintf( f2, "%s %s\n", data, p ); } fclose( f ); fclose( f2 ); remove( as_path ); rename( as2_path, as_path ); } /* RemoveFromAutoSaveList */