cmdtoargs.c revision 5269
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Converts a single string command line to the traditional argc, argv.
* There are rules which govern the breaking of the the arguments, and
* these rules are embodied in the regression tests below, and duplicated
* in the jdk regression tests.
*/
#ifndef IDE_STANDALONE
#include "java.h"
#include "jli_util.h"
#else /* IDE_STANDALONE */
// The defines we need for stand alone testing
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#define JLI_MemRealloc realloc
#define JLI_StringDup _strdup
#define JLI_MemFree free
typedef struct {
char* arg;
} StdArg ;
#endif
static int stdargc;
int quotes = 0;
int slashes = 0;
char prev = 0;
char ch = 0;
int i;
switch (ch) {
case '"':
if (separator) {
break;
}
if (prev == '\\') {
}
} else {
quotes++;
}
quotes++;
} else if (quotes == 0) {
quotes++; // starting quote
} else {
quotes--; // matching quote
}
slashes = 0;
break;
case '\\':
slashes++;
if (separator) {
}
break;
case ' ':
case '\t':
} else {
}
slashes = 0;
break;
case '*':
case '?':
if (separator) {
break;
}
if (quotes % 2 == 0) {
}
if (prev == '\\') {
}
break;
default:
if (prev == '\\') {
for (i = 0 ; i < slashes ; i++) {
}
} else if (separator) {
} else {
}
slashes = 0;
}
if (!done) {
src++;
}
}
if (prev == '\\') {
for (i = 0; i < slashes; i++) {
}
}
*dest = 0;
}
int JLI_GetStdArgc() {
return stdargc;
}
StdArg* JLI_GetStdArgs() {
return stdargs;
}
void JLI_CmdToArgs(char* cmdline) {
int nargs = 0;
// allocate arg buffer with sufficient space to receive the largest arg
do {
// resize to accommodate another Arg
nargs++;
}
#ifdef IDE_STANDALONE
printf("Hit any key to quit\n");
int c = getchar();
}
void doabort() {
doexit(1);
}
char* cmdline;
int argc;
char* argv[10];
Vector(){}
// Initialize our test vector with the program name, argv[0]
// and the single string command line.
argc = 1;
}
// add our expected strings, the program name has already been
// added so ignore that
argc++;
}
void disable() {
}
// validate the returned arguments with the expected arguments, using the
// new CmdToArgs method.
bool check() {
// "pgmname" rest of cmdline ie. pgmname + 2 double quotes + space + cmdline from windows
int kargc = JLI_GetStdArgc();
bool retval = true;
printf("\n===========================\n");
printf("*** argument count does not match\n");
printme();
doabort();
}
printf("*** argument at [%d] don't match\n got: %s\n exp: %s\n",
doabort();
}
}
printf("*** expansion flag at [%d] doesn't match\n got: %d\n exp: %d\n",
doabort();
}
}
for (int i = 0 ; i < kargc ; i++) {
}
return retval;
}
for (int i = 0 ; i < kargc ; i++) {
}
}
void printme() {
for (int i = 0 ; i < argc ; i++) {
}
}
};
for (int i = 0 ; v != NULL;) {
if (v->enabled) {
v->check();
}
v = vectors[++i];
}
}
#define MAXV 128
int n;
for (n=1; n < argc; n++) {
}
if (n > 1) {
for (n = 0; n < stdargc; n++) {
}
doexit(0);
}
int i = 0;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// Windows tests
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// Additional tests
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// test if a wildcard is present
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
// v->disable();
vectors[i++] = v;
printf("All tests pass [%d]\n", i);
doexit(0);
}
#endif /* IDE_STANDALONE */