Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hoc_regexp_* by std::regex #2694

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ set(OC_FILE_LIST
ocerf.cpp
plot.cpp
plt.cpp
regexp.cpp
scoprand.cpp
settext.cpp
symbol.cpp
Expand Down
46 changes: 39 additions & 7 deletions src/nrnoc/cabcode.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <../../nrnconf.h>
/* /local/src/master/nrn/src/nrnoc/cabcode.cpp,v 1.37 1999/07/08 14:24:59 hines Exp */

#define HOC_L_LIST 1
#include <regex>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define HOC_L_LIST 1
#include "section.h"
#include "nrn_ansi.h"
#include "nrniv_mf.h"
Expand All @@ -13,6 +15,36 @@
#include "hocparse.h"
#include "membdef.h"

static char* escape_bracket(const char* s) {
static char* b;
const char* p1;
char* p2;
if (!b) {
b = new char[256];
}
for (p1 = s, p2 = b; *p1; ++p1, ++p2) {
switch (*p1) {
case '<':
*p2 = '[';
break;
case '>':
*p2 = ']';
break;
case '[':
case ']':
*p2 = '\\';
*(++p2) = *p1;
break;
default:
*p2 = *p1;
break;
}
}
*p2 = '\0';
return b;
}


extern int hoc_execerror_messages;
#define symlist hoc_symlist

Expand Down Expand Up @@ -1979,8 +2011,8 @@ void forall_section(void) {
Section* sec = hocSEC(qsec);
qsec = qsec->next;
if (buf[0]) {
hoc_regexp_compile(buf);
if (!hoc_regexp_search(secname(sec))) {
std::regex pattern(escape_bracket(buf));
if (!std::regex_match(secname(sec), pattern)) {
continue;
}
}
Expand Down Expand Up @@ -2011,17 +2043,17 @@ void hoc_ifsec(void) {

s = hoc_strpop();
Sprintf(buf, ".*%s.*", *s);
hoc_regexp_compile(buf);
if (hoc_regexp_search(secname(chk_access()))) {
std::regex pattern(escape_bracket(buf));
if (std::regex_match(secname(chk_access()), pattern)) {
hoc_execute(relative(savepc));
}
if (!hoc_returning)
pc = relative(savepc + 1);
}

void issection(void) { /* returns true if string is the access section */
hoc_regexp_compile(gargstr(1));
if (hoc_regexp_search(secname(chk_access()))) {
std::regex pattern(escape_bracket(gargstr(1)));
if (std::regex_match(secname(chk_access()), pattern)) {
hoc_retpushx(1.);
} else {
hoc_retpushx(0.);
Expand Down
2 changes: 0 additions & 2 deletions src/oc/oc_ansi.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ int is_vector_arg(int);
char* vector_get_label(IvocVect*);
void vector_set_label(IvocVect*, char*);

void hoc_regexp_compile(const char*);
int hoc_regexp_search(const char*);
Symbol* hoc_install_var(const char*, double*);
void hoc_class_registration();
void hoc_spinit();
Expand Down
Loading
Loading