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

  1. ;dBRIEF Comment - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro comm
  6.     (
  7.         (string            comment_character
  8.         )
  9.         (if (get_parm 0 temp_str "Comment Conditionals, Prog, Block [Cpb]:" 1 "C")
  10.             (switch (upper (substr temp_str 1 1))
  11.                 "C"
  12.                     (_comment_conditionals)
  13.                 "P"
  14.                     (_comment_program)
  15.                 "B"
  16.                     (
  17.                         (if (get_parm 1 comment_character)
  18.                             (_comment_block comment_character)
  19.                         ;else
  20.                             (_comment_block)
  21.                         )
  22.                     )
  23.             )
  24.         )
  25.     )
  26. )
  27. (macro unco
  28.     (
  29.         (string            comment_character
  30.         )
  31.         (if (get_parm 0 temp_str "Uncomment Conditionals, Prog, or Block [Cpb]:" 1 "C")
  32.             (
  33.                 (switch (upper (substr temp_str 1 1))
  34.                     "C"
  35.                         (_uncomment_conditionals 1)
  36.                     "P"
  37.                         (_remove_same_line_comments)
  38.                     "B"
  39.                         (
  40.                             (if (get_parm 1 comment_character)
  41.                                 (_uncomment_block comment_character)
  42.                             ;else
  43.                                 (_uncomment_block)
  44.                             )
  45.                         )
  46.                 )
  47.             )
  48.         )
  49.     )
  50. )
  51. (macro _comment_block
  52.     (
  53.         (int                first_line
  54.                             first_column
  55.                             last_line
  56.         )
  57.         (string            comment_type
  58.                             comment_prompt
  59.         )
  60.         (if (inq_marked first_line first_column last_line NULL)
  61.             (
  62.                 (sprintf comment_prompt "%s or %s [%s%s]: " (_comment_character 2) (_comment_character 3) (lower (substr (_comment_character 2) 1 1)) (_comment_character 3))
  63.                 (if (get_parm 0 comment_type comment_prompt 1 (_comment_character 3))
  64.                     (
  65.                         (= temp_int (- first_line 1))
  66.                         (raise_anchor)
  67.                         (while (<= (++ temp_int) last_line)
  68.                             (
  69.                                 (move_abs temp_int first_column)
  70.                                 (if (== (upper (substr comment_type 1 1)) (substr (_comment_character 2) 1 1))
  71.                                     (= comment_type (_comment_character 2))
  72.                                 ;else
  73.                                     (= comment_type (_comment_character 3))
  74.                                 )
  75.                                 (insert (+ comment_type (_replicate " " dbr_comment_spaces)))
  76.                             )
  77.                         )
  78.                     )
  79.                 )
  80.             )
  81.         ;else
  82.             (_display_popup_message "No marked block!" "" 1)
  83.         )
  84.     )
  85. )
  86. (macro _uncomment_block
  87.     (
  88.         (int                first_line
  89.                             first_col
  90.                             last_line
  91.         )
  92.         (string            comment_type
  93.                             comment_prompt
  94.                             comment_temp_string
  95.         )
  96.         (if (inq_marked first_line first_col last_line NULL)
  97.             (
  98.                 (sprintf comment_prompt "%s or %s [%s%s]: " (_comment_character 2) (_comment_character 3) (lower (substr (_comment_character 2) 1 1)) (_comment_character 3))
  99.                 (if (get_parm 0 comment_type comment_prompt 1 (_comment_character 3))
  100.                     (
  101.                         (= temp_int (- first_line 1))
  102.                         (raise_anchor)
  103.                         (if (== (upper (substr comment_type 1 1)) (substr (_comment_character 2) 1 1))
  104.                             (= comment_type (_comment_character 2))
  105.                         ;else
  106.                             (= comment_type (_comment_character 3))
  107.                         )
  108.                         (while (<= (++ temp_int) last_line)
  109.                             (
  110.                                 (move_abs temp_int 1)
  111.                                 (switch (upper (substr comment_type 1 1))
  112.                                     (upper (substr (_comment_character 2) 1 1))
  113.                                         (if (index (read) (_comment_character 2))
  114.                                             (
  115.                                                 (move_abs 0 first_col)
  116.                                                 (delete_char (+ (strlen (_comment_character 2)) dbr_comment_spaces))
  117.                                             )
  118.                                         )
  119.                                     NULL
  120.                                         (
  121.                                             (sprintf comment_temp_string "{<[ \t]@\\%s}" comment_type)
  122.                                             (if (search_string comment_temp_string (read))
  123.                                                 (
  124.                                                     (move_abs 0 first_col)
  125.                                                     (delete_char (+ (strlen (_comment_character 3)) dbr_comment_spaces))
  126.                                                 )
  127.                                             )
  128.                                         )
  129.                                 )
  130.                             )
  131.                         )
  132.                     )
  133.                 )
  134.             )
  135.         ;else
  136.             (_display_popup_message "No marked block!" "" 1)
  137.         )
  138.     )
  139. )
  140. (macro _same_line_comment
  141.     (
  142.         (save_position)
  143.         (beginning_of_line)
  144.         (= temp_str (read))
  145.         (if (|| (== temp_str " ")(== temp_str "\n"))
  146.             (
  147.                 (restore_position)
  148.                 (delete_to_eol)
  149.                 (insert (+ (_comment_character 2) " "))
  150.             )
  151.         ;else
  152.             (
  153.                 (restore_position 0)
  154.                 (if (|| (== dbr_comment_tab 0)(> (strlen temp_str) dbr_comment_tab))
  155.                     (
  156.                         (end_of_line)
  157.                         (right)
  158.                         (right)
  159.                     )
  160.                 ;else
  161.                     (move_abs 0 dbr_comment_tab)
  162.                 )
  163.                 (delete_to_eol)
  164.                 (insert (+ (_comment_character 1) " "))
  165.             )
  166.         )
  167.     )
  168. )
  169. (macro _comment_program
  170.     (
  171.         (int            comm_last_line
  172.                         comm_current_line
  173.                         comm_current_buffer
  174.                         comm_text_buffer
  175.         )
  176.         (string        comm_srce_line
  177.                         comm_token
  178.                         comm_token_line
  179.                         comm_temp_string
  180.                         comm_pattern
  181.         )
  182.         (save_position)
  183.         (= comm_current_buffer (inq_buffer))
  184.         (if (inq_marked comm_current_line NULL comm_last_line NULL)
  185.             (raise_anchor)
  186.         ;else
  187.             (
  188.                 (end_of_buffer)
  189.                 (inq_position comm_last_line)
  190.                 (top_of_buffer)
  191.                 (inq_position comm_current_line)
  192.             )
  193.         )
  194.         (-= comm_current_line 2)
  195.         (while (&& (<= (++ comm_current_line) comm_last_line)(! (inq_kbd_char)))
  196.             (
  197.                 (move_abs comm_current_line 1)
  198.                 (= comm_srce_line (read))
  199.                 (if (! (index comm_srce_line (_comment_character 1)))
  200.                     (
  201.                         (= comm_token_line (upper (ltrim (trim comm_srce_line))))
  202.                         (if (&& (!= (substr comm_token_line 1 1)(_comment_character 3))(strlen comm_token_line))
  203.                             (
  204.                                 (if dbr_two_word_comments
  205.                                     (
  206.                                         (if (index comm_token_line " ")
  207.                                             (
  208.                                                 (= comm_token (substr comm_token_line 1 1))
  209.                                                 (+= comm_token (substr comm_token_line (+ (index comm_token_line " ") 1) 3))
  210.                                             )
  211.                                         ;else
  212.                                             (= comm_token (substr comm_token_line 1 4))
  213.                                         )
  214.                                     )
  215.                                 ;else
  216.                                     (
  217.                                         (= comm_token (substr comm_token_line 1 4))
  218.                                         (if (index comm_token " ")
  219.                                             (
  220.                                                 (= comm_token (substr comm_token_line 1 1))
  221.                                                 (+= comm_token (substr comm_token_line (+ (index comm_token_line " ") 1) 3))
  222.                                             )
  223.                                         )
  224.                                     )
  225.                                 )
  226.                                 (message "Reviewing line %d, any key to abort..." comm_current_line)
  227.                                 (if comm_text_buffer
  228.                                     (set_buffer comm_text_buffer)
  229.                                 ;else
  230.                                     (= comm_text_buffer (create_buffer "Comments" (search_path  (inq_environment "BPATH") "comments.cfg") 1))
  231.                                 )
  232.                                 (top_of_buffer)
  233.                                 (sprintf comm_pattern "<{%02d %s}|{00 %s}" dbr_dialect comm_token comm_token)
  234.                                 (if (search_fwd comm_pattern 1 0)
  235.                                     (
  236.                                         (move_abs 0 4)
  237.                                         (= comm_temp_string (read))
  238.                                         (= comm_temp_string (+ (+ (_comment_character 1) " ") (ltrim (trim (substr comm_temp_string 5)))))
  239.                                     )
  240.                                 ;else
  241.                                     (= comm_temp_string "")
  242.                                 )
  243.                                 (set_buffer comm_current_buffer)
  244.                                 (if (strlen (trim comm_temp_string))
  245.                                     (
  246.                                         (if (< (strlen (trim comm_srce_line)) dbr_comment_tab)
  247.                                             (
  248.                                                 (move_abs 0 dbr_comment_tab)
  249.                                                 (delete_to_eol)
  250.                                             )
  251.                                         ;else
  252.                                             (
  253.                                                 (end_of_line)
  254.                                                 (move_rel 0 2)
  255.                                             )
  256.                                         )
  257.                                         (if (> (atoi (ltrim comm_srce_line) 0) 95)
  258.                                             (insert (lower comm_temp_string))
  259.                                         ;else
  260.                                             (insert (upper comm_temp_string))
  261.                                         )
  262.                                     )
  263.                                 )
  264.                             )
  265.                         )
  266.                         (beginning_of_line)
  267.                         (refresh)
  268.                     )
  269.                 )
  270.             )
  271.         )
  272.         (if comm_text_buffer
  273.             (delete_buffer comm_text_buffer)
  274.         )
  275.         (keyboard_flush)
  276.         (restore_position)
  277.         (if (< comm_current_line comm_last_line)
  278.             (_display_popup_message "Automatic commenting aborted!" "" 1)
  279.         ;else
  280.             (_display_popup_message "Automatic commenting complete." "" 0)
  281.         )
  282.     )
  283. )
  284. (macro _remove_same_line_comments
  285.     (
  286.         (save_position)
  287.         (top_of_buffer)
  288.         (translate (+ (_comment_character 1) "*>") "" 1 1 0)
  289.         (restore_position)
  290.         (_display_popup_message "Program uncommenting complete." "" 0)
  291.     )
  292. )
  293.