#!/usr/local/bin/rxx /* * ------------------------------------------------------------- * Execution of this program requires a license for uni-REXX on * the host computer where it is to be run. It also requires a * license for uni-XEDIT Extended for each concurrent user. * ------------------------------------------------------------- * * * adbook - TWG electronic address book system * * Usage: adbook [n] [cardfile] * * n is a selection from the main menu; if specified, the system * immediately executes that menu selection; if omitted, the * main menu appears; if the specified option is not valid, the * main menu appears automatically with no message * * cardfile is the name of the file in which address book entries * are stored; if omitted, the default file name is "cardfile" * in the user's $HOME directory; the application assumes * that you have write permission to whatever path/filename * you specify for cardfile * * Modification History: * * 01/10/93 twg Initial implementation * */ parse arg first second signal on novalue callpath = '' parse source . . . whoami . if pos('/',whoami) <> 0 then do lastslash = lastpos('/',whoami) callpath = left(whoami,lastslash-1) if left(callpath,1) <> '/' then callpath = './'callpath end mypath = getenv('PATH') mypath = strip(mypath) if callpath <> '' then mypath = mypath':'callpath call fixpath mypath /* * Initialize main menu options */ options. = '' options.0 = 3 options.1 = 'Add a new entry' options.2 = 'Find an entry' options.3 = 'Exit' /* * Define subroutine calls for each option */ subr. = 'call error' subr.1 = 'call addnew' subr.2 = 'call find' subr.3 = 'call byebye' /* * If first argument is not numeric, then they must have meant it as * the cardfile name */ if datatype(first,'NUM') then do choice = first filename = second end else do filename = first choice = second end /* * If menu choice invalid, assume no choice was made */ if datatype(choice,'NUM') then choice = trunc(choice) if choice < 1 | choice > options.0 then choice = '' /* * Set address book file name */ if filename = '' then do yourhome = getenv('HOME') cardfile = yourhome'/cardfile' end else cardfile = filename call putenv 'TWGCARDFILE='cardfile /* set env var for use by macros */ /* * Main processing loop */ do forever macro = '' dowhat = '' do while choice = '' /* * Display main menu */ address unix 'clear' /* clear screen */ say '' say '' say 'WELCOME TO THE TWG ELECTRONIC ADDRESS BOOK SYSTEM!' say '' say '' say '' say ' Please choose an option from the menu' say '' say '' say '' do i = 1 to options.0 say ' ' i '-' options.i end /* * Get menu selection and process it */ pull choice if datatype(choice,'NUM') then choice = trunc(choice) if choice < 1 | choice > options.0 then do address unix 'clear' say '' say 'Invalid selection - please re-enter' say 'Selection must be between 1 and' options.0 say '' say 'Press Enter to return to main menu' pull response choice = '' end end interpret subr.choice end exit addnew: /* * Add a new entry to the address book */ macro = 'address.xedit' dowhat = 'add an entry to' isthere = verexist(macro) if isthere then 'xe newfile -prof address' else call notthere choice = '' return find: /* * Find an existing entry in the address book */ macro = 'reshow.xedit' dowhat = 'find an entry in' address unix 'clear' say '' say '' say 'There are many ways of finding entries in an address book. Each site' say 'may have different needs.' say '' say 'The current implementation of this program illustrates finding an' say 'entry by searching on Last Name. Since there may be more than one' say 'entry that matches the last name specified, it illustrates cycling' say 'through the matching records until the desired one appears. This' say 'technique may be adapted for other types of searches that you may' say 'wish to implement.' say '' say '' say 'Press Enter to continue' pull response address unix 'clear' say '' say '' say '' say 'Enter Last Name to look up' say ' (Lookup is not case sensitive)' say '' pull lookup found = 0 prevqd = queued() /* Find out how much is currently on the queue */ filethere = verexist(cardfile) /* Be sure address book file exists */ if filethere then do lookup = 'Last Name: ' lookup /* Set actual lookup string */ call popen 'grep -ni "'lookup'"' cardfile /* Find all lines w/string */ if result = 0 then found = 1 if found then do /* If you found some, */ call lineout cardfile /* close file, */ nomore = 0 /* initialize some variables, */ j = 0 lineno. = '' match. = '' address unix 'clear' /* clear screen, */ do until nomore /* and process all found entries */ j = j + 1 zname = '' pull nextone /* Get an entry */ parse var nextone lineno.j ':' . /* Get line no. where found */ where = lineno.j do i = 1 to 3 /* Get actual data from file */ x = linein(cardfile,where) parse var x ':' y /* Strip off descriptor string */ y = strip(y) /* and surrounding blanks */ if i = 1 then zname = zname||y', ' /* comma after last name */ else zname = zname y where = where + 1 end call lineout cardfile match.j = zname stillqd = queued() - prevqd /* Recheck what's left on queue */ if stillqd = 0 then nomore = 1 end do k = 1 to j /* Display all matches */ say '' say k '-' match.k end say '' /* Prompt for which one to view */ say 'Enter number of entry to view in detail' say '' say 'Press Enter to bypass detail view and return to main menu' say '' pull response /* Check for valid selection */ if response = '' then do choice = '' return end do while response < 1 | response > j say 'Invalid selection - must be between 1 and' j say '' pull response end /* * Set environment variables for communication of information between * this program and the uni-XEDIt profile that will retrieve and display * the detail data. */ call putenv 'TWGADBOOK='lineno.response isthere = verexist(macro) if isthere then 'xe newfile -prof reshow' /* Display detail */ else call notthere end else do /* If no matches found for last name chosen */ say '' say 'No entries found for Last Name:' lookup say '' say 'Press Enter to continue' pull response end end else do /* If address book file does not exist */ address unix 'clear' say '' say 'The address book file' cardfile 'does not exist.' say 'Please verify that you have a valid address book file before' say ' attempting to lookup entries.' say '' say 'Press Enter to return to the main menu' pull response end call putenv 'TWGADBOOK=' choice = '' return fixpath: /* * add directories to XEDITPATH environment variable */ parse arg dirlist oldpath = getenv('XEDITPATH') newpath = oldpath':'dirlist call putenv 'XEDITPATH='newpath return verexist: /* * Verify existence of screen display macro in current directory or in * XEDITPATH */ parse arg macroname exists = 0 if popen('test -f' macroname) = 0 then exists = 1 if ^exists then do xpath = getenv('XEDITPATH') do until xpath = '' parse var xpath one ':' xpath filepath = one'/'macroname if popen('test -f' filepath) = 0 then exists = 1 end end return exists notthere: /* * Messages if a required file is determined not to exist in any of the * valid locations. */ address unix 'clear' say '' say 'The macro' macro 'does not exist in the current directory,' say 'the directory in which the adbook program is located,' say 'or in any directory specified in PATH or XEDITPATH.' say '' say 'You cannot' dowhat 'the address book if this file is not' say 'present.' say '' say '' say "Contact your site's uni-XEDIT support staff for the location of" say 'this file and add that directory to your XEDITPATH environment' say 'variable.' say '' say 'Press Enter to return to the main menu' pull response return byebye: /* * Graceful exit */ call putenv 'TWGCARDFILE=' say 'Thank you for using the TWG Electronic Address Book System' exit novalue: /* * Uninitialized variable processing */ address unix 'clear' say '' say 'Internal error - uninitialized variable' error: /* * Error exit - only for severe errors */ say '' say 'Internal error in adbook processing' say '' say "For assistance, contact your site's uni-XEDIT support staff" say ' or contact The Workstation Group (708) 696-4800' say '' say 'Exiting now' exit