[OpenSDK-cvs] openSDK/loader opensdkAPI.cc, 1.4, 1.5 opensdkAPI.h, 1.4, 1.5
Status: Beta
Brought to you by:
nuno-lopes
From: Nuno L. <nun...@us...> - 2007-07-15 15:06:29
|
Update of /cvsroot/opensdk/openSDK/loader In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30504/loader Modified Files: opensdkAPI.cc opensdkAPI.h Log Message: add a new function: resolve_case_insensitive_path, and use it in the fopen/open wrappers Index: opensdkAPI.cc =================================================================== RCS file: /cvsroot/opensdk/openSDK/loader/opensdkAPI.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- opensdkAPI.cc 8 Mar 2007 22:34:19 -0000 1.4 +++ opensdkAPI.cc 15 Jul 2007 15:06:14 -0000 1.5 @@ -23,6 +23,8 @@ #include <OVirtualRobotComm.h> #include <main.h> #include <pthread.h> +#include <ctype.h> +#include <glob.h> static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -59,6 +61,7 @@ return oSUCCESS; } + OStatus GetJointValue(OPrimitiveID id, OJointValue* value) { memset(value, 0, sizeof(OJointValue)); @@ -66,9 +69,44 @@ return oSUCCESS; } + OStatus GetSensorValue(OPrimitiveID id, OSensorValue* value) { memset(value, 0, sizeof(OSensorValue)); value->value = VirtualRobotComm_get_sensor_reading(id); return oSUCCESS; } + + +/** resolve a case insensitive path. returns a dinamically allocated string, which you are responsible to free() */ +char* resolve_case_insensitive_path(const char *path) +{ + char *pattern = (char*)malloc(strlen(path) * 4 + 1); // allocate enough space for the worst case + char *tmp = pattern; + + while (*path) { + if (!isalpha(*path)) { + *tmp++ = *path++; + continue; + } + + *tmp++ = '['; + *tmp++ = tolower(*path); + *tmp++ = toupper(*path); + *tmp++ = ']'; + + ++path; + } + + *tmp = '\0'; + + glob_t globbuf; + if (glob(pattern, GLOB_NOSORT, NULL, &globbuf) == 0) { + tmp = strdup(globbuf.gl_pathv[0]); + } else { + tmp = strdup(path); + } + + globfree(&globbuf); + return tmp; +} Index: opensdkAPI.h =================================================================== RCS file: /cvsroot/opensdk/openSDK/loader/opensdkAPI.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- opensdkAPI.h 8 Mar 2007 22:34:19 -0000 1.4 +++ opensdkAPI.h 15 Jul 2007 15:06:14 -0000 1.5 @@ -39,5 +39,6 @@ OStatus _sendMessage(OServiceEntry entry, void *msg); OStatus GetJointValue(OPrimitiveID id, OJointValue* value); OStatus GetSensorValue(OPrimitiveID id, OSensorValue* value); +char* resolve_case_insensitive_path(const char *path); #endif |