17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <sys/stat.h>
30 #include <ctype.h>
31
32 #ifdef DEBUG_ARGFILE
33 #ifndef NO_JNI
34 #define NO_JNI
35 #endif
36 #define JLI_ReportMessage(...) printf(__VA_ARGS__)
37 #define JAVA_OPTIONS "JAVA_OPTIONS"
38 int IsWhiteSpaceOption(const char* name) { return 1; }
39 #else
40 #include "java.h"
41 #endif
42
43 #include "jli_util.h"
44 #include "emessages.h"
45
46 #define MAX_ARGF_SIZE 0x7fffffffL
47
48 static char* clone_substring(const char *begin, size_t len) {
49 char *rv = (char *) JLI_MemAlloc(len + 1);
50 memcpy(rv, begin, len);
51 rv[len] = '\0';
52 return rv;
53 }
54
55 enum STATE {
56 FIND_NEXT,
57 IN_COMMENT,
412 }
413
414 int isTerminalOpt(char *arg) {
415 return JLI_StrCmp(arg, "-jar") == 0 ||
416 JLI_StrCmp(arg, "-m") == 0 ||
417 JLI_StrCmp(arg, "--module") == 0 ||
418 JLI_StrCmp(arg, "--dry-run") == 0 ||
419 JLI_StrCmp(arg, "-h") == 0 ||
420 JLI_StrCmp(arg, "-?") == 0 ||
421 JLI_StrCmp(arg, "-help") == 0 ||
422 JLI_StrCmp(arg, "--help") == 0 ||
423 JLI_StrCmp(arg, "-X") == 0 ||
424 JLI_StrCmp(arg, "--help-extra") == 0 ||
425 JLI_StrCmp(arg, "-version") == 0 ||
426 JLI_StrCmp(arg, "--version") == 0 ||
427 JLI_StrCmp(arg, "-fullversion") == 0 ||
428 JLI_StrCmp(arg, "--full-version") == 0;
429 }
430
431 jboolean JLI_AddArgsFromEnvVar(JLI_List args, const char *var_name) {
432
433 #ifndef ENABLE_JAVA_OPTIONS
434 return JNI_FALSE;
435 #else
436 char *env = getenv(var_name);
437 char *p, *arg;
438 char quote;
439 JLI_List argsInFile;
440
441 if (firstAppArgIndex == 0) {
442 // Not 'java', return
443 return JNI_FALSE;
444 }
445
446 if (relaunch) {
447 return JNI_FALSE;
448 }
449
450 if (NULL == env) {
451 return JNI_FALSE;
452 }
453
454 JLI_ReportMessage(ARG_INFO_ENVVAR, var_name, env);
455
502 }
503 // Shallow free, we reuse the string to avoid copy
504 JLI_MemFree(argsInFile->elements);
505 JLI_MemFree(argsInFile);
506 }
507 /*
508 * Check if main-class is specified after argument being checked. It
509 * must always appear after expansion, as a main-class could be specified
510 * indirectly into environment variable via an @argfile, and it must be
511 * caught now.
512 */
513 if (firstAppArgIndex != NOT_FOUND) {
514 JLI_ReportMessage(ARG_ERROR11, var_name);
515 exit(1);
516 }
517
518 assert (*env == '\0' || isspace(*env));
519 }
520
521 return JNI_TRUE;
522 #endif
523 }
524
525 #ifdef DEBUG_ARGFILE
526 /*
527 * Stand-alone sanity test, build with following command line
528 * $ CC -DDEBUG_ARGFILE -DNO_JNI -g args.c jli_util.c
529 */
530
531 void fail(char *expected, char *actual, size_t idx) {
532 printf("FAILED: Token[%lu] expected to be <%s>, got <%s>\n", idx, expected, actual);
533 exit(1);
534 }
535
536 void test_case(char *case_data, char **tokens, size_t cnt_tokens) {
537 size_t actual_cnt;
538 char *token;
539 __ctx_args ctx;
540
541 actual_cnt = 0;
542
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <sys/stat.h>
30 #include <ctype.h>
31
32 #ifdef DEBUG_ARGFILE
33 #ifndef NO_JNI
34 #define NO_JNI
35 #endif
36 #define JLI_ReportMessage(...) printf(__VA_ARGS__)
37 #define JDK_JAVA_OPTIONS "JDK_JAVA_OPTIONS"
38 int IsWhiteSpaceOption(const char* name) { return 1; }
39 #else
40 #include "java.h"
41 #endif
42
43 #include "jli_util.h"
44 #include "emessages.h"
45
46 #define MAX_ARGF_SIZE 0x7fffffffL
47
48 static char* clone_substring(const char *begin, size_t len) {
49 char *rv = (char *) JLI_MemAlloc(len + 1);
50 memcpy(rv, begin, len);
51 rv[len] = '\0';
52 return rv;
53 }
54
55 enum STATE {
56 FIND_NEXT,
57 IN_COMMENT,
412 }
413
414 int isTerminalOpt(char *arg) {
415 return JLI_StrCmp(arg, "-jar") == 0 ||
416 JLI_StrCmp(arg, "-m") == 0 ||
417 JLI_StrCmp(arg, "--module") == 0 ||
418 JLI_StrCmp(arg, "--dry-run") == 0 ||
419 JLI_StrCmp(arg, "-h") == 0 ||
420 JLI_StrCmp(arg, "-?") == 0 ||
421 JLI_StrCmp(arg, "-help") == 0 ||
422 JLI_StrCmp(arg, "--help") == 0 ||
423 JLI_StrCmp(arg, "-X") == 0 ||
424 JLI_StrCmp(arg, "--help-extra") == 0 ||
425 JLI_StrCmp(arg, "-version") == 0 ||
426 JLI_StrCmp(arg, "--version") == 0 ||
427 JLI_StrCmp(arg, "-fullversion") == 0 ||
428 JLI_StrCmp(arg, "--full-version") == 0;
429 }
430
431 jboolean JLI_AddArgsFromEnvVar(JLI_List args, const char *var_name) {
432 char *env = getenv(var_name);
433 char *p, *arg;
434 char quote;
435 JLI_List argsInFile;
436
437 if (firstAppArgIndex == 0) {
438 // Not 'java', return
439 return JNI_FALSE;
440 }
441
442 if (relaunch) {
443 return JNI_FALSE;
444 }
445
446 if (NULL == env) {
447 return JNI_FALSE;
448 }
449
450 JLI_ReportMessage(ARG_INFO_ENVVAR, var_name, env);
451
498 }
499 // Shallow free, we reuse the string to avoid copy
500 JLI_MemFree(argsInFile->elements);
501 JLI_MemFree(argsInFile);
502 }
503 /*
504 * Check if main-class is specified after argument being checked. It
505 * must always appear after expansion, as a main-class could be specified
506 * indirectly into environment variable via an @argfile, and it must be
507 * caught now.
508 */
509 if (firstAppArgIndex != NOT_FOUND) {
510 JLI_ReportMessage(ARG_ERROR11, var_name);
511 exit(1);
512 }
513
514 assert (*env == '\0' || isspace(*env));
515 }
516
517 return JNI_TRUE;
518 }
519
520 #ifdef DEBUG_ARGFILE
521 /*
522 * Stand-alone sanity test, build with following command line
523 * $ CC -DDEBUG_ARGFILE -DNO_JNI -g args.c jli_util.c
524 */
525
526 void fail(char *expected, char *actual, size_t idx) {
527 printf("FAILED: Token[%lu] expected to be <%s>, got <%s>\n", idx, expected, actual);
528 exit(1);
529 }
530
531 void test_case(char *case_data, char **tokens, size_t cnt_tokens) {
532 size_t actual_cnt;
533 char *token;
534 __ctx_args ctx;
535
536 actual_cnt = 0;
537
|