home *** CD-ROM | disk | FTP | other *** search
- * MENUSYS.PRG -- by Darryl Rubin, November, 1984.
- *
- * For more information about this program, see COMPUTER LANGUAGE
- * MAGAZINE, January, 1985.
- *
- * This program implements an interactive menu system. It presents
- * a menu from a specified .DBF file and allows you to move a
- * highlighted selection bar using F3 (up), F4 (down), or an
- * alphanumeric key (first character of the desired menu item). Hitting
- * F1 or Enter will select the currently highlighted item and F2 will
- * quit the menu.
- *
- * Menu files have the structure ITEM (C 38), HELP (C 40), COMMAND (C 80),
- * and may have up to 23 records: one for each screen row from 1 to 23.
- * ITEMs are displayed on the screen one per line starting at column
- * 20, with HELP text for the currently selected item on line 25.
- * When a given item is selected, the COMMAND field is executed as
- * a macro.
- *
- * The COMMAND field can contain any command you could type at the
- * dot prompt, including another DO MENU command (however, the COMMAND
- * may not contain macros). Because the menu system is recursive, it's
- * OK for menus to call other menus. You can also provide a menu item
- * for quitting the menu if you want an alternative to F2; just
- * specify a COMMAND of RETURN.
- *
- * Records with blank COMMAND fields are treated as menu titles. The
- * selection bar automatically skips over these items -- they are
- * not selectable.
- *
- * The menu system consists of two procedures: DRAWMENU.PRG and MENU.PRG.
- * To start the system, type the following commands, where <MENUNAME>
- * is the file name (sans extension) of the desired MENU database.
- *
- * SET PROCEDURE TO MENUSYS.PRG
- * DO MENU WITH <MENUNAME>
- *
- * The menu system will run faster if you delete all the comments.
- *
- procedure drawmenu
- *
- * Draws the menu screen
- *
- use &menufile
- set talk off
- set exact on
- set filter to
- goto top
- clear
- do while .not. eof() .and. recno() <= 23
- @recno()-1,20 say trim(item)
- skip
- enddo
- set filter to trim(command) <> ''
- return
- *
- procedure menu
- *
- * Main routine and MENUSYS entry point
- *
- parameters menufile
- private first, last, exec, lastpos
- do drawmenu
- *1: Determine screen rows of first and last selectable items
- goto bottom
- do while recno() > 23
- skip -1
- enddo
- last = recno()
- goto top
- first = recno()
- key = chr(255)
- do while key <> chr(254)
- *2: Highlight the currently selected item and get next keystroke
- @recno()-1,20
- selectn = trim(item)
- set color to 7+
- @recno()-1,20 say selectn
- @24,0
- @24,(80-len(trim(help)))/2 say help
- set color to 7
- set console off
- wait to key
- set console on
- @recno()-1,20
- @recno()-1,20 say item
- @24,0
- do case
- case key = chr(252)
- *3: User hit F4. Select next item.
- if recno() < last
- skip 1
- if recno() > last
- goto first
- endif
- else
- goto first
- endif
- case key = chr(253)
- *4: User hit F3. Select previous item.
- if recno() > first
- skip -1
- if recno() < first
- goto last
- endif
- else
- goto last
- endif
- case len(key) = 0
- *5: User hit enter or other extended key. Exec the COMMAND field.
- clear
- exec = command
- lastpos = recno()
- set exact off
- &exec
- *6: We're back, now pause if not returning from another menu.
- if .not. upper(trim(substr(exec,1,8))) $ 'DO MENU HELPASSIST'
- ?
- wait to key
- endif
- do drawmenu
- goto lastpos
- key = ' '
- otherwise
- *7: User hit some other key, skip to matching menu item, if any
- lastpos = recno()
- locate for substr(item,1,1) = key
- if eof()
- goto lastpos
- endif
- endcase
- enddo
- *8: All done, restore settings and quit
- clear
- set exact off
- set talk on
- return