home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / demos.idb / usr / demos / Demo_Interfaces / Buttonfly / mkmenu.z / mkmenu
Encoding:
Text File  |  1997-06-26  |  13.0 KB  |  512 lines

  1. #!/usr/sbin/perl
  2.  
  3. # This is a script to dynamically create the Buttonfly menus
  4.  
  5. # Grab the basic information
  6. require "/usr/demos/Demo_Interfaces/Web/cgi-scripts/DEMO_base.cgi";
  7.  
  8.  
  9. # Set the colors
  10. $color = ".9 .5 .9";
  11. $highcolor = "1.0 .7 1.0";
  12.  
  13.  
  14. # Grab the argument
  15. $switch = shift(@ARGV);
  16. @args     = @ARGV;
  17.  
  18.  
  19. # Set DISPLAY
  20. $ENV{'DISPLAY'} = "localhost:0.0";
  21.  
  22. # Go to the right process
  23.  
  24. if ("$switch" eq "first" ) {
  25.     &first;
  26. }
  27.  
  28. if ("$switch" eq "hardware") {
  29.     &hardware;
  30. }
  31. if ("$switch" eq "features") {
  32.     &features;
  33. }
  34. if ("$switch" eq "industries") {
  35.     &industries;
  36. }
  37. if ("$switch" eq "info") {
  38.     &info;
  39. }
  40. if ("$switch" eq "man") {
  41.     &man;
  42. }
  43. if ("$switch" eq "related") {
  44.     &related;
  45. }
  46. if ("$switch" eq "howto") {
  47.     &howto;
  48. }
  49.  
  50.  
  51.  
  52. sub first {
  53.     print <<END
  54.  
  55. Features
  56.     $basedir/Demo_Interfaces/Buttonfly/mkmenu features one
  57.     .menu. -
  58.     .popup. Features %t
  59.     .color. $color
  60.     .highcolor. $highcolor
  61. Hardware
  62.     $basedir/Demo_Interfaces/Buttonfly/mkmenu hardware one
  63.     .menu. -
  64.     .popup. Hardware %t
  65.  
  66.     .color. $color
  67.     .highcolor. $highcolor
  68. Industries
  69.     $basedir/Demo_Interfaces/Buttonfly/mkmenu industries one
  70.     .menu. -
  71.     .popup. Industries %t
  72.     .color. $color
  73.     .highcolor. $highcolor
  74. END
  75. ;
  76.  
  77.     if (open(APP, "/usr/sbin/slaunch")) {
  78.     close(APP);
  79.     print <<EOF
  80. Find a Demo
  81.     $basedir/Demo_Interfaces/Buttonfly/demofind
  82.     .menu. -
  83.     .popup. Find a Demo %t
  84.     .color. $color
  85.     .highcolor. $highcolor
  86. EOF
  87.     ;
  88.     }
  89.     chdir("$basedir");
  90.     opendir(DIR, "$basedir/Buttonfly");
  91.     @allfiles = readdir(DIR);
  92.     closedir(DIR);
  93.     for (@allfiles) {
  94.         push(@alldirs, $_) if chdir("$basedir/Buttonfly/$_");
  95.     }
  96.     @dirs = grep(!/^\.\.?$/, @alldirs);
  97.     for (@dirs) {
  98.         print <<END
  99. $_
  100.     .cd. $basedir/Buttonfly/$_
  101.     cat ./.m*
  102.     .menu. -
  103.     .popup. $_ %t
  104.     .color. $color
  105.     .highcolor. $highcolor
  106. END
  107. ;
  108.     }
  109. }
  110.  
  111. sub hardware {
  112.  
  113.     if ( "$args[0]" eq "one" ) {
  114.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/hardware.index");
  115.         while(<INDEX>) {
  116.             chop;
  117.             @type = split (/<br>/, $_);
  118.             $key = shift(@type);
  119.             if (@type) {
  120.                 push(@hardware, $key);
  121.             }
  122.         }
  123.         foreach $i ( 0 .. $#hardware ) {
  124.             if ( "$hardware[$i]" eq "ALL SYSTEMS" ) {
  125.                 next;
  126.             } else {
  127.                 $title = "$hardware[$i]";
  128.                 $title =~ s/-/ - /;
  129.                 $title =~ s/SYSTEMS//;
  130.                 print "$title\n";
  131.                 print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu hardware $hardware[$i]\n";
  132.                 print "\t.menu. -\n";
  133.                 print "\t.popup. $title %t\n";
  134.                 print "\t.color. $color\n";
  135.                 print "\t.highcolor. $highcolor\n";
  136.             }
  137.         }
  138.     close(INDEX);
  139.     } else {
  140.         $index = "@args";
  141.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/hardware.index");
  142.         while(<INDEX>) {
  143.             chop;
  144.             @type = split (/<br>/, $_);
  145.             $key = shift(@type);
  146.             if (grep(/<br>$key<br>/, "<br>$index<br>")) {
  147.                 foreach $num ( 0 .. $#type ) {
  148.                     chdir("$basedir/General_Demos");
  149.                     opendir(DIR, "$basedir/General_Demos/$type[$num]");
  150.                     if(grep(/\.m_.*/, readdir(DIR))) {
  151.                         $execute = "$basedir/Demo_Interfaces/Buttonfly/mkmenu related $type[$num]";
  152.                         $type = "top";
  153.                     } else {
  154.                         $execute = "$basedir/General_Demos/$type[$num]/RUN";
  155.                         $type = "bottom";
  156.                     }
  157.                     close(DIR);
  158.                     print "$type[$num]\n";
  159.                     print "\t.cd. $basedir/General_Demos/$type[$num]\n";
  160.                     print "\t$execute\n";
  161.                     if ( "$type" eq "top" ) {
  162.                         print "\t.menu. -\n";
  163.                         print "\t.popup. $type[$num] %t\n";
  164.                         print "\t.color. $color\n";
  165.                         print "\t.highcolor. $highcolor\n";
  166.                     } else {
  167.                         print "\t.popup. $type[$num] %t\n";
  168.                         print "\t.popup. Manual\n";
  169.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu man $type[$num]\n";
  170.                         print "\t.popup. Information\n";
  171.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu info $type[$num]\n";
  172.                     }
  173.                 }
  174.             }
  175.         }
  176.     close(INDEX);
  177.     }
  178. }
  179.  
  180. sub features {
  181.  
  182.     if ( "$args[0]" eq "one" ) {
  183.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/features.index");
  184.         while(<INDEX>) {
  185.             chop;
  186.             @type = split (/<br>/, $_);
  187.             $key = shift(@type);
  188.             if (@type) {
  189.                 push(@features, $key);
  190.             }
  191.         }
  192.         foreach $i ( 0 .. $#features ) {
  193.             $title = "$features[$i]";
  194.             $title =~ s/-/ - /;
  195.             print "$title\n";
  196.             print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu features $features[$i]\n";
  197.             print "\t.menu. -\n";
  198.             print "\t.popup. $title %t\n";
  199.             print "\t.color. $color\n";
  200.             print "\t.highcolor. $highcolor\n";
  201.         }
  202.         close(INDEX);
  203.     } else {
  204.         $index = "@args";
  205.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/features.index");
  206.         while(<INDEX>) {
  207.             chop;
  208.             @type = split (/<br>/, $_);
  209.             $key = shift(@type);
  210.             if (grep(/<br>$key<br>/, "<br>$index<br>")) {
  211.                 foreach $num ( 0 .. $#type ) {
  212.                     chdir("$basedir/General_Demos");
  213.                     opendir(DIR, "$basedir/General_Demos/$type[$num]");
  214.                     if(grep(/\.m_.*/, readdir(DIR))) {
  215.                         $execute = "$basedir/Demo_Interfaces/Buttonfly/mkmenu related $type[$num]";
  216.                         $type = "top";
  217.                     } else {
  218.                         $execute = "$basedir/General_Demos/$type[$num]/RUN";
  219.                         $type = "bottom";
  220.                     }
  221.                     close(DIR);
  222.                     print "$type[$num]\n";
  223.                     print "\t.cd. $basedir/General_Demos/$type[$num]\n";
  224.                     print "\t$execute\n";
  225.                     if ( "$type" eq "top" ) {
  226.                         print "\t.menu. -\n";
  227.                         print "\t.popup. $type[$num] %t\n";
  228.                         print "\t.color. $color\n";
  229.                         print "\t.highcolor. $highcolor\n";
  230.                     } else {
  231.                         print "\t.popup. $type[$num] %t\n";
  232.                         print "\t.popup. Manual\n";
  233.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu man $type[$num]\n";
  234.                         print "\t.popup. Information\n";
  235.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu info $type[$num]\n";
  236.                     }
  237.                 }
  238.             }
  239.         }
  240.     close(INDEX);
  241.     }
  242. }
  243.  
  244. sub industries {
  245.  
  246.     if ( "$args[0]" eq "one" ) {
  247.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/markets.index");
  248.         while(<INDEX>) {
  249.             chop;
  250.             @type = split (/<br>/, $_);
  251.             $key = shift(@type);
  252.             if (@type) {
  253.                 push(@markets, $key);
  254.             }
  255.         }
  256.         foreach $i ( 0 .. $#markets ) {
  257.             $title = "$markets[$i]";
  258.             $title =~ s/-/ - /;
  259.             print "$title\n";
  260.             print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu industries $markets[$i]\n";
  261.             print "\t.menu. -\n";
  262.             print "\t.popup. $title %t\n";
  263.             print "\t.color. $color\n";
  264.             print "\t.highcolor. $highcolor\n";
  265.         }
  266.         close(INDEX);
  267.     } else {
  268.         $index = "@args";
  269.         open(INDEX, "$basedir/Demo_Interfaces/Web/tables/markets.index");
  270.         while(<INDEX>) {
  271.             chop;
  272.             @type = split (/<br>/, $_);
  273.             $key = shift(@type);
  274.             if (grep(/<br>$key<br>/, "<br>$index<br>")) {
  275.                 foreach $num ( 0 .. $#type ) {
  276.                     chdir("$basedir/General_Demos");
  277.                     opendir(DIR, "$basedir/General_Demos/$type[$num]");
  278.                     if(grep(/\.m_.*/, readdir(DIR))) {
  279.                         $execute = "$basedir/Demo_Interfaces/Buttonfly/mkmenu related $type[$num]";
  280.                         $type = "top";
  281.                     } else {
  282.                         $execute = "$basedir/General_Demos/$type[$num]/RUN";
  283.                         $type = "bottom";
  284.                     }
  285.                     close(DIR);
  286.                     print "$type[$num]\n";
  287.                     print "\t.cd. $basedir/General_Demos/$type[$num]\n";
  288.                     print "\t$execute\n";
  289.                     if ( "$type" eq "top" ) {
  290.                         print "\t.menu. -\n";
  291.                         print "\t.popup. $type[$num] %t\n";
  292.                         print "\t.color. $color\n";
  293.                         print "\t.highcolor. $highcolor\n";
  294.                     } else {
  295.                         print "\t.popup. $type[$num] %t\n";
  296.                         print "\t.popup. Manual\n";
  297.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu man $type[$num]\n";
  298.                         print "\t.popup. Information\n";
  299.                         print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu info $type[$num]\n";
  300.                     }
  301.                 }
  302.             }
  303.         }
  304.     close(INDEX);
  305.     }
  306. }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. sub info {
  313.     &infodemo("$basedir/General_Demos/$args[0]/.index");
  314.     open(TMP, ">/tmp/demotmp");
  315.     print TMP "$tags{'DESCRIPTION'}\n";
  316.     close(TMP);
  317.     print "$state";
  318.     `/usr/sbin/fmt -60 /tmp/demotmp>/tmp/demoinfo`;
  319.     `/usr/bin/X11/xconfirm -useslider -file "/tmp/demoinfo" -icon info`;
  320.         `/sbin/rm /tmp/demotmp <<y`;
  321.         `/sbin/rm /tmp/demoinfo <<y`;
  322. }
  323.  
  324.     
  325. sub man {
  326.     $demo = $args[0];
  327.     open(MAN, "/usr/bin/man $demo |");
  328.     read(MAN, $out, 200);
  329.     close(MAN);
  330.     chop $out;
  331.     if (grep(/No manual entry found for/, $out)) {
  332.         `/usr/bin/X11/xconfirm  -t "No Manual For $demo" -icon error>/dev/null&`;
  333.     } else {
  334.         open(CMD, "|/usr/bin/wsh -c man 6 $demo>/dev/null&");
  335.         close(CMD);
  336.     }
  337. }
  338.  
  339. sub related {
  340.     $demo = $args[0];
  341.     chdir("$basedir/General_Demos");
  342.     opendir(DIR, "$basedir/General_Demos/$demo");
  343.     @menus = grep(/\.m_.*/, readdir(DIR));
  344.     closedir(DIR);
  345.     foreach $i ( 0 .. $#menus) {
  346.         open(MENU, "$basedir/General_Demos/$demo/$menus[$i]");
  347.         while (<MENU>) {
  348.             print "$_"
  349.         }
  350.         close(MENU)
  351.     }
  352.     print "\n";
  353.     print "$demo\n";
  354.     print "\t.cd. $basedir/General_Demos/$demo\n";
  355.     print "\t$basedir/General_Demos/$demo/RUN\n";    
  356.     print "\t.popup. $demo %t\n";
  357.     print "\t.popup. Manual\n";
  358.     print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu man $demo\n";
  359.     print "\t.popup. Information\n";
  360.     print "\t$basedir/Demo_Interfaces/Buttonfly/mkmenu info $demo\n";
  361. }
  362.  
  363.  
  364. sub howto {
  365.     `/usr/bin/X11/xconfirm -useslider -file "$basedir/Demo_Interfaces/Buttonfly/buttonfly.info" -icon info>/dev/null&`;
  366. }
  367.  
  368.  
  369.  
  370.  
  371.  
  372. # Begin Subroutine
  373. sub infodemo {
  374.  
  375.         # Set the file to parse
  376.         $file = $_[0];
  377.  
  378.         # Clear out the array %tags
  379.         %tags = "";
  380.  
  381.         # Open the document
  382.         open(DOC, "$file") || ($state = "bad");
  383.  
  384.         # Take each line and parse
  385.         while (<DOC>) {
  386.                 if (grep(/\bEND_HTMLUI\s*/, $_)) {
  387.                         close(DOC);
  388.                         return scalar(@tags);
  389.                         exit;
  390.                 }
  391.                 $btw .= $_;
  392.  
  393.                 # Remove newline
  394.                 chop;
  395.  
  396.                 if ( &endmatch($_) ) {
  397.                         $junk .= $btw;
  398.                         $btw = "";
  399.                 }
  400.  
  401.  
  402.                 # Test to see if it is one of the tags
  403.                 if ( $endtag = &match($_) ) {
  404.  
  405.                         # If it is, make sure it is not a "noparse" tag
  406.                         if (&avoid($_)) {
  407.                                 
  408.                                 $btw = "";
  409.  
  410.                                 #Grab the next line
  411.                                 $_ = <DOC>;
  412.         
  413.                                 # Remove newline
  414.                                 chop;
  415.         
  416.                                 # Remove commented lines
  417.                                 if (grep(/^#/, $_)) {
  418.                                         $_ = <DOC>;
  419.                                 }
  420.         
  421.                                 # Keep feeding the lines into the array
  422.                                 # as long as we don't hit the endtag
  423.                                 while (!/$endtag((.|\s)*)/){
  424.         
  425.                                         # add the line to the array
  426.  
  427.                                         $key = $endtag;
  428.                                         $key =~ s/END_//;
  429.  
  430.                                         # Add a newline if its your 
  431.                                         # first time around
  432.                                         $_ = "\n$_" if (!$times);
  433.                                         $tags{$key} .= "$_\n";                                                                          
  434.                                         local($times);
  435.                                         $times = 1;
  436.  
  437.         
  438.                                         # if we somehow hit another tag
  439.                                         # (the endtag is missing or mispelled)
  440.                                         # start over, not parsing for
  441.                                         # the offending tag
  442.                                         if ((&match($_)) ) {
  443.                                                 $junk .= $tags{$key};
  444.                                                 $tags{$key} .= "";
  445.                                                 push(@noparse, "$key:");
  446.                                                 &infodemo("$file");
  447.                                                 return scalar(@tags);
  448.                                         }
  449.         
  450.                                         #Grab the next line
  451.                                         $_ = <DOC>;
  452.         
  453.                                         # Remove newline
  454.                                         chop;
  455.         
  456.                                         # Remove commented lines
  457.                                         if (grep(/^#/, $_)) {
  458.                                                 $_ = <DOC>;
  459.                                                 chop;
  460.                                         }
  461.                                 }
  462.                         } else {
  463.                                 $_ = <DOC>;
  464.                         }
  465.                 }
  466.  
  467.         }
  468.         close(DOC);
  469.         return scalar(@tags);
  470. }
  471.  
  472.  
  473. # Check the line against all possible elements
  474. sub match {
  475.         $line = $_[0];
  476.         foreach $tag ( @elements ) {
  477.                         $_ = $line;
  478.                         if (/\b$tag:\s*/) {
  479.                         return "END_$tag";
  480.                 }
  481.         }
  482.         return 0;
  483. }
  484.  
  485. sub endmatch {
  486.         $line = $_[0];
  487.         foreach $tag ( @elements ) {
  488.                         $_ = $line;
  489.                         if (/\bEND_$tag\s*/) {
  490.                         return 1;
  491.                 }
  492.         }
  493.         return 0;
  494. }
  495.  
  496.  
  497.  
  498. # Check to see if this is a tag we should avoid
  499. sub avoid {
  500.         $line = $_[0];
  501.         foreach $each ( @noparse ) {
  502.                         $_ = $line;
  503.                         if (/\b$each\s*/) {
  504.                         return 0;
  505.                 }
  506.         }
  507.         return 1;
  508. }
  509.  
  510.  
  511.  
  512.