* unnecessary runs of idempotent commands
*
* watershed is Copyright 2007 Canonical Ltd
+ * written by Ian Jackson <ian@davenant.greenend.org.uk>
+ * 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,
* 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.
*
*/
/*
/*
*/
-#define _GNU_SOURCE
+#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <nettle/sha.h>
+#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 }
};
}while(0)
-static void badusage(void) {
+static void printusage(FILE *f) {
fputs(_("usage: watershed [<options>] <command>...\n"
- "options: -d|--state-dir <directory> -i|--command-id <id>\n"),
- stderr);
+ "options:\n"
+ " -d|--state-dir <directory>\n"
+ " -i|--command-id <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);
}
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();
}
}