r38617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38616‎ | r38617 | r38618 >
Date:08:24, 5 August 2008
Author:werdna
Status:old
Tags:
Comment:
Add missing cpp file
Modified paths:
  • /trunk/extensions/AbuseFilter/parser_native/eval.cpp (added) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/parser_native/eval.cpp
@@ -0,0 +1,77 @@
 2+#include "afeval.h"
 3+#include "affunctions.h"
 4+#include <libxml++/libxml++.h>
 5+#include <iostream>
 6+#include <string>
 7+#include <sstream>
 8+#include <map>
 9+
 10+string filter;
 11+map<string,AFPData> vars;
 12+
 13+bool loadRequest();
 14+
 15+int main( int argc, char** argv ) {
 16+ FilterEvaluator e;
 17+ registerBuiltinFunctions();
 18+
 19+ string result;
 20+
 21+ try {
 22+ e.reset();
 23+ if (!loadRequest())
 24+ exit(-1);
 25+
 26+ e.setVars( vars );
 27+ result = e.evaluateExpression( filter );
 28+ } catch (AFPException excep) {
 29+ cout << "EXCEPTION: " << excep.what() << endl;
 30+ cerr << "EXCEPTION: " << excep.what() << endl;
 31+ }
 32+
 33+ cout << result << "\0";
 34+}
 35+
 36+// Protocol:
 37+// code NULL <key> NULL <value> NULL ... <value> NULL NULL
 38+
 39+bool loadRequest() {
 40+ stringbuf codesb(ios::out | ios::in);
 41+
 42+ // Load the code
 43+ cin.get( codesb, '\0' );
 44+ cin.get();
 45+ filter = codesb.str();
 46+
 47+ cerr << "Got code " << filter << endl;
 48+
 49+ while (true) {
 50+ stringbuf keysb(ios::out | ios::in);
 51+ stringbuf valsb(ios::out | ios::in);
 52+
 53+ // Double NULL = end
 54+ if (cin.peek() == 0) {
 55+ cin.get();
 56+ break;
 57+ } else if (cin.peek() == -1) {
 58+ exit(-1);
 59+ }
 60+
 61+ cin.get( keysb, '\0' );
 62+ cin.get();
 63+
 64+ if (cin.peek() == 0) {
 65+ cin.get();
 66+ // Leave blank.
 67+ } else {
 68+ cin.get( valsb, '\0' );
 69+ cin.get();
 70+ }
 71+
 72+ cerr << "Got var " << keysb.str() << "=" << valsb.str() << endl;
 73+
 74+ vars[keysb.str()] = AFPData( valsb.str() );
 75+ }
 76+
 77+ return true;
 78+}
Property changes on: trunk/extensions/AbuseFilter/parser_native/eval.cpp
___________________________________________________________________
Added: svn:eol-style
179 + native
Added: svn:executable
280 + *

Status & tagging log