UartBus source documentation
eu.javaexperience.electronic.uartbus.cli.apps.UartbusAttachProcess Class Reference
Collaboration diagram for eu.javaexperience.electronic.uartbus.cli.apps.UartbusAttachProcess:

Static Public Member Functions

static void main (String[] args) throws Exception
 
static String [] translateCommandline (String toProcess)
 

Static Public Attributes

static final CliEntry< String > PROGRAM
 

Static Protected Attributes

static final CliEntry [] PROG_CLI_ENTRIES
 

Detailed Description

Definition at line 25 of file UartbusAttachProcess.java.

Member Function Documentation

◆ translateCommandline()

static String [] eu.javaexperience.electronic.uartbus.cli.apps.UartbusAttachProcess.translateCommandline ( String  toProcess)
inlinestatic

https://stackoverflow.com/questions/3259143/split-a-string-containing-command-line-parameters-into-a-string-in-java [code borrowed from ant.jar] Crack a command line.

Parameters
toProcessthe command line to process.
Returns
the command line broken into strings. An empty or null toProcess parameter results in a zero sized array.

Definition at line 138 of file UartbusAttachProcess.java.

138  {
139  if (toProcess == null || toProcess.length() == 0) {
140  //no command? no string
141  return new String[0];
142  }
143  // parse with a simple finite state machine
144 
145  final int normal = 0;
146  final int inQuote = 1;
147  final int inDoubleQuote = 2;
148  int state = normal;
149  final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
150  final ArrayList<String> result = new ArrayList<String>();
151  final StringBuilder current = new StringBuilder();
152  boolean lastTokenHasBeenQuoted = false;
153 
154  while (tok.hasMoreTokens()) {
155  String nextTok = tok.nextToken();
156  switch (state) {
157  case inQuote:
158  if ("\'".equals(nextTok)) {
159  lastTokenHasBeenQuoted = true;
160  state = normal;
161  } else {
162  current.append(nextTok);
163  }
164  break;
165  case inDoubleQuote:
166  if ("\"".equals(nextTok)) {
167  lastTokenHasBeenQuoted = true;
168  state = normal;
169  } else {
170  current.append(nextTok);
171  }
172  break;
173  default:
174  if ("\'".equals(nextTok)) {
175  state = inQuote;
176  } else if ("\"".equals(nextTok)) {
177  state = inDoubleQuote;
178  } else if (" ".equals(nextTok)) {
179  if (lastTokenHasBeenQuoted || current.length() != 0) {
180  result.add(current.toString());
181  current.setLength(0);
182  }
183  } else {
184  current.append(nextTok);
185  }
186  lastTokenHasBeenQuoted = false;
187  break;
188  }
189  }
190  if (lastTokenHasBeenQuoted || current.length() != 0) {
191  result.add(current.toString());
192  }
193  if (state == inQuote || state == inDoubleQuote) {
194  throw new RuntimeException("unbalanced quotes in " + toProcess);
195  }
196  return result.toArray(new String[result.size()]);
197  }

Member Data Documentation

◆ PROG_CLI_ENTRIES

final CliEntry [] eu.javaexperience.electronic.uartbus.cli.apps.UartbusAttachProcess.PROG_CLI_ENTRIES
staticprotected
Initial value:
=
{
RPC_HOST,
RPC_PORT,
LOOPBACK,
PROGRAM
}

Definition at line 34 of file UartbusAttachProcess.java.

◆ PROGRAM

final CliEntry<String> eu.javaexperience.electronic.uartbus.cli.apps.UartbusAttachProcess.PROGRAM
static
Initial value:
= CliEntry.createFirstArgParserEntry
(
(e)->e,
"Application with arguments",
"a", "-program"
)

Definition at line 27 of file UartbusAttachProcess.java.


The documentation for this class was generated from the following file: