prefix die() calls with spmenu:

This commit is contained in:
speedie 2023-04-21 11:56:45 +02:00
parent c7b3e99892
commit 7c301a0bd4
4 changed files with 14 additions and 12 deletions

View file

@ -362,20 +362,20 @@ savehistory(char *input)
fp = fopen(histfile, "w"); fp = fopen(histfile, "w");
if (!fp) { if (!fp) {
die("failed to open %s", histfile); die("spmenu: failed to open %s", histfile);
} }
for (i = histsz < maxhist ? 0 : histsz - maxhist; i < histsz; i++) { for (i = histsz < maxhist ? 0 : histsz - maxhist; i < histsz; i++) {
if (0 >= fprintf(fp, "%s\n", history[i])) { if (0 >= fprintf(fp, "%s\n", history[i])) {
die("failed to write to %s", histfile); die("spmenu: failed to write to %s", histfile);
} }
} }
if (histsz == 0 || histdup || (histsz > 0 && strcmp(input, history[histsz-1]) != 0)) { if (histsz == 0 || histdup || (histsz > 0 && strcmp(input, history[histsz-1]) != 0)) {
if (0 >= fputs(input, fp)) { if (0 >= fputs(input, fp)) {
die("failed to write to %s", histfile); die("spmenu: failed to write to %s", histfile);
} }
} }
if (fclose(fp)) { if (fclose(fp)) {
die("failed to close file %s", histfile); die("spmenu: failed to close file %s", histfile);
} }
out: out:

View file

@ -48,7 +48,7 @@ fuzzymatch(void)
if (number_of_matches) { if (number_of_matches) {
// initialize array with matches // initialize array with matches
if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*))))
die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*)); die("spmenu: cannot realloc %u bytes:", number_of_matches * sizeof(struct item*));
for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) { for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) {
fuzzymatches[i] = it; fuzzymatches[i] = it;
} }
@ -103,7 +103,7 @@ match(void)
// separate input text into tokens to be matched individually // separate input text into tokens to be matched individually
for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " "))
if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))
die("cannot realloc %u bytes:", tokn * sizeof *tokv); die("spmenu: cannot realloc %u bytes:", tokn * sizeof *tokv);
len = tokc ? strlen(tokv[0]) : 0; len = tokc ? strlen(tokv[0]) : 0;
matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL; matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL;

View file

@ -8,10 +8,10 @@ tokenize(char *source, const char *delim, int *llen)
while (token) { while (token) {
if (listlength + 1 >= list_size) { if (listlength + 1 >= list_size) {
if (!(list = realloc(list, (list_size += 8) * sizeof(*list)))) if (!(list = realloc(list, (list_size += 8) * sizeof(*list))))
die("Unable to realloc %zu bytes\n", list_size * sizeof(*list)); die("spmenu: unable to realloc %zu bytes\n", list_size * sizeof(*list));
} }
if (!(list[listlength] = strdup(token))) if (!(list[listlength] = strdup(token)))
die("Unable to strdup %zu bytes\n", strlen(token) + 1); die("spmenu: unable to strdup %zu bytes\n", strlen(token) + 1);
token = strtok(NULL, delim); token = strtok(NULL, delim);
listlength++; listlength++;
} }

View file

@ -19,12 +19,12 @@ readstdin(void)
if (i + 1 >= itemsiz) { if (i + 1 >= itemsiz) {
itemsiz += 256; itemsiz += 256;
if (!(items = realloc(items, itemsiz * sizeof(*items)))) if (!(items = realloc(items, itemsiz * sizeof(*items))))
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items)); die("spmenu: cannot realloc %zu bytes:", itemsiz * sizeof(*items));
} }
if ((p = strchr(buf, '\n'))) if ((p = strchr(buf, '\n')))
*p = '\0'; *p = '\0';
if (!(items[i].text = strdup(buf))) if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1); die("spmenu: cannot strdup %u bytes:", strlen(buf) + 1);
items[i].hp = arrayhas(hpitems, hplength, items[i].text); items[i].hp = arrayhas(hpitems, hplength, items[i].text);
drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True); drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True);
if (tmpmax > inputw) { if (tmpmax > inputw) {
@ -80,12 +80,14 @@ readstdin(void)
// spmenu:version // spmenu:version
if (!strncmp("version", items[i].ex, strlen("version"))) { if (!strncmp("version", items[i].ex, strlen("version"))) {
die("spmenu version %s", VERSION); fprintf(stdout, "spmenu version %s", VERSION);
exit(0);
} }
// spmenu:license // spmenu:license
if (!strncmp("license", items[i].ex, strlen("license"))) { if (!strncmp("license", items[i].ex, strlen("license"))) {
die("spmenu is licensed under the MIT license. See the included LICENSE file for more information."); fprintf(stdout, "spmenu is licensed under the MIT license. See the included LICENSE file for more information.");
exit(0);
} }
// spmenu:test // spmenu:test