home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / DBRIEF.ZIP / SOURCE / TEMPLATE.M < prev   
Encoding:
Text File  |  1991-03-21  |  8.7 KB  |  298 lines

  1. ;dBRIEF Template - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro _prg_template
  6.     (
  7.         (int                constant_position
  8.                             template_counter
  9.                             template_case
  10.                             command_type
  11.         )
  12.         (string            template_token
  13.         )
  14.         (if (&& (== (read 1) "\n")(== dbr_template 1))
  15.             (
  16.                 (save_position)
  17.                 (beginning_of_line)
  18.                 (= temp_str (+ (trim (ltrim (read))) " "))
  19.                 (if (< (atoi (substr temp_str 1 1) 0) 97)
  20.                     (= template_case 1)
  21.                 )
  22.                 (restore_position)
  23.                 (if (&& (! (index " \t\n" (substr temp_str 1 1))) (&& (strlen temp_str) (< (strlen temp_str) 6)))
  24.                     (switch (trim (upper temp_str))
  25.                         (_do_case_syntax 0)
  26.                             (
  27.                                 (inq_position NULL curr_indent_col)
  28.                                 (-= curr_indent_col 4)
  29.                                 (_case_insert (+ (_do_case_syntax 1) "\n") 0 4 template_case)
  30.                                 (= template_counter 0)
  31.                                 (while (< (++ template_counter) 4)
  32.                                     (
  33.                                         (if (== dbr_indent_case 2)
  34.                                             (move_abs 0 (+ curr_indent_col dbr_indent_level))
  35.                                         ;else
  36.                                             (move_abs 0 curr_indent_col)
  37.                                         )
  38.                                         (_case_insert (+ (_do_case_syntax 2) " \n") 0 0 template_case)
  39.                                         (move_abs 0 (+ curr_indent_col (* dbr_indent_level dbr_indent_case)))
  40.                                         (_case_insert (+ (_do_case_syntax 3) "\n") 0 0 template_case)
  41.                                     )
  42.                                 )
  43.                                 (if (== dbr_indent_case 2)
  44.                                     (move_abs 0 (+ curr_indent_col dbr_indent_level))
  45.                                 ;else
  46.                                     (move_abs 0 curr_indent_col)
  47.                                 )
  48.                                 (_case_insert (+ (_do_case_syntax 4) "\n") 0 0 template_case)
  49.                                 (move_abs 0 (+ curr_indent_col (* dbr_indent_level dbr_indent_case)))
  50.                                 (_case_insert (+ (_do_case_syntax 3) "\n") 0 0 template_case)
  51.                                 (move_abs 0 curr_indent_col)
  52.                                 (if (index (upper temp_str) (+ (_do_case_syntax 0) " "))
  53.                                     (_case_insert (+ (_do_case_syntax 5) "\n") 0 0 template_case)
  54.                                 )
  55.                                 (delete_line)
  56.                                 (move_rel -9 0)
  57.                                 (end_of_line)
  58.                                 (delete_to_eol)
  59.                             )
  60.                         (_do_while_syntax 0)
  61.                             (
  62.                                 (inq_position NULL curr_indent_col)
  63.                                 (-= curr_indent_col 4)
  64.                                 (save_position)
  65.                                 (_case_insert (+ (_do_while_syntax 1) "\n\n") 0 4 template_case)
  66.                                 (restore_position)
  67.                                 (save_position)
  68.                                 (move_rel 2 0)
  69.                                 (_case_insert (+ (_do_while_syntax 2) "\n") 0 4 template_case)
  70.                                 (delete_line)
  71.                                 (restore_position)
  72.                                 (+= curr_indent_col dbr_indent_level)
  73.                                 (down)
  74.                                 (move_abs 0 curr_indent_col)
  75.                             )
  76.                         NULL
  77.                             (if (|| (== (strlen (trim temp_str)) 3)(== (strlen (trim temp_str)) 4))
  78.                                 (_evaluate_expansion_table temp_str (_command_table 0) (_function_table 0) (_set_table 0))
  79.                             ;else
  80.                                 (self_insert)
  81.                             )
  82.                     )
  83.                 ;else
  84.                     (self_insert)
  85.                 )
  86.             )
  87.         ;else
  88.             (self_insert)
  89.         )
  90.     )
  91. )
  92. (macro _evaluate_expansion_table
  93.     (
  94.         (int                constant_position
  95.                             template_counter
  96.                             command_type
  97.                             command_table_elements
  98.                             function_table_elements
  99.                             set_table_elements
  100.         )
  101.         (string            command_string
  102.         )
  103.         (get_parm 0 command_string)
  104.         (get_parm 1 command_table_elements)
  105.         (get_parm 2 function_table_elements)
  106.         (get_parm 3 set_table_elements)
  107.         (= constant_position 0)
  108.         (= template_counter 0)
  109.         (switch (strlen command_string)
  110.             4
  111.                 (
  112.                     (if (index (+ (+ (substr (_beg_of_proc_scan) 2 3) "~")(+ (substr (_beg_of_func_scan) 2 3) "~"))(trim (upper command_string)))
  113.                         (if (== (upper command_string) (+ (substr (_beg_of_proc_scan) 2 3) " "))
  114.                             (if (< (atoi (substr command_string 1 1) 0) 97)
  115.                                 (_procedure_header (substr (_beg_of_proc_scan) 2 (- (index (_beg_of_proc_scan) "}") 2)) (_end_of_rout_syntax) "prochead.cfg")
  116.                             ;else
  117.                                 (_procedure_header (lower (substr (_beg_of_proc_scan) 2 (- (index (_beg_of_proc_scan) "}") 2))) (lower (_end_of_rout_syntax)) "prochead.cfg")
  118.                             )
  119.                         ;else
  120.                             (if (< (atoi (substr command_string 1 1) 0) 97)
  121.                                 (_procedure_header (substr (_beg_of_func_scan) 2 (- (index (_beg_of_func_scan) "}") 2)) (+ (_end_of_rout_syntax) "(.T.)") "funchead.cfg")
  122.                             ;else
  123.                                 (_procedure_header (lower (substr (_beg_of_func_scan) 2 (- (index (_beg_of_func_scan) "}") 2))) (lower (+ (_end_of_rout_syntax) "(.T.)")) "funchead.cfg")
  124.                             )
  125.                         )
  126.                     ;else
  127.                         (
  128.                             (while (&& (== constant_position 0) (<= (+= template_counter 1) command_table_elements))
  129.                                 (if (= constant_position (search_string (+ "~" (upper command_string)) (_command_table template_counter) NULL 0))
  130.                                     (= command_type 0)
  131.                                 )
  132.                             )
  133.                             (if (== constant_position 0)
  134.                                 (
  135.                                     (= template_counter 0)
  136.                                     (while (&& (== constant_position 0) (<= (+= template_counter 1) function_table_elements))
  137.                                         (if (= constant_position (search_string (+ "~" (upper command_string)) (_function_table template_counter) NULL 0))
  138.                                             (= command_type 1)
  139.                                         )
  140.                                     )
  141.                                 )
  142.                             )
  143.                         )
  144.                     )
  145.                 )
  146.             5
  147.                 (while (&& (== constant_position 0) (<= (+= template_counter 1) set_table_elements))
  148.                     (if (= constant_position (search_string (+ "~" (upper command_string)) (_set_table template_counter) NULL 0))
  149.                         (= command_type 2)
  150.                     )
  151.                 )
  152.             NULL
  153.                 (self_insert)
  154.         )
  155.         (if constant_position
  156.             (_parse_and_expand command_type template_counter constant_position)
  157.         ;else
  158.             (self_insert)
  159.         )
  160.     )
  161. )
  162. (macro _parse_and_expand
  163.     (
  164.         (int                command_type
  165.                             table_number
  166.                             command_position
  167.                             more_syntax
  168.         )
  169.         (string            command
  170.                             command_string
  171.         )
  172.         (get_parm 0 command_type)
  173.         (get_parm 1 table_number)
  174.         (get_parm 2 command_position)
  175.         (switch command_type
  176.             0
  177.                 (= command_string (_command_table table_number))
  178.             1
  179.                 (= command_string (_function_table table_number))
  180.             2
  181.                 (= command_string (_set_table table_number))
  182.         )
  183.         (= command (substr command_string (+ command_position 5)))
  184.         (if (== (substr command (- (index command "~") 1) 1) " ")
  185.             (= more_syntax 1)
  186.         )
  187.         (= command (trim (substr command 1 (- (index command "~") 1))))
  188.         (if (&& (! dbr_expr_expansion)(== command_type 1))
  189.             (if (! (index command "^UX"))
  190.                 (= command (+ (substr command 1 (index command "(")) (substr command (index command ")"))))
  191.             )
  192.         )
  193.         (switch command_type
  194.             0
  195.                 (_command_insert command more_syntax 3)
  196.             1
  197.                 (_function_insert command 3)
  198.             2
  199.                 (_command_insert (ltrim command) more_syntax 4)
  200.         )
  201.     )
  202. )
  203. (macro _command_insert
  204.     (
  205.         (int            relational_move
  206.                         additional_syntax
  207.                         current_indent_column
  208.                         adjust_indent
  209.         )
  210.         (string        insert_string
  211.         )
  212.         (get_parm 0 insert_string)
  213.         (get_parm 1 additional_syntax)
  214.         (get_parm 2 relational_move)
  215.         (move_rel 0 (* -1 relational_move))
  216.         (inq_position NULL current_indent_column)
  217.         (if (< (atoi (read 1) 0) 97)
  218.             (= insert_string (upper insert_string))
  219.         ;else
  220.             (= insert_string (lower insert_string))
  221.         )
  222.         (delete_to_eol)
  223.         (insert insert_string)
  224.         (if additional_syntax
  225.             (self_insert)
  226.         ;else
  227.             (
  228.                 (insert "\n")
  229.                 (= adjust_indent (_adjust_indent_level (upper insert_string) current_indent_column))
  230.                 (if adjust_indent
  231.                     (
  232.                         (save_position)
  233.                         (search_back "<*\\c[~ \\t\\n]")
  234.                         (= insert_string (trim (read)))
  235.                         (delete_to_eol)
  236.                         (move_rel 0 adjust_indent)
  237.                         (insert insert_string)
  238.                         (restore_position)
  239.                     )
  240.                 )
  241.             )
  242.         )
  243.     )
  244. )
  245. (macro _function_insert
  246.     (
  247.         (string        insert_string
  248.         )
  249.         (int            relational_move
  250.         )
  251.         (get_parm 0 insert_string)
  252.         (get_parm 1 relational_move)
  253.         (move_rel 0 (* -1 relational_move))
  254.         ; (= insert_string (+ (substr insert_string 1 (index insert_string "("))) (substr insert_string (+ (index insert_string "(") 1)))
  255.         (if (< (atoi (read 1) 0) 97)
  256.             (= insert_string (upper insert_string))
  257.         ;else
  258.             (= insert_string (lower insert_string))
  259.         )
  260.         (delete_to_eol)
  261.         (insert insert_string)
  262.         (move_rel 0 (* (- (strlen insert_string) (index insert_string "(")) -1))
  263.         (if (== dbr_dialect 10)
  264.             (
  265.                 (search_fwd "(")
  266.                 (move_rel 0 1)
  267.             )
  268.         )
  269.     )
  270. )
  271. (macro expa
  272.     (
  273.         (int                constant_position
  274.                             template_counter
  275.         )
  276.         (string            command_string
  277.                             trailing_text
  278.         )
  279.         (= trailing_text (trim (read)))
  280.         (delete_to_eol)
  281.         (move_rel 0 -3)
  282.         (= command_string (+ (read 3) " "))
  283.         (end_of_line)
  284.         (= constant_position 0)
  285.         (= template_counter 0)
  286.         (while (&& (== constant_position 0) (<= (+= template_counter 1) (_function_table 0)))
  287.             (= constant_position (search_string (+ "~" (upper command_string)) (_function_table template_counter) NULL 0))
  288.         )
  289.         (if constant_position
  290.             (_parse_and_expand 1 template_counter constant_position)
  291.         )
  292.         (save_position)
  293.         (end_of_line)
  294.         (insert trailing_text)
  295.         (restore_position)
  296.     )
  297. )
  298.