NEURON
mos2nrn.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdio.h>
3 #include <assert.h>
4 #include "../oc/nrnassrt.h"
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include "mos2nrn.h"
8 
9 static void getdname(char* dname);
10 
11 #include <string.h>
12 
13 const char* back2forward(const char*);
14 const char* basefile(const char*);
15 
16 int main(int argc, char** argv) {
17  char buf[256];
18  char dname[256];
19 
20  if (argc != 2 ) {
21  fprintf(stderr, "Usage: mos2nrn [hocfile | nrnzipfile]\n");
22  return 1;
23  }
24  FILE* f = fopen(argv[1], "r");
25  if (!f) {
26  return 1;
27  }
28  if (fread(buf, 1, 5, f) < 2) { return 1; }
29  fclose(f);
30  if (strncmp(buf, "PK", 2) == 0) { // its a nrnzip file
31  getdname(dname);
32 nrn_assert(snprintf(buf, 256, "xterm -sb -e %s/mos2nrn2.sh %s %s %d", NEURON_BIN_DIR,
33  argv[1], dname, 0) < 256);
34  int i = system(buf);
35  if (i) { return i; }
36  }else{ // its a hoc file
37  sprintf(buf, "xterm -sb -e %s/nrniv %s -",
38  NEURON_BIN_DIR, argv[1]);
39  int i = system(buf);
40  if (i) { return i; }
41  }
42  return 0;
43 }
44 
45 const char* back2forward(const char* back) {
46  static char forward[256];
47  char *cp;
48  strcpy(forward, back);
49  for (cp = forward; *cp; ++cp) {
50  if (*cp == '\\') {
51  *cp = '/';
52  }
53  }
54  return forward;
55 }
56 
57 const char* basefile(const char* path) {
58  const char* cp;
59  for (cp = path + strlen(path) - 1; cp >= path; --cp) {
60  if (*cp == '\\' || *cp == ':' || *cp == '/') {
61  return cp+1;
62  }
63  }
64  return path;
65 }
66 
67 static void getdname(char* dname) {
68  int fd;
69  const char* tdir;
70  if ((tdir = getenv("TEMP")) == NULL) {
71  tdir = "/tmp";
72  }
73  sprintf(dname, "%s/nrnXXXXXX", tdir);
74 #if HAVE_MKSTEMP
75  fd = mkstemp(dname);
76  close(fd);
77 #else
78  mktemp(dname);
79 #endif
80 }
#define nrn_assert(ex)
Definition: nrnassrt.h:35
const char * basefile(const char *)
Definition: mos2nrn.cpp:57
static void getdname(char *dname)
Definition: mos2nrn.cpp:67
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
int system(const char *s)
Definition: mswinprt.cpp:281
char * mktemp(char *)
Definition: ivocmac.cpp:27
char * getenv(const char *s)
Definition: macprt.cpp:67
fprintf(stderr, "Don't know the location of params at %p\, pp)
const char * back2forward(const char *)
Definition: mos2nrn.cpp:45
int main(int argc, char **argv)
Definition: mos2nrn.cpp:53
#define i
Definition: md1redef.h:12
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:53
int close(int)
FILE * fopen()
return NULL
Definition: cabcode.cpp:461
static char ** argv
Definition: inithoc.cpp:54