Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import std.stdio, std.file, std.path, std.range, std.string, std.algorithm ;
  2.  
  3. string[] filterList = ["./Makefile.in", "./Makefile.am", "./index.d", "./unittest.d",
  4. "./libgphobos.spec.in", "./std/experimental/note.md"];
  5.  
  6. struct Files
  7. {
  8. string[] baseList;
  9. string[][string] sysList;
  10. }
  11.  
  12. void main(string[] args)
  13. {
  14. Files[string] fileMap;
  15.  
  16. foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => !filterList.canFind(a)))
  17. {
  18. if(entry.isFile)
  19. {
  20. auto ext = entry.extension.empty ? "" : entry.extension[1 .. $];
  21. if(!(ext in fileMap))
  22. fileMap[ext] = Files.init;
  23.  
  24. string sentry = entry[2 .. $];
  25.  
  26. if(entry.name.startsWith("./std/c/"))
  27. {
  28. if(entry.dirName == "./std/c")
  29. {
  30. fileMap[ext].sysList["stdc"] ~= sentry;
  31. }
  32. else
  33. {
  34. auto components = entry.pathSplitter;
  35. components.popFrontN(3);
  36. fileMap[ext].sysList[components.front] ~= sentry;
  37. }
  38. }
  39. else
  40. fileMap[ext].baseList ~= sentry;
  41. }
  42. }
  43.  
  44. foreach(extEntry; fileMap.byKeyValue.array.sort!"a.key < b.key")
  45. {
  46. auto ext = extEntry.key;
  47. auto value = extEntry.value;
  48. writeList("PHOBOS_" ~ ext.toUpper() ~ "SOURCES", value.baseList);
  49. foreach(entry; value.sysList.byKeyValue.array.sort!"a.key < b.key")
  50. {
  51. writeList("PHOBOS_" ~ ext.toUpper() ~ "SOURCES_" ~ entry.key.toUpper(), entry.value);
  52. }
  53. }
  54. }
  55.  
  56. void writeList(string name, string[] values)
  57. {
  58. if(values.empty)
  59. return;
  60.  
  61. values = sort(values).array();
  62. writef("%s =", name);
  63. size_t line = name.length + 3;
  64. foreach(entry; values)
  65. {
  66. if(line + entry.length > 70)
  67. {
  68. line = 0;
  69. writeln(` \`);
  70. write('\t');
  71. }
  72. else
  73. write(" ");
  74. write(entry);
  75. line += entry.length + 1;
  76. }
  77. writeln();
  78. writeln();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement