cmdline.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,350 行 · 第 1/3 页
C
1,350 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Editor command line processing.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <setjmp.h>
#ifdef M_I86
#include <i86.h>
#endif
#include "vi.h"
#include "parsecl.h"
#include "source.h"
#include "rxsupp.h"
#include "ex.h"
#include "win.h"
#include "expr.h"
#include "menu.h"
#include "source.h"
#ifdef __WIN__
#include "winvi.h"
#include "winrtns.h"
#endif
#include "sstyle.h"
#include "fts.h"
#include "rcscli.h"
#if defined( __WINDOWS__ ) && defined( VI_RCS )
static bool isOS2( void )
{
union {
DWORD dVersion;
struct {
char winMajor;
char winMinor;
char dosMinor;
char dosMajor;
} v;
} v;
v.dVersion = GetVersion();
if( v.v.dosMajor >= 20 ) {
return( TRUE );
}
return( FALSE );
}
#endif
static window_info *wInfo=NULL;
static int setWDimension( char * );
static int setWHilite( char * );
static int setWText( char * );
static int setWBorder( char * );
static int setSyntaxStyle( int, char * );
static char strLoad[] = "loaded";
static char strCompile[] = "compiled";
static char *dataBuff;
/*
* InitCommandLine - initialize command line processing
*/
void InitCommandLine( void )
{
dataBuff = MemAlloc( MaxLine );
} /* InitCommandLine */
/*
* FiniCommandLine - free memory
*/
void FiniCommandLine( void )
{
MemFree( dataBuff );
} /* FiniCommandLine */
/*
* doProcessCommandLine - handle getting and processing a command line
*/
static int doProcessCommandLine( bool is_fancy )
{
int rc;
char *st;
/*
* open the window and get the string
*/
st = MemAllocUnsafe( MaxLine );
if( st == NULL ) {
return( ERR_NO_MEMORY );
}
is_fancy = is_fancy;
#ifdef __WIN__
if( is_fancy ) {
if( !GetCmdDialog( st, MaxLine ) ) {
MemFree( st );
return( ERR_NO_ERR );
}
} else {
#endif
rc = PromptForString( ":", st, MaxLine, &CLHist );
if( rc ) {
MemFree( st );
if( rc == NO_VALUE_ENTERED ) {
return( ERR_NO_ERR );
}
return( rc );
}
#ifdef __WIN__
}
#endif
CommandBuffer = st;
rc = SourceHook( SRC_HOOK_COMMAND, ERR_NO_ERR );
if( !rc ) {
rc = RunCommandLine( st );
}
CommandBuffer = NULL;
MemFree( st );
return( rc );
} /* doProcessCommandLine */
/*
* ProcessCommandLine - do just that
*/
int ProcessCommandLine( void )
{
return( doProcessCommandLine( FALSE ) );
} /* ProcessCommandLine */
/*
* FancyProcessCommandLine - do just that
*/
int FancyProcessCommandLine( void )
{
return( doProcessCommandLine( TRUE ) );
} /* FancyProcessCommandLine */
/*
* TryCompileableToken - process token that can also be compiled
*/
int TryCompileableToken( int token, char *data, bool iscmdline,
bool dmt )
{
int rc = ERR_INVALID_COMMAND;
bool mflag;
char *tmp;
switch( token ) {
case PCL_T_MAPBASE:
case PCL_T_MAP:
if( iscmdline ) {
mflag = MAPFLAG_MESSAGE;
} else {
mflag = 0;
}
if( token == PCL_T_MAPBASE ) {
mflag |= MAPFLAG_BASE;
}
tmp = data;
if( iscmdline ) {
if( dmt ) {
mflag |= MAPFLAG_DAMMIT;
}
} else {
if( data[0] == '!' ) {
mflag |= MAPFLAG_DAMMIT;
tmp = &data[1];
}
}
rc = MapKey( mflag, tmp );
break;
case PCL_T_MENUFILELIST:
rc = MenuItemFileList();
break;
case PCL_T_MENULASTFILES:
rc = MenuItemLastFiles();
break;
case PCL_T_MENU:
rc = StartMenu( data );
break;
case PCL_T_MENUITEM:
rc = MenuItem( data );
break;
case PCL_T_FLOATMENU:
rc = ActivateFloatMenu( data );
break;
case PCL_T_ENDMENU:
rc = ViEndMenu();
break;
case PCL_T_FILETYPESOURCE:
rc = FTSStart( data );
break;
case PCL_T_ADDTOOLBARITEM:
#ifdef __WIN__
rc = AddBitmapToToolBar( data );
#endif
break;
case PCL_T_DELETETOOLBARITEM:
#ifdef __WIN__
rc = DeleteFromToolBar( data );
#endif
break;
case PCL_T_ACTIVATE_IDE:
#ifdef __WIN__
StartIDE( InstanceHandle, TRUE );
rc = ERR_NO_ERR;
#endif
break;
case PCL_T_ALIAS:
rc = SetAlias( data );
break;
case PCL_T_ABBREV:
rc = Abbrev( data );
break;
case PCL_T_SET:
if( iscmdline ) {
Expand( data, NULL );
}
rc = Set( data );
break;
case PCL_T_SETCOLOR:
rc = SetAColor( data );
break;
case PCL_T_SETFONT:
rc = SetFont( data );
break;
case PCL_T_MATCH:
rc = AddMatchString( data );
break;
case PCL_T_LOCATE:
rc = LocateCmd( data );
break;
default:
rc = NOT_COMPILEABLE_TOKEN;
break;
}
return( rc );
} /* TryCompileableToken */
/*
* RunCommandLine - run a command line command
*/
int RunCommandLine( char *cl )
{
int i,rc=ERR_INVALID_COMMAND,x,y,x2,y2;
int n2f,n1f,dmt,tkn,flag;
bool test1;
linenum n1,n2;
char st[FILENAME_MAX];
info *cinfo;
long val;
jmp_buf jmpaddr;
/*
* parse command string
*/
i = ParseCommandLine( cl, &n1, &n1f, &n2, &n2f, &tkn, dataBuff, &dmt );
if( i ) {
return( i );
}
if( !n2f ) {
if( !n1f ) {
n1 = n2 = CurrentLineNumber;
} else {
n2 = n1;
}
}
/*
* process tokens
*/
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:
RemoveLeadingSpaces( dataBuff );
i = strlen( dataBuff );
if( i > 0 ) {
key_map scr;
rc = AddKeyMap( &scr, dataBuff, i );
if( rc ) {
break;
}
rc = RunKeyMap( &scr, 1L );
MemFree( scr.data );
}
break;
case PCL_T_DELETEMENU:
rc = DoMenuDelete( dataBuff );
break;
case PCL_T_DELETEMENUITEM:
rc = DoItemDelete( dataBuff );
break;
case PCL_T_ADDMENUITEM:
rc = AddMenuItem( dataBuff );
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:
RemoveLeadingSpaces( dataBuff );
KeyAddString( dataBuff );
rc = ERR_NO_ERR;
break;
case PCL_T_UNALIAS:
rc = UnAlias( dataBuff );
break;
case PCL_T_UNABBREV:
rc = UnAbbrev( dataBuff );
break;
case PCL_T_UNMAP:
flag = MAPFLAG_MESSAGE + MAPFLAG_UNMAP;
if( dmt ) {
flag |= MAPFLAG_DAMMIT;
}
rc = MapKey( flag, dataBuff );
break;
case PCL_T_EVAL:
Expand( dataBuff, NULL );
rc = setjmp( jmpaddr );
if( rc == 0 ) {
StartExprParse( dataBuff, jmpaddr );
val = GetConstExpr();
ltoa( val, st, Radix );
Message1( "%s", st );
}
break;
case PCL_T_COMPILE:
case PCL_T_SOURCE:
case PCL_T_LOAD:
{
char *tstr;
if( NextWord1( dataBuff, 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;
}
if( NextWord1( dataBuff, st) <= 0 ) {
rc=ERR_NO_FILE_SPECIFIED;
break;
}
}
}
}
if( tkn == PCL_T_LOAD ) {
EditFlags.LoadResidentScript = TRUE;
}
rc = Source( st, dataBuff, &i );
EditFlags.LoadResidentScript = FALSE;
EditFlags.CompileScript = FALSE;
EditFlags.CompileAssignments = FALSE;
EditFlags.CompileAssignmentsDammit = FALSE;
if( EditFlags.SourceScriptActive ) {
LastError = rc;
}
if( rc > 0 ) {
Error( "%s on line %d of \"%s\"", GetErrorMsg( rc ), i, 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, %d lines generated, %d errors",
st, tstr, i, SourceErrCount );
rc = DO_NOT_CLEAR_MESSAGE_WINDOW;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?