#!/usr/bin/perl # roqetmenu; # Last updated: 2006-09-27 $version = '1.3'; $copyyear = '2006'; =head1 RoqetMenu v1.3 RoqetMenu is a utility that creates a menu and launches commands based in the input from a specially formatted XML file. =head1 The XML file layout Here is an example of the XML file layout, also see examples provided along with this script. Note there must always be at least one entry with the command of "exit". Test - Main Menu perl perl browse "C:\Program Files\Mozilla Firefox\firefox.exe" C:\roqetman\lang\sql\budget\ exit exit reconcile qif (*perl*)qif_reconcile.pl budget help (*browse*)budget_help.html =head1 ChangeLog 2005-12-06 :: 1.2 :: Made the menu fit into an ascii block 2006-09-27 :: 1.3 :: Fixed missing last menu item issue. =head1 Author roqet =head1 Copyright RoqetMenu Perl script copyright 2006 roqet . RoqetMenu can be distributed and modified under the terms of the GNU General Public License: http://www.gnu.org/copyleft/gpl.html This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details. Updates and other scripts and software available at: http://www.roqet.org/software.html ~~~ 'l' - =cut use XML::Simple; $xmlfile = $ARGV[0]; if ($xmlfile eq '') { die "error: no xml file specified: $!\n"; } $keys = XMLin($xmlfile); $title = $keys->{information}->{title}; # calculate how many items per column $inpdiv = $keys->{menu}->{item_count} / 2; $divresult = sprintf("%.1f", $inpdiv); $colconv = "$divresult"; ($colcount,$remainder) = split(/\./,$colconv,2); if ($remainder ne '') { $colcount++; } #print $colconv; #print "\n$first $second\n"; # build column text @col1 = undef; @col2 = undef; $menulines = ''; $num = 0; while ($i < $keys->{menu}->{item_count}) { $menuitem = $keys->{menu}->{item}->[$i]->{description}; $num = $i; if ($num eq '') { $num = 0; } if ($colcount > 1) { push(@col1, $num . " $menuitem"); } else { if ($menuitem ne '') { push(@col2, $num . " $menuitem\n"); } } $colcount--; $i++; } # # Menu # # 1 2 3 4 5 6 7 8 #012345678901234567890123456789012345678901234567890123456789012345678901234567890 format STDOUT= | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | $item1, $item2 . $input = ''; $command = ''; print "\n\n"; while ($command ne 'exit') { print "+-----------------------------------------------------------------------------+\n"; print "| $title\n"; print "+--------------------------------------+--------------------------------------+\n"; $q = 1; foreach $c (@col1) { $item1 = $c; $item2 = @col2[$q]; write; $q++; } print "| | |\n"; print "+--------------------------------------+--------------------------------------+\n"; print " Enter Your Selection: "; $input = ; chomp($input); if ($input > ($keys->{menu}->{item_count} - 1)) { print "\nPlease Enter 0 - " . ($keys->{menu}->{item_count} - 1) . " Press Enter to Continue...\n"; } $command = $keys->{menu}->{item}->[$input]->{command}; $x = 0; while ($x < $keys->{parameters}->{param_count}) { $paramname = $keys->{parameters}->{parameter}->[$x]->{paramname}; $paramvalue = $keys->{parameters}->{parameter}->[$x]->{paramvalue}; $command =~ s/\(\*$paramname\*\)/$paramvalue/g; $x++; } #print "test: $command\n"; system ($command); } print "\n\nRoqetMenu Exit.\n";