9#include "tpcclibConfig.h"
22static char *info[] = {
23 "Delete specified TAC(s) inside a TAC file.",
25 "Usage: @P [options] file [tacname(s) or tacnumber(s)]",
29 " Nothing is actually deleted, application only lists which TAC(s) would",
33 "Example 1: Delete TACs with name 'striatum' from file a123_12.dat",
34 " @P a123_06.dat striatum",
36 "Example 2: Delete TAC numbers 3 and 4 from file a234.dat",
39 "See also: taclist, tacadd, tacdelna, tacsort, tacunit, taccut, tacsplit",
41 "Keywords: TAC, tool",
60int main(
int argc,
char **argv)
62 int ai, help=0, version=0, verbose=1;
63 int ret, i, n, dryMode=0;
64 char *cptr, tacfile[FILENAME_MAX];
71 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
75 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
77 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
78 if(strcasecmp(cptr,
"DRY")==0) {
81 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
90 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
96 strlcpy(tacfile, argv[ai], FILENAME_MAX); ai++;
98 fprintf(stderr,
"Error: missing filename.\n");
102 fprintf(stderr,
"Error: missing TAC name or number.\n");
108 printf(
"tacfile := %s\n", tacfile);
109 printf(
"dryMode := %d\n", dryMode);
113 if(verbose>1) printf(
"reading %s\n", tacfile);
114 ret=
tacRead(&tac, tacfile, &status);
116 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
121 printf(
"tacNr := %d\n", tac.
tacNr);
122 printf(
"sampleNr := %d\n", tac.
sampleNr);
126 for(; ai<argc; ai++) {
128 if(n<=0 && verbose>0)
129 fprintf(stderr,
"Warning: no match found for '%s'.\n", argv[ai]);
131 printf(
"%d tac(s) match name '%s'\n", n, argv[ai]);
135 fprintf(stderr,
"Error: specified TACs not found in %s.\n", tacfile);
138 if(verbose>1) printf(
"%d matching tac(s) found\n", n);
140 fprintf(stderr,
"Warning: all TACs were selected for removal; aborted.\n");
151 printf(
"marked for deletion: %s\n", tac.
c[i].
name); n++;
153 if(verbose>=0) printf(
"%s deleted\n", tac.
c[i].
name);
160 fprintf(stderr,
"Error: cannot delete TAC.\n");
164 printf(
"%d TAC(s) were marked to be deleted.\n", n);
171 if(verbose>1) printf(
"writing %s\n", tacfile);
172 FILE *fp; fp=fopen(tacfile,
"w");
174 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", tacfile);
180 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
184 if(verbose>=0) printf(
"%d TAC(s) are deleted.\n", n);
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)
char name[MAX_TACNAME_LEN+1]
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
int tacWrite(TAC *tac, FILE *fp, tacformat format, int extra, TPCSTATUS *status)
int tacDeleteTACC(TAC *d, int i)
int tacSelectedTACs(TAC *d)
int tacSelectTACs(TAC *d, const char *region_name, int reset, TPCSTATUS *status)
Header file for library libtpcextensions.
Header file for library libtpcift.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.