-
Notifications
You must be signed in to change notification settings - Fork 19
/
wm-oldmenu2new
executable file
·217 lines (202 loc) · 4.98 KB
/
wm-oldmenu2new
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/sh
#
# wm-oldmenu2new: script to convert from old-style WindowMaker
# menu file to the new PropertyList style of the WMRootMenu.
#
# Note: ex in all the Linux systems I've used is badly
# broken, except for nex. perl can be relied on however.
# Re-written to use perl.
#
# Local dependencies:
# None.
#
# Authors: Luke Kendall, Toby J Sargeant
#
# Copyright waived; no warranty provided.
#
GLW=GNUstep/Library/WindowMaker
GD=GNUstep/Defaults
WLW=$HOME/$GLW
WD=$HOME/$GD
MYNAME=`basename $0`
USAGE="usage: $MYNAME [menu-file-specifier]
E.g. $MYNAME menu.pt
or $MYNAME pt
The default menu if no arguments are given is the English one, 'menu'."
#
# Process arguments - work out which language menu we're converting.
# Note that foreign language locales do *not* have the .lang suffix
# attached to the WMRootMenu name.
#
OLD_MENU=menu
NEW_MENU=WMRootMenu
if [ $# = 1 ]
then
if [ -s "$WLW/menu.$1" ]
then
OLD_MENU="menu.$1"
NEW_MENU="WMRootMenu"
elif [ -s "$WLW/$1" ]
then
OLD_MENU="$1"
x=`expr "$1" : "menu\.\(.*\)"`
[ "x$x" != "x" ] && NEW_MENU="WMRootMenu"
else
echo "$MYNAME: $WLW/$1 does not exist" >&2
exit 1
fi
elif [ $# != 0 ]
then
echo "$USAGE" >&2
exit 1
fi
#
# For working out what cc is installed
#
which1()
{
oldpath=$PATH
PATH=/bin:/usr/bin:/usr/local/bin
IFS=":"
for j in $oldpath
do
test -x $j/$1 && test ! -d $j/$1 && echo $j/$1 && return 0
done
IFS=" "
return 1
}
#
# Expand macros if necessary.
# Create a temp copy of the menu file to edit to turn into the new.
#
TD=$(/bin/mktemp -d /tmp/wmmenu.XXXXXX) || { echo "$0: can not create temporary file" >& 2; exit 1; }
T=$TD/wmmenu$$
echo "Converting $GLW/$OLD_MENU --> $GD/$NEW_MENU"
cd $WLW || exit 1
if [ ! -s "$OLD_MENU" ]
then
echo "$MYNAME: $WLW/$OLD_MENU does not exist" >&2
exit 1
fi
#
# Always pre-process, to join lines split with \, and to strip comments.
# Not to mention the main purpose, include & process wmmacros if used.
#
set -e
CC=`which1 cc`
[ "x$CC" = "x" ] && CC=`which1 gcc`
[ "x$CC" = "x" ] && "$MYNAME: no cc, gcc found - can't preprocess" >&2 && exit 1
#
# Use the "parse as if it's C option" if cc is gcc, because
# newer versions apparently get confused. Apparently gcc -E does
# not simply run the preprocessor (that's sad).
#
strings "$CC" | grep -l gcc > /dev/null && GCC_FLAGS="-x c"
cp $OLD_MENU $T-c
#
# Given the set -e, the exit 1 shouldn't be needed. But it is, on my NeXT!
#
$CC -E -I. $GCC_FLAGS $T-c > $T+c || exit 1
sed '/^#/d;/^[ ]*$/d' $T+c > $T
rm $T-c $T+c
set +e
#
# This is the interesting bit. Edit the old style menu and
# convert into new style property-list menu.
#
perl - $T <<-'EOF' > $T-p
$v=chr(22);
for (<>) {
push @foo,$_;
}
for (@foo) {
s/\s*$//;
s/^(\s*)"*(Workspaces*)"*\s\s*(WORKSPACE_MENU)/\1(\2, \3),/;
s/^(\s*)("[^"]*")\s+MENU/\1($v\n\1\2,/;
push @foo2,split "\n";
}
@foo=();
for (@foo2) {
s/^(\s*)"([^"]*)"\s\s*END/\1),/;
s/^(\s*)"([^"]*)"\s\s*EXEC\s\s*(.*)$/\1($v\n\1"\2",$v\n\1EXEC,$v\n\1"\3"$v\n\1),/;
s/^(\s*)"([^"]*)"\s\s*SHEXEC\s\s*(.*)$/\1($v\n\1"\2",$v\n\1SHEXEC,$v\n\1"\3"$v\n\1),/;
push @foo,split "\n";
}
@foo2=();
for (@foo) {
s/^(\s*)"([^"]*)"\s\s*OPEN_MENU\s\s*(.*)$/\1($v\n\1"\2",$v\n\1OPEN_MENU,$v\n\1"\3"$v\n\1),/;
push @foo2,split "\n";
}
@foo=();
for (@foo2) {
s/^(\s*)([^ ]*)\s\s*MENU/\1($v\n\1"\2",/;
push @foo,split "\n";
}
@foo2=();
for (@foo) {
s/^(\s*)([^ ]*)\s\s*END/\1),/;
s/^(\s*)([^ ]*)\s\s*EXEC\s\s*(.*)$/\1($v\n\1"\2",$v\n\1EXEC,$v\n\1"\3"$v\n\1),/;
s/^(\s*)([^ ]*)\s\s*SHEXEC\s\s*(.*)$/\1($v\n\1"\2",$v\n\1SHEXEC,$v\n\1"\3"$v\n\1),/;
push @foo2,split "\n";
}
@foo=();
for (@foo2) {
s/^(\s*)([^
]*)\s\s*OPEN_MENU\s\s*(.*)$/\1($v\n\1"\2",$v\n\1OPEN_MENU,$v\n\1"\3"$v\n\1),/;
push @foo,split "\n";
}
@foo2=();
for (@foo) {
s/ WITH / QQQjjQQQ /;
s/^(\s*)"([^"]*)"\s\s*([A-Z_][A-Z_]*)$/\1("\2", \3),/;
s/^(\s*)"([^"]*)"\s+([A-Z_][A-Z_]*)\s\s*(.*)$/\1("\2", \3, \4),/;
s/"(.*".*)"/JJJqqJJJ\1JJJqqJJJ/;
/JJJqqJJJ/ && s/"/\\"/g;
s/JJJqqJJJ/"/g;
s/ QQQjjQQQ / WITH /;
print "$_\n";
}
EOF
mv $T-p $T
#
# Now strip off spurious commas from lines like:
# ),
# )
# since comma is a property separator, not terminator. Sigh.
# Also correct for another problem - Linux ex's require the CTRL-V
# above; a real vi/ex doesn't; so we have to strip out any spurious
# CTRL-V characters if we're using a real ex:
#
sed 's///g' $T | awk '
{
if (last_line != null)
{
if ((last_line ~ /,$/) && ($0 ~ /^[ ]*\)/))
print substr(last_line, 0, length(last_line)-1)
else
print last_line
}
last_line = $0
}
END {
if (last_line != null)
{
if (last_line ~ /,$/)
print substr(last_line, 0, length(last_line)-1)
else
print last_line
}
}
' > $WD/$NEW_MENU.new || exit 1
rm -f $T
rm -fr $TD
#
# Now install it.
#
cd $WD
if [ -s $NEW_MENU ]
then
echo "Preserving $NEW_MENU as $NEW_MENU.sav in $WD"
mv $NEW_MENU $NEW_MENU.sav
fi
mv $NEW_MENU.new $NEW_MENU && echo "Created new $WD/$NEW_MENU"