home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w055 / 4.ddi / SOURCES.LIF / ROUTINES.PEL < prev    next >
Encoding:
Text File  |  1990-09-27  |  5.8 KB  |  201 lines

  1. # $Header:   P:/source/ppee/macros/routines.pev   1.8   24 Sep 1990 13:23:18   skipr  $
  2.  
  3. ##############################################################################
  4. #
  5. #           Sage Software - POLYTRON Division
  6. #             1700 NW 167th Place
  7. #               Beaverton, OR 97006
  8. #
  9. #   Copyright 1990, Sage Software, Inc.
  10. #
  11. #   Permission is hereby granted for licensed users of Sage Professional
  12. #   Editor and PolyAwk to copy and modify this source code for their own
  13. #   personal use.  These derivative works may be distributed only to other
  14. #   licensed Sage Professional Editor and PolyAwk users.  All other usage
  15. #   is prohibited without express written permission from Sage Software.
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   routines.pel  $: function name and string collection
  20.  
  21. ## routines()
  22. #
  23. #  Create a string of all the functions in the current edit buffer.
  24. #  This routines assumes the following format of each function declaration
  25. #
  26. #    For C files:
  27. #        [<type>] <function_name> ( [<parameters>] )
  28. #
  29. #    For PEL files
  30. #        [global|local] function <function_name> ( [<parameters>] ) [{]
  31. #
  32.  
  33. local    function_list = "";
  34. local    function_lines[]
  35. local    function_buffer_fname = ""
  36. local    function_total = 0
  37. local    function_buffer_size = 0;
  38.  
  39. global function routines() {
  40.     local    loc;
  41.     local    fun_name;
  42.     local    sflags = SEARCH_FORWARD+SEARCH_REGEX+SEARCH_MAXIMAL_MATCH
  43.     local    i;
  44.     local    ext = tolower(path_ext( buffer_filename ));
  45.  
  46.     # initialize dBase filename extension list
  47.     if ( !extensions_initialized ){
  48.         initialize_extensions()
  49.     }
  50.  
  51.     # check for known filename extension
  52.     if ( !(            \
  53.         ext == ".c"        \
  54.      || ext == ".pel"    \
  55.      || ext == ".pas"    \
  56.      || ext == ".bas"    \
  57.      || (buffer_filename ~ file_extensions["dbase"])    \
  58.      || (buffer_filename ~ file_extensions["clipper87"])    \
  59.      || (buffer_filename ~ file_extensions["clipper50"])    \
  60.      || (buffer_filename ~ file_extensions["force"]) )) {
  61.         beep();
  62.         return;
  63.     }
  64.  
  65.     if ( !((function_buffer_fname == buffer_filename) && 
  66.         (function_buffer_size == buffer_size)) ) {
  67.  
  68.         function_buffer_size = buffer_size;
  69.         function_buffer_fname = buffer_filename;
  70.         function_total = 0
  71.         function_list = "";
  72.         delete( function_lines );
  73.  
  74.         message("Scanning for routines...");
  75.         save_position();
  76.         goto_buffer_top();
  77.  
  78.         while (search( "^[a-zA-Z0-9_]", sflags)) {
  79.             loc = 0;
  80.             fun_name = trim( read_buffer() );
  81.  
  82.             if (ext == ".c") {
  83.                 if ((substr(fun_name,length(fun_name),1)==")")    \
  84.                  || (substr(fun_name,length(fun_name)-1,2)=="){")    \
  85.                  || (substr(fun_name,length(fun_name)-2,3)==") {")){
  86.                     loc = index( fun_name, "(" );
  87.                 }
  88.             } else if (ext == ".pel") {
  89.                 if (index( fun_name, "function" )){
  90.                     if (fun_name ~ /function[ \t]/ ){
  91.                         loc = index( fun_name, "(" );
  92.                     }
  93.                 }
  94.             } else if (ext == ".pas"){
  95.                 if ( index(fun_name,"function")        \
  96.                   || index(fun_name,"procedure")    \
  97.                   || index(fun_name,"FUNCTION")        \
  98.                   || index(fun_name,"PROCEDURE")){
  99.                     loc = index(fun_name,"(")
  100.                 }
  101.             } else if (ext == ".bas"){
  102.                 if ( index(fun_name,"FUNCTION")){
  103.                     if ( fun_name ~ /FUNCTION[ \t]/){
  104.                         loc = index(fun_name,"(")
  105.                     }
  106.                 }
  107.             } else if ( (buffer_filename ~ file_extensions["dbase"])    \
  108.                  || (buffer_filename ~ file_extensions["clipper87"])    \
  109.                  || (buffer_filename ~ file_extensions["clipper50"])    \
  110.                  || (buffer_filename ~ file_extensions["force"])) {
  111.                 if ( index(fun_name,"function")        \
  112.                   || index(fun_name,"procedure")    \
  113.                   || index(fun_name,"FUNCTION")        \
  114.                   || index(fun_name,"PROCEDURE")){
  115.                     if ( substr(fun_name,length(fun_name),1) == ")" ){
  116.                         loc = index(fun_name,"(")
  117.                     } else {
  118.                         loc = length(fun_name)+1
  119.                     }
  120.                 }
  121.             }
  122.  
  123.             if ( loc ) {
  124.                 # message("Scanning for routines [#%d]...", function_total + 1);
  125.  
  126.                 fun_name = substr(fun_name, 1, loc-1);
  127.                 if ( (loc = rindex( fun_name, " " )) ){
  128.                     fun_name = substr( fun_name, loc+1 );
  129.                 }
  130.                 function_list = function_list fun_name "\n"
  131.                 function_lines[function_total++] = current_line;
  132.             }
  133.             sflags = or( sflags, SEARCH_ADVANCE );
  134.         }
  135.  
  136.         restore_position(1);
  137.     }
  138.  
  139.     if (function_total) {
  140.         function_list = substr(function_list, 1, length( function_list ) - 1);
  141.         i = (function_total + 10 <= display_height) ? function_total : display_height - 10;
  142.         
  143.         if ((i = list_vertical( function_list, 20, 4, 20, i, 1 )) >= 0)
  144.             goto_pos( function_lines[ i-1 ], 1);
  145.         function_list = function_list "\n"
  146.     } else {
  147.         message("No routines found.");
  148.     }
  149. }
  150.  
  151.  
  152. ## grep()
  153. #
  154. #  given a string and an optional number or string matches, search for all
  155. #  occurrences of the string in the current buffer and display a list of the
  156. #  strings in a menu.
  157. #
  158. global function grep( str, numCount) {
  159.     local  sflags = or(search_flags, SEARCH_ONCE_PER_LINE+SEARCH_FORWARD)
  160.     local  i = 0;
  161.     local  menu_string = "";
  162.     local  menu_lines;
  163.  
  164.     numCount += 0;            # convert string to int
  165.  
  166.     if (numCount <= 0)
  167.         numCount = 0xFFFFFFF    # that ought to be enough searches
  168.  
  169.     message("Scanning for strings...");
  170.     save_position();
  171.     goto_buffer_top();
  172.  
  173.     while (numCount-- && search( str, sflags)) {
  174.         current_column = 1;
  175.         menu_string = sprintf( "%s%5d: %s\n",    \
  176.                 menu_string, current_line, read_buffer() )
  177.         menu_lines[i++] = current_line;
  178.         #message("Scanning for string [#%d]...", i );
  179.         sflags = or( sflags, SEARCH_ADVANCE );
  180.         if (!down())
  181.             break;
  182.         goto_bol();
  183.     }
  184.     restore_position(1);
  185.  
  186.     if (i) {
  187.         menu_string = substr(menu_string, 1, length( menu_string ) - 1);
  188.         i = (i + 10 <= display_height) ? i : display_height - 10;
  189.         
  190.         if ((i = list_vertical( menu_string, 10, 4, 60, i, 1 )) >= 0) {
  191.             current_line = menu_lines[ i-1 ]
  192.             current_column = 1;
  193.             search( str, SEARCH_FORWARD+SEARCH_ONCE_PER_LINE);
  194.         }
  195.     } else {
  196.         message("No matching strings found.");
  197.     }
  198. }
  199.  
  200.  
  201.