make_enum.cpp

来自「当前支持 16-bit, 32-bit and 64-bit 的二进制文件」· C++ 代码 · 共 63 行

CPP
63
字号
// make_enum.cpp
// Copyright (C) 2008 Willow Schlanger

#include <fstream>
#include <iostream>
#include <string>

int main()
{
	std::ifstream inf("in_enum.txt");
	if(inf == NULL)
	{
		std::cout << "Can\'t open in_enum.txt" << std::endl;
		return 1;
	}
	
	std::ofstream out1("out_enum.h");
	std::ofstream out2("out_enum_strings.h");
	
	out1 << "// out_enums.h  (note: this is an automatically generated file - do not edit!)" << std::endl;
	out1 << "// Copyright (C) 2008 Willow Schlanger" << std::endl;
	out2 << "// out_enums.h  (note: this is an automatically generated file - do not edit!)" << std::endl;
	out2 << "// Copyright (C) 2008 Willow Schlanger" << std::endl;

	std::string line;
	std::string prefix;
	prefix.clear();
	while(std::getline(inf, line) != NULL)
	{
		if(line.empty())
			continue;
		if(line[0] == '/')
		{
			if(!prefix.empty())
				out1 << line << std::endl;
		}
		else
		if(line[0] == '$')
		{
			if(line == "$end")
			{
				out1 << prefix << "__end" << std::endl;
				out1 << "};" << std::endl;
				out2 << "0" << std::endl;
				out2 << "};" << std::endl;
			}
			else
			{
				prefix = std::string(++line.begin(), line.end());
				out1 << "enum" << std::endl << "{" << std::endl;
				out2 << "const char *strings_" << prefix << "[] = {" << std::endl;
			}
		}
		else
		{
			out1 << prefix << "_" << line << "," << std::endl;;
			out2 << "\"" << line << "\"," << std::endl;
		}
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?