| t@@ -6,33 +6,13 @@
#include
#include
#include
-#include /* ifdef BSD */
#include
-#include
#include
#include
-typedef struct item Item;
-typedef struct dir Dir;
-
-struct item {
- char type;
- char *username;
- char *selector;
- char *host;
- char *port;
- char *raw;
- size_t printoff;
- Item *entry;
- Dir *dir;
-};
-
-struct dir {
- Item **items;
- size_t nitems;
-};
+#include "common.h"
-static void
+void
die(const char *fmt, ...)
{
va_list arg;
t@@ -90,33 +70,7 @@ usage(void)
die("usage: sacc URL");
}
-static void
-help(void)
-{
- puts("Commands:\n"
- "N = [1-9]...: browse item N.\n"
- "0: browse previous item.\n"
- "n: show next page.\n"
- "p: show previous page.\n"
- "!: refetch failed item.\n"
- "^D, q: quit.\n"
- "h: this help.");
-}
-
-static int
-termlines(void)
-{
- struct winsize ws;
-
- if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) {
- die("Could not get terminal resolution: %s",
- strerror(errno));
- }
-
- return ws.ws_row-1;
-}
-
-static const char *
+const char *
typedisplay(char t)
{
switch (t) {
t@@ -159,41 +113,6 @@ typedisplay(char t)
}
}
-static void
-display(Item *item)
-{
- Item **items;
- size_t i, lines, nitems;
- int ndigits;
-
- if (item->type > '1')
- return;
-
- switch (item->type) {
- case '0':
- puts(item->raw);
- break;
- case '1':
- items = item->dir->items;
- nitems = item->dir->nitems;
- lines = item->printoff + termlines();
- ndigits = (nitems < 10) ? 1 : (nitems < 100) ? 2 : 3;
-
- for (i = item->printoff; i < nitems && i < lines; ++i) {
- if (item = items[i]) {
- printf("%*d %-4s%c %s\n", ndigits, i+1,
- item->type != 'i' ?
- typedisplay(item->type) : "",
- item->type > '1' ? '|' : '+',
- items[i]->username);
- } else {
- printf("%*d !! |\n", ndigits, i+1);
- }
- }
- break;
- }
-}
-
static char *
pickfield(char **raw, char sep)
{
t@@ -411,66 +330,6 @@ dig(Item *entry, Item *item)
return 1;
}
-static Item *
-selectitem(Item *entry)
-{
- char buf[BUFSIZ], nl;
- Item *hole;
- int item, nitems, lines;
-
- nitems = entry->dir ? entry->dir->nitems : 0;
-
- do {
- printf("%d items (h for help): ", nitems);
-
- if (!fgets(buf, sizeof(buf), stdin)) {
- putchar('\n');
- return NULL;
- }
- if (!strcmp(buf, "q\n"))
- return NULL;
-
- if (!strcmp(buf, "n\n")) {
- lines = termlines();
- if (lines < entry->dir->nitems - entry->printoff &&
- lines < (size_t)-1 - entry->printoff)
- entry->printoff += lines;
- return entry;
- }
- if (!strcmp(buf, "p\n")) {
- lines = termlines();
- if (lines <= entry->printoff)
- entry->printoff -= lines;
- else
- entry->printoff = 0;
- return entry;
- }
-
- if (!strcmp(buf, "!\n")) {
- if (entry->raw)
- continue;
- return entry;
- }
-
- item = -1;
- if (!strcmp(buf, "h\n")) {
- help();
- continue;
- }
- if (*buf < '0' || *buf > '9')
- continue;
-
- nl = '\0';
- if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
- item = -1;
- } while (item < 0 || item > nitems);
-
- if (item > 0)
- return entry->dir->items[item-1];
-
- return entry->entry;
-}
-
static void
delve(Item *hole)
{ |
| t@@ -0,0 +1,128 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "common.h"
+
+void
+help(void)
+{
+ puts("Commands:\n"
+ "N = [1-9]...: browse item N.\n"
+ "0: browse previous item.\n"
+ "n: show next page.\n"
+ "p: show previous page.\n"
+ "!: refetch failed item.\n"
+ "^D, q: quit.\n"
+ "h: this help.");
+}
+
+static int
+termlines(void)
+{
+ struct winsize ws;
+
+ if (ioctl(1, TIOCGWINSZ, &ws) < 0) {
+ die("Could not get terminal resolution: %s",
+ strerror(errno));
+ }
+
+ return ws.ws_row-1;
+}
+
+void
+display(Item *item)
+{
+ Item **items;
+ size_t i, lines, nitems;
+ int ndigits;
+
+ if (item->type > '1')
+ return;
+
+ switch (item->type) {
+ case '0':
+ puts(item->raw);
+ break;
+ case '1':
+ items = item->dir->items;
+ nitems = item->dir->nitems;
+ lines = item->printoff + termlines();
+ ndigits = (nitems < 10) ? 1 : (nitems < 100) ? 2 : 3;
+
+ for (i = item->printoff; i < nitems && i < lines; ++i) {
+ if (item = items[i]) {
+ printf("%*d %-4s%c %s\n", ndigits, i+1,
+ item->type != 'i' ?
+ typedisplay(item->type) : "",
+ item->type > '1' ? '|' : '+',
+ items[i]->username);
+ } else {
+ printf("%*d !! |\n", ndigits, i+1);
+ }
+ }
+ break;
+ }
+}
+
+Item *
+selectitem(Item *entry)
+{
+ char buf[BUFSIZ], nl;
+ int item, nitems, lines;
+
+ nitems = entry->dir ? entry->dir->nitems : 0;
+
+ do {
+ printf("%d items (h for help): ", nitems);
+
+ if (!fgets(buf, sizeof(buf), stdin)) {
+ putchar('\n');
+ return NULL;
+ }
+ if (!strcmp(buf, "q\n"))
+ return NULL;
+
+ if (!strcmp(buf, "n\n")) {
+ lines = termlines();
+ if (lines < entry->dir->nitems - entry->printoff &&
+ lines < (size_t)-1 - entry->printoff)
+ entry->printoff += lines;
+ return entry;
+ }
+ if (!strcmp(buf, "p\n")) {
+ lines = termlines();
+ if (lines <= entry->printoff)
+ entry->printoff -= lines;
+ else
+ entry->printoff = 0;
+ return entry;
+ }
+
+ if (!strcmp(buf, "!\n")) {
+ if (entry->raw)
+ continue;
+ return entry;
+ }
+
+ item = -1;
+ if (!strcmp(buf, "h\n")) {
+ help();
+ continue;
+ }
+ if (*buf < '0' || *buf > '9')
+ continue;
+
+ nl = '\0';
+ if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
+ item = -1;
+ } while (item < 0 || item > nitems);
+
+ if (item > 0)
+ return entry->dir->items[item-1];
+
+ return entry->entry;
+} |