From 0dd086495d977cf1d832398fcdc6497e708c60b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 20:56:04 +0100 Subject: [PATCH] delete all, set all --- opustags.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/opustags.c b/opustags.c index 62fd4e5..cb61ac0 100644 --- a/opustags.c +++ b/opustags.c @@ -160,9 +160,11 @@ int main(int argc, char **argv){ const char* to_add[argc]; const char* to_delete[argc]; int count_add = 0, count_delete = 0; + int delete_all = 0; + int set_all = 0; int overwrite = 0; int c; - while((c = getopt(argc, argv, "o:yd:a:s:")) != -1){ + while((c = getopt(argc, argv, "o:yd:a:s:DS")) != -1){ switch(c){ case 'o': path_out = optarg; @@ -187,6 +189,11 @@ int main(int argc, char **argv){ if(c == 's') to_delete[count_delete++] = optarg; break; + case 'S': + set_all = 1; + case 'D': + delete_all = 1; + break; default: return EXIT_FAILURE; } @@ -215,8 +222,15 @@ int main(int argc, char **argv){ } } FILE *in; - if(strcmp(path_in, "-") == 0) + if(strcmp(path_in, "-") == 0){ + if(set_all){ + fputs("can't open stdin for input when -S is specified\n", stderr); + if(out) + fclose(out); + return EXIT_FAILURE; + } in = stdin; + } else in = fopen(path_in, "r"); if(!in){ @@ -294,8 +308,50 @@ int main(int argc, char **argv){ error = "opustags: invalid comment header"; break; } - for(int i=0; i