changeset 2591:f207279a5f89

Bump loc file spec to v4.1, and implement handling of location addition timestamp accuracy specifier.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 11 Feb 2024 17:52:39 +0200
parents f464c7064b81
children 01c077ac6766
files README.loc src/liblocfile.c src/liblocfile.h src/mkloc.c www/common.inc.php
diffstat 5 files changed, 83 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/README.loc	Sun Feb 11 17:26:44 2024 +0200
+++ b/README.loc	Sun Feb 11 17:52:39 2024 +0200
@@ -1,6 +1,6 @@
 MapUtils '.loc' file format documentation
 =========================================
-This document describes format version 4.0.
+This document describes format version 4.1.
 
 GENERAL FORMAT DESCRIPTION
 --------------------------
@@ -100,7 +100,15 @@
 
  * [OPT] Timestamp: MAY be left empty, otherwise a timestamp of when the area
    was added in the game. Formatted as 'dd.mm.yyyy', MUST be zero-padded.
-   Examples: 21.03.2008; 02.12.1996
+   The value MAY be prefixed with one of the following signifying accuracy:
+
+     nothing = Default accuracy
+     '?' = Timestamp is "guesstimated". Basically an educated "guess"
+           possibly based on some evidence.
+     '!' = Timestamp is "known", e.g. as accurate as it can be.
+     '#' = Timestamp is "approximate", e.g. may be off by some.
+
+   Examples: 21.03.2008; ?02.12.1996
 
  * [OPT] URL: Properly encoded URL-link pointing to related web-page.
 
--- a/src/liblocfile.c	Sun Feb 11 17:26:44 2024 +0200
+++ b/src/liblocfile.c	Sun Feb 11 17:52:39 2024 +0200
@@ -597,10 +597,25 @@
 
     case 6:            // Date
         marker->valid = false;
+        marker->added.accuracy = TS_ACC_DEFAULT;
         tmpStr = parseFieldString(ctx, ctx->fieldSep);
         if (tmpStr && tmpStr[0])
         {
-            if (sscanf(tmpStr, LOC_TIMEFMT, &marker->added.day, &marker->added.month, &marker->added.year) == 3)
+            char *stamp;
+            switch (tmpStr[0])
+            {
+                case TS_ACC_KNOWN:
+                case TS_ACC_GUESSTIMATE:
+                case TS_ACC_APPROXIMATE:
+                    marker->added.accuracy = (int) tmpStr[0];
+                    stamp = tmpStr + 1;
+                    break;
+
+                default:
+                    stamp = tmpStr;
+            }
+
+            if (sscanf(stamp, LOC_TIMEFMT, &marker->added.day, &marker->added.month, &marker->added.year) == 3)
                 marker->valid = true;
             else
             {
--- a/src/liblocfile.h	Sun Feb 11 17:26:44 2024 +0200
+++ b/src/liblocfile.h	Sun Feb 11 17:52:39 2024 +0200
@@ -15,7 +15,7 @@
  */
 #define LOC_MAGIC              "MapUtils LOC file"
 #define LOC_VERSION_MAJOR      (4)
-#define LOC_VERSION_MINOR      (0)
+#define LOC_VERSION_MINOR      (1)
 
 
 /* LOCD_* is an enum describing the preferred orientation of the
@@ -66,8 +66,8 @@
 #define LOCF_INVIS             (0x010000)   // '-' Invisible marker / Don't show label
 #define LOCF_CLOSED            (0x020000)   // '!' Location is CLOSED
 #define LOCF_INSTANCED         (0x040000)   // 'I' Location is "instanced" for each player
-#define LOCF_INVALID           (0x100000)   // Possibly invalid location
-#define LOCF_NOMARKER          (0x200000)   // Location has no marker in mapdata or explicitly defined
+#define LOCF_INVALID           (0x400000)   // Possibly invalid location
+#define LOCF_NOMARKER          (0x800000)   // Location has no marker in mapdata or explicitly defined
 #define LOCF_Q_MASK            (0xFF0000)
 
 
@@ -91,11 +91,19 @@
 #define NAME_ORIG              (0x00001)   // '@' Original area name
 
 
+/* Timestamp accuracy
+ */
+#define TS_ACC_DEFAULT         0
+#define TS_ACC_KNOWN           '!'
+#define TS_ACC_GUESSTIMATE     '?'
+#define TS_ACC_APPROXIMATE     '#'
+
+
 /* Structures
  */
 typedef struct
 {
-    int day, month, year;
+    int day, month, year, accuracy;
 } LocDateStruct;
 
 
--- a/src/mkloc.c	Sun Feb 11 17:26:44 2024 +0200
+++ b/src/mkloc.c	Sun Feb 11 17:52:39 2024 +0200
@@ -720,8 +720,18 @@
 
         if (tmp->valid)
         {
-            fprintf(outFile, LOC_TIMEFMT,
-            tmp->added.day, tmp->added.month, tmp->added.year);
+            const char *acc;
+            switch (tmp->added.accuracy)
+            {
+                case TS_ACC_DEFAULT: acc = ""; break;
+                case TS_ACC_KNOWN  : acc = "!"; break;
+                case TS_ACC_GUESSTIMATE : acc = "?"; break;
+                case TS_ACC_APPROXIMATE : acc = "#"; break;
+                default: acc = "ERROR! "; break;
+            }
+
+            fprintf(outFile, "%s" LOC_TIMEFMT,
+                acc, tmp->added.day, tmp->added.month, tmp->added.year);
         }
 
         fprintf(outFile, ";");
@@ -1038,8 +1048,20 @@
         // Added to game timestamp
         if (tmp->valid)
         {
-            fprintf(outFile, " added=\"" LOC_TIMEFMT "\"",
-                tmp->added.day, tmp->added.month, tmp->added.year);
+            const char *acc;
+            switch (tmp->added.accuracy)
+            {
+                case TS_ACC_DEFAULT: acc = "default"; break;
+                case TS_ACC_KNOWN  : acc = "known"; break;
+                case TS_ACC_GUESSTIMATE : acc = "guesstimate"; break;
+                case TS_ACC_APPROXIMATE : acc = "approximate"; break;
+                default: acc = "ERROR"; break;
+            }
+
+            fprintf(outFile,
+                " added=\"" LOC_TIMEFMT "\" added-accuracy=\"%s\"",
+                tmp->added.day, tmp->added.month, tmp->added.year,
+                acc);
         }
 
         fprintf(outFile, ">");
--- a/www/common.inc.php	Sun Feb 11 17:26:44 2024 +0200
+++ b/www/common.inc.php	Sun Feb 11 17:52:39 2024 +0200
@@ -46,6 +46,13 @@
 define("NAME_ORIG"              , 0x000001);   // '@' Original area name
 
 
+// Timestamp accuracy
+define("TS_ACC_DEFAULT"         , 0);
+define("TS_ACC_KNOWN"           , '!');
+define("TS_ACC_GUESSTIMATE"     , '?');
+define("TS_ACC_APPROXIMATE"     , '#');
+
+
 // Location types table
 define("LTI_PAGE_DESC"    , 0);
 define("LTI_MENU_TITLE"   , 1);
@@ -377,8 +384,19 @@
         // Get timestamp
         $stamp = $record[6];
         $added = -1;
+        $added_accuracy = TS_ACC_DEFAULT;
         if (strlen($stamp) > 0)
         {
+          switch ($stamp[0])
+          {
+            case TS_ACC_KNOWN:
+            case TS_ACC_GUESSTIMATE:
+            case TS_ACC_APPROXIMATE:
+              $added_accuracy = $stamp[0];
+              $stamp = substr($stamp, 1);
+              break;
+          }
+
           if (sscanf($stamp, "%02d.%02d.%04d", $aday, $amonth, $ayear) == 3)
           {
             if (($added = mktime(0, 0, 0, $amonth, $aday, $ayear)) === FALSE)
@@ -402,6 +420,7 @@
           "flags" => $flags,
           "coders" => $coders,
           "added" => $added,
+          "added_accuracy" => $added_accuracy,
           "url" => strlen($record[7]) ? $record[7] : NULL,
           "freeform" => strlen($ffreeform) ? $ffreeform : NULL,
         ];