home *** CD-ROM | disk | FTP | other *** search
- # $Header: P:/source/ppee/macros/routines.pev 1.8 24 Sep 1990 13:23:18 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: routines.pel $: function name and string collection
-
- ## routines()
- #
- # Create a string of all the functions in the current edit buffer.
- # This routines assumes the following format of each function declaration
- #
- # For C files:
- # [<type>] <function_name> ( [<parameters>] )
- #
- # For PEL files
- # [global|local] function <function_name> ( [<parameters>] ) [{]
- #
-
- local function_list = "";
- local function_lines[]
- local function_buffer_fname = ""
- local function_total = 0
- local function_buffer_size = 0;
-
- global function routines() {
- local loc;
- local fun_name;
- local sflags = SEARCH_FORWARD+SEARCH_REGEX+SEARCH_MAXIMAL_MATCH
- local i;
- local ext = tolower(path_ext( buffer_filename ));
-
- # initialize dBase filename extension list
- if ( !extensions_initialized ){
- initialize_extensions()
- }
-
- # check for known filename extension
- if ( !( \
- ext == ".c" \
- || ext == ".pel" \
- || ext == ".pas" \
- || ext == ".bas" \
- || (buffer_filename ~ file_extensions["dbase"]) \
- || (buffer_filename ~ file_extensions["clipper87"]) \
- || (buffer_filename ~ file_extensions["clipper50"]) \
- || (buffer_filename ~ file_extensions["force"]) )) {
- beep();
- return;
- }
-
- if ( !((function_buffer_fname == buffer_filename) &&
- (function_buffer_size == buffer_size)) ) {
-
- function_buffer_size = buffer_size;
- function_buffer_fname = buffer_filename;
- function_total = 0
- function_list = "";
- delete( function_lines );
-
- message("Scanning for routines...");
- save_position();
- goto_buffer_top();
-
- while (search( "^[a-zA-Z0-9_]", sflags)) {
- loc = 0;
- fun_name = trim( read_buffer() );
-
- if (ext == ".c") {
- if ((substr(fun_name,length(fun_name),1)==")") \
- || (substr(fun_name,length(fun_name)-1,2)=="){") \
- || (substr(fun_name,length(fun_name)-2,3)==") {")){
- loc = index( fun_name, "(" );
- }
- } else if (ext == ".pel") {
- if (index( fun_name, "function" )){
- if (fun_name ~ /function[ \t]/ ){
- loc = index( fun_name, "(" );
- }
- }
- } else if (ext == ".pas"){
- if ( index(fun_name,"function") \
- || index(fun_name,"procedure") \
- || index(fun_name,"FUNCTION") \
- || index(fun_name,"PROCEDURE")){
- loc = index(fun_name,"(")
- }
- } else if (ext == ".bas"){
- if ( index(fun_name,"FUNCTION")){
- if ( fun_name ~ /FUNCTION[ \t]/){
- loc = index(fun_name,"(")
- }
- }
- } else if ( (buffer_filename ~ file_extensions["dbase"]) \
- || (buffer_filename ~ file_extensions["clipper87"]) \
- || (buffer_filename ~ file_extensions["clipper50"]) \
- || (buffer_filename ~ file_extensions["force"])) {
- if ( index(fun_name,"function") \
- || index(fun_name,"procedure") \
- || index(fun_name,"FUNCTION") \
- || index(fun_name,"PROCEDURE")){
- if ( substr(fun_name,length(fun_name),1) == ")" ){
- loc = index(fun_name,"(")
- } else {
- loc = length(fun_name)+1
- }
- }
- }
-
- if ( loc ) {
- # message("Scanning for routines [#%d]...", function_total + 1);
-
- fun_name = substr(fun_name, 1, loc-1);
- if ( (loc = rindex( fun_name, " " )) ){
- fun_name = substr( fun_name, loc+1 );
- }
- function_list = function_list fun_name "\n"
- function_lines[function_total++] = current_line;
- }
- sflags = or( sflags, SEARCH_ADVANCE );
- }
-
- restore_position(1);
- }
-
- if (function_total) {
- function_list = substr(function_list, 1, length( function_list ) - 1);
- i = (function_total + 10 <= display_height) ? function_total : display_height - 10;
-
- if ((i = list_vertical( function_list, 20, 4, 20, i, 1 )) >= 0)
- goto_pos( function_lines[ i-1 ], 1);
- function_list = function_list "\n"
- } else {
- message("No routines found.");
- }
- }
-
-
- ## grep()
- #
- # given a string and an optional number or string matches, search for all
- # occurrences of the string in the current buffer and display a list of the
- # strings in a menu.
- #
- global function grep( str, numCount) {
- local sflags = or(search_flags, SEARCH_ONCE_PER_LINE+SEARCH_FORWARD)
- local i = 0;
- local menu_string = "";
- local menu_lines;
-
- numCount += 0; # convert string to int
-
- if (numCount <= 0)
- numCount = 0xFFFFFFF # that ought to be enough searches
-
- message("Scanning for strings...");
- save_position();
- goto_buffer_top();
-
- while (numCount-- && search( str, sflags)) {
- current_column = 1;
- menu_string = sprintf( "%s%5d: %s\n", \
- menu_string, current_line, read_buffer() )
- menu_lines[i++] = current_line;
- #message("Scanning for string [#%d]...", i );
- sflags = or( sflags, SEARCH_ADVANCE );
- if (!down())
- break;
- goto_bol();
- }
- restore_position(1);
-
- if (i) {
- menu_string = substr(menu_string, 1, length( menu_string ) - 1);
- i = (i + 10 <= display_height) ? i : display_height - 10;
-
- if ((i = list_vertical( menu_string, 10, 4, 60, i, 1 )) >= 0) {
- current_line = menu_lines[ i-1 ]
- current_column = 1;
- search( str, SEARCH_FORWARD+SEARCH_ONCE_PER_LINE);
- }
- } else {
- message("No matching strings found.");
- }
- }
-
-
-