summaryrefslogtreecommitdiff
path: root/scripts/config.sh
blob: f301246352f33832cd7280ff7135b493dc7b3ea9 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# The yhttpd Project (2004)
#
# This script modifues the src/glob.h file.

if ! which perl >/dev/null
then
 echo You need to have Perl in your PATH
 exit 1
fi

perl -e '
 use strict;

 use scripts::modules::file;

print <<END;
Welcome to the yhttpd configurator!
You may also edit the src/glob.h file manually instead of using 
this configurator option. Please also notice that this are only
before-compile options. All setups which can be made after com-
iling are placed in the yhttpd configuration file. 
END
 
 my $sep = "================================================================\n"; my $stdin;

for (;;)
 {
  print "$sep Do you want to use the default before-compile options?\n";
  print " (yes/no) [default is NO] ";
  $stdin = <STDIN>;
  chomp $stdin;
  prove_if_default(\$stdin);
  print "\n";

 
  if ( $stdin eq "yes")
  {
   print " You chose to use all the default before-compile options. Exiti-\n";
   print " ng the configurator now!\n";    
   print $sep;
   exit(0);
  }
  last if $stdin eq "no" or $stdin eq "";
  print " Wrong input: You need to specify yes or no!\n";
 } # for

 `cp src/glob.h src/glob.h.org`
   unless -f "src/glob.h.org";

 my @glob = fopen("src/glob.h.org");
 my $flag = 0;

 foreach( @glob ) 
 {
  if ( $flag == 0 && /- CONFIG -/ )
  {
   print $sep;
   $flag = 1;
   next;
  } 

  elsif ( $flag == 1 )
  {
   if ( /\*\// )
   {
    $flag = 2;
   }

   else 
   {
    print;
   }  

   next;
  }

  elsif ( $flag == 2 )
  {
   if ( /#define (.+) (.+)/ )
   {
    my $def = $1;
    my $val = $2;
    my $flg = 0;
 
    $flg = 1 if $val =~ s/"//g;

    print " [Press enter to use default value: $val] ";
    $stdin = <STDIN>;
    chomp $stdin;

    unless ( prove_if_default(\$stdin) )
    {
     $stdin = "\"$stdin\"" if $flg == 1;
     $_ = "#define $def $stdin\n";
    }
    
    print "\n";
    $flag = 0;
    next;
   } 

   elsif ( /#define .+/ ) 
   {
    my $default = "true";
    my $stdin;

    for (;;)
    {
     $default = "false" if /\/\/#define/;

     print " [Press enter to use default value: $default] ";
     $stdin = <STDIN>;
     chomp $stdin; 

     last if $stdin eq "" || $stdin eq "true" || $stdin eq "false";
     print " Wrong input: You need to specify true or false!\n";
    }

    if ( $default eq "true" )
    {
     $_ = "//$_"
      unless prove_if_default(\$stdin);
    }

    else
    {
     s/^\/\/// 
      unless prove_if_default(\$stdin);
    }
   
    print "\n";
    $flag = 0;
    next;
   } 
  }
 } // foreach

 fwrite("src/glob.h", @glob);
 
 sub prove_if_default
 {
  my $val = shift;
  if ( $$val eq "" )
  {
   print " -> Using default option!\n";
   return 1;
  }
  print " -> Using new option $$val!\n";
  return 0;
 }
'