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

  1. ;dBRIEF Scanner - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. #define  PrevScanMenu                "prevscan.txt"
  6. (macro tag
  7.     (
  8.         (save_position)
  9.         (beginning_of_line)
  10.         (= temp_str (read))
  11.         (if (index temp_str (+ (_comment_character 1) " dBRIEF Tag..."))
  12.             (
  13.                 (move_abs 0 1)
  14.                 (delete_to_eol)
  15.                 (insert (trim (substr temp_str 1 (- (index temp_str (+ (_comment_character 1) " dBRIEF Tag...")) 1))))
  16.                 (message "Tag removed.")
  17.             )
  18.         ;else
  19.             (
  20.                 (if (> (strlen (trim temp_str)) dbr_comment_tab)
  21.                     (end_of_line)
  22.                 ;else
  23.                     (move_abs 0 dbr_comment_tab)
  24.                 )
  25.                 (insert (+ (_comment_character 1) " dBRIEF Tag..."))
  26.                 (message "Tag placed.")
  27.             )
  28.         )
  29.         (restore_position)
  30.     )
  31. )
  32. (macro unta
  33.     (
  34.         (save_position)
  35.         (top_of_buffer)
  36.         (= temp_int 0)
  37.         (while (search_fwd (+ (_comment_character 1) " dBRIEF Tag...") 0)
  38.             (
  39.                 (delete_to_eol)
  40.                 (message "Tags removed: %d" (++ temp_int))
  41.             )
  42.         )
  43.         (restore_position)
  44.     )
  45. )
  46. (macro scan
  47.     (
  48.         (extern            _reg_exp
  49.         )
  50.         (int                scan_global_flag
  51.                             _temp_reg_exp
  52.                             _temp_case
  53.                             _invalid_buffer
  54.         )
  55.         (string            scan_search_str
  56.                             tmp_path
  57.         )
  58.         (= _temp_reg_exp _reg_exp)
  59.         (= _temp_case (search_case 1))
  60.         (if _reg_exp
  61.             (= temp_str "Text to scan for [expr=on]: ")
  62.         ;else
  63.             (= temp_str "Text to scan for [expr=off]: ")
  64.         )
  65.         (if (get_parm 0 scan_search_str temp_str)
  66.             (
  67.                 (if (== (upper (substr scan_search_str 1 4)) "GLOB")
  68.                     (
  69.                         (get_parm 1 scan_search_str)
  70.                         (= scan_global_flag 1)
  71.                     )
  72.                 ;else
  73.                     (= scan_global_flag 0)
  74.                 )
  75.                 (if (&& (== _reg_exp 0)(index "UDFS~UDCS~UDPS~ROUT~PROC~FUNC~COMM~APX" (upper (substr scan_search_str 1 4))))
  76.                     (= _reg_exp 1)
  77.                 )
  78.                 (= tmp_path (inq_environment "BTMP"))
  79.                 (if (! (strlen tmp_path))
  80.                     (= tmp_path (inq_environment "TMP"))
  81.                 )
  82.                 (if (! (strlen tmp_path))
  83.                     (= tmp_path PrevScanMenu)
  84.                 ;else
  85.                     (if (! (rindex "\\/" (substr tmp_path (strlen tmp_path) 1)))
  86.                         (+= tmp_path (+ "\\" PrevScanMenu))
  87.                     ;else
  88.                         (+= tmp_path PrevScanMenu)
  89.                     )
  90.                 )
  91.                 (= _invalid_buffer (create_buffer "Scanner" tmp_path 1))
  92.                 (if (! _invalid_buffer)
  93.                     (= tmp_path PrevScanMenu)
  94.                 ;else
  95.                     (delete_buffer _invalid_buffer)
  96.                 )
  97.                 (if (&& (exist tmp_path)(!= (upper (substr scan_search_str 1 4)) "PREV"))
  98.                     (del tmp_path)
  99.                 )
  100.                 (switch (upper (substr scan_search_str 1 4))
  101.                     "SIZE"
  102.                         (_scan_source "SIZE" "<~.~.~." scan_global_flag tmp_path)
  103.                     "UDCS"
  104.                         (_scan_source "UDCs" "#command" scan_global_flag tmp_path)
  105.                     "ROUT"
  106.                         (_scan_source "ROUTINES" (+ "<" (_beg_of_rout_scan)) scan_global_flag tmp_path)
  107.                     "UDPS"    NULL
  108.                     "PROC"
  109.                         (_scan_source "PROCEDURES" (+ "<" (_beg_of_proc_scan)) scan_global_flag tmp_path)
  110.                     "UDFS"    NULL
  111.                     "FUNC"
  112.                         (_scan_source "FUNCTIONS" (+ "<" (_beg_of_func_scan)) scan_global_flag tmp_path)
  113.                     "COMM"
  114.                         (_scan_source "COMMENTS" (_comment_character 1) scan_global_flag tmp_path)
  115.                     "NOTE"
  116.                         (_scan_source "NOTES" (+ "< @\t@" (_comment_character 2)) scan_global_flag tmp_path)
  117.                     "TAGS"
  118.                         (_scan_source "TAGS" (+ (_comment_character 1)" dBRIEF Tag...") scan_global_flag tmp_path)
  119.                     "APX"
  120.                         (if dbr_apx_file_id
  121.                             (
  122.                                 (get_parm 1 scan_search_str "Text to scan APX for: ")
  123.                                 (switch (upper (substr scan_search_str 1 4))
  124.                                     "ROUT"
  125.                                         (_scan_apx_programs_r)
  126.                                     "PROC"
  127.                                         (_scan_apx_programs_p)
  128.                                     "FUNC"
  129.                                         (_scan_apx_programs_f)
  130.                                     NULL
  131.                                         (
  132.                                             (if (!= dbr_apx_file_id 0)
  133.                                                 (_apx_scan_menu scan_search_str (upper scan_search_str))
  134.                                             ;else
  135.                                                 (_display_popup_message "APX file not loaded!" "" 1)
  136.                                             )
  137.                                         )
  138.                                 )
  139.                             )
  140.                         ;else
  141.                             (_display_popup_message "APX file not open!" "" 1)
  142.                         )
  143.                     "PREV"
  144.                         (if (&& (== dbr_previous_scan 1)(exist tmp_path))
  145.                             (_scan_source "" "" scan_global_flag tmp_path)
  146.                         ;else
  147.                             (if (== dbr_previous_scan 1)
  148.                                 (_display_popup_message "No previous scan available!" "" 1)
  149.                             ;else
  150.                                 (_display_popup_message "SCAN PREVIOUS command not enabled!" "" 1)
  151.                             )
  152.                         )
  153.                     NULL
  154.                         (if (strlen scan_search_str)
  155.                             (
  156.                                 (search_case _temp_case)
  157.                                 (_scan_source (upper scan_search_str) scan_search_str scan_global_flag tmp_path)
  158.                             )
  159.                         ;else
  160.                             (_display_popup_message "No text to scan!" "" 1)
  161.                         )
  162.                 )
  163.                 (= _reg_exp _temp_reg_exp)
  164.                 (search_case _temp_case)
  165.             )
  166.         )
  167.     )
  168. )
  169. (macro _scan_source
  170.     (
  171.         (extern _pick_menu
  172.         )
  173.         (int        program_line
  174.                     menu_buffer
  175.                     glb_buffer_search
  176.                     glb_start_buffer
  177.                     glb_scan_line
  178.                     glb_scan_col
  179.                     glb_search_flag
  180.                     glb_line_count
  181.                     glb_byte_count
  182.                     tmp_line_count
  183.                     tmp_byte_count
  184.                     bb_line
  185.                     eb_line
  186.         )
  187.         (string  _search_lbl
  188.                     _search_str
  189.                     menu_line
  190.                     routine_name
  191.                     glb_buffer_name
  192.                     glb_file_name
  193.                     tmp_path
  194.         )
  195.         (get_parm 0 _search_lbl)
  196.         (get_parm 1 _search_str)
  197.         (get_parm 2 glb_search_flag)
  198.         (get_parm 3 tmp_path)
  199.         (= temp_int 0)
  200.         (if (inq_marked)
  201.             (inq_marked bb_line NULL eb_line NULL)
  202.         )
  203.         (= dbr_current_buffer (inq_buffer))
  204.         (= glb_start_buffer (inq_buffer))
  205.         (if (exist tmp_path)
  206.             (= glb_buffer_search 0)
  207.         ;else
  208.             (= glb_buffer_search 1)
  209.         )
  210.         (= menu_buffer (create_buffer "Scanner" tmp_path 1))
  211.         (while glb_buffer_search
  212.             (
  213.                 (inq_names glb_buffer_name NULL glb_file_name)
  214.                 (inq_position glb_scan_line glb_scan_col)
  215.                 (top_of_buffer)
  216.                 (if (== glb_search_flag 1)
  217.                     (if (== _search_lbl "SIZE")
  218.                         (
  219.                             (= tmp_byte_count (_number_bytes))
  220.                             (= tmp_line_count (_number_lines))
  221.                             (+= glb_byte_count tmp_byte_count)
  222.                             (+= glb_line_count tmp_line_count)
  223.                             (sprintf menu_line "─── %s %s# Lines: %07d  # Bytes: %07d        |GLOBAL||%s\n" (upper glb_file_name) (_replicate " " (- 15 (strlen glb_file_name))) tmp_line_count tmp_byte_count glb_buffer_name)
  224.                         )
  225.                     ;else
  226.                           (sprintf menu_line "────── %s ──────%s|GLOBAL||%s\n" (upper glb_file_name) (_replicate " " 45) glb_buffer_name)
  227.                         ;(sprintf menu_line "────── %s ──────%s|GLOBAL||%s\n" (upper glb_file_name) (_replicate " " (- (inq_line_length) 90)) glb_buffer_name)
  228.                     )
  229.                 )
  230.                 (set_buffer menu_buffer)
  231.                 (insert menu_line)
  232.                 (set_buffer dbr_current_buffer)
  233.                 (message "Scanning %s for %s..." (upper glb_file_name) _search_lbl)
  234.                 (while (&& (search_fwd _search_str _reg_exp)(! (inq_kbd_char)))
  235.                     (
  236.                         (beginning_of_line)
  237.                         (= routine_name (ltrim (read)))
  238.                         (if (== _search_lbl "COMMENTS")
  239.                             (if (index routine_name (_comment_character 1))
  240.                                 (= routine_name (substr routine_name (index routine_name (_comment_character 1))))
  241.                             )
  242.                         )
  243.                         (if (strlen routine_name)
  244.                             (
  245.                                 (++ temp_int)
  246.                                 (message "Scanning %s for %s [#%d]..." (upper glb_file_name) _search_lbl temp_int)
  247.                                 (inq_position program_line)
  248.                                 (if (&& (>= program_line bb_line)(<= program_line eb_line))
  249.                                     ;(sprintf menu_line "%05d< %s ||%s\n" program_line (substr (_pad_right routine_name (- (inq_line_length) 68)) 1 (- (inq_line_length) 68)) glb_buffer_name)
  250.                                     (sprintf menu_line "%05d< %s ||%s\n" program_line (substr (_pad_right routine_name 53) 1 53) glb_buffer_name)
  251.                                 ;else
  252.                                     (sprintf menu_line "%05d: %s ||%s\n" program_line (substr (_pad_right routine_name 53) 1 53) glb_buffer_name)
  253.                                     ;(sprintf menu_line "%05d: %s ||%s\n" program_line (substr (_pad_right routine_name (- (inq_line_length) 68)) 1 (- (inq_line_length) 68)) glb_buffer_name)
  254.                                 )
  255.                                 (set_buffer menu_buffer)
  256.                                 (insert menu_line)
  257.                                 (set_buffer dbr_current_buffer)
  258.                             )
  259.                         )
  260.                         (move_rel 1 0)
  261.                         (move_abs 0 1)
  262.                     )
  263.                 )
  264.                 (move_abs glb_scan_line glb_scan_col)
  265.                 (if glb_search_flag
  266.                     (
  267.                         (set_buffer (next_buffer))
  268.                         (if (== glb_start_buffer (inq_buffer))
  269.                             (= glb_buffer_search 0)
  270.                         )
  271.                         (= dbr_current_buffer (inq_buffer))
  272.                     )
  273.                 ;else
  274.                     (= glb_buffer_search 0)
  275.                 )
  276.             )
  277.         )
  278.         (keyboard_flush)
  279.         (= temp_int 0)
  280.         (set_buffer menu_buffer)
  281.         (if (&& (== dbr_previous_scan 1)(inq_modified))
  282.             (write_buffer)
  283.         )
  284.         (end_of_buffer)
  285.         (delete_line)
  286.         (inq_position program_line)
  287.         (top_of_buffer)
  288.         (set_buffer glb_start_buffer)
  289.         (if (> program_line 1)
  290.             (
  291.                 (if glb_search_flag
  292.                     (if (== _search_lbl "SIZE")
  293.                         (
  294.                             (sprintf _search_lbl "Lines = %d  Bytes = %d" glb_line_count glb_byte_count)
  295.                             (_pick_menu "" "" 15 (_menu_lines program_line) 76 3 "_scan_jump" menu_buffer (+  _search_lbl " <Grey[-] to Print>"))
  296.                         )
  297.                     ;else
  298.                         (_pick_menu "" "" 15 (_menu_lines program_line) 76 3 "_scan_jump" menu_buffer (+ (+ "Global Scan: " (trim (substr _search_lbl 1 32))) " <Grey[-] to Print>"))
  299.                     )
  300.                 ;else
  301.                     (
  302.                         (_pick_menu "" "" 15 (_menu_lines program_line) 76 3 "_scan_jump" menu_buffer (+ "Local Scan: " (trim (substr _search_lbl 1 32))))
  303.                     )
  304.                 )
  305.                 (if (!= temp_str "NULL")
  306.                     (
  307.                         (if (inq_marked)
  308.                             (raise_anchor)
  309.                         )
  310.                         (if (strlen (trim temp_str))
  311.                             (edit_file temp_str)
  312.                         )
  313.                         (if temp_int
  314.                             (goto_line temp_int)
  315.                         )
  316.                     )
  317.                 )
  318.             )
  319.         ;else
  320.             (
  321.                 (_display_popup_message "Scan for %s unsuccessful." _search_lbl 1)
  322.                 (delete_buffer menu_buffer)
  323.             )
  324.         )
  325.     )
  326. )
  327. (macro _scan_jump
  328.     (
  329.         (int                scan_event_type
  330.         )
  331.         (string            scan_event_string
  332.                             print_output
  333.                             destination_file
  334.         )
  335.         (get_parm 0 scan_event_type)
  336.         (get_parm 1 scan_event_string)
  337.         (switch scan_event_type
  338.             45
  339.                 (
  340.                     (get_parm 2 print_output "Print to Printer or File [Pf]: " 1 "P")
  341.                     (if (== (upper print_output) "F")
  342.                         (if (! (get_parm 3 destination_file "Output file name: "))
  343.                             (return 0)
  344.                         )
  345.                     )
  346.                     (top_of_buffer)
  347.                     (if (search_fwd "|GLOBAL||" 0)
  348.                         (
  349.                             (translate "[ \t]@\\|GLOBAL*>" "" 1 -1 0)
  350.                             (translate "[ \t]@\\|\\|*>" "" 1 -1 0)
  351.                             (top_of_buffer)
  352.                             (insert "Global Scan Print\n")
  353.                             (insert (+ (_replicate "-" 50) "\n"))
  354.                             (insert "Line#  Source Line\n")
  355.                             (insert (+ "----- " (+ (_replicate "-" 44) "\n")))
  356.                             (end_of_buffer)
  357.                             (insert "\n \n")
  358.                             (top_of_buffer)
  359.                             (drop_anchor)
  360.                             (end_of_buffer)
  361.                             (if (== (upper print_output) "P")
  362.                                 (print)
  363.                             ;else
  364.                                 (if (&& (strlen destination_file)(== (upper print_output) "F"))
  365.                                     (
  366.                                         (copy)
  367.                                         (if (exist destination_file)
  368.                                             (del destination_file)
  369.                                         )
  370.                                         (edit_file destination_file)
  371.                                         (paste)
  372.                                         (write_buffer)
  373.                                         (delete_buffer (inq_buffer))
  374.                                     )
  375.                                 )
  376.                             )
  377.                         )
  378.                     ;else
  379.                         (_display_popup_message "Print scan is only available with SCAN GLOBAL and SCAN APX options!" "" 1)
  380.                     )
  381.                     (= temp_int 0)
  382.                     (= temp_str "NULL")
  383.                     (exit)
  384.                 )
  385.             27
  386.                 (
  387.                     (= temp_int 0)
  388.                     (= temp_str "NULL")
  389.                     (exit)
  390.                 )
  391.             13
  392.                 (
  393.                     (if (index scan_event_string "|GLOBAL||")
  394.                         (
  395.                             (= temp_int 0)
  396.                             (= temp_str (trim (substr scan_event_string (+ (index scan_event_string "||") 2))))
  397.                         )
  398.                     ;else
  399.                         (
  400.                             (= temp_int (atoi (substr scan_event_string 1 5)))
  401.                             (= temp_str (trim (substr scan_event_string (+ (index scan_event_string "||") 2))))
  402.                         )
  403.                     )
  404.                     (exit)
  405.                 )
  406.             03        NULL
  407.             02        NULL
  408.             00        NULL
  409.             01
  410.                 (if (index scan_event_string "|GLOBAL||")
  411.                     (message "Jump to %s" (trim (upper (substr scan_event_string (+ (index scan_event_string "||") 2)))))
  412.                 ;else
  413.                     (message "Jump to line %s in %s" (substr scan_event_string 1 5) (trim (upper (substr scan_event_string (+ (index scan_event_string "||") 2)))))
  414.                 )
  415.         )
  416.         (return 1)
  417.     )
  418. )
  419. (macro repl
  420.     (
  421.         (int                repl_global_flag
  422.                             repl_start_buffer
  423.                             repl_buffer_search
  424.                             repl_scan_line
  425.                             repl_scan_col
  426.                             repl_count
  427.                             repl_abort_flag
  428.                             apx_not_in_memory
  429.                             apx_program_buffer
  430.         )
  431.         (string            repl_search_str
  432.                             repl_replace_str
  433.                             repl_action
  434.                             repl_prompt
  435.                             repl_buffer_name
  436.                             apx_program_name
  437.         )
  438.         (if (! (get_parm 0 repl_action "Global or APX [Ga]: " 6 "Global"))
  439.             (return 0)
  440.         )
  441.         (if (! (get_parm 1 repl_search_str "Text to replace: "))
  442.             (return 0)
  443.         )
  444.         (if (! (get_parm 3 repl_replace_str "Text to replace with: "))
  445.             (return 0)
  446.         )
  447.         (if (! (get_parm 4 repl_prompt "Prompt each replacement? [yN]: " 1 "N"))
  448.             (return 0)
  449.         )
  450.         (if (get_parm 5 temp_str "Replace not undo-able, continue? [yN]: " 1 "N")
  451.             (if (!= (upper temp_str) "Y")
  452.                 (return 0)
  453.             )
  454.         )
  455.         (if (== (substr (upper repl_action) 1 1) "G")
  456.             (
  457.                 (= repl_buffer_search 1)
  458.                 (= repl_start_buffer (inq_buffer))
  459.                 (while repl_buffer_search
  460.                     (
  461.                         (inq_position repl_scan_line repl_scan_col)
  462.                         (top_of_buffer)
  463.                         (if (== (upper repl_prompt) "N")
  464.                             (if (! (inq_kbd_char))
  465.                                 (+= repl_count (translate repl_search_str repl_replace_str 1 0 NULL 0 1))
  466.                             ;else
  467.                                 (
  468.                                     (= repl_buffer_search 0)
  469.                                     (= repl_abort_flag 1)
  470.                                 )
  471.                             )
  472.                         ;else
  473.                             (+= repl_count (translate repl_search_str repl_replace_str NULL NULL NULL 0 1))
  474.                         )
  475.                         (move_abs repl_scan_line repl_scan_col)
  476.                         (set_buffer (next_buffer))
  477.                         (if (== repl_start_buffer (inq_buffer))
  478.                             (= repl_buffer_search 0)
  479.                         )
  480.                         (= dbr_current_buffer (inq_buffer))
  481.                         (attach_buffer dbr_current_buffer)
  482.                         (refresh)
  483.                         (inq_names NULL NULL repl_buffer_name)
  484.                         (message "%d replacements in %s." repl_count repl_buffer_name 0)
  485.                     )
  486.                 )
  487.                 (keyboard_flush)
  488.                 (set_buffer repl_start_buffer)
  489.                 (attach_buffer repl_start_buffer)
  490.                 (sprintf temp_str "%d" repl_count)
  491.                 (if repl_count
  492.                     (if repl_abort_flag
  493.                         (_display_popup_message "%s replacements before user abort!" temp_str 1)
  494.                     ;else
  495.                         (_display_popup_message "%s replacements." temp_str 0)
  496.                     )
  497.                 ;else
  498.                     (_display_popup_message "Pattern %s not found!" repl_search_str 1)
  499.                 )
  500.             )
  501.         ;else
  502.             (if (== (substr (upper repl_action) 1 1) "A")
  503.                 (if dbr_apx_file_id
  504.                     (
  505.                         (= repl_buffer_search 1)
  506.                         (= repl_start_buffer (inq_buffer))
  507.                         (set_buffer dbr_apx_file_id)
  508.                         (top_of_buffer)
  509.                         (while (&& (&& (search_fwd ";" 1 0)(! (inq_kbd_char)))(== repl_buffer_search 1))
  510.                             (
  511.                                 (beginning_of_line)
  512.                                 (= apx_program_name (read))
  513.                                 (= apx_program_name (trim (substr apx_program_name 50)))
  514.                                 (= apx_not_in_memory (edit_file apx_program_name))
  515.                                 (= apx_program_buffer (inq_buffer))
  516.                                 (inq_position repl_scan_line repl_scan_col)
  517.                                 (top_of_buffer)
  518.                                 (if (== (upper repl_prompt) "N")
  519.                                     (if (! (inq_kbd_char))
  520.                                         (+= repl_count (translate repl_search_str repl_replace_str 1 NULL NULL 0 1))
  521.                                     ;else
  522.                                         (
  523.                                             (= repl_buffer_search 0)
  524.                                             (= repl_abort_flag 1)
  525.                                         )
  526.                                     )
  527.                                 ;else
  528.                                     (+= repl_count (translate repl_search_str repl_replace_str NULL NULL NULL 0 1))
  529.                                 )
  530.                                 (move_abs repl_scan_line repl_scan_col)
  531.                                 (inq_names NULL NULL repl_buffer_name)
  532.                                 (message "%d replacements in %s." repl_count repl_buffer_name 0)
  533.                                 (if (inq_modified)
  534.                                     (write_buffer)
  535.                                 )
  536.                                 (set_buffer dbr_apx_file_id)
  537.                                 (if (== apx_not_in_memory 2)
  538.                                     (
  539.                                         (delete_buffer apx_program_buffer)
  540.                                     )
  541.                                 )
  542.                                 (move_rel 1 0)
  543.                             )
  544.                         )
  545.                         (keyboard_flush)
  546.                         (set_buffer repl_start_buffer)
  547.                         (attach_buffer repl_start_buffer)
  548.                         (sprintf temp_str "%d" repl_count)
  549.                         (if repl_count
  550.                             (if repl_abort_flag
  551.                                 (_display_popup_message "%s replacements before user abort!" temp_str 1)
  552.                             ;else
  553.                                 (_display_popup_message "%s replacements." temp_str 0)
  554.                             )
  555.                         ;else
  556.                             (_display_popup_message "Pattern %s not found!" repl_search_str 1)
  557.                         )
  558.                     )
  559.                 ;else
  560.                     (_display_popup_message "APX file not loaded!" "" 1)
  561.                 )
  562.             ;else
  563.                 (_display_popup_message "Invalid option %s!" repl_action 1)
  564.             )
  565.         )
  566.     )
  567. )
  568.