# HG changeset patch # User anatofuz # Date 1582787860 -32400 # Node ID a9aba14b2b6a923b8559a16e2568d237fb224338 # Parent 1a63c120f2bada3dda785118731206dcb880c98e add static_gen_header script diff -r 1a63c120f2ba -r a9aba14b2b6a src/gearsTools/static_gen_header.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gearsTools/static_gen_header.pl Thu Feb 27 16:17:40 2020 +0900 @@ -0,0 +1,81 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +=head1 DESCRIPTION + +emit Gears header files + +=head1 SYNOPSIS + + % sample.pl --interface list + % sample.pl --impl single_linked_list --interface list + % sample.pl -w --interface list + +=cut + +use Getopt::Long qw/:config posix_default no_ignore_case bundling auto_help/; + +use Pod::Usage qw/pod2usage/; + +GetOptions( + \my %opt, qw/ + interface=s + impl=s + o=s + w +/) or pod2usage(1); + + +unless ($opt{interface}) { + pod2usage(1); +} + +my ($type, $msg); + +if ($opt{impl}) { + $msg = emit_impl_header($opt{interface}, $opt{impl}); + $type = $opt{impl}; +} else { + $msg = emit_interface_header($opt{interface}); + $type = $opt{interface}; +} + +$msg .= emit_last($type); + +unless ($opt{w} || $opt{o}) { + print $msg; + exit 0; +} + +my $emit_file; + +if ($opt{o}) { + $emit_file = $opt{o}; +} else { + $emit_file = "$type.h" +} + + +open my $fh, '>', $emit_file; +print $fh $msg; +close $fh; + +sub emit_interface_header { + my $interface_name = shift; + return "typedef struct $interface_name {\n"; +} + +sub emit_impl_header { + my ($interface_name, $impl_name) = @_; + return "typedef struct $impl_name impl $interface_name {\n"; +} + +sub emit_last { + my $type = shift; + my $msg = <<"EOF"; + __code next(....); +} $type; +EOF + return $msg; +} diff -r 1a63c120f2ba -r a9aba14b2b6a src/types.h --- a/src/types.h Thu Feb 27 15:54:33 2020 +0900 +++ b/src/types.h Thu Feb 27 16:17:40 2020 +0900 @@ -7,4 +7,4 @@ #ifndef NULL #define NULL ((void*)0) -#endif \ No newline at end of file +#endif