static std::string GetTrackName(const char *category, const char *trackName) { void *trackHandle; std::string name; sprintf(buf, "tracks/%s/%s/%s.%s", category, trackName, trackName, TRKEXT); trackHandle = GfParmReadFile(buf, GFPARM_RMODE_STD); if (trackHandle) { name = GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_NAME, trackName); } else { GfTrace("Could not read file %s\n", buf); return 0; } GfParmReleaseHandle(trackHandle); return name; }
/** Get the track category name from the directory name @param category track category directory @return category display name @ingroup racemantools */ char * RmGetCategoryName(char *category) { void *categoryHandle; char *name; const int BUFSIZE = 1024; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "data/tracks/%s.%s", category, TRKEXT); categoryHandle = GfParmReadFile(buf, GFPARM_RMODE_STD); /* don't release, the name is used later */ if (categoryHandle) { name = strdup(GfParmGetStr(categoryHandle, TRK_SECT_HDR, TRK_ATT_NAME, category)); } else { GfTrace("File %s has pb\n", buf); return strdup(""); } GfParmReleaseHandle(categoryHandle); return name; }
static void rmUpdateTrackInfo(void) { void *trackHandle; float tmp; tTrack *trk; const int BUFSIZE = 1024; char buf[BUFSIZE]; snprintf(buf, BUFSIZE, "tracks/%s/%s/%s.%s", CategoryList->name, ((tFList*)CategoryList->userData)->name, ((tFList*)CategoryList->userData)->name, TRKEXT); trackHandle = GfParmReadFile(buf, GFPARM_RMODE_STD); /* COMMENT VALID? don't release, the name is used later */ if (!trackHandle) { GfTrace("File %s has pb\n", buf); return; } trk = ts->trackItf.trkBuild(buf); GfuiLabelSetText(scrHandle, DescId, GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_DESCR, "")); GfuiLabelSetText(scrHandle, AuthorId, GfParmGetStr(trackHandle, TRK_SECT_HDR, TRK_ATT_AUTHOR, "")); tmp = GfParmGetNum(trackHandle, TRK_SECT_MAIN, TRK_ATT_WIDTH, NULL, 0); snprintf(buf, BUFSIZE, "%.2f m", tmp); GfuiLabelSetText(scrHandle, WidthId, buf); tmp = trk->length; snprintf(buf, BUFSIZE, "%.2f m", tmp); GfuiLabelSetText(scrHandle, LengthId, buf); if (trk->pits.nMaxPits != 0) { snprintf(buf, BUFSIZE, "%d", trk->pits.nMaxPits); GfuiLabelSetText(scrHandle, PitsId, buf); } else { GfuiLabelSetText(scrHandle, PitsId, "none"); } ts->trackItf.trkShutdown(); GfParmReleaseHandle(trackHandle); }
/** Add a button to a menu screen. @ingroup gui @param scr Screen (menu) handle @param text Text of the button @param tip Text of the tip displayed when the button is focused @param userdata Parameter of the Push function @param onpush Callback when the button is pushed @return Button Id */ int GfuiMenuButtonCreate(void *scr, char *text, char *tip, void *userdata, tfuiCallback onpush) { tMnuCallbackInfo *cbinfo; int xpos, ypos; int nbItems = ((tGfuiScreen*)scr)->nbItems++; int bId; if (nbItems < 11) { xpos = 320; ypos = 380 - 30 * nbItems; } else { if (nbItems > 22) { GfTrace("Too many items in that menu !!!\n"); return -1; } xpos = 380; ypos = 380 - 30 * (nbItems - 11); } cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo)); cbinfo->screen = scr; cbinfo->labelId = GfuiTipCreate(scr, tip, strlen(tip)); GfuiVisibilitySet(scr, cbinfo->labelId, 0); bId = GfuiButtonCreate(scr, text, GFUI_FONT_LARGE, xpos, ypos, GFUI_BTNSZ, GFUI_ALIGN_HC_VB, 0, userdata, onpush, (void*)cbinfo, dispInfo, remInfo); return bId; }
/** Interactive track selection @param vs Pointer on a tRmTrackSelect structure (cast to void *) @warning The race manager's parameters are updated but not saved. @ingroup racemantools */ void RmTrackSelect(void *vs) { const char *defaultTrack; const char *defaultCategory; tFList *CatCur; tFList *TrList, *TrCur; int Xpos, Ypos, DX, DY; int curTrkIdx; const int BUFSIZE = 1024; char buf[BUFSIZE]; char path[BUFSIZE]; ts = (tRmTrackSelect*)vs; /* Get the list of categories directories */ CategoryList = GfDirGetList("tracks"); if (CategoryList == NULL) { GfTrace("RmTrackSelect: No track category available\n"); return; } CatCur = CategoryList; do { CatCur->dispName = RmGetCategoryName(CatCur->name); if (strlen(CatCur->dispName) == 0) { GfTrace("RmTrackSelect: No definition for track category %s\n", CatCur->name); return; } /* get the tracks in the category directory */ snprintf(buf, BUFSIZE, "tracks/%s", CatCur->name); TrList = GfDirGetList(buf); if (TrList == NULL) { GfTrace("RmTrackSelect: No track for category %s available\n", CatCur->name); return; } TrList = TrList->next; /* get the first one */ CatCur->userData = (void*)TrList; TrCur = TrList; do { TrCur->dispName = RmGetTrackName(CatCur->name, TrCur->name); if (strlen(TrCur->dispName) == 0) { GfTrace("RmTrackSelect: No definition for track %s\n", TrCur->name); return; } TrCur = TrCur->next; } while (TrCur != TrList); CatCur = CatCur->next; } while (CatCur != CategoryList); curTrkIdx = (int)GfParmGetNum(ts->param, RM_SECT_TRACKS, RE_ATTR_CUR_TRACK, NULL, 1); snprintf(path, BUFSIZE, "%s/%d", RM_SECT_TRACKS, curTrkIdx); defaultCategory = GfParmGetStr(ts->param, path, RM_ATTR_CATEGORY, CategoryList->name); /* XXX coherency check */ defaultTrack = GfParmGetStr(ts->param, path, RM_ATTR_NAME, ((tFList*)CategoryList->userData)->name); CatCur = CategoryList; do { if (strcmp(CatCur->name, defaultCategory) == 0) { CategoryList = CatCur; TrCur = (tFList*)(CatCur->userData); do { if (strcmp(TrCur->name, defaultTrack) == 0) { CatCur->userData = (void*)TrCur; break; } TrCur = TrCur->next; } while (TrCur != TrList); break; } CatCur = CatCur->next; } while (CatCur != CategoryList); scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, rmtsActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(scrHandle, "data/img/splash-qrtrk.png"); rmtsAddKeys(); GfuiTitleCreate(scrHandle, "Select Track", 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", 80, 400, GFUI_ALIGN_HC_VB, 0, (void*)0, rmCatPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); CatLabelId = GfuiLabelCreate(scrHandle, CategoryList->dispName, GFUI_FONT_LARGE_C, 320, 400, GFUI_ALIGN_HC_VB, 30); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", 540, 400, GFUI_ALIGN_HC_VB, 0, (void*)1, rmCatPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", 80, 370, GFUI_ALIGN_HC_VB, 0, (void*)0, rmtsPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); TrackLabelId = GfuiLabelCreate(scrHandle, ((tFList*)CategoryList->userData)->dispName, GFUI_FONT_LARGE_C, 320, 370, GFUI_ALIGN_HC_VB, 30); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", 540, 370, GFUI_ALIGN_HC_VB, 0, (void*)1, rmtsPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); MapId = GfuiStaticImageCreate(scrHandle, 320, 100, 260, 195, rmGetMapName(buf, BUFSIZE)); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmtsSelect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Back", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, ts->prevScreen, rmtsDeactivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); Xpos = 20; Ypos = 320; DX = 110; DY = 30; GfuiLabelCreate(scrHandle, "Description:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); DescId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 50); Ypos -= DY; GfuiLabelCreate(scrHandle, "Author:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); AuthorId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Length:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); LengthId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Width:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); WidthId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Pits:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); PitsId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); rmUpdateTrackInfo(); GfuiScreenActivate(scrHandle); }
/** Initialize the cars for a race. The car are positionned on the starting grid. @return 0 Ok -1 Error */ int ReInitCars(void) { int nCars; int index; int i, j, k; char *cardllname; int robotIdx; tModInfo *curModInfo; tRobotItf *curRobot; void *handle; char *category; void *cathdle; void *carhdle; void *robhdle; tCarElt *elt; char *focused; char *str; int focusedIdx; void *params = ReInfo->params; /* Get the number of cars racing */ nCars = GfParmGetEltNb(params, RM_SECT_DRIVERS_RACING); GfOut("loading %d cars\n", nCars); FREEZ(ReInfo->carList); ReInfo->carList = (tCarElt*)calloc(nCars, sizeof(tCarElt)); FREEZ(ReInfo->rules); ReInfo->rules = (tRmCarRules*)calloc(nCars, sizeof(tRmCarRules)); focused = GfParmGetStr(ReInfo->params, RM_SECT_DRIVERS, RM_ATTR_FOCUSED, ""); focusedIdx = (int)GfParmGetNum(ReInfo->params, RM_SECT_DRIVERS, RM_ATTR_FOCUSEDIDX, NULL, 0); index = 0; for (i = 1; i < nCars + 1; i++) { /* Get Shared library name */ sprintf(path, "%s/%d", RM_SECT_DRIVERS_RACING, i); cardllname = GfParmGetStr(ReInfo->params, path, RM_ATTR_MODULE, ""); robotIdx = (int)GfParmGetNum(ReInfo->params, path, RM_ATTR_IDX, NULL, 0); sprintf(path, "%sdrivers/%s/%s.%s", GetLibDir (), cardllname, cardllname, DLLEXT); /* load the robot shared library */ if (GfModLoad(CAR_IDENT, path, ReInfo->modList)) { GfTrace("Pb with loading %s driver\n", path); break; } /* search for corresponding index */ for (j = 0; j < MAX_MOD_ITF; j++) { if ((*(ReInfo->modList))->modInfo[j].index == robotIdx) { /* good robot found */ curModInfo = &((*(ReInfo->modList))->modInfo[j]); GfOut("Driver's name: %s\n", curModInfo->name); /* retrieve the robot interface (function pointers) */ curRobot = (tRobotItf*)calloc(1, sizeof(tRobotItf)); curModInfo->fctInit(robotIdx, (void*)(curRobot)); sprintf(buf, "%sdrivers/%s/%s.xml", GetLocalDir(), cardllname, cardllname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); if (!robhdle) { sprintf(buf, "drivers/%s/%s.xml", cardllname, cardllname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); } if (robhdle != NULL) { elt = &(ReInfo->carList[index]); GF_TAILQ_INIT(&(elt->_penaltyList)); elt->index = index; elt->robot = curRobot; elt->_paramsHandle = robhdle; elt->_driverIndex = robotIdx; strncpy(elt->_modName, cardllname, MAX_NAME_LEN - 1); elt->_modName[MAX_NAME_LEN - 1] = 0; sprintf(path, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, robotIdx); strncpy(elt->_name, GfParmGetStr(robhdle, path, ROB_ATTR_NAME, "<none>"), MAX_NAME_LEN - 1); elt->_name[MAX_NAME_LEN - 1] = 0; strncpy(elt->_teamname, GfParmGetStr(robhdle, path, ROB_ATTR_TEAM, "<none>"), MAX_NAME_LEN - 1); elt->_teamname[MAX_NAME_LEN - 1] = 0; strncpy(elt->_carName, GfParmGetStr(robhdle, path, ROB_ATTR_CAR, ""), MAX_NAME_LEN - 1); elt->_carName[MAX_NAME_LEN - 1] = 0; elt->_raceNumber = (int)GfParmGetNum(robhdle, path, ROB_ATTR_RACENUM, (char*)NULL, 0); if (strcmp(GfParmGetStr(robhdle, path, ROB_ATTR_TYPE, ROB_VAL_ROBOT), ROB_VAL_ROBOT)) { elt->_driverType = RM_DRV_HUMAN; } else { elt->_driverType = RM_DRV_ROBOT; } elt->_skillLevel = 0; str = GfParmGetStr(robhdle, path, ROB_ATTR_LEVEL, ROB_VAL_SEMI_PRO); for(k = 0; k < (int)(sizeof(level_str)/sizeof(char*)); k++) { if (strcmp(level_str[k], str) == 0) { elt->_skillLevel = k; break; } } elt->_startRank = index; elt->_pos = index+1; elt->_remainingLaps = ReInfo->s->_totLaps; /* handle contains the drivers modifications to the car */ /* Read Car model specifications */ sprintf(buf, "cars/%s/%s.xml", elt->_carName, elt->_carName); GfOut("Car Specification: %s\n", buf); carhdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); category = GfParmGetStr(carhdle, SECT_CAR, PRM_CATEGORY, NULL); sprintf(buf, "Loading Driver %-20s... Car: %s", curModInfo->name, elt->_carName); RmLoadingScreenSetText(buf); if (category != 0) { strncpy(elt->_category, category, MAX_NAME_LEN - 1); elt->_category[MAX_NAME_LEN - 1] = '\0'; /* Read Car Category specifications */ sprintf(buf, "categories/%s.xml", category); GfOut("Category Specification: %s\n", buf); cathdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); if (GfParmCheckHandle(cathdle, carhdle)) { GfTrace("Car %s not in Category %s (driver %s) !!!\n", elt->_carName, category, elt->_name); break; } carhdle = GfParmMergeHandles(cathdle, carhdle, GFPARM_MMODE_SRC | GFPARM_MMODE_DST | GFPARM_MMODE_RELSRC | GFPARM_MMODE_RELDST); curRobot->rbNewTrack(robotIdx, ReInfo->track, carhdle, &handle, ReInfo->s); if (handle != NULL) { if (GfParmCheckHandle(carhdle, handle)) { GfTrace("Bad Car parameters for driver %s\n", elt->_name); break; } handle = GfParmMergeHandles(carhdle, handle, GFPARM_MMODE_SRC | GFPARM_MMODE_DST | GFPARM_MMODE_RELSRC | GFPARM_MMODE_RELDST); } else { handle = carhdle; } elt->_carHandle = handle; //GfParmWriteFile("toto.xml", handle, "toto"); } else { elt->_category[0] = '\0'; GfTrace("Bad Car category for driver %s\n", elt->_name); break; } index ++; } else { GfTrace("Pb No description file for driver %s\n", cardllname); } break; } } } nCars = index; /* real number of cars */ if (nCars == 0) { GfTrace("No driver for that race...\n"); return -1; } else { GfOut("%d drivers ready to race\n", nCars); } ReInfo->s->_ncars = nCars; FREEZ(ReInfo->s->cars); ReInfo->s->cars = (tCarElt **)calloc(nCars, sizeof(tCarElt *)); for (i = 0; i < nCars; i++) { ReInfo->s->cars[i] = &(ReInfo->carList[i]); } // TODO: reconsider splitting the call into one for cars, track and maybe other objects. // I stuff for now anything into one call because collision detection works with the same // library on all objects, so it is a bit dangerous to distribute the handling to various // locations (because the library maintains global state like a default collision handler etc.). ReInfo->_reSimItf.init(nCars, ReInfo->track); initStartingGrid(); initPits(); return 0; }
/* * Function * windowsModLoad * * Description * * * Parameters * * * Return * * * Remarks * */ static int windowsModLoad(unsigned int gfid, char *sopath, tModList **modlist) { tfModInfo fModInfo; /* init function of the modules */ HMODULE handle; /* */ tModList *curMod; char dname[256]; /* name of the funtions */ char *lastSlash; curMod = (tModList*)calloc(1, sizeof(tModList)); GfOut("loading windows module %s\n",sopath); lastSlash = strrchr(sopath, '/'); if (lastSlash) { strcpy(dname, lastSlash+1); } else { strcpy(dname, sopath); } dname[strlen(dname) - 4] = 0; /* cut .dll */ GfOut("LoadLibrary from %s\n",sopath); /* This one doesn't load dynamically... */ if (strcmp(sopath,"modules/graphic/ssggraph.dll") == 0) { ssggraph(curMod->modInfo); if (*modlist == NULL) { *modlist = curMod; curMod->next = curMod; } else { curMod->next = (*modlist)->next; (*modlist)->next = curMod; *modlist = curMod; } GfOut("%s loaded staticaly\n",sopath); return 0; } handle = LoadLibrary( sopath ); GfOut("LoadLibrary return from %s\n",sopath); if (handle != NULL) { if ((fModInfo = (tfModInfo)GetProcAddress(handle, dname)) != NULL) { /* DLL loaded, init function exists, call it... */ GfOut("calling modInfo from %s\n",sopath); if (fModInfo(curMod->modInfo) == 0) { GfOut(">>> %s >>>\n", sopath); curMod->handle = handle; curMod->sopath = strdup(sopath); if (*modlist == NULL) { *modlist = curMod; curMod->next = curMod; } else { curMod->next = (*modlist)->next; (*modlist)->next = curMod; *modlist = curMod; } } else { FreeLibrary(handle); GfTrace("windowsModLoad: Module: %s not loaded\n", dname); return -1; } } else { GfTrace("windowsModLoad: ... can't find proc %s\n", dname); FreeLibrary(handle); return -1; } } else { GfTrace("windowsModLoad: ... can't open dll %s\n", sopath); return -1; } GfOut("windows module %s loaded\n",sopath); return 0; }
/* * Function * windowsModInfoDir * * Description * Load the modules contained in a directory and retrieve info * * Parameters * dir directory to search (relative) * modlist list of module description structure * * Return * >=0 number of modules loaded * -1 error * * Remarks * */ static int windowsModInfoDir(unsigned int gfid, char *dir, int level, tModList **modlist) { tfModInfo fModInfo; /* init function of the modules */ char dname[256]; /* name of the funtions */ char sopath[256]; /* path of the lib[x].so */ HMODULE handle; /* */ int modnb; /* number on loaded modules */ tModList *curMod; tModList *cMod; int prio; modnb = 0; curMod = (tModList*)calloc(1, sizeof(tModList)); /* open the current directory */ _finddata_t FData; char Dir_name[ 1024 ]; sprintf( Dir_name, "%s\\*.*", dir ); GfOut("trying dir info %s\n",dir); long Dirent = _findfirst( Dir_name, &FData ); if ( Dirent != -1 ) { do { if (((strlen(FData.name) > 5) && (strcmp(".dll", FData.name+strlen(FData.name)-4) == 0)) || (level == 1)) { /* xxxx.dll */ if (level == 1) { sprintf(sopath, "%s/%s/%s.dll", dir, FData.name, FData.name); strcpy(dname, FData.name); } else { sprintf(sopath, "%s/%s", dir, FData.name); strcpy(dname, FData.name); dname[strlen(dname) - 4] = 0; /* cut .dll */ } handle = LoadLibrary( sopath ); if (handle != NULL) { if ((fModInfo = (tfModInfo)GetProcAddress(handle, dname)) != NULL) { GfOut("Request Info for %s\n", sopath); /* DLL loaded, init function exists, call it... */ if (fModInfo(curMod->modInfo) == 0) { modnb++; curMod->handle = NULL; curMod->sopath = strdup(sopath); /* add the module in the list */ if (*modlist == NULL) { *modlist = curMod; curMod->next = curMod; } else { /* sort by prio */ prio = curMod->modInfo[0].prio; if (prio >= (*modlist)->modInfo[0].prio) { curMod->next = (*modlist)->next; (*modlist)->next = curMod; *modlist = curMod; } else { cMod = *modlist; do { if (prio < cMod->next->modInfo[0].prio) { curMod->next = cMod->next; cMod->next = curMod; break; } cMod = cMod->next; } while (cMod != *modlist); } } FreeLibrary(handle); curMod = (tModList*)calloc(1, sizeof(tModList)); } else { FreeLibrary(handle); GfTrace("windowsModInfoDir: Module: %s not retained\n", dname); } } else { GfTrace("windowsModInfoDir: ... can't find proc %s\n", dname); FreeLibrary(handle); } } else { GfTrace("windowsModInfoDir: ... can't open dll %s\n", sopath); } } } while ( _findnext( Dirent, &FData ) != -1 ); } _findclose( Dirent ); free(curMod); return modnb; }
/* * Function * windowsModLoadDir * * Description * Load the modules contained in a directory * * Parameters * dir directory to search (relative) * modlist list of module description structure * * Return * >=0 number of modules loaded * -1 error * * Remarks * */ static int windowsModLoadDir(unsigned int gfid, char *dir, tModList **modlist) { tfModInfo fModInfo; /* init function of the modules */ char dname[256]; /* name of the funtions */ char sopath[256]; /* path of the lib[x].so */ HMODULE handle; /* */ int modnb; /* number on loaded modules */ tModList *curMod; tModList *cMod; int prio; modnb = 0; curMod = (tModList*)calloc(1, sizeof(tModList)); // parcours du r�pertoire _finddata_t FData; char Dir_name[ 1024 ]; sprintf( Dir_name, "%s\\*.dll", dir ); long Dirent = _findfirst( Dir_name, &FData ); if ( Dirent != -1 ) do { sprintf(sopath, "%s\\%s", dir, FData.name); handle = LoadLibrary( sopath ); if (handle != NULL) { if ((fModInfo = (tfModInfo)GetProcAddress(handle, dname)) != NULL) { /* DLL loaded, init function exists, call it... */ if ((fModInfo(curMod->modInfo) == 0) && (curMod->modInfo[0].gfId == gfid)) { GfOut(">>> %s loaded >>>\n", sopath); modnb++; curMod->handle = handle; curMod->sopath = strdup(sopath); /* add the module in the list */ if (*modlist == NULL) { *modlist = curMod; curMod->next = curMod; } else { /* sort by prio */ prio = curMod->modInfo[0].prio; if (prio >= (*modlist)->modInfo[0].prio) { curMod->next = (*modlist)->next; (*modlist)->next = curMod; *modlist = curMod; } else { cMod = *modlist; do { if (prio < cMod->next->modInfo[0].prio) { curMod->next = cMod->next; cMod->next = curMod; break; } cMod = cMod->next; } while (cMod != *modlist); } } curMod = (tModList*)calloc(1, sizeof(tModList)); } else { FreeLibrary(handle); GfTrace("windowsModLoadDir: Module: %s not retained\n", dname); } } else { GfTrace("windowsModLoadDir: ... can't find proc %s\n", dname); FreeLibrary(handle); _findclose( Dirent ); return -1; } } } while ( _findnext( Dirent, &FData ) != -1 ); _findclose( Dirent ); free(curMod); return modnb; }
/* * Function * windowsModInfo * * Description * * * Parameters * * * Return * * * Remarks * */ static int windowsModInfo(unsigned int gfid, char *sopath, tModList **modlist) { tfModInfo fModInfo; /* init function of the modules */ HMODULE handle; /* */ tModList *curMod; char dname[256]; /* name of the funtions */ char *lastSlash; tModList *cMod; int prio; curMod = (tModList*)calloc(1, sizeof(tModList)); lastSlash = strrchr(sopath, '/'); if (lastSlash) { strcpy(dname, lastSlash+1); } else { strcpy(dname, sopath); } dname[strlen(dname) - 4] = 0; /* cut .dll */ handle = LoadLibrary( sopath ); if (handle != NULL) { if ((fModInfo = (tfModInfo)GetProcAddress(handle, dname)) != NULL) { /* DLL loaded, init function exists, call it... */ if (fModInfo(curMod->modInfo) == 0) { GfOut("Request Info for %s\n", sopath); curMod->handle = NULL; curMod->sopath = strdup(sopath); if (*modlist == NULL) { *modlist = curMod; curMod->next = curMod; } else { /* sort by prio */ prio = curMod->modInfo[0].prio; if (prio >= (*modlist)->modInfo[0].prio) { curMod->next = (*modlist)->next; (*modlist)->next = curMod; *modlist = curMod; } else { cMod = *modlist; do { if (prio < cMod->next->modInfo[0].prio) { curMod->next = cMod->next; cMod->next = curMod; break; } cMod = cMod->next; } while (cMod != *modlist); } } FreeLibrary(handle); } else { FreeLibrary(handle); GfTrace("windowsModInfo: Module: %s not loaded\n", dname); return -1; } } else { GfTrace("windowsModInfo: ... %d\n", GetLastError()); FreeLibrary(handle); return -1; } } else { GfTrace("windowsModInfo: ... %d\n", GetLastError()); return -1; } return 0; }