From 6afadafa1e908df5de5f6233a49cfc57e5f0f8f1 Mon Sep 17 00:00:00 2001 From: Will Date: Thu, 5 Dec 2013 16:17:41 +0100 Subject: [PATCH] Start to abstract model --- source/g3d_viewer/main.cpp | 5 +- source/g3d_viewer/renderer.cpp | 12 +-- source/g3d_viewer/renderer.h | 4 +- source/glest_game/graphics/particle_type.cpp | 5 +- source/glest_game/graphics/renderer.cpp | 14 ++- source/glest_game/graphics/renderer.h | 2 +- source/glest_game/main/intro.cpp | 12 ++- source/glest_game/main/main.cpp | 20 ++--- source/glest_game/menu/menu_background.cpp | 24 ++--- source/glest_game/types/object_type.cpp | 5 +- source/glest_game/types/resource_type.cpp | 5 +- source/glest_game/types/skill_type.cpp | 5 +- .../graphics/gl/graphics_factory_basic_gl.h | 2 +- .../include/graphics/gl/graphics_factory_gl.h | 2 +- .../shared_lib/include/graphics/gl/model_gl.h | 3 + .../include/graphics/graphics_factory.h | 7 +- .../include/graphics/graphics_interface.h | 2 +- source/shared_lib/include/graphics/model.h | 7 +- .../include/graphics/model_manager.h | 2 +- .../sources/graphics/gl/model_gl.cpp | 20 +++++ .../sources/graphics/model_manager.cpp | 4 +- .../sources/platform/sdl/platform_util.cpp | 87 ++++++++++--------- 22 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 source/shared_lib/sources/graphics/gl/model_gl.cpp diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 1693be82..201ef73c 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -1280,9 +1280,8 @@ void MainWindow::loadModel(string path) { if(timer) timer->Stop(); delete model; - Model *tmpModel= new ModelGl(); - if(renderer) renderer->loadTheModel(tmpModel, modelPath); - model= tmpModel; + model = NULL; + model = renderer? renderer->newModel(rsGlobal, modelPath): NULL; statusbarText = getModelInfo(); string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY); diff --git a/source/g3d_viewer/renderer.cpp b/source/g3d_viewer/renderer.cpp index 55bce5a4..45393b08 100644 --- a/source/g3d_viewer/renderer.cpp +++ b/source/g3d_viewer/renderer.cpp @@ -196,9 +196,8 @@ Texture2D * Renderer::getNewTexture2D() { return newTexture; } -Model * Renderer::getNewModel() { - Model *newModel = modelManager->newModel(); - return newModel; +Model * Renderer::newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader) { + return modelManager->newModel(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); } void Renderer::init() { @@ -416,13 +415,6 @@ void Renderer::toggleGrid() { grid= grid? false: true; } -void Renderer::loadTheModel(Model *model, string file) { - model->setTextureManager(textureManager); - model->loadG3d(file); - textureManager->init(); - modelManager->init(); -} - void Renderer::renderTheModel(Model *model, float f) { if(model != NULL){ modelRenderer->begin(true, true, !wireframe, false, &meshCallbackTeamColor); diff --git a/source/g3d_viewer/renderer.h b/source/g3d_viewer/renderer.h index d58eafb0..c70b8eca 100644 --- a/source/g3d_viewer/renderer.h +++ b/source/g3d_viewer/renderer.h @@ -137,7 +137,6 @@ public: void toggleWireframe(); void toggleGrid(); - void loadTheModel(Model *model, string file); void renderTheModel(Model *model, float f); void manageParticleSystem(ParticleSystem *particleSystem); @@ -146,9 +145,8 @@ public: Texture2D *getPlayerColorTexture(PlayerColor playerColor); Texture2D * getNewTexture2D(); - Model * getNewModel(); - Model *newModel(ResourceScope rs) { return getNewModel(); } + Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string *sourceLoader=NULL); Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); } void initTextureManager(); diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 5cb2c3fe..eb1b99e5 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -170,10 +170,7 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d endPathWithSlash(currentPath); string path= modelNode->getAttribute("path")->getRestrictedValue(currentPath); - model= renderer->newModel(rsGame); - if(model) { - model->load(path, false, &loadedFileList, &parentLoader); - } + model= renderer->newModel(rsGame,path, false, &loadedFileList, &parentLoader); loadedFileList[path].push_back(make_pair(parentLoader,modelNode->getAttribute("path")->getRestrictedValue())); if(modelNode->hasChild("cycles")) { diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 77ce9f6b..a307966b 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -598,12 +598,10 @@ void Renderer::manageDeferredParticleSystems() { if(dynamic_cast(ps) != NULL) { GameParticleSystem *gps = dynamic_cast(ps); if(gps->getModelFileLoadDeferred() != "" && gps->getModel() == NULL) { - Model *model= newModel(rsGame); - if(model) { - std::map > > loadedFileList; - model->load(gps->getModelFileLoadDeferred(), false, &loadedFileList, NULL); - gps->setModel(model); - } + std::map > > loadedFileList; + Model *model= newModel(rsGame, gps->getModelFileLoadDeferred(), false, &loadedFileList, NULL); + if(model) + gps->setModel(model); } } manageParticleSystem(ps, rs); @@ -886,12 +884,12 @@ void Renderer::endLastTexture(ResourceScope rs, bool mustExistInList) { textureManager[rs]->endLastTexture(mustExistInList); } -Model *Renderer::newModel(ResourceScope rs){ +Model *Renderer::newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader){ if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return NULL; } - return modelManager[rs]->newModel(); + return modelManager[rs]->newModel(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); } void Renderer::endModel(ResourceScope rs, Model *model,bool mustExistInList) { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 6f832fa6..2c48c730 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -458,7 +458,7 @@ public: void endTexture(ResourceScope rs, Texture *texture,bool mustExistInList=false); void endLastTexture(ResourceScope rs, bool mustExistInList=false); - Model *newModel(ResourceScope rs); + Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string *sourceLoader=NULL); void endModel(ResourceScope rs, Model *model, bool mustExistInList=false); void endLastModel(ResourceScope rs, bool mustExistInList=false); diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index 8ef096ce..967c758b 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -208,10 +208,9 @@ Intro::Intro(Program *program): findAll(introPath, introModels, false, false); for(int i = 0; i < (int)introModels.size(); ++i) { string logo = introModels[i]; - Model *model= renderer.newModel(rsMenu); - if(model) { - model->load(getGameCustomCoreDataPath(data_path, "") + "data/core/menu/main_model/" + logo); - models.push_back(model); + Model *model= renderer.newModel(rsMenu, getGameCustomCoreDataPath(data_path, "") + "data/core/menu/main_model/" + logo); + if(model) { + models.push_back(model); //printf("#1 Intro model [%s]\n",model->getFileName().c_str()); } } @@ -222,9 +221,8 @@ Intro::Intro(Program *program): findAll(introPath, introModels, false, false); for(int i = 0; i < (int)introModels.size(); ++i) { string logo = introModels[i]; - Model *model= renderer.newModel(rsMenu); - if(model) { - model->load(data_path + "data/core/menu/main_model/" + logo); + Model *model= renderer.newModel(rsMenu, data_path + "data/core/menu/main_model/" + logo); + if(model) { models.push_back(model); //printf("#2 Intro model [%s]\n",model->getFileName().c_str()); } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 7a194edd..ffb63ff2 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -5160,8 +5160,7 @@ int glestMain(int argc, char** argv) { char szTextBuf[8096]=""; for(unsigned int i =0; i < models.size(); ++i) { string &file = models[i]; - bool modelLoadedOk = false; - + renderer.clearBuffers(); renderer.clearZBuffer(); renderer.reset2d(); @@ -5187,23 +5186,18 @@ int glestMain(int argc, char** argv) { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); - Model *model = renderer.newModel(rsGlobal); try { printf("About to load model [%s] [%u of " MG_SIZE_T_SPECIFIER "]\n",file.c_str(),i,models.size()); - model->load(file); - modelLoadedOk = true; + Model *model = renderer.newModel(rsGlobal, file); + printf("About to save converted model [%s]\n",file.c_str()); + model->save(file,textureFormat,keepsmallest); + Renderer::getInstance().endModel(rsGlobal, model); } catch(const exception &ex) { result = 1; printf("ERROR loading model [%s] message [%s]\n",file.c_str(),ex.what()); - } - - if(modelLoadedOk == true) { - printf("About to save converted model [%s]\n",file.c_str()); - model->save(file,textureFormat,keepsmallest); - } - - Renderer::getInstance().endModel(rsGlobal, model); + } + } delete mainWindow; diff --git a/source/glest_game/menu/menu_background.cpp b/source/glest_game/menu/menu_background.cpp index 1d4638a6..93c3aa12 100644 --- a/source/glest_game/menu/menu_background.cpp +++ b/source/glest_game/menu/menu_background.cpp @@ -98,23 +98,17 @@ MenuBackground::MenuBackground() : rps(NULL) { degToRad(startRotation.z)))); //load main model - mainModel= renderer.newModel(rsMenu); - if(mainModel) { - string mainModelFile = "data/core/menu/main_model/menu_main.g3d"; - if(menuNode->hasChild("menu-background-model") == true) { - //mainModel->load(data_path + "data/core/menu/main_model/menu_main.g3d"); - const XmlNode *mainMenuModelNode= menuNode->getChild("menu-background-model"); - mainModelFile = mainMenuModelNode->getAttribute("value")->getRestrictedValue(); - } - mainModel->load(getGameCustomCoreDataPath(data_path, mainModelFile)); - } + string mainModelFile = "data/core/menu/main_model/menu_main.g3d"; + if(menuNode->hasChild("menu-background-model") == true) { + //mainModel->load(data_path + "data/core/menu/main_model/menu_main.g3d"); + const XmlNode *mainMenuModelNode= menuNode->getChild("menu-background-model"); + mainModelFile = mainMenuModelNode->getAttribute("value")->getRestrictedValue(); + } + mainModel = renderer.newModel(rsMenu, getGameCustomCoreDataPath(data_path, mainModelFile)); //models - for(int i=0; i<5; ++i){ - characterModels[i]= renderer.newModel(rsMenu); - if(characterModels[i]) { - characterModels[i]->load(getGameCustomCoreDataPath(data_path, "data/core/menu/about_models/character"+intToStr(i)+".g3d")); - } + for(int i=0; i<5; ++i) { + characterModels[i] = renderer.newModel(rsMenu, getGameCustomCoreDataPath(data_path, "data/core/menu/about_models/character"+intToStr(i)+".g3d")); } //about position diff --git a/source/glest_game/types/object_type.cpp b/source/glest_game/types/object_type.cpp index b3c72eb2..43f4e348 100644 --- a/source/glest_game/types/object_type.cpp +++ b/source/glest_game/types/object_type.cpp @@ -37,10 +37,7 @@ ObjectType::~ObjectType(){ TilesetModelType* ObjectType::loadModel(const string &path, std::map > > *loadedFileList, string parentLoader) { - Model *model= Renderer::getInstance().newModel(rsGame); - if(model) { - model->load(path, false, loadedFileList, &parentLoader); - } + Model *model= Renderer::getInstance().newModel(rsGame, path, false, loadedFileList, &parentLoader); color= Vec3f(0.f); if(model && model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) { const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst(); diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index 8c150a54..d90543d4 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -110,10 +110,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre const XmlNode *modelNode= typeNode->getChild("model"); string modelPath= modelNode->getAttribute("path")->getRestrictedValue(currentPath); - model= renderer.newModel(rsGame); - if(model) { - model->load(modelPath, false, &loadedFileList, &sourceXMLFile); - } + model= renderer.newModel(rsGame, modelPath, false, &loadedFileList, &sourceXMLFile); loadedFileList[modelPath].push_back(make_pair(sourceXMLFile,modelNode->getAttribute("path")->getRestrictedValue())); if(modelNode->hasChild("particles")){ diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index fc0d3681..dccc40dd 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -419,10 +419,7 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, for(unsigned int i = 0; i < animationList.size(); ++i) { string path= animationList[i]->getAttribute("path")->getRestrictedValue(currentPath); if(fileExists(path) == true) { - Model *animation= Renderer::getInstance().newModel(rsGame); - if(animation) { - animation->load(path, false, &loadedFileList, &parentLoader); - } + Model *animation= Renderer::getInstance().newModel(rsGame, path, false, &loadedFileList, &parentLoader); loadedFileList[path].push_back(make_pair(parentLoader,animationList[i]->getAttribute("path")->getRestrictedValue())); animations.push_back(animation); diff --git a/source/shared_lib/include/graphics/gl/graphics_factory_basic_gl.h b/source/shared_lib/include/graphics/gl/graphics_factory_basic_gl.h index 19234eb4..629e9148 100644 --- a/source/shared_lib/include/graphics/gl/graphics_factory_basic_gl.h +++ b/source/shared_lib/include/graphics/gl/graphics_factory_basic_gl.h @@ -33,7 +33,7 @@ public: virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();} virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();} virtual Context *newContext() {return new ContextGl();} - virtual Model *newModel() {return new ModelGl();} + virtual Model *newModel(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader) { return new ModelGl(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); } virtual Texture2D *newTexture2D() {return new Texture2DGl();} virtual Font2D *newFont2D() {return new Font2DGl();} virtual Font3D *newFont3D() {return new Font3DGl();} diff --git a/source/shared_lib/include/graphics/gl/graphics_factory_gl.h b/source/shared_lib/include/graphics/gl/graphics_factory_gl.h index 3ef9d0d4..b4412ecf 100644 --- a/source/shared_lib/include/graphics/gl/graphics_factory_gl.h +++ b/source/shared_lib/include/graphics/gl/graphics_factory_gl.h @@ -47,7 +47,7 @@ public: //models virtual ModelManager *newModelManager() {return new ModelManager();} virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();} - virtual Model *newModel() {return new ModelGl();} + virtual Model *newModel(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader) { return new ModelGl(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); } //text virtual FontManager *newFontManager() {return new FontManager();} diff --git a/source/shared_lib/include/graphics/gl/model_gl.h b/source/shared_lib/include/graphics/gl/model_gl.h index 4a899cc3..3c12d778 100644 --- a/source/shared_lib/include/graphics/gl/model_gl.h +++ b/source/shared_lib/include/graphics/gl/model_gl.h @@ -22,6 +22,9 @@ namespace Shared{ namespace Graphics{ namespace Gl{ // ===================================================== class ModelGl: public Model{ + friend class GraphicsFactoryGl; +protected: + ModelGl(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader); public: virtual void init(){} virtual void end(){} diff --git a/source/shared_lib/include/graphics/graphics_factory.h b/source/shared_lib/include/graphics/graphics_factory.h index dc6914c2..c965ee8f 100644 --- a/source/shared_lib/include/graphics/graphics_factory.h +++ b/source/shared_lib/include/graphics/graphics_factory.h @@ -13,6 +13,11 @@ #define _SHARED_GRAPHICS_GRAPHICSFACTORY_H_ #include +#include +#include +#include +using std::string; + #include "leak_dumper.h" namespace Shared{ namespace Graphics{ @@ -64,7 +69,7 @@ public: //models virtual ModelManager *newModelManager() {return NULL;} virtual ModelRenderer *newModelRenderer() {return NULL;} - virtual Model *newModel() {return NULL;} + virtual Model *newModel(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader) {return NULL;} //text virtual FontManager *newFontManager() {return NULL;} diff --git a/source/shared_lib/include/graphics/graphics_interface.h b/source/shared_lib/include/graphics/graphics_interface.h index 2cd29dbb..7423b274 100644 --- a/source/shared_lib/include/graphics/graphics_interface.h +++ b/source/shared_lib/include/graphics/graphics_interface.h @@ -35,7 +35,7 @@ enum ResourceScope { class RendererInterface { public: virtual Texture2D *newTexture2D(ResourceScope rs) = 0; - virtual Model *newModel(ResourceScope rs) = 0; + virtual Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string *sourceLoader=NULL) = 0; virtual ~RendererInterface() {} }; diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 909a492c..c7f8b000 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -221,9 +221,7 @@ public: uint32 getVertexCount() const; //io - void load(const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string *sourceLoader=NULL); void save(const string &path, string convertTextureToFormat,bool keepsmallest); - void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string sourceLoader=""); void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest); void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;} @@ -234,6 +232,11 @@ public: void toEndian(); void fromEndian(); +protected: + void load(const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string *sourceLoader=NULL); + void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map > > *loadedFileList=NULL, string sourceLoader=""); + + private: void buildInterpolationData() const; void autoJoinMeshFrames(); diff --git a/source/shared_lib/include/graphics/model_manager.h b/source/shared_lib/include/graphics/model_manager.h index e4c82a6e..0f119872 100644 --- a/source/shared_lib/include/graphics/model_manager.h +++ b/source/shared_lib/include/graphics/model_manager.h @@ -38,7 +38,7 @@ public: ModelManager(); virtual ~ModelManager(); - Model *newModel(); + Model *newModel(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader); void init(); void end(); diff --git a/source/shared_lib/sources/graphics/gl/model_gl.cpp b/source/shared_lib/sources/graphics/gl/model_gl.cpp new file mode 100644 index 00000000..12155f04 --- /dev/null +++ b/source/shared_lib/sources/graphics/gl/model_gl.cpp @@ -0,0 +1,20 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 MartiƱo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "model_gl.h" + +namespace Shared{ namespace Graphics{ namespace Gl{ + +ModelGl::ModelGl(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader) { + load(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); +} + +}}}//end namespace diff --git a/source/shared_lib/sources/graphics/model_manager.cpp b/source/shared_lib/sources/graphics/model_manager.cpp index 4fcd59be..0438bb4c 100644 --- a/source/shared_lib/sources/graphics/model_manager.cpp +++ b/source/shared_lib/sources/graphics/model_manager.cpp @@ -40,8 +40,8 @@ ModelManager::~ModelManager(){ end(); } -Model *ModelManager::newModel(){ - Model *model= GraphicsInterface::getInstance().getFactory()->newModel(); +Model *ModelManager::newModel(const string &path,bool deletePixMapAfterLoad,std::map > > *loadedFileList, string *sourceLoader){ + Model *model= GraphicsInterface::getInstance().getFactory()->newModel(path,deletePixMapAfterLoad,loadedFileList,sourceLoader); model->setTextureManager(textureManager); models.push_back(model); return model; diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index ebfe3298..4885df6a 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -121,55 +121,60 @@ static int getFileAndLine(char *function, void *address, char *file, size_t flen // prepare command to be executed // our program need to be passed after the -e parameter +#if __APPLE_CC__ + snprintf(buf, 8096,"xcrun atos -v -o %s %p",PlatformExceptionHandler::application_binary.c_str(),address); + fprintf(stderr,"> %s\n",buf); +#else snprintf(buf, 8096,"addr2line -C -e %s -f -i %p",PlatformExceptionHandler::application_binary.c_str(),address); - +#endif FILE* f = popen (buf, "r"); if (f == NULL) { perror (buf); return 0; } +#if __APPLE_CC__ + //### TODO Will: still working this out + int len = fread(buf,1,maxbufSize,f); + buf[len] = 0; + fprintf(stderr,"< %s",buf); + return -1; +#endif + for(;function != NULL && function[0] != '\0';) { + // get function name + char *ret = fgets (buf, maxbufSize, f); + if(ret == NULL) { + pclose(f); + return line; + } + //printf("Looking for [%s] Found [%s]\n",function,ret); + if(strstr(ret,function) != NULL) { + break; + } + // get file and line + ret = fgets (buf, maxbufSize, f); + if(ret == NULL) { + pclose(f); + return line; + } - if(function != NULL && function[0] != '\0') { - line = 0; - for(;function != NULL && function[0] != '\0';) { - // get function name - char *ret = fgets (buf, maxbufSize, f); - if(ret == NULL) { - pclose(f); - return line; - } - //printf("Looking for [%s] Found [%s]\n",function,ret); - if(strstr(ret,function) != NULL) { - break; - } + if(strlen(buf) > 0 && buf[0] != '?') { + //int l; + char *p = buf; + // file name is until ':' + while(*p != 0 && *p != ':') { + p++; + } - // get file and line - ret = fgets (buf, maxbufSize, f); - if(ret == NULL) { - pclose(f); - return line; - } - - if(strlen(buf) > 0 && buf[0] != '?') { - //int l; - char *p = buf; - - // file name is until ':' - while(*p != 0 && *p != ':') { - p++; - } - - *p++ = 0; - // after file name follows line number - strcpy (file , buf); - sscanf (p,"%10d", &line); - } - else { - strcpy (file,"unknown"); - line = 0; - } - } - } + *p++ = 0; + // after file name follows line number + strcpy (file , buf); + sscanf (p,"%10d", &line); + } + else { + strcpy (file,"unknown"); + line = 0; + } + } // get file and line char *ret = fgets (buf, maxbufSize, f);