Patch from Richard Basch to work around Solaris 8 lacking isblank()
[krb5.git] / src / config / wconfig.pl
1 #! perl
2 $win_flag = "WIN32##";
3 @wflags = ();
4 $mit_specific = 0;
5 @ignore_list = ( "DOS#?#?" );
6
7 foreach $arg (@ARGV) {
8     if ($arg =~ /^-/) { push @wflags, $arg; }
9     if ("--mit" eq $arg) {
10         $mit_specific = 1;
11     } elsif ("--win16" eq $arg) {
12         $win_flag = "WIN16##";
13     } elsif ("--win32" eq $arg) {
14         $win_flag = "WIN32##";
15     } elsif ($arg =~ /^--enable-/) {
16         my($a) = $arg . "##";
17         $a =~ s/^--enable-//;
18         $a =~ tr/a-z/A-Z/;
19         push @ignore_list, $a;
20     } elsif ($arg =~ /^--ignore=/) {
21         my($a) = $arg;
22         $a =~ s/--ignore=//;
23         push @ignore_list, $a;
24     } elsif ($arg =~ /^-/) {
25         print STDERR "Invalid option '$arg'\n";
26         exit 1;
27     } else {
28         if (! defined $dir) {
29             $dir = $arg;
30         }
31     }
32 }
33 push @ignore_list, $win_flag;
34 push @ignore_list, "MIT##" if $mit_specific;
35
36 if ($#wflags >= 0) { printf "WCONFIG_FLAGS=%s\n", join (" ", @wflags); }
37
38 # This has a couple variations from the old wconfig.c.
39 #
40 # The old script wouldn't treat the input strings as regular expressions.
41 # This one does, and actually it builds one regexp, so the strict order of
42 # checks done by wconfig.c no longer applies.
43 #
44 # And the old script would change "##DOS#" to "#", whereas this
45 # version (with the regexp given above) will accept and discard 0, 1
46 # or 2 "#" marks.
47 $sub = "sub do_subst { my (\$a) = shift; \$a =~ s/^##(" . join("|", @ignore_list) . ")//; return \$a; }";
48 #print STDERR $sub, "\n";
49 eval $sub;
50
51 sub process {
52     my $fh = shift;
53     while (<$fh>) {
54         if (/^@/) {
55             # This branch isn't actually used as far as I can tell.
56             print "\n";
57             next;
58         }
59         # Do we want to do any autoconf-style @FOO@ substitutions?
60         # s/@MAINT@/#/g;
61         # Are there any options we might want to set at configure time?
62         print &do_subst($_);
63     }
64 }
65
66 if (defined $dir) {
67     open AUX, "<$dir/win-pre.in" || die "Couldn't open win-pre.in: $!\n";
68     &process(\*AUX);
69     close AUX;
70 }
71 &process(\*STDIN);
72 if (defined $dir) {
73     open AUX, "<$dir/win-post.in" || die "Couldn't open win-post.in: $!\n";
74     &process(\*AUX);
75     close AUX;
76 }
77 exit 0;