Skip to content

Commit

Permalink
Version 1.5.1 - August 25, 1999
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Uziel committed Mar 7, 2014
1 parent 3612f44 commit 3352862
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
14 changes: 13 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Code Grep and Vi Grepped
cg, vg - tools for finding and modifying on keywords
Joshua Uziel <[email protected]> - August 18, 1999 - version 1.5
Joshua Uziel <[email protected]> - 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
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 1 addition & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ please email me at [email protected] ...
* 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
Expand Down
69 changes: 29 additions & 40 deletions cg.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cg - Code Grep - grep recursively through files and disiplay matches
# Copyright 1999 by Joshua Uziel <[email protected]> - version 1.5
# Copyright 1999 by Joshua Uziel <[email protected]> - version 1.5.1
#
# usage: cg [-i] [pattern] [files]
#
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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]$/) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions cgvgrc_example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion vg.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vg - Vi Grepped - edit a file at a line specified in a cg search.
# Copyright 1999 by Joshua Uziel <[email protected]> - version 1.5
# Copyright 1999 by Joshua Uziel <[email protected]> - version 1.5.1
#
# Usage: vg number
#
Expand Down Expand Up @@ -57,6 +57,8 @@
next;
} elsif ($key =~ /^BOLD_ALTERNATE$/) {
next;
} elsif ($key =~ /^SEARCH$/) {
next;
} elsif ($key =~ /^COLOR[S1-4]$/) {
next;
} else {
Expand Down

0 comments on commit 3352862

Please sign in to comment.