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(MINGW)
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(
103  "error on the help pipe, restarting\n\
104 but will be missing this sessions hoc help text\n");
105  pclose(help_pipe);
106  help_pipe = NULL;
107  }
108  if (!help_pipe) {
109  printf("Starting the help system\n");
110  char buf[200];
111  sprintf(buf, "%s/ochelp", "$NEURONHOME/bin/$CPU");
112  if ((help_pipe = popen(buf, "w")) == (FILE*) 0) {
113  printf("Could not start %s\n", buf);
114  }
115  // printf("help_pipe = %p\n", help_pipe);
116  readmore();
117  if (filequeue) {
118  for (long i = 0; i < filequeue->count(); ++i) {
119  fprintf(help_pipe, "%s\n", filequeue->item_ref(i).string());
120  }
121  filequeue->remove_all();
122  }
123  }
124  if (help_pipe) {
125  // printf("|%s|\n", s);
126  if (strncmp(s, "?0", 2) == 0) {
127  char buf[1024];
128  sprintf(buf, "?0 %s", hoc_current_xopen());
129  fprintf(help_pipe, "%s\n", buf);
130  } else {
131  fprintf(help_pipe, "%s\n", s);
132  }
133  fflush(help_pipe);
134  }
135 #endif
136 }
137 #endif
138 
139 #if defined(WIN32) || defined(MAC)
140 
141 void Oc::help(const char* s) {
142 #if 0
143 #ifndef MINGW
144  static bool ran_ochelp = false;
145  char buf[1024];
146  nrnbbs_connect(); // benign if already connected
147  if (!nrnbbs_connected()) {
148  printf("Could not connect to nrnbbs service\n");
149  return;
150  }
151  if (!ran_ochelp && !nrnbbs_look("ochelp running")) {
152  ran_ochelp = true;
153  printf("Starting the help system\n");
154  nrnbbs_exec("ochelp");
155  }else if (!nrnbbs_look("ochelp running")) {
156  printf("proper ochelp version not running\n");
157  return;
158  }
159 
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 
169  if (strncmp(s, "?0", 2) == 0) {
170  sprintf(buf, "?0 %s", hoc_current_xopen());
171  nrnbbs_post_string("ochelp", buf);
172  }else{
173  nrnbbs_post_string("ochelp", s);
174  }
175 #endif // MINGW
176 #endif
177 }
178 #endif // WIN32 or MAC
179 
180 void Oc::helpmode(bool b) {
181  helpmode_ = b;
182 }
183 
184 void Oc::helpmode(Window* w) {
185  if (helpmode()) {
186  if (w->cursor() != Oc::help_cursor()) {
187  w->push_cursor();
188  w->cursor(Oc::help_cursor());
189  }
190  } else {
191  if (w->cursor() == Oc::help_cursor()) {
192  w->pop_cursor();
193  }
194  }
195 }
196 
197 static const CursorPattern question_pat = {0x0000,
198  0x0000,
199  0x0000,
200  0x7c00,
201  0xce00,
202  0x0600,
203  0x0600,
204  0x0c00,
205  0x3000,
206  0x6000,
207  0x6000,
208  0x6000,
209  0x0000,
210  0x0000,
211  0x6000,
212  0x6000};
213 
214 static const CursorPattern question_mask = {
215 // 0x0000, 0x0000, 0x7c00, 0xfe00, 0xff00, 0xcf00, 0x0f00, 0x3e00,
216 // 0x7c00, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000, 0xf000
217 #if !defined(UNIX) && (defined(WIN32) || defined(MAC))
218  0xffff,
219  0xffff,
220  0xffff,
221  0xffff,
222  0xffff,
223  0xffff,
224  0xffff,
225  0xffff,
226  0xffff,
227  0xffff,
228  0xffff,
229  0xffff,
230  0xffff,
231  0xffff,
232  0xffff,
233  0xffff
234 #else
235  0xfe00,
236  0xfe00,
237  0xfe00,
238  0xfe00,
239  0xfe00,
240  0xfe00,
241  0xfe00,
242  0xfe00,
243  0xfe00,
244  0xfe00,
245  0xfe00,
246  0xfe00,
247  0xfe00,
248  0xfe00,
249  0xfe00,
250  0xfe00
251 #endif
252 };
253 
254 
256 
258  if (!Oc::help_cursor_) {
259  help_cursor_ = new Cursor(4, 7, question_pat, question_mask);
260  }
261  return help_cursor_;
262 }
263 
264 
265 #endif
#define Window
Definition: _defines.h:333
#define Cursor
Definition: _defines.h:85
static Cursor * help_cursor_
Definition: ivoc.h:86
static void help(const char *)
static Cursor * help_cursor()
static bool helpmode_
Definition: ivoc.h:84
static bool helpmode()
Definition: ivoc.h:70
Definition: string.h:34
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
char * hoc_current_xopen(void)
Definition: fileio.cpp:203
char buf[512]
Definition: init.cpp:13
void ivoc_help(const char *)
Definition: ocnoiv1.cpp:16
void nrnbbs_exec(const char *)
Definition: ivocmac.cpp:58
bool nrnbbs_connect()
Definition: ivocmac.cpp:32
bool nrnbbs_look(const char *)
Definition: ivocmac.cpp:54
void nrnbbs_post_string(const char *, const char *)
Definition: ivocmac.cpp:42
bool nrnbbs_connected()
Definition: ivocmac.cpp:36
#define declareList(List, T)
Definition: list.h:49
implementList(__AnyPtrList, __AnyPtr) static long ListImpl_best_new_sizes[]
pclose(FILE *p)
Definition: macprt.cpp:107
FILE * popen(char *s1, char *s2)
Definition: macprt.cpp:102
#define i
Definition: md1redef.h:12
#define printf
Definition: mwprefix.h:26
#define fprintf
Definition: mwprefix.h:30
size_t p
#define NULL
Definition: sptree.h:16