home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ead94216.zip / EADUMP.CMD
OS/2 REXX Batch file  |  1994-08-04  |  11KB  |  303 lines

  1. /* Extracts Extended Attributes From a File and Dumps them */
  2. /* $Header:   V:/SUEPVCS/GENERAL/EADUMP.CMV   1.0   04 Aug 1994 13:25:44   Dennis_Bareis  $ */
  3.  
  4. /*--- Validate and process parameters ---------------------------------------*/
  5. Args = ARG(1);
  6. Args = strip(Args);                  /* Remove leading & trailing whitespace */
  7. PARSE VAR Args SourceFile RequestedDumpFile ExtraNotWanted;
  8. if  SourceFile = "" then
  9. do
  10.     call SyntaxError "ERROR: Expected you to supply name of a file whose EAs should be dumped", 255;
  11. end;
  12. if  RequestedDumpFile = "" then
  13. do
  14.     DeleteDumpFile = 'Yes';
  15.     EaDumpFile     = "EADUMP_O.TMP";
  16. end;
  17. else
  18. do
  19.     DeleteDumpFile = 'No';
  20.     EaDumpFile     = RequestedDumpFile;
  21. end;
  22. if  ExtraNotWanted <> "" then
  23. do
  24.     call SyntaxError "ERROR: Expect 1 OR 2 parameters, you supplied too many", 254;
  25. end;
  26.  
  27. /*--- Get the Extended Attributes into a temporary file ---------------------*/
  28. FirstByte = substr(SourceFile, 1, 1);
  29. if FirstByte = '*' then
  30. do
  31.     /*--- We already have an extended attribute file check cmd line! --------*/
  32.     if DeleteDumpFile = 'No' then
  33.     do
  34.        call SyntaxError "ERROR: You supplied name of EA dump file, so can't supply 2nd parm.", 253;
  35.     end;
  36.  
  37.     DeleteDumpFile = 'No'
  38.     EaDumpFile     = substr(SourceFile, 2);
  39. end;
  40. else
  41. do
  42.     /*--- Create the Extended attribute file --------------------------------*/
  43.     Value        = substr(SourceFile, 2);
  44.     EaDumpOutFile  = "EADUMP_R.TMP";
  45.     '@echo off'
  46.     Cmd = 'EAUTIL.EXE 'SourceFile" "EaDumpFile' /P /S /R';
  47.     Cmd ' >'EaDumpOutFile" 2>&1"
  48.     if  RC = 0 then
  49.         'del 'EaDumpOutFile" >nul 2>&1";
  50.     else
  51.     do
  52.         say   "ERROR   : OS/2 EAUTIL command failed, Rc = "RC'';
  53.         say   "COMMAND : "Cmd;
  54.         say   "RETURNED:";
  55.         say   "~~~~~~~~";
  56.         'type 'EaDumpOutFile;
  57.         'del  'EaDumpOutFile" >nul 2>&1";
  58.         exit  Rc;
  59.     end;
  60. end;
  61.  
  62. /*--- Make sure that the file had extended attributes -----------------------*/
  63. if    stream(EaDumpFile, 'c', 'query exists') = "" then
  64. do
  65.       say 'The files does not have any extended attributes';
  66.       Exit 1;
  67. end;
  68.  
  69. /*--- Process the produced file ---------------------------------------------*/
  70. call  ProcessEaFile EaDumpFile;
  71.  
  72. /*--- Close the FBSS return code --------------------------------------------*/
  73. Dummy = stream(EaDumpFile, 'c', 'close');
  74.  
  75.  
  76. /*--- Delete temporary files ------------------------------------------------*/
  77. if DeleteDumpFile = 'Yes' then 'del 'EaDumpFile" >nul 2>&1";
  78.  
  79. exit;
  80.  
  81.  
  82. /****************************************************************************/
  83. ReadBytesFromFile:                    /* P1 = FileName, P2 = Length to read */
  84. /****************************************************************************/
  85.         ReadBytes = charin(ARG(1),, ARG(2));
  86.         RETURN ReadBytes;
  87.  
  88.  
  89. /****************************************************************************/
  90. ReadNextByteReturnValue:
  91. /****************************************************************************/
  92.         OneByte = ReadBytesFromFile(ARG(1), 1);
  93.         RETURN C2D(OneByte);
  94.  
  95.  
  96. /****************************************************************************/
  97. ReadNextWordReturnValue:
  98. /****************************************************************************/
  99.         RNWValue =  ReadNextByteReturnValue(ARG(1));
  100.         RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256) + RNWValue;
  101.         RETURN RNWValue;
  102.  
  103. /****************************************************************************/
  104. ReadNextDoubleWordReturnValue:
  105. /****************************************************************************/
  106.         RNWValue =  ReadNextByteReturnValue(ARG(1));
  107.         RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256)             + RNWValue;
  108.         RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256 * 256 )      + RNWValue;
  109.         RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256 * 256 * 256) + RNWValue;
  110.         RETURN RNWValue;
  111.  
  112.  
  113. /****************************************************************************/
  114. ProcessEaFile:
  115. /****************************************************************************/
  116.         /*--- Open the file and position at the first byte ------------------*/
  117.         charin(ARG(1), 1, 0);
  118.  
  119.         /*--- Get the length of the file ------------------------------------*/
  120.         LengthOfFile = ReadNextDoubleWordReturnValue(ARG(1));
  121.  
  122.         do FOREVER
  123.            Fea         = ReadBytesFromFile(ARG(1), 1);
  124.            KeyLength   = ReadNextByteReturnValue(ARG(1));
  125.            if KeyLength = 0 then leave;
  126.            ValueLength = ReadNextWordReturnValue(ARG(1));
  127.  
  128.            /*--- Get the Name of the key ------------------------------------*/
  129.            Key      = ReadBytesFromFile(ARG(1), KeyLength);
  130.            NullByte = ReadBytesFromFile(ARG(1), 1);
  131.            Value    = ReadBytesFromFile(ARG(1), ValueLength);
  132.            DumpOneKey(Fea, Key, Value);
  133.            say '';
  134.         end;
  135.  
  136.         /*--- Tell user how much space is used by EAs -----------------------*/
  137.         say "Total space used by Extended Attributes is "LengthOfFile' bytes';
  138.  
  139.         RETURN;
  140.  
  141.  
  142. /****************************************************************************/
  143. DumpOneKey:
  144. /****************************************************************************/
  145.  
  146.         /*--- Dump the keyname ----------------------------------------------*/
  147.         say 'KEY    : "'ARG(2)'"'
  148.  
  149.         /*--- Dump the keyname ----------------------------------------------*/
  150.         say 'FEA    : 'C2X(ARG(1));
  151.  
  152.         /*--- Remove the EA type from the information and output info -------*/
  153.         EAT_P1       = substr(ARG(3), 1, 1);
  154.         EAT_P2       = substr(ARG(3), 2, 1);
  155.         Value        = substr(ARG(3), 3);
  156.         FormattedEAT = C2X(EAT_P2)''C2X(EAT_P1);
  157.         EAT_Text     = "";
  158.         EAT_Length   = 'No/Unknown';
  159.         if FormattedEAT = 'FFFE' then
  160.         do
  161.            EAT_Text     = "  (Binary data)"
  162.            EAT_Length   = 'Yes';
  163.         end;
  164.         if FormattedEAT = 'FFFD' then
  165.         do
  166.            EAT_Text     = "  (Ascii text)"
  167.            EAT_Length   = 'Yes';
  168.         end;
  169.         if FormattedEAT = 'FFFC' then
  170.         do
  171.            EAT_Text     = "  (AsciiZ text)"
  172.         end;
  173.         if FormattedEAT = 'FFFB' then
  174.         do
  175.            EAT_Text     = "  (Bitmap data)"
  176.            EAT_Length   = 'Yes';
  177.         end;
  178.         if FormattedEAT = 'FFFA' then
  179.         do
  180.            EAT_Text     = "  (Metafile data)"
  181.            EAT_Length   = 'Yes';
  182.         end;
  183.         if FormattedEAT = 'FFF9' then
  184.         do
  185.            EAT_Text     = "  (Icon data)"
  186.            EAT_Length   = 'Yes';
  187.         end;
  188.         if FormattedEAT = 'FFEF' then
  189.         do
  190.            EAT_Text     = "  (AsciiZ Text)"
  191.         end;
  192.         if FormattedEAT = 'FFEE' then
  193.         do
  194.            EAT_Text     = "  (Ascii name of another EA assoc with file)"
  195.            EAT_Length   = 'Yes';
  196.         end;
  197.         if FormattedEAT = 'FFDF' then
  198.         do
  199.            EAT_Text     = "  (Multi-Valued Multi-Typed data)"
  200.         end;
  201.         if FormattedEAT = 'FFDE' then
  202.         do
  203.            EAT_Text     = "  (Multi-Valued Single-Typed data)"
  204.         end;
  205.         if FormattedEAT = 'FFDD' then
  206.         do
  207.            EAT_Text     = "  (ASN.1 ISO standard field data)"
  208.         end;
  209.         say 'EA TYPE: 'FormattedEAT""EAT_Text;
  210.  
  211.  
  212.         /*--- Display the length if this is part of the data ----------------*/
  213.         if  EAT_Length = 'Yes' then
  214.         do
  215.             EAT_LEN1     = substr(Value, 1, 1);
  216.             EAT_LEN2     = substr(Value, 2, 1);
  217.             Value        = substr(Value, 3);
  218.             FormattedLEN = C2X(EAT_LEN2)''C2X(EAT_LEN1);
  219.             say 'LENGTH : 'FormattedLEN;
  220.         end;
  221.  
  222.         /*--- The value is Hexadecimal so display the information -----------*/
  223.         Leader       = "VALUE  = ";
  224.         StrLength    = length(Value);
  225.         AsciiStr     = "";
  226.         HexStr       = "";
  227.         WantSpace    = 'Y';      /* Want a space before adding Hex value     */
  228.         Position     = 1;
  229.         PositionRel0 = 0;
  230.         do while Position <= StrLength
  231.            /*--- Handle End of old line & start of new ----------------------*/
  232.            if PositionRel0 // 16 = 0 then
  233.            do
  234.               /*--- See if we need to dump previous line --------------------*/
  235.               if  AsciiStr \== "" then
  236.               do
  237.                   say left(HexStr, 41) || '  | ' || AsciiStr || ' |' ;
  238.                   AsciiStr  = "";
  239.                   HexStr    = "";
  240.                   WantSpace = 'Y';
  241.               end;
  242.  
  243.               /*--- Dump the address of the information ---------------------*/
  244.               call charout , Leader""D2X(PositionRel0, 4)":";
  245.               Leader = "         ";
  246.            end;
  247.            Character    = substr(Value, Position, 1);
  248.            CharHexValue = C2X(Character);
  249.            CharValue    = C2D(Character);
  250.            if  CharValue < 32 | CharValue > 127 then Character = '.';
  251.            if  WantSpace = 'Y' then
  252.            do
  253.                HexStr    = HexStr' 'CharHexValue;
  254.                WantSpace = 'N'
  255.            end
  256.            else
  257.            do
  258.                HexStr    = HexStr''CharHexValue;
  259.                WantSpace = 'Y'
  260.            end;
  261.  
  262.            AsciiStr     = AsciiStr''Character;
  263.            Position     = Position     + 1;
  264.            PosItionRel0 = PosItionRel0 + 1;
  265.         end;
  266.  
  267.         /*--- See if we need to dump previous line --------------------------*/
  268.         if  AsciiStr \== "" then
  269.         do
  270.             say left(HexStr, 41) || '  | ' || left(AsciiStr, 16) || ' |' ;
  271.         end;
  272.         RETURN "";
  273.  
  274.  
  275. /****************************************************************************/
  276. SyntaxError:
  277. /****************************************************************************/
  278.         Say ARG(1);
  279.  
  280.         say "";
  281.         say "[]---------------------------------------------------------[]";
  282.         say "| EADUMP.CMD, Version 94.216 (C)opyright Dennis Bareis 1993 |";
  283.         say "[]---------------------------------------------------------[]";
  284.         say "";
  285.         say "This program dumps Extended Attributes into a text format.  If required";
  286.         say "the output can be redirected.";
  287.         say "";
  288.         say "CORRECT SYNTAX:";
  289.         say "        EADUMP[.CMD] [*]SourceFile [EaUtilOutputFile] [>DumpFile]";
  290.         say "";
  291.         say "If the '*' is used, it indicates that the 'SourceFile' is a file previously";
  292.         say "produced by a EAUTIL.EXE command and therefore contains all the attributes,";
  293.         say "otherwise the command 'EAUTIL.EXE SourceFile OutputFile /P /S /R' is executed"
  294.         say "against the 'SourceFile' to obtain the extended attributes.";
  295.         say "";
  296.         say "By specifying the 'EaUtilOutputFile' parameter the binary extended attributes";
  297.         say "generated by 'EAUTIL.EXE' will be placed into the specified file rather than";
  298.         say "a temporary file which gets deleted at the completion of this rexx procedure.";
  299.  
  300.         CmdRc = ARG(2); if CmdRc = "" then CmdRc = 255;
  301.         EXIT CmdRc;
  302.  
  303.