void item_contents_set(cst_item *current, cst_item *i) { cst_item_contents *c = 0; cst_item *nn_item; if (i == 0) c = new_item_contents(current); else c = i->contents; if (c != current->contents) { item_unref_contents(current); current->contents = c; /* If this contents is already in this relation */ /* empty the other reference */ if (feat_present(current->contents->relations,current->relation->name)) { /* oops this is already in this relation */ nn_item = val_item(feat_val(current->contents->relations, current->relation->name)); feat_set(nn_item->contents->relations, current->relation->name, item_val(nn_item)); } /* Add back reference */ feat_set(current->contents->relations, current->relation->name, item_val(current)); } }
static bool _get_key(struct response *rsp, struct bstring *key) { struct item *it; struct val val; it = cuckoo_get(key); if (it != NULL) { rsp->type = RSP_VALUE; rsp->key = *key; rsp->flag = item_flag(it); rsp->vcas = item_cas(it); item_val(&val, it); if (val.type == VAL_TYPE_INT) { rsp->num = 1; rsp->vint = val.vint; } else { rsp->vstr = val.vstr; } log_verb("found key at %p, location %p", key, it); return true; } else { log_verb("key at %p not found", key); return false; } }
void store_stimuli(void) { FILE *id; int n,i; int here; char buf[50]; /** First write the stimuli for possible re-use **/ sprintf(buf,"%s.stm",datafile); if ((id=fopen(buf,"a")) == (FILE *) 0) { if (verbose) printf("unable to open \"%s\" to store stimuli\n",buf); return; } fprintf(id,"Name: %s\n", user_name); fprintf(id,"Date: %s\n", Date2str()); fprintf(id,"Time: %s\n\n", Time2str()); fprintf(id,global_msg); fprintf(id,global_str,num_trials,num_stimuli,num_categories, num_choices_per_category,max_same_categories, ms_btwn_stim,ms_btwn_trials,total_ms_on); fprintf(id,"\n"); fprintf(id,color_msg); fprintf(id,color_str,_palette[0],_palette[1],_palette[2],_palette[3], _palette[4],_palette[5],_palette[6]); fprintf(id,"\n"); fprintf(id,stm_msg); for (n=0,here=0;n<num_trials;++n) { for (i=0;i<num_stimuli;++i,++here) { fprintf(id,stm_str,(n+1),i,_color[here],_shape[here],_num[here], _size[here],_filled[here],_pattern[here],_matches[here], item_val(here)); } } PrintCounterBalancePcts(id); fprintf(id,"\n\n"); fclose(id); }
void analyze(char *dest, int time_now) { FILE *id; int n,i; int here; int count; /** Now store the results for further analysis **/ if ((id=fopen(dest,"a")) == (FILE *) 0) { if (verbose) printf("unable to open \"%s\" to store results\n",dest); return; } fprintf(id,"Name: %s\n", user_name); fprintf(id,"Date: %s\n", (time_now) ? Date2str() : date_str); fprintf(id,"Time: %s\n\n", (time_now) ? Time2str() : time_str); if (!played_before) PrintHandedness(id); fprintf(id,"Experiment Type: %s\n", (time_now) ? ExpType[choice_type-1] : exp_type_str); fprintf(id,"Self-Eval: %s\n\n",selfeval_str); fprintf(id,global_msg); fprintf(id,global_str,num_trials,num_stimuli,num_categories, num_choices_per_category,max_same_categories, ms_btwn_stim,ms_btwn_trials,total_ms_on); fprintf(id,"\n"); fprintf(id,color_msg); fprintf(id,color_str,_palette[0],_palette[1],_palette[2],_palette[3], _palette[4],_palette[5],_palette[6]); fprintf(id,"\n**STIMULI**\n"); fprintf(id,stm_msg); for (n=0,here=0;n<num_trials;++n) { for (i=0;i<num_stimuli;++i,++here) { fprintf(id,stm_str,(n+1),i,_color[here],_shape[here],_num[here], _size[here],_filled[here],_pattern[here],_matches[here], item_val(here)); } } fprintf(id,"\n**RESPONSE DATA**\n"); fprintf(id,dat_msg); for (n=0,count=0;n<num_trials;++n,count+=num_stimuli) { here=count+_choice[n]; fprintf(id,dat_str,(n+1),_choice[n], _color[here],_shape[here],_num[here], _size[here],_filled[here],_pattern[here],_matches[here], item_val(here), _match_min[n], _match_max[n], _time[n]); } fprintf(id,"\n"); PrintCBTscores(id); PrintGraphs(id); fprintf(id,"\n\n"); // so space for next trial if needed fclose(id); }
int read_stimuli(char *filename) { FILE *id; int n,i; int here; int inada; int line=0; char buf[BUF_LEN+1]; pchar err_msg; if (verbose) printf("Reading stimuli from \"%s\"...\n",filename); if ((id=fopen(filename,"r+")) == (FILE *) 0) { puts("File does not exist"); return 0; } for (n=0;n<5;++n) { if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; } if (strlen(global_msg) != strlen(buf)) { err_msg=global_msg; goto invalid_file_format; } if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; if (sscanf(buf,global_str,&num_trials,&num_stimuli,&num_categories, &num_choices_per_category,&max_same_categories, &ms_btwn_stim,&ms_btwn_trials,&total_ms_on) != 8) goto unexpected_args; validate_args(); if (!init_arrays()) { fclose(id); return 0; } for (n=0;n<2;++n) { if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; } if (strlen(color_msg) != strlen(buf)) { err_msg=color_msg; goto invalid_file_format; } if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; if (get_colors_from == COLORS_FROM_STM_FILE) { if (sscanf(buf,color_str,&_palette[0],&_palette[1],&_palette[2], &_palette[3],&_palette[4],&_palette[5],&_palette[6]) != 7) goto unexpected_args; } /* Else use the ones parsed in from .cfg file, if at all */ for (n=0;n<2;++n) { if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; } if (strlen(stm_msg) != strlen(buf)) { err_msg=stm_msg; goto invalid_file_format; } for (n=0,here=0;n<num_trials;++n) { for (i=0;i<num_stimuli;++i,++here) { if (!fgets(buf,BUF_LEN,id)) goto end_of_file; ++line; if (sscanf(buf,stm_str,&inada,&inada, &_color[here],&_shape[here], &_num[here],&_size[here],&_filled[here],&_pattern[here], &_matches[here],&inada) != 10) goto unexpected_args; BOUNDED(_shape[here],0,num_choices_per_category-1); BOUNDED(_num[here],0,num_choices_per_category-1); BOUNDED(_size[here],0,num_choices_per_category-1); BOUNDED(_filled[here],0,num_choices_per_category-1); if(use_many_colors) { BOUNDED(_color[here],0,MAX_COLORS-1); BOUNDED(_pattern[here],0,MAX_PATTERNS-1); } else { BOUNDED(_color[here],0,num_choices_per_category-1); BOUNDED(_pattern[here],0,num_choices_per_category-1); } _Orig_stim[here] = item_val(here); // for randomization purposes } } fclose(id); calc_matches(); return 1; unexpected_args: if (verbose) printf("Unexpected args on line %i\n", line); fclose(id); return 0; end_of_file: puts("File ended too early"); fclose(id); return 0; invalid_file_format: printf("Invalid file format. Expects as line %i:\n",line); puts(err_msg); fclose(id); return 0; }