commit - 32ea74e2ed9b7178b183299dade65b7493495255
commit + 50610c96588883a7037ffb872e2d79c246fe0c72
blob - f80695ee1e75992165b4c87574f2af17fd330eb4
blob + 86db2cebe36322c9345d67a423ec7af0372576a0
--- Makefile
+++ Makefile
install -m 755 $(BIN) $(bindir)
mkdir -p $(mandir)
install -m 644 $(MAN) $(mandir)
- mkdir -p $(gpassdir)
- install -m 644 eff.long $(gpassdir)
+ install -m 644 eff.long $(sharedir)/gpass.dic
+ rm -rf $(gpassdir) # clean up legacy files
uninstall:
cd $(bindir) && rm -f $(BIN)
cd $(mandir) && rm -f $(MAN)
- rm -rf $(gpassdir)
+ rm -rf $(gpassdir) # clean up legacy files
clean:
-rm -f $(BIN) $(OBJ) $(MAN) *.tar.gz *.core gpass-$(V)
blob - e86176bf90c6547cc9cb6f6cb8b9d5c41f414bd8
blob + 76cfad5016864a79420ac399817332e95b13b814
--- gpass.c
+++ gpass.c
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#define NNUM ('9'-'0' + 1)
#define NALPHA ('z'-'a' + 1)
-#ifndef PREFIX
-# define PREFIX "/usr/local"
-#endif
-
int aflag = 0;
static int
fclose(fp);
}
+static char *
+getdicname(int *allocated)
+{
+ char *xdg, *home, *path;
+
+ if ((path = getenv("GPASS_DIC")) != NULL && *path != '\0') {
+ *allocated = 0;
+ return path;
+ }
+
+ if (((xdg = getenv("XDG_DATA_HOME")) != NULL && *xdg != '\0') ||
+ ((home = getenv("HOME")) != NULL && *home != '\0')) {
+ size_t sz;
+ char *pre, *suf;
+
+ if (xdg != NULL) {
+ pre = xdg;
+ suf = "/gpass.dic";
+ } else {
+ pre = home;
+ suf = "/.gpass.dic";
+ }
+
+ sz = strlen(pre) + strlen(suf) + 1;
+ if ((path = malloc(sz)) == NULL)
+ err(1, "malloc");
+ strlcpy(path, pre, sz);
+ strlcat(path, suf, sz);
+
+ if (access(path, F_OK) == 0) {
+ *allocated = 1;
+ return path;
+ } else {
+ free(path);
+ path = NULL;
+ }
+ }
+
+ if (access("/usr/share/gpass.dic", F_OK) == 0) {
+ *allocated = 0;
+ return "/usr/share/gpass.dic";
+ }
+ if (access("/usr/local/share/gpass.dic", F_OK) == 0) {
+ *allocated = 0;
+ return "/usr/local/share/gpass.dic";
+ }
+
+ *allocated = 0;
+ return NULL;
+}
+
int
main(int argc, char *argv[])
{
if (aflag)
gpass_alpha(npass, plen, ent);
else {
- if (!dicname && !(dicname = getenv("GPASS_DIC")))
- dicname = PREFIX "/share/gpass/eff.long";
+ int allocated = 0;
+ if (dicname == NULL &&
+ (dicname = getdicname(&allocated)) == NULL)
+ errx(1, "couldn't find dictionary file");
gpass_words(npass, plen, ent, dicname);
+ if (allocated)
+ free(dicname);
}
return 0;