static void save_program_settings(void) { const gchar *program_name = *program_executable ? program_executable : program_load_script; if (*program_name) { GtkTreeIter iter; gint id; GKeyFile *config = g_key_file_new(); char *configfile; if (program_find(&iter, program_name)) { scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); scp_tree_store_move(recent_programs, &iter, 0); } else { if (scp_tree_store_iter_nth_child(recent_programs, &iter, NULL, RECENT_COUNT - 1)) { scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); scp_tree_store_remove(recent_programs, &iter); } else { for (id = 1; id < RECENT_COUNT; id++) if ((recent_bitmap & (1 << id)) == 0) break; recent_bitmap |= 1 << id; } scp_tree_store_prepend_with_values(recent_programs, &iter, NULL, PROGRAM_NAME, program_name, PROGRAM_ID, id, -1); } configfile = recent_file_name(id); stash_foreach((GFunc) stash_group_save_to_key_file, config); breaks_save(config); watches_save(config); inspects_save(config); registers_save(config); parse_save(config); utils_key_file_write_to_file(config, configfile); g_free(configfile); g_key_file_free(config); } }
static void save_program_settings(void) { const gchar *program_name = *program_executable ? program_executable : program_load_script; if (*program_name) { RecentProgram *recent = (RecentProgram *) array_find(recent_programs, program_name, TRUE); GKeyFile *config = g_key_file_new(); char *configfile; if (!recent) { recent = (RecentProgram *) array_append(recent_programs); recent->name = g_strdup(program_name); for (recent->id = 1; recent->id < RECENT_COUNT; recent->id++) if ((recent_bitmap & (1 << recent->id)) == 0) break; recent_bitmap |= 1 << recent->id; } configfile = recent_file_name(recent->id); stash_foreach((GFunc) stash_group_save_to_key_file, config); breaks_save(config); watches_save(config); inspects_save(config); parse_save(config); utils_key_file_write_to_file(config, configfile); g_free(configfile); g_key_file_free(config); g_array_insert_vals(recent_programs, 0, ++recent, 1); array_remove(recent_programs, recent); recent_menu_create(); if (recent_programs->len > RECENT_COUNT) { recent_bitmap &= ~(1 << recent->id); array_remove(recent_programs, recent); } } }
static int res2file_instance(mapidflib_function_instance_t *instance, MAPI_UNUSED int flow_descr, mapidflib_flow_mod_t *flow_mod) { char *head, *savestr; int file; char *fids,*s; int type,fd,fid,save; char buf[DATA_SIZE],*cfids; char *types,*t,*t2,buf2[DATA_SIZE]; int min=0; int reset = -1; mapiFunctArg* fargs=instance->args; if(!(types = getargstr(&fargs))) return(MFUNCT_INVALID_ARGUMENT_1); if(!(fids = getargstr(&fargs))) return(MFUNCT_INVALID_ARGUMENT_2); if(!(head = getargstr(&fargs))) return(MFUNCT_INVALID_ARGUMENT_3); if((file = getargint(&fargs)) < 0) return(MFUNCT_INVALID_ARGUMENT_4); else { struct stat sbuf; if(fstat(file, &sbuf) == -1) { DEBUG_CMD(Debug_Message("Cannot fstat() file descriptor %d", file)); return(MFUNCT_INVALID_ARGUMENT_4); } } if((savestr = getargstr(&fargs)) == NULL) return(MFUNCT_INVALID_ARGUMENT_5); if((save=parse_save(savestr))<0) return MFUNCT_INVALID_ARGUMENT_5; reset = getargint(&fargs); if(!(reset == 0 || reset == 1)) return(MFUNCT_INVALID_ARGUMENT_6); //Loop through fids and types and verify strncpy(buf,fids,DATA_SIZE); cfids=buf; strncpy(buf2,types,DATA_SIZE); t=buf2; while((s=strchr(cfids,','))!=NULL) { *s='\0'; if((t2=strchr(t,','))==NULL) return MFUNCT_INVALID_ARGUMENT_1; *t2='\0'; sscanf(cfids,"%d@%d",&fid,&fd); if(fhlp_get_function_instance(instance->hwinfo->gflist,fd,fid)==NULL) return MFUNCT_INVALID_ARGUMENT_2; if(min==0 || min>fid) min=fid; sscanf(t,"%d",&type); if(type!=R2F_RAW && type!=R2F_ULLSTR && type!=R2F_ULLSEC && type!=R2F_STATS) return MFUNCT_INVALID_ARGUMENT_2; cfids=s+1; t=t2+1; } sscanf(cfids,"%d@%d",&fid,&fd); if(fhlp_get_function_instance(instance->hwinfo->gflist,fd,fid)==NULL) return MFUNCT_INVALID_ARGUMENT_2; if(save==PERIODIC) { //Move res2file in front of the other functions results are read from flow_mod->reorder=min; } return 0; };
static int res2file_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int flow_descr) { res2file_inst_t *i; char *fids,*s,*f; int type,fd,fid,c; char *head; char buf[DATA_SIZE],*cfids; char *types,*t,*t2,buf2[DATA_SIZE]; mapiFunctArg* fargs=instance->args; i=instance->internal_data=malloc(sizeof(res2file_inst_t)); mapidflib_function_instance_t *function; types=getargstr(&fargs); fids=getargstr(&fargs); head=getargstr(&fargs); i->file=getargint(&fargs); i->save=parse_save((s=getargstr(&fargs))); if(i->save==PERIODIC) { i->ticks=fhlp_str2ull(s); if(i->ticks==0) return MFUNCT_INVALID_ARGUMENT_5; } i->reset=getargint(&fargs); //Count number of fids c=0; f=fids; while((s=strchr(f,','))!=NULL) { f=s+1; c++; } c++; i->functs=malloc(sizeof(mapidflib_function_instance_t*)*c); i->types=malloc(sizeof(int)*c); i->numfuncts=c; i->last=0; //Loop through fids and types and verify strncpy(buf,fids,DATA_SIZE); cfids=buf; strncpy(buf2,types,DATA_SIZE); t=buf2; c=0; while((s=strchr(cfids,','))!=NULL) { *s='\0'; if((t2=strchr(t,','))==NULL) return MFUNCT_INVALID_ARGUMENT_1; *t2='\0'; sscanf(cfids,"%d@%d",&fid,&fd); function=fhlp_get_function_instance(instance->hwinfo->gflist,fd,fid); i->functs[c]=function; if(function==NULL) return MFUNCT_INVALID_ARGUMENT_2; sscanf(t,"%d",&type); i->types[c++]=type; if(type!=R2F_RAW && type!=R2F_ULLSTR && type!=R2F_ULLSEC && type!=R2F_STATS) return MFUNCT_INVALID_ARGUMENT_1; cfids=s+1; t=t2+1; } sscanf(cfids,"%d@%d",&fid,&fd); function=fhlp_get_function_instance(instance->hwinfo->gflist,fd,fid); i->functs[c]=function; sscanf(t,"%d",&type); i->types[c++]=type; write(i->file,head,strlen(head)); write(i->file,"\n",1); return 0; }