boxdir * boxtree_add_folder(const char * path, const char * id, jobj * folder) { boxdir * aDir; boxfile * aFile, * part; list_iter it, pit; jobj * obj, *item; char * type; aDir = boxdir_create(); aDir->id = strdup(id); if(options.verbose) syslog(LOG_DEBUG, "Adding %s", path); obj = jobj_get(folder, "entries"); it = list_get_iter(obj->children); for(; it; it = list_iter_next(it)) { item = list_iter_getval(it); aFile = obj_to_file(item); type = jobj_getval(item, "type"); if(!strcmp(type,"folder")) list_append(aDir->folders, aFile); else { if(options.splitfiles && ends_with(aFile->name, PART_SUFFIX)) list_insert_sorted_comp(aDir->pieces, aFile, filename_compare); else list_append(aDir->files, aFile); } free(type); } if(options.splitfiles) { it = list_get_iter(aDir->files); pit = list_get_iter(aDir->pieces); for(; pit; pit = list_iter_next(pit)) { part = (boxfile*)list_iter_getval(pit); find_file_for_part(part->name, &it); if(it) { aFile = (boxfile*)list_iter_getval(it); aFile->size+=part->size; } else { syslog(LOG_WARNING, "Stale file part %s found", part->name ); it = list_get_iter(aDir->files); } } } xmlHashAddEntry(allDirs, path, aDir); return aDir; }
int main ( int argc, char *argv[] ) { List* list = list_create ( sizeof ( int ),EqualInt ); int t; ListNode* n; int i; for ( i=0; i<10; ++i ) list_push_back ( list,createInt ( &t,rand() ) ); /*list_foreach(list,printInt);*/ ListIter iter = list_get_iter ( list ); while ( list_iter_hasNext ( iter ) ) { printInt ( list_iter_next ( iter ) ); } printf ( "\n" ); list_pop_back ( list ); list_foreach ( list,incInt ); list_foreach ( list,printInt ); printf ( "\n" ); n = list_find_first_node ( list,createInt ( &t,846930887 ) ); list_erase_node ( list,n ); list_foreach ( list,printInt ); list_delete ( list ); return 0; }
void list_dump(list *l, const char * fmt) { list_iter it = list_get_iter(l); printf("list size is %d\n", list_size(l)); while(it) { printf(fmt, list_iter_getval(it)); it = list_iter_next(it); } }
static void list_update_progress(PROC_T *p){ if(p->status.nseed==0) return; GtkListStore *list=lists[p->hid]; double total=(double)(p->status.rest+p->status.laps); if(fabs(total)>1.e-10){ p->frac=(double)p->status.laps/total; }else{ p->frac=0; } if(p->frac>1){ p->frac=1; }else if(p->frac<0){ p->frac=0; } GtkTreeIter iter; list_get_iter(p, &iter); const double tkmean=p->status.scale; const long tot=p->status.rest+p->status.laps;/*show total time. */ const long toth=tot/3600; const long totm=(tot-toth*3600)/60; const long tots=tot-toth*3600-totm*60; const long rest=p->status.rest; const long resth=rest/3600; const long restm=(rest-resth*3600)/60; const long rests=rest-resth*3600-restm*60; const double step=p->status.tot*tkmean; if(p->status.iseed!=p->iseed_old){ char tmp[64]; snprintf(tmp,64,"%d/%d",p->status.iseed+1,p->status.nseed); gtk_list_store_set(list, &iter, COL_SEED, tmp, COL_SEEDP, (100*(p->status.iseed+1)/p->status.nseed), -1); p->iseed_old=p->status.iseed; } char tmp[64]; if(toth>99){ snprintf(tmp,64, "%d/%d %5.2fs %ldh/%ldh",p->status.isim+1,p->status.simend, step, resth,toth); }else if(toth>0){ snprintf(tmp,64, "%d/%d %5.2fs %ldh%02ld/%ldh%02ld",p->status.isim+1,p->status.simend, step, resth,restm,toth,totm); }else{ snprintf(tmp,64, "%d/%d %5.2fs %2ld:%02ld/%ld:%02ld",p->status.isim+1,p->status.simend, step, restm,rests,totm,tots); } gtk_list_store_set(list, &iter, COL_STEP,tmp, COL_STEPP,(gint)(p->frac*100), -1); snprintf(tmp,64,"%.2f",p->status.clerrlo); gtk_list_store_set(list, &iter, COL_ERRLO,tmp, -1); snprintf(tmp,64,"%.2f",p->status.clerrhi); gtk_list_store_set(list, &iter, COL_ERRHI,tmp, -1); }
jobj * jobj_array_item(const jobj * obj, int at) { list_iter it; int i; if(obj->type != T_ARR) return NULL; if(at >= list_size(obj->children)) return NULL; it = list_get_iter(obj->children); for(i=0; i<at; ++i) it = list_iter_next(it); return (jobj*) list_iter_getval(it); }
void jobj_free(jobj * obj) { list_iter it; if(obj->type = T_VAL) { free(obj->value); return; } it = list_get_iter(obj->children); for(; it; it = list_iter_next(it)) { jobj_free(list_iter_getval(it)); } list_free(obj->children); free(obj); }
jobj * jobj_get(const jobj * obj, const char * key) { list_iter it; if(obj->type == T_VAL) return NULL; it = list_get_iter(obj->children); jobj * item; for(; it; it = list_iter_next(it)) { item = list_iter_getval(it); if(!strcmp(item->key, key)) return item; } return NULL; }
list_iter boxpath_first_part(boxpath * bpath) { list_iter it; boxfile * part; if(!boxpath_getfile(bpath)) return NULL; it = list_get_iter(bpath->dir->pieces); while(it && (filename_compare(bpath->file, list_iter_getval(it)) > 0)) it = list_iter_next(it); if(it) { part = (boxfile*) list_iter_getval(it); if(strncmp(bpath->base, part->name, strlen(bpath->base))) return NULL; } return it; }
boxfile * obj_to_file(jobj * obj) { list_iter it; jobj * item; boxfile * f = (boxfile*) malloc(sizeof(boxfile)); memset(f, 0, sizeof(boxfile)); it = list_get_iter(obj->children); for(; it; it = list_iter_next(it)) { item = list_iter_getval(it); if(!strcmp(item->key,"id")) f->id = strdup(item->value); else if(!strcmp(item->key, "size")) f->size = atoll(item->value); else if(!strcmp(item->key, "name")) f->name = strdup(item->value); else if(!strcmp(item->key, "created_at")) f->ctime = unix_time(item->value); else if(!strcmp(item->key, "modified_at")) f->mtime = unix_time(item->value); } return f; }
int boxpath_getfile(boxpath * bpath) { list_iter it; boxfile * aFile; /* check for obvious cases */ if(!bpath) return FALSE; if(bpath->file) return TRUE; it = list_get_iter(bpath->is_dir ? bpath->dir->folders : bpath->dir->files); for(; it; it = list_iter_next(it)) { aFile = (boxfile*)list_iter_getval(it); if(!strcmp(aFile->name, bpath->base)) { bpath->file = aFile; return TRUE; } } return FALSE; }
// Move a dir to another path in the tree, // recursively updating all the child entries in allDirs void boxtree_movedir(const char * from, const char * to) { boxdir * aDir = xmlHashLookup(allDirs, from); list_iter it; char * newfrom, * newto, *name; if(!aDir) { syslog(LOG_ERR, "no such directory %s", from); return; } for (it=list_get_iter(aDir->folders); it; it = list_iter_next(it)) { name = ((boxfile*)list_iter_getval(it))->name; newfrom = pathappend(from, name); newto = pathappend(to, name); boxtree_movedir(newfrom, newto); free(newfrom); free(newto); } //LOCKDIR(aDir); xmlHashRemoveEntry(allDirs, from, NULL); xmlHashAddEntry(allDirs, to, aDir); //UNLOCKDIR(aDir); }
static void list_modify_reset(PROC_T *p){ GtkTreeIter iter; GtkListStore *list=lists[p->hid]; list_get_iter(p, &iter); char spid[12]; snprintf(spid,12," %d ",p->pid); char sdate[80]; struct tm *tim=localtime(&p->status.timstart); strftime(sdate,80,"%m-%d %k:%M:%S",tim); gtk_list_store_set(list, &iter, COL_DATE, sdate, COL_PID, spid, COL_SEED," ", COL_SEEDP, 0, //Don't use 0. COL_STEP," ", COL_STEPP, 0, COL_ERRHI," ", COL_ERRLO," ", -1); p->iseed_old=-1; }
static void list_modify_color(PROC_T *p, const char *color){ GtkTreeIter iter; GtkListStore *list=lists[p->hid]; list_get_iter(p, &iter); gtk_list_store_set(list, &iter, COL_COLOR, color,-1); }
static void list_modify_icon(PROC_T *p, GdkPixbuf *newicon){ GtkTreeIter iter; GtkListStore *list=lists[p->hid]; list_get_iter(p, &iter); gtk_list_store_set(list, &iter, COL_ACTION, newicon,-1); }