commit - 36a15a9f3da905e359588b809b80a25122991586
commit + 95b27a5ee0eabd352594b209c4eec1399118515f
blob - a4b83d01291ed0299ed8e3fcdfe2ae2ba72cf8a0
blob + 5aa3ff080c67844d0b1d24a90910c499a92ef88b
--- mymenu.c
+++ mymenu.c
}
// TODO: dynamic?
-#define MAX_ITEMS 256
+#define INITIAL_ITEMS 64
#define TODO(s) { \
fprintf(stderr, "TODO! " s "\n"); \
return str;
}
-int readlines (char **lines) {
+int readlines (char ***lns, int items) {
bool finished = false;
int n = 0;
- while (n < MAX_ITEMS) {
+ char **lines = *lns;
+ while (true) {
lines[n] = readline(&finished);
if (strlen(lines[n]) == 0 || lines[n][0] == '\n')
break;
++n;
+
+ if (n == items - 1) {
+ items += items >>1;
+ char **l = realloc(lines, sizeof(char*) * items);
+ check_allocation(l);
+ *lns = l;
+ lines = l;
+ }
}
- /* for (n = 0; n < MAX_ITEMS -1; ++n) { */
- /* lines[n] = readline(&finished); */
- /* if (finished) */
- /* break; */
- /* } */
+
n++;
lines[n] = nil;
- return n;
+ return items;
}
// |------------------|----------------------------------------------|
}
int main() {
- char *lines[MAX_ITEMS] = {0};
- readlines(lines);
+ /* char *lines[INITIAL_ITEMS] = {0}; */
+ char **lines = calloc(INITIAL_ITEMS, sizeof(char*));
+ readlines(&lines, INITIAL_ITEMS);
setlocale(LC_ALL, getenv("LANG"));
free(fontname);
free(text);
+ free(lines);
compl_delete(cs);
/* XDestroyWindow(d, w); */