From 4f4c2d9686a432953f129b8503a53dcdd038b975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 29 May 2012 09:40:20 +0200 Subject: Particle: implement eiotas_particle_add_destinations --- src/include/eiotas_particle.h | 2 ++ src/lib/eiotas_particle.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/include/eiotas_particle.h b/src/include/eiotas_particle.h index 4ebe415..6897d89 100644 --- a/src/include/eiotas_particle.h +++ b/src/include/eiotas_particle.h @@ -51,4 +51,6 @@ EAPI void eiotas_particle_init(Eiotas_Particle *particle, Eiotas_Iota *iota); EAPI void eiotas_particle_merge(Eiotas_Particle *particle, Eiotas_Particle *p); +EAPI void eiotas_particle_add_destinations(Eiotas_Particle *particle, char* destinations); + #endif // __EIOTAS_PARTICLE_H__ diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c index 4927e90..4b0a5f6 100644 --- a/src/lib/eiotas_particle.c +++ b/src/lib/eiotas_particle.c @@ -89,3 +89,33 @@ EAPI void eiotas_particle_merge(Eiotas_Particle *particle, Eiotas_Particle *p) particle->merged = eina_inlist_append(particle->merged, EINA_INLIST_GET(p)); } +EAPI void eiotas_particle_add_destinations(Eiotas_Particle *particle, char* destinations) +{ + int n; + char *dst, *sep; + Eina_Stringshare *shared; + char tmp[EIOTAS_MAX_PATH_LENGTH]; + + dst = destinations; + for(; *dst;) { + for(; *dst==' '; dst++) /* eat leading spaces */; + sep = dst; + for(; (*sep && *sep!=EIOTAS_FIELDS_SEP && *sep!=' '); sep++) /* search destination end */; + n = (sep-dst); + if(n==0) { + ERR("ignore empty destination"); + } else if(n+2>EIOTAS_MAX_PATH_LENGTH) { + ERR("buffer overflow (%d)",n); + } else { + memcpy(tmp,dst,n); + tmp[n]='\0'; + shared = eina_stringshare_add(tmp); + eina_array_push(particle->dsts,shared); + DBG("add dst >%s<",shared); + } + for(; (*sep && *sep!=EIOTAS_FIELDS_SEP); sep++) /* eat whatever following */; + if(!*sep) return; + dst=sep+1; + } +} + -- cgit v1.1-2-g2b99