void parseCmdlineOpts (int argc, char **argv, struct args_info *args_info) { char *string_ptr = NULL; char *args_ptr = NULL; /* Clear out the argument structure */ memset (args_info, 0, sizeof (struct args_info)); while (argc > 1) { /* If we don't have a proper argument leading with '-' */ if (argv[1][0] != '-') { printHelp (); exit (1); } /* Deal with arguments of type '--', else deal with switches of * type '-'. */ if (argv[1][1] == '-') { string_ptr = &(argv[1][2]); /* Find the '=' if it exists, otherwise argv_ptr is '\0' */ for (args_ptr = string_ptr; *args_ptr != '\0'; args_ptr++) { if (*args_ptr == '=') { *args_ptr = '\0'; args_ptr++; break; } } if (!strcmp (string_ptr, "help")) { args_info->help_given = 1; printHelp (); exit (0); } if (!strcmp (string_ptr, "version")) { args_info->version_given = 1; printVersion (); exit (0); } if (!strcmp (string_ptr, "port")) { if (args_info->port_given) { optError ("`--port' (`-p') option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --port=INT"); } args_info->port_given = 1; GET_INT_FROM_STRING_ARG (args_ptr, args_info->port_arg, "Must specify argument: --port=INT") } if (!strcmp (string_ptr, "config")) { if (args_info->config_given) { optError ("`--config' (`-c') option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --config=STRING"); } args_info->config_given = 1; args_info->config_arg = args_ptr; } if (!strcmp (string_ptr, "voices")) { if (args_info->voices_given) { optError ("`--voices' (`-v') option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --voices=INT"); } args_info->voices_given = 1; GET_INT_FROM_STRING_ARG (args_ptr, args_info->voices_arg, "Must specify argument: --voices=INT") } if (!strcmp (string_ptr, "logfile")) { if (args_info->logfile_given) { optError ("`--logfile' (`-l') option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --logfile=STRING"); } args_info->logfile_given = 1; args_info->logfile_arg = args_ptr; } if (!strcmp (string_ptr, "pidfile")) { if (args_info->pidfile_given) { optError ("`--pidfile' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --pidfile=STRING"); } args_info->pidfile_given = 1; args_info->pidfile_arg = args_ptr; } if (!strcmp (string_ptr, "record-file")) { if (args_info->record_file_given) { optError ("`--record-file' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --record-file=STRING"); } args_info->record_file_given = 1; args_info->record_file_arg = args_ptr; } if (!strcmp (string_ptr, "start-time")) { if (args_info->start_time_given) { optError ("`--start-time' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --start_time=STRING"); } args_info->start_time_given = 1; args_info->start_time_arg = args_ptr; } if (!strcmp (string_ptr, "end-time")) { if (args_info->end_time_given) { optError ("`--end-time' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --end-time=STRING"); } args_info->end_time_given = 1; args_info->end_time_arg = args_ptr; } if (!strcmp (string_ptr, "snd-device")) { if (args_info->snd_device_given) { optError ("`--snd-device' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --snd-device=STRING"); } args_info->snd_device_given = 1; args_info->snd_device_arg = args_ptr; } if (!strcmp (string_ptr, "snd-port")) { if (args_info->snd_port_given) { optError ("`--snd-port' option given more than once"); } if (!*args_ptr) { optError ("Must specify argument: --snd-port=INT"); } args_info->snd_port_given = 1; GET_INT_FROM_STRING_ARG (args_ptr, args_info->snd_port_arg, "Must specify argument: --snd-port=INT") } if (!strcmp (string_ptr, "playback-mode")) { if (args_info->playback_mode_given) { optError ("`--playback-mode' option given more than once"); } args_info->playback_mode_given = 1; } if (!strcmp (string_ptr, "record-mode")) { if (args_info->record_mode_given) { optError ("`--record-mode' option given more than once"); } args_info->record_mode_given = 1; } if (!strcmp (string_ptr, "nodaemon")) { if (args_info->nodaemon_given) { optError ("`--nodaemon' option given more than once"); } args_info->nodaemon_given = 1; } } else { switch (argv[1][1]) {
int parseCommonOpts(char *string, InitArgs *args, int is_jni) { int status = OPT_OK; if(strcmp(string, "-Xasyncgc") == 0) args->asyncgc = TRUE; else if(strncmp(string, "-Xms", 4) == 0 || (!is_jni && strncmp(string, "-ms", 3) == 0)) { char *value = string + (string[1] == 'm' ? 3 : 4); args->min_heap = parseMemValue(value); if(args->min_heap < MIN_HEAP) { optError(args, "Invalid minimum heap size: %s (min %dK)\n", string, MIN_HEAP/KB); status = OPT_ERROR; } } else if(strncmp(string, "-Xmx", 4) == 0 || (!is_jni && strncmp(string, "-mx", 3) == 0)) { char *value = string + (string[1] == 'm' ? 3 : 4); args->max_heap = parseMemValue(value); if(args->max_heap < MIN_HEAP) { optError(args, "Invalid maximum heap size: %s (min is %dK)\n", string, MIN_HEAP/KB); status = OPT_ERROR; } } else if(strncmp(string, "-Xss", 4) == 0 || (!is_jni && strncmp(string, "-ss", 3) == 0)) { char *value = string + (string[1] == 'm' ? 3 : 4); args->java_stack = parseMemValue(value); if(args->java_stack < MIN_STACK) { optError(args, "Invalid Java stack size: %s (min is %dK)\n", string, MIN_STACK/KB); status = OPT_ERROR; } } else if(strncmp(string, "-D", 2) == 0) { char *key = strcpy(sysMalloc(strlen(string + 2) + 1), string + 2); char *pntr; for(pntr = key; *pntr && (*pntr != '='); pntr++); if(*pntr) *pntr++ = '\0'; args->commandline_props[args->props_count].key = key; args->commandline_props[args->props_count++].value = pntr; } else if(strncmp(string, "-Xbootclasspath:", 16) == 0) { args->bootpath = string + 16; args->bootpath_p = args->bootpath_a = NULL; } else if(strncmp(string, "-Xbootclasspath/a:", 18) == 0) { args->bootpath_a = string + 18; } else if(strncmp(string, "-Xbootclasspath/p:", 18) == 0) { args->bootpath_p = string + 18; } else if(strcmp(string, "-Xnocompact") == 0) { args->compact_specified = TRUE; args->do_compact = FALSE; } else if(strcmp(string, "-Xcompactalways") == 0) { args->compact_specified = args->do_compact = TRUE; } else if(strcmp(string, "-Xtracejnisigs") == 0) { args->trace_jni_sigs = TRUE; #ifdef INLINING } else if(strcmp(string, "-Xnoinlining") == 0) { /* Turning inlining off is equivalent to setting code memory to zero */ args->codemem = 0; } else if(strcmp(string, "-Xnoprofiling") == 0) { args->profiling = FALSE; } else if(strcmp(string, "-Xnopatching") == 0) { args->branch_patching = FALSE; } else if(strcmp(string, "-Xnopatchingdup") == 0) { args->branch_patching_dup = FALSE; } else if(strcmp(string, "-Xnojoinblocks") == 0) { args->join_blocks = FALSE; } else if(strcmp(string, "-Xcodestats") == 0) { args->print_codestats = TRUE; } else if(strncmp(string, "-Xprofiling:", 12) == 0) { args->profile_threshold = strtol(string + 12, NULL, 0); } else if(strncmp(string, "-Xreplication:", 14) == 0) { char *pntr = string + 14; if(strcmp(pntr, "none") == 0) args->replication_threshold = INT_MAX; else if(strcmp(pntr, "always") == 0) args->replication_threshold = 0; else args->replication_threshold = strtol(pntr, NULL, 0); } else if(strncmp(string, "-Xcodemem:", 10) == 0) { char *pntr = string + 10; args->codemem = strncmp(pntr, "unlimited", 10) == 0 ? INT_MAX : parseMemValue(pntr); } else if(strcmp(string, "-Xshowreloc") == 0) { showRelocatability(); #endif #ifdef HAVE_PROFILE_STUBS } else if(strcmp(string, "-Xdumpstubsprofiles") == 0) { args->dump_stubs_profiles = TRUE; #endif /* Compatibility options */ } else { int i; for(i = 0; compat[i].option != NULL; i++) { int len = strlen(compat[i].option); if(strncmp(string, compat[i].option, len) == 0 && (((compat[i].flags & OPT_ARG) && string[len] == ':') || ((compat[i].flags & OPT_NOARG) && string[len] == '\0'))) break; } if(compat[i].option == NULL) status = OPT_UNREC; } return status; }