Esempio n. 1
0
int main(int argc, char *argv[])
{
	astring *srcdir = NULL, *dstdir = NULL;
	int unadorned = 0;
	int result;
	int argnum;

	/* loop over arguments */
	for (argnum = 1; argnum < argc; argnum++)
	{
		char *arg = argv[argnum];

		/* include path? */
		if (arg[0] == '-' && arg[1] == 'I')
		{
			*incpathhead = malloc(sizeof(**incpathhead));
			if (*incpathhead != NULL)
			{
				(*incpathhead)->next = NULL;
				(*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]);
				incpathhead = &(*incpathhead)->next;
			}
		}

		/* other parameter */
		else if (arg[0] != '-' && unadorned == 0)
		{
			srcdir = astring_dupc(arg);
			unadorned++;
		}
		else if (arg[0] != '-' && unadorned == 1)
		{
			dstdir = astring_dupc(arg);
			unadorned++;
		}
		else
			goto usage;
	}

	/* make sure we got 2 parameters */
	if (srcdir == NULL || dstdir == NULL)
		goto usage;

	/* recurse over subdirectories */
	result = recurse_dir(astring_len(srcdir), astring_len(dstdir), srcdir, dstdir);

	/* free source and destination directories */
	astring_free(srcdir);
	astring_free(dstdir);
	return result;

usage:
	fprintf(stderr, "Usage:\n%s <srcroot> <destroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]);
	return 1;
}
Esempio n. 2
0
static void output_footer_and_close_file(core_file *file, const astring *templatefile, const astring *title)
{
	astring *modified;

	modified = astring_dup(templatefile);
	astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title));
	core_fwrite(file, astring_c(modified), astring_len(modified));
	astring_free(modified);
	core_fclose(file);
}
Esempio n. 3
0
static core_file *create_file_and_output_header(const astring *filename, const astring *templatefile, const astring *title)
{
	astring *modified;
	core_file *file;

	/* create the indexfile */
	if (core_fopen(astring_c(filename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
		return NULL;

	/* print a header */
	modified = astring_dup(templatefile);
	astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title));
	core_fwrite(file, astring_c(modified), astring_len(modified));

	/* return the file */
	astring_free(modified);
	return file;
}
Esempio n. 4
0
static void recurse_dependencies(file_entry *file, tagmap *map)
{
	int filelen = astring_len(file->name);
	exclude_path *exclude;
	dependency *dep;

	/* skip if we're in an exclude path */
	for (exclude = excpaths; exclude != NULL; exclude = exclude->next)
		if (exclude->pathlen < filelen && strncmp(astring_c(file->name), astring_c(exclude->path), exclude->pathlen) == 0)
			if (exclude->recursive || astring_chr(file->name, exclude->pathlen + 1, '/') == -1)
				return;

	/* attempt to add; if we get an error, we're already present */
	if (tagmap_add(map, astring_c(file->name), file->name, FALSE) != TMERR_NONE)
		return;

	/* recurse the list from there */
	for (dep = file->deplist; dep != NULL; dep = dep->next)
		recurse_dependencies(dep->file, map);
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	include_path **incpathhead = &incpaths;
	exclude_path **excpathhead = &excpaths;
	astring *srcdir = NULL;
	int unadorned = 0;
	int result;
	int argnum;

	/* loop over arguments */
	for (argnum = 1; argnum < argc; argnum++)
	{
		char *arg = argv[argnum];

		/* include path? */
		if (arg[0] == '-' && arg[1] == 'I')
		{
			*incpathhead = (include_path *)malloc(sizeof(**incpathhead));
			if (*incpathhead != NULL)
			{
				(*incpathhead)->next = NULL;
				(*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]);
				incpathhead = &(*incpathhead)->next;
			}
		}

		/* exclude path? */
		else if (arg[0] == '-' && arg[1] == 'X')
		{
			*excpathhead = (exclude_path *)malloc(sizeof(**excpathhead));
			if (*excpathhead != NULL)
			{
				astring *path;
				(*excpathhead)->next = NULL;
				path = astring_replacechr(astring_dupc(&arg[2]), PATH_SEPARATOR[0], '/');
				(*excpathhead)->recursive = (astring_replacec(path, astring_len(path) - 4, "/...", "") != 0);
				(*excpathhead)->path = path;
				(*excpathhead)->pathlen = astring_len(path);
				excpathhead = &(*excpathhead)->next;
			}
		}

		/* ignore -include which is used by sdlmame to include sdlprefix.h before all other includes */
		else if (strcmp(arg,"-include") == 0)
		{
			argnum++;
		}

		/* other parameter */
		else if (arg[0] != '-' && unadorned == 0)
		{
			srcdir = astring_replacechr(astring_dupc(arg), '/', PATH_SEPARATOR[0]);
			unadorned++;
		}
		else
			goto usage;
	}

	/* make sure we got 1 parameter */
	if (srcdir == NULL)
		goto usage;

	/* create a tagmap for tracking files we've visited */
	file_map = tagmap_alloc();

	/* recurse over subdirectories */
	result = recurse_dir(astring_len(srcdir), srcdir);

	/* free source and destination directories */
	tagmap_free(file_map);
	astring_free(srcdir);
	return result;

usage:
	fprintf(stderr, "Usage:\n%s <srcroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]);
	return 1;
}