9#include "tpcclibConfig.h"
20static char *info[] = {
21 "Deletes the items with specified key names from an Interfile-type file.",
22 "Notice that also all lines containing no key are deleted.",
24 "Usage: @P [Options] filename key(s)",
30 " @P iea345.hdr patient_name patient_id",
32 "See also: iftlist, iftadd, iftren, iftedit, iftisval, taclist, nii_lhdr",
34 "Keywords: header, IFT, tool",
53int main(
int argc,
char **argv)
55 int ai, help=0, version=0, verbose=1;
56 int ret, keyNr=0, fki=0;
57 char iftfile[FILENAME_MAX];
65 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
69 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
71 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
76 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
86 for(; ai<argc; ai++) {
87 if(!iftfile[0]) {strcpy(iftfile, argv[ai]);
continue;}
93 if(!iftfile[0] || keyNr<1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
97 printf(
"iftfile := %s\n", iftfile);
98 printf(
"keyNr := %d\n", keyNr);
105 if(verbose>1) printf(
"reading %s\n", iftfile);
106 fp=fopen(iftfile,
"r");
if(fp==NULL) {
107 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
110 ret=
iftRead(&ift, fp, 1, 1, &status); fclose(fp);
112 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
115 if(verbose>2) printf(
"list_size: %d item(s)\n", ift.
keyNr);
122 for(ai=fki; ai<argc; ai++) {
123 if(verbose>3) printf(
"key := '%s'\n", argv[ai]);
125 if(keyNr>1) fprintf(stderr,
"Warning: key '%s' was not found.\n", argv[ai]);
132 if(keyNr==1) fprintf(stderr,
"Error: key not found.\n");
133 else fprintf(stderr,
"Error: none of keys found.\n");
137 fprintf(stderr,
"Error: all items would be removed.\n");
145 if(verbose>1) printf(
"writing modified IFT in %s\n", iftfile);
146 fp=fopen(iftfile,
"w");
if(fp==NULL) {
147 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
150 ret=
iftWrite(&ift, fp, &status); fclose(fp);
void iftDeleteKey(IFT *ift, const char *key)
int iftFindNrOfKeys(IFT *ift, const char *key)
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)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
Header file for library libtpcextensions.
Header file for library libtpcift.