void verifySDownConditions(void)
{
  if(sDown_filtered < SDown_Threshold)
    {
      if(sd_printing)
	{

	  initPause();
	  config.status = 9;
	  write_config();
	  sd_printing = false;

	  queue_flush();
	  reset_current_block();

	  home_z();
	}
      else if(printerPause)
	{
	  config.status = 9;
	  write_config();
	  sd_printing = false;

	  queue_flush();
	  reset_current_block();

	  home_z();
	}
    }
}
Beispiel #2
0
/*********************************************
Update an entry from a network frame
return RET_NOK on error
*********************************************/
ret_code_t entry_update(char * data)
{
	char * elements[5] = {NULL,NULL,NULL,NULL,NULL};
	config_setting_t * setting;
	const config_t * config= NULL;
	int value;
	char * token;
	int index = 0;
	ret_code_t ret = RET_NOK;

	token = _strsep(&data,NETWORK_DELIMITER);
	while( token != NULL ) {
		elements[index] = strdup(token);
		index++;
		if(index>5) {
			werr(LOGDEV,"Split string error");
			goto entry_update_cleanup;
		}
		token = _strsep(&data,NETWORK_DELIMITER);
	}

	SDL_LockMutex(entry_mutex);
	config = get_config(elements[1],elements[2]);
	if(config==NULL) {
		goto entry_update_cleanup;
	}

	setting = config_lookup (config, elements[3]);
	if(setting==NULL) {
		goto entry_update_cleanup;
	}

	if( strcmp(elements[0],ENTRY_TYPE_INT) == 0 ) {
		value = atoll(elements[4]);
		if(config_setting_set_int (setting, value) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %d",elements[1],elements[2],elements[3],value);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	} else if( strcmp(elements[0],ENTRY_TYPE_STRING) == 0 ) {
		if(config_setting_set_string (setting,elements[4]) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %s",elements[1],elements[2],elements[3],elements[4]);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	}

	ret = RET_OK;

entry_update_cleanup:
	SDL_UnlockMutex(entry_mutex);
	for(index=0; index<5; index++) {
		if(elements[index]) {
			free(elements[index]);
		}
	}

	return ret;
}
Beispiel #3
0
/*
 * the notify_action_* functions get called when the user clicks on
 * the respective buttons we put in the notification window.
 * user_data contains the string we pass, so "yes" "no" "always" or "never".
 */
static void notify_action(NotifyNotification __unused *notify,
					gchar __unused *action, gpointer user_data)
{
	char *answer = (char *) user_data;

	send_permission(answer);
	detail_file_name = NULL;
	if (strcmp(answer, "always") == 0)
		write_config("always");
	if (strcmp(answer, "never") == 0)
		write_config("never");
	gtk_status_icon_set_visible(statusicon, FALSE);
}
Beispiel #4
0
int set_cluster_store(const char *name)
{
	memset(config.store, 0, sizeof(config.store));
	pstrcpy((char *)config.store, sizeof(config.store), name);

	return write_config();
}
bool ConfigFile::remove_rom_id_1(std::string package, std::string rom_id) {
    const Json::Value syncacross =
            m_root[CONF_PACKAGES][package][CONF_SYNC_ACROSS];

    if (syncacross.isNull() || !syncacross.isArray()) {
        return false;
    }

    bool removed = false;

    // jsoncpp has no built-in way of removing items from an array
    Json::Value new_array(Json::arrayValue);
    for (unsigned int i = 0; i < syncacross.size(); i++) {
        std::string value = syncacross[i].asString();
        if (rom_id == value) {
            removed = true;
            continue;
        }
        new_array.append(value);
    }

    if (new_array.size() == 0) {
        m_root[CONF_PACKAGES].removeMember(package);
        removed = true;
    } else {
        m_root[CONF_PACKAGES][package][CONF_SYNC_ACROSS] = new_array;
    }

    if (removed) {
        write_config();
    }

    return removed;
}
Beispiel #6
0
int init_config_file(void)
{
	int fd, ret;

	check_tmp_config();

	fd = open(config_path, O_RDONLY);
	if (fd < 0) {
		if (errno != ENOENT) {
			sd_eprintf("failed to read config file, %m");
			return -1;
		}
		goto create;
	}

	ret = xread(fd, &config, sizeof(config));
	if (ret == 0) {
		close(fd);
		goto create;
	}
	if (ret < 0) {
		sd_eprintf("failed to read config file, %m");
		goto out;
	}

	if (config.version != SD_FORMAT_VERSION) {
		sd_eprintf("This sheep version is not compatible with"
			   " the existing data layout, %d", config.version);
		if (sys->upgrade) {
			/* upgrade sheep store */
			ret = sd_migrate_store(config.version, SD_FORMAT_VERSION);
			if (ret == 0) {
				/* reload config file */
				ret = xpread(fd, &config, sizeof(config), 0);
				if (ret != sizeof(config)) {
					sd_eprintf("failed to reload config"
						   " file, %m");
					ret = -1;
				} else
					ret = 0;
			}
			goto out;
		}

		sd_eprintf("use '-u' option to upgrade sheep store");
		ret = -1;
		goto out;
	}
	ret = 0;
out:
	close(fd);

	return ret;
create:
	config.version = SD_FORMAT_VERSION;
	if (write_config() != SD_RES_SUCCESS)
		return -1;

	return 0;
}
Beispiel #7
0
/*********************
return RET_NOK on error
*********************/
static ret_code_t __write_list_index(const char * table, const char * file, const char * data, int index, va_list ap)
{
	config_setting_t * setting = NULL;
	const config_t * config;
	int list_size;


	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	if(config==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	setting = create_tree(config,NULL,NULL,NULL,CONFIG_TYPE_ARRAY,ap);

	// Create empty entry before index
	list_size = config_setting_length (setting);
	while( list_size <= index ) {
		if(config_setting_set_string_elem(setting,-1,"")==NULL) {
			SDL_UnlockMutex(entry_mutex);
			return RET_NOK;
		}
		list_size++;
	}

	if(config_setting_set_string_elem(setting,index,data)==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	write_config(config,table,file);
	SDL_UnlockMutex(entry_mutex);
	return RET_OK;
}
Beispiel #8
0
/*********************
return RET_NOK on error
*********************/
static ret_code_t __write_list(const char * table, const char * file, char ** data, va_list ap)
{
	config_setting_t * setting;
	const config_t * config;
	int i=0;

	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	if(config==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	setting = create_tree(config,NULL,NULL,NULL,CONFIG_TYPE_ARRAY,ap);

	while(data[i] != NULL) {
		// First try to update existing setting
		if(config_setting_set_string_elem(setting,i,data[i])==NULL) {
			// If it down not exist, add a new setting at the end of the list
			if(config_setting_set_string_elem(setting,-1,data[i])==NULL) {
				SDL_UnlockMutex(entry_mutex);
				return RET_NOK;
			}
		}
		i++;
	}

	write_config(config,table,file);
	SDL_UnlockMutex(entry_mutex);

	return RET_OK;
}
Beispiel #9
0
void terminate (void)
{
    /*
    int fh[10000], i;
    char buffer[100];

    for (i=0; i<10000; i++)
    {
        sprintf (buffer, "file%d", i);
        fh[i] = open (buffer, O_CREAT|O_WRONLY);
        if (fh[i] < 0) break;
    }
    close (fh[0]);
    */

    write_config ();
    video_update (0);

    set_window_name (wintitle);

    fly_terminate ();
#ifdef __MINGW32__
    WSACleanup ();
#endif
}
static void read_config(void)
{
	gchar *path;
	gboolean initial = FALSE;

	debug_print("autoenc: read_config\n");
	path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "autoencrc", NULL);
	if (!is_file_exist(path)) {
		initial = TRUE;
		prefs_set_default(param);
	} else {
		prefs_read_config(param, "AutoEncrypt", path, NULL);
	}

	if (!config.autoenc_template_subject) {
		config.autoenc_template_subject =
			g_strdup(_("Password of encrypted file"));
	}
	if (!config.autoenc_template_body) {
		config.autoenc_template_body =
			g_strdup(_("Subject: %s\\n"
				   "Date: %d\\n"
				   "The password of the encrypted file attached in the above mail is as follows:\\n"
				   "\\n"
				   "File name: %z\\n"
				   "Password: %p"));
	}

	if (initial) {
		write_config();
	}

	g_free(path);
}
Beispiel #11
0
/* open_default will make function reload default session files on close */
void project_close(gboolean open_default)
{
	GSList *node;

	g_return_if_fail(app->project != NULL);

	ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);

	/* use write_config() to save project session files */
	if (!write_config(FALSE))
		g_warning("Project file \"%s\" could not be written", app->project->file_name);

	/* remove project filetypes build entries */
	if (app->project->build_filetypes_list != NULL)
	{
		g_ptr_array_foreach(app->project->build_filetypes_list, remove_foreach_project_filetype, NULL);
		g_ptr_array_free(app->project->build_filetypes_list, FALSE);
	}

	/* remove project non filetype build menu items */
	build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1);
	build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1);

	g_free(app->project->name);
	g_free(app->project->description);
	g_free(app->project->file_name);
	g_free(app->project->base_path);

	g_free(app->project);
	app->project = NULL;

	foreach_slist(node, stash_groups)
		stash_group_free(node->data);

	g_slist_free(stash_groups);
	stash_groups = NULL;

	apply_editor_prefs(); /* ensure that global settings are restored */

	if (project_prefs.project_session)
	{
		/* close all existing tabs first */
		document_close_all();

		/* after closing all tabs let's open the tabs found in the default config */
		if (open_default && cl_options.load_session)
		{
			configuration_reload_default_session();
			configuration_open_files();
			/* open a new file if no other file was opened */
			document_new_file_if_non_open();
			ui_focus_current_document();
		}
	}
	g_signal_emit_by_name(geany_object, "project-close");

	update_ui();
}
Beispiel #12
0
void server::handle_flush(const boost::system::error_code& error)
{
	if(error) {
		ERR_CS << "Error from reload timer: " << error.message() << "\n";
		throw boost::system::system_error(error);
	}
	write_config();
	flush_cfg();
}
JNIEXPORT jboolean JNICALL Java_com_fastrunningblog_FastRunningFriend_ConfigState_write_1config
  (JNIEnv *env, jobject this_obj, jstring profile_name)
{
  jboolean res;
  const char* profile_name_s = (*env)->GetStringUTFChars(env,profile_name,0);
  res = write_config(env,this_obj,profile_name_s);
  (*env)->ReleaseStringUTFChars(env,profile_name,profile_name_s);
  return res;
}
JNIEXPORT jboolean
Java_com_fastrunningblog_FastRunningFriend_GPSCoordBuffer_init_1data_1dir( JNIEnv* env,
                                                  jobject this_obj, jstring dir_name_str )
{
  struct stat s;
  jboolean status = 0;
  const char *dir_name = (*env)->GetStringUTFChars(env, dir_name_str, NULL);
  int dir_created = 0;
  
  gps_data_dir[0] = 0;
  
  if (!dir_name)
    goto err;
  
  if (stat(dir_name,&s))
  {
    jobject cfg_obj;
    
    if (mkdir(dir_name,0755))
      goto err;
    
    dir_created = 1;
    
    if (!(cfg_obj = (*env)->GetObjectField(env,this_obj,gps_buf_fields.cfg_id)))
    {
      LOGE("Could not find config object while writing default config file");
      goto done;
    }
    
    if (!write_config(env,cfg_obj,"default"))
      LOGE("Error writing default config file");
    
    goto done;
  }  
  
  if ((s.st_mode & S_IFMT) != S_IFDIR)
    goto err;

done:  
  gps_data_dir_len = strlen(dir_name);
  
  if (gps_data_dir_len > sizeof(gps_data_dir) - 1)
    goto err;
  
  memcpy(gps_data_dir,dir_name,gps_data_dir_len+1);
  status = 1;  
  
  if (!dir_created)
    remove_expired_files(env,this_obj,gps_data_dir);
  
err:  
  if (dir_name)
    (*env)->ReleaseStringUTFChars(env,dir_name_str,dir_name);
  return status;
}
Beispiel #15
0
int s2e_clear (HTTP_INFO *info)
{
	int chan;

	for (chan = 0; chan < S2E_CHAN_MAX; chan ++) {
		default_config (chan, &s2e_conf[chan]);
		write_config (chan, &s2e_conf[chan]);
	}

	return 0;
}
Beispiel #16
0
int set_cluster_config(const struct cluster_info *cinfo)
{
	config.ctime = cinfo->ctime;
	config.copies = cinfo->nr_copies;
	config.copy_policy = cinfo->copy_policy;
	config.flags = cinfo->flags;
	memset(config.store, 0, sizeof(config.store));
	pstrcpy((char *)config.store, sizeof(config.store),
		(char *)cinfo->store);
	return write_config();
}
Beispiel #17
0
 void write_config
 (
     const Ch*                       a_filename,
     const basic_variant_tree<Ch>&   a_tree,
     config_format                   a_format,
     const Settings&                 a_settings = Settings(),
     const std::locale &             a_loc      = std::locale()
 ) {
     write_config(std::basic_string<Ch>(a_filename),
                  a_tree, a_format, a_settings, a_loc);
 }
Beispiel #18
0
 void LoginWidget::set_connected (bool connected)
 {
     QString status;
     if (connected)
     {
         status = "Connected to " + edit_host_->text();
         write_config();
     }
     else
         status = "Offline";
     label_status_->setText(status);
 }
Beispiel #19
0
void terminate (void)
{
    write_config ();
    video_update (0);
    
    set_window_name (wintitle);
        
    fly_terminate ();
#ifdef __MINGW32__
    WSACleanup ();
#endif
}
Beispiel #20
0
void
on_button4_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{  
memcpy(host,(char *)gtk_entry_get_text ((GtkEntry *)entry4),strlen((gchar *)gtk_entry_get_text ((GtkEntry *)entry4)));
write_config((gchar *)gtk_entry_get_text ((GtkEntry *)entry1),
			"");

	get_socket((char *)gtk_entry_get_text ((GtkEntry *)entry4));
	getAtrBox = create_messagebox("提示","恭喜,获取服务成功!",1);
 	gtk_widget_show (getAtrBox);
	return;//sorry i can not understand what is this
}
Beispiel #21
0
void server::handle_delete(const server::request& req)
{
	const config& erase = req.cfg;

	if(read_only_) {
		LOG_CS << "in read-only mode, request to delete '" << erase["name"] << "' from " << req.addr << " denied\n";
		send_error("Cannot delete add-on: The server is currently in read-only mode.", req.sock);
		return;
	}

	LOG_CS << "deleting campaign '" << erase["name"] << "' requested from " << req.addr << "\n";

	config& campaign = get_campaign(erase["name"]);

	if(!campaign) {
		send_error("The add-on does not exist.", req.sock);
		return;
	}

	if(!authenticate(campaign, erase["passphrase"])
		&& (campaigns()["master_password"].empty()
		|| campaigns()["master_password"] != erase["passphrase"]))
	{
		send_error("The passphrase is incorrect.", req.sock);
		return;
	}

	// Erase the campaign.
	filesystem::write_file(campaign["filename"], std::string());
	if(remove(campaign["filename"].str().c_str()) != 0) {
		ERR_CS << "failed to delete archive for campaign '" << erase["name"]
			   << "' (" << campaign["filename"] << "): " << strerror(errno)
			   << '\n';
	}

	config::child_itors itors = campaigns().child_range("campaign");
	for(size_t index = 0; !itors.empty(); ++index, itors.pop_front())
	{
		if(&campaign == &itors.front()) {
			campaigns().remove_child("campaign", index);
			break;
		}
	}

	write_config();

	send_message("Add-on deleted.", req.sock);

	fire("hook_post_erase", erase["name"]);

}
Beispiel #22
0
void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{	
if(gtk_toggle_button_get_active((GtkToggleButton *)checkbutton1))
write_config((gchar *)gtk_entry_get_text ((GtkEntry *)entry1),
			(gchar *)gtk_entry_get_text ((GtkEntry *)entry2));
else
write_config((gchar *)gtk_entry_get_text ((GtkEntry *)entry1),
			"");	
gtk_widget_hide_all (window1);
linkwindow = create_window3 ();
gtk_widget_show_all (linkwindow);
gint ptimer_flash=0;
gtk_timeout_remove(ptimer_flash);
ptimer_flash=gtk_timeout_add(15000,flash_timeout,NULL);	
	
pthread_t getaccess;
Acc_Keep_Link=0;
memcpy(username,(char *)gtk_entry_get_text ((GtkEntry *)entry1),strlen((char *)gtk_entry_get_text ((GtkEntry *)entry1)));
memcpy(passwd,(char *)gtk_entry_get_text ((GtkEntry *)entry2),strlen((char *)gtk_entry_get_text ((GtkEntry *)entry2)));
pthread_create(&getaccess,NULL,Access_Thread,NULL);
}
Beispiel #23
0
void cli_frontend_exit(void)
{
	/* close open files */
	if (logfile) fclose(logfile);

	if (options.playback) mame_fclose(options.playback);
	if (options.record)   mame_fclose(options.record);
	if (options.language_file) mame_fclose(options.language_file);

#ifdef MESS
	if (win_write_config)
		write_config(NULL, Machine->gamedrv);
#endif /* MESS */
}
void save(){
	
	gtk_color_button_get_color(GTK_COLOR_BUTTON(button_bcolor), &bcolor);
	gtk_color_button_get_color(GTK_COLOR_BUTTON(button_fcolor), &fcolor);

	struct v *p = st;
	int i;
	for(i = 0; i < c; i++){
		set_data(p);
		p = p -> next;
	}
	gtk_color_button_set_color(GTK_COLOR_BUTTON(button_bcolor), &bcolor);
	gtk_color_button_set_color(GTK_COLOR_BUTTON(button_fcolor), &fcolor);
	write_config();
}
Beispiel #25
0
void
before_quit                      (GtkWidget       *widget,
                                        gpointer         user_data)
{
/*
char cfgfile[1024]="";
sprintf(cfgfile,"%s/.mynet/run.pid",getenv("HOME"));
unlink(cfgfile);//delete mutex file*/
	
if(gtk_toggle_button_get_active((GtkToggleButton *)checkbutton1))
write_config((gchar *)gtk_entry_get_text ((GtkEntry *)entry1),
			(gchar *)gtk_entry_get_text ((GtkEntry *)entry2));//remember the passwd
close(sockfd); 
gtk_main_quit();
}
Beispiel #26
0
/* display the option dialog */
void display_options(nh_bool change_birth_opt)
{
    struct nh_menuitem *items;
    int icount, size;
    struct nh_option_desc *nhoptions = nh_get_options(GAME_OPTIONS);
    struct nh_option_desc *birthoptions = NULL;
    int n;
    
    size = 10;
    items = malloc(sizeof(struct nh_menuitem) * size);
    
    do {
	icount = 0;
	if (!change_birth_opt) {
	    birthoptions = nh_get_options(ACTIVE_BIRTH_OPTIONS);
	    /* add general game options */
	    add_menu_txt(items, size, icount, "游戏设置:", MI_HEADING);
	    menu_add_options(&items, &size, &icount, GAME_OPTS, nhoptions,
				FALSE);
	    
	    /* add or display birth options */
	    add_menu_txt(items, size, icount, "本次游戏人物设置:",
			    MI_HEADING);
	    menu_add_options(&items, &size, &icount, ACT_BIRTH_OPTS,
				birthoptions, TRUE);
	} else {
	    birthoptions = nh_get_options(CURRENT_BIRTH_OPTIONS);
	    /* add or display birth options */
	    add_menu_txt(items, size, icount, "创建人物设置:", MI_HEADING);
	    menu_add_options(&items, &size, &icount, CUR_BIRTH_OPTS,
				birthoptions, FALSE);
	    
	    add_menu_txt(items, size, icount, "游戏设置:", MI_HEADING);
	    menu_add_options(&items, &size, &icount, GAME_OPTS, nhoptions, FALSE);
	}
	
	/* add UI specific options */
	add_menu_txt(items, size, icount, "界面设置:", MI_HEADING);
	menu_add_options(&items, &size, &icount, UI_OPTS, curses_options, FALSE);
	
	n = curses_display_menu_core(items, icount, "选择哪个设置?", PICK_ONE,
				     NULL, 0, 0, -1, -1, get_option_value, FALSE);
    } while (n > 0);
    free(items);
    
    write_config();
}
Beispiel #27
0
/*********************
return RET_NOK on failure
*********************/
static ret_code_t __remove_from_list(const char * table, const char * file, const char * to_be_removed, va_list ap)
{
	const config_t * config = NULL;
	config_setting_t * setting = NULL;
	char * path;
	int i = 0;
	const char * elem;

	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	if(config==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	path = get_path(ap);
	if(path == NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	setting = config_lookup (config, path);
	if( setting == NULL ) {
		SDL_UnlockMutex(entry_mutex);
		free(path);
		return RET_NOK;
	}
	free(path);

	while( (elem=config_setting_get_string_elem (setting,i )) != NULL ) {
		if( strcmp(elem,to_be_removed) == 0 ) {
			if(config_setting_remove_elem (setting,i)==CONFIG_FALSE) {
				SDL_UnlockMutex(entry_mutex);
				return RET_NOK;
			}

			write_config(config,table,file);
			SDL_UnlockMutex(entry_mutex);
			return RET_OK;
		}
		i++;
	}

	SDL_UnlockMutex(entry_mutex);
	return RET_NOK;
}
Beispiel #28
0
bool
HMC5883L::begin()
{
  // Read the device identity register
  uint8_t id[3];
  twi.begin(this);
  twi.write((uint8_t) IDENTITY);
  twi.read(id, sizeof(id));
  twi.end();

  // Sanity check the identity
  static const uint8_t ID[3] __PROGMEM = { 'H', '4', '3' };
  if (memcmp_P(id, ID, sizeof(ID))) return (false);

  // Write configuration
  return (write_config());
}
Beispiel #29
0
/*********************
return RET_NOK on error
*********************/
static ret_code_t __group_create(const char * table, const char * file, va_list ap)
{
	const config_t * config;

	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	if(config==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	create_tree(config,NULL,NULL,NULL,CONFIG_TYPE_GROUP,ap);

	write_config(config,table,file);
	SDL_UnlockMutex(entry_mutex);
	return RET_OK;
}
Beispiel #30
0
 void write_config
 (
     const std::basic_string<Ch>&    a_filename,
     const basic_variant_tree<Ch>&   a_tree,
     config_format                   a_format,
     const Settings&                 a_settings = Settings(),
     const std::locale &             a_loc      = std::locale()
 ) {
     std::basic_ofstream<Ch> stream(a_filename.c_str());
     if (!stream) {
         throw variant_tree_parser_error(
             "Cannot open file for writing", a_filename, 0);
     }
     stream.imbue(a_loc);
     write_config(stream, a_tree, a_format, a_settings);
     if (!stream.good())
         throw variant_tree_parser_error("Write error", a_filename, 0);
 }