コード例 #1
0
ファイル: parse.c プロジェクト: KaSt/nereamud
//
// tries to make an int parse var
PARSE_VAR *use_one_parse_token_int(const char *buf) {
  PARSE_VAR *var = NULL;
  if(string_is_int(buf)) {
    var = newParseVar(PARSE_VAR_INT);
    var->int_val = atoi(buf);
  }
  return var;
}
コード例 #2
0
ファイル: CommandLine.cpp プロジェクト: HargisJ/KrisLibrary
bool CommandBase::SetArg(int arg, const char* val)
{
	if(0 == strcmp(val,"#")) return true;  //default arguments
	switch(args[arg].type) {
	case Bool: return string_is_bool(val,*(bool*)args[arg].data);
	case Int: return string_is_int(val,*(int*)args[arg].data);
	case Float: return string_is_float(val,*(float*)args[arg].data);
	case Double: return string_is_double(val,*(double*)args[arg].data);
	case String: *(const char**)args[arg].data = val;
		return true;
	}
	return false;
}
コード例 #3
0
ファイル: conf.c プロジェクト: fabienr/sauthpf
int load_config(const char *file)
{
	char *file_content = NULL;
	int i, ret = 0, nline = 1;

	file_content = file_get_contents(file);
	if (file_content == NULL) {
		log(LOG_WARNING, "cannot load content of config file %s", file);
		ret = 1;
		goto end;
	}

	for (i=0; file_content[i]; i++) {
		if (ret == 1) {
			nline++;
			ret = 0;
		}

		/* end of line, increment count */
		if (file_content[i] == '\n') {
			nline++;
			continue;
		}

		/* skip space at beginning  */
		while (file_content[i] && isspace(file_content[i])) {
			if (file_content[i] == '\n') {
				nline++;
				i++;
				continue;
			}
			i++;
		}

		/* it's a comment ? */
		if (file_content[i] == '#') {
			while (file_content[i] && file_content[i] != '\n')
				i++;
			if (file_content[i] == '\n') {
				nline++;
				continue;
			}
			if (!file_content[i])
				break;
		}
		/* test syntax : <var> = <arg> */
		else if (file_content[i]) {
			char *var, *arg;

			arg = &(file_content[i]);

			while (file_content[i] && file_content[i] != '=' &&
			    file_content[i] != '#' && file_content[i] != '\n')
				i++;

			if (file_content[i] != '=' ) {
				log(LOG_WARNING, "syntax error in configuration"
				    " file %s:l%d, should be <arg> = <var>",
				    file, nline);
				i--;
				continue;
			}
			file_content[i] = '\0';

			var = &(file_content[++i]);

			while (file_content[i] && file_content[i] != '\n' &&
			    file_content[i] != '#')
				i++;

			if (file_content[i] == '\n') {
				file_content[i] = '\0';
				ret = 1;
			}
			else if (file_content[i] == '#') {
				file_content[i++] = '\0';
				while (file_content[i] &&
				    file_content[i] != '\n')
					i++;
				ret = 1;
			}
			else {
				i--;
			}

			trim(arg, TRIM_BOTH);
			trim(var, TRIM_BOTH);

			if (!*var || !*arg) {
				log(LOG_WARNING, "syntax error in configuration"
				    " file %s:l%d, should be <arg> = <var>",
				    file, nline);
				continue;
			}
			log(LOG_INFO, "parse arg %s", arg);
			if (!strcmp(arg, "bdd_path")) {
				if (conf_bdd_path != NULL) {
					log(LOG_WARNING, "conf_bdd_path : "
					    "already define %s:l%d",
					    file, nline);
					free(conf_bdd_path);
				}
				conf_bdd_path = strdup(var);
			} else if (!strcmp(arg, "socket_path")) {
				if (conf_socket_path != NULL) {
					log(LOG_WARNING, "conf_socket_path : "
					    "already define %s:l%d",
					    file, nline);
					free(conf_socket_path);
				}
				conf_socket_path = strdup(var);
			} else if (!strcmp(arg, "pid_path")) {
				if (conf_pid_path != NULL) {
					log(LOG_WARNING, "conf_pid_path : "
					    "already define %s:l%d",
					    file, nline);
					free(conf_pid_path);
				}
				conf_pid_path = strdup(var);
			} else if (!strcmp(arg, "user")) {
				if (conf_user != NULL) {
					log(LOG_WARNING, "conf_user : "******"already define %s:l%d",
					    file, nline);
					free(conf_user);
				}
				conf_user = strdup(var);
			} else if (!strcmp(arg, "group")) {
				if (conf_group != NULL) {
					log(LOG_WARNING, "conf_group : "
					    "already define %s:l%d",
					    file, nline);
					free(conf_group);
				}
				conf_group = strdup(var);
			} else if (!strcmp(arg, "url_rewrite_program")) {
				if (conf_url_rewrite_program != NULL) {
					log(LOG_WARNING,
					    "conf_url_rewrite_program : "
					    "already define %s:l%d",
					    file, nline);
					free(conf_url_rewrite_program);
				}
				conf_url_rewrite_program = strdup(var);
			} else if (!strcmp(arg, "sessions_ttl")) {
				if (conf_sessions_ttl) {
					log(LOG_WARNING, "session_ttl : "
					    "already define %s:l%d",
					    file, nline);
				}
				if (string_is_int(var))
					conf_sessions_ttl = atoi(var);
				else
					log(LOG_WARNING, "session_ttl : "
					    "var is not an int %s:l%d",
					    file, nline);
			} else if (!strcmp(arg, "secure_auth")) {
				if (conf_secure_auth != undef) {
					log(LOG_WARNING, "secur_auth : "
					    "already define %s:l%d",
					    file, nline);
				}
				if (!strcasecmp(var, "true"))
					conf_secure_auth = true;
				else if (!strcasecmp(var, "false"))
					conf_secure_auth = false;
				else
					log(LOG_WARNING, "secur_auth : "
					    "var != true or false %s:l%d",
					    file, nline);
			}
			else {
				log(LOG_WARNING, "error in configuration"
				    " file %s:%d : unknow arg '%s'",
				    file, nline, arg);
			}
		}
	}
	ret = 0;
	nline++;

end:
	if (file_content)
		free(file_content);

	if (conf_bdd_path == NULL)
		conf_bdd_path = strdup(CONF_DEFAULT_BDD_PATH);

	if (conf_socket_path == NULL)
		conf_socket_path = strdup(CONF_DEFAULT_SOCKET_PATH);

	if (conf_pid_path == NULL)
		conf_pid_path = strdup(CONF_DEFAULT_PID_PATH);

	if (conf_user == NULL)
		conf_user = strdup(CONF_DEFAULT_USER);

	if (conf_group == NULL)
		conf_group = strdup(CONF_DEFAULT_GROUP);

	if (conf_sessions_ttl == 0)
		conf_sessions_ttl = CONF_DEFAULT_SESSIONS_TTL;

	if (conf_secure_auth == undef)
		conf_secure_auth = CONF_DEFAULT_SECURE_AUTH;

	return (ret);
}