<commit_before>/*
	adjustNamespace.exe [ϊs\[X̃fBNg]

		ϊs\[X̃fBNg  vWFNg̃[gfBNg Ɠzł邱ƁB

		vWFNg̃[gfBNg == .csproj fBNg
*/

#include "C:\Factory\Common\all.h"

static int BatchMode;

static char *GetProjFile_Dir(char *dir)
{
	autoList_t *files = lsFiles(dir);
	char *file;
	uint index;
	char *projFile;

	foreach(files, file, index)
		if(!_stricmp("csproj", getExt(file)))
			break;

	if(file)
		projFile = strx(file);
	else
		projFile = NULL;

	releaseDim(files, 1);
	return projFile;
}
static char *GetProjFile(char *dir)
{
	char *projFile;

	dir = strx(dir);

	while(!(projFile = GetProjFile_Dir(dir)))
	{
		errorCase(isRootDirAbs(dir));

		dir = getParent_x(dir);
	}
	memFree(dir);
	return projFile;
}
static char *GetProjRootNamespace(char *projFile)
{
	autoList_t *lines = readLines(projFile);
	char *line;
	uint index;
	char *ret = NULL;

	foreach(lines, line, index)
	{
		ucTrim(line);

		if(startsWith(line, "<RootNamespace>") && endsWith(line, "</RootNamespace>"))
		{
			ret = strx(ne_strchr(line, '>') + 1);
			*ne_strchr(ret, '<') = '\0';
			goto endFunc;
		}
	}
	errorCase(!ret);

endFunc:
	releaseDim(lines, 1);
	return ret;
}
static char *GetNamespaceFromLine(char *line)
{
	return strx(line + 10);
}
static char *GetNamespaceFromPath(char *rootNamespace, char *rootDir, char *file)
{
	char *namespace;

	file = changeRoot(strx(file), rootDir, NULL);
	namespace = xcout("%s\\%s", rootNamespace, file);
	namespace = changeLocal_xc(namespace, "");
	replaceChar(namespace, '\\', '.');

	memFree(file);
	return namespace;
}
static void AdjustNamespace(char *targetDir)
{
	char *projFile;
	char *rootDir;
	char *rootNamespace;
	autoList_t *files;
	char *file;
	uint index;

	targetDir = makeFullPath(targetDir);

	cout("T %s\n", targetDir);

	projFile = GetProjFile(targetDir);
	rootDir = getParent(projFile);
	rootNamespace = GetProjRootNamespace(projFile);

	cout("P %s\n", projFile);
	cout("D %s\n", rootDir);
	cout("N %s\n", rootNamespace);

	if(!BatchMode)
	{
		cout("sH\n");

		if(clearGetKey() == 0x1b)
			termination(0);

		cout("s܂B\n");
	}
	files = lssFiles(targetDir);

	foreach(files, file, index)
	{
		if(!_stricmp("cs", getExt(file)))
		{
			autoList_t *lines = readLines(file);
			char *line;
			uint index;
			int modified = 0;
			char *relFile = changeRoot(strx(file), rootDir, NULL);

			foreach(lines, line, index)
			{
				if(startsWith(line, "namespace ") && !endsWith(line, " {"))
				{
					char *oldNamespace = GetNamespaceFromLine(line);
					char *newNamespace = GetNamespaceFromPath(rootNamespace, rootDir, file);

					cout("F %s\n", relFile);
					cout("< %s\n", oldNamespace);
					cout("> %s\n", newNamespace);

					if(strcmp(oldNamespace, newNamespace))
					{
						LOGPOS();
						memFree(line);
						line = xcout("namespace %s", newNamespace);
						setElement(lines, index, (uint)line);
						modified = 1;
					}
					memFree(oldNamespace);<commit_msg>Gonna<commit_after>/*
	adjustNamespace.exe [ϊs\[X̃fBNg]

		ϊs\[X̃fBNg  vWFNg̃[gfBNg Ɠzł邱ƁB

		vWFNg̃[gfBNg == .csproj fBNg
*/

#include "C:\Factory\Common\all.h"

static int BatchMode;

static char *GetProjFile_Dir(char *dir)
{
	autoList_t *files = lsFiles(dir);
	char *file;
	uint index;
	char *projFile;

	foreach(files, file, index)
		if(!_stricmp("csproj", getExt(file)))
			break;

	if(file)
		projFile = strx(file);
	else
		projFile = NULL;

	releaseDim(files, 1);
	return projFile;
}
static char *GetProjFile(char *dir)
{
	char *projFile;

	dir = strx(dir);

	while(!(projFile = GetProjFile_Dir(dir)))
	{
		errorCase(isRootDirAbs(dir));

		dir = getParent_x(dir);
	}
	memFree(dir);
	return projFile;
}
static char *GetProjRootNamespace(char *projFile)
{
	autoList_t *lines = readLines(projFile);
	char *line;
	uint index;
	char *ret = NULL;

	foreach(lines, line, index)
	{
		ucTrim(line);

		if(startsWith(line, "<RootNamespace>") && endsWith(line, "</RootNamespace>"))
		{
			ret = strx(ne_strchr(line, '>') + 1);
			*ne_strchr(ret, '<') = '\0';
			goto endFunc;
		}
	}
	errorCase(!ret);

endFunc:
	releaseDim(lines, 1);
	return ret;
}
static char *GetNamespaceFromLine(char *line)
{
	return strx(line + 10);
}
static char *GetNamespaceFromPath(char *rootNamespace, char *rootDir, char *file)
{
	char *namespace;

	file = changeRoot(strx(file), rootDir, NULL);
	namespace = xcout("%s\\%s", rootNamespace, file);
	namespace = changeLocal_xc(namespace, "");
	replaceChar(namespace, '\\', '.');

	memFree(file);
	return namespace;
}
static void AdjustNamespace(char *targetDir)
{
	char *projFile;
	char *rootDir;
	char *rootNamespace;
	autoList_t *files;
	char *file;
	uint index;

	targetDir = makeFullPath(targetDir);

	cout("T %s\n", targetDir);

	projFile = GetProjFile(targetDir);
	rootDir = getParent(projFile);
	rootNamespace = GetProjRootNamespace(projFile);

	cout("P %s\n", projFile);
	cout("D %s\n", rootDir);
	cout("N %s\n", rootNamespace);

	if(!BatchMode)
	{
		cout("sH\n");

		if(clearGetKey() == 0x1b)
			termination(0);

		cout("s܂B\n");
	}
	files = lssFiles(targetDir);

	foreach(files, file, index)
	{
		if(!_stricmp("cs", getExt(file)))
		{
			autoList_t *lines = readLines(file);
			char *line;
			uint index;
			int modified = 0;
			char *relFile = changeRoot(strx(file), rootDir, NULL);

			foreach(lines, line, index)
			{
				if(lineExp("namespace <1,,..__09AZaz>", line))
				{
					char *oldNamespace = GetNamespaceFromLine(line);
					char *newNamespace = GetNamespaceFromPath(rootNamespace, rootDir, file);

					cout("F %s\n", relFile);
					cout("< %s\n", oldNamespace);
					cout("> %s\n", newNamespace);

					if(strcmp(oldNamespace, newNamespace))
					{
						LOGPOS();
						memFree(line);
						line = xcout("namespace %s", newNamespace);
						setElement(lines, index, (uint)line);
						modified = 1;
					}
					memFree(oldNamespace);
{'fraction_non_alphanumeric': 0.16519633281439197, 'fraction_numerical': 0.004324511330219685, 'mean_word_length': 4.261146496815287, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2329061', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2237, 'n_words': 451}