diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-06-01 16:45:38 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-06-01 16:45:38 +0200 |
commit | 22353b2bbb1b1db6cbfb915183974c259d165a22 (patch) | |
tree | 6ea0b8a12ef99a20d1d31188d05f98faa943248d /src/lib/eiotas_particle.c | |
parent | 8a7a3e0acc603896b9297fd82f99f91923be1b33 (diff) | |
download | edoors-22353b2bbb1b1db6cbfb915183974c259d165a22.zip edoors-22353b2bbb1b1db6cbfb915183974c259d165a22.tar.gz |
Particle: add eiotas_particle_split_dst
Diffstat (limited to 'src/lib/eiotas_particle.c')
-rw-r--r-- | src/lib/eiotas_particle.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c index 35f3691..4ead68f 100644 --- a/src/lib/eiotas_particle.c +++ b/src/lib/eiotas_particle.c @@ -116,6 +116,83 @@ EAPI Eina_Bool eiotas_particle_next_dst(Eiotas_Particle *particle) return ( (eina_array_count_get(particle->dsts)>particle->cur_dst) ? EINA_TRUE : EINA_FALSE ); } +EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle) +{ + unsigned int l, n; + char *sep, *tmp; + Eina_Stringshare *dst; + + if(!eiotas_particle_has_dst(particle)) { + if(particle->cur_room) eina_stringshare_del(particle->cur_room); + if(particle->cur_door) eina_stringshare_del(particle->cur_door); + if(particle->cur_action) eina_stringshare_del(particle->cur_action); + particle->cur_room = particle->cur_door = particle->cur_action = NULL; + return; + } + + dst = eina_array_data_get(particle->dsts,particle->cur_dst); + l = eina_stringshare_strlen(dst); + + sep = (char*)dst+l-1; + for(; (sep!=dst && *sep!=EIOTAS_ACTION_SEP ); sep--) /* reverse search for action separator */; + + if(*sep==EIOTAS_ACTION_SEP) { + tmp = sep+1; + /* action defined */ + if(particle->cur_action) { + if(strcmp(particle->cur_action,tmp)!=0) { + eina_stringshare_del(particle->cur_action); + particle->cur_action = eina_stringshare_add(tmp); + } + /* else : keep the same stringshare */ + } else { + particle->cur_action = eina_stringshare_add(tmp); + } + tmp = sep; + sep = sep-1; + } else { + if(particle->cur_action) { + eina_stringshare_del(particle->cur_action); + particle->cur_action = NULL; + } + tmp = (char*)dst+l; + sep = (char*)dst+l-1; + } + + for(; (sep!=dst && *sep!=EIOTAS_PATH_SEP ); sep--) /* reverse search path for separator */; + + if(sep==dst) { + /* no room */ + n=(tmp-sep); + if(particle->cur_room) eina_stringshare_del(particle->cur_room); + particle->cur_room = NULL; + } else { + n=(sep-dst); + /* door defined */ + if(particle->cur_room) { + if(strncmp(particle->cur_room,dst,n)!=0) { + eina_stringshare_del(particle->cur_room); + particle->cur_room = eina_stringshare_add_length(dst,n); + } + /* else : keep the same stringshare */ + } else { + particle->cur_room = eina_stringshare_add_length(dst,n); + } + n=(tmp-sep-1); + sep++; + } + /* door defined */ + if(particle->cur_door) { + if(strncmp(particle->cur_door,sep,n)!=0) { + eina_stringshare_del(particle->cur_door); + particle->cur_door = eina_stringshare_add_length(sep,n); + } + /* else : keep the same stringshare */ + } else { + particle->cur_door = eina_stringshare_add_length(sep,n); + } +} + EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char* destinations) { char *dst, *sep; |