home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
ENVED.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-01-05
|
6KB
|
174 lines
/*****************************************************************************/
/* */
/* (c) Copyright 1988-1993, Quercus Systems */
/* All rights reserved */
/* */
/* REXXLIB sample program: environment string editor */
/* */
/* This sample is an environment string editor that allows interactive */
/* examination and modification of system environment variables. It */
/* provides a simple illustration of the use of RXWINDOW functions. */
/* Other REXXLIB functions used include: */
/* */
/* dosenv pcvideomode */
/* dosenvlist scrsize */
/* lower scrwrite */
/* */
/*****************************************************************************/
/* Help data:
? ENVED.REX is an environment string editor. It displays a window with a
? copy of the system environment. Standard RXWINDOW editing keys can be
? used to modify environment variables. Modified values are updated in the
? system environment.
?
? - To delete environment variables, change the value to blanks.
? - Variables with blank values are removed from the environment.
*/
signal on halt
signal on novalue
signal on syntax
/* misc initialization and validation */
call initialize arg(1)
/* put output from "set" command into array "env.N" */
call dosenvlist 'env'
if env.0 > scr_height - 2 then
call emsg 'Too many environment variables'
/* open window and set border */
start_line = format((scr_height - env.0) / 2, 2, 0)
w = w_open(start_line, 1, env.0 + 2, scr_width)
if w = '' then
call emsg 'Error opening a window'
call w_border w, , , , ,color_border
call w_put w, 1, format((scr_width - length(top_header)) / 2, 2, 0), ,
top_header, , color_prefix
call w_put w, env.0 + 2, ,
format((scr_width - length(bot_header)) / 2, 2, 0), bot_header, , color_prefix
/* setup window with environment variables */
do i = 1 to env.0
name.i = env.i
value.i = dosenv(env.i)
call w_put w, i + 1, 2, name.i'=', ,color_prefix
field_width = scr_width - 3 - length(name.i)
if length(value.i) > field_width then
call w_put w, i + 1, 2 + length(name.i) + 1, ,
' ... Variable too long for ENVED ...', , color_prefix
else do
call w_field w, 'value.'i, i + 1, 2 + length(name.i) + 1, ,
field_width, color_data
if result \= 1 then
say 'error defining field'
end
end
/* make a copy of the original values */
do i = 1 to env.0
original.i = value.i
end
/* display variables and wait for user to finish editing */
call w_read w
call w_close w
w = ''
/* update the environment with any changed variables */
changes = 0
do i = 1 to env.0
if original.i \= value.i then do
call value name.i, value.i, 'os2environment'
if dosenv(name.i) \= value.i then
say 'Unable to set environment variable' name.i
else
changes = changes + 1
end
end
if \quiet then
if changes = 0 then
say 'Environment unchanged'
else
say changes 'environment variable(s) changed'
exit 0
/* initialize - misc initialization and validation */
initialize:
/* inititalize w (window number) */
w = ''
quiet = 0
/* display help info if any arguments were specified */
do i = 1 to words(arg(1))
parm = lower(word(arg(1),i))
select
when parm = '/q' then
quiet = 1
otherwise
signal explain
end
end
/* load rxwindow if necessary */
call load_rxwindow
/* set misc values for window handling */
parse value scrsize() with scr_height scr_width .
top_header = 'OS/2 Environment Editor'
bot_header = 'Press Enter to make all changes, Esc to abort all changes'
parse value pcvideomode() with . colors .
if colors <= 2 then do
color_prefix = 15
color_data = 7
color_border = 7
end
else do
color_prefix = 14
color_data = 10
color_border = 6
end
return
/* ctrl-break handler */
halt:
call emsg 'Ctrl-Break detected - aborting'
/* emsg - general purpose fatal error message routine */
emsg:
if w \= '' then
call w_close w
say arg(1)
exit 99
/* explain - when user asks for help */
explain:
do i = 1 to sourceline()
parse value sourceline(i) with firstcol +1 rest
if firstcol = '?' then
say rest
end
exit
/* syntax error handler */
syntax:
do stax = max(1, sigl - 7) to min(sigl + 3, sourceline())
call scrwrite , 1, '', 80
say right(word(stax '===>', 1 + (stax = sigl)), 4) sourceline(stax)
end
say '===> REXX error' rc 'in line' sigl':' errortext(rc)
exit
/* novalue - error handler */
novalue:
call emsg 'novalue error detected on line' sigl
exit
/* load rxwindow package if required to */
load_rxwindow: procedure
call rxfuncdrop 'w_register'
call rxfuncadd 'w_register', 'rxwin30', 'rxwindow'
call w_register
return