Let OS2APIINFO optionally take key/value pairs, use it for export names.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 17 Jun 2018 22:21:52 -0400
changeset 134 352d3fac725f
parent 133 1269cfcfa3d4
child 135 80d7cb0d83a2
Let OS2APIINFO optionally take key/value pairs, use it for export names. This lets me remove my tcpip32 hack, and will let me export old symbols as all caps for OS/2's use and something more sane for regular use (like VioGetCurPos() in modern times is VIOGETCURPOS in viocalls.dll, etc).
lxapigen.pl
native/os2native16.h
native/os2types.h
native/tcpip32.h
native/viocalls-lx.h
native/viocalls.h
--- a/lxapigen.pl	Sun Jun 17 00:23:53 2018 -0400
+++ b/lxapigen.pl	Sun Jun 17 22:21:52 2018 -0400
@@ -58,14 +58,31 @@
             #print("rettype='$rettype' fn='$fn' args='$args' apiinfo='$apiinfo'\n");
 
             my $fn = $table{'fn'};
-            my $ordinal;
+            my $ordinal = undef;
+            my $expname = undef;
             if ($apiinfo =~ /\A(\d+)\Z/) {
                 $ordinal = int($1);
             } else {
-                die("bogus OS2APIINFO for '$fn'\n");
+                foreach (split(/,/, $apiinfo)) {
+                    #print("apiinfoarg: '$_'\n");
+                    my ($infokey, $infoval) = /\A(.*?)\=(.*)\Z/;
+                    #print("apiinfo key='$infokey' val='$infoval'\n");
+                    if ($infokey eq 'ord') {
+                        if ($infoval =~ /\A(\d+)\Z/) {
+                            $ordinal = int($1);
+                        } else {
+                            die("Invalid ordinal '$infoval' for '$fn'\n");
+                        }
+                    } elsif ($infokey eq 'name') {
+                        $expname = $infoval;
+                    } else {
+                        die("unknown OS2APIINFO key '$infokey' for '$fn'\n");
+                    }
+                }
             }
 
             $table{'ordinal'} = $ordinal;
+            $table{'expname'} = $expname if defined $expname;
 
             if (defined $ordinalmap{$ordinal}) {
                 my $dupfn = $ordinalmap{$ordinal}{'fn'};
@@ -203,15 +220,15 @@
     foreach (sort { $a <=> $b } keys(%ordinalmap) ) {
         my $tableref = $ordinalmap{$_};
         my $fn = $tableref->{'fn'};
+        my $expname = $tableref->{'expname'};
         my $ordinal = $tableref->{'ordinal'};
         my $suffix = $tableref->{'is16bit'} ? '16' : '';
 
         print OUT $comma;
-        # This is a hack for tcpip32, which doesn't want to step on BSD sockets symbols.
-        if ($fn =~ /\AOS2_(.*)\Z/) {
-            print OUT "    LX_NATIVE_EXPORT_DIFFERENT_NAME($fn, \"$1\", $ordinal)";
+        if (defined $expname) {
+            print OUT "    LX_NATIVE_EXPORT${suffix}_DIFFERENT_NAME($fn, \"$expname\", $ordinal)";
         } else {
-            print OUT "    LX_NATIVE_EXPORT$suffix($fn, $ordinal)";
+            print OUT "    LX_NATIVE_EXPORT${suffix}($fn, $ordinal)";
         }
         $comma = ",\n";
     }
--- a/native/os2native16.h	Sun Jun 17 00:23:53 2018 -0400
+++ b/native/os2native16.h	Sun Jun 17 22:21:52 2018 -0400
@@ -265,6 +265,7 @@
     typ var = (typ) GLoaderState.convert1616to32(*((uint32 *) args)); args += sizeof (uint32)
 
 #define LX_NATIVE_EXPORT16(fn, ord) { ord, #fn, &fn##16, &obj16 }
+#define LX_NATIVE_EXPORT16_DIFFERENT_NAME(fn, fnname, ord) { ord, fnname, &fn##16, &obj16 }
 
 #endif
 
--- a/native/os2types.h	Sun Jun 17 00:23:53 2018 -0400
+++ b/native/os2types.h	Sun Jun 17 22:21:52 2018 -0400
@@ -17,7 +17,7 @@
 
 // this doesn't do anything when compiling, but a script parses these in
 //  the headers to generate some code.
-#define OS2APIINFO(retfcount)
+#define OS2APIINFO(...)
 
 #ifndef APIENTRY
 #define APIENTRY
--- a/native/tcpip32.h	Sun Jun 17 00:23:53 2018 -0400
+++ b/native/tcpip32.h	Sun Jun 17 22:21:52 2018 -0400
@@ -126,32 +126,32 @@
 } OS2_timezone;
 #pragma pack(pop)
 
-OS2EXPORT int OS2API OS2_sock_init(void) OS2APIINFO(26);
-OS2EXPORT int OS2API OS2_recv(int sock, void *buf, size_t len, int os2flags) OS2APIINFO(10);
-OS2EXPORT int OS2API OS2_connect(int sock, const OS2_sockaddr *os2addr, int addrlen) OS2APIINFO(3);
-OS2EXPORT int OS2API OS2_shutdown(int sock, int kind) OS2APIINFO(25);
-OS2EXPORT int OS2API OS2_socket(int family, int os2socktype, int protocol) OS2APIINFO(16);
-OS2EXPORT ssize_t OS2API OS2_send(int sock, const void *buf, size_t len, int os2flags) OS2APIINFO(13);
-OS2EXPORT int OS2API OS2_soclose(int sock) OS2APIINFO(17);
-OS2EXPORT int OS2API OS2_sock_errno(void) OS2APIINFO(20);
-OS2EXPORT unsigned long OS2API OS2_inet_addr(const char *name) OS2APIINFO(105);
-OS2EXPORT OS2_hostent * OS2API OS2_gethostbyname(const char *name) OS2APIINFO(111);
-OS2EXPORT unsigned short OS2API OS2_htons(unsigned short val) OS2APIINFO(205);
-OS2EXPORT char * OS2API OS2_inet_ntoa(OS2_in_addr os2inaddr) OS2APIINFO(110);
-OS2EXPORT OS2_servent * OS2API OS2_getservbyname(const char *name, const char *proto) OS2APIINFO(124);
-OS2EXPORT int OS2API OS2_select(int sock, OS2_fd_set *readfds, OS2_fd_set *writefds, OS2_fd_set *errorfds, OS2_timeval *timeout) OS2APIINFO(32);
-OS2EXPORT int OS2API OS2_os2_select(int *socks, int noreads, int nowrites, int noexcept, long timeout) OS2APIINFO(12);
-OS2EXPORT int OS2API OS2_getsockname(int sock, OS2_sockaddr *os2name, int *namelen) OS2APIINFO(6);
-OS2EXPORT int OS2API OS2_setsockopt(int sock, int os2level, int os2name, const void *value, int len) OS2APIINFO(15);
-OS2EXPORT int OS2API OS2_bind(int sock, const OS2_sockaddr *os2name, int os2namelen) OS2APIINFO(2);
-OS2EXPORT int OS2API OS2_accept(int sock, OS2_sockaddr *os2name, int *os2namelen) OS2APIINFO(1);
-OS2EXPORT int OS2API OS2_Rgetsockname(int sock, OS2_sockaddr *os2name, int *namelen) OS2APIINFO(159);
-OS2EXPORT int OS2API OS2_Rbind(int sock, OS2_sockaddr *os2name, int os2namelen, OS2_sockaddr *os2remote) OS2APIINFO(157);
-OS2EXPORT int OS2API OS2_Raccept(int sock, OS2_sockaddr *os2name, int *os2namelen) OS2APIINFO(156);
-OS2EXPORT int OS2API OS2_Rconnect(int sock, const OS2_sockaddr *os2name, int os2namelen) OS2APIINFO(158);
-OS2EXPORT int OS2API OS2_Rlisten(int sock, int backlog) OS2APIINFO(160);
-OS2EXPORT OS2_hostent * OS2API OS2_Rgethostbyname(const char *name) OS2APIINFO(161);
-OS2EXPORT int OS2API OS2_gettimeofday(OS2_timeval *os2tv, OS2_timezone *os2tz) OS2APIINFO(102);
+OS2EXPORT int OS2API OS2_sock_init(void) OS2APIINFO(ord=26,name=sock_init);
+OS2EXPORT int OS2API OS2_recv(int sock, void *buf, size_t len, int os2flags) OS2APIINFO(ord=10,name=recv);
+OS2EXPORT int OS2API OS2_connect(int sock, const OS2_sockaddr *os2addr, int addrlen) OS2APIINFO(ord=3,name=connect);
+OS2EXPORT int OS2API OS2_shutdown(int sock, int kind) OS2APIINFO(ord=25,name=shutdown);
+OS2EXPORT int OS2API OS2_socket(int family, int os2socktype, int protocol) OS2APIINFO(ord=16,name=socket);
+OS2EXPORT ssize_t OS2API OS2_send(int sock, const void *buf, size_t len, int os2flags) OS2APIINFO(ord=13,name=send);
+OS2EXPORT int OS2API OS2_soclose(int sock) OS2APIINFO(ord=17,name=soclose);
+OS2EXPORT int OS2API OS2_sock_errno(void) OS2APIINFO(ord=20,name=sock_errno);
+OS2EXPORT unsigned long OS2API OS2_inet_addr(const char *name) OS2APIINFO(ord=105,name=inet_addr);
+OS2EXPORT OS2_hostent * OS2API OS2_gethostbyname(const char *name) OS2APIINFO(ord=111,name=gethostbyname);
+OS2EXPORT unsigned short OS2API OS2_htons(unsigned short val) OS2APIINFO(ord=205,name=htons);
+OS2EXPORT char * OS2API OS2_inet_ntoa(OS2_in_addr os2inaddr) OS2APIINFO(ord=110,name=inet_ntoa);
+OS2EXPORT OS2_servent * OS2API OS2_getservbyname(const char *name, const char *proto) OS2APIINFO(ord=124,name=getservbyname);
+OS2EXPORT int OS2API OS2_select(int sock, OS2_fd_set *readfds, OS2_fd_set *writefds, OS2_fd_set *errorfds, OS2_timeval *timeout) OS2APIINFO(ord=32,name=select);
+OS2EXPORT int OS2API OS2_os2_select(int *socks, int noreads, int nowrites, int noexcept, long timeout) OS2APIINFO(ord=12,name=os2_select);
+OS2EXPORT int OS2API OS2_getsockname(int sock, OS2_sockaddr *os2name, int *namelen) OS2APIINFO(ord=6,name=getsockname);
+OS2EXPORT int OS2API OS2_setsockopt(int sock, int os2level, int os2name, const void *value, int len) OS2APIINFO(ord=15,name=setsockopt);
+OS2EXPORT int OS2API OS2_bind(int sock, const OS2_sockaddr *os2name, int os2namelen) OS2APIINFO(ord=2,name=bind);
+OS2EXPORT int OS2API OS2_accept(int sock, OS2_sockaddr *os2name, int *os2namelen) OS2APIINFO(ord=1,name=accept);
+OS2EXPORT int OS2API OS2_Rgetsockname(int sock, OS2_sockaddr *os2name, int *namelen) OS2APIINFO(ord=159,name=Rgetsockname);
+OS2EXPORT int OS2API OS2_Rbind(int sock, OS2_sockaddr *os2name, int os2namelen, OS2_sockaddr *os2remote) OS2APIINFO(ord=157,name=Rbind);
+OS2EXPORT int OS2API OS2_Raccept(int sock, OS2_sockaddr *os2name, int *os2namelen) OS2APIINFO(ord=156,name=Raccept);
+OS2EXPORT int OS2API OS2_Rconnect(int sock, const OS2_sockaddr *os2name, int os2namelen) OS2APIINFO(ord=158,name=Rconnect);
+OS2EXPORT int OS2API OS2_Rlisten(int sock, int backlog) OS2APIINFO(ord=160,name=Rlisten);
+OS2EXPORT OS2_hostent * OS2API OS2_Rgethostbyname(const char *name) OS2APIINFO(ord=161,name=Rgethostbyname);
+OS2EXPORT int OS2API OS2_gettimeofday(OS2_timeval *os2tv, OS2_timezone *os2tz) OS2APIINFO(ord=102,name=gettimeofday);
 
 #ifdef __cplusplus
 }
--- a/native/viocalls-lx.h	Sun Jun 17 00:23:53 2018 -0400
+++ b/native/viocalls-lx.h	Sun Jun 17 22:21:52 2018 -0400
@@ -132,17 +132,17 @@
 }
 
 LX_NATIVE_MODULE_INIT({ if (!init16_viocalls()) return 0; })
-    LX_NATIVE_EXPORT16(VioScrollUp, 7),
-    LX_NATIVE_EXPORT16(VioGetCurPos, 9),
-    LX_NATIVE_EXPORT16(VioWrtCellStr, 10),
-    LX_NATIVE_EXPORT16(VioSetCurPos, 15),
-    LX_NATIVE_EXPORT16(VioGetMode, 21),
-    LX_NATIVE_EXPORT16(VioReadCellStr, 24),
-    LX_NATIVE_EXPORT16(VioGetCurType, 27),
-    LX_NATIVE_EXPORT16(VioGetBuf, 31),
-    LX_NATIVE_EXPORT16(VioSetCurType, 32),
-    LX_NATIVE_EXPORT16(VioWrtCharStrAtt, 48),
-    LX_NATIVE_EXPORT16(VioWrtNCell, 52)
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioScrollUp, "VIOSCROLLUP", 7),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioGetCurPos, "VIOGETCURPOS", 9),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioWrtCellStr, "VIOWRTCELLSTR", 10),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioSetCurPos, "VIOSETCURPOS", 15),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioGetMode, "VIOGETMODE", 21),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioReadCellStr, "VIOREADCELLSTR", 24),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioGetCurType, "VIOGETCURTYPE", 27),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioGetBuf, "VIOGETBUF", 31),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioSetCurType, "VIOSETCURTYPE", 32),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioWrtCharStrAtt, "VIOWRTCHARSTRATT", 48),
+    LX_NATIVE_EXPORT16_DIFFERENT_NAME(VioWrtNCell, "VIOWRTNCELL", 52)
 LX_NATIVE_MODULE_INIT_END()
 
 #endif /* LX_LEGACY */
--- a/native/viocalls.h	Sun Jun 17 00:23:53 2018 -0400
+++ b/native/viocalls.h	Sun Jun 17 22:21:52 2018 -0400
@@ -50,17 +50,17 @@
     USHORT attr;
 } VIOCURSORINFO, *PVIOCURSORINFO;
 
-OS2EXPORT APIRET16 OS2API16 VioGetMode(PVIOMODEINFO pvioModeInfo, HVIO hvio) OS2APIINFO(21);
-OS2EXPORT APIRET16 OS2API16 VioGetCurPos(PUSHORT pusRow, PUSHORT pusColumn, HVIO hvio) OS2APIINFO(9);
-OS2EXPORT APIRET16 OS2API16 VioGetBuf(PULONG pLVB, PUSHORT pcbLVB, HVIO hvio) OS2APIINFO(31);
-OS2EXPORT APIRET16 OS2API16 VioGetCurType(PVIOCURSORINFO pvioCursorInfo, HVIO hvio) OS2APIINFO(27);
-OS2EXPORT APIRET16 OS2API16 VioScrollUp(USHORT usTopRow, USHORT usLeftCol, USHORT usBotRow, USHORT usRightCol, USHORT cbLines, PBYTE pCell, HVIO hvio) OS2APIINFO(7);
-OS2EXPORT APIRET16 OS2API16 VioSetCurPos(USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(15);
-OS2EXPORT APIRET16 OS2API16 VioSetCurType(PVIOCURSORINFO pvioCursorInfo, HVIO hvio) OS2APIINFO(32);
-OS2EXPORT APIRET16 OS2API16 VioReadCellStr(PCH pchCellStr, PUSHORT pcb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(24);
-OS2EXPORT APIRET16 OS2API16 VioWrtCellStr(PCH pchCellStr, USHORT cb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(10);
-OS2EXPORT APIRET16 OS2API16 VioWrtCharStrAtt(PCH pch, USHORT cb, USHORT usRow, USHORT usColumn, PBYTE pAttr, HVIO hvio) OS2APIINFO(48);
-OS2EXPORT APIRET16 OS2API16 VioWrtNCell(PBYTE pCell, USHORT cb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(52);
+OS2EXPORT APIRET16 OS2API16 VioGetMode(PVIOMODEINFO pvioModeInfo, HVIO hvio) OS2APIINFO(ord=21,name=VIOGETMODE);
+OS2EXPORT APIRET16 OS2API16 VioGetCurPos(PUSHORT pusRow, PUSHORT pusColumn, HVIO hvio) OS2APIINFO(ord=9,name=VIOGETCURPOS);
+OS2EXPORT APIRET16 OS2API16 VioGetBuf(PULONG pLVB, PUSHORT pcbLVB, HVIO hvio) OS2APIINFO(ord=31,name=VIOGETBUF);
+OS2EXPORT APIRET16 OS2API16 VioGetCurType(PVIOCURSORINFO pvioCursorInfo, HVIO hvio) OS2APIINFO(ord=27,name=VIOGETCURTYPE);
+OS2EXPORT APIRET16 OS2API16 VioScrollUp(USHORT usTopRow, USHORT usLeftCol, USHORT usBotRow, USHORT usRightCol, USHORT cbLines, PBYTE pCell, HVIO hvio) OS2APIINFO(ord=7,name=VIOSCROLLUP);
+OS2EXPORT APIRET16 OS2API16 VioSetCurPos(USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(ord=15,name=VIOSETCURPOS);
+OS2EXPORT APIRET16 OS2API16 VioSetCurType(PVIOCURSORINFO pvioCursorInfo, HVIO hvio) OS2APIINFO(ord=32,name=VIOSETCURTYPE);
+OS2EXPORT APIRET16 OS2API16 VioReadCellStr(PCH pchCellStr, PUSHORT pcb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(ord=24,name=VIOREADCELLSTR);
+OS2EXPORT APIRET16 OS2API16 VioWrtCellStr(PCH pchCellStr, USHORT cb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(ord=10,name=VIOWRTCELLSTR);
+OS2EXPORT APIRET16 OS2API16 VioWrtCharStrAtt(PCH pch, USHORT cb, USHORT usRow, USHORT usColumn, PBYTE pAttr, HVIO hvio) OS2APIINFO(ord=48,name=VIOWRTCHARSTRATT);
+OS2EXPORT APIRET16 OS2API16 VioWrtNCell(PBYTE pCell, USHORT cb, USHORT usRow, USHORT usColumn, HVIO hvio) OS2APIINFO(ord=52,name=VIOWRTNCELL);
 
 #ifdef __cplusplus
 }