home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ftes46b5.zip / ftes46b5 / src / h_ipf.cpp < prev    next >
C/C++ Source or Header  |  1997-05-30  |  3KB  |  108 lines

  1. /*    h_ipf.cpp
  2.  *
  3.  *    Copyright (c) 1994-1996, Marko Macek
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #include "fte.h"
  11.  
  12. #ifdef CONFIG_HILIT_IPF
  13.  
  14. #define hsIPF_Normal  0
  15. #define hsIPF_Symbol  1
  16. #define hsIPF_Tag     2
  17. #define hsIPF_Control 3
  18. #define hsIPF_String  4
  19.  
  20. int Hilit_IPF(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) {
  21.     ChColor *Colors = BF->Mode->fColorize->Colors;
  22.     HILIT_VARS(Colors[CLR_Normal], Line);
  23.     int j;
  24.  
  25.     C = 0;
  26.     NC = 0;
  27.     for (i = 0; i < Line->Count;) {
  28.         IF_TAB() else {
  29.             switch (State) {
  30.             case hsIPF_Normal:
  31.                 Color = Colors[CLR_Normal];
  32.                 if (i == 0 && *p == '.') {
  33.                     State = hsIPF_Control;
  34.                     Color = Colors[CLR_Control];
  35.                 } else if (*p == ':') {
  36.                     State = hsIPF_Tag;
  37.                     Color = Colors[CLR_Tag];
  38.                 } else if (*p == '&') {
  39.                     State = hsIPF_Symbol;
  40.                     Color = Colors[CLR_Symbol];
  41.                 }
  42.                 goto hilit;
  43.             case hsIPF_Tag:
  44.                 Color = Colors[CLR_Tag];
  45.         if (isalpha(*p) || *p == '_') {
  46.             j = 0;
  47.             while (((i + j) < Line->Count) &&
  48.                (isalnum(Line->Chars[i+j]) ||
  49.                 (Line->Chars[i + j] == '_'))
  50.                ) j++;
  51.             if (BF->GetHilitWord(j, &Line->Chars[i], Color, 1)) {
  52.             }
  53.             if (StateMap)
  54.             memset(StateMap + i, State, j);
  55.                     if (B) 
  56.             MoveMem(B, C - Pos, Width, Line->Chars + i, Color, j);
  57.             i += j;
  58.                     len -= j;
  59.                     p += j;
  60.                     C += j;
  61.                     Color = Colors[CLR_Tag];
  62.                     continue;
  63.                 } else if (*p == '\'') {
  64.                     State = hsIPF_String;
  65.                     Color = Colors[CLR_String];
  66.                     goto hilit;
  67.                 } else if (*p == '.') {
  68.                     ColorNext();
  69.                     State = hsIPF_Normal;
  70.                     continue;
  71.                 }
  72.                 goto hilit;
  73.             case hsIPF_String:
  74.                 Color = Colors[CLR_String];
  75.                 if (*p == '\'') {
  76.                     ColorNext();
  77.                     State = hsIPF_Tag;
  78.                     continue;
  79.                 }
  80.                 goto hilit;
  81.             case hsIPF_Symbol:
  82.                 Color = Colors[CLR_Symbol];
  83.                 if (*p == '.') {
  84.                     ColorNext();
  85.                     State = hsIPF_Normal;
  86.                     continue;
  87.                 }
  88.                 goto hilit;
  89.             case hsIPF_Control:
  90.                 State = hsIPF_Control;
  91.                 Color = Colors[CLR_Control];
  92.                 goto hilit;
  93.             default:
  94.                 State = hsIPF_Normal;
  95.                 Color = Colors[CLR_Normal];
  96.             hilit:
  97.                 ColorNext();
  98.                 continue;
  99.             }
  100.         }
  101.     }
  102.     if (State == hsIPF_Symbol || State == hsIPF_Control || State == hsIPF_String)
  103.         State = hsIPF_Normal;
  104.     *ECol = C;
  105.     return 0;
  106. }
  107. #endif
  108.