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

  1. ;dBRIEF Indenter - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro _prg_indent
  6.     (
  7.         (if (inq_mode)
  8.             (
  9.                 (int            dbr_curr_col
  10.                                 dbr_insert_col
  11.                                 c_col
  12.                                 p_col
  13.                 )
  14.                 (string        orig_line
  15.                                 token
  16.                 )
  17.                 (inq_position dbr_curr_line dbr_curr_col)
  18.                 (insert "~|")
  19.                 (beginning_of_line)
  20.                 (= orig_line (trim (ltrim (read))))
  21.                 (= temp_int (index orig_line "~|"))
  22.                 (= orig_line (+ (+ (substr orig_line 1 (- temp_int 1)) "\n") (substr orig_line (+ temp_int 2))))
  23.                 (= token (substr (upper orig_line) 1 4))
  24.                 (if (= temp_int (search_string "[ \\t]" token NULL 1))
  25.                     (= token (substr token 1 (-- temp_int)))
  26.                 )
  27.                 (if (< (strlen orig_line) 1)
  28.                     (= dbr_insert_col dbr_curr_col)
  29.                 ;else
  30.                     (
  31.                         (if (search_back "<*\\c[~ \\t\\n]")
  32.                             (
  33.                                 (inq_position NULL c_col)
  34.                                 (move_rel -1 0)
  35.                                 (end_of_line)
  36.                                 (search_back "<*\\c[~ \\t\\n]")
  37.                                 (inq_position NULL p_col)
  38.                                 (= temp_str (upper (trim (read))))
  39.                                 (if (&& (index (_backdenting_conditionals) token)(>= p_col c_col))
  40.                                     (if (&& (== p_col c_col)(index temp_str (_do_case_syntax 1)))
  41.                                         (= dbr_insert_col (+ c_col dbr_indent_level))
  42.                                     ;else
  43.                                         (= dbr_insert_col p_col)
  44.                                     )
  45.                                 ;else
  46.                                     (if (&& (== token (_do_case_syntax 2)) (< p_col c_col))
  47.                                         (if (== (+ p_col (* dbr_indent_case dbr_indent_level)) c_col)
  48.                                             (= dbr_insert_col c_col)
  49.                                         ;else
  50.                                             (= dbr_insert_col (+ c_col dbr_indent_level))
  51.                                         )
  52.                                     ;else
  53.                                         (if (&& (&& (== dbr_indent_case 1)(== p_col c_col))(index (upper token) "CASE"))
  54.                                             (= dbr_insert_col (+ c_col dbr_indent_level))
  55.                                         ;else
  56.                                             (= dbr_insert_col c_col)
  57.                                         )
  58.                                     )
  59.                                 )
  60.                             )
  61.                         ;else
  62.                             (= dbr_insert_col 1)
  63.                         )
  64.                     )
  65.                 )
  66.                 (= curr_indent_col dbr_insert_col)
  67.                 (if (== (strlen (trim token)) 3)
  68.                     (= token (+ (trim token) " "))
  69.                 ;else
  70.                     (+= token " ")
  71.                 )
  72.                 (if (&& (strlen token) (index (_dialect_table) token))
  73.                     (= dbr_insert_col (_indent_shift (trim token) orig_line dbr_insert_col))
  74.                 )
  75.                 (move_abs dbr_curr_line dbr_curr_col)
  76.                 (beginning_of_line)
  77.                 (delete_to_eol)
  78.                 (move_abs 0 dbr_insert_col)
  79.                 (insert orig_line)
  80.                 (beginning_of_line)
  81.                 (= temp_str (read))
  82.                 (delete_to_eol)
  83.                 (move_abs 0 curr_indent_col)
  84.                 (insert (substr temp_str 1 (- (strlen temp_str) 1)))
  85.                 (move_abs 0 curr_indent_col)
  86.             )
  87.         ;else
  88.             (
  89.                 (down)
  90.                 (beginning_of_line)
  91.                 (search_fwd "<*\\c[~ \\t\\n]")
  92.             )
  93.         )
  94.     )
  95. )
  96. (macro rein
  97.     (
  98.         (int            dbr_insert_col
  99.                         last_line
  100.                         n1r
  101.                         n1c
  102.                         n2r
  103.                         n2c
  104.                         col
  105.                         line_continue_flag
  106.                         refresh_flag
  107.         )
  108.         (string        orig_line
  109.                         token
  110.                         comment_string
  111.                         cmd_temp_str
  112.         )
  113.         (= refresh_flag 1)
  114.         (= dbr_return_flag 0)
  115.         (= line_continue_flag 0)
  116.         (get_parm 0 refresh_flag)
  117.         (message "Indenting, press any key to abort...")
  118.         (if (inq_marked dbr_curr_line curr_indent_col last_line NULL)
  119.             (
  120.                 (raise_anchor)
  121.                 (move_abs dbr_curr_line curr_indent_col)
  122.                 (save_position)
  123.                 (move_abs dbr_curr_line 1)
  124.             )
  125.         ;else
  126.             (
  127.                 (save_position)
  128.                 (end_of_buffer)
  129.                 (inq_position last_line)
  130.                 (top_of_buffer)
  131.                 (inq_position dbr_curr_line)
  132.                 (= dbr_insert_col 1)
  133.                 (= curr_indent_col 1)
  134.             )
  135.         )
  136.         (while (&& (<= dbr_curr_line last_line)(! (inq_kbd_char)))
  137.             (
  138.                 (= dbr_text_flag 0)
  139.                 (= orig_line (trim (ltrim (read))))
  140.                 (= token (substr (upper orig_line) 1 4))
  141.                 (if (= dbr_insert_col (search_string "[ \\t]" token NULL 1))
  142.                     (= token (substr token 1 (-- dbr_insert_col)))
  143.                 )
  144.                 (= dbr_insert_col curr_indent_col)
  145.                 (if (&& (strlen token) (index (_dialect_table) (+ token " ")))
  146.                     (
  147.                         (= dbr_insert_col (_indent_shift token orig_line dbr_insert_col))
  148.                         (if dbr_text_flag
  149.                             (= orig_line (trim (ltrim (read))))
  150.                         )
  151.                     )
  152.                 )
  153.                 (if dbr_indent_continuation_lines
  154.                     (if (== (_last_character orig_line) (_continuation_character))
  155.                         (if (== line_continue_flag 0)
  156.                             (
  157.                                 (= line_continue_flag 1)
  158.                                 (+= curr_indent_col (* dbr_indent_level dbr_ext_ind_level))
  159.                             )
  160.                         )
  161.                     )
  162.                 )
  163.                 (if dbr_indent_margin_comments
  164.                     (if (|| (== (substr orig_line  1 4) "*<<<")(== (substr orig_line  1 4) "*+++"))
  165.                         (if (index orig_line "\*+++")
  166.                             (
  167.                                 (= dbr_insert_col 1)
  168.                                 (= curr_indent_col (+ dbr_indent_level 1))
  169.                             )
  170.                         ;else
  171.                             (if (index orig_line ">>>\*")
  172.                                 (= dbr_insert_col (- 40 (/ (strlen orig_line) 2)))
  173.                             ;else
  174.                                 (= dbr_insert_col 1)
  175.                             )
  176.                         )
  177.                     )
  178.                 )
  179.                 (delete_to_eol)
  180.                 (if (&& (== dbr_dialect 9)(== (substr orig_line 1 1) "|"))
  181.                     (
  182.                         (save_position)
  183.                         (search_back "<*\\c\\|" 1 0)
  184.                         (inq_position NULL dbr_insert_col)
  185.                         (restore_position)
  186.                     )
  187.                 )
  188.                 (move_abs 0 dbr_insert_col)
  189.                 (insert orig_line)
  190.                 (if dbr_indent_continuation_lines
  191.                     (if (&& (!= (_last_character orig_line) (_continuation_character))(== line_continue_flag 1))
  192.                         (
  193.                             (= line_continue_flag 0)
  194.                             (-= curr_indent_col (* dbr_indent_level dbr_ext_ind_level))
  195.                         )
  196.                     )
  197.                 )
  198.                 (if dbr_indent_same_line_comments
  199.                     (if (&& (!= (index (ltrim orig_line) (_comment_character 1)) 1) (&& (search_string (_comment_character 1) orig_line) (!= dbr_comment_tab 0)))
  200.                         (
  201.                             (beginning_of_line)
  202.                             (= cmd_temp_str (read))
  203.                             (beginning_of_line)
  204.                             (delete_to_eol)
  205.                             (insert (trim (substr cmd_temp_str 1 (- (index cmd_temp_str (_comment_character 1)) 1))))
  206.                             (end_of_line)
  207.                             (inq_position NULL col)
  208.                             (if (< col (- dbr_comment_tab 1))
  209.                                 (move_abs 0 dbr_comment_tab)
  210.                             ;else
  211.                                 (
  212.                                     (end_of_line)
  213.                                     (move_rel 0 2)
  214.                                 )
  215.                             )
  216.                             (insert (trim (substr cmd_temp_str (index cmd_temp_str (_comment_character 1)))))
  217.                         )
  218.                     )
  219.                 )
  220.                 (move_abs (++ dbr_curr_line) 1)
  221.                 (if refresh_flag
  222.                     (refresh)
  223.                 )
  224.             )
  225.         )
  226.         (keyboard_flush)
  227.         (restore_position)
  228.         (if refresh_flag
  229.             (if (> dbr_curr_line last_line)
  230.                 (_display_popup_message "Indenting complete." "" 0)
  231.             ;else
  232.                 (_display_popup_message "Indenting aborted." "" 1)
  233.             )
  234.         ;else
  235.             (message "")
  236.         )
  237.     )
  238. )
  239. (macro _last_character
  240.     (
  241.         (string            temp_string
  242.         )
  243.         (get_parm 0 temp_string)
  244.         (if (index temp_string (_comment_character 1))
  245.             (= temp_string (trim (substr temp_string 1 (- (index temp_string (_comment_character 1)) 1))))
  246.         ;else
  247.             (= temp_string (trim temp_string))
  248.         )
  249.         (return (substr temp_string (strlen temp_string) 1))
  250.     )
  251. )
  252.