NEURON
nrnbinstr.cpp
Go to the documentation of this file.
1
// prints the first "x:.../activate.bat" in the first 10000 bytes of
2
// the binary file (second arg). Characters may or may not be 16 bit
3
// integers (ignore '\0')
4
// (return 0 if found, 1 if not found or error)
5
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <ctype.h>
10
11
int
main
(
int
argc
,
const
char
**
argv
) {
12
if
(
argc
!= 3) {
13
fprintf(stderr,
"Usage: nrnbinstr \"pattern\" \"binaryfile\"\n"
);
14
return
1;
15
}
16
const
char
* pat =
argv
[1];
17
const
char
* fname =
argv
[2];
18
19
FILE* f = fopen(fname,
"rb"
);
20
if
(!f) {
21
fprintf(stderr,
"Could not open %s\n"
, fname);
22
return
1;
23
}
24
25
char
*
buf
=
new
char
[10000];
26
int
size = fread(
buf
,
sizeof
(
char
), 10000, f);
27
fclose(f);
28
29
int
c
;
30
char
*
result
=
new
char
[10000];
31
int
lenpat = strlen(pat);
32
int
ifirst = 0, ipat = 0, iresult = 0;
33
int
icolon = 0;
34
for
(
int
i
= 0;
i
< size - 1; ++
i
) {
35
c
=
buf
[
i
];
36
if
(
c
== 0 &&
buf
[
i
+ 1] != 0) {
37
continue
;
38
}
// ignore single '\0'
39
if
(isprint(
c
)) {
40
if
(
c
==
':'
&& iresult > 0) {
41
icolon = iresult - 1;
// must be single character drive letter
42
}
43
result
[iresult++] =
c
;
44
if
(
c
== pat[ipat]) {
45
ipat++;
46
if
(ipat == lenpat) {
47
result
[iresult] =
'\0'
;
48
printf
(
"%s\n"
,
result
+ icolon);
49
return
0;
50
}
51
}
else
if
(ipat > 0) {
52
ipat = 0;
53
}
54
}
else
{
55
icolon = 0;
56
iresult = 0;
57
ipat = 0;
58
ifirst =
i
+ 1;
59
}
60
}
61
return
1;
62
}
i
#define i
Definition:
md1redef.h:19
buf
char buf[512]
Definition:
init.cpp:13
c
static int c
Definition:
hoc.cpp:169
argc
static int argc
Definition:
inithoc.cpp:45
argv
static char ** argv
Definition:
inithoc.cpp:46
printf
printf
Definition:
extdef.h:5
main
int main(int argc, const char **argv)
Definition:
nrnbinstr.cpp:11
result
result
Definition:
nrngsl_hc_radix2.cpp:61
src
mswin
extra
nrnbinstr.cpp