lxapigen.pl
author Ryan C. Gordon <icculus@icculus.org>
Tue, 27 Feb 2018 03:25:21 -0500
changeset 103 0aaa6d47f023
child 114 23577dfa3fad
permissions -rwxr-xr-x
Automate handling of support code for OS/2 binaries. Now a perl script parses our headers and generates glue code, export tables, etc. This automates all the macro nonsense and bridge code, and separates out all the stuff you need for binary compat with OS/2, so you can remove it all from the build if you want to just build native libraries that supply the OS/2 API to native apps (like Winelib vs Wine). This makes upkeep details less nasty, and easier to build native binaries when implementing and improving APIs, so you can debug directly without a lot of drama.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
103
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#!/usr/bin/perl -w
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
use warnings;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
use strict;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
my %typesizes = (
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
    'LONG' => 4,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
    'ULONG' => 4,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
    'SHORT' => 2,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
    'USHORT' => 2,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
    'HVIO' => 2,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
    'HKBD' => 2,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
sub typesize {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    my $t = shift;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    return 4 if ($t =~ /\AP/);  # pointers are 4 bytes (16:16).
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
    die("Unknown type '$t', please update \%typesizes\n") if not defined $typesizes{$t};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    return $typesizes{$t};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
}
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
my $dirname = defined $ARGV[0] ? $ARGV[0] : 'native';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
opendir(DIRH, $dirname) or die("Failed to opendir '$dirname': $!\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
while (readdir(DIRH)) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    next if not /\.h\Z/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    next if /\Aos2/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
    next if /\-lx\.h\Z/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
    my $module = $_;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
    my $header = "$dirname/$module";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    $module =~ s/\.h\Z//;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    open(IN, '<', $header) or die("Failed to open '$header' for reading: $!\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    print("$module ...\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    my %ordinalmap = ();
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    my $has16bitfns = 0;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    while (<IN>) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        chomp;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
        next if not /OS2APIINFO/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        my $line = $_;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        if (/\AOS2EXPORT\s+(.*?)\s+(OS2API|OS2API16)\s+(.*?)\((.*?)\)\s+OS2APIINFO\((.*?)\);/) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
            my %table = (
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
                'rettype' => $1,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
                'apitype' => $2,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
                'fn' => $3,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
                'args' => $4,
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
            );
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
            my $apiinfo = $5;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
            my $is16bit = $table{'apitype'} eq 'OS2API16';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
            $table{'is16bit'} = $is16bit;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
            $has16bitfns |= $is16bit;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
            #print("rettype='$rettype' fn='$fn' args='$args' apiinfo='$apiinfo'\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
            my $fn = $table{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
            my $ordinal;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
            if ($apiinfo =~ /\A(\d+)\Z/) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
                $ordinal = int($1);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            } else {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
                die("bogus OS2APIINFO for '$fn'\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
            $table{'ordinal'} = $ordinal;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
            if (defined $ordinalmap{$ordinal}) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
                my $dupfn = $ordinalmap{$ordinal}{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
                die("Duplicate ordinal #$ordinal between '$fn' and '$dupfn'\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            $ordinalmap{$ordinal} = \%table;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        } else {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
            die ("Couldn't parse:\n\n  $line\n\n")
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    close(IN);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    next if (not %ordinalmap);  # no exported items?
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
    #use Data::Dumper qw(Dumper); print Dumper \%ordinalmap;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    # Here we go...
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    my $outfname = "$dirname/$module-lx.h";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    open(OUT, '>', $outfname) or die("Failed to open '$outfname' for writing: $!\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    print OUT <<EOF
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
/**
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
 * 2ine; an OS/2 emulator for Linux.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
 *
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
 * Please see the file LICENSE.txt in the source's root directory.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
 */
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
/* THIS FILE IS AUTOGENERATED. DO NOT EDIT BY HAND. see lxapigen.pl */
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
/* This is glue code for OS/2 binaries. Native binaries don't need this. */
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
#if LX_LEGACY
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
EOF
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    foreach (sort { $a <=> $b } keys(%ordinalmap) ) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
        my $tableref = $ordinalmap{$_};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
        my $fn = $tableref->{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
        my $argstr = $tableref->{'args'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
        my $rettype = $tableref->{'rettype'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
        my $is16bit = $tableref->{'is16bit'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
        my @args = ();
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        if (($argstr ne 'VOID') and ($argstr ne 'void')) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            @args = split /,/, $argstr;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        # Build a little wrapper that'll pull arguments off the stack and
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        #  convert to whatever the native calling conventions are.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        if ($is16bit) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
            print OUT "static $rettype bridge16to32_$fn(uint8 *args) {\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
            #foreach (@args) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
            # arguments are listed backwards here.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
            for my $i (reverse 0..$#args) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
                my $arg = $args[$i];
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
                my ($t, $n) = $arg =~ /\A\s*(.*?)\s+(.*?)\s*\Z/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
                #print("arg='$_' t='$t' n='$n'\n");
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
                my $a = ($t =~ /\AP/) ? 'PTRARG' : 'ARG';  # it's a pointer?
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
                print OUT "    LX_NATIVE_MODULE_16BIT_BRIDGE_$a($t, $n);\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
            print OUT "    ";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
            if (($rettype ne 'void') && ($rettype ne 'VOID')) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
                # Currently it's reasonable to assume the retval will land in EAX.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
                print OUT "return ";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
            print OUT "$fn(";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
            my $comma = '';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
            foreach (@args) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
                my ($t, $n) = /\A\s*(.*?)\s+(.*?)\s*\Z/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
                print OUT "$comma$n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
                $comma = ', ';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
            print OUT ");\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
            print OUT "}\n\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    if ($has16bitfns) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        print OUT "LX_NATIVE_MODULE_16BIT_SUPPORT()\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        foreach (sort { $a <=> $b } keys(%ordinalmap) ) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
            my $tableref = $ordinalmap{$_};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
            next if not $tableref->{'is16bit'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
            my $fn = $tableref->{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
            print OUT "    LX_NATIVE_MODULE_16BIT_API($fn)\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
        print OUT "LX_NATIVE_MODULE_16BIT_SUPPORT_END()\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
        print OUT "\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
        print OUT "LX_NATIVE_MODULE_DEINIT({\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
        print OUT "    LX_NATIVE_MODULE_DEINIT_16BIT_SUPPORT();\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
        print OUT "})\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        print OUT "\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
        print OUT "static int init16_$module(void) {\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        print OUT "    LX_NATIVE_MODULE_INIT_16BIT_SUPPORT()\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        foreach (sort { $a <=> $b } keys(%ordinalmap) ) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
            my $tableref = $ordinalmap{$_};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
            next if not $tableref->{'is16bit'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
            my $fn = $tableref->{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
            my $argstr = $tableref->{'args'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
            my $argbytes = 0;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
            my @args = ();
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
            if (($argstr ne 'VOID') and ($argstr ne 'void')) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
                @args = split /,/, $argstr;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
            foreach (@args) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
                my ($t, $n) = /\A\s*(.*?)\s+(.*?)\s*\Z/;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
                $argbytes += typesize($t);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
            }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
            print OUT "        LX_NATIVE_INIT_16BIT_BRIDGE($fn, $argbytes)\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
        print OUT "    LX_NATIVE_MODULE_INIT_16BIT_SUPPORT_END()\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        print OUT "    return 1;\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
        print OUT "}\n\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    print OUT "LX_NATIVE_MODULE_INIT(";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    if ($has16bitfns) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        print OUT "{ if (!init16_$module()) return 0; }";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    print OUT ")\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    my $comma = '';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    foreach (sort { $a <=> $b } keys(%ordinalmap) ) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
        my $tableref = $ordinalmap{$_};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
        my $fn = $tableref->{'fn'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
        my $ordinal = $tableref->{'ordinal'};
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
        my $suffix = $tableref->{'is16bit'} ? '16' : '';
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        print OUT $comma;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
        # This is a hack for tcpip32, which doesn't want to step on BSD sockets symbols.
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
        if ($fn =~ /\AOS2_(.*)\Z/) {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
            print OUT "    LX_NATIVE_EXPORT_DIFFERENT_NAME($fn, \"$1\", $ordinal)";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
        } else {
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
            print OUT "    LX_NATIVE_EXPORT$suffix($fn, $ordinal)";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
        }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        $comma = ",\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    }
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    print OUT "\n";
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    print OUT <<EOF
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
LX_NATIVE_MODULE_INIT_END()
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
#endif /* LX_LEGACY */
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
/* end of $module-lx.h ... */
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
EOF
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
;
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
    close(OUT);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
}
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
closedir(DIRH);
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
# end of lxapigen.pl ...
0aaa6d47f023 Automate handling of support code for OS/2 binaries.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235