コード例 #1
0
ファイル: solarsystem.c プロジェクト: kaspermeerts/kosmos
static bool load_body(ALLEGRO_CONFIG *cfg, const char *fullname,
		Body *body, char **primary_name)
{
	const char *name;
	char *type;

	/* Just checking */
	if (al_get_first_config_entry(cfg, fullname, NULL) == NULL)
	{
		log_err("Section %s not in file\n", fullname);
		return false;
	}

	/* Fill in some common parameters */
	if (!config_get_double(cfg, fullname, "Mass", &body->mass, false))
		return false;

	if (!config_get_double(cfg, fullname, "Gravitational parameter",
			&body->grav_param, true))
	{
		body->grav_param = GRAV_CONST * body->mass;
	}

	if (!config_get_double(cfg, fullname, "Radius", &body->radius, false))
		return false;

	/* Figure out what kind of object it is */
	config_get_string(cfg, fullname, "Type", &type, true);
	if (type == NULL)
		body->type = BODY_UNKNOWN;
	else if (strcmp(type, "Star") == 0)
		body->type = BODY_STAR;
	else if (strcmp(type, "Planet") == 0)
		body->type = BODY_PLANET;
	else if (strcmp(type, "Moon") == 0)
		body->type = BODY_PLANET;
	else if (strcmp(type, "Comet") == 0)
		body->type = BODY_COMET;
	else
	{
		log_err("Unknown type: %s\n", type);
		ralloc_free(type);
		return false;
	}
	ralloc_free(type);

	/* Does it have a primary or not? 
	 * Full names are of the form of "Primary/Name"
	 * We search backwards to allow for things like "Sol/Earth/Moon" */
	if ((name = strrchr(fullname, '/')) == NULL)
	{
		/* This is a body without a primary */
		body->name = ralloc_strdup(body->ctx, fullname);
		body->type = (body->type == BODY_UNKNOWN ? BODY_STAR : body->type);
		body->primary = NULL;
		*primary_name = NULL;
	} else if (name == fullname) /* No primary name, eg: sec = "/Earth" */
	{
		log_err("Malformed name: %s", fullname);
		return false;
	} else
	{
		const char *c;
		for (c = name - 1; c >= fullname && *c != '/'; c--);
		c++;

		body->name = ralloc_strdup(body->ctx, name + 1);
		body->type = (body->type == BODY_UNKNOWN ? BODY_PLANET : body->type);
		body->primary = NULL; /* Fill in later */
		*primary_name = ralloc_strndup(body->ctx, c, name - c);
	}

	body->num_satellites = 0;
	body->satellite = NULL;

	/* Bodies without primaries can't orbit another body */
	if (*primary_name == NULL)
		return true;

	if (!config_get_double(cfg, fullname, "Ecc", &body->orbit.Ecc, false) ||
	    !config_get_double(cfg, fullname, "SMa", &body->orbit.SMa, false) ||
	    !config_get_double(cfg, fullname, "Inc", &body->orbit.Inc, false) ||
	    !config_get_double(cfg, fullname, "LAN", &body->orbit.LAN, false) ||
	    !config_get_double(cfg, fullname, "APe", &body->orbit.APe, false) ||
	    !config_get_double(cfg, fullname, "MnA", &body->orbit.MnA, false))
	{
		log_err("Couldn't load orbital elements of %s\n", fullname);
		return false;
	}

	return true;
}
コード例 #2
0
CWBool CWParseSettingsFile()
{
	char line[CW_BUFFER_SIZE];

	gSettingsFile = fopen(gCWSettingsFileName, "rb");
	if (gSettingsFile == NULL) {
		CWErrorRaiseSystemError(CW_ERROR_GENERAL);
	}

	if (!(gDefaultQosValues = ralloc_array(NULL, WTPQosValues, NUM_QOS_PROFILES)))
		return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);

	while (CWGetCommand(gSettingsFile, line, sizeof(line)) == CW_TRUE) {
		char *startTag = NULL;
		char *endTag = NULL;

		if ((startTag = strchr(line, '<')) == NULL)
			continue;

		if ((endTag = strchr(line, '>')) == NULL)
			continue;

		if (!strncmp(startTag + 1, "CWMIN_VOICE", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMIN_DEFAULT;
			gDefaultQosValues[VOICE_QUEUE_INDEX].cwMin = value;
			CWDebugLog("CWMIN_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].cwMin);
			continue;
		}
		if (!strncmp(startTag + 1, "CWMAX_VOICE", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMAX_DEFAULT;
			gDefaultQosValues[VOICE_QUEUE_INDEX].cwMax = value;
			CWDebugLog("CWMAX_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].cwMax);
			continue;
		}
		if (!strncmp(startTag + 1, "AIFS_VOICE", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = AIFS_DEFAULT;
			gDefaultQosValues[VOICE_QUEUE_INDEX].AIFS = value;
			CWDebugLog("AIFS_VOICE: %d", gDefaultQosValues[VOICE_QUEUE_INDEX].AIFS);
			continue;
		}

		if (!strncmp(startTag + 1, "CWMIN_VIDEO", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMIN_DEFAULT;
			gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMin = value;
			CWDebugLog("CWMIN_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMin);
			continue;
		}
		if (!strncmp(startTag + 1, "CWMAX_VIDEO", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMAX_DEFAULT;
			gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMax = value;
			CWDebugLog("CWMAX_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].cwMax);
			continue;
		}
		if (!strncmp(startTag + 1, "AIFS_VIDEO", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = AIFS_DEFAULT;
			gDefaultQosValues[VIDEO_QUEUE_INDEX].AIFS = value;
			CWDebugLog("AIFS_VIDEO: %d", gDefaultQosValues[VIDEO_QUEUE_INDEX].AIFS);
			continue;
		}

		if (!strncmp(startTag + 1, "CWMIN_BEST_EFFORT", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMIN_DEFAULT;
			gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMin = value;
			CWDebugLog("CWMIN_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMin);
			continue;
		}
		if (!strncmp(startTag + 1, "CWMAX_BEST_EFFORT", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMAX_DEFAULT;
			gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMax = value;
			CWDebugLog("CWMAX_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].cwMax);
			continue;
		}
		if (!strncmp(startTag + 1, "AIFS_BEST_EFFORT", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = AIFS_DEFAULT;
			gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].AIFS = value;
			CWDebugLog("AIFS_BEST_EFFORT: %d", gDefaultQosValues[BESTEFFORT_QUEUE_INDEX].AIFS);
			continue;
		}

		if (!strncmp(startTag + 1, "CWMIN_BACKGROUND", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMIN_DEFAULT;
			gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMin = value;
			CWDebugLog("CWMIN_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMin);
			continue;
		}
		if (!strncmp(startTag + 1, "CWMAX_BACKGROUND", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = CWMAX_DEFAULT;
			gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMax = value;
			CWDebugLog("CWMAX_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].cwMax);
			continue;
		}
		if (!strncmp(startTag + 1, "AIFS_BACKGROUND", endTag - startTag - 1)) {
			int value = atoi(endTag + 1);

			if (value == 0)
				value = AIFS_DEFAULT;
			gDefaultQosValues[BACKGROUND_QUEUE_INDEX].AIFS = value;
			CWDebugLog("AIFS_BACKGROUND: %d", gDefaultQosValues[BACKGROUND_QUEUE_INDEX].AIFS);
			continue;
		}
		if (!strncmp(startTag + 1, "AC_HOSTAPD_PORT", endTag - startTag - 1)) {

			gHostapd_port = atoi(endTag + 1);

			CWDebugLog("Hostapd Port connection: %d", gHostapd_port);
			continue;
		}
		if (!strncmp(startTag + 1, "AC_HOSTAPD_UNIX_PATH", endTag - startTag - 1)) {
			char *startValue = NULL;
			char *endValue = NULL;
			int offset = 0;

			CWExtractValue(endTag, &startValue, &endValue, &offset);

			if (!((gHostapd_unix_path = ralloc_strndup(NULL, startValue, offset))))
				return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL);

			CWDebugLog("Hostapd Unix Domain Path: %s", gHostapd_unix_path);
			continue;

		}
	}
	return CW_TRUE;
}