示例#1
0
static int SetGlobalString(long what, const char *string) {
    STARTFUNC("SetGlobalString");
    LOG << "What: " << what << " String: " << string << ENDLINE;

    switch (what) {
    case FLAG_DefaultModeName: strlcpy(DefaultModeName, string, sizeof(DefaultModeName)); break;
    case FLAG_CompletionFilter: if ((CompletionFilter = RxCompile(string)) == NULL) return -1; break;
    case FLAG_PrintDevice: strlcpy(PrintDevice, string, sizeof(PrintDevice)); break;
    case FLAG_CompileCommand: strlcpy(CompileCommand, string, sizeof(CompileCommand)); break;
    case FLAG_WindowFont: strlcpy(WindowFont, string, sizeof(WindowFont)); break;
    case FLAG_HelpCommand: strlcpy(HelpCommand, string, sizeof(HelpCommand)); break;
    case FLAG_GUICharacters: AppendGUICharacters (string); break;
#ifdef CONFIG_OBJ_CVS
    case FLAG_CvsCommand: strlcpy(CvsCommand, string, sizeof(CvsCommand)); break;
    case FLAG_CvsLogMode: strlcpy(CvsLogMode, string, sizeof(CvsLogMode)); break;
#endif
#ifdef CONFIG_OBJ_SVN
    case FLAG_SvnCommand: strlcpy(SvnCommand, string, sizeof(SvnCommand)); break;
    case FLAG_SvnLogMode: strlcpy(SvnLogMode, string, sizeof(SvnLogMode)); break;
#endif
    case FLAG_RGBColor: SetRGBColor(string); break;
    case FLAG_XShellCommand: strlcpy(XShellCommand, string, sizeof(XShellCommand)); break;
    default:
        //printf("Unknown global string: %ld\n", what);
        ENDFUNCRC(-1);
    }
    ENDFUNCRC(0);
}
示例#2
0
文件: h_c.cpp 项目: lecheel/fte-fork
int LookAt(EBuffer *B, int Row, unsigned int Pos, const char *What, hsState State, int NoWord, int CaseInsensitive) {
    STARTFUNC("LookAt{h_c.cpp}");

    int Len = strlen(What);

    if (Row < 0 || Row >= B->RCount) {
        LOG << "Row out of range: " << Row << " vs " << B->RCount << ENDLINE;
        ENDFUNCRC(0);
    }
    char*        pLine       = B->RLine(Row)->Chars;
    unsigned int uLineLength = B->RLine(Row)->Count;
    Pos = B->CharOffset(B->RLine(Row), Pos);
    if (Pos + strlen(What) > uLineLength) { ENDFUNCRC(0); }
    if (NoWord && uLineLength > Pos + Len && ISNAME(pLine[Pos + Len]))
    {
        ENDFUNCRC(0);
    }
    LOG << "Check against [" << What << ']' << ENDLINE;
    if (
        (CaseInsensitive && memicmp(pLine + Pos, What, Len) == 0) ||
        (!CaseInsensitive && memcmp(pLine + Pos, What, Len) == 0)
       )
    {
        ENDFUNCRC(1);
    }
    else
    {
        ENDFUNCRC(0);
    }
}
示例#3
0
static int SetColorizeString(EColorize *Colorize, long what, const char *string) {
    STARTFUNC("SetColorizeString");
    LOG << "What: " << what << " String: " << string << ENDLINE;
    switch (what) {
    case COL_SyntaxParser:
        Colorize->SyntaxParser = GetHilitMode(string);
        break;
    default:
        ENDFUNCRC(-1);
    }
    ENDFUNCRC(0);
}
示例#4
0
static const char *GetCharStr(CurPos &cp, unsigned short len) {
    STARTFUNC("GetCharStr");
    LOG << "Length: " << len << ENDLINE;

    const char *p = cp.c;
    if (cp.c + len > cp.z)
    {
        LOG << "End of config file in GetCharStr" << ENDLINE;
        ENDFUNCRC(0);
    }
    cp.c += len;
    ENDFUNCRC(p);
}
示例#5
0
static int SetEventString(EEventMap *Map, long what, const char *string) {
    STARTFUNC("SetEventString");
    LOG << "What: " << what << " String: " << string << ENDLINE;
    switch (what) {
    case EM_MainMenu:
    case EM_LocalMenu:
        Map->SetMenu(what, string);
        break;
    default:
        ENDFUNCRC(-1);
    }
    ENDFUNCRC(0);
}
示例#6
0
static int ReadCommands(CurPos &cp, const char *Name) {
    STARTFUNC("ReadCommands");
    LOG << "Name = " << (Name != NULL ? Name : "(null)") << ENDLINE;

    unsigned char obj;
    unsigned short len;
    long Cmd = NewCommand(Name);
    long cmdno;

    if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
    if (GetNum(cp, cmdno) == 0) ENDFUNCRC(-1);
    if (cmdno != (Cmd | CMD_EXT)) {
        fprintf(stderr, "Bad Command map %s -> %ld != %ld\n", Name, Cmd, cmdno);
        ENDFUNCRC(-1);
    }

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_COMMAND:
            {
                //              char *s;
                long cnt;
                long ign;
                long cmd;

                //                if ((s = GetCharStr(cp, len)) == 0) return -1;
                if (GetNum(cp, cmd) == 0) ENDFUNCRC(-1);
                if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
                if (GetNum(cp, cnt) == 0) ENDFUNCRC(-1);
                if (GetObj(cp, len) != CF_INT) ENDFUNCRC(-1);
                if (GetNum(cp, ign) == 0) ENDFUNCRC(-1);

                //                if (cmd != CmdNum(s)) {
                //                    fprintf(stderr, "Bad Command Id: %s -> %d\n", s, cmd);
                //                    return -1;
                //                }

                if (AddCommand(Cmd, cmd, cnt, ign) == 0) {
                    if (Name == 0 || strcmp(Name, "xx") != 0) {
                        fprintf(stderr, "Bad Command Id: %ld\n", cmd);
                        ENDFUNCRC(-1);
                    }
                }
            }
            break;
        case CF_STRING:
            {
                const char *s = GetCharStr(cp, len);

                if (s == 0) ENDFUNCRC(-1);
                if (AddString(Cmd, s) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_INT:
            {
                long num;

                if (GetNum(cp, num) == 0) ENDFUNCRC(-1);
                if (AddNumber(Cmd, num) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_VARIABLE:
            {
                long num;

                if (GetNum(cp, num) == 0) ENDFUNCRC(-1);
                if (AddVariable(Cmd, num) == 0) ENDFUNCRC(-1);
            }
            break;
        case CF_CONCAT:
            if (AddConcat(Cmd) == 0) ENDFUNCRC(-1);
            break;
        case CF_END:
            ENDFUNCRC(Cmd);
        default:
            ENDFUNCRC(-1);
        }
    }
    ENDFUNCRC(-1);
}
示例#7
0
static int SetGlobalNumber(int what, int number) {
    STARTFUNC("SetGlobalNumber");
    LOG << "What: " << what << " Number: " << number << ENDLINE;

    switch (what) {
#ifdef CONFIG_INDENT_C
    case FLAG_C_Indent:          C_Indent = number; break;
    case FLAG_C_BraceOfs:        C_BraceOfs = number; break;
    case FLAG_C_CaseOfs:         C_CaseOfs = number; break;
    case FLAG_C_CaseDelta:       C_CaseDelta = number; break;
    case FLAG_C_ClassOfs:        C_ClassOfs = number; break;
    case FLAG_C_ClassDelta:      C_ClassDelta = number; break;
    case FLAG_C_ColonOfs:        C_ColonOfs = number; break;
    case FLAG_C_CommentOfs:      C_CommentOfs = number; break;
    case FLAG_C_CommentDelta:    C_CommentDelta = number; break;
    case FLAG_C_FirstLevelIndent: C_FirstLevelIndent = number; break;
    case FLAG_C_FirstLevelWidth: C_FirstLevelWidth = number; break;
    case FLAG_C_Continuation:    C_Continuation = number; break;
    case FLAG_C_ParenDelta:      C_ParenDelta = number; break;
    case FLAG_FunctionUsesContinuation: FunctionUsesContinuation = number; break;
#endif
#ifdef CONFIG_INDENT_REXX
    case FLAG_REXX_Indent:       REXX_Base_Indent = number; break;
    case FLAG_REXX_Do_Offset:    REXX_Do_Offset = number; break;
#endif
    case FLAG_ScreenSizeX:       ScreenSizeX = number; break;
    case FLAG_ScreenSizeY:       ScreenSizeY = number; break;
    case FLAG_CursorInsertStart: CursorInsSize[0] = number; break;
    case FLAG_CursorInsertEnd:   CursorInsSize[1] = number; break;
    case FLAG_CursorOverStart:   CursorOverSize[0] = number; break;
    case FLAG_CursorOverEnd:     CursorOverSize[1] = number; break;
    case FLAG_CursorBlink:       CursorBlink = number; break;
    case FLAG_SysClipboard:      SystemClipboard = number; break;
    case FLAG_OpenAfterClose:    OpenAfterClose = number; break;
    case FLAG_ShowVScroll:       ShowVScroll = number; break;
    case FLAG_ShowHScroll:       ShowHScroll = number; break;
    case FLAG_ScrollBarWidth:    ScrollBarWidth = number; break;
    case FLAG_SelectPathname:    SelectPathname = number; break;
    case FLAG_ShowMenuBar:       ShowMenuBar = number; break;
    case FLAG_ShowToolBar:       ShowToolBar = number; break;
    case FLAG_KeepHistory:       KeepHistory = number; break;
    case FLAG_LoadDesktopOnEntry: LoadDesktopOnEntry = number; break;
    case FLAG_SaveDesktopOnExit: SaveDesktopOnExit = number; break;
    case FLAG_KeepMessages:      KeepMessages = number; break;
    case FLAG_ScrollBorderX:     ScrollBorderX = number; break;
    case FLAG_ScrollBorderY:     ScrollBorderY = number; break;
    case FLAG_ScrollJumpX:       ScrollJumpX = number; break;
    case FLAG_ScrollJumpY:       ScrollJumpY = number; break;
    case FLAG_GUIDialogs:        GUIDialogs = number; break;
    case FLAG_PMDisableAccel:    PMDisableAccel = number; break;
    case FLAG_SevenBit:          SevenBit = number; break;
    case FLAG_WeirdScroll:       WeirdScroll = number; break;
    case FLAG_LoadDesktopMode:   LoadDesktopMode = number; break;
    case FLAG_IgnoreBufferList:  IgnoreBufferList = number; break;
    case FLAG_ReassignModelIds:  ReassignModelIds = number; break;
    case FLAG_RecheckReadOnly:   RecheckReadOnly = number; break;
    default:
        //printf("Unknown global number: %d\n", what);
        ENDFUNCRC(-1);
    }
    ENDFUNCRC(0);
}
示例#8
0
int LoadConfig(int /*argc*/, char ** /*argv*/, char *CfgFileName) {
    STARTFUNC("LoadConfig");
    LOG << "Config file: " << CfgFileName << ENDLINE;

    int fd, rc;
    char *buffer = 0;
    struct stat statbuf;
    CurPos cp;

    if ((fd = open(CfgFileName, O_RDONLY | O_BINARY)) == -1)
        ENDFUNCRC(-1);
    if (fstat(fd, &statbuf) != 0) {
        close(fd);
        ENDFUNCRC(-1);
    }

    // check that we have enough room for signature (CONFIG_ID + VERNUM)
    if (statbuf.st_size < (4+4)) {
        close(fd);
        DieError(0, "Bad .CNF signature");
        ENDFUNCRC(-1);
    }

    buffer = (char *) malloc(statbuf.st_size);
    if (buffer == 0) {
        close(fd);
        ENDFUNCRC(-1);
    }
    if (read(fd, buffer, statbuf.st_size) != statbuf.st_size) {
        close(fd);
        free(buffer);
        ENDFUNCRC(-1);
    }
    close(fd);

    unsigned char l[4];
    unsigned long ln;

    memcpy(l, buffer, 4);
    ln = (l[3] << 24) + (l[2] << 16) + (l[1] << 8) + l[0];

    if (ln != CONFIG_ID) {
        free(buffer);
        DieError(0, "Bad .CNF signature");
        ENDFUNCRC(-1);
    }

    memcpy(l, buffer + 4, 4);
    ln = (l[3] << 24) + (l[2] << 16) + (l[1] << 8) + l[0];

    if (ln != VERNUM) {
        LOG << hex << ln << " != " << VERNUM << ENDLINE;
        free(buffer);
        DieError(0, "Bad .CNF version.");
        ENDFUNCRC(-1);
    }

    cp.name = CfgFileName;
    cp.sz = statbuf.st_size;
    cp.a = buffer;
    cp.c = cp.a + 2 * 4;
    cp.z = cp.a + cp.sz;
    cp.line = 1;

    rc = ReadConfigFile(cp);

    free(buffer);

    if (rc == -1) {
        DieError(1, "Error %s offset %d\n", CfgFileName, cp.c - cp.a);
    }
    ENDFUNCRC(rc);
}
示例#9
0
文件: h_c.cpp 项目: lecheel/fte-fork
static int FindPrevIndent(EBuffer *B, int &RowP, int &ColP, char &CharP, int Flags)
{
    STARTFUNC("FindPrevIndent{h_c.cpp}");
    LOG << "Flags: " << hex << Flags << dec << ENDLINE;
    int StateLen;
    hsState *StateMap = 0;
    char *P;
    int L;
    int Count[4] = {
        0, // { }
        0, // ( )
        0, // [ ]
        0, // if/else (one if for each else)
    };

    assert(RowP >= 0 && RowP < B->RCount);
    L = B->RLine(RowP)->Count;
    if (ColP >= L)
        ColP = L - 1;
    assert(ColP >= -1 && ColP <= L);

    char BolChar = ' ';
    int BolCol = -1;
    int BolRow = -1;

    while (RowP >= 0) {

        P = B->RLine(RowP)->Chars;
        L = B->RLine(RowP)->Count;
        StateMap = NULL;
        if (B->GetMap(RowP, &StateLen, &StateMap) == 0)
        {
            LOG << "Can't get state maps" << ENDLINE;
            ENDFUNCRC(0);
        }
	if (L > 0)
	    while (ColP >= 0) {
            LOG << "ColP: " << ColP << " State: " << (int)StateMap[ColP] << ENDLINE;
            if (StateMap[ColP] == hsC_Normal) {
                LOG << "CharP: " << BinChar(P[ColP]) << " BolChar: " << BinChar(BolChar) <<
                    " BolRow: " << BolRow <<
                    " BolCol: " << BolCol <<
                    ENDLINE;
                switch (CharP = P[ColP]) {
                case '{':
                    if (BolChar == ':' || BolChar == ',') {
                        CharP = BolChar;
                        ColP = BolCol;
                        RowP = BolRow;
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
		    if (TEST_ZERO) {
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    Count[0]--;
                    break;
                case '}':
                    if (BolChar == ':' || BolChar == ',') {
                        CharP = BolChar;
                        ColP = BolCol;
                        RowP = BolRow;
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if (BolChar == ';') {
                        CharP = BolChar;
                        ColP = BolCol;
                        RowP = BolRow;
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if (ColP == 0) { /* speed optimization */
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
		    if (TEST_ZERO && (Flags & FIND_ENDBLOCK)) {
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    Count[0]++;
                    break;
                case '(':
		    if (TEST_ZERO) {
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    Count[1]--;
                    break;
                case ')':
                    Count[1]++;
                    break;
                case '[':
                    if (TEST_ZERO) {
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    Count[2]--;
                    break;
                case ']':
                    Count[2]++;
                    break;
                case ':':
                    if (ColP >= 1 && P[ColP - 1] == ':') { // skip ::
                        ColP -= 2;
                        continue;
                    }
                case ',':
                case ';':
                    if (TEST_ZERO && BolChar == ' ') {
			if ((CharP == ';' && (Flags & FIND_SEMICOLON))
			    || (CharP == ',' && (Flags & FIND_COMMA))
			    || (CharP == ':' && (Flags & FIND_COLON))) {
                            BolChar = CharP;
                            BolCol = ColP;
			    BolRow = RowP;
			    // this should be here
                            // if not say why ???
			    //free(StateMap);
			    //return 1;
                        }
                    }
                    if (BolChar == ',' && CharP == ':') {
                        BolChar = ' ';
                        BolCol = -1;
                        BolRow = -1;
                        break;
                    }
		    if ((BolChar == ':' || BolChar == ',')
			&& (CharP == ';'/* || CharP == ','*/)) {
                        CharP = ':';
                        ColP = BolCol;
                        RowP = BolRow;
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    break;
                case '?':
                    //if ((Flags & FIND_QUESTION)) {
                    if (BolChar == ':' || BolChar == ',') {
                        BolChar = ' ';
                        BolCol = -1;
                        BolRow = -1;
                    }
                    //}
                    break;
                }
            } else if (StateMap[ColP] == hsC_Keyword && (BolChar == ' ' || BolChar == ':')) {
                if (L - ColP >= 2 &&
                    IsState(StateMap + ColP, hsC_Keyword, 2) &&
                    memcmp(P + ColP, "if", 2) == 0)
                {
                    //puts("\nif");
                    if (Count[3] > 0)
                        Count[3]--;
                    if (Flags & FIND_IF) {
                        if (TEST_ZERO) {
                            CharP = 'i';
                            free(StateMap);
                            ENDFUNCRC(1);
                        }
                    }
                }
                if (L - ColP >= 4 &&
                    IsState(StateMap + ColP, hsC_Keyword, 4) &&
                    memcmp(P + ColP, "else", 4) == 0)
                {
                    //puts("\nelse\x7");
                    if (Flags & FIND_ELSE) {
			if (TEST_ZERO) {
                            CharP = 'e';
                            free(StateMap);
                            ENDFUNCRC(1);
                        }
                    }
                    Count[3]++;
                }
		if (TEST_ZERO) {

                    if ((Flags & FIND_FOR) &&
                        L - ColP >= 3 &&
                        IsState(StateMap + ColP, hsC_Keyword, 3) &&
                        memcmp(P + ColP, "for", 3) == 0)
                    {
                        CharP = 'f';
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if ((Flags & FIND_WHILE) &&
                        L - ColP >= 5 &&
                        IsState(StateMap + ColP, hsC_Keyword, 5) &&
                        memcmp(P + ColP, "while", 5) == 0)
                    {
                        CharP = 'w';
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if ((Flags & FIND_SWITCH) &&
                        L - ColP >= 6 &&
                        IsState(StateMap + ColP, hsC_Keyword, 6) &&
                        memcmp(P + ColP, "switch", 6) == 0)
                    {
                        CharP = 's';
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if (((Flags & FIND_CASE) || (BolChar == ':')) &&
                        (L - ColP >= 4 &&
                         IsState(StateMap + ColP, hsC_Keyword, 4) &&
                         memcmp(P + ColP, "case", 4) == 0) ||
                        ((L - ColP >= 7) &&
                         IsState(StateMap + ColP, hsC_Keyword, 7) &&
                         memcmp(P + ColP, "default", 7) == 0))
                    {
                        CharP = 'c';
                        if (BolChar == ':') {
                            CharP = BolChar;
                            ColP = BolCol;
                            RowP = BolRow;
                        }
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if (((Flags & FIND_CLASS) || (BolChar == ':')) &&
                        (L - ColP >= 5 &&
                         IsState(StateMap + ColP, hsC_Keyword, 5) &&
                         memcmp(P + ColP, "class", 5) == 0))
                    {
                        CharP = 'l';
                        if (BolChar == ':') {
                            CharP = BolChar;
                            ColP = BolCol;
                            RowP = BolRow;
                        }
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                    if (((Flags & FIND_CLASS) || (BolChar == ':')) &&
                        ((L - ColP >= 6 &&
                          IsState(StateMap + ColP, hsC_Keyword, 6) &&
                          memcmp(P + ColP, "public", 6) == 0) ||
                         ((L - ColP >= 7) &&
                          IsState(StateMap + ColP, hsC_Keyword, 7) &&
                          memcmp(P + ColP, "private", 7) == 0) ||
                         ((L - ColP >= 9) &&
                          IsState(StateMap + ColP, hsC_Keyword, 9) &&
                          memcmp(P + ColP, "protected", 9) == 0)))
                    {
                        CharP = 'p';
                        if (BolChar == ':') {
                            CharP = BolChar;
                            ColP = BolCol;
                            RowP = BolRow;
                        }
                        free(StateMap);
                        ENDFUNCRC(1);
                    }
                }
            }
            ColP--;
        }
        free(StateMap);
        if (BolChar != ' ' && BolChar != ':' && BolChar != ',') {
            CharP = BolChar;
            ColP = BolCol;
            ENDFUNCRC(1);
        }
        RowP--;
        if (RowP >= 0) {
            L = B->RLine(RowP)->Count;
            ColP = L - 1;
        }
    }
#undef TEST_ZERO
    ENDFUNCRC(0);
}