home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / mgrdemos.zoo / demo / sh / menu < prev    next >
Encoding:
Korn shell script  |  1989-01-25  |  3.1 KB  |  106 lines

  1. #!/bin/ksh
  2. #                        Copyright (c) 1987 Bellcore
  3. #                            All Rights Reserved
  4. #       Permission is granted to copy or use this program, EXCEPT that it
  5. #       may not be sold for profit, the copyright notice must be reproduced
  6. #       on copies, and credit should be given to Bellcore where it is due.
  7. #       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  8.  
  9. #    $Header: menu,v 4.1 88/06/21 14:01:33 bianchi Exp $
  10. #    $Source: /tmp/mgrsrc/demo/sh/RCS/menu,v $
  11.  
  12. # Select a pop-up menu in the current mgr window,
  13. # Or download and select a menu
  14. # Or just download a new menu and don't select it.
  15. # Menus are activated by the middle mouse button.
  16. # See "man menu" for more details
  17.  
  18. # Complaints to: Paul Tukey, paul@bellcore
  19.  
  20. TAB="    " FONT=7 NAME= C="`basename $0`" LOAD=1 SELECT=
  21. if test "$TERM" != mgr; then
  22.     echo "$C only works with mrg" >&2; exit
  23. fi
  24. for ARG
  25. do
  26.     case "$ARG" in
  27.       -l*) LOAD="`expr 0 + \`echo $ARG | sed 's/..//'\``";;
  28.       -s*) SELECT="`expr 0 + \`echo $ARG | sed 's/..//'\``";;
  29.       -f*) FONT="`echo $ARG | sed 's/..//'`";;
  30.       -d*) TAB="`echo $ARG | sed 's/..//'`";;
  31.       -n*) NAME="`echo $ARG | sed 's/..//'`";;
  32.        -*) echo >&2 "$C: unknown option $ARG"; exit 1; exit;;
  33.     *) break;;
  34.     esac
  35.     shift
  36. done
  37.  
  38. case "$SELECT" in
  39.      0) ;;
  40.     "") SELECT=$LOAD;;
  41.      *) echo "${SELECT}m\c"; exit
  42. esac
  43.  
  44. case $# in
  45.   0) if test -t 0; then
  46.     echo >&2 "Usage: $C [-l<load-pos>] [-s<select-pos>]
  47.         [-f<font>] [-d<delim>] [-n<name>] menufile(s)"
  48.     exit
  49.      fi
  50. esac
  51.  
  52. if test "X$NAME" = "X" -a "X$*" != X; then
  53.     NAME="`echo \"$*\" | tr 'a-z' 'A-Z' | sed 's/ /; /'`"
  54.     fi
  55.  
  56. stty tabs
  57. (/bin/cat $*; echo pos=9999) | 
  58.     awk -F"$TAB" '
  59.     BEGIN { TAB = FS
  60.         first = 0; nameflag = 0
  61.         font = "'"$FONT"'"
  62.         pos = "'"$LOAD"'"
  63.         items = ""; actions = ""; name = ""; nameact = ""
  64.         defaultname = "'"$NAME"'" }
  65.     /^delim=/ { if ( NR != 1 ) { print "echo Error: delim= line must be first"; exit }
  66.         FS = substr($0,7,1); TAB = FS; next }
  67.     $0 ~ /^pos=/ && first == 0 { pos = substr($0,5); first = 1; next }
  68.     /^font=/  { font = substr($0,6); next }
  69.     /^name=/  { nameflag = 1
  70.         if ( length($0) > 5 ) {
  71.             name = name TAB substr($0,6)
  72.             nameact = nameact TAB }
  73.         next }
  74.     /^pos=/ { if ( nameflag != 1 && defaultname != "" ) {
  75.             name = TAB defaultname
  76.             nameact = TAB
  77.             }
  78.           items = name items
  79.           actions = nameact actions TAB
  80.           if ( length(items) == 0 ) items = TAB " " TAB
  81.           line = "" pos "," font "," length(items actions) "m" items actions
  82.           printf "%s", line
  83.            pos = substr($0,5)
  84.           items = ""; actions = ""; name = ""; nameact = ""
  85.           nameflag = 0
  86.           next
  87.          }
  88.     { if ( $1 == "" ) items = items TAB " "
  89.       else items = items TAB $1
  90.       first = 1
  91.       actions = actions TAB
  92.       if( NF > 1) { act = ""
  93.             for(i=2; i<=NF; i++)
  94.             if(length($i) > 0 ) {
  95.                     act = $i; break }
  96.             if ( substr(act,length(act)-1,2) == "\\c" )
  97.             actions = actions substr(act,1,length(act)-2)
  98.             else
  99.             actions = actions act "\r"
  100.             }
  101.       }
  102.     END { line = "'"$SELECT"'m"
  103.       printf "%s", line
  104.       }
  105.   '
  106.