TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
ecat
lmhdr.c
Go to the documentation of this file.
1
7
/*****************************************************************************/
8
#include "tpcclibConfig.h"
9
/*****************************************************************************/
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <math.h>
13
#include <string.h>
14
#include <unistd.h>
15
#include <time.h>
16
/*****************************************************************************/
17
#include "
libtpcmisc.h
"
18
#include "
libtpcimgio.h
"
19
/*****************************************************************************/
20
21
/*****************************************************************************/
22
static
char
*info[] = {
23
"List the information in the main header of an ECAT 6 or 7 file."
,
24
" "
,
25
"Usage: @P [Options] ecatfile"
,
26
" "
,
27
"Options:"
,
28
" -stdoptions"
,
// List standard options like --help, -v, etc
29
" "
,
30
"Example:"
,
31
" @P s2345dy1.img "
,
32
" "
,
33
"See also: lshdr, lmlist, egetstrt, imgunit, e7emhdr, e63emhdr"
,
34
" "
,
35
"Keywords: ECAT, header"
,
36
0};
37
/*****************************************************************************/
38
39
/*****************************************************************************/
40
/* Turn on the globbing of the command line, since it is disabled by default in
41
mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
42
In Unix&Linux wildcard command line processing is enabled by default. */
43
/*
44
#undef _CRT_glob
45
#define _CRT_glob -1
46
*/
47
int
_dowildcard = -1;
48
/*****************************************************************************/
49
50
/*****************************************************************************/
54
int
main(
int
argc,
char
**argv)
55
{
56
int
ai, help=0, version=0, verbose=1;
57
int
ret;
58
char
*cptr, ecatfile[FILENAME_MAX];
59
FILE *fp;
60
ECAT63_mainheader
e6_mainheader;
61
ECAT7_mainheader
e7_mainheader;
62
int
ecat_format=0;
// 6 or 7
63
64
65
/*
66
* Get arguments
67
*/
68
if
(argc==1) {
tpcPrintUsage
(argv[0], info, stderr);
return
(1);}
69
ecatfile[0]=(char)0;
70
/* Options */
71
for
(ai=1; ai<argc; ai++)
if
(*argv[ai]==
'-'
) {
/* options */
72
cptr=argv[ai]+1;
if
(*cptr==
'-'
) cptr++;
if
(cptr==NULL)
continue
;
73
if
(
tpcProcessStdOptions
(argv[ai], &help, &version, &verbose)==0)
continue
;
74
fprintf(stderr,
"Error: invalid option %s\n"
, argv[ai]);
75
return
(1);
76
}
else
break
;
77
78
/* Print help or version? */
79
if
(help==2) {
tpcHtmlUsage
(argv[0], info,
""
);
return
(0);}
80
if
(help) {
tpcPrintUsage
(argv[0], info, stdout);
return
(0);}
81
if
(version) {
tpcPrintBuild
(argv[0], stdout);
return
(0);}
82
83
/* Process other arguments, starting from the first non-option */
84
for
(; ai<argc; ai++) {
85
if
(!ecatfile[0]) {
86
strcpy(ecatfile, argv[ai]);
continue
;
87
}
88
fprintf(stderr,
"Error: invalid argument '%s'\n"
, argv[ai]);
89
return
(1);
90
}
91
92
/* Is something missing? */
93
if
(!ecatfile[0]) {
94
fprintf(stderr,
"Error: missing command-line argument; try %s --help\n"
,
95
argv[0]);
96
return
(1);
97
}
98
99
100
/* In verbose mode print arguments and options */
101
if
(verbose>1) {
102
printf(
"ecatfile := %s\n"
, ecatfile);
103
}
104
105
106
/*
107
* Open ECAT file
108
*/
109
if
((fp=fopen(ecatfile,
"rb"
)) == NULL) {
110
fprintf(stderr,
"Error: cannot read file %s\n"
, ecatfile);
111
return
(2);
112
}
113
114
/*
115
* Read main header
116
*/
117
ecat_format=0;
118
/* Try to read ECAT 7.x main header */
119
if
(verbose>2) printf(
"trying to read ecat mainheader\n"
);
120
ret=
ecat7ReadMainheader
(fp, &e7_mainheader);
121
if
(ret) {
122
fprintf(stderr,
"Error: unsupported file format (%s)\n"
, ecatfile);
123
fclose(fp);
return
(3);
124
}
125
/* If header could be read, check for magic number */
126
if
(verbose>2) printf(
"checking ecat mainheader for ECAT7 magic number\n"
);
127
if
(strncmp(e7_mainheader.
magic_number
, ECAT7V_MAGICNR, 7)==0) {
128
if
(verbose>2) printf(
"ECAT7 magic number found\n"
);
129
ecat_format=7;
130
}
else
{
// maybe this is ECAT 6.3
131
if
(verbose>2) printf(
"ECAT7 magic number not found\n"
);
132
if
(verbose>2)
ECAT63_TEST
=verbose-2;
else
ECAT63_TEST
=0;
133
ret=
ecat63ReadMainheader
(fp, &e6_mainheader);
134
if
(ret==0) ecat_format=6;
135
}
136
if
(ecat_format==0) {
137
fprintf(stderr,
"Error: unsupported file format (%s)\n"
, ecatfile);
138
fclose(fp);
return
(3);
139
}
140
if
(verbose>1) printf(
"ecat_format := %d\n"
, ecat_format);
141
142
/*
143
* Close ECAT file
144
*/
145
fclose(fp);
146
147
/*
148
* Print main header
149
*/
150
if
(ecat_format==6)
151
ecat63PrintMainheader
(&e6_mainheader, stdout);
152
else
153
ecat7PrintMainheader
(&e7_mainheader, stdout);
154
printf(
"\n"
);
155
156
return
(0);
157
}
158
/*****************************************************************************/
159
160
/*****************************************************************************/
ECAT63_TEST
int ECAT63_TEST
Definition
ecat63h.c:6
ecat63PrintMainheader
void ecat63PrintMainheader(ECAT63_mainheader *h, FILE *fp)
Definition
ecat63p.c:16
ecat63ReadMainheader
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
Definition
ecat63r.c:25
ecat7PrintMainheader
void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp)
Definition
ecat7p.c:16
ecat7ReadMainheader
int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h)
Definition
ecat7r.c:15
libtpcimgio.h
Header file for libtpcimgio.
libtpcmisc.h
Header file for libtpcmisc.
tpcProcessStdOptions
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition
proginfo.c:40
tpcHtmlUsage
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition
proginfo.c:213
tpcPrintBuild
void tpcPrintBuild(const char *program, FILE *fp)
Definition
proginfo.c:383
tpcPrintUsage
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition
proginfo.c:158
ECAT63_mainheader
Definition
libtpcimgio.h:1002
ECAT7_mainheader
Definition
libtpcimgio.h:300
ECAT7_mainheader::magic_number
char magic_number[14]
Definition
libtpcimgio.h:302
Generated on
for TPCCLIB by
1.17.0