| 1 |
#!/usr/bin/env regina |
| 2 |
/* |
| 3 |
* Example of how to use sysgetline() and sysgetlinehistory() |
| 4 |
*/ |
| 5 |
call RxFuncAdd 'sysloadfuncs', 'regutil', 'sysloadfuncs' |
| 6 |
call sysloadfuncs |
| 7 |
/* specify our history file */ |
| 8 |
histfile = syshomedirectory()||.dirsep'.history-regutil' |
| 9 |
/* initialise and read the history file so we have access to previous lines */ |
| 10 |
rc = sysgetlinehistory( histfile, 'init') |
| 11 |
rc = sysgetlinehistory( histfile, 'read') |
| 12 |
Say 'This is an example of using the sysgetline() and sysgetlinehistory() functions.' |
| 13 |
Say 'Type in an operating system command, and when you press ENTER it will be executed.' |
| 14 |
Say ' *** BE CAREFUL ***' |
| 15 |
Say 'You can scroll through the history by pressing Up Arrow and Down Arrow.' |
| 16 |
Say 'You can use Left Arrow and Right Arrow to move the cursor within the line displayed.' |
| 17 |
Say 'To exit the program; enter "quit"' |
| 18 |
Say |
| 19 |
Say 'History will be saved in:' histfile |
| 20 |
Say |
| 21 |
Do Forever |
| 22 |
cmd = sysgetline( '> ' ) |
| 23 |
If cmd = 'not implemented' Then |
| 24 |
Do |
| 25 |
Say 'This program relies on a functioning Rexx function; sysgetline(). This function is not available. Aborting.' |
| 26 |
Exit 1 |
| 27 |
End |
| 28 |
cmd = Strip( cmd ) |
| 29 |
If Upper( cmd ) = 'QUIT' Then Leave |
| 30 |
/* execute cmd as shell command */ |
| 31 |
Address System cmd |
| 32 |
End |
| 33 |
/* save our history for next time */ |
| 34 |
rc = sysgetlinehistory( histfile, 'write' ) |