Here is a patch, which adds support for tcc's alloca.
[elinks.git] / contrib / conv / conf-links2elinks.pl
blob481e9904e0332970a34d355daf0d90f967773fee
1 #!/usr/bin/perl
2 # This script converts html.cfg and links.cfg files of Links and older ELinks
3 # versions to the new ELinks' elinks.conf. Intended use:
5 # cat .links/html.cfg .links/links.cfg .links/user.cfg |
6 # conf-links2elinks.pl > .elinks/elinks.conf
8 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
9 if $running_under_some_shell;
10 # this emulates #! processing on NIH machines.
11 # (remove #! line above if indigestible)
13 eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
14 # process any FOO=bar switches
16 $[ = 1; # set array base to 1
17 $, = ' '; # set output field separator
18 $\ = "\n"; # set output record separator
20 print <<HEADER
21 # This file was automatically generated by conf-links2elinks.pl -- feel free
22 # to mess around! Note that if you want to see option descriptions here, don't
23 # let ELinks load this file and save options to clean new file and it'll be all
24 # there nicely indented! ;-)
25 HEADER
28 @system_id = qw(unix os2 win32 beos riscos atheos);
30 # get_token() vars
31 $pos = 0;
32 $line = '';
34 while (<>) {
35 chomp; # strip record separator
36 @Fld = split(' ', $_, 9999);
38 ###
39 ### links.conf
40 ###
42 if ($Fld[1] eq 'accesskey_enter') {
43 print 'set document.browse.accesskey.auto_follow = ' . $Fld[2];
45 if ($Fld[1] eq 'accesskey_priority') {
46 print 'set document.browse.accesskey.priority = ' . $Fld[2];
48 if ($Fld[1] eq 'allow_special_files') {
49 print 'set protocol.file.allow_special_files = ' . $Fld[2];
51 if ($Fld[1] eq 'async_dns') {
52 print 'set connection.async_dns = ' . $Fld[2];
54 if ($Fld[1] eq 'color_dirs') {
55 print 'set document.browse.links.color_dirs = ' . $Fld[2];
57 if ($Fld[1] eq 'cookies_accept') {
58 print 'set cookies.accept_policy = ' . $Fld[2];
60 if ($Fld[1] eq 'cookies_paranoid_security') {
61 print 'set cookies.paranoid_security = ' . $Fld[2];
63 if ($Fld[1] eq 'cookies_save') {
64 print 'set cookies.save = ' . $Fld[2];
66 if ($Fld[1] eq 'cookies_resave') {
67 print 'set cookies.resave = ' . $Fld[2];
69 if ($Fld[1] eq 'download_dir') {
70 print 'set document.download.directory = ' . $Fld[2];
72 if ($Fld[1] eq 'download_utime') {
73 print 'set document.download.set_original_time = ' . $Fld[2];
75 if ($Fld[1] eq 'dump_width') {
76 print 'set document.dump.width = ' . $Fld[2];
78 if ($Fld[1] eq 'format_cache_size') {
79 print 'set document.cache.format.size = ' . $Fld[2];
81 if ($Fld[1] eq 'form_submit_auto') {
82 print 'set document.browse.forms.auto_submit = ' . $Fld[2];
84 if ($Fld[1] eq 'form_submit_confirm') {
85 print 'set document.browse.forms.confirm_submit = ' . $Fld[2];
87 if ($Fld[1] eq 'ftp.anonymous_password') {
88 print 'set protocol.ftp.anon_passwd = ' . $Fld[2];
90 if ($Fld[1] eq 'ftp_proxy') {
91 print 'set protocol.ftp.proxy.host = ' . $Fld[2];
93 if ($Fld[1] eq 'http_bugs.allow_blacklist') {
94 print 'set protocol.http.bugs.allow_blacklist = ' . $Fld[2];
96 if ($Fld[1] eq 'http_bugs.bug_302_redirect') {
97 print 'set protocol.http.bugs.broken_302_redirect = ' . $Fld[2];
99 if ($Fld[1] eq 'http_bugs.bug_post_no_keepalive') {
100 print 'set protocol.http.bugs.post_no_keepalive = ' . $Fld[2];
102 if ($Fld[1] eq 'http_bugs.http10') {
103 print 'set protocol.http.bugs.http10 = ' . $Fld[2];
105 if ($Fld[1] eq 'http_proxy') {
106 print 'set protocol.http.proxy.host = ' . $Fld[2];
108 if ($Fld[1] eq 'http_referer') {
109 print 'set protocol.http.referer.policy = ' . $Fld[2];
111 if ($Fld[1] eq 'fake_referer') {
112 print 'set protocol.http.referer.fake = ' . $Fld[2];
114 if ($Fld[1] eq 'enable_global_history') {
115 print 'set document.history.global.enable = ' . $Fld[2];
117 if ($Fld[1] eq 'keep_unhistory') {
118 print 'set document.history.keep_unhistory = ' . $Fld[2];
120 if ($Fld[1] eq 'language') {
121 print 'set ui.language = ' . $Fld[2];
123 if ($Fld[1] eq 'max_connections') {
124 print 'set connection.max_connections = ' . $Fld[2];
126 if ($Fld[1] eq 'max_connections_to_host') {
127 print 'set connection.max_connections_to_host = ' . $Fld[2];
129 if ($Fld[1] eq 'memory_cache_size') {
130 print 'set document.cache.memory.size = ' . $Fld[2];
132 if ($Fld[1] eq 'receive_timeout') {
133 print 'set connection.receive_timeout = ' . $Fld[2];
135 if ($Fld[1] eq 'retries') {
136 print 'set connection.retries = ' . $Fld[2];
138 if ($Fld[1] eq 'show_status_bar') {
139 print 'set ui.show_status_bar = ' . $Fld[2];
141 if ($Fld[1] eq 'show_title_bar') {
142 print 'set ui.show_title_bar = ' . $Fld[2];
144 if ($Fld[1] eq 'unrestartable_receive_timeout') {
145 print 'set connection.unrestartable_receive_timeout = ' . $Fld[2];
147 if ($Fld[1] eq 'user_agent') {
148 print 'set protocol.http.user_agent = ' . $Fld[2];
150 if ($Fld[1] eq 'terminal') {
151 $Fld[2] = substr($Fld[2], 2, length($Fld[2]) - 2);
152 print 'set terminal.' . $Fld[2] . '.type = ' . $Fld[4];
153 print 'set terminal.' . $Fld[2] . '.m11_hack = ' . $Fld[4];
154 print 'set terminal.' . $Fld[2] . '.utf_8_io = ' . (($Fld[7] eq '') ? '0' : '1');
155 print 'set terminal.' . $Fld[2] . '.restrict_852 = ' . (!(!($Fld[5] & 2))+0);
156 print 'set terminal.' . $Fld[2] . '.block_cursor = ' . (!(!($Fld[5] & 4))+0);
157 print 'set terminal.' . $Fld[2] . '.colors = ' . (!(!($Fld[5] & 1))+0);
158 print 'set terminal.' . $Fld[2] . '.charset = "' . $Fld[6] . '"';
160 if ($Fld[1] eq 'extension') {
161 $num_exts = (@ext = split(/, */, substr($Fld[2], 2, length($Fld[2]) - 2), 9999));
162 for ($i = $num_exts; $i; --$i) {
163 $ext[$i] =~ s/\./*/g;
164 print 'set mime.extension.' . $ext[$i] . ' = ' . $Fld[3];
167 if ($Fld[1] eq 'association') {
168 $pos = length($Fld[1]) + 2;
169 $line = $_;
171 $name = &get_token();
172 $name = substr($name, 2, length($name) - 2);
173 $name =~ s/[ \t]/_/g;
174 $name =~ s/[^a-zA-Z0-9_]/-/g;
176 $mimelist = &get_token();
177 $mimelist = substr($mimelist, 2, length($mimelist) - 2);
178 $mimelist =~ s/\./*/g;
179 $mimelist =~ s/\//./g;
180 $num_mimetypes = (@mimetype = split(/, */, $mimelist, 9999));
182 $program = &get_token();
184 $flags = $Fld[$#Fld - 1];
185 $cons = $flags & 1;
186 $xwin = $flags & 2;
187 $ask = (!(!($flags & 4))+0);
188 $block = ($flags & 8 or $flags & 16) ? !(!($flags & 16)) : (!$xwin or $cons);
190 for ($i = $num_mimetypes; $i; $i--) {
191 print 'set mime.type.' . $mimetype[$i] . " = \"" . $name . "\"";
193 if ($cons || $Fld[$#Fld] != 1) {
194 &print_association($name, $system_id[$Fld[$#Fld]], $ask, $block, $program);
196 if ($xwin && $Fld[$#Fld] == 1) {
197 &print_association($name, $system_id[$Fld[$#Fld]] . '-xwin', $ask, $block, $program);
200 if ($Fld[1] eq 'mailto' || $Fld[1] eq 'telnet' || $Fld[1] eq 'tn3270') {
201 $val = $Fld[0];
202 $val =~ s/^[^ ]* (".*") .$/$1/;
203 if ($val eq "mailto") { $val =~ s/%/\%h/g; } else { $val =~ s/%/\%h:\%p/g; }
204 print 'set protocol.user.' . $Fld[1] . '.' . $system_id[$Fld[$#Fld]] . ' = ' . $val;
205 if ($Fld[$#Fld] = 1) {# Only Unix has X.
206 print 'set protocol.user.' . $Fld[1] . '.' . $system_id[$Fld[$#Fld]] . '-xwin = ' . $val;
211 ### html.conf
214 if ($Fld[1] eq 'html_assume_codepage') {
215 print "set document.codepage.assume = \"" . $Fld[2] . "\"";
217 if ($Fld[1] eq 'html_avoid_dark_on_black') {
218 print 'set document.allow_dark_on_black = ' . (!($Fld[2])+0);
220 if ($Fld[1] eq 'html_frames') {
221 print 'set document.html.display_frames = ' . $Fld[2];
223 if ($Fld[1] eq 'html_hard_assume') {
224 print 'set document.codepage.force_assumed = ' . $Fld[2];
226 if ($Fld[1] eq 'html_images') {
227 print 'set document.browse.images.show_as_links = ' . $Fld[2];
229 if ($Fld[1] eq 'html_margin') {
230 print 'set document.browse.margin_width = ' . $Fld[2];
232 if ($Fld[1] eq 'html_numbered_links') {
233 print 'set document.browse.links.numbering = ' . $Fld[2];
235 if ($Fld[1] eq 'html_tables') {
236 print 'set document.html.display_tables = ' . $Fld[2];
238 if ($Fld[1] eq 'html_table_order') {
239 print 'set document.browse.table_move_order = ' . $Fld[2];
241 if ($Fld[1] eq 'html_use_document_colours') {
242 print 'set document.colors.use_document_colors = ' . $Fld[2];
246 sub get_token {
247 $backwhacked = 0;
248 $quote = 0;
249 $token = '';
250 $len = length($line);
251 for (; $pos <= $len; ++$pos) { #???
252 $char = substr($line, $pos, 1);
253 if ($backwhacked) {
254 $backwhacked = 0;
256 elsif ($char eq "\\") {
257 $backwhacked = 1;
259 elsif ($char eq "\"") {
260 $quote = !$quote;
262 elsif (($char eq ' ' || $char eq ' ') && !$quote) {
263 last;
265 $token = $token . $char;
267 ++$pos;
269 $token;
272 sub print_association {
273 local($name, $system_str, $ask, $block, $program) = @_;
274 print 'set mime.handler.' . $name . '.' . $system_str . '.ask = ' . $ask;
275 print 'set mime.handler.' . $name . '.' . $system_str . '.block = ' . ($block ? '1' : '0');
276 print 'set mime.handler.' . $name . '.' . $system_str . '.program = ' . $program;