void Buffer::TrimLeft( unsigned int iTrimAmount ) { if ( iTrimAmount == 0 ) return; if ( iTrimAmount > GetWritten() ) iTrimAmount = GetWritten(); MoveMem( iTrimAmount, GetWritten() - iTrimAmount, 0 ); if ( m_iPos > iTrimAmount ) m_iPos -= iTrimAmount; else m_iPos = 0; m_iWritten -= iTrimAmount; }
/* WARNING: fwd_copy() doesn't call dirty_tty(), you must call it manually! */ static void fwd_copy(hwattr *s, hwattr *d, ldat len) { ldat l; while (s >= Split) s -= Split - Base; while (d >= Split) d -= Split - Base; while (len > 0) { l = Min2(len, Split - s); l = Min2(l, Split - d); MoveMem(s, d, l * sizeof(hwattr)); // s and d can overlap! s += l; d += l; len -= l; if (s == Split) s = Base; if (d == Split) d = Base; } }
/* WARNING: rev_copy() doesn't call dirty_tty(), you must call it manually! */ static void rev_copy(hwattr *s, hwattr *d, ldat len) { ldat l; s += len; d += len; while (s > Split) s -= Split - Base; while (d > Split) d -= Split - Base; while (len > 0) { l = Min2(len, s - Base); l = Min2(l, d - Base); s -= l; d -= l; len -= l; MoveMem(s, d, l * sizeof(hwattr)); if (s == Base) s = Split; if (d == Base) d = Split; } }
int Hilit_MSG(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine* Line, hlState& State, hsState *StateMap, int *ECol) { HILIT_VARS(BF->Mode->fColorize->Colors, Line); int is_head = 0, is_quote = 0, is_space = 0, is_tag = 0, is_control = 0; if (Line->Count > 0) { if (State == hsMSG_Header) { if (Line->Chars[0] == ' ' || Line->Chars[0] == '\t') is_head = 1; else State = hsMSG_Normal; } if (State == hsMSG_Normal) { if (Line->Count >= 2 && Line->Chars[0] == '-' && Line->Chars[1] == '-' && (Line->Count == 2 || Line->Chars[2] == ' ')) is_tag = 1; else if (Line->Count >= 2 && Line->Chars[0] == '.' && Line->Chars[1] == '.' && (Line->Count == 2 || Line->Chars[2] == ' ')) is_tag = 1; else if (Line->Count >= 3 && Line->Chars[0] == '-' && Line->Chars[1] == '-' && Line->Chars[2] == '-' && (Line->Count == 3 || Line->Chars[3] == ' ')) is_tag = 1; else if (Line->Count >= 3 && Line->Chars[0] == '.' && Line->Chars[1] == '.' && Line->Chars[2] == '.' && (Line->Count == 3 || Line->Chars[3] == ' ')) is_tag = 1; else if (Line->Count > 10 && memcmp(Line->Chars, " * Origin:", 10) == 0) is_control = 1; else if (Line->Count > 0 && Line->Chars[0] == '\x01') is_control = 1; else for (i = 0; i < Line->Count; i++) { if (i < 30 && Line->Chars[i] == ':' && i < Line->Count - 1 && Line->Chars[i+1] == ' ' && !is_space) { is_head = 1; break; } else if (i < 5 && Line->Chars[i] == '>') { is_quote = 1; break; } else if (Line->Chars[i] == '<' || (Line->Chars[i] == ' ' && i > 0) || Line->Chars[i] == '\t') break; else if (Line->Chars[i] == ' ' || Line->Chars[i] == '\t') is_space = 0; } } } if (is_head) { State = hsMSG_Header; Color = CLR_Header; } else if (is_quote) { State = hsMSG_Quote; Color = CLR_Quotes; } else if (is_tag) { State = hsMSG_Tag; Color = CLR_Tag; } else if (is_control) { State = hsMSG_Control; Color = CLR_Control; } else { State = hsMSG_Normal; Color = CLR_Normal; } ChColor DefColor = Color; int j = 0; if (BF->Mode->fColorize->Keywords.TotalCount > 0 || BF->WordCount > 0) { /* words have to be hilited, go slow */ for (i = 0; i < Line->Count;) { IF_TAB() else { if (isalpha(*p) || (*p == '_')) { j = 0; while (((i + j) < Line->Count) && (isalnum(Line->Chars[i+j]) || (Line->Chars[i + j] == '_')) ) j++; if (BF->GetHilitWord(j, Line->Chars + i, Color, 1)) ; else { Color = DefColor; } if (StateMap) memset(StateMap + i, State, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; Color = DefColor; continue; } ColorNext(); continue; } } } else if (ExpandTabs) { /* use slow mode */
int Hilit_SIMPLE(EBuffer *BF, int LN, PCell B, int Pos, int Width, ELine *Line, hlState& State, hsState *StateMap, int *ECol) { EColorize *col = BF->Mode->fColorize; HMachine *hm = col->hm; HILIT_VARS(col->Colors, Line); HState *st = 0; HTrans *tr = 0; int t, cc; int quotech = 0; int matchFlags; int matchLen; int nextState; char *match; int lastPos = -1; hlState entryState; int iterCount; bool reportError = true; if ((hm == 0) || (hm->stateCount == 0)) return 0; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; /*{ fprintf(stderr, "ColMode:%s, State:%d\n", col->Name, State); for (int s = 0; s < hm->stateCount; s++) { fprintf(stderr, "State:%d, transCount:%d, firstTrans:%d, options:%d, color:%d, nextState:%d\n", s, hm->state[s].transCount, hm->state[s].firstTrans, hm->state[s].options, hm->state[s].color, hm->state[s].nextState); } for (int t = 0; t < hm->transCount; t++) { fprintf(stderr, "Trans:%d, matchLen:%d, matchFlags:%d, nextState:%d, color:%d\n", t, hm->trans[t].matchLen, hm->trans[t].matchFlags, hm->trans[t].nextState, hm->trans[t].color); } //exit(1); sleep(5); }*/ for (i = 0; i < Line->Count;) { // Check for infinite loops if (i == lastPos) { if (++iterCount > hm->stateCount) { // Passed the same position more times than number of states -> must be // looping if (reportError) { // Report only once per line since other errors may be false alarms // caused by hiliter restart reportError = false; BF->Msg(S_INFO, "Hiliter looping at line %d, column %d, entry state %d", LN + 1, i + 1, entryState); } else { // Already reported - advance by one character Color = hm->state[entryState].color; IF_TAB() else ColorNext(); } // Restart with state 0 State = 0; st = hm->state; iterCount = 1; goto next_state; } } else { lastPos = i; entryState = State; iterCount = 1; } if (quotech) { quotech = 0; } else { for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; // fprintf(stderr, // "line:%d, char:%d (%c), len:%d, state:%d, tr:%d, // st->transCount:%d, st->firstTrans:%d, nextState:%d, // matchFlags:%08x\n", // LN, i, *p, len, State, t, st->transCount, st->firstTrans, // nextState, matchFlags); if (len < matchLen) continue; if ((i > 0) && (matchFlags & MATCH_MUST_BOL)) continue; if ((matchFlags & (MATCH_SET | MATCH_NOTSET)) == 0) { if (matchFlags & MATCH_REGEXP) { RxMatchRes b; if (!RxExecMatch(tr->regexp, Line->Chars, Line->Count, p, &b, (matchFlags & MATCH_NO_CASE) ? 0 : RX_CASE)) continue; if ((b.Open[1] != -1) && (b.Close[1] != -1)) matchLen = b.Open[1] - i; else matchLen = b.Close[0] - i; } else if (matchFlags & MATCH_NO_CASE) { if (memicmp(match, p, matchLen)) continue; } else { for (cc = 0; cc < matchLen; cc++) if (p[cc] != match[cc]) goto next_trans; } } else if (matchFlags & MATCH_SET) { if (!WGETBIT(match, *p)) continue; } else if (matchFlags & MATCH_NOTSET) { if (WGETBIT(match, *p)) continue; } if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) continue; if (matchFlags & MATCH_NOGRAB) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; // fprintf(stderr, "nograb\n"); } else { if (matchFlags & MATCH_TAGASNEXT) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } Color = tr->color; for (cc = 0; cc < matchLen; cc++) IF_TAB() else ColorNext(); if (!(matchFlags & MATCH_TAGASNEXT)) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } if (len > 0) { if (matchFlags & MATCH_QUOTECH) quotech = 1; } else if (len == 0) { if (matchFlags & MATCH_QUOTEEOL) goto end_parse; /* see note below !! */ } } // fprintf(stderr, "next state\n"); goto next_state; next_trans: /* */ ; } if (st->wordChars != 0) { int j; hlState MState = State; j = 0; while (((i + j) < Line->Count) && (WGETBIT(st->wordChars, Line->Chars[i + j]))) j++; // GP (fix) Color = st->color; if (j == 0) { if (st->nextKwdNoCharState != -1) { State = st->nextKwdNoCharState; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } else { if (st->GetHilitWord(j, &Line->Chars[i], Color) || BF->GetHilitWord(j, &Line->Chars[i], Color, BFI(BF, BFI_MatchCase) ? 0 : 1)) { if (st->nextKwdMatchedState != -1) State = st->nextKwdMatchedState; } else { if (st->nextKwdNotMatchedState != -1) { State = st->nextKwdNotMatchedState; if (st->options & STATE_NOGRAB) { if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } } if (State >= hm->stateCount) State = 0; // highlight/tag as next state if (st->options & STATE_TAGASNEXT) { MState = State; st = hm->state + State; Color = st->color; } if (StateMap) memset(StateMap + i, MState, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; if (!(st->options & STATE_TAGASNEXT)) { st = hm->state + State; Color = st->color; } goto next_state; } } } Color = st->color; IF_TAB() else ColorNext(); next_state: /* */ ; }
int Hilit_FTE(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) { int j = 0; HILIT_VARS(BF->Mode->fColorize->Colors, Line); int len1 = len; char *last = p + len1 - 1; C = 0; NC = 0; for (i = 0; i < Line->Count;) { IF_TAB() else { switch(State) { default: case hsFTE_Normal: if (isalpha(*p) || *p == '_') { j = 0; while (((i + j) < Line->Count) && (isalnum(Line->Chars[i+j]) || (Line->Chars[i + j] == '_')) ) j++; if (BF->GetHilitWord(j, &Line->Chars[i], Color)) { State = hsFTE_Keyword; } else { Color = CLR_Normal; State = hsFTE_Normal; } if (StateMap) memset(StateMap + i, State, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; State = hsFTE_Normal; continue; } else if (*p == '#') { State = hsFTE_Comment; Color = CLR_Comment; goto hilit; } else if (*p == '%') { State = hsFTE_CPP; Color = CLR_CPreprocessor; goto hilit; } else if (isdigit(*p)) { Color = CLR_Number; ColorNext(); while (len && (isdigit(*p) || *p == 'e' || *p == 'E' || *p == '.')) ColorNext(); if (len && (toupper(*p) == 'U')) ColorNext(); if (len && (toupper(*p) == 'L')) ColorNext(); continue; } else if (*p == '\'') { State = hsFTE_String1; Color = CLR_String; goto hilit; } else if (*p == '[') { State = hsFTE_KeySpec; Color = CLR_Command; goto hilit; } else if (*p == '"') { State = hsFTE_String2; Color = CLR_String; goto hilit; } else if (*p == '/') { State = hsFTE_Regexp; Color = CLR_Regexp; goto hilit; } else if (ispunct(*p)) { Color = CLR_Punctuation; ColorNext(); continue; } Color = CLR_Normal; ColorNext(); continue; case hsFTE_Comment: Color = CLR_Comment; goto hilit; case hsFTE_CPP: Color = CLR_CPreprocessor; goto hilit; case hsFTE_String1: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { hilit2: ColorNext(); hilit: ColorNext(); continue; } else if (*p == '\'') { ColorNext(); State = hsFTE_Normal; continue; } goto hilit; case hsFTE_String2: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '"') { ColorNext(); State = hsFTE_Normal; continue; } goto hilit; case hsFTE_KeySpec: Color = CLR_Command; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == ']') { ColorNext(); State = hsFTE_Normal; continue; } goto hilit; case hsFTE_Regexp: Color = CLR_Regexp; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '/') { ColorNext(); State = hsFTE_Normal; continue; } goto hilit; } } } if (State == hsFTE_Comment) State = hsFTE_Normal; if ((len1 == 0) || (*last != '\\')) { switch(State) { case hsFTE_CPP: case hsFTE_String1: case hsFTE_String2: case hsFTE_KeySpec: case hsFTE_Regexp: State = hsFTE_Normal; break; } } *ECol = C; return 0; }
void * memmove (void * t1, const void * t2, size_t len) { MoveMem((APTR)t2, t1, len); return t1; }
int Hilit_SH(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) { HILIT_VARS(BF->Mode->fColorize->Colors, Line); int CommandStr = 0; int isEOF = 0; int parenCount = 0; int bracketCount = 0; for (i = 0; i < Line->Count;) { if (State == hsSH_EOF && 0 == i) { //printf("i=%d, len=%d, strlen(seof)=%d, seof=%s, Line-Chars=%s\n", // i, len, strlen(seof), seof, Line->Chars); // Skip past any leading tabs. char* iseof = Line->Chars; size_t len_left = len; while (*iseof == '\t') ++iseof, --len_left; isEOF = strlen(seof) == len_left && strncmp(seof, iseof, len_left) == 0; } IF_TAB() else { int j = 1; if (!isspace(*p)) CommandStr++; switch( *p ) { case '(': parenCount++; break; case ')': parenCount--; break; case '[': bracketCount++; break; case ']': bracketCount--; break; } Color = CLR_Normal; switch (State) { case hsSH_Normal: if (CommandStr == 1 && len > 2 && *p == '.' && isspace(p[1])) { Color = CLR_Keyword; } else if (isalpha(*p) || *p == '_' || ((CommandStr == 1) && (*p == '/' || *p == '.'))) { while (len > j && (isalnum(p[j]) || strchr("_-[]$", p[j]) != NULL || ((CommandStr == 1) && (p[j] == '/' || p[j] == '.')))) j++; if (p[j] == '=') Color = CLR_Variable; else if (p[j] == '*' || p[j] == ')') Color = CLR_Normal; else { if (!BF->GetHilitWord(j, p, Color, 0)) { // Color for good match is set by this function Color = (CommandStr == 1) ? CLR_Command : CLR_Normal; //printf("Command %d %c%c\n", //CommandStr, //Line->Chars[i],Line->Chars[i+1]); } else { if (i > 0 && p[-1] != ';' && p[-1] != '(' && !isspace(p[-1])) Color = CLR_Normal; else { int s; switch (j) { case 2: s = strncmp(p, "in", j); break; case 3: s = strncmp(p, "for", j); break; case 4: s = strncmp(p, "read", j); break; case 5: s = strncmp(p, "unset", j); break; case 6: s = strncmp(p, "export", j); break; default: s = 1; break; } if (s) CommandStr = 0; } } } break; } else if (*p == '[' || *p == ']' || (CommandStr == 1 && *p == '!')) { CommandStr = 0; Color = CLR_Keyword; //Colors[CLR_Control]; //static a=0; //if (!a) {for(int i=0;i<COUNT_CLR;i++) //printf("%d %d\n", i, Colors[i]); //a++;} //same state } else if (*p == '\'') { State = hsSH_SQuote; Color = CLR_String; } else if (*p == '"') { State = hsSH_DQuote; Color = CLR_String; } else if (len >= 2 && *p == '\\' && p[1] == '\'') { Color = CLR_String; ColorNext(); } else if (len >= 2 && *p == '\\' && p[1] == '"') { Color = CLR_String; ColorNext(); } else if (len >= 2 && *p == '\\' && p[1] == '`') { Color = CLR_Command; ColorNext(); } else if (*p == '`') { State = hsSH_BQuote; Color = CLR_Command; } else if (*p == '~') { Color = CLR_Variable; } else if (*p == '$') { State = hsSH_Variable; Color = CLR_Variable; } else if (*p == '#') { State = hsSH_Comment; Color = CLR_Comment; //} else if (isdigit(*p)) { //Color = CLR_Number; //while (len > 0 && (isdigit(*p))) //ColorNext(); //continue; } else if (len > 3 && parenCount < 1 && bracketCount < 1 && *p == '<' && p[1] == '<' && p[2] != '<' && ( i == 0 || p[-1] != '<' ) ) { // !!! this is a hack, doesn't work properly -- Mark char *s = seof; j++; if (p[2] == '-') j++; Color = CLR_Control; while (len > j && (isspace(p[j]) || p[j] == '\'' || p[j] == '"')) j++; if (p[j] == '\\') j++; while (len > j && !(isspace(p[j]) || p[j] == '\'' || p[j] == '"')) *s++ = p[j++]; if (len > j && (p[j] == '\'' || p[j] == '"')) j++; *s = 0; State = hsSH_EOF; break; } else if (*p == '=' || *p == '\\' || *p == '>' || *p == '<' || *p == '!' /*|| *p == ':'*/) { Color = CLR_Control; } else if (strchr(";|&(){}", *p) != NULL) { CommandStr = 0; Color = CLR_Control; } break; case hsSH_SQuote: Color = CLR_String; if ((len >= 2) && (*p == '\\')) j++; else if (*p == '\'') State = hsSH_Normal; break; case hsSH_DQuote: Color = CLR_String; if ((len >= 2) && (*p == '\\')) j++; else if (*p == '"') State = hsSH_Normal; else if (*p == '`') { Color = CLR_Command; State = hsSH_DBQuote; } break; case hsSH_BQuote: Color = CLR_Command; if ((len >= 2) && (*p == '\\')) j++; else if (*p == '`') State = hsSH_Normal; break; case hsSH_DBQuote: Color = CLR_Command; if ((len >= 2) && (*p == '\\')) j++; else if (*p == '`') State = hsSH_DQuote; break; case hsSH_Variable: Color = CLR_Variable; State = hsSH_Normal; if (!isdigit(*p)) { int b = 1; if (*p == '{') b = 2; else if (*p == '[') b = 3; while (b && len > 0 && (isalnum(*p) || (strchr("{}[]_", *p) != NULL) || (b == 2 && (strchr("#%:-=?+/", *p) != NULL)) || (b == 1 && (strchr("*@#?-$!", *p) != NULL) /*|| (b == 0, 1) ????? */) ) ) { // !!!!! ????? // in ${...}, once we hit a :, %, or #, anything goes. // Ideally, we'd do normal processing inside as well, // but that'll take much, much longer to figure out // how to do. if (b == 2 && strchr("#%:", *p) != NULL) { UntilMatchBrace('{', ColorNext()); break; } if (b == 2 && *p == '}') b = 0; else if (b == 3 && *p == ']') b = 0; ColorNext(); } continue; } break; case hsSH_Comment: Color = CLR_Comment; break; case hsSH_EOF: Color = CLR_String; if (isEOF) { Color = CLR_Control; State = hsSH_Normal; j += len - 1; } break; default: State = hsSH_Normal; Color = CLR_Normal; } if (StateMap) memset(StateMap + i, State, j); if (B) MoveMem(B, C - Pos, Width, p, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; } } if (State == hsSH_Comment || State == hsSH_Variable) State = hsSH_Normal; *ECol = C; return 0; }
int Hilit_C(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) { int j = 0; int firstnw = 0; HILIT_VARS(BF->Mode->fColorize->Colors, Line); int len1 = len; char *last = p + len1 - 1; int was_include = 0; for(i = 0; i < Line->Count;) { if (*p != ' ' && *p != 9) firstnw++; IF_TAB() else { switch(State) { default: case hsC_Normal: if (toupper(*p) == 'L' && p[1] == '"') { State = hsC_String2; Color = CLR_String; goto hilit2; } else if (toupper(*p) == 'L' && p[1] == '\'') { State = hsC_String1; Color = CLR_String; goto hilit2; } else if (isalpha(*p) || *p == '_') { j = 0; while (((i + j) < Line->Count) && ISNAME(Line->Chars[i + j])) j++; if (BF->GetHilitWord(j, &Line->Chars[i], Color)) { //Color = hcC_Keyword; State = hsC_Keyword; } else { int x; x = i + j; while (x < Line->Count && isspace(Line->Chars[x])) x++; if (x < Line->Count && Line->Chars[x] == '(') { Color = CLR_Function; } else if ((x < Line->Count) && (Line->Chars[x] == ':' && (x == Line->Count - 1 || Line->Chars[x + 1] != ':')) && firstnw == 1) { Color = CLR_Label; } else { Color = CLR_Normal; } State = hsC_Normal; } if (StateMap) memset(StateMap + i, State, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; State = hsC_Normal; continue; } else if ((len >= 2) && (*p == '/') && (*(p+1) == '*')) { State = hsC_Comment; Color = CLR_Comment; goto hilit2; } else if ((len >= 2) && (*p == '/') && (p[1] == '/')) { State = hsC_CommentL; Color = CLR_Comment; goto hilit2; } else if (isdigit(*p)) { // check if it is not floating point number 0.08! if ((len >= 2) && (*p == '0') && p[1] != '.') { if (toupper(*(p+1)) == 'X') { Color = CLR_HexNumber; ColorNext(); ColorNext(); while (len && isxdigit(*p)) ColorNext(); } else /* assume it's octal */ { Color = CLR_Number; ColorNext(); while (len && ('0' <= *p && *p <= '7')) ColorNext(); // if we hit a non-octal, stop hilighting it. if (len && ('8' <= *p && *p <= '9')) { Color = CLR_Normal; while (len && !isspace(*p)) ColorNext(); continue; } } } else /* assume it's decimal/floating */ { Color = CLR_Number; ColorNext(); while (len && (isdigit(*p) || *p == 'e' || *p == 'E' || *p == '.')) ColorNext(); // if it ends with 'f', the number can't have more extras. if (len && (toupper(*p) == 'F')) { ColorNext(); continue; } } // allowed extras: u, l, ll, ul, ull, lu, llu int colored_u = 0; if (len && (toupper(*p) == 'U')) { ColorNext(); colored_u = 1; } if (len && (toupper(*p) == 'L')) { ColorNext(); if (len && (toupper(*p) == 'L')) ColorNext(); if (! colored_u && len && (toupper(*p) == 'U')) ColorNext(); } continue; } else if (*p == '\'') { State = hsC_String1; Color = CLR_String; goto hilit; } else if (*p == '"') { State = hsC_String2; Color = CLR_String; goto hilit; } else if (firstnw == 1 && *p == '#') { State = hsC_CPP; Color = CLR_CPreprocessor; goto hilit; } else if (ispunct(*p) && *p != '_') { Color = CLR_Punctuation; goto hilit; } Color = CLR_Normal; goto hilit; case hsC_Comment: Color = CLR_Comment; if ((len >= 2) && (*p == '*') && (*(p+1) == '/')) { ColorNext(); ColorNext(); State = hsC_Normal; continue; } goto hilit; case hsC_CPP_Comm: Color = CLR_Comment; if ((len >= 2) && (*p == '*') && (*(p+1) == '/')) { ColorNext(); ColorNext(); State = hsC_CPP; continue; } goto hilit; case hsC_CPP_ABrace: Color = CLR_String; if (*p == '>') { Color = CLR_CPreprocessor; State = hsC_CPP; } goto hilit; case hsC_CommentL: Color = CLR_Comment; goto hilit; case hsC_String1: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '\'') { ColorNext(); State = hsC_Normal; continue; } goto hilit; case hsC_String2: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '"') { ColorNext(); State = hsC_Normal; continue; } goto hilit; case hsC_CPP_String1: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '\'') { ColorNext(); State = hsC_CPP; continue; } goto hilit; case hsC_CPP_String2: Color = CLR_String; if ((len >= 2) && (*p == '\\')) { goto hilit2; } else if (*p == '"') { ColorNext(); State = hsC_CPP; continue; } goto hilit; case hsC_CPP: if (ISNAME(*p)) { j = 0; Color = CLR_CPreprocessor; while (((i + j) < Line->Count) && (isalnum(Line->Chars[i+j]) || (Line->Chars[i + j] == '_')) ) j++; if (j == 7 && memcmp(Line->Chars + i, "include", 7) == 0) was_include = 1; if (StateMap) memset(StateMap + i, State, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; continue; } else if ((len >= 2) && (*p == '/') && (*(p+1) == '*')) { State = hsC_CPP_Comm; Color = CLR_Comment; goto hilit2; } else if ((len >= 2) && (*p == '/') && (*(p+1) == '/')) { State = hsC_CommentL; Color = CLR_Comment; hilit2: ColorNext(); hilit: ColorNext(); continue; } else if (isdigit(*p)) { if ((len >= 2) && (*p == '0')) { if (toupper(*(p+1)) == 'X') { Color = CLR_HexNumber; ColorNext(); ColorNext(); while (len && isxdigit(*p)) ColorNext(); } else /* assume it's octal */ { Color = CLR_Number; ColorNext(); while (len && ('0' <= *p && *p <= '7')) ColorNext(); // if we hit a non-octal, stop hilighting it. if (len && ('8' <= *p && *p <= '9')) { Color = CLR_Normal; while (len && !isspace(*p)) ColorNext(); continue; } } } else /* assume it's decimal/floating */ { Color = CLR_Number; ColorNext(); while (len && (isdigit(*p) || *p == 'e' || *p == 'E' || *p == '.')) ColorNext(); // if it ends with 'f', the number can't have more extras. if (len && (toupper(*p) == 'F')) { ColorNext(); continue; } } // allowed extras: u, l, ll, ul, ull, lu, llu int colored_u = 0; if (len && (toupper(*p) == 'U')) { ColorNext(); colored_u = 1; } if (len && (toupper(*p) == 'L')) { ColorNext(); if (len && (toupper(*p) == 'L')) ColorNext(); if (! colored_u && len && (toupper(*p) == 'U')) ColorNext(); } continue; } else if (*p == '\'') { State = hsC_CPP_String1; Color = CLR_String; goto hilit; } else if (*p == '"') { State = hsC_CPP_String2; Color = CLR_String; goto hilit; } else if (*p == '<' && was_include) { ColorNext(); State = hsC_CPP_ABrace; continue; } else { Color = CLR_CPreprocessor; goto hilit; } } } } if (State == hsC_CommentL) State = hsC_Normal; if ((len1 == 0) || (*last != '\\')) { switch(State) { case hsC_String1: case hsC_String2: case hsC_CPP: case hsC_CPP_String1: case hsC_CPP_String2: State = hsC_Normal; break; } } *ECol = C; return 0; }
int Hilit_SIMPLE(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) { EColorize *col = BF->Mode->fColorize; HMachine *hm = col->hm; HILIT_VARS(col->Colors, Line); HState *st = 0; HTrans *tr = 0; int t, cc; int quotech = 0; int matchFlags; int matchLen; int nextState; char *match; if (hm == 0 || hm->stateCount == 0) return 0; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; /*{ fprintf(stderr, "ColMode:%s, State:%d\n", col->Name, State); for (int s = 0; s < hm->stateCount; s++) { fprintf(stderr, "State:%d, transCount:%d, firstTrans:%d, options:%d, color:%d, nextState:%d\n", s, hm->state[s].transCount, hm->state[s].firstTrans, hm->state[s].options, hm->state[s].color, hm->state[s].nextState); } for (int t = 0; t < hm->transCount; t++) { fprintf(stderr, "Trans:%d, matchLen:%d, matchFlags:%d, nextState:%d, color:%d\n", t, hm->trans[t].matchLen, hm->trans[t].matchFlags, hm->trans[t].nextState, hm->trans[t].color); } //exit(1); sleep(5); }*/ for (i = 0; i < Line->Count; ) { if (quotech) { quotech = 0; } else { for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; //fprintf(stderr, // "line:%d, char:%d (%c), len:%d, state:%d, tr:%d, st->transCount:%d, st->firstTrans:%d, nextState:%d, matchFlags:%08x\n", // LN, i, *p, len, State, t, st->transCount, st->firstTrans, nextState, matchFlags); if (len < matchLen) continue; if ((i > 0) && (matchFlags & MATCH_MUST_BOL)) continue; if ((matchFlags & (MATCH_SET | MATCH_NOTSET)) == 0) { if (matchFlags & MATCH_REGEXP) { RxMatchRes b; if (!RxExecMatch(tr->regexp, Line->Chars, Line->Count, p, &b, (matchFlags & MATCH_NO_CASE) ? 0 : RX_CASE)) continue; if (b.Open[1] != -1 && b.Close[1] != -1) matchLen = b.Open[1] - i; else matchLen = b.Close[0] - i; } else if (matchFlags & MATCH_NO_CASE) { if (memicmp(match, p, matchLen)) continue; } else { for (cc = 0; cc < matchLen; cc++) if (p[cc] != match[cc]) goto next_trans; } } else if (matchFlags & MATCH_SET) { if (!WGETBIT(match, *p)) continue; } else if (matchFlags & MATCH_NOTSET) { if (WGETBIT(match, *p)) continue; } if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) continue; if (matchFlags & MATCH_NOGRAB) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; //fprintf(stderr, "nograb\n"); } else { if (matchFlags & MATCH_TAGASNEXT) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } Color = tr->color; for (cc = 0; cc < matchLen; cc++) IF_TAB() else ColorNext(); if (!(matchFlags & MATCH_TAGASNEXT)) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } if (len > 0) { if (matchFlags & MATCH_QUOTECH) quotech = 1; } else if (len == 0) { if (matchFlags & MATCH_QUOTEEOL) goto end_parse; /* see note below !! */ } } //fprintf(stderr, "next state\n"); goto next_state; next_trans: /* */; } if (st->wordChars != 0) { int j; hlState MState = State; j = 0; while (((i + j) < Line->Count) && (WGETBIT(st->wordChars, Line->Chars[i + j]))) j++; //GP (fix) Color = st->color; if (j == 0) { if (st->nextKwdNoCharState != -1) { State = st->nextKwdNoCharState; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } else { if (st->GetHilitWord(j, &Line->Chars[i], Color ) || BF->GetHilitWord(j, &Line->Chars[i], Color, BFI( BF, BFI_MatchCase ) ? 0 : 1)) { if (st->nextKwdMatchedState != -1) State = st->nextKwdMatchedState; } else { if (st->nextKwdNotMatchedState != -1) { State = st->nextKwdNotMatchedState; if (st->options & STATE_NOGRAB) { if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } } if (State >= hm->stateCount) State = 0; // highlight/tag as next state if (st->options & STATE_TAGASNEXT) { MState = State; st = hm->state + State; Color = st->color; } if (StateMap) memset(StateMap + i, MState, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; if (!(st->options & STATE_TAGASNEXT)) { st = hm->state + State; Color = st->color; } goto next_state; } } } Color = st->color; IF_TAB() else ColorNext(); next_state: /* */; } /* check if there are any matches for EOL */ /* NOTE: this is skipped when Q option is used above. !! */ for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; if (((i > 0) && (matchFlags & MATCH_MUST_BOL)) || (matchFlags & MATCH_REGEXP)) continue; //cant match eol beyond eol. //if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) //continue; if (matchLen == 0) { State = nextState; if (State >= hm->stateCount) State = 0; break; } } end_parse: ; *ECol = C; return 0; }