static void writesave_callback(GConfClient* gclient, guint cnxn_id, GConfEntry *entry, gpointer user_data) { if (gconf_entry_get_value (entry) == NULL) { /* value is unset */ } else { if (gconf_entry_get_value (entry)->type == GCONF_VALUE_STRING) { const char *fni = gconf_value_get_string (gconf_entry_get_value (entry)); if(fni && !in_main_iteration()) { int use_arg = strcmp(fni, "+"); /* plus filename uses default */ const char *fn = use_arg ? fni : GLOBALS->filesel_writesave; if(fn) { FILE *wave; if(!(wave=fopen(fn, "wb"))) { fprintf(stderr, "GTKWAVE | RPC Writesave: error opening save file '%s' for writing.\n", fn); perror("Why"); errno=0; } else { write_save_helper(fn, wave); if(use_arg) { if(GLOBALS->filesel_writesave) { free_2(GLOBALS->filesel_writesave); } GLOBALS->filesel_writesave = strdup_2(fn); } wave_gconf_client_set_string("/current/savefile", fn); fclose(wave); fprintf(stderr, "GTKWAVE | RPC Writesave: wrote save file '%s'.\n", GLOBALS->filesel_writesave); } } } gconf_entry_set_value(entry, NULL); } else { /* value is of wrong type */ } } }
void read_rc_file(char *override_rc) { FILE *handle; int i; int num_rcitems = sizeof(rcitems)/sizeof(struct rc_entry); for(i=0;i<(num_rcitems-1);i++) { if(strcmp(rcitems[i].name, rcitems[i+1].name) > 0) { fprintf(stderr, "rcitems misordering: '%s' vs '%s'\n", rcitems[i].name, rcitems[i+1].name); exit(255); } } /* move defaults first and only go whitescreen if instructed to do so */ if(GLOBALS->possibly_use_rc_defaults) vanilla_rc(); if((override_rc)&&((handle=fopen(override_rc,"rb")))) { /* good, we have a handle */ wave_gconf_client_set_string("/current/rcfile", override_rc); } else #if !defined __MINGW32__ && !defined _MSC_VER if(!(handle=fopen(rcname,"rb"))) { char *home; char *rcpath; home=getpwuid(geteuid())->pw_dir; rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1); strcpy(rcpath,home); strcat(rcpath,"/"); strcat(rcpath,rcname); if(!(handle=fopen(rcpath,"rb"))) { #ifdef MAC_INTEGRATION const gchar *bundle_id = gtkosx_application_get_bundle_id(); if(bundle_id) { const gchar *rpath = gtkosx_application_get_resource_path(); const char *suf = "/gtkwaverc"; rcpath = NULL; if(rpath) { rcpath = (char *)alloca(strlen(rpath) + strlen(suf) + 1); strcpy(rcpath, rpath); strcat(rcpath, suf); } if(!rcpath || !(handle=fopen(rcpath,"rb"))) { wave_gconf_client_set_string("/current/rcfile", ""); errno=0; return; /* no .rc file */ } else { wave_gconf_client_set_string("/current/rcfile", rcpath); } } else #endif { wave_gconf_client_set_string("/current/rcfile", ""); errno=0; return; /* no .rc file */ } } else { wave_gconf_client_set_string("/current/rcfile", rcpath); } } #else if(!(handle=fopen(rcname,"rb"))) /* no concept of ~ in win32 */ { /* Try to find rcname in USERPROFILE */ char *home; char *rcpath; home=getenv("USERPROFILE"); if (home != NULL) { /* printf("USERPROFILE = %s\n", home); */ rcpath=(char *)alloca(strlen(home)+1+strlen(rcname)+1); strcpy(rcpath,home); strcat(rcpath,"\\"); strcat(rcpath,rcname); /* printf("rcpath = %s\n", rcpath); */ } if ((home == NULL) || (!(handle=fopen(rcpath,"rb")))) { /* printf("No rc file\n"); */ wave_gconf_client_set_string("/current/rcfile", ""); errno=0; if(GLOBALS->possibly_use_rc_defaults) vanilla_rc(); return; /* no .rc file */ } wave_gconf_client_set_string("/current/rcfile", rcpath); } #endif GLOBALS->rc_line_no=0; while(!feof(handle)) { char *str; GLOBALS->rc_line_no++; if((str=fgetmalloc(handle))) { int len; len=strlen(str); if(len) { for(i=0;i<len;i++) { int pos; if((str[i]==' ')||(str[i]=='\t')) continue; /* skip leading ws */ if(str[i]=='#') break; /* is a comment */ for(pos=i;i<len;i++) { if((str[i]==' ')||(str[i]=='\t')) { str[i]=0; /* null term envname */ for(i=i+1;i<len;i++) { struct rc_entry *r; if((str[i]==' ')||(str[i]=='\t')) continue; if((r=bsearch((void *)(str+pos), (void *)rcitems, sizeof(rcitems)/sizeof(struct rc_entry), sizeof(struct rc_entry), rc_compare))) { int j; for(j=len-1;j>=i;j--) { if((str[j]==' ')||(str[j]=='\t')) /* nuke trailing spaces */ { str[j]=0; continue; } else { break; } } r->func(str+i); /* call resolution function */ } break; } break; /* added so multiple word values work properly*/ } } break; } } free_2(str); } } fclose(handle); errno=0; return; }