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

  1. ;dBRIEF Optimize - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro opti
  6.     (
  7.         (string        pass_1
  8.                         pass_2
  9.                         pass_3
  10.                         pass_4
  11.                         pass_5
  12.                         srce_file
  13.                         dest_file
  14.                         buff_name
  15.         )
  16.         (if (! (get_parm 0 pass_1 "Remove indentations? [yN]: " 1 "N"))
  17.             (return 0)
  18.         )
  19.         (if (! (get_parm 1 pass_2 "Remove comments? [yN]: " 1 "N"))
  20.             (return 0)
  21.         )
  22.         (if (! (get_parm 2 pass_3 "Remove blank lines? [yN]: " 1 "N"))
  23.             (return 0)
  24.         )
  25.         (if (! (get_parm 3 pass_4 "Remove trailing spaces? [yN]: " 1 "N"))
  26.             (return 0)
  27.         )
  28.         (if (!= (upper pass_1) "Y")
  29.             (if (! (get_parm 3 pass_5 "Convert spaces to tabs? [yN]: " 1 "N"))
  30.                 (return 0)
  31.             )
  32.         )
  33.         (message "Please wait...")
  34.         (if (inq_modified)
  35.             (write_buffer)
  36.         )
  37.         (inq_names buff_name NULL NULL)
  38.         (= srce_file buff_name)
  39.         (= buff_name (substr buff_name 1 (search_string "?." buff_name)))
  40.         (= dest_file (+ buff_name ".bak"))
  41.         (if (exist dest_file)
  42.             (del dest_file)
  43.         )
  44.         (edit_file dest_file)
  45.         (read_file srce_file)
  46.         (write_buffer)
  47.         (delete_buffer (inq_buffer))
  48.         (edit_file srce_file)
  49.         (top_of_buffer)
  50.         (if (== (upper pass_1) "Y")
  51.             (
  52.                 (message "Removing indentations, stand by...")
  53.                 (translate "<[ \\t]" "" 1 1)
  54.             )
  55.         )
  56.         ;**  Remove comments.
  57.         (if (== (upper pass_2) "Y")
  58.             (
  59.                 (message "Removing comments, stand by...")
  60.                 (translate "{{&&}|{<[ \\t]@\\*}|{<[ \\t]@NOTE}|{<[ \\t]@note}}*>" "" 1 1 0)
  61.             )
  62.         )
  63.         (if (== (upper pass_3) "Y")
  64.             (
  65.                 (message "Removing blank lines, stand by...")
  66.                 (translate "<[ \\t]@\\n" "" 1 1)
  67.             )
  68.         )
  69.         (if (== (upper pass_4) "Y")
  70.             (
  71.                 (message "Removing trailing spaces, stand by...")
  72.                 (translate "[ \\t]+>" "" 1 1)
  73.             )
  74.         )
  75.         (if (== (upper pass_5) "Y")
  76.             (
  77.                 (message "Replacing spaces with tabs, stand by...")
  78.                 (_tab_support "T")
  79.             )
  80.         )
  81.         (message "Saving optimized file %s, stand by..." buff_name)
  82.         (if (inq_modified)
  83.             (write_buffer)
  84.         )
  85.         (top_of_buffer)
  86.         (_display_popup_message "Optimization complete." "" 0)
  87.     )
  88. )
  89. (macro _tab_support
  90.     (
  91.         (int            curr_line
  92.                         last_line
  93.                         old_col
  94.                         new_col
  95.         )
  96.         (string        orig_line
  97.                         message_string
  98.                         tab_operation
  99.         )
  100.         (extern _block_search)
  101.         (if (get_parm 0 tab_operation "Convert spaces->Tabs or tabs->Spaces? [Ts]: " 1 "T")
  102.             (
  103.                 (save_position)
  104.                 (if (! (inq_marked))
  105.                     (top_of_buffer)
  106.                 ;else
  107.                     (
  108.                         (swap_anchor)
  109.                         (= _block_search 1)
  110.                     )
  111.                 )
  112.                 (if (== (upper tab_operation) "T")
  113.                     (
  114.                         (= orig_line (_replicate " " (distance_to_tab)))
  115.                         (= tab_operation (use_tab_char "y"))
  116.                         (while (&& (search_fwd orig_line 1)(! (inq_kbd_char)))
  117.                             (
  118.                                 (inq_position NULL old_col)
  119.                                 (self_insert (key_to_int "<Tab>"))
  120.                                 (inq_position curr_line new_col)
  121.                                 (delete_char (- new_col old_col))
  122.                                 (= orig_line (_replicate " " (distance_to_tab)))
  123.                                 (message "Inserting tabs - line: %d, any key to abort..." curr_line)
  124.                             )
  125.                         )
  126.                         (use_tab_char tab_operation)
  127.                     )
  128.                 ;else
  129.                     (
  130.                         (while (&& (search_fwd "\t" 1)(! (inq_kbd_char)))
  131.                             (
  132.                                 (delete_char)
  133.                                 (insert (_replicate " " (distance_to_tab)))
  134.                                 (inq_position curr_line NULL)
  135.                                 (message "Inserting spaces - line: %d, any key to abort..." curr_line)
  136.                             )
  137.                         )
  138.                     )
  139.                 )
  140.                 (raise_anchor)
  141.                 (restore_position)
  142.                 (_display_popup_message "Tab operation complete." "" 0)
  143.             )
  144.         )
  145.     )
  146. )
  147.