Menu

[e85c93]: / generate.pl.in  Maximize  Restore  History

Download this file

103 lines (72 with data), 2.3 kB

BEGIN {

  $srcdir = shift;

};

if( /LIBSPECTRUM_AUTOGEN_WARNING/ ) {
  $_ = << "CODE";
/* NB: This file is autogenerated from libspectrum.h.in. Do not edit
   unless you know what you're doing */
CODE
}

if( /LIBSPECTRUM_SNAP_ACCESSORS/ ) {

  open( DATAFILE, '<' . "${srcdir}/snap_accessors.txt" ) or die "Couldn't open `snap_accessors.txt': $!";

  $_ = '';
  while( <DATAFILE> ) {

    # Blank lines
    next if /^\s*$/;

    # Perl comments
    next if /^\s*#/;

    # Leading C comments
    next if /^\s*\/\*/;

    # Trailing C comments
    s/\/\*(.*)\*\///;

    my( $type, $name, $indexed ) = split;

    my $return_type;
    if( $type =~ /^(.*)\*/ ) {
	$return_type = "LIBSPECTRUM_API $1 *";
    } else {
	$return_type = "LIBSPECTRUM_API $type";
    }

    if( $indexed ) {

	print << "CODE";
$return_type libspectrum_snap_$name( libspectrum_snap *snap, int idx );
LIBSPECTRUM_API void libspectrum_snap_set_$name( libspectrum_snap *snap, int idx, $type $name );
CODE

    } else {

	print << "CODE";
$return_type libspectrum_snap_$name( libspectrum_snap *snap );
LIBSPECTRUM_API void libspectrum_snap_set_$name( libspectrum_snap *snap, $type $name );
CODE

    }
  }
}

if( /LIBSPECTRUM_TAPE_ACCESSORS/ ) {

    open( DATAFILE, '<' . "${srcdir}/tape_accessors.txt" )
	or die "Couldn't open `tape_accessors.txt': $!";

    $_ = '';
    while( <DATAFILE> ) {

	# Remove comments and blank lines
	s/#.*//;
	next if /^\s*$/;

	# Skip which block types each accessor applies to
	next if /^\s/;
	
	my( $type, $name, $indexed, undef ) = split;
	
	my $return_type;
	if( $type =~ /^(.*)\*/ ) {
	    $return_type = "LIBSPECTRUM_API $1 *";
	} else {
	    $return_type = "LIBSPECTRUM_API $type";
	}

	if( $indexed ) {

	  print << "CODE";
$return_type libspectrum_tape_block_$name( libspectrum_tape_block *block, size_t idx );
LIBSPECTRUM_API libspectrum_error libspectrum_tape_block_set_$name( libspectrum_tape_block *block, $type \*$name );
CODE

	} else {

	print << "CODE";
$return_type libspectrum_tape_block_$name( libspectrum_tape_block *block );
LIBSPECTRUM_API libspectrum_error libspectrum_tape_block_set_$name( libspectrum_tape_block *block, $type $name );
CODE
    
	}
    }

    close DATAFILE or die "Couldn't close `tape_accessors.txt': $!";
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.