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

  1. ;Crossreferencing System - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro _find_constant
  6.     (
  7.         (int buf_start_buffer
  8.               buf_buffer_search
  9.               row
  10.               col
  11.               token_loc
  12.               incl_row
  13.               incl_in_memory
  14.               include_buffer
  15.               search_buffer
  16.         )
  17.         (string constant
  18.                   value
  19.                   msge
  20.                   file_name
  21.                   include_file
  22.         )
  23.         (inq_position row col)
  24.         (search_back "{<}|{[!\*()=+ \t]}\\c")
  25.         (= msge (trim (ltrim (read))))
  26.         (= token_loc (search_string "[!\*()=+ \t]" msge))
  27.         (if token_loc
  28.             (= constant (substr msge 1 (- token_loc 1)))
  29.         ;else
  30.             (= constant msge)
  31.         )
  32.         (= msge "")
  33.         (= incl_row row)
  34.         (if (strlen constant)
  35.             (
  36.                 (message "Searching for constant definition...")
  37.                 (= buf_start_buffer (inq_buffer))
  38.                 (= buf_buffer_search 1)
  39.                 (while buf_buffer_search
  40.                     (
  41.                         (inq_names NULL NULL file_name)
  42.                         (if (search_back (+ "#define[ \t]@" (+ constant "\\c")) 1 1)
  43.                             (
  44.                                  (= value (trim (ltrim (read))))
  45.                                 (message "")
  46.                                 (if (== "\"" (substr value 1 1))
  47.                                     (= value (substr value 2 (- (rindex value "\"") 2)))
  48.                                 )
  49.                                 (= search_buffer (inq_buffer))
  50.                                 (if (!= search_buffer buf_start_buffer)
  51.                                     (
  52.                                         (restore_position)
  53.                                         (if (!= incl_in_memory 1)
  54.                                             (delete_buffer search_buffer)
  55.                                         )
  56.                                     )
  57.                                 )
  58.                                 (set_buffer buf_start_buffer)
  59.                                 (move_abs row col)
  60.                                 (= buf_buffer_search 0)
  61.                             )
  62.                         ;else
  63.                             (
  64.                                 (= search_buffer (inq_buffer))
  65.                                 (if (!= search_buffer buf_start_buffer)
  66.                                     (
  67.                                         (restore_position)
  68.                                         (if (!= incl_in_memory 1)
  69.                                             (delete_buffer search_buffer)
  70.                                         )
  71.                                     )
  72.                                 )
  73.                                 (set_buffer buf_start_buffer)
  74.                                 (move_abs incl_row NULL)
  75.                                 (if (! (move_rel -1 0))
  76.                                     (
  77.                                         (= buf_buffer_search 0)
  78.                                         (= value "")
  79.                                         (break)
  80.                                     )
  81.                                 )
  82.                                 (if (search_back "<[ \t]@#include\\c")
  83.                                     (
  84.                                         (inq_position incl_row NULL)
  85.                                         (= include_file (trim (ltrim (read))))
  86.                                         (if (index include_file ">")
  87.                                              (= include_file (substr include_file 2 (- (index include_file ">") 2)))
  88.                                         ;else
  89.                                             (if (index include_file "\"")
  90.                                                 (= include_file (substr include_file 2 (- (rindex include_file "\"") 2)))
  91.                                             ;else
  92.                                                 (= include_file (trim (substr include_file 1 (+ (index include_file ".") 3))))
  93.                                             )
  94.                                         )
  95.                                         (= value include_file)
  96.                                         (= include_file (search_path (inq_environment "INCLUDE") include_file))
  97.                                         (if (strlen include_file)         ; if the include file object exists
  98.                                             (
  99.                                                 (= incl_in_memory (edit_file include_file))     ; edit the file to see if it's already in memory
  100.                                                 (= include_buffer (inq_buffer))     ; get the file id
  101.                                                 (save_position)
  102.                                                 (= value "")
  103.                                                 (end_of_buffer)
  104.                                             )
  105.                                         ;else
  106.                                             (
  107.                                                 (_display_popup_message "Unable to locate %s!" (upper value) 1)
  108.                                                 (= value "")
  109.                                                 (break)
  110.                                                 (_pause_for_seconds dbr_msg_seconds)
  111.                                             )
  112.                                         )
  113.                                     )
  114.                                 ;else
  115.                                     (
  116.                                         (= buf_buffer_search 0)
  117.                                         (= value "")
  118.                                         (break)
  119.                                         (move_abs row col)
  120.                                     )
  121.                                 )
  122.                             )
  123.                         )
  124.                     )
  125.                 )
  126.                 (set_buffer buf_start_buffer)
  127.                 (attach_buffer buf_start_buffer)
  128.                 (refresh)
  129.                 (if (strlen value)                            ; if we really did find something worth reporting
  130.                     (
  131.                         (sprintf msge "%s = %s" constant value) ; build the result display
  132.                         (_display_constant msge "" 0 file_name) ; display the constant value
  133.                     )
  134.                 ;else                                                ; no value discernable
  135.                     (_display_constant "%s not found!" (trim constant) 1 "[press any key]")
  136.                 )
  137.             )
  138.         ;else
  139.             (_display_popup_message "Is this a constant?" "" 1)
  140.         )
  141.         (move_abs row col)
  142.     )
  143. )
  144. (macro _display_constant
  145.     (
  146.         (int pop_error)
  147.         (string pop_message_string
  148.                   pop_message_parm
  149.                   found_file_name
  150.         )
  151.         (get_parm 0 pop_message_string)
  152.         (get_parm 1 pop_message_parm)
  153.         (get_parm 2 pop_error)
  154.         (get_parm 3 found_file_name)
  155.         (int pop_current_buffer
  156.               pop_display_buffer
  157.               pop_screen_lines
  158.               pop_screen_height
  159.               pop_window_width
  160.               pop_beep_count
  161.         )
  162.         (string pop_temp_str
  163.                   _line_1
  164.                   _line_2
  165.         )
  166.         (if (> (strlen pop_message_parm) 40)
  167.             (= pop_message_parm (trim (substr pop_message_parm 1 40)))
  168.         )
  169.         (if (index pop_message_string "\n")
  170.             (
  171.                 (= pop_screen_height 9)
  172.                 (= _line_1 (substr pop_message_string 1 (index pop_message_string "\n")))
  173.                 (sprintf _line_1 _line_1 pop_message_parm)
  174.                 (= _line_2 (substr pop_message_string (+ (index pop_message_string "\n") 1)))
  175.                 (sprintf _line_2 _line_2 pop_message_parm)
  176.             )
  177.         ;else
  178.             (
  179.                 (= pop_screen_height 8)
  180.                 (sprintf _line_1 pop_message_string pop_message_parm)
  181.                 (= _line_2 "")
  182.             )
  183.         )
  184.         (if (> (strlen (+ _line_1 pop_message_parm)) (strlen _line_2))
  185.             (
  186.                 (= pop_window_width (+ (strlen (+ _line_1 pop_message_parm)) 8))
  187.                 (= pop_message_string _line_1)
  188.             )
  189.         ;else
  190.             (
  191.                 (= pop_window_width (+ (strlen _line_2) 10))
  192.                 (= pop_message_string _line_2)
  193.             )
  194.         )
  195.         (if (> pop_window_width 72)
  196.             (= pop_window_width 72)
  197.         )
  198.         (inq_screen_size pop_screen_lines NULL)
  199.         (= pop_current_buffer (inq_buffer))
  200.         (if pop_error
  201.             (
  202.                 (while (<= (++ pop_beep_count) 2)
  203.                     (beep)
  204.                     )
  205.                 (= pop_display_buffer (create_buffer "ConstantXRef" NULL 1))
  206.             )
  207.         ;else
  208.             (= pop_display_buffer (create_buffer "ConstantXRef" NULL 1))
  209.         )
  210.         (if (>= (version) 310)
  211.             (execute_macro "db_hide 1")
  212.         )
  213.         (create_window (- 80 pop_window_width) (- pop_screen_lines 4) 75 (- pop_screen_lines pop_screen_height) found_file_name)
  214.         (if (>= (version) 310)
  215.             (execute_macro "db_show 1")
  216.         )
  217.         (set_buffer pop_display_buffer)
  218.         (attach_buffer pop_display_buffer)
  219.         (if (== pop_screen_height 8)
  220.             (
  221.                 (move_abs 2 (- (/ (- pop_window_width (strlen _line_1)) 2) 2))
  222.                 (insert _line_1)
  223.             )
  224.         ;else
  225.             (
  226.                 (move_abs 2 (- (/ (- pop_window_width (strlen _line_1)) 2) 2))
  227.                 (insert _line_1)
  228.                 (move_abs 3 (- (/ (- pop_window_width (strlen _line_2)) 2) 2))
  229.                 (insert _line_2)
  230.             )
  231.         )
  232.         (beginning_of_line)
  233.         (top_of_buffer)
  234.         (refresh)
  235.         (_pause_for_seconds dbr_msg_seconds)
  236.         (delete_window)
  237.         (set_buffer pop_current_buffer)
  238.         (attach_buffer pop_current_buffer)
  239.         (delete_buffer pop_display_buffer)
  240.     )
  241. )
  242.