NEURON
ochelp.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 // nrnbbs has been removed. This is no longer working.
5 
6 #include <InterViews/cursor.h>
7 #include <InterViews/window.h>
8 #include <OS/list.h>
9 #include <OS/string.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <ctype.h>
13 
14 #include "ivoc.h"
15 
16 static FILE* help_pipe;
17 
18 #if MAC && !defined(carbon)
19 #define WIN32 1
20 #endif
21 
22 #if defined(WIN32) && !defined(CYGWIN)
23 #include "nrnbbs.h"
24 #endif
25 
26 #ifndef WIN32
27 #define WIN32
28 #define UNIX 1
29 //#include "../uxnrnbbs/nrnbbs.h"
30 #endif
31 
32 extern const char* hoc_current_xopen();
33 
34 declareList(CopyStringList, CopyString)
35 implementList(CopyStringList, CopyString)
36 
37 static CopyStringList* filequeue;
38 
39 extern "C" void ivoc_help(const char* s) {
40 #if 1
41 // printf("online help not currently working\n");
42  return;
43 #else
44  char buf[256];
45  strncpy(buf, s+4, 256);
46  char* p;
47  for (p = buf; *p; ++p) { // eliminate trailing newline
48  if (*p == '\n') {
49  *p = '\0';
50  break;
51  }
52  }
53  for (p = buf; *p; ++p) { // start at first character
54  if (!isspace(*p)) {
55  break;
56  }
57  }
58  // queue up the help files if haven't invoked help
59  if (!help_pipe) {
60  if (!filequeue) {
61  filequeue = new CopyStringList();
62  }
63  if (strncmp(p, "?0", 2) == 0) {
64  sprintf(buf, "?0 %s", hoc_current_xopen());
65  String str(buf);
66  filequeue->append(str);
67  return;
68  }else if (strncmp(p, "?1", 2) == 0) {
69  filequeue->append(p);
70  return;
71  }
72  }
73  if (*p) {
74  Oc::help(p);
75  }else{
76  Oc::help("Help_root");
77  }
78 #endif
79 }
80 
81 static void readmore() {
82 #if !defined(WIN32) && !defined(MAC)
83  char buf[1024];
84  char* cmd = "ls $NEURONHOME/doc/help/*.help";
85  FILE* p = popen(cmd, "r");
86  if (!p) {
87  printf("couldn't do: %s\n", cmd);
88  return;
89  }
90  while (fgets(buf, 1024, p)) {
91  fprintf(help_pipe, "?0 %s", buf);
92  }
93 #endif
94 }
95 
96 #if !defined(WIN32) && !defined(MAC)
97 void Oc::help(const char* s) {
98 #if 1
99  printf("online help not currently working\n");
100 #else
101  if (help_pipe && ferror(help_pipe)) {
102 printf("error on the help pipe, restarting\n\
103 but will be missing this sessions hoc help text\n");
104  pclose(help_pipe);
105  help_pipe = NULL;
106  }
107  if (!help_pipe) {
108  printf("Starting the help system\n");
109  char buf[200];
110  sprintf(buf, "%s/ochelp", "$NEURONHOME/bin/$CPU");
111  if ((help_pipe = popen(buf, "w")) == (FILE*)0) {
112  printf("Could not start %s\n", buf);
113  }
114 //printf("help_pipe = %p\n", help_pipe);
115  readmore();
116  if (filequeue) {
117  for (long i = 0; i < filequeue->count(); ++i) {
118 fprintf(help_pipe, "%s\n", filequeue->item_ref(i).string());
119  }
120  filequeue->remove_all();
121  }
122  }
123  if (help_pipe) {
124 //printf("|%s|\n", s);
125  if (strncmp(s, "?0", 2) == 0) {
126  char buf[1024];
127  sprintf(buf, "?0 %s", hoc_current_xopen());
128  fprintf(help_pipe, "%s\n", buf);
129  }else{
130  fprintf(help_pipe, "%s\n", s);
131  }
132  fflush(help_pipe);
133  }
134 #endif
135 }
136 #endif
137 
138 #if defined(WIN32) || defined(MAC)
139 
140 void Oc::help(const char* s) {
141 #if 0
142 #ifndef CYGWIN
143  static bool ran_ochelp = false;
144  char buf[1024];
145  nrnbbs_connect(); // benign if already connected
146  if (!nrnbbs_connected()) {
147  printf("Could not connect to nrnbbs service\n");
148  return;
149  }
150  if (!ran_ochelp && !nrnbbs_look("ochelp running")) {
151  ran_ochelp = true;
152  printf("Starting the help system\n");
153  nrnbbs_exec("ochelp");
154  }else if (!nrnbbs_look("ochelp running")) {
155  printf("proper ochelp version not running\n");
156  return;
157  }
158 
159 #if 1
160  readmore();
161  if (filequeue) {
162  for (long i = 0; i < filequeue->count(); ++i) {
163 sprintf(buf, "%s\n", filequeue->item_ref(i).string());
164  nrnbbs_post_string("ochelp", buf);
165  }
166  filequeue->remove_all();
167  }
168 #endif
169 
170  if (strncmp(s, "?0", 2) == 0) {
171  sprintf(buf, "?0 %s", hoc_current_xopen());
172  nrnbbs_post_string("ochelp", buf);
173  }else{
174  nrnbbs_post_string("ochelp", s);
175  }
176 #endif
177 #endif
178 }
179 #endif
180 
181 void Oc::helpmode(bool b) {
182  helpmode_ = b;
183 }
184 
185 void Oc::helpmode(Window* w) {
186  if (helpmode()) {
187  if (w->cursor() != Oc::help_cursor()) {
188  w->push_cursor();
189  w->cursor(Oc::help_cursor());
190  }
191  }else{
192  if (w->cursor() == Oc::help_cursor()) {
193  w->pop_cursor();
194  }
195  }
196 }
197 
198 static const CursorPattern question_pat = {
199  0x0000, 0x0000, 0x0000, 0x7c00, 0xce00, 0x0600, 0x0600, 0x0c00,
200  0x3000, 0x6000, 0x6000, 0x6000, 0x0000, 0x0000, 0x6000, 0x6000
201 };
202 
203 static const CursorPattern question_mask = {
204 // 0x0000, 0x0000, 0x7c00, 0xfe00, 0xff00, 0xcf00, 0x0f00, 0x3e00,
205 // 0x7c00, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000
206 #if !defined(UNIX) && (defined(WIN32) || defined(MAC))
207  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
208  0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
209 #else
210  0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00,
211  0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00, 0xfe00
212 #endif
213 };
214 
215 
216 
218 
220  if (!Oc::help_cursor_) {
221  help_cursor_ = new Cursor(4, 7, question_pat, question_mask);
222  }
223  return help_cursor_;
224 }
225 
226 
227 #endif
static bool helpmode()
Definition: ivoc.h:66
pclose(FILE *p)
Definition: macprt.cpp:107
static Cursor * help_cursor_
Definition: ivoc.h:79
#define Cursor
Definition: _defines.h:85
char * hoc_current_xopen(void)
Definition: fileio.cpp:225
void nrnbbs_post_string(const char *, const char *)
Definition: ivocmac.cpp:38
bool nrnbbs_connected()
Definition: ivocmac.cpp:34
size_t p
static void help(const char *)
#define implementList(List, T)
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
bool nrnbbs_connect()
Definition: ivocmac.cpp:32
void ivoc_help(const char *)
Definition: ocnoiv1.cpp:16
bool nrnbbs_look(const char *)
Definition: ivocmac.cpp:44
static bool helpmode_
Definition: ivoc.h:77
_CONST char * s
Definition: system.cpp:74
FILE * popen(char *s1, char *s2)
Definition: macprt.cpp:102
#define printf
Definition: mwprefix.h:26
fprintf(stderr, "Don't know the location of params at %p\, pp)
static Cursor * help_cursor()
#define i
Definition: md1redef.h:12
void nrnbbs_exec(const char *)
Definition: ivocmac.cpp:46
#define declareList(List, T)
Definition: list.h:49
Definition: string.h:34
#define Window
Definition: _defines.h:333
char buf[512]
Definition: init.cpp:13
return NULL
Definition: cabcode.cpp:461