home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / STYLE.PEL < prev    next >
Text File  |  1995-03-27  |  11KB  |  267 lines

  1. # $Header:   P:\source\wmacros\style.pev   1.49   27 Mar 1995 16:48:38   PFHJXM0  $
  2.  
  3. ##############################################################################
  4. #
  5. #       Compuware Corporation
  6. #         31440 Northwestern Highway
  7. #           Farmington Hills, Michigan 48334-2564
  8. #
  9. #   This source code listing contains information that is
  10. #   proprietary to Compuware Corporation and may not be copied
  11. #   duplicated, translated, transmitted, stored, retrieved
  12. #   or in any manner or by any method conveyed or disclosed
  13. #   to a third party or parties without express written
  14. #   permission from Compuware Corporation.
  15. #
  16. #  
  17. ##############################################################################
  18.  
  19. #### $Workfile:   style.pel  $: 
  20.  
  21. global defined_styles[];
  22. global save_styles[];
  23.  
  24. global CATEGORY_ALL         = 0x0009
  25. global CATEGORY_RESERVED    = 0x0102
  26. global CATEGORY_COMMENT     = 0x0209
  27. global CATEGORY_LITERAL     = 0x030D
  28.  
  29. global CATEGORY_TYPE        = 0x040A
  30. global CATEGORY_DIRECTIVE   = 0x050B
  31. global CATEGORY_CONSTANT    = 0x060B
  32.  
  33. global CATEGORY_FUNCTIONS   = 0x070A
  34. global CATEGORY_PROCEDURES  = 0x0802
  35.  
  36. global CATEGORY_DIVISION    = 0x090B
  37. global CATEGORY_CLAUSE      = 0x0A0B
  38. global CATEGORY_EXPRESSIONS = 0x0B02
  39. global CATEGORY_SECTION     = 0x0C02
  40. global CATEGORY_STATEMENTS  = 0x0D0A
  41. global CATEGORY_PARAGRAPH   = 0x0e0A
  42.  
  43. global VDIFF_PLUS           = 0x0011;
  44. global VDIFF_MINUS          = 0x0012;
  45. global VDIFF_BLANK          = 0x0013;
  46.  
  47. global syntax_colors_fg[];
  48. global syntax_colors_bg[];
  49.  
  50. global function set_factory_categories(type)
  51. {
  52.    local index = shiftr(and(CATEGORY_RESERVED, not(CATEGORY_MASK)), 8);
  53.    local fg    = query_syntax_style(and(CATEGORY_RESERVED, not(ITEM_MASK)), 0);
  54.    local bg    = query_syntax_style(and(CATEGORY_RESERVED, not(ITEM_MASK)), 1);
  55.  
  56.    add_syntax_category(type, index, "Reserved words", fg, bg);
  57.  
  58.    index = shiftr(and(CATEGORY_ALL, not(CATEGORY_MASK)), 8);
  59.    fg    = query_syntax_style(and(CATEGORY_ALL, not(ITEM_MASK)), 0);
  60.    bg    = query_syntax_style(and(CATEGORY_ALL, not(ITEM_MASK)), 1);
  61.    add_syntax_category(type, index, "All", fg, bg);
  62.  
  63.    index = shiftr(and(CATEGORY_COMMENT, not(CATEGORY_MASK)), 8);
  64.    fg    = query_syntax_style(and(CATEGORY_COMMENT, not(ITEM_MASK)), 0);
  65.    bg    = query_syntax_style(and(CATEGORY_COMMENT, not(ITEM_MASK)), 1);
  66.    add_syntax_category(type, index, "Comments", fg, bg);
  67.  
  68.    index = shiftr(and(CATEGORY_LITERAL, not(CATEGORY_MASK)), 8);
  69.    fg    = query_syntax_style(and(CATEGORY_LITERAL, not(ITEM_MASK)), 0);
  70.    bg    = query_syntax_style(and(CATEGORY_LITERAL, not(ITEM_MASK)), 1);
  71.    add_syntax_category(type, index, "Literals", fg, bg);
  72.  
  73.    index = shiftr(and(CATEGORY_TYPE, not(CATEGORY_MASK)), 8);
  74.    fg    = query_syntax_style(and(CATEGORY_TYPE, not(ITEM_MASK)), 0);
  75.    bg    = query_syntax_style(and(CATEGORY_TYPE, not(ITEM_MASK)), 1);
  76.    add_syntax_category(type, index, "Types", fg, bg);
  77.  
  78.    if(type == "c")
  79.    {
  80.       index = shiftr(and(CATEGORY_DIRECTIVE, not(CATEGORY_MASK)), 8);
  81.       fg    = query_syntax_style(and(CATEGORY_DIRECTIVE, not(ITEM_MASK)), 0);
  82.       bg    = query_syntax_style(and(CATEGORY_DIRECTIVE, not(ITEM_MASK)), 1);
  83.       add_syntax_category(type, index, "Directives", fg, bg);
  84.        
  85.       index = shiftr(and(CATEGORY_CONSTANT, not(CATEGORY_MASK)), 8);
  86.       fg    = query_syntax_style(and(CATEGORY_CONSTANT, not(ITEM_MASK)), 0);
  87.       bg    = query_syntax_style(and(CATEGORY_CONSTANT, not(ITEM_MASK)), 1);
  88.       add_syntax_category(type, index, "Constants", fg, bg);
  89.    }
  90.  
  91.    if(type == "cobol")
  92.    {
  93.       index = shiftr(and(CATEGORY_DIVISION, not(CATEGORY_MASK)), 8);
  94.       fg    = query_syntax_style(and(CATEGORY_DIVISION, not(ITEM_MASK)), 0);
  95.       bg    = query_syntax_style(and(CATEGORY_DIVISION, not(ITEM_MASK)), 1);
  96.       add_syntax_category(type, index, "Divisions", fg, bg);
  97.  
  98.       index = shiftr(and(CATEGORY_PARAGRAPH, not(CATEGORY_MASK)), 8);
  99.       fg    = query_syntax_style(and(CATEGORY_PARAGRAPH, not(ITEM_MASK)), 0);
  100.       bg    = query_syntax_style(and(CATEGORY_PARAGRAPH, not(ITEM_MASK)), 1);
  101.       add_syntax_category(type, index, "Paragraphs", fg, bg);
  102.  
  103.       index = shiftr(and(CATEGORY_SECTION, not(CATEGORY_MASK)), 8);
  104.       fg    = query_syntax_style(and(CATEGORY_SECTION, not(ITEM_MASK)), 0);
  105.       bg    = query_syntax_style(and(CATEGORY_SECTION, not(ITEM_MASK)), 1);
  106.       add_syntax_category(type, index, "Sections", fg, bg);
  107.  
  108.       index = shiftr(and(CATEGORY_CLAUSE, not(CATEGORY_MASK)), 8);
  109.       fg    = query_syntax_style(and(CATEGORY_CLAUSE, not(ITEM_MASK)), 0);
  110.       bg    = query_syntax_style(and(CATEGORY_CLAUSE, not(ITEM_MASK)), 1);
  111.       add_syntax_category(type, index, "Clauses", fg, bg);
  112.  
  113.       index = shiftr(and(CATEGORY_EXPRESSIONS, not(CATEGORY_MASK)), 8);
  114.       fg    = query_syntax_style(and(CATEGORY_EXPRESSIONS, not(ITEM_MASK)), 0);
  115.       bg    = query_syntax_style(and(CATEGORY_EXPRESSIONS, not(ITEM_MASK)), 1);
  116.       add_syntax_category(type, index, "Expressions", fg, bg);
  117.  
  118.       index = shiftr(and(CATEGORY_STATEMENTS, not(CATEGORY_MASK)), 8);
  119.       fg    = query_syntax_style(and(CATEGORY_STATEMENTS, not(ITEM_MASK)), 0);
  120.       bg    = query_syntax_style(and(CATEGORY_STATEMENTS, not(ITEM_MASK)), 1);
  121.       add_syntax_category(type, index, "Statements", fg, bg);
  122.    }
  123.  
  124.    if(type == "pascal")
  125.    {
  126.       index = shiftr(and(CATEGORY_FUNCTIONS, not(CATEGORY_MASK)), 8);
  127.       fg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 0);
  128.       bg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 1);
  129.       add_syntax_category(type, index, "Functions", fg, bg);
  130.  
  131.       index = shiftr(and(CATEGORY_PROCEDURES, not(CATEGORY_MASK)), 8);
  132.       fg    = query_syntax_style(and(CATEGORY_PROCEDURES, not(ITEM_MASK)), 0);
  133.       bg    = query_syntax_style(and(CATEGORY_PROCEDURES, not(ITEM_MASK)), 1);
  134.       add_syntax_category(type, index, "Procedures", fg, bg);
  135.    }
  136.  
  137.    if(type == "rexx")
  138.    {
  139.       index = shiftr(and(CATEGORY_FUNCTIONS, not(CATEGORY_MASK)), 8);
  140.       fg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 0);
  141.       bg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 1);
  142.       add_syntax_category(type, index, "Functions", fg, bg);
  143.    }
  144. }
  145.   
  146. # These are the colors returned in the first
  147. # 16 entries of get_color_table().  
  148. #local SI_BACKGROUND    = 0x000000
  149. #local SI_BLUE          = 0x000001
  150. #local SI_RED           = 0x000002
  151. #local SI_PINK          = 0x000003
  152. #local SI_GREEN         = 0x000004
  153. #local SI_CYAN          = 0x000005
  154. #local SI_YELLOW        = 0x000006
  155. #local SI_NUETRAL       = 0x000007
  156. #
  157. #local SI_DARK_GRAY     = 0x000008
  158. #local SI_DARK_BLUE     = 0x000009
  159. #local SI_DARK_RED      = 0x00000A
  160. #local SI_DARK_PINK     = 0x00000B
  161. #local SI_DARK_GREEN    = 0x00000C
  162. #local SI_DARK_CYAN     = 0x00000D
  163. #local SI_BROWN         = 0x00000E
  164. #local SI_PALE_GRAY     = 0x00000F
  165.  
  166. global function load_factory_syntax_colors()
  167. {
  168.    local available_colors = get_color_table()
  169.  
  170.    delete syntax_colors_fg;
  171.    delete syntax_colors_bg;
  172.  
  173.    syntax_colors_fg[0x10001] = available_colors[0]
  174.    syntax_colors_fg[0x20001] = available_colors[1]
  175.    syntax_colors_fg[0x30001] = available_colors[2]
  176.    syntax_colors_fg[0x40001] = available_colors[3]
  177.    syntax_colors_fg[0x50001] = available_colors[4]
  178.    syntax_colors_fg[0x60001] = available_colors[5]
  179.    syntax_colors_fg[0x70001] = available_colors[6]
  180.    syntax_colors_fg[0x80001] = available_colors[7]
  181.  
  182.    syntax_colors_fg[0x10002] = available_colors[8]
  183.    syntax_colors_fg[0x20002] = available_colors[9]
  184.    syntax_colors_fg[0x30002] = available_colors[10]
  185.    syntax_colors_fg[0x40002] = available_colors[11]
  186.    syntax_colors_fg[0x50002] = available_colors[12]
  187.    syntax_colors_fg[0x60002] = available_colors[13]
  188.    syntax_colors_fg[0x70002] = available_colors[14]
  189.    syntax_colors_fg[0x80002] = available_colors[15]
  190.  
  191.    #  Background colors
  192.    syntax_colors_bg[0x10001] = available_colors[0]
  193.    syntax_colors_bg[0x20001] = available_colors[1]
  194.    syntax_colors_bg[0x30001] = available_colors[2]
  195.    syntax_colors_bg[0x40001] = available_colors[3]
  196.    syntax_colors_bg[0x50001] = available_colors[4]
  197.    syntax_colors_bg[0x60001] = available_colors[5]
  198.    syntax_colors_bg[0x70001] = available_colors[6]
  199.    syntax_colors_bg[0x80001] = available_colors[7]
  200.  
  201.    syntax_colors_bg[0x10002] = available_colors[8]
  202.    syntax_colors_bg[0x20002] = available_colors[9]
  203.    syntax_colors_bg[0x30002] = available_colors[10]
  204.    syntax_colors_bg[0x40002] = available_colors[11]
  205.    syntax_colors_bg[0x50002] = available_colors[12]
  206.    syntax_colors_bg[0x60002] = available_colors[13]
  207.    syntax_colors_bg[0x70002] = available_colors[14]
  208.    syntax_colors_bg[0x80002] = available_colors[15]
  209. }
  210.  
  211. #  
  212. #  No styles may be created before this function is called;
  213. #  This function assumes no styles exist.
  214. #  The syntax_colors array must also be defined.  The colors defined
  215. #  there are accessed in this function.
  216. #  
  217. global function load_factory_default_styles()
  218. {
  219.    local DEFAULT  = -1, index, row, col;
  220.    
  221.    #  Create the 16 default styles (16 foreground colors on default background);
  222.    for(row = 1; row <= 2; row++)
  223.    {
  224.       for(col = 1; col <= 8; col++)
  225.       {
  226.          index = or(shiftl(col, 16), row);
  227.  
  228.          create_syntax_style(syntax_colors_fg[index] , DEFAULT);
  229.          defined_styles[syntax_colors_fg[index]][DEFAULT] = ((row-1)*8)+col;
  230.       }
  231.    }
  232.  
  233.    #  Create VDIFF styles;
  234.    create_syntax_style(COLOR_WHITE, COLOR_BROWN);
  235.    defined_styles[COLOR_WHITE][COLOR_BROWN] = 0x11;
  236.  
  237.    create_syntax_style(COLOR_WHITE, COLOR_DARK_BLUE);
  238.    defined_styles[COLOR_WHITE][COLOR_DARK_BLUE] = 0x12;
  239.  
  240.    create_syntax_style(COLOR_DARK_BLUE, COLOR_DARK_BLUE);
  241.    defined_styles[COLOR_DARK_BLUE][COLOR_DARK_BLUE] = 0x13;
  242. }
  243.  
  244. global function syntax_new_buffer()
  245. {
  246.    local ext = path_ext(buffer_filename);
  247.  
  248.    if(!and(buffer_flags, BUFFER_SYSTEM))
  249.    {
  250.       #  TODO: this is here until electric_mode is turned into a buffer variable;
  251.       #  if(Template(ext) != ELEC_LANG)
  252.       #  {  this "if" was not correct.  we can have the same template mapped
  253.       #     to different types with one on and the other off
  254.  
  255.       #  If we have a deifferent template or the same template with a different status, toggle;
  256.       if((Template(ext) != ELEC_LANG) || xor(get_expand_template(ext), electric_mode))
  257.           toggle_electric(get_expand_template(ext));
  258.  
  259.       matching_pairs = MatchingPairs(ext);
  260.       #     languages_id = languages_id;
  261.  
  262.       #  These variables were made buffer variables and don't need to be set here;
  263.       #  style_delimiter = StyleDelimiters(ext) "";
  264.       #  escape_character = EscapeCharacter(ext) "";
  265.    }
  266. }
  267.