changeset 1754:3280d419f1c8

Improve GMaps XML/JSON output by adding links to quests etc.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Oct 2017 18:45:39 +0300
parents 4d160a5c6425
children c97f28d7c4eb
files Makefile.gen mkloc.c
diffstat 2 files changed, 68 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Thu Oct 19 16:55:41 2017 +0300
+++ b/Makefile.gen	Thu Oct 19 18:45:39 2017 +0300
@@ -42,7 +42,7 @@
 	$(addprefix $(MAP_PATH),$(filter %.html,$(MAP_FILES)))
 
 THLIBS_A = $(OBJPATH)thlibs.a
-THLIBS_OBJ = th_util.o th_string.o th_args.o
+THLIBS_OBJ = th_util.o th_string.o th_args.o th_datastruct.o
 
 
 ###
--- a/mkloc.c	Thu Oct 19 16:55:41 2017 +0300
+++ b/mkloc.c	Thu Oct 19 18:45:39 2017 +0300
@@ -8,6 +8,7 @@
 #include "liblocfile.h"
 #include "th_args.h"
 #include "th_string.h"
+#include "th_datastruct.h"
 
 enum
 {
@@ -851,6 +852,36 @@
 /* Output locations in GMaps XML format. Character set conversion
  * is not performed, caller must take care of it via iconv or similar.
  */
+static char *getQuestLink(const char *name, const char *desc)
+{
+    char *str, *tmp = th_strdup(name);
+    size_t i;
+    for (i = 0; i < strlen(tmp); i++)
+        tmp[i] = th_isspace(tmp[i]) ? '+' : th_tolower(tmp[i]);
+
+    str = th_strdup_printf("<a href=\"http://www.bat.org/help/quests?str=%s\">%s</a>", tmp, desc);
+    th_free(tmp);
+    return str;
+}
+
+
+static char *addQuestLink(char **buf, size_t *bufSize, size_t *bufLen, char *ptr, char *start, char *end)
+{
+    if (start != NULL && end != NULL)
+    {
+        char *name = th_strndup(start + 1, end - start - 1);
+        char *desc = th_strndup(ptr, end - ptr + 1);
+        char *tmp = getQuestLink(name, desc);
+        th_strbuf_puts(buf, bufSize, bufLen, tmp);
+        th_free(name);
+        th_free(desc);
+        th_free(tmp);
+        return end + 1;
+    }
+    else
+        return ptr;
+}
+
 void outputGMapsHTML(FILE *outFile, LocMarker *tmp,
     int (*fpr)(FILE *, const char *fmt, ...), int (*fps)(const char *, FILE *))
 {
@@ -909,17 +940,18 @@
             fprintf(outFile, "Coders: ");
             for (n = 0; n < tmp->ncoders; n++)
             {
-                char *info = "";
+                char *info = "", *sinfo = "";
                 switch (tmp->coders[n].flags)
                 {
-                    case NAME_ORIG: info = " (O)"; break;
-                    case NAME_RECODER: info = " (R)"; break;
-                    case NAME_MAINTAINER: info = " (M)"; break;
-                    case NAME_EXPANDER: info = " (E)"; break;
+                    case NAME_ORIG: info = " (O)"; sinfo = "Original coder"; break;
+                    case NAME_RECODER: info = " (R)"; sinfo = "Re-coder"; break;
+                    case NAME_MAINTAINER: info = " (M)"; sinfo = "Maintainer"; break;
+                    case NAME_EXPANDER: info = " (E)"; sinfo = "Expander"; break;
                 }
                 //fpr(outFile, "<a target=\"_blank\" href=\"http://www.bat.org/char/%s\">%s%s</a>",
-                fpr(outFile, "<a target=\"_blank\" href=\"https://tnsp.org/maps/loc.php?a=%s\">%s%s</a>",
-                    tmp->coders[n].name, tmp->coders[n].name, info);
+                fpr(outFile, "<a target=\"_blank\" href=\"https://tnsp.org/maps/loc.php?a=%s\" title=\"%s\">%s%s</a>",
+                    tmp->coders[n].name, sinfo,
+                    tmp->coders[n].name, info);
 
                 if (n < tmp->ncoders - 1)
                     fprintf(outFile, ", ");
@@ -930,7 +962,34 @@
 
     /* Print out freeform information field */
     if (tmp->freeform)
-        fpr(outFile, "<br>%s<br>", tmp->freeform);
+    {
+        char *ptr = tmp->freeform;
+        char *buf = NULL;
+        size_t bufLen = 0, bufSize = 0;
+
+        while (*ptr != 0)
+        {
+            if (ptr[0] == 'A' && ptr[1] == 'Q' && th_isspace(ptr[2]))
+            {
+                char *start = strchr(ptr + 3, '"');
+                ptr = addQuestLink(&buf, &bufSize, &bufLen, ptr, start, strchr(start + 1, '"'));
+            }
+            else
+            if (ptr[0] == 'L' && ptr[1] == 'Q' && th_isdigit(ptr[2]))
+            {
+                char *start = strchr(ptr + 3, '"');
+                ptr = addQuestLink(&buf, &bufSize, &bufLen, ptr, start, start ? strchr(start + 1, '"') : NULL);
+            }
+
+            if (*ptr != 0)
+                th_strbuf_putch(&buf, &bufSize, &bufLen, *ptr++);
+        }
+
+        th_strbuf_putch(&buf, &bufSize, &bufLen, 0);
+
+        fpr(outFile, "<br>%s<br>", buf);
+        th_free(buf);
+    }
 }