













                                     MPATCH LIB
                                    Release 1.50













                    Freeware C library to apply *.MDF patch files
                       produced by a REGISTERED copy of MDIFF.
                     Dos, OS/2 and Windows95/WindowsNT versions.

























                             (C) 1995/96 Maurizio Giunti






     1.INDEX


     1.INDEX                                                                  2


     2.LEGAL STUFF                                                            3

       1.DISCLAIMER OF WARRANTY                                               3

       2.DISTRIBUTION AND USE                                                 3

       3.LIMITS                                                               3


     3.OVERVIEW                                                               3

       1.WHAT IS AN MDF PATCH                                                 3

       2.DOS, OS/2, WINDOWS 95 AND WINDOWS NT                                 3

       3.COMPILER OPTIONS                                                     4


     4.BASIC FEATURES                                                         4

       1.READING THE HEADER                                                   4
        short MDF_ReadHead(char *fn, struct MDF_header_info *hi)              4

       2.APPLYING THE PATCH                                                   5
        short MDF_Patch(char *diffile, char *oldfile, char *newfile)          5

       3.ERRORS                                                               5
        char *MDF_LastError(void)                                             5
        char *MDF_Error(short e)                                              5


     5.ADVANCED FEATURES                                                      5

       1.PASSWORD                                                             5
        void MDF_SetPassword(char *pwd)                                       5

       2.IDLE FUNCTION                                                        6
        void MDF_SetIdle(void (*idl)(void),short rate)                        6

       3.CRC CHECK                                                            6
        unsigned long FileCrc32(char *fn)                                     6


     6.HOW TO CONTACT THE AUTHOR                                              6




                                                                              2






     2.LEGAL STUFF

     1.DISCLAIMER OF WARRANTY
     THIS  SOFTWARE AND THE  ACCOMPANYING FILES  ARE SOLD "AS  IS" AND  WITHOUT
     WARRANTIES  AS TO PERFORMANCE OF  MERCHANTABILITY OR ANY OTHER  WARRANTIES
     WHETHER EXPRESSED OR IMPLIED.
     The  only warranty that comes  with this software is  that it will  occupy
     disk  space. I absolutely can NOT warrant that it will perfectly work,  or
     that it will be your problems' solution.
     Nevertheless,  it is not a virus and does not contain (unless infected  or
     modified  after the   compilation)  Trojan-horses, backdoors  and  similar
     tricky  garbage. In  any case,  the author  is not  responsible   for  any
     damage, moral or material, direct or indirect, derived from its use.

     2.DISTRIBUTION AND USE
     MPATCH LIB can be freely distributed at no cost, except for  eventual copy
     and/or  shipping  expenses. It  is  imperative anyway  that  the  ORIGINAL
     PACKET is distributed without any modification WHATSOEVER.
     Using  a library  means to  statically include  it in  your own  products:
     MPATCH  LIB is FREEWARE (but  it is NOT public  domain); it means you  can
     include it in your own applications and distribute them freely.
     No royalty or extra charge required!

     3.LIMITS
     Libraries  contained in this packet can  only apply *.MDF patches  builded
     by a REGISTERED COPY of MDIFF patch software release 1.50.
     Please  don't consider this limit as a  sort of crippleware: this  library
     is  fully functional, just  it can't  apply *.MDF patches  produced by  an
     unregistered copy of MDIFF.

     3.OVERVIEW

     1.WHAT IS AN MDF PATCH
     A  MDF patch is a patch file builded by a shareware software named  MDIFF.
     If  you  don't  know  MDIFF  probably  you  are  not  interested  in  this
     libraries.  If you want to know more  about MDIFF please search FTP  sites
     or  local bbs for a  file named mdf150.zip (or  .arj, .rar, etc.).  Anyway
     the following is a short abstract from MDIFF's manual:
        WHAT MDIFF-MPATCH DO?
        MDIFF  creates a binary difference between  two files. With MPATCH
        and the  older file you can create a new file using the difference
        file.  What  is  the advantage?  Usually  the  difference  file is
        smaller  and therefore more suitable  for distribution, especially
        by modem.

     2.DOS, OS/2, WINDOWS 95 AND WINDOWS NT
     MPATCH LIB is a single library, but you will find in the packet  many .LIB
     files.  That's because I  compiled MPATCH LIB  for many operating  systems
     and  C/C++  compilers.  To find  the  library  you need  please  read  the
     following table:
           FILE NAME           OS and Memory Model             COMPILER
     MPTBDC.LIB                   DOS - Compact                 Borland
     MPTBDL.LIB                    DOS - Large                  Borland
     MPTBDH.LIB                     DOS - Huge                  Borland
                                                                              3





     MPTMDC.LIB                   DOS - Compact                Microsoft
     MPTMDL.LIB                    DOS - Large                 Microsoft
     MPTMDH.LIB                     DOS - Huge                 Microsoft
     MPTW32.LIB                Windows95/WindowsNT             Microsoft
     MPTOS2B.LIB                       OS/2                     Borland
     MPTOS2I.LIB                       OS/2                       IBM

     3.COMPILER OPTIONS
     To  link MPATCH LIB to your software you probably need to compile it  with
     1 byte struct alignment option.

     4.BASIC FEATURES
     Each MDF file contains a patch to apply to an existent file (OLD  file) to
     rebuild a newer version of the same file (NEW file).
     MPATCH  LIB gives you  the ability to  read the header  info from any  MDF
     file and to apply the patch it contains.
     Before  reading the  following chapters,  please examine  MPTLIB.H  header
     file and the SAMPLE.C sample source file.

     1.READING THE HEADER
     Each  *.MDF file  contains  a header  in which  are recorded  some  useful
     information. You can read this  header using the MDF_ReadHead() function:

     short MDF_ReadHead(char *fn, struct MDF_header_info *hi)
     fn  argument is a pointer to the *.MDF file  name, and hi is a pointer  to
     the structure where the function  will store the information read,  and it
     is defined as:

     struct MDF_header_info   {
          char alg_ver[4];
          char oldfilename[255];
          char newfilename[255];
          char registeredto[255];
          char comment[2048];
          unsigned long oldfilecrc;
          short chunk_len;
          unsigned long n_chunks;
          short password;
     };

     Where:
     alg_ver          Version of the algorithm used to create  the *.MDF file
     oldfilename      OLD file original name
     newfilename      NEW file original name
     registeredto     Owner's name of the the *.MDF file (registered only)
     comment          Comment
     oldfilecrc       OLD file crc
     chunk_len        Chunk lenght
     n_chunks         Number of chunks
     password         non zero if MDF file is password protected

     Return value:
     0        File not found
     1        OK
     -1       This is not a valid *.MDF file
                                                                              4





     -2       Incorrect version of MDIFF


     2.APPLYING THE PATCH
     The  MDF_Patch() function makes all  the work. It reads  the old file  and
     checks  it to be sure it is the right  one, then it creates the new  file.
     At  the end of the  job it returns  a 0 or  a non zero  value if an  error
     occurred.

     short MDF_Patch(char *diffile, char *oldfile, char *newfile)
     diffile is a pointer to the name of the MDF file, oldfile is a  pointer to
     the  name of the existing old file and new  file is a pointer to the  name
     of the file it must create.
     Return value:
       VALUE                             DESCRIPTION
     -1       "Can't run more than one patch at a time!"
     0        "OK!"
     1        "Out of memory!"
     2        "Can't open MDF file!"
     3        "Invalid MDF file!"
     4        "MDF file version mismatch!"
     5        "UNREGISTERED!"
     6        "Incorrect OLD file!"
     7        "Can't open OLD file!"
     8        "Can't create NEW file!"
     9        "General failure: NEW file corrupted!"
     10       "OLD and NEW can't be the same file!"
     11       "NEW file was already patched!"
     12       "Wrong password!"

     3.ERRORS
     MPATCH  LIB contains, for each error code,  the brief description you  can
     see in the previous table.
     To obtain a pointer to the string which describes last error  occurred you
     can use MDF_LastError() function:

     char *MDF_LastError(void)
     This function does not need parameters.
     If  you need to get the description of a particular error you can  use the
     MDF_Error() function:

     char *MDF_Error(short e)
     which returns a pointer to the description of the error number e.

     5.ADVANCED FEATURES

     1.PASSWORD
     Sometime you must use a password to decrypt the patch to install.  You can
     specify  it by calling the  function MDF_SetPassword() before calling  the
     MDF_Patch() function:

     void MDF_SetPassword(char *pwd)
     where  pwd is a pointer to the password string. If you specify a  password
     but  the patch does not  need to be decrypted,  then the password will  be
     ignored.
                                                                              5





     2.IDLE FUNCTION
     Since applying a patch is not always a quick operation, you  probably need
     to  execute some other operation, like displaying a message on the  screen
     or  dispatching messages  in  a Windows'  application. You  can do  it  by
     setting an idle function with the MDF_SetIdle():

     void MDF_SetIdle(void (*idl)(void),short rate)
     where idl is a pointer to your idle function declared as
          void myidle(void)
     and rate is a value which determins the how many times your  idle function
     is called by the MDF_Patch() function.
     Please look at SAMPLE.C to have an example of the use of this function.

     3.CRC CHECK
     In  MPATCH LIB  you will  find one  more function  which can  help you  to
     develop smarter applications:

     unsigned long FileCrc32(char *fn)
     where  fn is  a  complete file  name. This  function returns  a  crc-32bit
     computed  on the fn  file, which  can help  you to find  whether the  file
     specified to be the old one is right or not. You must compare this  crc to
     the one stored in the field oldfilecrc of the MDF_header_info structure.
     Please look at SAMPLE.C to have an example.

     6.HOW TO CONTACT THE AUTHOR
     For any question you can contact me at:
     My home address:
                         Maurizio Giunti
                         Via G.B. Foggini, 24
                         50142 Firenze
                         Italy

     My E-Mail addresses:
             Fidonet:    2:332/102.3
             Internet:   giunti@kagi.com
                         giunti@abeline.it
                         giunti@statsun.ds.unifi.it


















                                                                              6
