[ScryMUD] SVN Commit Info r779 - trunk/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Sat Dec 18 12:50:50 PST 2004
Author: eroper
Date: 2004-12-18 12:50:48 -0800 (Sat, 18 Dec 2004)
New Revision: 779
Added:
trunk/mud/grrmud/server/regex.cc
trunk/mud/grrmud/server/regex.h
Modified:
trunk/mud/grrmud/server/command4.cc
trunk/mud/grrmud/server/command4.h
trunk/mud/grrmud/server/gen_cmds.spec
Log:
Added regex.[h/cc] (we now require linking to libpcre)
Added osdsearch (object short description search)
Added oldsearch (object long description search)
Added msdsearch (mob short description search)
Added mldsearch (mob long description search)
Fixed unsigned!=signed compilation warning with poofin/poofout
Notes on regex: options that would normally come after the Perl // syntax i.e.
/cat/i (for a case insensitive match on cat) can be accomplished like this:
osdsearch '(?i)cat'. In otherwords put the options in a (? ) container within
the pattern. For specifics on this, please see the pcrepattern manpage.
< 1032H 567M 511V > oldsearch '(?i)is\s+also\s+covered\s+in\s+acid'
425 the Sword of Sorrows
Bad regex patterns are reported to the user i.e.:
< 1032H 567M 511V > oldsearch '(?
REGEX compilation failed at 2: unrecognized character after (?
Modified: trunk/mud/grrmud/server/command4.cc
===================================================================
--- trunk/mud/grrmud/server/command4.cc 2004-12-18 06:51:40 UTC (rev 778)
+++ trunk/mud/grrmud/server/command4.cc 2004-12-18 20:50:48 UTC (rev 779)
@@ -44,6 +44,7 @@
#include <time.h>
#include <unistd.h>
#include "vehicle.h"
+#include "regex.h"
int do_gecho(const char* msg) {
@@ -92,7 +93,7 @@
return -1;
}//if
- for (int i = 0; i<pin->Strlen(); i++) {
+ for (unsigned int i = 0; i<pin->Strlen(); i++) {
if (pin->charAt(i) == '\n') {
pin->setCharAt(i, ' ');
}//if
@@ -114,7 +115,7 @@
return -1;
}//if
- for (int i = 0; i<pin->Strlen(); i++) {
+ for (unsigned int i = 0; i<pin->Strlen(); i++) {
if (pin->charAt(i) == '\n') {
pin->setCharAt(i, ' ');
}//if
@@ -1602,7 +1603,56 @@
return 0;
}//olist
+int osdsearch(String *match_str, critter& pc) {
+ String buf(100);
+ regex my_regex;
+ if (!ok_to_do_action(NULL, "IFP", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
+ return -1;
+ }
+
+ if (! (my_regex = *match_str) ) {
+ pc.show(my_regex.getErr());
+ return -1;
+ }
+
+ for (int i=0;i<NUMBER_OF_ITEMS;i++) {
+ if ( obj_list[i].isInUse() ) {
+ if ( my_regex == obj_list[i].short_desc ) {
+ Sprintf(buf, "\t%i\t%S\n", i, &(obj_list[i].short_desc));
+ pc.show(buf);
+ }//if matches
+ }//if in use
+ }//for
+
+ return 0;
+}//osdsearch
+
+int oldsearch(String *match_str, critter& pc) {
+ String buf(100);
+ regex my_regex;
+
+ if (!ok_to_do_action(NULL, "IFP", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
+ return -1;
+ }
+
+ if (! (my_regex = *match_str) ) {
+ pc.show(my_regex.getErr());
+ return -1;
+ }
+
+ for (int i=0;i<NUMBER_OF_ITEMS;i++) {
+ if ( obj_list[i].isInUse() ) {
+ if ( my_regex == obj_list[i].long_desc ) {
+ Sprintf(buf, "\t%i\t%S\n", i, &(obj_list[i].short_desc));
+ pc.show(buf);
+ }//if matches
+ }//if in use
+ }//for
+
+ return 0;
+}//oldsearch
+
int zlist(int start, int end, critter& pc) {
if (!ok_to_do_action(NULL, "IF", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
return -1;
@@ -1631,7 +1681,54 @@
return 0;
}//zlist
+int msdsearch(String *match_str, critter& pc) {
+ String buf(100);
+ regex my_regex;
+ if (!ok_to_do_action(NULL, "IFP", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
+ return -1;
+ }
+
+ if (! (my_regex = *match_str) ) {
+ pc.show(my_regex.getErr());
+ return -1;
+ }
+
+ for (int i=0;i<=NUMBER_OF_MOBS;i++) {
+ if (mob_list[i].isInUse()) {
+ if ( my_regex == mob_list[i].short_desc ) {
+ Sprintf(buf, "\t%i\t%S\n", i, &(mob_list[i].short_desc));
+ show(buf, pc);
+ }//if matches
+ }//if in use
+ }//for
+ return 0;
+}//msdsearch
+
+int mldsearch(String *match_str, critter& pc) {
+ String buf(100);
+ regex my_regex;
+
+ if (!ok_to_do_action(NULL, "IFP", 0, pc, pc.getCurRoom(), NULL, TRUE)) {
+ return -1;
+ }
+
+ if (! (my_regex = *match_str) ) {
+ pc.show(my_regex.getErr());
+ return -1;
+ }
+
+ for (int i=0;i<=NUMBER_OF_MOBS;i++) {
+ if (mob_list[i].isInUse()) {
+ if ( my_regex == mob_list[i].long_desc ) {
+ Sprintf(buf, "\t%i\t%S\n", i, &(mob_list[i].short_desc));
+ show(buf, pc);
+ }//if matches
+ }//if in use
+ }//for
+ return 0;
+}//mldsearch
+
int mlist(int start, int end, critter& pc) {
String buf(100);
@@ -1666,7 +1763,6 @@
return 0;
}//mlist
-
int rlist(int start, int end, critter& pc) {
String buf(100);
Modified: trunk/mud/grrmud/server/command4.h
===================================================================
--- trunk/mud/grrmud/server/command4.h 2004-12-18 06:51:40 UTC (rev 778)
+++ trunk/mud/grrmud/server/command4.h 2004-12-18 20:50:48 UTC (rev 779)
@@ -74,6 +74,10 @@
int brief(critter& pc);
int olist(int start, int end, critter& pc);
+int oldsearch(String* match_str, critter& pc);
+int osdsearch(String* match_str, critter& pc);
+int msdsearch(String* match_str, critter& pc);
+int mldsearch(String* match_str, critter& pc);
int mlist(int start, int end, critter& pc);
int rlist(int start, int end, critter& pc);
int dlist(int start, int end, critter& pc);
Modified: trunk/mud/grrmud/server/gen_cmds.spec
===================================================================
--- trunk/mud/grrmud/server/gen_cmds.spec 2004-12-18 06:51:40 UTC (rev 778)
+++ trunk/mud/grrmud/server/gen_cmds.spec 2004-12-18 20:50:48 UTC (rev 779)
@@ -520,10 +520,14 @@
return mclear(i, pc);
mclone ~
return mclone(i, &(cooked_strs[1]), pc);
+mldsearch ~
+return mldsearch(&(cooked_strs[1]), pc);
mlist ~
return mlist(i, j, pc);
mload ~
return mload(i, &(cooked_strs[1]), pc);
+msdsearch ~
+return msdsearch(&(cooked_strs[1]), pc);
mset ~
return mset(i, &(cooked_strs[1]), &(cooked_strs[2]), k, &(cooked_strs[3]), pc);
mstat ~
@@ -570,12 +574,16 @@
return oclone(i, &(cooked_strs[1]), pc);
olc ~
return handle_olc(pc, do_sub);
+oldsearch ~
+return oldsearch(&(cooked_strs[1]), pc);
olist ~
return olist(i, j, pc);
oload ~
return oload(i, &(cooked_strs[1]), pc);
opurge ~
return opurge(i, &(cooked_strs[1]), pc);
+osdsearch ~
+return osdsearch(&(cooked_strs[1]), pc);
ostat ~
return ostat(i, &(cooked_strs[1]), pc);
oreload ~
Added: trunk/mud/grrmud/server/regex.cc
===================================================================
--- trunk/mud/grrmud/server/regex.cc 2004-12-18 06:51:40 UTC (rev 778)
+++ trunk/mud/grrmud/server/regex.cc 2004-12-18 20:50:48 UTC (rev 779)
@@ -0,0 +1,82 @@
+// $Id$
+// $Revision: 1.52 $ $Author$ $Date$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 1998 Ben Greear
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// To contact the Author, Ben Greear: greear at cyberhighway.net, (preferred)
+// greearb at agcs.com
+//
+#include "regex.h"
+
+regex::regex() {
+ re = NULL;
+ err_msg.clear();
+ pattern.clear();
+}//regex::regex
+
+regex::~regex() {
+ if ( re ) {
+ pcre_free(re);
+ }
+}//regex::~regex
+
+regex *regex::operator=(String &new_pat) {
+ const char *err;
+ int err_offset;
+
+ re = pcre_compile(
+ (const char*)new_pat,
+ 0,
+ &err,
+ &err_offset,
+ NULL);
+ if (re == NULL) {
+ Sprintf(err_msg, "REGEX compilation failed at %d: %s\n",
+ err_offset, err);
+ delete err;
+ return NULL;
+ }
+ pattern = new_pat;
+ return this;
+}//regex::operator=
+
+bool regex::operator==(String &match_str) {
+
+ int rc;
+
+ //no pattern initialized
+ if ( !re ) {
+ return false;
+ }
+
+ rc = pcre_exec(
+ re,
+ NULL,
+ (const char*)match_str,
+ match_str.Strlen(),
+ 0,
+ 0,
+ NULL,
+ 0);
+
+ if ( rc < 0 ) {
+ return false;
+ }
+ return true;
+}//regex::operator==
Property changes on: trunk/mud/grrmud/server/regex.cc
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
Added: trunk/mud/grrmud/server/regex.h
===================================================================
--- trunk/mud/grrmud/server/regex.h 2004-12-18 06:51:40 UTC (rev 778)
+++ trunk/mud/grrmud/server/regex.h 2004-12-18 20:50:48 UTC (rev 779)
@@ -0,0 +1,46 @@
+// $Id$
+// $Revision: 1.52 $ $Author$ $Date$
+
+//
+//ScryMUD Server Code
+//Copyright (C) 1998 Ben Greear
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// To contact the Author, Ben Greear: greear at cyberhighway.net, (preferred)
+// greearb at agcs.com
+//
+
+#ifndef GRRMUD_REGEX_INCLUDE_H
+#define GRRMUD_REGEX_INCLUDE_H
+
+#include <string2.h>
+#include <pcre.h>
+
+class regex {
+ protected:
+ String err_msg;
+ String pattern;
+ pcre *re;
+ //TODO: add a ptrarray of Strings for submatch contents
+ public:
+ regex();
+ ~regex();
+ regex* operator=(String &new_pat);
+ bool operator==(String &match_str);
+ String &getErr(void) { return err_msg; }
+};
+
+#endif
Property changes on: trunk/mud/grrmud/server/regex.h
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision
More information about the ScryMUD
mailing list