This is the mail archive of the
gsl-discuss@sourceware.cygnus.com
mailing list for the GSL project.
extern "C" compromise?
- To: GSL mailing list <gsl-discuss at sourceware dot cygnus dot com>
- Subject: extern "C" compromise?
- From: David Morrison <dave at bnl dot gov>
- Date: Sun, 12 Mar 2000 14:28:20 -0500
Hi all,
The conviction that the GSL header files ought to contain their own
'extern "C"' statements doesn't seem to be gaining traction (though I
don't think I'm alone in my views), but would it deeply offend anyone to
keep a perl script to do the trick alongside the sources in the CVS
repo? I've attached the little script I use to do this - it darts about
in my working copy of the sources and modifies all the `gsl_*.h' files.
This seems to me to be a compromise pretty much in the same spirit as
the existing libtoolswitch.pl script.
Cheers,
Dave
#!/usr/bin/perl
use File::Find;
find(\&wanted, '.');
sub wanted {
my $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size;
my $atime,$mtime,$ctime,$blksize,$blocks;
my $filename, @lines, $i;
return unless /^gsl_.*\.h/;
$filename = "$_";
rename "$filename", "$filename.bak";
# slurp the whole file into an array
open(IN, "$filename.bak");
@lines = <IN>;
close(IN);
# insert the `extern "C" {' stuff after the first #define
push @lines, "#define";
$i = 0;
while (! ($lines[$i] =~ /^#define/)) {$i++;}
if ($i == $#lines) {
$i = 0;
}
splice (@lines, $i+1, 0,
"\n",
"#ifdef __cplusplus\n",
"extern \"C\" {\n",
"#endif\n");
pop @lines;
# insert the `}' stuff before the last #endif
unshift @lines, "#endif";
$i = $#lines;
while (! ($lines[$i] =~ /^#endif/)) {$i--;}
if ($i == 0) {
$i = $#lines+1;
}
splice (@lines, $i, 0,
"#ifdef __cplusplus\n",
"}\n",
"#endif\n",
"\n");
shift @lines;
open(OUT, ">$filename");
print OUT @lines;
close(OUT);
}
--
David Morrison Brookhaven National Laboratory phone: 631-344-5840
Physics Department, Bldg 510 C fax: 631-344-3253
Upton, NY 11973-5000 email: dave@bnl.gov