glviewvol

changeset 2:701507c8238f

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 28 Dec 2014 15:26:36 +0200
parents cc9e0d8590e2
children 32c4a7160350
files src/volume.cc
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/volume.cc	Sat Dec 27 06:32:28 2014 +0200
     1.2 +++ b/src/volume.cc	Sun Dec 28 15:26:36 2014 +0200
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <stdio.h>
     1.5  #include <string.h>
     1.6  #include <ctype.h>
     1.7 +#include <alloca.h>
     1.8  #include <errno.h>
     1.9  #include <math.h>
    1.10  #include "volume.h"
    1.11 @@ -80,18 +81,28 @@
    1.12  
    1.13  bool VoxelVolume::load(const char *fname)
    1.14  {
    1.15 +	char *prefix = (char*)alloca(strlen(fname) + 1);
    1.16 +	strcpy(prefix, fname);
    1.17 +	char *slash = strrchr(prefix, '/');
    1.18 +	if(slash) {
    1.19 +		*slash = 0;
    1.20 +	} else {
    1.21 +		prefix = 0;
    1.22 +	}
    1.23 +
    1.24  	FILE *fp = fopen(fname, "r");
    1.25  	if(!fp) {
    1.26  		fprintf(stderr, "failed to open file: %s: %s\n", fname, strerror(errno));
    1.27  		return false;
    1.28  	}
    1.29  
    1.30 -	char buf[512];
    1.31 +	char buf[256], path[300];
    1.32  	while(fgets(buf, sizeof buf, fp)) {
    1.33  		char *line = strip_space(buf);
    1.34 +		sprintf(path, "%s/%s", prefix, line);
    1.35  
    1.36  		Image img;
    1.37 -		if(!img.load(line)) {
    1.38 +		if(!img.load(path)) {
    1.39  			slices.clear();
    1.40  			return false;
    1.41  		}