Some more Rexx help,
Does some one know how to take user iinput (directories) and write a config file ?
Greggory
Split the problem up into parts and solve each part.
I prefer UZUnzipToVar or LINEIN below to load the settings and the latter is better in combination with 3. to write configuration settings.
1. Read a File into memory in one chunk that you need to interpret each setting later?
rxReadFile: PROCEDURE
f_name = STRIP( ARG(1) )
IF LENGTH( f_name ) = 0 THEN RETURN 1
IF STREAM( f_name, 'C', 'QUERY EXIST' ) < 10 THEN RETURN 2
f_size = STREAM( f_name, 'C', 'QUERY SIZE' )
temp = CHARIN( f_name, 1, f_size )
CALL STREAM f_name, 'C', 'CLOSE'
RETURN temp
or UZUnzipToVar to use a zipped textfile with key = value pairs of data
see Rexx Tips & Tricks documentation
or line by line and Interpret code directly to overwrite variables already populated with default settings¹
rxLoadSettings:
f_name = STRIP( ARG(1) )
IF LENGTH( f_name ) = 0 THEN RETURN 1
IF STREAM( f_name, 'C', 'QUERY EXIST' ) < 10 THEN RETURN 2
DO WHILE LINES( f_name ) > 0
INTERPRET LINEIN( f_name )
END
CALL STREAM f_name, 'C', 'CLOSE'
RETURN 0
/* Only needed if you use dynamic variables that contain parameters */
rxGetSetting:
INTERPRET 'temp = 'ARG(1)
RETURN temp
2. User input
/* The user has to type in a valid path, or 0 to skip and let us decide what to do */
DO WHILE answer = ''
PARSE PULL answer
/* If the user typed in anything, check it */
IF answer = 0 THEN LEAVE /* User only typed 0, so we jump out of this loop and have to take care of it further down */
ELSE IF STRIP( answer ) <> '' THEN
answer = DIRECTORY( answer ) /* The path will be returned if it is valid, otherwise '' (empty string) will be returned */
END
IF answer = 0 THEN
answer = DIRECTORY() /* We use the current directory instead?*/
/* another alternative is to RETURN from the program, but that could be done in the loop as well. You decide*/
3. Write the config file
/* The example below write the settings to file with current values */
settings = 'variablename search_path app_path combined_var'
CALL SysFileDelete my_cfg_file
DO i = 1 TO WORDS( settings )
CALL LINEOUT my_cfg_file, SUBWORD( settings, i, 1 )' = "'VALUE( SUBWORD( settings, i, 1 ) )'"'
END
Variables such as ARG(1), ARG(2) etc. only appear in prewritten config/translation files.
Static text appear such as the variable "search_path" below is present in config files written by the application to save paths etc. related to the computer the script execute on.
¹) plain text file or .zip-file
variablename = "'This is a text with a parameter value ( 'ARG(2)' ) that can be set during execution'
app_path = "'C:\Tools\'ARG(2)"
search_path = "This is just a plain static text"
combined_var = "ARG(2)' and 'ARG(3)' can be used, as well as 'ARG(4)' and so on"
Load and overwrite default variables with
CALL rxLoadSettings 'mysettings.cfg'
/***** Not needed for value based only settings *****/
and get each variable combined with input parameters with
SAY rxGetSetting( 'variablename', 'MYPARAM' )
/*Would output "'This is a text with a parameter value ( MYPARAM ) that can be set during execution" */
It's possible to call rxGetSettings with more variables.