diff --git a/ChangeLog b/ChangeLog index c075b6c..cd62beb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,15 @@ ---------------- Change Log ---------------- +August 28, 2014 +1.6.3 - Modernizing fixes + + Well, if you thought it was a while since the last release, here's an + even bigger gap. This time, it's just a few quick changes to fix things + up for contemporary use. Changes in this release: + * Newer versions of Perl do away with find.pl -- switch to File::Find + * Add support for Python (*.py) and excluding the .git directory + March 13, 2002 1.6.2 - Minor cleanup @@ -21,7 +30,7 @@ March 13, 2002 * More exact matching on checking that an editor is in the $PATH. August 29, 2000 -1.6.1 - Pretty much added two things... +1.6.1 - Pretty much added two things... * "Colon mode"... which prints out something like this: @@ -138,8 +147,8 @@ August 15, 1999 July 7, 1999 1.3 - Same as the last version, except now colors are supported - in cg. There are the options $BOLD, $BOLD_ALTERNATE and - $COLOR to be set to 1 (on) or 0 (off) if you do or don't + in cg. There are the options $BOLD, $BOLD_ALTERNATE and + $COLOR to be set to 1 (on) or 0 (off) if you do or don't want these feature. $COLOR is needed for the $BOLD options, and really you should select only one or neither of the two $BOLD options. Colors only work when displaying @@ -181,8 +190,8 @@ June 28, 1999 and cut an argument... none of the flexibility is lost, and it's actually advisable to avoid the mode where you specify the files to search for as a huge overhead reduction in the - program's runtime. The use of arguments for find(1) chosen - are also done so that non-GNU versions of it can be used, and + program's runtime. The use of arguments for find(1) chosen + are also done so that non-GNU versions of it can be used, and I use Perl to do some cleanup. The vg script has also been modified to support both "vim" diff --git a/README b/README index e18bf9f..7b5d3af 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 - March 13, 2002 - version 1.6.2 +Joshua Uziel - August 28, 2014 - version 1.6.3 [Note: the below is historical... SCO released cscope under a BSD license several months ago (http://cscope.sourceforge.net/), which @@ -18,8 +18,8 @@ is defined... not wherever it is used, which makes it frustrating when, for example, you're at the definition of a function and instead want to see who and what use that function. -So, as a quick hack, mostly for myself, I started writing up some -perl scripts (I consciously chose perl, but considered other +So, as a quick hack, mostly for myself, I started writing up some +perl scripts (I consciously chose perl, but considered other languages first). One script, "cg", does the equivalent of a find and grep, storing matches and then displaying it in a human-friendly manner. Run it like so: @@ -56,7 +56,7 @@ as well as a built-in pager. The pager allows for colors while paging (that "more" or "less" can't deal with), as well as allowing one to go back or launch an editor directly using our other script... -The other script is called "vg" and opens an editor on what has been +The other script is called "vg" and opens an editor on what has been grepped (most editors work). So remember that count? All you have to do is run "vg count" and it'll fire off a editor in that file and at that line number. So, in our example, running "vg 1" would diff --git a/cg.in b/cg.in index 1636931..7140262 100644 --- a/cg.in +++ b/cg.in @@ -39,10 +39,11 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use POSIX; -require "find.pl"; # Include our general functions and variables. use File::Basename; +use File::Find (); +*name = *File::Find::name; BEGIN { $prefix = "@prefix@" } use lib dirname($0), "@datadir@/cgvg"; @@ -168,7 +169,7 @@ $LOGFILE = $LASTLOG if ($uselast); #--------------------------------------------------------------------------# # -# Clean up code. We generate a bunch of log files over time, and we +# Clean up code. We generate a bunch of log files over time, and we # want to clean 'em up if we don't need them. Search for files for the # present host to clean up by seeing if the shell that ran them possibly # still exists. @@ -221,12 +222,12 @@ sub get_number_of_columns_rows { $ROW =~ s/\D*(\d+)\D*/$1/; # For Cols, Something's weird if 0, and we want more than 40. - die "Error: Zero value found for number of columns.\n" + die "Error: Zero value found for number of columns.\n" if ($COL == 0); die "Error: Too few columns to work with.\n" if ($COL < 40); # For Rows, Something's weird if 0, and we want more than 4. - die "Error: Zero value found for number of rows.\n" + die "Error: Zero value found for number of rows.\n" if ($ROW == 0); die "Error: Too few rows to work with.\n" if ($ROW < 4); @@ -257,6 +258,12 @@ sub wanted { } } +# +# File::Find helper +# +sub find { + &File::Find::find(\&wanted, @_); +} # # Generate the list of files to search through. @@ -333,7 +340,7 @@ sub read_log { chomp $in; # Split and strip the first few colons, leave the rest. - ($rec[$i]->{num}, $rec[$i]->{file}, $rec[$i]->{line}, + ($rec[$i]->{num}, $rec[$i]->{file}, $rec[$i]->{line}, $rec[$i]->{str}) = split /:/, $in, 4; # Remove all leading whitespace. @@ -342,7 +349,7 @@ sub read_log { # Swap tabs for 8 spaces $rec[$i]->{str} =~ s/\t/ /g; - # If we have a longer length for this field, save it. + # If we have a longer length for this field, save it. if ($COLON) { # Store it as filename length in colon mode $tmp = length $rec[$i]->{file}; @@ -395,12 +402,12 @@ sub display_read_log { # Print the properly justified first 3 fields. print "\e[$b[1];${c[1]}m" if ($COLORS); - printf "%${mnum}s ", $rec[$i]->{num}; + printf "%${mnum}s ", $rec[$i]->{num}; print "\e[0m" if ($COLORS); if ($COLON) { print "\e[$b[2];${c[2]}m" if ($COLORS); - printf "%s", $rec[$i]->{file}; + printf "%s", $rec[$i]->{file}; print "\e[0m" if ($COLORS); print ":"; @@ -415,7 +422,7 @@ sub display_read_log { print " " x $colnumsp; } else { print "\e[$b[2];${c[2]}m" if ($COLORS); - printf "%-${mfile}s ", $rec[$i]->{file}; + printf "%-${mfile}s ", $rec[$i]->{file}; print "\e[0m" if ($COLORS); print "\e[$b[3];${c[3]}m" if ($COLORS); diff --git a/cgvg-common.pl b/cgvg-common.pl index 9bd57f9..1b1af43 100644 --- a/cgvg-common.pl +++ b/cgvg-common.pl @@ -1,5 +1,5 @@ # cgvg-common.pl - common variables and functions to cgvg -# Copyright 2000-2002 by Joshua Uziel - version 1.6.2 +# Copyright 2000-2014 by Joshua Uziel - version 1.6.3 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -30,12 +30,11 @@ $RCFILE = "$ENV{'HOME'}/.cgvgrc"; # Default search list: -# Make* *.c *.h *.s *.cc *.pl *.pm *.java *.*sh *.idl -$SEARCH = '(^Make.*$|^.*\.([chslySC]|cc|p[lm]|java|php|.*sh|idl)$)'; - +# Make* *.c *.h *.s *.cc *.pl *.pm *.py *.java *.*sh *.idl +$SEARCH = '(^Make.*$|^.*\.([chslySC]|cc|p[lmy]|java|php|.*sh|idl)$)'; # List of files and strings to exclude from our search. -$EXCLUDE = "SCCS|RCS|tags|\.make\.state"; +$EXCLUDE = "SCCS|RCS|tags|\.make\.state|\.git"; # Oldest age (in days) before we delete. $AGE = 30; @@ -88,7 +87,7 @@ # Set b (bold) and c (color) values for printing for ($i=1; $i<=5; $i++) { $c[$i] = $colors{$color[$i]}; - $b[$i] = ($color[$i] =~ /^b_/) ? 1 : 0; + $b[$i] = ($color[$i] =~ /^b_/) ? 1 : 0; } # Code to parse the RCFILE entries @@ -129,7 +128,7 @@ sub parse_rcfile { } elsif ($key =~ /^COLOR[1-5]$/) { # See that a legal color has been given - if ($value =~ + if ($value =~ /^(black|red|green|yellow|blue|magenta|cyan|white|\ |b_black|b_red|b_green|b_yellow|b_blue|b_magenta|b_cyan|b_white)$/) { $coltmp = $key; diff --git a/configure b/configure index e31125c..b2a3ef6 100755 --- a/configure +++ b/configure @@ -692,7 +692,7 @@ fi PACKAGE=cgvg -VERSION=1.6.2 +VERSION=1.6.3 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index 31a58ab..13a2cbe 100644 --- a/configure.in +++ b/configure.in @@ -5,7 +5,7 @@ dnl GNU Autoconf file AC_INIT(cg.in) -AM_INIT_AUTOMAKE(cgvg, 1.6.2) +AM_INIT_AUTOMAKE(cgvg, 1.6.3) AC_PATH_PROGS(PERL, perl5 perl perl5.005 perl5.004, "") if test -z "$PERL"; then diff --git a/vg.in b/vg.in index ec8d101..5ab895f 100644 --- a/vg.in +++ b/vg.in @@ -44,14 +44,14 @@ die "Error: Editor $EDITOR isn't in your path.\n" if ($no_editor != 0); # One argument can be numerical only. if ($#ARGV == 0) { $num = $ARGV[0]; - die "Error: Non-numerical argument.\n" + die "Error: Non-numerical argument.\n" unless (($num =~ /\d+/) && ($num !~ /\D+/)); # Two arguments must be '-l' and then a number. } elsif ($#ARGV == 1) { die "Error: Unknown option.\n" unless ($ARGV[0] == '-l'); $num = $ARGV[1]; - die "Error: Non-numerical argument.\n" + die "Error: Non-numerical argument.\n" unless (($num =~ /\d+/) && ($num !~ /\D+/)); $LOGFILE = $LASTLOG;