home *** CD-ROM | disk | FTP | other *** search
- /* GetString.e
- * Opens a string requester from Shell (useful in scripts) and stores the
- * result in an environment variable or prints it.
- *
- * Public Domain by Diego Caravana.
- *
- *
- * Thanks to Wouter van Oortmerssen for his VERY GOOD work, hoping that he
- * will continue to improve E language !
- *
- * Hey, consider to learn E !!!
- *
- * ========================================================================
- *
- * $Id: GetString.e,v 1.3 93/02/13 00:55:26 diego Rel $
- *
- * $Log: GetString.e,v $
- * Revision 1.3 93/02/13 00:55:26 diego
- * Some small adjustements. Better code.
- * Released to Wouter for inclusion in next release of E.
- * WOW!
- *
- *
- * Revision 1.2.1.2 93/02/05 21:46:46 diego
- * Some adjustements of the code. Some small corrections.
- * Ready for realeasing.
- *
- * Revision 1.2.1.1 93/02/03 22:00:37 diego
- * Added more E exception support (i.e. RAISE/IF)
- * Fixed nasty bug of uninitialized variables.
- * Some adjustements. More reliable code.
- *
- * Revision 1.2 93/02/02 22:09:13 diego
- * More E-like code :) i.e. HANDLE/EXCEPT
- *
- * Revision 1.1 93/02/02 22:02:50 diego
- * Some bug fixes (forgot FreeArgs()).
- * Enhanced code.
- *
- * Revision 1.0 93/02/02 21:51:52 diego
- * Initial revision
- *
- */
-
- OPT OSVERSION=37
-
- MODULE 'ReqTools', 'libraries/reqtools', 'dos/var', 'utility/tagitem'
-
- CONST ARGS_NUM=7, BUFLEN=100
- ENUM ARG_TITLE, ARG_USTRING, ARG_MSG, ARG_VAR, ARG_GLOBAL, ARG_STDOUT,
- ARG_PUBSCREEN
- ENUM ERR_NONE=0, ERR_WRONGARGS, ERR_BADKEYS, ERR_NOREQLIB, ERR_CANCEL,
- ERR_NOVAR
-
- RAISE ERR_NOREQLIB IF OpenLibrary()=NIL,
- ERR_WRONGARGS IF ReadArgs()=NIL,
- ERR_CANCEL IF RtGetStringA()=NIL,
- ERR_NOVAR IF SetVar()=NIL
-
- PROC main() HANDLE
- DEF buf[BUFLEN]:STRING, args[ARGS_NUM]:ARRAY OF LONG, rdargs=NIL,
- template
-
- /* version string, as C= says... */
- VOID '$VER: GetString 1.3 (13.02.93) by Diego Caravana'
-
- /* do this if you don't want to meet the Guru :) (only if RAISE automatic
- * mechanism is used!)
- */
- reqtoolsbase:=0
-
- /* assignment made just for commodity */
- template:='TITLE/A,STRING/K,MSG=MESSAGE/K,VAR=VARIABLE/K,'+
- 'GLOBAL/S,STDOUT/S,PUBSCREEN/K'
-
- /* open Nico's library */
- reqtoolsbase := OpenLibrary('reqtools.library', REQTOOLSVERSION)
-
- /* get user arguments from command line */
- rdargs := ReadArgs(template, args, 0)
-
- /* do not allow the use of VAR/GLOBAL and STDOUT keywords
- * because in this way the user can print the result directly on stdout
- * without being bored by env variables
- */
- IF ((StrLen(args[ARG_VAR]) <> 0) OR args[ARG_GLOBAL]) AND
- args[ARG_STDOUT] THEN Raise(ERR_BADKEYS)
-
- /* the default string specified by the user is copied in the buffer passed
- * to the requester
- */
- StrCopy(buf, args[ARG_USTRING], ALL)
-
- /* open the requester (the result is checked via RAISE/IF) */
- RtGetStringA(buf, BUFLEN, args[ARG_TITLE], 0,
- [ RTGS_TEXTFMT, args[ARG_MSG], RTGS_ALLOWEMPTY, TRUE,
- RT_PUBSCRNAME, args[ARG_PUBSCREEN], TAG_DONE ])
-
- IF args[ARG_STDOUT] /* choose the way */
- WriteF(buf)
- ELSE
- /* default name for environment variable */
- IF StrLen(args[ARG_VAR]) = 0 THEN args[ARG_VAR] := 'GetStringResult'
-
- SetVar(args[ARG_VAR], buf, StrLen(buf),
- IF args[ARG_GLOBAL] THEN GVF_GLOBAL_ONLY ELSE GVF_LOCAL_ONLY)
- ENDIF
-
- /* let's exit cleanly */
- Raise(ERR_NONE)
-
- EXCEPT
- IF rdargs THEN FreeArgs(rdargs)
- IF reqtoolsbase THEN CloseLibrary(reqtoolsbase)
-
- SELECT exception
- CASE ERR_NOREQLIB
- WriteF('*** could not open reqtools.library v38!\n')
- CASE ERR_BADKEYS
- WriteF('*** no simultaneous VAR/GLOBAL and STDOUT keywords.\n')
- CASE ERR_CANCEL; CleanUp(5);
- DEFAULT
- PrintFault(IoErr(), '*** DOS Error')
- ENDSELECT
-
- IF exception THEN CleanUp(10)
- CleanUp(0)
- ENDPROC
-