Daniel F. Savarese wrote:
> Should I add [the test program] to the awk examples in CVS?
It's a good example, and a good tool for Windows users w/o the strings
util (I say this because I now work within a Windows environment and I am
a bit shell shocked w/o all the tools I am familiar with). When I played
with it I only wanted/needed to pass the encoding in from the command
line, and not the pattern to search for. So here's a lil patch to try the
first param as the char encoding, and if it throws UnsupportedEncoding,
use this first param as a pattern instead. I also experienced
ArrayIndexOutOfBounds when setting the encoding to US-ASCII.
--
Dave
--- strings.java~ Thu Jan 24 23:18:02 2002
+++ strings.java Thu Jan 24 23:38:37 2002
@@ -46,22 +46,29 @@
Reader file = null;
if(args.length < 1) {
- System.err.println("usage: strings file [pattern] [encoding]");
+ System.err.println("usage: strings file [pattern|encoding] [encoding]");
return;
}
filename = args[0];
- if(args.length > 1)
+ if(args.length > 2) {
regex = args[1];
-
- if(args.length > 2)
encoding = args[2];
+ } else if(args.length > 1) {
+ encoding = args[1];
+ }
try {
+ InputStream fin = new FileInputStream(filename);
+ try {
+ file = new InputStreamReader(fin, encoding);
+ } catch(UnsupportedEncodingException e) {
+ file = new InputStreamReader(fin);
+ if(args.length > 1)
+ regex = args[1];
+ }
finder = new StringFinder(regex);
- file =
- new InputStreamReader(new FileInputStream(filename), encoding);
finder.search(file, new PrintWriter(new OutputStreamWriter(System.out)));
} catch(Exception e) {
e.printStackTrace();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>