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

  1. ;dBRIEF MacroLib - v3.10
  2. ;Copyright (c) 1990 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro _date_time
  6.     (
  7.         (int                year
  8.                             month
  9.                             day
  10.                             hours
  11.                             minutes
  12.                             seconds
  13.                             operation
  14.         )
  15.         (string            return_string
  16.                             month_string
  17.                             weekday_string
  18.                             year_string
  19.                             ampm
  20.         )
  21.         (get_parm 0 operation)
  22.         (date year month day month_string weekday_string)
  23.         (sprintf year_string "%d" year)
  24.         (= year_string (substr year_string 3 2))
  25.         (time hours minutes seconds)
  26.         (switch operation
  27.             1
  28.                 (sprintf return_string "%02d/%02d/%s" month day year_string)
  29.             2
  30.                 (sprintf return_string "%d" year)
  31.             3
  32.                 (sprintf return_string "%02d:%02d:%02d" hours minutes seconds)
  33.             4
  34.                 (
  35.                     (= ampm "a")
  36.                     (if (>= hours 12)
  37.                         (
  38.                             (= ampm "p")
  39.                             (if (!= hours 12)
  40.                                 (-= hours 12)
  41.                             )
  42.                         )
  43.                     )
  44.                     (if (== hours 0)
  45.                         (= hours 12)
  46.                     )
  47.                     (sprintf return_string "%02d:%02d %sm" hours minutes ampm)
  48.                 )
  49.             5
  50.                 (sprintf return_string "%s %d, %d" month_string day year)
  51.         )
  52.         (return return_string)
  53.     )
  54. )
  55. (macro _pad_right
  56.     (
  57.         (int                pad_length
  58.         )
  59.         (string            pad_string
  60.         )
  61.         (get_parm 0 pad_string)
  62.         (get_parm 1 pad_length)
  63.         (= pad_string (trim pad_string))
  64.         (if (< (strlen pad_string) pad_length)
  65.             (return (+ pad_string (_replicate " " (- pad_length (strlen pad_string)))))
  66.         ;else
  67.             (return pad_string)
  68.         )
  69.     )
  70. )
  71. (macro _display_popup_message
  72.     (
  73.         (int                pop_current_buffer
  74.                             pop_display_buffer
  75.                             pop_error
  76.                             pop_screen_lines
  77.                             pop_window_width
  78.                             pop_beep_count
  79.         )
  80.         (string            pop_message_string
  81.                             pop_message_parm
  82.                             pop_temp_str
  83.         )
  84.         (get_parm 0 pop_message_string)
  85.         (get_parm 1 pop_message_parm)
  86.         (get_parm 2 pop_error)
  87.         (if (> (strlen (+ pop_message_string pop_message_parm)) 62)
  88.             (= pop_message_parm (trim (substr pop_message_parm 1 (- 62 (strlen pop_message_string)))))
  89.         )
  90.         (message "")
  91.         (if dbr_message_windows
  92.             (
  93.                 (inq_screen_size pop_screen_lines NULL)
  94.                 (if (strlen pop_message_parm)
  95.                     (= pop_window_width (+ (strlen (+ pop_message_string pop_message_parm)) 8))
  96.                 ;else
  97.                     (= pop_window_width (+ (strlen pop_message_string) 10))
  98.                 )
  99.                 (= pop_current_buffer (inq_buffer))
  100.                 (if pop_error
  101.                     (
  102.                         (while (<= (++ pop_beep_count ) dbr_err_beeps)
  103.                             (beep)
  104.                         )
  105.                         (= pop_display_buffer (create_buffer "Error!" NULL 1))
  106.                     )
  107.                 ;else
  108.                     (= pop_display_buffer (create_buffer "Message" NULL 1))
  109.                 )
  110.                 (if (>= (version) 310)
  111.                     (execute_macro "db_hide 1")
  112.                 )
  113.                 (create_window (- 80 pop_window_width) (- pop_screen_lines 4) 75 (- pop_screen_lines 8) "[press any key]")
  114.                 (if (>= (version) 310)
  115.                     (execute_macro "db_show 1")
  116.                 )
  117.                 (set_buffer pop_display_buffer)
  118.                 (attach_buffer pop_display_buffer)
  119.                 (sprintf pop_temp_str pop_message_string pop_message_parm)
  120.                 (move_abs 2 3)
  121.                 (insert pop_temp_str)
  122.                 (refresh)
  123.                 (_pause_for_seconds dbr_msg_seconds)
  124.                 (delete_window)
  125.                 (set_buffer pop_current_buffer)
  126.                 (attach_buffer pop_current_buffer)
  127.                 (delete_buffer pop_display_buffer)
  128.             )
  129.         ;else
  130.             (
  131.                 (if pop_error
  132.                     (while (<= (++ pop_beep_count ) dbr_err_beeps)
  133.                         (beep)
  134.                     )
  135.                 )
  136.                 (message pop_message_string)
  137.             ;pop_message_parm)
  138.             )
  139.         )
  140.     )
  141. )
  142. (macro _pause_for_seconds
  143.     (
  144.         (int            start_seconds
  145.                         pause_seconds
  146.                         curnt_seconds
  147.         )
  148.         (get_parm 0 pause_seconds)
  149.         (time NULL NULL start_seconds NULL)
  150.         (= start_seconds (% (+ start_seconds pause_seconds) 60))
  151.         (while (&& (!= curnt_seconds start_seconds)(! (inq_kbd_char)))
  152.             (time NULL NULL curnt_seconds NULL)
  153.         )
  154.         (keyboard_flush)
  155.     )
  156. )
  157. (macro _menu_lines
  158.     (
  159.         (int                screen_lines
  160.                             options
  161.         )
  162.         (get_parm 0 options)
  163.         (inq_screen_size screen_lines NULL)
  164.         (if (> screen_lines 24)
  165.             (-= screen_lines 4)
  166.         ;else
  167.             (-= screen_lines 2)
  168.         )
  169.         (if (> (+= options 3) screen_lines)
  170.             (= options screen_lines)
  171.         )
  172.         (return options)
  173.     )
  174. )
  175. (macro _get_directory
  176.     (
  177.         (string            directory
  178.         )
  179.         (inq_names directory NULL NULL)
  180.         (if (rindex directory "\\")
  181.             (= directory (substr directory 1 (rindex directory "\\")))
  182.         )
  183.         (return (upper directory))
  184.     )
  185. )
  186. (macro _replicate
  187.     (
  188.         (int                rep_characters
  189.                             rep_times
  190.         )
  191.         (string            rep_character
  192.                             rep_string
  193.         )
  194.         (get_parm 0 rep_character)
  195.         (get_parm 1 rep_characters)
  196.         (while (<= (++ rep_times) rep_characters)
  197.             (+= rep_string rep_character)
  198.         )
  199.         (return rep_string)
  200.     )
  201. )
  202. (macro _number_lines
  203.     (
  204.         (int                number_lines
  205.         )
  206.         (save_position)
  207.         (end_of_buffer)
  208.         (inq_position number_lines NULL)
  209.         (restore_position)
  210.         (return number_lines)
  211.     )
  212. )
  213. (macro _number_bytes
  214.     (
  215.         (int            number_bytes
  216.         )
  217.         (save_position)
  218.         (top_of_buffer)
  219.         (drop_anchor)
  220.         (end_of_buffer)
  221.         (= number_bytes (inq_mark_size))
  222.         (raise_anchor)
  223.         (restore_position)
  224.         (return number_bytes)
  225.     )
  226. )
  227. (replacement _invalid_key
  228.     (
  229.         (int _key_int)
  230.         (string _key_read)
  231.         (if (== (inq_called) "_pick_menu")
  232.             (
  233.                 (= _key_int (& 0xff (read_char)))
  234.                 (sprintf _key_read "%c" _key_int)
  235.                 (raise_anchor)
  236.                 (save_position)
  237.                 (move_rel 0 1)
  238.                 (= _key_read (+ "<\\c[ \t]@" _key_read))
  239.                 (if (! (search_fwd _key_read 1 0))
  240.                     (
  241.                         (top_of_buffer)
  242.                         (if (! (search_fwd _key_read 1 0))
  243.                             (
  244.                                 (restore_position)
  245.                                 (beep)
  246.                             )
  247.                         )
  248.                     )
  249.                 )
  250.                 (drop_anchor 3)
  251.                 (refresh)
  252.                 (_menu_message)
  253.             )
  254.         ;else
  255.             (_invalid_key)
  256.         )
  257.     )
  258. )
  259. (macro _pick_menu
  260.     (
  261.         (int                _mnu_ul_x
  262.                             _mnu_ul_y
  263.                             _mnu_lr_x
  264.                             _mnu_lr_y
  265.                             _mnu_current_buffer
  266.                             _mnu_display_buffer
  267.         )
  268.         (string            _mnu_file
  269.                             _mnu_titl
  270.                             _mnu_inst
  271.                             _mnu_process
  272.                             _mnu_parameter
  273.                             _mouse_macro
  274.         )
  275.         (global            _mnu_parameter
  276.         )
  277.         (get_parm 0 _mnu_file)
  278.         (get_parm 1 _mnu_titl)
  279.         (get_parm 2 _mnu_ul_x)
  280.         (get_parm 3 _mnu_ul_y)
  281.         (get_parm 4 _mnu_lr_x)
  282.         (get_parm 5 _mnu_lr_y)
  283.         (get_parm 6 _mnu_process)
  284.         (get_parm 7 _mnu_display_buffer)
  285.         (get_parm 8 _mnu_inst)
  286.         (get_parm 9 _mouse_macro)
  287.         (set_calling_name "_pick_menu")
  288.         (= _mnu_current_buffer (inq_buffer))
  289.         (if (|| (!= "" _mnu_file)(!= 0 _mnu_display_buffer))
  290.             (
  291.                 (keyboard_push)
  292.                 (if (! _mnu_display_buffer)
  293.                     (= _mnu_display_buffer (create_buffer _mnu_titl _mnu_file))
  294.                 )
  295.                 (if (>= (version) 310)
  296.                     (execute_macro "db_hide 0 _pick_action")
  297.                 )
  298.                 (if (strlen _mnu_inst)
  299.                     (create_window _mnu_ul_x _mnu_ul_y _mnu_lr_x _mnu_lr_y _mnu_inst)
  300.                 ;else
  301.                     (create_window _mnu_ul_x _mnu_ul_y _mnu_lr_x _mnu_lr_y "  ─┘ to select")
  302.                 )
  303.                 (if (>= (version) 310)
  304.                     (execute_macro "db_show 0")
  305.                 )
  306.                 (set_buffer _mnu_display_buffer)
  307.                 (attach_buffer _mnu_display_buffer)
  308.                 (top_of_buffer)
  309.                 (raise_anchor)
  310.                 (drop_anchor 3)
  311.                 (refresh)
  312.                 (if (strlen _mnu_process)
  313.                     (
  314.                         (sprintf _mnu_parameter "_menu_process %s %d %d" _mnu_process (- _mnu_ul_y _mnu_lr_y) (_number_lines))
  315.                         (execute_macro (+ _mnu_parameter " 0"))
  316.                         (assign_to_key "<Enter>" (+ _mnu_parameter " 13"))
  317.                         (assign_to_key "<Keypad-plus>" (+ _mnu_parameter " 13"))
  318.                         (assign_to_key "<Esc>" (+ _mnu_parameter " 27"))
  319.                         (assign_to_key "<Keypad-minus>" (+ _mnu_parameter " 45"))
  320.                         (assign_to_key "<Up>" (+ _mnu_parameter " 0"))
  321.                         (assign_to_key "<Down>" (+ _mnu_parameter " 1"))
  322.                         (assign_to_key "<PgUp>" (+ _mnu_parameter " 2"))
  323.                         (assign_to_key "<PgDn>" (+ _mnu_parameter " 3"))
  324.                     )
  325.                 ;else
  326.                     (
  327.                         (_menu_message 1)
  328.                         (assign_to_key "<Enter>" "_menu_enter")
  329.                         (assign_to_key "<Keypad-plus>" "_menu_enter")
  330.                         (assign_to_key "<Esc>" "_menu_escape")
  331.                         (assign_to_key "<Keypad-minus>" "_menu_escape")
  332.                         (sprintf _mnu_parameter "1 %d" (_number_lines))
  333.                         (assign_to_key "<Up>" (+ "_menu_line -1 " _mnu_parameter))
  334.                         (assign_to_key "<Down>" (+ "_menu_line 1 " _mnu_parameter))
  335.                         (sprintf _mnu_parameter "1 %d %d" (- _mnu_ul_y _mnu_lr_y) (_number_lines))
  336.                         (assign_to_key "<PgUp>" (+ "_menu_page -1 " _mnu_parameter))
  337.                         (assign_to_key "<PgDn>" (+ "_menu_page 1 " _mnu_parameter))
  338.                     )
  339.                 )
  340.                 (process)
  341.                 (keyboard_pop)
  342.                 (delete_window)
  343.                 (set_buffer _mnu_current_buffer)
  344.                 (attach_buffer _mnu_current_buffer)
  345.                 (delete_buffer _mnu_display_buffer)
  346.                 (message "")
  347.             )
  348.         ;else
  349.             (
  350.                 (= temp_str "NULL")
  351.                 (_display_popup_message "Cannot create menu. File not found!" "" 1)
  352.             )
  353.         )
  354.     )
  355. )
  356. (macro _pick_action
  357.     (
  358.         (int event
  359.               modifier
  360.               parm2
  361.               parm3
  362.         )
  363.         (get_parm 0 event)
  364.         (get_parm 1 modifier)
  365.         (get_parm 2 parm2)
  366.         (get_parm 3 parm3)
  367.         (switch event
  368.             10      NULL ;BTN1_CLICK:
  369.             13
  370.             (
  371.                 (int lines
  372.                         max_lines
  373.                 )
  374.                 (if (&& (! (inq_position lines))(< 0 parm2))
  375.                     (
  376.                         (= max_lines lines)
  377.                         (while (&& (! (inq_position))(> parm2 lines))
  378.                             (
  379.                                 (execute_macro (inq_assignment "<Down>"))
  380.                                 (inq_position lines)
  381.                                 (if (== max_lines lines)
  382.                                     (break)
  383.                                 ;else
  384.                                     (= max_lines lines)
  385.                                 )
  386.                             )
  387.                         )
  388.                 ;else
  389.                         (while (&& (! (inq_position))(< parm2 lines))
  390.                             (
  391.                                 (execute_macro (inq_assignment "<Up>"))
  392.                                 (inq_position lines)
  393.                                 (if (== max_lines lines)
  394.                                     (break)
  395.                                 ;else
  396.                                     (= max_lines lines)
  397.                                 )
  398.                             )
  399.                         )
  400.                         (switch event
  401.                             13      ; edit the file
  402.                                 (execute_macro (inq_assignment "<Enter>"))
  403.                         )
  404.                     )
  405.                 )
  406.             )
  407.             19
  408.                 (if (== (inq_assignment "<Esc>") "nothing")
  409.                     (push_back (key_to_int "<Esc>"))
  410.                 ;else
  411.                     (execute_macro (inq_assignment "<Esc>"))
  412.                 )
  413.             17
  414.             (
  415.                 (switch parm2
  416.                     3
  417.                         (execute_macro (inq_assignment "<PgDn>"))
  418.                     2
  419.                         (execute_macro (inq_assignment "<PgUp>"))
  420.                     1
  421.                         (execute_macro (inq_assignment "<Down>"))
  422.                     0
  423.                         (execute_macro (inq_assignment "<Up>"))
  424.                 )
  425.             )
  426.         )
  427.     )
  428. )
  429. (macro _menu_process
  430.     (
  431.         (int                _mnu_last_key
  432.                             _mnu_length
  433.                             _mnu_options
  434.         )
  435.         (string            _mnu_process
  436.                             _mnu_text_line
  437.         )
  438.         (get_parm 0 _mnu_process)
  439.         (get_parm 1 _mnu_length)
  440.         (get_parm 2 _mnu_options)
  441.         (get_parm 3 _mnu_last_key)
  442.         (switch _mnu_last_key
  443.             0
  444.                 (_menu_line -1 0 _mnu_options)
  445.             1
  446.                 (_menu_line 1 0 _mnu_options)
  447.             2
  448.                 (_menu_page -1 0 _mnu_length _mnu_options)
  449.             3
  450.                 (_menu_page 1 0 _mnu_length _mnu_options)
  451.         )
  452.         (beginning_of_line)
  453.         (= _mnu_text_line (trim (read)))
  454.         (execute_macro _mnu_process _mnu_last_key _mnu_text_line)
  455.     )
  456. )
  457. (macro _menu_message
  458.     (
  459.         (string            _mnu_message
  460.                             _mnu_text_line
  461.         )
  462.         (beginning_of_line)
  463.         (= _mnu_text_line (trim (read)))
  464.         (= _mnu_message (substr _mnu_text_line (+ (index _mnu_text_line "|") 1)))
  465.         (if (!= "|" (substr _mnu_message 1 1))
  466.             (message "%s" _mnu_message)
  467.         )
  468.     )
  469. )
  470. (macro _menu_line
  471.     (
  472.         (int                _dis_message
  473.                             _dis_options
  474.                             _dis_direction
  475.         )
  476.         (get_parm 0 _dis_direction)
  477.         (get_parm 1 _dis_message)
  478.         (get_parm 2 _dis_options)
  479.         (if (|| (&& (== (_menu_position) _dis_options)(== _dis_direction 1))(&& (== (_menu_position) 1)(== _dis_direction -1)))
  480.             (= _dis_direction 0)
  481.         )
  482.         (if (!= _dis_direction 0)
  483.             (
  484.                 (raise_anchor)
  485.                 (move_rel _dis_direction 0)
  486.                 (drop_anchor 3)
  487.                 (if _dis_message
  488.                     (_menu_message)
  489.                 )
  490.             )
  491.         )
  492.     )
  493. )
  494. (macro _menu_page
  495.     (
  496.         (int                _dis_message
  497.                             _dis_length
  498.                             _dis_options
  499.                             _dis_direction
  500.                             _dis_move
  501.         )
  502.         (extern to_bottom)
  503.         (get_parm 0 _dis_direction)
  504.         (get_parm 1 _dis_message)
  505.         (get_parm 2 _dis_length)
  506.         (get_parm 3 _dis_options)
  507.         (extern to_bottom)
  508.         (= _dis_move (- _dis_length 1))
  509.         (*= _dis_length _dis_direction)
  510.         (if (< (+ (_menu_position) _dis_length) _dis_options)
  511.             (
  512.                 (raise_anchor)
  513.                 (inq_top_left _dis_length NULL)
  514.                 (if (&& (== 1 _dis_direction)(!= (_menu_position) _dis_length))
  515.                     (to_top)
  516.                 ;else
  517.                     (
  518.                         (move_rel (* _dis_move _dis_direction) 0)
  519.                         (to_top)
  520.                     )
  521.                 )
  522.                 (while (inq_position)
  523.                     (move_rel -1 0)
  524.                 )
  525.                 (drop_anchor 3)
  526.                 (if _dis_message
  527.                     (_menu_message)
  528.                 )
  529.             )
  530.             ;else
  531.             (
  532.                 (raise_anchor)
  533.                 (if (== 1 _dis_direction)
  534.                     (
  535.                         (= _dis_move (_menu_position))
  536.                         (move_rel _dis_options 0)
  537.                         (while (inq_position)
  538.                             (move_rel -1 0)
  539.                         )
  540.                         (drop_anchor 3)
  541.                     )
  542.                 ;else
  543.                     (
  544.                         (top_of_buffer)
  545.                         (drop_anchor 3)
  546.                     )
  547.                 )
  548.                 (if _dis_message
  549.                     (_menu_message)
  550.                 )
  551.             )
  552.         )
  553.     )
  554. )
  555. (macro _menu_enter
  556.     (
  557.         (string            _mnu_pointer
  558.                             _mnu_text_line
  559.         )
  560.         (beginning_of_line)
  561.         (= _mnu_text_line (trim (read)))
  562.         (= _mnu_pointer (substr _mnu_text_line (+ (index _mnu_text_line ";") 1)))
  563.         (= _mnu_pointer (substr _mnu_pointer 1 (- (index _mnu_pointer "|") 1)))
  564.         (= temp_str (trim _mnu_pointer))
  565.         (message "")
  566.         (exit)
  567.     )
  568. )
  569. (macro _menu_escape
  570.     (
  571.         (= temp_str "NULL")
  572.         (message "")
  573.         (exit)
  574.     )
  575. )
  576. (macro _menu_position
  577.     (
  578.         (int                _mnu_current_line
  579.         )
  580.         (inq_position _mnu_current_line NULL)
  581.         (return _mnu_current_line)
  582.     )
  583. )
  584. (macro _parse_child
  585.     (
  586.         (string            _dbf_file
  587.                             _str_file
  588.         )
  589.         (get_parm 0 _dbf_file)
  590.         (get_parm 1 _str_file)
  591.         (if (== (substr _dbf_file 1 3) "..\\")
  592.             (= _str_file (substr _dbf_file 4))
  593.         ;else
  594.             (if (== (substr _dbf_file 2 4) ":..\\")
  595.                 (= _str_file (substr _dbf_file 6))
  596.             ;else
  597.                 (= _str_file _dbf_file)
  598.             )
  599.         )
  600.         (while (index _str_file "\\")
  601.             (= _str_file (substr _str_file (+ (index _str_file "\\") 1)))
  602.         )
  603.         (return _str_file)
  604.     )
  605. )
  606.