home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / qbnws204.arj / BRIEF.ZIP / ROUTINES.CB < prev    next >
Encoding:
Text File  |  1991-12-07  |  4.4 KB  |  183 lines

  1. /*
  2. ** ROUTINES.CB
  3. **
  4. ** This file contains macros that allow a programmer to select a
  5. ** BASIC SUB or FUNCTION procedure or label from a menu and then go to it.
  6. ** Lines with labels must have the : as the last character, a space or comment
  7. ** after it on the same line will cause the macro to skip that label.
  8. */
  9.  
  10. #include "dialog.h"
  11.  
  12. int    _r_line;
  13. int   mh_num_cols,
  14.       mh_max_width,
  15.       mh_line,
  16.       mh_menu_buf,
  17.       mh_flag;
  18.  
  19. string mh_name,
  20.        mh_ext,
  21.        mh_buf;
  22.  
  23.  
  24. void routines ()
  25. {
  26.     int    menu_buf,
  27.             old_buf_id,
  28.             max_width,
  29.             line,
  30.             loc,
  31.          s,
  32.          flag = 0;
  33.  
  34.     string    menu_line,
  35.                 routine_name;
  36.  
  37.     _r_line = 0;
  38.     save_position ();
  39.     top_of_buffer ();
  40.     old_buf_id = inq_buffer ();
  41.     menu_buf = create_buffer ("Labels by MH", NULL, 1);
  42.     message ("Scanning for routines...");
  43.  
  44.    while (search_fwd("{<{SUB }|{FUNCTION }}|{:>}"))
  45.       {
  46.          routine_name = trim(read());
  47.          if (routine_name == ":")
  48.             {
  49.                move_abs(0,1);
  50.                routine_name = trim(read());
  51.                move_rel(1);
  52.                flag=1;
  53.             }
  54.          else
  55.             {
  56.                if (upper(read(4)) == "SUB ")
  57.                   {
  58.                      loc = search_string ("(",routine_name) - 5;
  59.                      routine_name = substr(routine_name,5,loc);
  60.                      flag=1;
  61.                   }
  62.                else
  63.                   {
  64.                      loc = search_string ("(",routine_name) - 10;
  65.                      routine_name = substr(routine_name,10,loc);
  66.                      flag=1;
  67.                   }
  68.             }
  69.          if (flag == 1)
  70.             {
  71.                   _r_line++;
  72.                   message ("Scanning for routines [#%d]...", _r_line);
  73.  
  74.                   inq_position (line);
  75.  
  76.                   if (strlen (routine_name) > max_width)
  77.                       max_width = strlen (routine_name);
  78.  
  79.                   set_buffer (menu_buf);
  80.                   insert ("\n%s\t%d;", routine_name, line);
  81.                   set_buffer (old_buf_id);
  82.                flag = 0;
  83.               }
  84.          next_char();
  85.       }
  86.  
  87.     _r_line = 0;
  88.     restore_position ();
  89.     set_buffer (menu_buf);
  90.     inq_position (line);
  91.     top_of_buffer ();
  92.  
  93.     if (line > 1)
  94.         {
  95.         int    num_lines,
  96.                 num_cols;
  97.  
  98.         delete_line ();
  99.         tabs (80);
  100.  
  101.         inq_screen_size (num_lines, num_cols);
  102.  
  103.         if ((line += 3) > (num_lines - 5))
  104.             line = num_lines - 5;
  105.  
  106.         if ((max_width += 2) < 15)
  107.             max_width = 15;
  108.  
  109.         if (max_width >= num_cols - 3)
  110.             max_width = num_cols - 3;
  111.  
  112.         max_width = (max_width + 1) / 2;
  113.         num_cols = (num_cols + 1 ) / 2;
  114.  
  115.         set_buffer (old_buf_id);
  116.  
  117.       mh_num_cols = num_cols;
  118.       mh_max_width = max_width;
  119.       mh_line = line;
  120.       mh_menu_buf = menu_buf;
  121.       mh_flag = 1;
  122.  
  123.       inq_names(mh_name,mh_ext,mh_buf);
  124.  
  125.         _process_menu (num_cols - max_width, line, num_cols + max_width, 3, NULL, "", NULL, menu_buf, "_r_action", TRUE);
  126.  
  127.         if (_r_line)
  128.             goto_line (_r_line);
  129.         }
  130.     else
  131.         {
  132.         set_buffer (old_buf_id);
  133.         delete_buffer (menu_buf);
  134.         message ("No routines found.");
  135.       mh_flag = 0;
  136.         }
  137. }
  138.  
  139. /*
  140. **        _r_action:
  141. **
  142. **        This routine is called by the dialog manager when a routine is
  143. **    selected.
  144. */
  145.  
  146. int _r_action (int event_type, ...)
  147. {
  148.     string button_text;
  149.  
  150.     get_parm (0, event_type);
  151.  
  152.  
  153.     switch (event_type)
  154.         {
  155.         case DIALOG_PICK_MENU:
  156.         case DIALOG_F10:
  157.             {
  158.             get_parm (2, button_text);
  159.             _r_line = atoi (substr (button_text, rindex (button_text, "\t") + 1));
  160.             _dialog_esc ();
  161.             }
  162.         }
  163.     returns (TRUE);
  164. }
  165.  
  166. void rerout()
  167. {
  168.    string mh_n,mh_e,mh_b;
  169.  
  170.    inq_names(mh_n,mh_e,mh_b);
  171.  
  172.    if (mh_flag == 0 || mh_n != mh_name || mh_e != mh_ext || mh_b != mh_buf)
  173.       {
  174.          error ("No previous routines found.");
  175.       }
  176.    else
  177.       {
  178.          _process_menu (mh_num_cols - mh_max_width, mh_line, mh_num_cols + mh_max_width, 3, NULL, "", NULL, mh_menu_buf, "_r_action", TRUE);
  179.            if (_r_line)
  180.                goto_line (_r_line);
  181.       }
  182. }
  183.