go my file uploader
This commit is contained in:
22
tools/GenerateHeader/GenerateHeader.sln
Normal file
22
tools/GenerateHeader/GenerateHeader.sln
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenerateHeader", "GenerateHeader\GenerateHeader.csproj", "{DA075B6D-3506-42FA-8FD8-34F79E5578E0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{DA075B6D-3506-42FA-8FD8-34F79E5578E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DA075B6D-3506-42FA-8FD8-34F79E5578E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DA075B6D-3506-42FA-8FD8-34F79E5578E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DA075B6D-3506-42FA-8FD8-34F79E5578E0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
6
tools/GenerateHeader/GenerateHeader/App.config
Normal file
6
tools/GenerateHeader/GenerateHeader/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
||||
59
tools/GenerateHeader/GenerateHeader/GenerateHeader.csproj
Normal file
59
tools/GenerateHeader/GenerateHeader/GenerateHeader.csproj
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{DA075B6D-3506-42FA-8FD8-34F79E5578E0}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GenerateHeader</RootNamespace>
|
||||
<AssemblyName>GenerateHeader</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HeaderGen.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
213
tools/GenerateHeader/GenerateHeader/HeaderGen.cs
Normal file
213
tools/GenerateHeader/GenerateHeader/HeaderGen.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GenerateHeader
|
||||
{
|
||||
class HeaderFile
|
||||
{
|
||||
public string Name;
|
||||
public List<string> Lines;
|
||||
public List<HeaderFile> Dependencies;
|
||||
}
|
||||
|
||||
class HeaderGen
|
||||
{
|
||||
private string _baseDirectory;
|
||||
private string[] _modes;
|
||||
private string[] _files;
|
||||
private string _outputFile;
|
||||
private string _header = "";
|
||||
private string _footer = "";
|
||||
|
||||
private string UnEscape(string text)
|
||||
{
|
||||
return text.Replace("\\r", "\r").Replace("\\n", "\n").Replace("\\\\", "\\");
|
||||
}
|
||||
|
||||
public void LoadConfig(string fileName)
|
||||
{
|
||||
string[] lines = File.ReadAllLines(fileName);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] split = line.Split(new char[] { '=' }, 2);
|
||||
|
||||
switch (split[0])
|
||||
{
|
||||
case "base":
|
||||
_baseDirectory = split[1];
|
||||
break;
|
||||
case "modes":
|
||||
_modes = split[1].ToLowerInvariant().Split(';');
|
||||
break;
|
||||
case "in":
|
||||
_files = split[1].Split(';');
|
||||
break;
|
||||
case "out":
|
||||
_outputFile = split[1];
|
||||
break;
|
||||
case "header":
|
||||
_header = UnEscape(split[1]);
|
||||
break;
|
||||
case "footer":
|
||||
_footer = UnEscape(split[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<HeaderFile> OrderHeaderFiles(List<HeaderFile> headerFiles)
|
||||
{
|
||||
var result = new List<HeaderFile>();
|
||||
var done = new HashSet<HeaderFile>();
|
||||
|
||||
foreach (var h in headerFiles)
|
||||
OrderHeaderFiles(result, done, h);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void OrderHeaderFiles(List<HeaderFile> result, HashSet<HeaderFile> done, HeaderFile headerFile)
|
||||
{
|
||||
if (done.Contains(headerFile))
|
||||
return;
|
||||
|
||||
done.Add(headerFile);
|
||||
|
||||
foreach (var h in headerFile.Dependencies)
|
||||
OrderHeaderFiles(result, done, h);
|
||||
|
||||
result.Add(headerFile);
|
||||
}
|
||||
|
||||
private List<string> ProcessHeaderLines(IEnumerable<string> lines)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var modes = new HashSet<string>();
|
||||
var blankLine = false;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var s = line.Trim();
|
||||
|
||||
if (s.StartsWith("// begin_"))
|
||||
{
|
||||
modes.Add(s.Remove(0, "// begin_".Length));
|
||||
}
|
||||
else if (s.StartsWith("// end_"))
|
||||
{
|
||||
modes.Remove(s.Remove(0, "// end_".Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool blockMode = _modes.Any(modes.Contains);
|
||||
bool lineMode = _modes.Any(mode =>
|
||||
{
|
||||
int indexOfMarker = s.LastIndexOf("// " + mode);
|
||||
if (indexOfMarker == -1)
|
||||
return false;
|
||||
|
||||
return s.Substring(indexOfMarker).Trim().All(c => char.IsLetterOrDigit(c) || c == ' ' || c == '/');
|
||||
});
|
||||
|
||||
if (blockMode || lineMode)
|
||||
{
|
||||
if (blankLine && result.Count != 0)
|
||||
result.Add(string.Empty);
|
||||
|
||||
result.Add(line);
|
||||
blankLine = false;
|
||||
}
|
||||
else if (s.Length == 0)
|
||||
{
|
||||
blankLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
// Read in all header files.
|
||||
|
||||
var headerFiles = _files.Select(fileName =>
|
||||
{
|
||||
var fullFileName = _baseDirectory + "\\" + fileName;
|
||||
var lines = File.ReadAllLines(fullFileName).ToList();
|
||||
|
||||
return new HeaderFile { Name = Path.GetFileName(fullFileName).ToLowerInvariant(), Lines = lines };
|
||||
}).ToDictionary(h => h.Name);
|
||||
|
||||
foreach (var h in headerFiles.Values)
|
||||
{
|
||||
var partitions =
|
||||
h.Lines
|
||||
.Select(s =>
|
||||
{
|
||||
var trimmed = s.Trim().ToLowerInvariant();
|
||||
if (trimmed.StartsWith("#include <") && trimmed.EndsWith(">"))
|
||||
{
|
||||
HeaderFile d;
|
||||
if (headerFiles.TryGetValue(trimmed.Remove(trimmed.Length - 1).Remove(0, "#include <".Length), out d))
|
||||
return Tuple.Create(s, d);
|
||||
else
|
||||
return Tuple.Create<string, HeaderFile>(s, null);
|
||||
}
|
||||
return Tuple.Create<string, HeaderFile>(s, null);
|
||||
})
|
||||
.ToLookup(p => p.Item2 != null);
|
||||
|
||||
h.Lines = partitions[false].Select(p => p.Item1).ToList();
|
||||
h.Dependencies = partitions[true].Select(p => p.Item2).Distinct().ToList();
|
||||
|
||||
foreach (var d in h.Dependencies)
|
||||
Console.WriteLine("Dependency: " + h.Name + " -> " + d.Name);
|
||||
}
|
||||
|
||||
// Generate the ordering.
|
||||
|
||||
var orderedHeaderFiles = OrderHeaderFiles(_files.Select(s => headerFiles[Path.GetFileName(s).ToLower()]).ToList());
|
||||
|
||||
// Process each header file and remove irrelevant content.
|
||||
|
||||
foreach (var h in orderedHeaderFiles)
|
||||
h.Lines = ProcessHeaderLines(h.Lines);
|
||||
|
||||
// Write out the result.
|
||||
|
||||
StreamWriter sw = new StreamWriter(_baseDirectory + "\\" + _outputFile);
|
||||
|
||||
// Header
|
||||
|
||||
sw.Write(_header);
|
||||
|
||||
// Header files
|
||||
|
||||
foreach (var h in orderedHeaderFiles)
|
||||
{
|
||||
Console.WriteLine("Header file: " + h.Name);
|
||||
|
||||
sw.WriteLine();
|
||||
sw.WriteLine("//");
|
||||
sw.WriteLine("// " + Path.GetFileNameWithoutExtension(h.Name));
|
||||
sw.WriteLine("//");
|
||||
sw.WriteLine();
|
||||
|
||||
foreach (var line in h.Lines)
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
// Footer
|
||||
|
||||
sw.Write(_footer);
|
||||
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
tools/GenerateHeader/GenerateHeader/Program.cs
Normal file
27
tools/GenerateHeader/GenerateHeader/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GenerateHeader
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
HeaderGen gen = new HeaderGen();
|
||||
string configFile = args.Length > 0 ? args[0] : "options.txt";
|
||||
|
||||
try
|
||||
{
|
||||
gen.LoadConfig(configFile);
|
||||
gen.Execute();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("GenerateHeader")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("GenerateHeader")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("efba3f55-999d-4dde-8217-118ba2aed831")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Binary file not shown.
Reference in New Issue
Block a user