libpsys

diff src/pattr.c @ 13:1b0db53d5b5b

started writting config file for the particle system attributes
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 06 Sep 2012 02:32:58 +0300
parents 9c24273f211b
children 4f36bbbcc82f
line diff
     1.1 --- a/src/pattr.c	Wed Aug 29 05:11:47 2012 +0300
     1.2 +++ b/src/pattr.c	Thu Sep 06 02:32:58 2012 +0300
     1.3 @@ -7,6 +7,7 @@
     1.4  
     1.5  static int init_particle_attr(struct psys_particle_attributes *pattr);
     1.6  static void destroy_particle_attr(struct psys_particle_attributes *pattr);
     1.7 +static char *stripspace(char *str);
     1.8  
     1.9  static void *tex_cls;
    1.10  static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture;
    1.11 @@ -125,7 +126,30 @@
    1.12  
    1.13  int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp)
    1.14  {
    1.15 -	return -1;	/* TODO */
    1.16 +	int lineno = 0;
    1.17 +	char buf[512];
    1.18 +
    1.19 +	psys_init_attr(attr);
    1.20 +
    1.21 +	while(fgets(buf, sizeof buf, fp)) {
    1.22 +		char *key, *valstr;
    1.23 +
    1.24 +		lineno++;
    1.25 +
    1.26 +		key = stripspace(buf);
    1.27 +		if(key[0] == '#' || !key[0]) {
    1.28 +			continue;	// skip empty lines and comments
    1.29 +		}
    1.30 +
    1.31 +		if(!(valstr = strchr(buf, '='))) {
    1.32 +			fprintf(stderr "%s: invalid input: %s\n", __func__, line);
    1.33 +			return -1;
    1.34 +		}
    1.35 +		*valstr++ = 0;
    1.36 +		valstr = stripspace(valstr);
    1.37 +
    1.38 +
    1.39 +	}
    1.40  }
    1.41  
    1.42  
    1.43 @@ -147,3 +171,19 @@
    1.44  {
    1.45  	return -1;	/* TODO */
    1.46  }
    1.47 +
    1.48 +
    1.49 +static char *stripspace(char *str)
    1.50 +{
    1.51 +	char *end;
    1.52 +
    1.53 +	while(*str && isspace(*str)) {
    1.54 +		str++;
    1.55 +	}
    1.56 +
    1.57 +	end = str + strlen(str);
    1.58 +	while(end >= str && isspace(*end)) {
    1.59 +		*end-- = 0;
    1.60 +	}
    1.61 +	return str;
    1.62 +}