SDL_rtf: Updated for SDL3 version changes

From bf7520195f42cf043139404bd8e5ea8bcbf2bf06 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 15 May 2024 13:16:44 -0700
Subject: [PATCH] Updated for SDL3 version changes

---
 .wikiheaders-options             |  2 +-
 build-scripts/test-versioning.sh |  2 +-
 build-scripts/wikiheaders.pl     | 22 ++++++++---------
 include/SDL3_rtf/SDL_rtf.h       | 42 ++++++++++++++------------------
 src/SDL_rtf.c                    |  6 ++---
 5 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/.wikiheaders-options b/.wikiheaders-options
index 2a48069..f9ebeb2 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -7,7 +7,7 @@ mainincludefname = SDL3_rtf/SDL_rtf.h
 versionfname = include/SDL3_rtf/SDL_rtf.h
 versionmajorregex = \A\#define\s+SDL_RTF_MAJOR_VERSION\s+(\d+)\Z
 versionminorregex = \A\#define\s+SDL_RTF_MINOR_VERSION\s+(\d+)\Z
-versionpatchregex = \A\#define\s+SDL_RTF_PATCHLEVEL\s+(\d+)\Z
+versionmicroregex = \A\#define\s+SDL_RTF_MICRO_VERSION\s+(\d+)\Z
 selectheaderregex = \ASDL_rtf\.h\Z
 projecturl = https://libsdl.org/projects/SDL_rtf
 wikiurl = https://wiki.libsdl.org/SDL_rtf
diff --git a/build-scripts/test-versioning.sh b/build-scripts/test-versioning.sh
index a73fe97..a600872 100755
--- a/build-scripts/test-versioning.sh
+++ b/build-scripts/test-versioning.sh
@@ -11,7 +11,7 @@ export LC_CTYPE=C
 
 ref_major=$(sed -ne 's/^#define SDL_RTF_MAJOR_VERSION  *//p' include/SDL3_rtf/SDL_rtf.h)
 ref_minor=$(sed -ne 's/^#define SDL_RTF_MINOR_VERSION  *//p' include/SDL3_rtf/SDL_rtf.h)
-ref_micro=$(sed -ne 's/^#define SDL_RTF_PATCHLEVEL  *//p' include/SDL3_rtf/SDL_rtf.h)
+ref_micro=$(sed -ne 's/^#define SDL_RTF_MICRO_VERSION  *//p' include/SDL3_rtf/SDL_rtf.h)
 ref_version="${ref_major}.${ref_minor}.${ref_micro}"
 
 tests=0
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 185701b..6e42197 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -16,7 +16,7 @@
 my $versionfname = 'include/SDL_version.h';
 my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
 my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
-my $versionpatchregex = '\A\#define\s+SDL_PATCHLEVEL\s+(\d+)\Z';
+my $versionmicroregex = '\A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z';
 my $mainincludefname = 'SDL.h';
 my $selectheaderregex = '\ASDL.*?\.h\Z';
 my $projecturl = 'https://libsdl.org/';
@@ -92,7 +92,7 @@
             $readmesubdir = $val, next if $key eq 'readmesubdir';
             $versionmajorregex = $val, next if $key eq 'versionmajorregex';
             $versionminorregex = $val, next if $key eq 'versionminorregex';
-            $versionpatchregex = $val, next if $key eq 'versionpatchregex';
+            $versionmicroregex = $val, next if $key eq 'versionmicroregex';
             $versionfname = $val, next if $key eq 'versionfname';
             $mainincludefname = $val, next if $key eq 'mainincludefname';
             $selectheaderregex = $val, next if $key eq 'selectheaderregex';
@@ -2036,19 +2036,19 @@ sub print_undocumented_section {
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
     my $majorver = 0;
     my $minorver = 0;
-    my $patchver = 0;
+    my $microver = 0;
     while (<FH>) {
         chomp;
         if (/$versionmajorregex/) {
             $majorver = int($1);
         } elsif (/$versionminorregex/) {
             $minorver = int($1);
-        } elsif (/$versionpatchregex/) {
-            $patchver = int($1);
+        } elsif (/$versionmicroregex/) {
+            $microver = int($1);
         }
     }
     close(FH);
-    my $fullversion = "$majorver.$minorver.$patchver";
+    my $fullversion = "$majorver.$minorver.$microver";
 
     foreach (keys %headersyms) {
         my $sym = $_;
@@ -2318,19 +2318,19 @@ sub print_undocumented_section {
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
     my $majorver = 0;
     my $minorver = 0;
-    my $patchver = 0;
+    my $microver = 0;
     while (<FH>) {
         chomp;
         if (/$versionmajorregex/) {
             $majorver = int($1);
         } elsif (/$versionminorregex/) {
             $minorver = int($1);
-        } elsif (/$versionpatchregex/) {
-            $patchver = int($1);
+        } elsif (/$versionmicroregex/) {
+            $microver = int($1);
         }
     }
     close(FH);
-    my $fullversion = "$majorver.$minorver.$patchver";
+    my $fullversion = "$majorver.$minorver.$microver";
 
     my $latex_fname = "$srcpath/$projectshortname.tex";
     my $latex_tmpfname = "$latex_fname.tmp";
@@ -2369,7 +2369,7 @@ sub print_undocumented_section {
 \\begin{document}
 \\frontmatter
 
-\\title{$projectfullname $majorver.$minorver.$patchver Reference Manual}
+\\title{$projectfullname $majorver.$minorver.$microver Reference Manual}
 \\author{The $projectshortname Developers}
 \\maketitle
 
diff --git a/include/SDL3_rtf/SDL_rtf.h b/include/SDL3_rtf/SDL_rtf.h
index 537d289..c1ad4e7 100644
--- a/include/SDL3_rtf/SDL_rtf.h
+++ b/include/SDL3_rtf/SDL_rtf.h
@@ -32,42 +32,36 @@
 extern "C" {
 #endif
 
-/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
-*/
+/**
+ * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
+ */
 #define SDL_RTF_MAJOR_VERSION   3
 #define SDL_RTF_MINOR_VERSION   0
-#define SDL_RTF_PATCHLEVEL      0
+#define SDL_RTF_MICRO_VERSION   0
 
-/* This macro can be used to fill a version structure with the compile-time
- * version of the SDL_rtf library.
+/**
+ * This is the version number macro for the current SDL_rtf version.
  */
-#define SDL_RTF_VERSION(X)                          \
-{                                                   \
-        (X)->major = SDL_RTF_MAJOR_VERSION;         \
-        (X)->minor = SDL_RTF_MINOR_VERSION;         \
-        (X)->patch = SDL_RTF_PATCHLEVEL;            \
-}
+#define SDL_RTF_VERSION \
+    SDL_VERSIONNUM(SDL_RTF_MAJOR_VERSION, SDL_RTF_MINOR_VERSION, SDL_RTF_MICRO_VERSION)
 
-/* Backwards compatibility */
-#define RTF_MAJOR_VERSION       SDL_RTF_MAJOR_VERSION
-#define RTF_MINOR_VERSION       SDL_RTF_MINOR_VERSION
-#define RTF_PATCHLEVEL          SDL_RTF_PATCHLEVEL
-#define RTF_VERSION(X)          SDL_RTF_VERSION(X)
+/**
+ * This macro will evaluate to true if compiled with SDL_rtf at least X.Y.Z.
+ */
+#define SDL_RTF_VERSION_ATLEAST(X, Y, Z) \
+    ((SDL_RTF_MAJOR_VERSION >= X) && \
+     (SDL_RTF_MAJOR_VERSION > X || SDL_RTF_MINOR_VERSION >= Y) && \
+     (SDL_RTF_MAJOR_VERSION > X || SDL_RTF_MINOR_VERSION > Y || SDL_RTF_MICRO_VERSION >= Z))
 
 /**
- * Query the version of SDL_rtf that the program is linked against.
- *
  * This function gets the version of the dynamically linked SDL_rtf library.
- * This is separate from the SDL_RTF_VERSION() macro, which tells you what
- * version of the SDL_rtf headers you compiled against.
  *
- * This returns static internal data; do not free or modify it!
- *
- * \returns a pointer to the version information.
+ * \returns SDL_rtf version
  *
  * \since This function is available since SDL_rtf 3.0.0.
  */
-extern DECLSPEC const SDL_Version * SDLCALL RTF_Linked_Version(void);
+extern DECLSPEC int SDLCALL RTF_Version(void);
+
 
 typedef struct _RTF_Context RTF_Context;
 
diff --git a/src/SDL_rtf.c b/src/SDL_rtf.c
index 1f8ca3e..0ed9fd4 100644
--- a/src/SDL_rtf.c
+++ b/src/SDL_rtf.c
@@ -28,11 +28,9 @@
 
 
 /* rcg06192001 get linked library's version. */
-const SDL_Version *RTF_Linked_Version(void)
+int RTF_Linked_Version(void)
 {
-    static SDL_Version linked_version;
-    SDL_RTF_VERSION(&linked_version);
-    return(&linked_version);
+    return SDL_RTF_VERSION;
 }