📄 configuration.c
字号:
*=======================================================================*/void initProps (Property ** props, char *name, char *midp_home) { char pathname[MAX_FILENAME_LENGTH + 1]; int fd = -1 ; char * errStr; /* Property file can be relative or at midp_home variable */ (void)strcpy(pathname, midp_home); (void)strcat(pathname, getFileSeparator()); (void)strcat(pathname, name); if ((fd = storageOpen(&errStr, pathname, OPEN_READ)) != -1){ /* Read through the file one line at a time */ parseConfig (fd, props); /* Close the storage handle */ storageClose (&errStr, fd); } else { if (errStr != NULL) { fprintf (stderr, "Warning: could not open config file(%s): %s\n", pathname, errStr); storageFreeError(errStr); return; } }}/*========================================================================= * FUNCTION: findProp(Property * , char *) * TYPE: public operation * OVERVIEW: Return a value of a property key * INTERFACE: * parameters: Property *props * char *key * returns: char *result *=======================================================================*/static char * findProp (Property * prop, char* key) { Property * p= prop; while (p) { if (strcmp(key, p->key) == 0 ) return (p->value); p = p->next; } return(NULL);}/*========================================================================= * FUNCTION: setProp(Property *, char * , char *) * TYPE: public operation * OVERVIEW: Set a value of a property key, value pair * INTERFACE: * parameters: Property *props * char *key * char *value *=======================================================================*/static void setProp (Property **props, char* key , char* value ) { /* Try to find the property in the current pool. */ Property *p; for (p= *props; p; p = p->next){ if (strcmp(key, p->key) == 0 ){ midpFree (p->value); p->value = midpStrdup(value); /** * if midpStrdup fails we will just return without setting the value * to anything other than NULL */ return; } } /* If the value is not defined, add it now */ if (p = (Property *) midpMalloc (sizeof(Property))){ p->next = *props ; p->key = midpStrdup(key); p->value = midpStrdup(value); if ((p->key == NULL) || (p->value == NULL)) { /* * do nothing if there is no memory */ midpFree(p->key); midpFree(p->value); midpFree(p); return; } *props = p ; }}/*========================================================================= * FUNCTION: setInternalProp(char * , char *) * TYPE: public operation * OVERVIEW: Set a value of a property key, value pair * INTERFACE: * parameters: char *key * char *value *=======================================================================*/void setInternalProp (char* key , char* value ) { setProp(&implementationProperties, key, value);}/*========================================================================= * FUNCTION: getInternalProp(char *) * TYPE: public operation * OVERVIEW: Return a value of a property key * INTERFACE: * parameters: char *key * returns: char *result *=======================================================================*/char * getInternalProp (char* key) { char *result = findProp(implementationProperties, key) ; return (result? result : findProp(applicationProperties, key));}/*========================================================================= * FUNCTION: getInternalProp(char *) * TYPE: public operation * OVERVIEW: Return a value of a property key or the supplied default. * INTERFACE: * parameters: char *key * char *def * returns: char *result *=======================================================================*/char * getInternalPropDefault (char* key, char * def) { /* check the implementation specific configuration properties. */ char *result = findProp(implementationProperties, key) ; if (result == NULL) { /* check the apllication properties, as well. */ result = findProp(applicationProperties, key); } /* If the key was not found return the supplied default value. */ return (result? result : def);}/*========================================================================= * FUNCTION: getSystemProp(char *) * TYPE: public operation * OVERVIEW: Return a value of a property key * INTERFACE: * parameters: char *key * returns: char *result *=======================================================================*/char * getSystemProp (char* key ) { char *value = findProp(applicationProperties, key); if (value == NULL && (strcmp(key, "microedition.hostname") == 0)) { /* * If the host name was not configured, use the * native networking function to determine, * the name of the local host. */ value = getLocalHostName(); } return value;}/*========================================================================= * FUNCTION: setSystemProp(char*, char*) * TYPE: public operation * OVERVIEW: Set a value of a property key, value pair * INTERFACE: * parameters: char *key * char *value *=======================================================================*/void setSystemProp (char* key , char* value) { setProp(&applicationProperties, key, value);}static char* UnicodeToCString(jchar* uString, int length);/*========================================================================= * FUNCTION: getProperty0(Ljava.lang.String)Ljava.lang.String (STATIC) * CLASS: com.sun.midp.main.Configuration * TYPE: static native function * OVERVIEW: Return a property * INTERFACE (operand stack manipulation): * parameters: A string * returns: A string *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_OBJECTJava_com_sun_midp_main_Configuration_getProperty0() { jchar* uStr; char* key; char* value; int strLen; KNI_StartHandles(5); KNI_DeclareHandle(str); KNI_DeclareHandle(result); KNI_GetParameterAsObject(1, str); strLen = KNI_GetStringLength(str); uStr = (jchar*) midpMalloc(strLen * sizeof(jchar)); if (uStr == NULL) { KNI_ThrowNew("java/lang/OutOfMemoryError", ""); } else { KNI_GetStringRegion(str, 0, strLen, uStr); key = UnicodeToCString(uStr, strLen); midpFree(uStr); /* Look up the property value */ value = getInternalProp(key); midpFree(key); if (value != NULL) { KNI_NewStringUTF(value, result); } else { KNI_ReleaseHandle(result); } } KNI_EndHandlesAndReturnObject(result);}/*========================================================================= * FUNCTION: UnicodeToCString() * TYPE: internal operation on string objects * OVERVIEW: Get the contents of a string object in C/C++ string format. * INTERFACE: * parameters: String object pointer * returns: char* to the string in C/C++ format *=======================================================================*/static char* UnicodeToCString(jchar* uString, int length) { int i; char* cString; if (NULL == uString) { return NULL; } cString = (char*) midpMalloc((sizeof(char)*length) + 1); /* one for the zero terminator */ if (NULL == cString) { return NULL; } for (i = 0; i < length; i++) { cString[i] = (char)uString[i]; } /* Terminating C-string with zero */ cString[length] = 0; return cString;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -