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

  1. /*    h_html.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_HTML
  13.  
  14. #define hsHTML_Normal  0
  15. #define hsHTML_Command 1
  16. #define hsHTML_String1 2
  17. #define hsHTML_String2 3
  18. #define hsHTML_Char    4
  19. #define hsHTML_Slashed 5
  20. #define hsHTML_Comment 6
  21.  
  22. int Hilit_HTML(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) {
  23.     ChColor *Colors = BF->Mode->fColorize->Colors;
  24.     HILIT_VARS(Colors[CLR_Normal], Line);
  25.     int j;
  26.  
  27.     for (i = 0; i < Line->Count;) {
  28.         IF_TAB() else {
  29.             switch (State) {
  30.             case hsHTML_Normal:
  31.                 Color = Colors[CLR_Normal];
  32.                 if (*p == '<') {
  33.                     State = hsHTML_Command;
  34.                     Color = Colors[CLR_Command];
  35.                     ColorNext();
  36.                     if ((len > 0) && (*p == '/')) ColorNext();
  37.                     continue;
  38.                 } else if (*p == '&') {
  39.                     State = hsHTML_Char;
  40.                     Color = Colors[CLR_Symbol];
  41.                 }
  42.                 goto hilit;
  43.             case hsHTML_Slashed:
  44.                 Color = Colors[CLR_Tag];
  45.                 if (*p == '/') {
  46.                     Color = Colors[CLR_Command];
  47.                     ColorNext();
  48.                     State = hsHTML_Normal;
  49.                     continue;
  50.                 }
  51.                 goto hilit;
  52.             case hsHTML_Command:
  53.                 Color = Colors[CLR_Command];
  54.         if (isalpha(*p) || *p == '_') {
  55.             j = 0;
  56.             while (((i + j) < Line->Count) &&
  57.                (isalnum(Line->Chars[i+j]) ||
  58.                 (Line->Chars[i + j] == '_'))
  59.                ) j++;
  60.             if (BF->GetHilitWord(j, &Line->Chars[i], Color, 1)) {
  61.             }
  62.             if (StateMap)
  63.             memset(StateMap + i, State, j);
  64.                     if (B) 
  65.             MoveMem(B, C - Pos, Width, Line->Chars + i, Color, j);
  66.             i += j;
  67.                     len -= j;
  68.                     p += j;
  69.                     C += j;
  70.                     Color = Colors[CLR_Command];
  71.                     continue;
  72.                 } else if (*p == '-' && len > 1 && p[1] == '-') {
  73.                     State = hsHTML_Comment;
  74.                     Color = Colors[CLR_Comment];
  75.                     ColorNext();
  76.                     goto hilit;
  77.                 } else if (*p == '"') {
  78.                     State = hsHTML_String2;
  79.                     Color = Colors[CLR_String];
  80.                     goto hilit;
  81.                 } else if (*p == '\'') {
  82.                     State = hsHTML_String1;
  83.                     Color = Colors[CLR_String];
  84.                     goto hilit;
  85.                 } else if (*p == '>') {
  86.                     ColorNext();
  87.                     State = hsHTML_Normal;
  88.                     continue;
  89.                 } else if (*p == '/') {
  90.                     ColorNext();
  91.                     State = hsHTML_Slashed;
  92.                     continue;
  93.                 }
  94.                 goto hilit;
  95.             case hsHTML_String2:
  96.                 Color = Colors[CLR_String];
  97.                 if (*p == '"') {
  98.                     ColorNext();
  99.                     State = hsHTML_Command;
  100.                     continue;
  101.                 }
  102.                 goto hilit;
  103.             case hsHTML_String1:
  104.                 Color = Colors[CLR_String];
  105.                 if (*p == '\'') {
  106.                     ColorNext();
  107.                     State = hsHTML_Command;
  108.                     continue;
  109.                 }
  110.                 goto hilit;
  111.             case hsHTML_Char:
  112.                 Color = Colors[CLR_Symbol];
  113.                 if (*p == ';' || *p == ' ' || *p == '<') {
  114.                     ColorNext();
  115.                     State = hsHTML_Normal;
  116.                     continue;
  117.                 }
  118.                 goto hilit;
  119.             case hsHTML_Comment:
  120.                 Color = Colors[CLR_Comment];
  121.                 if (*p == '-' && len > 1 && p[1] == '-') {
  122.                     ColorNext();
  123.                     ColorNext();
  124.                     State = hsHTML_Command;
  125.                     continue;
  126.                 }
  127.                 goto hilit;
  128.             default:
  129.                 State = hsHTML_Normal;
  130.                 Color = Colors[CLR_Normal];
  131.             hilit:
  132.                 ColorNext();
  133.                 continue;
  134.             }
  135.         }
  136.     }
  137.     if (State == hsHTML_Char)
  138.         State = hsHTML_Normal;
  139.     *ECol = C;
  140.     return 0;
  141. }
  142.  
  143. #endif
  144.