8#include "tpcclibConfig.h"
20static char *info[] = {
21 "Execute shell command based on the contents of given IFT file.",
22 "IFT file may or may not contain key names; any key names are ignored.",
23 "First line must contain the program/command name.",
24 "Comment lines are ignored.",
26 "Usage: @P [options] filename",
30 " Just print the command line in stdout.",
36 "Program uses system() function; its return value is not standardized,",
37 "therefore do not trust the return value of this function either.",
39 "See also: iftadd, iftdel, iftisval, iftvalc",
41 "Keywords: header, IFT, tool",
60int main(
int argc,
char **argv)
62 int ai, help=0, version=0, verbose=1;
64 char *cptr, iftfile[FILENAME_MAX];
71 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
74 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
76 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
77 if(strcasecmp(cptr,
"DRY")==0) {
80 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
89 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
94 if(ai<argc)
strlcpy(iftfile, argv[ai++], FILENAME_MAX);
96 fprintf(stderr,
"Error: too many arguments.\n");
102 fprintf(stderr,
"Error: missing command parameter file; use option --help\n");
108 printf(
"iftfile := %s\n", iftfile);
109 printf(
"dryrun := %d\n", dryrun);
113 if(dryrun==0 && system(NULL)==0) {
114 fprintf(stderr,
"Error: no command processor available.\n");
122 if(verbose>1) printf(
"reading %s\n", iftfile);
125 FILE *fp=fopen(iftfile,
"r");
if(fp==NULL) {
126 fprintf(stderr,
"Error: cannot open file %s\n", iftfile);
129 ret=
iftRead(&ift, fp, 0, 0, &status); fclose(fp);
131 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
134 if(verbose>2) printf(
"list size: %d item(s)\n", ift.
keyNr);
138 for(i=0; i<ift.
keyNr; i++) {
143 fprintf(stderr,
"Error: invalid file contents.\n");
149 char cmdline[len+1]; cmdline[0]=(char)0;
150 for(i=0; i<ift.
keyNr; i++) {
151 if(i>0) strcat(cmdline,
" ");
159 fprintf(stdout,
"%s\n", cmdline);
167 fprintf(stdout,
"command := %s\n", cmdline);
174 if(ret!=0 || verbose>2) printf(
" %d returned.\n", ret);
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.