Updated for CVS 2.5.32 now.
[fvwm.git] / bin / fvwm-convert-2.2
blobd6e526399679aef7ef1c3c7ae04afb8686cbcd22
1 #!/bin/sh
3 # Some time ago, Martin Kraemer <Martin.Kraemer@mch.sni.de> posted an
4 # incomplete script to convert fvwm-1 'rc' files to fvwm-2. I've just
5 # recently fixed and enhanced that script; it's complete (or nearly
6 # so) now. This should help if you choose to convert.
7 #
8 # I've also made a couple of other minor changes to make life easier
9 # for our users here: I changed the default initialization from "Read
10 # .fvwmrc" to "Read .fvwm2rc" (in fvwm/fvwmc), and I installed fvwm 2
11 # as "fvwm2". With these changes, users can easily convert at their
12 # leisure.
14 # Herewith the script. It's using GNU awk (gawk), but will run with
15 # any "new" awk (nawk on Suns (SunOS 4, Solaris), awk on most other
16 # systems). If you do not use gawk, it will be case-sensitive (the
17 # case of the fvwm commands must match those in the script
18 # exactly). With gawk, it'll be case-insensitive.
20 # It's not perfect: some old commands slip through, especially in the
21 # context of Mouse and Key commands. But it provides a good basis on
22 # which to go further.
25 # Convert fvwm 1.x configuration file to 2.2 configuration file
27 # Originally written by Martin Kraemer <Martin.Kraemer@mch.sni.de>
28 # Corrected, extended, and modified by Grant McDorman <grant@isgtec.com>
29 # 24 May 95
30 # Additional corrections and extensions by Bill Oswald <wamo@vnet.ibm.com>
31 # 8 Mar 96 thru 18 Jul 96
32 # Minor corrections to make it easier to customize by Charles Hines 08/01/96
33 # Further minor corrections by Julian Gilbey <jdg@debian.org> based on those
34 # of Austin Donnelly <and1000@debian.org>, 1 Mar 1999
35 # Further major corrections by Julian Gilbey <jdg@debian.org>, 3 Mar 1999
36 # and minor corrections March - May 1999.
37 # Correct some major gaffs: Julian Gilbey, January 2000, with thanks to
38 # Victor Meghesan <victorm@genesys.ro>
40 echo "fvwmrc-to-fvwm2rc" >&2
42 # gawk has IGNORECASE, so we use it if possible.
43 if [ -n `command -v gawk 2>/dev/null` ]
44 then
45 AWK=`command -v gawk`
46 elif [ -x /usr/bin/gawk ]
47 then
48 AWK=/usr/bin/gawk
49 elif [ -n `command -v awk 2>/dev/null` ]
50 then
51 AWK=`command -v awk`
52 elif [ -x /usr/bin/awk ]
53 then
54 AWK=/usr/bin/awk
57 if [ ! -x $AWK ];then
58 echo "Can't find any awk, cannot run!" >&2
59 exit 1
62 source=${1:-$HOME/.fvwmrc}
63 if [ ! -r $source ] ; then
64 echo "Can't find source file $source, giving up" >&2
65 exit 1
68 dest=${2:-$HOME/.fvwm2rc}
69 if [ "$dest" != "-" ] ;then
70 echo "Output to $dest" >&2
71 if [ -f $dest ] ; then
72 echo "Saving existing $dest as $dest.bak" >&2
73 cp -p $dest $dest.bak || { echo "Couldn't save; aborting" >&2; exit 1; }
74 else
75 cp -p $source $dest 2>/dev/null # try to preserve permissions
77 exec >$dest || { echo "Couldn't write to $dest, aborting" >&2; exit 1; }
78 TTY=`tty`
79 if [ ! -w "$TTY" ] ;then
80 TTY=/dev/stderr
82 else
83 TTY=/dev/stderr
85 if [ ! -w "$TTY" ] ;then
86 TTY=/dev/null
89 cat $source | $AWK '
90 BEGIN {
91 printf ("# Trying to compile an old .fvwrc to the new fvwm-2.xx Format\n");
92 TRUE=1; FALSE=0;
94 IGNORECASE=TRUE;
96 hiforecolor=""; dflt["hiforecolor"] = "black";
97 hibackcolor=""; dflt["hibackcolor"] = "CadetBlue";
98 hilightcolor = FALSE;
100 stdforecolor=""; dflt["stdforecolor"] = "black";
101 stdbackcolor=""; dflt["stdbackcolor"] = "grey70";
103 inpopup=FALSE;
104 infunction=FALSE;
105 prefix="";
107 placement = FALSE; dflt["placement"] = "ActivePlacement, DumbPlacement"
110 /^[ \t]*#/ { # Comment, pass it thru
111 print $0;
112 next;
115 /^[ \t]*$/ { # Empty line, pass it thru
116 print $0;
117 next;
120 ################ Rename common items ##############
121 /Restart/ && /fvwm/ {
122 gsub("fvwm", "fvwm2"); gsub("fvwm22","fvwm2"); # try to leave paths alone
124 /GoodStuff/ { gsub("GoodStuff", "FvwmButtons"); }
126 ############ Chop off trailing "&" from Exec commands ##########
127 /^Exec[ \t]+/ || /[ \t]+Exec[ \t]+/ { gsub ("\&[ \t]*$",""); }
129 ################ Highlight Colors ##############
130 /^[ \t]*HiBackColor[ \t]*/ {
131 dflt["hibackcolor"]=hibackcolor=$2;
132 printf ("#!%s (new command=HilightColor)\n", $0);
133 if (hibackcolor != "" && hiforecolor != "" && !hilightcolor) {
134 printf ("\n#Set the foreground and background color for selected windows\n");
135 printf ("HilightColor %s %s\n", hiforecolor, hibackcolor);
136 hilightcolor=TRUE;
137 } else
138 hilightcolor=FALSE;
139 next;
142 /^[ \t]*HiForeColor[ \t]*/ {
143 dflt["hiforecolor"]=hiforecolor=$2;
144 printf ("#!%s (new command=HilightColor)\n", $0);
145 if (hibackcolor != "" && hiforecolor != "" && !hilightcolor) {
146 printf ("\n#Set the foreground and background color for selected windows\n");
147 printf ("HilightColor %s %s\n", hiforecolor, hibackcolor);
148 hilightcolor=TRUE;
149 } else
150 hilightcolor=FALSE;
151 next;
155 ########## Menu Colors, Style and Font ###########
156 /^[ \t]*MenuForeColor[ \t]*/ {
157 printf ("#!%s\n", $0);
158 printf ("MenuStyle * Foreground %s\n", $2);
159 next;
162 /^[ \t]*MenuBackColor[ \t]*/ {
163 printf ("#!%s\n", $0);
164 printf ("MenuStyle * Background %s\n", $2);
165 next;
168 /^[ \t]*MenuStippleColor[ \t]*/ {
169 printf ("#!%s\n", $0);
170 printf ("MenuStyle * Greyed %s\n", $2);
171 next;
174 /^[ \t]*MWMMenus[ \t]*/ {
175 printf ("#!%s\n", $0);
176 printf ("MenuStyle * mwm\n");
177 next;
180 /^[ \t]*Font[ \t]*/ {
181 printf ("#!%s\n", $0);
182 printf ("MenuStyle * Font %s\n", $2);
183 next;
187 # Translate both old ButtonStyle formats to the new format:
188 /^[ \t]*ButtonStyle[ \t]*/ {
189 if ($2 == ":") { # new style already
190 if (NF != $4+4)
191 print "ERROR: ButtonStyle command incorrect\n" NR ": " $0 >"'$TTY'";
192 printf ("%s %d %d", $1, $3, $4);
193 for (i=5; i<=NF; ++i)
194 printf (" %s", $i);
195 printf ("\n");
196 } else {
197 print "Note: Conversion of old ButtonStyle; values rounded" \
198 >"'$TTY'"
199 printf ("#! Old line was: %s\n", $0);
200 p=index ($3,"x");
201 x=substr($3,1,p-1)/2;
202 y=substr($3,p+1)/2;
203 printf ("%s %s 5 %dx%d@0 %dx%d@0 %dx%d@0 %dx%d@1 %dx%d@1\n",
204 $1, $2, 50-x,50+y, 50+x,50+y, 50+x,50-y, 50-x,50-y,
205 50-x,50+y);
207 next;
210 ########## Standard Colors ###########
211 /^[ \t]*StdForeColor[ \t]*/ {
212 dflt["stdforecolor"]=stdforecolor=$2;
213 printf ("#!%s (new command=Style \"*\" Color f/b)\n", $0);
214 print "Style \"*\" ForeColor " $2;
215 next;
218 /^[ \t]*StdBackColor[ \t]*/ {
219 dflt["stdbackcolor"]=stdbackcolor=$2;
220 printf ("#!%s (new command=Style \"*\" Color f/b)\n", $0);
221 print "Style \"*\" BackColor " $2;
222 next;
225 ########## Icon Related Stuff ##########
226 /^[ \t]*IconBox[ \t]*/ { print "Style \"*\" " $0; next; }
227 /^[ \t]*IconFont[ \t]*/ { print $0; next; }
228 /^[ \t]*SuppressIcons[ \t]*/ { print "Style \"*\" NoIcon"; next; }
229 /^[ \t]*StickyIcons[ \t]*/ { print "Style \"*\" StickyIcon"; next; }
230 /^[ \t]*ModulePath[ \t]*/ { print "#! (ModulePath command commented out)\n#" $0; next; }
231 /^[ \t]*PixmapPath[ \t]*/ { print $0; next; }
232 /^[ \t]*IconPath[ \t]*/ { print $0; next; }
233 # note: Icon must be followed by some white space
234 /^[ \t]*Icon[ \t]+/ { printf "Style %s Icon %s\n", $2, $3; next; }
236 ########## MWM hints ##########
237 /^[ \t]*MWMFunctionHints[ \t]*/ { printf ("Style \"*\" MWMFunctions\n"); next; }
238 /^[ \t]*MWMDecor[ \t]*/ { printf ("Style \"*\" MWMDecor\n"); next; }
239 /^[ \t]*MWMDecorHints[ \t]*/ { printf ("Style \"*\" MWMDecor\n"); next; }
240 /^[ \t]*MWMBorders[ \t]*/ { printf ("Style \"*\" MWMBorder\n"); next; }
241 /^[ \t]*MWMButtons[ \t]*/ { printf ("Style \"*\" MWMButtons\n"); next; }
242 /^[ \t]*MWMHintOverride[ \t]*/ { printf ("Style \"*\" HintOverride\n"); next; }
244 ########## Placement & Focus styles ##########
245 /^[ \t]*RandomPlacement[ \t]*/ { print "Style \"*\" " $0; placement = TRUE; next; }
246 /^[ \t]*SmartPlacement[ \t]*/ { print "Style \"*\" " $0; placement = TRUE; next; }
247 /^[ \t]*Sticky(Back|Fore)Color[ \t]*/ {
248 print "#! " $0 " (not supported in FVWM2)"; next;
250 /^[ \t]*Sticky[ \t]+/ { printf "Style \"%s\" Sticky\n", $2; next; }
251 /^[ \t]*NoPPosition[ \t]*/ { print "Style \"*\" " $0; next; }
252 /^[ \t]*ClickToFocus[ \t]*/ { print "Style \"*\" " $0; next; }
253 /^[ \t]*SloppyFocus[ \t]*/ { print "Style \"*\" " $0; next; }
254 /^[ \t]*StaysOnTop[ \t]*/ { printf "Style \"%s\" StaysOnTop\n", $2; next; }
255 /^[ \t]*AutoRaise[ \t]*/ {
256 print "#! " $0 " (use Module FvwmAuto)";
257 print "AddToFunc \"InitFunction\" \"I\" Module FvwmAuto " $2;
258 print "AddToFunc \"RestartFunction\" \"I\" Module FvwmAuto " $2;
259 next;
262 ########## Decoration styles ##########
263 /^[ \t]*BorderWidth[ \t]*/ { print "Style \"*\" " $0; next; }
264 /^[ \t]*HandleWidth[ \t]*/ { print "Style \"*\" " $0; next; }
265 /^[ \t]*DecorateTransients[ \t]*/ { print "Style \"*\" DecorateTransient"; next; }
266 /^[ \t]*XORvalue[ \t]*/ { print $0; next; }
267 /^[ \t]*BoundaryWidth[ \t]*/ { printf "Style \"*\" HandleWidth %s\n", $2; next; }
268 /^[ \t]*NoBoundaryWidth[ \t]*/ { print "Style \"*\" BorderWidth " $2; next; }
269 /^[ \t]*NoTitle[ \t]*/ { print "Style \"*\" " $0; next; }
270 /^[ \t]*NoBorder[ \t]*/ { print "Style \"*\" " $0; next; }
274 ########## Etc ##########
275 /^[ \t]*Lenience[ \t]*/ { print "Style \"*\" " $0; next; }
276 /^[ \t]*Style[ \t]*/ { print $0; next; }
277 # Key keyname context mods (Exec|Module|Restart) ...
278 # used to be followed by a "name"; it is no longer
279 /^[ \t]*Key[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+(Exec|Module|Restart)[ \t]+\"/ {
280 # not going to handle escaped quotes
281 label=$6;
282 first=7;
283 quoted=substr(label, 1, 1)=="\"" &&
284 substr(label, length(label), 1)!="\"";
285 for (i=7;i<=NF && quoted;i++) {
286 label=$i;
287 quoted=substr(label, length(label), 1)!="\"";
288 first=i + 1;
290 printf ("%s %s %s %s %s", $1, $2, $3, $4, $5);
291 for (i=first; i<=NF; ++i)
292 printf (" %s", $i);
293 printf ("\n");
294 next;
296 # Any other Key command
297 /^[ \t]*Key[ \t]*/ { print $0; next; }
299 # Similarly with Mouse commands
300 /^[ \t]*Mouse[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+[^ \t]+[ \t]+(Exec|Module|Restart)[ \t]+\"/ {
301 # not going to handle escaped quotes
302 label=$6;
303 first=7;
304 quoted=substr(label, 1, 1)=="\"" &&
305 substr(label, length(label), 1)!="\"";
306 for (i=7;i<=NF && quoted;i++) {
307 label=$i;
308 quoted=substr(label, length(label), 1)!="\"";
309 first=i + 1;
311 printf ("%s %s %s %s %s", $1, $2, $3, $4, $5);
312 for (i=first; i<=NF; ++i)
313 printf (" %s", $i);
314 printf ("\n");
315 next;
318 /^[ \t]*Mouse[ \t]*/ { print $0; next; }
319 # This is probably not necessary
320 # /^[ \t]*Mouse[ \t]*/ {
321 # if (sub("[ \t]Pop[uU]p[ \t]", " Menu ")) {
322 # if (!warn["Mouse"]) {
323 # print "Note: Setting mouse bindings to sticky menus">"'$TTY'";
324 # warn["Mouse"] = TRUE;
326 # sub("$", " Nop");
328 # print $0; next;
331 /^[ \t]*WindowListSkip[ \t]*/ { printf "Style %s WindowListSkip\n", $2; next; }
332 /^[ \t]*WindowFont[ \t]*/ { print $0; next; }
333 /^[ \t]*ClickTime[ \t]*/ { print $0; next; }
334 /^[ \t]*OpaqueMove[ \t]*/ { print "OpaqueMoveSize " $2; next; }
335 /^[ \t]*EdgeScroll[ \t]*/ { print $0; next; }
336 /^[ \t]*EdgeResistance[ \t]*/ { print $0; next; }
337 /^[ \t]*DeskTopSize[ \t]*/ { print $0; next; }
338 /^[ \t]*DeskTopScale[ \t]*/ {
339 printf ("#!%s (new command=*FvwmPagerDeskTopScale <scale>)\n", $0);
340 print "*FvwmPagerDeskTopScale " $2;
341 next;
344 /^[ \t]*FvwmButtons[ \t]*/ {
345 sub("[ ]Swallow[ ]*[^ ]*", "& Exec");
346 print $0;
347 if (length($0) > 199)
349 print "Warning: line" NR "too long" >"'$TTY'";
350 print ">> " $0 >"'$TTY'";
352 if (!warn["GoodStuff"])
354 print "Note: GoodStuff renamed to FvwmButtons" >"'$TTY'";
355 print "Note: FvwmButtons syntax may now be wrong; please check!" >"'$TTY'";
356 warn["GoodStuff"]=TRUE;
358 next;
361 /^\*/ {
362 # other Module Configuration commands are passed thru
363 print $0;
364 next;
367 # hack: Modules spawned outside of a function, menu, or popup cannot have leading whitespace.
368 # add these to the initfunction
369 /^Module[ \t]*/ { printf "AddToFunc \"InitFunction\" \"I\" %s \n", $0; next; }
371 # hack: function declarations cannot have leading whitespace
372 /^Function[ \t]*/ {
373 if (inpopup)
374 print "ERROR: EndPopup missing\n" NR ": " $0 >"'$TTY'";
375 inpopup=FALSE;
376 if (infunction)
377 print "ERROR: EndFunction missing\n" NR ": " $0 >"'$TTY'";
378 infunction=TRUE;
379 prefix="AddToFunc " $2;
380 next;
383 /^[ \t]*EndFunction[ \t]*/ {
384 if (!infunction)
385 print "ERROR: EndFunction outside of function" >"'$TTY'";
386 infunction=FALSE;
387 prefix="";
388 next;
391 # hack: popup declarations cannot have leading whitespace
392 /^Popup/ {
393 if (inpopup)
394 print "ERROR: EndPopup missing\n" NR ": " $0 >"'$TTY'";
395 if (infunction)
396 print "ERROR: EndFunction missing\n" NR ": " $0 >"'$TTY'";
397 infunction=FALSE;
398 inpopup=TRUE;
400 label=$2;
401 if (index($2, "\"") == 1) {
402 # not going to handle escaped quotes
403 first=3;
404 quoted=substr(label, 1, 1)=="\"" &&
405 substr(label, length(label), 1)!="\"";
406 for (i=3;i<=NF && quoted;i++) {
407 label=label " " $i;
408 quoted=substr(label, length(label), 1)!="\"";
409 first=i + 1;
413 prefix="AddToMenu " label;
414 next;
417 /^[ \t]*EndPopup[ \t]*/ {
418 if (!inpopup)
419 print "ERROR: EndPopup outside of popup\n" NR ": " $0 >"'$TTY'";
420 inpopup=FALSE;
421 prefix="";
422 next;
427 ########## Deleted Commands ##########
428 /^[ \t]*DontMoveOff[ \t]*/ ||
429 /^[ \t]*BackingStore[ \t]*/ ||
430 /^[ \t]*AppsBackingStore[ \t]*/ ||
431 /^[ \t]*SaveUnders[ \t]*/ ||
432 /^[ \t]*StubbornIcons[ \t]*/ ||
433 /^[ \t]*StubbornIconPlacement[ \t]*/ ||
434 /^[ \t]*StubbornPlacement[ \t]*/ ||
435 /^[ \t]*Cursor[ \t]*/ {
436 print "#! " $0 " [deleted]";
437 if (warned[$1]==FALSE) {
438 print "Warning: " $1 " not in Fvwm2, command dropped" >"'$TTY'";
439 warned[$1] = TRUE;
441 next;
444 /^[ \t]*Pager[ \t]*/ {
445 print "#! " $0 " [deleted]";
446 print "#! An FvwmPager config to emulate builtin pager would be as follows:"
447 print "# *FvwmPagerBack SlateGrey";
448 print "# *FvwmPagerFore Black";
449 print "# *FvwmPagerFont none";
450 print "# *FvwmPagerHilight SlateBlue4";
451 print "# *FvwmPagerGeometry <xsize> <ysize>";
452 print "# *FvwmPagerSmallFont -*-times-medium-r-*-*-*-80-*-*-*-*-*-*";
453 print "# *FvwmPagerDeskTopScale 32";
454 print "# #! Now start pager";
455 print "# Module FvwmPager 0 0";
456 if (warned[$1]==FALSE) {
457 print "Warning: " $1 " omitted, internal pager is obsolete (use FvwmPager)" >"'$TTY'";
458 warned[$1] = TRUE;
460 next;
463 /^[ \t]*PagingDefault[ \t]*/ ||
464 /^[ \t]*TogglePage[ \t]*/ {
465 print "#! " $0 " (use EdgeScroll 0 0)"; next;
466 print "Warning: " $1 " not in Fvwm2, use EdgeScroll">"'$TTY'";
469 ########## Old Internal Pager Colors ###########
470 /^[ \t]*PagerForeColor[ \t]*/ ||
471 /^[ \t]*PagerBackColor[ \t]*/ {
472 printf ("#!%s (new command=Style FvwmPager Color fore_color/back_color)\n", $0);
473 if (warned[$1]==FALSE) {
474 print "Warning: " $1 " omitted, internal pager is obsolete (use FvwmPager)" >"'$TTY'";
475 warned[$1] = TRUE;
477 next;
480 ########## Sticky Colors ###########
481 /^[ \t]*StickyForeColor[ \t]*/ {
482 printf ("#!%s (no sticky foreground color in fvwm2)\n", $0);
483 if (warned[$1]==FALSE) {
484 print "Warning: StickyForeColor not in fvwm2, omitted" > "'$TTY'"
485 print " Use the Style command to assign each sticky window the same ForeColor" > "'$TTY'"
487 next;
490 /^[ \t]*StickyBackColor[ \t]*/ {
491 printf ("#!%s (no sticky background color in fvwm2)\n", $0);
492 if (warned[$1]==FALSE) {
493 print "Warning: StickyBackColor not in fvwm2, omitted" >"'$TTY'"
494 print " Use the Style command to assign each sticky window the same BackColor" > "'$TTY'"
496 next;
501 if (infunction) {
502 #gsub("[ ]PopUp[ ]", " "); }
503 if ($2 == "\"Motion\"")
504 context="\"M\"";
505 else if ($2 == "\"Click\"")
506 context="\"C\"";
507 else if ($2 == "\"DoubleClick\"")
508 context="\"D\"";
509 else if ($2 == "\"Immediate\"")
510 context="\"I\"";
511 else context=$2;
512 printf "%s", prefix " " context " " $1;
513 for (i=3; i<=NF; ++i)
514 printf (" %s", $i);
515 printf ("\n");
516 prefix="+ ";
517 next;
518 } else if (inpopup) {
519 # not going to handle escaped quotes
520 label=$2;
521 first=3;
522 quoted=substr(label, 1, 1)=="\"" &&
523 substr(label, length(label), 1)!="\"";
524 for (i=3;i<=NF && quoted;i++) {
525 label=label " " $i;
526 quoted=substr(label, length(label), 1)!="\"";
527 first=i + 1;
529 printf ("%s %s %s", prefix, label, $1);
530 for (i=first; i<=NF; ++i)
531 printf (" %s", $i);
532 printf ("\n");
533 prefix="+ ";
534 next;
537 if (warned[$1]==FALSE) {
538 printf ("#!Warning: Keyword \"%s\" not handled yet\n", $1);
539 warned[$1]=TRUE;
540 print "Warning: Unknown keyword "$1" passed through">"'$TTY'";
542 print $0;
543 next;
546 END {
547 if (!hilightcolor) {
548 printf ("\n#Set the foreground and background color for selected windows\n");
549 printf ("HilightColor %s %s\n", dflt["hiforecolor"], dflt["hibackcolor"]);
551 if (!placement) {
552 printf "# overide default RandomPlacement and SmartPlacement Styles\n";
553 printf "Style \"*\" %s\n", dflt["placement"];
557 exit