From: Erik Garrison Date: Mon, 6 Jun 2011 23:15:49 +0000 (-0700) Subject: Merge pull request #2 from makoshark/master X-Git-Url: https://projects.mako.cc/source/wikiq/commitdiff_plain/dbb6c62b620005faf7049c2e7d5625bfeb3a681e?hp=87e6add2820dd71cd79585d3ffa74f7fe46820f3 Merge pull request #2 from makoshark/master regex titles and static linking --- diff --git a/Makefile b/Makefile index 12459ed..cc0e56f 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,21 @@ -CXX = g++ -CFLAGS = -O3 -OBJECTS = disorder.o md5.o +CXXFLAGS = -O3 +CFLAGS = $(CXXFLAGS) +OBJECTS = wikiq.o md5.o disorder.o all: wikiq -wikiq: wikiq.cpp $(OBJECTS) - $(CXX) $(CFLAGS) -lpcrecpp -lexpat wikiq.cpp $(OBJECTS) -o wikiq +wikiq: $(OBJECTS) + $(CXX) $(CXXFLAGS) $(OBJECTS) -lpcrecpp -lpcre -lexpat -o wikiq -disorder.o: disorder.c disorder.h - $(CXX) $(CFLAGS) -c disorder.c - -md5.o: md5.c md5.h - $(CXX) $(CFLAGS) -c md5.c -lm +disorder.o: disorder.h +md5.o: md5.h clean: rm -f wikiq $(OBJECTS) +static: $(OBJECTS) + $(CXX) $(CXXFLAGS) $(OBJECTS) -static -lpcrecpp -lpcre -lexpat -o wikiq + gprof: $(MAKE) CFLAGS=-pg wikiq diff --git a/disorder.h b/disorder.h index 3458774..91ec47d 100644 --- a/disorder.h +++ b/disorder.h @@ -24,6 +24,10 @@ #ifndef __DISORDER_H_ #define __DISORDER_H_ +#ifdef __cplusplus +extern "C" { +#endif + /** Max number of bytes (i.e., tokens) */ #define LIBDO_MAX_BYTES 256 @@ -59,4 +63,8 @@ float get_max_entropy(void); /** Returns the ratio of entropy to maxentropy */ float get_entropy_ratio(void); +#ifdef __cplusplus +}; +#endif + #endif diff --git a/wikiq.cpp b/wikiq.cpp index da5e7b7..e8ca4d2 100644 --- a/wikiq.cpp +++ b/wikiq.cpp @@ -57,6 +57,7 @@ typedef struct { char *text; vector last_text_tokens; vector regexes; + vector wp_namespace_res; vector regex_names; map revision_md5; // used for detecting reversions @@ -246,6 +247,22 @@ write_row(revisionData *data) ++pos; } + // skip this if the wp_namespace is not in the proscribed list of + // namespaces + bool wp_namespace_found = false; + if (!data->wp_namespace_res.empty()) { + for (vector::iterator r = data->wp_namespace_res.begin(); r != data->wp_namespace_res.end(); ++r) { + pcrecpp::RE& wp_namespace_re = *r; + if (wp_namespace_re.PartialMatch(data->title)) { + wp_namespace_found = true; + break; + } + } + if (!wp_namespace_found) { + return; + } + } + //vector additions; //vector deletions; string additions; @@ -488,9 +505,10 @@ void print_usage(char* argv[]) { cerr << "usage: | " << argv[0] << "[options]" << endl << endl << "options:" << endl - << " -t print text and comments after each line of tab separated data" << endl + << " -v verbose mode prints text and comments after each line of tab separated data" << endl << " -n name of the following regex (e.g. -n name -r \"...\")" << endl << " -r regex to check against additions and deletions" << endl + << " -t regex(es) to check title against as a way of limiting output to specific namespaces" << endl << endl << "Takes a wikimedia data dump XML stream on standard in, and produces" << endl << "a tab-separated stream of revisions on standard out:" << endl @@ -521,13 +539,13 @@ main(int argc, char *argv[]) // the user data struct which is passed to callback functions revisionData data; - while ((c = getopt(argc, argv, "htn:r:")) != -1) + while ((c = getopt(argc, argv, "hvn:r:t:")) != -1) switch (c) { case 'd': dry_run = 1; break; - case 't': + case 'v': output_type = FULL; break; case 'n': @@ -544,6 +562,9 @@ main(int argc, char *argv[]) print_usage(argv); exit(0); break; + case 't': + data.wp_namespace_res.push_back(pcrecpp::RE(optarg, pcrecpp::UTF8())); + break; } if (dry_run) { // lets us print initialization options