diff options
-rw-r--r-- | src/include/eiotas_particle.h | 8 | ||||
-rw-r--r-- | src/lib/eiotas_particle.c | 77 |
2 files changed, 85 insertions, 0 deletions
diff --git a/src/include/eiotas_particle.h b/src/include/eiotas_particle.h index 0f93959..12026d8 100644 --- a/src/include/eiotas_particle.h +++ b/src/include/eiotas_particle.h @@ -119,6 +119,14 @@ EAPI Eina_Bool eiotas_particle_has_dst(Eiotas_Particle *particle); EAPI Eina_Bool eiotas_particle_next_dst(Eiotas_Particle *particle); /** + * @brief Split current destination in room ; door ; action Eina_Stringshare + * + * @param particle The @ref Eiotas_Particle to split current destination + * + */ +EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle); + +/** * @brief Add destinations to the @ref Eiotas_Particle * * @param particle The @ref Eiotas_Particle to add destinations to 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; |