⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sstyle_r.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
{
    ss_new->type = SE_WHITESPACE;
    ss_new->len = BEYOND_TEXT;
}

static void getInvalidChar( ss_block *ss_new )
{
    ss_new->type = SE_INVALIDTEXT;
    ss_new->len = 1;
}

static void getCComment( ss_block *ss_new, char *start, int skip )
{
    char    *text = start + skip;
    lenCComment += skip;
    for( ;; ) {
        while( *text && *text != '*' ) {
            lenCComment++;
            text++;
        }
        if( *text == '\0' ) {
            // comment extends to next line
            flags.inCComment = TRUE;
            break;
        }
        text++;
        lenCComment++;
        if( *( text ) == '/' && lenCComment > 2 ) {
            text++;
            // comment definitely done
            flags.inCComment = FALSE;
            break;
        }
    }
    ss_new->type = SE_COMMENT;
    ss_new->len = text - start;
}

static void getCPPComment( ss_block *ss_new, char *start )
{
    char    *text = start;
    while( *text ) {
        text++;
    }
    flags.inCPPComment = TRUE;
    if( *start == '\0' || *( text - 1 ) != '\\' ) {
        flags.inCPPComment = FALSE;
    }
    ss_new->type = SE_COMMENT;
    ss_new->len = text - start;
}

static void getString( ss_block *ss_new, char *start, int skip )
{
    char    *nstart = start + skip;
    char    *text = nstart;

    ss_new->type = SE_STRING;
again:
    while( *text && *text != '"' ) {
        text++;
    }
    if( *text == '\0' ) {
        if( *( text - 1 ) != '\\' ) {
            // unterminated string
            ss_new->type = SE_INVALIDTEXT;

            // don't try to trash rest of file
            flags.inString = FALSE;
        } else {
            // string continued on next line
            flags.inString = TRUE;
        }
    } else {
        text++;
        // definitely finished string
        flags.inString = FALSE;
    }
    ss_new->len = text - start;
}

void InitRexxFlagsGivenValues( ss_flags_c *newFlags )
{
    // Arrrrrrrrrggggg ! you have got to be kidding !!!!!!!!!!

    flags = *newFlags;
}

void GetRexxFlags( ss_flags_c *storeFlags )
{
    *storeFlags = flags;
}

void InitRexxFlags( linenum line_no )
{
    fcb     *fcb;
    char    *text;
    char    *starttext;
    line    *thisline;
    line    *topline;
    char    topChar;
    int     rc;
    int     withinQuotes = 0;
    line    *line;
    bool    inBlock = FALSE;

    flags.inCComment = 0;
    flags.inCPPComment = 0;
    flags.inString = 0;
    flags.inPreprocessor = 0;

    CGimmeLinePtr( line_no, &fcb, &thisline );
    line = thisline;
    rc = GimmePrevLinePtr( &fcb, &line );
    while( rc == ERR_NO_ERR ) {
        if( line->data[ line->len - 1 ] != '\\' ) {
            break;
        }
        inBlock = TRUE;
        rc = GimmePrevLinePtr( &fcb, &line );
    }

    if( rc == ERR_NO_ERR ) {
        topline = line;
        if( inBlock ) {
            CGimmeNextLinePtr( &fcb, &line );
        }
    } else {
        topline = NULL;
        if( inBlock ) {
            CGimmeLinePtr( 1, &fcb, &line );
        } else {
            return;
        }
    }

    if( inBlock ) {
        // jot down whether it started with #
        text = line->data;
        while( *text && isspace( *text ) ) {
            text++;
        }
        topChar = *text;

        // parse down through lines, noticing /*, */ and "
        while( line != thisline ) {
            text = line->data;
            for( ;; ) {
                while( *text && *text != '/' ) {
                    if( *text == '"' ) {
                        if( !withinQuotes ) {
                            withinQuotes = TRUE;
                        } else if( *( text - 1 ) != '\\' ||
                                   *( text - 2 ) == '\\' ) {
                            withinQuotes = FALSE;
                        }
                    }
                    text++;
                }
                if( *text == '\0' ) {
                    break;
                }
                if( !withinQuotes ) {
                    if( *( text - 1 ) == '/' ) {
                        flags.inCPPComment = TRUE;
                    } else if( *( text + 1 ) == '*' ) {
                        flags.inCComment = TRUE;
                        lenCComment = 100;
                    }
                }
                if( *( text - 1 ) == '*' && !withinQuotes ) {
                    flags.inCComment = FALSE;
                }
                text++;
            }
            rc = CGimmeNextLinePtr( &fcb, &line );
        }

        // if not in a comment (and none above), we may be string or pp
        if( !flags.inCComment ) {
            if( topChar == '#' && !EditFlags.PPKeywordOnly ) {
                flags.inPreprocessor = TRUE;
            }
            if( withinQuotes ) {
                flags.inString = TRUE;
            }
        }
    }

    if( topline == NULL ) {
        return;
    }

    if( !flags.inCComment ) {
        // keep going above multi-line thing till hit /* or */
        line = topline;
        do {
            starttext = line->data;
            text = starttext + line->len;
            for( ;; ) {
                while( text != starttext && *text != '/' ) {
                    text--;
                }
                if( *( text + 1 ) == '*' && *text == '/' &&
                    *( text - 1 ) != '/' ) {
                    if( text == starttext ) {
                        flags.inCComment = TRUE;
                        lenCComment = 100;
                        return;
                    }
                    withinQuotes = 0;
                    do {
                        text--;
                        if( *text == '"' ) {
                            if( !withinQuotes ) {
                                withinQuotes = TRUE;
                            } else if( *( text - 1 ) != '\\' ||
                                       *( text - 2 ) == '\\' ) {
                                withinQuotes = FALSE;
                            }
                        }
                    } while( text != starttext );
                    if( withinQuotes ) {
                        flags.inString = TRUE;
                    } else {
                        flags.inCComment = TRUE;
                        lenCComment = 100;
                    }
                    return;
                }
                if( text == starttext ) {
                    break;
                }
                if( *( text - 1 ) == '*' ) {
                    // we may actually be in a string, but that's extreme
                    // (if this becomes a problem, count the "s to beginning
                    // of line, check if multiline, etc. etc.)
                    return;
                }
                text--;
            }
            rc = GimmePrevLinePtr( &fcb, &line );
        } while( rc == ERR_NO_ERR );
    }
}

void GetRexxBlock( ss_block *ss_new, char *start, line *line, linenum line_no )
{
    line = line;
    line_no = line_no;

    if( start[ 0 ] == '\0' ) {
        if( firstNonWS == start ) {
            // line is empty -
            // do not flag following line as having anything to do
            // with an unterminated " or # or // from previous line
            flags.inString = flags.inPreprocessor = flags.inCPPComment = FALSE;
        }
        getBeyondText( ss_new );
        return;
    }

    if( flags.inCComment ) {
        getCComment( ss_new, start, 0 );
        return;
    }
    if( flags.inCPPComment ) {
        getCPPComment( ss_new, start );
        return;
    }
    if( flags.inPreprocessor ) {
        getPreprocessor( ss_new, start );
        return;
    }
    if( flags.inString ) {
        getString( ss_new, start, 0 );
        return;
    }

    if( isspace( start[ 0 ] ) ) {
        getWhiteSpace( ss_new, start );
        return;
    }

    if( *firstNonWS == '#' &&
        ( !EditFlags.PPKeywordOnly || firstNonWS == start ) ) {
        getPreprocessor( ss_new, start );
        return;
    }

    switch( start[ 0 ] ) {
        case '"':
            getString( ss_new, start, 1 );
            return;
        case '/':
            if( start[ 1 ] == '*' ) {
                getCComment( ss_new, start, 2 );
                return;
            } else if( start[ 1 ] == '/' ) {
                getCPPComment( ss_new, start );
                return;
            }
            break;
        case '\'':
            getChar( ss_new, start, 1 );
            return;
        case 'L':
            if( start[ 1 ] == '\'' ) {
                // wide char constant
                getChar( ss_new, start, 2 );
                return;
            }
            break;
        case '.':
            if( isdigit( start[ 1 ] ) ) {
                getFloat( ss_new, start, 1, AFTER_DOT );
                return;
            }
            break;
        case '0':
            if( start[ 1 ] == 'x' || start[ 1 ] == 'X' ) {
                getHex( ss_new, start );
                return;
            } else {
                getNumber( ss_new, start, '7' );
                return;
            }
            break;
    }

    if( issymbol( start[ 0 ] ) ) {
        getSymbol( ss_new );
        return;
    }

    if( isdigit( start[ 0 ] ) ) {
        getNumber( ss_new, start, '9' );
        return;
    }

    if( isalpha( *start ) || ( *start == '_' ) ) {
        getText( ss_new, start );
        return;
    }

    getInvalidChar( ss_new );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -