Beispiel #1
0
int scconf_put_int(scconf_block * block, const char *option, int value)
{
	char *str;

	str = malloc(64);
	if (!str) {
		return value;
	}
	snprintf(str, 64, "%i", value);
	scconf_put_str(block, option, str);
	free(str);
	return value;
}
Beispiel #2
0
static int write_type(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
{
	void *parm = entry->parm;
	void *arg = entry->arg;
	int (*callback_func) (scconf_context * config, scconf_block * block, scconf_entry * entry, int depth) =
	(int (*)(scconf_context *, scconf_block *, scconf_entry *, int)) parm;
	int r = 0;

	if (config->debug) {
		fprintf(stderr, "encoding '%s'\n", entry->name);
	}
	switch (entry->type) {
	case SCCONF_CALLBACK:
		if (parm) {
			r = callback_func(config, block, entry, depth);
		}
		break;
	case SCCONF_BLOCK:
		if (parm) {
			scconf_block *subblock;
			const scconf_list *name = (const scconf_list *) arg;

			subblock = scconf_block_add(config, block, entry->name, name);
			r = write_entries(config, subblock, (scconf_entry *) parm, depth + 1);
		}
		break;
	case SCCONF_LIST:
		if (parm) {
			const scconf_list *val = (const scconf_list *) parm;

			scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_VALUE, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				char *buf = scconf_list_strdup(val, ", ");
				printf("%s = %s\n", entry->name, buf);
				free(buf);
			}
		}
		break;
	case SCCONF_BOOLEAN:
		if (parm) {
			const int val = * (int* ) parm;

			scconf_put_bool(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val == 0 ? "false" : "true");
			}
		}
		break;
	case SCCONF_INTEGER:
		if (parm) {
			const int val = * (int*) parm;

			scconf_put_int(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %i\n", entry->name, val);
			}
		}
		break;
	case SCCONF_STRING:
		if (parm) {
			const char *val = (const char *) parm;

			scconf_put_str(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val);
			}
		}
		break;
	default:
		fprintf(stderr, "invalid configuration type: %d\n", entry->type);
	}
	if (r) {
		fprintf(stderr, "encoding of configuration entry '%s' failed.\n", entry->name);
		return r;
	}
	entry->flags |= SCCONF_PRESENT;
	return 0;
}
Beispiel #3
0
int scconf_put_bool(scconf_block * block, const char *option, int value)
{
	scconf_put_str(block, option, !value ? "false" : "true");
	return value;
}
static int write_cb(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
{
	scconf_put_str(block, entry->name, "inside write_cb();");
	scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_COMMENT, NULL, "# commentN");
	return 0;		/* 0 for ok, 1 for error */
}