This file is indexed.

/usr/bin/fvwm-crystal.generate-menu is in fvwm-crystal 3.4.1+dfsg-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

   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
#!/bin/bash
#
# Generate FVWM-Crystal menu from desktop and icons files provided by the applications.
#
# Author: Dominique Michel <dominique_libre@user.sourceforge.net>, 2007-2014
#
# Provided as it without any garanty of any kind. 
# Released under the GPL version 3+ license.
#
# Usage: 
# fvwm-crystal.generate-menu : will search for all the desktop files in the system and
# generate the corresponding entries and icons if they don't already exist. Make asumption
# based on the install Prefix to find the existing FVWM-Crystal files.
#
# fvwm-crystal.generate-menu <name> : will search only for <name>.desktop and 
# generate the corresponding entry and icons if they don't already exist.
#
# When running this script as user, the files will be generated in FVWM_USERDIR,
# as root, in FVWM_SYSTEMDIR
#
# Syntax from fvwm-crystal:
# fvwm-crystal.generate-menu $[FVWM_SYSTEMDIR] $[FVWM_USERDIR]
#
# For a detailled view of the algorhythm, open generate_menu.png in your favorite
# picture viewer.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # 

# Your real id
your_id="$(id -un)"

# If run from a shell
if [ $# -lt 2 ]; then
	echo "Running $0 from the shell"
	# Where are the Fvwm-Crystal menu files:
	FC_MENUBASEROOT="/usr/share/fvwm-crystal/fvwm/Applications"
	FC_MENUBASEUSER="/.fvwm-crystal/Applications"
	# Where are the Fvwm-Crystal icons files:
	FC_ICONBASEROOT="/usr/share/fvwm-crystal/fvwm/icons/Default"
	FC_ICONBASEUSER="/.fvwm-crystal/icons/Default"
	# Test which user run the script. Ir root, install in FVWM-SYSTEMDIR,
	# otherwise in FVWM_USERDIR. If ROOT, existing entry will be searched
	# only in FVWM_SYSTEMDIR, otherwise in both FVWM_DIR.
	if [[ "${your_id}" == root ]]; then
		FC_MENUBASE="${FC_MENUBASEROOT}"
		FC_ICONBASE="${FC_ICONBASEROOT}"
		FC_MENUEXIST="${FC_MENUBASEROOT}"
		FC_ICONEXIST="${FC_ICONBASEROOT}"
	else
		FC_MENUBASE="/home/${your_id}${FC_MENUBASEUSER}"
		FC_ICONBASE="/home/${your_id}${FC_ICONBASEUSER}"
		FC_MENUEXIST="${FC_MENUBASEROOT} /home/${your_id}${FC_MENUBASEUSER}"
		FC_ICONEXIST="${FC_ICONBASEROOT} /home/${your_id}${FC_ICONBASEUSER}"
	fi
else
	FC_MENUBASEROOT="$1/Applications"
	FC_ICONBASEROOT="$1/icons/Default"
	FC_MENUBASE="$2/Applications"
	FC_ICONBASE="$2/icons/Default"
	FC_MENUEXIST="${FC_MENUBASEROOT} ${FC_MENUBASE}"
	FC_ICONEXIST="${FC_ICONBASEROOT} ${FC_ICONBASE}"
fi
	SIZES="22x22 32x32 48x48"

#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# Don't change anything past this line
# # # # # # # # # # # # # # # # # # # # # # # # # # #

# The locale in use
LOC="$(echo $LANG|cut -d "_" -f 1)"
case "$LOC" in
	en)
	LOC=""
	echo "Using English"
	;;
	C)
	LOC=""
	echo "Using English"
	;;
	POSIX)
	LOC=""
	echo "Using English"
	;;
	*)
	echo "Using $LOC"
	;;
esac

# Type of .desktop files to search for
DESKTYPE="Type=Application"

# Where are the preferences:
if [ $# -lt 2 ]; then
	SYSPREFS="/usr/share/fvwm-crystal/fvwm/preferences"
	USERPREFS="/home/$your_id/.fvwm-crystal/preferences"
else
	SYSPREFS="$1/preferences"
	USERPREFS="$2/preferences"
fi

loadpref() {
# Copy default user prefs if they don't exist.
if [ ! -e $USERPREFS/$1 ]; then
	cp $SYSPREFS/$1 $USERPREFS
fi

eval "$2=\"$(cat $USERPREFS/$1|grep -Ev ^#)\""
}

# Load the icon files preference:
loadpref IconDirs SYSTEM_ICONDIRS
# Load the desktop files preference:
loadpref DesktopDirs DesktopDir

# Info screen
echo "You are running $0 as user ${your_id}."
echo " "
echo "FVWM-Crystal menu entries will be installed in"
echo "$FC_MENUBASE and the icons in $FC_ICONBASE."
echo " "
echo "The program will search for existing menu entries in $FC_MENUEXIST and for existing"
echo " icons in $FC_ICONEXIST."
echo "It will look for desktop file into $DesktopDir and for original icons into $SYSTEM_ICONDIRS"
echo " "
echo "Installing the menu entrie in $FC_MENUBASE and the icons in $FC_ICONBASE"

# Parameter test
if [ $# -lt 2 ]; then
	if [[ $1 == "" ]]; then
		echo "- Searching for all the desktop files in $DesktopDir"
		echo ""
		echo "This will go fast..."
		searchdesktop="searchallappdesktop"
		else
		echo "- Searching for $1.desktop in $DesktopDir"
		searchdesktop="searchoneappdesktop"
	fi
else
	searchdesktop="searchallappdesktop"
fi

# Remove the temp files if the user press Ctrl-C
USER_INTERRUPT=13
trap 'rm -f filelist filelist1; exit $USER_INTERRUPT' TERM INT

# # # # # # # # # # # # # # # # # # # # # # # # # # #
# Some functions

# Create icons
# createicon <commandname> <iconfile>
createicon() {
	RETVAL="no"; for j in ${FC_ICONEXIST}; do 
	if [[ ! -z "`find ${j}/22x22 -name "$1.png"`" ]] && [[ ! -z "`find ${j}/32x32 -name "$1.png"`" ]] && [[ ! -z "`find ${j}/48x48 -name "$1.png"`" ]] ; then
		# icons found
		RETVAL="yes"
	fi; done
	if [[ $RETVAL == "yes" ]]; then
		# fvwm-crystal icon exists, nothing to do (1)
		echo "Icon for $1 exist, skip"
	else
		if [[ "$2" != "$1" ]]; then
			# use file hint pointed to by menu entry
			# test if file don't exist
			if [ ! -e "$2" ]; then
				ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$2"`
			else
				ICONSRCFILE="$2"
			fi
			if [ -z "$ICONSRCFILE" ]; then
				ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$2.png" -or -iname "$2.xpm" -or -iname "$2.ico" -or -iname "svg" -or -iname "$2.bmp" -or -iname "$2.gif" -or -iname "$2.jpg" -or -iname "$2.pcx" -or -iname "$2.ppm" -or -iname "$2.tga"`
			fi
		else
			# try to find a suitable icon in the system directories
			ICONSRCFILE=`find $SYSTEM_ICONDIRS -type f -iname "$1.png" -or -iname "$1.xpm" -or -iname "$1.ico" -or -iname "$1.svg" -or -iname "$2.bmp" -or -iname "$2.gif" -or -iname "$2.jpg" -or -iname "$2.pcx" -or -iname "$2.ppm" -or -iname "$2.tga"`
		fi

		if [[ "$ICONSRCFILE" != "" ]]; then
			for i in $ICONSRCFILE; do
				# convert the first found file to png of required sizes
				for size in ${SIZES}; do
					mkdir -p "${FC_ICONBASE}/${size}/apps"
					convert -resize ${size} "$i" "${FC_ICONBASE}/${size}/apps/$1.png"
					# if an icon file contain several pictures, several files are generated. Use the first one.
					if [ -e "${FC_ICONBASE}/${size}/apps/$1-0.png" ]; then
						mv "${FC_ICONBASE}/${size}/apps/$1-0.png" "${FC_ICONBASE}/${size}/apps/$1.png"
					fi
					
					# fix the gAMA value; this remove warninngs and spped up fvwm
					# fix the sRGB profile; this remove warninngs and spped up fvwm
					convert "${FC_ICONBASE}/${size}/apps/$1.png" -strip -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
					convert "${FC_ICONBASE}/${size}/apps/$1.png" -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
					convert "${FC_ICONBASE}/${size}/apps/$1.png" -resize ${size} "${FC_ICONBASE}/${size}/apps/$1.png"
					echo "Icon for $1 created as  ${FC_ICONBASE}/${size}/apps/$1.png"
				done
				break
			done
		else
			echo "Original icon for $1 don't exist, skip."
		fi
	fi
}

# Search desktop files new format
echo -n "" > filelist
# Search for application type desktop file
searchallappdesktop() {
	echo -n "" > filelist1
	DesktopFile="$(find ${DesktopDir} -iname ?*.desktop -type f)"
	echo "$DesktopFile" >> filelist1
	echo "Sorting out non application type desktop files."
	echo "This will take a while..."
	while read myline ; do
		if [[ -n "${myline}" ]]; then
			TestDeskType="$(grep -h '\<Type\>' "${myline}")"
			OnlyShowIn="$(grep -h '\<OnlyShowIn\>' "${myline}")"
			NotShowIn="$(grep -h '\<NotShowIn\>' "${myline}")"
			NoDisplay="$(grep -h '\<NoDisplay\>' "${myline}")"
			Hidden="$(grep -h '\<Hidden\>' "${myline}")"
			if [[ "${TestDeskType}" == "${DESKTYPE}" ]] && [[ "${OnlyShowIn}" == "" ]] && [[ "${NotShowIn}" == "" ]] && [[ "${NoDisplay}" == "" ]] && [[ "${Hidden}" == "" ]]; then
				echo "${myline}" >> filelist
			fi
		fi
	done < filelist1
	rm filelist1
}

searchoneappdesktop() {
	echo -n "" > filelist1
	DesktopFile="$(find ${DesktopDir} -iname $1.desktop -type f)"
	echo "$DesktopFile" >> filelist1

	while read myline ; do
		if [[ -n "${myline}" ]]; then
			TestDeskType="$(grep -h '\<Type\>' "${myline}")"
			OnlyShowIn="$(grep -h '\<OnlyShowIn\>' "${myline}")"
			NotShowIn="$(grep -h '\<NotShowIn\>' "${myline}")"
			NoDisplay="$(grep -h '\<NoDisplay\>' "${myline}")"
			Hidden="$(grep -h '\<Hidden\>' "${myline}")"
			if [[ "${TestDeskType}" == "${DESKTYPE}" ]] && [[ "${OnlyShowIn}" == "" ]] && [[ "${NotShowIn}" == "" ]] && [[ "${NoDisplay}" == "" ]] && [[ "${Hidden}" == "" ]]; then
				echo "${myline}" >> filelist
			fi
		fi
		break
	done < filelist1
	rm filelist1
}

# Search TryExec in desktop file, Exec if not found
searchexecname() {
	EXEC="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Exec=/!d' -e 's:^.\{0,3\}Exec=\([^ ]*\).*:\1:' -e 's:.*/::')"
	export EXEC
}

# Search for icon name in desktop file
searchiconname() {
	ICONNAME="$(cat ${1} | sed -e '/Icon=/!d' -e 's/Icon=//')"
	export ICONNAME
}

# Search for key strings in desktop file
searchkeystrings() {
	CATNAME="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/Categories=/!d' -e 's/Categories=//' -e 's/;/ /g')"
	export CATNAME
#	echo "CATNAME = $CATNAME"
	SOFTNAME=""
	if [[ "$LOC" != "" ]]; then
		SOFTNAME="$(cat ${1} | grep -m 1 ^Name.${LOC}. | sed -e '/^\Name....=/!d' -e 's/Name....=//' -e 's/ /_/g' -e 's:/:-:')"
		export SOFTNAME
#	else
	fi
	if [[ "$SOFTNAME" == "" ]]; then
		SOFTNAME="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Name=/!d' -e 's/Name=//' -e 's/ /_/g' -e 's:/:-:')"
		export SOFTNAME
	fi

	COMMANDF="$(cat ${1} | sed -e '/Desktop Entry/,/Desktop Action/ !d' -e '/^\Exec=/!d' -e 's/Exec=//' -e 's:.%.*::' -e 's/ -caption//')"
	export COMMANDF

	TERMINAL="$(cat ${1} | sed -e '/Terminal=true/!d' -e 's/Terminal=//')"
	export TERMINAL
}

# Search for existing menu entry
searchexist() {
	EntryExist="$(find ${FC_MENUEXIST} -iname *${2}~?* -type f)"
	if [[ "${EntryExist}" != "" ]]; then
		echo "${EntryExist} exist, skip"
		EXIST="true"
		export EXIST
		createicon $EXEC $ICONNAME
	else
		echo "${EntryExist} dont exist"
		EXIST="false"
		export EXIST
		createicon $EXEC $ICONNAME
	fi
}

# Generate the category path for the menu
# 1) search for main category
# 2) search for sub-category
# special cases: if both audio and audiovideo are in the desktop file,
# audio will be preferred; if both audiovideo are in the desktop file,
# video will be preferred.
#
# main categories
maincategory() {
MAINCAT=""
export MAINCAT
case "$1" in
        Audio)
                MAINCAT="/Multimedia/Audio"
		export MAINCAT
                ;;
	AudioVideo | Multimedia)
		MAINCAT="/Multimedia/Audio-Video"
		export MAINCAT
		;;
	Development)
		MAINCAT="/Development"
		export MAINCAT
		;;
	Education)
		MAINCAT="/Knowledge"
		export MAINCAT
		;;
	Games | Game)
		MAINCAT="/20~Games"
		export MAINCAT
		;;
	Graphics)
		MAINCAT="/Graphics"
		export MAINCAT
		;;
	Internet | Network)
		MAINCAT="/Network"
		export MAINCAT
		;;
	Office)
		MAINCAT="/Office"
		export MAINCAT
		;;
	Settings)
		MAINCAT="/Settings"
		export MAINCAT
		;;
	System)
		MAINCAT="/System"
		export MAINCAT
		;;
	Utilities | Utility)
		MAINCAT="/Utilities"
		export MAINCAT
		;;
	Video)
		MAINCAT="/Multimedia/Video"
		export MAINCAT
		;;
#	*)
#		MAINCAT="/Utilities"
#		export MAINCAT
#		;;
esac
}
# sub categories
category() {
SUBCAT=""
export SUBCAT
case "$1" in
	2DGraphics)
		SUBCAT="/2D_Graphics"
		export SUBCAT
		;;
	3DGraphics)
		SUBCAT="/3D_Graphics"
		export SUBCAT
		;;
	Accessibility)
		SUBCAT="/Accessibility"
		export SUBCAT
		;;
	ActionGame)
		SUBCAT="/20~Action_Games"
		export SUBCAT
		;;
	AdventureGame)
		SUBCAT="/Adventure_Games"
		export SUBCAT
		;;
	Adult)
		SUBCAT="/Adult"
		export SUBCAT
		;;
	ArcadeGame)
		SUBCAT="/Arcade_Games"
		export SUBCAT
		;;
	Amusement)
		SUBCAT="/Amusement"
		export SUBCAT
		;;
	Archiving)
		SUBCAT="/Archiving"
		export SUBCAT
		;;
	Art)
		SUBCAT="/Art"
		export SUBCAT
		;;
	ArtificialIntelligence)
		SUBCAT="/Artificial_Intelligence"
		export SUBCAT
		;;
	Astronomy)
		SUBCAT="/Astronomy"
		export SUBCAT
		;;
	AudioVideoEditing)
		SUBCAT="/Audio-Video_Editing"
		export SUBCAT
		;;
	Biology)
		SUBCAT="/Biology"
		export SUBCAT
		;;
	BlocksGame)
		SUBCAT="/20~Blocks_Games"
		export SUBCAT
		;;
	BoardGame)
		SUBCAT="/Board_Games"
		export SUBCAT
		;;
	Building)
		SUBCAT="/Building"
		export SUBCAT
		;;
	Calculator)
		SUBCAT="/Calculators"
		export SUBCAT
		;;
	Calendar)
		SUBCAT="/Calendars"
		export SUBCAT
		;;
	CardGame)
		SUBCAT="/Card_Games"
		export SUBCAT
		;;
	Chart)
		SUBCAT="/Charts"
		export SUBCAT
		;;
	Chat)
		SUBCAT="/Chat"
		export SUBCAT
		;;
	Chemistry)
		SUBCAT="/Chemistry"
		export SUBCAT
		;;
	Clock)
		SUBCAT="/Clocks"
		export SUBCAT
		;;
	Compression)
		SUBCAT="/Compression"
		export SUBCAT
		;;
	ComputerScience)
		SUBCAT="/Computer_Science"
		export SUBCAT
		;;
	ConsoleOnly)
		SUBCAT="/Console_Only"
		export SUBCAT
		;;
	Construction)
		SUBCAT="/Construction"
		export SUBCAT
		;;
	ContactManagement)
		SUBCAT="/Contact_Management"
		export SUBCAT
		;;
	Core)
		SUBCAT="/Core"
		export SUBCAT
		;;
	DataVisualization)
		SUBCAT="/Data_Visualization"
		export SUBCAT
		;;
	Database)
		SUBCAT="/Databases"
		export SUBCAT
		;;
	Dialup)
		SUBCAT="/Dial-up"
		export SUBCAT
		;;
	Debugger)
		SUBCAT="/Debuggers"
		export SUBCAT
		;;
	DesktopSettings)
		SUBCAT="/Desktop_Settings"
		export SUBCAT
		;;
	Dialup)
		SUBCAT="/Dialup"
		export SUBCAT
		;;
	Dictionary)
		SUBCAT="/Dictionaries"
		export SUBCAT
		;;
	DiscBurning)
		SUBCAT="/Disc_Burning"
		export SUBCAT
		;;
	Documentation)
		SUBCAT="/Documentation"
		export SUBCAT
		;;
	Economy)
		SUBCAT="/Economy"
		export SUBCAT
		;;
	Electricity)
		SUBCAT="/Electricity"
		export SUBCAT
		;;
	Electronics)
		SUBCAT="/Electronics"
		export SUBCAT
		;;
	Email)
		SUBCAT="/13~Email"
		export SUBCAT
		;;
	Emulator)
		SUBCAT="/Emulators"
		export SUBCAT
		;;
	Engineering)
		SUBCAT="/Engineering"
		export SUBCAT
		;;
	Feed)
		SUBCAT="/Feed"
		export SUBCAT
		;;
	FileManager)
		SUBCAT="/File_Managers"
		export SUBCAT
		;;
	FileSystem)
		SUBCAT="/File_Systems"
		export SUBCAT
		;;
	FileTools)
		SUBCAT="/File_Tools"
		export SUBCAT
		;;
	FileTransfer)
		SUBCAT="/File_Transfer"
		export SUBCAT
		;;
	Finance)
		SUBCAT="/Finance"
		export SUBCAT
		;;
	FlowChart)
		SUBCAT="/Flow_Charts"
		export SUBCAT
		;;
	Geography)
		SUBCAT="/Geography"
		export SUBCAT
		;;
	Geology)
		SUBCAT="/Geology"
		export SUBCAT
		;;
	Geoscience)
		SUBCAT="/Geoscience"
		export SUBCAT
		;;
	GNOME)
		SUBCAT=""
		export SUBCAT
		;;
	GTK)
		SUBCAT=""
		export SUBCAT
		;;
	GUIDesigner)
		SUBCAT="/GUI_Designers"
		export SUBCAT
		;;
	HamRadio)
		SUBCAT="/Ham_Radio"
		export SUBCAT
		;;
	HardwareSettings)
		SUBCAT="/Hardware_Settings"
		export SUBCAT
		;;
	History)
		SUBCAT="/History"
		export SUBCAT
		;;
	Humanities)
		SUBCAT="/Humanities"
		export SUBCAT
		;;
	IDE)
		SUBCAT="/IDE"
		export SUBCAT
		;;
	ImageProcessing)
		SUBCAT="/Image_Processing"
		export SUBCAT
		;;
	IRCClient)
		SUBCAT="/IRC_Clients"
		export SUBCAT
		;;
	InstantMessaging)
		SUBCAT="/Instant_Messaging"
		export SUBCAT
		;;
	Java)
		SUBCAT="/Java"
		export SUBCAT
		;;
	KDE)
		SUBCAT=""
		export SUBCAT
		;;
	KDE-settins-hardware)
		SUBCAT=""
		export SUBCAT
		;;
	KidsGame)
		SUBCAT="/Kids_Games"
		export SUBCAT
		;;
	Languages)
		SUBCAT="/Languages"
		export SUBCAT
		;;
	Literature)
		SUBCAT="/Literature"
		export SUBCAT
		;;
	LogicGame)
		SUBCAT="/Logic_Games"
		export SUBCAT
		;;
	Maps)
		SUBCAT="/Maps"
		export SUBCAT
		;;
	Math)
		SUBCAT="/Math"
		export SUBCAT
		;;
	MedicalSoftware)
		SUBCAT="/Medical_Softwares"
		export SUBCAT
		;;
	Midi)
		SUBCAT="/MIDI"
		export SUBCAT
		;;
	Mixer)
		SUBCAT="/10~Mixers"
		export SUBCAT
		;;
	Monitor)
		SUBCAT="/Monitors"
		export SUBCAT
		;;
	Motif)
		SUBCAT="/Motif"
		export SUBCAT
		;;
	Music)
		SUBCAT="/Music"
		export SUBCAT
		;;
	News)
		SUBCAT="/7~News"
		export SUBCAT
		;;
	NumericalAnalysis)
		SUBCAT="/Numerical_Analysis"
		export SUBCAT
		;;
	OCR)
		SUBCAT="/OCR"
		export SUBCAT
		;;
	P2P)
		SUBCAT="/P2P"
		export SUBCAT
		;;
	PackageManager)
		SUBCAT="/Package_Managers"
		export SUBCAT
		;;
	ParallelComputing)
		SUBCAT="/Parallel_Computing"
		export SUBCAT
		;;
	PDA)
		SUBCAT="/PDA"
		export SUBCAT
		;;
	Photography)
		SUBCAT="/Photography"
		export SUBCAT
		;;
	Physics)
		SUBCAT="/Physics"
		export SUBCAT
		;;
	Player)
		SUBCAT="/Players"
		export SUBCAT
		;;
	Presentation)
		SUBCAT="/Presentations"
		export SUBCAT
		;;
	Printing)
		SUBCAT="/Printing"
		export SUBCAT
		;;
	Profiling)
		SUBCAT="/Profiling"
		export SUBCAT
		;;
	ProjectManagement)
		SUBCAT="/Project_Management"
		export SUBCAT
		;;
	Publishing)
		SUBCAT="/Publishing"
		export SUBCAT
		;;
	QT)
		SUBCAT=""
		export SUBCAT
		;;
	RasterGraphics)
		SUBCAT="/Raster_Graphics"
		export SUBCAT
		;;
	Recorder)
		SUBCAT="/Recorders"
		export SUBCAT
		;;
	RemoteAccess)
		SUBCAT="/Remote_Access"
		export SUBCAT
		;;
	RevisionControl)
		SUBCAT="/Revision_Control"
		export SUBCAT
		;;
	Robotics)
		SUBCAT="/Robotics"
		export SUBCAT
		;;
	RolePlaying)
		SUBCAT="/Role_Playing"
		export SUBCAT
		;;
	Scanning)
		SUBCAT="/Scanning"
		export SUBCAT
		;;
	Science)
		SUBCAT="/Science"
		export SUBCAT
		;;
	Security)
		SUBCAT="/Security"
		export SUBCAT
		;;
	Sequencer)
		SUBCAT="/Sequencers"
		export SUBCAT
		;;
	Shooter)
		SUBCAT="/Shooter"
		export SUBCAT
		;;
	Simulation)
		SUBCAT="/Simulation"
		export SUBCAT
		;;
	Spirituality)
		SUBCAT="/Spirituality"
		export SUBCAT
		;;
	Sports)
		SUBCAT="/Sports"
		export SUBCAT
		;;
	SportsGame)
		SUBCAT="/Sports_Games"
		export SUBCAT
		;;
	Spreadsheet)
		SUBCAT="/Spreadsheets"
		export SUBCAT
		;;
	StrategyGame)
		SUBCAT="/Strategy_Games"
		export SUBCAT
		;;
	Sun-Supported)
		SUBCAT=""
		export SUBCAT
		;;
	Telephony)
		SUBCAT="/5~Telephony"
		export SUBCAT
		;;
	TelephonyTools)
		SUBCAT="/Telephony_Tools"
		export SUBCAT
		;;
	TerminalEmulator)
		SUBCAT="/Terminals"
		export SUBCAT
		;;
	TextEditor)
		SUBCAT="/Text_Editors"
		export SUBCAT
		;;
	TextTools)
		SUBCAT="/Text_Tools"
		export SUBCAT
		;;
	Translation)
		SUBCAT="/Translation"
		export SUBCAT
		;;
	Tuner)
		SUBCAT="/Tuners"
		export SUBCAT
		;;
	TV)
		SUBCAT="/TV"
		export SUBCAT
		;;
	VectorGraphics)
		SUBCAT="/Vector_Graphics"
		export SUBCAT
		;;
	VideoConference)
		SUBCAT="/Webcam"
		export SUBCAT
		;;
	Viewer)
		SUBCAT="/Viewers"
		export SUBCAT
		;;
	WebBrowser)
		SUBCAT="/10~Web_Browsers"
		export SUBCAT
		;;
	WebDevelopment)
		SUBCAT="/Web_Development"
		export SUBCAT
		;;
	WordProcessor)
		SUBCAT="/Word_Processors"
		export SUBCAT
		;;
	XFCE)
		SUBCAT=""
		export SUBCAT
		;;
	X-KDE*)
		SUBCAT=""
		export SUBCAT
		;;
	X-Red-Hat*)
		SUBCAT=""
		export SUBCAT
		;;
	X-"$2")
		SUBCAT="/$2"
		export SUBCAT
		;;
	*)
		SUBCAT=""
		export SUBCAT
		;;
esac
}

gen_category() {
# Test for X-Category
	MAIN_CAT=""
	SUB_CAT=""
	if [[ "$1" != "" ]]; then	
		for i in $1; do
			XEXIST="$(echo "$i" | sed -e 's/.*X-.*/X-/')"
			if [[ "$XEXIST" == "X-" ]]
				then XCAT="$(echo "$i" | sed -e 's/X-//')"
				category "$i" "$XCAT"
				SUB_CAT="${SUB_CAT} ${SUBCAT}"
				export SUB_CAT
			else
				maincategory "$i"
				MAIN_CAT="${MAIN_CAT} ${MAINCAT}"
				export MAIN_CAT
				category "$i"
				SUB_CAT="${SUB_CAT} ${SUBCAT}"
				export SUB_CAT
			fi
		done
	else
		case "$2" in
			/usr/share/applnk*)
				CATNAME="$(echo ${2} | sed -e 's:/usr/share/applnk::' -e 's:/: :g')"
				;;
			/usr/share/gnome/apps*)
				CATNAME="$(echo ${2} | sed -e 's:/usr/share/gnome/apps::' -e 's:/: :g')"
				;;
			/usr/kde/3.5/share/applnk*)
				CATNAME="$(echo ${2} | sed -e 's:/usr/kde/3.5/share/applnk::' -e 's:/: :g')"
				;;
			/usr/kde/3.5/share/apps/kappfinder/apps*)
				CATNAME="$(echo ${2} | sed -e 's:/usr/kde/3.5/share/apps/kappfinder/apps::' -e 's:/: :g')"
				;;
			*)
				CATNAME=""
				;;
		esac
		for i in $CATNAME; do
			XEXIST="$(echo "$i" | sed -e 's/.*X-.*/X-/')"
			if [[ "$XEXIST" == "X-" ]]
				then XCAT="$(echo "$i" | sed -e 's/X-//')"
				category "$i" "$XCAT"
				SUB_CAT="${SUB_CAT} ${SUBCAT}"
				export SUB_CAT
			else
				maincategory "$i"
				MAIN_CAT="${MAIN_CAT} ${MAINCAT}"
				export MAIN_CAT
				category "$i"
				SUB_CAT="${SUB_CAT} ${SUBCAT}"
				export SUB_CAT
			fi
		done
	fi
}

echo -n "" > non_valid_cat.log
check_category() {
# Check at it is only one main cat in the menu
	TMP_CAT="$(echo $1 | sed -e 's/ //g')"
	MAIN__CAT="${MAIN_CAT}"
	if [[ "$TMP_CAT" != "" ]]; then
		AV=""
		A=""
		V=""
		for i in $1; do
			if [[ "$i" == "/Multimedia/Audio-Video" ]]; then
				AV="AV"
			fi
			if [[ "$i" == "/Multimedia/Audio" ]]; then
				A="A"
			fi
			if [[ "$i" == "/Multimedia/Video" ]]; then
				V="V"
			fi
		done
		
		if [[ "${AV}" == "AV" ]] && [[ "${A}" == "A" ]] && [[ "${V}" == "V" ]]; then
			MAIN__CAT=""
			echo "$2" >> non_valid_cat.log
		else
			if [[ "${AV}" == "AV" ]] && [[ "${A}" == "A" ]]; then
				MAIN__CAT="/Multimedia/Audio"
			fi
			if [[ "${AV}" == "AV" ]] && [[ "${V}" == "V" ]]; then
				MAIN__CAT="/Multimedia/Video"
			fi
		fi
		
	else
		MAIN__CAT=""
		echo "$2" >> non_valid_cat.log
	fi
	CATEGORY=""
	for i in $MAIN__CAT; do
		if [[ "$MAIN__CAT" != "" ]]; then
			SUB_CAT2="$(echo $3 | sed -e 's/ //g')"
			CATEGORY="$i$SUB_CAT2"
		fi
	break
	done
	
	export CATEGORY
}

# Write a FVWM-Crystal menu entry
# Usage: gen_entry <exec_name> <entry_name> <category> <command>
# Usage: gen_consoleentry <exec_name> <entry_name> <category> <command>
gen_entry() {
	mkdir -p "${FC_MENUBASE}${3}"
	FNAME="${FC_MENUBASE}$3/~$1~$2"
	(
	echo "#!/bin/sh"
	echo
	echo "exec $4 \$@"
	) > "${FNAME}"
	chmod +x "${FNAME}"
}
gen_consoleentry() {
	mkdir -p "${FC_MENUBASE}${3}"
	FNAME="${FC_MENUBASE}$3/~$1~$2"
	(
	echo "#!/bin/sh"
	echo
	echo "exec FvwmCommand 'A $4 \$@'"
	) > "${FNAME}"
	chmod +x "${FNAME}"
}

# # # # # # # # # # # # # # # # # # # # # # # # # # #
# Do something now

$searchdesktop $1

# Main loop
while read myline ; do
	searchexecname "${myline}"
	searchiconname "${myline}"
	searchexist "${myline}" $EXEC
	if [[ "$EXIST" == "false" ]]; then
		searchkeystrings "${myline}" $USERLOC
		gen_category "$CATNAME" "${myline}"
		check_category "$MAIN_CAT" "${myline}" "$SUB_CAT"
		if [[ "$MAIN__CAT" != "" ]]; then
			echo "Generation of menu entry for ${EXEC}"
			if [[ "$TERMINAL" == "true" ]]; then
				gen_consoleentry "$EXEC" "$SOFTNAME" "$CATEGORY" "$COMMANDF"
			else
				gen_entry "$EXEC" "$SOFTNAME" "$CATEGORY" "$COMMANDF"
			fi
		fi
	fi
done < filelist
rm filelist

echo ""
echo "All is done"
echo ""

if [ $# -ge 2 ]; then
	rm non_valid_cat.log
	DesktopDir=`awk -v ORS="" '!/(#|^$)/{print $0"/* "}' $USERPREFS/DesktopDirs`
	echo "Saving the date of the last installed desktop file in ${FVWM_USERDIR}/preferences/DateLastApp"
	echo "Reloading the menu..."
	echo "SetEnv DateLastApp \"`stat --printf="%y\n" ${DesktopDir} | sort -n -r | head -1`\"" > ${FVWM_USERDIR}/preferences/DateLastApp
	FvwmCommand 'ReloadRecipe'
else
	echo "You will find the list of the desktop files with non valid Main Category in non_valid_cat.log"
fi