<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># This script must be run by FvwmScript-Setup95 only!

use Getopt::Long;

my $uncomment=0;
my $comment=0;
my $prefapps=0;
my $gnomepath=0;
my $mainOut="";
my $currentOut="";
my @PATH_DIRS = split(':',$ENV{PATH});
my $date=`date +%Y%m%d-%H%M%S`;
$date=~ s/\s//g;
my $backupDir="";

GetOptions(
	"help"         =&gt; \&amp;wrongUsage,
   "configin=s"	=&gt; \$ConfigIn,
   "dirout=s"		=&gt; \$DirOut,
	"fvwm=i"       =&gt; \$Fvwm,
	"sxs=i"			=&gt; \$Slow,
	"km=i"			=&gt; \$KdeMenu,
	"ksm=i"       	=&gt; \$KdeSysMenu,
	"kum=i"			=&gt; \$KdeUserMenu,
	"kfm=i"   		=&gt; \$KfmIcons,
	"gmg=i"  		=&gt; \$GnomeMenuGtk,
	"gsmg=i"   		=&gt; \$GnomeSysMenuGtk,
	"gumg=i"       =&gt; \$GnomeUserMenuGtk,
	"grmg=i"      	=&gt; \$GnomeRHMenuGtk,
	"gsmf=i"   		=&gt; \$GnomeSysMenuFvwm,
	"gumf=i"       =&gt; \$GnomeUserMenuFvwm,
	"grmf=i"      	=&gt; \$GnomeRHMenuFvwm,
	"gs=i"      	=&gt; \$GnomeSession,
	"gy=i"       	=&gt; \$GnomeY,
	"gpath=s"      =&gt; \$GnomePath,
	"cde=i"			=&gt; \$Cde,
	"stroke=i"     =&gt; \$Stroke,
	"lap=i"      	=&gt; \$Laptop,
	"pp=i"  			=&gt; \$PanelStaysPut,
	"editor=s" 		=&gt; \$Editor,
	"reditor=s" 	=&gt; \$Reditor,
	"file=s" 		=&gt; \$FileMgr,
	"term=s" 		=&gt; \$Term,
	"spl=s"			=&gt; \$SoundPlayer,
	"spa=s"			=&gt; \$SoundPath,
	"i=i"				=&gt; \$IP,
	"ip=s"			=&gt; \$ImagePath,
	"dip=s"			=&gt; \$DefImagePath
) || wrongUsage();

if ($ConfigIn eq "" || $DirOut eq "" || $Fvwm eq "" || $Slow eq "" ||
		$KdeMenu eq "" || $KdeSysMenu eq "" || $KdeUserMenu eq "" ||  
		$KfmIcons eq "" ||  $GnomeMenuGtk eq "" || 
		$GnomeSysMenuGtk eq "" || $GnomeUserMenuGtk eq "" ||
		$GnomeRHMenuGtk eq "" || $GnomeSysMenuFvwm eq "" || 
		$GnomeUserMenuFvwm eq "" || $GnomeRHMenuFvwm eq "" ||
		$GnomeSession eq "" || $GnomeY eq "" || $GnomePath eq "" ||
		$Stroke eq "" || $Laptop eq "" || $PanelStaysPut eq "" || 
		$Editor eq "" || $Reditor eq "" || $FileMgr eq "" || 
		$Term eq "" || $SoundPlayer eq "" || $SoundPath eq "" ||
		$IP eq "" || $ImagePath	eq "" || $DefImagePath	eq "" ||
		$Cde eq "") {
	wrongUsage();
}

if (! $SoundPath =~ /\/$/) { $SoundPath = "$SoundPath/"; }
$fileOut=".fvwm2rc";
$mainOut="$DirOut/$fileOut";
$currentOut=$mainOut;
$backupDir="$DirOut/backup";

open(IN,"$ConfigIn") || die "cannot read $ConfigIn";

if (-f "$mainOut") {
	system("/bin/mkdir -p '$backupDir'");
	$backup="$backupDir/$fileOut-$date";
	system("/bin/mv '$mainOut' '$backup'");
   print "Echo backup $mainOut in $backup\n"
}
open(MAINOUT,"&gt;$mainOut") || die "cannot write on $mainOut";

while(&lt;IN&gt;) {
	$line=$_;
	chomp($line);

	next if ($line =~ /^\#\!D/);

	$line =~ s/^\#// if $uncomment;
   $line = "\#$line" if $comment;
   $uncomment-- if ($uncomment &gt; 0);
   $comment-- if ($comment &gt; 0);

   if ((/^\#WIN/ &amp;&amp; $Fvwm)||(/^\#FAST/ &amp;&amp; $Slow)) {
		@l=split(' ',$line);
		$comment=$l[1];
	}
	

	if(($line =~ /^\#FVWM/ &amp;&amp; $Fvwm) ||
			($line =~ /^\#SLOW/ &amp;&amp; $Slow) ||
			($line =~ /^\#K_M/ &amp;&amp; $KdeMenu) || 
			($line =~ /^\#K_SM/&amp;&amp; $KdeSysMenu) || 
			($line =~ /^\#K_UM/ &amp;&amp; $KdeUserMenu) ||
			($line =~ /^\#KFM_ICONS/ &amp;&amp; $KfmIcons) || 
			($line =~ /^\#G_M_G/ &amp;&amp; $GnomeMenuGtk) ||
			($line =~ /^\#G_SM_G/ &amp;&amp; $GnomeSysMenuGtk) || 
			($line =~ /^\#G_UM_G/ &amp;&amp; $GnomeUserMenuGtk) || 
			($line =~ /^\#G_RHM_G/ &amp;&amp; $GnomeRHMenuGtk) || 
			($line =~ /^\#G_SM_F/ &amp;&amp; $GnomeSysMenuFvwm) || 
			($line =~ /^\#G_UM_F/ &amp;&amp; $GnomeUserMenuFvwm) || 
			($line =~ /^\#G_RHM_F/ &amp;&amp; $GnomeRHMenuFvwm) || 
			($line =~ /^\#G_SESSION/ &amp;&amp; $GnomeSession) || 
			($line =~ /^\#G_ST/ &amp;&amp; $GnomeY) || 
			($line =~ /^\#STROKE/ &amp;&amp; $Stroke) ||
			($line =~ /^\#LAPTOP/ &amp;&amp; $Laptop) || 
			($line =~ /^\#PANEL_PUT/ &amp;&amp; $PanelStaysPut) ||
			($line =~ /^\#CDE/ &amp;&amp; $Cde)) {
		@l=split(' ',$line);
		$uncomment=$l[1];
	}

	if ($prefapps) {
		$line =~ s# emacs# $Editor#;
		$line =~ s#\^"emacs"#\^"$Editor"#;
		$line =~ s#\*macs#$Reditor#;
		$line =~ s# xfm# $FileMgr#;
		$line =~ s# xterm# $Term#;
	}
	$prefapps-- if $prefapps;
	if ($line =~ /^\#PREF/) {
		@l=split(' ',$line);
		$prefapps=$l[1];
	}

	if ($currentOut =~ /menus/ &amp;&amp; $line =~ /^\+/) {
		$line = menuCheck($line);
	}

	$line =~ s#rplay#$SoundPlayer# if ($line =~ /Event/);
	$line =~ s#/usr/share/sounds/#$SoundPath# if ($line =~ /Event/);

	$line =~ s#/usr#$GnomePath# if($gnomepath);
	$gnomepath-- if $gnomepath;
	$gnomepath=1 if ($line =~ /^\#G/);

	if ($line =~ /add_dir_to_fvwm_image_path/ &amp;&amp; $IP) {
		$line =~ s/^\#//;
		$line =~ s#add_dir_to_fvwm_image_path#$ImagePath#;
	}
	$line =~ s#/usr/include/X11/bitmap:/usr/include/X11/pixmaps#$DefImagePath# 
		if ($line =~ /\/usr\/include\/X11\/bitmap:\/usr\/include\/X11\/pixmaps/);
	
	if ($line =~ /\#\!E/) {
		$tmp = substr($line,index($line,'#!E')+3);
		$tmp =~ s/\s//g;
		@l = split(':',$tmp);
		$t=0;
		foreach $a (@l) { $t=1 if (checkApp($a)); }
		$line = "#".$line unless $t;
		$line =~ s/\s+\#\!E\s*.*\s*//;
	}

	if ($line =~ /^\#SEG/) {
		$line =~ s/^\#SEG//;
		$line =~ s/\s//g;
		$currentOut=$line;
		if ($line eq "END") {
			$currentOut=$mainOut;
			close(OUT);
		} else {
			print MAINOUT "Read $line\n\n";
			close(OUT) if ($currentOut ne $mainOut);
			$currentOut="$DirOut/$line";
			$fileOut=$line;
			if (-f "$currentOut") {
				system("/bin/mkdir -p '$backupDir'");
				$backup="$backupDir/$fileOut-$date";
				system("/bin/mv '$currentOut' '$backup'");
				print "Echo backup $currentOut in $backup\n";
			}
			open(OUT,"&gt;$currentOut") || die "cannot write on $currentOut";
		}
	} else {
		if ($currentOut ne $mainOut) {
			print OUT "$line\n";
		} else {
			print MAINOUT "$line\n";
		}
	}
}

close(IN);
close(MAINOUT);

print "Echo END\n";

#--------------------------------------------------------------------------
# menu check

sub menuCheck {
	my ($menuline) =  @_;
	my $path = "";

	return $menuline unless $menuline =~ /([Ee]xec|"\s+Restart)\s+(.+)$/;
	my $action = $2;
	
	if ($menuline =~ /Exec\s+cd/) {
		$path = substr($menuline,rindex($menuline,'Exec cd'));
		$path =~  s/^\s*Exec\s+cd\s*//;
		$path = substr($action,0,index($path,';'));
		$path =~ s/\s//g;
		$path =~ s/\/$//;
	}
	$action =~ s/^exec\s+//;
	$action =~ s/^killall\s+//;
	my $tact = $action;
	$tact = substr($tact,0,index($tact,' ')) if ($tact =~ /\s/);
	if ($tact eq "xterm" &amp;&amp; $menuline =~ /\-e/) {
		$action = substr($action,index($action,'-e'));
		$action =~ s/^\-e\s+//;
		$action = substr($action,0,index($action,' ')) if ($action =~ /\s/);
	} else {
		$action = $tact;
	}
	$action =~ s/^\s*\.\///;
	$action = "$path/$action" if ($path ne "");
	$menuline = "#".$menuline if (!checkApp($action));
	return $menuline;
}

sub checkApp {
	my($app) = @_;
	my $dir ="";
	if ($app =~ /^\//) {
		if (-x $app ) { return 1 }
	} else {
		foreach $dir (@PATH_DIRS) {
			if ( -x "$dir/$app" ) { return 1 }
		}
	}
	return 0;
}

sub wrongUsage {
	print STDERR "This script must be run by FvwmScript-Setup95 only!\n";
	exit -1;
}
</pre></body></html>