Change 117522 by jkristian@jkristian-home on 2003/11/11 00:46:57

	Renamed UnixStyleFilter to UnixCommand.
	Improved.

Affected files ...

... //users/jkristian/lib/UnixCommandResources.properties#1 branch
... //users/jkristian/lib/UnixStyleFilterResources.properties#2 delete
... //users/jkristian/lib/p4d2pResources.properties#3 edit
... //users/jkristian/src/UnixCommand.java#1 add
... //users/jkristian/src/UnixStyleFilter.java#3 delete
... //users/jkristian/src/p4d2p.java#3 edit

Differences ...

==== //users/jkristian/lib/p4d2pResources.properties#3 (text) ====

48a49
> diff.default: converting default diff (not recommended for `patch`)\n

==== //users/jkristian/src/p4d2p.java#3 (text) ====

2,3d1
< import java.io.BufferedReader;
< import java.io.InputStreamReader;
5d2
< import java.io.PushbackReader;
20c17
<         UnixStyleFilter filter = new UnixStyleFilter(p4d2p.class, "hi::o:p:v", ARGV);
---
>         UnixCommand command = new UnixCommand(p4d2p.class, "hi::o:p:v", ARGV);
22,24c19,21
<             Properties options = filter.getOptions();
<             if (options.getProperty("h") != null) {
<                 filter.writeError(filter.getHelp());
---
>             Properties options = command.getOptions();
>             if (options.get("h") != null) {
>                 command.writeError(command.getHelp());
26,29c23,26
<                 filter.setEditInPlace(options.getProperty("i"));
<                 LineWriter self = new p4d2p(filter, filter.getOutputWriter());
<                 while (filter.getFile()) {
<                     Copier.copyAll(filter.getInputLineReader(), self);
---
>                 command.setEditInPlace(options.getProperty("i"));
>                 LineWriter self = new p4d2p(command);
>                 while (command.getFile()) {
>                     Copier.copyAll(command.getInputLineReader(), self);
34c31
<             filter.flush();
---
>             command.flush();
38,42c35,50
<     private String oldFile = null;
<     private String oldNote;
<     private String newFile;
<     private String newNote;
<     private List movedFiles = new ArrayList();
---
>     protected p4d2p(UnixCommand command) throws IOException {
>         this.command = command;
>         this.options = command.getOptions();
>         this.verbose = (options.get("v") != null);
>         this.out = command.getOutputWriter();
>     }
> 
>     protected static DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); // ISO 8601
>     protected static String epoch = timeFormat.format(new Date(0));
> 
>     protected String now = timeFormat.format(new Date());
>     protected UnixCommand command;
>     protected Properties options;
>     protected boolean verbose;
>     protected Writer out;
>     protected Writer err;
44,48c52,56
<     private static final Pattern P4_DESCRIBE_MOVE   = Pattern.compile("^\\.\\.\\. (//.+?\\#\\d+ (add|branch|delete))$", Pattern.MULTILINE);
<     private static final Pattern P4_MOVED_FILE      = Pattern.compile("//(.+?)(\\#\\d+) (\\w*)$", Pattern.MULTILINE);
<     private static final Pattern P4_DESCRIBE_HEADER = Pattern.compile("^==== //(.+?)(\\#\\d+) .*?====( \\(.+\\))?$", Pattern.MULTILINE);
<     private static final Pattern P4_DIFF_HEADER     = Pattern.compile("^==== //(.+?)(\\#\\d+) +- +(.+?) +====( \\(.+\\))?$", Pattern.MULTILINE);
<     private static final Pattern P4_DIFF2_HEADER    = Pattern.compile("^==== //(.+?)(\\#\\d+) +\\(.+?\\) +- +(.+?)(\\#\\d+) +\\(.+?\\) +==== +\\w+$", Pattern.MULTILINE);
---
>     protected String oldFile = null;
>     protected String oldNote;
>     protected String newFile;
>     protected String newNote;
>     protected List movedFiles = new ArrayList();
50,53c58,67
<     private static final Pattern VERSION = Pattern.compile("\\#(\\d+)");
<     private static final Pattern UNIFIED_DIFF = Pattern.compile("^\\@\\@\\s.*\\s\\@\\@$", Pattern.MULTILINE);
<     private static final Pattern CONTEXT_DIFF = Pattern.compile("^\\*+$", Pattern.MULTILINE);
<     private static final Pattern DEFAULT_DIFF = Pattern.compile("^\\d+(,\\d+)?[acd]\\d+", Pattern.MULTILINE);
---
>     protected static Pattern P4_DESCRIBE_MOVE   = Pattern.compile("^\\.\\.\\. (//.+?\\#\\d+ (add|branch|delete))$", Pattern.MULTILINE);
>     protected static Pattern P4_MOVED_FILE      = Pattern.compile("//(.+?)(\\#\\d+) (\\w*)$", Pattern.MULTILINE);
>     protected static Pattern P4_DESCRIBE_HEADER = Pattern.compile("^==== //(.+?)(\\#\\d+) .*?====( \\(.+\\))?$", Pattern.MULTILINE);
>     protected static Pattern P4_DIFF_HEADER     = Pattern.compile("^==== //(.+?)(\\#\\d+) +- +(.+?) +====( \\(.+\\))?$", Pattern.MULTILINE);
>     protected static Pattern P4_DIFF2_HEADER    = Pattern.compile("^==== //(.+?)(\\#\\d+) +\\(.+?\\) +- +(.+?)(\\#\\d+) +\\(.+?\\) +==== +\\w+$",
>                                                                   Pattern.MULTILINE);
>     protected static Pattern VERSION = Pattern.compile("\\#(\\d+)");
>     protected static Pattern UNIFIED_DIFF = Pattern.compile("^\\@\\@\\s.*\\s\\@\\@$", Pattern.MULTILINE);
>     protected static Pattern CONTEXT_DIFF = Pattern.compile("^\\*+$", Pattern.MULTILINE);
>     protected static Pattern DEFAULT_DIFF = Pattern.compile("^\\d+(,\\d+)?[acd]\\d+", Pattern.MULTILINE);
56d69
<         //if (verbose) out.write("// write(line)\n");
60d72
<             if (verbose) out.write("// p4 describe move\n");
64d75
<             if (verbose) out.write("// p4 diff header\n");
72d82
<             if (verbose) out.write("// p4 diff2 header\n");
79d88
<             if (verbose) out.write("// p4 describe header\n");
90d98
<                 if (verbose) System.err.println("emitting diff -u header");
97d104
<                 if (verbose) System.err.println("emitting diff -c header");
104c111
<                 if (verbose) System.err.println("emitting diff header (not recommended for `patch`)");
---
>                 if (verbose) command.writeError(command.getResource("diff.default"));
109a117
> 
126d133
<                 if (verbose) System.err.println(verb);
128,131c135,137
<                 if (verb.equals("delete")) {
<                     Matcher version = VERSION.matcher(newNote);
<                     version.find();
<                     oldNote = "#" + (Long.parseLong(version.group(1)) - 1);
---
>                 if ("delete".equals(verb)) {
>                     (m = VERSION.matcher(newNote)).find();
>                     oldNote = "#" + (Long.parseLong(m.group(1)) - 1);
147c153
<                     if (verb.equals("delete")) {
---
>                     if ("delete".equals(verb)) {
168c174
<     private List p4print(String name) throws IOException {
---
>     protected List p4print(String name) throws IOException {
176c182
<             System.err.println("exit " + p.exitValue() + " from " + cmd);
---
>             command.writeError("exit " + p.exitValue() + " from " + cmd + "\n");
181,197d186
<     protected UnixStyleFilter filter;
<     protected Properties options;
<     protected boolean verbose;
<     protected Writer out;
< 
<     private p4d2p(UnixStyleFilter filter, Writer out) {
<         this.filter = filter;
<         this.options = filter.getOptions();
<         this.verbose = (options.getProperty("v") != null);
<         this.out = out;
<     }
< 
<     private static DateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); // ISO 8601
<     private static final String epoch = timeFormat.format(new Date(0));
< 
<     private String now = timeFormat.format(new Date());
<