1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#!/usr/bin/perl
##############################################################################
# #
# UNURAN -- Universal Non-Uniform Random number generator #
# #
##############################################################################
# #
# FILE: make_urng_header.pl #
# #
# Make header file for UNU.RAN wrapper functions for external URNGs #
# #
##############################################################################
# #
# Copyright (c) 2000-2006 Wolfgang Hoermann and Josef Leydold #
# Department of Statistics and Mathematics, WU Wien, Austria #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA #
# #
##############################################################################
use strict;
my $DEBUG = 0;
############################################################
sub usage {
my $progname = $0;
$progname =~ s#^.*/##g;
print STDERR <<EOM;
usage: $progname <file1> [<file2> ...]
Create header file for wrappers for external URNGs
EOM
exit -1;
}
############################################################
# year
my $year = 1900 + (localtime(time))[5];
# content of files
my $out = '';
# copyright statment
my $copyright =
"/*******************************************************************\\\n".
" * *\n".
" * UNU.RAN -- Universal Non-Uniform Random number generator *\n".
" * *\n".
" *******************************************************************\n".
" * Copyright (c) 2000-$year Wolfgang Hoermann and Josef Leydold *\n".
" * Department of Statistics and Mathematics, WU Wien, Austria *\n".
"\\*******************************************************************/\n";
my $CPP_header =
"#undef __BEGIN_DECLS\n".
"#undef __END_DECLS\n".
"#ifdef __cplusplus\n".
"# define __BEGIN_DECLS extern \"C\" {\n".
"# define __END_DECLS }\n".
"#else\n".
"# define __BEGIN_DECLS /* empty */\n".
"# define __END_DECLS /* empty */\n".
"#endif\n".
"\n".
"__BEGIN_DECLS\n\n";
my $CPP_bottom =
"__END_DECLS\n";
# marker
my $marker = '';
# read file name from argument list ...
while (my $file = shift) {
# open file ...
open IN, $file or die "cannot open file $file\n";
# do we have to define a marker?
unless ($marker) {
$marker = "UNURAN_" . uc($file) . "_SEEN";
$marker =~ s/\W/\_/g;
}
# read file ...
my $content = '';
while (<IN>) { $content .= $_; }
close IN;
# remove all comments and empty lines ...
$content =~ s {/\*.*?\*/} []gsx;
$content =~ s /\n\s*\n/\n/gsx;
# remove ifdef ...H_SEEN
if ($content =~ /\#ifndef URNG_.*_H_SEEN/) {
$content =~ s {\#ifndef\s+URNG_.*_H_SEEN\s+\#define\s+URNG_.*_H_SEEN\s*\n} []gsx;
$content =~ s /\#endif\s+$//gsx;
}
# add to output
$out .= $content;
}
print $copyright .
$CPP_header .
"\#ifndef $marker\n" .
"\#define $marker\n" .
$out .
"\#endif /* $marker */\n" .
$CPP_bottom;
# end
exit 0;
############################################################
|