2 JPC-RR: A x86 PC Hardware Emulator
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
33 * Provides simple command line parsing for the various frontends to the
37 public class ArgProcessor
40 * Finds the value of the variable <code>key</code>. Searches the given
41 * commandline for <code>-key value</code>
42 * @param args array of strings to search
43 * @param key key to search for
44 * @param defaultValue value returned on failure
45 * @return result, or <code>defaultValue</code> on failure
47 public static String
findVariable(String
[] args
, String key
, String defaultValue
)
49 int keyIndex
= findKey(args
, key
);
53 if((keyIndex
+ 1) < args
.length
)
54 return args
[keyIndex
+ 1];
60 * Searches for the presence of the given flag on the command line as
62 * @param args array of strings to search
63 * @param flag parameter to search for
64 * @return true if flag is found
66 public static boolean findFlag(String
[] args
, String flag
)
68 return findKey(args
, flag
) >= 0;
71 private static int findKey(String
[] args
, String key
)
73 if(key
.startsWith("-"))
74 key
= key
.substring(1);
76 for(int i
=0; i
<args
.length
; i
++) {
77 if(!args
[i
].startsWith("-"))
80 if(args
[i
].substring(1).equalsIgnoreCase(key
))
87 private ArgProcessor()