8#include "tpcclibConfig.h"
19static char *info[] = {
20 "Change the value of specified key in Interfile-type file or files that can",
21 "contain similar header data (such as TAC and parameter files).",
22 "Any additional lines with the same key name are removed.",
23 "If new value is not given, then previous key and value are deleted.",
24 "If key does not exist in the file, then the key with value are added.",
26 "Usage: @P [Options] filename key [value]",
32 " @P rabbit12.par studynr tg2r12",
34 "See also: iftlist, iftren, iftvalc, iftadd, iftdel, iftisval",
36 "Keywords: header, parameter, IFT, tool",
55int main(
int argc,
char **argv)
57 int ai, help=0, version=0, verbose=1;
59 char iftfile[FILENAME_MAX], keyname[FILENAME_MAX], keyvalue[FILENAME_MAX];
65 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
66 iftfile[0]=keyname[0]=keyvalue[0]=(char)0;
68 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);}
85 if(ai<argc)
strlcpy(iftfile, argv[ai++], FILENAME_MAX);
86 if(ai<argc)
strlcpy(keyname, argv[ai++], FILENAME_MAX);
87 if(ai<argc)
strlcpy(keyvalue, argv[ai++], FILENAME_MAX);
88 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
91 if(!keyname[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
95 for(ai=0; ai<argc; ai++) printf(
"%s ", argv[ai]);
96 printf(
"\n"); fflush(stdout);
97 printf(
"iftfile := %s\n", iftfile);
98 printf(
"keyname := %s\n", keyname);
99 printf(
"keyvalue := %s\n", keyvalue);
108 if(verbose>1) {printf(
"reading %s\n", iftfile); fflush(stdout);}
109 FILE *fp=fopen(iftfile,
"r");
if(fp==NULL) {
110 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
113 ret=
iftRead(&ift, fp, 0, 1, &status); fclose(fp);
118 if(verbose>2) {printf(
"list size: %d item(s)\n", ift.
keyNr); fflush(stdout);}
120 if(verbose>1) {printf(
"%d match(es) found.\n", foundNr); fflush(stdout);}
121 if(foundNr==0 && !keyvalue[0]) {
122 fprintf(stderr,
"Note: file contains no key '%s'\n", keyname);
126 if(verbose>0) {printf(
"deleting duplicate keys\n"); fflush(stdout);}
137 if(verbose>2) {printf(
"adding new key\n"); fflush(stdout);}
142 if(verbose>0) {printf(
"added new key with given value\n"); fflush(stdout);}
144 }
else if(keyvalue[0]) {
145 if(verbose>3) printf(
"key_index := %d\n", li);
146 if(verbose>0) printf(
"resetting value '%s' -> '%s'\n", ift.
item[li].
value, keyvalue);
151 if(verbose>0) {printf(
"added new key with given value\n"); fflush(stdout);}
153 if(verbose>3) printf(
"key_index := %d\n", li);
154 if(verbose>0) printf(
"removing '%s','%s'\n", ift.
item[li].
key, ift.
item[li].
value);
166 if(verbose>1) printf(
"writing modified IFT in %s\n", iftfile);
167 fp=fopen(iftfile,
"w");
if(fp==NULL) {
168 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
171 ret=
iftWrite(&ift, fp, &status); fclose(fp);
int iftReplaceValue(IFT *ift, int i, const char *value, TPCSTATUS *status)
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
int iftDeleteDuplicateKeys(IFT *ift, TPCSTATUS *status)
int iftDelete(IFT *ift, int index)
int iftFindNrOfKeys(IFT *ift, const char *key)
int iftFindKey(IFT *ift, const char *key, int start_index)
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)
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.