Skip to content

Instantly share code, notes, and snippets.

@jpf91
Last active February 26, 2017 12:16
Show Gist options
  • Save jpf91/8744acebc9dcf1e9d1a35cdff20afbb2 to your computer and use it in GitHub Desktop.
Save jpf91/8744acebc9dcf1e9d1a35cdff20afbb2 to your computer and use it in GitHub Desktop.
import std.stdio, std.file, std.path, std.range, std.string, std.algorithm ;
string[] filterList = ["./Makefile.in", "./Makefile.am", "./index.d", "./unittest.d",
"./std/experimental/note.md"];
struct Files
{
string[] baseList;
string[][string] sysList;
}
void main(string[] args)
{
Files[string] fileMap;
foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => !filterList.canFind(a)))
{
if(entry.isFile)
{
auto ext = entry.extension.empty ? "" : entry.extension[1 .. $];
if(!(ext in fileMap))
fileMap[ext] = Files.init;
string sentry = entry[2 .. $];
if(entry.name.startsWith("./std/c/"))
{
if(entry.dirName == "./std/c")
{
fileMap[ext].sysList["stdc"] ~= sentry;
}
else
{
auto components = entry.pathSplitter;
components.popFrontN(3);
fileMap[ext].sysList[components.front] ~= sentry;
}
}
else
fileMap[ext].baseList ~= sentry;
}
}
foreach(extEntry; fileMap.byKeyValue)
{
auto ext = extEntry.key;
auto value = extEntry.value;
writeList("PHOBOS_" ~ ext.toUpper() ~ "SOURCES", value.baseList);
foreach(entry; value.sysList.byKeyValue)
{
writeList("PHOBOS_" ~ ext.toUpper() ~ "SOURCES_" ~ entry.key.toUpper(), entry.value);
}
}
}
void writeList(string name, string[] values)
{
if(values.empty)
return;
values = sort(values).array();
writef("%s =", name);
size_t line = name.length + 3;
foreach(entry; values)
{
if(line + entry.length > 70)
{
line = 0;
writeln(` \`);
write('\t');
}
else
write(" ");
write(entry);
line += entry.length + 1;
}
writeln();
writeln();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment