/****************************** Module Header ******************************* * * Module Name: arrayvars.e * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ compile if not defined( SMALL) -- If compiled separately define INCLUDING_FILE = 'ARRAYVARS.E' include 'stdconst.e' const tryinclude 'mycnf.e' const compile if not defined( NLS_LANGUAGE) NLS_LANGUAGE = 'ENGLISH' compile endif include NLS_LANGUAGE'.e' compile endif ; --------------------------------------------------------------------------- /* 旼컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴커 � what's it called: Get_Array_Value( array_ID, array_index, value) � � � � what does it do : Looks up the index in the array, and if found, puts the � � value in value. The result returned for the function � � is the return code from the array lookup - 0 if � � successful. If the index wasn't found, value will � � contain the null string and rc = -330 will be set. � � � � who and when : Larry M. 9/12/91 � 읕컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴켸 */ ; This should be used instead of any 'do_array 3' to avoid the error msg ; 'Invalid third parameter' of do_array 3, if it doesn't exist. ; ; Additionally, before removing an array var, it should be queried with ; get_array_value if it exists, e.g.: ; ; defc RmArrayVar ; universal epm_utility_array_id ; varname = arg( 1) ; -- Always call get_array_value with a 3rd parameter. ; -- varvalue doesn't have to be defined before using it as a ; -- call by reference variable. ; call get_array_value( epm_utility_array_id, varname, varvalue) ; if not rc then ; do_array 4, epm_utility_array_id, varname ; endif defproc Get_Array_Value( array_ID, array_index, var array_value) rc = 0 array_value = '' display -2 -- switch off messages do_array 3, array_ID, array_index, array_value display 2 return ; --------------------------------------------------------------------------- ; Some useful procedures to use array vars easily. They can be used like ; universal vars, but 'universal' must not be specified. Maybe array vars ; are slower than universal vars, but on a 2Mhz CPU there's no noticable ; difference. ; =========================================================================== ; Only the proc GetAVar returns a value. Therefore these procs can be used ; without 'call'. rc will be set by do_array, so it can be checked, if the ; operation was successful. ; Varnames are converted to lowercase, so every case can be used. defproc GetAVar( VarName) universal epm_utility_array_id VarName = lowcase( arg( 1)) ArrayFid = arg( 2) if ArrayFid = '' then ArrayFid = epm_utility_array_id endif if ArrayFid = '' then --sayerror 'GetAVar( 'VarName'): Array ArrayFid doesnot exist at this time.' rc = 0 return '' endif VarValue = '' if leftstr( VarName, 1) == '.' then getfileid fid VarName = fid''VarName endif call Get_Array_Value( ArrayFid, VarName, VarValue) -- sets rc if rc = -330 then -- rc = -330: "Invalid third parameter" -- Return no error, if var doesn't exist already rc = 0 VarValue = '' endif return VarValue defc GetAVar, ShowAVar VarName = strip( arg( 1)) -- A cmd can't return anything, therefore just give a msg 'SayError 'VarName' = "'GetAVar( VarName)'"' ; --------------------------------------------------------------------------- ; Set VarName to VarValue defproc SetAVar( VarName, VarValue) universal epm_utility_array_id ArrayFid = arg( 3) if ArrayFid = '' then ArrayFid = epm_utility_array_id endif VarName = lowcase( VarName) if ArrayFid = '' then --sayerror 'SetAVar( 'VarName', 'VarValue'): Array ArrayFid doesnot exist at this time.' rc = -337 return endif if leftstr( VarName, 1) == '.' then getfileid fid VarName = fid''VarName endif do_array 2, ArrayFid, VarName, VarValue -- sets rc -- Strange: do array 2 often sets rc = -273. Set it to 0 then. if rc = -273 then rc = 0 endif return defc SetAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetAVar( VarName, VarValue) ; --------------------------------------------------------------------------- ; Remove VarName from array defproc DropAVar( VarName) universal epm_utility_array_id ArrayFid = arg( 2) if ArrayFid = '' then ArrayFid = epm_utility_array_id endif VarName = lowcase( VarName) if ArrayFid = '' then --sayerror 'DropAVar( 'VarName'): Array ArrayFid doesnot exist at this time.' rc = 0 return endif if leftstr( VarName, 1) == '.' then getfileid fid VarName = fid''VarName endif call Get_Array_Value( ArrayFid, VarName, VarValue) if not rc then do_array 4, ArrayFid, VarName -- delete entry endif return defc DropAVar VarName = strip( arg( 1)) call DropAVar( VarName) ; --------------------------------------------------------------------------- ; Check for every word of VarValuePart if already present in VarName; add if not ; present; else nothing. defproc AddAVar( VarName, VarValuePart) universal epm_utility_array_id ArrayFid = arg( 3) if ArrayFid = '' then ArrayFid = epm_utility_array_id endif if VarValuePart = '' then -- This would add a space at the end return endif if leftstr( VarName, 1) == '.' then getfileid fid VarName = fid''VarName endif OldValue = GetAVar( VarName, ArrayFid) NewValue = strip( OldValue) do w = 1 to words( VarValuePart) wrd = word( VarValuePart, w) if wordpos( upcase( wrd), upcase( OldValue)) then iterate endif if NewValue = '' then NewValue = wrd else NewValue = NewValue wrd endif enddo call SetAVar( VarName, NewValue, ArrayFid) return defc AddAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call AddAVar( VarName, VarValuePart) ; --------------------------------------------------------------------------- ; Remove every word of VarValuePart from VarName defproc DelAVar( VarName, VarValuePart) universal epm_utility_array_id ArrayFid = arg( 3) if ArrayFid = '' then ArrayFid = epm_utility_array_id endif if leftstr( VarName, 1) == '.' then getfileid fid VarName = fid''VarName endif OldValue = GetAVar( VarName, ArrayFid) if OldValue = '' then return endif NewValue = OldValue do w = 1 to words( VarValuePart) wrd = word( VarValuePart, w) do forever wp = wordpos( upcase( wrd), upcase( NewValue)) if wp = 0 then leave endif -- delword doesn't remove a trailing space if the last word is -- deleted. For that case, strip is required. NewValue = strip( delword( NewValue, wp, 1)) enddo enddo call SetAVar( VarName, NewValue, ArrayFid) return defc DelAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call DelAVar( VarName, VarValuePart) ; =========================================================================== defproc GetFileAVar( VarName) getfileid fid VarValue = GetAVar( fid'.'VarName) return VarValue defc GetFileAVar, ShowFileAVar VarName = strip( arg( 1)) -- A cmd can't return anything, therefore just give a msg getfileid fid 'SayError 'fid'.'VarName' = "'GetAVar( fid'.'VarName)'"' ; --------------------------------------------------------------------------- ; Set fid'.'VarName to VarValue defproc SetFileAVar( VarName, VarValue) getfileid fid call SetAVar( fid'.'VarName, VarValue) return defc SetFileAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetFileAVar( VarName, VarValue) ; --------------------------------------------------------------------------- defproc DropFileAVar( VarName) getfileid fid DropAVar( fid'.'VarName) return defc DropFileAVar VarName = strip( arg( 1)) DropFileAVar( VarName) ; =========================================================================== defproc GetMenuAVar( VarName) universal epm_menu_array_id if not pos( 'mid_', lowcase( VarName)) = 1 then VarName = 'mid_'VarName endif VarValue = GetAVar( VarName, epm_menu_array_id) return VarValue defc GetMenuAVar, ShowMenuAVar VarName = strip( arg( 1)) 'SayError 'VarName' = "'GetMenuAVar( VarName)'"' ; --------------------------------------------------------------------------- defproc SetMenuAVar( VarName, VarValue) universal epm_menu_array_id if not pos( 'mid_', lowcase( VarName)) = 1 then VarName = 'mid_'VarName endif call SetAVar( VarName, VarValue, epm_menu_array_id) return defc SetMenuAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetMenuAVar( VarName, VarValue) ; --------------------------------------------------------------------------- defproc DropMenuAVar( VarName) universal epm_menu_array_id if not pos( 'mid_', lowcase( VarName)) = 1 then VarName = 'mid_'VarName endif call DropAVar( VarName, epm_menu_array_id) return defc DropMenuAVar VarName = strip( arg( 1)) call DropMenuAVar( VarName) ; --------------------------------------------------------------------------- defproc AddMenuAVar( VarName, VarValuePart) universal epm_menu_array_id if not pos( 'mid_', lowcase( VarName)) = 1 then VarName = 'mid_'VarName endif call AddAVar( VarName, VarValuePart, epm_menu_array_id) return defc AddMenuAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call AddMenuAVar( VarName, VarValuePart) ; --------------------------------------------------------------------------- defproc DelMenuAVar( VarName, VarValuePart) universal epm_menu_array_id if not pos( 'mid_', lowcase( VarName)) = 1 then VarName = 'mid_'VarName endif call DelAVar( VarName, VarValuePart, epm_menu_array_id) return defc DelMenuAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call DelMenuAVar( VarName, VarValuePart) ; =========================================================================== defproc GetKeysAVar( VarName) universal epm_keys_array_id VarValue = GetAVar( VarName, epm_keys_array_id) return VarValue defc GetKeysAVar, ShowKeysAVar VarName = strip( arg( 1)) 'SayError 'VarName' = "'GetKeysAVar( VarName)'"' ; --------------------------------------------------------------------------- defproc SetKeysAVar( VarName, VarValue) universal epm_keys_array_id call SetAVar( VarName, VarValue, epm_keys_array_id) return defc SetKeysAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetKeysAVar( VarName, VarValue) ; --------------------------------------------------------------------------- defproc DropKeysAVar( VarName) universal epm_keys_array_id call DropAVar( VarName, epm_keys_array_id) return defc DropKeysAVar VarName = strip( arg( 1)) call DropKeysAVar( VarName) ; --------------------------------------------------------------------------- defproc AddKeysAVar( VarName, VarValuePart) universal epm_keys_array_id call AddAVar( VarName, VarValuePart, epm_keys_array_id) return defc AddKeysAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call AddKeysAVar( VarName, VarValuePart) ; --------------------------------------------------------------------------- defproc DelKeysAVar( VarName, VarValuePart) universal epm_keys_array_id call DelAVar( VarName, VarValuePart, epm_keys_array_id) return defc DelKeysAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call DelKeysAVar( VarName, VarValuePart) ; =========================================================================== defproc GetMlcAVar( VarName) universal epm_mlc_array_id VarValue = GetAVar( VarName, epm_mlc_array_id) return VarValue defc GetMlcAVar, ShowMlcAVar VarName = strip( arg( 1)) 'SayError 'VarName' = "'GetMlcAVar( VarName)'"' ; --------------------------------------------------------------------------- defproc SetMlcAVar( VarName, VarValue) universal epm_mlc_array_id call SetAVar( VarName, VarValue, epm_mlc_array_id) return defc SetMlcAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetMlcAVar( VarName, VarValue) ; --------------------------------------------------------------------------- defproc DropMlcAVar( VarName) universal epm_mlc_array_id call DropAVar( VarName, epm_mlc_array_id) return defc DropMlcAVar VarName = strip( arg( 1)) call DropMlcAVar( VarName) ; --------------------------------------------------------------------------- defproc AddMlcAVar( VarName, VarValuePart) universal epm_mlc_array_id call AddAVar( VarName, VarValuePart, epm_mlc_array_id) return defc AddMlcAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call AddMlcAVar( VarName, VarValuePart) ; --------------------------------------------------------------------------- defproc DelMlcAVar( VarName, VarValuePart) universal epm_mlc_array_id call DelAVar( VarName, VarValuePart, epm_mlc_array_id) return defc DelMlcAVar Args = strip( arg( 1)) parse value Args with VarName VarValuePart call DelMlcAVar( VarName, VarValuePart) ; =========================================================================== defproc GetModeAVar( VarName) LoMode = lowcase( GetMode()) VarValue = GetAVar( LoMode'.'VarName) return VarValue defc GetModeAVar, ShowModeAVar VarName = strip( arg( 1)) -- A cmd can't return anything, therefore just give a msg LoMode = lowcase( GetMode()) 'SayError 'LoMode'.'VarName' = "'GetAVar( LoMode'.'VarName)'"' ; --------------------------------------------------------------------------- ; Set LoMode'.'VarName to VarValue defproc SetModeAVar( VarName, VarValue) LoMode = lowcase( GetMode()) call SetAVar( LoMode'.'VarName, VarValue) return defc SetModeAVar Args = strip( arg( 1)) parse value Args with VarName VarValue call SetModeAVar( VarName, VarValue) ; --------------------------------------------------------------------------- defproc DropModeAVar( VarName) LoMode = lowcase( GetMode()) DropAVar( LoMode'.'VarName) return defc DropModeAVar VarName = strip( arg( 1)) DropModeAVar( VarName) ; ---------------------------------------------------------------------------