summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Shields <mail@kennyshields.net>2020-07-29 17:24:48 -0400
committerKenny Shields <mail@kennyshields.net>2020-07-29 17:24:48 -0400
commit758659702b27c6240691f548c54f09b89959f11d (patch)
tree7fc92cc584affe4c7f69d648f9715480fa3ad1fd
parenta93babe5d1abffe628c31f8dbfdddc11545b779a (diff)
downloaddsymlist-758659702b27c6240691f548c54f09b89959f11d.tar.gz
dsymlist-758659702b27c6240691f548c54f09b89959f11d.zip
Add symbol count, namespace count and better namespace filtering
-rw-r--r--source/main.d35
1 files changed, 32 insertions, 3 deletions
diff --git a/source/main.d b/source/main.d
index 71a1e91..e53b3e7 100644
--- a/source/main.d
+++ b/source/main.d
@@ -4,12 +4,13 @@ import std.stdio : writeln, writefln;
import std.demangle : demangle;
import std.process : execute;
import std.file : exists, isFile, write, append;
+import std.path : baseName;
import std.array : join, split;
import std.string : splitLines;
import std.regex : matchFirst, regex;
import std.getopt : getopt;
import std.algorithm.sorting : sort;
-import std.algorithm.searching : canFind;
+import std.algorithm.searching : startsWith;
import std.conv : to;
/// Symbol data structure.
@@ -51,6 +52,15 @@ string __opt_outFile;
/// Array of namespaces to filter symbols by.
string[] namespaces;
+/// File to scan specified by user.
+string inputFile;
+
+/// Total symbol count.
+ulong symbolCount = 0;
+
+/// Total namespace count.
+ulong namespaceCount = 0;
+
/**
* Program entry point.
*/
@@ -84,7 +94,7 @@ void main(string[] args) {
writeln("Error: No input file specified.");
return;
}
- string inputFile = args[1];
+ inputFile = args[1];
// check file path
if(!exists(inputFile) || !isFile(inputFile)) {
writeln("Error: Invalid input file.");
@@ -129,13 +139,22 @@ void collect(string file) {
}
// filter symbols if namespaces were provided by the user
if(namespaces.length > 0) {
- if(!namespaces.canFind(symbolMatches[2])) {
+ import std.algorithm.iteration : each;
+ bool found = false;
+ namespaces.each!((n) {
+ if(symbolMatches[2].startsWith(n)) {
+ found = true;
+ return;
+ }
+ });
+ if(!found) {
continue;
}
}
// add the symbol to the list
if((symbolMatches[2] in symbols) is null) {
symbols[symbolMatches[2]] = [];
+ namespaceCount++;
}
symbols[symbolMatches[2]] ~= Symbol(
symbolMatches[3],
@@ -143,6 +162,7 @@ void collect(string file) {
symbolMatches[4].split(","),
matches[3]
);
+ symbolCount++;
}
}
@@ -155,6 +175,15 @@ void output() {
if(__opt_outFile.length > 0 && exists(__opt_outFile) && isFile(__opt_outFile)) {
write(__opt_outFile, "");
}
+ // write file name, symbol count and namespace count to output file header
+ writeToFile(baseName(inputFile));
+ writeToFile(to!string(symbolCount) ~ " symbols in " ~ to!string(namespaceCount)
+ ~ " namespaces");
+ // write namespaces from user input to output file header
+ if(__opt_nameSpaces.length > 0) {
+ writeToFile(to!string(__opt_nameSpaces.split(",")));
+ }
+ writeToFile("------------------------------------\n");
foreach(namespace; sort(symbols.keys)) {
string length = to!string(symbols[namespace].length);
string consoleStr = "\033[0;92m" ~ namespace ~ " (" ~ length ~ ")\033[0m\n{\n";