[delphizip] Re: Code Pages

  • From: "R.Peters" <russellpeters@xxxxxxxxxxx>
  • To: <delphizip@xxxxxxxxxxxxx>
  • Date: Thu, 11 Aug 2005 19:59:49 +1000

Part of your problem, with little doubt, is that it is not really
manipulating codepages!
What it is (or is supposed to do) is compensate for early dos zips being
stored OEM but only for certain versions.
We have updated the function a bit, hopefully also fixing the brackets (not
easy for c programmers) but I don't think that the names of the consts are
actually correct (values are) - they represent the versions of the programs
that converted depending upon operating system.
I did find a reasonable description somewhere in the InfoZip source code but
it is obscure (at least in my foggy memory).

function TZMWorker.ConvertOEM(const Source: String;
  Direction: CodePageDirection): String;
const
  FS_FAT: Integer = 0;
  FS_HPFS: Integer = 6;
  FS_NTFS: Integer = 11;
var
  buf: String;
begin
  Result := Source;
  if ((FCodePage = cpAuto) and (FVersionMadeBy1 = FS_FAT) or
    (FVersionMadeBy1 =
    FS_HPFS) or ((FVersionMadeBy1 = FS_NTFS) and
    (FVersionMadeBy0 = 50))) or
    (FCodePage =
    cpOEM) then
  begin
    SetLength(buf, 2 * Length(Source) + 1);
    // allow worst case - all double
    if (Direction = cpdOEM2ISO) then
      OemToChar(Pchar(Source), Pchar(buf))
    else
      CharToOem(Pchar(Source), Pchar(buf));
    Result := Pchar(buf);
  end;
end;

May have to watch this in the future if converting to Unicode which (at
present) may be 4* length.

- Russell Peters
-----Original Message-----
From: delphizip-bounce@xxxxxxxxxxxxx [mailto:delphizip-bounce@xxxxxxxxxxxxx]
On Behalf Of James Turner
Sent: Thursday, August 11, 2005 7:42 PM
To: delphizip@xxxxxxxxxxxxx
Subject: [delphizip] Code Pages

I've been looking at the issue of code pages.

My copy of DelphiZip is pretty ancient , so this may have been addressed but
it appears that the function ConvCodePage is faulty (requiring extra
brackets around the ( ) or ( ) or ( ) I think).
I've always struggled with the whole concept of codepages so I could be
wrong.

The code that I have reads as follows.
function TZipMaster.ConvCodePage( Source: String; Direction:
CodePageDirection ): String;
const
   FS_FAT:  Integer =  0;
   FS_HPFS: Integer =  6;
   FS_NTFS: Integer = 11;
var
   i: Integer;
begin
   SetLength( Result, Length( Source ) );
   if ((FCodePage = cpAuto) and (FVersionMadeBy1 = FS_FAT) or
(FVersionMadeBy1 = FS_HPFS)
        or ((FVersionMadeBy1 = FS_NTFS) and (FVersionMadeBy0 = 50))) or
(FCodePage = cpOEM) then
   begin
      for i := 1 to Length( Source ) do
         if Char( Source[i] ) < Char( $80 ) then
            Result[i] := Source[i]
         else
            if Direction = cpdOEM2ISO then
               OemToCharBuff( @Source[i], @Result[i], 1 )
            else
               CharToOemBuff( @Source[i], @Result[i], 1 )
   end
   else
      Result := Source;
end;

This function also appears to be very inefficient. To perform the conversion
you could use something like this procedure OEMConvert(var s:string); begin
  if s = '' then exit;

  UniqueString(s); OEMToChar(pointer(s),pointer(s)); end; (Obviously, this
only performs the conversion one way.)

Alternatively
function OEMConvert(const s:string):string; begin
  result := s; if result = '' then exit;

  UniqueString(result); OEMToChar(pointer(result),pointer(result));
end;

-- James Turner

-----------
To unsubscribe from this list, send an empty e-mail message to:
  delphizip-request@xxxxxxxxxxxxx
and put the word unsubscribe in the subject.


__________ NOD32 1.1191 (20050810) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com


-----------
To unsubscribe from this list, send an empty e-mail 
message to:
  delphizip-request@xxxxxxxxxxxxx 
and put the word unsubscribe in the subject.

Other related posts: