diff --git a/README b/README index cae7c68..34af485 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ Code Grep and Vi Grepped cg, vg - tools for finding and modifying on keywords -Joshua Uziel - August 18, 1999 - version 1.5 +Joshua Uziel - August 25, 1999 - version 1.5.1 All too often I need to dig through source code. Where something is defined, used, what files, etc. There's a great tool for doing @@ -70,6 +70,18 @@ of time. Feel free to send me comments or suggestions... ---------------- REVISION HISTORY ---------------- +August 25, 1999 +1.5.1 - Fixed a bug where if one and only one file was specified + to search through and it was an existing text file that it + would read that file rather than blindly assume it's a + search expression and do a huge recursive search. + + Cleaned up the finding code a bit. Now both the default + search and a user-specified search use the same &wanted + subroutine, with the search list being specified by a + $SEARCH variable. Along with this, the default search list + is user-defineable in the .cgvgrc file as well. + August 18, 1999 1.5 - The big change of this version is that now the searching is handled by Perl rather than by grep(1), egrep(1) and fgrep(1). diff --git a/TODO b/TODO index fd303fc..c5aa878 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,7 @@ please email me at juziel@home.com ... * Optimization! This program has to do a lot of searching, and any and all speed improvements need to be applied. -* Perhaps expand the .cgvgrc file's ability to also specify a per-user - default search path to use rather than all users having the same default. +* Perhaps improve error checking on the .cgvgrc file * Add options and arguments. Currently, the only option beyond the search pattern and search list is '-i', or case insensitive. Additional diff --git a/cg.pl b/cg.pl index ce1b988..ec97242 100644 --- a/cg.pl +++ b/cg.pl @@ -1,5 +1,5 @@ # cg - Code Grep - grep recursively through files and disiplay matches -# Copyright 1999 by Joshua Uziel - version 1.5 +# Copyright 1999 by Joshua Uziel - version 1.5.1 # # usage: cg [-i] [pattern] [files] # @@ -40,48 +40,25 @@ use File::Find; require "find.pl"; + # Search for wanted entries for perl internal find subroutine. sub wanted { - # If there isn't a specified thing to search for, use the default. - unless ($nondash) { - if ( - - # Skip things that aren't normal files (like directories). - (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && - - /^.*\.[chs]$/ # *.c, *.h and *.s - || - /^.*\.cc$/ # *.cc - || - /^Make.*$/ # Make* - || - /^.*\.p[lm]$/ # *.pl and *.pm - || - /^.*\.java$/ # *.java - || - /^.*\..*sh$/ # *.*sh - || - /^.*\.idl$/ # *.idl - - ) { - # Kill the leading ./ and push it on the @LIST - $name =~ s/^\.\///; - push @LIST, $name; - } - } else { - # Skip things that aren't normal files (like directories). - if ((($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _) { + # Skip things that aren't normal files (like directories). + if ((($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _) { - # Kill the leading ./ and push it on the @LIST - $name =~ s/^\.\///; + # Kill the leading ./ and push it on the @LIST + $name =~ s/^\.\///; - # Push onto the list if we have a match - push @LIST, $name if ($name =~ /$SEARCH/); - } + # Push onto the list if we have a match + push @LIST, $name if ($name =~ /$SEARCH/o); } } +# Default search list: +# Make* *.c *.h *.s *.cc *.pl *.pm *.java *.*sh *.idl +$SEARCH = '(^Make.*$|^.*\.([chs]|cc|p[lm]|java|.*sh|idl)$)'; + # Where to store the data $LOGFILE = "$ENV{'HOME'}/.cglast"; @@ -145,6 +122,9 @@ sub wanted { $BOLD_ALTERNATE=$value; } elsif ($key =~ /^EDITOR$/) { $EDITOR=$value; + } elsif ($key =~ /^SEARCH$/) { + print "$value\n"; + $SEARCH=$value; # Change colors from the defaults. } elsif ($key =~ /^COLOR[1-4]$/) { @@ -197,9 +177,18 @@ sub wanted { # If we have a file list of size 1, use it as a search pattern # for files automatically. if ($nondash == 1) { - $SEARCH = $FILELIST[0]; - $SEARCH =~ s/\./\\\./g; # . --> \. - $SEARCH =~ s/\*/\.\*/g; # * --> .* + + # Unless that one thing is a file, in which case we just + # search it. + if (-T $FILELIST[0]) { + die "error: File $FILELIST[0] not readable.\n" + unless (-r $FILELIST[0]); + $nondash++; # Psych out the $nondash check later. + } else { + $SEARCH = $FILELIST[0]; + $SEARCH =~ s/\./\\\./g; # . --> \. + $SEARCH =~ s/\*/\.\*/g; # * --> .* + } } # Check our arguments @@ -232,7 +221,7 @@ sub wanted { @LIST = grep !/$EXCLUDE/, @LIST; # Special case of no matching files, we die with an error. - die "error: No matching files found.\n" if ($#LIST <= 0); + die "error: No matching files found.\n" if ($#LIST < 0); # Search through the list of files and generate the $LOGFILE foreach $file (@LIST) { @@ -256,7 +245,7 @@ sub wanted { # differently from how it's stored to make it easier on the human eyes. # Attempt to get the number of columns from an "stty -a" -if ($COL = `stty -a 2> /dev/null | grep column 2> /dev/null`) { +if ($COL = `stty -a | grep column 2> /dev/null`) { # Strip out the value with the string "column" @TMP = split ';', $COL; diff --git a/cgvgrc_example b/cgvgrc_example index b84cf52..4c6afd0 100644 --- a/cgvgrc_example +++ b/cgvgrc_example @@ -7,6 +7,9 @@ # default editor. EDITOR=vi +# Default list of files to search through +SEARCH=(^Make.*$|^.*\.([chs]|cc|p[lm]|java|.*sh|idl)$) + # Colors on or off (1 or 0) COLORS=1 diff --git a/vg.pl b/vg.pl index e55254f..605a880 100644 --- a/vg.pl +++ b/vg.pl @@ -1,5 +1,5 @@ # vg - Vi Grepped - edit a file at a line specified in a cg search. -# Copyright 1999 by Joshua Uziel - version 1.5 +# Copyright 1999 by Joshua Uziel - version 1.5.1 # # Usage: vg number # @@ -57,6 +57,8 @@ next; } elsif ($key =~ /^BOLD_ALTERNATE$/) { next; + } elsif ($key =~ /^SEARCH$/) { + next; } elsif ($key =~ /^COLOR[S1-4]$/) { next; } else {