X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fwatershed.c;h=f8fbc898727eca2ff5eb00b406444173b9e397c7;hp=d7926539e6f8d8c6c87523d62d6204b4b7ed2c2d;hb=a14cb06ac8fff27e407a39993b2b20f9a7109f7c;hpb=38f9191adf18ff7284a30b5672f0c90dd4e3bce7 diff --git a/cprogs/watershed.c b/cprogs/watershed.c index d792653..f8fbc89 100644 --- a/cprogs/watershed.c +++ b/cprogs/watershed.c @@ -3,11 +3,13 @@ * unnecessary runs of idempotent commands * * watershed is Copyright 2007 Canonical Ltd + * written by Ian Jackson + * and this version now maintained as part of chiark-utils * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -15,12 +17,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * See the file XXXXX for a full list of credits information (often - * installed as XXXXX. + * You should have received a copy of the GNU General Public + * License along with this file; if not, consult the Free Software + * Foundation's website at www.fsf.org, or the GNU Project website at + * www.gnu.org. * */ /* @@ -246,7 +246,7 @@ /* */ -#define _GNU_SOURCE +#include "common.h" #include #include @@ -267,9 +267,13 @@ #include +#define die common_die +#define diee common_diee + static const struct option os[]= { { "--state-dir", 1,0,'d' }, { "--command-id",1,0,'i' }, + { "--help", 0,0,'h' }, { 0 } }; @@ -294,17 +298,24 @@ static int cohort_fd, lock_fd; }while(0) -static void badusage(void) { +static void printusage(FILE *f) { fputs(_("usage: watershed [] ...\n" - "options: -d|--state-dir -i|--command-id \n"), - stderr); + "options:\n" + " -d|--state-dir \n" + " -i|--command-id \n" + " -h|--help\n" + "see /usr/share/doc/chiark-utils-bin/watershed.txt\n"), + f); +} +static void badusage(void) { + printusage(stderr); exit(127); } -static void die(const char *m) { +void die(const char *m) { fprintf(stderr,_("watershed: error: %s\n"), m); exit(127); } -static void diee(const char *m) { +void diee(const char *m) { fprintf(stderr,_("watershed: error: %s failed: %s\n"), m, strerror(errno)); exit(127); } @@ -314,26 +325,15 @@ static void dieep(const char *action, const char *path) { exit(127); } -static char *m_vasprintf(const char *fmt, va_list al) { - char *s; int r; - r= vasprintf(&s,fmt,al); - if (r==-1) diee("vasprintf"); - return s; -} -static char *m_asprintf(const char *fmt, ...) { - char *s; va_list al; - va_start(al,fmt); s= m_vasprintf(fmt,al); va_end(al); - return s; -} - static void parse_args(int argc, char *const *argv) { int o; for (;;) { - o= getopt_long(argc, argv, "+d:i:", os,0); + o= getopt_long(argc, argv, "+d:i:h", os,0); if (o==-1) break; switch (o) { case 'd': state_dir= optarg; break; case 'i': command_id= optarg; break; + case 'h': printusage(stdout); exit(0); break; default: badusage(); } }