fvwm-convert-2.6: Fix StartFunction handling.
[fvwm.git] / bin / fvwm-convert-2.4.in
blob1f1278ae79dd3fa2f5e1e9fba525329f716e2c9d
1 #!@PERL@
2 # -*-perl-*-
4 # Convert .fvwm2rc from 2.2.x format to 2.4.x format.
6 # Originally written by Dan Espen <despen@telcordia.com> Sept 2000
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 ($source,$dest) = @ARGV;
23 if ( $source eq "") {
24   $source = "$ENV{'HOME'}/.fvwm2rc";
26 if ( ! -e $source ) {
27   die "Can't find source file $source, giving up.\n";
30 if ($dest eq "") {
31   $dest = "$ENV{'HOME'}/.fvwm/.fvwm2rc";
33 $dest2 = "$dest.pass1";
34 if ( -e $dest ) {
35   die "Output file $dest already exists, exiting.\n";
37 if ( -e $dest2 ) {
38   die "Output file $dest2 already exists, exiting.\n";
40 system "cp -p $source $dest 2>/dev/null"; # try to preserve permissions
41 system "cp -p $source $dest2 2>/dev/null"; # try to preserve permissions
43 $[ = 1;                         # set array base to 1
44 $, = ' ';                       # set output field separator
45 $\ = "\n";                      # set output record separator
47 # GlobalOpts that became Styles:
48 %OPTS = ('SMARTPLACEMENTISREALLYSMART','MinOverlapPlacement',
49          'SMARTPLACEMENTISNORMAL','TileCascadePlacement',
50          'ACTIVEPLACEMENTHONORSSTARTSONPAGE',
51            'ManualPlacementHonorsStartsOnPage',
52          'ACTIVEPLACEMENTIGNORESSTARTSONPAGE',
53            'ManualPlacementIgnoresStartsOnPage',
54          'CLICKTOFOCUSDOESNTPASSCLICK', 'ClickToFocusPassesClickOff',
55          'CLICKTOFOCUSDOESNTRAISE', 'ClickToFocusRaisesOff',
56          'MOUSEFOCUSCLICKDOESNTRAISE', 'MouseFocusClickRaisesOff',
57          'NOSTIPLEDTITLES', 'StippledTitleOff',
58          'STIPLEDTITLES', 'StippledTitle');
60 # GlobalOpts that became BugOpts:
61 %BUGOPTS= ('RAISEOVERNATIVEWINDOWS','RaiseOverNativeWindows on',
62            'IGNORENATIVEWINDOWS','RaiseOverNativeWindows off');
64 print "Input from $source, output to $dest\n";
65 parse_pass($source, $dest2, 1);
66 parse_pass($dest2, $dest, 2);
67 unlink($dest2);
68 exit 0;
71 sub parse_pass {
72   local($sourcefile, $destfile, $pass) = @_;
74   open(IN, $sourcefile) || die "Can't open $source";
75   open(STDOUT, ">$destfile") || die "Can't redirect stdout to $dest2";
76   if ($pass == 2) {
77     print '# This file changed by the .fvwm2rc to .fvwm/.fvwm2rc converter';
78   }
79   # create assoc array by imagepath:
80   $imagepath = '@FVWM_IMAGEPATH@';
81   $isize = (@iarray = split(/:/, $imagepath, 9999));
82   for ($i = 1; $i <= $isize; ++$i) {
83     $iassoc{$iarray[$i]} = '1';
84   }
86   $newwarn = "";
87   $commchar="#";                        # help un-confuse emacs.
88  line: while ( <IN> ) {
89     chomp;                      # strip record separator
90     @Fld = split(' ', $_, 9999);
91     if (/^\s*[$commchar]/) {    # Comment, pass it thru
92       print $_;
93       $line = $_;
94       while (substr($line, length($line), 1) eq "\\") { # backslashed lines
95         $line = &Getline1();
96         print $line;
97       }
98       next line;
99     }
101     if (/^\s*$/) {              # Empty line, pass it thru
102       print $_;
103       next line;
104     }
106     $lastwarn = $newwarn;
107     $newwarn = "";
109     # Adds "path" to "newpath":
110     if (/^\s*ICONPATH|^\s*PIXMAPPATH/i) { # Fix up IconPath/PixmapPath:
111       $newpath = '';
112       &add_to_path($Fld[2]);
113       $line = $_;
114       # prime possible loop
115       while (substr($line, length($line), 1) eq "\\") {
116         $line = &Getline1();
117         &add_to_path($line);
118       }
119       if ($newpath eq '') {
120         print
121           '# To use your own icons, uncomment and change the next line';
122         print "#ImagePath \$HOME/icons:+";
123       }
124       else {
125         print 'ImagePath ' . $newpath . ':+';
126       }
127       next line;
128     }
130     # Change GlobOpts to "Style * xxx, ..." commands
131     if (/^\s*globalopts/i) { # Fix up GlobalOpts:
132       $newopts = '';
133       @rest=@Fld;                       # copy the whole line
134       shift @rest;              # remove first element
135       &add_to_opts(join($",@rest)); # pass rest of line
136       $line = $_;                       # prime possible loop
137       while (substr($line, length($line), 1) eq "\\") { # backslashed lines
138         $line = &Getline1();
139         &add_to_opts($line);    # build up newopts
140       }
141       if ($newopts eq '') {
142         next line;              # GlobalOpts without argument, drop silently
143       }
144       else {
145         print 'Style "*"  ' . $newopts; # print as style command
146       }
147       next line;
148     }
150     if (/^\s*MODULEPATH/i) {
151       # Deletes continuation lines too, although if there are
152       # continuation lines, there might be some part of the path we want to
153       # Delete them anyway.
154       print '# Removed by fvwm-convert-2.4: ' . $_;
155       while (substr($_, length($_), 1) eq "\\") {
156         $_ = &Getline1();
157         print '# Removed by fvwm-convert-2.4: ' . $_;
158       }
159       next line;
160     }
162     $single_lines = $_;
163     if ($pass == 2) {
164       $line = $_;
165       # collect continuation lines
166       while (substr($line, length($line), 1) eq "\\") { # backslashed lines
167         $old_line = substr($line, 1, length($line) - 1);
168         $new_line = &Getline1();
169         $single_lines = "$single_lines\n$new_line";
170         $line = "$old_line$new_line";
171       }
172       $_ = $line;
173     }
175     if (/^\s*HILIGHTCOLOR\s/i) {
176       @colors = split("/", $Fld[2], 9999);
177       if ($colors[2] eq '') {
178         $colors[1] = $Fld[2];
179         $colors[2] = $Fld[3];
180       }
181       print "Style \"*\" HilightFore " . $colors[1] . ', HilightBack ' .
182         $colors[2];
183       next line;
184     }
186     if (/^\s*HILIGHTCOLORSET/i) {
187       print "Style \"*\" HilightColorset " . $Fld[2];
188       next line;
189     }
191     if (/^\s*WINDOWSHADEANIMATE/i) {
192       print "Style \"*\" WindowShadeSteps " . $Fld[2];
193       next line;
194     }
196     if (/^\s*WINDOWFONT/i) {
197       print "Style \"*\" Font " . $Fld[2];
198       next line;
199     }
201     if (/^\s*ICONFONT/i) {
202       print "Style \"*\" IconFont " . $Fld[2];
203       next line;
204     }
206     if (/^\s*COLORLIMIT/i) {
207       print '# Removed by fvwm-convert-2.4: ' . $_;
208       next line;
209     }
211     # generate warnings in pass 2 only
212     if ($pass == 2) {
213       if (/^\s*[*].+PANEL/i) {
214         if ($lastwarn ne "panel") {
215           print STDERR "Possible old style FvwmButtons Panel definition found";
216           print STDERR
217             "  See FvwmButtons(1), \"CONVERTING OLD PANEL CONFIGURATIONS\"";
218         }
219         print STDERR "  $_";
220         print $_;
221         $newwarn = "panel";
222         next line;
223       }
225       if (/^\s*READ/i) {
226         if ($lastwarn ne "read") {
227           print STDERR
228             "Read command found, file(s) must be converted in a separate run:";
229         }
230         print STDERR "  $_";
231         print $_;
232         $newwarn = "read";
233         next line;
234       }
236       if (/FvwmConfig/i) {
237         print STDERR "The FvwmConfig module is no longer part of fvwm:";
238         print STDERR "  $_";
239         if (/^\s*[*]?\s*FvwmConfig/i) {
240           print STDERR "  Line commented out.";
241           print '# Removed by fvwm-convert-2.4: ' . $_;
242           next line;
243         }
244         else {
245           print $_;
246         }
247         next line;
248       }
250       if (/FvwmPipe/i) {
251         print STDERR "The FvwmPipe module is no longer part of fvwm:";
252         print STDERR "  $_";
253         if (/^\s*[*]?\s*FvwmPipe/i) {
254           print STDERR "  Line commented out.";
255           print '# Removed by fvwm-convert-2.4: ' . $_;
256         }
257         else {
258           print $_;
259         }
260         next line;
261       }
262       if (/RANDOMPLACEMENT|ACTIVEPLACEMENT|SMARTPLACEMENT/i ||
263           /DUMBPLACEMENT|CLEVERPLACEMENT/i) {
264         $newwarn = "placement";
265         if ($lastwarn ne $newwarn) {
266           print STDERR
267             "Placement style names can not be converted automatically:";
268           print STDERR
269             "  See fvwm(1), \"Window manager placement\" for instructions.";
270         }
271         print STDERR "  $_";
272         print $_;
273         $newwarn = "placement";
274         next line;
275       }
276     }
277     $lastwarn = "";
278     print $single_lines;                        # pass everything else thru
279   }
280   close(IN);
281   close(STDOUT);
294 sub add_to_path {
295   local($path) = @_;
296   $psize = (@parray = split(/:/, $path, 9999));
297   # split them up
298   for ($i = 1; $i <= $psize; ++$i) {
299     # Drop any builtin imagepath:
300     if ($iassoc{$parray[$i]} eq '1') {
301       next;
302     }
303     if ($parray[$i] eq "\\") {
304       next;
305     }
307     # Maybe this next line should only skip files starting with $,
308     # that dont start with  $HOME.
309     if (substr($parray[$i], 1, 1) eq "\$") {
310       next;
311     }
313     if ($newpath eq '') {
314       $newpath = $parray[$i];
315     }
316     else {
317       $newpath = $newpath . ':' . $parray[$i];
318     }
319   }
322 # take one GlobalOpt and convert it to a style argument -or-
323 # just print any bugOpts
324 sub add_to_opts {
325   local($opts) = @_;
326   $psize = (@parray = split(/[ ,\t]/, $opts, 9999));
327   # split them up
328   for ($i = 1; $i <= $psize; ++$i) {
329     if ($parray[$i] eq "\\") {
330       next;
331     }
332     if ($parray[$i] eq "") {
333       next;
334     }
336     # Convert args:
337     # Some args are the same in a style command
338     # Some are changed a little,
339     # the native window stuff becomes a BugOpt
341     $work = $parray[$i];        # init w. unconverted arg
342     $uwork = uc $work;          # uppercase version for lookup
343     $newStyleArg = $OPTS{$uwork}; # do conversion using hash
344     if ($newStyleArg ne '') {   # if arg got converted
345       $work = $newStyleArg;     # save new arg
346     }
348     $bugArg = $BUGOPTS{$uwork}; # convert using hash
349     if ($bugArg ne '') {        # if converted
350       print 'BugOpts ' . $bugArg;
351     } else {                    # if not bugOpt, accum
352       if ($newopts eq '') {     # first time, just arg
353         $newopts = $work;
354       } else {
355         $newopts = $newopts . ', ' . $work; # add comma and arg
356       }
357     }                           # end bugArg vs. style
358   }                             # end for
361 sub Getline1 {
362   local($_);
363   if ($getline_ok = (($_ = <IN>) ne '')) {
364     chomp;                      # strip record separator
365   }
366   $_;