From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26182 invoked by alias); 15 Mar 2008 15:49:53 -0000 Received: (qmail 26155 invoked by uid 367); 15 Mar 2008 15:49:50 -0000 Date: Sat, 15 Mar 2008 15:49:00 -0000 Message-ID: <20080315154950.26140.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Parser for #!. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: c8c4519bd07e78dbf250681cf3d76a536cea69cc X-Git-Newrev: 903d1a983673aaae8ec74df389194c23d374648a 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/msg00377.txt.bz2 The branch, master has been updated via 903d1a983673aaae8ec74df389194c23d374648a (commit) from c8c4519bd07e78dbf250681cf3d76a536cea69cc (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 903d1a983673aaae8ec74df389194c23d374648a Author: Andrew Cagney Date: Fri Mar 14 19:28:13 2008 -0400 Parser for #!. frysk-core/frysk/proc/dead/ChangeLog 2008-03-14 Andrew Cagney * InterpreterFactory.java: New. * TestInterpreter.java: New. frysk-sys/frysk/rsl/ChangeLog 2008-03-14 Andrew Cagney * Log.java (log(String,String,String,String)): New. * Log.java (log(String,Object,String,int)): New. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/proc/dead/ChangeLog | 5 ++ .../{DeadProc.java => InterpreterFactory.java} | 68 +++++++++--------- .../frysk/proc/dead/TestInterpreter.java | 77 +++++++++++--------- frysk-sys/frysk/rsl/ChangeLog | 3 + frysk-sys/frysk/rsl/Log.java | 13 +++- 5 files changed, 97 insertions(+), 69 deletions(-) copy frysk-core/frysk/proc/dead/{DeadProc.java => InterpreterFactory.java} (63%) copy frysk-sys/frysk/sys/ptrace/TestRegisterSet.java => frysk-core/frysk/proc/dead/TestInterpreter.java (62%) First 500 lines of diff: diff --git a/frysk-core/frysk/proc/dead/ChangeLog b/frysk-core/frysk/proc/dead/ChangeLog index edab625..da6e811 100644 --- a/frysk-core/frysk/proc/dead/ChangeLog +++ b/frysk-core/frysk/proc/dead/ChangeLog @@ -1,3 +1,8 @@ +2008-03-14 Andrew Cagney + + * InterpreterFactory.java: New. + * TestInterpreter.java: New. + 2008-03-13 Stan Cox * LinuxExeFactory.java (findExe): Move to SysRoot.findExe. diff --git a/frysk-core/frysk/proc/dead/DeadProc.java b/frysk-core/frysk/proc/dead/InterpreterFactory.java similarity index 63% copy from frysk-core/frysk/proc/dead/DeadProc.java copy to frysk-core/frysk/proc/dead/InterpreterFactory.java index 727cd15..9514f2f 100644 --- a/frysk-core/frysk/proc/dead/DeadProc.java +++ b/frysk-core/frysk/proc/dead/InterpreterFactory.java @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2007, 2008 Red Hat Inc. +// Copyright 2008 Red Hat Inc. // // FRYSK is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by @@ -40,44 +40,44 @@ package frysk.proc.dead; import frysk.rsl.Log; -import frysk.proc.Proc; -import frysk.proc.Host; /** - * A dead Host/Proc/Task is characterised by its lack of state, and an - * in ability to respond to stateful requests such as add/remove - * observers. + * Given a String lifted from the start of a file and an ARGV, + * transform it into an ARGV suitable for invoking a #! interpreter. */ - -public abstract class DeadProc extends Proc { - private static final Log fine = Log.fine(DeadProc.class); - - DeadProc(Host host, Proc parent, int pid) { - super(host, parent, pid); - } +class InterpreterFactory { + private static final Log fine = Log.fine(InterpreterFactory.class); /** - * Return the current state as a string. + * Parse FILE (taken from the head of a shell file) and args + * transforming them into a script invocation. */ - protected String getStateFIXME() { - return "dead"; - } - - /** - * Request that the Proc's task list be refreshed using system - * tables. - */ - public void requestRefresh() { - fine.log(this, "requestRefresh"); - } - public void sendRefresh() { - fine.log(this, "sendRefresh"); - } - - protected void performDetach() { - fine.log(this, "performDetach"); - // XXX: Fake out for now. What kind of observers would you put - // on a core file? Might need a brain dead attached state in - // this scenario for compataibility. + static String[] parse(String file, String[] args) { + fine.log("file", file); + if (!file.startsWith("#!")) + return null; + String[] fields = file.replaceFirst("#! *", "").split(" +"); + fine.log("fields", fields); + String[] interpreter; + int start; + if (fields.length == 1) { + // #!interpreter + interpreter = new String[args.length + 1]; + interpreter[0] = fields[0]; + fine.log("interpreter", interpreter[0]); + start = 1; + } else { + // #!interpreter option + interpreter = new String[args.length + 2]; + interpreter[0] = fields[0]; + interpreter[1] = fields[1]; + fine.log("interpreter", interpreter[0], "options", interpreter[1]); + start = 2; + } + for (int i = 0; i < args.length; i++) { + interpreter[i + start] = args[i]; + fine.log("interpreter", i, "is", interpreter[i]); + } + return interpreter; } } diff --git a/frysk-sys/frysk/sys/ptrace/TestRegisterSet.java b/frysk-core/frysk/proc/dead/TestInterpreter.java similarity index 62% copy from frysk-sys/frysk/sys/ptrace/TestRegisterSet.java copy to frysk-core/frysk/proc/dead/TestInterpreter.java index 4d6b3d4..b90966c 100644 --- a/frysk-sys/frysk/sys/ptrace/TestRegisterSet.java +++ b/frysk-core/frysk/proc/dead/TestInterpreter.java @@ -1,11 +1,11 @@ // This file is part of the program FRYSK. -// -// Copyright 2008, Red Hat Inc. -// +// +// Copyright 2008 Red Hat Inc. +// // FRYSK is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; version 2 of the License. -// +// // FRYSK is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -37,46 +37,57 @@ // version and license this file solely under the GPL without // exception. -package frysk.sys.ptrace; +package frysk.proc.dead; -import frysk.sys.ProcessIdentifier; import frysk.junit.TestCase; -import frysk.testbed.TearDownProcess; -import frysk.testbed.ForkFactory; /** - * Trace a process. + * Test the interpreter parser. */ +public class TestInterpreter extends TestCase { -public class TestRegisterSet extends TestCase { - /** - * Rip down everything related to PID. - */ - public void tearDown() { - TearDownProcess.tearDown (); + public void testFileScript() { + assertEquals("args", + new String[] { "program", "script" }, + InterpreterFactory.parse("#!program", + new String[] { + "script" + })); } - private void verifyTransfer(String what, RegisterSet regs) { - if (unsupported(what, regs == null)) - return; - ProcessIdentifier pid = ForkFactory.attachedDaemon(); - // Read, write, read. - byte[] bytes = new byte[regs.length()]; - regs.transfer(pid, bytes, false); // read - byte old = bytes[0]; - bytes[0] = (byte) ~old; - regs.transfer(pid, bytes, true); // write - regs.transfer(pid, bytes, false); // read - assertEquals("modified", (byte)~old, bytes[0]); + public void testFileArgScript() { + assertEquals("args", + new String[] { "program", "arg", "script" }, + InterpreterFactory.parse("#!program arg", + new String[] { + "script" + })); } - public void testREGS() { - verifyTransfer("REGS", RegisterSet.REGS); + public void testFileScriptParam() { + assertEquals("args", + new String[] { "program", "script", "param" }, + InterpreterFactory.parse("#!program", + new String[] { + "script", "param" + })); } - public void testFPREGS() { - verifyTransfer("FPREGS", RegisterSet.FPREGS); + + public void testFileArgScriptParam() { + assertEquals("args", + new String[] { "program", "arg", "script", "param" }, + InterpreterFactory.parse("#!program arg", + new String[] { + "script", "param" + })); } - public void testFPXREGS() { - verifyTransfer("FPXREGS", RegisterSet.FPXREGS); + + public void testSpaces() { + assertEquals("args", + new String[] { "program", "arg", "script", "param" }, + InterpreterFactory.parse("#! program arg ", + new String[] { + "script", "param" + })); } } diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog index 948af70..71c9b4e 100644 --- a/frysk-sys/frysk/rsl/ChangeLog +++ b/frysk-sys/frysk/rsl/ChangeLog @@ -1,5 +1,8 @@ 2008-03-14 Andrew Cagney + * Log.java (log(String,String,String,String)): New. + * Log.java (log(String,Object,String,int)): New. + * TestLog.java (testDefault()): New. 2008-03-13 Andrew Cagney diff --git a/frysk-sys/frysk/rsl/Log.java b/frysk-sys/frysk/rsl/Log.java index ed3cae0..a522ad8 100644 --- a/frysk-sys/frysk/rsl/Log.java +++ b/frysk-sys/frysk/rsl/Log.java @@ -382,9 +382,9 @@ public final class Log { return; prefix().print(p1).print(p2).suffix(); } + // Disambiguate log(String,String) which could be either + // log(Object,String) or log(String,Object). public void log(String p1, String p2) { - // Needed to disambiguate log(String,String) which could be - // either log(Object,String) or log(String,Object). log(p1, (Object)p2); } @@ -416,11 +416,20 @@ public final class Log { return; prefix().print(p1).print(p2).print(p3).print(p4).suffix(); } + public void log(String p1, Object p2, String p3, int p4) { + if (!logging) + return; + prefix().print(p1).print(p2).print(p3).print(p4).suffix(); + } public void log(String p1, Object p2, String p3, Object p4) { if (!logging) return; prefix().print(p1).print(p2).print(p3).print(p4).suffix(); } + // Disambiguate log(String,String,String,String). + public void log(String p1, String p2, String p3, String p4) { + log(p1, (Object)p2, p3, (Object)p4); + } // static 6 parameters public void log(String p1, int p2, String p3, Object p4, String p5, int p6) { hooks/post-receive -- frysk system monitor/debugger