INIREAD

Автор: Dennis Bareis

Дата: 1993

Скачать в ZIP архиве.

This program dumps the value of a specific application & key component from
the specified INI file.  You can also dump INI values by specifying a
ApplicationPart which should be contained in an INI Application name, the
whole INI is then searched (case insensitive) for matching entries.

There is another mode where selected INI entries will be tested, if a
application/key value can be read it is concidered OK.  Invalid entries
are reported.

CORRECT SYNTAX:
        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ![ApplicationPartSubStr]  or
        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName *[ApplicationPartSubStr]  or
        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ApplicationPart KeyPart

Example to dump whole USER INI file (usually C:\OS2\OS2.INI):
        (a) INIREAD.CMD  USER *   (b) INIREAD.CMD C:\OS2\OS2.INI *

/**/

/*--- Initialization --------------------------------------------------------*/
call RxFuncAdd  'SysIni',      'RexxUtil', 'SysIni';
call RxFuncAdd  'SysFileTree', 'RexxUtil', 'SysFileTree';

/*--- Split up the passed argument and display the info ---------------------*/
Args = ARG(1);
Args = strip(Args);            /* Remove leading & trailing whitespace */
PARSE VAR Args IniFile Application Key;

/*--- Make sure an ini file was specified -----------------------------------*/
if  IniFile = "" then
   call SyntaxError 'ERROR: Expected "USER", "SYSTEM", "BOTH", or the name of an .INI file...';
parse UPPER VAR IniFile IniFile;
if IniFile <> "USER" & IniFile <> "SYSTEM" & IniFile <> "BOTH" then
do
   /*--- Make sure the specified INI file exists ---------------------------*/
   TreeRc = SysFileTree(IniFile, 'FileBase', 'FO');
   if   TreeRc <> 0 | FileBase.0 = 0 then
   do
       say 'ERROR: The INI file "' || IniFile || '" does not exist.';
       exit( SourceLine() );
   end;
end;

/*--- Check out the rest! ---------------------------------------------------*/
if Application = "" then
   call SyntaxError 'ERROR: Expected the "APPLICATION" key part, or "*SubStr", or "*" for all.';
if left(Application,1) = "!" then
do
   Application = substr(Application, 2);
   call CheckWholeIni IniFile, Application;
   exit(0);
end;
if left(Application,1) = "*" then
do
   Application = substr(Application, 2);
   call DumpWholeIni IniFile, Application;
   exit(0);
end;
else
do
   if  Key = "" then
       call SyntaxError "ERROR: Expected a key to identify the value to be dumped...";
   call Dump1Key IniFile, Application, Key;
   exit 0;
end;



/****************************************************************************/
Dump1Key:
/****************************************************************************/
   call DumpIniValue ARG(1), ARG(2), ARG(3);
   exit 0;

/****************************************************************************/
DumpWholeIni:
/****************************************************************************/
        /****  Type all OS2.INI file information to the screen  *****/
        UpperDumpSpec = ARG(2);
        parse UPPER VAR UpperDumpSpec UpperDumpSpec;
        call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
        call sysloadfuncs

        call SysIni ARG(1), 'All:', 'Apps.'
        if Result = 'ERROR:' then
        do
           say 'ERROR: Could not obtain list of APPLICATION keys.'
           RETURN;
        end;
        if Apps.0 = 0 then
        do
           say 'ERROR: INI file "'ARG(1)'" does not exist, or contains no data.'
           RETURN;
        end

        do i = 1 to Apps.0
           /*--- See if we want to limit the dump ---------------------------*/
           if ARG(2) <> "" then
           do
              parse UPPER VAR Apps.i UpperApplication;
              if pos(UpperDumpSpec, UpperApplication) = 0 then iterate;  /* Don't want this one*/
           end;
           call SysIni ARG(1), Apps.i, 'All:', 'Keys'
           if Result = 'ERROR:' then
           do
              say 'Could not obtain List of Keys for APPLICATION = 'Apps.i;
              call AddSeperator ARG(1);
              iterate;
           end;
           if Keys.0 = 0 then
           do
              say 'There are no keys for application "'Apps.i'".';
              iterate;
           end;

           do j=1 to Keys.0
               call AddSeperator ARG(1);
               call DumpIniValue ARG(1), Apps.i, Keys.j;
           end;
        end;
        exit 0;



/****************************************************************************/
CheckWholeIni:
/****************************************************************************/
        say 'Checking INI = 'ARG(1)', please wait...';
        InvalidCount = 0;
        UpperDumpSpec = ARG(2);
        parse UPPER VAR UpperDumpSpec UpperDumpSpec;
        call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
        call sysloadfuncs

        call SysIni ARG(1), 'All:', 'Apps.'
        if Result = 'ERROR:' then
        do
           say 'ERROR: Could not obtain list of APPLICATION keys.'
           exit( SourceLine() );
        end;
        if Apps.0 = 0 then
        do
           say 'ERROR: INI file "'ARG(1)'" does not exist (or may be corrupt).'
           exit( SourceLine() );
        end

        do i = 1 to Apps.0
           /*--- See if we want to limit the dump ---------------------------*/
           if ARG(2) <> "" then
           do
              parse UPPER VAR Apps.i UpperApplication;
              if pos(UpperDumpSpec, UpperApplication) = 0 then iterate;  /* Don't want this one*/
           end;
           call SysIni ARG(1), Apps.i, 'All:', 'Keys'
           if Result = 'ERROR:' then
           do
              say 'Could not obtain List of Keys for APPLICATION = 'Apps.i;
              call AddSeperator ARG(1);
              InvalidCount = InvalidCount + 1;
              iterate;
           end;

           do j=1 to Keys.0
               Value = SysIni( ARG(1), Apps.i, Keys.j);
               if Value = "ERROR:" then
               do
                  InvalidCount = InvalidCount + 1;
                  say 'INVALID COMBINATION'
                  say '~~~~~~~~~~~~~~~~~~~'
                  say 'INI FILE   : "'ARG(1)'"';
                  say 'APPLICATION: "'Apps.i'"';
                  say 'KEY        : "'Keys.j'"';
                  call AddSeperator ARG(1);
               end;

           end
        end

        if  InvalidCount <> 0 then
        do
            say InvalidCount" ERRORS WERE FOUND IN THE INI FILE!";
            exit( SourceLine() );
        end;
        else
        do
            say "No errors were found";
            exit 0;
        end;




/****************************************************************************/
DumpIniValue:
/****************************************************************************/
        say 'APPLICATION: "'ARG(2)'"';
        say 'KEY        : "'ARG(3)'"';

        /*--- Get the value of the data from the INI file -------------------*/
        Value = SysIni( ARG(1), ARG(2), ARG(3));
        if Value = "ERROR:" then
        do
           say '<>';
           RETURN;
        end;

        /*--- Work out if the value is HEX or a string ----------------------*/
        StrLength   = length(Value);
        HasHex      = 'N';
        AsciiString = 'N';
        Position  = 1;
        do while Position <= StrLength
           Character    = substr(Value, Position, 1);
           CharValue    = C2D(Character);
           if  CharValue < 32 | CharValue > 127 then
           do
               /*--- See if a null terminated string ------------------------*/
               if Position = StrLength & HasHex = 'N' then
               do
                  if CharValue = 0 then
                  do
                     AsciiString = 'Y';
                     Value = left(Value, StrLength - 1);
                     leave;      /* Ignore the terminating null */
                  end;
               end;
               HasHex    = 'Y';
           end;
           Position = Position + 1;
        end;

        /*--- Show the value if its ASCII -----------------------------------*/
        if  HasHex = 'N' then
        do
            if  StrLength = 0 then
                say "VALUE      : <>";
            else
            do
                if   AsciiString = 'Y' then
                     say 'STRING     : "'Value'"';
                else
                     say 'VALUE      : "'Value'"';
            end;
            RETURN;
        end

        /*--- The value is Hexadecimal so display the header ----------------*/
        say "VALUE:";
        say "~~~~~~";

        /*--- The value is Hexadecimal so display the information -----------*/
        AsciiStr     = "";
        HexStr       = "";
        WantSpace    = 'Y';      /* Want a space before adding Hex value     */
        Position     = 1;
        PositionRel0 = 0;
        do while Position <= StrLength
           /*--- Handle End of old line & start of new ----------------------*/
           if PositionRel0 // 16 = 0 then
           do
              /*--- See if we need to dump previous line --------------------*/
              if  AsciiStr \== "" then
              do
                  say left(HexStr, 41) || '  | ' || AsciiStr || ' |' ;
                  AsciiStr  = "";
                  HexStr    = "";
                  WantSpace = 'Y';
              end;

              /*--- Dump the address of the information ---------------------*/
              call charout , D2X(PositionRel0, 4)":";
           end;
           Character    = substr(Value, Position, 1);
           CharHexValue = C2X(Character);
           CharValue    = C2D(Character);
           if  CharValue < 32 | CharValue > 127 then Character = '.';
           if  WantSpace = 'Y' then
           do
               HexStr    = HexStr' 'CharHexValue;
               WantSpace = 'N'
           end
           else
           do
               HexStr    = HexStr''CharHexValue;
               WantSpace = 'Y'
           end;

           AsciiStr     = AsciiStr''Character;
           Position     = Position     + 1;
           PosItionRel0 = PosItionRel0 + 1;
        end;

        /*--- See if we need to dump previous line --------------------*/
        if  AsciiStr \== "" then
        do
                say left(HexStr, 41) || '  | ' || left(AsciiStr, 16) || ' |' ;
        end;

        RETURN;

/****************************************************************************/
AddSeperator:
/****************************************************************************/
   Padding = length(ARG(1));
   Padding = (79 - Padding) - 3;
   say "";
   say copies('#', Padding) || ' : ' || ARG(1);
   RETURN;




/****************************************************************************/
SyntaxError:
/****************************************************************************/
   ErrorLine = SIGL;
   say "[]----------------------------------------------------------[]";
   say "| INIREAD.CMD, Version 97.312 (C)opyright Dennis Bareis 1993 |";
   say '|      https://www.ozemail.com.au/~dbareis (db0@anz.com)      |';
   say "[]----------------------------------------------------------[]";
   say "";
   say "This program dumps the value of a specific application & key component from";
   say "the specified INI file.  You can also dump INI values by specifying a";
   say "ApplicationPart which should be contained in an INI Application name, the";
   say "whole INI is then searched (case insensitive) for matching entries.";
   say "";
   say "There is another mode where selected INI entries will be tested, if a";
   say "application/key value can be read it is concidered OK.  Invalid entries";
   say "are reported.";
   say "";
   say "CORRECT SYNTAX:";
   say "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ![ApplicationPartSubStr]  or";
   say "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName *[ApplicationPartSubStr]  or";
   say "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ApplicationPart KeyPart ";
   say "";
   say "Example to dump whole USER INI file (usually C:\OS2\OS2.INI):";
   say "        (a) INIREAD.CMD  USER *   (b) INIREAD.CMD C:\OS2\OS2.INI *";
   say "";
   say ARG(1);
   exit(ErrorLine);


/*===========================================================================*/
SourceLine:
/*===========================================================================*/
   retrun(SIGL);
/**/