8#include "tpcclibConfig.h"
20static char *info[] = {
21 "List on screen the specified or all key names and values in",
22 "an Interfile-type (IFT) header file.",
24 "Usage: @P [options] filename [key1 [key2...]] [> outputfile]",
28 " List all values, also those with no key name",
30 " Print only the key value(s) without key name(s)",
34 " @P iea345.hdr patient_name",
36 "See also: iftadd, iftdel, iftisval, iftmatch, rmcmnts",
38 "Keywords: header, IFT, tool",
57int main(
int argc,
char **argv)
59 int ai, help=0, version=0, verbose=1;
60 int ret, is_key_required=1, print_value=0;
61 char *cptr, iftfile[FILENAME_MAX];
68 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
72 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
75 if(strncasecmp(cptr,
"ALL", 1)==0) {
76 is_key_required=0;
continue;
77 }
else if(strcasecmp(cptr,
"VALUE")==0) {
78 print_value=1;
continue;
80 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
85 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
90 printf(
"is_key_required := %d\n", is_key_required);
91 printf(
"print_value := %d\n", print_value);
100 for(; ai<argc; ai++) {
102 strlcpy(iftfile, argv[ai], FILENAME_MAX);
104 if(verbose>1) printf(
"reading %s\n", iftfile);
105 FILE *fp=fopen(iftfile,
"r");
if(fp==NULL) {
106 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
109 ret=
iftRead(&ift, fp, is_key_required, 1, &status); fclose(fp);
111 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
114 if(verbose>1) printf(
"list size: %d item(s)\n", ift.
keyNr);
116 key=
strdup(argv[ai]); m=0;
120 if(m<1) fprintf(stderr,
"Key \"%s\" was not found.\n", argv[ai]);
122 if(print_value==0)
iftWriteItem(&ift, li, stdout, NULL);
123 else fprintf(stdout,
"%s\n", ift.
item[li].
value);
139 if(verbose>0) printf(
"Parameters in %s :\n", iftfile);
140 if(print_value==0) ret=
iftWrite(&ift, stdout, NULL);
141 else for(li=0; li<ift.
keyNr; li++)
142 fprintf(stdout,
"%s\n", ift.
item[li].
value);
int iftSearchKey(IFT *ift, const char *s, int start_index)
int iftWriteItem(IFT *ift, int item, FILE *fp, TPCSTATUS *status)
int iftWrite(IFT *ift, FILE *fp, TPCSTATUS *status)
int iftRead(IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
char * strdup(const char *s)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for library libtpcextensions.
Header file for library libtpcift.