From 8db0b48f9dce63bfdb410b9b4e13e4adf0326830 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 15 Jan 2021 14:47:42 -0500 Subject: Output htagml -x from the main loop Silly the way it was written, but I think I started writing it that way before I decided to make it mutually exclusive with regular output. --- bin/htagml.c | 43 ++++++++++++++++--------------------------- bin/man1/htagml.1 | 2 +- 2 files changed, 17 insertions(+), 28 deletions(-) (limited to 'bin') diff --git a/bin/htagml.c b/bin/htagml.c index 7db101ce..955a9839 100644 --- a/bin/htagml.c +++ b/bin/htagml.c @@ -23,16 +23,6 @@ #include #include -struct Tag { - char *tag; - int num; - regex_t regex; -}; - -static int compar(const void *a, const void *b) { - return ((const struct Tag *)a)->num - ((const struct Tag *)b)->num; -} - static char *nomagic(const char *pattern) { char *buf = malloc(2 * strlen(pattern) + 1); if (!buf) err(EX_OSERR, "malloc"); @@ -94,7 +84,11 @@ int main(int argc, char *argv[]) { size_t len = 0; size_t cap = 256; - struct Tag *tags = malloc(cap * sizeof(*tags)); + struct Tag { + char *tag; + int num; + regex_t regex; + } *tags = malloc(cap * sizeof(*tags)); if (!tags) err(EX_OSERR, "malloc"); char *buf = NULL; @@ -142,7 +136,7 @@ int main(int argc, char *argv[]) { if (!file) err(EX_NOINPUT, "%s", name); int num = 0; - if (pre) printf("
");
+	printf(pre ? "
" : index ? "
    \n" : ""); while (0 < getline(&buf, &bufCap, file) && ++num) { struct Tag *tag = NULL; for (size_t i = 0; i < len; ++i) { @@ -155,7 +149,15 @@ int main(int argc, char *argv[]) { tag->num = num; break; } - if (index) continue; + if (index) { + if (!tag) continue; + printf("
  • tag, strlen(tag->tag)); + printf("\">"); + escape(true, tag->tag, strlen(tag->tag)); + printf("
  • \n"); + continue; + } if (pipe) { ssize_t len = getline(&buf, &bufCap, stdin); if (len < 0) { @@ -187,18 +189,5 @@ int main(int argc, char *argv[]) { printf(""); if (match) escape(!pipe, match, strlen(match)); } - if (pre) printf("
"); - - if (!index) return EX_OK; - qsort(tags, len, sizeof(*tags), compar); - printf("\n"); + printf(pre ? "
" : index ? "\n" : ""); } diff --git a/bin/man1/htagml.1 b/bin/man1/htagml.1 index 7a5f572f..97e8f3f2 100644 --- a/bin/man1/htagml.1 +++ b/bin/man1/htagml.1 @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm -.Op Fl ipx +.Op Fl ip | x .Op Fl f Ar tagsfile .Ar file . -- cgit 1.4.1