-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joshua Uziel
committed
Mar 7, 2014
1 parent
3612f44
commit 3352862
Showing
5 changed files
with
49 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
# | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# | ||
|
@@ -57,6 +57,8 @@ | |
next; | ||
} elsif ($key =~ /^BOLD_ALTERNATE$/) { | ||
next; | ||
} elsif ($key =~ /^SEARCH$/) { | ||
next; | ||
} elsif ($key =~ /^COLOR[S1-4]$/) { | ||
next; | ||
} else { | ||
|