Last active
September 12, 2022 22:47
-
-
Save TheBuzzSaw/17c1ef85919ff3ced75915f0936a58e4 to your computer and use it in GitHub Desktop.
#define dumper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void ConvertLine(string line) | |
{ | |
const string Define = "#define "; | |
if (!line.StartsWith(Define)) | |
return; | |
var begin = Define.Length; | |
var end = begin; | |
while (end < line.Length && char.IsLetterOrDigit(line[end])) | |
++end; | |
var name = line.Substring(begin, end - begin); | |
// Comment Index | |
var ciBegin = line.IndexOf("/*"); | |
if (ciBegin == -1) | |
return; | |
var ciEnd = line.IndexOf("*/"); | |
if (ciEnd == -1) | |
return; | |
var id = line.Substring(end, ciBegin - end).Trim(); | |
var description = line.Substring(ciBegin + 2, ciEnd - ciBegin - 2).Trim(); | |
Console.WriteLine($"new({id}, \"{name}\", \"{description}\"),"); | |
} | |
static void ConvertFile(string file) | |
{ | |
var lines = File.ReadAllLines(file); | |
foreach (var line in lines) | |
ConvertLine(line); | |
} | |
foreach (var arg in Environment.GetCommandLineArgs()) | |
ConvertFile(arg); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void ConvertFile(string file) | |
{ | |
const string Prefix = "#define"; | |
var lines = File.ReadAllLines(file); | |
for (int i = 0; i < lines.Length; ++i) | |
{ | |
var line = lines[i]; | |
if (!line.StartsWith(Prefix)) | |
continue; | |
var begin = Prefix.Length; | |
while (begin < line.Length && line[begin] == ' ') | |
++begin; | |
var end = begin; | |
while (end < line.Length && (char.IsLetterOrDigit(line[end]) || line[end] == '_')) | |
++end; | |
var name = line.Substring(begin, end - begin); | |
if (!name.StartsWith("WSA") || name == "WSABASEERR") | |
continue; | |
var idBegin = end; | |
while (idBegin < line.Length && line[idBegin] == ' ') | |
++idBegin; | |
var idEnd = idBegin; | |
while (idEnd < line.Length && char.IsDigit(line[idEnd])) | |
++idEnd; | |
var id = line.Substring(idBegin, idEnd - idBegin); | |
var description = lines[i - 2].Substring(3); | |
Console.WriteLine($"new({id}, \"{name}\", \"{description}\"),"); | |
} | |
} | |
foreach (var arg in args) | |
ConvertFile(arg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment