Created
January 23, 2018 01:01
-
-
Save Broxzier/6fb463d7844d295c5d027affcf611442 to your computer and use it in GitHub Desktop.
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
using System.Text.RegularExpressions; | |
using System.IO; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace format_rct2_functionlist_cs | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Path to file with output from: git grep -h -A 15 '\*\s*rct2\s*:' | |
string contents = File.ReadAllText(args[0]); | |
Regex fullRegex = new Regex(pattern: @"\*\s*rct2:\s*(.*?)\s*\*\/.*?([^\s]+?)(\(|\[|\s*=)", RegexOptions.Singleline); | |
Match match = fullRegex.Match(contents); | |
while (match.Success) | |
{ | |
string part = match.ToString(); | |
string comment = match.Groups[1].ToString().Trim().Replace("\r\n", @"\n"); | |
string identifier = match.Groups[2].ToString(); | |
string type = part.EndsWith("(") ? "function" : "variable"; | |
List<uint> addresses = new List<uint>(); | |
// Find addresses in comment | |
Regex addressRegex = new Regex(pattern: @"(?:0x)?([0-9A-F]{4,})", RegexOptions.IgnoreCase); | |
Match address = addressRegex.Match(comment); | |
while (address.Success) | |
{ | |
string addrStr = address.Groups[1].ToString(); | |
uint addr = uint.Parse(addrStr, System.Globalization.NumberStyles.HexNumber); | |
addresses.Add(addr); | |
address = address.NextMatch(); | |
} | |
string mainAddress = "<not found>"; | |
string mentionedAddresses = ""; | |
if (addresses.Count() != 0) | |
{ | |
mainAddress = "0x" + addresses[0].ToString("X8"); | |
addresses.RemoveAt(0); | |
mentionedAddresses = string.Join(", ", addresses.Select(x => "0x" + x.ToString("X8")).ToArray()); | |
} | |
Console.Write(mainAddress + "\t"); | |
Console.Write(type + "\t"); | |
Console.Write(identifier + "\t"); | |
Console.Write(mentionedAddresses + "\n"); | |
match = match.NextMatch(); | |
} | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment