about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-01-03 22:10:09 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-01-03 22:10:09 -0800
commit58f19b4c41f5c4ca9fec1515fe5e24732eda19b7 (patch)
tree421a140e86c7742136b04dc4ae9c88207661669a
parent5a6ec8d0514c16b29afea3edc26c98ead6015b48 (diff)
downloadmu-58f19b4c41f5c4ca9fec1515fe5e24732eda19b7.tar.gz
3729
-rw-r--r--linkify/000test.cc26
-rw-r--r--linkify/001trace.cc139
-rw-r--r--linkify/001trace.test.cc88
-rw-r--r--linkify/002main.cc50
-rw-r--r--linkify/Readme2
-rw-r--r--linkify/boot.cc41
-rwxr-xr-xlinkify/build8
-rwxr-xr-xlinkify/clean2
-rw-r--r--linkify/linkify.cc (renamed from linkify/003linkify.cc)26
9 files changed, 29 insertions, 353 deletions
diff --git a/linkify/000test.cc b/linkify/000test.cc
deleted file mode 100644
index 2754b254..00000000
--- a/linkify/000test.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-typedef void (*test_fn)(void);
-
-const test_fn Tests[] = {
-  #include "test_list"  // auto-generated; see makefile
-};
-
-bool Passed = true;
-
-long Num_failures = 0;
-
-#define CHECK(X) \
-  if (!(X)) { \
-    ++Num_failures; \
-    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << '\n'; \
-    Passed = false; \
-    return; \
-  }
-
-#define CHECK_EQ(X, Y) \
-  if ((X) != (Y)) { \
-    ++Num_failures; \
-    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << " == " << #Y << '\n'; \
-    cerr << "  got " << (X) << '\n';  /* BEWARE: multiple eval */ \
-    Passed = false; \
-    return; \
-  }
diff --git a/linkify/001trace.cc b/linkify/001trace.cc
deleted file mode 100644
index e78c0010..00000000
--- a/linkify/001trace.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-bool Hide_warnings = false;
-
-struct trace_stream {
-  vector<pair<string, string> > past_lines;  // [(layer label, line)]
-  // accumulator for current line
-  ostringstream* curr_stream;
-  string curr_layer;
-  trace_stream() :curr_stream(NULL) {}
-  ~trace_stream() { if (curr_stream) delete curr_stream; }
-
-  ostringstream& stream(string layer) {
-    newline();
-    curr_stream = new ostringstream;
-    curr_layer = layer;
-    return *curr_stream;
-  }
-
-  // be sure to call this before messing with curr_stream or curr_layer
-  void newline() {
-    if (!curr_stream) return;
-    string curr_contents = curr_stream->str();
-    curr_contents.erase(curr_contents.find_last_not_of("\r\n")+1);
-    past_lines.push_back(pair<string, string>(curr_layer, curr_contents));
-    delete curr_stream;
-    curr_stream = NULL;
-  }
-
-  string readable_contents(string layer) {  // missing layer = everything
-    newline();
-    ostringstream output;
-    for (vector<pair<string, string> >::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
-      if (layer.empty() || layer == p->first)
-        output << p->first << ": " << with_newline(p->second);
-    return output.str();
-  }
-
-  string with_newline(string s) {
-    if (s[s.size()-1] != '\n') return s+'\n';
-    return s;
-  }
-};
-
-trace_stream* Trace_stream = NULL;
-
-// Top-level helper. IMPORTANT: can't nest.
-#define trace(layer)  !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(layer)
-// Warnings should go straight to cerr by default since calls to trace() have
-// some unfriendly constraints (they delay printing, they can't nest)
-#define raise  ((!Trace_stream || !Hide_warnings) ? cerr /*do print*/ : Trace_stream->stream("warn")) << __FILE__ << ":" << __LINE__ << " "
-
-// raise << die exits after printing -- unless Hide_warnings is set.
-struct die {};
-ostream& operator<<(ostream& os, __attribute__((unused)) die) {
-  if (Hide_warnings) return os;
-  os << "dying\n";
-  exit(1);
-}
-
-#define CLEAR_TRACE  delete Trace_stream, Trace_stream = new trace_stream;
-
-#define DUMP(layer)  cerr << Trace_stream->readable_contents(layer)
-
-// Trace_stream is a resource, lease_tracer uses RAII to manage it.
-struct lease_tracer {
-  lease_tracer() { Trace_stream = new trace_stream; }
-  ~lease_tracer() { delete Trace_stream, Trace_stream = NULL; }
-};
-
-#define START_TRACING_UNTIL_END_OF_SCOPE  lease_tracer leased_tracer;
-
-bool check_trace_contents(string FUNCTION, string FILE, int LINE, string layer, string expected) {  // empty layer == everything
-  vector<string> expected_lines = split(expected, "");
-  size_t curr_expected_line = 0;
-  while (curr_expected_line < expected_lines.size() && expected_lines[curr_expected_line].empty())
-    ++curr_expected_line;
-  if (curr_expected_line == expected_lines.size()) return true;
-  Trace_stream->newline();
-  ostringstream output;
-  for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (!layer.empty() && layer != p->first)
-      continue;
-    if (p->second != expected_lines[curr_expected_line])
-      continue;
-    ++curr_expected_line;
-    while (curr_expected_line < expected_lines.size() && expected_lines[curr_expected_line].empty())
-      ++curr_expected_line;
-    if (curr_expected_line == expected_lines.size()) return true;
-  }
-
-  ++Num_failures;
-  cerr << "\nF " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << expected_lines[curr_expected_line] << "] in trace:\n";
-  DUMP(layer);
-  Passed = false;
-  return false;
-}
-
-#define CHECK_TRACE_CONTENTS(...)  check_trace_contents(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
-
-int trace_count(string layer, string line) {
-  Trace_stream->newline();
-  long result = 0;
-  for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
-    if (layer == p->first)
-      if (line == "" || p->second == line)
-        ++result;
-  }
-  return result;
-}
-
-#define CHECK_TRACE_WARNS()  CHECK(trace_count("warn", "") > 0)
-#define CHECK_TRACE_DOESNT_WARN() \
-  if (trace_count("warn") > 0) { \
-    ++Num_failures; \
-    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): unexpected warnings\n"; \
-    DUMP("warn"); \
-    Passed = false; \
-    return; \
-  }
-
-bool trace_doesnt_contain(string layer, string line) {
-  return trace_count(layer, line) == 0;
-}
-
-#define CHECK_TRACE_DOESNT_CONTAIN(...)  CHECK(trace_doesnt_contain(__VA_ARGS__))
-
-vector<string> split(string s, string delim) {
-  vector<string> result;
-  string::size_type begin=0, end=s.find(delim);
-  while (true) {
-    if (end == string::npos) {
-      result.push_back(string(s, begin, string::npos));
-      break;
-    }
-    result.push_back(string(s, begin, end-begin));
-    begin = end+delim.size();
-    end = s.find(delim, begin);
-  }
-  return result;
-}
diff --git a/linkify/001trace.test.cc b/linkify/001trace.test.cc
deleted file mode 100644
index 5f0a696e..00000000
--- a/linkify/001trace.test.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-void test_trace_check_compares() {
-  CHECK_TRACE_CONTENTS("test layer", "");
-  trace("test layer") << "foo";
-  CHECK_TRACE_CONTENTS("test layer", "foo");
-}
-
-void test_trace_check_filters_layers() {
-  trace("test layer 1") << "foo";
-  trace("test layer 2") << "bar";
-  CHECK_TRACE_CONTENTS("test layer 1", "foo");
-}
-
-void test_trace_check_ignores_other_lines() {
-  trace("test layer 1") << "foo";
-  trace("test layer 1") << "bar";
-  CHECK_TRACE_CONTENTS("test layer 1", "foo");
-}
-
-void test_trace_check_always_finds_empty_lines() {
-  CHECK_TRACE_CONTENTS("test layer 1", "");
-}
-
-void test_trace_check_treats_empty_layers_as_wildcards() {
-  trace("test layer 1") << "foo";
-  CHECK_TRACE_CONTENTS("", "foo");
-}
-
-void test_trace_check_multiple_lines_at_once() {
-  trace("test layer 1") << "foo";
-  trace("test layer 2") << "bar";
-  CHECK_TRACE_CONTENTS("", "foobar");
-}
-
-void test_trace_check_always_finds_empty_lines2() {
-  CHECK_TRACE_CONTENTS("test layer 1", "");
-}
-
-void test_trace_orders_across_layers() {
-  trace("test layer 1") << "foo";
-  trace("test layer 2") << "bar";
-  trace("test layer 1") << "qux";
-  CHECK_TRACE_CONTENTS("", "foobarqux");
-}
-
-void test_trace_supports_count() {
-  trace("test layer 1") << "foo";
-  trace("test layer 1") << "foo";
-  CHECK_EQ(trace_count("test layer 1", "foo"), 2);
-}
-
-//// helpers
-
-// can't check trace because trace methods call 'split'
-
-void test_split_returns_at_least_one_elem() {
-  vector<string> result = split("", ",");
-  CHECK_EQ(result.size(), 1);
-  CHECK_EQ(result[0], "");
-}
-
-void test_split_returns_entire_input_when_no_delim() {
-  vector<string> result = split("abc", ",");
-  CHECK_EQ(result.size(), 1);
-  CHECK_EQ(result[0], "abc");
-}
-
-void test_split_works() {
-  vector<string> result = split("abc,def", ",");
-  CHECK_EQ(result.size(), 2);
-  CHECK_EQ(result[0], "abc");
-  CHECK_EQ(result[1], "def");
-}
-
-void test_split_works2() {
-  vector<string> result = split("abc,def,ghi", ",");
-  CHECK_EQ(result.size(), 3);
-  CHECK_EQ(result[0], "abc");
-  CHECK_EQ(result[1], "def");
-  CHECK_EQ(result[2], "ghi");
-}
-
-void test_split_handles_multichar_delim() {
-  vector<string> result = split("abc,,def,,ghi", ",,");
-  CHECK_EQ(result.size(), 3);
-  CHECK_EQ(result[0], "abc");
-  CHECK_EQ(result[1], "def");
-  CHECK_EQ(result[2], "ghi");
-}
diff --git a/linkify/002main.cc b/linkify/002main.cc
deleted file mode 100644
index a4f5b273..00000000
--- a/linkify/002main.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-int main(int argc, const char* argv[]) {
-  if (flag("test", argc, argv))
-    return run_tests();
-  return linkify(argc, argv);
-}
-
-bool flag(const string& flag, int argc, const char* argv[]) {
-  for (int i = 1; i < argc; ++i)
-    if (string(argv[i]) == flag)
-      return true;
-  return false;
-}
-
-string flag_value(const string& flag, int argc, const char* argv[]) {
-  for (int i = 1; i < argc-1; ++i)
-    if (string(argv[i]) == flag)
-      return argv[i+1];
-  return "";
-}
-
-//// test harness
-
-int run_tests() {
-  for (unsigned long i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
-    START_TRACING_UNTIL_END_OF_SCOPE;
-    setup();
-    (*Tests[i])();
-    verify();
-  }
-
-  cerr << '\n';
-  if (Num_failures > 0)
-    cerr << Num_failures << " failure"
-         << (Num_failures > 1 ? "s" : "")
-         << '\n';
-  return Num_failures;
-}
-
-void verify() {
-  Hide_warnings = false;
-  if (!Passed)
-    ;
-  else
-    cerr << ".";
-}
-
-void setup() {
-  Hide_warnings = false;
-  Passed = true;
-}
diff --git a/linkify/Readme b/linkify/Readme
index c88928b1..c4625a9d 100644
--- a/linkify/Readme
+++ b/linkify/Readme
@@ -1 +1,3 @@
 Tool used while rendering Mu's codebase in html. See the mu/update_html script.
+
+Extremely hacky; just see the number of tests.
diff --git a/linkify/boot.cc b/linkify/boot.cc
deleted file mode 100644
index d3b59a7c..00000000
--- a/linkify/boot.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-#include<assert.h>
-#include<cstdlib>
-#include<cstring>
-
-#include<vector>
-using std::vector;
-#include<list>
-using std::list;
-#include<map>
-using std::map;
-#include<utility>
-using std::pair;
-
-#include<string>
-using std::string;
-
-#include<iostream>
-using std::istream;
-using std::ostream;
-using std::cin;
-using std::cout;
-using std::cerr;
-
-#include<sstream>
-using std::istringstream;
-using std::ostringstream;
-
-#include<fstream>
-using std::ifstream;
-using std::ofstream;
-
-#include <locale>
-using std::isspace;  // unicode-aware
-
-#include "type_list"
-
-#include "function_list"
-
-#include "file_list"
-
-#include "test_file_list"
diff --git a/linkify/build b/linkify/build
index da6c3ff4..54c3f459 100755
--- a/linkify/build
+++ b/linkify/build
@@ -1,9 +1,3 @@
 #!/bin/sh
 
-grep -h "^struct .* {" [0-9]*.cc  |sed 's/\(struct *[^ ]*\).*/\1;/'  > type_list
-grep -h "^typedef " [0-9]*.cc  >> type_list
-grep -h "^[^ #].*) {" [0-9]*.cc  |sed 's/ {.*/;/'  > function_list
-ls [0-9]*.cc  |grep -v "\.test\.cc$"  |sed 's/.*/#include "&"/'  > file_list
-ls [0-9]*.test.cc  |sed 's/.*/#include "&"/'  > test_file_list
-grep -h "^[[:space:]]*void test_" [0-9]*.cc  |sed 's/^\s*void \(.*\)() {$/\1,/'  > test_list
-c++ -g -O3 boot.cc -o linkify
+c++ -g linkify.cc -o linkify
diff --git a/linkify/clean b/linkify/clean
index 87321f72..7838b78a 100755
--- a/linkify/clean
+++ b/linkify/clean
@@ -1,2 +1,2 @@
 #!/bin/sh
-rm -rf linkify *.dSYM *_list
+rm -rf linkify *.dSYM
diff --git a/linkify/003linkify.cc b/linkify/linkify.cc
index 3bb77401..7ed2bc38 100644
--- a/linkify/003linkify.cc
+++ b/linkify/linkify.cc
@@ -19,6 +19,30 @@
 //     'clear()' on some type, and it's already defined on STL classes)
 // - ctags misses some symbols in layered code
 
+#include<assert.h>
+
+#include<map>
+using std::map;
+
+#include<string>
+using std::string;
+
+#include<iostream>
+using std::istream;
+using std::cout;
+using std::cerr;
+
+#include<sstream>
+using std::istringstream;
+using std::ostringstream;
+
+#include<fstream>
+using std::ifstream;
+using std::ofstream;
+
+#include <locale>
+using std::isspace;  // unicode-aware
+
 struct syminfo {
   string filename;
   int line_num;
@@ -196,7 +220,7 @@ void replace_tags_in_file(const string& filename, const map<string, syminfo>& in
   in.close();  out.close();
 }
 
-int linkify(int argc, const char* argv[]) {
+int main(int argc, const char* argv[]) {
   map<string, syminfo> info;
   read_tags(argv[1], info);
   for (int i = 2;  i < argc;  ++i) {