     /* File: PROPERTIES.QRPGLESRC RPG Properties ala Java                   */
     /* Copyright (C) 2005  Dieter Bender  <db@bender-dv.de>                 */
     /*                                                                      */
     /* This program 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.                                        */
     /*                                                                      */
     /* This program 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.                         */
     /*                                                                      */
     /* You should have received a copy of the GNU General Public License    */
     /* along with this program; if not, write to the Free Software          */
     /* Foundation, Inc., 59 Temple Place,                                   */
     /* Suite 330, Boston, MA  02111-1307   USA                              */
     /* You might find a version at http://www.gnu.org                       */
     /************************************************************************/
     H nomain
     D*B   CRTRPGMOD PROPERTIES
     D*B+       DBGVIEW(*COPY)
     D*B   CRTSRVPGM PROPERTIES
     D*B+       EXPORT(*ALL)
     D*B+       BNDSRVPGM(INSTREAM
     D*B+                 OUTSTREAM
     D*B+                 HASHTABLE)
     D*B+       ACTGRP(*CALLER)
     /*---   Prototypen Exporte   ----------------------------------------*/
      /COPY QRPGLEH,PROPERTIES
     /*---   Prototypen Importe   ----------------------------------------*/
      /COPY QRPGLEH,HASHTABLE
      /COPY QRPGLEH,INSTREAM
      /COPY QRPGLEH,OUTSTREAM
     /*---   lokale Prototypen    ----------------------------------------*/
     d init            pr
     d getLine         pr           256a
     /*---   Konstanten           ----------------------------------------*/
     D TRUE            C                   *ON
     D FALSE           C                   *OFF
     d EQ              C                   '='
     d KNAST           C                   '#'
     /*---   Zustands Variablen   ----------------------------------------*/
     d path            s            128a
     d initFlag        s               n   inz(FALSE)
     /*-------------------------------------------------------------------*/
     P getProperty     b                   export
     D getProperty     pi          1024a   varying
     D Key                           36a   value
     D result          s           1024a   varying
     d resultP         s               *   inz(%addr(result))
      /free
                   if not initFlag;
                      init();
                   endif;
                   if get(key : resultP : 1024);
                      result = %trim(result);
                   else;
                      result = *BLANK;
                   endif;
                   return result;
      /end-free
     P getProperty     E
     /*-------------------------------------------------------------------*/
     P setProperty     b                   export
     D setProperty     pi              n
     D Key                           36a   value
     D value                       1024a   varying
     d                                     value
     d wValue          s           1024a   varying
     d wValueP         s               *   inz(%addr(wValue))
     D result          s               n
      /free
                   wValue = value;
                   if not initFlag;
                      init();
                   endif;
                   result = put(key : wValueP : %len(value) + 2);
                   return result;
      /end-free
     P setProperty     e
     /*-------------------------------------------------------------------*/
     P loadProperties  b                   export
     D loadProperties  pi
     D fileName                     128a   value
     d line            s           1024a
     d posEq           s             10i 0
     d key             s             36a
     d value           s           1024a   varying
     d valueP          s               *   inz(%addr(value))
     d length          s             10i 0
      /free
                   if not initFlag;
                      init();
                   endif;
                   setInStream(fileName);
                   line = readLnStream();
                   dow %len(%trim(line)) > 0;
                      if %subst(%trim(line) : 1 : 1) <> KNAST;
                         posEq = %scan(EQ : %trim(line)) - 1;
                         key = %subst(%trim(line) : 1 : posEq);
                         posEq = posEq + 2;
                         length = %len(%trim(line)) - posEq + 1;
                         value = %subst(%trim(line) : posEq : length);
                         put(key : valueP : length + 2);
                      endif;
                      line = readLnStream();
                   enddo;
                   return;
      /end-free
     P loadProperties  e
     /*-------------------------------------------------------------------*/
     P saveProperties  b                   export
     D saveProperties  pi
     D fileName                     128a   value
     d line            s            256a   INZ('#generated by PROPERTIES')
      /free
                   if not initFlag;
                      init();
                   endif;
                   setOutStream(fileName);
                   dou line = *BLANKS;
                      writeLnStream(line : %len(%trim(line)));
                      line = getLine();
                   enddo;
                   closeStream();
                   return;
      /end-free
     p saveProperties  e
     /*-------------------------------------------------------------------*/
     p removeProperty  b                   export
     D removeProperty  Pi              n
     D Key                           36    VALUE
     d result          s               n
      /free
                   if not initFlag;
                      init();
                   endif;
                   result = remove(key);
                   return result;
      /end-free
     p removeProperty  e
     /*-------------------------------------------------------------------*/
     p getLine         b
     d getLine         pi           256a
     d result          s            256a
      /free
                   result = getKey();
                   if result <> *BLANKS;
                      result = %trim(result)
                             + '='
                             + getProperty(result);
                   endif;
                   return result;
      /end-free
     p getLine         e
     /*-------------------------------------------------------------------*/
     p init            b
     d init            pi
     c                   eval      initFlag = TRUE
     p init            e
