summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-12-19 22:43:43 +0900
committerJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-12-19 22:43:43 +0900
commit928ef9567389725941f0e743078de18cd38d27a5 (patch)
tree94bad5dc568be284d9020d092576fa5ecda68308
parent17d73be65daf43c214f00002ddb549e768ca2d09 (diff)
downloadcubedbus-928ef9567389725941f0e743078de18cd38d27a5.tar.gz
cubedbus-928ef9567389725941f0e743078de18cd38d27a5.tar.bz2
Use findPath function to get absolute path to mtl and tex files from the
path of obj file and relative paths specified in the obj and mtl files respecitvely
-rw-r--r--cubedbusModel.c.in25
1 files changed, 19 insertions, 6 deletions
diff --git a/cubedbusModel.c.in b/cubedbusModel.c.in
index bae01ef..0b29277 100644
--- a/cubedbusModel.c.in
+++ b/cubedbusModel.c.in
@@ -11,6 +11,7 @@ static bool cubedbusModifyModelObject (CubedbusObject *obj, CompOption *option,
static bool cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption);
static char *getLine (FILE *fp);
+static char *findPath (char *object, char *file);
typedef struct _vect3d
{
@@ -88,7 +89,6 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
char delim[]={' ','\t','\0'};
-
/* First pass - count how much data we need to store */
FILE *fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r");
@@ -224,17 +224,20 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
/* XXX Parse MTL file and load textures XXX */
int mtlCount;
+ char *tmpName;
for(mtlCount=0;mtllib[mtlCount] != NULL;mtlCount++)
{
- fp=fopen(mtllib[mtlCount], "r"); /* XXX should get path as well XXX */
+ fp=fopen((tmpName=findPath( getStringOptionNamed(option, nOption, "file", ""), mtllib[mtlCount])) , "r"); /* XXX should get path as well XXX */
if(fp == NULL)
{
compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "mtl: can't open %s: %s",
mtllib[mtlCount], strerror(errno));
return FALSE;
- }
+ }
+ free(tmpName);
+ tmpName = NULL;
while((strline=getLine(fp))!=NULL)
{
@@ -313,7 +316,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
compLogMessage (obj->s->display, "cubedbus", CompLogLevelWarn, "CompTexture is not malloced properly");
}
else if(!readImageToTexture (obj->s, mtlPtr->tex, /*texture pointer*/
- tmpType[1], /*XXX*/ /*file*/
+ (tmpName=findPath(getStringOptionNamed (option, nOption, "file", ""),tmpType[1])), /*file*/
&(mtlPtr->width), /*pointer for width*/
&(mtlPtr->height)) ) /*pointer for height*/
{
@@ -321,7 +324,9 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption)
finiTexture(obj->s, mtlPtr->tex);
mtlPtr->tex=NULL;
- }
+ }
+ if(tmpName != NULL) free(tmpName);
+ tmpName = NULL;
}
//free(strline);
strline=NULL;
@@ -585,6 +590,13 @@ getLine (FILE *fp)
return NULL;
}
+/**************************
+* Gets path from object *
+* and file name from file *
+* and returns full path *
+* to the file *
+**************************/
+
static char *
findPath (char *object, char *file)
{
@@ -597,7 +609,7 @@ findPath (char *object, char *file)
strcpy(myObject, object);
strcpy(myFile, file);
-
+
int i;
for(i=strlen(myObject);i>=0;i--)
{
@@ -607,6 +619,7 @@ findPath (char *object, char *file)
tmpPtr=realloc(myObject, sizeof(char)*(i+1));
if(tmpPtr==NULL) return NULL;
myObject=tmpPtr;
+ break;
}
}