556 }
557
558 /*
559 * Test if the given name is a module-system white-space option that
560 * will be passed to the VM with its corresponding long-form option
561 * name and "=" delimiter.
562 */
563 static jboolean
564 IsModuleOption(const char* name) {
565 return JLI_StrCmp(name, "--module-path") == 0 ||
566 JLI_StrCmp(name, "-p") == 0 ||
567 JLI_StrCmp(name, "--upgrade-module-path") == 0 ||
568 JLI_StrCmp(name, "--add-modules") == 0 ||
569 JLI_StrCmp(name, "--limit-modules") == 0 ||
570 JLI_StrCmp(name, "--add-exports") == 0 ||
571 JLI_StrCmp(name, "--add-opens") == 0 ||
572 JLI_StrCmp(name, "--add-reads") == 0 ||
573 JLI_StrCmp(name, "--patch-module") == 0;
574 }
575
576 /*
577 * Test if the given name has a white space option.
578 */
579 jboolean
580 IsWhiteSpaceOption(const char* name) {
581 return IsModuleOption(name) ||
582 IsLauncherOption(name);
583 }
584
585 /*
586 * Checks the command line options to find which JVM type was
587 * specified. If no command line option was given for the JVM type,
588 * the default type is used. The environment variable
589 * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
590 * checked as ways of specifying which JVM type to invoke.
591 */
592 char *
593 CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
594 int i, argi;
595 int argc;
1219 * should exit without starting vm, returns JNI_TRUE if vm needs
1220 * to be started to process given options. *pret (the launcher
1221 * process return value) is set to 0 for a normal exit.
1222 */
1223 static jboolean
1224 ParseArguments(int *pargc, char ***pargv,
1225 int *pmode, char **pwhat,
1226 int *pret, const char *jrepath)
1227 {
1228 int argc = *pargc;
1229 char **argv = *pargv;
1230 int mode = LM_UNKNOWN;
1231 char *arg;
1232
1233 *pret = 0;
1234
1235 while ((arg = *argv) != 0 && *arg == '-') {
1236 char *option = NULL;
1237 char *value = NULL;
1238 int kind = GetOpt(&argc, &argv, &option, &value);
1239 jboolean has_arg = value != NULL;
1240
1241 /*
1242 * Option to set main entry point
1243 */
1244 if (JLI_StrCmp(arg, "-jar") == 0) {
1245 ARG_CHECK(argc, ARG_ERROR2, arg);
1246 mode = LM_JAR;
1247 } else if (JLI_StrCmp(arg, "--module") == 0 ||
1248 JLI_StrCCmp(arg, "--module=") == 0 ||
1249 JLI_StrCmp(arg, "-m") == 0) {
1250 REPORT_ERROR (has_arg, ARG_ERROR5, arg);
1251 SetMainModule(value);
1252 mode = LM_MODULE;
1253 if (has_arg) {
1254 *pwhat = value;
1255 break;
1256 }
1257 } else if (JLI_StrCmp(arg, "--class-path") == 0 ||
1258 JLI_StrCCmp(arg, "--class-path=") == 0 ||
1259 JLI_StrCmp(arg, "-classpath") == 0 ||
1268 // set listModules to --list-modules=<module-names> if argument is specified
1269 if (JLI_StrCmp(arg, "--list-modules") == 0 && has_arg) {
1270 static const char format[] = "%s=%s";
1271 size_t buflen = JLI_StrLen(option) + 2 + JLI_StrLen(value);
1272 listModules = JLI_MemAlloc(buflen);
1273 JLI_Snprintf(listModules, buflen, format, option, value);
1274 }
1275 return JNI_TRUE;
1276 /*
1277 * Parse white-space options
1278 */
1279 } else if (has_arg) {
1280 if (kind == VM_LONG_OPTION) {
1281 AddOption(option, NULL);
1282 } else if (kind == VM_LONG_OPTION_WITH_ARGUMENT) {
1283 AddLongFormOption(option, value);
1284 }
1285 /*
1286 * Error missing argument
1287 */
1288 } else if (!has_arg && IsWhiteSpaceOption(arg)) {
1289 if (JLI_StrCmp(arg, "--module-path") == 0 ||
1290 JLI_StrCmp(arg, "-p") == 0 ||
1291 JLI_StrCmp(arg, "--upgrade-module-path") == 0) {
1292 REPORT_ERROR (has_arg, ARG_ERROR4, arg);
1293 } else if (JLI_StrCmp(arg, "--add-modules") == 0 ||
1294 JLI_StrCmp(arg, "--limit-modules") == 0 ||
1295 JLI_StrCmp(arg, "--add-exports") == 0 ||
1296 JLI_StrCmp(arg, "--add-opens") == 0 ||
1297 JLI_StrCmp(arg, "--add-reads") == 0 ||
1298 JLI_StrCmp(arg, "--patch-module") == 0) {
1299 REPORT_ERROR (has_arg, ARG_ERROR6, arg);
1300 }
1301 /*
1302 * The following cases will cause the argument parsing to stop
1303 */
1304 } else if (JLI_StrCmp(arg, "-help") == 0 ||
1305 JLI_StrCmp(arg, "-h") == 0 ||
1306 JLI_StrCmp(arg, "-?") == 0) {
1307 printUsage = JNI_TRUE;
1308 return JNI_TRUE;
1309 } else if (JLI_StrCmp(arg, "--help") == 0) {
1310 printUsage = JNI_TRUE;
1311 printTo = USE_STDOUT;
1312 return JNI_TRUE;
1313 } else if (JLI_StrCmp(arg, "-version") == 0) {
1314 printVersion = JNI_TRUE;
1315 return JNI_TRUE;
1316 } else if (JLI_StrCmp(arg, "--version") == 0) {
1317 printVersion = JNI_TRUE;
1318 printTo = USE_STDOUT;
1319 return JNI_TRUE;
1320 } else if (JLI_StrCmp(arg, "-showversion") == 0) {
|
556 }
557
558 /*
559 * Test if the given name is a module-system white-space option that
560 * will be passed to the VM with its corresponding long-form option
561 * name and "=" delimiter.
562 */
563 static jboolean
564 IsModuleOption(const char* name) {
565 return JLI_StrCmp(name, "--module-path") == 0 ||
566 JLI_StrCmp(name, "-p") == 0 ||
567 JLI_StrCmp(name, "--upgrade-module-path") == 0 ||
568 JLI_StrCmp(name, "--add-modules") == 0 ||
569 JLI_StrCmp(name, "--limit-modules") == 0 ||
570 JLI_StrCmp(name, "--add-exports") == 0 ||
571 JLI_StrCmp(name, "--add-opens") == 0 ||
572 JLI_StrCmp(name, "--add-reads") == 0 ||
573 JLI_StrCmp(name, "--patch-module") == 0;
574 }
575
576 static jboolean
577 IsLongFormModuleOption(const char* name) {
578 return JLI_StrCCmp(name, "--module-path=") == 0 ||
579 JLI_StrCCmp(name, "--upgrade-module-path=") == 0 ||
580 JLI_StrCCmp(name, "--add-modules=") == 0 ||
581 JLI_StrCCmp(name, "--limit-modules=") == 0 ||
582 JLI_StrCCmp(name, "--add-exports=") == 0 ||
583 JLI_StrCCmp(name, "--add-reads=") == 0 ||
584 JLI_StrCCmp(name, "--patch-module=") == 0;
585 }
586
587 /*
588 * Test if the given name has a white space option.
589 */
590 jboolean
591 IsWhiteSpaceOption(const char* name) {
592 return IsModuleOption(name) ||
593 IsLauncherOption(name);
594 }
595
596 /*
597 * Checks the command line options to find which JVM type was
598 * specified. If no command line option was given for the JVM type,
599 * the default type is used. The environment variable
600 * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
601 * checked as ways of specifying which JVM type to invoke.
602 */
603 char *
604 CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
605 int i, argi;
606 int argc;
1230 * should exit without starting vm, returns JNI_TRUE if vm needs
1231 * to be started to process given options. *pret (the launcher
1232 * process return value) is set to 0 for a normal exit.
1233 */
1234 static jboolean
1235 ParseArguments(int *pargc, char ***pargv,
1236 int *pmode, char **pwhat,
1237 int *pret, const char *jrepath)
1238 {
1239 int argc = *pargc;
1240 char **argv = *pargv;
1241 int mode = LM_UNKNOWN;
1242 char *arg;
1243
1244 *pret = 0;
1245
1246 while ((arg = *argv) != 0 && *arg == '-') {
1247 char *option = NULL;
1248 char *value = NULL;
1249 int kind = GetOpt(&argc, &argv, &option, &value);
1250 jboolean has_arg = value != NULL && JLI_StrLen(value) > 0;
1251
1252 /*
1253 * Option to set main entry point
1254 */
1255 if (JLI_StrCmp(arg, "-jar") == 0) {
1256 ARG_CHECK(argc, ARG_ERROR2, arg);
1257 mode = LM_JAR;
1258 } else if (JLI_StrCmp(arg, "--module") == 0 ||
1259 JLI_StrCCmp(arg, "--module=") == 0 ||
1260 JLI_StrCmp(arg, "-m") == 0) {
1261 REPORT_ERROR (has_arg, ARG_ERROR5, arg);
1262 SetMainModule(value);
1263 mode = LM_MODULE;
1264 if (has_arg) {
1265 *pwhat = value;
1266 break;
1267 }
1268 } else if (JLI_StrCmp(arg, "--class-path") == 0 ||
1269 JLI_StrCCmp(arg, "--class-path=") == 0 ||
1270 JLI_StrCmp(arg, "-classpath") == 0 ||
1279 // set listModules to --list-modules=<module-names> if argument is specified
1280 if (JLI_StrCmp(arg, "--list-modules") == 0 && has_arg) {
1281 static const char format[] = "%s=%s";
1282 size_t buflen = JLI_StrLen(option) + 2 + JLI_StrLen(value);
1283 listModules = JLI_MemAlloc(buflen);
1284 JLI_Snprintf(listModules, buflen, format, option, value);
1285 }
1286 return JNI_TRUE;
1287 /*
1288 * Parse white-space options
1289 */
1290 } else if (has_arg) {
1291 if (kind == VM_LONG_OPTION) {
1292 AddOption(option, NULL);
1293 } else if (kind == VM_LONG_OPTION_WITH_ARGUMENT) {
1294 AddLongFormOption(option, value);
1295 }
1296 /*
1297 * Error missing argument
1298 */
1299 } else if (!has_arg && (JLI_StrCmp(arg, "--module-path") == 0 ||
1300 JLI_StrCmp(arg, "-p") == 0 ||
1301 JLI_StrCmp(arg, "--upgrade-module-path") == 0)) {
1302 REPORT_ERROR (has_arg, ARG_ERROR4, arg);
1303
1304 } else if (!has_arg && (IsModuleOption(arg) || IsLongFormModuleOption(arg))) {
1305 REPORT_ERROR (has_arg, ARG_ERROR6, arg);
1306 /*
1307 * The following cases will cause the argument parsing to stop
1308 */
1309 } else if (JLI_StrCmp(arg, "-help") == 0 ||
1310 JLI_StrCmp(arg, "-h") == 0 ||
1311 JLI_StrCmp(arg, "-?") == 0) {
1312 printUsage = JNI_TRUE;
1313 return JNI_TRUE;
1314 } else if (JLI_StrCmp(arg, "--help") == 0) {
1315 printUsage = JNI_TRUE;
1316 printTo = USE_STDOUT;
1317 return JNI_TRUE;
1318 } else if (JLI_StrCmp(arg, "-version") == 0) {
1319 printVersion = JNI_TRUE;
1320 return JNI_TRUE;
1321 } else if (JLI_StrCmp(arg, "--version") == 0) {
1322 printVersion = JNI_TRUE;
1323 printTo = USE_STDOUT;
1324 return JNI_TRUE;
1325 } else if (JLI_StrCmp(arg, "-showversion") == 0) {
|