REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Get default object settings



The default settings for the standard WPS objects are saved in the file 
\OS2\INI.RC . (see also GETOBJ.CMD; see the routine ShowObjectDate in the 
section General routines for the samples for an example on how to get the 
settings of an object).   

 
/* sample routine to get the default settings of an object            */
/* This routine reads the file INI.RC to get the default settings     */
/* of the object.                                                     */
/* Note that object IDs are case sensitive!                           */

                        /* path & name of the RC file for MAKEINI     */
  INIRCFile = 'C:\OS2\INI.RC'

  do forever
    call CharOut, 'Enter the object ID (<RETURN> to exit): '
    objectID = strip( lineIn() )

    if objectID = '' then
      leave

    if left( ObjectID,1 ) <> '<' then
      objectID = '<' || objectID || '>'

    say 'Detecting the data of the object "' || ObjectID || '" ...'
    rc = getObjectData( ObjectID, 'objectData', iniRCFile  )
    if rc = 0 then
    do
      say 'title:     "' || objectData.title     || '"'
      say 'className: "' || objectData.className || '"'
      say 'location:  "' || objectData.location  || '"'
      say 'setup:     "' || objectData.setup     || '"'
    end /* if rc = 0  */
    else
    do
      say 'Error ' || rc || ' detecing the object settings!'
    end
  end /* do forever */

exit

/* ------------------------------------------------------------------ */
/* function: get the data of an object                                */
/*                                                                    */
/* call:     getObjectData objectID, resultStem, rcFile               */
/*                                                                    */
/* where:    objectID - the id of the object                          */
/*           resultStem - name of the stem for the result             */
/*           rcFile - name of the rc file with the object description */
/*                    The format of the rc file must be equal to the  */
/*                    format of the file \OS2\INI.RC.                 */
/*                                                                    */
/* returns:  0 - ok                                                   */
/*           1 - rc file not found                                    */
/*           2 - object not found in the RC file                      */
/*         255 - invalid call                                         */
/*                                                                    */
/* output:   "objectData".title     = title                           */
/*                       .className = className                       */
/*                       .location  = location                        */
/*                       .setup     = setup string                    */
/*                                                                    */
GetObjectData:
  parse arg god.__objectID, god.__resultStem, god.__thisRCFile .

                        /* constants for the comment begin and end    */
                        /* strings used in the RC files               */
  god.__CommentBegin = '/' || '*'
  god.__CommentEnd   = '*' || '/'

                        /* init the return code                       */
  thisRC = 255

  if god.__objectID <> '' & god.__objectData <> '' then
  do
    thisRC = 1
    if stream( god.__thisRCFile, 'c', 'QUERY EXISTS' ) <> '' then
    do
      thisRC = 2
      god.__searchString = 'OBJECTID=' || god.__objectID

                        /* open the RC file in READ ONLY mode         */
      call stream god.__ThisRCFile, 'c', 'OPEN READ'

                    /* search the object definition in the rc file    */
      do god.__curRCLineNo = 1 while lines( god.__thisRCFile ) <> 0

        god.__curRCFileLIne = strip( lineIn( god.__thisRCFile ) )

                    /* discard comments                               */
        do until god.__curComment = ''
          parse var god.__curRCFileLine  ,
                    god.__part1          ,
                    (god.__CommentBegin) ,
                    god.__curComment     ,
                    (god.__CommentEnd)   ,
                    god.__part2

          god.__curRCFileLine = god.__part1 || god.__part2
        end /* do until commentFound = '' */

                        /* ignore empty lines                         */
        if god.__curRCFileLine = '' then
          iterate


        if translate( word( god.__curRCFileLIne, 1 ) ) = '"PM_INSTALLOBJECT"' then
        do
          if pos( god.__searchString, god.__curRCFileLIne) <> 0 then
          do
                        /* object description found                   */
            parse var god.__curRCFileLine  ,
                      '"' . '"'            ,
                      '"' ,
                        god.__title . ';'       ,
                        god.__className ';'     ,
                        god.__location          ,
                      '"'                  ,
                      '"'                  ,
                      god.__setup 'OBJECTID=' . ,
                      '"'

            parse var god.__location god.__location ';' .

                            /* fill the result stem                   */
            interpret god.__resultStem || '.title = '     || ,
                      '"' || strip( god.__title )     || '"'

            interpret god.__resultStem || '.className = ' || ,
                      '"' || strip( god.__className ) || '"'

            interpret god.__resultStem || '.location = '  || ,
                      '"' || strip( god.__location )  || '"'

            interpret god.__resultStem || '.setup = '     || ,
                      '"' || strip( god.__setup )     || '"'

            thisRC = 0
            leave god.__curRCLineNo
          end /* if pos( ... */

        end /* if word(  */
      end /* do god.__CurRCLineNo = 1 while ... */
    end /* if stream( ... */
  end /* if god.__ObjectID <> '' ... */

                        /* close the RC file                          */
  call stream god.__ThisRCFile, 'c', 'CLOSE'

                        /* delete local variables                     */
  drop god.
RETURN thisRC

  

Inf-HTML End Run - Successful