C+ C NAME: C mkenv C PURPOSE: C Process logicals and symbols C CATEGORY: C Environment C CALLING SEQUENCE: C mkenv [-sym -log] [-set -get -del] [-value_only] [name=value] C INPUTS: C Command line switches and arguments C -sym process a logical C -log process a symbol C If neither is set then -log is assumed C C -get get value of symbol or logical C -set set a symbol or logical C -delete delete a symbol or logical C If neither is set then C -get is assumed if no name=value pair is specified C -set is assumed if a name=value pair is specified C C -value_only Only used if -get is set. C By default -get will display a line of the form C Logical: name = value C if the logical or symbol is defined, or C Logical: name is not defined C if the logical or symbol doesn't exist. C C If -value_only is set then only the name of the logical C or symbol is displayed if it exists; it it doesn't then C nothing is displayed. This is useful for extracting the C the value and storing it in a script variable: C C value=$($exe/mkenv -log -get temp) C C sets 'value' to the value of the logical temp, or to the C null string (if temp doesn't exist). C C name=value name: name of the logical or symbol C value: value to be assigned to logical or symbol C OUTPUTS: C If -get is used a line is written to standard output giving the value C of the specified logical or symbol. C C The exit status of the program is 0 on failure and 1 on success. C CALLS: C ForeignArg, Say, lowercase, LocFirst, icompress, itrim, iGetSymbol C iSetSymbol, iDeleteSymbol, iGetLogical, iSetLogical, iDeleteLogical C iCheckDirectory, iGetFileSpec C INCLUDE: C include 'dirspec.h' C SIDE EFFECTS: C -set and -delete update the ~/LOGFIL.TXT file C PROCEDURE: C This program is useful primarily on Linux and Unix for maintaining the C file ~/LOGFIL.TXT containing 'logical' and 'symbol' definitions. C MODIFICATION HISTORY: C JUL-2000, Paul Hick (UCSD; pphick@ucsd.edu) C- program mkenv character cVars(5)*50 character cVar*200 character cArg*30 character cNam*80 character cVal*200 character cTyp*7 character cSay*6 /'mkenv'/ integer Str2Str logical bLog logical bSym logical bGet logical bSet logical bDel logical bVal logical bList include 'dirspec.h' include 'filparts.h' iVar = 5 cVars(1) = 'quiet' call ForeignArg(' ', iVar, cVars, cArg) if (iVar .eq. 0 .and. cArg .eq. ' ') then call Say(cSay,'I','Syntax',cSay//' ['//cSwitch//'log '//cSwitch//'sym] ['// & cSwitch//'get '//cSwitch//'set '//cSwitch//'del] name=value') call Say(cSay,'I','Stop',' ') endif !------- ! Concatenate cVar strings. This will happen when setting a symbol ! containing the cSwitch character. ! E.g. mkenv -set -sym LIB__LS_PRNT='lpr --lp --r'. J = 0 do I=1,iVar if (I .gt. 1) J = J+1 J = J+Str2Str(cVars(I),cVar(J+1:)) end do call lowercase(cArg) !------- ! Check for operations on logicals or symbols. ! Default: logicals bLog = LocFirst(cSwitch//'log', cArg) .ne. 0 bSym = LocFirst(cSwitch//'sym', cArg) .ne. 0 bLog = bLog .or. .not. bSym bSym = bSym .and. .not. bLog if (bLog) cTyp = 'Logical' if (bSym) cTyp = 'Symbol' !------- ! Check for operation: get, set or delete bGet = LocFirst(cSwitch//'get', cArg) .ne. 0 bSet = LocFirst(cSwitch//'set', cArg) .ne. 0 bDel = LocFirst(cSwitch//'del', cArg) .ne. 0 !------- ! If no keyword is specified and equal sign is found, then assume 'set' if (.not. bGet .and. .not. bSet .and. .not. bDel) bSet = LocFirst('=',cVar) .ne. 0 !------- ! If no keyword is specified (and no equal sign present) assume 'get' bGet = bGet .or. (.not. bDel .and. .not. bSet) bSet = bSet .and. .not. bGet bDel = bDel .and. .not. bGet .and. .not. bSet bVal = LocFirst(cSwitch//'val', cArg) .ne. 0 iNam = LocFirst('=',cVar) if (iNam .eq. 0) then cNam = cVar cVal = ' ' if (bSet) then bSet = .FALSE. bDel = .TRUE. end if else cNam = cVar(:iNam-1) cVal = cVar(iNam+1:) end if bList = LocFirst(cSwitch//'list',cArg) .ne. 0 bList = bList .and. bGet iNam = icompress(cNam ,cNam) c iVal = icompress(cVal, cVal) iVal = itrim(cVal) iErr = 1 do while (iErr .ne. 0) if (bList) cNam = '#next_name#' if (bSym) then if (bGet) then iErr = iGetSymbol(cNam, cVal) else if (bSet) then iErr = iSetSymbol(cNam, cVal, 2) else if (bDel) then iErr = iDeleteSymbol(cNam, 2) endif else if (bGet) then iErr = iGetLogical(cNam, cVal) else if (bSet) then !------- ! Logicals almost always refer to directories. If cVal points ! to an existing directory, make sure to add the trailing (back)slash. if (iCheckDirectory(cVal) .eq. 1) I = iGetFileSpec(0,FIL__DIRECTORY,cVal) iErr = iSetLogical(cNam, cVal, 2) else if (bDel) then iErr = iDeleteLogical(cNam) endif end if if (bGet) then iTyp = itrim(cTyp) iNam = itrim(cNam) iVal = itrim(cVal) !------- ! If bVal=.TRUE. then write only the value of the logical/symbol ! if it exists (nothing is written if it doesn't exist) if (bVal) then if (iVal .gt. 0) write (*,'(A)') cVal(:iVal) else if (iVal .gt. 0) then call Say(cSay,'I',cTyp,cNam(:iNam)//' = '//cVal) else if (.not. bList) call Say(cSay,'I',cTyp,cNam(:iNam)//' is not defined') end if end if !------- ! The error code returned from the Symbol and Logical operations is ! used to set the exit code to 0 (failure) or 1 (success). ! For the 'success' exit the 'STOP' is mandatory. if (.not. bList) then if (iErr .eq. 0) call Say(cSay,'W','STOP','') if (iErr .ne. 0) call Say(cSay,'S','STOP','') end if end do end