diff --git a/cmake/ConfigFileSetting.cmake b/cmake/ConfigFileSetting.cmake index 64c09dbea5..205aff616a 100644 --- a/cmake/ConfigFileSetting.cmake +++ b/cmake/ConfigFileSetting.cmake @@ -271,7 +271,6 @@ nrn_configure_file(nrnpython_config.h src/nrnpython) nrn_configure_file(bbsconf.h src/parallel) nrn_configure_file(nrnneosm.h src/nrncvode) nrn_configure_file(sundials_config.h src/sundials) -nrn_configure_file(mos2nrn.h src/uxnrnbbs) nrn_configure_dest_src(nrnunits.lib share/nrn/lib nrnunits.lib share/lib) nrn_configure_dest_src(nrn.defaults share/nrn/lib nrn.defaults share/lib) # NRN_DYNAMIC_UNITS requires nrnunits.lib.in be in same places as nrnunits.lib diff --git a/src/ivoc/nrnbbs.cpp b/src/ivoc/nrnbbs.cpp deleted file mode 100755 index a2e1b40e9c..0000000000 --- a/src/ivoc/nrnbbs.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -// -// This just includes a file from another directory. Automake doesn't like -// to have source files living in a separate directory. -// -#include "../uxnrnbbs/nrnbbs.cpp" diff --git a/src/ivoc/ochelp.cpp b/src/ivoc/ochelp.cpp index 204c8cab02..fa9b5d540e 100644 --- a/src/ivoc/ochelp.cpp +++ b/src/ivoc/ochelp.cpp @@ -26,7 +26,6 @@ static FILE* help_pipe; #ifndef WIN32 #define WIN32 #define UNIX 1 -//#include "../uxnrnbbs/nrnbbs.h" #endif extern const char* hoc_current_xopen(); diff --git a/src/uxnrnbbs/bbstest.cpp b/src/uxnrnbbs/bbstest.cpp deleted file mode 100644 index 36406a9589..0000000000 --- a/src/uxnrnbbs/bbstest.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include <../../nrnconf.h> -#include -#include "nrnbbs.h" - -void cb(const char* s) { - printf("callback %s\n", s); - char buf[200]; - buf[0] = '\0'; - int ok = nrnbbs_take_string(s, buf); - printf("%d take |%s| |%s|\n", ok, s, buf); -} - -void main() { - int i, ok; - char buf[256]; - nrnbbs_connect(); - nrnbbs_notify("test2", cb); - nrnbbs_post("test1"); - nrnbbs_post_int("test2", 5); - nrnbbs_post_string("test3", "posted string"); - - printf("test1 look %d\n", nrnbbs_look("test1")); - printf("test1 look %d\n", nrnbbs_look("test1")); - printf("test1 take %d\n", nrnbbs_take("test1")); - printf("test1 take %d\n", nrnbbs_take("test1")); - - i = 0; - ok = nrnbbs_take_int("test2", &i); - printf("test2 %d i=%d\n", ok, i); - - nrnbbs_post("space look"); - printf("space look %d\n", nrnbbs_look("space look")); - printf("space take %d\n", nrnbbs_take("space look")); - buf[0] = '\0'; - ok = nrnbbs_take_string("test3", buf); - printf("test3 %d buf=|%s|\n", ok, buf); - - printf("Hit Return:\n"); - gets(buf); - nrnbbs_disconnect(); -} diff --git a/src/uxnrnbbs/hel2mos.cpp b/src/uxnrnbbs/hel2mos.cpp deleted file mode 100644 index 918c750384..0000000000 --- a/src/uxnrnbbs/hel2mos.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include <../../nrnconf.h> -#ifdef WIN32 -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include "nrnbbs.h" - -#ifdef WIN32 -#include "../winio/debug.h" -static void setneuronhome(const char*); -#endif - -extern const char* neuronhome(); - -void start(); -void stop(); -void send(const char* url); - -static bool quit_; - -static void quit(const char* msg) { - // printf("hel2mos quit |%s|\n", msg); - // DebugMessage("hel2mos quit |%s|\n", msg); - if (strcmp(msg, "neuron closed") == 0) { - quit_ = true; - } -} - -static RETSIGTYPE quit1(int) { - quit_ = true; -} - -static void help(const char*); -static CopyString* shelp; - - -int main(int argc, const char** argv) { -#ifdef WIN32 - setneuronhome(argv[0]); -#endif - if (!neuronhome()) { - printf("no NEURONHOME\n"); - return 1; - } - // printf("started hel2mos\n"); - - { - std::string name = std::string(neuronhome()) + "/lib/helpdict"; - std::ifstream f(name, std::ios::in | std::ios::binary); - if (!f.is_open()) { - printf("Can't open %s\n", name.c_str()); - return 1; - } - std::string content; - f.seekg(0, std::ios::end); - size_t flen = f.tellg(); - content.resize(flen); - f.seekg(0, std::ios::beg); - f.read(&content[0], content.size()); - f.close(); - shelp = new CopyString(content.c_str(), flen); - } - - nrnbbs_connect(); - nrnbbs_post("ochelp running"); - start(); - nrnbbs_notify("ochelp", help); -#ifdef WIN32 - nrnbbs_notify("neuron closed", help); -#else - nrnbbs_notify("neuron closed", quit); -#endif - help(""); - nrnbbs_wait(&quit_); - stop(); - nrnbbs_take("ochelp running"); - nrnbbs_disconnect(); - return 0; -} - -static bool find(const char* key, char* val) { - static char buf[256]; - Sprintf(buf, "^%s ", key); - // printf("|%s|\n", buf); - Regexp r1(buf); - int i = r1.Search(shelp->string(), shelp->length(), 0, shelp->length()); - // printf("i=%d\n", i); - if (i < 0) { - return false; - } - Regexp r2("neuron/"); - i = r2.Search(shelp->string(), shelp->length(), i, shelp->length()); - // printf("i=%d\n", i); - int j = shelp->search(i, '\n'); - // printf("j=%d\n", j); - strncpy(val, shelp->string() + i, j - i); - val[j - i] = '\0'; - return true; -} - -static void help(const char* msg) { - if (strcmp(msg, "neuron closed") == 0) { - quit_ = true; - } - char buf[256]; - // printf("hel2mos help |%s|\n", msg); - while (nrnbbs_take_string("ochelp", buf)) { - if (buf[0] == '?') { - // printf("took ochelp: %s\n", buf); - } else { - if (find(buf, buf)) { - // printf("%s\n", buf); - } else { - Sprintf(buf, "contents.html"); - } -#ifdef WIN32 - // DebugMessage("buf=|%s|\n", buf); - char buf1[256], buf2[256]; - strcpy(buf2, buf); - strcpy(buf1, neuronhome()); - for (char* cp = buf1; *cp; ++cp) { - if (*cp == ':') { - *cp = '|'; - } - if (*cp == '\\') { - *cp = '/'; - } - } - Sprintf(buf, "file:///%s/html/help/%s", buf1, buf2); -#endif - send(buf); - } - } -} - -const char* neuronhome() { - const char* n = getenv("NEURONHOME"); - if (n) { - return n; - } - return nil; -} - -#if defined(WIN32) -static void setneuronhome(const char* p) { - // if the program lives in .../bin/mos2nrn.exe - // and .../lib exists then use ... as the - // NEURONHOME - // printf("p=|%s|\n", p); - char buf[256]; - if (p[0] == '"') { - strcpy(buf, p + 1); - } else { - strcpy(buf, p); - } - int i, j; - for (i = strlen(buf); i >= 0 && buf[i] != '\\'; --i) { - ; - } - buf[i] = '\0'; // /neuron.exe gone - // printf("setneuronhome |%s|\n", buf); - for (j = strlen(buf); j >= 0 && buf[j] != '\\'; --j) { - ; - } - buf[j] = '\0'; // /bin gone - // but make sure it was bin Bin or BIN -- damn you bill gates - // printf("i=%d j=%d buf=|%s|\n",i, j, buf); - if (i == j + 4 && (buf[--i] == 'n' || buf[i] == 'N') && (buf[--i] == 'i' || buf[i] == 'I') && - (buf[--i] == 'b' || buf[i] == 'B')) { - static char buf1[256]; - // check for nrn.def or nrn.defaults - // if it exists assume valid installation - FILE* f; - Sprintf(buf1, "%s/lib/nrn.def", buf); - if ((f = fopen(buf1, "r")) == (FILE*) 0) { - Sprintf(buf1, "%s/lib/nrn.defaults", buf); - if ((f = fopen(buf1, "r")) == (FILE*) 0) { - Sprintf(buf1, "%s not valid neuronhome\n", buf); - MessageBox(NULL, buf1, "mos2nrn", MB_OK); - return; - } - } - fclose(f); - Sprintf(buf1, "NEURONHOME=%s", buf); - putenv(buf1); // arg must be global - } -} - -char* nrnhome; - -#else - -#include -#include - -static int mosaic_pid_; /* no longer used. 0 is fine */ - -void start() { -#if defined(SIGNAL_CAST) - signal(SIGHUP, (SIGNAL_CAST) quit1); -#else - signal(SIGHUP, quit1); -#endif -} - -void stop() {} - -void send(const char* url) { - char buf1[512]; - int start = 0; - while (url[start] == ' ') { - ++start; - } - Sprintf(buf1, "%s/bin/hel2mos1.sh \"%s\"", neuronhome(), url + start); - // printf("sending |%s|\n", buf1); - signal(SIGCHLD, SIG_IGN); - system(buf1); -#if defined(SIGNAL_CAST) - signal(SIGCHLD, (SIGNAL_CAST) quit1); -#else - signal(SIGCHLD, quit1); -#endif -} - -#endif diff --git a/src/uxnrnbbs/mos2nrn.cpp b/src/uxnrnbbs/mos2nrn.cpp deleted file mode 100644 index 8cf94c9ffc..0000000000 --- a/src/uxnrnbbs/mos2nrn.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include <../../nrnconf.h> -#include -#include -#include "../oc/nrnassrt.h" -#include -#include -#include "mos2nrn.h" - -static void getdname(char* dname, size_t sz); - -#include - -const char* back2forward(const char*); -const char* basefile(const char*); - -int main(int argc, char** argv) { - char buf[256]; - char dname[256]; - - if (argc != 2) { - fprintf(stderr, "Usage: mos2nrn [hocfile | nrnzipfile]\n"); - return 1; - } - FILE* f = fopen(argv[1], "r"); - if (!f) { - return 1; - } - if (fread(buf, 1, 5, f) < 2) { - return 1; - } - fclose(f); - if (strncmp(buf, "PK", 2) == 0) { // its a nrnzip file - getdname(dname, 256); - nrn_assert(snprintf(buf, - 256, - "xterm -sb -e %s/mos2nrn2.sh %s %s %d", - NEURON_BIN_DIR, - argv[1], - dname, - 0) < 256); - int i = system(buf); - if (i) { - return i; - } - } else { // its a hoc file - Sprintf(buf, "xterm -sb -e %s/nrniv %s -", NEURON_BIN_DIR, argv[1]); - int i = system(buf); - if (i) { - return i; - } - } - return 0; -} - -const char* back2forward(const char* back) { - static char forward[256]; - char* cp; - strcpy(forward, back); - for (cp = forward; *cp; ++cp) { - if (*cp == '\\') { - *cp = '/'; - } - } - return forward; -} - -const char* basefile(const char* path) { - const char* cp; - for (cp = path + strlen(path) - 1; cp >= path; --cp) { - if (*cp == '\\' || *cp == ':' || *cp == '/') { - return cp + 1; - } - } - return path; -} - -static void getdname(char* dname, size_t sz) { - int fd; - const char* tdir; - if ((tdir = getenv("TEMP")) == NULL) { - tdir = "/tmp"; - } - std::snprintf(dname, sz, "%s/nrnXXXXXX", tdir); -#if HAVE_MKSTEMP - fd = mkstemp(dname); - close(fd); -#else - mktemp(dname); -#endif -} diff --git a/src/uxnrnbbs/mos2nrn.h.in b/src/uxnrnbbs/mos2nrn.h.in deleted file mode 100755 index 9a15952671..0000000000 --- a/src/uxnrnbbs/mos2nrn.h.in +++ /dev/null @@ -1 +0,0 @@ -#define NEURON_BIN_DIR "@exec_prefix@/bin" diff --git a/src/uxnrnbbs/nrnbbs.cpp b/src/uxnrnbbs/nrnbbs.cpp deleted file mode 100644 index fe16624516..0000000000 --- a/src/uxnrnbbs/nrnbbs.cpp +++ /dev/null @@ -1,363 +0,0 @@ -#include <../../nrnconf.h> -// bug in the osx 10.2 environment -#if defined(__POWERPC__) && defined(__APPLE__) -#undef HAVE_LOCKF -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include "nrnbbs.h" - -#if !defined(HAVE_LOCKF) -#include -#endif - -#define HISTORY 0 - -#define NRNBBSTMP "nrnbbs" -#define NOTIFY "notify" -#define NRNBBS "nrnbbs" -#define LOCKFILE "lock" -#define TMPFILE "temp" -#define NOTIFY_SIGNAL SIGUSR1 - -class NrnBBSCallbackItem { - public: - NrnBBSCallbackItem(const char*, NrnBBSCallback); - virtual ~NrnBBSCallbackItem(); - bool equal(const char*); - void execute(); - - private: - CopyString s_; - NrnBBSCallback cb_; -}; - -static const char* fname(const char* name); - -static void history(const char* s1, const char* s2, const char* s3) { -#if HISTORY - FILE* f; - if ((f = fopen(fname("history"), "a")) != (FILE*) 0) { - fprintf(f, "%5d %s |%s| |%s|\n", getpid(), s1, s2, s3); - fclose(f); - } -#endif -} - -static void history(const char* s1) { - history(s1, "", ""); -} -static void history(const char* s1, const char* s2) { - history(s1, s2, ""); -} -static void history(const char* s1, int i) { - char buf[20]; - Sprintf(buf, "%d", i); - history(s1, buf, ""); -} - -declarePtrList(NrnBBSCallbackList, NrnBBSCallbackItem) -implementPtrList(NrnBBSCallbackList, NrnBBSCallbackItem) - -static NrnBBSCallbackList* cblist_; -static FILE* lockfile_; - -static void get_lock() { -#if !defined(HAVE_LOCKF) - while (flock(fileno(lockfile_), LOCK_EX) != 0) { -#else - while (lockf(fileno(lockfile_), F_LOCK, 0) != 0) { -#endif - history("lockf returned non zero"); - } - // printf("got lock for %d\n", getpid()); -} - -static void release_lock() { -#if !defined(HAVE_LOCKF) - flock(fileno(lockfile_), LOCK_UN); -#else - lockf(fileno(lockfile_), F_ULOCK, 0); -#endif - // printf("released lock for %d\n", getpid()); -} - -static const char* nrnbbsdir() { - static char* d; - if (!d) { - char buf[256]; - char* tmpdir; - tmpdir = getenv("TMPDIR"); - if (!tmpdir) { - tmpdir = "/tmp"; - } - Sprintf(buf, "%s/%s_%s", tmpdir, getenv("USER"), NRNBBSTMP); - d = new char[strlen(buf) + 1]; - strcpy(d, buf); - mkdir(d, 0777); - } - return d; -} - -static const char* fname(const char* name) { - static char buf[2][256]; - static int i = 0; - i = (i + 1) % 2; - Sprintf(buf[i], "%s/%s", nrnbbsdir(), name); - return buf[i]; -} - -static bool connected_; - -bool nrnbbs_connect() { - if (!lockfile_) { - const char* lfile = fname(LOCKFILE); - lockfile_ = fopen(lfile, "w"); - if (!lockfile_) { - connected_ = false; - return connected_; - } - } - connected_ = true; - history("connect"); - return connected_; -} - -void nrnbbs_disconnect() { - connected_ = false; - history("disconnect"); - if (cblist_) { - get_lock(); - int pid = getpid(); - FILE* f = fopen(fname(NOTIFY), "r"); - if (f) { - char buf[256]; - int id; - FILE* f2 = fopen(fname(TMPFILE), "w"); - if (!f2) { - fprintf(stderr, "can't open %s\n", fname(TMPFILE)); - } - while (fgets(buf, 256, f)) { - buf[strlen(buf) - 1] = '\0'; - fscanf(f, "%d\n", &id); - if (id != pid) { - fprintf(f2, "%s\n%d\n", buf, id); - } - } - fclose(f2); - fclose(f); - rename(fname(TMPFILE), fname(NOTIFY)); - } - release_lock(); - for (long i = 0; i < cblist_->count(); ++i) { - delete cblist_->item(i); - } - delete cblist_; - cblist_ = nil; - } - if (lockfile_) { - fclose(lockfile_); - lockfile_ = (FILE*) 0; - } -} - -bool nrnbbs_connected() { - return connected_; -} - - -void nrnbbs_wait(bool* pflag) { - bool f = false; - bool* pf; - pf = (pflag) ? pflag : &f; - while (!(*pf) && nrnbbs_connected()) { - f = true; // once only if no arg - pause(); - } -} - -void nrnbbs_post(const char* key) { - nrnbbs_post_string(key, ""); -} - -void nrnbbs_post_int(const char* key, int ival) { - char buf[30]; - Sprintf(buf, "%d", ival); - nrnbbs_post_string(key, buf); -} - -void nrnbbs_post_string(const char* key, const char* sval) { - history("post", key, sval); - get_lock(); - FILE* f = fopen(fname(NRNBBS), "a"); - fprintf(f, "%s\n%s\n", key, sval); - FILE* f2 = fopen(fname(NOTIFY), "r"); - char name[256]; - int i, n, id[10]; - n = 0; - if (f2) { - while (fgets(name, 256, f2) && n < 10) { - name[strlen(name) - 1] = '\0'; - fscanf(f2, "%d\n", &i); - if (strcmp(name, key) == 0) { - id[n++] = i; - fprintf(f, "nrnbbs_notifying %s\n\n", key); - } - } - fclose(f2); - } - fclose(f); - release_lock(); - for (i = 0; i < n; ++i) { - history(" notify", id[i]); - kill(id[i], NOTIFY_SIGNAL); - } -} - - -bool nrnbbs_take(const char* key) { - char buf[256]; - return nrnbbs_take_string(key, buf); -} - -bool nrnbbs_take_int(const char* key, int* ipval) { - char buf[256]; - bool b = nrnbbs_take_string(key, buf); - if (b) { - b = (sscanf(buf, "%d\n", ipval) == 1) ? true : false; - } - return b; -} - -bool nrnbbs_take_string(const char* key, char* sval) { - history("take", key); - get_lock(); - bool b = false; - FILE* f = fopen(fname(NRNBBS), "r"); - if (f != (FILE*) 0) { - char name[256], val[256]; - FILE* f2 = fopen(fname(TMPFILE), "w"); - while (fgets(name, 256, f)) { - name[strlen(name) - 1] = '\0'; - if (name[0] == '\0') { - continue; - } - fgets(val, 256, f); - val[strlen(val) - 1] = '\0'; - if (!b && strcmp(name, key) == 0) { - history(" found", val); - b = true; - strcpy(sval, val); - continue; - } - fprintf(f2, "%s\n%s\n", name, val); - } - fclose(f2); - fclose(f); - if (b) { - rename(fname(TMPFILE), fname(NRNBBS)); - } - } else { - b = false; - } - release_lock(); - return b; -} - - -bool nrnbbs_look(const char* key) { - history("look", key); - get_lock(); - bool b = false; - FILE* f = fopen(fname(NRNBBS), "r"); - if (f != (FILE*) 0) { - char name[256], val[256]; - while (fgets(name, 256, f)) { - name[strlen(name) - 1] = '\0'; - fgets(val, 256, f); - if (strcmp(name, key) == 0) { - history(" found"); - b = true; - break; - } - } - fclose(f); - } else { - b = false; - } - release_lock(); - return b; -} - - -void nrnbbs_exec(const char* cmd) { - history("exec", cmd); - char buf[256]; - Sprintf(buf, "%s&", cmd); - system(buf); -} - - -static RETSIGTYPE nrnbbs_handler(int) { - long i; -#if defined(SIGNAL_CAST) - signal(NOTIFY_SIGNAL, (SIGNAL_CAST) nrnbbs_handler); -#else - signal(NOTIFY_SIGNAL, nrnbbs_handler); -#endif - for (i = 0; i < cblist_->count(); ++i) { - cblist_->item(i)->execute(); - } -} - -void nrnbbs_notify(const char* key, NrnBBSCallback cb) { - history("nrnbbs_notify", key); - if (!cblist_) { - cblist_ = new NrnBBSCallbackList(); - } - cblist_->append(new NrnBBSCallbackItem(key, cb)); - get_lock(); - FILE* f = fopen(fname(NOTIFY), "a"); - if (!f) { - fprintf(stderr, "can't open %s\n", fname(NOTIFY)); - return; - } - fprintf(f, "%s\n%d\n", key, getpid()); - fclose(f); - release_lock(); -#if defined(SIGNAL_CAST) - signal(NOTIFY_SIGNAL, (SIGNAL_CAST) nrnbbs_handler); -#else - signal(NOTIFY_SIGNAL, nrnbbs_handler); -#endif -} - -NrnBBSCallbackItem::NrnBBSCallbackItem(const char* s, NrnBBSCallback cb) { - cb_ = cb; - s_ = s; -} - -NrnBBSCallbackItem::~NrnBBSCallbackItem() {} - -bool NrnBBSCallbackItem::equal(const char* s) { - return (strcmp(s_.string(), s) == 0) ? true : false; -} - -void NrnBBSCallbackItem::execute() { - char buf[256]; - Sprintf(buf, "nrnbbs_notifying %s", s_.string()); - if (nrnbbs_take(buf)) { - (*cb_)(s_.string()); - } -} diff --git a/src/uxnrnbbs/nrnbbs.h b/src/uxnrnbbs/nrnbbs.h deleted file mode 100644 index 9b9ea3f80d..0000000000 --- a/src/uxnrnbbs/nrnbbs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef nrnbbs_h -#define nrnbbs_h - -typedef void (*NrnBBSCallback)(const char*); - -bool nrnbbs_connect(); -void nrnbbs_disconnect(); -bool nrnbbs_connected(); - -void nrnbbs_post(const char*); -void nrnbbs_post_int(const char*, int); -void nrnbbs_post_string(const char*, const char*); - -bool nrnbbs_take(const char*); -bool nrnbbs_take_int(const char*, int*); -bool nrnbbs_take_string(const char*, char*); - -bool nrnbbs_look(const char*); - -void nrnbbs_exec(const char*); - -void nrnbbs_notify(const char*, NrnBBSCallback); - -// return when *pflag = true or one step wait if no arg -void nrnbbs_wait(bool* pflag = (bool*) 0); - -/* for debugging and bbs management */ -#if 0 -void nrnbbs_clean(); -void nnrbbs_quit(); -int nrnbbs_count(); -bool nrnbbs_query(long index); -#endif - -#endif