aboutsummaryrefslogtreecommitdiff
path: root/util/fluxbox-generate_menu.in
blob: b00db10c4608e580a56698b1aed069c858336ca3 (plain)
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
#!/bin/sh
#
# generate_menu for Fluxbox
#
# Copyright (c) 2005 Dung N. Lam <dnlam@users.sourceforge.net>
# Copyright (c) 2002-2004 Han Boetes <han@mijncomputer.nl>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Portability notes:
# To guarantee this script works on all platforms that support fluxbox
# please keep the following restrictions in mind:
#
# - don't use [ "a" == "a" ]; use [ "a" = "a" ]    (found with help from FreeBSD user relaxed)
# - don't use if ! command;, use command; if [ $? -ne 0 ];
# - don't use [ -e file ] use [ -r file ]
# - don't use $(), use ``
# - don't use ~, use ${HOME}
# - don't use id -u or $UID, use whoami
# - getopts won't work on all platforms, but the config-file can
#   compensate for that.
# - OpenBSD and Solaris grep do not have the -m or -q options
# - various software like grep/sed/perl may be not present or not
#   the version you have. for example grep '\W' only works on gnu-grep.
# - echo can lack several flags (notably -n) and might default to absent -e
#   In doubt, use printf
#   Keep this in mind, use bare basic defaults.
# - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash.
#   Non portable features like getopts in this script can be achieved in
#   other ways.


# Functions
display_usage() {
    cat << EOF
Usage: @pkgprefix@fluxbox-generate_menu@pkgsuffix@ [-kgrBh] [-t terminal] [-w url] [-b browser]
         [-m menu-title] [-o /path] [-u /path] [-p /path] [-n /path] [-q /path]
         [-d /path ] [-ds] [-i /path] [-is] [-su]
EOF
}

display_help() {
    display_usage
    cat << EOF

Options:

    -k  Insert a KDE menu
    -g  Add a Gnome menu
    -B  Enable backgrounds menu
    -su Enable sudo commands
    -r  Don't remove empty menu-entries; for templates

    -d  Other path(s) to recursively search for *.desktop files
    -ds Wider search for *.desktop files (takes more time)
    -i  Other path(s) to search for icons
        e.g., "/usr/kde/3.3/share/icons/crystalsvg/16x16/*"
    -is Wider search for icons (worth the extra time)
    -in Skip icon search

    -t  Favourite terminal
    -w  Homepage for console-browsers. Default is fluxbox.org
    -b  Favourite browser
    -m  Menu-title; default is "Fluxbox"
    -o  Outputfile; default is ~/.@pkgprefix@fluxbox@pkgsuffix@/menu
    -u  User sub-menu; default is ~/.@pkgprefix@fluxbox@pkgsuffix@/usermenu

    -h  Display this help
    -a  Display the authors of this script

  Only for packagers:

    -p  Prefix; default is @PREFIX@
    -n  Gnome-prefix; /opt, /usr, /usr/X11R6 and /usr/local autodetected
    -q  KDE-prefix; idem dito


Files:
    ~/.@pkgprefix@fluxbox@pkgsuffix@/usermenu     Your own submenu which will be included in the menu
    ~/.@pkgprefix@fluxbox@pkgsuffix@/menuconfig   rc file for fluxbox-generate_menu

EOF
}

#'
display_authors() {
    cat << EOF

@pkgprefix@fluxbox-generate_menu@pkgsuffix@ was brought to you by:

    Henrik Kinnunen:    Project leader.
    Han Boetes:         Packaging, debugging and scripts.
    Simon Bowden:       Cleanups and compatibility for SUN.
    Jeramy B. Smith:    Packaging assistance, Gnome and KDE menu system.
    Filippo Pappalardo: Italian locales and -t option.
    $WHOAMI:            Innocent bystander.

EOF
}

testoption() {
    if [ -z "$3" -o -n "`echo $3|grep '^-'`" ]; then
        echo "Error: The option $2 requires an argument." >&2
        exit 1
    fi
    case $1 in
        ex) # executable
            if find_it "$3"; then
                :
            else
                echo "Error: The option $2 needs an executable as argument, and \`$3' is not." >&2
            fi
            ;;
        di) # directory
            if [ -d "$3" ]; then
                :
            else
                echo "Error: The option $2 needs a directory as argument, and \`$3' is not." >&2
            fi
            ;;
        fl) # file
            if [ -r "$3" ]; then
                :
            else
                echo "Error: The option $2 needs a readable file as argument, and \`$3' is not." >&2
            fi
            ;;
        sk) # skip
            :
            ;;
    esac
}

# some shell's hash returns 0 always
if hash this_program_does_not_exist-no_really-aA1zZ9 > /dev/null 2>&1; then
    # can't rely on return value
    # ash / ksh
    find_it() {
        which "$1" > /dev/null 2>&1 && shift && "$@"
    }

    find_it_options() {
        which "$1" > /dev/null 2>&1
    }
else
    # can rely on return value
    # bash / dash / zsh / sh on Solaris
    find_it() {
        [ -n "$1" ] && hash "$1" 2> /dev/null && shift && "$@"
    }

    find_it_options() {
        [ -n "$1" ] && hash "$1" 2> /dev/null
    }
fi

#echo "replaceWithinString: $1, $2, $3" >&2
#echo ${1//$2/$3} # causes error in BSD even though not used
replaceWithinString(){
    echo $1 | awk "{ gsub(/$2/, \"$3\"); print }"
}

convertIcon(){
    if [ ! -f "$1" ] ; then 
        echo "Icon file not found: $1" >&2
        return 1
    fi

    if [ "$1" = "$2" ]; then
        # $dnlamVERBOSE "Files are in the same location: $1 = $2" >&2
        # not really an error; just nothing to do.
        return 0;
    fi

    BASENAME="${1##*/}"

    # make sure it is an icon by checking if it has an extension
    if [ "$BASENAME" = "${BASENAME%%.*}" ]; then
        # $dnlamVERBOSE "File $1 does not have a filename extention." >&2
        return 1;
    fi

    # don't have to convert xpm files
    case "$1" in
        *.xpm)
            echo "$1"
            return 0;
        ;;
    esac

    # may not have to convert png if imlib is enabled
    if [ "$PNG_ICONS" = "yes" ]; then
        case "$1" in
            *.png)
                echo "$1"
                return 0;
            ;;
        esac
    fi

    # convert all others icons and save it as xpm format under directory $2
    entry_icon="$2/${BASENAME%.*}.xpm"
    if [ -f "${entry_icon}" ]; then
        : echo "File exists. To overwrite, type: convert \"$1\" \"$entry_icon\"" >&2
    else
        if find_it_options convert; then
            convert "$1" "$entry_icon"
            # echo convert "$1" , "$entry_icon" >> $ICONMAPPING
        else
            echo "Please install ImageMagick's convert utility" >&2
        fi
    fi
    echo "$entry_icon"
}

removePath(){
    execname="$1"
    progname="${execname%% *}"
    # separate program name and its parameters
    if [ "$progname" = "$execname" ]; then
        # no params
        # remove path from only program name
        execname="${progname##*/}"
    else
        params="${execname#* }"
        # remove path from only program name
        execname="${progname##*/} $params"
    fi
    echo $execname
}

doSearchLoop(){
    for ICONPATH in "$@"; do
        # $dnlamVERBOSE ": $ICONPATH" >> $ICONMAPPING
          [ -d "$ICONPATH" ] || continue
        #echo -n "."
        # # $dnlamVERBOSE ":: $ICONPATH/$temp_icon" >> $ICONMAPPING
        if [ -f "$ICONPATH/$temp_icon" ]; then
            echo "$ICONPATH/$temp_icon"
            return 0;
        else # try different extensions; 
            # remove extension
            iconNOext="${temp_icon%%.*}"
            [ -d "$ICONPATH" ] && for ICONEXT in .xpm .png .gif ; do
                # echo "::: $ICONPATH/$iconNOext$ICONEXT" >> $ICONMAPPING
                realpath=`find "$ICONPATH" -type f -name "$iconNOext$ICONEXT" | head -n 1`
                if [ -n "$realpath" ]; then
                    echo $realpath
                    return 0;
                fi
            done
        fi
    done
    #echo "done"
    return 1
}

doSearch(){
    # remove '(' from '(fluxbox ...) | ...'
    execname=`replaceWithinString "$1" "\("`
    temp_icon="$2"
    # $dnlamVERBOSE "# Searching for icon $temp_icon for $execname" >> $ICONMAPPING

    # check in $ICONMAPPING before searching directories
    entry_icon=`grep "^\"${execname}\"" $ICONMAPPING | head -n 1 | grep -o '<.*>'`
    if [ -n "$entry_icon" ]; then
        entry_icon=`replaceWithinString "$entry_icon" "<"`
        entry_icon=`replaceWithinString "$entry_icon" ">"`
        echo $entry_icon
        return 0;
    fi
    # echo "$ICONMAPPING for $execname: $entry_icon"

    # the following paths include a user-defined variable, listing paths to search for icons
    # echo -n "for $temp_icon"
    eval doSearchLoop $USER_ICONPATHS \
      "$FB_ICONDIR" \
      "/usr/share/${execname%% *}" \
      ${OTHER_ICONPATHS} \


}

searchForIcon(){
    # remove '&' and everything after it
    entry_exec="${1%%&*}"
    entry_icon="$2"
    # $dnlamVERBOSE echo "searchForIcon \"$entry_exec\" \"$entry_icon\"" >&2

    # get the basename and parameters of entry_exec -- no path
    entry_exec=`removePath "${entry_exec}"`
    [ -z "$entry_exec" ] && { echo "Exec is NULL $1 with icon $2"; return 1; }

    # search for specified icon if it does not exists
    if [ -n "$entry_icon" ] && [ ! "$entry_exec" = "$entry_icon" ] && [ ! -f "$entry_icon" ]; then
        # to search for icon in other paths,
        # get basename
        temp_icon="${entry_icon##*/}"
        # remove parameters
        temp_icon="${temp_icon#* }"
        # clear entry_icon until temp_icon is found
        unset entry_icon

        if [ ! -f "$entry_icon" ]; then
            entry_icon=`doSearch "$entry_exec" "$temp_icon"`
        fi
    fi

    # remove parameters
    execname="${entry_exec%% *}"

    # echo "search for icon named $execname.{xpm,png,gif}"
    if [ ! -f "$entry_icon" ]; then
        entry_icon=`doSearch "$entry_exec" "$execname"`
    fi

    # -----------  done with search ------------
    # $dnlamVERBOSE echo "::: $entry_icon" >&2

    # convert icon file, if needed
    if [ -f "$entry_icon" ] && [ -n "yes$ConvertIfNecessary" ]; then
        entry_icon=`convertIcon "$entry_icon" "$USERFLUXDIR/icons"`
        # $dnlamVERBOSE echo ":::: $entry_icon" >&2
    fi

    # remove path to icon; just get basename
    icon_base="${entry_icon##*/}"
    # remove extension
    icon_base="${icon_base%%.*}"
    # echo "^.${entry_exec}.[[:space:]]*<.*/${icon_base}\....>" 
    if [ -f "$entry_icon" ]; then
    # if icon exists and entry does not already exists, add it
        if ! grep "^.${execname}.[[:space:]]*<.*/${icon_base}\....>" $ICONMAPPING > /dev/null 2>&1; then
            printf "\"${execname}\" \t <${entry_icon}>\n" >> $ICONMAPPING
        else 
            : echo "#    mapping already exists for ${execname}" >> $ICONMAPPING
        fi
    else
        echo "# No icon file found for $execname" >> $ICONMAPPING
    fi
}

toSingleLine(){ echo "$@"; }
createIconMapping(){
    # $dnlamVERBOSE "# creating `date`" >> $ICONMAPPING
    # $dnlamVERBOSE "# using desktop files in $@" >> $ICONMAPPING
    # $dnlamVERBOSE "# searching for icons in `eval toSingleLine $OTHER_ICONPATHS`" >> $ICONMAPPING
    # need to determine when to use .fluxbox/icons/$execname.xpm over those listed in iconmapping
    # $dnlamVERBOSE echo "createIconMapping: $@"
    for DIR in "$@" ; do
        if [ -d "$DIR" ]; then
            # $dnlamVERBOSE echo "# ------- Looking in $DIR" >&2 
            # >> $ICONMAPPING
            find "$DIR" -type f -name "*.desktop" | while read DESKTOP_FILE; do 
                # echo $DESKTOP_FILE; 
                #entry_name=`grep '^[ ]*Name=' $DESKTOP_FILE | head -n 1`
                #entry_name=${entry_name##*=}
                entry_exec=`grep '^[ ]*Exec=' "$DESKTOP_FILE" | head -n 1`
                entry_exec=${entry_exec##*=}
                entry_exec=`replaceWithinString "$entry_exec" "\""`
                if [ -z "$entry_exec" ]; then
                    entry_exec=${DESKTOP_FILE%%.desktop*}
                fi

                entry_icon=`grep '^[ ]*Icon=' "$DESKTOP_FILE" | head -n 1`
                entry_icon=${entry_icon##*=}

                # $dnlamVERBOSE echo "--- $entry_exec $entry_icon" >&2
                case "$entry_icon" in
                    "" | mime_empty | no_icon )
                        : echo "no icon for $entry_exec"
                    ;;
                    *)
                        searchForIcon "$entry_exec" "$entry_icon"
                    ;;
                esac
            done
        fi
    done
    # $dnlamVERBOSE "# done `date`" >> $ICONMAPPING
}

lookupIcon() {
    if [ ! -f "$ICONMAPPING" ]; then
        echo "!!! Icon map file not found: $ICONMAPPING" >&2
        return 1
    fi

    execname="$1"
    shift
    [ -n "$1" ] && echo "!! Ignoring extra parameters: $*" >&2

    [ -z "$execname" ] && { echo "execname is NULL; cannot lookup"; return 1; }
    execname=`removePath "$execname"`

    #echo "grepping ${execname}"
    iconString=`grep "^\"${execname}\"" $ICONMAPPING | head -n 1 | grep -o '<.*>'`
    # $dnlamVERBOSE "lookupIcon $execname, $iconString" >&2

    if [ -z "$iconString" ] ; then
        iconString=`grep "^\"${execname%% *}" $ICONMAPPING | head -n 1 | grep -o '<.*>'`
    fi

    if [ -z "$iconString" ] && [ -z "$PARSING_DESKTOP" ] ; then
        # $dnlamVERBOSE "lookupIcon: Searching ...  should only be needed for icons not gotten from *.desktop (manual-created ones): $execname" >&2
        searchForIcon "$execname" "$execname"
        [ -n "$entry_icon" ] && iconString="<$entry_icon>"
    fi

    # [ -n "$iconString" ] && echo "  Found icon for $execname: $iconString" >&2
    echo $iconString
}

append() {
     if [ -z "${INSTALL}" ]; then
        # $dnlamVERBOSE echo "append: $*" >&2
        iconString="`echo $* | grep -o '<.*>'`"
        # echo "iconString=$iconString" >&2
        if [ -z "$iconString" ] && [ -z "$NO_ICON" ]; then
            printf "      $* " >> ${MENUFILENAME}
            # get the program name between '{}' from parameters            
            execname="$*"
            execname=${execname#*\{}
            execname=${execname%%\}*}
            # $dnlamVERBOSE echo "execname=$execname" >&2
            # if execname hasn't changed from original $*, then no '{...}' was given
            if [ ! "$execname" = "$*" ]; then
                case "$execname" in
                    $DEFAULT_TERM*)
                        # remove quotes
                        execname=`replaceWithinString "$execname" "\""`
                        # remove "$DEFAULT_TERM -e "
                        # needed in case calling another program (e.g., vi) via "xterm -e"                    
                        execname=${execname##*$DEFAULT_TERM -e }
                    ;;
                esac
                # lookup execname in icon map file
                iconString=`lookupIcon "$execname"`
                #[ -n "$iconString" ] || echo "No icon found for $execname"
            fi
            echo "${iconString}" >> ${MENUFILENAME}
        else
            echo "      $*" >> ${MENUFILENAME}
        fi
    else
        echo "      $*" >> ${MENUFILENAME}
    fi
}

append_menu() {
    echo "$*" >> ${MENUFILENAME}
}

append_submenu() {
    [ "${REMOVE}" ] && echo >> ${MENUFILENAME} # only an empty line in templates
    append_menu "[submenu] ($1)"
}

append_menu_end() {
    append_menu '[end]'
    [ "${REMOVE}" ] && echo >> ${MENUFILENAME} # only an empty line in templates
}

menu_entry() {
    if [ -f "$1" ]; then
        #                   space&tab here
        entry_name=`grep '^[     ]*Name=' "$1" | head -n 1 | cut -d = -f 2`
        entry_exec=`grep '^[     ]*Exec=' "$1" | head -n 1 | cut -d = -f 2`
        if [ -n "$entry_name" -a -n "$entry_exec" ]; then
            append "[exec] ($entry_name) {$entry_exec}"
        fi
    fi
}

menu_entry_dir() {
    for b in  "$*"/*.desktop; do
        menu_entry "${b}"
    done
}

menu_entry_dircheck() {
    if [ -d "$*" ]; then
        menu_entry_dir "$*"
    fi
}


# recursively build a menu from the listed directories
# the dirs are merged
recurse_dir_menu () {
    ls "$@"/ 2>/dev/null | sort | uniq | while read name; do
        for dir in "$@"; do
            if [ -n "$name" -a -d "$dir/$name" ]; then
                # recurse
                append_submenu "${name}"
                # unfortunately, this is messy since we can't easily expand
                # them all. Only allow for 3 atm. Add more if needed
                recurse_dir_menu ${1:+"$1/$name"}  ${2:+"$2/$name"} ${3:+"$3/$name"}
                append_menu_end
                break; # found one, it'll pick up all the rest
            fi
            # ignore it if it is a file, since menu_entry_dir picks those up
        done
    done

    # Make entries for current dir after all submenus
    for dir in "$@"; do
        menu_entry_dircheck "${dir}"
    done
}


normal_find() {
    while [ "$1" ]; do
        find_it $1     append "[exec]   ($1) {$1}"
        shift
    done
}

cli_find() {
    while [ "$1" ]; do
        find_it $1     append "[exec]   ($1) {${DEFAULT_TERM} -e $1}"
        shift
    done
}

sudo_find() {
    [ "${DOSUDO}" = yes ] || return
    while [ "$1" ]; do
        find_it $1     append "[exec]   ($1 (as root)) {${DEFAULT_TERM} -e sudo $1}"
        shift
    done
}

clean_up() {
[ -f "$ICONMAPPING" ] && rm -f "$ICONMAPPING"

# Some magic to clean up empty menus
rm -f ${MENUFILENAME}.tmp
touch ${MENUFILENAME}.tmp
counter=10 # prevent looping in odd circumstances
until [ $counter -lt 1 ] || \
    cmp ${MENUFILENAME} ${MENUFILENAME}.tmp >/dev/null 2>&1; do
    [ -s ${MENUFILENAME}.tmp ] && mv ${MENUFILENAME}.tmp ${MENUFILENAME}
    counter=`expr $counter - 1`
    grep -v '^$' ${MENUFILENAME}|sed -e "/^\[submenu].*/{
n
N
/^\[submenu].*\n\[end]/d
}"|sed -e "/^\[submenu].*/{
N
/^\[submenu].*\n\[end]/d
}" > ${MENUFILENAME}.tmp
done
rm -f ${MENUFILENAME}.tmp
}
# End functions


WHOAMI=`whoami`
[ "$WHOAMI" = root ] && PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

# Check for Imlib2-support
if @pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -info 2> /dev/null | grep "^IMLIB" >/dev/null 2>&1; then
    PNG_ICONS="yes"
else
    # better assume to assume "no"
    PNG_ICONS="no"
fi

# menu defaults (if translation forget to set one of them)

MENU_ENCODING=UTF-8 # (its also ascii)

ABOUTITEM='About'
ANALYZERMENU='Analyzers'
BACKGROUNDMENU='Backgrounds'
BACKGROUNDMENUTITLE='Set the Background'
BROWSERMENU='Browsers'
BURNINGMENU='Burning'
CONFIGUREMENU='Configure'
EDITORMENU='Editors'
EDUCATIONMENU='Education'
EXITITEM='Exit'
FBSETTINGSMENU='Fluxbox menu'
FILEUTILSMENU='File utils'
FLUXBOXCOMMAND='Fluxbox Command'
GAMESMENU='Games'
GNOMEMENUTEXT='Gnome-menus'
GRAPHICMENU='Graphics'
KDEMENUTEXT='KDE-menus'
LOCKSCREEN='Lock screen'
MISCMENU='Misc'
MULTIMEDIAMENU='Multimedia'
MUSICMENU='Audio'
NETMENU='Net'
NEWS='News'
OFFICEMENU='Office'
RANDOMBACKGROUND='Random Background'
REGENERATEMENU='Regen Menu'
RELOADITEM='Reload config'
RESTARTITEM='Restart'
RUNCOMMAND='Run'
SCREENSHOT='Screenshot'
STYLEMENUTITLE='Choose a style...'
SYSTEMSTYLES='System Styles'
SYSTEMTOOLSMENU='System Tools'
TERMINALMENU='Terminals'
TOOLS='Tools'
USERSTYLES='User Styles'
VIDEOMENU='Video'
WINDOWMANAGERS='Window Managers'
WINDOWNAME='Window name'
WORKSPACEMENU='Workspace List'
XUTILSMENU='X-utils'

# Check translation
case ${LC_ALL} in
    ru_RU*) #Russian locales

# Ah my Russian hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=KOI8-R

        BACKGROUNDMENU='ïÂÏÉ'
        BACKGROUNDMENUTITLE='õÓÔÁÎÏ×ÉÔØ ÏÂÏÉ'
        BROWSERMENU='âÒÁÕÚÅÒÙ'
        CONFIGUREMENU='îÁÓÔÒÏÊËÁ'
        EDITORMENU='òÅÄÁËÔÏÒÙ'
        EXITITEM='÷ÙÊÔÉ'
        FBSETTINGSMENU='FB-ÎÁÓÔÒÏÊËÉ'
        FILEUTILSMENU='æÁÊÌÏ×ÙÅ ÕÔÉÌÉÔÙ'
        FLUXBOXCOMMAND='÷ÙÐÏÌÎÉÔØ ËÏÍÁÎÄÕ'
        GAMESMENU='éÇÒÙ'
        GNOMEMENUTEXT='Gnome-ÍÅÎÀ'
        GRAPHICMENU='çÒÁÆÉËÁ'
        KDEMENUTEXT='KDE-ÍÅÎÀ'
        LOCKSCREEN='úÁÂÌÏËÉÒÏ×ÁÔØ ÜËÒÁÎ'
        MISCMENU='ðÒÏÞÅÅ'
        MUSICMENU='ú×ÕË'
        NETMENU='óÅÔØ'
        OFFICEMENU='ïÆÉÓÎÙÅ ÐÒÉÌÏÖÅÎÉÑ'
        RANDOMBACKGROUND='óÌÕÞÁÊÎÙÅ ÏÂÏÉ'
        REGENERATEMENU='óÏÚÄÁÔØ ÍÅÎÀ ÚÁÎÏ×Ï'
        RELOADITEM='ðÅÒÅÎÁÓÔÒÏÉÔØ'
        RESTARTITEM='ðÅÒÅÚÁÐÕÓÔÉÔØ'
        RUNCOMMAND='÷ÙÐÏÌÎÉÔØ'
        SCREENSHOT='óÎÉÍÏË ÜËÒÁÎÁ'
        STYLEMENUTITLE='÷ÙÂÅÒÉÔÅ ÓÔÉÌØ'
        SYSTEMSTYLES='óÉÓÔÅÍÎÙÅ ÓÔÉÌÉ'
        TERMINALMENU='ôÅÒÍÉÎÁÌÙ'
        TOOLS='õÔÉÌÉÔÙ'
        USERSTYLES='ðÏÌØÚÏ×ÁÔÅÌØÓËÉÅ ÓÔÉÌÉ'
        WINDOWMANAGERS='íÅÎÅÄÖÅÒÙ ÏËÏÎ'
        WINDOWNAME='éÍÑ ÏËÎÁ'
        WORKSPACEMENU='òÁÂÏÞÉÅ ÐÒÏÓÔÒÁÎÓÔ×Á'
        XUTILSMENU='X-ÕÔÉÌÉÔÙ'
        ;;

    cs_CZ.ISO*) # Czech locales (ISO-8859-2 encodings)

        MENU_ENCODING=ISO-8859-2

        ABOUTITEM='O programu...'
        BACKGROUNDMENU='Pozadí'
        BACKGROUNDMENUTITLE='Nastavení pozadí'
        BROWSERMENU='Prohlí¾eèe'
        BURNINGMENU='Vypalování'
        CONFIGUREMENU='Konfigurace'
        EDITORMENU='Editory'
        EXITITEM='Ukonèit'
        FBSETTINGSMENU='Fluxbox Menu'
        FILEUTILSMENU='Souborové utility'
        FLUXBOXCOMMAND='Pøíkaz Fluxboxu'
        GAMESMENU='Hry'
        GNOMEMENUTEXT='Gnome-menu'
        GRAPHICMENU='Grafika'
        KDEMENUTEXT='KDE-menu'
        LOCKSCREEN='Zamknout obrazovku'
        MISCMENU='Rùzné'
        MULTIMEDIAMENU='Multimédia'
        MUSICMENU='Audio'
        NETMENU='Internet'
        NEWS='News'
        OFFICEMENU='Kanceláø'
        RANDOMBACKGROUND='Náhodné pozadí'
        REGENERATEMENU='Obnovení menu'
        RELOADITEM='Obnovení konfigurace'
        RESTARTITEM='Restart'
        RUNCOMMAND='Spustit program...'
        SCREENSHOT='Screenshot'
        STYLEMENUTITLE='Volba stylu...'
        SYSTEMTOOLSMENU='Systémové utility'
        SYSTEMSTYLES='Systémové styly'
        TERMINALMENU='Terminály'
        TOOLS='Nástroje'
        USERSTYLES='U¾ivatelské styly'
        VIDEOMENU='Video'
        WINDOWMANAGERS='Okenní mana¾ery'
        WINDOWNAME='Jméno okna'
        WORKSPACEMENU='Seznam ploch'
        XUTILSMENU='X-utility'
        ;;

    de_DE*) # german locales

        MENU_ENCODING=ISO-8859-15

        BACKGROUNDMENU='Hintergrundbilder'
        BACKGROUNDMENUTITLE='Hintergrundbild setzen'
        BROWSERMENU='Internet-Browser'
        CONFIGUREMENU='Einstellungen'
        EDITORMENU='Editoren'
        EXITITEM='Beenden'
        FBSETTINGSMENU='Fluxbox-Einstellungen'
        FILEUTILSMENU='Datei-Utilities'
        FLUXBOXCOMMAND='Fluxbox Befehl'
        GAMESMENU='Spiele'
        GNOMEMENUTEXT='Gnome-Menues'
        GRAPHICMENU='Grafik'
        KDEMENUTEXT='Kde-Menues'
        LOCKSCREEN='Bildschirmsperre'
        MISCMENU='Sonstiges'
        MUSICMENU='Musik'
        NETMENU='Netzwerk'
        OFFICEMENU='Bueroprogramme'
        RANDOMBACKGROUND='Zufaelliger Hintergrund'
        REGENERATEMENU='Menu-Regeneration'
        RELOADITEM='Konfiguration neu laden'
        RESTARTITEM='Neustarten'
        RUNCOMMAND='Ausführen'
        SCREENSHOT='Bildschirmfoto'
        STYLEMENUTITLE='Einen Stil auswaehlen...'
        SYSTEMSTYLES='Systemweite Stile'
        TERMINALMENU='Terminals'
        TOOLS='Helfer'
        USERSTYLES='Eigene Stile'
        WINDOWMANAGERS='Window Manager'
        WINDOWNAME='Window Name'
        WORKSPACEMENU='Arbeitsflaechenliste'
        XUTILSMENU='X-Anwendungen'
        ;;
    sv_SE*) #Swedish locales
# Ah my Swedish hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=ISO-8859-1

        BACKGROUNDMENU='Bakgrunder'
        BACKGROUNDMENUTITLE='Sätt bakgrund'
        BROWSERMENU='Webbläsare'
        CONFIGUREMENU='Konfiguration'
        EDITORMENU='Editorer'
        EXITITEM='Avsluta'
        FBSETTINGSMENU='FB-inställningar'
        FILEUTILSMENU='Filverktyg'
        FLUXBOXCOMMAND='Fluxbox kommando'
        GAMESMENU='Spel'
        GNOMEMENUTEXT='Gnome-menyer'
        GRAPHICMENU='Grafik'
        KDEMENUTEXT='KDE-menyer'
        LOCKSCREEN='Lås skärm'
        MISCMENU='Blandat'
        MULTIMEDIAMENU='Multimedia'
        MUSICMENU='Musik'
        NETMENU='Internet'
        OFFICEMENU='Office'
        RANDOMBACKGROUND='Slumpmässig bakgrund'
        REGENERATEMENU='Generera meny'
        RELOADITEM='Ladda om konfig'
        RESTARTITEM='Starta om'
        RUNCOMMAND='Kör'
        SCREENSHOT='Skärmdump'
        STYLEMENUTITLE='Välj en stil'
        SYSTEMSTYLES='Stiler'
        TERMINALMENU='Terminaler'
        TOOLS='Verktyg'
        USERSTYLES='Stiler'
        VIDEOMENU='Video'
        WINDOWMANAGERS='Fönsterhanterare'
        WINDOWNAME='Fönsternamn'
        WORKSPACEMENU='Arbetsytor'
        XUTILSMENU='X-program'
        ;;
    nl_*) #Nederlandse locales

        MENU_ENCODING=ISO-8859-15

        BACKGROUNDMENU='Achtergrond'
        BACKGROUNDMENUTITLE='Kies een achtergrond'
        BROWSERMENU='Browsers'
        CONFIGUREMENU='Instellingen'
        EDITORMENU='Editors'
        EXITITEM='Afsluiten'
        FBSETTINGSMENU='FB-Instellingen'
        FILEUTILSMENU='Verkenners'
        FLUXBOXCOMMAND='Fluxbox Commando'
        GAMESMENU='Spelletjes'
        GNOMEMENUTEXT='Gnome-menu'
        GRAPHICMENU='Grafisch'
        KDEMENUTEXT='KDE-menu'
        LOCKSCREEN='Scherm op slot'
        MISCMENU='Onregelmatig'
        MUSICMENU='Muziek'
        NETMENU='Internet'
        OFFICEMENU='Office'
        RANDOMBACKGROUND='Willekeurige Achtergrond'
        REGENERATEMENU='Nieuw Menu'
        RELOADITEM='Vernieuw instellingen'
        RESTARTITEM='Herstart'
        RUNCOMMAND='Voer uit'
        SCREENSHOT='Schermafdruk'
        STYLEMENUTITLE='Kies een stijl'
        SYSTEMSTYLES='Systeem Stijlen'
        TERMINALMENU='Terminals'
        TOOLS='Gereedschap'
        USERSTYLES='Gebruikers Stijlen'
        WINDOWMANAGERS='Venster Managers'
        WINDOWNAME='Venster Naam'
        WORKSPACEMENU='Werkveld menu'
        XUTILSMENU='X-Gereedschap'
        ;;
    fi_FI*) #Finnish locales

        MENU_ENCODING=ISO-8859-1

        ABOUTMENU='Tietoja ohjelmasta'
        ABOUTITEM='Tietoja ohjelmasta'
        BACKGROUNDMENU='Taustakuvat'
        BACKGROUNDMENUTITLE='Määritä taustakuva'
        BROWSERMENU='Selaimet'
        CONFIGUREMENU='Asetukset'
        EDITORMENU='Editorit'
        EXITITEM='Lopeta'
        FBSETTINGSMENU='Fluxboxin asetukset'
        FILEUTILSMENU='Tiedostotyökalut'
        FLUXBOXCOMMAND='Fluxbox komentorivi'
        GAMESMENU='Pelit'
        GNOMEMENUTEXT='Gnomen valikot'
        GRAPHICMENU='Grafiikka'
        KDEMENUTEXT='KDE:n valikot'
        LOCKSCREEN='Lukitse näyttö'
        MISCMENU='Sekalaista'
        MUSICMENU='Musiikki'
        NETMENU='Verkko'
        OFFICEMENU='Toimisto-ohjelmat'
        RANDOMBACKGROUND='Satunnainen taustakuva'
        REGENERATEMENU='Päivitä valikko'
        RELOADITEM='Päivitä'
        RESTARTITEM='Käynnistä uudelleen'
        RUNCOMMAND='Suorita'
        SCREENSHOT='Kuvakaappaus'
        STYLEMENUTITLE='Valitse tyyli'
        SYSTEMSTYLES='Järjestelmän tyylit'
        TERMINALMENU='Terminaalit'
        TOOLS='Työkalut'
        USERSTYLES='Käyttäjän tyylit'
        WINDOWMANAGERS='Ikkunointiohjelmat'
        WINDOWNAME='Ikkunan nimi'
        WORKSPACEMENU='Työalueet'
        XUTILSMENU='X-Ohjelmat'
        ;;
    ja_JP*) #Japanese locales
# Ah my Japanese hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=eucJP

        BACKGROUNDMENU='ÇØ·Ê'
        BACKGROUNDMENUTITLE='ÇطʤÎÀßÄê'
        BROWSERMENU='¥Ö¥é¥¦¥¶'
        CONFIGUREMENU='ÀßÄê'
        EDITORMENU='¥¨¥Ç¥£¥¿'
        EXITITEM='½ªÎ»'
        FBSETTINGSMENU='Fluxbox¤ÎÀßÄê'
        FILEUTILSMENU='¥Õ¥¡¥¤¥ëÁàºî'
        FLUXBOXCOMMAND='Fluxbox¥³¥Þ¥ó¥É'
        GAMESMENU='¥²¡¼¥à'
        GNOMEMENUTEXT='Gnome¥á¥Ë¥å¡¼'
        GRAPHICMENU='²èÁü'
        KDEMENUTEXT='KDE¥á¥Ë¥å¡¼'
        LOCKSCREEN='¥¹¥¯¥ê¡¼¥ó¥í¥Ã¥¯'
        MISCMENU='¤¤¤í¤¤¤í'
        MUSICMENU='²»³Ú'
        NETMENU='¥Í¥Ã¥È¥ï¡¼¥¯'
        OFFICEMENU='¥ª¥Õ¥£¥¹(Office)'
        RANDOMBACKGROUND='ÇØ·Ê(¥é¥ó¥À¥à)'
        REGENERATEMENU='¥á¥Ë¥å¡¼ºÆ¹½À®'
        RELOADITEM='ºÆÆɤ߹þ¤ß'
        RESTARTITEM='ºÆµ¯Æ°'
        RUNCOMMAND='¥³¥Þ¥ó¥É¤Î¼Â¹Ô'
        SCREENSHOT='¥¹¥¯¥ê¡¼¥ó¥·¥ç¥Ã¥È'
        STYLEMENUTITLE='¥¹¥¿¥¤¥ëÁªÂò...'
        SYSTEMSTYLES='¥¹¥¿¥¤¥ë'
        TERMINALMENU='¥¿¡¼¥ß¥Ê¥ë'
        TOOLS='¥Ä¡¼¥ë'
        USERSTYLES='¥¹¥¿¥¤¥ë'
        WINDOWMANAGERS='¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã'
        WINDOWNAME='¥¦¥£¥ó¥É¥¦Ì¾'
        WORKSPACEMENU='¥ï¡¼¥¯¥¹¥Ú¡¼¥¹'
        XUTILSMENU='X¥æ¡¼¥Æ¥£¥ê¥Æ¥£'
        ;;
    fr_FR*) # french locales
# Ah my french hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=ISO-8859-15

        ANALYZERMENU='Analyseurs'
        BACKGROUNDMENU="Fond d'écran"
        BACKGROUNDMENUTITLE="Changer le fond d'écran"
        BROWSERMENU='Navigateurs'
        CONFIGUREMENU='Configurer'
        EDITORMENU='Éditeurs'
        EXITITEM='Sortir'
        FBSETTINGSMENU='Configurer Fluxbox'
        FILEUTILSMENU='Outils fichiers'
        FLUXBOXCOMMAND='Commande Fluxbox'
        GAMESMENU='Jeux'
        GNOMEMENUTEXT='Menus Gnome'
        GRAPHICMENU='Graphisme'
        KDEMENUTEXT='Menus KDE'
        LOCKSCREEN="Verrouiller l'écran"
        MISCMENU='Divers'
        MULTIMEDIAMENU='Multimédia'
        MUSICMENU='Musique'
        NETMENU='Réseau'
        OFFICEMENU='Bureautique'
        RANDOMBACKGROUND="Fond d'écran aléatoire"
        REGENERATEMENU='Régénérer le menu'
        RELOADITEM='Recharger la configuration'
        RESTARTITEM='Redémarrer Fluxbox'
        RUNCOMMAND='Run'
        SCREENSHOT="Capture d'écran"
        STYLEMENUTITLE='Choisir un style...'
        SYSTEMSTYLES='Styles Système'
        SYSTEMTOOLSMENU='Outils Système'
        TERMINALMENU='Terminaux'
        TOOLS='Outils'
        USERSTYLES='Styles Utilisateur'
        VIDEOMENU='Vidéo'
        WINDOWMANAGERS='Gestionnaires de fenêtres'
        WINDOWNAME='Nom de la fenêtre'
        WORKSPACEMENU='Liste des bureaux'
        XUTILSMENU='Outils X'
        ;;
    it_IT*) # italian locales

        MENU_ENCODING=ISO-8859-1

        BACKGROUNDMENU='Sfondi'
        BACKGROUNDMENUTITLE='Imposta lo sfondo'
        BROWSERMENU='Browsers'
        CONFIGUREMENU='Configurazione'
        EDITORMENU='Editori'
        EXITITEM='Esci'
        FBSETTINGSMENU='Preferenze'
        FILEUTILSMENU='Utilità'
        FLUXBOXCOMMAND='Comando Fluxbox'
        GAMESMENU='Giochi'
        GNOMEMENUTEXT='Gnome'
        GRAPHICMENU='Grafica'
        KDEMENUTEXT='KDE'
        LOCKSCREEN='Blocca lo schermo'
        MISCMENU='Varie'
        MUSICMENU='Musica'
        NETMENU='Internet'
        OFFICEMENU='Office'
        RANDOMBACKGROUND='Sfondo casuale'
        REGENERATEMENU='Rigenera il menu'
        RELOADITEM='Rileggi la configurazione'
        RESTARTITEM='Riavvia'
        RUNCOMMAND='Esegui'
        SCREENSHOT='Schermata'
        STYLEMENUTITLE='Scegli uno stile'
        SYSTEMSTYLES='Stile'
        TERMINALMENU='Terminali'
        TOOLS='Attrezzi'
        USERSTYLES='Stile'
        WINDOWMANAGERS='Gestori finestre'
        WINDOWNAME='Nome della finestra'
        WORKSPACEMENU='Aree di lavoro'
        XUTILSMENU='Utilità X'
        ;;
    ro_RO*) # Romanian locales
# Ah my Romanian hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=ISO-8859-15

        BACKGROUNDMENU='Fundaluri'
        BACKGROUNDMENUTITLE='Alege fundalul'
        BROWSERMENU='Navigatoare'
        CONFIGUREMENU='Configurare'
        EDITORMENU='Editoare'
        EXITITEM='Iesire'
        FBSETTINGSMENU='Meniul Fluxbox'
        FILEUTILSMENU='Utilitare de fisier'
        FLUXBOXCOMMAND='Comanda Fluxbox'
        GAMESMENU='Jocuri'
        GNOMEMENUTEXT='Meniu Gnome'
        GRAPHICMENU='Grafica'
        KDEMENUTEXT='Meniu KDE'
        LOCKSCREEN='Incuie ecranul'
        MISCMENU='Diverse'
        MULTIMEDIAMENU='Multimedia'
        MUSICMENU='Muzica'
        NETMENU='Retea'
        OFFICEMENU='Office'
        RANDOMBACKGROUND='Fundal aleator'
        REGENERATEMENU='Regenereaza meniul'
        RELOADITEM='Reincarca configuratia'
        RESTARTITEM='Restart'
        RUNCOMMAND='Lanseaza'
        SCREENSHOT='Captura ecran'
        STYLEMENUTITLE='Alege un stil...'
        SYSTEMSTYLES='Stiluri sistem'
        TERMINALMENU='Terminale'
        TOOLS='Unelte'
        USERSTYLES='Stiluri utilizator'
        WINDOWMANAGERS='WindowManagers'
        WINDOWNAME='Nume fereastra'
        WORKSPACEMENU='Lista workspace-uri'
        XUTILSMENU='Utilitare X'
        ;;
    es_ES*) # spanish locales

        MENU_ENCODING=ISO-8859-15

        ABOUTITEM='Acerca'
        BACKGROUNDMENU='Fondos'
        BACKGROUNDMENUTITLE='Seleccionar Fondo'
        BROWSERMENU='Navegadores'
        BURNINGMENU='Herramientas de grabación'
        CONFIGUREMENU='Configurar'
        EDITORMENU='Editores'
        EDUCATIONMENU='Educación'
        EXITITEM='Salir'
        FBSETTINGSMENU='Menú fluxbox'
        FILEUTILSMENU='Utilidades'
        FLUXBOXCOMMAND='Comandos de Fluxbox'
        GAMESMENU='Juegos'
        GNOMEMENUTEXT='Menús Gnome'
        GRAPHICMENU='Gráficos'
        KDEMENUTEXT='Menús KDE'
        LOCKSCREEN='Bloquear Pantalla'
        MISCMENU='Varios'
        MULTIMEDIAMENU='Multimedia'
        MUSICMENU='Música'
        NETMENU='Red'
        NEWS='Noticias'
        OFFICEMENU='Oficina'
        RANDOMBACKGROUND='Fondo Aleatoreo'
        REGENERATEMENU='Regenerar Menú'
        RELOADITEM='Reconfigurar'
        RESTARTITEM='Reiniciar'
        RUNCOMMAND='Ejecutar'
        SCREENSHOT='Captura de Pantalla'
        STYLEMENUTITLE='Escoge un Estilo...'
        SYSTEMSTYLES='Estilos del Sistema'
        TERMINALMENU='Terminales'
        TOOLS='Herramienta'
        USERSTYLES='Estilos del Usuario'
        VIDEOMENU='Video'
        WINDOWMANAGERS='Gestores de Ventanas'
        WINDOWNAME='Nombre de Ventana'
        WORKSPACEMENU='Lista de Escritorios'
        XUTILSMENU='Utilidades X'
        ;;
    pl_PL*) # Polish locales
# Ah my Russian hero. Please help me update the translation
# $ cp fluxbox-generate-menu.in fluxbox-generate-menu.in.orig
# $ $EDITOR fluxbox-generate-menu.in
# $ diff -u fluxbox-generate-menu.in.orig fluxbox-generate-menu.in > fbgm.diff
# email fbgm.diff to han@mijncomputer.nl

        MENU_ENCODING=ISO-8859-2

        BACKGROUNDMENU='Tapety'
        BACKGROUNDMENUTITLE='Ustaw tapetê'
        BROWSERMENU='Przegl±darki'
        CONFIGUREMENU='Konfiguracja'
        EDITORMENU='Edytory'
        EXITITEM='Wyj¶cie'
        FBSETTINGSMENU='Menu Fluxbox'
        FILEUTILSMENU='Narzêdzia do plików'
        FLUXBOXCOMMAND='Polecenia Fluxbox'
        GAMESMENU='Gry'
        GNOMEMENUTEXT='Menu Gnome'
        GRAPHICMENU='Grafika'
        KDEMENUTEXT='Menu KDE'
        LOCKSCREEN='Zablokuj ekran'
        MISCMENU='Ró¿ne'
        MULTIMEDIAMENU='Multimedia'
        MUSICMENU='Muzyka'
        NETMENU='Sieæ'
        OFFICEMENU='Aplikacje biurowe'
        RANDOMBACKGROUND='Losowa tapeta'
        REGENERATEMENU='Wygeneruj menu'
        RELOADITEM='Od¶wie¿ konfiguracjê'
        RESTARTITEM='Restartuj'
        RUNCOMMAND='Uruchom...'
        SCREENSHOT='Zrzut ekranu'
        STYLEMENUTITLE='Wybierz styl...'
        SYSTEMSTYLES='Style systemowe'
        TERMINALMENU='Terminale'
        TOOLS='Narzêdzia'
        USERSTYLES='Style u¿ytkownika'
        WINDOWMANAGERS='Menad¿ery okien'
        WINDOWNAME='Nazwy okien'
        WORKSPACEMENU='Lista pulpitów'
        XUTILSMENU='Narzêdzia X'
        ;;
    pt_PT*) # Portuguese locales

        MENU_ENCODING=ISO-8859-1

        ABOUTMENU="Sobre"
        BACKGROUNDMENU='Imagens de Fundo'
        BACKGROUNDMENUTITLE='Definir Imagem de Fundo'
        BROWSERMENU='Browsers'
        BURNINGMENU='Ferramentas de Gravação'
        CONFIGUREMENU='Configuração'
        EDITORMENU='Editores'
        EDUCATIONMENU='Educação'
        EXITITEM='Sair'
        FBSETTINGSMENU='Menu Fluxbox'
        FILEUTILSMENU='Utilitários de Ficheiros'
        FLUXBOXCOMMAND='Comando Fluxbox'
        GAMESMENU='Jogos'
        GNOMEMENUTEXT='Menu Gnome'
        GRAPHICMENU='Gráficos'
        KDEMENUTEXT='Menu KDE'
        LOCKSCREEN='Trancar Ecrã'
        MISCMENU='Misc.'
        MULTIMEDIAMENU='Multimédia'
        MUSICMENU='Áudio'
        NETMENU='Rede'
        NEWS='Notícias'
        OFFICEMENU='Escritório'
        RANDOMBACKGROUND='Imagem Aleatória'
        REGENERATEMENU='Regenerar Menu'
        RELOADITEM='Recarregar configuração'
        RESTARTITEM='Reiniciar'
        RUNCOMMAND='Executar'
        SCREENSHOT='Capturar Ecrã'
        STYLEMENUTITLE='Escolha um estilo...'
        SYSTEMSTYLES='Estilos do Sistema'
        SYSTEMTOOLSMENU='Ferramentas de Sistema'
        TERMINALMENU='Terminais'
        TOOLS='Ferramentas'
        USERSTYLES='Estilos do Utilizador'
        VIDEOMENU='Vídeo'
        WINDOWMANAGERS='Gestores de Janelas'
        WINDOWNAME='Nome da Janela'
        WORKSPACEMENU='Lista de Áreas de Trabalho'
        XUTILSMENU='Utilitários X'
        ;;
    nb_NO*) # Norwegian locales

        MENU_ENCODING=UTF-8

        ABOUTITEM='Om'
        BACKGROUNDMENU='Bakgrunner'
        BACKGROUNDMENUTITLE='Velg bakgrunn'
        BROWSERMENU='Nettlesere'
        CONFIGUREMENU='Oppsett'
        EDITORMENU='Tekstredigeringsprogram'
        EDUCATIONMENU='Lek og lær'
        EXITITEM='Avslutt'
        FBSETTINGSMENU='FluxBox-meny'
        FILEUTILSMENU='Filverktøy'
        FLUXBOXCOMMAND='FluxBox-kommando'
        GAMESMENU='Spill'
        GNOMEMENUTEXT='Gnome-menyer'
        GRAPHICMENU='Grafikk'
        KDEMENUTEXT='KDE-menyer'
        LOCKSCREEN='LÃ¥s skjermen'
        MISCMENU='Diverse'
        MULTIMEDIAMENU='Multimedia'
        MUSICMENU='Lyd'
        NETMENU='Nett'
        NEWS='Nyheter'
        OFFICEMENU='Kontor'
        RANDOMBACKGROUND='Tilfeldig bakgrunn'
        REGENERATEMENU='Regen Menu'
        RELOADITEM='Last oppsett på nytt'
        RESTARTITEM='Start på nytt'
        RUNCOMMAND='Kjør'
        SCREENSHOT='Ta bilde'
        STYLEMENUTITLE='Velg en stil . . .'
        SYSTEMSTYLES='System-stiler'
        TERMINALMENU='Terminaler'
        TOOLS='Verktøy'
        USERSTYLES='Bruker-stiler'
        VIDEOMENU='Video'
        WINDOWMANAGERS='Vindusbehandlere'
        WINDOWNAME='Vindunavn'
        WORKSPACEMENU='Liste over arbeidsområder'
        XUTILSMENU='X-verktøy'
        ;;
    *)
        ;;
esac

# Set Defaults
USERFLUXDIR="${HOME}/.@pkgprefix@fluxbox@pkgsuffix@"
MENUFILENAME="${MENUFILENAME:=${USERFLUXDIR}/menu}"
MENUTITLE="${MENUTITLE:=Fluxbox}"
HOMEPAGE="${HOMEPAGE:=fluxbox.org}"
USERMENU="${USERMENU:=${USERFLUXDIR}/usermenu}"
MENUCONFIG="${MENUCONFIG:=${USERFLUXDIR}/menuconfig}"
DOSUDO="no"

# Read the menuconfig file if it exists or else create it.
# But not during install time, use envvar for sun
if [ ! "${INSTALL}" = Yes ]; then
    if [ -r ${MENUCONFIG} ]; then
        . ${MENUCONFIG}
    else
        if [ ! "$WHOAMI" = root ]; then # this is only for users.
            if touch ${MENUCONFIG}; then
                cat << EOF > ${MENUCONFIG}
# This file is read by fluxbox-generate_menu.  If you don't like a
# default you can change it here.  Don't forget to remove the # in front
# of the line.

# Your favourite terminal. Put the command in quotes if you want to use
# options. Put a backslash in before odd chars
# MY_TERM='Eterm --tint \#123456'
# MY_TERM='aterm -tint \$(random_color)'

# Your favourite browser. You can also specify options.
# MY_BROWSER=mozilla

# Name of the outputfile
# MENUFILENAME=${USERFLUXDIR}/menu

# MENUTITLE=\`@pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -version|cut -d " " -f-2\`

# standard url for console-browsers
# HOMEPAGE=fluxbox.org

# location with your own menu-entries
# USERMENU=~/.@pkgprefix@fluxbox@pkgsuffix@/usermenu

# Put the launcher you would like to use here
# LAUNCHER=@pkgprefix@fbrun@pkgsuffix@@EXEEXT@
# LAUNCHER=fbgm

# Options for fbrun
# FBRUNOPTIONS='-font 10x20 -fg grey -bg black -title run'

# --- PREFIX'es
# These are prefixes; So if fluxbox is installed in @PREFIX@/bin/fluxbox
# your prefix is: @PREFIX@

# fluxbox-generate already looks in /usr/X11R6, /usr, /usr/local and /opt so
# there should be no need to specify them.
#
# PREFIX=@PREFIX@
# GNOME_PREFIX=/opt/gnome
# KDE_PREFIX=/opt/kde


# Separate the list of background dirs with colons ':'
# BACKGROUND_DIRS="${USERFLUXDIR}/backgrounds/:@PREFIX@/share/fluxbox/backgrounds/:/usr/share/wallpapers"


# --- Boolean variables.
# Setting a variable to ``no'' won't help. Comment them out if you don't
# want them. Settings are overruled by the command-line options.

# Include all backgrounds in your backgrounds-directory
# BACKGROUNDMENUITEM=yes

# Include KDE-menus
# KDEMENU=yes

# Include Gnome-menus
# GNOMEMENU=yes

# Enable sudo commands
# DOSUDO=yes

# Don't cleanup the menu
# REMOVE=no

# Don't add icons to the menu
# NO_ICON=yes

EOF
            else
                echo "Warning: I couldn't create ${MENUCONFIG}" >&2
            fi
        fi
    fi
fi

BACKUPOPTIONS=$@
if [ -n "$BACKUPOPTIONS" ]; then
    FBGM_CMD="@pkgprefix@fluxbox-generate_menu@pkgsuffix@ $BACKUPOPTIONS"
else
    FBGM_CMD=@pkgprefix@fluxbox-generate_menu@pkgsuffix@
fi
# Get options.
while [ $# -gt 0 ]; do
    case "$1" in
        -B) BACKGROUNDMENUITEM=yes; shift;;
        -k) KDEMENU=yes; shift;;
        -g) GNOMEMENU=yes; shift;;
        -in) NO_ICON=yes; shift;;
        -is) OTHER_ICONPATHS="
                /usr/share/icons
                /usr/share/icons/mini
                /usr/share/pixmaps
                /usr/local/share/icons
                /usr/local/share/icons/mini
                /usr/local/share/pixmaps
                /usr/share/xclass/icons
                /usr/share/xclass/pixmaps
                /usr/local/share/xclass/icons
                /usr/local/share/xclass/pixmaps
                /usr/X11R6/share/icons/default/16x16
                /usr/X11R6/share/icons/kde/16x16
                /usr/X11R6/share/icons/hicolor/16x16
                /usr/local/X11R6/share/icons/default/16x16
                /usr/local/X11R6/share/icons/kde/16x16
                /usr/local/X11R6/share/icons/hicolor/16x16
            "
            shift;;
        -ds) OTHER_DESKTOP_PATHS="
                /usr/share/mimelnk 
                /usr/share/applications
                /usr/share/xsessions 
                /usr/share/services 
            "
            # /usr/share/apps \
            shift;;
        -i) USER_ICONPATHS=${2};
            #needs testing 
            for aPath in $2; do
                testoption di $1 $aPath; 
            done
            shift 2;;
        -d) USER_DESKTOP_PATHS=${2};
            #needs testing 
            for aPath in $2; do
                testoption di $1 $aPath; 
            done
            shift 2;;
        -t) MY_TERM=${2}; testoption ex $1 $2; shift 2;;
        -b) MY_BROWSER=${2}; testoption ex $1 $2; shift 2;;
        -o) MENUFILENAME=${2}; shift 2; CHECKINIT=NO ;;
        -p) PREFIX=${2}; testoption di $1 $2; shift 2;;
        -n) GNOME_PREFIX=${2}; testoption di $1 $2; shift 2;;
        -q) KDE_PREFIX=${2}; testoption di $1 $2; shift 2;;
        -m) MENUTITLE=${2}; testoption sk $1 $2; shift 2;;
        -w) HOMEPAGE=${2}; testoption sk $1 $2; shift 2;;
        -u) USERMENU=${2}; testoption fl $1 $2; shift 2;;
	-su) DOSUDO=yes; shift;;
        -r) REMOVE=no; shift;;
        -h) display_help ; exit 0 ;;
        -a) display_authors ; exit 0 ;;
        --*) echo "fluxbox-generate_menu doesn't recognize -- gnu-longopts."
            echo 'Use fluxbox-generate_menu -h for a long help message.'
            display_usage
            exit 1 ;;
        -[a-zA-Z][a-zA-Z]*)
            # split concatenated single-letter options apart
            FIRST="$1"; shift
            set -- `echo "$FIRST" | sed 's/^-\(.\)\(.*\)/-\1 -\2/'` "$@"
            ;;
        -*)
            echo 1>&2 "fluxbox-generate_menu: unrecognized option "\`"$1'"
            display_usage
            exit 1
            ;;
        *)
            break
            ;;
    esac
done

# Check defaults

# Can we actually create ${MENUFILENAME}
touch ${MENUFILENAME} 2> /dev/null
if [ $? -ne 0 ]; then
    echo "Fatal error: can't create or write to $MENUFILENAME" >&2
    exit 1
fi

# backup menu
if [ -w "${MENUFILENAME}" ]; then
    if [ -f ${MENUFILENAME}.firstbak ]; then
        cp ${MENUFILENAME} ${MENUFILENAME}.firstbak
    fi
    if [ -s "${MENUFILENAME}" ]; then
       mv ${MENUFILENAME} ${MENUFILENAME}.bak
    fi
fi

# prefix
PREFIX="${PREFIX:=@PREFIX@}"
if [  -z "${PREFIX}" -o ! -d "${PREFIX}" ]; then
    hash @pkgprefix@fluxbox@pkgsuffix@@EXEEXT@
    PREFIX=`hash | grep @pkgprefix@fluxbox@pkgsuffix@ | sed 's,.*\t/,/,' | sed 's,/bin/@pkgprefix@fluxbox@pkgsuffix@@EXEEXT@$,,'`
fi


# gnome prefix
for GNOME_PREFIX in "${GNOME_PREFIX}" /usr/local /usr/X11R6 /usr /opt "${PREFIX}"; do
    if [ -n "${GNOME_PREFIX}" -a -d "$GNOME_PREFIX/share/gnome" ]; then
        break;
    fi
done
# Will remain $PREFIX if all else fails

# kde prefix
for KDE_PREFIX in "${KDE_PREFIX}" /usr/local /usr/X11R6 /usr /opt "${PREFIX}"; do
    if [ -n "${KDE_PREFIX}" -a -d "$KDE_PREFIX/share/applnk" ]; then
        break;
    fi
done

if [ -z "${INSTALL}" ] && [ -z "${NO_ICON}" ]; then
    # [ -z "$dnlamVERBOSE" ] && dnlamVERBOSE=": echo"   # for debugging
    FB_ICONDIR="$USERFLUXDIR/icons"
    [ -r "$FB_ICONDIR" ] || mkdir "$FB_ICONDIR"
    ICONMAPPING="$USERFLUXDIR/iconmapping"

    if [ "$GNOMEMENU" ] ; then
        OTHER_DESKTOP_PATHS="\"$HOME/.gnome/apps\" \"${GNOME_PREFIX}/share/gnome/apps\" $OTHER_DESKTOP_PATHS"
        #[ "OTHER_ICONPATHS" ] && OTHER_ICONPATHS=
    fi
    if [ "$KDEMENU" ] ; then
        OTHER_DESKTOP_PATHS="\"$HOME/.kde/share/applnk\" \"${KDE_PREFIX}/share/applnk\" $OTHER_DESKTOP_PATHS"
        [ "OTHER_ICONPATHS" ] && OTHER_ICONPATHS="\"$HOME\"/.kde/share/icons/{,*} $OTHER_ICONPATHS"
    fi
    [ "$GNOMEMENU$KDEMENU" ] && OTHER_DESKTOP_PATHS="\"$ETCAPPLNK\" $OTHER_DESKTOP_PATHS"

    checkDirs(){
        #echo checkDirs: $* >&2
        CHECKED_DIRS=""
        for DIR in "$@"; do
            if [ -d "$DIR" ]; then
                # todo: should check if there are duplicates
                CHECKED_DIRS="$CHECKED_DIRS \"$DIR\""
            fi
        done
        #echo checkDirs - $CHECKED_DIRS >&2
        echo $CHECKED_DIRS
    }

    OTHER_ICONPATHS=`eval checkDirs $OTHER_ICONPATHS`
    OTHER_DESKTOP_PATHS=`eval checkDirs $OTHER_DESKTOP_PATHS`

    # $dnlamVERBOSE "Using USER_DESKTOP_PATHS=\"$USER_DESKTOP_PATHS\" and USER_ICONPATHS=\"$USER_ICONPATHS\""
    # $dnlamVERBOSE "Using OTHER_ICONPATHS=$OTHER_ICONPATHS"
    # $dnlamVERBOSE "Using OTHER_DESKTOP_PATHS=$OTHER_DESKTOP_PATHS"
    # $dnlamVERBOSE "Calling function: createIconMapping"
    
    # $dnlamVERBOSE "Creating $ICONMAPPING" >&2
    touch "$ICONMAPPING"
    eval createIconMapping $USER_DESKTOP_PATHS $OTHER_DESKTOP_PATHS
    # $dnlamVERBOSE "Done createIconMapping."
fi

# directory for the backgrounds
if [ -z "$BACKGROUND_DIRS" ]; then
    BACKGROUND_DIRS="${USERFLUXDIR}/backgrounds/:${PREFIX}/share/fluxbox/backgrounds/"
fi

# find the default terminal
if find_it_options $MY_TERM; then
    DEFAULT_TERM=$MY_TERM
else
    [ -n "$MY_TERM" ] && echo "Warning: you chose an invalid term." >&2
    #The precise order is up for debate.
    for term in Eterm urxvt urxvtc aterm mrxvt rxvt wterm konsole gnome-terminal xterm; do
        if find_it_options $term; then
            DEFAULT_TERM=$term
            break
        fi
    done
fi
# a unix system without any terms. that's odd
if [ -z "$DEFAULT_TERM" ]; then
    cat << EOF >&2

Warning: I can't find any terminal-emulators in your PATH.  Please fix
your PATH or specify your favourite terminal-emulator with the -t option

EOF
    DEFAULT_TERM=xterm
fi

DEFAULT_TERMNAME=`echo $DEFAULT_TERM|awk '{print $1}'`
DEFAULT_TERMNAME=`basename $DEFAULT_TERMNAME`


# find the default browser
if find_it_options $MY_BROWSER; then
    DEFAULT_BROWSER=$MY_BROWSER
else
    [ -n "$MY_BROWSER" ] && echo "Warning: you chose an invalid browser." >&2
    #The precise order is up for debate.
    for browser in firefox mozilla-firefox chrome chromium google-chrome mozilla-firebird MozillaFirebird opera skipstone mozilla seamonkey galeon konqueror dillo netscape w3m amaya links lynx; do
        if find_it_options $browser; then
            DEFAULT_BROWSER=$browser
            break
        fi
    done
fi
DEFAULT_BROWSERNAME=`echo $DEFAULT_BROWSER|awk '{print $1}'`
if [ "x$DEFAULT_BROWSERNAME" != "x" ]; then
	DEFAULT_BROWSERNAME=`basename $DEFAULT_BROWSERNAME`
else
	DEFAULT_BROWSERNAME="firefox"
fi

if [ -z "$LAUNCHER" ]; then
    LAUNCHER=@pkgprefix@fbrun@pkgsuffix@@EXEEXT@
fi
if [ -n "$FBRUNOPTIONS" ]; then
    # with this, LAUNCHER should be renamed LAUNCHER_NAME, but then there's
    # backwards-compatibility...
    LAUNCHER_CMD="$LAUNCHER $FBRUNOPTIONS"
else
    LAUNCHER_CMD=$LAUNCHER
fi

# if gxmessage exists, use it; else use xmessage
if find_it gxmessage; then
    XMESSAGE=gxmessage
else
    XMESSAGE=xmessage
fi

# Start of menu
cat << EOF > ${MENUFILENAME}
# Generated by fluxbox-generate_menu
#
# If you read this it means you want to edit this file manually, so here
# are some useful tips:
#
# - You can add your own menu-entries to ~/.@pkgprefix@fluxbox@pkgsuffix@/usermenu
#
# - If you miss apps please let me know and I will add them for the next
#   release.
#
# - The -r option prevents removing of empty menu entries and lines which
#   makes things much more readable.
#
# - To prevent any other app from overwriting your menu
#   you can change the menu name in ~/.@pkgprefix@fluxbox@pkgsuffix@/init to:
#     session.menuFile: ~/.@pkgprefix@fluxbox@pkgsuffix@/my-menu

EOF

echo "[begin] (${MENUTITLE})" >> ${MENUFILENAME}

if [ -n "$MENU_ENCODING" ]; then
    append_menu "[encoding] {$MENU_ENCODING}"
fi

append "[exec] (${DEFAULT_TERMNAME}) {${DEFAULT_TERM}}"

case "$DEFAULT_BROWSERNAME" in
    links|w3m|lynx)  append "[exec] (${DEFAULT_BROWSERNAME}) {${DEFAULT_TERM} -e ${DEFAULT_BROWSER} ${HOMEPAGE}}" ;;
    firefox|firebird|mozilla|seamonkey|phoenix|galeon|dillo|netscape|amaya) append "[exec] (${DEFAULT_BROWSERNAME}) {${DEFAULT_BROWSER}}" ;;
    chrome|chromium) append "[exec] (${DEFAULT_BROWSERNAME}) {${DEFAULT_BROWSER}}" ;;
    google-chrome) append "[exec] (${DEFAULT_BROWSERNAME}) {${DEFAULT_BROWSER}}" ;;
    konqueror) append "[exec] (konqueror) {kfmclient openProfile webbrowsing}" ;;
    opera) append "[exec] (opera) {env QT_XFT=true opera}" ;;
    MozillaFirebird) append "[exec] (firebird) {MozillaFirebird}" ;;
    MozillaFirefox) append "[exec] (firefox) {MozillaFirefox}" ;;
    *) append "[exec] ($DEFAULT_BROWSERNAME) {$DEFAULT_BROWSER}" ;;
esac

find_it "${LAUNCHER}" append "[exec]   (${RUNCOMMAND}) {$LAUNCHER_CMD}"


append_submenu "${TERMINALMENU}"
    normal_find xterm urxvt urxvtc gnome-terminal multi-gnome-terminal Eterm \
        konsole aterm mlterm multi-aterm rxvt mrxvt lxterminal
append_menu_end


append_submenu "${NETMENU}"
    append_submenu "${BROWSERMENU}"
        normal_find chrome chromium firefox google-chrome mozilla-firefox MozillaFirefox galeon mozilla seamonkey dillo netscape vncviewer
        find_it links       append "[exec]   (links-graphic) {links -driver x ${HOMEPAGE}}"
        find_it opera       append "[exec]   (opera) {env QT_XFT=true opera}"
        find_it konqueror   append "[exec]   (konqueror) {kfmclient openProfile webbrowsing}"
        find_it links       append "[exec]   (links) {${DEFAULT_TERM} -e links ${HOMEPAGE}}"
        find_it w3m         append "[exec]   (w3m) {${DEFAULT_TERM} -e w3m ${HOMEPAGE}}"
        find_it lynx        append "[exec]   (lynx) {${DEFAULT_TERM} -e lynx ${HOMEPAGE}}"
    append_menu_end

    append_submenu IM
        normal_find pidgin gaim kopete gnomemeeting sim kadu psi amsn aim ayttm everybuddy gabber ymessenger
        find_it licq        append "[exec]   (licq) {env QT_XFT=true licq}"
        cli_find centericq micq
    append_menu_end

    append_submenu Mail
        normal_find sylpheed kmail evolution thunderbird mozilla-thunderbird \
            sylpheed-claws claws-mail
        cli_find mutt pine
    append_menu_end

    append_submenu News
        normal_find liferea pears pan
        cli_find slrn tin
    append_menu_end

    append_submenu IRC
        normal_find xchat xchat-2 ksirc vyqchat lostirc logui konversation kvirc skype
        cli_find irssi epic4 weechat ninja
        find_it BitchX        append "[exec]   (BitchX) {${DEFAULT_TERM} -e BitchX -N}" || \
        find_it bitchx        append "[exec]   (BitchX) {${DEFAULT_TERM} -e bitchx -N}"
        find_it ircii         append "[exec]   (ircii) {${DEFAULT_TERM} -e ircii -s}"
    append_menu_end

    append_submenu P2P
        normal_find gtk-gnutella lopster nicotine pyslsk xmule amule \
            valknut dcgui-qt dc_qt quickdc asami azureus
        cli_find TekNap giFTcurs
    append_menu_end

    append_submenu FTP
        normal_find gftp IglooFTP-PRO kbear
        cli_find ncftp pftp ftp lftp yafc
    append_menu_end

    append_submenu SMB
      normal_find LinNeighborhood jags SambaSentinel
    append_menu_end

    append_submenu "${ANALYZERMENU}"
	  normal_find xnmap nmapfe wireshark ettercap
	  sudo_find xnmap nmapfe wireshark ettercap
    append_menu_end

    normal_find x3270 wpa_gui

append_menu_end

append_submenu "${EDITORMENU}"
    normal_find gvim bluefish nedit gedit geany xedit kword kwrite kate anjuta \
        wings xemacs emacs kvim cream evim scite Ted
    cli_find nano vim vi zile jed joe
    find_it     emacs  append "[exec]   (emacs-nw) {${DEFAULT_TERM} -e emacs -nw}"
    find_it     xemacs append "[exec]   (xemacs-nw) {${DEFAULT_TERM} -e xemacs -nw}"
append_menu_end

append_submenu "${EDUCATIONMENU}"
    normal_find celestia scilab geomview scigraphica oregano xcircuit electric \
        pymol elem chemtool xdrawchem gperiodic stellarium   
    find_it drgeo          append "[exec] (Dr. Geo) {drgeo}"
    find_it     R          append "[exec] (R) {${DEFAULT_TERM} -e R --gui=gnome}"
    cli_find maxima grace yacas octave gnuplot grass coq acl
append_menu_end

append_submenu "${FILEUTILSMENU}"
    find_it     konqueror append "[exec] (konqueror) {kfmclient openProfile filemanagement}"
    normal_find gentoo krusader kcommander linuxcmd rox tuxcmd krename xfe xplore worker endeavour2 evidence
    find_it     nautilus append "[exec] (nautilus) {nautilus --no-desktop --browser}"
    cli_find mc
append_menu_end

append_submenu "${MULTIMEDIAMENU}"
       append_submenu "${GRAPHICMENU}"
               normal_find gimp gimp2 gimp-2.2 inkscape sodipodi xv gqview showimg xpaint kpaint kiconedit \
                   ee xzgv xscreensaver-demo xlock gphoto tuxpaint krita skencil
               find_it xnview           append "[exec] (xnview browser) {xnview -browser}"
               find_it blender          append "[exec] (blender) {blender -w}"
               find_it gears            append "[exec] (Mesa gears) {gears}"
               find_it morph3d          append "[exec] (Mesa morph) {morph3d}"
               find_it reflect          append "[exec] (Mesa reflect) {reflect}"
       append_menu_end

       append_submenu "${MUSICMENU}"
               normal_find xmms noatun alsaplayer gqmpeg aumix xmixer gnome-alsamixer gmix kmix kscd \
                   grecord kmidi xplaycd soundtracker grip easytag audacity \
                   zinf rhythmbox kaboodle beep-media-player amarok tagtool \
                   audacious bmpx
               cli_find cdcd cplay alsamixer orpheus mp3blaster
       append_menu_end


       append_submenu "${VIDEOMENU}"
           normal_find xine gxine aviplay gtv gmplayer xmovie xcdroast xgdb \
               realplay xawtv fxtv ogle goggles vlc
           find_it dvdrip append "[exec] (dvdrip) {nohup dvdrip}"
       append_menu_end

       append_submenu "${XUTILSMENU}"
           normal_find xfontsel xman xload xbiff editres viewres xclock \
               xmag wmagnify gkrellm gkrellm2 vmware portagemaster agave 
           find_it xrdb append "[exec] (Reload .Xdefaults) {xrdb -load \$HOME/.Xdefaults}"
       append_menu_end
append_menu_end


append_submenu "${OFFICEMENU}"
    normal_find xclock xcalc kcalc grisbi qbankmanager evolution
    find_it gcalc           append "[exec] (gcalc) {gcalc}" || \
        find_it gnome-calculator append "[exec] (gcalc) {gnome-calculator}"
    find_it ical            append "[exec] (Calendar)   {ical}"

    # older <=1.1.3 apparently have stuff like swriter, not sowriter
    for ext in s so oo xoo; do
        find_it ${ext}ffice2 && (
            find_it ${ext}ffice2        append "[exec] (Open Office 2)  {${ext}ffice2}"
            find_it ${ext}base2         append "[exec] (OO Base 2)      {${ext}base2}"
            find_it ${ext}calc2         append "[exec] (OO Calc 2)      {${ext}calc2}"
            find_it ${ext}writer2       append "[exec] (OO Writer 2)    {${ext}writer2}"
            find_it ${ext}web2          append "[exec] (OO Web 2)       {${ext}web2}"
            find_it ${ext}html2         append "[exec] (OO HTML 2)      {${ext}html2}"
            find_it ${ext}impress2      append "[exec] (OO Impress 2)   {${ext}impress2}"
            find_it ${ext}draw2         append "[exec] (OO Draw 2)      {${ext}draw2}"
            find_it ${ext}math2         append "[exec] (OO Math 2)      {${ext}math2}"
            find_it ${ext}fromtemplate2 append "[exec] (OO Templates 2) {${ext}fromtemplate2}"
        )
        find_it ${ext}ffice && (
            find_it ${ext}ffice        append "[exec] (Open Office)      {${ext}ffice}"
            find_it ${ext}base         append "[exec] (OO Base)          {${ext}base}"
            find_it ${ext}calc         append "[exec] (OO Calc)          {${ext}calc}"
            find_it ${ext}writer       append "[exec] (OO Writer)        {${ext}writer}"
            find_it ${ext}web          append "[exec] (OO Web)           {${ext}web}"
            find_it ${ext}impress      append "[exec] (OO Impress)       {${ext}impress}"
            find_it ${ext}draw         append "[exec] (OO Draw)          {${ext}draw}"
            find_it ${ext}math         append "[exec] (OO Math)          {${ext}math}"
            find_it ${ext}fromtemplate append "[exec] (OO Templates)     {${ext}fromtemplate}"
            find_it ${ext}padmin       append "[exec] (OO Printer Admin) {${ext}padmin}"
            find_it mrproject          append "[exec] (Mr.Project)       {mrproject}"
        )
    done

    normal_find abiword kword wordperfect katoob lyx acroread xpdf gv ghostview
    normal_find dia xfig
    normal_find gnumeric
append_menu_end

append_submenu "${GAMESMENU}"
    normal_find bzflag gnibbles gnobots2 tuxpuck gataxx glines \
        gnect mahjongg gnomine gnome-stones gnometris gnotravex \
        gnotski iagno knights eboard xboard scid freecell pysol \
        gtali tuxracer xpenguins xsnow xeyes smclone \
        openmortal quake2 quake3 skoosh same-gnome enigma xbill \
        icebreaker scorched3d sol dosbox black-box freeciv \
        freeciv-server frozen-bubble liquidwar qt-nethack \
        nethack-gnome pathological scummvm xqf \
        wesnoth canfeild ace_canfeild golf merlin chickens \
        supertux tuxdash  neverball cube_client blackjack \
        doom doom3 quake4 blackshades gltron kpoker concentration \
        torrent scramble kiki xmoto warsow wormux zsnes
    cli_find gnugo xgame

    find_it et append "[exec] (Enemy Territory) {et}"
    find_it ut append "[exec] (Unreal Tournament) {ut}"
    find_it ut2003 append "[exec] (Unreal Tournament 2003) {ut2003}"
    find_it ut2004 append "[exec] (Unreal Tournament 2004) {ut2004}"
append_menu_end

append_submenu "${SYSTEMTOOLSMENU}"
  append_submenu "${BURNINGMENU}"
    normal_find k3b cdbakeoven graveman xcdroast arson eroaster gcombust \
                gtoaster kiso kover gtkcdlabel kcdlabel cdw cdlabelgen 
    cli_find     mp3burn cdrx burncenter
  append_menu_end

  normal_find firestarter gtk-lshw gproftd gpureftpd guitoo porthole gtk-iptables \
              gtk-cpuspeedy
  find_it    fireglcontrol   append "[exec] (ATI Config) {fireglcontrol}"
  cli_find    top htop iotop ntop powertop
append_menu_end




# We'll only use this once
ETCAPPLNK=/etc/X11/applnk
PARSING_DESKTOP="true"
# gnome menu
if [ "${GNOMEMENU}" ]; then
    append_submenu "${GNOMEMENUTEXT}"
    recurse_dir_menu "${GNOME_PREFIX}/share/gnome/apps" "$HOME/.gnome/apps" ${ETCAPPLNK}
    append_menu_end
    unset ETCAPPLNK
fi

# kde submenu
if [ -d "${KDE_PREFIX}/share/applnk/" -a "${KDEMENU}" ]; then
    append_submenu "${KDEMENUTEXT}"
    recurse_dir_menu "${KDE_PREFIX}/share/applnk" "$HOME/.kde/share/applnk" ${ETCAPPLNK}
    append_menu_end
    unset ETCAPPLNK
fi
unset PARSING_DESKTOP

#User menu
if [ -r "${USERMENU}" ]; then
    cat ${USERMENU} >> ${MENUFILENAME}
fi

append_submenu "${FBSETTINGSMENU}"
    append "[config] (${CONFIGUREMENU})"

    append_menu "[submenu] (${SYSTEMSTYLES}) {${STYLEMENUTITLE}}"
        append "[stylesdir] (${PREFIX}/share/fluxbox/styles)"
    append_menu_end

    append_menu "[submenu] (${USERSTYLES}) {${STYLEMENUTITLE}}"
        append "[stylesdir] (~/.@pkgprefix@fluxbox@pkgsuffix@/styles)"
    append_menu_end

    # Backgroundmenu
    addbackground() {
                picturename=`basename "$1"`
                append "[exec] (${picturename%.???}) {@pkgprefix@fbsetbg@pkgsuffix@ -a \"$1\" }"
    }

    if [ "$BACKGROUNDMENUITEM" = yes ]; then
        IFS=: # set delimetor for find
        NUMBER_OF_BACKGROUNDS=`find $BACKGROUND_DIRS -follow -type f 2> /dev/null|wc -l`
        if [ "$NUMBER_OF_BACKGROUNDS" -gt 0 ]; then
            append_menu "[submenu] (${BACKGROUNDMENU}) {${BACKGROUNDMENUTITLE}}"
            append "[exec] (${RANDOMBACKGROUND}) {@pkgprefix@fbsetbg@pkgsuffix@ -r ${USERFLUXDIR}/backgrounds}"
            if [ "$NUMBER_OF_BACKGROUNDS" -gt 30 ]; then
                menucounter=1 ; counter=1
                append_menu "[submenu] (${BACKGROUNDMENU} $menucounter) {${BACKGROUNDMENUTITLE}}"
                find $BACKGROUND_DIRS -follow -type f|sort|while read i; do
                    counter=`expr $counter + 1`
                    if [ $counter -eq 30 ]; then
                        counter=1
                        menucounter=`expr $menucounter + 1`
                        append_menu_end
                        append_menu "[submenu] (${BACKGROUNDMENU} $menucounter) {${BACKGROUNDMENUTITLE}}"
                    fi
                    addbackground "$i"
                done
                append_menu_end
            else
                find $BACKGROUND_DIRS -follow -type f|sort|while read i; do
                addbackground "$i"
                done
            fi
            append_menu_end
        else
            echo "Warning: You wanted a background-menu but I couldn't find any backgrounds in:
    $BACKGROUND_DIRS" >&2
        fi
    fi

    append "[workspaces] (${WORKSPACEMENU})"

    append_submenu "${TOOLS}"
        normal_find fluxconf fluxkeys fluxmenu
        find_it fbpanel append "[exec] (Fluxbox panel) {fbpanel}"
        find_it $XMESSAGE append \
            "[exec] (${WINDOWNAME}) {xprop WM_CLASS|cut -d \\\" -f 2|$XMESSAGE -file - -center}"
        find_it import append "[exec] (${SCREENSHOT} - JPG) {import screenshot.jpg && display -resize 50% screenshot.jpg}"
        find_it import append "[exec] (${SCREENSHOT} - PNG) {import screenshot.png && display -resize 50% screenshot.png}"
        find_it ${LAUNCHER} append "[exec] (${RUNCOMMAND}) {$LAUNCHER_CMD}"
        find_it switch append "[exec] (gtk-theme-switch) {switch}"
        find_it switch2 append "[exec] (gtk2-theme-switch) {switch2}"
        find_it @pkgprefix@fluxbox-generate_menu@pkgsuffix@ append "[exec] (${REGENERATEMENU}) {$FBGM_CMD}"
    append_menu_end

    append_submenu "${WINDOWMANAGERS}"
    #hard to properly maintain since there are so many exceptions to the rule.
    for wm in mwm twm wmii beryl compiz metacity icewm ion kde sawfish enlightenment fvwm openbox evilwm waimea xfce pekwm xfce4 fvwm2 blackbox ; do
        find_it start${wm} append "[restart] (${wm}) {start${wm}}" ||\
            find_it ${wm} append "[restart] (${wm}) {${wm}}"
    done
        find_it startgnome append "[restart] (gnome) {startgnome}" ||\
            find_it gnome-session append "[restart] (gnome) {gnome-session}"

        find_it startwindowmaker append "[restart] (windowmaker) {startwindowmaker}" ||\
            find_it wmaker append "[restart] (windowmaker) {wmaker}"
    append_menu_end
    find_it xlock append "[exec] (${LOCKSCREEN}) {xlock}" ||\
        find_it xscreensaver-command append "[exec] (${LOCKSCREEN}) {xscreensaver-command -lock}"
    append "[commanddialog] (${FLUXBOXCOMMAND})"
    append "[reconfig] (${RELOADITEM})"
    append "[restart] (${RESTARTITEM})"
    append "[exec] (${ABOUTITEM}) {(@pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -v; @pkgprefix@fluxbox@pkgsuffix@@EXEEXT@ -info | sed 1d) | $XMESSAGE -file - -center}"
    append "[separator]"
    append "[exit] (${EXITITEM})"

    append_menu_end

if [ -n "$MENU_ENCODING" ]; then
    append_menu "[endencoding]"
fi

append_menu_end

# this function removes empty menu items. It can not yet  remove  nested
# empty submenus :\

if [ ! "${REMOVE}" ]; then
    clean_up
fi

# escapes any parentheses in menu label
# e.g.,  "[exec] (konqueror (web))" becomes  "[exec] (konqueror (web\))"
sed 's/(\(.*\)(\(.*\)))/(\1 (\2\\))/' $MENUFILENAME > $MENUFILENAME.tmp
mv -f $MENUFILENAME.tmp $MENUFILENAME

if [ -z "$INSTALL" ]; then
    if [ -z "$CHECKINIT" ]; then
        INITMENUFILENAME=`awk '/menuFile/ {print $2}' $USERFLUXDIR/init`
        INITMENUFILENAME=`replaceWithinString "$INITMENUFILENAME" "~" "$HOME"`
        if [ ! "$INITMENUFILENAME" = "$MENUFILENAME" ]; then 
            echo "Note: In $USERFLUXDIR/init, your \"session.menuFile\" does not point to $MENUFILENAME but to $INITMENUFILENAME" >&2
        fi
    fi
    echo "Menu successfully generated: $MENUFILENAME"
    #echo "  Make sure \"session.menuFile: $MENUFILENAME\" is in $HOME/.@pkgprefix@fluxbox@pkgsuffix@/init."
    echo 'Use @pkgprefix@fluxbox-generate_menu@pkgsuffix@ -h to read about all the latest features.'
fi