From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2365 invoked by alias); 29 Feb 2008 15:19:24 -0000 Received: (qmail 2338 invoked by uid 367); 29 Feb 2008 15:19:23 -0000 Date: Fri, 29 Feb 2008 15:19:00 -0000 Message-ID: <20080229151923.2323.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Split Glob from ftrace. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 8e6ab5488ff4b517582979b2fa0b8384ac6b0e09 X-Git-Newrev: a1f129abe0820ed5a7bd9f34842f4ebded1b9a97 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q1/txt/msg00287.txt.bz2 The branch, master has been updated via a1f129abe0820ed5a7bd9f34842f4ebded1b9a97 (commit) from 8e6ab5488ff4b517582979b2fa0b8384ac6b0e09 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit a1f129abe0820ed5a7bd9f34842f4ebded1b9a97 Author: Andrew Cagney Date: Fri Feb 29 10:15:29 2008 -0500 Split Glob from ftrace. frysk-core/frysk/bindir/ChangeLog 2008-02-29 Andrew Cagney * ftrace.java: Glob moved to frysk.util.Glob. frysk-core/frysk/util/ChangeLog 2008-02-29 Andrew Cagney * Glob.java: Extracted from frysk.bindir.ftrace. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/bindir/ChangeLog | 4 + frysk-core/frysk/bindir/ftrace.java | 87 +------------- frysk-core/frysk/util/ChangeLog | 4 + .../frysk/{bindir/fcatch.java => util/Glob.java} | 132 +++++++++++--------- 4 files changed, 82 insertions(+), 145 deletions(-) copy frysk-core/frysk/{bindir/fcatch.java => util/Glob.java} (51%) First 500 lines of diff: diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog index 1ba5299..b4b4092 100644 --- a/frysk-core/frysk/bindir/ChangeLog +++ b/frysk-core/frysk/bindir/ChangeLog @@ -1,3 +1,7 @@ +2008-02-29 Andrew Cagney + + * ftrace.java: Glob moved to frysk.util.Glob. + 2008-02-29 Sami Wagiaalla * TestFcatch.java (testFcatchFollowsForks): new test. diff --git a/frysk-core/frysk/bindir/ftrace.java b/frysk-core/frysk/bindir/ftrace.java index 06c7972..da886bb 100644 --- a/frysk-core/frysk/bindir/ftrace.java +++ b/frysk-core/frysk/bindir/ftrace.java @@ -51,8 +51,7 @@ import java.util.Map; import java.util.Set; import frysk.proc.Proc; import java.util.logging.*; -import java.util.regex.*; - +import java.util.regex.Pattern; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -69,92 +68,10 @@ import frysk.ftrace.TracePointOrigin; import frysk.ftrace.Symbol; import lib.dwfl.ElfSymbolVersion; - +import frysk.util.Glob; import gnu.classpath.tools.getopt.Option; import gnu.classpath.tools.getopt.OptionException; -class Glob -{ - private static int matchCharacterClass(String glob, int from) - throws PatternSyntaxException - { - int i = from + 2; - while (glob.charAt(++i) != ':' && i < glob.length()) - continue; - if (i >= glob.length() || glob.charAt(++i) != ']') - throw new PatternSyntaxException - ("Unmatched '['.", glob, from); - return i; - } - - private static int matchBrack(String glob, int from) - throws PatternSyntaxException - { - // On first character, both [ and ] are legal. But when [ is - // foolowed with :, it's character class. - int i = from + 1; - if (glob.charAt(i) == '[' && glob.charAt(i + 1) == ':') - i = matchCharacterClass(glob, i) + 1; - else - ++i; // skip any character, including [ or ] - boolean escape = false; - for (; i < glob.length(); ++i) { - char c = glob.charAt(i); - if (escape) { - ++i; - escape = false; - } - else if (c == '[' && glob.charAt(i + 1) == ':') - i = matchCharacterClass(glob, i); - else if (c == ']') - return i; - } - throw new PatternSyntaxException - ("Unmatched '" + glob.charAt(from) + "'.", glob, from); - } - - private static String toRegex(String glob) { - StringBuffer buf = new StringBuffer(); - boolean escape = false; - for(int i = 0; i < glob.length(); ++i) { - char c = glob.charAt(i); - if (escape) { - if (c == '\\') - buf.append("\\\\"); - else if (c == '*') - buf.append("\\*"); - else if (c == '?') - buf.append('?'); - else - buf.append('\\').append(c); - escape = false; - } - else { - if (c == '\\') - escape = true; - else if (c == '[') { - int j = matchBrack(glob, i); - buf.append(glob.substring(i, j+1)); - i = j; - } - else if (c == '*') - buf.append(".*"); - else if (c == '?') - buf.append('.'); - else if (c == '.') - buf.append("\\."); - else - buf.append(c); - } - } - return buf.toString(); - } - - public static Pattern compile(String glob) { - return Pattern.compile(toRegex(glob)); - } -} - abstract class Rule { final public boolean addition; diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog index b7ef1d7..a4de4ff 100644 --- a/frysk-core/frysk/util/ChangeLog +++ b/frysk-core/frysk/util/ChangeLog @@ -1,3 +1,7 @@ +2008-02-29 Andrew Cagney + + * Glob.java: Extracted from frysk.bindir.ftrace. + 2008-02-28 Sami Wagiaalla * ProcRunningUtil.java: Framework for all commandline diff --git a/frysk-core/frysk/bindir/fcatch.java b/frysk-core/frysk/util/Glob.java similarity index 51% copy from frysk-core/frysk/bindir/fcatch.java copy to frysk-core/frysk/util/Glob.java index ed5f6cf..8cd8bdc 100644 --- a/frysk-core/frysk/bindir/fcatch.java +++ b/frysk-core/frysk/util/Glob.java @@ -37,77 +37,89 @@ // version and license this file solely under the GPL without // exception. -package frysk.bindir; +package frysk.util; -import frysk.util.Util; -import frysk.util.CommandlineParser; -import frysk.util.FCatch; -import frysk.proc.Proc; -import gnu.classpath.tools.getopt.Option; -import gnu.classpath.tools.getopt.OptionException; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; -public class fcatch { +public class Glob { - FCatch catcher = new FCatch(); - - private boolean requestedPid = false; - - private static StringBuffer argString; - - private void run(String[] args) { - CommandlineParser parser = new CommandlineParser("fcatch") { - protected void validate() throws OptionException { - if (!requestedPid && argString == null) - throw new OptionException("no command or PID specified"); - } + private static int matchCharacterClass(String glob, int from) + throws PatternSyntaxException + { + int i = from + 2; + while (glob.charAt(++i) != ':' && i < glob.length()) + continue; + if (i >= glob.length() || glob.charAt(++i) != ']') + throw new PatternSyntaxException + ("Unmatched '['.", glob, from); + return i; + } - //@Override - public void parseCommand(Proc command) { - // FIXME: This concatinatin the string is unnecessary. - String[] line = command.getCmdLine(); - argString = new StringBuffer(line[0]); - for (int i = 1; i < line.length; i++) - argString.append(" ").append(line[i]); + private static int matchBrack(String glob, int from) + throws PatternSyntaxException + { + // On first character, both [ and ] are legal. But when [ is + // foolowed with :, it's character class. + int i = from + 1; + if (glob.charAt(i) == '[' && glob.charAt(i + 1) == ':') + i = matchCharacterClass(glob, i) + 1; + else + ++i; // skip any character, including [ or ] + boolean escape = false; + for (; i < glob.length(); ++i) { + char c = glob.charAt(i); + if (escape) { + ++i; + escape = false; } - - }; - addOptions(parser); - parser - .setHeader("Usage: fcatch [OPTIONS] -- PATH ARGS || fcatch [OPTIONS] PID"); - - parser.parse(args); - - if (argString != null) { - String[] cmd = argString.toString().split("\\s"); - - catcher.trace(cmd, requestedPid); + else if (c == '[' && glob.charAt(i + 1) == ':') + i = matchCharacterClass(glob, i); + else if (c == ']') + return i; } + throw new PatternSyntaxException + ("Unmatched '" + glob.charAt(from) + "'.", glob, from); } - public void addOptions(CommandlineParser p) { - p.add(new Option('p', "pid to trace", "PID") { - public void parsed(String arg) throws OptionException { - try { - int pid = Integer.parseInt(arg); - catcher.addProc(Util.getProcFromPid(pid)); - requestedPid = true; - if (argString == null) - argString = new StringBuffer(pid); - else - argString.append(" " + pid); - - } catch (NumberFormatException e) { - OptionException oe = new OptionException( - "couldn't parse pid: " + arg); - oe.initCause(e); - throw oe; + private static String toRegex(String glob) { + StringBuffer buf = new StringBuffer(); + boolean escape = false; + for(int i = 0; i < glob.length(); ++i) { + char c = glob.charAt(i); + if (escape) { + if (c == '\\') + buf.append("\\\\"); + else if (c == '*') + buf.append("\\*"); + else if (c == '?') + buf.append('?'); + else + buf.append('\\').append(c); + escape = false; + } + else { + if (c == '\\') + escape = true; + else if (c == '[') { + int j = matchBrack(glob, i); + buf.append(glob.substring(i, j+1)); + i = j; } + else if (c == '*') + buf.append(".*"); + else if (c == '?') + buf.append('.'); + else if (c == '.') + buf.append("\\."); + else + buf.append(c); } - }); + } + return buf.toString(); } - public static void main(String[] args) { - fcatch fc = new fcatch(); - fc.run(args); + public static Pattern compile(String glob) { + return Pattern.compile(toRegex(glob)); } } hooks/post-receive -- frysk system monitor/debugger