home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / wp / bmacs.zip / BMACS.DOC next >
Text File  |  1988-02-06  |  4KB  |  149 lines

  1. ;BRIEF macros by Gary Gruber
  2. ;
  3. ;Here are a couple of macros I use regularly to make screen drawing 
  4. ;a breeze. PLUS and MINUS increment or decrement the numeric value of 
  5. ;an @ SAY command's row and column coordinates. Place the cursor on the
  6. ;leftmost digit of the number to be converted. I leave the ASSIGN-TO-KEY
  7. ;statements up to you. These are great for moving windows around on screen
  8. ;without contantly typing in new numbers for a long series of @ SAY's.
  9. ;
  10. ;CENTER_LINE reads all the chars between two sets of double quotation marks 
  11. ;(doesn't matter where on the line your cursor is) and then moves back to 
  12. ;the column coordinate and inserts the appropriate coordinate to center
  13. ;the line on the screen display.
  14. ;
  15. ;Example:  @ 2, say "This is the string to be centered."
  16. ;Don't enter the column coordinate. Call CENTER_LINE.
  17. ;
  18. ;LINE_LENGTH displays the length of the string between two sets of double
  19. ;quotation marks. I use this one when I need to erase a line with an
  20. ;@ x,y, say SPACE(?) statement.
  21. ;
  22. #define COMMA ","
  23. #define SPACE " "
  24.  
  25. (macro plus
  26.  
  27.    (
  28.    (int int1 int2 num_digits new_num)
  29.    (= num_digits 2)
  30.    (string digit1 digit2 new_str)
  31.    (save_position)
  32.    (drop_anchor 1)
  33.    (= digit1 (read 1))
  34.    (next_char)
  35.    (= digit2 (read 1))
  36.  
  37.    (if (|| (== digit2 SPACE) (== digit2 COMMA))
  38.       (= num_digits 1)
  39.     )
  40.  
  41.     (= int1 (atoi digit1 1))
  42.  
  43.     (if (== num_digits 1)
  44.       (
  45.          (prev_char)
  46.          (= new_num (++ int1))
  47.        )
  48.     )
  49.     
  50.     (if (== num_digits 2)
  51.         (
  52.            (= int2 (atoi digit2 1))
  53.            (= new_num (+ (*= int1 10) int2))
  54.            (++ new_num) 
  55.         )
  56.       )
  57.  
  58.     (sprintf new_str "%d" new_num)
  59.     (delete_block)    
  60.     (insert new_str)
  61.     (restore_position)
  62.    )
  63. )
  64.  
  65.  
  66. #define COMMA ","
  67. #define SPACE " "
  68.  
  69. (macro minus
  70.    (
  71.    (int int1 int2 num_digits new_num)
  72.    (= num_digits 2)
  73.    (string digit1 digit2 new_str)
  74.    (save_position)
  75.    (drop_anchor 1)
  76.    (= digit1 (read 1))
  77.    (next_char)
  78.    (= digit2 (read 1))
  79.  
  80.    (if (|| (== digit2 SPACE) (== digit2 COMMA))
  81.       (= num_digits 1)
  82.     )
  83.  
  84.     (= int1 (atoi digit1 1))
  85.  
  86.     (if (== num_digits 1)
  87.       (
  88.          (prev_char)
  89.          (= new_num (-- int1))
  90.        )
  91.     )
  92.     
  93.     (if (== num_digits 2)
  94.         (
  95.            (= int2 (atoi digit2 1))
  96.            (= new_num (+ (*= int1 10) int2))
  97.            (-- new_num)
  98.         )
  99.       )
  100.  
  101.     (sprintf new_str "%d" new_num)
  102.     (delete_block)    
  103.     (insert new_str)
  104.     (restore_position)
  105.     (down)
  106.     
  107.    )
  108. )
  109.  
  110.  
  111. (macro center_line
  112.    (
  113.       (int col_start col_end line_len center_pos diff real_len inter_pos)
  114.       (beginning_of_line)
  115.       (search_fwd "\"")
  116.       (next_char)
  117.       (inq_position NULL col_start)
  118.       (save_position)
  119.       (end_of_line)
  120.       (inq_position NULL col_end)
  121.       (restore_position)
  122.       (= diff (- col_end col_start))
  123.       (= real_len ( - diff 2))
  124.       (= inter_pos ( - 80 real_len))
  125.       (= center_pos ( / inter_pos 2))
  126.       (search_back ",")
  127.       (next_char)
  128.       (string output)
  129.       (sprintf output "%d" center_pos)
  130.       (insert output)
  131.    )
  132. )
  133.  
  134. (macro line_length
  135.    (
  136.       (save_position)
  137.       (int col_start col_end line_len)
  138.       (beginning_of_line)
  139.       (search_fwd "\"")
  140.       (next_char)
  141.       (inq_position NULL col_start)
  142.       (search_fwd "\"")
  143.       (inq_position NULL col_end)
  144.       (restore_position)
  145.       (message "Line length =  %d" (- col_end col_start))
  146.    )
  147. )
  148.  
  149.