📄 sstyle_r.c
字号:
/****************************************************************************
*
* 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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "vi.h"
#include "sstyle.h"
#include "lang.h"
/*----- LOCALS -----*/
static ss_flags_c flags;
static int lenCComment = 0;
static char *firstNonWS;
enum getFloatCommands {
AFTER_ZERO,
AFTER_DOT,
AFTER_EXP,
BADTEXT,
};
static int issymbol( int c )
{
/* symbol list taken from Watcom C Lang Ref. pg 11
*/
if( c == ';' ||
c == '(' || c == ')' ||
c == '{' || c == '}' ||
c == '=' ||
c == '+' || c == '-' ||
c == '/' || c == '*' || c == '%' || c == '^' ||
c == '|' || c == '&' || c == '!' ||
c == '[' || c == ']' ||
c == '<' || c == '>' ||
c == '.' || c == '\\' ||
c == '?' || c == ':' ||
c == ',' ||
c == '~' ) {
return( 1 );
} else {
return( 0 );
}
}
void InitRexxLine( char *text )
{
while( *text && isspace( *text ) ) {
text++;
}
firstNonWS = text;
}
static void getHex( ss_block *ss_new, char *start )
{
int lastc;
char *text = start + 2;
bool nodigits = TRUE;
ss_new->type = SE_HEX;
while( *text && isxdigit( *text ) ) {
text++;
nodigits = FALSE;
}
if( nodigits ) {
ss_new->type = SE_INVALIDTEXT;
}
lastc = tolower ( *text );
if( lastc == 'u' ) {
text++;
if( tolower( *text ) == 'l' ) {
text++;
}
} else if( lastc == 'l' ) {
text++;
if( tolower( *text ) == 'u' ) {
text++;
}
}
ss_new->len = text - start;
}
static void getFloat( ss_block *ss_new, char *start, int skip, int command )
{
char *text = start + skip;
char lastc;
ss_new->type = SE_FLOAT;
if( command == AFTER_ZERO ) {
while( isdigit( *text ) ) {
text++;
}
if( *text == 'E' || *text == 'e' ) {
command = AFTER_EXP;
text++;
} else if( *text == '.' ) {
command = AFTER_DOT;
text++;
} else {
// simply a bad octal value (eg 09)
ss_new->type = SE_INVALIDTEXT;
command = BADTEXT;
}
}
switch( command ) {
case AFTER_DOT:
if( !isdigit( *text ) ) {
if( *text == 'e' || *text == 'E' ) {
getFloat( ss_new, start, text - start + 1, AFTER_EXP );
return;
}
if( *text && !isspace( *text ) && !issymbol( *text ) ) {
if( *text ) text++;
ss_new->type = SE_INVALIDTEXT;
}
break;
}
text++;
while( isdigit( *text ) ) {
text++;
}
if( *text != 'E' && *text != 'e' ) {
break;
}
text++;
// fall through
case AFTER_EXP:
if( *text == '+' || *text == '-' ) {
text++;
}
if( !isdigit( *text ) ) {
if( *text ) text++;
ss_new->type = SE_INVALIDTEXT;
break;
}
text++;
while( isdigit( *text ) ) {
text++;
}
}
// get float/long spec
lastc = tolower( *text );
if( lastc == 'f' || lastc == 'l' ) {
text++;
} else if( *text && !isspace( *text ) && !issymbol( *text ) ) {
ss_new->type = SE_INVALIDTEXT;
text++;
}
ss_new->len = text - start;
}
static void getNumber( ss_block *ss_new, char *start, char top )
{
int lastc;
char *text = start + 1;
while( ( *text >= '0' ) && ( *text <= top ) ) {
text++;
}
if( *text == '.' ) {
getFloat( ss_new, start, text - start + 1, AFTER_DOT );
return;
} else if( *text == 'e' || *text == 'E' ) {
getFloat( ss_new, start, text - start + 1, AFTER_EXP );
return;
} else if( isdigit( *text ) ) {
// correctly handle something like 09.3
getFloat( ss_new, start, text - start + 1, AFTER_ZERO );
return;
}
ss_new->len = text - start;
/* feature!: we display 0 as an integer (it's really an octal)
* as it is so common & is usually thought of as such
*/
ss_new->type = ( top == '7' && ss_new->len > 1 ) ? SE_OCTAL : SE_INTEGER;
lastc = tolower ( *text );
if( lastc == 'u' ) {
ss_new->len++;
if( tolower( *( text + 1 ) ) == 'l' ) {
ss_new->len++;
}
} else if( lastc == 'l' ) {
ss_new->len++;
if( tolower( *( text + 1 ) ) == 'u' ) {
ss_new->len++;
}
}
}
static void getWhiteSpace( ss_block *ss_new, char *start )
{
char *text = start + 1;
while( isspace( *text ) ) {
text++;
}
ss_new->type = SE_WHITESPACE;
ss_new->len = text - start;
}
static void getText( ss_block *ss_new, char *start )
{
char *text = start + 1;
char save_char;
bool isKeyword;
while( isalnum( *text ) || ( *text == '_' ) || ( *text == '.' )) {
text++;
}
save_char = *text;
*text = '\0';
isKeyword = IsKeyword( start, FALSE );
*text = save_char;
ss_new->type = SE_IDENTIFIER;
if( isKeyword ) {
ss_new->type = SE_KEYWORD;
} else
if( *text == ':' && firstNonWS == start &&
*( text + 1 ) != ':' && *( text + 1 ) != '>' ) {
// : and > checked as it may be :: (CPP) operator or :> (base op.)
text++;
ss_new->type = SE_JUMPLABEL;
}
ss_new->len = text - start;
}
static void getSymbol( ss_block *ss_new )
{
ss_new->type = SE_SYMBOL;
ss_new->len = 1;
}
static void getPreprocessor( ss_block *ss_new, char *start )
{
char *text = start;
int withinQuotes = (int)flags.inString;
ss_new->type = SE_PREPROCESSOR;
if( EditFlags.PPKeywordOnly ) {
// just grab the #xxx bit & go
// skip the #
text++;
// take any spaces present
while( *text && isspace( *text ) ) {
text++;
}
// and then the keyword
while( *text && !isspace( *text ) ) {
text++;
}
ss_new->len = text - start;
flags.inPreprocessor = FALSE;
return;
}
flags.inPreprocessor = TRUE;
while( *text ) {
if( *text == '"' ) {
if( !withinQuotes ) {
withinQuotes = TRUE;
} else if( *( text - 1 ) != '\\' || *( text - 2 ) == '\\' ) {
withinQuotes = FALSE;
}
}
if( *text == '/' ) {
if( *( text + 1 ) == '*' && !withinQuotes ) {
flags.inCComment = TRUE;
lenCComment = 0;
break;
} else if( *( text + 1 ) == '/' && !withinQuotes ) {
flags.inCPPComment = TRUE;
flags.inPreprocessor = FALSE;
break;
}
}
text++;
}
flags.inString = (bool)withinQuotes;
if( *text == '\0' ) {
if( *( text - 1 ) != '\\' ) {
flags.inPreprocessor = FALSE;
if( flags.inString ) {
ss_new->type = SE_INVALIDTEXT;
flags.inString = FALSE;
}
}
}
ss_new->len = text - start;
}
static void getChar( ss_block *ss_new, char *start, int skip )
{
char *text = start + skip;
ss_new->type = SE_CHAR;
embedded:
while( ( *text ) && ( *text != '\'' ) ) {
text++;
}
if( *text == '\0' ) {
ss_new->type = SE_INVALIDTEXT;
} else if( *( text - 1 ) == '\\' ) {
text++;
goto embedded;
} else {
text++;
}
ss_new->len = text - start;
}
static void getBeyondText( ss_block *ss_new )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -