Revert "Speed up and simplify reading of standard input"

This reverts commit b812702115.
This commit is contained in:
Jacob 2023-07-29 04:40:02 +02:00
parent 1213017dc7
commit 0c949db21b

View file

@ -1,58 +1,65 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
void readstdin(void) { void readstdin(void) {
char *line = NULL; char buf[sizeof tx.text], *p;
size_t i, junk, size = 0; size_t i, itemsiz = 0;
ssize_t len; unsigned int tmpmax = 0;
#if USEIMAGE
int oneitem = 0;
#endif
if (passwd) { // -P: No items should be displayed if (passwd) {
sp.inputw = lines = 0; sp.inputw = lines = 0;
return; return;
} }
if (listfile) { // -lf: List file is used so no need to read stdin if (listfile) {
readfile(); readfile();
return; return;
} }
/* read each line from stdin and add it to the item list */ int o = 0;
for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) {
if (i + 1 >= size / sizeof *items)
if (!(items = realloc(items, (size += BUFSIZ))))
die("cannot realloc %zu bytes:", size);
if (line[len - 1] == '\n')
line[len - 1] = '\0';
items[i].text = line; // read each line from stdin and add it to the item list
items[i].index = i; for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
if (i + 1 >= itemsiz) {
itemsiz += 256;
if (!(items = realloc(items, itemsiz * sizeof(*items))))
die("spmenu: cannot realloc %zu bytes:", itemsiz * sizeof(*items));
}
if ((p = strchr(buf, '\n')))
*p = '\0';
if (!(items[i].text = strdup(buf)))
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);
draw_font_getexts(draw->font, buf, strlen(buf), &tmpmax, NULL, True);
if (parsemarkup(i)) { if (tmpmax > sp.inputw) {
#if USEIMAGE sp.inputw = tmpmax;
oneitem = 1;
#endif
} }
} items[i].index = i;
free(line);
if (items) { if (parsemarkup(i)) {
items[i].text = NULL; o = 1;
}
#if !USEIMAGE
if (o) {
;
}
#endif
}
#if USEIMAGE
if (!o) img.longestedge = img.imagegaps = 0;
#endif
// clean
if (items) {
items[i].text = NULL;
#if USEIMAGE #if USEIMAGE
items[i].image = NULL; items[i].image = NULL;
#endif #endif
} }
#if USEIMAGE lines = MIN(lines, i);
if (!oneitem) {
img.longestedge = img.imagegaps = 0;
}
#endif
lines = MIN(lines, i);
} }
void readfile(void) { void readfile(void) {
@ -193,7 +200,5 @@ int parsemarkup(int index) {
items[index].text += strlen("img://")+strlen(data)+1; items[index].text += strlen("img://")+strlen(data)+1;
} }
} }
return 0;
#endif #endif
} }