Debian Codegraph @

seagen/hitConverter.C

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "aHit.H"
4
5 void
6 bin2asc(FILE *I, FILE *O) {
7 uint32 i = 0;
8 aHit a;
9
10 fprintf(stderr, "Converting BINARY to ASCII.\n");
11
12 while (!feof(I)) {
13 ahit_readBinary(&a, I);
14
15 if (!feof(I)) {
16 ahit_printASCII(&a, O);
17
18 if ((++i & 0xffff) == 0) {
19 fprintf(stderr, uint32FMT" hits.\r", i);
20 fflush(stderr);
21 }
22 }
23 }
24
25 fprintf(stderr, uint32FMT" hits.\r", i);
26 fprintf(stderr, "\n");
27 }
28
29
30 void
31 asc2bin(FILE *I, FILE *O) {
32 uint32 i = 0;
33 aHit a;
34 char b[1025];
35
36 fprintf(stderr, "Converting ASCII to BINARY.\n");
37
38 while (!feof(I)) {
39 fgets(b, 1024, I);
40
41 if (!feof(I)) {
42 ahit_parseString(&a, b);
43 ahit_writeBinary(&a, O);
44
45 if ((++i & 0xffff) == 0) {
46 fprintf(stderr, uint32FMT" hits.\r", i);
47 fflush(stderr);
48 }
49 }
50 }
51
52 fprintf(stderr, uint32FMT" hits.\r", i);
53 fprintf(stderr, "\n");
54 }
55
56
57 int
58 main(int argc, char **argv) {
59
60 if (argc != 1) {
61 fprintf(stderr, "%s: I only read stdin and write stdout.\n", argv[0]);
62 exit(1);
63 }
64
65 // If the first character in the stream is ascii, do ASCII -> BINARY.
66 // Else, do BINARY -> ASCII.
67 //
68 char x = (char)fgetc(stdin);
69 ungetc(x, stdin);
70
71 if (x == '-')
72 asc2bin(stdin, stdout);
73 else
74 bin2asc(stdin, stdout);
75
76 return(0);
77 }