nt

Unnamed repository; edit this file 'description' to name the repository.
git clone git://edryd.org/nt
Log | Files | Refs | LICENSE

commit 4e9704a205e91fd61703e22d0ea7db495b651290
parent 0f47a300791df3ec514f0538d3338df45d8ce24e
Author: Ed van Bruggen <edvb54@gmail.com>
Date:   Sat, 12 Aug 2017 23:46:47 -0700

Require note for -f and -e, fix util dies

Diffstat:
arg.h | 2+-
nt.c | 13++++++-------
util.c | 8++++----
util.h | 2+-
4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/arg.h b/arg.h @@ -9,7 +9,7 @@ extern char *argv0; /* use main(int argc, char *argv[]) */ -#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ +#define ARGBEGIN for (argv0 = basename(*argv), argv++, argc--;\ argv[0] && argv[0][0] == '-'\ && argv[0][1];\ argc--, argv++) {\ diff --git a/nt.c b/nt.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <libgen.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -284,8 +285,8 @@ cleanup(void) void usage(void) { - die("usage: %s [-Dilvy] [-f FILE] [-e NOTE] [-d NOTE]\n" - " [-s SEARCH] [-c [CATEGORY]] [-n NUM | -NUM] [NOTE ...]", argv0); + die("usage: %s [-Dilyv] [-f FILE] [-e NOTE] [-d NOTE]\n" + " [-s SEARCH] [-c [CATEGORY]] [-n NUM | -NUM] [NOTE ...]", argv0); } int @@ -301,11 +302,9 @@ main(int argc, char *argv[]) break; case 'e': mode = nt_edit; - neednt = 0; break; case 'f': fname = EARGF(usage()); - neednt = 0; break; case 'i': yes = 0; @@ -331,12 +330,12 @@ main(int argc, char *argv[]) mode = nt_cat; neednt = 0; break; - case 'v': - printf("%s v%s (c) 2017 Ed van Bruggen\n", argv0, VERSION); - return 0; case 'y': yes = 1; break; + case 'v': + printf("%s v%s (c) 2017 Ed van Bruggen\n", argv0, VERSION); + return 0; default: usage(); } ARGEND; diff --git a/util.c b/util.c @@ -13,7 +13,7 @@ ecalloc(size_t nmemb, size_t size) void *p; if (!(p = calloc(nmemb, size))) - die("calloc: out of memory"); + die("calloc:"); return p; } @@ -24,7 +24,7 @@ emalloc(size_t size) void *p; if (!(p = malloc(size))) - die("malloc: out of memory"); + die("malloc:"); return p; } @@ -33,7 +33,7 @@ void * erealloc(void *p, size_t size) { if (!(p = realloc(p, size))) - die("realloc: out of memory"); + die("realloc:"); return p; } @@ -42,7 +42,7 @@ char * estrdup(char *s) { if (!(s = strdup(s))) - die("strdup: out of memory"); + die("strdup:"); return s; } diff --git a/util.h b/util.h @@ -10,4 +10,4 @@ void *emalloc(size_t size); void *erealloc(void *p, size_t size); char *estrdup(char *s); -void die(const char *errstr, ...); +void die(const char *fmt, ...);