first commit (2009-03-30)
This commit is contained in:
		
							
								
								
									
										5
									
								
								bin/chpwd.ini
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								bin/chpwd.ini
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					[APs]
 | 
				
			||||||
 | 
					count=3
 | 
				
			||||||
 | 
					AP1=192.168.1.80;admin;admin;elW1lvFYCX37p
 | 
				
			||||||
 | 
					AP2=192.168.1.160;admin;admin;1234567891234
 | 
				
			||||||
 | 
					AP3=192.168.1.240;admin;admin;1234567891234
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								bin/wrt54gl_chpwd.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/wrt54gl_chpwd.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/wrt54gl_chpwd.tds
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/wrt54gl_chpwd.tds
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/zlib1.dll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/zlib1.dll
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								obj/THTTPdownloader.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								obj/THTTPdownloader.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								obj/base64.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								obj/base64.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								obj/mainGUI.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								obj/mainGUI.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								obj/tsplash.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								obj/tsplash.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								obj/wrt54gl_chpwd.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								obj/wrt54gl_chpwd.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										180
									
								
								src/THTTPdownloader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								src/THTTPdownloader.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,180 @@
 | 
				
			|||||||
 | 
					#define CHUNK 16384
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "THTTPdownloader.h"
 | 
				
			||||||
 | 
					#include "TZlib\GZipHelper.h"
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
 | 
					#pragma resource "*.dfm"
 | 
				
			||||||
 | 
					THTTPdownloader *HTTPdownloader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					__fastcall THTTPdownloader::THTTPdownloader(TComponent* Owner)
 | 
				
			||||||
 | 
					        : TForm(Owner)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  headers = new TList();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					int __fastcall THTTPdownloader::descargarHTML(char *host, char *request, TStream *out)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    TMemoryStream* in  = new TMemoryStream();
 | 
				
			||||||
 | 
					    char buffer[4096];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int pos,readed;
 | 
				
			||||||
 | 
					    int currSize,lastSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AnsiString line;
 | 
				
			||||||
 | 
					    HTTPheaders_list HeaderStruct;
 | 
				
			||||||
 | 
					    httpResult->Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = 0; i < headers->Count; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					     HeaderStruct = (HTTPheaders_list) headers->Items[i];
 | 
				
			||||||
 | 
					     delete HeaderStruct;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    headers->Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TcpClient1->RemoteHost = AnsiString( host );
 | 
				
			||||||
 | 
					    TcpClient1->RemotePort = 80;
 | 
				
			||||||
 | 
					    TcpClient1->Open();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( TcpClient1->Connected )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					            statusBar->SelAttributes->Color = clGreen;statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("Conectado a: ")+AnsiString(host));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* <20>ver que se envia?
 | 
				
			||||||
 | 
					            if ( Visible && debug->Checked ) ShowMessage("Cierre esta ventana para continuar");
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            TcpClient1->SendBuf(request,StrLen(request));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bool R,W,T;
 | 
				
			||||||
 | 
					            bool atStart = true;
 | 
				
			||||||
 | 
					            bool inHeaders = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            while (TcpClient1->Connected)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              R=TcpClient1->WaitForData(20000);
 | 
				
			||||||
 | 
					              if (!TcpClient1->Connected || !R) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if ( inHeaders )
 | 
				
			||||||
 | 
					                      line = TcpClient1->Receiveln();
 | 
				
			||||||
 | 
					              else {
 | 
				
			||||||
 | 
					                      readed = TcpClient1->ReceiveBuf(buffer,4096);
 | 
				
			||||||
 | 
					                      if(readed<=0) break;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if ( atStart )
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
							atStart = false;  //if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', line, m))  return false;
 | 
				
			||||||
 | 
					                httpResult->SelAttributes->Color = clGreen;
 | 
				
			||||||
 | 
					                httpResult->Paragraph->Numbering = nsBullet;
 | 
				
			||||||
 | 
					                httpResult->Lines->Add(line);
 | 
				
			||||||
 | 
					                if ( line.SubString(1,4)!="HTTP" )  return -1;
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if (inHeaders)
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
						      	if ( line.Trim() == "" )
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                  inHeaders = false;
 | 
				
			||||||
 | 
							  continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pos = line.AnsiPos(":");
 | 
				
			||||||
 | 
							if (pos==0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// Skip to the next header
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                HeaderStruct = new THTTP_headers;
 | 
				
			||||||
 | 
					                HeaderStruct->key = line.SubString(1,pos-1).Trim().LowerCase();
 | 
				
			||||||
 | 
					                HeaderStruct->value = line.SubString(pos+1,line.Length()).Trim();
 | 
				
			||||||
 | 
					                headers->Add(HeaderStruct);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                httpResult->SelAttributes->Color = clRed;
 | 
				
			||||||
 | 
					                httpResult->Paragraph->Numbering = nsBullet;
 | 
				
			||||||
 | 
					                httpResult->Lines->Add(line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              in->Write(buffer,readed);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            TcpClient1->Close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("Leidos: ")+AnsiString(readed)+"/"+AnsiString(in->Size));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bool gziped=false;
 | 
				
			||||||
 | 
					            for ( pos=0;pos<headers->Count; pos++ )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					               HeaderStruct = (HTTPheaders_list)headers->Items[pos];
 | 
				
			||||||
 | 
					               if ( HeaderStruct->key=="content-encoding" )
 | 
				
			||||||
 | 
					               {
 | 
				
			||||||
 | 
					                  gziped= (HeaderStruct->value=="gzip");
 | 
				
			||||||
 | 
					                  break;
 | 
				
			||||||
 | 
					               }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            httpResult->Paragraph->Numbering = nsNone;
 | 
				
			||||||
 | 
					            if ( gziped )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					               in->Position=0;
 | 
				
			||||||
 | 
					               CGZIP2A plain((unsigned char *)in->Memory,(int)in->Size);
 | 
				
			||||||
 | 
					               out->Write(plain.psz,plain.Length);out->Write("",1);
 | 
				
			||||||
 | 
					               httpResult->Lines->Add(plain.psz);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					               in->Write("",1);in->Position = 0;
 | 
				
			||||||
 | 
					               out->Write(in->Memory,in->Size);
 | 
				
			||||||
 | 
					               httpResult->Lines->Add((char *)in->Memory);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( debug->Checked )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                  DateSeparator	= '-';
 | 
				
			||||||
 | 
					                  TimeSeparator	= ';';
 | 
				
			||||||
 | 
					             statusBar->Clear();
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("RX: ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					             statusBar->Lines->Assign(httpResult->Lines);
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("TX: ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					             statusBar->Lines->Add(request);
 | 
				
			||||||
 | 
					//             statusBar->Lines->SaveToFile( ExtractFilePath(Application->ExeName)+"log\\"+DateTimeToStr(Now())+".http.rtf" );
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("EOT ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            delete in;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					     statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("ERROR CONECTANDO a: ")+AnsiString(host));
 | 
				
			||||||
 | 
					     return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall THTTPdownloader::FormDestroy(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  HTTPheaders_list HeaderStruct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Clean up <20> must free memory for the items as well as the list
 | 
				
			||||||
 | 
					  for (int i = 0; i < headers->Count; i++)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    HeaderStruct = (HTTPheaders_list) headers->Items[i];
 | 
				
			||||||
 | 
					    delete HeaderStruct;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete headers;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/THTTPdownloader.ddp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/THTTPdownloader.ddp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										57
									
								
								src/THTTPdownloader.dfm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/THTTPdownloader.dfm
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					object HTTPdownloader: THTTPdownloader
 | 
				
			||||||
 | 
					  Left = 462
 | 
				
			||||||
 | 
					  Top = 523
 | 
				
			||||||
 | 
					  Width = 648
 | 
				
			||||||
 | 
					  Height = 474
 | 
				
			||||||
 | 
					  Caption = 'HTTPdownloader'
 | 
				
			||||||
 | 
					  Color = clBtnFace
 | 
				
			||||||
 | 
					  Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					  Font.Color = clWindowText
 | 
				
			||||||
 | 
					  Font.Height = -11
 | 
				
			||||||
 | 
					  Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					  Font.Style = []
 | 
				
			||||||
 | 
					  OldCreateOrder = False
 | 
				
			||||||
 | 
					  OnDestroy = FormDestroy
 | 
				
			||||||
 | 
					  PixelsPerInch = 96
 | 
				
			||||||
 | 
					  TextHeight = 13
 | 
				
			||||||
 | 
					  object httpResult: TRichEdit
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 0
 | 
				
			||||||
 | 
					    Width = 640
 | 
				
			||||||
 | 
					    Height = 344
 | 
				
			||||||
 | 
					    Align = alClient
 | 
				
			||||||
 | 
					    ScrollBars = ssBoth
 | 
				
			||||||
 | 
					    TabOrder = 0
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  object Panel1: TPanel
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 344
 | 
				
			||||||
 | 
					    Width = 640
 | 
				
			||||||
 | 
					    Height = 99
 | 
				
			||||||
 | 
					    Align = alBottom
 | 
				
			||||||
 | 
					    BevelOuter = bvNone
 | 
				
			||||||
 | 
					    Caption = 'Panel1'
 | 
				
			||||||
 | 
					    TabOrder = 1
 | 
				
			||||||
 | 
					    object statusBar: TRichEdit
 | 
				
			||||||
 | 
					      Left = 0
 | 
				
			||||||
 | 
					      Top = 19
 | 
				
			||||||
 | 
					      Width = 640
 | 
				
			||||||
 | 
					      Height = 80
 | 
				
			||||||
 | 
					      Align = alBottom
 | 
				
			||||||
 | 
					      ScrollBars = ssVertical
 | 
				
			||||||
 | 
					      TabOrder = 0
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    object debug: TCheckBox
 | 
				
			||||||
 | 
					      Left = 0
 | 
				
			||||||
 | 
					      Top = 0
 | 
				
			||||||
 | 
					      Width = 97
 | 
				
			||||||
 | 
					      Height = 17
 | 
				
			||||||
 | 
					      Caption = 'Modo Debug'
 | 
				
			||||||
 | 
					      TabOrder = 1
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  object TcpClient1: TTcpClient
 | 
				
			||||||
 | 
					    Left = 96
 | 
				
			||||||
 | 
					    Top = 64
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										42
									
								
								src/THTTPdownloader.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/THTTPdownloader.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef THTTPdownloaderH
 | 
				
			||||||
 | 
					#define THTTPdownloaderH
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#include <Classes.hpp>
 | 
				
			||||||
 | 
					#include <Controls.hpp>
 | 
				
			||||||
 | 
					#include <StdCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Forms.hpp>
 | 
				
			||||||
 | 
					#include <ComCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Sockets.hpp>
 | 
				
			||||||
 | 
					#include <ExtCtrls.hpp>
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					typedef struct HTTP_headers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  AnsiString key;
 | 
				
			||||||
 | 
					  AnsiString value;
 | 
				
			||||||
 | 
					} THTTP_headers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef THTTP_headers* HTTPheaders_list;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					class THTTPdownloader : public TForm
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					__published:	// IDE-managed Components
 | 
				
			||||||
 | 
					        TTcpClient *TcpClient1;
 | 
				
			||||||
 | 
					        TRichEdit *httpResult;
 | 
				
			||||||
 | 
					        TPanel *Panel1;
 | 
				
			||||||
 | 
					        TRichEdit *statusBar;
 | 
				
			||||||
 | 
					        TCheckBox *debug;
 | 
				
			||||||
 | 
					        void __fastcall FormDestroy(TObject *Sender);
 | 
				
			||||||
 | 
					private:	// User declarations
 | 
				
			||||||
 | 
					public:		// User declarations
 | 
				
			||||||
 | 
					        __fastcall THTTPdownloader(TComponent* Owner);
 | 
				
			||||||
 | 
					        TList *headers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int __fastcall descargarHTML(char *host, char *request, TStream *out);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					extern PACKAGE THTTPdownloader *HTTPdownloader;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										181
									
								
								src/THTTPdownloader.~cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								src/THTTPdownloader.~cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,181 @@
 | 
				
			|||||||
 | 
					#define CHUNK 16384
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "THTTPdownloader.h"
 | 
				
			||||||
 | 
					#include "TZlib\GZipHelper.h"
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
 | 
					#pragma resource "*.dfm"
 | 
				
			||||||
 | 
					THTTPdownloader *HTTPdownloader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					__fastcall THTTPdownloader::THTTPdownloader(TComponent* Owner)
 | 
				
			||||||
 | 
					        : TForm(Owner)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  headers = new TList();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					int __fastcall THTTPdownloader::descargarHTML(char *host, char *request, TStream *out)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    TMemoryStream* in  = new TMemoryStream();
 | 
				
			||||||
 | 
					    char buffer[4096];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int pos,readed;
 | 
				
			||||||
 | 
					    int currSize,lastSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AnsiString line;
 | 
				
			||||||
 | 
					    HTTPheaders_list HeaderStruct;
 | 
				
			||||||
 | 
					    httpResult->Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = 0; i < headers->Count; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					     HeaderStruct = (HTTPheaders_list) headers->Items[i];
 | 
				
			||||||
 | 
					     delete HeaderStruct;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    headers->Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TcpClient1->RemoteHost = AnsiString( host );
 | 
				
			||||||
 | 
					    TcpClient1->RemotePort = 80;
 | 
				
			||||||
 | 
					    TcpClient1->Open();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( TcpClient1->Connected )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					            statusBar->SelAttributes->Color = clGreen;statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("Conectado a: ")+AnsiString(host));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* <20>ver que se envia?
 | 
				
			||||||
 | 
					            if ( Visible && debug->Checked ) ShowMessage("Cierre esta ventana para continuar");
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            TcpClient1->SendBuf(request,StrLen(request));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bool R,W,T;
 | 
				
			||||||
 | 
					            bool atStart = true;
 | 
				
			||||||
 | 
					            bool inHeaders = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            while (TcpClient1->Connected)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              R=TcpClient1->WaitForData(20000);
 | 
				
			||||||
 | 
					              if (!TcpClient1->Connected) break;
 | 
				
			||||||
 | 
					//              if (!TcpClient1->Connected || !R) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if ( inHeaders )
 | 
				
			||||||
 | 
					                      line = TcpClient1->Receiveln();
 | 
				
			||||||
 | 
					              else {
 | 
				
			||||||
 | 
					                      readed = TcpClient1->ReceiveBuf(buffer,4096);
 | 
				
			||||||
 | 
					                      if(readed<=0) break;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if ( atStart )
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
							atStart = false;  //if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', line, m))  return false;
 | 
				
			||||||
 | 
					                httpResult->SelAttributes->Color = clGreen;
 | 
				
			||||||
 | 
					                httpResult->Paragraph->Numbering = nsBullet;
 | 
				
			||||||
 | 
					                httpResult->Lines->Add(line);
 | 
				
			||||||
 | 
					                if ( line.SubString(1,4)!="HTTP" )  return -1;
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              if (inHeaders)
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
						      	if ( line.Trim() == "" )
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                  inHeaders = false;
 | 
				
			||||||
 | 
							  continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pos = line.AnsiPos(":");
 | 
				
			||||||
 | 
							if (pos==0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// Skip to the next header
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                HeaderStruct = new THTTP_headers;
 | 
				
			||||||
 | 
					                HeaderStruct->key = line.SubString(1,pos-1).Trim().LowerCase();
 | 
				
			||||||
 | 
					                HeaderStruct->value = line.SubString(pos+1,line.Length()).Trim();
 | 
				
			||||||
 | 
					                headers->Add(HeaderStruct);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                httpResult->SelAttributes->Color = clRed;
 | 
				
			||||||
 | 
					                httpResult->Paragraph->Numbering = nsBullet;
 | 
				
			||||||
 | 
					                httpResult->Lines->Add(line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							continue;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					              in->Write(buffer,readed);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            TcpClient1->Close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("Leidos: ")+AnsiString(readed)+"/"+AnsiString(in->Size));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bool gziped=false;
 | 
				
			||||||
 | 
					            for ( pos=0;pos<headers->Count; pos++ )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					               HeaderStruct = (HTTPheaders_list)headers->Items[pos];
 | 
				
			||||||
 | 
					               if ( HeaderStruct->key=="content-encoding" )
 | 
				
			||||||
 | 
					               {
 | 
				
			||||||
 | 
					                  gziped= (HeaderStruct->value=="gzip");
 | 
				
			||||||
 | 
					                  break;
 | 
				
			||||||
 | 
					               }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            httpResult->Paragraph->Numbering = nsNone;
 | 
				
			||||||
 | 
					            if ( gziped )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					               in->Position=0;
 | 
				
			||||||
 | 
					               CGZIP2A plain((unsigned char *)in->Memory,(int)in->Size);
 | 
				
			||||||
 | 
					               out->Write(plain.psz,plain.Length);out->Write("",1);
 | 
				
			||||||
 | 
					               httpResult->Lines->Add(plain.psz);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					               in->Write("",1);in->Position = 0;
 | 
				
			||||||
 | 
					               out->Write(in->Memory,in->Size);
 | 
				
			||||||
 | 
					               httpResult->Lines->Add((char *)in->Memory);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ( debug->Checked )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                  DateSeparator	= '-';
 | 
				
			||||||
 | 
					                  TimeSeparator	= ';';
 | 
				
			||||||
 | 
					             statusBar->Clear();
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("RX: ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					             statusBar->Lines->Assign(httpResult->Lines);
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("TX: ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					             statusBar->Lines->Add(request);
 | 
				
			||||||
 | 
					//             statusBar->Lines->SaveToFile( ExtractFilePath(Application->ExeName)+"log\\"+DateTimeToStr(Now())+".http.rtf" );
 | 
				
			||||||
 | 
					             statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add("EOT ------------------------------------------------------------------");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            delete in;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					     statusBar->SelAttributes->Color = clRed;statusBar->Lines->Add(AnsiString(Now())+AnsiString(" > ")+AnsiString("ERROR CONECTANDO a: ")+AnsiString(host));
 | 
				
			||||||
 | 
					     return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall THTTPdownloader::FormDestroy(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  HTTPheaders_list HeaderStruct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Clean up <20> must free memory for the items as well as the list
 | 
				
			||||||
 | 
					  for (int i = 0; i < headers->Count; i++)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    HeaderStruct = (HTTPheaders_list) headers->Items[i];
 | 
				
			||||||
 | 
					    delete HeaderStruct;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete headers;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/THTTPdownloader.~ddp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/THTTPdownloader.~ddp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										57
									
								
								src/THTTPdownloader.~dfm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/THTTPdownloader.~dfm
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					object HTTPdownloader: THTTPdownloader
 | 
				
			||||||
 | 
					  Left = 462
 | 
				
			||||||
 | 
					  Top = 523
 | 
				
			||||||
 | 
					  Width = 648
 | 
				
			||||||
 | 
					  Height = 474
 | 
				
			||||||
 | 
					  Caption = 'HTTPdownloader'
 | 
				
			||||||
 | 
					  Color = clBtnFace
 | 
				
			||||||
 | 
					  Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					  Font.Color = clWindowText
 | 
				
			||||||
 | 
					  Font.Height = -11
 | 
				
			||||||
 | 
					  Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					  Font.Style = []
 | 
				
			||||||
 | 
					  OldCreateOrder = False
 | 
				
			||||||
 | 
					  OnDestroy = FormDestroy
 | 
				
			||||||
 | 
					  PixelsPerInch = 96
 | 
				
			||||||
 | 
					  TextHeight = 13
 | 
				
			||||||
 | 
					  object httpResult: TRichEdit
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 0
 | 
				
			||||||
 | 
					    Width = 640
 | 
				
			||||||
 | 
					    Height = 344
 | 
				
			||||||
 | 
					    Align = alClient
 | 
				
			||||||
 | 
					    ScrollBars = ssBoth
 | 
				
			||||||
 | 
					    TabOrder = 0
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  object Panel1: TPanel
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 344
 | 
				
			||||||
 | 
					    Width = 640
 | 
				
			||||||
 | 
					    Height = 99
 | 
				
			||||||
 | 
					    Align = alBottom
 | 
				
			||||||
 | 
					    BevelOuter = bvNone
 | 
				
			||||||
 | 
					    Caption = 'Panel1'
 | 
				
			||||||
 | 
					    TabOrder = 1
 | 
				
			||||||
 | 
					    object statusBar: TRichEdit
 | 
				
			||||||
 | 
					      Left = 0
 | 
				
			||||||
 | 
					      Top = 19
 | 
				
			||||||
 | 
					      Width = 640
 | 
				
			||||||
 | 
					      Height = 80
 | 
				
			||||||
 | 
					      Align = alBottom
 | 
				
			||||||
 | 
					      ScrollBars = ssVertical
 | 
				
			||||||
 | 
					      TabOrder = 0
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    object debug: TCheckBox
 | 
				
			||||||
 | 
					      Left = 0
 | 
				
			||||||
 | 
					      Top = 0
 | 
				
			||||||
 | 
					      Width = 97
 | 
				
			||||||
 | 
					      Height = 17
 | 
				
			||||||
 | 
					      Caption = 'Modo Debug'
 | 
				
			||||||
 | 
					      TabOrder = 1
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					  object TcpClient1: TTcpClient
 | 
				
			||||||
 | 
					    Left = 96
 | 
				
			||||||
 | 
					    Top = 64
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										42
									
								
								src/THTTPdownloader.~h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/THTTPdownloader.~h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef THTTPdownloaderH
 | 
				
			||||||
 | 
					#define THTTPdownloaderH
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#include <Classes.hpp>
 | 
				
			||||||
 | 
					#include <Controls.hpp>
 | 
				
			||||||
 | 
					#include <StdCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Forms.hpp>
 | 
				
			||||||
 | 
					#include <ComCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Sockets.hpp>
 | 
				
			||||||
 | 
					#include <ExtCtrls.hpp>
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					typedef struct HTTP_headers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  AnsiString key;
 | 
				
			||||||
 | 
					  AnsiString value;
 | 
				
			||||||
 | 
					} THTTP_headers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef THTTP_headers* HTTPheaders_list;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					class THTTPdownloader : public TForm
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					__published:	// IDE-managed Components
 | 
				
			||||||
 | 
					        TTcpClient *TcpClient1;
 | 
				
			||||||
 | 
					        TRichEdit *httpResult;
 | 
				
			||||||
 | 
					        TPanel *Panel1;
 | 
				
			||||||
 | 
					        TRichEdit *statusBar;
 | 
				
			||||||
 | 
					        TCheckBox *debug;
 | 
				
			||||||
 | 
					        void __fastcall FormDestroy(TObject *Sender);
 | 
				
			||||||
 | 
					private:	// User declarations
 | 
				
			||||||
 | 
					public:		// User declarations
 | 
				
			||||||
 | 
					        __fastcall THTTPdownloader(TComponent* Owner);
 | 
				
			||||||
 | 
					        TList *headers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int __fastcall descargarHTML(char *host, char *request, TStream *out);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					extern PACKAGE THTTPdownloader *HTTPdownloader;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										397
									
								
								src/TZlib/DLL_FAQ.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										397
									
								
								src/TZlib/DLL_FAQ.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,397 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					            Frequently Asked Questions about ZLIB1.DLL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This document describes the design, the rationale, and the usage
 | 
				
			||||||
 | 
					of the official DLL build of zlib, named ZLIB1.DLL.  If you have
 | 
				
			||||||
 | 
					general questions about zlib, you should see the file "FAQ" found
 | 
				
			||||||
 | 
					in the zlib distribution, or at the following location:
 | 
				
			||||||
 | 
					  http://www.gzip.org/zlib/zlib_faq.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 1. What is ZLIB1.DLL, and how can I get it?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - ZLIB1.DLL is the official build of zlib as a DLL.
 | 
				
			||||||
 | 
					    (Please remark the character '1' in the name.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Pointers to a precompiled ZLIB1.DLL can be found in the zlib
 | 
				
			||||||
 | 
					    web site at:
 | 
				
			||||||
 | 
					      http://www.zlib.org/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Applications that link to ZLIB1.DLL can rely on the following
 | 
				
			||||||
 | 
					    specification:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * The exported symbols are exclusively defined in the source
 | 
				
			||||||
 | 
					      files "zlib.h" and "zlib.def", found in an official zlib
 | 
				
			||||||
 | 
					      source distribution.
 | 
				
			||||||
 | 
					    * The symbols are exported by name, not by ordinal.
 | 
				
			||||||
 | 
					    * The exported names are undecorated.
 | 
				
			||||||
 | 
					    * The calling convention of functions is "C" (CDECL).
 | 
				
			||||||
 | 
					    * The ZLIB1.DLL binary is linked to MSVCRT.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The archive in which ZLIB1.DLL is bundled contains compiled
 | 
				
			||||||
 | 
					    test programs that must run with a valid build of ZLIB1.DLL.
 | 
				
			||||||
 | 
					    It is recommended to download the prebuilt DLL from the zlib
 | 
				
			||||||
 | 
					    web site, instead of building it yourself, to avoid potential
 | 
				
			||||||
 | 
					    incompatibilities that could be introduced by your compiler
 | 
				
			||||||
 | 
					    and build settings.  If you do build the DLL yourself, please
 | 
				
			||||||
 | 
					    make sure that it complies with all the above requirements,
 | 
				
			||||||
 | 
					    and it runs with the precompiled test programs, bundled with
 | 
				
			||||||
 | 
					    the original ZLIB1.DLL distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If, for any reason, you need to build an incompatible DLL,
 | 
				
			||||||
 | 
					    please use a different file name.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 2. Why did you change the name of the DLL to ZLIB1.DLL?
 | 
				
			||||||
 | 
					    What happened to the old ZLIB.DLL?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required
 | 
				
			||||||
 | 
					    compilation settings that were incompatible to those used by
 | 
				
			||||||
 | 
					    a static build.  The DLL settings were supposed to be enabled
 | 
				
			||||||
 | 
					    by defining the macro ZLIB_DLL, before including "zlib.h".
 | 
				
			||||||
 | 
					    Incorrect handling of this macro was silently accepted at
 | 
				
			||||||
 | 
					    build time, resulting in two major problems:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * ZLIB_DLL was missing from the old makefile.  When building
 | 
				
			||||||
 | 
					      the DLL, not all people added it to the build options.  In
 | 
				
			||||||
 | 
					      consequence, incompatible incarnations of ZLIB.DLL started
 | 
				
			||||||
 | 
					      to circulate around the net.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * When switching from using the static library to using the
 | 
				
			||||||
 | 
					      DLL, applications had to define the ZLIB_DLL macro and
 | 
				
			||||||
 | 
					      to recompile all the sources that contained calls to zlib
 | 
				
			||||||
 | 
					      functions.  Failure to do so resulted in creating binaries
 | 
				
			||||||
 | 
					      that were unable to run with the official ZLIB.DLL build.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The only possible solution that we could foresee was to make
 | 
				
			||||||
 | 
					    a binary-incompatible change in the DLL interface, in order to
 | 
				
			||||||
 | 
					    remove the dependency on the ZLIB_DLL macro, and to release
 | 
				
			||||||
 | 
					    the new DLL under a different name.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    We chose the name ZLIB1.DLL, where '1' indicates the major
 | 
				
			||||||
 | 
					    zlib version number.  We hope that we will not have to break
 | 
				
			||||||
 | 
					    the binary compatibility again, at least not as long as the
 | 
				
			||||||
 | 
					    zlib-1.x series will last.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    There is still a ZLIB_DLL macro, that can trigger a more
 | 
				
			||||||
 | 
					    efficient build and use of the DLL, but compatibility no
 | 
				
			||||||
 | 
					    longer dependents on it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 3. Can I build ZLIB.DLL from the new zlib sources, and replace
 | 
				
			||||||
 | 
					    an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - In principle, you can do it by assigning calling convention
 | 
				
			||||||
 | 
					    keywords to the macros ZEXPORT and ZEXPORTVA.  In practice,
 | 
				
			||||||
 | 
					    it depends on what you mean by "an old ZLIB.DLL", because the
 | 
				
			||||||
 | 
					    old DLL exists in several mutually-incompatible versions.
 | 
				
			||||||
 | 
					    You have to find out first what kind of calling convention is
 | 
				
			||||||
 | 
					    being used in your particular ZLIB.DLL build, and to use the
 | 
				
			||||||
 | 
					    same one in the new build.  If you don't know what this is all
 | 
				
			||||||
 | 
					    about, you might be better off if you would just leave the old
 | 
				
			||||||
 | 
					    DLL intact.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 4. Can I compile my application using the new zlib interface, and
 | 
				
			||||||
 | 
					    link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or
 | 
				
			||||||
 | 
					    earlier?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - The official answer is "no"; the real answer depends again on
 | 
				
			||||||
 | 
					    what kind of ZLIB.DLL you have.  Even if you are lucky, this
 | 
				
			||||||
 | 
					    course of action is unreliable.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If you rebuild your application and you intend to use a newer
 | 
				
			||||||
 | 
					    version of zlib (post- 1.1.4), it is strongly recommended to
 | 
				
			||||||
 | 
					    link it to the new ZLIB1.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 5. Why are the zlib symbols exported by name, and not by ordinal?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Although exporting symbols by ordinal is a little faster, it
 | 
				
			||||||
 | 
					    is risky.  Any single glitch in the maintenance or use of the
 | 
				
			||||||
 | 
					    DEF file that contains the ordinals can result in incompatible
 | 
				
			||||||
 | 
					    builds and frustrating crashes.  Simply put, the benefits of
 | 
				
			||||||
 | 
					    exporting symbols by ordinal do not justify the risks.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Technically, it should be possible to maintain ordinals in
 | 
				
			||||||
 | 
					    the DEF file, and still export the symbols by name.  Ordinals
 | 
				
			||||||
 | 
					    exist in every DLL, and even if the dynamic linking performed
 | 
				
			||||||
 | 
					    at the DLL startup is searching for names, ordinals serve as
 | 
				
			||||||
 | 
					    hints, for a faster name lookup.  However, if the DEF file
 | 
				
			||||||
 | 
					    contains ordinals, the Microsoft linker automatically builds
 | 
				
			||||||
 | 
					    an implib that will cause the executables linked to it to use
 | 
				
			||||||
 | 
					    those ordinals, and not the names.  It is interesting to
 | 
				
			||||||
 | 
					    notice that the GNU linker for Win32 does not suffer from this
 | 
				
			||||||
 | 
					    problem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    It is possible to avoid the DEF file if the exported symbols
 | 
				
			||||||
 | 
					    are accompanied by a "__declspec(dllexport)" attribute in the
 | 
				
			||||||
 | 
					    source files.  You can do this in zlib by predefining the
 | 
				
			||||||
 | 
					    ZLIB_DLL macro.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling
 | 
				
			||||||
 | 
					    convention.  Why not use the STDCALL convention?
 | 
				
			||||||
 | 
					    STDCALL is the standard convention in Win32, and I need it in
 | 
				
			||||||
 | 
					    my Visual Basic project!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (For readability, we use CDECL to refer to the convention
 | 
				
			||||||
 | 
					     triggered by the "__cdecl" keyword, STDCALL to refer to
 | 
				
			||||||
 | 
					     the convention triggered by "__stdcall", and FASTCALL to
 | 
				
			||||||
 | 
					     refer to the convention triggered by "__fastcall".)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Most of the native Windows API functions (without varargs) use
 | 
				
			||||||
 | 
					    indeed the WINAPI convention (which translates to STDCALL in
 | 
				
			||||||
 | 
					    Win32), but the standard C functions use CDECL.  If a user
 | 
				
			||||||
 | 
					    application is intrinsically tied to the Windows API (e.g.
 | 
				
			||||||
 | 
					    it calls native Windows API functions such as CreateFile()),
 | 
				
			||||||
 | 
					    sometimes it makes sense to decorate its own functions with
 | 
				
			||||||
 | 
					    WINAPI.  But if ANSI C or POSIX portability is a goal (e.g.
 | 
				
			||||||
 | 
					    it calls standard C functions such as fopen()), it is not a
 | 
				
			||||||
 | 
					    sound decision to request the inclusion of <windows.h>, or to
 | 
				
			||||||
 | 
					    use non-ANSI constructs, for the sole purpose to make the user
 | 
				
			||||||
 | 
					    functions STDCALL-able.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The functionality offered by zlib is not in the category of
 | 
				
			||||||
 | 
					    "Windows functionality", but is more like "C functionality".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Technically, STDCALL is not bad; in fact, it is slightly
 | 
				
			||||||
 | 
					    faster than CDECL, and it works with variable-argument
 | 
				
			||||||
 | 
					    functions, just like CDECL.  It is unfortunate that, in spite
 | 
				
			||||||
 | 
					    of using STDCALL in the Windows API, it is not the default
 | 
				
			||||||
 | 
					    convention used by the C compilers that run under Windows.
 | 
				
			||||||
 | 
					    The roots of the problem reside deep inside the unsafety of
 | 
				
			||||||
 | 
					    the K&R-style function prototypes, where the argument types
 | 
				
			||||||
 | 
					    are not specified; but that is another story for another day.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The remaining fact is that CDECL is the default convention.
 | 
				
			||||||
 | 
					    Even if an explicit convention is hard-coded into the function
 | 
				
			||||||
 | 
					    prototypes inside C headers, problems may appear.  The
 | 
				
			||||||
 | 
					    necessity to expose the convention in users' callbacks is one
 | 
				
			||||||
 | 
					    of these problems.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The calling convention issues are also important when using
 | 
				
			||||||
 | 
					    zlib in other programming languages.  Some of them, like Ada
 | 
				
			||||||
 | 
					    (GNAT) and Fortran (GNU G77), have C bindings implemented
 | 
				
			||||||
 | 
					    initially on Unix, and relying on the C calling convention.
 | 
				
			||||||
 | 
					    On the other hand, the pre- .NET versions of Microsoft Visual
 | 
				
			||||||
 | 
					    Basic require STDCALL, while Borland Delphi prefers, although
 | 
				
			||||||
 | 
					    it does not require, FASTCALL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    In fairness to all possible uses of zlib outside the C
 | 
				
			||||||
 | 
					    programming language, we choose the default "C" convention.
 | 
				
			||||||
 | 
					    Anyone interested in different bindings or conventions is
 | 
				
			||||||
 | 
					    encouraged to maintain specialized projects.  The "contrib/"
 | 
				
			||||||
 | 
					    directory from the zlib distribution already holds a couple
 | 
				
			||||||
 | 
					    of foreign bindings, such as Ada, C++, and Delphi.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 7. I need a DLL for my Visual Basic project.  What can I do?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Define the ZLIB_WINAPI macro before including "zlib.h", when
 | 
				
			||||||
 | 
					    building both the DLL and the user application (except that
 | 
				
			||||||
 | 
					    you don't need to define anything when using the DLL in Visual
 | 
				
			||||||
 | 
					    Basic).  The ZLIB_WINAPI macro will switch on the WINAPI
 | 
				
			||||||
 | 
					    (STDCALL) convention.  The name of this DLL must be different
 | 
				
			||||||
 | 
					    than the official ZLIB1.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Gilles Vollant has contributed a build named ZLIBWAPI.DLL,
 | 
				
			||||||
 | 
					    with the ZLIB_WINAPI macro turned on, and with the minizip
 | 
				
			||||||
 | 
					    functionality built in.  For more information, please read
 | 
				
			||||||
 | 
					    the notes inside "contrib/vstudio/readme.txt", found in the
 | 
				
			||||||
 | 
					    zlib distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 8. I need to use zlib in my Microsoft .NET project.  What can I
 | 
				
			||||||
 | 
					    do?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Henrik Ravn has contributed a .NET wrapper around zlib.  Look
 | 
				
			||||||
 | 
					    into contrib/dotzlib/, inside the zlib distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 9. If my application uses ZLIB1.DLL, should I link it to
 | 
				
			||||||
 | 
					    MSVCRT.DLL?  Why?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - It is not required, but it is recommended to link your
 | 
				
			||||||
 | 
					    application to MSVCRT.DLL, if it uses ZLIB1.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The executables (.EXE, .DLL, etc.) that are involved in the
 | 
				
			||||||
 | 
					    same process and are using the C run-time library (i.e. they
 | 
				
			||||||
 | 
					    are calling standard C functions), must link to the same
 | 
				
			||||||
 | 
					    library.  There are several libraries in the Win32 system:
 | 
				
			||||||
 | 
					    CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc.
 | 
				
			||||||
 | 
					    Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that
 | 
				
			||||||
 | 
					    depend on it should also be linked to MSVCRT.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					10. Why are you saying that ZLIB1.DLL and my application should
 | 
				
			||||||
 | 
					    be linked to the same C run-time (CRT) library?  I linked my
 | 
				
			||||||
 | 
					    application and my DLLs to different C libraries (e.g. my
 | 
				
			||||||
 | 
					    application to a static library, and my DLLs to MSVCRT.DLL),
 | 
				
			||||||
 | 
					    and everything works fine.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - If a user library invokes only pure Win32 API (accessible via
 | 
				
			||||||
 | 
					    <windows.h> and the related headers), its DLL build will work
 | 
				
			||||||
 | 
					    in any context.  But if this library invokes standard C API,
 | 
				
			||||||
 | 
					    things get more complicated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    There is a single Win32 library in a Win32 system.  Every
 | 
				
			||||||
 | 
					    function in this library resides in a single DLL module, that
 | 
				
			||||||
 | 
					    is safe to call from anywhere.  On the other hand, there are
 | 
				
			||||||
 | 
					    multiple versions of the C library, and each of them has its
 | 
				
			||||||
 | 
					    own separate internal state.  Standalone executables and user
 | 
				
			||||||
 | 
					    DLLs that call standard C functions must link to a C run-time
 | 
				
			||||||
 | 
					    (CRT) library, be it static or shared (DLL).  Intermixing
 | 
				
			||||||
 | 
					    occurs when an executable (not necessarily standalone) and a
 | 
				
			||||||
 | 
					    DLL are linked to different CRTs, and both are running in the
 | 
				
			||||||
 | 
					    same process.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Intermixing multiple CRTs is possible, as long as their
 | 
				
			||||||
 | 
					    internal states are kept intact.  The Microsoft Knowledge Base
 | 
				
			||||||
 | 
					    articles KB94248 "HOWTO: Use the C Run-Time" and KB140584
 | 
				
			||||||
 | 
					    "HOWTO: Link with the Correct C Run-Time (CRT) Library"
 | 
				
			||||||
 | 
					    mention the potential problems raised by intermixing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If intermixing works for you, it's because your application
 | 
				
			||||||
 | 
					    and DLLs are avoiding the corruption of each of the CRTs'
 | 
				
			||||||
 | 
					    internal states, maybe by careful design, or maybe by fortune.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such
 | 
				
			||||||
 | 
					    as those provided by Borland, raises similar problems.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					11. Why are you linking ZLIB1.DLL to MSVCRT.DLL?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - MSVCRT.DLL exists on every Windows 95 with a new service pack
 | 
				
			||||||
 | 
					    installed, or with Microsoft Internet Explorer 4 or later, and
 | 
				
			||||||
 | 
					    on all other Windows 4.x or later (Windows 98, Windows NT 4,
 | 
				
			||||||
 | 
					    or later).  It is freely distributable; if not present in the
 | 
				
			||||||
 | 
					    system, it can be downloaded from Microsoft or from other
 | 
				
			||||||
 | 
					    software provider for free.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The fact that MSVCRT.DLL does not exist on a virgin Windows 95
 | 
				
			||||||
 | 
					    is not so problematic.  Windows 95 is scarcely found nowadays,
 | 
				
			||||||
 | 
					    Microsoft ended its support a long time ago, and many recent
 | 
				
			||||||
 | 
					    applications from various vendors, including Microsoft, do not
 | 
				
			||||||
 | 
					    even run on it.  Furthermore, no serious user should run
 | 
				
			||||||
 | 
					    Windows 95 without a proper update installed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					12. Why are you not linking ZLIB1.DLL to
 | 
				
			||||||
 | 
					    <<my favorite C run-time library>> ?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - We considered and abandoned the following alternatives:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or
 | 
				
			||||||
 | 
					      LIBCMT.LIB) is not a good option.  People are using the DLL
 | 
				
			||||||
 | 
					      mainly to save disk space.  If you are linking your program
 | 
				
			||||||
 | 
					      to a static C library, you may as well consider linking zlib
 | 
				
			||||||
 | 
					      in statically, too.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because
 | 
				
			||||||
 | 
					      CRTDLL.DLL is present on every Win32 installation.
 | 
				
			||||||
 | 
					      Unfortunately, it has a series of problems: it does not
 | 
				
			||||||
 | 
					      work properly with Microsoft's C++ libraries, it does not
 | 
				
			||||||
 | 
					      provide support for 64-bit file offsets, (and so on...),
 | 
				
			||||||
 | 
					      and Microsoft discontinued its support a long time ago.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied
 | 
				
			||||||
 | 
					      with the Microsoft .NET platform, and Visual C++ 7.0/7.1,
 | 
				
			||||||
 | 
					      raises problems related to the status of ZLIB1.DLL as a
 | 
				
			||||||
 | 
					      system component.  According to the Microsoft Knowledge Base
 | 
				
			||||||
 | 
					      article KB326922 "INFO: Redistribution of the Shared C
 | 
				
			||||||
 | 
					      Runtime Component in Visual C++ .NET", MSVCR70.DLL and
 | 
				
			||||||
 | 
					      MSVCR71.DLL are not supposed to function as system DLLs,
 | 
				
			||||||
 | 
					      because they may clash with MSVCRT.DLL.  Instead, the
 | 
				
			||||||
 | 
					      application's installer is supposed to put these DLLs
 | 
				
			||||||
 | 
					      (if needed) in the application's private directory.
 | 
				
			||||||
 | 
					      If ZLIB1.DLL depends on a non-system runtime, it cannot
 | 
				
			||||||
 | 
					      function as a redistributable system component.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    * Linking ZLIB1.DLL to non-Microsoft runtimes, such as
 | 
				
			||||||
 | 
					      Borland's, or Cygwin's, raises problems related to the
 | 
				
			||||||
 | 
					      reliable presence of these runtimes on Win32 systems.
 | 
				
			||||||
 | 
					      It's easier to let the DLL build of zlib up to the people
 | 
				
			||||||
 | 
					      who distribute these runtimes, and who may proceed as
 | 
				
			||||||
 | 
					      explained in the answer to Question 14.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL,
 | 
				
			||||||
 | 
					    how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0
 | 
				
			||||||
 | 
					    (Visual Studio .NET) or newer?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Due to the problems explained in the Microsoft Knowledge Base
 | 
				
			||||||
 | 
					    article KB326922 (see the previous answer), the C runtime that
 | 
				
			||||||
 | 
					    comes with the VC7 environment is no longer considered a
 | 
				
			||||||
 | 
					    system component.  That is, it should not be assumed that this
 | 
				
			||||||
 | 
					    runtime exists, or may be installed in a system directory.
 | 
				
			||||||
 | 
					    Since ZLIB1.DLL is supposed to be a system component, it may
 | 
				
			||||||
 | 
					    not depend on a non-system component.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    In order to link ZLIB1.DLL and your application to MSVCRT.DLL
 | 
				
			||||||
 | 
					    in VC7, you need the library of Visual C++ 6.0 or older.  If
 | 
				
			||||||
 | 
					    you don't have this library at hand, it's probably best not to
 | 
				
			||||||
 | 
					    use ZLIB1.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    We are hoping that, in the future, Microsoft will provide a
 | 
				
			||||||
 | 
					    way to build applications linked to a proper system runtime,
 | 
				
			||||||
 | 
					    from the Visual C++ environment.  Until then, you have a
 | 
				
			||||||
 | 
					    couple of alternatives, such as linking zlib in statically.
 | 
				
			||||||
 | 
					    If your application requires dynamic linking, you may proceed
 | 
				
			||||||
 | 
					    as explained in the answer to Question 14.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					14. I need to link my own DLL build to a CRT different than
 | 
				
			||||||
 | 
					    MSVCRT.DLL.  What can I do?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Feel free to rebuild the DLL from the zlib sources, and link
 | 
				
			||||||
 | 
					    it the way you want.  You should, however, clearly state that
 | 
				
			||||||
 | 
					    your build is unofficial.  You should give it a different file
 | 
				
			||||||
 | 
					    name, and/or install it in a private directory that can be
 | 
				
			||||||
 | 
					    accessed by your application only, and is not visible to the
 | 
				
			||||||
 | 
					    others (e.g. it's not in the SYSTEM or the SYSTEM32 directory,
 | 
				
			||||||
 | 
					    and it's not in the PATH).  Otherwise, your build may clash
 | 
				
			||||||
 | 
					    with applications that link to the official build.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    For example, in Cygwin, zlib is linked to the Cygwin runtime
 | 
				
			||||||
 | 
					    CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					15. May I include additional pieces of code that I find useful,
 | 
				
			||||||
 | 
					    link them in ZLIB1.DLL, and export them?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - No.  A legitimate build of ZLIB1.DLL must not include code
 | 
				
			||||||
 | 
					    that does not originate from the official zlib source code.
 | 
				
			||||||
 | 
					    But you can make your own private DLL build, under a different
 | 
				
			||||||
 | 
					    file name, as suggested in the previous answer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    For example, zlib is a part of the VCL library, distributed
 | 
				
			||||||
 | 
					    with Borland Delphi and C++ Builder.  The DLL build of VCL
 | 
				
			||||||
 | 
					    is a redistributable file, named VCLxx.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					16. May I remove some functionality out of ZLIB1.DLL, by enabling
 | 
				
			||||||
 | 
					    macros like NO_GZCOMPRESS or NO_GZIP at compile time?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - No.  A legitimate build of ZLIB1.DLL must provide the complete
 | 
				
			||||||
 | 
					    zlib functionality, as implemented in the official zlib source
 | 
				
			||||||
 | 
					    code.  But you can make your own private DLL build, under a
 | 
				
			||||||
 | 
					    different file name, as suggested in the previous answer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					17. I made my own ZLIB1.DLL build.  Can I test it for compliance?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - We prefer that you download the official DLL from the zlib
 | 
				
			||||||
 | 
					    web site.  If you need something peculiar from this DLL, you
 | 
				
			||||||
 | 
					    can send your suggestion to the zlib mailing list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    However, in case you do rebuild the DLL yourself, you can run
 | 
				
			||||||
 | 
					    it with the test programs found in the DLL distribution.
 | 
				
			||||||
 | 
					    Running these test programs is not a guarantee of compliance,
 | 
				
			||||||
 | 
					    but a failure can imply a detected problem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This document is written and maintained by
 | 
				
			||||||
 | 
					Cosmin Truta <cosmint@cs.ubbcluj.ro>
 | 
				
			||||||
							
								
								
									
										474
									
								
								src/TZlib/GZipHelper.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										474
									
								
								src/TZlib/GZipHelper.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,474 @@
 | 
				
			|||||||
 | 
					/* version: 1.0, Feb, 2003
 | 
				
			||||||
 | 
					   Author : Gao Dasheng
 | 
				
			||||||
 | 
					   Copyright (C) 1995-2002 Gao Dasheng(dsgao@hotmail.com)
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					  This software is provided 'as-is', without any express or implied
 | 
				
			||||||
 | 
					  warranty.  In no event will the authors be held liable for any damages
 | 
				
			||||||
 | 
					  arising from the use of this software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Permission is granted to anyone to use this software for any purpose,
 | 
				
			||||||
 | 
					  including commercial applications, and to alter it and redistribute it
 | 
				
			||||||
 | 
					  freely, subject to the following restrictions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. The origin of this software must not be misrepresented; you must not
 | 
				
			||||||
 | 
					     claim that you wrote the original software. If you use this software
 | 
				
			||||||
 | 
					     in a product, an acknowledgment in the product documentation would be
 | 
				
			||||||
 | 
					     appreciated but is not required.
 | 
				
			||||||
 | 
					  2. Altered source versions must be plainly marked as such, and must not be
 | 
				
			||||||
 | 
					     misrepresented as being the original software.
 | 
				
			||||||
 | 
					  3. This notice may not be removed or altered from any source distribution.
 | 
				
			||||||
 | 
					//////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					  Introduce:
 | 
				
			||||||
 | 
					     This file includes two classes CA2GZIP and CGZIP2A which do compressing and 
 | 
				
			||||||
 | 
						 uncompressing in memory. and It 's very easy to use for small data compressing.
 | 
				
			||||||
 | 
						 Some compress and uncompress codes came from gzip  unzip function of zlib 1.1.x. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Usage: 
 | 
				
			||||||
 | 
					     these two classes work used with zlib 1.1.x (http://www.gzip.org/zlib/).
 | 
				
			||||||
 | 
						 They were tested in Window OS.
 | 
				
			||||||
 | 
					  Exmaple:
 | 
				
			||||||
 | 
					     #include "GZipHelper.h"
 | 
				
			||||||
 | 
						 void main()
 | 
				
			||||||
 | 
						 {
 | 
				
			||||||
 | 
					        char plainText[]="Plain text here";
 | 
				
			||||||
 | 
							CA2GZIP gzip(plainText,strlen(plainText));  // do compressing here;
 | 
				
			||||||
 | 
							LPGZIP pgzip=gzip.pgzip;  // pgzip is zipped data pointer, you can use it directly
 | 
				
			||||||
 | 
							int len=gzip.Length;      // Length is length of zipped data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							CGZIP2A plain(pgzip,len);  // do decompressing here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							char *pplain=plain.psz;    // psz is plain data pointer
 | 
				
			||||||
 | 
							int  aLen=plain.Length;    // Length is length of unzipped data.
 | 
				
			||||||
 | 
						 }
 | 
				
			||||||
 | 
					//////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __GZipHelper__
 | 
				
			||||||
 | 
					#define __GZipHelper__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zip/zutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EOF      0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ALLOC(size) malloc(size)
 | 
				
			||||||
 | 
					#define TRYFREE(p) {if (p) free(p);}
 | 
				
			||||||
 | 
					#define Z_BUFSIZE 4096
 | 
				
			||||||
 | 
					#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 | 
				
			||||||
 | 
					#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
 | 
				
			||||||
 | 
					#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 | 
				
			||||||
 | 
					#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 | 
				
			||||||
 | 
					#define COMMENT      0x10 /* bit 4 set: file comment present */
 | 
				
			||||||
 | 
					#define RESERVED     0xE0 /* bits 5..7: reserved */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef  unsigned char GZIP;
 | 
				
			||||||
 | 
					typedef  GZIP* LPGZIP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template< int t_nBufferLength = 1024 ,int t_nLevel=Z_DEFAULT_COMPRESSION,int t_nStrategy=Z_DEFAULT_STRATEGY>
 | 
				
			||||||
 | 
					class CA2GZIPT
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					    LPGZIP pgzip;
 | 
				
			||||||
 | 
					    int Length;
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					  CA2GZIPT(char* lpsz,int len=-1):pgzip(0),Length(0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    Init(lpsz,len);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ~CA2GZIPT()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if(pgzip!=m_buffer) TRYFREE(pgzip);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  void Init(char *lpsz,int len=-1)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if(lpsz==0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  pgzip=0; 
 | 
				
			||||||
 | 
						  Length=0;
 | 
				
			||||||
 | 
						  return ;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if(len==-1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					     len=(int)strlen(lpsz);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
						m_CurrentBufferSize=t_nBufferLength;
 | 
				
			||||||
 | 
						pgzip=m_buffer;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
						m_zstream.zalloc = (alloc_func)0;
 | 
				
			||||||
 | 
					    m_zstream.zfree = (free_func)0;
 | 
				
			||||||
 | 
					    m_zstream.opaque = (voidpf)0;
 | 
				
			||||||
 | 
					    m_zstream.next_in = Z_NULL;
 | 
				
			||||||
 | 
					    m_zstream.next_out = Z_NULL;
 | 
				
			||||||
 | 
					    m_zstream.avail_in = 0;
 | 
				
			||||||
 | 
						m_zstream.avail_out = 0;
 | 
				
			||||||
 | 
					    m_z_err = Z_OK;
 | 
				
			||||||
 | 
					    m_crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
					    int err = deflateInit2(&(m_zstream), t_nLevel,Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, t_nStrategy);
 | 
				
			||||||
 | 
						m_outbuf = (Byte*)ALLOC(Z_BUFSIZE);
 | 
				
			||||||
 | 
						m_zstream.next_out = m_outbuf;
 | 
				
			||||||
 | 
						if (err != Z_OK || m_outbuf == Z_NULL)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						   destroy();
 | 
				
			||||||
 | 
						   return ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
						m_zstream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
						GZIP header[10]={0x1f,0x8b,Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE};
 | 
				
			||||||
 | 
					    write(header,10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_zstream.next_in = (Bytef*)lpsz;
 | 
				
			||||||
 | 
					    m_zstream.avail_in = len;
 | 
				
			||||||
 | 
					    while (m_zstream.avail_in != 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					        if (m_zstream.avail_out == 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
					            m_zstream.next_out = m_outbuf;
 | 
				
			||||||
 | 
							 	this->write(m_outbuf,Z_BUFSIZE);
 | 
				
			||||||
 | 
					            m_zstream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        m_z_err = deflate(&m_zstream,Z_NO_FLUSH);
 | 
				
			||||||
 | 
					        if (m_z_err != Z_OK) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
						m_crc = crc32(m_crc, (const Bytef *)lpsz, len);
 | 
				
			||||||
 | 
						if (finish() != Z_OK) { destroy(); return ;}
 | 
				
			||||||
 | 
					    putLong(m_crc);
 | 
				
			||||||
 | 
					    putLong (m_zstream.total_in);  
 | 
				
			||||||
 | 
						destroy();
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 private:
 | 
				
			||||||
 | 
					   GZIP m_buffer[t_nBufferLength];
 | 
				
			||||||
 | 
					   int m_CurrentBufferSize;
 | 
				
			||||||
 | 
					   z_stream m_zstream;
 | 
				
			||||||
 | 
					   int      m_z_err;   /* error code for last stream operation */
 | 
				
			||||||
 | 
					   unsigned char     *m_outbuf; /* output buffer */
 | 
				
			||||||
 | 
					   uLong    m_crc;     /* crc32 of uncompressed data */
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   int write(LPGZIP buf,int count)
 | 
				
			||||||
 | 
					   {
 | 
				
			||||||
 | 
					     if(buf==0) return 0;
 | 
				
			||||||
 | 
						 if(Length+count>m_CurrentBufferSize)
 | 
				
			||||||
 | 
						 {
 | 
				
			||||||
 | 
						   int nTimes=(Length+count)/t_nBufferLength +1;
 | 
				
			||||||
 | 
						   LPGZIP pTemp=pgzip;
 | 
				
			||||||
 | 
						   pgzip=static_cast<LPGZIP>( malloc(nTimes*t_nBufferLength));
 | 
				
			||||||
 | 
						   m_CurrentBufferSize=nTimes*t_nBufferLength;
 | 
				
			||||||
 | 
						   memcpy(pgzip,pTemp,Length);
 | 
				
			||||||
 | 
						   if(pTemp!=m_buffer) free(pTemp);
 | 
				
			||||||
 | 
						 }
 | 
				
			||||||
 | 
						 memcpy(pgzip+Length,buf,count);
 | 
				
			||||||
 | 
						 Length+=count;
 | 
				
			||||||
 | 
						 return count;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int finish()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					    int done = 0;
 | 
				
			||||||
 | 
					    m_zstream.avail_in = 0; 
 | 
				
			||||||
 | 
					    for (;;)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					        len = Z_BUFSIZE - m_zstream.avail_out;
 | 
				
			||||||
 | 
					        if (len != 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								write(m_outbuf,len);
 | 
				
			||||||
 | 
					            m_zstream.next_out = m_outbuf;
 | 
				
			||||||
 | 
					            m_zstream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (done) break;
 | 
				
			||||||
 | 
					        m_z_err = deflate(&(m_zstream), Z_FINISH);
 | 
				
			||||||
 | 
							if (len == 0 && m_z_err == Z_BUF_ERROR) m_z_err = Z_OK;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
							done = (m_zstream.avail_out != 0 || m_z_err == Z_STREAM_END);
 | 
				
			||||||
 | 
					         if (m_z_err != Z_OK && m_z_err != Z_STREAM_END) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return  m_z_err == Z_STREAM_END ? Z_OK : m_z_err;
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 int destroy()
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					    int err = Z_OK;
 | 
				
			||||||
 | 
						if (m_zstream.state != NULL) {
 | 
				
			||||||
 | 
					    err = deflateEnd(&(m_zstream));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (m_z_err < 0) err = m_z_err;
 | 
				
			||||||
 | 
					    TRYFREE(m_outbuf);
 | 
				
			||||||
 | 
					    return err;
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 void putLong (uLong x)
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					    for(int n = 0; n < 4; n++) {
 | 
				
			||||||
 | 
					        unsigned char c=(unsigned char)(x & 0xff);
 | 
				
			||||||
 | 
							write(&c,1);
 | 
				
			||||||
 | 
					        x >>= 8;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					typedef CA2GZIPT<10> CA2GZIP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template< int t_nBufferLength = 1024>
 | 
				
			||||||
 | 
					class CGZIP2AT
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					   char *psz;
 | 
				
			||||||
 | 
					   int  Length;
 | 
				
			||||||
 | 
					   CGZIP2AT(LPGZIP pgzip,int len):m_gzip(pgzip),m_gziplen(len),psz(0),Length(0),m_pos(0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    Init(); 
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ~CGZIP2AT()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if(psz!=m_buffer) TRYFREE(psz);  
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  void Init()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
						if(m_gzip==0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  psz=0; 
 | 
				
			||||||
 | 
						  Length=0;
 | 
				
			||||||
 | 
						  return ;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						m_CurrentBufferSize=t_nBufferLength;
 | 
				
			||||||
 | 
						psz=m_buffer;
 | 
				
			||||||
 | 
						memset(psz,0,m_CurrentBufferSize+1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m_zstream.zalloc = (alloc_func)0;
 | 
				
			||||||
 | 
					    m_zstream.zfree = (free_func)0;
 | 
				
			||||||
 | 
					    m_zstream.opaque = (voidpf)0;
 | 
				
			||||||
 | 
					    m_zstream.next_in = m_inbuf = Z_NULL;
 | 
				
			||||||
 | 
					    m_zstream.next_out = Z_NULL;
 | 
				
			||||||
 | 
					    m_zstream.avail_in = m_zstream.avail_out = 0;
 | 
				
			||||||
 | 
					    m_z_err = Z_OK;
 | 
				
			||||||
 | 
						m_z_eof = 0;
 | 
				
			||||||
 | 
						m_transparent = 0;
 | 
				
			||||||
 | 
					    m_crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
						m_zstream.next_in  =m_inbuf = (unsigned char *)ALLOC(Z_BUFSIZE);
 | 
				
			||||||
 | 
					    int  err = inflateInit2(&(m_zstream), -MAX_WBITS);
 | 
				
			||||||
 | 
						if (err != Z_OK || m_inbuf == Z_NULL)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  destroy();
 | 
				
			||||||
 | 
						  return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    m_zstream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
						check_header();
 | 
				
			||||||
 | 
						char outbuf[Z_BUFSIZE];
 | 
				
			||||||
 | 
						int nRead;
 | 
				
			||||||
 | 
						while(true)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  nRead=gzread(outbuf,Z_BUFSIZE);
 | 
				
			||||||
 | 
						  if(nRead<=0) break;
 | 
				
			||||||
 | 
						  write(outbuf,nRead);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						destroy();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  private:
 | 
				
			||||||
 | 
					   char m_buffer[t_nBufferLength+1];
 | 
				
			||||||
 | 
					   int m_CurrentBufferSize;
 | 
				
			||||||
 | 
					   z_stream m_zstream;
 | 
				
			||||||
 | 
					   int      m_z_err;   /* error code for last stream operation */
 | 
				
			||||||
 | 
					   unsigned char     *m_inbuf; /* output buffer */
 | 
				
			||||||
 | 
					   uLong    m_crc;     /* crc32 of uncompressed data */
 | 
				
			||||||
 | 
					   int      m_z_eof;
 | 
				
			||||||
 | 
					   int      m_transparent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   int      m_pos;
 | 
				
			||||||
 | 
					   LPGZIP   m_gzip;
 | 
				
			||||||
 | 
					   int      m_gziplen;
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					  void check_header()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    int method; /* method byte */
 | 
				
			||||||
 | 
					    int flags;  /* flags byte */
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					    int c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Check the gzip magic header */
 | 
				
			||||||
 | 
					    for (len = 0; len < 2; len++) {
 | 
				
			||||||
 | 
						c = get_byte();
 | 
				
			||||||
 | 
						if (c != gz_magic[len]) {
 | 
				
			||||||
 | 
						    if (len != 0) m_zstream.avail_in++, m_zstream.next_in--;
 | 
				
			||||||
 | 
						    if (c != EOF) {
 | 
				
			||||||
 | 
							m_zstream.avail_in++, m_zstream.next_in--;
 | 
				
			||||||
 | 
							m_transparent = 1;
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    m_z_err =m_zstream.avail_in != 0 ? Z_OK : Z_STREAM_END;
 | 
				
			||||||
 | 
						    return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    method = get_byte();
 | 
				
			||||||
 | 
					    flags = get_byte();
 | 
				
			||||||
 | 
					    if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
 | 
				
			||||||
 | 
						m_z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* Discard time, xflags and OS code: */
 | 
				
			||||||
 | 
					    for (len = 0; len < 6; len++) (void)get_byte();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
 | 
				
			||||||
 | 
						len  =  (uInt)get_byte();
 | 
				
			||||||
 | 
						len += ((uInt)get_byte())<<8;
 | 
				
			||||||
 | 
						/* len is garbage if EOF but the loop below will quit anyway */
 | 
				
			||||||
 | 
						while (len-- != 0 && get_byte() != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
 | 
				
			||||||
 | 
						while ((c = get_byte()) != 0 && c != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & COMMENT) != 0) {   /* skip the .gz file comment */
 | 
				
			||||||
 | 
						while ((c = get_byte()) != 0 && c != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
 | 
				
			||||||
 | 
						for (len = 0; len < 2; len++) (void)get_byte();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    m_z_err = m_z_eof ? Z_DATA_ERROR : Z_OK;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int get_byte()
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (m_z_eof) return EOF;
 | 
				
			||||||
 | 
					    if (m_zstream.avail_in == 0) 
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						 errno = 0;
 | 
				
			||||||
 | 
						 m_zstream.avail_in =read(m_inbuf,Z_BUFSIZE);
 | 
				
			||||||
 | 
						 if(m_zstream.avail_in == 0)
 | 
				
			||||||
 | 
						 {
 | 
				
			||||||
 | 
						    m_z_eof = 1;
 | 
				
			||||||
 | 
						    return EOF;
 | 
				
			||||||
 | 
						 }
 | 
				
			||||||
 | 
						 m_zstream.next_in = m_inbuf;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    m_zstream.avail_in--;
 | 
				
			||||||
 | 
					    return *(m_zstream.next_in)++;
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 int read(LPGZIP buf,int size)
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					   int nRead=size;
 | 
				
			||||||
 | 
					   if(m_pos+size>=m_gziplen)
 | 
				
			||||||
 | 
					   {
 | 
				
			||||||
 | 
					    nRead=m_gziplen-m_pos;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					   if(nRead<=0) return 0;
 | 
				
			||||||
 | 
					   memcpy(buf,m_gzip+m_pos,nRead);
 | 
				
			||||||
 | 
					   m_pos+=nRead;
 | 
				
			||||||
 | 
					   return nRead;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 int gzread(char* buf,int len)
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					    Bytef *start = (Bytef*)buf; /* starting point for crc computation */
 | 
				
			||||||
 | 
					    unsigned char   *next_out; /* == stream.next_out but not forced far (for MSDOS) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     
 | 
				
			||||||
 | 
						if (m_z_err == Z_DATA_ERROR || m_z_err == Z_ERRNO) return -1;
 | 
				
			||||||
 | 
					    if (m_z_err == Z_STREAM_END) return 0;  /* EOF */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    next_out = (unsigned char *)buf;
 | 
				
			||||||
 | 
					    m_zstream.next_out = (Bytef*)buf;
 | 
				
			||||||
 | 
					    m_zstream.avail_out = len;
 | 
				
			||||||
 | 
					    while (m_zstream.avail_out != 0) {
 | 
				
			||||||
 | 
						if (m_transparent)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						    /* Copy first the lookahead bytes: */
 | 
				
			||||||
 | 
						    uInt n = m_zstream.avail_in;
 | 
				
			||||||
 | 
						    if (n > m_zstream.avail_out) n = m_zstream.avail_out;
 | 
				
			||||||
 | 
						    if (n > 0) 
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
							zmemcpy(m_zstream.next_out,m_zstream.next_in, n);
 | 
				
			||||||
 | 
							next_out += n;
 | 
				
			||||||
 | 
							m_zstream.next_out = next_out;
 | 
				
			||||||
 | 
							m_zstream.next_in   += n;
 | 
				
			||||||
 | 
							m_zstream.avail_out -= n;
 | 
				
			||||||
 | 
							m_zstream.avail_in  -= n;
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    if (m_zstream.avail_out > 0) {
 | 
				
			||||||
 | 
							 m_zstream.avail_out -=read(next_out,m_zstream.avail_out);
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    len -= m_zstream.avail_out;
 | 
				
			||||||
 | 
						    m_zstream.total_in  += (uLong)len;
 | 
				
			||||||
 | 
						    m_zstream.total_out += (uLong)len;
 | 
				
			||||||
 | 
					        if (len == 0) m_z_eof = 1;
 | 
				
			||||||
 | 
						    return (int)len;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    if (m_zstream.avail_in == 0 && !m_z_eof)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					          errno = 0;
 | 
				
			||||||
 | 
					          m_zstream.avail_in = read(m_inbuf,Z_BUFSIZE);
 | 
				
			||||||
 | 
					          if (m_zstream.avail_in == 0)
 | 
				
			||||||
 | 
							  {
 | 
				
			||||||
 | 
					             m_z_eof = 1;
 | 
				
			||||||
 | 
							  }
 | 
				
			||||||
 | 
					          m_zstream.next_in = m_inbuf;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        m_z_err = inflate(&(m_zstream), Z_NO_FLUSH);
 | 
				
			||||||
 | 
						   if (m_z_err == Z_STREAM_END)
 | 
				
			||||||
 | 
						   {
 | 
				
			||||||
 | 
						    /* Check CRC and original size */
 | 
				
			||||||
 | 
						    m_crc = crc32(m_crc, start, (uInt)(m_zstream.next_out - start));
 | 
				
			||||||
 | 
						    start = m_zstream.next_out;
 | 
				
			||||||
 | 
						    if (getLong() != m_crc) {
 | 
				
			||||||
 | 
					  		  m_z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
						    }else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
						       (void)getLong();
 | 
				
			||||||
 | 
					         	check_header();
 | 
				
			||||||
 | 
							   if (m_z_err == Z_OK)
 | 
				
			||||||
 | 
							   {
 | 
				
			||||||
 | 
							    uLong total_in = m_zstream.total_in;
 | 
				
			||||||
 | 
							    uLong total_out = m_zstream.total_out;
 | 
				
			||||||
 | 
							    inflateReset(&(m_zstream));
 | 
				
			||||||
 | 
							    m_zstream.total_in = total_in;
 | 
				
			||||||
 | 
							    m_zstream.total_out = total_out;
 | 
				
			||||||
 | 
							    m_crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (m_z_err != Z_OK || m_z_eof) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    m_crc = crc32(m_crc, start, (uInt)(m_zstream.next_out - start));
 | 
				
			||||||
 | 
					    return (int)(len - m_zstream.avail_out);
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 uLong getLong()
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					    uLong x = (uLong)get_byte();
 | 
				
			||||||
 | 
					    int c;
 | 
				
			||||||
 | 
					    x += ((uLong)get_byte())<<8;
 | 
				
			||||||
 | 
					    x += ((uLong)get_byte())<<16;
 | 
				
			||||||
 | 
					    c = get_byte();
 | 
				
			||||||
 | 
					    if (c == EOF) m_z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    x += ((uLong)c)<<24;
 | 
				
			||||||
 | 
					    return x;
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 int write(char* buf,int count)
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					     if(buf==0) return 0;
 | 
				
			||||||
 | 
						 if(Length+count>m_CurrentBufferSize)
 | 
				
			||||||
 | 
						 {
 | 
				
			||||||
 | 
						   int nTimes=(Length+count)/t_nBufferLength +1;
 | 
				
			||||||
 | 
						   char *pTemp=psz;
 | 
				
			||||||
 | 
						   psz=static_cast<char*>( malloc(nTimes*t_nBufferLength+1));
 | 
				
			||||||
 | 
						   m_CurrentBufferSize=nTimes*t_nBufferLength;
 | 
				
			||||||
 | 
						   memset(psz,0,m_CurrentBufferSize+1);
 | 
				
			||||||
 | 
						   memcpy(psz,pTemp,Length);
 | 
				
			||||||
 | 
						   if(pTemp!=m_buffer) free(pTemp);
 | 
				
			||||||
 | 
						 }
 | 
				
			||||||
 | 
						 memcpy(psz+Length,buf,count);
 | 
				
			||||||
 | 
						 Length+=count;
 | 
				
			||||||
 | 
						 return count;
 | 
				
			||||||
 | 
					 }
 | 
				
			||||||
 | 
					 int destroy()
 | 
				
			||||||
 | 
					 {
 | 
				
			||||||
 | 
					    int err = Z_OK;
 | 
				
			||||||
 | 
						if (m_zstream.state != NULL) {
 | 
				
			||||||
 | 
						    err = inflateEnd(&(m_zstream));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    if (m_z_err < 0) err = m_z_err;
 | 
				
			||||||
 | 
					    TRYFREE(m_inbuf);
 | 
				
			||||||
 | 
					    return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					typedef CGZIP2AT<> CGZIP2A;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										63
									
								
								src/TZlib/Gziphelper.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/TZlib/Gziphelper.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					<!--#include virtual="header.shtml" -->
 | 
				
			||||||
 | 
					<!--#include virtual="/global/getCss.inc" -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<CENTER><H3><FONT COLOR="#AOAO99">
 | 
				
			||||||
 | 
					Two classes for doing Gzip in memory!
 | 
				
			||||||
 | 
					</FONT></H3></CENTER><HR>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- Author and contact details -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This article was contributed by 
 | 
				
			||||||
 | 
					<A HREF="mailto:dsgao@hotmail.com">Gao dasheng</A>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- Sample image - gif or jpg -->
 | 
				
			||||||
 | 
					<P><IMG SRC="[image filename here]" >
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- For which environment is this code specific??? -->
 | 
				
			||||||
 | 
					<p><u>Environment:</u> OS independend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<p>
 | 
				
			||||||
 | 
					<!-- The 'p' starts a paragraph of normal text -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now many applications need API to do gzip in memory. Zlib form http://www.gzip.org/zlib provides gzip and ungzip function,but they is for file,It's very inconvenience to compress and decompress small data compressing in memory. I ported the gzip and ungzip function to two template class CA2GZIP and CGZIP2A to do gzip in memory, and they also allocate and deallocate memory automatically. 
 | 
				
			||||||
 | 
					It works with zlib from http://www.gzip.org/zlib.
 | 
				
			||||||
 | 
					the following is some codes for how to use them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- create more blocks of article text as needed separated -->
 | 
				
			||||||
 | 
					<!-- with the <p> HTML tag -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- start a block of source code -->
 | 
				
			||||||
 | 
					<PRE>
 | 
				
			||||||
 | 
					     #include "GZipHelper.h"
 | 
				
			||||||
 | 
						 void main()
 | 
				
			||||||
 | 
						 {
 | 
				
			||||||
 | 
					        char plainText[]="Plain text here";
 | 
				
			||||||
 | 
							CA2GZIP gzip(plainText,strlen(plainText));  // do compressing here;
 | 
				
			||||||
 | 
							LPGZIP pgzip=gzip.pgzip;  // pgzip is zipped data pointer, you can use it irectly
 | 
				
			||||||
 | 
							int len=gzip.Length;      // Length is length of zipped data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							CGZIP2A plain(pgzip,len);  // do uncompressing here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							char *pplain=plain.psz;    // psz is plain data pointer
 | 
				
			||||||
 | 
							int  aLen=plain.Length;    // Length is length of unzipped data.
 | 
				
			||||||
 | 
						 }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- end the block of source code -->
 | 
				
			||||||
 | 
					</PRE>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h3>Downloads</h3>
 | 
				
			||||||
 | 
					<!-- demo and source files -->
 | 
				
			||||||
 | 
					<A HREF="gzipdemo.zip">
 | 
				
			||||||
 | 
					Download demo project - 142 Kb</A><BR>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<A HREF=  "gzipdemo">
 | 
				
			||||||
 | 
					Download source - 142 Kb</A><BR>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h3>History</h3>
 | 
				
			||||||
 | 
					Date Posted: Jun 20, 2003]<BR>
 | 
				
			||||||
 | 
					<!-- Only use the following if the article is updated -->
 | 
				
			||||||
 | 
					<!-- Date Last Updated: [today's date in the format month day, year] --><BR>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!--#include virtual= "footer.shtml"  -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
							
								
								
									
										53
									
								
								src/TZlib/README.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/TZlib/README.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					What's here
 | 
				
			||||||
 | 
					===========
 | 
				
			||||||
 | 
					  The official ZLIB1.DLL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Source
 | 
				
			||||||
 | 
					======
 | 
				
			||||||
 | 
					  zlib version 1.2.3
 | 
				
			||||||
 | 
					  available at http://www.gzip.org/zlib/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Specification and rationale
 | 
				
			||||||
 | 
					===========================
 | 
				
			||||||
 | 
					  See the accompanying DLL_FAQ.txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Usage
 | 
				
			||||||
 | 
					=====
 | 
				
			||||||
 | 
					  See the accompanying USAGE.txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Build info
 | 
				
			||||||
 | 
					==========
 | 
				
			||||||
 | 
					  Contributed by Gilles Vollant <info@winimage.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Compiler: Microsoft Visual C++ Toolkit 2003
 | 
				
			||||||
 | 
					  Library:  Microsoft Visual C++ 6.0  (to link with MSVCRT.DLL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Copyright notice
 | 
				
			||||||
 | 
					================
 | 
				
			||||||
 | 
					 (C) 1995-2005 Jean-loup Gailly and Mark Adler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  This software is provided 'as-is', without any express or implied
 | 
				
			||||||
 | 
					  warranty.  In no event will the authors be held liable for any damages
 | 
				
			||||||
 | 
					  arising from the use of this software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Permission is granted to anyone to use this software for any purpose,
 | 
				
			||||||
 | 
					  including commercial applications, and to alter it and redistribute it
 | 
				
			||||||
 | 
					  freely, subject to the following restrictions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. The origin of this software must not be misrepresented; you must not
 | 
				
			||||||
 | 
					     claim that you wrote the original software. If you use this software
 | 
				
			||||||
 | 
					     in a product, an acknowledgment in the product documentation would be
 | 
				
			||||||
 | 
					     appreciated but is not required.
 | 
				
			||||||
 | 
					  2. Altered source versions must be plainly marked as such, and must not be
 | 
				
			||||||
 | 
					     misrepresented as being the original software.
 | 
				
			||||||
 | 
					  3. This notice may not be removed or altered from any source distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Jean-loup Gailly        Mark Adler
 | 
				
			||||||
 | 
					  jloup@gzip.org          madler@alumni.caltech.edu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										94
									
								
								src/TZlib/USAGE.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/TZlib/USAGE.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,94 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					Installing ZLIB1.DLL
 | 
				
			||||||
 | 
					====================
 | 
				
			||||||
 | 
					  Copy ZLIB1.DLL to the SYSTEM or the SYSTEM32 directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Using ZLIB1.DLL with Microsoft Visual C++
 | 
				
			||||||
 | 
					=========================================
 | 
				
			||||||
 | 
					   1. Install the supplied header files "zlib.h" and "zconf.h"
 | 
				
			||||||
 | 
					      into a directory found in the INCLUDE path list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   2. Install the supplied library files "zdll.exp" and "zdll.lib"
 | 
				
			||||||
 | 
					      into a directory found in the LIB path list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   3. Add "zdll.exp" or "zdll.lib" to your project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   Notes:
 | 
				
			||||||
 | 
					   - Usually, you don't need both the .exp file and the .lib file.
 | 
				
			||||||
 | 
					   - If you wish, you may rename "zdll.exp" to "zlib1.exp", and/or
 | 
				
			||||||
 | 
					     rename "zdll.lib" to "zlib1.lib".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Using ZLIB1.DLL with Borland C++
 | 
				
			||||||
 | 
					================================
 | 
				
			||||||
 | 
					   1. Install the supplied header files "zlib.h" and "zconf.h"
 | 
				
			||||||
 | 
					      into a directory found in the INCLUDE path list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   2. Build the import library using the IMPLIB tool:
 | 
				
			||||||
 | 
					        implib -a -c -f lib\zdllbor.lib zlib1.dll
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      OR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   2' Convert the supplied library file "zdll.lib" to OMF format,
 | 
				
			||||||
 | 
					      using the COFF2OMF tool:
 | 
				
			||||||
 | 
					        coff2omf lib\zdll.lib lib\zdllbor.lib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   3. Install "zdllbor.lib" into a directory found in the LIB path
 | 
				
			||||||
 | 
					      list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   4. Add "zdllbor.lib" to your project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Notes:
 | 
				
			||||||
 | 
					  - The modules that are linked with "zdllbor.lib" must be compiled
 | 
				
			||||||
 | 
					    using a 4-byte alignment (option -a):
 | 
				
			||||||
 | 
					        bcc32 -a -c myprog.c
 | 
				
			||||||
 | 
					        bcc32 myprog.obj zdllbor.lib
 | 
				
			||||||
 | 
					  - If you wish, you may use "zlib1.lib" instead of "zdllbor.lib".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Using ZLIB1.DLL with gcc/MinGW
 | 
				
			||||||
 | 
					==============================
 | 
				
			||||||
 | 
					   1. Install the supplied header files "zlib.h" and "zconf.h"
 | 
				
			||||||
 | 
					      into the INCLUDE directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   2. Build the import library from the supplied "zlib.def":
 | 
				
			||||||
 | 
					        dlltool -D zlib1.dll -d lib/zlib.def -l lib/libzdll.a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      OR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   2' Copy the supplied library file "zdll.lib" to "libzdll.a":
 | 
				
			||||||
 | 
					        cp lib/zdll.lib lib/libzdll.a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   3. Install "libzdll.a" into the LIB directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   4. Add "libzdll.a" to your project, or use the -lzdll option.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Using ZLIB1.DLL with gcc/Cygwin
 | 
				
			||||||
 | 
					===============================
 | 
				
			||||||
 | 
					  ZLIB1.DLL is not designed to work with Cygwin.  The Cygwin
 | 
				
			||||||
 | 
					  system has its own DLL build of zlib, named CYGZ.DLL.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Rebuilding ZLIB1.DLL
 | 
				
			||||||
 | 
					====================
 | 
				
			||||||
 | 
					  Depending on your build environment, use the appropriate
 | 
				
			||||||
 | 
					  makefile from the win32/ directory, found in the zlib source
 | 
				
			||||||
 | 
					  distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Your custom build has to comply with the requirements stated
 | 
				
			||||||
 | 
					  in DLL_FAQ.txt, including (but not limited to) the following:
 | 
				
			||||||
 | 
					    - It must be built from an unaltered zlib source distribution.
 | 
				
			||||||
 | 
					    - It must be linked to MSVCRT.DLL.
 | 
				
			||||||
 | 
					    - The macros that compile out certain portions of the zlib
 | 
				
			||||||
 | 
					      code (such as NO_GZCOMPRESS, NO_GZIP) must not be enabled.
 | 
				
			||||||
 | 
					    - The ZLIB_WINAPI macro must not be enabled.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Furthermore, it has to run successfully with the test suite
 | 
				
			||||||
 | 
					  found in this package.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  It is recommended, however, to use the supplied ZLIB1.DLL,
 | 
				
			||||||
 | 
					  instead of rebuilding it yourself.  You should rebuild it
 | 
				
			||||||
 | 
					  only if you have a special reason.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										48
									
								
								src/TZlib/Zip/adler32.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/TZlib/Zip/adler32.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					/* adler32.c -- compute the Adler-32 checksum of a data stream
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BASE 65521L /* largest prime smaller than 65536 */
 | 
				
			||||||
 | 
					#define NMAX 5552
 | 
				
			||||||
 | 
					/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
 | 
				
			||||||
 | 
					#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
 | 
				
			||||||
 | 
					#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
 | 
				
			||||||
 | 
					#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
 | 
				
			||||||
 | 
					#define DO16(buf)   DO8(buf,0); DO8(buf,8);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ========================================================================= */
 | 
				
			||||||
 | 
					uLong ZEXPORT adler32(adler, buf, len)
 | 
				
			||||||
 | 
					    uLong adler;
 | 
				
			||||||
 | 
					    const Bytef *buf;
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned long s1 = adler & 0xffff;
 | 
				
			||||||
 | 
					    unsigned long s2 = (adler >> 16) & 0xffff;
 | 
				
			||||||
 | 
					    int k;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (buf == Z_NULL) return 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (len > 0) {
 | 
				
			||||||
 | 
					        k = len < NMAX ? len : NMAX;
 | 
				
			||||||
 | 
					        len -= k;
 | 
				
			||||||
 | 
					        while (k >= 16) {
 | 
				
			||||||
 | 
					            DO16(buf);
 | 
				
			||||||
 | 
						    buf += 16;
 | 
				
			||||||
 | 
					            k -= 16;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (k != 0) do {
 | 
				
			||||||
 | 
					            s1 += *buf++;
 | 
				
			||||||
 | 
						    s2 += s1;
 | 
				
			||||||
 | 
					        } while (--k);
 | 
				
			||||||
 | 
					        s1 %= BASE;
 | 
				
			||||||
 | 
					        s2 %= BASE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return (s2 << 16) | s1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										68
									
								
								src/TZlib/Zip/compress.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/TZlib/Zip/compress.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
				
			|||||||
 | 
					/* compress.c -- compress a memory buffer
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Compresses the source buffer into the destination buffer. The level
 | 
				
			||||||
 | 
					   parameter has the same meaning as in deflateInit.  sourceLen is the byte
 | 
				
			||||||
 | 
					   length of the source buffer. Upon entry, destLen is the total size of the
 | 
				
			||||||
 | 
					   destination buffer, which must be at least 0.1% larger than sourceLen plus
 | 
				
			||||||
 | 
					   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 | 
				
			||||||
 | 
					   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
 | 
				
			||||||
 | 
					   Z_STREAM_ERROR if the level parameter is invalid.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
 | 
				
			||||||
 | 
					    Bytef *dest;
 | 
				
			||||||
 | 
					    uLongf *destLen;
 | 
				
			||||||
 | 
					    const Bytef *source;
 | 
				
			||||||
 | 
					    uLong sourceLen;
 | 
				
			||||||
 | 
					    int level;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    z_stream stream;
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stream.next_in = (Bytef*)source;
 | 
				
			||||||
 | 
					    stream.avail_in = (uInt)sourceLen;
 | 
				
			||||||
 | 
					#ifdef MAXSEG_64K
 | 
				
			||||||
 | 
					    /* Check for source > 64K on 16-bit machine: */
 | 
				
			||||||
 | 
					    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    stream.next_out = dest;
 | 
				
			||||||
 | 
					    stream.avail_out = (uInt)*destLen;
 | 
				
			||||||
 | 
					    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stream.zalloc = (alloc_func)0;
 | 
				
			||||||
 | 
					    stream.zfree = (free_func)0;
 | 
				
			||||||
 | 
					    stream.opaque = (voidpf)0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = deflateInit(&stream, level);
 | 
				
			||||||
 | 
					    if (err != Z_OK) return err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = deflate(&stream, Z_FINISH);
 | 
				
			||||||
 | 
					    if (err != Z_STREAM_END) {
 | 
				
			||||||
 | 
					        deflateEnd(&stream);
 | 
				
			||||||
 | 
					        return err == Z_OK ? Z_BUF_ERROR : err;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    *destLen = stream.total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = deflateEnd(&stream);
 | 
				
			||||||
 | 
					    return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int ZEXPORT compress (dest, destLen, source, sourceLen)
 | 
				
			||||||
 | 
					    Bytef *dest;
 | 
				
			||||||
 | 
					    uLongf *destLen;
 | 
				
			||||||
 | 
					    const Bytef *source;
 | 
				
			||||||
 | 
					    uLong sourceLen;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										162
									
								
								src/TZlib/Zip/crc32.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										162
									
								
								src/TZlib/Zip/crc32.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,162 @@
 | 
				
			|||||||
 | 
					/* crc32.c -- compute the CRC-32 of a data stream
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define local static
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef DYNAMIC_CRC_TABLE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local int crc_table_empty = 1;
 | 
				
			||||||
 | 
					local uLongf crc_table[256];
 | 
				
			||||||
 | 
					local void make_crc_table OF((void));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					  Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
 | 
				
			||||||
 | 
					  x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Polynomials over GF(2) are represented in binary, one bit per coefficient,
 | 
				
			||||||
 | 
					  with the lowest powers in the most significant bit.  Then adding polynomials
 | 
				
			||||||
 | 
					  is just exclusive-or, and multiplying a polynomial by x is a right shift by
 | 
				
			||||||
 | 
					  one.  If we call the above polynomial p, and represent a byte as the
 | 
				
			||||||
 | 
					  polynomial q, also with the lowest power in the most significant bit (so the
 | 
				
			||||||
 | 
					  byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
 | 
				
			||||||
 | 
					  where a mod b means the remainder after dividing a by b.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  This calculation is done using the shift-register method of multiplying and
 | 
				
			||||||
 | 
					  taking the remainder.  The register is initialized to zero, and for each
 | 
				
			||||||
 | 
					  incoming bit, x^32 is added mod p to the register if the bit is a one (where
 | 
				
			||||||
 | 
					  x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
 | 
				
			||||||
 | 
					  x (which is shifting right by one and adding x^32 mod p if the bit shifted
 | 
				
			||||||
 | 
					  out is a one).  We start with the highest power (least significant bit) of
 | 
				
			||||||
 | 
					  q and repeat for all eight bits of q.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The table is simply the CRC of all possible eight bit values.  This is all
 | 
				
			||||||
 | 
					  the information needed to generate CRC's on data a byte at a time for all
 | 
				
			||||||
 | 
					  combinations of CRC register values and incoming bytes.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local void make_crc_table()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uLong c;
 | 
				
			||||||
 | 
					  int n, k;
 | 
				
			||||||
 | 
					  uLong poly;            /* polynomial exclusive-or pattern */
 | 
				
			||||||
 | 
					  /* terms of polynomial defining this crc (except x^32): */
 | 
				
			||||||
 | 
					  static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* make exclusive-or pattern from polynomial (0xedb88320L) */
 | 
				
			||||||
 | 
					  poly = 0L;
 | 
				
			||||||
 | 
					  for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
 | 
				
			||||||
 | 
					    poly |= 1L << (31 - p[n]);
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					  for (n = 0; n < 256; n++)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    c = (uLong)n;
 | 
				
			||||||
 | 
					    for (k = 0; k < 8; k++)
 | 
				
			||||||
 | 
					      c = c & 1 ? poly ^ (c >> 1) : c >> 1;
 | 
				
			||||||
 | 
					    crc_table[n] = c;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  crc_table_empty = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					/* ========================================================================
 | 
				
			||||||
 | 
					 * Table of CRC-32's of all single-byte values (made by make_crc_table)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					local const uLongf crc_table[256] = {
 | 
				
			||||||
 | 
					  0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
 | 
				
			||||||
 | 
					  0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
 | 
				
			||||||
 | 
					  0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
 | 
				
			||||||
 | 
					  0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
 | 
				
			||||||
 | 
					  0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
 | 
				
			||||||
 | 
					  0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
 | 
				
			||||||
 | 
					  0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
 | 
				
			||||||
 | 
					  0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
 | 
				
			||||||
 | 
					  0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
 | 
				
			||||||
 | 
					  0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
 | 
				
			||||||
 | 
					  0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
 | 
				
			||||||
 | 
					  0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
 | 
				
			||||||
 | 
					  0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
 | 
				
			||||||
 | 
					  0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
 | 
				
			||||||
 | 
					  0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
 | 
				
			||||||
 | 
					  0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
 | 
				
			||||||
 | 
					  0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
 | 
				
			||||||
 | 
					  0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
 | 
				
			||||||
 | 
					  0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
 | 
				
			||||||
 | 
					  0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
 | 
				
			||||||
 | 
					  0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
 | 
				
			||||||
 | 
					  0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
 | 
				
			||||||
 | 
					  0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
 | 
				
			||||||
 | 
					  0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
 | 
				
			||||||
 | 
					  0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
 | 
				
			||||||
 | 
					  0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
 | 
				
			||||||
 | 
					  0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
 | 
				
			||||||
 | 
					  0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
 | 
				
			||||||
 | 
					  0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
 | 
				
			||||||
 | 
					  0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
 | 
				
			||||||
 | 
					  0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
 | 
				
			||||||
 | 
					  0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
 | 
				
			||||||
 | 
					  0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
 | 
				
			||||||
 | 
					  0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
 | 
				
			||||||
 | 
					  0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
 | 
				
			||||||
 | 
					  0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
 | 
				
			||||||
 | 
					  0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
 | 
				
			||||||
 | 
					  0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
 | 
				
			||||||
 | 
					  0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
 | 
				
			||||||
 | 
					  0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
 | 
				
			||||||
 | 
					  0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
 | 
				
			||||||
 | 
					  0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
 | 
				
			||||||
 | 
					  0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
 | 
				
			||||||
 | 
					  0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
 | 
				
			||||||
 | 
					  0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
 | 
				
			||||||
 | 
					  0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
 | 
				
			||||||
 | 
					  0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
 | 
				
			||||||
 | 
					  0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
 | 
				
			||||||
 | 
					  0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
 | 
				
			||||||
 | 
					  0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
 | 
				
			||||||
 | 
					  0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
 | 
				
			||||||
 | 
					  0x2d02ef8dL
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* =========================================================================
 | 
				
			||||||
 | 
					 * This function can be used by asm versions of crc32()
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					const uLongf * ZEXPORT get_crc_table()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#ifdef DYNAMIC_CRC_TABLE
 | 
				
			||||||
 | 
					  if (crc_table_empty) make_crc_table();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					  return (const uLongf *)crc_table;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ========================================================================= */
 | 
				
			||||||
 | 
					#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
 | 
				
			||||||
 | 
					#define DO2(buf)  DO1(buf); DO1(buf);
 | 
				
			||||||
 | 
					#define DO4(buf)  DO2(buf); DO2(buf);
 | 
				
			||||||
 | 
					#define DO8(buf)  DO4(buf); DO4(buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ========================================================================= */
 | 
				
			||||||
 | 
					uLong ZEXPORT crc32(crc, buf, len)
 | 
				
			||||||
 | 
					    uLong crc;
 | 
				
			||||||
 | 
					    const Bytef *buf;
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (buf == Z_NULL) return 0L;
 | 
				
			||||||
 | 
					#ifdef DYNAMIC_CRC_TABLE
 | 
				
			||||||
 | 
					    if (crc_table_empty)
 | 
				
			||||||
 | 
					      make_crc_table();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    crc = crc ^ 0xffffffffL;
 | 
				
			||||||
 | 
					    while (len >= 8)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      DO8(buf);
 | 
				
			||||||
 | 
					      len -= 8;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (len) do {
 | 
				
			||||||
 | 
					      DO1(buf);
 | 
				
			||||||
 | 
					    } while (--len);
 | 
				
			||||||
 | 
					    return crc ^ 0xffffffffL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1350
									
								
								src/TZlib/Zip/deflate.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1350
									
								
								src/TZlib/Zip/deflate.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										318
									
								
								src/TZlib/Zip/deflate.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										318
									
								
								src/TZlib/Zip/deflate.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,318 @@
 | 
				
			|||||||
 | 
					/* deflate.h -- internal compression state
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _DEFLATE_H
 | 
				
			||||||
 | 
					#define _DEFLATE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					 * Internal compression state.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LENGTH_CODES 29
 | 
				
			||||||
 | 
					/* number of length codes, not counting the special END_BLOCK code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LITERALS  256
 | 
				
			||||||
 | 
					/* number of literal bytes 0..255 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define L_CODES (LITERALS+1+LENGTH_CODES)
 | 
				
			||||||
 | 
					/* number of Literal or Length codes, including the END_BLOCK code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define D_CODES   30
 | 
				
			||||||
 | 
					/* number of distance codes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define BL_CODES  19
 | 
				
			||||||
 | 
					/* number of codes used to transfer the bit lengths */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define HEAP_SIZE (2*L_CODES+1)
 | 
				
			||||||
 | 
					/* maximum heap size */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_BITS 15
 | 
				
			||||||
 | 
					/* All codes must not exceed MAX_BITS bits */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define INIT_STATE    42
 | 
				
			||||||
 | 
					#define BUSY_STATE   113
 | 
				
			||||||
 | 
					#define FINISH_STATE 666
 | 
				
			||||||
 | 
					/* Stream status */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Data structure describing a single value and its code string. */
 | 
				
			||||||
 | 
					typedef struct ct_data_s {
 | 
				
			||||||
 | 
					    union {
 | 
				
			||||||
 | 
					        ush  freq;       /* frequency count */
 | 
				
			||||||
 | 
					        ush  code;       /* bit string */
 | 
				
			||||||
 | 
					    } fc;
 | 
				
			||||||
 | 
					    union {
 | 
				
			||||||
 | 
					        ush  dad;        /* father node in Huffman tree */
 | 
				
			||||||
 | 
					        ush  len;        /* length of bit string */
 | 
				
			||||||
 | 
					    } dl;
 | 
				
			||||||
 | 
					} FAR ct_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Freq fc.freq
 | 
				
			||||||
 | 
					#define Code fc.code
 | 
				
			||||||
 | 
					#define Dad  dl.dad
 | 
				
			||||||
 | 
					#define Len  dl.len
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct static_tree_desc_s  static_tree_desc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct tree_desc_s {
 | 
				
			||||||
 | 
					    ct_data *dyn_tree;           /* the dynamic tree */
 | 
				
			||||||
 | 
					    int     max_code;            /* largest code with non zero frequency */
 | 
				
			||||||
 | 
					    static_tree_desc *stat_desc; /* the corresponding static tree */
 | 
				
			||||||
 | 
					} FAR tree_desc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef ush Pos;
 | 
				
			||||||
 | 
					typedef Pos FAR Posf;
 | 
				
			||||||
 | 
					typedef unsigned IPos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* A Pos is an index in the character window. We use short instead of int to
 | 
				
			||||||
 | 
					 * save space in the various tables. IPos is used only for parameter passing.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct internal_state {
 | 
				
			||||||
 | 
					    z_streamp strm;      /* pointer back to this zlib stream */
 | 
				
			||||||
 | 
					    int   status;        /* as the name implies */
 | 
				
			||||||
 | 
					    Bytef *pending_buf;  /* output still pending */
 | 
				
			||||||
 | 
					    ulg   pending_buf_size; /* size of pending_buf */
 | 
				
			||||||
 | 
					    Bytef *pending_out;  /* next pending byte to output to the stream */
 | 
				
			||||||
 | 
					    int   pending;       /* nb of bytes in the pending buffer */
 | 
				
			||||||
 | 
					    int   noheader;      /* suppress zlib header and adler32 */
 | 
				
			||||||
 | 
					    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */
 | 
				
			||||||
 | 
					    Byte  method;        /* STORED (for zip only) or DEFLATED */
 | 
				
			||||||
 | 
					    int   last_flush;    /* value of flush param for previous deflate call */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                /* used by deflate.c: */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt  w_size;        /* LZ77 window size (32K by default) */
 | 
				
			||||||
 | 
					    uInt  w_bits;        /* log2(w_size)  (8..16) */
 | 
				
			||||||
 | 
					    uInt  w_mask;        /* w_size - 1 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Bytef *window;
 | 
				
			||||||
 | 
					    /* Sliding window. Input bytes are read into the second half of the window,
 | 
				
			||||||
 | 
					     * and move to the first half later to keep a dictionary of at least wSize
 | 
				
			||||||
 | 
					     * bytes. With this organization, matches are limited to a distance of
 | 
				
			||||||
 | 
					     * wSize-MAX_MATCH bytes, but this ensures that IO is always
 | 
				
			||||||
 | 
					     * performed with a length multiple of the block size. Also, it limits
 | 
				
			||||||
 | 
					     * the window size to 64K, which is quite useful on MSDOS.
 | 
				
			||||||
 | 
					     * To do: use the user input buffer as sliding window.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ulg window_size;
 | 
				
			||||||
 | 
					    /* Actual size of window: 2*wSize, except when the user input buffer
 | 
				
			||||||
 | 
					     * is directly used as sliding window.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Posf *prev;
 | 
				
			||||||
 | 
					    /* Link to older string with same hash index. To limit the size of this
 | 
				
			||||||
 | 
					     * array to 64K, this link is maintained only for the last 32K strings.
 | 
				
			||||||
 | 
					     * An index in this array is thus a window index modulo 32K.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Posf *head; /* Heads of the hash chains or NIL. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt  ins_h;          /* hash index of string to be inserted */
 | 
				
			||||||
 | 
					    uInt  hash_size;      /* number of elements in hash table */
 | 
				
			||||||
 | 
					    uInt  hash_bits;      /* log2(hash_size) */
 | 
				
			||||||
 | 
					    uInt  hash_mask;      /* hash_size-1 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt  hash_shift;
 | 
				
			||||||
 | 
					    /* Number of bits by which ins_h must be shifted at each input
 | 
				
			||||||
 | 
					     * step. It must be such that after MIN_MATCH steps, the oldest
 | 
				
			||||||
 | 
					     * byte no longer takes part in the hash key, that is:
 | 
				
			||||||
 | 
					     *   hash_shift * MIN_MATCH >= hash_bits
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    long block_start;
 | 
				
			||||||
 | 
					    /* Window position at the beginning of the current output block. Gets
 | 
				
			||||||
 | 
					     * negative when the window is moved backwards.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt match_length;           /* length of best match */
 | 
				
			||||||
 | 
					    IPos prev_match;             /* previous match */
 | 
				
			||||||
 | 
					    int match_available;         /* set if previous match exists */
 | 
				
			||||||
 | 
					    uInt strstart;               /* start of string to insert */
 | 
				
			||||||
 | 
					    uInt match_start;            /* start of matching string */
 | 
				
			||||||
 | 
					    uInt lookahead;              /* number of valid bytes ahead in window */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt prev_length;
 | 
				
			||||||
 | 
					    /* Length of the best match at previous step. Matches not greater than this
 | 
				
			||||||
 | 
					     * are discarded. This is used in the lazy match evaluation.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt max_chain_length;
 | 
				
			||||||
 | 
					    /* To speed up deflation, hash chains are never searched beyond this
 | 
				
			||||||
 | 
					     * length.  A higher limit improves compression ratio but degrades the
 | 
				
			||||||
 | 
					     * speed.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt max_lazy_match;
 | 
				
			||||||
 | 
					    /* Attempt to find a better match only when the current match is strictly
 | 
				
			||||||
 | 
					     * smaller than this value. This mechanism is used only for compression
 | 
				
			||||||
 | 
					     * levels >= 4.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					#   define max_insert_length  max_lazy_match
 | 
				
			||||||
 | 
					    /* Insert new strings in the hash table only if the match length is not
 | 
				
			||||||
 | 
					     * greater than this length. This saves time but degrades compression.
 | 
				
			||||||
 | 
					     * max_insert_length is used only for compression levels <= 3.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int level;    /* compression level (1..9) */
 | 
				
			||||||
 | 
					    int strategy; /* favor or force Huffman coding*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt good_match;
 | 
				
			||||||
 | 
					    /* Use a faster search when the previous match is longer than this */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int nice_match; /* Stop searching when current match exceeds this */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                /* used by trees.c: */
 | 
				
			||||||
 | 
					    /* Didn't use ct_data typedef below to supress compiler warning */
 | 
				
			||||||
 | 
					    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
 | 
				
			||||||
 | 
					    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
 | 
				
			||||||
 | 
					    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct tree_desc_s l_desc;               /* desc. for literal tree */
 | 
				
			||||||
 | 
					    struct tree_desc_s d_desc;               /* desc. for distance tree */
 | 
				
			||||||
 | 
					    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ush bl_count[MAX_BITS+1];
 | 
				
			||||||
 | 
					    /* number of codes at each bit length for an optimal tree */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
 | 
				
			||||||
 | 
					    int heap_len;               /* number of elements in the heap */
 | 
				
			||||||
 | 
					    int heap_max;               /* element of largest frequency */
 | 
				
			||||||
 | 
					    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
 | 
				
			||||||
 | 
					     * The same heap array is used to build all trees.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uch depth[2*L_CODES+1];
 | 
				
			||||||
 | 
					    /* Depth of each subtree used as tie breaker for trees of equal frequency
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uchf *l_buf;          /* buffer for literals or lengths */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt  lit_bufsize;
 | 
				
			||||||
 | 
					    /* Size of match buffer for literals/lengths.  There are 4 reasons for
 | 
				
			||||||
 | 
					     * limiting lit_bufsize to 64K:
 | 
				
			||||||
 | 
					     *   - frequencies can be kept in 16 bit counters
 | 
				
			||||||
 | 
					     *   - if compression is not successful for the first block, all input
 | 
				
			||||||
 | 
					     *     data is still in the window so we can still emit a stored block even
 | 
				
			||||||
 | 
					     *     when input comes from standard input.  (This can also be done for
 | 
				
			||||||
 | 
					     *     all blocks if lit_bufsize is not greater than 32K.)
 | 
				
			||||||
 | 
					     *   - if compression is not successful for a file smaller than 64K, we can
 | 
				
			||||||
 | 
					     *     even emit a stored file instead of a stored block (saving 5 bytes).
 | 
				
			||||||
 | 
					     *     This is applicable only for zip (not gzip or zlib).
 | 
				
			||||||
 | 
					     *   - creating new Huffman trees less frequently may not provide fast
 | 
				
			||||||
 | 
					     *     adaptation to changes in the input data statistics. (Take for
 | 
				
			||||||
 | 
					     *     example a binary file with poorly compressible code followed by
 | 
				
			||||||
 | 
					     *     a highly compressible string table.) Smaller buffer sizes give
 | 
				
			||||||
 | 
					     *     fast adaptation but have of course the overhead of transmitting
 | 
				
			||||||
 | 
					     *     trees more frequently.
 | 
				
			||||||
 | 
					     *   - I can't count above 4
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uInt last_lit;      /* running index in l_buf */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ushf *d_buf;
 | 
				
			||||||
 | 
					    /* Buffer for distances. To simplify the code, d_buf and l_buf have
 | 
				
			||||||
 | 
					     * the same number of elements. To use different lengths, an extra flag
 | 
				
			||||||
 | 
					     * array would be necessary.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ulg opt_len;        /* bit length of current block with optimal trees */
 | 
				
			||||||
 | 
					    ulg static_len;     /* bit length of current block with static trees */
 | 
				
			||||||
 | 
					    uInt matches;       /* number of string matches in current block */
 | 
				
			||||||
 | 
					    int last_eob_len;   /* bit length of EOB code for last block */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef DEBUG
 | 
				
			||||||
 | 
					    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
 | 
				
			||||||
 | 
					    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ush bi_buf;
 | 
				
			||||||
 | 
					    /* Output buffer. bits are inserted starting at the bottom (least
 | 
				
			||||||
 | 
					     * significant bits).
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    int bi_valid;
 | 
				
			||||||
 | 
					    /* Number of valid bits in bi_buf.  All bits above the last valid bit
 | 
				
			||||||
 | 
					     * are always zero.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} FAR deflate_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Output a byte on the stream.
 | 
				
			||||||
 | 
					 * IN assertion: there is enough room in pending_buf.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
 | 
				
			||||||
 | 
					/* Minimum amount of lookahead, except at the end of the input file.
 | 
				
			||||||
 | 
					 * See deflate.c for comments about the MIN_MATCH+1.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
 | 
				
			||||||
 | 
					/* In order to simplify the code, particularly on 16 bit machines, match
 | 
				
			||||||
 | 
					 * distances are limited to MAX_DIST instead of WSIZE.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* in trees.c */
 | 
				
			||||||
 | 
					void _tr_init         OF((deflate_state *s));
 | 
				
			||||||
 | 
					int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));
 | 
				
			||||||
 | 
					void _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,
 | 
				
			||||||
 | 
								  int eof));
 | 
				
			||||||
 | 
					void _tr_align        OF((deflate_state *s));
 | 
				
			||||||
 | 
					void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
 | 
				
			||||||
 | 
					                          int eof));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define d_code(dist) \
 | 
				
			||||||
 | 
					   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
 | 
				
			||||||
 | 
					/* Mapping from a distance to a distance code. dist is the distance - 1 and
 | 
				
			||||||
 | 
					 * must not have side effects. _dist_code[256] and _dist_code[257] are never
 | 
				
			||||||
 | 
					 * used.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef DEBUG
 | 
				
			||||||
 | 
					/* Inline versions of _tr_tally for speed: */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(GEN_TREES_H) || !defined(STDC)
 | 
				
			||||||
 | 
					  extern uch _length_code[];
 | 
				
			||||||
 | 
					  extern uch _dist_code[];
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  extern const uch _length_code[];
 | 
				
			||||||
 | 
					  extern const uch _dist_code[];
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# define _tr_tally_lit(s, c, flush) \
 | 
				
			||||||
 | 
					  { uch cc = (c); \
 | 
				
			||||||
 | 
					    s->d_buf[s->last_lit] = 0; \
 | 
				
			||||||
 | 
					    s->l_buf[s->last_lit++] = cc; \
 | 
				
			||||||
 | 
					    s->dyn_ltree[cc].Freq++; \
 | 
				
			||||||
 | 
					    flush = (s->last_lit == s->lit_bufsize-1); \
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					# define _tr_tally_dist(s, distance, length, flush) \
 | 
				
			||||||
 | 
					  { uch len = (length); \
 | 
				
			||||||
 | 
					    ush dist = (distance); \
 | 
				
			||||||
 | 
					    s->d_buf[s->last_lit] = dist; \
 | 
				
			||||||
 | 
					    s->l_buf[s->last_lit++] = len; \
 | 
				
			||||||
 | 
					    dist--; \
 | 
				
			||||||
 | 
					    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
 | 
				
			||||||
 | 
					    s->dyn_dtree[d_code(dist)].Freq++; \
 | 
				
			||||||
 | 
					    flush = (s->last_lit == s->lit_bufsize-1); \
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
 | 
				
			||||||
 | 
					# define _tr_tally_dist(s, distance, length, flush) \
 | 
				
			||||||
 | 
					              flush = _tr_tally(s, distance, length) 
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										875
									
								
								src/TZlib/Zip/gzio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										875
									
								
								src/TZlib/Zip/gzio.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,875 @@
 | 
				
			|||||||
 | 
					/* gzio.c -- IO on .gz files
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Compile this file with -DNO_DEFLATE to avoid the compression code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct internal_state {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef Z_BUFSIZE
 | 
				
			||||||
 | 
					#  ifdef MAXSEG_64K
 | 
				
			||||||
 | 
					#    define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define Z_BUFSIZE 16384
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef Z_PRINTF_BUFSIZE
 | 
				
			||||||
 | 
					#  define Z_PRINTF_BUFSIZE 4096
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ALLOC(size) malloc(size)
 | 
				
			||||||
 | 
					#define TRYFREE(p) {if (p) free(p);}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* gzip flag byte */
 | 
				
			||||||
 | 
					#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 | 
				
			||||||
 | 
					#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
 | 
				
			||||||
 | 
					#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 | 
				
			||||||
 | 
					#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 | 
				
			||||||
 | 
					#define COMMENT      0x10 /* bit 4 set: file comment present */
 | 
				
			||||||
 | 
					#define RESERVED     0xE0 /* bits 5..7: reserved */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct gz_stream {
 | 
				
			||||||
 | 
					    z_stream stream;
 | 
				
			||||||
 | 
					    int      z_err;   /* error code for last stream operation */
 | 
				
			||||||
 | 
					    int      z_eof;   /* set if end of input file */
 | 
				
			||||||
 | 
					    FILE     *file;   /* .gz file */
 | 
				
			||||||
 | 
					    Byte     *inbuf;  /* input buffer */
 | 
				
			||||||
 | 
					    Byte     *outbuf; /* output buffer */
 | 
				
			||||||
 | 
					    uLong    crc;     /* crc32 of uncompressed data */
 | 
				
			||||||
 | 
					    char     *msg;    /* error message */
 | 
				
			||||||
 | 
					    char     *path;   /* path name for debugging only */
 | 
				
			||||||
 | 
					    int      transparent; /* 1 if input file is not a .gz file */
 | 
				
			||||||
 | 
					    char     mode;    /* 'w' or 'r' */
 | 
				
			||||||
 | 
					    long     startpos; /* start of compressed data in file (header skipped) */
 | 
				
			||||||
 | 
					} gz_stream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local gzFile gz_open      OF((const char *path, const char *mode, int  fd));
 | 
				
			||||||
 | 
					local int do_flush        OF((gzFile file, int flush));
 | 
				
			||||||
 | 
					local int    get_byte     OF((gz_stream *s));
 | 
				
			||||||
 | 
					local void   check_header OF((gz_stream *s));
 | 
				
			||||||
 | 
					local int    destroy      OF((gz_stream *s));
 | 
				
			||||||
 | 
					local void   putLong      OF((FILE *file, uLong x));
 | 
				
			||||||
 | 
					local uLong  getLong      OF((gz_stream *s));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Opens a gzip (.gz) file for reading or writing. The mode parameter
 | 
				
			||||||
 | 
					   is as in fopen ("rb" or "wb"). The file is given either by file descriptor
 | 
				
			||||||
 | 
					   or path name (if fd == -1).
 | 
				
			||||||
 | 
					     gz_open return NULL if the file could not be opened or if there was
 | 
				
			||||||
 | 
					   insufficient memory to allocate the (de)compression state; errno
 | 
				
			||||||
 | 
					   can be checked to distinguish the two cases (if errno is zero, the
 | 
				
			||||||
 | 
					   zlib error is Z_MEM_ERROR).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local gzFile gz_open (path, mode, fd)
 | 
				
			||||||
 | 
					    const char *path;
 | 
				
			||||||
 | 
					    const char *mode;
 | 
				
			||||||
 | 
					    int  fd;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					    int level = Z_DEFAULT_COMPRESSION; /* compression level */
 | 
				
			||||||
 | 
					    int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
 | 
				
			||||||
 | 
					    char *p = (char*)mode;
 | 
				
			||||||
 | 
					    gz_stream *s;
 | 
				
			||||||
 | 
					    char fmode[80]; /* copy of mode, without the compression level */
 | 
				
			||||||
 | 
					    char *m = fmode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!path || !mode) return Z_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s = (gz_stream *)ALLOC(sizeof(gz_stream));
 | 
				
			||||||
 | 
					    if (!s) return Z_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->stream.zalloc = (alloc_func)0;
 | 
				
			||||||
 | 
					    s->stream.zfree = (free_func)0;
 | 
				
			||||||
 | 
					    s->stream.opaque = (voidpf)0;
 | 
				
			||||||
 | 
					    s->stream.next_in = s->inbuf = Z_NULL;
 | 
				
			||||||
 | 
					    s->stream.next_out = s->outbuf = Z_NULL;
 | 
				
			||||||
 | 
					    s->stream.avail_in = s->stream.avail_out = 0;
 | 
				
			||||||
 | 
					    s->file = NULL;
 | 
				
			||||||
 | 
					    s->z_err = Z_OK;
 | 
				
			||||||
 | 
					    s->z_eof = 0;
 | 
				
			||||||
 | 
					    s->crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
					    s->msg = NULL;
 | 
				
			||||||
 | 
					    s->transparent = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->path = (char*)ALLOC(strlen(path)+1);
 | 
				
			||||||
 | 
					    if (s->path == NULL) {
 | 
				
			||||||
 | 
					        return destroy(s), (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    strcpy(s->path, path); /* do this early for debugging */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->mode = '\0';
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        if (*p == 'r') s->mode = 'r';
 | 
				
			||||||
 | 
					        if (*p == 'w' || *p == 'a') s->mode = 'w';
 | 
				
			||||||
 | 
					        if (*p >= '0' && *p <= '9') {
 | 
				
			||||||
 | 
						    level = *p - '0';
 | 
				
			||||||
 | 
						} else if (*p == 'f') {
 | 
				
			||||||
 | 
						  strategy = Z_FILTERED;
 | 
				
			||||||
 | 
						} else if (*p == 'h') {
 | 
				
			||||||
 | 
						  strategy = Z_HUFFMAN_ONLY;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
						    *m++ = *p; /* copy the mode */
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    } while (*p++ && m != fmode + sizeof(fmode));
 | 
				
			||||||
 | 
					    if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (s->mode == 'w') {
 | 
				
			||||||
 | 
					#ifdef NO_DEFLATE
 | 
				
			||||||
 | 
					        err = Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					        err = deflateInit2(&(s->stream), level,
 | 
				
			||||||
 | 
					                           Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
 | 
				
			||||||
 | 
					        /* windowBits is passed < 0 to suppress zlib header */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					        if (err != Z_OK || s->outbuf == Z_NULL) {
 | 
				
			||||||
 | 
					            return destroy(s), (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        s->stream.next_in  = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        err = inflateInit2(&(s->stream), -MAX_WBITS);
 | 
				
			||||||
 | 
					        /* windowBits is passed < 0 to tell that there is no zlib header.
 | 
				
			||||||
 | 
					         * Note that in this case inflate *requires* an extra "dummy" byte
 | 
				
			||||||
 | 
					         * after the compressed stream in order to complete decompression and
 | 
				
			||||||
 | 
					         * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
 | 
				
			||||||
 | 
					         * present after the compressed stream.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        if (err != Z_OK || s->inbuf == Z_NULL) {
 | 
				
			||||||
 | 
					            return destroy(s), (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s->stream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    errno = 0;
 | 
				
			||||||
 | 
					    s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s->file == NULL) {
 | 
				
			||||||
 | 
					        return destroy(s), (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (s->mode == 'w') {
 | 
				
			||||||
 | 
					        /* Write a very simple .gz header:
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
 | 
				
			||||||
 | 
					             Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
 | 
				
			||||||
 | 
						s->startpos = 10L;
 | 
				
			||||||
 | 
						/* We use 10L instead of ftell(s->file) to because ftell causes an
 | 
				
			||||||
 | 
					         * fflush on some systems. This version of the library doesn't use
 | 
				
			||||||
 | 
					         * startpos anyway in write mode, so this initialization is not
 | 
				
			||||||
 | 
					         * necessary.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
						check_header(s); /* skip the .gz header */
 | 
				
			||||||
 | 
						s->startpos = (ftell(s->file) - s->stream.avail_in);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return (gzFile)s;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Opens a gzip (.gz) file for reading or writing.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					gzFile ZEXPORT gzopen (path, mode)
 | 
				
			||||||
 | 
					    const char *path;
 | 
				
			||||||
 | 
					    const char *mode;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return gz_open (path, mode, -1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Associate a gzFile with the file descriptor fd. fd is not dup'ed here
 | 
				
			||||||
 | 
					   to mimic the behavio(u)r of fdopen.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					gzFile ZEXPORT gzdopen (fd, mode)
 | 
				
			||||||
 | 
					    int fd;
 | 
				
			||||||
 | 
					    const char *mode;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[20];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (fd < 0) return (gzFile)Z_NULL;
 | 
				
			||||||
 | 
					    sprintf(name, "<fd:%d>", fd); /* for debugging */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return gz_open (name, mode, fd);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					 * Update the compression level and strategy
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int ZEXPORT gzsetparams (file, level, strategy)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    int level;
 | 
				
			||||||
 | 
					    int strategy;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Make room to allow flushing */
 | 
				
			||||||
 | 
					    if (s->stream.avail_out == 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s->stream.next_out = s->outbuf;
 | 
				
			||||||
 | 
						if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
 | 
				
			||||||
 | 
						    s->z_err = Z_ERRNO;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						s->stream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return deflateParams (&(s->stream), level, strategy);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
 | 
				
			||||||
 | 
					   for end of file.
 | 
				
			||||||
 | 
					   IN assertion: the stream s has been sucessfully opened for reading.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local int get_byte(s)
 | 
				
			||||||
 | 
					    gz_stream *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (s->z_eof) return EOF;
 | 
				
			||||||
 | 
					    if (s->stream.avail_in == 0) {
 | 
				
			||||||
 | 
						errno = 0;
 | 
				
			||||||
 | 
						s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
 | 
				
			||||||
 | 
						if (s->stream.avail_in == 0) {
 | 
				
			||||||
 | 
						    s->z_eof = 1;
 | 
				
			||||||
 | 
						    if (ferror(s->file)) s->z_err = Z_ERRNO;
 | 
				
			||||||
 | 
						    return EOF;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						s->stream.next_in = s->inbuf;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s->stream.avail_in--;
 | 
				
			||||||
 | 
					    return *(s->stream.next_in)++;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Check the gzip header of a gz_stream opened for reading. Set the stream
 | 
				
			||||||
 | 
					    mode to transparent if the gzip magic header is not present; set s->err
 | 
				
			||||||
 | 
					    to Z_DATA_ERROR if the magic header is present but the rest of the header
 | 
				
			||||||
 | 
					    is incorrect.
 | 
				
			||||||
 | 
					    IN assertion: the stream s has already been created sucessfully;
 | 
				
			||||||
 | 
					       s->stream.avail_in is zero for the first time, but may be non-zero
 | 
				
			||||||
 | 
					       for concatenated .gz files.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local void check_header(s)
 | 
				
			||||||
 | 
					    gz_stream *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int method; /* method byte */
 | 
				
			||||||
 | 
					    int flags;  /* flags byte */
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					    int c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Check the gzip magic header */
 | 
				
			||||||
 | 
					    for (len = 0; len < 2; len++) {
 | 
				
			||||||
 | 
						c = get_byte(s);
 | 
				
			||||||
 | 
						if (c != gz_magic[len]) {
 | 
				
			||||||
 | 
						    if (len != 0) s->stream.avail_in++, s->stream.next_in--;
 | 
				
			||||||
 | 
						    if (c != EOF) {
 | 
				
			||||||
 | 
							s->stream.avail_in++, s->stream.next_in--;
 | 
				
			||||||
 | 
							s->transparent = 1;
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
 | 
				
			||||||
 | 
						    return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    method = get_byte(s);
 | 
				
			||||||
 | 
					    flags = get_byte(s);
 | 
				
			||||||
 | 
					    if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
 | 
				
			||||||
 | 
						s->z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Discard time, xflags and OS code: */
 | 
				
			||||||
 | 
					    for (len = 0; len < 6; len++) (void)get_byte(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
 | 
				
			||||||
 | 
						len  =  (uInt)get_byte(s);
 | 
				
			||||||
 | 
						len += ((uInt)get_byte(s))<<8;
 | 
				
			||||||
 | 
						/* len is garbage if EOF but the loop below will quit anyway */
 | 
				
			||||||
 | 
						while (len-- != 0 && get_byte(s) != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
 | 
				
			||||||
 | 
						while ((c = get_byte(s)) != 0 && c != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & COMMENT) != 0) {   /* skip the .gz file comment */
 | 
				
			||||||
 | 
						while ((c = get_byte(s)) != 0 && c != EOF) ;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
 | 
				
			||||||
 | 
						for (len = 0; len < 2; len++) (void)get_byte(s);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 /* ===========================================================================
 | 
				
			||||||
 | 
					 * Cleanup then free the given gz_stream. Return a zlib error code.
 | 
				
			||||||
 | 
					   Try freeing in the reverse order of allocations.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					local int destroy (s)
 | 
				
			||||||
 | 
					    gz_stream *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int err = Z_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!s) return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TRYFREE(s->msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s->stream.state != NULL) {
 | 
				
			||||||
 | 
						if (s->mode == 'w') {
 | 
				
			||||||
 | 
					#ifdef NO_DEFLATE
 | 
				
			||||||
 | 
						    err = Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						    err = deflateEnd(&(s->stream));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						} else if (s->mode == 'r') {
 | 
				
			||||||
 | 
						    err = inflateEnd(&(s->stream));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (s->file != NULL && fclose(s->file)) {
 | 
				
			||||||
 | 
					#ifdef ESPIPE
 | 
				
			||||||
 | 
						if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						    err = Z_ERRNO;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (s->z_err < 0) err = s->z_err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TRYFREE(s->inbuf);
 | 
				
			||||||
 | 
					    TRYFREE(s->outbuf);
 | 
				
			||||||
 | 
					    TRYFREE(s->path);
 | 
				
			||||||
 | 
					    TRYFREE(s);
 | 
				
			||||||
 | 
					    return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Reads the given number of uncompressed bytes from the compressed file.
 | 
				
			||||||
 | 
					   gzread returns the number of bytes actually read (0 for end of file).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzread (file, buf, len)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    voidp buf;
 | 
				
			||||||
 | 
					    unsigned len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					    Bytef *start = (Bytef*)buf; /* starting point for crc computation */
 | 
				
			||||||
 | 
					    Byte  *next_out; /* == stream.next_out but not forced far (for MSDOS) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
 | 
				
			||||||
 | 
					    if (s->z_err == Z_STREAM_END) return 0;  /* EOF */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    next_out = (Byte*)buf;
 | 
				
			||||||
 | 
					    s->stream.next_out = (Bytef*)buf;
 | 
				
			||||||
 | 
					    s->stream.avail_out = len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (s->stream.avail_out != 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->transparent) {
 | 
				
			||||||
 | 
						    /* Copy first the lookahead bytes: */
 | 
				
			||||||
 | 
						    uInt n = s->stream.avail_in;
 | 
				
			||||||
 | 
						    if (n > s->stream.avail_out) n = s->stream.avail_out;
 | 
				
			||||||
 | 
						    if (n > 0) {
 | 
				
			||||||
 | 
							zmemcpy(s->stream.next_out, s->stream.next_in, n);
 | 
				
			||||||
 | 
							next_out += n;
 | 
				
			||||||
 | 
							s->stream.next_out = next_out;
 | 
				
			||||||
 | 
							s->stream.next_in   += n;
 | 
				
			||||||
 | 
							s->stream.avail_out -= n;
 | 
				
			||||||
 | 
							s->stream.avail_in  -= n;
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    if (s->stream.avail_out > 0) {
 | 
				
			||||||
 | 
							s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
 | 
				
			||||||
 | 
										     s->file);
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    len -= s->stream.avail_out;
 | 
				
			||||||
 | 
						    s->stream.total_in  += (uLong)len;
 | 
				
			||||||
 | 
						    s->stream.total_out += (uLong)len;
 | 
				
			||||||
 | 
					            if (len == 0) s->z_eof = 1;
 | 
				
			||||||
 | 
						    return (int)len;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					        if (s->stream.avail_in == 0 && !s->z_eof) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            errno = 0;
 | 
				
			||||||
 | 
					            s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
 | 
				
			||||||
 | 
					            if (s->stream.avail_in == 0) {
 | 
				
			||||||
 | 
					                s->z_eof = 1;
 | 
				
			||||||
 | 
							if (ferror(s->file)) {
 | 
				
			||||||
 | 
							    s->z_err = Z_ERRNO;
 | 
				
			||||||
 | 
							    break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            s->stream.next_in = s->inbuf;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (s->z_err == Z_STREAM_END) {
 | 
				
			||||||
 | 
						    /* Check CRC and original size */
 | 
				
			||||||
 | 
						    s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
 | 
				
			||||||
 | 
						    start = s->stream.next_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						    if (getLong(s) != s->crc) {
 | 
				
			||||||
 | 
							s->z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
						    } else {
 | 
				
			||||||
 | 
						        (void)getLong(s);
 | 
				
			||||||
 | 
					                /* The uncompressed length returned by above getlong() may
 | 
				
			||||||
 | 
					                 * be different from s->stream.total_out) in case of
 | 
				
			||||||
 | 
							 * concatenated .gz files. Check for such files:
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							check_header(s);
 | 
				
			||||||
 | 
							if (s->z_err == Z_OK) {
 | 
				
			||||||
 | 
							    uLong total_in = s->stream.total_in;
 | 
				
			||||||
 | 
							    uLong total_out = s->stream.total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							    inflateReset(&(s->stream));
 | 
				
			||||||
 | 
							    s->stream.total_in = total_in;
 | 
				
			||||||
 | 
							    s->stream.total_out = total_out;
 | 
				
			||||||
 | 
							    s->crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (s->z_err != Z_OK || s->z_eof) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (int)(len - s->stream.avail_out);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Reads one byte from the compressed file. gzgetc returns this byte
 | 
				
			||||||
 | 
					   or -1 in case of end of file or error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzgetc(file)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned char c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return gzread(file, &c, 1) == 1 ? c : -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Reads bytes from the compressed file until len-1 characters are
 | 
				
			||||||
 | 
					   read, or a newline character is read and transferred to buf, or an
 | 
				
			||||||
 | 
					   end-of-file condition is encountered.  The string is then terminated
 | 
				
			||||||
 | 
					   with a null character.
 | 
				
			||||||
 | 
					      gzgets returns buf, or Z_NULL in case of error.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      The current implementation is not optimized at all.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					char * ZEXPORT gzgets(file, buf, len)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    char *buf;
 | 
				
			||||||
 | 
					    int len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char *b = buf;
 | 
				
			||||||
 | 
					    if (buf == Z_NULL || len <= 0) return Z_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
 | 
				
			||||||
 | 
					    *buf = '\0';
 | 
				
			||||||
 | 
					    return b == buf && len > 0 ? Z_NULL : b;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef NO_DEFLATE
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Writes the given number of uncompressed bytes into the compressed file.
 | 
				
			||||||
 | 
					   gzwrite returns the number of bytes actually written (0 in case of error).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzwrite (file, buf, len)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    const voidp buf;
 | 
				
			||||||
 | 
					    unsigned len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->stream.next_in = (Bytef*)buf;
 | 
				
			||||||
 | 
					    s->stream.avail_in = len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (s->stream.avail_in != 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (s->stream.avail_out == 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            s->stream.next_out = s->outbuf;
 | 
				
			||||||
 | 
					            if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
 | 
				
			||||||
 | 
					                s->z_err = Z_ERRNO;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            s->stream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
 | 
				
			||||||
 | 
					        if (s->z_err != Z_OK) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    s->crc = crc32(s->crc, (const Bytef *)buf, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return (int)(len - s->stream.avail_in);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Converts, formats, and writes the args to the compressed file under
 | 
				
			||||||
 | 
					   control of the format string, as in fprintf. gzprintf returns the number of
 | 
				
			||||||
 | 
					   uncompressed bytes actually written (0 in case of error).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#ifdef STDC
 | 
				
			||||||
 | 
					#include <stdarg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char buf[Z_PRINTF_BUFSIZE];
 | 
				
			||||||
 | 
					    va_list va;
 | 
				
			||||||
 | 
					    int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    va_start(va, format);
 | 
				
			||||||
 | 
					#ifdef HAS_vsnprintf
 | 
				
			||||||
 | 
					    (void)vsnprintf(buf, sizeof(buf), format, va);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    (void)vsprintf(buf, format, va);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    va_end(va);
 | 
				
			||||||
 | 
					    len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
 | 
				
			||||||
 | 
					    if (len <= 0) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return gzwrite(file, buf, (unsigned)len);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#else /* not ANSI C */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
 | 
				
			||||||
 | 
						               a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    const char *format;
 | 
				
			||||||
 | 
					    int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
 | 
				
			||||||
 | 
						a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char buf[Z_PRINTF_BUFSIZE];
 | 
				
			||||||
 | 
					    int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAS_snprintf
 | 
				
			||||||
 | 
					    snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
 | 
				
			||||||
 | 
						     a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
 | 
				
			||||||
 | 
						    a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
 | 
				
			||||||
 | 
					    if (len <= 0) return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return gzwrite(file, buf, len);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Writes c, converted to an unsigned char, into the compressed file.
 | 
				
			||||||
 | 
					   gzputc returns the value that was written, or -1 in case of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzputc(file, c)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    int c;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned char cc = (unsigned char) c; /* required for big endian systems */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Writes the given null-terminated string to the compressed file, excluding
 | 
				
			||||||
 | 
					   the terminating null character.
 | 
				
			||||||
 | 
					      gzputs returns the number of characters written, or -1 in case of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzputs(file, s)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    const char *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return gzwrite(file, (char*)s, (unsigned)strlen(s));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Flushes all pending output into the compressed file. The parameter
 | 
				
			||||||
 | 
					   flush is as in the deflate() function.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local int do_flush (file, flush)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    int flush;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uInt len;
 | 
				
			||||||
 | 
					    int done = 0;
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->stream.avail_in = 0; /* should be zero already anyway */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (;;) {
 | 
				
			||||||
 | 
					        len = Z_BUFSIZE - s->stream.avail_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (len != 0) {
 | 
				
			||||||
 | 
					            if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
 | 
				
			||||||
 | 
					                s->z_err = Z_ERRNO;
 | 
				
			||||||
 | 
					                return Z_ERRNO;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            s->stream.next_out = s->outbuf;
 | 
				
			||||||
 | 
					            s->stream.avail_out = Z_BUFSIZE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (done) break;
 | 
				
			||||||
 | 
					        s->z_err = deflate(&(s->stream), flush);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Ignore the second of two consecutive flushes: */
 | 
				
			||||||
 | 
						if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* deflate has finished flushing only when it hasn't used up
 | 
				
			||||||
 | 
					         * all the available space in the output buffer: 
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					        if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT gzflush (file, flush)
 | 
				
			||||||
 | 
					     gzFile file;
 | 
				
			||||||
 | 
					     int flush;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					    int err = do_flush (file, flush);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (err) return err;
 | 
				
			||||||
 | 
					    fflush(s->file);
 | 
				
			||||||
 | 
					    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif /* NO_DEFLATE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					      Sets the starting position for the next gzread or gzwrite on the given
 | 
				
			||||||
 | 
					   compressed file. The offset represents a number of bytes in the
 | 
				
			||||||
 | 
					      gzseek returns the resulting offset location as measured in bytes from
 | 
				
			||||||
 | 
					   the beginning of the uncompressed stream, or -1 in case of error.
 | 
				
			||||||
 | 
					      SEEK_END is not implemented, returns error.
 | 
				
			||||||
 | 
					      In this version of the library, gzseek can be extremely slow.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					z_off_t ZEXPORT gzseek (file, offset, whence)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    z_off_t offset;
 | 
				
			||||||
 | 
					    int whence;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL || whence == SEEK_END ||
 | 
				
			||||||
 | 
						s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
 | 
				
			||||||
 | 
						return -1L;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (s->mode == 'w') {
 | 
				
			||||||
 | 
					#ifdef NO_DEFLATE
 | 
				
			||||||
 | 
						return -1L;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						if (whence == SEEK_SET) {
 | 
				
			||||||
 | 
						    offset -= s->stream.total_in;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (offset < 0) return -1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* At this point, offset is the number of zero bytes to write. */
 | 
				
			||||||
 | 
						if (s->inbuf == Z_NULL) {
 | 
				
			||||||
 | 
						    s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
 | 
				
			||||||
 | 
						    zmemzero(s->inbuf, Z_BUFSIZE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						while (offset > 0)  {
 | 
				
			||||||
 | 
						    uInt size = Z_BUFSIZE;
 | 
				
			||||||
 | 
						    if (offset < Z_BUFSIZE) size = (uInt)offset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						    size = gzwrite(file, s->inbuf, size);
 | 
				
			||||||
 | 
						    if (size == 0) return -1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						    offset -= size;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return (z_off_t)s->stream.total_in;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* Rest of function is for reading only */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* compute absolute position */
 | 
				
			||||||
 | 
					    if (whence == SEEK_CUR) {
 | 
				
			||||||
 | 
						offset += s->stream.total_out;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (offset < 0) return -1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s->transparent) {
 | 
				
			||||||
 | 
						/* map to fseek */
 | 
				
			||||||
 | 
						s->stream.avail_in = 0;
 | 
				
			||||||
 | 
						s->stream.next_in = s->inbuf;
 | 
				
			||||||
 | 
					        if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s->stream.total_in = s->stream.total_out = (uLong)offset;
 | 
				
			||||||
 | 
						return offset;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* For a negative seek, rewind and use positive seek */
 | 
				
			||||||
 | 
					    if ((uLong)offset >= s->stream.total_out) {
 | 
				
			||||||
 | 
						offset -= s->stream.total_out;
 | 
				
			||||||
 | 
					    } else if (gzrewind(file) < 0) {
 | 
				
			||||||
 | 
						return -1L;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* offset is now the number of bytes to skip. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (offset != 0 && s->outbuf == Z_NULL) {
 | 
				
			||||||
 | 
						s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    while (offset > 0)  {
 | 
				
			||||||
 | 
						int size = Z_BUFSIZE;
 | 
				
			||||||
 | 
						if (offset < Z_BUFSIZE) size = (int)offset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						size = gzread(file, s->outbuf, (uInt)size);
 | 
				
			||||||
 | 
						if (size <= 0) return -1L;
 | 
				
			||||||
 | 
						offset -= size;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return (z_off_t)s->stream.total_out;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Rewinds input file. 
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzrewind (file)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (s == NULL || s->mode != 'r') return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    s->z_err = Z_OK;
 | 
				
			||||||
 | 
					    s->z_eof = 0;
 | 
				
			||||||
 | 
					    s->stream.avail_in = 0;
 | 
				
			||||||
 | 
					    s->stream.next_in = s->inbuf;
 | 
				
			||||||
 | 
					    s->crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					    if (s->startpos == 0) { /* not a compressed file */
 | 
				
			||||||
 | 
						rewind(s->file);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    (void) inflateReset(&s->stream);
 | 
				
			||||||
 | 
					    return fseek(s->file, s->startpos, SEEK_SET);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Returns the starting position for the next gzread or gzwrite on the
 | 
				
			||||||
 | 
					   given compressed file. This position represents a number of bytes in the
 | 
				
			||||||
 | 
					   uncompressed data stream.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					z_off_t ZEXPORT gztell (file)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return gzseek(file, 0L, SEEK_CUR);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Returns 1 when EOF has previously been detected reading the given
 | 
				
			||||||
 | 
					   input stream, otherwise zero.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzeof (file)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					   Outputs a long in LSB order to the given file
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local void putLong (file, x)
 | 
				
			||||||
 | 
					    FILE *file;
 | 
				
			||||||
 | 
					    uLong x;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int n;
 | 
				
			||||||
 | 
					    for (n = 0; n < 4; n++) {
 | 
				
			||||||
 | 
					        fputc((int)(x & 0xff), file);
 | 
				
			||||||
 | 
					        x >>= 8;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					   Reads a long in LSB order from the given gz_stream. Sets z_err in case
 | 
				
			||||||
 | 
					   of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					local uLong getLong (s)
 | 
				
			||||||
 | 
					    gz_stream *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uLong x = (uLong)get_byte(s);
 | 
				
			||||||
 | 
					    int c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    x += ((uLong)get_byte(s))<<8;
 | 
				
			||||||
 | 
					    x += ((uLong)get_byte(s))<<16;
 | 
				
			||||||
 | 
					    c = get_byte(s);
 | 
				
			||||||
 | 
					    if (c == EOF) s->z_err = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    x += ((uLong)c)<<24;
 | 
				
			||||||
 | 
					    return x;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Flushes all pending output if necessary, closes the compressed file
 | 
				
			||||||
 | 
					   and deallocates all the (de)compression state.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT gzclose (file)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL) return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s->mode == 'w') {
 | 
				
			||||||
 | 
					#ifdef NO_DEFLATE
 | 
				
			||||||
 | 
						return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					        err = do_flush (file, Z_FINISH);
 | 
				
			||||||
 | 
					        if (err != Z_OK) return destroy((gz_stream*)file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        putLong (s->file, s->crc);
 | 
				
			||||||
 | 
					        putLong (s->file, s->stream.total_in);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return destroy((gz_stream*)file);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Returns the error message for the last error which occured on the
 | 
				
			||||||
 | 
					   given compressed file. errnum is set to zlib error number. If an
 | 
				
			||||||
 | 
					   error occured in the file system and not in the compression library,
 | 
				
			||||||
 | 
					   errnum is set to Z_ERRNO and the application may consult errno
 | 
				
			||||||
 | 
					   to get the exact error code.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					const char*  ZEXPORT gzerror (file, errnum)
 | 
				
			||||||
 | 
					    gzFile file;
 | 
				
			||||||
 | 
					    int *errnum;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char *m;
 | 
				
			||||||
 | 
					    gz_stream *s = (gz_stream*)file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (s == NULL) {
 | 
				
			||||||
 | 
					        *errnum = Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					        return (const char*)ERR_MSG(Z_STREAM_ERROR);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    *errnum = s->z_err;
 | 
				
			||||||
 | 
					    if (*errnum == Z_OK) return (const char*)"";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m =  (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TRYFREE(s->msg);
 | 
				
			||||||
 | 
					    s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
 | 
				
			||||||
 | 
					    strcpy(s->msg, s->path);
 | 
				
			||||||
 | 
					    strcat(s->msg, ": ");
 | 
				
			||||||
 | 
					    strcat(s->msg, m);
 | 
				
			||||||
 | 
					    return (const char*)s->msg;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										403
									
								
								src/TZlib/Zip/infblock.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										403
									
								
								src/TZlib/Zip/infblock.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,403 @@
 | 
				
			|||||||
 | 
					/* infblock.c -- interpret and process block types to last block
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "infblock.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					#include "infcodes.h"
 | 
				
			||||||
 | 
					#include "infutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_codes_state {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* simplify the use of the inflate_huft type with some defines */
 | 
				
			||||||
 | 
					#define exop word.what.Exop
 | 
				
			||||||
 | 
					#define bits word.what.Bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Table for deflate from PKZIP's appnote.txt. */
 | 
				
			||||||
 | 
					local const uInt border[] = { /* Order of the bit length code lengths */
 | 
				
			||||||
 | 
					        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					   Notes beyond the 1.93a appnote.txt:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   1. Distance pointers never point before the beginning of the output
 | 
				
			||||||
 | 
					      stream.
 | 
				
			||||||
 | 
					   2. Distance pointers can point back across blocks, up to 32k away.
 | 
				
			||||||
 | 
					   3. There is an implied maximum of 7 bits for the bit length table and
 | 
				
			||||||
 | 
					      15 bits for the actual data.
 | 
				
			||||||
 | 
					   4. If only one code exists, then it is encoded using one bit.  (Zero
 | 
				
			||||||
 | 
					      would be more efficient, but perhaps a little confusing.)  If two
 | 
				
			||||||
 | 
					      codes exist, they are coded using one bit each (0 and 1).
 | 
				
			||||||
 | 
					   5. There is no way of sending zero distance codes--a dummy must be
 | 
				
			||||||
 | 
					      sent if there are none.  (History: a pre 2.0 version of PKZIP would
 | 
				
			||||||
 | 
					      store blocks with no distance codes, but this was discovered to be
 | 
				
			||||||
 | 
					      too harsh a criterion.)  Valid only for 1.93a.  2.04c does allow
 | 
				
			||||||
 | 
					      zero distance codes, which is sent as one code of zero bits in
 | 
				
			||||||
 | 
					      length.
 | 
				
			||||||
 | 
					   6. There are up to 286 literal/length codes.  Code 256 represents the
 | 
				
			||||||
 | 
					      end-of-block.  Note however that the static length tree defines
 | 
				
			||||||
 | 
					      288 codes just to fill out the Huffman codes.  Codes 286 and 287
 | 
				
			||||||
 | 
					      cannot be used though, since there is no length base or extra bits
 | 
				
			||||||
 | 
					      defined for them.  Similarily, there are up to 30 distance codes.
 | 
				
			||||||
 | 
					      However, static trees define 32 codes (all 5 bits) to fill out the
 | 
				
			||||||
 | 
					      Huffman codes, but the last two had better not show up in the data.
 | 
				
			||||||
 | 
					   7. Unzip can check dynamic Huffman blocks for complete code sets.
 | 
				
			||||||
 | 
					      The exception is that a single code would not be complete (see #4).
 | 
				
			||||||
 | 
					   8. The five bits following the block type is really the number of
 | 
				
			||||||
 | 
					      literal codes sent minus 257.
 | 
				
			||||||
 | 
					   9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
 | 
				
			||||||
 | 
					      (1+6+6).  Therefore, to output three times the length, you output
 | 
				
			||||||
 | 
					      three codes (1+1+1), whereas to output four times the same length,
 | 
				
			||||||
 | 
					      you only need two codes (1+3).  Hmm.
 | 
				
			||||||
 | 
					  10. In the tree reconstruction algorithm, Code = Code + Increment
 | 
				
			||||||
 | 
					      only if BitLength(i) is not zero.  (Pretty obvious.)
 | 
				
			||||||
 | 
					  11. Correction: 4 Bits: # of Bit Length codes - 4     (4 - 19)
 | 
				
			||||||
 | 
					  12. Note: length code 284 can represent 227-258, but length code 285
 | 
				
			||||||
 | 
					      really is 258.  The last length deserves its own, short code
 | 
				
			||||||
 | 
					      since it gets used a lot in very redundant files.  The length
 | 
				
			||||||
 | 
					      258 is special since 258 - 3 (the min match length) is 255.
 | 
				
			||||||
 | 
					  13. The literal/length and distance code bit lengths are read as a
 | 
				
			||||||
 | 
					      single stream of lengths.  It is possible (and advantageous) for
 | 
				
			||||||
 | 
					      a repeat code (16, 17, or 18) to go across the boundary between
 | 
				
			||||||
 | 
					      the two sets of lengths.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void inflate_blocks_reset(s, z, c)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					uLongf *c;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (c != Z_NULL)
 | 
				
			||||||
 | 
					    *c = s->check;
 | 
				
			||||||
 | 
					  if (s->mode == BTREE || s->mode == DTREE)
 | 
				
			||||||
 | 
					    ZFREE(z, s->sub.trees.blens);
 | 
				
			||||||
 | 
					  if (s->mode == CODES)
 | 
				
			||||||
 | 
					    inflate_codes_free(s->sub.decode.codes, z);
 | 
				
			||||||
 | 
					  s->mode = TYPE;
 | 
				
			||||||
 | 
					  s->bitk = 0;
 | 
				
			||||||
 | 
					  s->bitb = 0;
 | 
				
			||||||
 | 
					  s->read = s->write = s->window;
 | 
				
			||||||
 | 
					  if (s->checkfn != Z_NULL)
 | 
				
			||||||
 | 
					    z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate:   blocks reset\n"));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inflate_blocks_statef *inflate_blocks_new(z, c, w)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					check_func c;
 | 
				
			||||||
 | 
					uInt w;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ((s = (inflate_blocks_statef *)ZALLOC
 | 
				
			||||||
 | 
					       (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
 | 
				
			||||||
 | 
					    return s;
 | 
				
			||||||
 | 
					  if ((s->hufts =
 | 
				
			||||||
 | 
					       (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    ZFREE(z, s);
 | 
				
			||||||
 | 
					    return Z_NULL;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    ZFREE(z, s->hufts);
 | 
				
			||||||
 | 
					    ZFREE(z, s);
 | 
				
			||||||
 | 
					    return Z_NULL;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  s->end = s->window + w;
 | 
				
			||||||
 | 
					  s->checkfn = c;
 | 
				
			||||||
 | 
					  s->mode = TYPE;
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate:   blocks allocated\n"));
 | 
				
			||||||
 | 
					  inflate_blocks_reset(s, z, Z_NULL);
 | 
				
			||||||
 | 
					  return s;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_blocks(s, z, r)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					int r;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uInt t;               /* temporary storage */
 | 
				
			||||||
 | 
					  uLong b;              /* bit buffer */
 | 
				
			||||||
 | 
					  uInt k;               /* bits in bit buffer */
 | 
				
			||||||
 | 
					  Bytef *p;             /* input data pointer */
 | 
				
			||||||
 | 
					  uInt n;               /* bytes available there */
 | 
				
			||||||
 | 
					  Bytef *q;             /* output window write pointer */
 | 
				
			||||||
 | 
					  uInt m;               /* bytes to end of window or read pointer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* copy input/output information to locals (UPDATE macro restores) */
 | 
				
			||||||
 | 
					  LOAD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* process input based on current state */
 | 
				
			||||||
 | 
					  while (1) switch (s->mode)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    case TYPE:
 | 
				
			||||||
 | 
					      NEEDBITS(3)
 | 
				
			||||||
 | 
					      t = (uInt)b & 7;
 | 
				
			||||||
 | 
					      s->last = t & 1;
 | 
				
			||||||
 | 
					      switch (t >> 1)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        case 0:                         /* stored */
 | 
				
			||||||
 | 
					          Tracev((stderr, "inflate:     stored block%s\n",
 | 
				
			||||||
 | 
					                 s->last ? " (last)" : ""));
 | 
				
			||||||
 | 
					          DUMPBITS(3)
 | 
				
			||||||
 | 
					          t = k & 7;                    /* go to byte boundary */
 | 
				
			||||||
 | 
					          DUMPBITS(t)
 | 
				
			||||||
 | 
					          s->mode = LENS;               /* get length of stored block */
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 1:                         /* fixed */
 | 
				
			||||||
 | 
					          Tracev((stderr, "inflate:     fixed codes block%s\n",
 | 
				
			||||||
 | 
					                 s->last ? " (last)" : ""));
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            uInt bl, bd;
 | 
				
			||||||
 | 
					            inflate_huft *tl, *td;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            inflate_trees_fixed(&bl, &bd, &tl, &td, z);
 | 
				
			||||||
 | 
					            s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
 | 
				
			||||||
 | 
					            if (s->sub.decode.codes == Z_NULL)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              r = Z_MEM_ERROR;
 | 
				
			||||||
 | 
					              LEAVE
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          DUMPBITS(3)
 | 
				
			||||||
 | 
					          s->mode = CODES;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 2:                         /* dynamic */
 | 
				
			||||||
 | 
					          Tracev((stderr, "inflate:     dynamic codes block%s\n",
 | 
				
			||||||
 | 
					                 s->last ? " (last)" : ""));
 | 
				
			||||||
 | 
					          DUMPBITS(3)
 | 
				
			||||||
 | 
					          s->mode = TABLE;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 3:                         /* illegal */
 | 
				
			||||||
 | 
					          DUMPBITS(3)
 | 
				
			||||||
 | 
					          s->mode = BAD;
 | 
				
			||||||
 | 
					          z->msg = (char*)"invalid block type";
 | 
				
			||||||
 | 
					          r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					          LEAVE
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    case LENS:
 | 
				
			||||||
 | 
					      NEEDBITS(32)
 | 
				
			||||||
 | 
					      if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        s->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"invalid stored block lengths";
 | 
				
			||||||
 | 
					        r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      s->sub.left = (uInt)b & 0xffff;
 | 
				
			||||||
 | 
					      b = k = 0;                      /* dump bits */
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate:       stored length %u\n", s->sub.left));
 | 
				
			||||||
 | 
					      s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    case STORED:
 | 
				
			||||||
 | 
					      if (n == 0)
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      NEEDOUT
 | 
				
			||||||
 | 
					      t = s->sub.left;
 | 
				
			||||||
 | 
					      if (t > n) t = n;
 | 
				
			||||||
 | 
					      if (t > m) t = m;
 | 
				
			||||||
 | 
					      zmemcpy(q, p, t);
 | 
				
			||||||
 | 
					      p += t;  n -= t;
 | 
				
			||||||
 | 
					      q += t;  m -= t;
 | 
				
			||||||
 | 
					      if ((s->sub.left -= t) != 0)
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate:       stored end, %lu total out\n",
 | 
				
			||||||
 | 
					              z->total_out + (q >= s->read ? q - s->read :
 | 
				
			||||||
 | 
					              (s->end - s->read) + (q - s->window))));
 | 
				
			||||||
 | 
					      s->mode = s->last ? DRY : TYPE;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    case TABLE:
 | 
				
			||||||
 | 
					      NEEDBITS(14)
 | 
				
			||||||
 | 
					      s->sub.trees.table = t = (uInt)b & 0x3fff;
 | 
				
			||||||
 | 
					#ifndef PKZIP_BUG_WORKAROUND
 | 
				
			||||||
 | 
					      if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        s->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"too many length or distance symbols";
 | 
				
			||||||
 | 
					        r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					      t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
 | 
				
			||||||
 | 
					      if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        r = Z_MEM_ERROR;
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      DUMPBITS(14)
 | 
				
			||||||
 | 
					      s->sub.trees.index = 0;
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate:       table sizes ok\n"));
 | 
				
			||||||
 | 
					      s->mode = BTREE;
 | 
				
			||||||
 | 
					    case BTREE:
 | 
				
			||||||
 | 
					      while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        NEEDBITS(3)
 | 
				
			||||||
 | 
					        s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
 | 
				
			||||||
 | 
					        DUMPBITS(3)
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      while (s->sub.trees.index < 19)
 | 
				
			||||||
 | 
					        s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
 | 
				
			||||||
 | 
					      s->sub.trees.bb = 7;
 | 
				
			||||||
 | 
					      t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
 | 
				
			||||||
 | 
					                             &s->sub.trees.tb, s->hufts, z);
 | 
				
			||||||
 | 
					      if (t != Z_OK)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        r = t;
 | 
				
			||||||
 | 
					        if (r == Z_DATA_ERROR)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          ZFREE(z, s->sub.trees.blens);
 | 
				
			||||||
 | 
					          s->mode = BAD;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      s->sub.trees.index = 0;
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate:       bits tree ok\n"));
 | 
				
			||||||
 | 
					      s->mode = DTREE;
 | 
				
			||||||
 | 
					    case DTREE:
 | 
				
			||||||
 | 
					      while (t = s->sub.trees.table,
 | 
				
			||||||
 | 
					             s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        inflate_huft *h;
 | 
				
			||||||
 | 
					        uInt i, j, c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        t = s->sub.trees.bb;
 | 
				
			||||||
 | 
					        NEEDBITS(t)
 | 
				
			||||||
 | 
					        h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
 | 
				
			||||||
 | 
					        t = h->bits;
 | 
				
			||||||
 | 
					        c = h->base;
 | 
				
			||||||
 | 
					        if (c < 16)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          DUMPBITS(t)
 | 
				
			||||||
 | 
					          s->sub.trees.blens[s->sub.trees.index++] = c;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else /* c == 16..18 */
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          i = c == 18 ? 7 : c - 14;
 | 
				
			||||||
 | 
					          j = c == 18 ? 11 : 3;
 | 
				
			||||||
 | 
					          NEEDBITS(t + i)
 | 
				
			||||||
 | 
					          DUMPBITS(t)
 | 
				
			||||||
 | 
					          j += (uInt)b & inflate_mask[i];
 | 
				
			||||||
 | 
					          DUMPBITS(i)
 | 
				
			||||||
 | 
					          i = s->sub.trees.index;
 | 
				
			||||||
 | 
					          t = s->sub.trees.table;
 | 
				
			||||||
 | 
					          if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
 | 
				
			||||||
 | 
					              (c == 16 && i < 1))
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            ZFREE(z, s->sub.trees.blens);
 | 
				
			||||||
 | 
					            s->mode = BAD;
 | 
				
			||||||
 | 
					            z->msg = (char*)"invalid bit length repeat";
 | 
				
			||||||
 | 
					            r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					            LEAVE
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
 | 
				
			||||||
 | 
					          do {
 | 
				
			||||||
 | 
					            s->sub.trees.blens[i++] = c;
 | 
				
			||||||
 | 
					          } while (--j);
 | 
				
			||||||
 | 
					          s->sub.trees.index = i;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      s->sub.trees.tb = Z_NULL;
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        uInt bl, bd;
 | 
				
			||||||
 | 
					        inflate_huft *tl, *td;
 | 
				
			||||||
 | 
					        inflate_codes_statef *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        bl = 9;         /* must be <= 9 for lookahead assumptions */
 | 
				
			||||||
 | 
					        bd = 6;         /* must be <= 9 for lookahead assumptions */
 | 
				
			||||||
 | 
					        t = s->sub.trees.table;
 | 
				
			||||||
 | 
					        t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
 | 
				
			||||||
 | 
					                                  s->sub.trees.blens, &bl, &bd, &tl, &td,
 | 
				
			||||||
 | 
					                                  s->hufts, z);
 | 
				
			||||||
 | 
					        if (t != Z_OK)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          if (t == (uInt)Z_DATA_ERROR)
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            ZFREE(z, s->sub.trees.blens);
 | 
				
			||||||
 | 
					            s->mode = BAD;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          r = t;
 | 
				
			||||||
 | 
					          LEAVE
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        Tracev((stderr, "inflate:       trees ok\n"));
 | 
				
			||||||
 | 
					        if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          r = Z_MEM_ERROR;
 | 
				
			||||||
 | 
					          LEAVE
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        s->sub.decode.codes = c;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      ZFREE(z, s->sub.trees.blens);
 | 
				
			||||||
 | 
					      s->mode = CODES;
 | 
				
			||||||
 | 
					    case CODES:
 | 
				
			||||||
 | 
					      UPDATE
 | 
				
			||||||
 | 
					      if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
 | 
				
			||||||
 | 
					        return inflate_flush(s, z, r);
 | 
				
			||||||
 | 
					      r = Z_OK;
 | 
				
			||||||
 | 
					      inflate_codes_free(s->sub.decode.codes, z);
 | 
				
			||||||
 | 
					      LOAD
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate:       codes end, %lu total out\n",
 | 
				
			||||||
 | 
					              z->total_out + (q >= s->read ? q - s->read :
 | 
				
			||||||
 | 
					              (s->end - s->read) + (q - s->window))));
 | 
				
			||||||
 | 
					      if (!s->last)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        s->mode = TYPE;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      s->mode = DRY;
 | 
				
			||||||
 | 
					    case DRY:
 | 
				
			||||||
 | 
					      FLUSH
 | 
				
			||||||
 | 
					      if (s->read != s->write)
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      s->mode = DONE;
 | 
				
			||||||
 | 
					    case DONE:
 | 
				
			||||||
 | 
					      r = Z_STREAM_END;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    case BAD:
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					      r = Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_blocks_free(s, z)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  inflate_blocks_reset(s, z, Z_NULL);
 | 
				
			||||||
 | 
					  ZFREE(z, s->window);
 | 
				
			||||||
 | 
					  ZFREE(z, s->hufts);
 | 
				
			||||||
 | 
					  ZFREE(z, s);
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate:   blocks freed\n"));
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void inflate_set_dictionary(s, d, n)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					const Bytef *d;
 | 
				
			||||||
 | 
					uInt  n;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  zmemcpy(s->window, d, n);
 | 
				
			||||||
 | 
					  s->read = s->write = s->window + n;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Returns true if inflate is currently at the end of a block generated
 | 
				
			||||||
 | 
					 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. 
 | 
				
			||||||
 | 
					 * IN assertion: s != Z_NULL
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int inflate_blocks_sync_point(s)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return s->mode == LENS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								src/TZlib/Zip/infblock.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/TZlib/Zip/infblock.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					/* infblock.h -- header to use infblock.c
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_blocks_state;
 | 
				
			||||||
 | 
					typedef struct inflate_blocks_state FAR inflate_blocks_statef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern inflate_blocks_statef * inflate_blocks_new OF((
 | 
				
			||||||
 | 
					    z_streamp z,
 | 
				
			||||||
 | 
					    check_func c,               /* check function */
 | 
				
			||||||
 | 
					    uInt w));                   /* window size */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_blocks OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp ,
 | 
				
			||||||
 | 
					    int));                      /* initial return code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void inflate_blocks_reset OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp ,
 | 
				
			||||||
 | 
					    uLongf *));                  /* check value on output */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_blocks_free OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void inflate_set_dictionary OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *s,
 | 
				
			||||||
 | 
					    const Bytef *d,  /* dictionary */
 | 
				
			||||||
 | 
					    uInt  n));       /* dictionary length */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_blocks_sync_point OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *s));
 | 
				
			||||||
							
								
								
									
										251
									
								
								src/TZlib/Zip/infcodes.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										251
									
								
								src/TZlib/Zip/infcodes.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,251 @@
 | 
				
			|||||||
 | 
					/* infcodes.c -- process literals and length/distance pairs
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					#include "infblock.h"
 | 
				
			||||||
 | 
					#include "infcodes.h"
 | 
				
			||||||
 | 
					#include "infutil.h"
 | 
				
			||||||
 | 
					#include "inffast.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* simplify the use of the inflate_huft type with some defines */
 | 
				
			||||||
 | 
					#define exop word.what.Exop
 | 
				
			||||||
 | 
					#define bits word.what.Bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
 | 
				
			||||||
 | 
					      START,    /* x: set up for LEN */
 | 
				
			||||||
 | 
					      LEN,      /* i: get length/literal/eob next */
 | 
				
			||||||
 | 
					      LENEXT,   /* i: getting length extra (have base) */
 | 
				
			||||||
 | 
					      DIST,     /* i: get distance next */
 | 
				
			||||||
 | 
					      DISTEXT,  /* i: getting distance extra */
 | 
				
			||||||
 | 
					      COPY,     /* o: copying bytes in window, waiting for space */
 | 
				
			||||||
 | 
					      LIT,      /* o: got literal, waiting for output space */
 | 
				
			||||||
 | 
					      WASH,     /* o: got eob, possibly still output waiting */
 | 
				
			||||||
 | 
					      END,      /* x: got eob and all data flushed */
 | 
				
			||||||
 | 
					      BADCODE}  /* x: got error */
 | 
				
			||||||
 | 
					inflate_codes_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inflate codes private state */
 | 
				
			||||||
 | 
					struct inflate_codes_state {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode */
 | 
				
			||||||
 | 
					  inflate_codes_mode mode;      /* current inflate_codes mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode dependent information */
 | 
				
			||||||
 | 
					  uInt len;
 | 
				
			||||||
 | 
					  union {
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      inflate_huft *tree;       /* pointer into tree */
 | 
				
			||||||
 | 
					      uInt need;                /* bits needed */
 | 
				
			||||||
 | 
					    } code;             /* if LEN or DIST, where in tree */
 | 
				
			||||||
 | 
					    uInt lit;           /* if LIT, literal */
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      uInt get;                 /* bits to get for extra */
 | 
				
			||||||
 | 
					      uInt dist;                /* distance back to copy from */
 | 
				
			||||||
 | 
					    } copy;             /* if EXT or COPY, where and how much */
 | 
				
			||||||
 | 
					  } sub;                /* submode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode independent information */
 | 
				
			||||||
 | 
					  Byte lbits;           /* ltree bits decoded per branch */
 | 
				
			||||||
 | 
					  Byte dbits;           /* dtree bits decoder per branch */
 | 
				
			||||||
 | 
					  inflate_huft *ltree;          /* literal/length/eob tree */
 | 
				
			||||||
 | 
					  inflate_huft *dtree;          /* distance tree */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
 | 
				
			||||||
 | 
					uInt bl, bd;
 | 
				
			||||||
 | 
					inflate_huft *tl;
 | 
				
			||||||
 | 
					inflate_huft *td; /* need separate declaration for Borland C++ */
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  inflate_codes_statef *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ((c = (inflate_codes_statef *)
 | 
				
			||||||
 | 
					       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    c->mode = START;
 | 
				
			||||||
 | 
					    c->lbits = (Byte)bl;
 | 
				
			||||||
 | 
					    c->dbits = (Byte)bd;
 | 
				
			||||||
 | 
					    c->ltree = tl;
 | 
				
			||||||
 | 
					    c->dtree = td;
 | 
				
			||||||
 | 
					    Tracev((stderr, "inflate:       codes new\n"));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return c;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_codes(s, z, r)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					int r;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uInt j;               /* temporary storage */
 | 
				
			||||||
 | 
					  inflate_huft *t;      /* temporary pointer */
 | 
				
			||||||
 | 
					  uInt e;               /* extra bits or operation */
 | 
				
			||||||
 | 
					  uLong b;              /* bit buffer */
 | 
				
			||||||
 | 
					  uInt k;               /* bits in bit buffer */
 | 
				
			||||||
 | 
					  Bytef *p;             /* input data pointer */
 | 
				
			||||||
 | 
					  uInt n;               /* bytes available there */
 | 
				
			||||||
 | 
					  Bytef *q;             /* output window write pointer */
 | 
				
			||||||
 | 
					  uInt m;               /* bytes to end of window or read pointer */
 | 
				
			||||||
 | 
					  Bytef *f;             /* pointer to copy strings from */
 | 
				
			||||||
 | 
					  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* copy input/output information to locals (UPDATE macro restores) */
 | 
				
			||||||
 | 
					  LOAD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* process input and output based on current state */
 | 
				
			||||||
 | 
					  while (1) switch (c->mode)
 | 
				
			||||||
 | 
					  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
 | 
				
			||||||
 | 
					    case START:         /* x: set up for LEN */
 | 
				
			||||||
 | 
					#ifndef SLOW
 | 
				
			||||||
 | 
					      if (m >= 258 && n >= 10)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        UPDATE
 | 
				
			||||||
 | 
					        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
 | 
				
			||||||
 | 
					        LOAD
 | 
				
			||||||
 | 
					        if (r != Z_OK)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					#endif /* !SLOW */
 | 
				
			||||||
 | 
					      c->sub.code.need = c->lbits;
 | 
				
			||||||
 | 
					      c->sub.code.tree = c->ltree;
 | 
				
			||||||
 | 
					      c->mode = LEN;
 | 
				
			||||||
 | 
					    case LEN:           /* i: get length/literal/eob next */
 | 
				
			||||||
 | 
					      j = c->sub.code.need;
 | 
				
			||||||
 | 
					      NEEDBITS(j)
 | 
				
			||||||
 | 
					      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
 | 
				
			||||||
 | 
					      DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					      e = (uInt)(t->exop);
 | 
				
			||||||
 | 
					      if (e == 0)               /* literal */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        c->sub.lit = t->base;
 | 
				
			||||||
 | 
					        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
 | 
				
			||||||
 | 
					                 "inflate:         literal '%c'\n" :
 | 
				
			||||||
 | 
					                 "inflate:         literal 0x%02x\n", t->base));
 | 
				
			||||||
 | 
					        c->mode = LIT;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (e & 16)               /* length */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        c->sub.copy.get = e & 15;
 | 
				
			||||||
 | 
					        c->len = t->base;
 | 
				
			||||||
 | 
					        c->mode = LENEXT;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if ((e & 64) == 0)        /* next table */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        c->sub.code.need = e;
 | 
				
			||||||
 | 
					        c->sub.code.tree = t + t->base;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (e & 32)               /* end of block */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        Tracevv((stderr, "inflate:         end of block\n"));
 | 
				
			||||||
 | 
					        c->mode = WASH;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      c->mode = BADCODE;        /* invalid code */
 | 
				
			||||||
 | 
					      z->msg = (char*)"invalid literal/length code";
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    case LENEXT:        /* i: getting length extra (have base) */
 | 
				
			||||||
 | 
					      j = c->sub.copy.get;
 | 
				
			||||||
 | 
					      NEEDBITS(j)
 | 
				
			||||||
 | 
					      c->len += (uInt)b & inflate_mask[j];
 | 
				
			||||||
 | 
					      DUMPBITS(j)
 | 
				
			||||||
 | 
					      c->sub.code.need = c->dbits;
 | 
				
			||||||
 | 
					      c->sub.code.tree = c->dtree;
 | 
				
			||||||
 | 
					      Tracevv((stderr, "inflate:         length %u\n", c->len));
 | 
				
			||||||
 | 
					      c->mode = DIST;
 | 
				
			||||||
 | 
					    case DIST:          /* i: get distance next */
 | 
				
			||||||
 | 
					      j = c->sub.code.need;
 | 
				
			||||||
 | 
					      NEEDBITS(j)
 | 
				
			||||||
 | 
					      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
 | 
				
			||||||
 | 
					      DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					      e = (uInt)(t->exop);
 | 
				
			||||||
 | 
					      if (e & 16)               /* distance */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        c->sub.copy.get = e & 15;
 | 
				
			||||||
 | 
					        c->sub.copy.dist = t->base;
 | 
				
			||||||
 | 
					        c->mode = DISTEXT;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if ((e & 64) == 0)        /* next table */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        c->sub.code.need = e;
 | 
				
			||||||
 | 
					        c->sub.code.tree = t + t->base;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      c->mode = BADCODE;        /* invalid code */
 | 
				
			||||||
 | 
					      z->msg = (char*)"invalid distance code";
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    case DISTEXT:       /* i: getting distance extra */
 | 
				
			||||||
 | 
					      j = c->sub.copy.get;
 | 
				
			||||||
 | 
					      NEEDBITS(j)
 | 
				
			||||||
 | 
					      c->sub.copy.dist += (uInt)b & inflate_mask[j];
 | 
				
			||||||
 | 
					      DUMPBITS(j)
 | 
				
			||||||
 | 
					      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
 | 
				
			||||||
 | 
					      c->mode = COPY;
 | 
				
			||||||
 | 
					    case COPY:          /* o: copying bytes in window, waiting for space */
 | 
				
			||||||
 | 
					      f = q - c->sub.copy.dist;
 | 
				
			||||||
 | 
					      while (f < s->window)             /* modulo window size-"while" instead */
 | 
				
			||||||
 | 
					        f += s->end - s->window;        /* of "if" handles invalid distances */
 | 
				
			||||||
 | 
					      while (c->len)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        NEEDOUT
 | 
				
			||||||
 | 
					        OUTBYTE(*f++)
 | 
				
			||||||
 | 
					        if (f == s->end)
 | 
				
			||||||
 | 
					          f = s->window;
 | 
				
			||||||
 | 
					        c->len--;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      c->mode = START;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    case LIT:           /* o: got literal, waiting for output space */
 | 
				
			||||||
 | 
					      NEEDOUT
 | 
				
			||||||
 | 
					      OUTBYTE(c->sub.lit)
 | 
				
			||||||
 | 
					      c->mode = START;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    case WASH:          /* o: got eob, possibly more output */
 | 
				
			||||||
 | 
					      if (k > 7)        /* return unused byte, if any */
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        Assert(k < 16, "inflate_codes grabbed too many bytes")
 | 
				
			||||||
 | 
					        k -= 8;
 | 
				
			||||||
 | 
					        n++;
 | 
				
			||||||
 | 
					        p--;            /* can always return one */
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      FLUSH
 | 
				
			||||||
 | 
					      if (s->read != s->write)
 | 
				
			||||||
 | 
					        LEAVE
 | 
				
			||||||
 | 
					      c->mode = END;
 | 
				
			||||||
 | 
					    case END:
 | 
				
			||||||
 | 
					      r = Z_STREAM_END;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    case BADCODE:       /* x: got error */
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					      r = Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					      LEAVE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#ifdef NEED_DUMMY_RETURN
 | 
				
			||||||
 | 
					  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void inflate_codes_free(c, z)
 | 
				
			||||||
 | 
					inflate_codes_statef *c;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  ZFREE(z, c);
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate:       codes free\n"));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/TZlib/Zip/infcodes.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/TZlib/Zip/infcodes.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					/* infcodes.h -- header to use infcodes.c
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_codes_state;
 | 
				
			||||||
 | 
					typedef struct inflate_codes_state FAR inflate_codes_statef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern inflate_codes_statef *inflate_codes_new OF((
 | 
				
			||||||
 | 
					    uInt, uInt,
 | 
				
			||||||
 | 
					    inflate_huft *, inflate_huft *,
 | 
				
			||||||
 | 
					    z_streamp ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_codes OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp ,
 | 
				
			||||||
 | 
					    int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void inflate_codes_free OF((
 | 
				
			||||||
 | 
					    inflate_codes_statef *,
 | 
				
			||||||
 | 
					    z_streamp ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										183
									
								
								src/TZlib/Zip/inffast.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								src/TZlib/Zip/inffast.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,183 @@
 | 
				
			|||||||
 | 
					/* inffast.c -- process literals and length/distance pairs fast
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					#include "infblock.h"
 | 
				
			||||||
 | 
					#include "infcodes.h"
 | 
				
			||||||
 | 
					#include "infutil.h"
 | 
				
			||||||
 | 
					#include "inffast.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_codes_state {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* simplify the use of the inflate_huft type with some defines */
 | 
				
			||||||
 | 
					#define exop word.what.Exop
 | 
				
			||||||
 | 
					#define bits word.what.Bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* macros for bit input with no checking and for returning unused bytes */
 | 
				
			||||||
 | 
					#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
 | 
				
			||||||
 | 
					#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Called with number of bytes left to write in window at least 258
 | 
				
			||||||
 | 
					   (the maximum string length) and number of input bytes available
 | 
				
			||||||
 | 
					   at least ten.  The ten bytes are six bytes for the longest length/
 | 
				
			||||||
 | 
					   distance pair plus four bytes for overloading the bit buffer. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_fast(bl, bd, tl, td, s, z)
 | 
				
			||||||
 | 
					uInt bl, bd;
 | 
				
			||||||
 | 
					inflate_huft *tl;
 | 
				
			||||||
 | 
					inflate_huft *td; /* need separate declaration for Borland C++ */
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  inflate_huft *t;      /* temporary pointer */
 | 
				
			||||||
 | 
					  uInt e;               /* extra bits or operation */
 | 
				
			||||||
 | 
					  uLong b;              /* bit buffer */
 | 
				
			||||||
 | 
					  uInt k;               /* bits in bit buffer */
 | 
				
			||||||
 | 
					  Bytef *p;             /* input data pointer */
 | 
				
			||||||
 | 
					  uInt n;               /* bytes available there */
 | 
				
			||||||
 | 
					  Bytef *q;             /* output window write pointer */
 | 
				
			||||||
 | 
					  uInt m;               /* bytes to end of window or read pointer */
 | 
				
			||||||
 | 
					  uInt ml;              /* mask for literal/length tree */
 | 
				
			||||||
 | 
					  uInt md;              /* mask for distance tree */
 | 
				
			||||||
 | 
					  uInt c;               /* bytes to copy */
 | 
				
			||||||
 | 
					  uInt d;               /* distance back to copy from */
 | 
				
			||||||
 | 
					  Bytef *r;             /* copy source pointer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* load input, output, bit values */
 | 
				
			||||||
 | 
					  LOAD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* initialize masks */
 | 
				
			||||||
 | 
					  ml = inflate_mask[bl];
 | 
				
			||||||
 | 
					  md = inflate_mask[bd];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* do until not enough input or output space for fast loop */
 | 
				
			||||||
 | 
					  do {                          /* assume called with m >= 258 && n >= 10 */
 | 
				
			||||||
 | 
					    /* get literal/length code */
 | 
				
			||||||
 | 
					    GRABBITS(20)                /* max bits for literal/length code */
 | 
				
			||||||
 | 
					    if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					      Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
 | 
				
			||||||
 | 
					                "inflate:         * literal '%c'\n" :
 | 
				
			||||||
 | 
					                "inflate:         * literal 0x%02x\n", t->base));
 | 
				
			||||||
 | 
					      *q++ = (Byte)t->base;
 | 
				
			||||||
 | 
					      m--;
 | 
				
			||||||
 | 
					      continue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					      DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					      if (e & 16)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        /* get extra bits for length */
 | 
				
			||||||
 | 
					        e &= 15;
 | 
				
			||||||
 | 
					        c = t->base + ((uInt)b & inflate_mask[e]);
 | 
				
			||||||
 | 
					        DUMPBITS(e)
 | 
				
			||||||
 | 
					        Tracevv((stderr, "inflate:         * length %u\n", c));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* decode distance base of block to copy */
 | 
				
			||||||
 | 
					        GRABBITS(15);           /* max bits for distance code */
 | 
				
			||||||
 | 
					        e = (t = td + ((uInt)b & md))->exop;
 | 
				
			||||||
 | 
					        do {
 | 
				
			||||||
 | 
					          DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					          if (e & 16)
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            /* get extra bits to add to distance base */
 | 
				
			||||||
 | 
					            e &= 15;
 | 
				
			||||||
 | 
					            GRABBITS(e)         /* get extra bits (up to 13) */
 | 
				
			||||||
 | 
					            d = t->base + ((uInt)b & inflate_mask[e]);
 | 
				
			||||||
 | 
					            DUMPBITS(e)
 | 
				
			||||||
 | 
					            Tracevv((stderr, "inflate:         * distance %u\n", d));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* do the copy */
 | 
				
			||||||
 | 
					            m -= c;
 | 
				
			||||||
 | 
					            r = q - d;
 | 
				
			||||||
 | 
					            if (r < s->window)                  /* wrap if needed */
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              do {
 | 
				
			||||||
 | 
					                r += s->end - s->window;        /* force pointer in window */
 | 
				
			||||||
 | 
					              } while (r < s->window);          /* covers invalid distances */
 | 
				
			||||||
 | 
					              e = s->end - r;
 | 
				
			||||||
 | 
					              if (c > e)
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
					                c -= e;                         /* wrapped copy */
 | 
				
			||||||
 | 
					                do {
 | 
				
			||||||
 | 
					                    *q++ = *r++;
 | 
				
			||||||
 | 
					                } while (--e);
 | 
				
			||||||
 | 
					                r = s->window;
 | 
				
			||||||
 | 
					                do {
 | 
				
			||||||
 | 
					                    *q++ = *r++;
 | 
				
			||||||
 | 
					                } while (--c);
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					              else                              /* normal copy */
 | 
				
			||||||
 | 
					              {
 | 
				
			||||||
 | 
					                *q++ = *r++;  c--;
 | 
				
			||||||
 | 
					                *q++ = *r++;  c--;
 | 
				
			||||||
 | 
					                do {
 | 
				
			||||||
 | 
					                    *q++ = *r++;
 | 
				
			||||||
 | 
					                } while (--c);
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else                                /* normal copy */
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              *q++ = *r++;  c--;
 | 
				
			||||||
 | 
					              *q++ = *r++;  c--;
 | 
				
			||||||
 | 
					              do {
 | 
				
			||||||
 | 
					                *q++ = *r++;
 | 
				
			||||||
 | 
					              } while (--c);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          else if ((e & 64) == 0)
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            t += t->base;
 | 
				
			||||||
 | 
					            e = (t += ((uInt)b & inflate_mask[e]))->exop;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          else
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            z->msg = (char*)"invalid distance code";
 | 
				
			||||||
 | 
					            UNGRAB
 | 
				
			||||||
 | 
					            UPDATE
 | 
				
			||||||
 | 
					            return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        } while (1);
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if ((e & 64) == 0)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        t += t->base;
 | 
				
			||||||
 | 
					        if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          DUMPBITS(t->bits)
 | 
				
			||||||
 | 
					          Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
 | 
				
			||||||
 | 
					                    "inflate:         * literal '%c'\n" :
 | 
				
			||||||
 | 
					                    "inflate:         * literal 0x%02x\n", t->base));
 | 
				
			||||||
 | 
					          *q++ = (Byte)t->base;
 | 
				
			||||||
 | 
					          m--;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else if (e & 32)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        Tracevv((stderr, "inflate:         * end of block\n"));
 | 
				
			||||||
 | 
					        UNGRAB
 | 
				
			||||||
 | 
					        UPDATE
 | 
				
			||||||
 | 
					        return Z_STREAM_END;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->msg = (char*)"invalid literal/length code";
 | 
				
			||||||
 | 
					        UNGRAB
 | 
				
			||||||
 | 
					        UPDATE
 | 
				
			||||||
 | 
					        return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } while (1);
 | 
				
			||||||
 | 
					  } while (m >= 258 && n >= 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* not enough input or output--restore pointers and return */
 | 
				
			||||||
 | 
					  UNGRAB
 | 
				
			||||||
 | 
					  UPDATE
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17
									
								
								src/TZlib/Zip/inffast.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/TZlib/Zip/inffast.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					/* inffast.h -- header to use inffast.c
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_fast OF((
 | 
				
			||||||
 | 
					    uInt,
 | 
				
			||||||
 | 
					    uInt,
 | 
				
			||||||
 | 
					    inflate_huft *,
 | 
				
			||||||
 | 
					    inflate_huft *,
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp ));
 | 
				
			||||||
							
								
								
									
										151
									
								
								src/TZlib/Zip/inffixed.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								src/TZlib/Zip/inffixed.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,151 @@
 | 
				
			|||||||
 | 
					/* inffixed.h -- table for decoding fixed codes
 | 
				
			||||||
 | 
					 * Generated automatically by the maketree.c program
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local uInt fixed_bl = 9;
 | 
				
			||||||
 | 
					local uInt fixed_bd = 5;
 | 
				
			||||||
 | 
					local inflate_huft fixed_tl[] = {
 | 
				
			||||||
 | 
					    {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
 | 
				
			||||||
 | 
					    {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
 | 
				
			||||||
 | 
					    {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
 | 
				
			||||||
 | 
					    {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
 | 
				
			||||||
 | 
					    {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
 | 
				
			||||||
 | 
					    {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
 | 
				
			||||||
 | 
					    {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
 | 
				
			||||||
 | 
					    {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
 | 
				
			||||||
 | 
					    {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
 | 
				
			||||||
 | 
					    {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
 | 
				
			||||||
 | 
					    {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
 | 
				
			||||||
 | 
					    {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
 | 
				
			||||||
 | 
					    {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
 | 
				
			||||||
 | 
					    {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
 | 
				
			||||||
 | 
					    {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
 | 
				
			||||||
 | 
					    {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
 | 
				
			||||||
 | 
					    {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
 | 
				
			||||||
 | 
					    {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
 | 
				
			||||||
 | 
					    {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
 | 
				
			||||||
 | 
					    {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
 | 
				
			||||||
 | 
					    {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
 | 
				
			||||||
 | 
					    {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
 | 
				
			||||||
 | 
					    {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
 | 
				
			||||||
 | 
					    {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
 | 
				
			||||||
 | 
					    {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
 | 
				
			||||||
 | 
					    {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
 | 
				
			||||||
 | 
					    {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
 | 
				
			||||||
 | 
					    {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
 | 
				
			||||||
 | 
					    {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
 | 
				
			||||||
 | 
					    {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
 | 
				
			||||||
 | 
					    {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
 | 
				
			||||||
 | 
					    {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
 | 
				
			||||||
 | 
					    {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
 | 
				
			||||||
 | 
					    {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
 | 
				
			||||||
 | 
					    {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
 | 
				
			||||||
 | 
					    {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
 | 
				
			||||||
 | 
					    {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
 | 
				
			||||||
 | 
					    {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
 | 
				
			||||||
 | 
					    {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
 | 
				
			||||||
 | 
					    {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
 | 
				
			||||||
 | 
					    {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
 | 
				
			||||||
 | 
					    {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
 | 
				
			||||||
 | 
					    {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
 | 
				
			||||||
 | 
					    {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
 | 
				
			||||||
 | 
					    {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
 | 
				
			||||||
 | 
					    {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
 | 
				
			||||||
 | 
					    {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
 | 
				
			||||||
 | 
					    {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
 | 
				
			||||||
 | 
					    {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
 | 
				
			||||||
 | 
					    {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
 | 
				
			||||||
 | 
					    {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
 | 
				
			||||||
 | 
					    {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
 | 
				
			||||||
 | 
					    {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
 | 
				
			||||||
 | 
					    {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
 | 
				
			||||||
 | 
					    {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
 | 
				
			||||||
 | 
					    {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
 | 
				
			||||||
 | 
					    {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
 | 
				
			||||||
 | 
					    {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
 | 
				
			||||||
 | 
					    {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
 | 
				
			||||||
 | 
					    {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
 | 
				
			||||||
 | 
					    {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
 | 
				
			||||||
 | 
					    {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
 | 
				
			||||||
 | 
					    {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
 | 
				
			||||||
 | 
					    {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
 | 
				
			||||||
 | 
					    {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
 | 
				
			||||||
 | 
					    {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
 | 
				
			||||||
 | 
					    {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
 | 
				
			||||||
 | 
					    {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
 | 
				
			||||||
 | 
					    {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
 | 
				
			||||||
 | 
					    {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
 | 
				
			||||||
 | 
					    {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
 | 
				
			||||||
 | 
					    {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
 | 
				
			||||||
 | 
					    {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
 | 
				
			||||||
 | 
					    {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
 | 
				
			||||||
 | 
					    {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
 | 
				
			||||||
 | 
					    {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
 | 
				
			||||||
 | 
					    {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
 | 
				
			||||||
 | 
					    {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
 | 
				
			||||||
 | 
					    {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
 | 
				
			||||||
 | 
					    {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
 | 
				
			||||||
 | 
					    {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
 | 
				
			||||||
 | 
					    {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
 | 
				
			||||||
 | 
					    {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
 | 
				
			||||||
 | 
					    {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
 | 
				
			||||||
 | 
					    {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
 | 
				
			||||||
 | 
					    {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
 | 
				
			||||||
 | 
					    {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
 | 
				
			||||||
 | 
					    {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
 | 
				
			||||||
 | 
					    {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
 | 
				
			||||||
 | 
					    {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
 | 
				
			||||||
 | 
					    {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
 | 
				
			||||||
 | 
					    {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
 | 
				
			||||||
 | 
					    {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
 | 
				
			||||||
 | 
					    {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
 | 
				
			||||||
 | 
					    {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
 | 
				
			||||||
 | 
					    {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
 | 
				
			||||||
 | 
					    {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
 | 
				
			||||||
 | 
					    {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
 | 
				
			||||||
 | 
					    {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
 | 
				
			||||||
 | 
					    {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
 | 
				
			||||||
 | 
					    {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
 | 
				
			||||||
 | 
					    {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
 | 
				
			||||||
 | 
					    {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
 | 
				
			||||||
 | 
					    {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
 | 
				
			||||||
 | 
					    {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
 | 
				
			||||||
 | 
					    {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
 | 
				
			||||||
 | 
					    {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
 | 
				
			||||||
 | 
					    {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
 | 
				
			||||||
 | 
					    {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
 | 
				
			||||||
 | 
					    {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
 | 
				
			||||||
 | 
					    {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
 | 
				
			||||||
 | 
					    {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
 | 
				
			||||||
 | 
					    {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
 | 
				
			||||||
 | 
					    {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
 | 
				
			||||||
 | 
					    {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
 | 
				
			||||||
 | 
					    {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
 | 
				
			||||||
 | 
					    {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
 | 
				
			||||||
 | 
					    {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
 | 
				
			||||||
 | 
					    {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
 | 
				
			||||||
 | 
					    {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
 | 
				
			||||||
 | 
					    {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
 | 
				
			||||||
 | 
					    {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
 | 
				
			||||||
 | 
					    {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
 | 
				
			||||||
 | 
					    {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
 | 
				
			||||||
 | 
					    {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
 | 
				
			||||||
 | 
					    {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
 | 
				
			||||||
 | 
					    {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
 | 
				
			||||||
 | 
					    {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					local inflate_huft fixed_td[] = {
 | 
				
			||||||
 | 
					    {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
 | 
				
			||||||
 | 
					    {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
 | 
				
			||||||
 | 
					    {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
 | 
				
			||||||
 | 
					    {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
 | 
				
			||||||
 | 
					    {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
 | 
				
			||||||
 | 
					    {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
 | 
				
			||||||
 | 
					    {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
 | 
				
			||||||
 | 
					    {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
							
								
								
									
										366
									
								
								src/TZlib/Zip/inflate.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										366
									
								
								src/TZlib/Zip/inflate.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,366 @@
 | 
				
			|||||||
 | 
					/* inflate.c -- zlib interface to inflate modules
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "infblock.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					      METHOD,   /* waiting for method byte */
 | 
				
			||||||
 | 
					      FLAG,     /* waiting for flag byte */
 | 
				
			||||||
 | 
					      DICT4,    /* four dictionary check bytes to go */
 | 
				
			||||||
 | 
					      DICT3,    /* three dictionary check bytes to go */
 | 
				
			||||||
 | 
					      DICT2,    /* two dictionary check bytes to go */
 | 
				
			||||||
 | 
					      DICT1,    /* one dictionary check byte to go */
 | 
				
			||||||
 | 
					      DICT0,    /* waiting for inflateSetDictionary */
 | 
				
			||||||
 | 
					      BLOCKS,   /* decompressing blocks */
 | 
				
			||||||
 | 
					      CHECK4,   /* four check bytes to go */
 | 
				
			||||||
 | 
					      CHECK3,   /* three check bytes to go */
 | 
				
			||||||
 | 
					      CHECK2,   /* two check bytes to go */
 | 
				
			||||||
 | 
					      CHECK1,   /* one check byte to go */
 | 
				
			||||||
 | 
					      DONE,     /* finished check, done */
 | 
				
			||||||
 | 
					      BAD}      /* got an error--stay here */
 | 
				
			||||||
 | 
					inflate_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inflate private state */
 | 
				
			||||||
 | 
					struct internal_state {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode */
 | 
				
			||||||
 | 
					  inflate_mode  mode;   /* current inflate mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode dependent information */
 | 
				
			||||||
 | 
					  union {
 | 
				
			||||||
 | 
					    uInt method;        /* if FLAGS, method byte */
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      uLong was;                /* computed check value */
 | 
				
			||||||
 | 
					      uLong need;               /* stream check value */
 | 
				
			||||||
 | 
					    } check;            /* if CHECK, check values to compare */
 | 
				
			||||||
 | 
					    uInt marker;        /* if BAD, inflateSync's marker bytes count */
 | 
				
			||||||
 | 
					  } sub;        /* submode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode independent information */
 | 
				
			||||||
 | 
					  int  nowrap;          /* flag for no wrapper */
 | 
				
			||||||
 | 
					  uInt wbits;           /* log2(window size)  (8..15, defaults to 15) */
 | 
				
			||||||
 | 
					  inflate_blocks_statef 
 | 
				
			||||||
 | 
					    *blocks;            /* current inflate_blocks state */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateReset(z)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  z->total_in = z->total_out = 0;
 | 
				
			||||||
 | 
					  z->msg = Z_NULL;
 | 
				
			||||||
 | 
					  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
 | 
				
			||||||
 | 
					  inflate_blocks_reset(z->state->blocks, z, Z_NULL);
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate: reset\n"));
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateEnd(z)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  if (z->state->blocks != Z_NULL)
 | 
				
			||||||
 | 
					    inflate_blocks_free(z->state->blocks, z);
 | 
				
			||||||
 | 
					  ZFREE(z, z->state);
 | 
				
			||||||
 | 
					  z->state = Z_NULL;
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate: end\n"));
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateInit2_(z, w, version, stream_size)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					int w;
 | 
				
			||||||
 | 
					const char *version;
 | 
				
			||||||
 | 
					int stream_size;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
 | 
				
			||||||
 | 
					      stream_size != sizeof(z_stream))
 | 
				
			||||||
 | 
					      return Z_VERSION_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* initialize state */
 | 
				
			||||||
 | 
					  if (z == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  z->msg = Z_NULL;
 | 
				
			||||||
 | 
					  if (z->zalloc == Z_NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    z->zalloc = zcalloc;
 | 
				
			||||||
 | 
					    z->opaque = (voidpf)0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (z->zfree == Z_NULL) z->zfree = zcfree;
 | 
				
			||||||
 | 
					  if ((z->state = (struct internal_state FAR *)
 | 
				
			||||||
 | 
					       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					  z->state->blocks = Z_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* handle undocumented nowrap option (no zlib header or check) */
 | 
				
			||||||
 | 
					  z->state->nowrap = 0;
 | 
				
			||||||
 | 
					  if (w < 0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    w = - w;
 | 
				
			||||||
 | 
					    z->state->nowrap = 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* set window size */
 | 
				
			||||||
 | 
					  if (w < 8 || w > 15)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    inflateEnd(z);
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  z->state->wbits = (uInt)w;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* create inflate_blocks state */
 | 
				
			||||||
 | 
					  if ((z->state->blocks =
 | 
				
			||||||
 | 
					      inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
 | 
				
			||||||
 | 
					      == Z_NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    inflateEnd(z);
 | 
				
			||||||
 | 
					    return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  Tracev((stderr, "inflate: allocated\n"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* reset state */
 | 
				
			||||||
 | 
					  inflateReset(z);
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateInit_(z, version, stream_size)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					const char *version;
 | 
				
			||||||
 | 
					int stream_size;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return inflateInit2_(z, DEF_WBITS, version, stream_size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
 | 
				
			||||||
 | 
					#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflate(z, f)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					int f;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int r;
 | 
				
			||||||
 | 
					  uInt b;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
 | 
				
			||||||
 | 
					  r = Z_BUF_ERROR;
 | 
				
			||||||
 | 
					  while (1) switch (z->state->mode)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    case METHOD:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"unknown compression method";
 | 
				
			||||||
 | 
					        z->state->sub.marker = 5;       /* can't try inflateSync */
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"invalid window size";
 | 
				
			||||||
 | 
					        z->state->sub.marker = 5;       /* can't try inflateSync */
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      z->state->mode = FLAG;
 | 
				
			||||||
 | 
					    case FLAG:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      b = NEXTBYTE;
 | 
				
			||||||
 | 
					      if (((z->state->sub.method << 8) + b) % 31)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"incorrect header check";
 | 
				
			||||||
 | 
					        z->state->sub.marker = 5;       /* can't try inflateSync */
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate: zlib header ok\n"));
 | 
				
			||||||
 | 
					      if (!(b & PRESET_DICT))
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BLOCKS;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      z->state->mode = DICT4;
 | 
				
			||||||
 | 
					    case DICT4:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
 | 
				
			||||||
 | 
					      z->state->mode = DICT3;
 | 
				
			||||||
 | 
					    case DICT3:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
 | 
				
			||||||
 | 
					      z->state->mode = DICT2;
 | 
				
			||||||
 | 
					    case DICT2:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
 | 
				
			||||||
 | 
					      z->state->mode = DICT1;
 | 
				
			||||||
 | 
					    case DICT1:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE;
 | 
				
			||||||
 | 
					      z->adler = z->state->sub.check.need;
 | 
				
			||||||
 | 
					      z->state->mode = DICT0;
 | 
				
			||||||
 | 
					      return Z_NEED_DICT;
 | 
				
			||||||
 | 
					    case DICT0:
 | 
				
			||||||
 | 
					      z->state->mode = BAD;
 | 
				
			||||||
 | 
					      z->msg = (char*)"need dictionary";
 | 
				
			||||||
 | 
					      z->state->sub.marker = 0;       /* can try inflateSync */
 | 
				
			||||||
 | 
					      return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					    case BLOCKS:
 | 
				
			||||||
 | 
					      r = inflate_blocks(z->state->blocks, z, r);
 | 
				
			||||||
 | 
					      if (r == Z_DATA_ERROR)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BAD;
 | 
				
			||||||
 | 
					        z->state->sub.marker = 0;       /* can try inflateSync */
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (r == Z_OK)
 | 
				
			||||||
 | 
					        r = f;
 | 
				
			||||||
 | 
					      if (r != Z_STREAM_END)
 | 
				
			||||||
 | 
					        return r;
 | 
				
			||||||
 | 
					      r = f;
 | 
				
			||||||
 | 
					      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
 | 
				
			||||||
 | 
					      if (z->state->nowrap)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = DONE;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      z->state->mode = CHECK4;
 | 
				
			||||||
 | 
					    case CHECK4:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
 | 
				
			||||||
 | 
					      z->state->mode = CHECK3;
 | 
				
			||||||
 | 
					    case CHECK3:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
 | 
				
			||||||
 | 
					      z->state->mode = CHECK2;
 | 
				
			||||||
 | 
					    case CHECK2:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
 | 
				
			||||||
 | 
					      z->state->mode = CHECK1;
 | 
				
			||||||
 | 
					    case CHECK1:
 | 
				
			||||||
 | 
					      NEEDBYTE
 | 
				
			||||||
 | 
					      z->state->sub.check.need += (uLong)NEXTBYTE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (z->state->sub.check.was != z->state->sub.check.need)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        z->state->mode = BAD;
 | 
				
			||||||
 | 
					        z->msg = (char*)"incorrect data check";
 | 
				
			||||||
 | 
					        z->state->sub.marker = 5;       /* can't try inflateSync */
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      Tracev((stderr, "inflate: zlib check ok\n"));
 | 
				
			||||||
 | 
					      z->state->mode = DONE;
 | 
				
			||||||
 | 
					    case DONE:
 | 
				
			||||||
 | 
					      return Z_STREAM_END;
 | 
				
			||||||
 | 
					    case BAD:
 | 
				
			||||||
 | 
					      return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					      return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#ifdef NEED_DUMMY_RETURN
 | 
				
			||||||
 | 
					  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					const Bytef *dictionary;
 | 
				
			||||||
 | 
					uInt  dictLength;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uInt length = dictLength;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					  z->adler = 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (length >= ((uInt)1<<z->state->wbits))
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    length = (1<<z->state->wbits)-1;
 | 
				
			||||||
 | 
					    dictionary += dictLength - length;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  inflate_set_dictionary(z->state->blocks, dictionary, length);
 | 
				
			||||||
 | 
					  z->state->mode = BLOCKS;
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ZEXPORT inflateSync(z)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uInt n;       /* number of bytes to look at */
 | 
				
			||||||
 | 
					  Bytef *p;     /* pointer to bytes */
 | 
				
			||||||
 | 
					  uInt m;       /* number of marker bytes found in a row */
 | 
				
			||||||
 | 
					  uLong r, w;   /* temporaries to save total_in and total_out */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* set up */
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  if (z->state->mode != BAD)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    z->state->mode = BAD;
 | 
				
			||||||
 | 
					    z->state->sub.marker = 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if ((n = z->avail_in) == 0)
 | 
				
			||||||
 | 
					    return Z_BUF_ERROR;
 | 
				
			||||||
 | 
					  p = z->next_in;
 | 
				
			||||||
 | 
					  m = z->state->sub.marker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* search */
 | 
				
			||||||
 | 
					  while (n && m < 4)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    static const Byte mark[4] = {0, 0, 0xff, 0xff};
 | 
				
			||||||
 | 
					    if (*p == mark[m])
 | 
				
			||||||
 | 
					      m++;
 | 
				
			||||||
 | 
					    else if (*p)
 | 
				
			||||||
 | 
					      m = 0;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      m = 4 - m;
 | 
				
			||||||
 | 
					    p++, n--;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* restore */
 | 
				
			||||||
 | 
					  z->total_in += p - z->next_in;
 | 
				
			||||||
 | 
					  z->next_in = p;
 | 
				
			||||||
 | 
					  z->avail_in = n;
 | 
				
			||||||
 | 
					  z->state->sub.marker = m;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* return no joy or set up to restart on a new block */
 | 
				
			||||||
 | 
					  if (m != 4)
 | 
				
			||||||
 | 
					    return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					  r = z->total_in;  w = z->total_out;
 | 
				
			||||||
 | 
					  inflateReset(z);
 | 
				
			||||||
 | 
					  z->total_in = r;  z->total_out = w;
 | 
				
			||||||
 | 
					  z->state->mode = BLOCKS;
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Returns true if inflate is currently at the end of a block generated
 | 
				
			||||||
 | 
					 * by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 | 
				
			||||||
 | 
					 * implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
 | 
				
			||||||
 | 
					 * but removes the length bytes of the resulting empty stored block. When
 | 
				
			||||||
 | 
					 * decompressing, PPP checks that at the end of input packet, inflate is
 | 
				
			||||||
 | 
					 * waiting for these length bytes.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int ZEXPORT inflateSyncPoint(z)
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_STREAM_ERROR;
 | 
				
			||||||
 | 
					  return inflate_blocks_sync_point(z->state->blocks);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										454
									
								
								src/TZlib/Zip/inftrees.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										454
									
								
								src/TZlib/Zip/inftrees.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,454 @@
 | 
				
			|||||||
 | 
					/* inftrees.c -- generate Huffman trees for efficient decoding
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(BUILDFIXED) && !defined(STDC)
 | 
				
			||||||
 | 
					#  define BUILDFIXED   /* non ANSI compilers may not accept inffixed.h */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const char inflate_copyright[] =
 | 
				
			||||||
 | 
					   " inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					  If you use the zlib library in a product, an acknowledgment is welcome
 | 
				
			||||||
 | 
					  in the documentation of your product. If for some reason you cannot
 | 
				
			||||||
 | 
					  include such an acknowledgment, I would appreciate that you keep this
 | 
				
			||||||
 | 
					  copyright string in the executable of your product.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct internal_state  {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* simplify the use of the inflate_huft type with some defines */
 | 
				
			||||||
 | 
					#define exop word.what.Exop
 | 
				
			||||||
 | 
					#define bits word.what.Bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local int huft_build OF((
 | 
				
			||||||
 | 
					    uIntf *,            /* code lengths in bits */
 | 
				
			||||||
 | 
					    uInt,               /* number of codes */
 | 
				
			||||||
 | 
					    uInt,               /* number of "simple" codes */
 | 
				
			||||||
 | 
					    const uIntf *,      /* list of base values for non-simple codes */
 | 
				
			||||||
 | 
					    const uIntf *,      /* list of extra bits for non-simple codes */
 | 
				
			||||||
 | 
					    inflate_huft * FAR*,/* result: starting table */
 | 
				
			||||||
 | 
					    uIntf *,            /* maximum lookup bits (returns actual) */
 | 
				
			||||||
 | 
					    inflate_huft *,     /* space for trees */
 | 
				
			||||||
 | 
					    uInt *,             /* hufts used in space */
 | 
				
			||||||
 | 
					    uIntf * ));         /* space for values */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Tables for deflate from PKZIP's appnote.txt. */
 | 
				
			||||||
 | 
					local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
 | 
				
			||||||
 | 
					        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
 | 
				
			||||||
 | 
					        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
 | 
				
			||||||
 | 
					        /* see note #13 above about 258 */
 | 
				
			||||||
 | 
					local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
 | 
				
			||||||
 | 
					        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
 | 
				
			||||||
 | 
					        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
 | 
				
			||||||
 | 
					local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
 | 
				
			||||||
 | 
					        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
 | 
				
			||||||
 | 
					        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
 | 
				
			||||||
 | 
					        8193, 12289, 16385, 24577};
 | 
				
			||||||
 | 
					local const uInt cpdext[30] = { /* Extra bits for distance codes */
 | 
				
			||||||
 | 
					        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
 | 
				
			||||||
 | 
					        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
 | 
				
			||||||
 | 
					        12, 12, 13, 13};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					   Huffman code decoding is performed using a multi-level table lookup.
 | 
				
			||||||
 | 
					   The fastest way to decode is to simply build a lookup table whose
 | 
				
			||||||
 | 
					   size is determined by the longest code.  However, the time it takes
 | 
				
			||||||
 | 
					   to build this table can also be a factor if the data being decoded
 | 
				
			||||||
 | 
					   is not very long.  The most common codes are necessarily the
 | 
				
			||||||
 | 
					   shortest codes, so those codes dominate the decoding time, and hence
 | 
				
			||||||
 | 
					   the speed.  The idea is you can have a shorter table that decodes the
 | 
				
			||||||
 | 
					   shorter, more probable codes, and then point to subsidiary tables for
 | 
				
			||||||
 | 
					   the longer codes.  The time it costs to decode the longer codes is
 | 
				
			||||||
 | 
					   then traded against the time it takes to make longer tables.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   This results of this trade are in the variables lbits and dbits
 | 
				
			||||||
 | 
					   below.  lbits is the number of bits the first level table for literal/
 | 
				
			||||||
 | 
					   length codes can decode in one step, and dbits is the same thing for
 | 
				
			||||||
 | 
					   the distance codes.  Subsequent tables are also less than or equal to
 | 
				
			||||||
 | 
					   those sizes.  These values may be adjusted either when all of the
 | 
				
			||||||
 | 
					   codes are shorter than that, in which case the longest code length in
 | 
				
			||||||
 | 
					   bits is used, or when the shortest code is *longer* than the requested
 | 
				
			||||||
 | 
					   table size, in which case the length of the shortest code in bits is
 | 
				
			||||||
 | 
					   used.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   There are two different values for the two tables, since they code a
 | 
				
			||||||
 | 
					   different number of possibilities each.  The literal/length table
 | 
				
			||||||
 | 
					   codes 286 possible values, or in a flat code, a little over eight
 | 
				
			||||||
 | 
					   bits.  The distance table codes 30 possible values, or a little less
 | 
				
			||||||
 | 
					   than five bits, flat.  The optimum values for speed end up being
 | 
				
			||||||
 | 
					   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
 | 
				
			||||||
 | 
					   The optimum values may differ though from machine to machine, and
 | 
				
			||||||
 | 
					   possibly even between compilers.  Your mileage may vary.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
 | 
				
			||||||
 | 
					#define BMAX 15         /* maximum bit length of any code */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
 | 
				
			||||||
 | 
					uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
 | 
				
			||||||
 | 
					uInt n;                 /* number of codes (assumed <= 288) */
 | 
				
			||||||
 | 
					uInt s;                 /* number of simple-valued codes (0..s-1) */
 | 
				
			||||||
 | 
					const uIntf *d;         /* list of base values for non-simple codes */
 | 
				
			||||||
 | 
					const uIntf *e;         /* list of extra bits for non-simple codes */
 | 
				
			||||||
 | 
					inflate_huft * FAR *t;  /* result: starting table */
 | 
				
			||||||
 | 
					uIntf *m;               /* maximum lookup bits, returns actual */
 | 
				
			||||||
 | 
					inflate_huft *hp;       /* space for trees */
 | 
				
			||||||
 | 
					uInt *hn;               /* hufts used in space */
 | 
				
			||||||
 | 
					uIntf *v;               /* working area: values in order of bit length */
 | 
				
			||||||
 | 
					/* Given a list of code lengths and a maximum table size, make a set of
 | 
				
			||||||
 | 
					   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
 | 
				
			||||||
 | 
					   if the given code set is incomplete (the tables are still built in this
 | 
				
			||||||
 | 
					   case), or Z_DATA_ERROR if the input is invalid. */
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  uInt a;                       /* counter for codes of length k */
 | 
				
			||||||
 | 
					  uInt c[BMAX+1];               /* bit length count table */
 | 
				
			||||||
 | 
					  uInt f;                       /* i repeats in table every f entries */
 | 
				
			||||||
 | 
					  int g;                        /* maximum code length */
 | 
				
			||||||
 | 
					  int h;                        /* table level */
 | 
				
			||||||
 | 
					  register uInt i;              /* counter, current code */
 | 
				
			||||||
 | 
					  register uInt j;              /* counter */
 | 
				
			||||||
 | 
					  register int k;               /* number of bits in current code */
 | 
				
			||||||
 | 
					  int l;                        /* bits per table (returned in m) */
 | 
				
			||||||
 | 
					  uInt mask;                    /* (1 << w) - 1, to avoid cc -O bug on HP */
 | 
				
			||||||
 | 
					  register uIntf *p;            /* pointer into c[], b[], or v[] */
 | 
				
			||||||
 | 
					  inflate_huft *q;              /* points to current table */
 | 
				
			||||||
 | 
					  struct inflate_huft_s r;      /* table entry for structure assignment */
 | 
				
			||||||
 | 
					  inflate_huft *u[BMAX];        /* table stack */
 | 
				
			||||||
 | 
					  register int w;               /* bits before this table == (l * h) */
 | 
				
			||||||
 | 
					  uInt x[BMAX+1];               /* bit offsets, then code stack */
 | 
				
			||||||
 | 
					  uIntf *xp;                    /* pointer into x */
 | 
				
			||||||
 | 
					  int y;                        /* number of dummy codes added */
 | 
				
			||||||
 | 
					  uInt z;                       /* number of entries in current table */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Generate counts for each bit length */
 | 
				
			||||||
 | 
					  p = c;
 | 
				
			||||||
 | 
					#define C0 *p++ = 0;
 | 
				
			||||||
 | 
					#define C2 C0 C0 C0 C0
 | 
				
			||||||
 | 
					#define C4 C2 C2 C2 C2
 | 
				
			||||||
 | 
					  C4                            /* clear c[]--assume BMAX+1 is 16 */
 | 
				
			||||||
 | 
					  p = b;  i = n;
 | 
				
			||||||
 | 
					  do {
 | 
				
			||||||
 | 
					    c[*p++]++;                  /* assume all entries <= BMAX */
 | 
				
			||||||
 | 
					  } while (--i);
 | 
				
			||||||
 | 
					  if (c[0] == n)                /* null input--all zero length codes */
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    *t = (inflate_huft *)Z_NULL;
 | 
				
			||||||
 | 
					    *m = 0;
 | 
				
			||||||
 | 
					    return Z_OK;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Find minimum and maximum length, bound *m by those */
 | 
				
			||||||
 | 
					  l = *m;
 | 
				
			||||||
 | 
					  for (j = 1; j <= BMAX; j++)
 | 
				
			||||||
 | 
					    if (c[j])
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					  k = j;                        /* minimum code length */
 | 
				
			||||||
 | 
					  if ((uInt)l < j)
 | 
				
			||||||
 | 
					    l = j;
 | 
				
			||||||
 | 
					  for (i = BMAX; i; i--)
 | 
				
			||||||
 | 
					    if (c[i])
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					  g = i;                        /* maximum code length */
 | 
				
			||||||
 | 
					  if ((uInt)l > i)
 | 
				
			||||||
 | 
					    l = i;
 | 
				
			||||||
 | 
					  *m = l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Adjust last length count to fill out codes, if needed */
 | 
				
			||||||
 | 
					  for (y = 1 << j; j < i; j++, y <<= 1)
 | 
				
			||||||
 | 
					    if ((y -= c[j]) < 0)
 | 
				
			||||||
 | 
					      return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					  if ((y -= c[i]) < 0)
 | 
				
			||||||
 | 
					    return Z_DATA_ERROR;
 | 
				
			||||||
 | 
					  c[i] += y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Generate starting offsets into the value table for each length */
 | 
				
			||||||
 | 
					  x[1] = j = 0;
 | 
				
			||||||
 | 
					  p = c + 1;  xp = x + 2;
 | 
				
			||||||
 | 
					  while (--i) {                 /* note that i == g from above */
 | 
				
			||||||
 | 
					    *xp++ = (j += *p++);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Make a table of values in order of bit lengths */
 | 
				
			||||||
 | 
					  p = b;  i = 0;
 | 
				
			||||||
 | 
					  do {
 | 
				
			||||||
 | 
					    if ((j = *p++) != 0)
 | 
				
			||||||
 | 
					      v[x[j]++] = i;
 | 
				
			||||||
 | 
					  } while (++i < n);
 | 
				
			||||||
 | 
					  n = x[g];                     /* set n to length of v */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Generate the Huffman codes and for each, make the table entries */
 | 
				
			||||||
 | 
					  x[0] = i = 0;                 /* first Huffman code is zero */
 | 
				
			||||||
 | 
					  p = v;                        /* grab values in bit order */
 | 
				
			||||||
 | 
					  h = -1;                       /* no tables yet--level -1 */
 | 
				
			||||||
 | 
					  w = -l;                       /* bits decoded == (l * h) */
 | 
				
			||||||
 | 
					  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
 | 
				
			||||||
 | 
					  q = (inflate_huft *)Z_NULL;   /* ditto */
 | 
				
			||||||
 | 
					  z = 0;                        /* ditto */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* go through the bit lengths (k already is bits in shortest code) */
 | 
				
			||||||
 | 
					  for (; k <= g; k++)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    a = c[k];
 | 
				
			||||||
 | 
					    while (a--)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      /* here i is the Huffman code of length k bits for value *p */
 | 
				
			||||||
 | 
					      /* make tables up to required level */
 | 
				
			||||||
 | 
					      while (k > w + l)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        h++;
 | 
				
			||||||
 | 
					        w += l;                 /* previous table always l bits */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* compute minimum size table less than or equal to l bits */
 | 
				
			||||||
 | 
					        z = g - w;
 | 
				
			||||||
 | 
					        z = z > (uInt)l ? l : z;        /* table size upper limit */
 | 
				
			||||||
 | 
					        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
 | 
				
			||||||
 | 
					        {                       /* too few codes for k-w bit table */
 | 
				
			||||||
 | 
					          f -= a + 1;           /* deduct codes from patterns left */
 | 
				
			||||||
 | 
					          xp = c + k;
 | 
				
			||||||
 | 
					          if (j < z)
 | 
				
			||||||
 | 
					            while (++j < z)     /* try smaller tables up to z bits */
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              if ((f <<= 1) <= *++xp)
 | 
				
			||||||
 | 
					                break;          /* enough codes to use up j bits */
 | 
				
			||||||
 | 
					              f -= *xp;         /* else deduct codes from patterns */
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        z = 1 << j;             /* table entries for j-bit table */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* allocate new table */
 | 
				
			||||||
 | 
					        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
 | 
				
			||||||
 | 
					          return Z_DATA_ERROR;  /* overflow of MANY */
 | 
				
			||||||
 | 
					        u[h] = q = hp + *hn;
 | 
				
			||||||
 | 
					        *hn += z;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* connect to last table, if there is one */
 | 
				
			||||||
 | 
					        if (h)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          x[h] = i;             /* save pattern for backing up */
 | 
				
			||||||
 | 
					          r.bits = (Byte)l;     /* bits to dump before this table */
 | 
				
			||||||
 | 
					          r.exop = (Byte)j;     /* bits in this table */
 | 
				
			||||||
 | 
					          j = i >> (w - l);
 | 
				
			||||||
 | 
					          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
 | 
				
			||||||
 | 
					          u[h-1][j] = r;        /* connect to last table */
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          *t = q;               /* first table is returned result */
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* set up table entry in r */
 | 
				
			||||||
 | 
					      r.bits = (Byte)(k - w);
 | 
				
			||||||
 | 
					      if (p >= v + n)
 | 
				
			||||||
 | 
					        r.exop = 128 + 64;      /* out of values--invalid code */
 | 
				
			||||||
 | 
					      else if (*p < s)
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
 | 
				
			||||||
 | 
					        r.base = *p++;          /* simple code is just the value */
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
 | 
				
			||||||
 | 
					        r.base = d[*p++ - s];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* fill code-like entries with r */
 | 
				
			||||||
 | 
					      f = 1 << (k - w);
 | 
				
			||||||
 | 
					      for (j = i >> w; j < z; j += f)
 | 
				
			||||||
 | 
					        q[j] = r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* backwards increment the k-bit code i */
 | 
				
			||||||
 | 
					      for (j = 1 << (k - 1); i & j; j >>= 1)
 | 
				
			||||||
 | 
					        i ^= j;
 | 
				
			||||||
 | 
					      i ^= j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* backup over finished tables */
 | 
				
			||||||
 | 
					      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
 | 
				
			||||||
 | 
					      while ((i & mask) != x[h])
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        h--;                    /* don't need to update q */
 | 
				
			||||||
 | 
					        w -= l;
 | 
				
			||||||
 | 
					        mask = (1 << w) - 1;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* Return Z_BUF_ERROR if we were given an incomplete table */
 | 
				
			||||||
 | 
					  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_trees_bits(c, bb, tb, hp, z)
 | 
				
			||||||
 | 
					uIntf *c;               /* 19 code lengths */
 | 
				
			||||||
 | 
					uIntf *bb;              /* bits tree desired/actual depth */
 | 
				
			||||||
 | 
					inflate_huft * FAR *tb; /* bits tree result */
 | 
				
			||||||
 | 
					inflate_huft *hp;       /* space for trees */
 | 
				
			||||||
 | 
					z_streamp z;            /* for messages */
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int r;
 | 
				
			||||||
 | 
					  uInt hn = 0;          /* hufts used in space */
 | 
				
			||||||
 | 
					  uIntf *v;             /* work area for huft_build */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
 | 
				
			||||||
 | 
					                 tb, bb, hp, &hn, v);
 | 
				
			||||||
 | 
					  if (r == Z_DATA_ERROR)
 | 
				
			||||||
 | 
					    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
 | 
				
			||||||
 | 
					  else if (r == Z_BUF_ERROR || *bb == 0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    z->msg = (char*)"incomplete dynamic bit lengths tree";
 | 
				
			||||||
 | 
					    r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ZFREE(z, v);
 | 
				
			||||||
 | 
					  return r;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
 | 
				
			||||||
 | 
					uInt nl;                /* number of literal/length codes */
 | 
				
			||||||
 | 
					uInt nd;                /* number of distance codes */
 | 
				
			||||||
 | 
					uIntf *c;               /* that many (total) code lengths */
 | 
				
			||||||
 | 
					uIntf *bl;              /* literal desired/actual bit depth */
 | 
				
			||||||
 | 
					uIntf *bd;              /* distance desired/actual bit depth */
 | 
				
			||||||
 | 
					inflate_huft * FAR *tl; /* literal/length tree result */
 | 
				
			||||||
 | 
					inflate_huft * FAR *td; /* distance tree result */
 | 
				
			||||||
 | 
					inflate_huft *hp;       /* space for trees */
 | 
				
			||||||
 | 
					z_streamp z;            /* for messages */
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int r;
 | 
				
			||||||
 | 
					  uInt hn = 0;          /* hufts used in space */
 | 
				
			||||||
 | 
					  uIntf *v;             /* work area for huft_build */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* allocate work area */
 | 
				
			||||||
 | 
					  if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
 | 
				
			||||||
 | 
					    return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* build literal/length tree */
 | 
				
			||||||
 | 
					  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
 | 
				
			||||||
 | 
					  if (r != Z_OK || *bl == 0)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (r == Z_DATA_ERROR)
 | 
				
			||||||
 | 
					      z->msg = (char*)"oversubscribed literal/length tree";
 | 
				
			||||||
 | 
					    else if (r != Z_MEM_ERROR)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      z->msg = (char*)"incomplete literal/length tree";
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ZFREE(z, v);
 | 
				
			||||||
 | 
					    return r;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* build distance tree */
 | 
				
			||||||
 | 
					  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
 | 
				
			||||||
 | 
					  if (r != Z_OK || (*bd == 0 && nl > 257))
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (r == Z_DATA_ERROR)
 | 
				
			||||||
 | 
					      z->msg = (char*)"oversubscribed distance tree";
 | 
				
			||||||
 | 
					    else if (r == Z_BUF_ERROR) {
 | 
				
			||||||
 | 
					#ifdef PKZIP_BUG_WORKAROUND
 | 
				
			||||||
 | 
					      r = Z_OK;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					      z->msg = (char*)"incomplete distance tree";
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (r != Z_MEM_ERROR)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      z->msg = (char*)"empty distance tree with lengths";
 | 
				
			||||||
 | 
					      r = Z_DATA_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ZFREE(z, v);
 | 
				
			||||||
 | 
					    return r;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* done */
 | 
				
			||||||
 | 
					  ZFREE(z, v);
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* build fixed tables only once--keep them here */
 | 
				
			||||||
 | 
					#ifdef BUILDFIXED
 | 
				
			||||||
 | 
					local int fixed_built = 0;
 | 
				
			||||||
 | 
					#define FIXEDH 544      /* number of hufts used by fixed tables */
 | 
				
			||||||
 | 
					local inflate_huft fixed_mem[FIXEDH];
 | 
				
			||||||
 | 
					local uInt fixed_bl;
 | 
				
			||||||
 | 
					local uInt fixed_bd;
 | 
				
			||||||
 | 
					local inflate_huft *fixed_tl;
 | 
				
			||||||
 | 
					local inflate_huft *fixed_td;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#include "inffixed.h"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int inflate_trees_fixed(bl, bd, tl, td, z)
 | 
				
			||||||
 | 
					uIntf *bl;               /* literal desired/actual bit depth */
 | 
				
			||||||
 | 
					uIntf *bd;               /* distance desired/actual bit depth */
 | 
				
			||||||
 | 
					inflate_huft * FAR *tl;  /* literal/length tree result */
 | 
				
			||||||
 | 
					inflate_huft * FAR *td;  /* distance tree result */
 | 
				
			||||||
 | 
					z_streamp z;             /* for memory allocation */
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#ifdef BUILDFIXED
 | 
				
			||||||
 | 
					  /* build fixed tables if not already */
 | 
				
			||||||
 | 
					  if (!fixed_built)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    int k;              /* temporary variable */
 | 
				
			||||||
 | 
					    uInt f = 0;         /* number of hufts used in fixed_mem */
 | 
				
			||||||
 | 
					    uIntf *c;           /* length list for huft_build */
 | 
				
			||||||
 | 
					    uIntf *v;           /* work area for huft_build */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* allocate memory */
 | 
				
			||||||
 | 
					    if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
 | 
				
			||||||
 | 
					      return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					    if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      ZFREE(z, c);
 | 
				
			||||||
 | 
					      return Z_MEM_ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* literal table */
 | 
				
			||||||
 | 
					    for (k = 0; k < 144; k++)
 | 
				
			||||||
 | 
					      c[k] = 8;
 | 
				
			||||||
 | 
					    for (; k < 256; k++)
 | 
				
			||||||
 | 
					      c[k] = 9;
 | 
				
			||||||
 | 
					    for (; k < 280; k++)
 | 
				
			||||||
 | 
					      c[k] = 7;
 | 
				
			||||||
 | 
					    for (; k < 288; k++)
 | 
				
			||||||
 | 
					      c[k] = 8;
 | 
				
			||||||
 | 
					    fixed_bl = 9;
 | 
				
			||||||
 | 
					    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
 | 
				
			||||||
 | 
					               fixed_mem, &f, v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* distance table */
 | 
				
			||||||
 | 
					    for (k = 0; k < 30; k++)
 | 
				
			||||||
 | 
					      c[k] = 5;
 | 
				
			||||||
 | 
					    fixed_bd = 5;
 | 
				
			||||||
 | 
					    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
 | 
				
			||||||
 | 
					               fixed_mem, &f, v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* done */
 | 
				
			||||||
 | 
					    ZFREE(z, v);
 | 
				
			||||||
 | 
					    ZFREE(z, c);
 | 
				
			||||||
 | 
					    fixed_built = 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					  *bl = fixed_bl;
 | 
				
			||||||
 | 
					  *bd = fixed_bd;
 | 
				
			||||||
 | 
					  *tl = fixed_tl;
 | 
				
			||||||
 | 
					  *td = fixed_td;
 | 
				
			||||||
 | 
					  return Z_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										58
									
								
								src/TZlib/Zip/inftrees.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/TZlib/Zip/inftrees.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					/* inftrees.h -- header to use inftrees.c
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Huffman code lookup table entry--this entry is four bytes for machines
 | 
				
			||||||
 | 
					   that have 16-bit pointers (e.g. PC's in the small or medium model). */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct inflate_huft_s FAR inflate_huft;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_huft_s {
 | 
				
			||||||
 | 
					  union {
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      Byte Exop;        /* number of extra bits or operation */
 | 
				
			||||||
 | 
					      Byte Bits;        /* number of bits in this code or subcode */
 | 
				
			||||||
 | 
					    } what;
 | 
				
			||||||
 | 
					    uInt pad;           /* pad structure to a power of 2 (4 bytes for */
 | 
				
			||||||
 | 
					  } word;               /*  16-bit, 8 bytes for 32-bit int's) */
 | 
				
			||||||
 | 
					  uInt base;            /* literal, length base, distance base,
 | 
				
			||||||
 | 
					                           or table offset */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum size of dynamic tree.  The maximum found in a long but non-
 | 
				
			||||||
 | 
					   exhaustive search was 1004 huft structures (850 for length/literals
 | 
				
			||||||
 | 
					   and 154 for distances, the latter actually the result of an
 | 
				
			||||||
 | 
					   exhaustive search).  The actual maximum is not known, but the
 | 
				
			||||||
 | 
					   value below is more than safe. */
 | 
				
			||||||
 | 
					#define MANY 1440
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_trees_bits OF((
 | 
				
			||||||
 | 
					    uIntf *,                    /* 19 code lengths */
 | 
				
			||||||
 | 
					    uIntf *,                    /* bits tree desired/actual depth */
 | 
				
			||||||
 | 
					    inflate_huft * FAR *,       /* bits tree result */
 | 
				
			||||||
 | 
					    inflate_huft *,             /* space for trees */
 | 
				
			||||||
 | 
					    z_streamp));                /* for messages */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_trees_dynamic OF((
 | 
				
			||||||
 | 
					    uInt,                       /* number of literal/length codes */
 | 
				
			||||||
 | 
					    uInt,                       /* number of distance codes */
 | 
				
			||||||
 | 
					    uIntf *,                    /* that many (total) code lengths */
 | 
				
			||||||
 | 
					    uIntf *,                    /* literal desired/actual bit depth */
 | 
				
			||||||
 | 
					    uIntf *,                    /* distance desired/actual bit depth */
 | 
				
			||||||
 | 
					    inflate_huft * FAR *,       /* literal/length tree result */
 | 
				
			||||||
 | 
					    inflate_huft * FAR *,       /* distance tree result */
 | 
				
			||||||
 | 
					    inflate_huft *,             /* space for trees */
 | 
				
			||||||
 | 
					    z_streamp));                /* for messages */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int inflate_trees_fixed OF((
 | 
				
			||||||
 | 
					    uIntf *,                    /* literal desired/actual bit depth */
 | 
				
			||||||
 | 
					    uIntf *,                    /* distance desired/actual bit depth */
 | 
				
			||||||
 | 
					    inflate_huft * FAR *,       /* literal/length tree result */
 | 
				
			||||||
 | 
					    inflate_huft * FAR *,       /* distance tree result */
 | 
				
			||||||
 | 
					    z_streamp));                /* for memory allocation */
 | 
				
			||||||
							
								
								
									
										87
									
								
								src/TZlib/Zip/infutil.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								src/TZlib/Zip/infutil.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					/* inflate_util.c -- data and routines common to blocks and codes
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "infblock.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					#include "infcodes.h"
 | 
				
			||||||
 | 
					#include "infutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inflate_codes_state {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* And'ing with mask[n] masks the lower n bits */
 | 
				
			||||||
 | 
					uInt inflate_mask[17] = {
 | 
				
			||||||
 | 
					    0x0000,
 | 
				
			||||||
 | 
					    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
 | 
				
			||||||
 | 
					    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* copy as much as possible from the sliding window to the output area */
 | 
				
			||||||
 | 
					int inflate_flush(s, z, r)
 | 
				
			||||||
 | 
					inflate_blocks_statef *s;
 | 
				
			||||||
 | 
					z_streamp z;
 | 
				
			||||||
 | 
					int r;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  uInt n;
 | 
				
			||||||
 | 
					  Bytef *p;
 | 
				
			||||||
 | 
					  Bytef *q;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* local copies of source and destination pointers */
 | 
				
			||||||
 | 
					  p = z->next_out;
 | 
				
			||||||
 | 
					  q = s->read;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* compute number of bytes to copy as far as end of window */
 | 
				
			||||||
 | 
					  n = (uInt)((q <= s->write ? s->write : s->end) - q);
 | 
				
			||||||
 | 
					  if (n > z->avail_out) n = z->avail_out;
 | 
				
			||||||
 | 
					  if (n && r == Z_BUF_ERROR) r = Z_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* update counters */
 | 
				
			||||||
 | 
					  z->avail_out -= n;
 | 
				
			||||||
 | 
					  z->total_out += n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* update check information */
 | 
				
			||||||
 | 
					  if (s->checkfn != Z_NULL)
 | 
				
			||||||
 | 
					    z->adler = s->check = (*s->checkfn)(s->check, q, n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* copy as far as end of window */
 | 
				
			||||||
 | 
					  zmemcpy(p, q, n);
 | 
				
			||||||
 | 
					  p += n;
 | 
				
			||||||
 | 
					  q += n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* see if more to copy at beginning of window */
 | 
				
			||||||
 | 
					  if (q == s->end)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    /* wrap pointers */
 | 
				
			||||||
 | 
					    q = s->window;
 | 
				
			||||||
 | 
					    if (s->write == s->end)
 | 
				
			||||||
 | 
					      s->write = s->window;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* compute bytes to copy */
 | 
				
			||||||
 | 
					    n = (uInt)(s->write - q);
 | 
				
			||||||
 | 
					    if (n > z->avail_out) n = z->avail_out;
 | 
				
			||||||
 | 
					    if (n && r == Z_BUF_ERROR) r = Z_OK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* update counters */
 | 
				
			||||||
 | 
					    z->avail_out -= n;
 | 
				
			||||||
 | 
					    z->total_out += n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* update check information */
 | 
				
			||||||
 | 
					    if (s->checkfn != Z_NULL)
 | 
				
			||||||
 | 
					      z->adler = s->check = (*s->checkfn)(s->check, q, n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* copy */
 | 
				
			||||||
 | 
					    zmemcpy(p, q, n);
 | 
				
			||||||
 | 
					    p += n;
 | 
				
			||||||
 | 
					    q += n;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* update pointers */
 | 
				
			||||||
 | 
					  z->next_out = p;
 | 
				
			||||||
 | 
					  s->read = q;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* done */
 | 
				
			||||||
 | 
					  return r;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										98
									
								
								src/TZlib/Zip/infutil.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								src/TZlib/Zip/infutil.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,98 @@
 | 
				
			|||||||
 | 
					/* infutil.h -- types and macros common to blocks and codes
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _INFUTIL_H
 | 
				
			||||||
 | 
					#define _INFUTIL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum {
 | 
				
			||||||
 | 
					      TYPE,     /* get type bits (3, including end bit) */
 | 
				
			||||||
 | 
					      LENS,     /* get lengths for stored */
 | 
				
			||||||
 | 
					      STORED,   /* processing stored block */
 | 
				
			||||||
 | 
					      TABLE,    /* get table lengths */
 | 
				
			||||||
 | 
					      BTREE,    /* get bit lengths tree for a dynamic block */
 | 
				
			||||||
 | 
					      DTREE,    /* get length, distance trees for a dynamic block */
 | 
				
			||||||
 | 
					      CODES,    /* processing fixed or dynamic block */
 | 
				
			||||||
 | 
					      DRY,      /* output remaining window bytes */
 | 
				
			||||||
 | 
					      DONE,     /* finished last block, done */
 | 
				
			||||||
 | 
					      BAD}      /* got a data error--stuck here */
 | 
				
			||||||
 | 
					inflate_block_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inflate blocks semi-private state */
 | 
				
			||||||
 | 
					struct inflate_blocks_state {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode */
 | 
				
			||||||
 | 
					  inflate_block_mode  mode;     /* current inflate_block mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode dependent information */
 | 
				
			||||||
 | 
					  union {
 | 
				
			||||||
 | 
					    uInt left;          /* if STORED, bytes left to copy */
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      uInt table;               /* table lengths (14 bits) */
 | 
				
			||||||
 | 
					      uInt index;               /* index into blens (or border) */
 | 
				
			||||||
 | 
					      uIntf *blens;             /* bit lengths of codes */
 | 
				
			||||||
 | 
					      uInt bb;                  /* bit length tree depth */
 | 
				
			||||||
 | 
					      inflate_huft *tb;         /* bit length decoding tree */
 | 
				
			||||||
 | 
					    } trees;            /* if DTREE, decoding info for trees */
 | 
				
			||||||
 | 
					    struct {
 | 
				
			||||||
 | 
					      inflate_codes_statef 
 | 
				
			||||||
 | 
					         *codes;
 | 
				
			||||||
 | 
					    } decode;           /* if CODES, current state */
 | 
				
			||||||
 | 
					  } sub;                /* submode */
 | 
				
			||||||
 | 
					  uInt last;            /* true if this block is the last block */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /* mode independent information */
 | 
				
			||||||
 | 
					  uInt bitk;            /* bits in bit buffer */
 | 
				
			||||||
 | 
					  uLong bitb;           /* bit buffer */
 | 
				
			||||||
 | 
					  inflate_huft *hufts;  /* single malloc for tree space */
 | 
				
			||||||
 | 
					  Bytef *window;        /* sliding window */
 | 
				
			||||||
 | 
					  Bytef *end;           /* one byte after sliding window */
 | 
				
			||||||
 | 
					  Bytef *read;          /* window read pointer */
 | 
				
			||||||
 | 
					  Bytef *write;         /* window write pointer */
 | 
				
			||||||
 | 
					  check_func checkfn;   /* check function */
 | 
				
			||||||
 | 
					  uLong check;          /* check on output */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* defines for inflate input/output */
 | 
				
			||||||
 | 
					/*   update pointers and return */
 | 
				
			||||||
 | 
					#define UPDBITS {s->bitb=b;s->bitk=k;}
 | 
				
			||||||
 | 
					#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
 | 
				
			||||||
 | 
					#define UPDOUT {s->write=q;}
 | 
				
			||||||
 | 
					#define UPDATE {UPDBITS UPDIN UPDOUT}
 | 
				
			||||||
 | 
					#define LEAVE {UPDATE return inflate_flush(s,z,r);}
 | 
				
			||||||
 | 
					/*   get bytes and bits */
 | 
				
			||||||
 | 
					#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
 | 
				
			||||||
 | 
					#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
 | 
				
			||||||
 | 
					#define NEXTBYTE (n--,*p++)
 | 
				
			||||||
 | 
					#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
 | 
				
			||||||
 | 
					#define DUMPBITS(j) {b>>=(j);k-=(j);}
 | 
				
			||||||
 | 
					/*   output bytes */
 | 
				
			||||||
 | 
					#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
 | 
				
			||||||
 | 
					#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
 | 
				
			||||||
 | 
					#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
 | 
				
			||||||
 | 
					#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
 | 
				
			||||||
 | 
					#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
 | 
				
			||||||
 | 
					#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
 | 
				
			||||||
 | 
					/*   load local pointers */
 | 
				
			||||||
 | 
					#define LOAD {LOADIN LOADOUT}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
 | 
				
			||||||
 | 
					extern uInt inflate_mask[17];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* copy as much as possible from the sliding window to the output area */
 | 
				
			||||||
 | 
					extern int inflate_flush OF((
 | 
				
			||||||
 | 
					    inflate_blocks_statef *,
 | 
				
			||||||
 | 
					    z_streamp ,
 | 
				
			||||||
 | 
					    int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct internal_state      {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										51
									
								
								src/TZlib/Zip/maketree.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/TZlib/Zip/maketree.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					/* maketree.c -- make inffixed.h table for decoding fixed codes
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Mark Adler
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* This program is included in the distribution for completeness.
 | 
				
			||||||
 | 
					   You do not need to compile or run this program since inffixed.h
 | 
				
			||||||
 | 
					   is already included in the distribution.  To use this program
 | 
				
			||||||
 | 
					   you need to compile zlib with BUILDFIXED defined and then compile
 | 
				
			||||||
 | 
					   and link this program with the zlib library.  Then the output of
 | 
				
			||||||
 | 
					   this program can be piped to inffixed.h. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					#include "inftrees.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* simplify the use of the inflate_huft type with some defines */
 | 
				
			||||||
 | 
					#define exop word.what.Exop
 | 
				
			||||||
 | 
					#define bits word.what.Bits
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* generate initialization table for an inflate_huft structure array */
 | 
				
			||||||
 | 
					void maketree(uInt b, inflate_huft *t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int i, e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  i = 0;
 | 
				
			||||||
 | 
					  while (1)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    e = t[i].exop;
 | 
				
			||||||
 | 
					    if (e && (e & (16+64)) == 0)        /* table pointer */
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fprintf(stderr, "maketree: cannot initialize sub-tables!\n");
 | 
				
			||||||
 | 
					      exit(1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (i % 4 == 0)
 | 
				
			||||||
 | 
					      printf("\n   ");
 | 
				
			||||||
 | 
					    printf(" {{{%u,%u}},%u}", t[i].exop, t[i].bits, t[i].base);
 | 
				
			||||||
 | 
					    if (++i == (1<<b))
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    putchar(',');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  puts("");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										1214
									
								
								src/TZlib/Zip/trees.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1214
									
								
								src/TZlib/Zip/trees.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										128
									
								
								src/TZlib/Zip/trees.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								src/TZlib/Zip/trees.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,128 @@
 | 
				
			|||||||
 | 
					/* header created automatically with -DGEN_TREES_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local const ct_data static_ltree[L_CODES+2] = {
 | 
				
			||||||
 | 
					{{ 12},{  8}}, {{140},{  8}}, {{ 76},{  8}}, {{204},{  8}}, {{ 44},{  8}},
 | 
				
			||||||
 | 
					{{172},{  8}}, {{108},{  8}}, {{236},{  8}}, {{ 28},{  8}}, {{156},{  8}},
 | 
				
			||||||
 | 
					{{ 92},{  8}}, {{220},{  8}}, {{ 60},{  8}}, {{188},{  8}}, {{124},{  8}},
 | 
				
			||||||
 | 
					{{252},{  8}}, {{  2},{  8}}, {{130},{  8}}, {{ 66},{  8}}, {{194},{  8}},
 | 
				
			||||||
 | 
					{{ 34},{  8}}, {{162},{  8}}, {{ 98},{  8}}, {{226},{  8}}, {{ 18},{  8}},
 | 
				
			||||||
 | 
					{{146},{  8}}, {{ 82},{  8}}, {{210},{  8}}, {{ 50},{  8}}, {{178},{  8}},
 | 
				
			||||||
 | 
					{{114},{  8}}, {{242},{  8}}, {{ 10},{  8}}, {{138},{  8}}, {{ 74},{  8}},
 | 
				
			||||||
 | 
					{{202},{  8}}, {{ 42},{  8}}, {{170},{  8}}, {{106},{  8}}, {{234},{  8}},
 | 
				
			||||||
 | 
					{{ 26},{  8}}, {{154},{  8}}, {{ 90},{  8}}, {{218},{  8}}, {{ 58},{  8}},
 | 
				
			||||||
 | 
					{{186},{  8}}, {{122},{  8}}, {{250},{  8}}, {{  6},{  8}}, {{134},{  8}},
 | 
				
			||||||
 | 
					{{ 70},{  8}}, {{198},{  8}}, {{ 38},{  8}}, {{166},{  8}}, {{102},{  8}},
 | 
				
			||||||
 | 
					{{230},{  8}}, {{ 22},{  8}}, {{150},{  8}}, {{ 86},{  8}}, {{214},{  8}},
 | 
				
			||||||
 | 
					{{ 54},{  8}}, {{182},{  8}}, {{118},{  8}}, {{246},{  8}}, {{ 14},{  8}},
 | 
				
			||||||
 | 
					{{142},{  8}}, {{ 78},{  8}}, {{206},{  8}}, {{ 46},{  8}}, {{174},{  8}},
 | 
				
			||||||
 | 
					{{110},{  8}}, {{238},{  8}}, {{ 30},{  8}}, {{158},{  8}}, {{ 94},{  8}},
 | 
				
			||||||
 | 
					{{222},{  8}}, {{ 62},{  8}}, {{190},{  8}}, {{126},{  8}}, {{254},{  8}},
 | 
				
			||||||
 | 
					{{  1},{  8}}, {{129},{  8}}, {{ 65},{  8}}, {{193},{  8}}, {{ 33},{  8}},
 | 
				
			||||||
 | 
					{{161},{  8}}, {{ 97},{  8}}, {{225},{  8}}, {{ 17},{  8}}, {{145},{  8}},
 | 
				
			||||||
 | 
					{{ 81},{  8}}, {{209},{  8}}, {{ 49},{  8}}, {{177},{  8}}, {{113},{  8}},
 | 
				
			||||||
 | 
					{{241},{  8}}, {{  9},{  8}}, {{137},{  8}}, {{ 73},{  8}}, {{201},{  8}},
 | 
				
			||||||
 | 
					{{ 41},{  8}}, {{169},{  8}}, {{105},{  8}}, {{233},{  8}}, {{ 25},{  8}},
 | 
				
			||||||
 | 
					{{153},{  8}}, {{ 89},{  8}}, {{217},{  8}}, {{ 57},{  8}}, {{185},{  8}},
 | 
				
			||||||
 | 
					{{121},{  8}}, {{249},{  8}}, {{  5},{  8}}, {{133},{  8}}, {{ 69},{  8}},
 | 
				
			||||||
 | 
					{{197},{  8}}, {{ 37},{  8}}, {{165},{  8}}, {{101},{  8}}, {{229},{  8}},
 | 
				
			||||||
 | 
					{{ 21},{  8}}, {{149},{  8}}, {{ 85},{  8}}, {{213},{  8}}, {{ 53},{  8}},
 | 
				
			||||||
 | 
					{{181},{  8}}, {{117},{  8}}, {{245},{  8}}, {{ 13},{  8}}, {{141},{  8}},
 | 
				
			||||||
 | 
					{{ 77},{  8}}, {{205},{  8}}, {{ 45},{  8}}, {{173},{  8}}, {{109},{  8}},
 | 
				
			||||||
 | 
					{{237},{  8}}, {{ 29},{  8}}, {{157},{  8}}, {{ 93},{  8}}, {{221},{  8}},
 | 
				
			||||||
 | 
					{{ 61},{  8}}, {{189},{  8}}, {{125},{  8}}, {{253},{  8}}, {{ 19},{  9}},
 | 
				
			||||||
 | 
					{{275},{  9}}, {{147},{  9}}, {{403},{  9}}, {{ 83},{  9}}, {{339},{  9}},
 | 
				
			||||||
 | 
					{{211},{  9}}, {{467},{  9}}, {{ 51},{  9}}, {{307},{  9}}, {{179},{  9}},
 | 
				
			||||||
 | 
					{{435},{  9}}, {{115},{  9}}, {{371},{  9}}, {{243},{  9}}, {{499},{  9}},
 | 
				
			||||||
 | 
					{{ 11},{  9}}, {{267},{  9}}, {{139},{  9}}, {{395},{  9}}, {{ 75},{  9}},
 | 
				
			||||||
 | 
					{{331},{  9}}, {{203},{  9}}, {{459},{  9}}, {{ 43},{  9}}, {{299},{  9}},
 | 
				
			||||||
 | 
					{{171},{  9}}, {{427},{  9}}, {{107},{  9}}, {{363},{  9}}, {{235},{  9}},
 | 
				
			||||||
 | 
					{{491},{  9}}, {{ 27},{  9}}, {{283},{  9}}, {{155},{  9}}, {{411},{  9}},
 | 
				
			||||||
 | 
					{{ 91},{  9}}, {{347},{  9}}, {{219},{  9}}, {{475},{  9}}, {{ 59},{  9}},
 | 
				
			||||||
 | 
					{{315},{  9}}, {{187},{  9}}, {{443},{  9}}, {{123},{  9}}, {{379},{  9}},
 | 
				
			||||||
 | 
					{{251},{  9}}, {{507},{  9}}, {{  7},{  9}}, {{263},{  9}}, {{135},{  9}},
 | 
				
			||||||
 | 
					{{391},{  9}}, {{ 71},{  9}}, {{327},{  9}}, {{199},{  9}}, {{455},{  9}},
 | 
				
			||||||
 | 
					{{ 39},{  9}}, {{295},{  9}}, {{167},{  9}}, {{423},{  9}}, {{103},{  9}},
 | 
				
			||||||
 | 
					{{359},{  9}}, {{231},{  9}}, {{487},{  9}}, {{ 23},{  9}}, {{279},{  9}},
 | 
				
			||||||
 | 
					{{151},{  9}}, {{407},{  9}}, {{ 87},{  9}}, {{343},{  9}}, {{215},{  9}},
 | 
				
			||||||
 | 
					{{471},{  9}}, {{ 55},{  9}}, {{311},{  9}}, {{183},{  9}}, {{439},{  9}},
 | 
				
			||||||
 | 
					{{119},{  9}}, {{375},{  9}}, {{247},{  9}}, {{503},{  9}}, {{ 15},{  9}},
 | 
				
			||||||
 | 
					{{271},{  9}}, {{143},{  9}}, {{399},{  9}}, {{ 79},{  9}}, {{335},{  9}},
 | 
				
			||||||
 | 
					{{207},{  9}}, {{463},{  9}}, {{ 47},{  9}}, {{303},{  9}}, {{175},{  9}},
 | 
				
			||||||
 | 
					{{431},{  9}}, {{111},{  9}}, {{367},{  9}}, {{239},{  9}}, {{495},{  9}},
 | 
				
			||||||
 | 
					{{ 31},{  9}}, {{287},{  9}}, {{159},{  9}}, {{415},{  9}}, {{ 95},{  9}},
 | 
				
			||||||
 | 
					{{351},{  9}}, {{223},{  9}}, {{479},{  9}}, {{ 63},{  9}}, {{319},{  9}},
 | 
				
			||||||
 | 
					{{191},{  9}}, {{447},{  9}}, {{127},{  9}}, {{383},{  9}}, {{255},{  9}},
 | 
				
			||||||
 | 
					{{511},{  9}}, {{  0},{  7}}, {{ 64},{  7}}, {{ 32},{  7}}, {{ 96},{  7}},
 | 
				
			||||||
 | 
					{{ 16},{  7}}, {{ 80},{  7}}, {{ 48},{  7}}, {{112},{  7}}, {{  8},{  7}},
 | 
				
			||||||
 | 
					{{ 72},{  7}}, {{ 40},{  7}}, {{104},{  7}}, {{ 24},{  7}}, {{ 88},{  7}},
 | 
				
			||||||
 | 
					{{ 56},{  7}}, {{120},{  7}}, {{  4},{  7}}, {{ 68},{  7}}, {{ 36},{  7}},
 | 
				
			||||||
 | 
					{{100},{  7}}, {{ 20},{  7}}, {{ 84},{  7}}, {{ 52},{  7}}, {{116},{  7}},
 | 
				
			||||||
 | 
					{{  3},{  8}}, {{131},{  8}}, {{ 67},{  8}}, {{195},{  8}}, {{ 35},{  8}},
 | 
				
			||||||
 | 
					{{163},{  8}}, {{ 99},{  8}}, {{227},{  8}}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local const ct_data static_dtree[D_CODES] = {
 | 
				
			||||||
 | 
					{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
 | 
				
			||||||
 | 
					{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
 | 
				
			||||||
 | 
					{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
 | 
				
			||||||
 | 
					{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
 | 
				
			||||||
 | 
					{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
 | 
				
			||||||
 | 
					{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const uch _dist_code[DIST_CODE_LEN] = {
 | 
				
			||||||
 | 
					 0,  1,  2,  3,  4,  4,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  8,
 | 
				
			||||||
 | 
					 8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10,
 | 
				
			||||||
 | 
					10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
 | 
				
			||||||
 | 
					11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
 | 
				
			||||||
 | 
					12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
 | 
				
			||||||
 | 
					13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
 | 
				
			||||||
 | 
					13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
 | 
				
			||||||
 | 
					14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
 | 
				
			||||||
 | 
					14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
 | 
				
			||||||
 | 
					14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
 | 
				
			||||||
 | 
					15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
 | 
				
			||||||
 | 
					15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
 | 
				
			||||||
 | 
					15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,  0,  0, 16, 17,
 | 
				
			||||||
 | 
					18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
 | 
				
			||||||
 | 
					23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
 | 
				
			||||||
 | 
					24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
 | 
				
			||||||
 | 
					26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
 | 
				
			||||||
 | 
					26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
 | 
				
			||||||
 | 
					27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
 | 
				
			||||||
 | 
					27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
 | 
				
			||||||
 | 
					28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
 | 
				
			||||||
 | 
					28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
 | 
				
			||||||
 | 
					28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
 | 
				
			||||||
 | 
					29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
 | 
				
			||||||
 | 
					29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
 | 
				
			||||||
 | 
					29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
 | 
				
			||||||
 | 
					 0,  1,  2,  3,  4,  5,  6,  7,  8,  8,  9,  9, 10, 10, 11, 11, 12, 12, 12, 12,
 | 
				
			||||||
 | 
					13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
 | 
				
			||||||
 | 
					17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
 | 
				
			||||||
 | 
					19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
 | 
				
			||||||
 | 
					21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
 | 
				
			||||||
 | 
					22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
 | 
				
			||||||
 | 
					23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
 | 
				
			||||||
 | 
					24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
 | 
				
			||||||
 | 
					25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
 | 
				
			||||||
 | 
					25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
 | 
				
			||||||
 | 
					26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
 | 
				
			||||||
 | 
					26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
 | 
				
			||||||
 | 
					27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local const int base_length[LENGTH_CODES] = {
 | 
				
			||||||
 | 
					0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
 | 
				
			||||||
 | 
					64, 80, 96, 112, 128, 160, 192, 224, 0
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local const int base_dist[D_CODES] = {
 | 
				
			||||||
 | 
					    0,     1,     2,     3,     4,     6,     8,    12,    16,    24,
 | 
				
			||||||
 | 
					   32,    48,    64,    96,   128,   192,   256,   384,   512,   768,
 | 
				
			||||||
 | 
					 1024,  1536,  2048,  3072,  4096,  6144,  8192, 12288, 16384, 24576
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										58
									
								
								src/TZlib/Zip/uncompr.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/TZlib/Zip/uncompr.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					/* uncompr.c -- decompress a memory buffer
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ===========================================================================
 | 
				
			||||||
 | 
					     Decompresses the source buffer into the destination buffer.  sourceLen is
 | 
				
			||||||
 | 
					   the byte length of the source buffer. Upon entry, destLen is the total
 | 
				
			||||||
 | 
					   size of the destination buffer, which must be large enough to hold the
 | 
				
			||||||
 | 
					   entire uncompressed data. (The size of the uncompressed data must have
 | 
				
			||||||
 | 
					   been saved previously by the compressor and transmitted to the decompressor
 | 
				
			||||||
 | 
					   by some mechanism outside the scope of this compression library.)
 | 
				
			||||||
 | 
					   Upon exit, destLen is the actual size of the compressed buffer.
 | 
				
			||||||
 | 
					     This function can be used to decompress a whole file at once if the
 | 
				
			||||||
 | 
					   input file is mmap'ed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					   enough memory, Z_BUF_ERROR if there was not enough room in the output
 | 
				
			||||||
 | 
					   buffer, or Z_DATA_ERROR if the input data was corrupted.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					int ZEXPORT uncompress (dest, destLen, source, sourceLen)
 | 
				
			||||||
 | 
					    Bytef *dest;
 | 
				
			||||||
 | 
					    uLongf *destLen;
 | 
				
			||||||
 | 
					    const Bytef *source;
 | 
				
			||||||
 | 
					    uLong sourceLen;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    z_stream stream;
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stream.next_in = (Bytef*)source;
 | 
				
			||||||
 | 
					    stream.avail_in = (uInt)sourceLen;
 | 
				
			||||||
 | 
					    /* Check for source > 64K on 16-bit machine: */
 | 
				
			||||||
 | 
					    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stream.next_out = dest;
 | 
				
			||||||
 | 
					    stream.avail_out = (uInt)*destLen;
 | 
				
			||||||
 | 
					    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stream.zalloc = (alloc_func)0;
 | 
				
			||||||
 | 
					    stream.zfree = (free_func)0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = inflateInit(&stream);
 | 
				
			||||||
 | 
					    if (err != Z_OK) return err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = inflate(&stream, Z_FINISH);
 | 
				
			||||||
 | 
					    if (err != Z_STREAM_END) {
 | 
				
			||||||
 | 
					        inflateEnd(&stream);
 | 
				
			||||||
 | 
					        return err == Z_OK ? Z_BUF_ERROR : err;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    *destLen = stream.total_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = inflateEnd(&stream);
 | 
				
			||||||
 | 
					    return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										279
									
								
								src/TZlib/Zip/zconf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										279
									
								
								src/TZlib/Zip/zconf.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,279 @@
 | 
				
			|||||||
 | 
					/* zconf.h -- configuration of the zlib compression library
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _ZCONF_H
 | 
				
			||||||
 | 
					#define _ZCONF_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * If you *really* need a unique prefix for all types and library functions,
 | 
				
			||||||
 | 
					 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef Z_PREFIX
 | 
				
			||||||
 | 
					#  define deflateInit_	z_deflateInit_
 | 
				
			||||||
 | 
					#  define deflate	z_deflate
 | 
				
			||||||
 | 
					#  define deflateEnd	z_deflateEnd
 | 
				
			||||||
 | 
					#  define inflateInit_ 	z_inflateInit_
 | 
				
			||||||
 | 
					#  define inflate	z_inflate
 | 
				
			||||||
 | 
					#  define inflateEnd	z_inflateEnd
 | 
				
			||||||
 | 
					#  define deflateInit2_	z_deflateInit2_
 | 
				
			||||||
 | 
					#  define deflateSetDictionary z_deflateSetDictionary
 | 
				
			||||||
 | 
					#  define deflateCopy	z_deflateCopy
 | 
				
			||||||
 | 
					#  define deflateReset	z_deflateReset
 | 
				
			||||||
 | 
					#  define deflateParams	z_deflateParams
 | 
				
			||||||
 | 
					#  define inflateInit2_	z_inflateInit2_
 | 
				
			||||||
 | 
					#  define inflateSetDictionary z_inflateSetDictionary
 | 
				
			||||||
 | 
					#  define inflateSync	z_inflateSync
 | 
				
			||||||
 | 
					#  define inflateSyncPoint z_inflateSyncPoint
 | 
				
			||||||
 | 
					#  define inflateReset	z_inflateReset
 | 
				
			||||||
 | 
					#  define compress	z_compress
 | 
				
			||||||
 | 
					#  define compress2	z_compress2
 | 
				
			||||||
 | 
					#  define uncompress	z_uncompress
 | 
				
			||||||
 | 
					#  define adler32	z_adler32
 | 
				
			||||||
 | 
					#  define crc32		z_crc32
 | 
				
			||||||
 | 
					#  define get_crc_table z_get_crc_table
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#  define Byte		z_Byte
 | 
				
			||||||
 | 
					#  define uInt		z_uInt
 | 
				
			||||||
 | 
					#  define uLong		z_uLong
 | 
				
			||||||
 | 
					#  define Bytef	        z_Bytef
 | 
				
			||||||
 | 
					#  define charf		z_charf
 | 
				
			||||||
 | 
					#  define intf		z_intf
 | 
				
			||||||
 | 
					#  define uIntf		z_uIntf
 | 
				
			||||||
 | 
					#  define uLongf	z_uLongf
 | 
				
			||||||
 | 
					#  define voidpf	z_voidpf
 | 
				
			||||||
 | 
					#  define voidp		z_voidp
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
 | 
				
			||||||
 | 
					#  define WIN32
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
 | 
				
			||||||
 | 
					#  ifndef __32BIT__
 | 
				
			||||||
 | 
					#    define __32BIT__
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(__MSDOS__) && !defined(MSDOS)
 | 
				
			||||||
 | 
					#  define MSDOS
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
 | 
				
			||||||
 | 
					 * than 64k bytes at a time (needed on systems with 16-bit int).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#if defined(MSDOS) && !defined(__32BIT__)
 | 
				
			||||||
 | 
					#  define MAXSEG_64K
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef MSDOS
 | 
				
			||||||
 | 
					#  define UNALIGNED_OK
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
 | 
				
			||||||
 | 
					#  ifndef STDC
 | 
				
			||||||
 | 
					#    define STDC
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef STDC
 | 
				
			||||||
 | 
					#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
 | 
				
			||||||
 | 
					#    define const
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Some Mac compilers merge all .h files incorrectly: */
 | 
				
			||||||
 | 
					#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
 | 
				
			||||||
 | 
					#  define NO_DUMMY_DECL
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Old Borland C incorrectly complains about missing returns: */
 | 
				
			||||||
 | 
					#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
 | 
				
			||||||
 | 
					#  define NEED_DUMMY_RETURN
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum value for memLevel in deflateInit2 */
 | 
				
			||||||
 | 
					#ifndef MAX_MEM_LEVEL
 | 
				
			||||||
 | 
					#  ifdef MAXSEG_64K
 | 
				
			||||||
 | 
					#    define MAX_MEM_LEVEL 8
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define MAX_MEM_LEVEL 9
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum value for windowBits in deflateInit2 and inflateInit2.
 | 
				
			||||||
 | 
					 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
 | 
				
			||||||
 | 
					 * created by gzip. (Files created by minigzip can still be extracted by
 | 
				
			||||||
 | 
					 * gzip.)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifndef MAX_WBITS
 | 
				
			||||||
 | 
					#  define MAX_WBITS   15 /* 32K LZ77 window */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The memory requirements for deflate are (in bytes):
 | 
				
			||||||
 | 
					            (1 << (windowBits+2)) +  (1 << (memLevel+9))
 | 
				
			||||||
 | 
					 that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
 | 
				
			||||||
 | 
					 plus a few kilobytes for small objects. For example, if you want to reduce
 | 
				
			||||||
 | 
					 the default memory requirements from 256K to 128K, compile with
 | 
				
			||||||
 | 
					     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
 | 
				
			||||||
 | 
					 Of course this will generally degrade compression (there's no free lunch).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The memory requirements for inflate are (in bytes) 1 << windowBits
 | 
				
			||||||
 | 
					 that is, 32K for windowBits=15 (default value) plus a few kilobytes
 | 
				
			||||||
 | 
					 for small objects.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* Type declarations */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef OF /* function prototypes */
 | 
				
			||||||
 | 
					#  ifdef STDC
 | 
				
			||||||
 | 
					#    define OF(args)  args
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define OF(args)  ()
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The following definitions for FAR are needed only for MSDOS mixed
 | 
				
			||||||
 | 
					 * model programming (small or medium model with some far allocations).
 | 
				
			||||||
 | 
					 * This was tested only with MSC; for other MSDOS compilers you may have
 | 
				
			||||||
 | 
					 * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
 | 
				
			||||||
 | 
					 * just define FAR to be empty.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
 | 
				
			||||||
 | 
					   /* MSC small or medium model */
 | 
				
			||||||
 | 
					#  define SMALL_MEDIUM
 | 
				
			||||||
 | 
					#  ifdef _MSC_VER
 | 
				
			||||||
 | 
					#    define FAR _far
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define FAR far
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
 | 
				
			||||||
 | 
					#  ifndef __32BIT__
 | 
				
			||||||
 | 
					#    define SMALL_MEDIUM
 | 
				
			||||||
 | 
					#    define FAR _far
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Compile with -DZLIB_DLL for Windows DLL support */
 | 
				
			||||||
 | 
					#if defined(ZLIB_DLL)
 | 
				
			||||||
 | 
					#  if defined(_WINDOWS) || defined(WINDOWS)
 | 
				
			||||||
 | 
					#    ifdef FAR
 | 
				
			||||||
 | 
					#      undef FAR
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#    include <windows.h>
 | 
				
			||||||
 | 
					#    define ZEXPORT  WINAPI
 | 
				
			||||||
 | 
					#    ifdef WIN32
 | 
				
			||||||
 | 
					#      define ZEXPORTVA  WINAPIV
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      define ZEXPORTVA  FAR _cdecl _export
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#  if defined (__BORLANDC__)
 | 
				
			||||||
 | 
					#    if (__BORLANDC__ >= 0x0500) && defined (WIN32)
 | 
				
			||||||
 | 
					#      include <windows.h>
 | 
				
			||||||
 | 
					#      define ZEXPORT __declspec(dllexport) WINAPI
 | 
				
			||||||
 | 
					#      define ZEXPORTRVA __declspec(dllexport) WINAPIV
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      if defined (_Windows) && defined (__DLL__)
 | 
				
			||||||
 | 
					#        define ZEXPORT _export
 | 
				
			||||||
 | 
					#        define ZEXPORTVA _export
 | 
				
			||||||
 | 
					#      endif
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined (__BEOS__)
 | 
				
			||||||
 | 
					#  if defined (ZLIB_DLL)
 | 
				
			||||||
 | 
					#    define ZEXTERN extern __declspec(dllexport)
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define ZEXTERN extern __declspec(dllimport)
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ZEXPORT
 | 
				
			||||||
 | 
					#  define ZEXPORT
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef ZEXPORTVA
 | 
				
			||||||
 | 
					#  define ZEXPORTVA
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef ZEXTERN
 | 
				
			||||||
 | 
					#  define ZEXTERN extern
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef FAR
 | 
				
			||||||
 | 
					#   define FAR
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(MACOS) && !defined(TARGET_OS_MAC)
 | 
				
			||||||
 | 
					typedef unsigned char  Byte;  /* 8 bits */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					typedef unsigned int   uInt;  /* 16 bits or more */
 | 
				
			||||||
 | 
					typedef unsigned long  uLong; /* 32 bits or more */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef SMALL_MEDIUM
 | 
				
			||||||
 | 
					   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
 | 
				
			||||||
 | 
					#  define Bytef Byte FAR
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					   typedef unsigned char  FAR Bytef;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					typedef char  FAR charf;
 | 
				
			||||||
 | 
					typedef int   FAR intf;
 | 
				
			||||||
 | 
					typedef uInt  FAR uIntf;
 | 
				
			||||||
 | 
					typedef uLong FAR uLongf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef STDC
 | 
				
			||||||
 | 
					   typedef void FAR *voidpf;
 | 
				
			||||||
 | 
					   typedef void     *voidp;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					   typedef Byte FAR *voidpf;
 | 
				
			||||||
 | 
					   typedef Byte     *voidp;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_UNISTD_H
 | 
				
			||||||
 | 
					#  include <sys/types.h> /* for off_t */
 | 
				
			||||||
 | 
					#  include <unistd.h>    /* for SEEK_* and off_t */
 | 
				
			||||||
 | 
					#  define z_off_t  off_t
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef SEEK_SET
 | 
				
			||||||
 | 
					#  define SEEK_SET        0       /* Seek from beginning of file.  */
 | 
				
			||||||
 | 
					#  define SEEK_CUR        1       /* Seek from current position.  */
 | 
				
			||||||
 | 
					#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef z_off_t
 | 
				
			||||||
 | 
					#  define  z_off_t long
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* MVS linker does not support external names larger than 8 bytes */
 | 
				
			||||||
 | 
					#if defined(__MVS__)
 | 
				
			||||||
 | 
					#   pragma map(deflateInit_,"DEIN")
 | 
				
			||||||
 | 
					#   pragma map(deflateInit2_,"DEIN2")
 | 
				
			||||||
 | 
					#   pragma map(deflateEnd,"DEEND")
 | 
				
			||||||
 | 
					#   pragma map(inflateInit_,"ININ")
 | 
				
			||||||
 | 
					#   pragma map(inflateInit2_,"ININ2")
 | 
				
			||||||
 | 
					#   pragma map(inflateEnd,"INEND")
 | 
				
			||||||
 | 
					#   pragma map(inflateSync,"INSY")
 | 
				
			||||||
 | 
					#   pragma map(inflateSetDictionary,"INSEDI")
 | 
				
			||||||
 | 
					#   pragma map(inflate_blocks,"INBL")
 | 
				
			||||||
 | 
					#   pragma map(inflate_blocks_new,"INBLNE")
 | 
				
			||||||
 | 
					#   pragma map(inflate_blocks_free,"INBLFR")
 | 
				
			||||||
 | 
					#   pragma map(inflate_blocks_reset,"INBLRE")
 | 
				
			||||||
 | 
					#   pragma map(inflate_codes_free,"INCOFR")
 | 
				
			||||||
 | 
					#   pragma map(inflate_codes,"INCO")
 | 
				
			||||||
 | 
					#   pragma map(inflate_fast,"INFA")
 | 
				
			||||||
 | 
					#   pragma map(inflate_flush,"INFLU")
 | 
				
			||||||
 | 
					#   pragma map(inflate_mask,"INMA")
 | 
				
			||||||
 | 
					#   pragma map(inflate_set_dictionary,"INSEDI2")
 | 
				
			||||||
 | 
					#   pragma map(inflate_copyright,"INCOPY")
 | 
				
			||||||
 | 
					#   pragma map(inflate_trees_bits,"INTRBI")
 | 
				
			||||||
 | 
					#   pragma map(inflate_trees_dynamic,"INTRDY")
 | 
				
			||||||
 | 
					#   pragma map(inflate_trees_fixed,"INTRFI")
 | 
				
			||||||
 | 
					#   pragma map(inflate_trees_free,"INTRFR")
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* _ZCONF_H */
 | 
				
			||||||
							
								
								
									
										893
									
								
								src/TZlib/Zip/zlib.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										893
									
								
								src/TZlib/Zip/zlib.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,893 @@
 | 
				
			|||||||
 | 
					/* zlib.h -- interface of the 'zlib' general purpose compression library
 | 
				
			||||||
 | 
					  version 1.1.4, March 11th, 2002
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  This software is provided 'as-is', without any express or implied
 | 
				
			||||||
 | 
					  warranty.  In no event will the authors be held liable for any damages
 | 
				
			||||||
 | 
					  arising from the use of this software.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Permission is granted to anyone to use this software for any purpose,
 | 
				
			||||||
 | 
					  including commercial applications, and to alter it and redistribute it
 | 
				
			||||||
 | 
					  freely, subject to the following restrictions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  1. The origin of this software must not be misrepresented; you must not
 | 
				
			||||||
 | 
					     claim that you wrote the original software. If you use this software
 | 
				
			||||||
 | 
					     in a product, an acknowledgment in the product documentation would be
 | 
				
			||||||
 | 
					     appreciated but is not required.
 | 
				
			||||||
 | 
					  2. Altered source versions must be plainly marked as such, and must not be
 | 
				
			||||||
 | 
					     misrepresented as being the original software.
 | 
				
			||||||
 | 
					  3. This notice may not be removed or altered from any source distribution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Jean-loup Gailly        Mark Adler
 | 
				
			||||||
 | 
					  jloup@gzip.org          madler@alumni.caltech.edu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The data format used by the zlib library is described by RFCs (Request for
 | 
				
			||||||
 | 
					  Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
 | 
				
			||||||
 | 
					  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _ZLIB_H
 | 
				
			||||||
 | 
					#define _ZLIB_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zconf.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZLIB_VERSION "1.1.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					     The 'zlib' compression library provides in-memory compression and
 | 
				
			||||||
 | 
					  decompression functions, including integrity checks of the uncompressed
 | 
				
			||||||
 | 
					  data.  This version of the library supports only one compression method
 | 
				
			||||||
 | 
					  (deflation) but other algorithms will be added later and will have the same
 | 
				
			||||||
 | 
					  stream interface.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Compression can be done in a single step if the buffers are large
 | 
				
			||||||
 | 
					  enough (for example if an input file is mmap'ed), or can be done by
 | 
				
			||||||
 | 
					  repeated calls of the compression function.  In the latter case, the
 | 
				
			||||||
 | 
					  application must provide more input and/or consume the output
 | 
				
			||||||
 | 
					  (providing more output space) before each call.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The library also supports reading and writing files in gzip (.gz) format
 | 
				
			||||||
 | 
					  with an interface similar to that of stdio.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The library does not install any signal handler. The decoder checks
 | 
				
			||||||
 | 
					  the consistency of the compressed data, so the library should never
 | 
				
			||||||
 | 
					  crash even in case of corrupted input.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
 | 
				
			||||||
 | 
					typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct internal_state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct z_stream_s {
 | 
				
			||||||
 | 
					    Bytef    *next_in;  /* next input byte */
 | 
				
			||||||
 | 
					    uInt     avail_in;  /* number of bytes available at next_in */
 | 
				
			||||||
 | 
					    uLong    total_in;  /* total nb of input bytes read so far */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Bytef    *next_out; /* next output byte should be put there */
 | 
				
			||||||
 | 
					    uInt     avail_out; /* remaining free space at next_out */
 | 
				
			||||||
 | 
					    uLong    total_out; /* total nb of bytes output so far */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    char     *msg;      /* last error message, NULL if no error */
 | 
				
			||||||
 | 
					    struct internal_state FAR *state; /* not visible by applications */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    alloc_func zalloc;  /* used to allocate the internal state */
 | 
				
			||||||
 | 
					    free_func  zfree;   /* used to free the internal state */
 | 
				
			||||||
 | 
					    voidpf     opaque;  /* private data object passed to zalloc and zfree */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int     data_type;  /* best guess about the data type: ascii or binary */
 | 
				
			||||||
 | 
					    uLong   adler;      /* adler32 value of the uncompressed data */
 | 
				
			||||||
 | 
					    uLong   reserved;   /* reserved for future use */
 | 
				
			||||||
 | 
					} z_stream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef z_stream FAR *z_streamp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					   The application must update next_in and avail_in when avail_in has
 | 
				
			||||||
 | 
					   dropped to zero. It must update next_out and avail_out when avail_out
 | 
				
			||||||
 | 
					   has dropped to zero. The application must initialize zalloc, zfree and
 | 
				
			||||||
 | 
					   opaque before calling the init function. All other fields are set by the
 | 
				
			||||||
 | 
					   compression library and must not be updated by the application.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The opaque value provided by the application will be passed as the first
 | 
				
			||||||
 | 
					   parameter for calls of zalloc and zfree. This can be useful for custom
 | 
				
			||||||
 | 
					   memory management. The compression library attaches no meaning to the
 | 
				
			||||||
 | 
					   opaque value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   zalloc must return Z_NULL if there is not enough memory for the object.
 | 
				
			||||||
 | 
					   If zlib is used in a multi-threaded application, zalloc and zfree must be
 | 
				
			||||||
 | 
					   thread safe.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   On 16-bit systems, the functions zalloc and zfree must be able to allocate
 | 
				
			||||||
 | 
					   exactly 65536 bytes, but will not be required to allocate more than this
 | 
				
			||||||
 | 
					   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
 | 
				
			||||||
 | 
					   pointers returned by zalloc for objects of exactly 65536 bytes *must*
 | 
				
			||||||
 | 
					   have their offset normalized to zero. The default allocation function
 | 
				
			||||||
 | 
					   provided by this library ensures this (see zutil.c). To reduce memory
 | 
				
			||||||
 | 
					   requirements and avoid any allocation of 64K objects, at the expense of
 | 
				
			||||||
 | 
					   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The fields total_in and total_out can be used for statistics or
 | 
				
			||||||
 | 
					   progress reports. After compression, total_in holds the total size of
 | 
				
			||||||
 | 
					   the uncompressed data and may be saved for use in the decompressor
 | 
				
			||||||
 | 
					   (particularly if the decompressor wants to decompress everything in
 | 
				
			||||||
 | 
					   a single step).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_NO_FLUSH      0
 | 
				
			||||||
 | 
					#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
 | 
				
			||||||
 | 
					#define Z_SYNC_FLUSH    2
 | 
				
			||||||
 | 
					#define Z_FULL_FLUSH    3
 | 
				
			||||||
 | 
					#define Z_FINISH        4
 | 
				
			||||||
 | 
					/* Allowed flush values; see deflate() below for details */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_OK            0
 | 
				
			||||||
 | 
					#define Z_STREAM_END    1
 | 
				
			||||||
 | 
					#define Z_NEED_DICT     2
 | 
				
			||||||
 | 
					#define Z_ERRNO        (-1)
 | 
				
			||||||
 | 
					#define Z_STREAM_ERROR (-2)
 | 
				
			||||||
 | 
					#define Z_DATA_ERROR   (-3)
 | 
				
			||||||
 | 
					#define Z_MEM_ERROR    (-4)
 | 
				
			||||||
 | 
					#define Z_BUF_ERROR    (-5)
 | 
				
			||||||
 | 
					#define Z_VERSION_ERROR (-6)
 | 
				
			||||||
 | 
					/* Return codes for the compression/decompression functions. Negative
 | 
				
			||||||
 | 
					 * values are errors, positive values are used for special but normal events.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_NO_COMPRESSION         0
 | 
				
			||||||
 | 
					#define Z_BEST_SPEED             1
 | 
				
			||||||
 | 
					#define Z_BEST_COMPRESSION       9
 | 
				
			||||||
 | 
					#define Z_DEFAULT_COMPRESSION  (-1)
 | 
				
			||||||
 | 
					/* compression levels */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_FILTERED            1
 | 
				
			||||||
 | 
					#define Z_HUFFMAN_ONLY        2
 | 
				
			||||||
 | 
					#define Z_DEFAULT_STRATEGY    0
 | 
				
			||||||
 | 
					/* compression strategy; see deflateInit2() below for details */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_BINARY   0
 | 
				
			||||||
 | 
					#define Z_ASCII    1
 | 
				
			||||||
 | 
					#define Z_UNKNOWN  2
 | 
				
			||||||
 | 
					/* Possible values of the data_type field */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_DEFLATED   8
 | 
				
			||||||
 | 
					/* The deflate compression method (the only one supported in this version) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define zlib_version zlibVersion()
 | 
				
			||||||
 | 
					/* for compatibility with versions < 1.0.2 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* basic functions */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN const char * ZEXPORT zlibVersion OF((void));
 | 
				
			||||||
 | 
					/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
 | 
				
			||||||
 | 
					   If the first character differs, the library code actually used is
 | 
				
			||||||
 | 
					   not compatible with the zlib.h header file used by the application.
 | 
				
			||||||
 | 
					   This check is automatically made by deflateInit and inflateInit.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Initializes the internal stream state for compression. The fields
 | 
				
			||||||
 | 
					   zalloc, zfree and opaque must be initialized before by the caller.
 | 
				
			||||||
 | 
					   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
 | 
				
			||||||
 | 
					   use default allocation functions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 | 
				
			||||||
 | 
					   1 gives best speed, 9 gives best compression, 0 gives no compression at
 | 
				
			||||||
 | 
					   all (the input data is simply copied a block at a time).
 | 
				
			||||||
 | 
					   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
 | 
				
			||||||
 | 
					   compression (currently equivalent to level 6).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
 | 
				
			||||||
 | 
					   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
 | 
				
			||||||
 | 
					   with the version assumed by the caller (ZLIB_VERSION).
 | 
				
			||||||
 | 
					   msg is set to null if there is no error message.  deflateInit does not
 | 
				
			||||||
 | 
					   perform any compression: this will be done by deflate().
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					    deflate compresses as much data as possible, and stops when the input
 | 
				
			||||||
 | 
					  buffer becomes empty or the output buffer becomes full. It may introduce some
 | 
				
			||||||
 | 
					  output latency (reading input without producing any output) except when
 | 
				
			||||||
 | 
					  forced to flush.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The detailed semantics are as follows. deflate performs one or both of the
 | 
				
			||||||
 | 
					  following actions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Compress more input starting at next_in and update next_in and avail_in
 | 
				
			||||||
 | 
					    accordingly. If not all input can be processed (because there is not
 | 
				
			||||||
 | 
					    enough room in the output buffer), next_in and avail_in are updated and
 | 
				
			||||||
 | 
					    processing will resume at this point for the next call of deflate().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Provide more output starting at next_out and update next_out and avail_out
 | 
				
			||||||
 | 
					    accordingly. This action is forced if the parameter flush is non zero.
 | 
				
			||||||
 | 
					    Forcing flush frequently degrades the compression ratio, so this parameter
 | 
				
			||||||
 | 
					    should be set only when necessary (in interactive applications).
 | 
				
			||||||
 | 
					    Some output may be provided even if flush is not set.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Before the call of deflate(), the application should ensure that at least
 | 
				
			||||||
 | 
					  one of the actions is possible, by providing more input and/or consuming
 | 
				
			||||||
 | 
					  more output, and updating avail_in or avail_out accordingly; avail_out
 | 
				
			||||||
 | 
					  should never be zero before the call. The application can consume the
 | 
				
			||||||
 | 
					  compressed output when it wants, for example when the output buffer is full
 | 
				
			||||||
 | 
					  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
 | 
				
			||||||
 | 
					  and with zero avail_out, it must be called again after making room in the
 | 
				
			||||||
 | 
					  output buffer because there might be more output pending.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 | 
				
			||||||
 | 
					  flushed to the output buffer and the output is aligned on a byte boundary, so
 | 
				
			||||||
 | 
					  that the decompressor can get all input data available so far. (In particular
 | 
				
			||||||
 | 
					  avail_in is zero after the call if enough output space has been provided
 | 
				
			||||||
 | 
					  before the call.)  Flushing may degrade compression for some compression
 | 
				
			||||||
 | 
					  algorithms and so it should be used only when necessary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If flush is set to Z_FULL_FLUSH, all output is flushed as with
 | 
				
			||||||
 | 
					  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
 | 
				
			||||||
 | 
					  restart from this point if previous compressed data has been damaged or if
 | 
				
			||||||
 | 
					  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
 | 
				
			||||||
 | 
					  the compression.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If deflate returns with avail_out == 0, this function must be called again
 | 
				
			||||||
 | 
					  with the same value of the flush parameter and more output space (updated
 | 
				
			||||||
 | 
					  avail_out), until the flush is complete (deflate returns with non-zero
 | 
				
			||||||
 | 
					  avail_out).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If the parameter flush is set to Z_FINISH, pending input is processed,
 | 
				
			||||||
 | 
					  pending output is flushed and deflate returns with Z_STREAM_END if there
 | 
				
			||||||
 | 
					  was enough output space; if deflate returns with Z_OK, this function must be
 | 
				
			||||||
 | 
					  called again with Z_FINISH and more output space (updated avail_out) but no
 | 
				
			||||||
 | 
					  more input data, until it returns with Z_STREAM_END or an error. After
 | 
				
			||||||
 | 
					  deflate has returned Z_STREAM_END, the only possible operations on the
 | 
				
			||||||
 | 
					  stream are deflateReset or deflateEnd.
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    Z_FINISH can be used immediately after deflateInit if all the compression
 | 
				
			||||||
 | 
					  is to be done in a single step. In this case, avail_out must be at least
 | 
				
			||||||
 | 
					  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
 | 
				
			||||||
 | 
					  Z_STREAM_END, then it must be called again as described above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    deflate() sets strm->adler to the adler32 checksum of all input read
 | 
				
			||||||
 | 
					  so far (that is, total_in bytes).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    deflate() may update data_type if it can make a good guess about
 | 
				
			||||||
 | 
					  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
 | 
				
			||||||
 | 
					  binary. This field is only for information purposes and does not affect
 | 
				
			||||||
 | 
					  the compression algorithm in any manner.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    deflate() returns Z_OK if some progress has been made (more input
 | 
				
			||||||
 | 
					  processed or more output produced), Z_STREAM_END if all input has been
 | 
				
			||||||
 | 
					  consumed and all output has been produced (only when flush is set to
 | 
				
			||||||
 | 
					  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
 | 
				
			||||||
 | 
					  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
 | 
				
			||||||
 | 
					  (for example avail_in or avail_out was zero).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     All dynamically allocated data structures for this stream are freed.
 | 
				
			||||||
 | 
					   This function discards any unprocessed input and does not flush any
 | 
				
			||||||
 | 
					   pending output.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
 | 
				
			||||||
 | 
					   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
 | 
				
			||||||
 | 
					   prematurely (some input or output was discarded). In the error case,
 | 
				
			||||||
 | 
					   msg may be set but then points to a static string (which must not be
 | 
				
			||||||
 | 
					   deallocated).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Initializes the internal stream state for decompression. The fields
 | 
				
			||||||
 | 
					   next_in, avail_in, zalloc, zfree and opaque must be initialized before by
 | 
				
			||||||
 | 
					   the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
 | 
				
			||||||
 | 
					   value depends on the compression method), inflateInit determines the
 | 
				
			||||||
 | 
					   compression method from the zlib header and allocates all data structures
 | 
				
			||||||
 | 
					   accordingly; otherwise the allocation will be deferred to the first call of
 | 
				
			||||||
 | 
					   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
 | 
				
			||||||
 | 
					   use default allocation functions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
 | 
				
			||||||
 | 
					   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
 | 
				
			||||||
 | 
					   version assumed by the caller.  msg is set to null if there is no error
 | 
				
			||||||
 | 
					   message. inflateInit does not perform any decompression apart from reading
 | 
				
			||||||
 | 
					   the zlib header if present: this will be done by inflate().  (So next_in and
 | 
				
			||||||
 | 
					   avail_in may be modified, but next_out and avail_out are unchanged.)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					    inflate decompresses as much data as possible, and stops when the input
 | 
				
			||||||
 | 
					  buffer becomes empty or the output buffer becomes full. It may some
 | 
				
			||||||
 | 
					  introduce some output latency (reading input without producing any output)
 | 
				
			||||||
 | 
					  except when forced to flush.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  The detailed semantics are as follows. inflate performs one or both of the
 | 
				
			||||||
 | 
					  following actions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Decompress more input starting at next_in and update next_in and avail_in
 | 
				
			||||||
 | 
					    accordingly. If not all input can be processed (because there is not
 | 
				
			||||||
 | 
					    enough room in the output buffer), next_in is updated and processing
 | 
				
			||||||
 | 
					    will resume at this point for the next call of inflate().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - Provide more output starting at next_out and update next_out and avail_out
 | 
				
			||||||
 | 
					    accordingly.  inflate() provides as much output as possible, until there
 | 
				
			||||||
 | 
					    is no more input data or no more space in the output buffer (see below
 | 
				
			||||||
 | 
					    about the flush parameter).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Before the call of inflate(), the application should ensure that at least
 | 
				
			||||||
 | 
					  one of the actions is possible, by providing more input and/or consuming
 | 
				
			||||||
 | 
					  more output, and updating the next_* and avail_* values accordingly.
 | 
				
			||||||
 | 
					  The application can consume the uncompressed output when it wants, for
 | 
				
			||||||
 | 
					  example when the output buffer is full (avail_out == 0), or after each
 | 
				
			||||||
 | 
					  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
 | 
				
			||||||
 | 
					  must be called again after making room in the output buffer because there
 | 
				
			||||||
 | 
					  might be more output pending.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
 | 
				
			||||||
 | 
					  output as possible to the output buffer. The flushing behavior of inflate is
 | 
				
			||||||
 | 
					  not specified for values of the flush parameter other than Z_SYNC_FLUSH
 | 
				
			||||||
 | 
					  and Z_FINISH, but the current implementation actually flushes as much output
 | 
				
			||||||
 | 
					  as possible anyway.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    inflate() should normally be called until it returns Z_STREAM_END or an
 | 
				
			||||||
 | 
					  error. However if all decompression is to be performed in a single step
 | 
				
			||||||
 | 
					  (a single call of inflate), the parameter flush should be set to
 | 
				
			||||||
 | 
					  Z_FINISH. In this case all pending input is processed and all pending
 | 
				
			||||||
 | 
					  output is flushed; avail_out must be large enough to hold all the
 | 
				
			||||||
 | 
					  uncompressed data. (The size of the uncompressed data may have been saved
 | 
				
			||||||
 | 
					  by the compressor for this purpose.) The next operation on this stream must
 | 
				
			||||||
 | 
					  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
 | 
				
			||||||
 | 
					  is never required, but can be used to inform inflate that a faster routine
 | 
				
			||||||
 | 
					  may be used for the single inflate() call.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     If a preset dictionary is needed at this point (see inflateSetDictionary
 | 
				
			||||||
 | 
					  below), inflate sets strm-adler to the adler32 checksum of the
 | 
				
			||||||
 | 
					  dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise 
 | 
				
			||||||
 | 
					  it sets strm->adler to the adler32 checksum of all output produced
 | 
				
			||||||
 | 
					  so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
 | 
				
			||||||
 | 
					  an error code as described below. At the end of the stream, inflate()
 | 
				
			||||||
 | 
					  checks that its computed adler32 checksum is equal to that saved by the
 | 
				
			||||||
 | 
					  compressor and returns Z_STREAM_END only if the checksum is correct.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    inflate() returns Z_OK if some progress has been made (more input processed
 | 
				
			||||||
 | 
					  or more output produced), Z_STREAM_END if the end of the compressed data has
 | 
				
			||||||
 | 
					  been reached and all uncompressed output has been produced, Z_NEED_DICT if a
 | 
				
			||||||
 | 
					  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
 | 
				
			||||||
 | 
					  corrupted (input stream not conforming to the zlib format or incorrect
 | 
				
			||||||
 | 
					  adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
 | 
				
			||||||
 | 
					  (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					  enough memory, Z_BUF_ERROR if no progress is possible or if there was not
 | 
				
			||||||
 | 
					  enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
 | 
				
			||||||
 | 
					  case, the application may then call inflateSync to look for a good
 | 
				
			||||||
 | 
					  compression block.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     All dynamically allocated data structures for this stream are freed.
 | 
				
			||||||
 | 
					   This function discards any unprocessed input and does not flush any
 | 
				
			||||||
 | 
					   pending output.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
 | 
				
			||||||
 | 
					   was inconsistent. In the error case, msg may be set but then points to a
 | 
				
			||||||
 | 
					   static string (which must not be deallocated).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* Advanced functions */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					    The following functions are needed only in some special applications.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*   
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
 | 
				
			||||||
 | 
					                                     int  level,
 | 
				
			||||||
 | 
					                                     int  method,
 | 
				
			||||||
 | 
					                                     int  windowBits,
 | 
				
			||||||
 | 
					                                     int  memLevel,
 | 
				
			||||||
 | 
					                                     int  strategy));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     This is another version of deflateInit with more compression options. The
 | 
				
			||||||
 | 
					   fields next_in, zalloc, zfree and opaque must be initialized before by
 | 
				
			||||||
 | 
					   the caller.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The method parameter is the compression method. It must be Z_DEFLATED in
 | 
				
			||||||
 | 
					   this version of the library.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The windowBits parameter is the base two logarithm of the window size
 | 
				
			||||||
 | 
					   (the size of the history buffer).  It should be in the range 8..15 for this
 | 
				
			||||||
 | 
					   version of the library. Larger values of this parameter result in better
 | 
				
			||||||
 | 
					   compression at the expense of memory usage. The default value is 15 if
 | 
				
			||||||
 | 
					   deflateInit is used instead.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The memLevel parameter specifies how much memory should be allocated
 | 
				
			||||||
 | 
					   for the internal compression state. memLevel=1 uses minimum memory but
 | 
				
			||||||
 | 
					   is slow and reduces compression ratio; memLevel=9 uses maximum memory
 | 
				
			||||||
 | 
					   for optimal speed. The default value is 8. See zconf.h for total memory
 | 
				
			||||||
 | 
					   usage as a function of windowBits and memLevel.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The strategy parameter is used to tune the compression algorithm. Use the
 | 
				
			||||||
 | 
					   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
 | 
				
			||||||
 | 
					   filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
 | 
				
			||||||
 | 
					   string match).  Filtered data consists mostly of small values with a
 | 
				
			||||||
 | 
					   somewhat random distribution. In this case, the compression algorithm is
 | 
				
			||||||
 | 
					   tuned to compress them better. The effect of Z_FILTERED is to force more
 | 
				
			||||||
 | 
					   Huffman coding and less string matching; it is somewhat intermediate
 | 
				
			||||||
 | 
					   between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
 | 
				
			||||||
 | 
					   the compression ratio but not the correctness of the compressed output even
 | 
				
			||||||
 | 
					   if it is not set appropriately.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 | 
				
			||||||
 | 
					   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
 | 
				
			||||||
 | 
					   method). msg is set to null if there is no error message.  deflateInit2 does
 | 
				
			||||||
 | 
					   not perform any compression: this will be done by deflate().
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					                            
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
 | 
				
			||||||
 | 
					                                             const Bytef *dictionary,
 | 
				
			||||||
 | 
					                                             uInt  dictLength));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Initializes the compression dictionary from the given byte sequence
 | 
				
			||||||
 | 
					   without producing any compressed output. This function must be called
 | 
				
			||||||
 | 
					   immediately after deflateInit, deflateInit2 or deflateReset, before any
 | 
				
			||||||
 | 
					   call of deflate. The compressor and decompressor must use exactly the same
 | 
				
			||||||
 | 
					   dictionary (see inflateSetDictionary).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The dictionary should consist of strings (byte sequences) that are likely
 | 
				
			||||||
 | 
					   to be encountered later in the data to be compressed, with the most commonly
 | 
				
			||||||
 | 
					   used strings preferably put towards the end of the dictionary. Using a
 | 
				
			||||||
 | 
					   dictionary is most useful when the data to be compressed is short and can be
 | 
				
			||||||
 | 
					   predicted with good accuracy; the data can then be compressed better than
 | 
				
			||||||
 | 
					   with the default empty dictionary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Depending on the size of the compression data structures selected by
 | 
				
			||||||
 | 
					   deflateInit or deflateInit2, a part of the dictionary may in effect be
 | 
				
			||||||
 | 
					   discarded, for example if the dictionary is larger than the window size in
 | 
				
			||||||
 | 
					   deflate or deflate2. Thus the strings most likely to be useful should be
 | 
				
			||||||
 | 
					   put at the end of the dictionary, not at the front.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Upon return of this function, strm->adler is set to the Adler32 value
 | 
				
			||||||
 | 
					   of the dictionary; the decompressor may later use this value to determine
 | 
				
			||||||
 | 
					   which dictionary has been used by the compressor. (The Adler32 value
 | 
				
			||||||
 | 
					   applies to the whole dictionary even if only a subset of the dictionary is
 | 
				
			||||||
 | 
					   actually used by the compressor.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
 | 
				
			||||||
 | 
					   parameter is invalid (such as NULL dictionary) or the stream state is
 | 
				
			||||||
 | 
					   inconsistent (for example if deflate has already been called for this stream
 | 
				
			||||||
 | 
					   or if the compression method is bsort). deflateSetDictionary does not
 | 
				
			||||||
 | 
					   perform any compression: this will be done by deflate().
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
 | 
				
			||||||
 | 
					                                    z_streamp source));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Sets the destination stream as a complete copy of the source stream.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     This function can be useful when several compression strategies will be
 | 
				
			||||||
 | 
					   tried, for example when there are several ways of pre-processing the input
 | 
				
			||||||
 | 
					   data with a filter. The streams that will be discarded should then be freed
 | 
				
			||||||
 | 
					   by calling deflateEnd.  Note that deflateCopy duplicates the internal
 | 
				
			||||||
 | 
					   compression state which can be quite large, so this strategy is slow and
 | 
				
			||||||
 | 
					   can consume lots of memory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
 | 
				
			||||||
 | 
					   (such as zalloc being NULL). msg is left unchanged in both source and
 | 
				
			||||||
 | 
					   destination.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     This function is equivalent to deflateEnd followed by deflateInit,
 | 
				
			||||||
 | 
					   but does not free and reallocate all the internal compression state.
 | 
				
			||||||
 | 
					   The stream will keep the same compression level and any other attributes
 | 
				
			||||||
 | 
					   that may have been set by deflateInit2.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 | 
				
			||||||
 | 
					   stream state was inconsistent (such as zalloc or state being NULL).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
 | 
				
			||||||
 | 
									      int level,
 | 
				
			||||||
 | 
									      int strategy));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Dynamically update the compression level and compression strategy.  The
 | 
				
			||||||
 | 
					   interpretation of level and strategy is as in deflateInit2.  This can be
 | 
				
			||||||
 | 
					   used to switch between compression and straight copy of the input data, or
 | 
				
			||||||
 | 
					   to switch to a different kind of input data requiring a different
 | 
				
			||||||
 | 
					   strategy. If the compression level is changed, the input available so far
 | 
				
			||||||
 | 
					   is compressed with the old level (and may be flushed); the new level will
 | 
				
			||||||
 | 
					   take effect only at the next call of deflate().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     Before the call of deflateParams, the stream state must be set as for
 | 
				
			||||||
 | 
					   a call of deflate(), since the currently available input may have to
 | 
				
			||||||
 | 
					   be compressed and flushed. In particular, strm->avail_out must be non-zero.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
 | 
				
			||||||
 | 
					   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
 | 
				
			||||||
 | 
					   if strm->avail_out was zero.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*   
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
 | 
				
			||||||
 | 
					                                     int  windowBits));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     This is another version of inflateInit with an extra parameter. The
 | 
				
			||||||
 | 
					   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
 | 
				
			||||||
 | 
					   before by the caller.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     The windowBits parameter is the base two logarithm of the maximum window
 | 
				
			||||||
 | 
					   size (the size of the history buffer).  It should be in the range 8..15 for
 | 
				
			||||||
 | 
					   this version of the library. The default value is 15 if inflateInit is used
 | 
				
			||||||
 | 
					   instead. If a compressed stream with a larger window size is given as
 | 
				
			||||||
 | 
					   input, inflate() will return with the error code Z_DATA_ERROR instead of
 | 
				
			||||||
 | 
					   trying to allocate a larger window.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 | 
				
			||||||
 | 
					   memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
 | 
				
			||||||
 | 
					   memLevel). msg is set to null if there is no error message.  inflateInit2
 | 
				
			||||||
 | 
					   does not perform any decompression apart from reading the zlib header if
 | 
				
			||||||
 | 
					   present: this will be done by inflate(). (So next_in and avail_in may be
 | 
				
			||||||
 | 
					   modified, but next_out and avail_out are unchanged.)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
 | 
				
			||||||
 | 
					                                             const Bytef *dictionary,
 | 
				
			||||||
 | 
					                                             uInt  dictLength));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Initializes the decompression dictionary from the given uncompressed byte
 | 
				
			||||||
 | 
					   sequence. This function must be called immediately after a call of inflate
 | 
				
			||||||
 | 
					   if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
 | 
				
			||||||
 | 
					   can be determined from the Adler32 value returned by this call of
 | 
				
			||||||
 | 
					   inflate. The compressor and decompressor must use exactly the same
 | 
				
			||||||
 | 
					   dictionary (see deflateSetDictionary).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
 | 
				
			||||||
 | 
					   parameter is invalid (such as NULL dictionary) or the stream state is
 | 
				
			||||||
 | 
					   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
 | 
				
			||||||
 | 
					   expected one (incorrect Adler32 value). inflateSetDictionary does not
 | 
				
			||||||
 | 
					   perform any decompression: this will be done by subsequent calls of
 | 
				
			||||||
 | 
					   inflate().
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					    Skips invalid compressed data until a full flush point (see above the
 | 
				
			||||||
 | 
					  description of deflate with Z_FULL_FLUSH) can be found, or until all
 | 
				
			||||||
 | 
					  available input is skipped. No output is provided.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
 | 
				
			||||||
 | 
					  if no more input was provided, Z_DATA_ERROR if no flush point has been found,
 | 
				
			||||||
 | 
					  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
 | 
				
			||||||
 | 
					  case, the application may save the current current value of total_in which
 | 
				
			||||||
 | 
					  indicates where valid compressed data was found. In the error case, the
 | 
				
			||||||
 | 
					  application may repeatedly call inflateSync, providing more input each time,
 | 
				
			||||||
 | 
					  until success or end of the input data.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     This function is equivalent to inflateEnd followed by inflateInit,
 | 
				
			||||||
 | 
					   but does not free and reallocate all the internal decompression state.
 | 
				
			||||||
 | 
					   The stream will keep attributes that may have been set by inflateInit2.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 | 
				
			||||||
 | 
					   stream state was inconsistent (such as zalloc or state being NULL).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* utility functions */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     The following utility functions are implemented on top of the
 | 
				
			||||||
 | 
					   basic stream-oriented functions. To simplify the interface, some
 | 
				
			||||||
 | 
					   default options are assumed (compression level and memory usage,
 | 
				
			||||||
 | 
					   standard memory allocation functions). The source code of these
 | 
				
			||||||
 | 
					   utility functions can easily be modified if you need special options.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
 | 
				
			||||||
 | 
					                                 const Bytef *source, uLong sourceLen));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Compresses the source buffer into the destination buffer.  sourceLen is
 | 
				
			||||||
 | 
					   the byte length of the source buffer. Upon entry, destLen is the total
 | 
				
			||||||
 | 
					   size of the destination buffer, which must be at least 0.1% larger than
 | 
				
			||||||
 | 
					   sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
 | 
				
			||||||
 | 
					   compressed buffer.
 | 
				
			||||||
 | 
					     This function can be used to compress a whole file at once if the
 | 
				
			||||||
 | 
					   input file is mmap'ed.
 | 
				
			||||||
 | 
					     compress returns Z_OK if success, Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					   enough memory, Z_BUF_ERROR if there was not enough room in the output
 | 
				
			||||||
 | 
					   buffer.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
 | 
				
			||||||
 | 
					                                  const Bytef *source, uLong sourceLen,
 | 
				
			||||||
 | 
					                                  int level));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Compresses the source buffer into the destination buffer. The level
 | 
				
			||||||
 | 
					   parameter has the same meaning as in deflateInit.  sourceLen is the byte
 | 
				
			||||||
 | 
					   length of the source buffer. Upon entry, destLen is the total size of the
 | 
				
			||||||
 | 
					   destination buffer, which must be at least 0.1% larger than sourceLen plus
 | 
				
			||||||
 | 
					   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 | 
				
			||||||
 | 
					   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
 | 
				
			||||||
 | 
					   Z_STREAM_ERROR if the level parameter is invalid.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 | 
				
			||||||
 | 
					                                   const Bytef *source, uLong sourceLen));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Decompresses the source buffer into the destination buffer.  sourceLen is
 | 
				
			||||||
 | 
					   the byte length of the source buffer. Upon entry, destLen is the total
 | 
				
			||||||
 | 
					   size of the destination buffer, which must be large enough to hold the
 | 
				
			||||||
 | 
					   entire uncompressed data. (The size of the uncompressed data must have
 | 
				
			||||||
 | 
					   been saved previously by the compressor and transmitted to the decompressor
 | 
				
			||||||
 | 
					   by some mechanism outside the scope of this compression library.)
 | 
				
			||||||
 | 
					   Upon exit, destLen is the actual size of the compressed buffer.
 | 
				
			||||||
 | 
					     This function can be used to decompress a whole file at once if the
 | 
				
			||||||
 | 
					   input file is mmap'ed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
 | 
				
			||||||
 | 
					   enough memory, Z_BUF_ERROR if there was not enough room in the output
 | 
				
			||||||
 | 
					   buffer, or Z_DATA_ERROR if the input data was corrupted.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef voidp gzFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Opens a gzip (.gz) file for reading or writing. The mode parameter
 | 
				
			||||||
 | 
					   is as in fopen ("rb" or "wb") but can also include a compression level
 | 
				
			||||||
 | 
					   ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
 | 
				
			||||||
 | 
					   Huffman only compression as in "wb1h". (See the description
 | 
				
			||||||
 | 
					   of deflateInit2 for more information about the strategy parameter.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     gzopen can be used to read a file which is not in gzip format; in this
 | 
				
			||||||
 | 
					   case gzread will directly read from the file without decompression.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     gzopen returns NULL if the file could not be opened or if there was
 | 
				
			||||||
 | 
					   insufficient memory to allocate the (de)compression state; errno
 | 
				
			||||||
 | 
					   can be checked to distinguish the two cases (if errno is zero, the
 | 
				
			||||||
 | 
					   zlib error is Z_MEM_ERROR).  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     gzdopen() associates a gzFile with the file descriptor fd.  File
 | 
				
			||||||
 | 
					   descriptors are obtained from calls like open, dup, creat, pipe or
 | 
				
			||||||
 | 
					   fileno (in the file has been previously opened with fopen).
 | 
				
			||||||
 | 
					   The mode parameter is as in gzopen.
 | 
				
			||||||
 | 
					     The next call of gzclose on the returned gzFile will also close the
 | 
				
			||||||
 | 
					   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
 | 
				
			||||||
 | 
					   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
 | 
				
			||||||
 | 
					     gzdopen returns NULL if there was insufficient memory to allocate
 | 
				
			||||||
 | 
					   the (de)compression state.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Dynamically update the compression level or strategy. See the description
 | 
				
			||||||
 | 
					   of deflateInit2 for the meaning of these parameters.
 | 
				
			||||||
 | 
					     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
 | 
				
			||||||
 | 
					   opened for writing.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Reads the given number of uncompressed bytes from the compressed file.
 | 
				
			||||||
 | 
					   If the input file was not in gzip format, gzread copies the given number
 | 
				
			||||||
 | 
					   of bytes into the buffer.
 | 
				
			||||||
 | 
					     gzread returns the number of uncompressed bytes actually read (0 for
 | 
				
			||||||
 | 
					   end of file, -1 for error). */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzwrite OF((gzFile file, 
 | 
				
			||||||
 | 
									   const voidp buf, unsigned len));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Writes the given number of uncompressed bytes into the compressed file.
 | 
				
			||||||
 | 
					   gzwrite returns the number of uncompressed bytes actually written
 | 
				
			||||||
 | 
					   (0 in case of error).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Converts, formats, and writes the args to the compressed file under
 | 
				
			||||||
 | 
					   control of the format string, as in fprintf. gzprintf returns the number of
 | 
				
			||||||
 | 
					   uncompressed bytes actually written (0 in case of error).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					      Writes the given null-terminated string to the compressed file, excluding
 | 
				
			||||||
 | 
					   the terminating null character.
 | 
				
			||||||
 | 
					      gzputs returns the number of characters written, or -1 in case of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					      Reads bytes from the compressed file until len-1 characters are read, or
 | 
				
			||||||
 | 
					   a newline character is read and transferred to buf, or an end-of-file
 | 
				
			||||||
 | 
					   condition is encountered.  The string is then terminated with a null
 | 
				
			||||||
 | 
					   character.
 | 
				
			||||||
 | 
					      gzgets returns buf, or Z_NULL in case of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					      Writes c, converted to an unsigned char, into the compressed file.
 | 
				
			||||||
 | 
					   gzputc returns the value that was written, or -1 in case of error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					      Reads one byte from the compressed file. gzgetc returns this byte
 | 
				
			||||||
 | 
					   or -1 in case of end of file or error.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Flushes all pending output into the compressed file. The parameter
 | 
				
			||||||
 | 
					   flush is as in the deflate() function. The return value is the zlib
 | 
				
			||||||
 | 
					   error number (see function gzerror below). gzflush returns Z_OK if
 | 
				
			||||||
 | 
					   the flush parameter is Z_FINISH and all output could be flushed.
 | 
				
			||||||
 | 
					     gzflush should be called only when strictly necessary because it can
 | 
				
			||||||
 | 
					   degrade compression.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
 | 
				
			||||||
 | 
									      z_off_t offset, int whence));
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					      Sets the starting position for the next gzread or gzwrite on the
 | 
				
			||||||
 | 
					   given compressed file. The offset represents a number of bytes in the
 | 
				
			||||||
 | 
					   uncompressed data stream. The whence parameter is defined as in lseek(2);
 | 
				
			||||||
 | 
					   the value SEEK_END is not supported.
 | 
				
			||||||
 | 
					     If the file is opened for reading, this function is emulated but can be
 | 
				
			||||||
 | 
					   extremely slow. If the file is opened for writing, only forward seeks are
 | 
				
			||||||
 | 
					   supported; gzseek then compresses a sequence of zeroes up to the new
 | 
				
			||||||
 | 
					   starting position.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      gzseek returns the resulting offset location as measured in bytes from
 | 
				
			||||||
 | 
					   the beginning of the uncompressed stream, or -1 in case of error, in
 | 
				
			||||||
 | 
					   particular if the file is opened for writing and the new starting position
 | 
				
			||||||
 | 
					   would be before the current position.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Rewinds the given file. This function is supported only for reading.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Returns the starting position for the next gzread or gzwrite on the
 | 
				
			||||||
 | 
					   given compressed file. This position represents a number of bytes in the
 | 
				
			||||||
 | 
					   uncompressed data stream.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT gzeof OF((gzFile file));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Returns 1 when EOF has previously been detected reading the given
 | 
				
			||||||
 | 
					   input stream, otherwise zero.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Flushes all pending output if necessary, closes the compressed file
 | 
				
			||||||
 | 
					   and deallocates all the (de)compression state. The return value is the zlib
 | 
				
			||||||
 | 
					   error number (see function gzerror below).
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Returns the error message for the last error which occurred on the
 | 
				
			||||||
 | 
					   given compressed file. errnum is set to zlib error number. If an
 | 
				
			||||||
 | 
					   error occurred in the file system and not in the compression library,
 | 
				
			||||||
 | 
					   errnum is set to Z_ERRNO and the application may consult errno
 | 
				
			||||||
 | 
					   to get the exact error code.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* checksum functions */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     These functions are not related to compression but are exported
 | 
				
			||||||
 | 
					   anyway because they might be useful in applications using the
 | 
				
			||||||
 | 
					   compression library.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
 | 
				
			||||||
 | 
					   return the updated checksum. If buf is NULL, this function returns
 | 
				
			||||||
 | 
					   the required initial value for the checksum.
 | 
				
			||||||
 | 
					   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
 | 
				
			||||||
 | 
					   much faster. Usage example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     uLong adler = adler32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     while (read_buffer(buffer, length) != EOF) {
 | 
				
			||||||
 | 
					       adler = adler32(adler, buffer, length);
 | 
				
			||||||
 | 
					     }
 | 
				
			||||||
 | 
					     if (adler != original_adler) error();
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					     Update a running crc with the bytes buf[0..len-1] and return the updated
 | 
				
			||||||
 | 
					   crc. If buf is NULL, this function returns the required initial value
 | 
				
			||||||
 | 
					   for the crc. Pre- and post-conditioning (one's complement) is performed
 | 
				
			||||||
 | 
					   within this function so it shouldn't be done by the application.
 | 
				
			||||||
 | 
					   Usage example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     uLong crc = crc32(0L, Z_NULL, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     while (read_buffer(buffer, length) != EOF) {
 | 
				
			||||||
 | 
					       crc = crc32(crc, buffer, length);
 | 
				
			||||||
 | 
					     }
 | 
				
			||||||
 | 
					     if (crc != original_crc) error();
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* various hacks, don't look :) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* deflateInit and inflateInit are macros to allow checking the zlib version
 | 
				
			||||||
 | 
					 * and the compiler's view of z_stream:
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
 | 
				
			||||||
 | 
					                                     const char *version, int stream_size));
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
 | 
				
			||||||
 | 
					                                     const char *version, int stream_size));
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
 | 
				
			||||||
 | 
					                                      int windowBits, int memLevel,
 | 
				
			||||||
 | 
					                                      int strategy, const char *version,
 | 
				
			||||||
 | 
					                                      int stream_size));
 | 
				
			||||||
 | 
					ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
 | 
				
			||||||
 | 
					                                      const char *version, int stream_size));
 | 
				
			||||||
 | 
					#define deflateInit(strm, level) \
 | 
				
			||||||
 | 
					        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
 | 
				
			||||||
 | 
					#define inflateInit(strm) \
 | 
				
			||||||
 | 
					        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
 | 
				
			||||||
 | 
					#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
 | 
				
			||||||
 | 
					        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
 | 
				
			||||||
 | 
					                      (strategy),           ZLIB_VERSION, sizeof(z_stream))
 | 
				
			||||||
 | 
					#define inflateInit2(strm, windowBits) \
 | 
				
			||||||
 | 
					        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
 | 
				
			||||||
 | 
					    struct internal_state {int dummy;}; /* hack for buggy compilers */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ZEXTERN const char   * ZEXPORT zError           OF((int err));
 | 
				
			||||||
 | 
					ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
 | 
				
			||||||
 | 
					ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* _ZLIB_H */
 | 
				
			||||||
							
								
								
									
										225
									
								
								src/TZlib/Zip/zutil.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										225
									
								
								src/TZlib/Zip/zutil.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,225 @@
 | 
				
			|||||||
 | 
					/* zutil.c -- target dependent utility functions for the compression library
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h 
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zutil.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct internal_state      {int dummy;}; /* for buggy compilers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef STDC
 | 
				
			||||||
 | 
					extern void exit OF((int));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const char *z_errmsg[10] = {
 | 
				
			||||||
 | 
					"need dictionary",     /* Z_NEED_DICT       2  */
 | 
				
			||||||
 | 
					"stream end",          /* Z_STREAM_END      1  */
 | 
				
			||||||
 | 
					"",                    /* Z_OK              0  */
 | 
				
			||||||
 | 
					"file error",          /* Z_ERRNO         (-1) */
 | 
				
			||||||
 | 
					"stream error",        /* Z_STREAM_ERROR  (-2) */
 | 
				
			||||||
 | 
					"data error",          /* Z_DATA_ERROR    (-3) */
 | 
				
			||||||
 | 
					"insufficient memory", /* Z_MEM_ERROR     (-4) */
 | 
				
			||||||
 | 
					"buffer error",        /* Z_BUF_ERROR     (-5) */
 | 
				
			||||||
 | 
					"incompatible version",/* Z_VERSION_ERROR (-6) */
 | 
				
			||||||
 | 
					""};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const char * ZEXPORT zlibVersion()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ZLIB_VERSION;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#  ifndef verbose
 | 
				
			||||||
 | 
					#    define verbose 0
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					int z_verbose = verbose;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void z_error (m)
 | 
				
			||||||
 | 
					    char *m;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    fprintf(stderr, "%s\n", m);
 | 
				
			||||||
 | 
					    exit(1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* exported to allow conversion of error code to string for compress() and
 | 
				
			||||||
 | 
					 * uncompress()
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					const char * ZEXPORT zError(err)
 | 
				
			||||||
 | 
					    int err;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ERR_MSG(err);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef HAVE_MEMCPY
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void zmemcpy(dest, source, len)
 | 
				
			||||||
 | 
					    Bytef* dest;
 | 
				
			||||||
 | 
					    const Bytef* source;
 | 
				
			||||||
 | 
					    uInt  len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (len == 0) return;
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        *dest++ = *source++; /* ??? to be unrolled */
 | 
				
			||||||
 | 
					    } while (--len != 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int zmemcmp(s1, s2, len)
 | 
				
			||||||
 | 
					    const Bytef* s1;
 | 
				
			||||||
 | 
					    const Bytef* s2;
 | 
				
			||||||
 | 
					    uInt  len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uInt j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (j = 0; j < len; j++) {
 | 
				
			||||||
 | 
					        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void zmemzero(dest, len)
 | 
				
			||||||
 | 
					    Bytef* dest;
 | 
				
			||||||
 | 
					    uInt  len;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (len == 0) return;
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					        *dest++ = 0;  /* ??? to be unrolled */
 | 
				
			||||||
 | 
					    } while (--len != 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __TURBOC__
 | 
				
			||||||
 | 
					#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
 | 
				
			||||||
 | 
					/* Small and medium model in Turbo C are for now limited to near allocation
 | 
				
			||||||
 | 
					 * with reduced MAX_WBITS and MAX_MEM_LEVEL
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#  define MY_ZCALLOC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
 | 
				
			||||||
 | 
					 * and farmalloc(64K) returns a pointer with an offset of 8, so we
 | 
				
			||||||
 | 
					 * must fix the pointer. Warning: the pointer must be put back to its
 | 
				
			||||||
 | 
					 * original form in order to free it, use zcfree().
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_PTR 10
 | 
				
			||||||
 | 
					/* 10*64K = 640K */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local int next_ptr = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct ptr_table_s {
 | 
				
			||||||
 | 
					    voidpf org_ptr;
 | 
				
			||||||
 | 
					    voidpf new_ptr;
 | 
				
			||||||
 | 
					} ptr_table;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local ptr_table table[MAX_PTR];
 | 
				
			||||||
 | 
					/* This table is used to remember the original form of pointers
 | 
				
			||||||
 | 
					 * to large buffers (64K). Such pointers are normalized with a zero offset.
 | 
				
			||||||
 | 
					 * Since MSDOS is not a preemptive multitasking OS, this table is not
 | 
				
			||||||
 | 
					 * protected from concurrent access. This hack doesn't work anyway on
 | 
				
			||||||
 | 
					 * a protected system like OS/2. Use Microsoft C instead.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    voidpf buf = opaque; /* just to make some compilers happy */
 | 
				
			||||||
 | 
					    ulg bsize = (ulg)items*size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* If we allocate less than 65520 bytes, we assume that farmalloc
 | 
				
			||||||
 | 
					     * will return a usable pointer which doesn't have to be normalized.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    if (bsize < 65520L) {
 | 
				
			||||||
 | 
					        buf = farmalloc(bsize);
 | 
				
			||||||
 | 
					        if (*(ush*)&buf != 0) return buf;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        buf = farmalloc(bsize + 16L);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
 | 
				
			||||||
 | 
					    table[next_ptr].org_ptr = buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Normalize the pointer to seg:0 */
 | 
				
			||||||
 | 
					    *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
 | 
				
			||||||
 | 
					    *(ush*)&buf = 0;
 | 
				
			||||||
 | 
					    table[next_ptr++].new_ptr = buf;
 | 
				
			||||||
 | 
					    return buf;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void  zcfree (voidpf opaque, voidpf ptr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int n;
 | 
				
			||||||
 | 
					    if (*(ush*)&ptr != 0) { /* object < 64K */
 | 
				
			||||||
 | 
					        farfree(ptr);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* Find the original pointer */
 | 
				
			||||||
 | 
					    for (n = 0; n < next_ptr; n++) {
 | 
				
			||||||
 | 
					        if (ptr != table[n].new_ptr) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        farfree(table[n].org_ptr);
 | 
				
			||||||
 | 
					        while (++n < next_ptr) {
 | 
				
			||||||
 | 
					            table[n-1] = table[n];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        next_ptr--;
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ptr = opaque; /* just to make some compilers happy */
 | 
				
			||||||
 | 
					    Assert(0, "zcfree: ptr not found");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#endif /* __TURBOC__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(M_I86) && !defined(__32BIT__)
 | 
				
			||||||
 | 
					/* Microsoft C in 16-bit mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#  define MY_ZCALLOC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
 | 
				
			||||||
 | 
					#  define _halloc  halloc
 | 
				
			||||||
 | 
					#  define _hfree   hfree
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (opaque) opaque = 0; /* to make compiler happy */
 | 
				
			||||||
 | 
					    return _halloc((long)items, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void  zcfree (voidpf opaque, voidpf ptr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (opaque) opaque = 0; /* to make compiler happy */
 | 
				
			||||||
 | 
					    _hfree(ptr);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* MSC */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef MY_ZCALLOC /* Any system without a special alloc function */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef STDC
 | 
				
			||||||
 | 
					extern voidp  calloc OF((uInt items, uInt size));
 | 
				
			||||||
 | 
					extern void   free   OF((voidpf ptr));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					voidpf zcalloc (opaque, items, size)
 | 
				
			||||||
 | 
					    voidpf opaque;
 | 
				
			||||||
 | 
					    unsigned items;
 | 
				
			||||||
 | 
					    unsigned size;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (opaque) items += size - size; /* make compiler happy */
 | 
				
			||||||
 | 
					    return (voidpf)calloc(items, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void  zcfree (opaque, ptr)
 | 
				
			||||||
 | 
					    voidpf opaque;
 | 
				
			||||||
 | 
					    voidpf ptr;
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    free(ptr);
 | 
				
			||||||
 | 
					    if (opaque) return; /* make compiler happy */
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* MY_ZCALLOC */
 | 
				
			||||||
							
								
								
									
										220
									
								
								src/TZlib/Zip/zutil.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										220
									
								
								src/TZlib/Zip/zutil.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,220 @@
 | 
				
			|||||||
 | 
					/* zutil.h -- internal interface and configuration of the compression library
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2002 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* WARNING: this file should *not* be used by applications. It is
 | 
				
			||||||
 | 
					   part of the implementation of the compression library and is
 | 
				
			||||||
 | 
					   subject to change. Applications should only use zlib.h.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _Z_UTIL_H
 | 
				
			||||||
 | 
					#define _Z_UTIL_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "zlib.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef STDC
 | 
				
			||||||
 | 
					#  include <stddef.h>
 | 
				
			||||||
 | 
					#  include <string.h>
 | 
				
			||||||
 | 
					#  include <stdlib.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef NO_ERRNO_H
 | 
				
			||||||
 | 
					    extern int errno;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#   include <errno.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef local
 | 
				
			||||||
 | 
					#  define local static
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					/* compile with -Dlocal if your debugger can't find static symbols */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef unsigned char  uch;
 | 
				
			||||||
 | 
					typedef uch FAR uchf;
 | 
				
			||||||
 | 
					typedef unsigned short ush;
 | 
				
			||||||
 | 
					typedef ush FAR ushf;
 | 
				
			||||||
 | 
					typedef unsigned long  ulg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
 | 
				
			||||||
 | 
					/* (size given to avoid silly warnings with Visual C++) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ERR_RETURN(strm,err) \
 | 
				
			||||||
 | 
					  return (strm->msg = (char*)ERR_MSG(err), (err))
 | 
				
			||||||
 | 
					/* To be used only when the state is known to be valid */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* common constants */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef DEF_WBITS
 | 
				
			||||||
 | 
					#  define DEF_WBITS MAX_WBITS
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					/* default windowBits for decompression. MAX_WBITS is for compression only */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if MAX_MEM_LEVEL >= 8
 | 
				
			||||||
 | 
					#  define DEF_MEM_LEVEL 8
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					/* default memLevel */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define STORED_BLOCK 0
 | 
				
			||||||
 | 
					#define STATIC_TREES 1
 | 
				
			||||||
 | 
					#define DYN_TREES    2
 | 
				
			||||||
 | 
					/* The three kinds of block type */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MIN_MATCH  3
 | 
				
			||||||
 | 
					#define MAX_MATCH  258
 | 
				
			||||||
 | 
					/* The minimum and maximum match lengths */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* target dependencies */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef MSDOS
 | 
				
			||||||
 | 
					#  define OS_CODE  0x00
 | 
				
			||||||
 | 
					#  if defined(__TURBOC__) || defined(__BORLANDC__)
 | 
				
			||||||
 | 
					#    if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
 | 
				
			||||||
 | 
					       /* Allow compilation with ANSI keywords only enabled */
 | 
				
			||||||
 | 
					       void _Cdecl farfree( void *block );
 | 
				
			||||||
 | 
					       void *_Cdecl farmalloc( unsigned long nbytes );
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#     include <alloc.h>
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  else /* MSC or DJGPP */
 | 
				
			||||||
 | 
					#    include <malloc.h>
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef OS2
 | 
				
			||||||
 | 
					#  define OS_CODE  0x06
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WIN32 /* Window 95 & Windows NT */
 | 
				
			||||||
 | 
					#  define OS_CODE  0x0b
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(VAXC) || defined(VMS)
 | 
				
			||||||
 | 
					#  define OS_CODE  0x02
 | 
				
			||||||
 | 
					#  define F_OPEN(name, mode) \
 | 
				
			||||||
 | 
					     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef AMIGA
 | 
				
			||||||
 | 
					#  define OS_CODE  0x01
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(ATARI) || defined(atarist)
 | 
				
			||||||
 | 
					#  define OS_CODE  0x05
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(MACOS) || defined(TARGET_OS_MAC)
 | 
				
			||||||
 | 
					#  define OS_CODE  0x07
 | 
				
			||||||
 | 
					#  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
 | 
				
			||||||
 | 
					#    include <unix.h> /* for fdopen */
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    ifndef fdopen
 | 
				
			||||||
 | 
					#      define fdopen(fd,mode) NULL /* No fdopen() */
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __50SERIES /* Prime/PRIMOS */
 | 
				
			||||||
 | 
					#  define OS_CODE  0x0F
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef TOPS20
 | 
				
			||||||
 | 
					#  define OS_CODE  0x0a
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(_BEOS_) || defined(RISCOS)
 | 
				
			||||||
 | 
					#  define fdopen(fd,mode) NULL /* No fdopen() */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if (defined(_MSC_VER) && (_MSC_VER > 600))
 | 
				
			||||||
 | 
					#  define fdopen(fd,type)  _fdopen(fd,type)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* Common defaults */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef OS_CODE
 | 
				
			||||||
 | 
					#  define OS_CODE  0x03  /* assume Unix */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef F_OPEN
 | 
				
			||||||
 | 
					#  define F_OPEN(name, mode) fopen((name), (mode))
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					         /* functions */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_STRERROR
 | 
				
			||||||
 | 
					   extern char *strerror OF((int));
 | 
				
			||||||
 | 
					#  define zstrerror(errnum) strerror(errnum)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#  define zstrerror(errnum) ""
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(pyr)
 | 
				
			||||||
 | 
					#  define NO_MEMCPY
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
 | 
				
			||||||
 | 
					 /* Use our own functions for small and medium model with MSC <= 5.0.
 | 
				
			||||||
 | 
					  * You may have to use the same strategy for Borland C (untested).
 | 
				
			||||||
 | 
					  * The __SC__ check is for Symantec.
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					#  define NO_MEMCPY
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
 | 
				
			||||||
 | 
					#  define HAVE_MEMCPY
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef HAVE_MEMCPY
 | 
				
			||||||
 | 
					#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
 | 
				
			||||||
 | 
					#    define zmemcpy _fmemcpy
 | 
				
			||||||
 | 
					#    define zmemcmp _fmemcmp
 | 
				
			||||||
 | 
					#    define zmemzero(dest, len) _fmemset(dest, 0, len)
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define zmemcpy memcpy
 | 
				
			||||||
 | 
					#    define zmemcmp memcmp
 | 
				
			||||||
 | 
					#    define zmemzero(dest, len) memset(dest, 0, len)
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					   extern void zmemcpy  OF((Bytef* dest, const Bytef* source, uInt len));
 | 
				
			||||||
 | 
					   extern int  zmemcmp  OF((const Bytef* s1, const Bytef* s2, uInt len));
 | 
				
			||||||
 | 
					   extern void zmemzero OF((Bytef* dest, uInt len));
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Diagnostic functions */
 | 
				
			||||||
 | 
					#ifdef DEBUG
 | 
				
			||||||
 | 
					#  include <stdio.h>
 | 
				
			||||||
 | 
					   extern int z_verbose;
 | 
				
			||||||
 | 
					   extern void z_error    OF((char *m));
 | 
				
			||||||
 | 
					#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
 | 
				
			||||||
 | 
					#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
 | 
				
			||||||
 | 
					#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
 | 
				
			||||||
 | 
					#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
 | 
				
			||||||
 | 
					#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
 | 
				
			||||||
 | 
					#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#  define Assert(cond,msg)
 | 
				
			||||||
 | 
					#  define Trace(x)
 | 
				
			||||||
 | 
					#  define Tracev(x)
 | 
				
			||||||
 | 
					#  define Tracevv(x)
 | 
				
			||||||
 | 
					#  define Tracec(c,x)
 | 
				
			||||||
 | 
					#  define Tracecv(c,x)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
 | 
				
			||||||
 | 
									       uInt len));
 | 
				
			||||||
 | 
					voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
 | 
				
			||||||
 | 
					void   zcfree  OF((voidpf opaque, voidpf ptr));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ZALLOC(strm, items, size) \
 | 
				
			||||||
 | 
					           (*((strm)->zalloc))((strm)->opaque, (items), (size))
 | 
				
			||||||
 | 
					#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
 | 
				
			||||||
 | 
					#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* _Z_UTIL_H */
 | 
				
			||||||
							
								
								
									
										32
									
								
								src/TZlib/gzipdemo/ReadMe.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/TZlib/gzipdemo/ReadMe.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					========================================================================
 | 
				
			||||||
 | 
					    CONSOLE APPLICATION : gzipdemo Project Overview
 | 
				
			||||||
 | 
					========================================================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AppWizard has created this gzipdemo application for you.  
 | 
				
			||||||
 | 
					This file contains a summary of what you will find in each of the files that
 | 
				
			||||||
 | 
					make up your gzipdemo application.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gzipdemo.vcproj
 | 
				
			||||||
 | 
					    This is the main project file for VC++ projects generated using an Application Wizard. 
 | 
				
			||||||
 | 
					    It contains information about the version of Visual C++ that generated the file, and 
 | 
				
			||||||
 | 
					    information about the platforms, configurations, and project features selected with the
 | 
				
			||||||
 | 
					    Application Wizard.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gzipdemo.cpp
 | 
				
			||||||
 | 
					    This is the main application source file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					Other standard files:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					StdAfx.h, StdAfx.cpp
 | 
				
			||||||
 | 
					    These files are used to build a precompiled header (PCH) file
 | 
				
			||||||
 | 
					    named gzipdemo.pch and a precompiled types file named StdAfx.obj.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					Other notes:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AppWizard uses "TODO:" comments to indicate parts of the source code you
 | 
				
			||||||
 | 
					should add to or customize.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
							
								
								
									
										36
									
								
								src/TZlib/gzipdemo/gzipdemo.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/TZlib/gzipdemo/gzipdemo.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					// gzipdemo.cpp : Defines the entry point for the console application.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "stdafx.h"
 | 
				
			||||||
 | 
					#include "../GZipHelper.h"
 | 
				
			||||||
 | 
					int _tmain(int argc, _TCHAR* argv[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   /*
 | 
				
			||||||
 | 
						FILE *ain=fopen("d:\\BigExample.txt","rb");
 | 
				
			||||||
 | 
						fseek( ain,0,SEEK_END);
 | 
				
			||||||
 | 
						long size=ftell(ain);
 | 
				
			||||||
 | 
						fseek(ain,0,SEEK_SET);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
						char* buffer=(char*)malloc(size);
 | 
				
			||||||
 | 
						size_t count0=fread(buffer,1,size,ain);
 | 
				
			||||||
 | 
					    CA2GZIP gzip(buffer,size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FILE *aout=fopen("d:\\BigExample.gz","wb");
 | 
				
			||||||
 | 
						size_t count1=fwrite(gzip.pgzip,1,gzip.Length,aout);
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						FILE *in=fopen("d:\\BigExample.gz","rb");
 | 
				
			||||||
 | 
						FILE *out=fopen("c:\\BigExample.txt","wb");
 | 
				
			||||||
 | 
						fseek( in,0,SEEK_END);
 | 
				
			||||||
 | 
						long size=ftell(in);
 | 
				
			||||||
 | 
						fseek(in,0,SEEK_SET);
 | 
				
			||||||
 | 
					    LPGZIP buffer=(LPGZIP)malloc(size);
 | 
				
			||||||
 | 
						size_t count0=fread(buffer,1,size,in);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
						CGZIP2A a(buffer,count0);
 | 
				
			||||||
 | 
						size_t count=strlen(a.psz);
 | 
				
			||||||
 | 
						size_t count1=fwrite(a.psz,1,a.Length,out);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/gzipdemo/gzipdemo.ncb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/gzipdemo/gzipdemo.ncb
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										21
									
								
								src/TZlib/gzipdemo/gzipdemo.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/TZlib/gzipdemo/gzipdemo.sln
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					Microsoft Visual Studio Solution File, Format Version 7.00
 | 
				
			||||||
 | 
					Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gzipdemo", "gzipdemo.vcproj", "{B013F279-7272-47D6-B8C9-B583C2BDE1B4}"
 | 
				
			||||||
 | 
					EndProject
 | 
				
			||||||
 | 
					Global
 | 
				
			||||||
 | 
						GlobalSection(SolutionConfiguration) = preSolution
 | 
				
			||||||
 | 
							ConfigName.0 = Debug
 | 
				
			||||||
 | 
							ConfigName.1 = Release
 | 
				
			||||||
 | 
						EndGlobalSection
 | 
				
			||||||
 | 
						GlobalSection(ProjectDependencies) = postSolution
 | 
				
			||||||
 | 
						EndGlobalSection
 | 
				
			||||||
 | 
						GlobalSection(ProjectConfiguration) = postSolution
 | 
				
			||||||
 | 
							{B013F279-7272-47D6-B8C9-B583C2BDE1B4}.Debug.ActiveCfg = Debug|Win32
 | 
				
			||||||
 | 
							{B013F279-7272-47D6-B8C9-B583C2BDE1B4}.Debug.Build.0 = Debug|Win32
 | 
				
			||||||
 | 
							{B013F279-7272-47D6-B8C9-B583C2BDE1B4}.Release.ActiveCfg = Release|Win32
 | 
				
			||||||
 | 
							{B013F279-7272-47D6-B8C9-B583C2BDE1B4}.Release.Build.0 = Release|Win32
 | 
				
			||||||
 | 
						EndGlobalSection
 | 
				
			||||||
 | 
						GlobalSection(ExtensibilityGlobals) = postSolution
 | 
				
			||||||
 | 
						EndGlobalSection
 | 
				
			||||||
 | 
						GlobalSection(ExtensibilityAddIns) = postSolution
 | 
				
			||||||
 | 
						EndGlobalSection
 | 
				
			||||||
 | 
					EndGlobal
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/gzipdemo/gzipdemo.suo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/gzipdemo/gzipdemo.suo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										226
									
								
								src/TZlib/gzipdemo/gzipdemo.vcproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								src/TZlib/gzipdemo/gzipdemo.vcproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,226 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding = "gb2312"?>
 | 
				
			||||||
 | 
					<VisualStudioProject
 | 
				
			||||||
 | 
						ProjectType="Visual C++"
 | 
				
			||||||
 | 
						Version="7.00"
 | 
				
			||||||
 | 
						Name="gzipdemo"
 | 
				
			||||||
 | 
						ProjectGUID="{B013F279-7272-47D6-B8C9-B583C2BDE1B4}"
 | 
				
			||||||
 | 
						Keyword="Win32Proj">
 | 
				
			||||||
 | 
						<Platforms>
 | 
				
			||||||
 | 
							<Platform
 | 
				
			||||||
 | 
								Name="Win32"/>
 | 
				
			||||||
 | 
						</Platforms>
 | 
				
			||||||
 | 
						<Configurations>
 | 
				
			||||||
 | 
							<Configuration
 | 
				
			||||||
 | 
								Name="Debug|Win32"
 | 
				
			||||||
 | 
								OutputDirectory="Debug"
 | 
				
			||||||
 | 
								IntermediateDirectory="Debug"
 | 
				
			||||||
 | 
								ConfigurationType="1"
 | 
				
			||||||
 | 
								CharacterSet="2">
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCCLCompilerTool"
 | 
				
			||||||
 | 
									Optimization="0"
 | 
				
			||||||
 | 
									PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 | 
				
			||||||
 | 
									MinimalRebuild="TRUE"
 | 
				
			||||||
 | 
									BasicRuntimeChecks="3"
 | 
				
			||||||
 | 
									RuntimeLibrary="5"
 | 
				
			||||||
 | 
									UsePrecompiledHeader="0"
 | 
				
			||||||
 | 
									WarningLevel="3"
 | 
				
			||||||
 | 
									Detect64BitPortabilityProblems="TRUE"
 | 
				
			||||||
 | 
									DebugInformationFormat="4"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCCustomBuildTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCLinkerTool"
 | 
				
			||||||
 | 
									OutputFile="$(OutDir)/gzipdemo.exe"
 | 
				
			||||||
 | 
									LinkIncremental="2"
 | 
				
			||||||
 | 
									GenerateDebugInformation="TRUE"
 | 
				
			||||||
 | 
									ProgramDatabaseFile="$(OutDir)/gzipdemo.pdb"
 | 
				
			||||||
 | 
									SubSystem="1"
 | 
				
			||||||
 | 
									TargetMachine="1"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCMIDLTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPostBuildEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPreBuildEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPreLinkEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCResourceCompilerTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCWebServiceProxyGeneratorTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCWebDeploymentTool"/>
 | 
				
			||||||
 | 
							</Configuration>
 | 
				
			||||||
 | 
							<Configuration
 | 
				
			||||||
 | 
								Name="Release|Win32"
 | 
				
			||||||
 | 
								OutputDirectory="Release"
 | 
				
			||||||
 | 
								IntermediateDirectory="Release"
 | 
				
			||||||
 | 
								ConfigurationType="1"
 | 
				
			||||||
 | 
								CharacterSet="2">
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCCLCompilerTool"
 | 
				
			||||||
 | 
									Optimization="2"
 | 
				
			||||||
 | 
									InlineFunctionExpansion="1"
 | 
				
			||||||
 | 
									OmitFramePointers="TRUE"
 | 
				
			||||||
 | 
									PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 | 
				
			||||||
 | 
									StringPooling="TRUE"
 | 
				
			||||||
 | 
									RuntimeLibrary="4"
 | 
				
			||||||
 | 
									EnableFunctionLevelLinking="TRUE"
 | 
				
			||||||
 | 
									UsePrecompiledHeader="0"
 | 
				
			||||||
 | 
									WarningLevel="3"
 | 
				
			||||||
 | 
									Detect64BitPortabilityProblems="TRUE"
 | 
				
			||||||
 | 
									DebugInformationFormat="3"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCCustomBuildTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCLinkerTool"
 | 
				
			||||||
 | 
									OutputFile="$(OutDir)/gzipdemo.exe"
 | 
				
			||||||
 | 
									LinkIncremental="1"
 | 
				
			||||||
 | 
									GenerateDebugInformation="TRUE"
 | 
				
			||||||
 | 
									SubSystem="1"
 | 
				
			||||||
 | 
									OptimizeReferences="2"
 | 
				
			||||||
 | 
									EnableCOMDATFolding="2"
 | 
				
			||||||
 | 
									TargetMachine="1"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCMIDLTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPostBuildEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPreBuildEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCPreLinkEventTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCResourceCompilerTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCWebServiceProxyGeneratorTool"/>
 | 
				
			||||||
 | 
								<Tool
 | 
				
			||||||
 | 
									Name="VCWebDeploymentTool"/>
 | 
				
			||||||
 | 
							</Configuration>
 | 
				
			||||||
 | 
						</Configurations>
 | 
				
			||||||
 | 
						<Files>
 | 
				
			||||||
 | 
							<Filter
 | 
				
			||||||
 | 
								Name="Source Files"
 | 
				
			||||||
 | 
								Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="gzipdemo.cpp">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="stdafx.cpp">
 | 
				
			||||||
 | 
									<FileConfiguration
 | 
				
			||||||
 | 
										Name="Debug|Win32">
 | 
				
			||||||
 | 
										<Tool
 | 
				
			||||||
 | 
											Name="VCCLCompilerTool"
 | 
				
			||||||
 | 
											UsePrecompiledHeader="1"/>
 | 
				
			||||||
 | 
									</FileConfiguration>
 | 
				
			||||||
 | 
									<FileConfiguration
 | 
				
			||||||
 | 
										Name="Release|Win32">
 | 
				
			||||||
 | 
										<Tool
 | 
				
			||||||
 | 
											Name="VCCLCompilerTool"
 | 
				
			||||||
 | 
											UsePrecompiledHeader="1"/>
 | 
				
			||||||
 | 
									</FileConfiguration>
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<Filter
 | 
				
			||||||
 | 
									Name="zip"
 | 
				
			||||||
 | 
									Filter="">
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\adler32.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\compress.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\crc32.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\deflate.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\gzio.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\infblock.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\infcodes.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\inffast.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\inflate.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\inftrees.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\infutil.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\maketree.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\trees.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\uncompr.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
									<File
 | 
				
			||||||
 | 
										RelativePath="..\Zip\zutil.c">
 | 
				
			||||||
 | 
									</File>
 | 
				
			||||||
 | 
								</Filter>
 | 
				
			||||||
 | 
							</Filter>
 | 
				
			||||||
 | 
							<Filter
 | 
				
			||||||
 | 
								Name="Header Files"
 | 
				
			||||||
 | 
								Filter="h;hpp;hxx;hm;inl;inc">
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\GZipHelper.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\deflate.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\infblock.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\infcodes.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\inffast.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\inffixed.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\inftrees.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\infutil.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="stdafx.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\trees.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\zconf.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\zlib.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
								<File
 | 
				
			||||||
 | 
									RelativePath="..\Zip\zutil.h">
 | 
				
			||||||
 | 
								</File>
 | 
				
			||||||
 | 
							</Filter>
 | 
				
			||||||
 | 
							<Filter
 | 
				
			||||||
 | 
								Name="Resource Files"
 | 
				
			||||||
 | 
								Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
 | 
				
			||||||
 | 
							</Filter>
 | 
				
			||||||
 | 
							<File
 | 
				
			||||||
 | 
								RelativePath="ReadMe.txt">
 | 
				
			||||||
 | 
							</File>
 | 
				
			||||||
 | 
						</Files>
 | 
				
			||||||
 | 
						<Globals>
 | 
				
			||||||
 | 
						</Globals>
 | 
				
			||||||
 | 
					</VisualStudioProject>
 | 
				
			||||||
							
								
								
									
										8
									
								
								src/TZlib/gzipdemo/stdafx.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/TZlib/gzipdemo/stdafx.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					// stdafx.cpp : source file that includes just the standard includes
 | 
				
			||||||
 | 
					// gzipdemo.pch will be the pre-compiled header
 | 
				
			||||||
 | 
					// stdafx.obj will contain the pre-compiled type information
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "stdafx.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: reference any additional headers you need in STDAFX.H
 | 
				
			||||||
 | 
					// and not in this file
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/TZlib/gzipdemo/stdafx.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/TZlib/gzipdemo/stdafx.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					// stdafx.h : include file for standard system include files,
 | 
				
			||||||
 | 
					// or project specific include files that are used frequently, but
 | 
				
			||||||
 | 
					// are changed infrequently
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <tchar.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: reference additional headers your program requires here
 | 
				
			||||||
							
								
								
									
										332
									
								
								src/TZlib/include/zconf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										332
									
								
								src/TZlib/include/zconf.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,332 @@
 | 
				
			|||||||
 | 
					/* zconf.h -- configuration of the zlib compression library
 | 
				
			||||||
 | 
					 * Copyright (C) 1995-2005 Jean-loup Gailly.
 | 
				
			||||||
 | 
					 * For conditions of distribution and use, see copyright notice in zlib.h
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @(#) $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ZCONF_H
 | 
				
			||||||
 | 
					#define ZCONF_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * If you *really* need a unique prefix for all types and library functions,
 | 
				
			||||||
 | 
					 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef Z_PREFIX
 | 
				
			||||||
 | 
					#  define deflateInit_          z_deflateInit_
 | 
				
			||||||
 | 
					#  define deflate               z_deflate
 | 
				
			||||||
 | 
					#  define deflateEnd            z_deflateEnd
 | 
				
			||||||
 | 
					#  define inflateInit_          z_inflateInit_
 | 
				
			||||||
 | 
					#  define inflate               z_inflate
 | 
				
			||||||
 | 
					#  define inflateEnd            z_inflateEnd
 | 
				
			||||||
 | 
					#  define deflateInit2_         z_deflateInit2_
 | 
				
			||||||
 | 
					#  define deflateSetDictionary  z_deflateSetDictionary
 | 
				
			||||||
 | 
					#  define deflateCopy           z_deflateCopy
 | 
				
			||||||
 | 
					#  define deflateReset          z_deflateReset
 | 
				
			||||||
 | 
					#  define deflateParams         z_deflateParams
 | 
				
			||||||
 | 
					#  define deflateBound          z_deflateBound
 | 
				
			||||||
 | 
					#  define deflatePrime          z_deflatePrime
 | 
				
			||||||
 | 
					#  define inflateInit2_         z_inflateInit2_
 | 
				
			||||||
 | 
					#  define inflateSetDictionary  z_inflateSetDictionary
 | 
				
			||||||
 | 
					#  define inflateSync           z_inflateSync
 | 
				
			||||||
 | 
					#  define inflateSyncPoint      z_inflateSyncPoint
 | 
				
			||||||
 | 
					#  define inflateCopy           z_inflateCopy
 | 
				
			||||||
 | 
					#  define inflateReset          z_inflateReset
 | 
				
			||||||
 | 
					#  define inflateBack           z_inflateBack
 | 
				
			||||||
 | 
					#  define inflateBackEnd        z_inflateBackEnd
 | 
				
			||||||
 | 
					#  define compress              z_compress
 | 
				
			||||||
 | 
					#  define compress2             z_compress2
 | 
				
			||||||
 | 
					#  define compressBound         z_compressBound
 | 
				
			||||||
 | 
					#  define uncompress            z_uncompress
 | 
				
			||||||
 | 
					#  define adler32               z_adler32
 | 
				
			||||||
 | 
					#  define crc32                 z_crc32
 | 
				
			||||||
 | 
					#  define get_crc_table         z_get_crc_table
 | 
				
			||||||
 | 
					#  define zError                z_zError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#  define alloc_func            z_alloc_func
 | 
				
			||||||
 | 
					#  define free_func             z_free_func
 | 
				
			||||||
 | 
					#  define in_func               z_in_func
 | 
				
			||||||
 | 
					#  define out_func              z_out_func
 | 
				
			||||||
 | 
					#  define Byte                  z_Byte
 | 
				
			||||||
 | 
					#  define uInt                  z_uInt
 | 
				
			||||||
 | 
					#  define uLong                 z_uLong
 | 
				
			||||||
 | 
					#  define Bytef                 z_Bytef
 | 
				
			||||||
 | 
					#  define charf                 z_charf
 | 
				
			||||||
 | 
					#  define intf                  z_intf
 | 
				
			||||||
 | 
					#  define uIntf                 z_uIntf
 | 
				
			||||||
 | 
					#  define uLongf                z_uLongf
 | 
				
			||||||
 | 
					#  define voidpf                z_voidpf
 | 
				
			||||||
 | 
					#  define voidp                 z_voidp
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(__MSDOS__) && !defined(MSDOS)
 | 
				
			||||||
 | 
					#  define MSDOS
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
 | 
				
			||||||
 | 
					#  define OS2
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(_WINDOWS) && !defined(WINDOWS)
 | 
				
			||||||
 | 
					#  define WINDOWS
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
 | 
				
			||||||
 | 
					#  ifndef WIN32
 | 
				
			||||||
 | 
					#    define WIN32
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
 | 
				
			||||||
 | 
					#  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
 | 
				
			||||||
 | 
					#    ifndef SYS16BIT
 | 
				
			||||||
 | 
					#      define SYS16BIT
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
 | 
				
			||||||
 | 
					 * than 64k bytes at a time (needed on systems with 16-bit int).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef SYS16BIT
 | 
				
			||||||
 | 
					#  define MAXSEG_64K
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef MSDOS
 | 
				
			||||||
 | 
					#  define UNALIGNED_OK
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __STDC_VERSION__
 | 
				
			||||||
 | 
					#  ifndef STDC
 | 
				
			||||||
 | 
					#    define STDC
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#  if __STDC_VERSION__ >= 199901L
 | 
				
			||||||
 | 
					#    ifndef STDC99
 | 
				
			||||||
 | 
					#      define STDC99
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
 | 
				
			||||||
 | 
					#  define STDC
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef STDC
 | 
				
			||||||
 | 
					#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
 | 
				
			||||||
 | 
					#    define const       /* note: need a more gentle solution here */
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Some Mac compilers merge all .h files incorrectly: */
 | 
				
			||||||
 | 
					#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
 | 
				
			||||||
 | 
					#  define NO_DUMMY_DECL
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum value for memLevel in deflateInit2 */
 | 
				
			||||||
 | 
					#ifndef MAX_MEM_LEVEL
 | 
				
			||||||
 | 
					#  ifdef MAXSEG_64K
 | 
				
			||||||
 | 
					#    define MAX_MEM_LEVEL 8
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define MAX_MEM_LEVEL 9
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum value for windowBits in deflateInit2 and inflateInit2.
 | 
				
			||||||
 | 
					 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
 | 
				
			||||||
 | 
					 * created by gzip. (Files created by minigzip can still be extracted by
 | 
				
			||||||
 | 
					 * gzip.)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifndef MAX_WBITS
 | 
				
			||||||
 | 
					#  define MAX_WBITS   15 /* 32K LZ77 window */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The memory requirements for deflate are (in bytes):
 | 
				
			||||||
 | 
					            (1 << (windowBits+2)) +  (1 << (memLevel+9))
 | 
				
			||||||
 | 
					 that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
 | 
				
			||||||
 | 
					 plus a few kilobytes for small objects. For example, if you want to reduce
 | 
				
			||||||
 | 
					 the default memory requirements from 256K to 128K, compile with
 | 
				
			||||||
 | 
					     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
 | 
				
			||||||
 | 
					 Of course this will generally degrade compression (there's no free lunch).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The memory requirements for inflate are (in bytes) 1 << windowBits
 | 
				
			||||||
 | 
					 that is, 32K for windowBits=15 (default value) plus a few kilobytes
 | 
				
			||||||
 | 
					 for small objects.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        /* Type declarations */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef OF /* function prototypes */
 | 
				
			||||||
 | 
					#  ifdef STDC
 | 
				
			||||||
 | 
					#    define OF(args)  args
 | 
				
			||||||
 | 
					#  else
 | 
				
			||||||
 | 
					#    define OF(args)  ()
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The following definitions for FAR are needed only for MSDOS mixed
 | 
				
			||||||
 | 
					 * model programming (small or medium model with some far allocations).
 | 
				
			||||||
 | 
					 * This was tested only with MSC; for other MSDOS compilers you may have
 | 
				
			||||||
 | 
					 * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
 | 
				
			||||||
 | 
					 * just define FAR to be empty.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef SYS16BIT
 | 
				
			||||||
 | 
					#  if defined(M_I86SM) || defined(M_I86MM)
 | 
				
			||||||
 | 
					     /* MSC small or medium model */
 | 
				
			||||||
 | 
					#    define SMALL_MEDIUM
 | 
				
			||||||
 | 
					#    ifdef _MSC_VER
 | 
				
			||||||
 | 
					#      define FAR _far
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      define FAR far
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#  if (defined(__SMALL__) || defined(__MEDIUM__))
 | 
				
			||||||
 | 
					     /* Turbo C small or medium model */
 | 
				
			||||||
 | 
					#    define SMALL_MEDIUM
 | 
				
			||||||
 | 
					#    ifdef __BORLANDC__
 | 
				
			||||||
 | 
					#      define FAR _far
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      define FAR far
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(WINDOWS) || defined(WIN32)
 | 
				
			||||||
 | 
					   /* If building or using zlib as a DLL, define ZLIB_DLL.
 | 
				
			||||||
 | 
					    * This is not mandatory, but it offers a little performance increase.
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					#  ifdef ZLIB_DLL
 | 
				
			||||||
 | 
					#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
 | 
				
			||||||
 | 
					#      ifdef ZLIB_INTERNAL
 | 
				
			||||||
 | 
					#        define ZEXTERN extern __declspec(dllexport)
 | 
				
			||||||
 | 
					#      else
 | 
				
			||||||
 | 
					#        define ZEXTERN extern __declspec(dllimport)
 | 
				
			||||||
 | 
					#      endif
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif  /* ZLIB_DLL */
 | 
				
			||||||
 | 
					   /* If building or using zlib with the WINAPI/WINAPIV calling convention,
 | 
				
			||||||
 | 
					    * define ZLIB_WINAPI.
 | 
				
			||||||
 | 
					    * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					#  ifdef ZLIB_WINAPI
 | 
				
			||||||
 | 
					#    ifdef FAR
 | 
				
			||||||
 | 
					#      undef FAR
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#    include <windows.h>
 | 
				
			||||||
 | 
					     /* No need for _export, use ZLIB.DEF instead. */
 | 
				
			||||||
 | 
					     /* For complete Windows compatibility, use WINAPI, not __stdcall. */
 | 
				
			||||||
 | 
					#    define ZEXPORT WINAPI
 | 
				
			||||||
 | 
					#    ifdef WIN32
 | 
				
			||||||
 | 
					#      define ZEXPORTVA WINAPIV
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      define ZEXPORTVA FAR CDECL
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined (__BEOS__)
 | 
				
			||||||
 | 
					#  ifdef ZLIB_DLL
 | 
				
			||||||
 | 
					#    ifdef ZLIB_INTERNAL
 | 
				
			||||||
 | 
					#      define ZEXPORT   __declspec(dllexport)
 | 
				
			||||||
 | 
					#      define ZEXPORTVA __declspec(dllexport)
 | 
				
			||||||
 | 
					#    else
 | 
				
			||||||
 | 
					#      define ZEXPORT   __declspec(dllimport)
 | 
				
			||||||
 | 
					#      define ZEXPORTVA __declspec(dllimport)
 | 
				
			||||||
 | 
					#    endif
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ZEXTERN
 | 
				
			||||||
 | 
					#  define ZEXTERN extern
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef ZEXPORT
 | 
				
			||||||
 | 
					#  define ZEXPORT
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef ZEXPORTVA
 | 
				
			||||||
 | 
					#  define ZEXPORTVA
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef FAR
 | 
				
			||||||
 | 
					#  define FAR
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(__MACTYPES__)
 | 
				
			||||||
 | 
					typedef unsigned char  Byte;  /* 8 bits */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					typedef unsigned int   uInt;  /* 16 bits or more */
 | 
				
			||||||
 | 
					typedef unsigned long  uLong; /* 32 bits or more */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef SMALL_MEDIUM
 | 
				
			||||||
 | 
					   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
 | 
				
			||||||
 | 
					#  define Bytef Byte FAR
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					   typedef unsigned char  FAR Bytef;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					typedef char  FAR charf;
 | 
				
			||||||
 | 
					typedef int   FAR intf;
 | 
				
			||||||
 | 
					typedef uInt  FAR uIntf;
 | 
				
			||||||
 | 
					typedef uLong FAR uLongf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef STDC
 | 
				
			||||||
 | 
					   typedef void const *voidpc;
 | 
				
			||||||
 | 
					   typedef void FAR   *voidpf;
 | 
				
			||||||
 | 
					   typedef void       *voidp;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					   typedef Byte const *voidpc;
 | 
				
			||||||
 | 
					   typedef Byte FAR   *voidpf;
 | 
				
			||||||
 | 
					   typedef Byte       *voidp;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if 0           /* HAVE_UNISTD_H -- this line is updated by ./configure */
 | 
				
			||||||
 | 
					#  include <sys/types.h> /* for off_t */
 | 
				
			||||||
 | 
					#  include <unistd.h>    /* for SEEK_* and off_t */
 | 
				
			||||||
 | 
					#  ifdef VMS
 | 
				
			||||||
 | 
					#    include <unixio.h>   /* for off_t */
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#  define z_off_t off_t
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef SEEK_SET
 | 
				
			||||||
 | 
					#  define SEEK_SET        0       /* Seek from beginning of file.  */
 | 
				
			||||||
 | 
					#  define SEEK_CUR        1       /* Seek from current position.  */
 | 
				
			||||||
 | 
					#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifndef z_off_t
 | 
				
			||||||
 | 
					#  define z_off_t long
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(__OS400__)
 | 
				
			||||||
 | 
					#  define NO_vsnprintf
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(__MVS__)
 | 
				
			||||||
 | 
					#  define NO_vsnprintf
 | 
				
			||||||
 | 
					#  ifdef FAR
 | 
				
			||||||
 | 
					#    undef FAR
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* MVS linker does not support external names larger than 8 bytes */
 | 
				
			||||||
 | 
					#if defined(__MVS__)
 | 
				
			||||||
 | 
					#   pragma map(deflateInit_,"DEIN")
 | 
				
			||||||
 | 
					#   pragma map(deflateInit2_,"DEIN2")
 | 
				
			||||||
 | 
					#   pragma map(deflateEnd,"DEEND")
 | 
				
			||||||
 | 
					#   pragma map(deflateBound,"DEBND")
 | 
				
			||||||
 | 
					#   pragma map(inflateInit_,"ININ")
 | 
				
			||||||
 | 
					#   pragma map(inflateInit2_,"ININ2")
 | 
				
			||||||
 | 
					#   pragma map(inflateEnd,"INEND")
 | 
				
			||||||
 | 
					#   pragma map(inflateSync,"INSY")
 | 
				
			||||||
 | 
					#   pragma map(inflateSetDictionary,"INSEDI")
 | 
				
			||||||
 | 
					#   pragma map(compressBound,"CMBND")
 | 
				
			||||||
 | 
					#   pragma map(inflate_table,"INTABL")
 | 
				
			||||||
 | 
					#   pragma map(inflate_fast,"INFA")
 | 
				
			||||||
 | 
					#   pragma map(inflate_copyright,"INCOPY")
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* ZCONF_H */
 | 
				
			||||||
							
								
								
									
										1357
									
								
								src/TZlib/include/zlib.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1357
									
								
								src/TZlib/include/zlib.h
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/lib/zdll.exp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/lib/zdll.exp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/lib/zdll.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/lib/zdll.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/lib/zdllbor.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/lib/zdllbor.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										60
									
								
								src/TZlib/lib/zlib.def
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/TZlib/lib/zlib.def
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
				
			|||||||
 | 
					LIBRARY
 | 
				
			||||||
 | 
					; zlib data compression library
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXPORTS
 | 
				
			||||||
 | 
					; basic functions
 | 
				
			||||||
 | 
					    zlibVersion
 | 
				
			||||||
 | 
					    deflate
 | 
				
			||||||
 | 
					    deflateEnd
 | 
				
			||||||
 | 
					    inflate
 | 
				
			||||||
 | 
					    inflateEnd
 | 
				
			||||||
 | 
					; advanced functions
 | 
				
			||||||
 | 
					    deflateSetDictionary
 | 
				
			||||||
 | 
					    deflateCopy
 | 
				
			||||||
 | 
					    deflateReset
 | 
				
			||||||
 | 
					    deflateParams
 | 
				
			||||||
 | 
					    deflateBound
 | 
				
			||||||
 | 
					    deflatePrime
 | 
				
			||||||
 | 
					    inflateSetDictionary
 | 
				
			||||||
 | 
					    inflateSync
 | 
				
			||||||
 | 
					    inflateCopy
 | 
				
			||||||
 | 
					    inflateReset
 | 
				
			||||||
 | 
					    inflateBack
 | 
				
			||||||
 | 
					    inflateBackEnd
 | 
				
			||||||
 | 
					    zlibCompileFlags
 | 
				
			||||||
 | 
					; utility functions
 | 
				
			||||||
 | 
					    compress
 | 
				
			||||||
 | 
					    compress2
 | 
				
			||||||
 | 
					    compressBound
 | 
				
			||||||
 | 
					    uncompress
 | 
				
			||||||
 | 
					    gzopen
 | 
				
			||||||
 | 
					    gzdopen
 | 
				
			||||||
 | 
					    gzsetparams
 | 
				
			||||||
 | 
					    gzread
 | 
				
			||||||
 | 
					    gzwrite
 | 
				
			||||||
 | 
					    gzprintf
 | 
				
			||||||
 | 
					    gzputs
 | 
				
			||||||
 | 
					    gzgets
 | 
				
			||||||
 | 
					    gzputc
 | 
				
			||||||
 | 
					    gzgetc
 | 
				
			||||||
 | 
					    gzungetc
 | 
				
			||||||
 | 
					    gzflush
 | 
				
			||||||
 | 
					    gzseek
 | 
				
			||||||
 | 
					    gzrewind
 | 
				
			||||||
 | 
					    gztell
 | 
				
			||||||
 | 
					    gzeof
 | 
				
			||||||
 | 
					    gzclose
 | 
				
			||||||
 | 
					    gzerror
 | 
				
			||||||
 | 
					    gzclearerr
 | 
				
			||||||
 | 
					; checksum functions
 | 
				
			||||||
 | 
					    adler32
 | 
				
			||||||
 | 
					    crc32
 | 
				
			||||||
 | 
					; various hacks, don't look :)
 | 
				
			||||||
 | 
					    deflateInit_
 | 
				
			||||||
 | 
					    deflateInit2_
 | 
				
			||||||
 | 
					    inflateInit_
 | 
				
			||||||
 | 
					    inflateInit2_
 | 
				
			||||||
 | 
					    inflateBackInit_
 | 
				
			||||||
 | 
					    inflateSyncPoint
 | 
				
			||||||
 | 
					    get_crc_table
 | 
				
			||||||
 | 
					    zError
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/test/example_d.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/test/example_d.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/test/minigzip_d.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/test/minigzip_d.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/test/testzlib_d.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/test/testzlib_d.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/test/untgz_d.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/test/untgz_d.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/TZlib/zlib1.dll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/TZlib/zlib1.dll
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										111
									
								
								src/base64.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								src/base64.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,111 @@
 | 
				
			|||||||
 | 
					// Base 64 encoder / decoder
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <math.h>
 | 
				
			||||||
 | 
					//-------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Encode(AnsiString slToEnc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  //The Base64 Table
 | 
				
			||||||
 | 
					  const char Base64Table[64]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 | 
				
			||||||
 | 
					  char * buftoenc = slToEnc.c_str();
 | 
				
			||||||
 | 
					  int bufsize = slToEnc.Length() + 1;
 | 
				
			||||||
 | 
					  char * encbuf = new char[slToEnc.Length() * 5];
 | 
				
			||||||
 | 
					  encbuf[0] = '\0';  int ilStrLen = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int i=0; int b64byte[5];
 | 
				
			||||||
 | 
					  unsigned char *buftemp;
 | 
				
			||||||
 | 
					  AnsiString slRetVal = EmptyStr;
 | 
				
			||||||
 | 
					  buftemp=(unsigned char *)malloc(bufsize+2);
 | 
				
			||||||
 | 
					  strcpy(buftemp,buftoenc);
 | 
				
			||||||
 | 
					  if (fmod(bufsize,3)==1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    buftemp[bufsize]='\0';
 | 
				
			||||||
 | 
					    buftemp[bufsize+1]='\0';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (fmod(bufsize,3)==2)buftemp[bufsize]='\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  while (i<bufsize)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    b64byte[0]=buftemp[i]>>2;
 | 
				
			||||||
 | 
					    b64byte[1]=((buftemp[i]&3)<<4)|(buftemp[i+1]>>4);
 | 
				
			||||||
 | 
					    b64byte[2]=((buftemp[i+1]&0x0F)<<2)|(buftemp[i+2]>>6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    b64byte[3]=buftemp[i+2]&0x3F;
 | 
				
			||||||
 | 
					    encbuf[i+(i/3)]=Base64Table[b64byte[0]];
 | 
				
			||||||
 | 
					    encbuf[i+(i/3)+1]=Base64Table[b64byte[1]];
 | 
				
			||||||
 | 
					    encbuf[i+(i/3)+2]=Base64Table[b64byte[2]];
 | 
				
			||||||
 | 
					    encbuf[i+(i/3)+3]=Base64Table[b64byte[3]];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    i+=3;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  free(buftemp);
 | 
				
			||||||
 | 
					  if (fmod(bufsize,3)==0) ilStrLen = bufsize*8/6;
 | 
				
			||||||
 | 
					  else if (fmod(bufsize,3)==1) ilStrLen = ((bufsize+2)*8/6)-2;
 | 
				
			||||||
 | 
					  else if (fmod(bufsize,3)==2) ilStrLen = ((bufsize+1)*8/6)-1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  else ilStrLen = -1;
 | 
				
			||||||
 | 
					  if(ilStrLen > 0) slRetVal = AnsiString(encbuf).SubString(1, ilStrLen);
 | 
				
			||||||
 | 
					  if(encbuf != NULL) { delete encbuf; encbuf = NULL; }
 | 
				
			||||||
 | 
					  return slRetVal;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Decode(AnsiString slToDec)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  //Base64 Table
 | 
				
			||||||
 | 
					  const char Base64Table[64]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 | 
				
			||||||
 | 
					  char * buftodec = slToDec.c_str();
 | 
				
			||||||
 | 
					  int bufsize = slToDec.Length() + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  char * decbuf = new char[slToDec.Length() * 5];
 | 
				
			||||||
 | 
					  decbuf[0] = '\0';  int ilStrLen = -1;
 | 
				
			||||||
 | 
					  AnsiString slRetVal = EmptyStr;
 | 
				
			||||||
 | 
					  int i=0; unsigned char binbyte[4];
 | 
				
			||||||
 | 
					  int cpos[5]; unsigned char *buftemp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  buftemp=(unsigned char *)malloc(bufsize);
 | 
				
			||||||
 | 
					  strcpy(buftemp,buftodec);
 | 
				
			||||||
 | 
					  if (fmod(bufsize,4)==1)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    buftemp[bufsize]='\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    buftemp[bufsize+1]='\0';
 | 
				
			||||||
 | 
					    buftemp[bufsize+2]='\0';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (fmod(bufsize,4)==2)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    buftemp[bufsize]='\0';
 | 
				
			||||||
 | 
					    buftemp[bufsize+1]='\0';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (fmod(bufsize,4)==3)buftemp[bufsize]='\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  while (i<bufsize)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    cpos[0]=strchr(Base64Table,buftemp[i])-Base64Table;
 | 
				
			||||||
 | 
					    cpos[1]=strchr(Base64Table,buftemp[i+1])-Base64Table;
 | 
				
			||||||
 | 
					    cpos[2]=strchr(Base64Table,buftemp[i+2])-Base64Table;
 | 
				
			||||||
 | 
					    cpos[3]=strchr(Base64Table,buftemp[i+3])-Base64Table;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    binbyte[0]=((cpos[0]<<2)|(cpos[1]>>4));
 | 
				
			||||||
 | 
					    binbyte[1]=((cpos[1]<<4)|(cpos[2]>>2));
 | 
				
			||||||
 | 
					    binbyte[2]=(((cpos[2]&0x03)<<6)|(cpos[3]&0x3f));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    decbuf[i-(i/4)]=binbyte[0];
 | 
				
			||||||
 | 
					    decbuf[i-(i/4)+1]=binbyte[1];
 | 
				
			||||||
 | 
					    decbuf[i-(i/4)+2]=binbyte[2];
 | 
				
			||||||
 | 
					    i+=4;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  free(buftemp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (fmod(bufsize,4)==0) ilStrLen = bufsize*6/8;
 | 
				
			||||||
 | 
					  else if (fmod(bufsize,4)==1) ilStrLen = ((bufsize+3)*6/8)-3;
 | 
				
			||||||
 | 
					  else if (fmod(bufsize,4)==2) ilStrLen = ((bufsize+2)*6/8)-2;
 | 
				
			||||||
 | 
					  else if (fmod(bufsize,4)==3) ilStrLen = ((bufsize+1)*6/8)-1;
 | 
				
			||||||
 | 
					  else ilStrLen = -1;
 | 
				
			||||||
 | 
					  if(ilStrLen > 0) slRetVal = AnsiString(decbuf).SubString(1, ilStrLen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if(decbuf != NULL) { delete decbuf; decbuf = NULL; }
 | 
				
			||||||
 | 
					  return slRetVal;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
							
								
								
									
										94
									
								
								src/base64.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/base64.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,94 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					// Base 64 encoder / decoder
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Base64.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//-------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Encode(char *input)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   char keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   AnsiString output = "";
 | 
				
			||||||
 | 
					   char chr1, chr2, chr3;
 | 
				
			||||||
 | 
					   char enc1, enc2, enc3, enc4;
 | 
				
			||||||
 | 
					   int i = 0, l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   l = strlen(input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   do {
 | 
				
			||||||
 | 
					      chr1 = input[i++];
 | 
				
			||||||
 | 
					      enc1 = chr1 >> 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ( i<l ) {
 | 
				
			||||||
 | 
					        chr2 = input[i++];
 | 
				
			||||||
 | 
					        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( i<l ) {
 | 
				
			||||||
 | 
					          chr3 = input[i++];
 | 
				
			||||||
 | 
					          enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
 | 
				
			||||||
 | 
					          enc4 = chr3 & 63;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          enc3 = ((chr2 & 15) << 2);
 | 
				
			||||||
 | 
					          enc4 = 64;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					         enc2 = ((chr1 & 3) << 4);
 | 
				
			||||||
 | 
					         enc3 = 64;
 | 
				
			||||||
 | 
					         enc4 = 64;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      output += AnsiString(keyStr[enc1]) + AnsiString(keyStr[enc2]) + AnsiString(keyStr[enc3]) + AnsiString(keyStr[enc4]);
 | 
				
			||||||
 | 
					   } while (i < l);
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   return output;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Decode(char *input)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   char keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   AnsiString output = "";
 | 
				
			||||||
 | 
					   char chr1, chr2, chr3;
 | 
				
			||||||
 | 
					   char enc1, enc2, enc3, enc4;
 | 
				
			||||||
 | 
					   int i = 0, l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
 | 
				
			||||||
 | 
					//   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   l = strlen(input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   do {
 | 
				
			||||||
 | 
					      enc1 = strchr( keyStr, input[i++] ) - keyStr;
 | 
				
			||||||
 | 
					      if (i<l) enc2 = strchr( keyStr, input[i++] ) - keyStr; else enc2 = 0;
 | 
				
			||||||
 | 
					      if (i<l) enc3 = strchr( keyStr, input[i++] ) - keyStr; else enc3 = 0;
 | 
				
			||||||
 | 
					      if (i<l) enc4 = strchr( keyStr, input[i++] ) - keyStr; else enc4 = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      chr1 = (enc1 << 2) | (enc2 >> 4);
 | 
				
			||||||
 | 
					      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
 | 
				
			||||||
 | 
					      chr3 = ((enc3 & 3) << 6) | enc4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      output += AnsiString(chr1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (enc3 != 64) {
 | 
				
			||||||
 | 
					         output += AnsiString(chr2);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (enc4 != 64) {
 | 
				
			||||||
 | 
					         output += AnsiString(chr3);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					   } while (i < l);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   return output;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/base64.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/base64.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef Base64H
 | 
				
			||||||
 | 
					#define Base64H
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Decode(char *input);
 | 
				
			||||||
 | 
					AnsiString Base64Encode(char *input);
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
							
								
								
									
										94
									
								
								src/base64.~cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/base64.~cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,94 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					// Base 64 encoder / decoder
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "Base64.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//-------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Encode(char *input)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   char keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   AnsiString output = "";
 | 
				
			||||||
 | 
					   char chr1, chr2, chr3;
 | 
				
			||||||
 | 
					   char enc1, enc2, enc3, enc4;
 | 
				
			||||||
 | 
					   int i = 0, l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   l = strlen(input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   do {
 | 
				
			||||||
 | 
					      chr1 = input[i++];
 | 
				
			||||||
 | 
					      enc1 = chr1 >> 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ( i<l ) {
 | 
				
			||||||
 | 
					        chr2 = input[i++];
 | 
				
			||||||
 | 
					        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( i<l ) {
 | 
				
			||||||
 | 
					          chr3 = input[i++];
 | 
				
			||||||
 | 
					          enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
 | 
				
			||||||
 | 
					          enc4 = chr3 & 63;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          enc3 = ((chr2 & 15) << 2);
 | 
				
			||||||
 | 
					          enc4 = 64;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					         enc2 = ((chr1 & 3) << 4);
 | 
				
			||||||
 | 
					         enc3 = 64;
 | 
				
			||||||
 | 
					         enc4 = 64;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      output += AnsiString(keyStr[enc1]) + AnsiString(keyStr[enc2]) + AnsiString(keyStr[enc3]) + AnsiString(keyStr[enc4]);
 | 
				
			||||||
 | 
					   } while (i < l);
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					   return output;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Decode(char *input)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					   char keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   AnsiString output = "";
 | 
				
			||||||
 | 
					   char chr1, chr2, chr3;
 | 
				
			||||||
 | 
					   char enc1, enc2, enc3, enc4;
 | 
				
			||||||
 | 
					   int i = 0, l;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
 | 
				
			||||||
 | 
					//   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   l = strlen(input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   do {
 | 
				
			||||||
 | 
					      enc1 = keyStr[ input[i++] ];
 | 
				
			||||||
 | 
					      if (i<l) enc2 = strchr( keyStr, input[i++] ) - keyStr; else enc2 = 0;
 | 
				
			||||||
 | 
					      if (i<l) enc3 = strchr( keyStr, input[i++] ) - keyStr; else enc3 = 0;
 | 
				
			||||||
 | 
					      if (i<l) enc4 = strchr( keyStr, input[i++] ) - keyStr; else enc4 = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      chr1 = (enc1 << 2) | (enc2 >> 4);
 | 
				
			||||||
 | 
					      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
 | 
				
			||||||
 | 
					      chr3 = ((enc3 & 3) << 6) | enc4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      output += AnsiString(chr1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (enc3 != 64) {
 | 
				
			||||||
 | 
					         output += AnsiString(chr2);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (enc4 != 64) {
 | 
				
			||||||
 | 
					         output += AnsiString(chr3);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					   } while (i < l);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   return output;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/base64.~h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/base64.~h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef Base64H
 | 
				
			||||||
 | 
					#define Base64H
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString Base64Decode(char *input);
 | 
				
			||||||
 | 
					AnsiString Base64Encode(char *input);
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
							
								
								
									
										245
									
								
								src/mainGUI.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										245
									
								
								src/mainGUI.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,245 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <Math.hpp>
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inifiles.hpp"
 | 
				
			||||||
 | 
					#include "mainGUI.h"
 | 
				
			||||||
 | 
					#include "tsplash.h"
 | 
				
			||||||
 | 
					#include "stdio.h"
 | 
				
			||||||
 | 
					#include "THTTPdownloader.h"
 | 
				
			||||||
 | 
					#include "base64.h"
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
 | 
					#pragma resource "*.dfm"
 | 
				
			||||||
 | 
					TForm1 *Form1;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					__fastcall TForm1::TForm1(TComponent* Owner)
 | 
				
			||||||
 | 
					        : TForm(Owner)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  #define IDM_ABOUTBOX 1
 | 
				
			||||||
 | 
					  HMENU pSysMenu = GetSystemMenu(this->Handle, FALSE);
 | 
				
			||||||
 | 
					  if (pSysMenu != NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					        AppendMenu(pSysMenu, MF_SEPARATOR,0,0);
 | 
				
			||||||
 | 
					        AppendMenu(pSysMenu, MF_STRING, IDM_ABOUTBOX, "Acerca de...");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  WindowProc=MyWndProc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TIniFile *ini;
 | 
				
			||||||
 | 
					  ini = new TIniFile(ExtractFileDir(Application->ExeName)+"\\chpwd.ini");
 | 
				
			||||||
 | 
					  StringGrid1->RowCount = 1 + ini->ReadInteger("aps","count",1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  APs = new AP[StringGrid1->RowCount];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  StringGrid1->ColWidths[0] = 200;
 | 
				
			||||||
 | 
					  StringGrid1->ColWidths[1] = 50;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  StringGrid1->Cells[0][0] = "IP";
 | 
				
			||||||
 | 
					  StringGrid1->Cells[1][0] = "Status";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TStringList *StringList = new TStringList();
 | 
				
			||||||
 | 
					  int i; AnsiString aux;
 | 
				
			||||||
 | 
					  for(i=1;i<StringGrid1->RowCount;i++){
 | 
				
			||||||
 | 
					        StringList->Clear();
 | 
				
			||||||
 | 
					        aux = ini->ReadString("aps","AP"+AnsiString(i),"0:0:0:0;user;pass;wep128pass");
 | 
				
			||||||
 | 
					        ExtractStrings(TSysCharSet()<<';',TSysCharSet(), (char *)aux.data(), StringList);
 | 
				
			||||||
 | 
					        if ( StringList->Count == 4 ) {
 | 
				
			||||||
 | 
					                APs[i-1].IP = StringList->Strings[0];
 | 
				
			||||||
 | 
					                APs[i-1].user = StringList->Strings[1];
 | 
				
			||||||
 | 
					                APs[i-1].pass = StringList->Strings[2];
 | 
				
			||||||
 | 
					                APs[i-1].wep = StringList->Strings[3];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        StringGrid1->RowHeights[i] = 14;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete StringList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  delete ini;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  currWEP->Text = APs[0].wep;
 | 
				
			||||||
 | 
					  currHexWEP->Caption = wepASCII2HEX( currWEP->Text );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generarClaveWEP->Caption = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generarClaveWEPClick(0);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString __fastcall TForm1::wepASCII2HEX(AnsiString txt) {
 | 
				
			||||||
 | 
					  char ascWEPkey[14], hexWEPkey[27];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  sprintf(ascWEPkey,"%13s",(char *)txt.data());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  BinToHex(ascWEPkey, hexWEPkey, 13);
 | 
				
			||||||
 | 
					  hexWEPkey[26]='\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return AnsiString( hexWEPkey );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::MyWndProc(Messages::TMessage &Message)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  HMENU hMenu;
 | 
				
			||||||
 | 
					  hMenu = GetSystemMenu (this->Handle, FALSE);
 | 
				
			||||||
 | 
					  if (Message.Msg == WM_SYSCOMMAND)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					     switch(Message.WParamLo)
 | 
				
			||||||
 | 
					     {
 | 
				
			||||||
 | 
					        case IDM_ABOUTBOX:
 | 
				
			||||||
 | 
					                 if ( Splash==NULL ) Splash = new TSplash(NULL);
 | 
				
			||||||
 | 
					                 Splash->pressKeyToClose = true;
 | 
				
			||||||
 | 
					                 Splash->Show();
 | 
				
			||||||
 | 
					                 Splash->Repaint();
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					           WndProc(Message);
 | 
				
			||||||
 | 
					     }
 | 
				
			||||||
 | 
					  } else
 | 
				
			||||||
 | 
					    WndProc(Message);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::FormShow(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if(Splash){
 | 
				
			||||||
 | 
					          delete Splash;
 | 
				
			||||||
 | 
					          Splash = NULL;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TIniFile *ini;
 | 
				
			||||||
 | 
					  ini = new TIniFile(ExtractFileDir(Application->ExeName)+"\\chpwd.ini");
 | 
				
			||||||
 | 
					  for(int i=1;i<StringGrid1->RowCount;i++){
 | 
				
			||||||
 | 
					        ini->WriteString("aps","AP"+AnsiString(i),APs[i-1].IP+";"+APs[i-1].user+";"+APs[i-1].pass+";"+APs[i-1].wep);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete ini;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  delete []APs;        
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
 | 
				
			||||||
 | 
					      int ARow, TRect &Rect, TGridDrawState State)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if ( ARow>0 ) {
 | 
				
			||||||
 | 
					      TStringGrid *grid;
 | 
				
			||||||
 | 
					      grid = (TStringGrid *)Sender;
 | 
				
			||||||
 | 
					      grid->Canvas->FillRect(Rect);
 | 
				
			||||||
 | 
					      Rect.right -= 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ( ACol==0 ) DrawText( grid->Canvas->Handle, (char *)APs[ARow-1].IP.data(),APs[ARow-1].IP.Length(), &Rect,DT_LEFT ); else
 | 
				
			||||||
 | 
					      if ( ACol==1 ) DrawText( grid->Canvas->Handle, (char *)APs[ARow-1].status.data(),APs[ARow-1].status.Length(), &Rect,DT_RIGHT );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::generarClaveWEPClick(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  char ascWEPkey[14], hexWEPkey[27];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Randomize();
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  int i, r;
 | 
				
			||||||
 | 
					//  char charArray[] = {' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '\'', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'};
 | 
				
			||||||
 | 
					  char charArray[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', '+', 'l', '-', '.', 'm', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'o', 'p', 'q', 'r', 's', 't', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '_', '5', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '6', '7', '8', '9'};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int keyLengthInBytes = 13;
 | 
				
			||||||
 | 
					  for(i=0;i<keyLengthInBytes;i++) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        r = RandomRange(0, 94); // range is 0 ~ 94
 | 
				
			||||||
 | 
					        ascWEPkey[i] = charArray[r];      // creates the ASCII version of the WEP key
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ascWEPkey[keyLengthInBytes] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  newWEP->Text = AnsiString(ascWEPkey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::newWEPChange(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					 hexWEP->Caption = wepASCII2HEX( newWEP->Text );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::Button1Click(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if ( newWEP->Text.Length()!=13 ) {
 | 
				
			||||||
 | 
					        ShowMessage("La nueva clave debe contener 13 d<>gitos.");
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					        Button1->Caption = "Por favor, espere...";
 | 
				
			||||||
 | 
					        // Propagar la clave por los routers.
 | 
				
			||||||
 | 
					        for (int i=0;i<StringGrid1->RowCount;i++) {
 | 
				
			||||||
 | 
					                if ( updateRouter(APs[i].IP, APs[i].user, APs[i].pass, hexWEP->Caption) ) {
 | 
				
			||||||
 | 
					                        APs[i].wep = newWEP->Text;
 | 
				
			||||||
 | 
					                        APs[i].status = "OK";
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                        APs[i].status = "ERROR";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        Button1->Caption = "Aplicar Cambios";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					bool __fastcall TForm1::updateRouter(AnsiString IP, AnsiString user, AnsiString pass, AnsiString WEP)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  TMemoryStream* out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int error;
 | 
				
			||||||
 | 
					  AnsiString Authorization, content, request, aux;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  aux = user+":"+pass;
 | 
				
			||||||
 | 
					  Authorization = Base64Encode((char *)aux.data());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*  
 | 
				
			||||||
 | 
					  request = "GET / HTTP/1.1\r\n";
 | 
				
			||||||
 | 
					  request+= "Host: "+IP+"\r\n";
 | 
				
			||||||
 | 
					  request+= "User-Agent: JDsoft\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept: text/html;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Language: es-es,es\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Encoding: gzip,deflate\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Authorization: Basic "+Authorization+"\r\n"; // YWRtaW46YWRtaW4=
 | 
				
			||||||
 | 
					  request+= "Keep-Alive: 300\r\n";
 | 
				
			||||||
 | 
					  request+= "Proxy-Connection: keep-alive\r\n";
 | 
				
			||||||
 | 
					  request+= "\r\n";
 | 
				
			||||||
 | 
					  out  = new TMemoryStream();
 | 
				
			||||||
 | 
					  error = HTTPdownloader->descargarHTML(IP.c_str(),request.c_str(),out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ( error==-1 ) return false; 
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  content = "submit_button=WL_WPATable&change_action=&submit_type=&action=Apply&security_mode_last=";
 | 
				
			||||||
 | 
					  content+= "&wl_wep_last=&security_mode2=wep&wl_key=1&wl_WEP_key=&wl_wep=restricted&wl_wep_bit=128";
 | 
				
			||||||
 | 
					  content+= "&wl_passphrase=&generateButton=Null";
 | 
				
			||||||
 | 
					  content+= "&wl_key1="+WEP;
 | 
				
			||||||
 | 
					  content+= "&wl_key2=&wl_key3=&wl_key4=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  request = "POST /apply.cgi HTTP/1.1\r\n";
 | 
				
			||||||
 | 
					  request+= "Host: "+IP+"\r\n";
 | 
				
			||||||
 | 
					  request+= "User-Agent: JDsoft\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept: text/html;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Encoding: gzip,deflate\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Keep-Alive: 300\r\n";
 | 
				
			||||||
 | 
					  request+= "Proxy-Connection: keep-alive\r\n";
 | 
				
			||||||
 | 
					  request+= "Referer: http://"+IP+"/WL_WPATable.asp\r\n";
 | 
				
			||||||
 | 
					  request+= "Authorization: Basic "+Authorization+"\r\n";
 | 
				
			||||||
 | 
					  request+= "Content-Type: application/x-www-form-urlencoded\r\n";
 | 
				
			||||||
 | 
					  request+= "Content-Length: "+AnsiString(content.Length())+"\r\n\r\n";
 | 
				
			||||||
 | 
					  request+= content;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /*TMemoryStream* */ out  = new TMemoryStream();
 | 
				
			||||||
 | 
					  error = HTTPdownloader->descargarHTML(IP.c_str(),request.c_str(),out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ( error!=-1 ) {
 | 
				
			||||||
 | 
					                char *pos, *posEnd;
 | 
				
			||||||
 | 
					                out->Position=0;
 | 
				
			||||||
 | 
					        	pos=StrPos((char *)out->Memory,"Settings are successful.");
 | 
				
			||||||
 | 
					                if ( pos<=0 ) error=-1; else error = 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return (error!=-1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/mainGUI.ddp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/mainGUI.ddp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										143
									
								
								src/mainGUI.dfm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								src/mainGUI.dfm
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,143 @@
 | 
				
			|||||||
 | 
					object Form1: TForm1
 | 
				
			||||||
 | 
					  Left = 499
 | 
				
			||||||
 | 
					  Top = 114
 | 
				
			||||||
 | 
					  Width = 301
 | 
				
			||||||
 | 
					  Height = 337
 | 
				
			||||||
 | 
					  Caption = 'WRT54GL chpwd'
 | 
				
			||||||
 | 
					  Color = clBtnFace
 | 
				
			||||||
 | 
					  Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					  Font.Color = clWindowText
 | 
				
			||||||
 | 
					  Font.Height = -11
 | 
				
			||||||
 | 
					  Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					  Font.Style = []
 | 
				
			||||||
 | 
					  OldCreateOrder = False
 | 
				
			||||||
 | 
					  OnClose = FormClose
 | 
				
			||||||
 | 
					  OnShow = FormShow
 | 
				
			||||||
 | 
					  PixelsPerInch = 96
 | 
				
			||||||
 | 
					  TextHeight = 13
 | 
				
			||||||
 | 
					  object PageControl1: TPageControl
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 0
 | 
				
			||||||
 | 
					    Width = 293
 | 
				
			||||||
 | 
					    Height = 306
 | 
				
			||||||
 | 
					    ActivePage = TabSheet1
 | 
				
			||||||
 | 
					    Align = alClient
 | 
				
			||||||
 | 
					    TabIndex = 0
 | 
				
			||||||
 | 
					    TabOrder = 0
 | 
				
			||||||
 | 
					    TabPosition = tpBottom
 | 
				
			||||||
 | 
					    object TabSheet1: TTabSheet
 | 
				
			||||||
 | 
					      Caption = 'Inicio'
 | 
				
			||||||
 | 
					      object Label2: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 112
 | 
				
			||||||
 | 
					        Width = 61
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'Cambiar a:'
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -11
 | 
				
			||||||
 | 
					        Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object Label1: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 16
 | 
				
			||||||
 | 
					        Width = 108
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'Clave WEP actual:'
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -11
 | 
				
			||||||
 | 
					        Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object hexWEP: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 184
 | 
				
			||||||
 | 
					        Width = 42
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'hexWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object currHexWEP: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 88
 | 
				
			||||||
 | 
					        Width = 42
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'hexWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object Button1: TButton
 | 
				
			||||||
 | 
					        Left = 80
 | 
				
			||||||
 | 
					        Top = 220
 | 
				
			||||||
 | 
					        Width = 129
 | 
				
			||||||
 | 
					        Height = 25
 | 
				
			||||||
 | 
					        Caption = 'Aplicar Cambios'
 | 
				
			||||||
 | 
					        TabOrder = 0
 | 
				
			||||||
 | 
					        OnClick = Button1Click
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object newWEP: TEdit
 | 
				
			||||||
 | 
					        Left = 7
 | 
				
			||||||
 | 
					        Top = 136
 | 
				
			||||||
 | 
					        Width = 226
 | 
				
			||||||
 | 
					        Height = 39
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -27
 | 
				
			||||||
 | 
					        Font.Name = 'Courier New'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        MaxLength = 13
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					        TabOrder = 1
 | 
				
			||||||
 | 
					        Text = '0123456789123'
 | 
				
			||||||
 | 
					        OnChange = newWEPChange
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object currWEP: TEdit
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 40
 | 
				
			||||||
 | 
					        Width = 273
 | 
				
			||||||
 | 
					        Height = 41
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -29
 | 
				
			||||||
 | 
					        Font.Name = 'Courier New'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        MaxLength = 13
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					        ReadOnly = True
 | 
				
			||||||
 | 
					        TabOrder = 2
 | 
				
			||||||
 | 
					        Text = 'currWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object generarClaveWEP: TBitBtn
 | 
				
			||||||
 | 
					        Left = 240
 | 
				
			||||||
 | 
					        Top = 136
 | 
				
			||||||
 | 
					        Width = 41
 | 
				
			||||||
 | 
					        Height = 41
 | 
				
			||||||
 | 
					        TabOrder = 3
 | 
				
			||||||
 | 
					        OnClick = generarClaveWEPClick
 | 
				
			||||||
 | 
					        Kind = bkRetry
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    object TabSheet2: TTabSheet
 | 
				
			||||||
 | 
					      Caption = 'Configurar APs'
 | 
				
			||||||
 | 
					      ImageIndex = 1
 | 
				
			||||||
 | 
					      object StringGrid1: TStringGrid
 | 
				
			||||||
 | 
					        Left = 0
 | 
				
			||||||
 | 
					        Top = 0
 | 
				
			||||||
 | 
					        Width = 285
 | 
				
			||||||
 | 
					        Height = 280
 | 
				
			||||||
 | 
					        Align = alClient
 | 
				
			||||||
 | 
					        ColCount = 2
 | 
				
			||||||
 | 
					        FixedCols = 0
 | 
				
			||||||
 | 
					        TabOrder = 0
 | 
				
			||||||
 | 
					        OnDrawCell = StringGrid1DrawCell
 | 
				
			||||||
 | 
					        RowHeights = (
 | 
				
			||||||
 | 
					          24
 | 
				
			||||||
 | 
					          26
 | 
				
			||||||
 | 
					          12
 | 
				
			||||||
 | 
					          24
 | 
				
			||||||
 | 
					          24)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										62
									
								
								src/mainGUI.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/mainGUI.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef mainGUIH
 | 
				
			||||||
 | 
					#define mainGUIH
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#include <Classes.hpp>
 | 
				
			||||||
 | 
					#include <Controls.hpp>
 | 
				
			||||||
 | 
					#include <StdCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Forms.hpp>
 | 
				
			||||||
 | 
					#include <ComCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Grids.hpp>
 | 
				
			||||||
 | 
					#include <Buttons.hpp>
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					struct AP {
 | 
				
			||||||
 | 
					        AnsiString IP;
 | 
				
			||||||
 | 
					        AnsiString user;
 | 
				
			||||||
 | 
					        AnsiString pass;
 | 
				
			||||||
 | 
					        AnsiString wep;
 | 
				
			||||||
 | 
					        AnsiString status;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					class TForm1 : public TForm
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					__published:	// IDE-managed Components
 | 
				
			||||||
 | 
					        TPageControl *PageControl1;
 | 
				
			||||||
 | 
					        TTabSheet *TabSheet1;
 | 
				
			||||||
 | 
					        TButton *Button1;
 | 
				
			||||||
 | 
					        TEdit *newWEP;
 | 
				
			||||||
 | 
					        TLabel *Label2;
 | 
				
			||||||
 | 
					        TEdit *currWEP;
 | 
				
			||||||
 | 
					        TLabel *Label1;
 | 
				
			||||||
 | 
					        TTabSheet *TabSheet2;
 | 
				
			||||||
 | 
					        TStringGrid *StringGrid1;
 | 
				
			||||||
 | 
					        TBitBtn *generarClaveWEP;
 | 
				
			||||||
 | 
					        TLabel *hexWEP;
 | 
				
			||||||
 | 
					        TLabel *currHexWEP;
 | 
				
			||||||
 | 
					        void __fastcall FormShow(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
 | 
				
			||||||
 | 
					        void __fastcall StringGrid1DrawCell(TObject *Sender, int ACol,
 | 
				
			||||||
 | 
					          int ARow, TRect &Rect, TGridDrawState State);
 | 
				
			||||||
 | 
					        void __fastcall generarClaveWEPClick(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall newWEPChange(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall Button1Click(TObject *Sender);
 | 
				
			||||||
 | 
					private:	// User declarations
 | 
				
			||||||
 | 
					        AP *APs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        AnsiString __fastcall wepASCII2HEX(AnsiString txt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:		// User declarations
 | 
				
			||||||
 | 
					        __fastcall TForm1(TComponent* Owner);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void __fastcall MyWndProc(Messages::TMessage &Message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        bool __fastcall updateRouter(AnsiString IP, AnsiString user, AnsiString pass, AnsiString WEP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					extern PACKAGE TForm1 *Form1;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										246
									
								
								src/mainGUI.~cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										246
									
								
								src/mainGUI.~cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,246 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <Math.hpp>
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "inifiles.hpp"
 | 
				
			||||||
 | 
					#include "mainGUI.h"
 | 
				
			||||||
 | 
					#include "tsplash.h"
 | 
				
			||||||
 | 
					#include "stdio.h"
 | 
				
			||||||
 | 
					#include "THTTPdownloader.h"
 | 
				
			||||||
 | 
					#include "base64.h"
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
 | 
					#pragma resource "*.dfm"
 | 
				
			||||||
 | 
					TForm1 *Form1;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					__fastcall TForm1::TForm1(TComponent* Owner)
 | 
				
			||||||
 | 
					        : TForm(Owner)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  #define IDM_ABOUTBOX 1
 | 
				
			||||||
 | 
					  HMENU pSysMenu = GetSystemMenu(this->Handle, FALSE);
 | 
				
			||||||
 | 
					  if (pSysMenu != NULL)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					        AppendMenu(pSysMenu, MF_SEPARATOR,0,0);
 | 
				
			||||||
 | 
					        AppendMenu(pSysMenu, MF_STRING, IDM_ABOUTBOX, "Acerca de...");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  WindowProc=MyWndProc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TIniFile *ini;
 | 
				
			||||||
 | 
					  ini = new TIniFile(ExtractFileDir(Application->ExeName)+"\\chpwd.ini");
 | 
				
			||||||
 | 
					  StringGrid1->RowCount = 1 + ini->ReadInteger("aps","count",1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  APs = new AP[StringGrid1->RowCount];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  StringGrid1->ColWidths[0] = 200;
 | 
				
			||||||
 | 
					  StringGrid1->ColWidths[1] = 50;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  StringGrid1->Cells[0][0] = "IP";
 | 
				
			||||||
 | 
					  StringGrid1->Cells[1][0] = "Status";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TStringList *StringList = new TStringList();
 | 
				
			||||||
 | 
					  int i; AnsiString aux;
 | 
				
			||||||
 | 
					  for(i=1;i<StringGrid1->RowCount;i++){
 | 
				
			||||||
 | 
					        StringList->Clear();
 | 
				
			||||||
 | 
					        aux = ini->ReadString("aps","AP"+AnsiString(i),"0:0:0:0;user;pass;wep128pass");
 | 
				
			||||||
 | 
					        ExtractStrings(TSysCharSet()<<';',TSysCharSet(), (char *)aux.data(), StringList);
 | 
				
			||||||
 | 
					        if ( StringList->Count == 4 ) {
 | 
				
			||||||
 | 
					                APs[i-1].IP = StringList->Strings[0];
 | 
				
			||||||
 | 
					                APs[i-1].user = StringList->Strings[1];
 | 
				
			||||||
 | 
					                APs[i-1].pass = StringList->Strings[2];
 | 
				
			||||||
 | 
					                APs[i-1].wep = StringList->Strings[3];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        StringGrid1->RowHeights[i] = 14;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete StringList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  delete ini;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  currWEP->Text = APs[0].wep;
 | 
				
			||||||
 | 
					  currHexWEP->Caption = wepASCII2HEX( currWEP->Text );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generarClaveWEP->Caption = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generarClaveWEPClick(0);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					AnsiString __fastcall TForm1::wepASCII2HEX(AnsiString txt) {
 | 
				
			||||||
 | 
					  char ascWEPkey[14], hexWEPkey[27];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  sprintf(ascWEPkey,"%13s",(char *)txt.data());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  BinToHex(ascWEPkey, hexWEPkey, 13);
 | 
				
			||||||
 | 
					  hexWEPkey[26]='\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return AnsiString( hexWEPkey );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::MyWndProc(Messages::TMessage &Message)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  HMENU hMenu;
 | 
				
			||||||
 | 
					  hMenu = GetSystemMenu (this->Handle, FALSE);
 | 
				
			||||||
 | 
					  if (Message.Msg == WM_SYSCOMMAND)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					     switch(Message.WParamLo)
 | 
				
			||||||
 | 
					     {
 | 
				
			||||||
 | 
					        case IDM_ABOUTBOX:
 | 
				
			||||||
 | 
					                 if ( Splash==NULL ) Splash = new TSplash(NULL);
 | 
				
			||||||
 | 
					                 Splash->pressKeyToClose = true;
 | 
				
			||||||
 | 
					                 Splash->Show();
 | 
				
			||||||
 | 
					                 Splash->Repaint();
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					           WndProc(Message);
 | 
				
			||||||
 | 
					     }
 | 
				
			||||||
 | 
					  } else
 | 
				
			||||||
 | 
					    WndProc(Message);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::FormShow(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if(Splash){
 | 
				
			||||||
 | 
					          delete Splash;
 | 
				
			||||||
 | 
					          Splash = NULL;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  TIniFile *ini;
 | 
				
			||||||
 | 
					  ini = new TIniFile(ExtractFileDir(Application->ExeName)+"\\chpwd.ini");
 | 
				
			||||||
 | 
					  for(int i=1;i<StringGrid1->RowCount;i++){
 | 
				
			||||||
 | 
					        ini->WriteString("aps","AP"+AnsiString(i),APs[i-1].IP+";"+APs[i-1].user+";"+APs[i-1].pass+";"+APs[i-1].wep);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  delete ini;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  delete []APs;        
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
 | 
				
			||||||
 | 
					      int ARow, TRect &Rect, TGridDrawState State)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if ( ARow>0 ) {
 | 
				
			||||||
 | 
					      TStringGrid *grid;
 | 
				
			||||||
 | 
					      grid = (TStringGrid *)Sender;
 | 
				
			||||||
 | 
					      grid->Canvas->FillRect(Rect);
 | 
				
			||||||
 | 
					      Rect.right -= 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if ( ACol==0 ) DrawText( grid->Canvas->Handle, (char *)APs[ARow-1].IP.data(),APs[ARow-1].IP.Length(), &Rect,DT_LEFT ); else
 | 
				
			||||||
 | 
					      if ( ACol==1 ) DrawText( grid->Canvas->Handle, (char *)APs[ARow-1].status.data(),APs[ARow-1].status.Length(), &Rect,DT_RIGHT );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::generarClaveWEPClick(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  char ascWEPkey[14], hexWEPkey[27];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Randomize();
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  int i, r;
 | 
				
			||||||
 | 
					//  char charArray[] = {' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '\'', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'};
 | 
				
			||||||
 | 
					  char charArray[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', '+', 'l', '-', '.', 'm', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'o', 'p', 'q', 'r', 's', 't', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '_', '5', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '6', '7', '8', '9'};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int keyLengthInBytes = 13;
 | 
				
			||||||
 | 
					  for(i=0;i<keyLengthInBytes;i++) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        r = RandomRange(0, 94); // range is 0 ~ 94
 | 
				
			||||||
 | 
					        ascWEPkey[i] = charArray[r];      // creates the ASCII version of the WEP key
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  ascWEPkey[keyLengthInBytes] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  newWEP->Text = AnsiString(ascWEPkey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::newWEPChange(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					 hexWEP->Caption = wepASCII2HEX( newWEP->Text );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TForm1::Button1Click(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if ( newWEP->Text.Length()!=13 ) {
 | 
				
			||||||
 | 
					        ShowMessage("La nueva clave debe contener 13 d<>gitos.");
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					        Button1->Caption = "Por favor, espere...";
 | 
				
			||||||
 | 
					        // Propagar la clave por los routers.
 | 
				
			||||||
 | 
					        for (int i=0;i<StringGrid1->RowCount;i++) {
 | 
				
			||||||
 | 
					                if ( updateRouter(APs[i].IP, APs[i].user, APs[i].pass, hexWEP->Caption) ) {
 | 
				
			||||||
 | 
					                        APs[i].wep = newWEP->Text;
 | 
				
			||||||
 | 
					                        APs[i].status = "OK";
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                        APs[i].status = "ERROR";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        Button1->Caption = "Aplicar Cambios";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					bool __fastcall TForm1::updateRouter(AnsiString IP, AnsiString user, AnsiString pass, AnsiString WEP)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  TMemoryStream* out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int error;
 | 
				
			||||||
 | 
					  AnsiString Authorization, content, request, aux;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  aux = user+":"+pass;
 | 
				
			||||||
 | 
					  Authorization = Base64Encode((char *)aux.data());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*  
 | 
				
			||||||
 | 
					  request = "GET / HTTP/1.1\r\n";
 | 
				
			||||||
 | 
					  request+= "Host: "+IP+"\r\n";
 | 
				
			||||||
 | 
					  request+= "User-Agent: JDsoft\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept: text/html;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Language: es-es,es\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Encoding: gzip,deflate\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Authorization: Basic "+Authorization+"\r\n"; // YWRtaW46YWRtaW4=
 | 
				
			||||||
 | 
					  request+= "Keep-Alive: 300\r\n";
 | 
				
			||||||
 | 
					  request+= "Proxy-Connection: keep-alive\r\n";
 | 
				
			||||||
 | 
					  request+= "\r\n";
 | 
				
			||||||
 | 
					  out  = new TMemoryStream();
 | 
				
			||||||
 | 
					  error = HTTPdownloader->descargarHTML(IP.c_str(),request.c_str(),out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ( error==-1 ) return false; 
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  content = "submit_button=WL_WPATable&change_action=&submit_type=&action=Apply&security_mode_last=";
 | 
				
			||||||
 | 
					  content+= "&wl_wep_last=&security_mode2=wep&wl_key=1&wl_WEP_key=&wl_wep=restricted&wl_wep_bit=128";
 | 
				
			||||||
 | 
					  content+= "&wl_passphrase=&generateButton=Null";
 | 
				
			||||||
 | 
					  content+= "&wl_key1="+WEP;
 | 
				
			||||||
 | 
					  content+= "&wl_key2=&wl_key3=&wl_key4=";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  request = "POST /apply.cgi HTTP/1.1\r\n";
 | 
				
			||||||
 | 
					  request+= "Host: "+IP+"\r\n";
 | 
				
			||||||
 | 
					  request+= "User-Agent: JDsoft\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept: text/html;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Encoding: gzip,deflate\r\n";
 | 
				
			||||||
 | 
					  request+= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
 | 
				
			||||||
 | 
					  request+= "Keep-Alive: 300\r\n";
 | 
				
			||||||
 | 
					  request+= "Proxy-Connection: keep-alive\r\n";
 | 
				
			||||||
 | 
					  request+= "Referer: http://"+IP+"/WL_WPATable.asp\r\n";
 | 
				
			||||||
 | 
					  request+= "Authorization: Basic "+Authorization+"\r\n";
 | 
				
			||||||
 | 
					  request+= "Content-Type: application/x-www-form-urlencoded\r\n";
 | 
				
			||||||
 | 
					  request+= "Content-Length: "+AnsiString(content.Length())+"\r\n\r\n";
 | 
				
			||||||
 | 
					  request+= content;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /*TMemoryStream* */ out  = new TMemoryStream();
 | 
				
			||||||
 | 
					  error = HTTPdownloader->descargarHTML(IP.c_str(),request.c_str(),out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ( error!=-1 ) {
 | 
				
			||||||
 | 
					                char *pos, *posEnd;
 | 
				
			||||||
 | 
					                out->Position=0;
 | 
				
			||||||
 | 
					        	pos=StrPos((char *)out->Memory,"Settings are successful.");
 | 
				
			||||||
 | 
					                if ( pos<=0 ) error=-1; else error = 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return (error!=-1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/mainGUI.~ddp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/mainGUI.~ddp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										143
									
								
								src/mainGUI.~dfm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								src/mainGUI.~dfm
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,143 @@
 | 
				
			|||||||
 | 
					object Form1: TForm1
 | 
				
			||||||
 | 
					  Left = 499
 | 
				
			||||||
 | 
					  Top = 114
 | 
				
			||||||
 | 
					  Width = 301
 | 
				
			||||||
 | 
					  Height = 337
 | 
				
			||||||
 | 
					  Caption = 'WRT54GL chpwd'
 | 
				
			||||||
 | 
					  Color = clBtnFace
 | 
				
			||||||
 | 
					  Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					  Font.Color = clWindowText
 | 
				
			||||||
 | 
					  Font.Height = -11
 | 
				
			||||||
 | 
					  Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					  Font.Style = []
 | 
				
			||||||
 | 
					  OldCreateOrder = False
 | 
				
			||||||
 | 
					  OnClose = FormClose
 | 
				
			||||||
 | 
					  OnShow = FormShow
 | 
				
			||||||
 | 
					  PixelsPerInch = 96
 | 
				
			||||||
 | 
					  TextHeight = 13
 | 
				
			||||||
 | 
					  object PageControl1: TPageControl
 | 
				
			||||||
 | 
					    Left = 0
 | 
				
			||||||
 | 
					    Top = 0
 | 
				
			||||||
 | 
					    Width = 293
 | 
				
			||||||
 | 
					    Height = 306
 | 
				
			||||||
 | 
					    ActivePage = TabSheet1
 | 
				
			||||||
 | 
					    Align = alClient
 | 
				
			||||||
 | 
					    TabIndex = 0
 | 
				
			||||||
 | 
					    TabOrder = 0
 | 
				
			||||||
 | 
					    TabPosition = tpBottom
 | 
				
			||||||
 | 
					    object TabSheet1: TTabSheet
 | 
				
			||||||
 | 
					      Caption = 'Inicio'
 | 
				
			||||||
 | 
					      object Label2: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 112
 | 
				
			||||||
 | 
					        Width = 61
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'Cambiar a:'
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -11
 | 
				
			||||||
 | 
					        Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object Label1: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 16
 | 
				
			||||||
 | 
					        Width = 108
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'Clave WEP actual:'
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -11
 | 
				
			||||||
 | 
					        Font.Name = 'MS Sans Serif'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object hexWEP: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 184
 | 
				
			||||||
 | 
					        Width = 42
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'hexWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object currHexWEP: TLabel
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 88
 | 
				
			||||||
 | 
					        Width = 42
 | 
				
			||||||
 | 
					        Height = 13
 | 
				
			||||||
 | 
					        Caption = 'hexWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object Button1: TButton
 | 
				
			||||||
 | 
					        Left = 80
 | 
				
			||||||
 | 
					        Top = 220
 | 
				
			||||||
 | 
					        Width = 129
 | 
				
			||||||
 | 
					        Height = 25
 | 
				
			||||||
 | 
					        Caption = 'Aplicar Cambios'
 | 
				
			||||||
 | 
					        TabOrder = 0
 | 
				
			||||||
 | 
					        OnClick = Button1Click
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object newWEP: TEdit
 | 
				
			||||||
 | 
					        Left = 7
 | 
				
			||||||
 | 
					        Top = 136
 | 
				
			||||||
 | 
					        Width = 226
 | 
				
			||||||
 | 
					        Height = 39
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -27
 | 
				
			||||||
 | 
					        Font.Name = 'Courier New'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        MaxLength = 13
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					        TabOrder = 1
 | 
				
			||||||
 | 
					        Text = '0123456789123'
 | 
				
			||||||
 | 
					        OnChange = newWEPChange
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object currWEP: TEdit
 | 
				
			||||||
 | 
					        Left = 8
 | 
				
			||||||
 | 
					        Top = 40
 | 
				
			||||||
 | 
					        Width = 273
 | 
				
			||||||
 | 
					        Height = 41
 | 
				
			||||||
 | 
					        Font.Charset = DEFAULT_CHARSET
 | 
				
			||||||
 | 
					        Font.Color = clWindowText
 | 
				
			||||||
 | 
					        Font.Height = -29
 | 
				
			||||||
 | 
					        Font.Name = 'Courier New'
 | 
				
			||||||
 | 
					        Font.Style = [fsBold]
 | 
				
			||||||
 | 
					        MaxLength = 13
 | 
				
			||||||
 | 
					        ParentFont = False
 | 
				
			||||||
 | 
					        ReadOnly = True
 | 
				
			||||||
 | 
					        TabOrder = 2
 | 
				
			||||||
 | 
					        Text = 'currWEP'
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      object generarClaveWEP: TBitBtn
 | 
				
			||||||
 | 
					        Left = 240
 | 
				
			||||||
 | 
					        Top = 136
 | 
				
			||||||
 | 
					        Width = 41
 | 
				
			||||||
 | 
					        Height = 41
 | 
				
			||||||
 | 
					        TabOrder = 3
 | 
				
			||||||
 | 
					        OnClick = generarClaveWEPClick
 | 
				
			||||||
 | 
					        Kind = bkRetry
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    object TabSheet2: TTabSheet
 | 
				
			||||||
 | 
					      Caption = 'Configurar APs'
 | 
				
			||||||
 | 
					      ImageIndex = 1
 | 
				
			||||||
 | 
					      object StringGrid1: TStringGrid
 | 
				
			||||||
 | 
					        Left = 0
 | 
				
			||||||
 | 
					        Top = 0
 | 
				
			||||||
 | 
					        Width = 285
 | 
				
			||||||
 | 
					        Height = 280
 | 
				
			||||||
 | 
					        Align = alClient
 | 
				
			||||||
 | 
					        ColCount = 2
 | 
				
			||||||
 | 
					        FixedCols = 0
 | 
				
			||||||
 | 
					        TabOrder = 0
 | 
				
			||||||
 | 
					        OnDrawCell = StringGrid1DrawCell
 | 
				
			||||||
 | 
					        RowHeights = (
 | 
				
			||||||
 | 
					          24
 | 
				
			||||||
 | 
					          26
 | 
				
			||||||
 | 
					          12
 | 
				
			||||||
 | 
					          24
 | 
				
			||||||
 | 
					          24)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										62
									
								
								src/mainGUI.~h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/mainGUI.~h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef mainGUIH
 | 
				
			||||||
 | 
					#define mainGUIH
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#include <Classes.hpp>
 | 
				
			||||||
 | 
					#include <Controls.hpp>
 | 
				
			||||||
 | 
					#include <StdCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Forms.hpp>
 | 
				
			||||||
 | 
					#include <ComCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Grids.hpp>
 | 
				
			||||||
 | 
					#include <Buttons.hpp>
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					struct AP {
 | 
				
			||||||
 | 
					        AnsiString IP;
 | 
				
			||||||
 | 
					        AnsiString user;
 | 
				
			||||||
 | 
					        AnsiString pass;
 | 
				
			||||||
 | 
					        AnsiString wep;
 | 
				
			||||||
 | 
					        AnsiString status;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					class TForm1 : public TForm
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					__published:	// IDE-managed Components
 | 
				
			||||||
 | 
					        TPageControl *PageControl1;
 | 
				
			||||||
 | 
					        TTabSheet *TabSheet1;
 | 
				
			||||||
 | 
					        TButton *Button1;
 | 
				
			||||||
 | 
					        TEdit *newWEP;
 | 
				
			||||||
 | 
					        TLabel *Label2;
 | 
				
			||||||
 | 
					        TEdit *currWEP;
 | 
				
			||||||
 | 
					        TLabel *Label1;
 | 
				
			||||||
 | 
					        TTabSheet *TabSheet2;
 | 
				
			||||||
 | 
					        TStringGrid *StringGrid1;
 | 
				
			||||||
 | 
					        TBitBtn *generarClaveWEP;
 | 
				
			||||||
 | 
					        TLabel *hexWEP;
 | 
				
			||||||
 | 
					        TLabel *currHexWEP;
 | 
				
			||||||
 | 
					        void __fastcall FormShow(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
 | 
				
			||||||
 | 
					        void __fastcall StringGrid1DrawCell(TObject *Sender, int ACol,
 | 
				
			||||||
 | 
					          int ARow, TRect &Rect, TGridDrawState State);
 | 
				
			||||||
 | 
					        void __fastcall generarClaveWEPClick(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall newWEPChange(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall Button1Click(TObject *Sender);
 | 
				
			||||||
 | 
					private:	// User declarations
 | 
				
			||||||
 | 
					        AP *APs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        AnsiString __fastcall wepASCII2HEX(AnsiString txt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:		// User declarations
 | 
				
			||||||
 | 
					        __fastcall TForm1(TComponent* Owner);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void __fastcall MyWndProc(Messages::TMessage &Message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        bool __fastcall updateRouter(AnsiString IP, AnsiString user, AnsiString pass, AnsiString WEP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					extern PACKAGE TForm1 *Form1;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										88
									
								
								src/tsplash.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								src/tsplash.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include <windows.h>
 | 
				
			||||||
 | 
					#define min(a, b)  (((a) < (b)) ? (a) : (b)) 
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "tsplash.h"
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#pragma package(smart_init)
 | 
				
			||||||
 | 
					#pragma resource "*.dfm"
 | 
				
			||||||
 | 
					TSplash *Splash;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					__fastcall TSplash::TSplash(TComponent* Owner)
 | 
				
			||||||
 | 
					        : TForm(Owner)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  pressKeyToClose = false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TSplash::GetNextSpan(PByteArray row, int SpanLeft, int *SpanRight, TColor *SpanColor, int y)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int column;
 | 
				
			||||||
 | 
					  TColor TempColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  column = SpanLeft;
 | 
				
			||||||
 | 
					  TempColor = MaskColor(SpanLeft,y);
 | 
				
			||||||
 | 
					  while (  column <= ImageMap->Width && TempColor == MaskColor(column,y) ) column = column + 1;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  *SpanRight = column - 1;
 | 
				
			||||||
 | 
					  *SpanColor = TempColor;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					TColor __fastcall TSplash::MaskColor(int x,int y)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if ( ImageMap->Canvas->Pixels[x][y] == 0x00FF00FF ) return clFuchsia; else return clBlack;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void __fastcall TSplash::FormCreate(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  int y;
 | 
				
			||||||
 | 
					  PByteArray row;
 | 
				
			||||||
 | 
					  HRGN YRgn;
 | 
				
			||||||
 | 
					  HRGN SpanRgn;
 | 
				
			||||||
 | 
					  int SpanLeft;
 | 
				
			||||||
 | 
					  int SpanRight;
 | 
				
			||||||
 | 
					  TColor SpanColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Canvas->Brush->Style = bsClear;
 | 
				
			||||||
 | 
					  ImageMap = Image1->Picture->Bitmap;
 | 
				
			||||||
 | 
					  WindowRgn = CreateRectRgn(0, 0, 0, 0);
 | 
				
			||||||
 | 
					  for (y=0;y<ImageMap->Height;y++) {
 | 
				
			||||||
 | 
					    YRgn = CreateRectRgn(0, y, 0, y);
 | 
				
			||||||
 | 
					//    row = (PByteArray)ImageMap->ScanLine[y];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SpanLeft = 0;
 | 
				
			||||||
 | 
					    SpanRight = 0;
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					      GetNextSpan(row, SpanLeft, &SpanRight, &SpanColor,y);
 | 
				
			||||||
 | 
					      if ( SpanColor != clFuchsia ) {
 | 
				
			||||||
 | 
					        SpanRgn = CreateRectRgn(SpanLeft, y, SpanRight + 1, y + 1);
 | 
				
			||||||
 | 
					        CombineRgn(YRgn, YRgn, SpanRgn, RGN_OR);
 | 
				
			||||||
 | 
					        DeleteObject(SpanRgn);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      SpanLeft = SpanRight + 1;
 | 
				
			||||||
 | 
					    } while ( SpanRight < (ImageMap->Width-1));
 | 
				
			||||||
 | 
					    CombineRgn(WindowRgn, WindowRgn, YRgn, RGN_OR);
 | 
				
			||||||
 | 
					    DeleteObject(YRgn);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  SetWindowRgn(Handle,WindowRgn,true);
 | 
				
			||||||
 | 
					  DeleteObject(WindowRgn);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void __fastcall TSplash::FormPaint(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  Canvas->Draw(0, 0, ImageMap);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void __fastcall TSplash::Image1Click(TObject *Sender)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (pressKeyToClose) Close();        
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/tsplash.ddp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/tsplash.ddp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1505
									
								
								src/tsplash.dfm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1505
									
								
								src/tsplash.dfm
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										33
									
								
								src/tsplash.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/tsplash.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef tsplashH
 | 
				
			||||||
 | 
					#define tsplashH
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#include <Classes.hpp>
 | 
				
			||||||
 | 
					#include <Controls.hpp>
 | 
				
			||||||
 | 
					#include <StdCtrls.hpp>
 | 
				
			||||||
 | 
					#include <Forms.hpp>
 | 
				
			||||||
 | 
					#include <ExtCtrls.hpp>
 | 
				
			||||||
 | 
					#include <jpeg.hpp>
 | 
				
			||||||
 | 
					#include <Graphics.hpp>
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					class TSplash : public TForm
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					__published:	// IDE-managed Components
 | 
				
			||||||
 | 
					        TImage *Image1;
 | 
				
			||||||
 | 
					        void __fastcall FormCreate(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall FormPaint(TObject *Sender);
 | 
				
			||||||
 | 
					        void __fastcall Image1Click(TObject *Sender);
 | 
				
			||||||
 | 
					private:	// User declarations
 | 
				
			||||||
 | 
					        HRGN WindowRgn;
 | 
				
			||||||
 | 
					        Graphics::TBitmap *ImageMap;
 | 
				
			||||||
 | 
					        void __fastcall TSplash::GetNextSpan(PByteArray row, int SpanLeft, int *SpanRight, TColor *SpanColor,int y);
 | 
				
			||||||
 | 
					        TColor __fastcall TSplash::MaskColor(int x,int y);
 | 
				
			||||||
 | 
					public:		// User declarations
 | 
				
			||||||
 | 
					        __fastcall TSplash(TComponent* Owner);
 | 
				
			||||||
 | 
					        bool pressKeyToClose;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					extern PACKAGE TSplash *Splash;
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										159
									
								
								src/wrt54gl_chpwd.bpr
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								src/wrt54gl_chpwd.bpr
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,159 @@
 | 
				
			|||||||
 | 
					<?xml version='1.0' encoding='utf-8' ?>
 | 
				
			||||||
 | 
					<!-- C++Builder XML Project -->
 | 
				
			||||||
 | 
					<PROJECT>
 | 
				
			||||||
 | 
					  <MACROS>
 | 
				
			||||||
 | 
					    <VERSION value="BCB.06.00"/>
 | 
				
			||||||
 | 
					    <PROJECT value="..\bin\wrt54gl_chpwd.exe"/>
 | 
				
			||||||
 | 
					    <OBJFILES value="..\obj\wrt54gl_chpwd.obj ..\obj\mainGUI.obj ..\obj\tsplash.obj 
 | 
				
			||||||
 | 
					      ..\obj\THTTPdownloader.obj ..\obj\base64.obj"/>
 | 
				
			||||||
 | 
					    <RESFILES value="wrt54gl_chpwd.res"/>
 | 
				
			||||||
 | 
					    <IDLFILES value=""/>
 | 
				
			||||||
 | 
					    <IDLGENFILES value=""/>
 | 
				
			||||||
 | 
					    <DEFFILE value=""/>
 | 
				
			||||||
 | 
					    <RESDEPEN value="$(RESFILES) mainGUI.dfm tsplash.dfm THTTPdownloader.dfm"/>
 | 
				
			||||||
 | 
					    <LIBFILES value="zdllbor.lib"/>
 | 
				
			||||||
 | 
					    <LIBRARIES value="inet.lib rtl.lib vcl.lib"/>
 | 
				
			||||||
 | 
					    <SPARELIBS value="vcl.lib rtl.lib inet.lib"/>
 | 
				
			||||||
 | 
					    <PACKAGES value="vcl.bpi rtl.bpi dbrtl.bpi adortl.bpi vcldb.bpi vclx.bpi bdertl.bpi 
 | 
				
			||||||
 | 
					      vcldbx.bpi ibxpress.bpi dsnap.bpi cds.bpi bdecds.bpi teeui.bpi teedb.bpi 
 | 
				
			||||||
 | 
					      tee.bpi dss.bpi visualclx.bpi visualdbclx.bpi dsnapcrba.bpi dsnapcon.bpi 
 | 
				
			||||||
 | 
					      bcbsmp.bpi vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi 
 | 
				
			||||||
 | 
					      inetdb.bpi nmfast.bpi webdsnap.bpi bcbie.bpi websnap.bpi soaprtl.bpi 
 | 
				
			||||||
 | 
					      dclocx.bpi dbexpress.bpi dbxcds.bpi indy.bpi bcb2kaxserver.bpi JDsoft.bpi 
 | 
				
			||||||
 | 
					      TVidGrab.bpi ZComponent.bpi ZPlain.bpi ZCore.bpi ZDbc.bpi ZParseSql.bpi 
 | 
				
			||||||
 | 
					      QR5RunC6.bpi"/>
 | 
				
			||||||
 | 
					    <PATHCPP value=".;"/>
 | 
				
			||||||
 | 
					    <PATHPAS value=".;"/>
 | 
				
			||||||
 | 
					    <PATHRC value=".;"/>
 | 
				
			||||||
 | 
					    <PATHASM value=".;"/>
 | 
				
			||||||
 | 
					    <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
 | 
				
			||||||
 | 
					    <RELEASELIBPATH value="$(BCB)\lib\release"/>
 | 
				
			||||||
 | 
					    <LINKER value="ilink32"/>
 | 
				
			||||||
 | 
					    <USERDEFINES value=""/>
 | 
				
			||||||
 | 
					    <SYSDEFINES value="NO_STRICT"/>
 | 
				
			||||||
 | 
					    <MAINSOURCE value="wrt54gl_chpwd.cpp"/>
 | 
				
			||||||
 | 
					    <INCLUDEPATH value=""..\..\Ventas\GeneradorDeTickets v2.0\src";..\..\..\wrt54gl_chwpwd\src;$(BCB)\include;$(BCB)\include\vcl"/>
 | 
				
			||||||
 | 
					    <LIBPATH value=""..\..\Ventas\GeneradorDeTickets v2.0\src";..\..\..\wrt54gl_chwpwd\src;$(BCB)\Projects\Lib;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib"/>
 | 
				
			||||||
 | 
					    <WARNINGS value="-w-par"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </MACROS>
 | 
				
			||||||
 | 
					  <OPTIONS>
 | 
				
			||||||
 | 
					    <IDLCFLAGS value="-I"..\..\Ventas\GeneradorDeTickets v2.0\src" -I..\..\..\wrt54gl_chwpwd\src 
 | 
				
			||||||
 | 
					      -I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp -boa"/>
 | 
				
			||||||
 | 
					    <CFLAG1 value="-O2 -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -a8 -b- -k- -vi -c -tW -tWM"/>
 | 
				
			||||||
 | 
					    <PFLAGS value="-N2..\obj -N0..\obj -$Y- -$L- -$D- -$A8 -v -JPHNE -M"/>
 | 
				
			||||||
 | 
					    <RFLAGS value=""/>
 | 
				
			||||||
 | 
					    <AFLAGS value="/mx /w2 /zn"/>
 | 
				
			||||||
 | 
					    <LFLAGS value="-l..\obj -I..\obj -D"" -aa -Tpe -x -Gn"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </OPTIONS>
 | 
				
			||||||
 | 
					  <LINKER>
 | 
				
			||||||
 | 
					    <ALLOBJ value="c0w32.obj sysinit.obj $(OBJFILES)"/>
 | 
				
			||||||
 | 
					    <ALLRES value="$(RESFILES)"/>
 | 
				
			||||||
 | 
					    <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </LINKER>
 | 
				
			||||||
 | 
					  <FILELIST>
 | 
				
			||||||
 | 
					      <FILE FILENAME="wrt54gl_chpwd.res" FORMNAME="" UNITNAME="wrt54gl_chpwd.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="wrt54gl_chpwd.cpp" FORMNAME="" UNITNAME="wrt54gl_chpwd" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="mainGUI.cpp" FORMNAME="Form1" UNITNAME="mainGUI" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="tsplash.cpp" FORMNAME="Splash" UNITNAME="tsplash" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="zdllbor.lib" FORMNAME="" UNITNAME="zdllbor.lib" CONTAINERID="LibTool" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="THTTPdownloader.cpp" FORMNAME="HTTPdownloader" UNITNAME="THTTPdownloader" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="base64.cpp" FORMNAME="" UNITNAME="base64" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					  </FILELIST>
 | 
				
			||||||
 | 
					  <BUILDTOOLS>
 | 
				
			||||||
 | 
					  </BUILDTOOLS>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <IDEOPTIONS>
 | 
				
			||||||
 | 
					[Version Info]
 | 
				
			||||||
 | 
					IncludeVerInfo=0
 | 
				
			||||||
 | 
					AutoIncBuild=0
 | 
				
			||||||
 | 
					MajorVer=1
 | 
				
			||||||
 | 
					MinorVer=0
 | 
				
			||||||
 | 
					Release=0
 | 
				
			||||||
 | 
					Build=0
 | 
				
			||||||
 | 
					Debug=0
 | 
				
			||||||
 | 
					PreRelease=0
 | 
				
			||||||
 | 
					Special=0
 | 
				
			||||||
 | 
					Private=0
 | 
				
			||||||
 | 
					DLL=0
 | 
				
			||||||
 | 
					Locale=1034
 | 
				
			||||||
 | 
					CodePage=1252
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Version Info Keys]
 | 
				
			||||||
 | 
					CompanyName=
 | 
				
			||||||
 | 
					FileDescription=
 | 
				
			||||||
 | 
					FileVersion=1.0.0.0
 | 
				
			||||||
 | 
					InternalName=
 | 
				
			||||||
 | 
					LegalCopyright=
 | 
				
			||||||
 | 
					LegalTrademarks=
 | 
				
			||||||
 | 
					OriginalFilename=
 | 
				
			||||||
 | 
					ProductName=
 | 
				
			||||||
 | 
					ProductVersion=1.0.0.0
 | 
				
			||||||
 | 
					Comments=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Excluded Packages]
 | 
				
			||||||
 | 
					c:\archivos de programa\borland\cbuilder6\Bin\dclqrt60.bpl=QuickReport Components
 | 
				
			||||||
 | 
					c:\archivos de programa\borland\cbuilder6\Bin\dcltqr60.bpl=TeeChart for QuickReport Components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlIncludePath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\..\Ventas\GeneradorDeTickets v2.0\src;..\..\..\wrt54gl_chwpwd\src;$(BCB)\include;$(BCB)\include\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlLibraryPath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\..\Ventas\GeneradorDeTickets v2.0\src;..\..\..\wrt54gl_chwpwd\src;$(BCB)\Projects\Lib;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlDebugSourcePath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=$(BCB)\source\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlConditionals]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlIntOutputDir]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\obj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlFinalOutputDir]
 | 
				
			||||||
 | 
					Count=2
 | 
				
			||||||
 | 
					Item0=..\bin\
 | 
				
			||||||
 | 
					Item1=..\bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hIBPIOutputDir]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\obj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Debugging]
 | 
				
			||||||
 | 
					DebugSourceDirs=$(BCB)\source\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Parameters]
 | 
				
			||||||
 | 
					RunParams=
 | 
				
			||||||
 | 
					Launcher=
 | 
				
			||||||
 | 
					UseLauncher=0
 | 
				
			||||||
 | 
					DebugCWD=
 | 
				
			||||||
 | 
					HostApplication=
 | 
				
			||||||
 | 
					RemoteHost=
 | 
				
			||||||
 | 
					RemotePath=
 | 
				
			||||||
 | 
					RemoteLauncher=
 | 
				
			||||||
 | 
					RemoteCWD=
 | 
				
			||||||
 | 
					RemoteDebug=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Compiler]
 | 
				
			||||||
 | 
					ShowInfoMsgs=0
 | 
				
			||||||
 | 
					LinkDebugVcl=0
 | 
				
			||||||
 | 
					LinkCGLIB=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[CORBA]
 | 
				
			||||||
 | 
					AddServerUnit=1
 | 
				
			||||||
 | 
					AddClientUnit=1
 | 
				
			||||||
 | 
					PrecompiledHeaders=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Language]
 | 
				
			||||||
 | 
					ActiveLang=
 | 
				
			||||||
 | 
					ProjectLang=
 | 
				
			||||||
 | 
					RootDir=
 | 
				
			||||||
 | 
					  </IDEOPTIONS>
 | 
				
			||||||
 | 
					</PROJECT>
 | 
				
			||||||
							
								
								
									
										46
									
								
								src/wrt54gl_chpwd.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/wrt54gl_chpwd.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include "tsplash.h"
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					USEFORM("mainGUI.cpp", Form1);
 | 
				
			||||||
 | 
					USEFORM("tsplash.cpp", Splash);
 | 
				
			||||||
 | 
					USEFORM("THTTPdownloader.cpp", HTTPdownloader);
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					try {//outer finally
 | 
				
			||||||
 | 
					        try
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 Application->Initialize();
 | 
				
			||||||
 | 
					                 Splash = new TSplash(NULL);
 | 
				
			||||||
 | 
					                 Splash->Show();
 | 
				
			||||||
 | 
					                 Splash->Repaint();
 | 
				
			||||||
 | 
					                 Application->CreateForm(__classid(TForm1), &Form1);
 | 
				
			||||||
 | 
					                 Application->CreateForm(__classid(THTTPdownloader), &HTTPdownloader);
 | 
				
			||||||
 | 
					                 Application->Run();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (Exception &exception)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 Application->ShowException(&exception);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (...)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 try
 | 
				
			||||||
 | 
					                 {
 | 
				
			||||||
 | 
					                         throw Exception("");
 | 
				
			||||||
 | 
					                 }
 | 
				
			||||||
 | 
					                 catch (Exception &exception)
 | 
				
			||||||
 | 
					                 {
 | 
				
			||||||
 | 
					                         Application->ShowException(&exception);
 | 
				
			||||||
 | 
					                 }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					__finally{
 | 
				
			||||||
 | 
					  if(Splash)
 | 
				
			||||||
 | 
					    delete Splash;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/wrt54gl_chpwd.res
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/wrt54gl_chpwd.res
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										160
									
								
								src/wrt54gl_chpwd.~bpr
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								src/wrt54gl_chpwd.~bpr
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,160 @@
 | 
				
			|||||||
 | 
					<?xml version='1.0' encoding='utf-8' ?>
 | 
				
			||||||
 | 
					<!-- C++Builder XML Project -->
 | 
				
			||||||
 | 
					<PROJECT>
 | 
				
			||||||
 | 
					  <MACROS>
 | 
				
			||||||
 | 
					    <VERSION value="BCB.06.00"/>
 | 
				
			||||||
 | 
					    <PROJECT value="..\bin\wrt54gl_chpwd.exe"/>
 | 
				
			||||||
 | 
					    <OBJFILES value="..\obj\wrt54gl_chpwd.obj ..\obj\mainGUI.obj ..\obj\tsplash.obj 
 | 
				
			||||||
 | 
					      ..\obj\THTTPdownloader.obj ..\obj\base64.obj"/>
 | 
				
			||||||
 | 
					    <RESFILES value="wrt54gl_chpwd.res"/>
 | 
				
			||||||
 | 
					    <IDLFILES value=""/>
 | 
				
			||||||
 | 
					    <IDLGENFILES value=""/>
 | 
				
			||||||
 | 
					    <DEFFILE value=""/>
 | 
				
			||||||
 | 
					    <RESDEPEN value="$(RESFILES) mainGUI.dfm tsplash.dfm THTTPdownloader.dfm"/>
 | 
				
			||||||
 | 
					    <LIBFILES value="zdllbor.lib"/>
 | 
				
			||||||
 | 
					    <LIBRARIES value="inet.lib rtl.lib vcl.lib"/>
 | 
				
			||||||
 | 
					    <SPARELIBS value="vcl.lib rtl.lib inet.lib"/>
 | 
				
			||||||
 | 
					    <PACKAGES value="vcl.bpi rtl.bpi dbrtl.bpi adortl.bpi vcldb.bpi vclx.bpi bdertl.bpi 
 | 
				
			||||||
 | 
					      vcldbx.bpi ibxpress.bpi dsnap.bpi cds.bpi bdecds.bpi teeui.bpi teedb.bpi 
 | 
				
			||||||
 | 
					      tee.bpi dss.bpi visualclx.bpi visualdbclx.bpi dsnapcrba.bpi dsnapcon.bpi 
 | 
				
			||||||
 | 
					      bcbsmp.bpi vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi 
 | 
				
			||||||
 | 
					      inetdb.bpi nmfast.bpi webdsnap.bpi bcbie.bpi websnap.bpi soaprtl.bpi 
 | 
				
			||||||
 | 
					      dclocx.bpi dbexpress.bpi dbxcds.bpi indy.bpi bcb2kaxserver.bpi JDsoft.bpi 
 | 
				
			||||||
 | 
					      TVidGrab.bpi ZComponent.bpi ZPlain.bpi ZCore.bpi ZDbc.bpi ZParseSql.bpi 
 | 
				
			||||||
 | 
					      QR5RunC6.bpi"/>
 | 
				
			||||||
 | 
					    <PATHCPP value=".;"/>
 | 
				
			||||||
 | 
					    <PATHPAS value=".;"/>
 | 
				
			||||||
 | 
					    <PATHRC value=".;"/>
 | 
				
			||||||
 | 
					    <PATHASM value=".;"/>
 | 
				
			||||||
 | 
					    <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
 | 
				
			||||||
 | 
					    <RELEASELIBPATH value="$(BCB)\lib\release"/>
 | 
				
			||||||
 | 
					    <LINKER value="ilink32"/>
 | 
				
			||||||
 | 
					    <USERDEFINES value="_DEBUG"/>
 | 
				
			||||||
 | 
					    <SYSDEFINES value="_RTLDLL;NO_STRICT"/>
 | 
				
			||||||
 | 
					    <MAINSOURCE value="wrt54gl_chpwd.cpp"/>
 | 
				
			||||||
 | 
					    <INCLUDEPATH value=""..\..\Ventas\GeneradorDeTickets v2.0\src";..\..\..\wrt54gl_chwpwd\src;$(BCB)\include;$(BCB)\include\vcl"/>
 | 
				
			||||||
 | 
					    <LIBPATH value=""..\..\Ventas\GeneradorDeTickets v2.0\src";..\..\..\wrt54gl_chwpwd\src;$(BCB)\Projects\Lib;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib"/>
 | 
				
			||||||
 | 
					    <WARNINGS value="-w-par"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </MACROS>
 | 
				
			||||||
 | 
					  <OPTIONS>
 | 
				
			||||||
 | 
					    <IDLCFLAGS value="-I"..\..\Ventas\GeneradorDeTickets v2.0\src" -I..\..\..\wrt54gl_chwpwd\src 
 | 
				
			||||||
 | 
					      -I$(BCB)\include -I$(BCB)\include\vcl -src_suffix cpp -D_DEBUG -boa"/>
 | 
				
			||||||
 | 
					    <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c 
 | 
				
			||||||
 | 
					      -tW -tWM"/>
 | 
				
			||||||
 | 
					    <PFLAGS value="-N2..\obj -N0..\obj -$YD -$W -$O- -$A8 -v -JPHNE -M"/>
 | 
				
			||||||
 | 
					    <RFLAGS value=""/>
 | 
				
			||||||
 | 
					    <AFLAGS value="/mx /w2 /zd"/>
 | 
				
			||||||
 | 
					    <LFLAGS value="-l..\obj -I..\obj -D"" -aa -Tpe -x -Gn -v"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </OPTIONS>
 | 
				
			||||||
 | 
					  <LINKER>
 | 
				
			||||||
 | 
					    <ALLOBJ value="c0w32.obj Memmgr.Lib sysinit.obj $(OBJFILES)"/>
 | 
				
			||||||
 | 
					    <ALLRES value="$(RESFILES)"/>
 | 
				
			||||||
 | 
					    <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mti.lib"/>
 | 
				
			||||||
 | 
					    <OTHERFILES value=""/>
 | 
				
			||||||
 | 
					  </LINKER>
 | 
				
			||||||
 | 
					  <FILELIST>
 | 
				
			||||||
 | 
					      <FILE FILENAME="wrt54gl_chpwd.res" FORMNAME="" UNITNAME="wrt54gl_chpwd.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="wrt54gl_chpwd.cpp" FORMNAME="" UNITNAME="wrt54gl_chpwd" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="mainGUI.cpp" FORMNAME="Form1" UNITNAME="mainGUI" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="tsplash.cpp" FORMNAME="Splash" UNITNAME="tsplash" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="zdllbor.lib" FORMNAME="" UNITNAME="zdllbor.lib" CONTAINERID="LibTool" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="THTTPdownloader.cpp" FORMNAME="HTTPdownloader" UNITNAME="THTTPdownloader" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					      <FILE FILENAME="base64.cpp" FORMNAME="" UNITNAME="base64" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
 | 
				
			||||||
 | 
					  </FILELIST>
 | 
				
			||||||
 | 
					  <BUILDTOOLS>
 | 
				
			||||||
 | 
					  </BUILDTOOLS>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <IDEOPTIONS>
 | 
				
			||||||
 | 
					[Version Info]
 | 
				
			||||||
 | 
					IncludeVerInfo=0
 | 
				
			||||||
 | 
					AutoIncBuild=0
 | 
				
			||||||
 | 
					MajorVer=1
 | 
				
			||||||
 | 
					MinorVer=0
 | 
				
			||||||
 | 
					Release=0
 | 
				
			||||||
 | 
					Build=0
 | 
				
			||||||
 | 
					Debug=0
 | 
				
			||||||
 | 
					PreRelease=0
 | 
				
			||||||
 | 
					Special=0
 | 
				
			||||||
 | 
					Private=0
 | 
				
			||||||
 | 
					DLL=0
 | 
				
			||||||
 | 
					Locale=1034
 | 
				
			||||||
 | 
					CodePage=1252
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Version Info Keys]
 | 
				
			||||||
 | 
					CompanyName=
 | 
				
			||||||
 | 
					FileDescription=
 | 
				
			||||||
 | 
					FileVersion=1.0.0.0
 | 
				
			||||||
 | 
					InternalName=
 | 
				
			||||||
 | 
					LegalCopyright=
 | 
				
			||||||
 | 
					LegalTrademarks=
 | 
				
			||||||
 | 
					OriginalFilename=
 | 
				
			||||||
 | 
					ProductName=
 | 
				
			||||||
 | 
					ProductVersion=1.0.0.0
 | 
				
			||||||
 | 
					Comments=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Excluded Packages]
 | 
				
			||||||
 | 
					c:\archivos de programa\borland\cbuilder6\Bin\dclqrt60.bpl=QuickReport Components
 | 
				
			||||||
 | 
					c:\archivos de programa\borland\cbuilder6\Bin\dcltqr60.bpl=TeeChart for QuickReport Components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlIncludePath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\..\Ventas\GeneradorDeTickets v2.0\src;..\..\..\wrt54gl_chwpwd\src;$(BCB)\include;$(BCB)\include\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlLibraryPath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\..\Ventas\GeneradorDeTickets v2.0\src;..\..\..\wrt54gl_chwpwd\src;$(BCB)\Projects\Lib;C:\programacion\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlDebugSourcePath]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=$(BCB)\source\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlConditionals]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlIntOutputDir]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\obj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hlFinalOutputDir]
 | 
				
			||||||
 | 
					Count=2
 | 
				
			||||||
 | 
					Item0=..\bin\
 | 
				
			||||||
 | 
					Item1=..\bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[HistoryLists\hIBPIOutputDir]
 | 
				
			||||||
 | 
					Count=1
 | 
				
			||||||
 | 
					Item0=..\obj
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Debugging]
 | 
				
			||||||
 | 
					DebugSourceDirs=$(BCB)\source\vcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Parameters]
 | 
				
			||||||
 | 
					RunParams=
 | 
				
			||||||
 | 
					Launcher=
 | 
				
			||||||
 | 
					UseLauncher=0
 | 
				
			||||||
 | 
					DebugCWD=
 | 
				
			||||||
 | 
					HostApplication=
 | 
				
			||||||
 | 
					RemoteHost=
 | 
				
			||||||
 | 
					RemotePath=
 | 
				
			||||||
 | 
					RemoteLauncher=
 | 
				
			||||||
 | 
					RemoteCWD=
 | 
				
			||||||
 | 
					RemoteDebug=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Compiler]
 | 
				
			||||||
 | 
					ShowInfoMsgs=0
 | 
				
			||||||
 | 
					LinkDebugVcl=0
 | 
				
			||||||
 | 
					LinkCGLIB=0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[CORBA]
 | 
				
			||||||
 | 
					AddServerUnit=1
 | 
				
			||||||
 | 
					AddClientUnit=1
 | 
				
			||||||
 | 
					PrecompiledHeaders=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Language]
 | 
				
			||||||
 | 
					ActiveLang=
 | 
				
			||||||
 | 
					ProjectLang=
 | 
				
			||||||
 | 
					RootDir=
 | 
				
			||||||
 | 
					  </IDEOPTIONS>
 | 
				
			||||||
 | 
					</PROJECT>
 | 
				
			||||||
							
								
								
									
										46
									
								
								src/wrt54gl_chpwd.~cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/wrt54gl_chpwd.~cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vcl.h>
 | 
				
			||||||
 | 
					#include "tsplash.h"
 | 
				
			||||||
 | 
					#pragma hdrstop
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					USEFORM("mainGUI.cpp", Form1);
 | 
				
			||||||
 | 
					USEFORM("tsplash.cpp", Splash);
 | 
				
			||||||
 | 
					USEFORM("THTTPdownloader.cpp", HTTPdownloader);
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					try {//outer finally
 | 
				
			||||||
 | 
					        try
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 Application->Initialize();
 | 
				
			||||||
 | 
					                 Splash = new TSplash(NULL);
 | 
				
			||||||
 | 
					                 Splash->Show();
 | 
				
			||||||
 | 
					                 Splash->Repaint();
 | 
				
			||||||
 | 
					                 Application->CreateForm(__classid(TForm1), &Form1);
 | 
				
			||||||
 | 
					                 Application->CreateForm(__classid(THTTPdownloader), &HTTPdownloader);
 | 
				
			||||||
 | 
					                 Application->Run();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (Exception &exception)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 Application->ShowException(&exception);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        catch (...)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					                 try
 | 
				
			||||||
 | 
					                 {
 | 
				
			||||||
 | 
					                         throw Exception("");
 | 
				
			||||||
 | 
					                 }
 | 
				
			||||||
 | 
					                 catch (Exception &exception)
 | 
				
			||||||
 | 
					                 {
 | 
				
			||||||
 | 
					                         Application->ShowException(&exception);
 | 
				
			||||||
 | 
					                 }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					__finally{
 | 
				
			||||||
 | 
					  if(Splash)
 | 
				
			||||||
 | 
					    delete Splash;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					//---------------------------------------------------------------------------
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/zdllbor.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/zdllbor.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user