SDL_net: Updated for SDL3 version changes

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

---
 .wikiheaders-options                          |  2 +-
 .../cmake/sdl3_net-config-version.cmake       |  8 ++--
 build-scripts/test-versioning.sh              |  2 +-
 build-scripts/wikiheaders.pl                  | 22 ++++-----
 include/SDL3_net/SDL_net.h                    | 48 ++++++++-----------
 src/SDL_net.c                                 |  7 +--
 6 files changed, 38 insertions(+), 51 deletions(-)

diff --git a/.wikiheaders-options b/.wikiheaders-options
index eb4d6fa..445054b 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -7,7 +7,7 @@ mainincludefname = SDL3_net/SDL_net.h
 versionfname = include/SDL3_net/SDL_net.h
 versionmajorregex = \A\#define\s+SDL_NET_MAJOR_VERSION\s+(\d+)\Z
 versionminorregex = \A\#define\s+SDL_NET_MINOR_VERSION\s+(\d+)\Z
-versionpatchregex = \A\#define\s+SDL_NET_PATCHLEVEL\s+(\d+)\Z
+versionmicroregex = \A\#define\s+SDL_NET_MICRO_VERSION\s+(\d+)\Z
 selectheaderregex = \ASDL_net\.h\Z
 projecturl = https://libsdl.org/projects/SDL_net
 wikiurl = https://wiki.libsdl.org/SDL_net
diff --git a/VisualC/pkg-support/cmake/sdl3_net-config-version.cmake b/VisualC/pkg-support/cmake/sdl3_net-config-version.cmake
index 1132507..a9d8d65 100644
--- a/VisualC/pkg-support/cmake/sdl3_net-config-version.cmake
+++ b/VisualC/pkg-support/cmake/sdl3_net-config-version.cmake
@@ -13,10 +13,10 @@ string(REGEX MATCH "#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major
 set(_sdl_major "${CMAKE_MATCH_1}")
 string(REGEX MATCH "#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_net_h}")
 set(_sdl_minor "${CMAKE_MATCH_1}")
-string(REGEX MATCH "#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_net_h}")
-set(_sdl_patch "${CMAKE_MATCH_1}")
-if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re)
-    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}")
+string(REGEX MATCH "#define[ \t]+SDL_NET_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_net_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
 else()
     message(AUTHOR_WARNING "Could not extract version from SDL_net.h.")
     return()
diff --git a/build-scripts/test-versioning.sh b/build-scripts/test-versioning.sh
index ea57938..893525f 100755
--- a/build-scripts/test-versioning.sh
+++ b/build-scripts/test-versioning.sh
@@ -12,7 +12,7 @@ export LC_CTYPE=C
 header=include/SDL3_net/SDL_net.h
 ref_major=$(sed -ne 's/^#define SDL_NET_MAJOR_VERSION  *//p' $header)
 ref_minor=$(sed -ne 's/^#define SDL_NET_MINOR_VERSION  *//p' $header)
-ref_micro=$(sed -ne 's/^#define SDL_NET_PATCHLEVEL  *//p' $header)
+ref_micro=$(sed -ne 's/^#define SDL_NET_MICRO_VERSION  *//p' $header)
 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_net/SDL_net.h b/include/SDL3_net/SDL_net.h
index ee59561..ceb59ab 100644
--- a/include/SDL3_net/SDL_net.h
+++ b/include/SDL3_net/SDL_net.h
@@ -38,45 +38,35 @@
 extern "C" {
 #endif
 
-/* Version checks... */
-
+/**
+ * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
+ */
 #define SDL_NET_MAJOR_VERSION   3
 #define SDL_NET_MINOR_VERSION   0
-#define SDL_NET_PATCHLEVEL      0
+#define SDL_NET_MICRO_VERSION   0
 
 /**
- * Query the verion of the SDL_net library in use at compile time.
- *
- * This macro copies the version listen in the SDL_net headers into a struct
- * of the app's choosing.
- *
- * \threadsafety It is safe to use this macro from any thread.
- *
- * \since This macro is available since SDL_Net 3.0.0.
+ * This is the version number macro for the current SDL_net version.
  */
-#define SDL_NET_VERSION(X)                          \
-{                                                   \
-    (X)->major = SDL_NET_MAJOR_VERSION;             \
-    (X)->minor = SDL_NET_MINOR_VERSION;             \
-    (X)->patch = SDL_NET_PATCHLEVEL;                \
-}
+#define SDL_NET_VERSION \
+    SDL_VERSIONNUM(SDL_NET_MAJOR_VERSION, SDL_NET_MINOR_VERSION, SDL_NET_MICRO_VERSION)
 
 /**
- * Query the verion of the SDL_net library in use at runtime.
- *
- * The returned value points to static, internal, read-only memory. Do not
- * modify or free it. The pointer remains valid as long as the library is
- * loaded by the system.
- *
- * This function can be safely called before SDLNet_Init().
- *
- * \returns An object with the runtime library version. Never returns NULL.
+ * This macro will evaluate to true if compiled with SDL_net at least X.Y.Z.
+ */
+#define SDL_NET_VERSION_ATLEAST(X, Y, Z) \
+    ((SDL_NET_MAJOR_VERSION >= X) && \
+     (SDL_NET_MAJOR_VERSION > X || SDL_NET_MINOR_VERSION >= Y) && \
+     (SDL_NET_MAJOR_VERSION > X || SDL_NET_MINOR_VERSION > Y || SDL_NET_MICRO_VERSION >= Z))
+
+/**
+ * This function gets the version of the dynamically linked SDL_net library.
  *
- * \threadsafety It is safe to call this function from any thread.
+ * \returns SDL_net version
  *
- * \since This function is available since SDL_Net 3.0.0.
+ * \since This function is available since SDL_net 3.0.0.
  */
-extern DECLSPEC const SDL_Version * SDLCALL SDLNet_LinkedVersion(void);
+extern DECLSPEC int SDLCALL SDLNet_Version(void);
 
 
 /* init/quit functions... */
diff --git a/src/SDL_net.c b/src/SDL_net.c
index 916c240..9c23779 100644
--- a/src/SDL_net.c
+++ b/src/SDL_net.c
@@ -86,12 +86,9 @@ typedef enum SDLNet_SocketType
 } SDLNet_SocketType;
 
 
-const SDL_Version *SDLNet_LinkedVersion(void)
+int SDLNet_LinkedVersion(void)
 {
-    static const SDL_Version linked_version = {
-        SDL_NET_MAJOR_VERSION, SDL_NET_MINOR_VERSION, SDL_NET_PATCHLEVEL
-    };
-    return &linked_version;
+    return SDL_NET_VERSION;
 }
 
 struct SDLNet_Address