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

  1. ;dBRIEF Generate  - v3.10
  2. ;Copyright (c) 1991 - Global Technologies Corporation
  3. ;ALL RIGHTS RESERVED
  4. #include "dbrief.h"
  5. (macro stor
  6.     (
  7.         (if (_get_dialect_info dbr_dialect 6)
  8.             (
  9.                 (string            scatter_file
  10.                 )
  11.                 (if (get_parm 0 scatter_file "Database file to store to memars: ")
  12.                     (_generate_fields scatter_file "S")
  13.                 )
  14.             )
  15.         ;else
  16.             (
  17.                 (_display_popup_message "STORE not supported in %s!" (_get_dialect_info dbr_dialect 1) 1)
  18.                 (return 0)
  19.             )
  20.         )
  21.     )
  22. )
  23. (macro scat
  24.     (
  25.         (if (_get_dialect_info dbr_dialect 6)
  26.             (
  27.                 (string            scatter_file
  28.                 )
  29.                 (if (get_parm 0 scatter_file "Database file to scatter: ")
  30.                     (_generate_fields scatter_file "=")
  31.                 )
  32.             )
  33.         ;else
  34.             (
  35.                 (_display_popup_message "SCATTER not supported in %s!" (_get_dialect_info dbr_dialect 1) 1)
  36.                 (return 0)
  37.             )
  38.         )
  39.     )
  40. )
  41. (macro gath
  42.     (
  43.         (if (_get_dialect_info dbr_dialect 6)
  44.             (
  45.                 (string            gather_file
  46.                 )
  47.                 (if (get_parm 0 gather_file "Database file to gather: ")
  48.                     (_generate_fields gather_file "R")
  49.                 )
  50.             )
  51.         ;else
  52.             (
  53.                 (_display_popup_message "GATHER not supported in %s!" (_get_dialect_info dbr_dialect 1) 1)
  54.                 (return 0)
  55.             )
  56.         )
  57.     )
  58. )
  59. (macro init
  60.     (
  61.         (if (_get_dialect_info dbr_dialect 6)
  62.             (
  63.                 (string        _dbf_file
  64.                 )
  65.                 (if (get_parm 0 _dbf_file "Database file name: ")
  66.                     (_generate_fields _dbf_file "I")
  67.                 )
  68.             )
  69.         ;else
  70.             (
  71.                 (_display_popup_message "INITIALIZE not supported in %s!" (_get_dialect_info dbr_dialect 1) 1)
  72.                 (return 0)
  73.             )
  74.         )
  75.     )
  76. )
  77. (macro _create_routine_from_block
  78.     (
  79.         (int                function_column
  80.                             routine_line
  81.                             routine_col
  82.                             routine_start_line
  83.                             routine_start_col
  84.                             routine_end_line
  85.                             routine_end_col
  86.                             routine_orig_buffer
  87.                             routine_dest_buffer
  88.         )
  89.         (string            routine_name
  90.                             routine_prompt
  91.                             routine_return
  92.                             routine_mask
  93.                             routine_exec
  94.                             routine_comment
  95.                             header_file
  96.                             routine_temp_str
  97.                             routine_destination
  98.                             routine_suffix
  99.         )
  100.         (get_parm 0 routine_prompt)
  101.         (get_parm 1 routine_return)
  102.         (get_parm 2 header_file)
  103.         (get_parm 3 routine_mask)
  104.         (get_parm 4 routine_exec)
  105.         (inq_names NULL NULL temp_str)
  106.         (if (get_parm 5 routine_name (+ routine_prompt " name: "))
  107.             (
  108.                 (if (! (get_parm 6 routine_comment "Comment: "))
  109.                     (return)
  110.                 )
  111.                 (if (! (get_parm 7 routine_destination "Destination file: " NULL temp_str))
  112.                     (return)
  113.                 )
  114.                 (inq_marked routine_start_line routine_start_col routine_end_line routine_end_col)
  115.                 (raise_anchor)
  116.                 (if (|| (== (upper temp_str) (upper (+ routine_name (+ "." (_get_dialect_info dbr_dialect 3))))) (search_fwd (+ (+ (+ "<" routine_mask) "*{ @}|{\\t@}") routine_name) 1 0))
  117.                     (
  118.                         (_display_popup_message (+ routine_prompt " %s already exists as a file or function!") (upper routine_name) 1)
  119.                         (move_abs routine_start_line routine_start_col)
  120.                         (mark 4)
  121.                         (move_abs (+ routine_end_line 1) 1)
  122.                     )
  123.                 ;else
  124.                     (
  125.                         (move_abs routine_start_line routine_start_col)
  126.                         (drop_anchor)
  127.                         (move_abs routine_end_line routine_end_col)
  128.                         (cut)
  129.                         (save_position)
  130.                         (up)
  131.                         (end_of_line)
  132.                         (insert "\n")
  133.                         (inq_position routine_start_line routine_start_col)
  134.                         (if (== routine_prompt "Procedure")
  135.                             (_case_insert (+ (+ (_execute_command) (+ routine_exec " ")) routine_name) 0 0)
  136.                         ;else
  137.                             (_case_insert (+ routine_name "()") 0 0)
  138.                         )
  139.                         (if (!= (upper routine_destination) (upper temp_str))
  140.                             (
  141.                                 (= routine_orig_buffer (inq_buffer))
  142.                                 (edit_file routine_destination)
  143.                                 (= routine_dest_buffer (inq_buffer))
  144.                             )
  145.                         )
  146.                         (end_of_buffer)
  147.                         (insert "\n\n")
  148.                         (save_position)
  149.                         (inq_position routine_line NULL)
  150.                         (if (& (inq_kbd_flags) 0x40)
  151.                             (_procedure_header (upper routine_prompt) routine_return header_file)
  152.                         ;else
  153.                             (_procedure_header (lower routine_prompt) routine_return header_file)
  154.                         )
  155.                         (if (== dbr_dialect 9)
  156.                             (_case_insert (+ " " (+ routine_name "()\n")) 0 0)
  157.                         ;else
  158.                             (_case_insert (+ " " (+ routine_name "\n")) 0 0)
  159.                         )
  160.                         (paste)
  161.                         (delete_line)
  162.                         (delete_line)
  163.                         (if (strlen ProcSuffix)
  164.                             (
  165.                                 (end_of_line)
  166.                                 (sprintf routine_suffix ProcSuffix routine_name routine_name)
  167.                                 (insert routine_suffix)
  168.                                 (up)
  169.                                 (up)
  170.                             )
  171.                         )
  172.                         (up)
  173.                         (beginning_of_line)
  174.                         (search_fwd "<*\\c[~ \\t\\n]")
  175.                         (inq_position NULL function_column)
  176.                         (search_back (+ "<" routine_mask) 1 0)
  177.                         (beginning_of_line)
  178.                         (drop_anchor)
  179.                         (search_fwd (+ "<" routine_return) 1 0)
  180.                         (down)
  181.                         (rein 0)
  182.                         (restore_position)
  183.                         (if (!= (upper routine_destination) (upper temp_str))
  184.                             (
  185.                                 (write_buffer)
  186.                                 (set_buffer routine_orig_buffer)
  187.                                 (attach_buffer routine_orig_buffer)
  188.                                 (if (!= routine_orig_buffer routine_dest_buffer)
  189.                                     (delete_buffer routine_dest_buffer)
  190.                                 )
  191.                             )
  192.                         ;else
  193.                             (if (== dbr_dialect 9)
  194.                                 (
  195.                                     (drop_anchor 3)
  196.                                     (end_of_buffer)
  197.                                     (cut)
  198.                                 )
  199.                             )
  200.                         )
  201.                         (restore_position)
  202.                         (= routine_temp_str (read))
  203.                         (beginning_of_line)
  204.                         (delete_to_eol)
  205.                         (move_abs 0 function_column)
  206.                         (insert routine_temp_str)
  207.                         (delete_line)
  208.                         (up)
  209.                         (end_of_line)
  210.                         (if (== routine_prompt "Procedure")
  211.                             (move_rel 0 1)
  212.                         ;else
  213.                             (move_rel 0 -1)
  214.                         )
  215.                         (if (strlen routine_comment)
  216.                             (_write_comment routine_comment)
  217.                         )
  218.                           (move_abs routine_start_line routine_col)
  219.                         (if (&& (== dbr_dialect 9)(== (upper routine_destination) (upper temp_str)))
  220.                             (
  221.                                 (top_of_buffer)
  222.                                 (paste)
  223.                                 (move_rel (- routine_start_line 1) 0)
  224.                                 (= routine_line 1)
  225.                             )
  226.                         )
  227.                         (sprintf routine_temp_str "%s %s created at line %d in %s." routine_prompt (upper routine_name) routine_line routine_destination)
  228.                         (_display_popup_message routine_temp_str "" 0)
  229.                     )
  230.                 )
  231.             )
  232.         )
  233.     )
  234. )
  235. (macro _write_comment
  236.     (
  237.         (string            comment_string
  238.                             comment_read
  239.         )
  240.         (get_parm 0 comment_string)
  241.         (save_position)
  242.         (beginning_of_line)
  243.         (= comment_read (read))
  244.         (if (|| (== comment_read " ")(== comment_read "\n"))
  245.             (
  246.                 (delete_to_eol)
  247.                 (insert (+ (_comment_character 2) (+ " " comment_string)))
  248.             )
  249.         ;else
  250.             (
  251.                 (if (|| (== dbr_comment_tab 0)(> (strlen comment_read) dbr_comment_tab))
  252.                     (
  253.                         (end_of_line)
  254.                         (right)
  255.                         (right)
  256.                     )
  257.                 ;else
  258.                     (move_abs 0 dbr_comment_tab)
  259.                 )
  260.                 (delete_to_eol)
  261.                 (insert (+ (+ (_comment_character 1) " ") comment_string))
  262.             )
  263.         )
  264.         (restore_position)
  265.     )
  266. )
  267. (macro _substitute_window_coordinates
  268.     (
  269.         (int                beg_line
  270.                             beg_col
  271.                             end_line
  272.                             end_col
  273.                             top_line
  274.                             current_line
  275.                             current_column
  276.         )
  277.         (string            coordinate_string
  278.         )
  279.         (if (== (inq_marked) 2)
  280.             (
  281.                 (drop_bookmark 5 "y")
  282.                 (top_of_window)
  283.                 (inq_position top_line NULL)
  284.                 (goto_bookmark 5)
  285.                 (inq_marked beg_line beg_col end_line end_col)
  286.                 (-= beg_line top_line)
  287.                 (-= end_line top_line)
  288.                 (-- beg_col)
  289.                 (-- end_col)
  290.                 (raise_anchor)
  291.                 (top_of_buffer)
  292.                 (if (search_fwd "^UX,^UY*^LX,^LY" 1 0)
  293.                     (
  294.                         (inq_position current_line current_column)
  295.                         (sprintf coordinate_string "%02d" beg_line)
  296.                         (translate "^ux" coordinate_string 1 0 0)
  297.                         (sprintf coordinate_string "%02d" beg_col)
  298.                         (translate "^uy" coordinate_string 1 0 0)
  299.                         (sprintf coordinate_string "%02d" end_line)
  300.                         (translate "^lx" coordinate_string 1 0 0)
  301.                         (sprintf coordinate_string "%02d" end_col)
  302.                         (translate "^ly" coordinate_string 1 0 0)
  303.                         (move_abs current_line current_column)
  304.                     )
  305.                 ;else
  306.                     (_display_popup_message "Window coordinates not found!" "" 1)
  307.                 )
  308.             )
  309.         ;else
  310.             (_display_popup_message "No column mark present!" "" 1)
  311.         )
  312.     )
  313. )
  314. (macro _reverse_window_coordinates
  315.     (
  316.         (int              top_line
  317.                             current_line
  318.                             current_column
  319.                             beg_line
  320.                             beg_col
  321.                             end_line
  322.                             end_col
  323.                             coord_position
  324.         )
  325.         (string            coordinate_string
  326.         )
  327.         (save_position)
  328.         (beginning_of_line)
  329.         (= coordinate_string (read))
  330.         (restore_position)
  331.         (if (search_string "{ CLEA TO }|{ CLEAR TO }|{ FILL TO }|{ TO }|{[0-9][0-9],[0-9][0-9],[0-9][0-9],[0-9][0-9]}" (upper coordinate_string) NULL 1)
  332.             (
  333.                 (beginning_of_line)
  334.                 (drop_anchor)
  335.                 (end_of_line)
  336.                 (if (index (upper coordinate_string) " CLEAR TO ")
  337.                     (
  338.                         (= coordinate_string (ltrim (trim (substr coordinate_string (- (index (upper coordinate_string) " CLEAR TO ") 5) 20))))
  339.                         (translate coordinate_string "^ux,^uy clear to ^lx,^ly" 0 0 0 1)
  340.                         (= coord_position 16)
  341.                     )
  342.                 ;else
  343.                     (if (index (upper coordinate_string) " CLEA TO ")
  344.                         (
  345.                             (= coordinate_string (ltrim (trim (substr coordinate_string (- (index (upper coordinate_string) " CLEA TO ") 5) 19))))
  346.                             (translate coordinate_string "^ux,^uy clea to ^lx,^ly" 0 0 0 1)
  347.                             (= coord_position 15)
  348.                         )
  349.                     ;else
  350.                         (if (index (upper coordinate_string) " FILL TO ")
  351.                             (
  352.                                 (= coordinate_string (ltrim (trim (substr coordinate_string (- (index (upper coordinate_string) " FILL TO ") 5) 19))))
  353.                                 (translate coordinate_string "^ux,^uy fill to ^lx,^ly" 0 0 0 1)
  354.                                 (= coord_position 15)
  355.                             )
  356.                         ;else
  357.                             (if (index (upper coordinate_string) " TO ")
  358.                                 (
  359.                                     (= coordinate_string (ltrim (trim (substr coordinate_string (- (index (upper coordinate_string) " TO ") 5) 14))))
  360.                                     (translate coordinate_string "^ux,^uy to ^lx,^ly" 0 0 0 1)
  361.                                     (= coord_position 10)
  362.                                 )
  363.                             ;else
  364.                                 (if (search_string "{[0-9][0-9],[0-9][0-9],[0-9][0-9],[0-9][0-9]}" coordinate_string NULL 1)
  365.                                     (
  366.                                         (= coord_position (search_string "{[0-9][0-9],[0-9][0-9],[0-9][0-9],[0-9][0-9]}" coordinate_string NULL 1))
  367.                                         (= coordinate_string (ltrim (trim (substr coordinate_string coord_position 11))))
  368.                                         (translate coordinate_string "^ux,^uy,^lx,^ly" 0 0 0 1)
  369.                                         (= coord_position 7)
  370.                                     )
  371.                                 )
  372.                             )
  373.                         )
  374.                     )
  375.                 )
  376.                 (raise_anchor)
  377.                 (= beg_line (atoi (substr coordinate_string 1 2) 1))
  378.                 (= beg_col (atoi (substr coordinate_string 4 2) 1))
  379.                 (= end_line (atoi (substr coordinate_string coord_position 2) 1))
  380.                 (= end_col (atoi (substr coordinate_string (+ coord_position 3) 2) 1))
  381.                 (drop_bookmark 5 "y")
  382.                 (top_of_window)
  383.                 (inq_position top_line NULL)
  384.                 (goto_bookmark 5)
  385.                 (+= beg_line top_line)
  386.                 (+= end_line top_line)
  387.                 (++ beg_col)
  388.                 (++ end_col)
  389.                 (move_abs beg_line beg_col)
  390.                 (drop_anchor 2)
  391.                 (move_abs end_line end_col)
  392.                 (return 1)
  393.             )
  394.         ;else
  395.             (return 0)
  396.         )
  397.     )
  398. )
  399. (macro coor
  400.     (
  401.         (switch dbr_dialect
  402.             1  NULL
  403.             2  NULL
  404.             6  NULL
  405.             7  NULL
  406.             11 NULL
  407.             13 NULL
  408.             12
  409.                 (_case_insert "^UX,^UY,^LX,^LY" 0 0)
  410.             3  NULL
  411.             4  NULL
  412.             5  NULL
  413.             8  NULL
  414.             9  NULL
  415.             10
  416.                 (_case_insert "^UX,^UY TO ^LX,^LY" 0 0)
  417.         )
  418.     )
  419. )
  420.