6 # This script is called from the makefile. It reads the settings file and
7 # inserts the information in the source files.
9 # Copyright (C) 2015-2017 Balthasar SzczepaĆski
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as
13 # published by the Free Software Foundation, either version 3 of the
14 # License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Affero General Public License for more details.
21 # You should have received a copy of the GNU Affero General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 print STDERR "Configfile missing.\n";
29 unless (open $configfile, "<", $ARGV[0]) {
30 print STDERR "Cannot open configfile\n";
34 # Read the config file, line format:
35 # some_name = some value # some comment
36 while (defined(my $line = <$configfile>)) {
38 $line =~ s/#.*$//; #comment
39 if ($line =~ /^[ \t]*([a-zA-Z0-9_\-\.]+)[ \t]*=[ \t]*([^ \t](.*[^ \t])?)[ \t]*$/){
47 # Now generate things to be inserted.
49 $def{'GZIP_PATH'} = "use constant GZIP_PATH => '".$set{'gzip'}."';";
50 $def{'LOG_PATH'} = "use constant LOG_PATH => '".$set{'log_path'}."';";
52 $def{'DATA_PATH'} = "use constant DATA_PATH => '".$set{'data_path'}."';";
53 $def{'DEFAULT_PATH'} = "use constant DEFAULT_PATH => '".$set{'data_path'}."default';";
54 $def{'SETTINGS_PATH'} = "use constant SETTINGS_PATH => '".$set{'data_path'}."settings';";
55 $def{'NOACCESS_PATH'} = "use constant NOACCESS_PATH => '".$set{'data_path'}."noaccess';";
56 $def{'STATE_PATH'} = "use constant STATE_PATH => '".$set{'data_path'}."state';";
57 $def{'STORY_PATH'} = "use constant STORY_PATH => '".$set{'data_path'}."story';";
58 $def{'CHAT_PATH'} = "use constant CHAT_PATH => '".$set{'data_path'}."chat';";
59 $def{'COIN_PATH'} = "use constant COIN_PATH => '".$set{'data_path'}."coincidence';";
60 $def{'LIST_PATH'} = "use constant LIST_PATH => '".$set{'data_path'}."list';";
61 $def{'WWW_PATH'} = "use constant WWW_PATH => '".$set{'www_path'}."';";
62 $def{'INDEX_PATH'} = "use constant INDEX_PATH => '".$set{'www_path'}."index.htm';";
63 $def{'CGI_PATH'} = "use constant CGI_PATH => '".$set{'cgi_path'}."';";
64 $def{'CSS_PATH'} = "use constant CSS_PATH => '".$set{'cgi_path'}."bsta.css';";
65 $def{'LOGO_PATH'} = "use constant LOGO_PATH => '".$set{'cgi_path'}."botmlogo.png';";
66 $def{'FRAME_PATH'} = "use constant FRAME_PATH => '".$set{'cgi_path'}."f';";
67 $def{'VIEWER_PATH'} = "use constant VIEWER_PATH => '".$set{'cgi_path'}."v';";
68 $def{'ATTACH_PATH'} = "use constant ATTACH_PATH => '".$set{'cgi_path'}."a';";
69 $def{'INFO_PATH'} = "use constant INFO_PATH => '".$set{'cgi_path'}."i';";
70 $def{'BBCODE_PATH'} = "use constant BBCODE_PATH => '".$set{'cgi_path'}."b';";
71 $def{'GOTO_PATH'} = "use constant GOTO_PATH => '".$set{'cgi_path'}."g';";
72 $def{'TWOWORDS_PATH'} = "use constant TWOWORDS_PATH => '".$set{'cgi_path'}."2words';";
73 $def{'COINCIDENCE_PATH'} = "use constant COINCIDENCE_PATH => '".$set{'cgi_path'}."coin';";
74 $def{'TIMER_PATH'} = "use constant TIMER_PATH => '".$set{'cgi_path'}."timer.js';";
75 $def{'FAVICON_PATH'} = "use constant FAVICON_PATH => '".$set{'favicon_path'}."';";
76 $def{'WEBSITE'} = "use constant WEBSITE => '".$set{'website'}."';";
77 $def{'WEBSITE_NAME'} = "use constant WEBSITE_NAME => '".$set{'website_name'}."';";
78 $def{'INTF_DATE'} = "use constant INTF_DATE => '".$set{'intf_date'}."';";
79 $def{'COIN_DATE'} = "use constant COIN_DATE => '".$set{'coin_date'}."';";
80 $def{'LOG_SIZE_LIMIT'} = "use constant LOG_SIZE_LIMIT => ".$set{'log_size_limit'}.";";
81 $def{'LOGS_UNCOMPRESSED'} = "use constant LOGS_UNCOMPRESSED => ".$set{'logs_uncompressed'}.";";
82 $def{'LOGS_TOTAL'} = "use constant LOGS_TOTAL => ".$set{'logs_total'}.";";
83 $def{'STORY_LENGTH'} = "use constant STORY_LENGTH => ".int($set{'story_length'}).";";
84 $def{'PAGE_LENGTH'} = "use constant PAGE_LENGTH => ".int($set{'page_length'}).";";
85 $def{'FIRSTPAGE_LENGTH'} = "use constant FIRSTPAGE_LENGTH => ".int($set{'firstpage_length'}).";";
87 $def{'VIEWER_ALIAS'} = 'ScriptAlias '.$set{'cgi_path'}.'v '.$set{'bin_path'}.'viewer';
88 $def{'FRAME_ALIAS' } = 'ScriptAlias '.$set{'cgi_path'}.'v '.$set{'bin_path'}.'frame';
90 $def{'LIB'} = "use lib '".$set{'lib_path'}."';";
92 $def{'PATH'} = "\$ENV{'PATH'} = '".$set{'path'}."';";
94 $def{'PERL'} = "#!".$set{'perl'};
96 $def{'FRAME_PL'} = '#define FRAME_PL "'.$set{'bin_path'}.'frame.pl"';
97 $def{'VIEWER_PL'} = '#define VIEWER_PL "'.$set{'bin_path'}.'viewer.pl"';
98 $def{'ATTACH_PL'} = '#define ATTACH_PL "'.$set{'bin_path'}.'attach.pl"';
99 $def{'TWOWORDS_PL'} = '#define TWOWORDS_PL "'.$set{'bin_path'}.'2words.pl"';
100 $def{'CHAT_PL'} = '#define CHAT_PL "'.$set{'bin_path'}.'chat.pl"';
101 $def{'INFO_PL'} = '#define INFO_PL "'.$set{'bin_path'}.'info.pl"';
102 $def{'GOTO_PL'} = '#define GOTO_PL "'.$set{'bin_path'}.'goto.pl"';
103 $def{'BBCODE_PL'} = '#define BBCODE_PL "'.$set{'bin_path'}.'bbcode.pl"';
104 $def{'FRAME_PL_ERRLOG'} = '#define FRAME_PL_ERRLOG "'.$set{'log_path'}.'frame-stderr.log"';
105 $def{'VIEWER_PL_ERRLOG'} = '#define VIEWER_PL_ERRLOG "'.$set{'log_path'}.'viewer-stderr.log"';
106 $def{'ATTACH_PL_ERRLOG'} = '#define ATTACH_PL_ERRLOG "'.$set{'log_path'}.'attach-stderr.log"';
107 $def{'TWOWORDS_PL_ERRLOG'} = '#define TWOWORDS_PL_ERRLOG "'.$set{'log_path'}.'2words-stderr.log"';
108 $def{'CHAT_PL_ERRLOG'} = '#define CHAT_PL_ERRLOG "'.$set{'log_path'}.'chat-stderr.log"';
109 $def{'INFO_PL_ERRLOG'} = '#define INFO_PL_ERRLOG "'.$set{'log_path'}.'info-stderr.log"';
110 $def{'GOTO_PL_ERRLOG'} = '#define GOTO_PL_ERRLOG "'.$set{'log_path'}.'goto-stderr.log"';
111 $def{'BBCODE_PL_ERRLOG'} = '#define BBCODE_PL_ERRLOG "'.$set{'log_path'}.'bbcode-stderr.log"';
113 $def{'CC'} = 'CC='.$set{'gcc'};
114 $def{'CF'} = 'CF='.$set{'c_flags'};
115 $def{'PL'} = 'PL='.$set{'perl'};
116 $def{'MV'} = 'MV='.$set{'mv'};
117 $def{'CP'} = 'CP='.$set{'cp'};
118 $def{'RM'} = 'RM='.$set{'rm'};
119 $def{'OD'} = 'OD='.$set{'bin_path'};
120 $def{'LD'} = 'LD='.$set{'lib_path'};
121 $def{'WD'} = 'WD='.$set{'www_path'};
122 $def{'CM'} = 'CM='.$set{'chmod'};
125 # Now go through input file, find lines to be replaced. Format:
127 # If found - replace.
129 while (defined($line = <STDIN>)) {
130 $line =~ s/[\r\n]//g;
131 if ($line =~ /###([a-zA-Z0-9_]+);/) {