/** * Simple function to check for the version options, -v and --version. If found * we use printf the version string specified. * * @param argc * @param argv * * @return bool */ static bool isVersionRequest(int argc, char **argv) { for ( int i = 1; i < argc && haveFlag(argv[i]); i++ ) { switch ( argv[i][1] ) { case 'h' : case '?' : printShortHelp(); return true; case 'v' : printStandardVersion(); return true; case '-' : if ( stricmp(argv[i], "--version") == 0 ) { printFullVersion(); return true; } else if ( stricmp(argv[i], "--help") == 0 ) { printLongHelp(); return true; } break; default : break; } } return false; }
/* * Process program's flags. */ static int options(char** argv, int argc) { int i; unsigned int j; size_t sz; userProperty* prop; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { break; } if (strcmp(argv[i], "-help") == 0) { usage(); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-version") == 0) { printShortVersion(); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "-fullversion") == 0) { printFullVersion(); exit(EXIT_SUCCESS); } #if defined(__ia64__) else if (strcmp(argv[i], "-ia32") == 0) { i++; /* FIXME: skip, case handled by the calle script */ } #endif else if (strcmp(argv[i], "-classpath") == 0 || strcmp(argv[i], "-cp") == 0) { i++; if (argv[i] == 0) { fprintf(stderr, "Error: No path found for %s option.\n", argv[i - 1]); exit(EXIT_FAILURE); } /* set the new classpath */ vmargs.classpath = strdup(argv[i]); } else if (strcmp(argv[i], "-addclasspath") == 0) { char *newcpath; unsigned int cpathlength; i++; if (argv[i] == 0) { fprintf(stderr, "Error: No path found for %s option.\n", argv[i - 1]); exit(EXIT_FAILURE); } cpathlength = ((vmargs.classpath != NULL) ? strlen(vmargs.classpath) : 0) + strlen(path_separator) + strlen(argv[i]) + 1; /* Get longer buffer FIXME: free the old one */ if ((newcpath = malloc(cpathlength)) == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } /* Construct new classpath */ if( vmargs.classpath != 0 ) strcpy(newcpath, vmargs.classpath); else newcpath[0] = '\0'; strcat(newcpath, path_separator); strcat(newcpath, argv[i]); /* set the new classpath */ vmargs.classpath = newcpath; } #ifdef KAFFE_X_AWT_INCLUDED /* Extra option to use kaffe's Xlib AWT backend. */ else if (strncmp(argv[i], "-Xkaffe-xlib-awt", (j=16)) == 0) { prop = setKaffeAWT("kaffe.awt.nativelib=xawt"); } #endif #ifdef KAFFE_QT_AWT_INCLUDED /* Extra option to use kaffe's Qt/Embedded AWT backend. */ else if (strncmp(argv[i], "-Xkaffe-qt-awt", (j=15)) == 0) { prop = setKaffeAWT("kaffe.awt.nativelib=qtawt"); } #endif #ifdef KAFFE_NANOX_AWT_INCLUDED /* Extra option to use kaffe's Nano-X AWT backend. */ else if (strncmp(argv[i], "-Xkaffe-nanox-awt", (j=17)) == 0) { prop = setKaffeAWT("kaffe.awt.nativelib=nanoxawt"); } #endif #if defined(USE_GMP) /* Extra option to use gmp for native, fast bignums. * Only available with binreloc, since binreloc is used to * find the gmpjavamath.jar file. */ else if (strncmp(argv[i], "-Xnative-big-math", (j=17)) == 0) { char *newbootcpath; unsigned int bootcpathlength; const char *prefix = #if defined(ENABLE_BINRELOC) LIBDIR #else /* !defined(ENABLE_BINRELOC) */ DEFAULT_KAFFEHOME #endif /* defined(ENABLE_BINRELOC) */ ; const char *suffix = file_separator "gmpjavamath.jar"; bootcpathlength = strlen(prefix) + strlen(suffix) + strlen(path_separator) + ((vmargs.bootClasspath != NULL) ? strlen(vmargs.bootClasspath) : 0) + 1; /* Get longer buffer FIXME: free the old one */ if ((newbootcpath = malloc(bootcpathlength)) == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } /* Construct new boot classpath */ strcpy(newbootcpath, prefix); strcat(newbootcpath, suffix); strcat(newbootcpath, path_separator); if( vmargs.bootClasspath != 0 ) strcat(newbootcpath, vmargs.bootClasspath); /* set the new boot classpath */ vmargs.bootClasspath = newbootcpath; } #endif /* defined(USE_GMP) */ else if (strncmp(argv[i], "-Xbootclasspath/p:", (j=18)) == 0) { char *newbootcpath; unsigned int bootcpathlength; bootcpathlength = strlen(&argv[i][j]) + strlen(path_separator) + ((vmargs.bootClasspath != NULL) ? strlen(vmargs.bootClasspath) : 0) + 1; /* Get longer buffer FIXME: free the old one */ if ((newbootcpath = malloc(bootcpathlength)) == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } /* Construct new boot classpath */ strcpy(newbootcpath, &argv[i][j]); strcat(newbootcpath, path_separator); if( vmargs.bootClasspath != 0 ) strcat(newbootcpath, vmargs.bootClasspath); /* set the new boot classpath */ vmargs.bootClasspath = newbootcpath; } else if (strncmp(argv[i], "-Xbootclasspath/a:", (j=18)) == 0) { char *newbootcpath; unsigned int bootcpathlength; bootcpathlength = strlen(&argv[i][j]) + strlen(path_separator) + ((vmargs.bootClasspath != NULL) ? strlen(vmargs.bootClasspath) : 0) + 1; /* Get longer buffer FIXME: free the old one */ if ((newbootcpath = malloc(bootcpathlength)) == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } /* Construct new boot classpath */ if( vmargs.bootClasspath != 0 ) { strcpy(newbootcpath, vmargs.bootClasspath); strcat(newbootcpath, path_separator); } strcat(newbootcpath, &argv[i][j]); /* set the new boot classpath */ vmargs.bootClasspath = newbootcpath; } else if (strncmp(argv[i], "-Xbootclasspath:", (j=16)) == 0) { char *newbootcpath; unsigned int bootcpathlength; bootcpathlength = strlen(&argv[i][j]) + 1; /* Get longer buffer FIXME: free the old one */ if ((newbootcpath = malloc(bootcpathlength)) == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } /* Construct new boot classpath */ strcpy(newbootcpath, &argv[i][j]); /* set the new boot classpath */ vmargs.bootClasspath = newbootcpath; } else if ((strncmp(argv[i], "-ss", (j=3)) == 0) || (strncmp(argv[i], "-Xss", (j=4)) == 0)) { if (argv[i][j] == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: No stack size found for -ss option.\n")); exit(EXIT_FAILURE); } sz = parseSize(argv[i]); } else { sz = parseSize(&argv[i][j]); } if (sz < THREADSTACKSIZE) { fprintf(stderr, _("Warning: Attempt to set stack size smaller than %d - ignored.\n"), THREADSTACKSIZE); } else { vmargs.nativeStackSize = sz; } } else if ((strncmp(argv[i], "-mx", (j=3)) == 0) || (strncmp(argv[i], "-Xmx", (j=4)) == 0)) { if (argv[i][j] == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: No heap size found for -mx option.\n")); exit(EXIT_FAILURE); } if (strcmp(argv[i], "unlimited") == 0) vmargs.maxHeapSize = UNLIMITED_HEAP; else vmargs.maxHeapSize = parseSize(argv[i]); } else { if (strcmp(&argv[i][j], "unlimited") == 0) vmargs.maxHeapSize = UNLIMITED_HEAP; else vmargs.maxHeapSize = parseSize(&argv[i][j]); } } else if ((strncmp(argv[i], "-ms", (j=3)) == 0) || (strncmp(argv[i], "-Xms", (j=4)) == 0)) { if (argv[i][j] == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: No heap size found for -ms option.\n")); exit(EXIT_FAILURE); } vmargs.minHeapSize = parseSize(argv[i]); } else { vmargs.minHeapSize = parseSize(&argv[i][j]); } } else if (strncmp(argv[i], "-as", 3) == 0) { if (argv[i][3] == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: No heap size found for -as option.\n")); exit(EXIT_FAILURE); } vmargs.allocHeapSize = parseSize(argv[i]); } else { vmargs.allocHeapSize = parseSize(&argv[i][3]); } } else if (strcmp(argv[i], "-verify") == 0) { vmargs.verifyMode = 3; } else if (strcmp(argv[i], "-verifyremote") == 0) { vmargs.verifyMode = 2; } else if (strcmp(argv[i], "-noverify") == 0) { vmargs.verifyMode = 0; } else if (strcmp(argv[i], "-verbosegc") == 0) { vmargs.enableVerboseGC = 1; } else if (strcmp(argv[i], "-noclassgc") == 0) { vmargs.enableClassGC = 0; } else if (strcmp(argv[i], "-verbosejit") == 0) { vmargs.enableVerboseJIT = 1; } else if (strcmp(argv[i], "-verbosemem") == 0) { vmargs.enableVerboseGC = 2; } else if (strcmp(argv[i], "-verbosecall") == 0) { vmargs.enableVerboseCall = 1; } else if (strcmp(argv[i], "-verbose") == 0 || strcmp(argv[i], "-v") == 0) { vmargs.enableVerboseClassloading = 1; } else if (strcmp(argv[i], "-jar") == 0) { char *newcpath; unsigned int cpathlength; cpathlength = strlen(argv[i+1]) + strlen(path_separator) + ((vmargs.classpath!=NULL) ? strlen(vmargs.classpath) : 0) + 1; newcpath = (char *)malloc (cpathlength); if (newcpath == NULL) { fprintf(stderr, _("Error: out of memory.\n")); exit(EXIT_FAILURE); } strcpy (newcpath, argv[i+1]); if (vmargs.classpath != NULL) { strcat (newcpath, path_separator); strcat (newcpath, vmargs.classpath); free ((void*)vmargs.classpath); } /* set the new classpath */ vmargs.classpath = newcpath; isJar = 1; } else if (strncmp(argv[i], "-Xrun", 5) == 0) { char *argPos; char *libName; int libnameLen; argPos = strchr(argv[i], ':'); if (argPos != NULL) { libnameLen = argPos - &argv[i][5]; vmargs.profilerArguments = strdup(argPos+1); } else libnameLen = strlen(argv[i]) - 1; libName = malloc(libnameLen+4); strcpy(libName, "lib"); strncat(libName, &argv[i][5], libnameLen); vmargs.profilerLibname = libName; } #if defined(KAFFE_PROFILER) else if (strcmp(argv[i], "-prof") == 0) { profFlag = 1; vmargs.enableClassGC = 0; } #endif #if defined(KAFFE_XPROFILER) else if (strcmp(argv[i], "-Xxprof") == 0) { xProfFlag = 1; vmargs.enableClassGC = 0; } else if (strcmp(argv[i], "-Xxprof_syms") == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: -Xxprof_syms option requires " "a file name.\n")); } else if( !profileSymbolFile(argv[i]) ) { fprintf(stderr, _("Unable to create profiler symbol " "file %s.\n"), argv[i]); } } else if (strcmp(argv[i], "-Xxprof_gmon") == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: -Xxprof_gmon option requires " "a file name.\n")); } else if (!profileGmonFile(argv[i])) { fprintf(stderr, _("Unable to create gmon file %s.\n"), argv[i]); } } #endif #if defined(KAFFE_XDEBUGGING) else if (strcmp(argv[i], "-Xxdebug") == 0) { /* Use a default name */ machine_debug_filename = "xdb.as"; } else if (strcmp(argv[i], "-Xxdebug_file") == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: -Xxdebug_file option requires " "a file name.\n")); } else { machine_debug_filename = argv[i]; } } #endif #if defined(KAFFE_FEEDBACK) else if (strcmp(argv[i], "-Xfeedback") == 0) { i++; if (argv[i] == 0) { fprintf(stderr, _("Error: -Xfeedback option requires a " "file name.\n")); } else { feedback_filename = argv[i]; } } #endif else if (strcmp(argv[i], "-nodeadlock") == 0) { KaffeVM_setDeadlockDetection(0); } #if defined(KAFFE_STATS) else if (strcmp(argv[i], "-vmstats") == 0) { extern void statsSetMaskStr(char *); i++; if (argv[i] == 0) { /* forgot second arg */ fprintf(stderr, _("Error: -vmstats option requires a " "second arg.\n")); exit(EXIT_FAILURE); } statsSetMaskStr(argv[i]); } #endif #if defined(KAFFE_VMDEBUG) else if (strcmp(argv[i], "-vmdebug") == 0) { i++; if (argv[i] == 0) { /* forgot second arg */ fprintf(stderr, _("Error: -vmdebug option requires a " "debug flag. Use `list' for a list.\n")); exit(EXIT_FAILURE); } if (!dbgSetMaskStr(argv[i])) exit(EXIT_FAILURE); } #endif else if (strcmp(argv[i], "-debug-fd") == 0) { char *end; i++; if (argv[i] == 0) { /* forgot second arg */ fprintf(stderr, _("Error: -debug-fd an open descriptor.\n")); exit(EXIT_FAILURE); } dbgSetDprintfFD(strtol(argv[i], &end, 10)); if (end != 0 && *end != '\0') { fprintf(stderr, _("Error: -debug-fd requires an integer.\n")); exit(EXIT_FAILURE); } } else if (argv[i][1] == 'D') { /* Set a property */ char *propStr = strdup(&argv[i][2]); prop = setUserProperty(propStr); } else if (argv[i][1] == 'X') { fprintf(stderr, _("Error: Unrecognized JVM specific option " "`%s'.\n"), argv[i]); } /* The following options are not supported and will be * ignored for compatibility purposes. */ else if (strcmp(argv[i], "-noasyncgc") == 0 || strcmp(argv[i], "-cs") == 0 || strcmp(argv[i], "-checksource")) { } else if (strcmp(argv[i], "-oss") == 0) { i++; } else { fprintf(stderr, _("Unknown flag: %s\n"), argv[i]); } } /* Return first no-flag argument */ return (i); }