📄 midpstartup.c
字号:
/* * @(#)midpStartup.c 1.15 02/10/14 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. *//*========================================================================= * Virtual Machine *========================================================================= * SYSTEM: MIDP native * SUBSYSTEM: Main program * FILE: midpStartup.c * OVERVIEW: Utilities required to start the MIDP *=======================================================================*//*========================================================================= * Include files *=======================================================================*/#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include <stdio.h>#include <kni.h>#include "midpMalloc.h"#include "midpServices.h"#include "commandState.h"#include "storage.h"/*========================================================================= * global variables *=======================================================================*/static char* MidpCommandLineClassPath;/*========================================================================= * local variables *=======================================================================*/static const char* AppJarFile = "suite.jar";/* value "suites.utf" is from com.sun.midp.midletsuite.Installer */static const char* SuitesFile = "suites.utf";static const char* MidpUsageText ="\n""Usage: midp [<options>]\n"" Run the Graphical MIDlet Suite Manager.\n""\n"" or midp [<options>] -autotest [-domain <dname>] <descriptor URL>\n"" Install, and run MIDlet number 1, and remove a MIDlet repeatedly.\n"" Overwrite the existing suite and removing the RMS data if \n"" necessary. Stop and remove the previously installed test suite\n"" when a 404 code is received from the server. Use the maximum\n"" security domain when installing unsigned suites so that all\n"" permissions are allowed, but not requested.\n"" -domain: security domain to use for installing unsigned suites\n""\n"" or midp [<options>] -transient [-force] [-domain <dname>] [-removeRMS]\n"" <descriptor URL> [<MIDlet name>]\n"" Install, run, and remove a MIDlet.\n"" -force: Force the installed version to be overwritten\n"" -domain: security domain to use for installing unsigned suites\n"" -removeRMS: Remove the RMS data when overwriting a suite\n""\n"" or midp [<options>] -install [-force] [-domain <dname>] [-removeRMS]\n"" <descriptor URL>\n"" Install a MIDlet suite using the URL of a descriptor.\n"" -force: Force the installed version to be overwritten\n"" -domain: security domain to use for unsigned suites\n"" -removeRMS: Remove the RMS data when overwriting a suite\n""\n"" or midp [<options>] -run (<suite number> | <storage name>)\n"" [<name of MIDlet to run>]\n"" Run a MIDlet of an installed suite. If the name or number of the \n"" MIDlet is not provided and the suite has multiple MIDlets,\n"" the user will be prompted to select a MIDlet from the\n"" suite to run.\n""\n"" or midp [<options>] -remove (<suite number> | <storage name> | all)\n"" Remove an installed MIDlet suite or all suites.\n"#ifdef INTERNAL_BUILD" To clean up RMS space used when running a MIDlet from the \n"" classpath, use the storage name \"run_by_class_storage_\".\n""\n"" or midp [<options>] [-domain <dname>] [-Xdescriptor <filename>] <class>\n"" Run a MIDlet from the classpath.\n"" -domain: run under a different security domain than untrusted\n"" -Xdescriptor: Get the MIDlet properties from this file\n""\n"" or midp [<options>] [-domain <dname>] -Xdescriptor <filename>\n"" Select a MIDlet to run from a local MIDlet suite descriptor.\n"" -domain: run under a different security domain than untrusted\n"" -Xdescriptor: Display a selection of MIDlets from this file\n"#endif /* INTERNAL_BUILD */"\n"" or midp [<options>] -list\n"" List the installed MIDlet suites by number and name.\n""\n"" or midp [<options>] -storageNames\n"" List the unique storage names of the installed MIDlet suites,\n"" one per line.\n""\n"" or midp -version\n"" Show version information and exit.\n""\n"" or midp -help\n"" Show this message and exit.\n""\n""where <suite number> is the number of a suite as displayed by the list\n""command,\n""\n""<storage name> is the unique name a suite is stored by,\n""\n""<dname> is the name of a domain in the security policy file,\n""\n""and <options> include:\n"" -classpath <path> directories and zip files to search for classes\n"" -D<property>=<value> Override configuration file settings\n""";/*========================================================================= * function prototypes *=======================================================================*/char* midpFixMidpHome(char* cmd);void midpParseArgs(int argc, char* argv[]);int midpSetClassPath(char* storageName, char** userClassPath);void midpPrintUsage(char* progname);static char* buildJarPath(char* suiteStorageName);static char* getStorageNameFromNumber(char* numberString);static char* readSuiteStorageName(char** ppszError, int handle);/*========================================================================= * FUNCTION: midpFixMidpHome * OVERVIEW: Fixup routine for MIDP_HOME directory when the midp * executable is invoked from some other current working * directory. * * The search for the "lib" directory is in the order of: * - current directory (in case midp is in the PATH * and the current directory is the right place) * - parent directory of the midp executable * - grandparent directory of the midp executable * * If 'cmd' does not contain any directory (i.e. just * "midp"), the search starts from the current directory. * Otherwise, it starts from the directory that midp is * located (i.e. "bin" if 'cmd' is "bin/midp"). * INTERFACE: * parameters: cmd: 'C' string of the command used to start * the MIDP. * returns: 'C' string: A pointer to the "found" MIDP directory. *=======================================================================*/char*midpFixMidpHome(char *cmd) { int i = 0; char* filesep; char* lastsep; char* midp_home; char libdir[MAX_FILENAME_LENGTH+1]; /* temp buffer to the lib dir */ struct stat statbuf; /* * If MIDP_HOME is set, just use it. Does not check if MIDP_HOME is * pointing to a directory contain "lib". */ if (!getenv("MIDP_HOME")) { filesep = getFileSeparator(); /* Look for the last slash in the pathanme. */ if ((lastsep = strrchr(cmd, (int) *filesep)) != 0) { *lastsep = '\0'; } /* start from the current directory */ sprintf(libdir, "%s%c.%clib", lastsep ? cmd : ".", *filesep, *filesep); /* try to search for "lib" 3 times only (see above) */ while (i < 3) { /* found it and it is a directory */ if (!stat(libdir, &statbuf) && (statbuf.st_mode & S_IFDIR)) { break; } /* strip off "lib" to add 1 more level of ".." */ *(strrchr(libdir, (int) *filesep)) = '\0'; strcat(libdir, filesep); strcat(libdir, ".."); strcat(libdir, filesep); strcat(libdir, "lib"); i++; } /* tried 3 times, and still cannot find "lib" */ if (i == 3) { fprintf(stderr, "Warning: cannot find lib subdirectory.\n" "Please specify MIDP_HOME environment variable such " "that $MIDP_HOME%clib contains the proper configuration " "files.\n", *filesep); /* assume the default to the be the current directory */ sprintf(libdir, ".%clib", *filesep); } /* save the parent directory and strip off "lib" from the path */ midp_home = midpStrdup(libdir); if (midp_home == NULL) { fprintf(stderr, "Out of memory: could not allocate midp_home.\n"); exit(-1); } *(strrchr(midp_home, (int) *filesep)) = '\0'; if (lastsep != 0) { /* restore the last file separator for cmd */ *lastsep = *filesep; } } else { /* * make copy of MIDP_HOME env var because we want to call * midpFree() on midp_home, but we cannot do that on the * pointer returned by getenv(). And we do not know whether * the memory pointed to by midp_home is from getenv() or * midpStrdup() in main(). */ midp_home = midpStrdup(getenv("MIDP_HOME")); if (midp_home == NULL) { fprintf(stderr, "Out of memory: could not allocate midp_home.\n"); exit(-1); } } return midp_home;}/*========================================================================= * FUNCTION: midpParseArgs * OVERVIEW: Process command-line arguments. Any arguments not * recognized as MIDP arguments will be processed as * VM arguments. * * If an unknown argument or invalid parameter is * encountered, usage text will be printed to stdout * and the process will be terminated. * INTERFACE: * parameters: argc: The total number of arguments * argv: An array of 'C' strings containing the * arguments * returns: none *=======================================================================*/voidmidpParseArgs(int argc, char* argv[]) { char* progName = NULL; char** ppTarget; /* where to put the target of the command */ int currentArg; /* Save program name for showing the usage */ if (argc > 0) { progName = argv[0]; } memset(&MidpCommandState, 0, sizeof(MidpCommandState)); /* no options means, run a MIDlet class from ROM or the classpath */ MidpCommandState.initialCommand = RUN_CLASS; ppTarget = &MidpCommandState.midletClassName; for (currentArg = 1; currentArg < argc; currentArg++) { if (strcmp(argv[currentArg], "-help") == 0) { midpPrintUsage(progName); exit(0); } else if (strcmp(argv[currentArg], "-version") == 0) { fprintf(stdout, "Profile Spec : %s\n", getInternalProp("microedition.profiles")); fprintf(stdout, "Profile Impl : %s %s\n",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -