Exemple #1
0
const char* CCAPI_Config_get_version() {
	return config_get_version();
}
Exemple #2
0
int parse_metadata() {
	int returnV = 0;
	int done = 0;
	char *line;
	
	do {
		do {
			line = config_read_line();
			if (*line == '\n' || *line == '#') {
				free(line);
				line = NULL;
			}
		} while (!line);
		
		// Required metadata
		if (config_key_match(line, "name")) {
			packager.pkgname = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "repo")) {
			packager.repo = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "version")) {
			config_get_version(line, '=', &packager.version);
			packager.mdlen++;
		}
		// Optional metadata
		else if (config_key_match(line, "description")) {
			packager.description = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "dependencies")) {
			// A bit more complicated
			packager.mdlen++;
			char *deplist = config_get_string(line);
			int i, j = 0;
			for (i = 0; 1; ++i) {
				if (deplist[i] == ' ' || deplist[i] == '\0') {
					char *dep = malloc(strlen(deplist));
					strcpy(dep, deplist + j);
					dep[i - j] = '\0';
					j = i + 1;
					versionData *version = malloc(sizeof(version));
					version->major = version->minor = version->patch = 0;
					if (strchr(dep, ':') != NULL) {
						config_get_version(dep, ':', version);
						*strchr(dep, ':') = '\0';
					}
					packageDependency *depv = malloc(sizeof(packageDependency));
					depv->version = *version;
					depv->name = dep;
					packager.dependencies[packager.dependencies_len] = depv;
					packager.dependencies_len++;
				}
				if (deplist[i] == '\0') {
					break;
				}
			}
		} else if (config_key_match(line, "author")) {
			packager.author = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "maintainer")) {
			packager.maintainer = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "copyright")) {
			packager.copyright = config_get_string(line);
			packager.mdlen++;
		} else if (config_key_match(line, "infourl")) {
			packager.infourl = config_get_string(line);
			packager.mdlen++;
		}
		
		done = *line == '\0';
		free(line);
	} while (!done);
	
	if (!packager.pkgname) {
		printf("Error: configuration does not include package name.\n");
		exit(1);
	}
	if (!packager.repo) {
		printf("Error: configuration does not include package repository.\n");
		exit(1);
	}
	if (packager.version.major == 0xff || packager.version.minor == 0xff || packager.version.patch == 0xff) {
		printf("Error: configuration does not include valid package version.\n");
		exit(1);
	}
	
	return returnV;
}