home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / FLASHPAC.ZIP / CH5_1.DOC < prev    next >
Encoding:
Text File  |  1991-03-15  |  18.3 KB  |  785 lines

  1. ..pgno01
  2. ..foot60A5-##
  3. ..head02L──────────────────────────────────────────────────────────────────────
  4. ..head04L──────────────────────────────────────────────────────────────────────
  5. ..head03LGlobal Structures
  6.  
  7. typedef TFindRec = {
  8.                    UINT2 Attr;
  9.                    UINT2 Time;
  10.                    UINT2 Date;
  11.                    UINT4 Size;
  12.                    UCHAR Name[13];
  13.                    } TFindRec;
  14.  
  15.  
  16.  
  17. Global Variable Declarations
  18. ──────────────────────────────────────────────────────────────────────
  19. INT2 DosErrNo         the error code for function result errors.
  20.  
  21. INT2 CErrCode         the error code for critical errors.
  22.  
  23. INT2 CErrType         contains the type of device for the critical
  24.                       error.
  25.                          0 = Block device
  26.                          1 = Character device
  27.  
  28. INT2 CErrDrive        contains the number of the disk drive where the
  29.                       critical error occurred.  If the critical error
  30.                       is not a disk drive the value will then remain
  31.                       as -1.
  32.  
  33. CHAR CErrDevice[9]    contains the name of the device in error.
  34. ..page
  35. ..head03ACloseFile
  36. ■ Description
  37.  
  38.   Closes a file and flushes all file buffers for a file.
  39.  
  40. ■ Summary
  41.  
  42.   VOID FPENTRY CloseFile( INT2 Handle );
  43.  
  44.   Handle     the handle number of a file that was opened using the
  45.          OpenFile operation.
  46.  
  47.  
  48. ■ Remarks
  49.  
  50.   If an error occurred DosErrNo will contain one of the following
  51.   error codes.
  52.  
  53.      DosErrNo     Description
  54.      ──────── ───────────────────
  55.         6     Invalid file handle
  56.  
  57.  
  58. ■ Example
  59.  
  60.   #include <fpclib.h>
  61.  
  62.   main()
  63.   {
  64.      INT Handle;
  65.  
  66.      OpenFile( "Temp.Fil", READ_ONLY, &Handle );
  67.              .
  68.              .
  69.              .
  70.      CloseFile( Handle );
  71.   }
  72.  
  73.   This example will close the file that is associate with the handle
  74.   number returned in the OpenFile function.  If the close operation
  75.   was successful DosErrNo will contain a zero, provided the variable
  76.   was reset to zero after the last I/O error.  If an error occurred
  77.   DosErrNo should contain the value 6.
  78. ..page
  79. ..head03ACreateFile
  80. ■ Description
  81.  
  82.   Opens an existing file or creates a new file if it does not exist.
  83.  
  84.  
  85. ■ Summary
  86.  
  87.   VOID FPENTRY CreateFile( CHAR *Path, INT2 Attr, INT2 *Handle );
  88.  
  89.   Path        the path and filename of the file to be opened or
  90.               created.
  91.  
  92.   Attr        mode to set the file's attribute to.
  93.  
  94.   Handle      returns an integer that this file is assoicated with for
  95.               access.
  96.  
  97.  
  98. ■ Remarks
  99.  
  100.   This operation will open a new or existing file for read/write
  101.   access. CreateFile assumes that the file is opened as an output file
  102.   and will set the length of any existing file to zero.  If any errors
  103.   occur DosErrNo will have the error code.
  104.  
  105.   DosErrNo    Description
  106.   ──────── ───────────────────
  107.      3     Path not found
  108.      4     No handle available
  109.      5     Access denied
  110.      6     Invalid file handle
  111.  
  112.  
  113. ■ See Also
  114.  
  115.   OpenFile
  116. ..page
  117. ■ Example
  118.  
  119.   #include <fpclib.h>
  120.  
  121.   main()
  122.   {
  123.      CreateFile( "NewFile", 32, &Handle );
  124.              .
  125.              .
  126.              .
  127.   }
  128.  
  129.   If "Newfile" exists in the current directory then CreateFile will
  130.   open the file for output and assign a length of zero to the file.
  131.   If "Newfile" does not exist then a new file will be created.  The
  132.   variable Handle will return an integer that is associated with the
  133.   file "Newfile". DosErrNo will contain zero if the CreateFile
  134.   operation was successful.
  135. ..page
  136. ..head03ADosFindFirst
  137. ■ Description
  138.  
  139.   Find the first file that matches the given filespec and attributes.
  140.  
  141.  
  142. ■ Summary
  143.  
  144.   VOID FPENTRY DosFindFirst( CHAR     *Path,
  145.                  INT2      Attr,
  146.                  TFindRec  FindRec );
  147.  
  148.   Path        the path and filename of the file to search for.
  149.  
  150.   Attr        attributes of the files to include in the file search
  151.  
  152.   FindRec     the result of the search is returned in a variable of
  153.               TFindRec. (See Global Structures page 5-1).
  154.  
  155.  
  156. ■ Remarks
  157.  
  158.   This operation will search for the specified file.  The characters *
  159.   and ? may be used for the filespec.  If any errors occur DosErrNo
  160.   will have the error code.
  161.  
  162.   DosErrNo    Description
  163.   ──────── ───────────────────
  164.      2     Directory not found
  165.      3     Path not found
  166.     18     No more files
  167.  
  168.   The search attibute values may be one or any combination of values.
  169.   (e.g. to search for a hidden system file use value 6).
  170.  
  171.   Bit(s)   Value   Description
  172.   ──────   ─────   ───────────
  173.    0         1     read-only
  174.    1         2     hidden
  175.    2         4     system
  176.    3         8     volumne label
  177.    4        16     directory
  178.    5        32     archive
  179.    6-15            reserved
  180.  
  181.  
  182. ■ See Also
  183.  
  184.   DosFindNext
  185. ..page
  186. ■ Example
  187.  
  188.   #include <fpclib.h>
  189.  
  190.   main()
  191.   {
  192.       TFindRec Rec;
  193.  
  194.       DosFindFirst( "*.PAS", 32, &Rec );
  195.   }
  196.  
  197.   This example will find the first occurrance of a file in the current
  198.   directory that has the extension of "PAS".
  199. ..page
  200. ..head03ADosFindNext
  201. ■ Description
  202.  
  203.   Returns the next file entry that matches the filespec and attributes
  204.   used in a previous call to DosFindFirst.
  205.  
  206.  
  207. ■ Summary
  208.  
  209.   VOID FPENTRY DosFindNext( TFindRec FindRec );
  210.  
  211.   FindRec     the result of the search is returned in the variable of
  212.               TFindRec. (See Global Structures page 5-1).
  213.  
  214.  
  215. ■ Remarks
  216.  
  217.   DosFindNext must be called after DosFindFirst and before any other
  218.   calls that transfer data into the DTA at the time of the call to
  219.   DosFindFirst.
  220.  
  221.   DosErrNo    Description
  222.   ──────── ──────────────────
  223.      18    No more files
  224.  
  225.  
  226. ■ See Also
  227.  
  228.   DosFindFirst
  229.  
  230.  
  231. ■ Example
  232.  
  233.   #include <fpclib.h>
  234.  
  235.   main()
  236.   {
  237.      TFindRec Rec;
  238.  
  239.      DosFindFirst( "*.PAS", 32, &Rec );
  240.      while ( !DosErrorNo ) {
  241.         printf( "%s", Rec.Name );
  242.         DosFindNext( &Rec );
  243.      }
  244.   }
  245.  
  246.   This example will find the all occurrances of files in the current
  247.   directory that have the extension of "PAS".
  248. ..page
  249. ..head03AFSeek
  250. ■ Description
  251.  
  252.   Change the logical read/write position of the file pointer.
  253.  
  254.  
  255. ■ Summary
  256.  
  257.   UINT4 FSeek( INT Handle, INT Orgin, INT4 Offset );
  258.  
  259.   Handle      file handle that was assigned to a file using either the
  260.               OpenFile or CreateFile operaton.
  261.  
  262.   Orgin       gives the starting location to use when moving the file
  263.               pointer.
  264.  
  265.               Method           Description
  266.               ────── ────────────────────────────────
  267.                0     beginning of file
  268.                1     current location of file pointer
  269.                2     EOF location
  270.  
  271.   Offset      gives the number of bytes to move the file pointer.
  272.  
  273.  
  274. ■ Remarks
  275.  
  276.   This operation will move the file pointer for the specified number
  277.   of bytes given.  On return this function reports the number of bytes
  278.   the file pointer is from the beginning of the file.  If any errors
  279.   occur DosErrNo will have the error code.
  280.  
  281.   DosErrNo Description
  282.   ──────── ───────────────────
  283.       1    Invalid method code
  284.       6    Invalid file handle
  285. ..page
  286. ■ Example
  287.  
  288.   #include <fpclib.h>
  289.  
  290.   main()
  291.   {
  292.      INT  handle;
  293.      INT4 offset;
  294.  
  295.      Openfile( "file.dat", 2, &handle );
  296.  
  297.       if ( !DosErrNo )
  298.         offset = FSeek( handle, 2, 0L );
  299.   }
  300.  
  301.   Executing FSeek with an offset of zero, and the seek beginning at
  302.   the end of the file, the variable Offset will contain a long integer
  303.   of the file size in bytes.  FSeek always returns the number of bytes
  304.   the file pointer is located from the beginning of the file.
  305. ..page
  306. ..head03AGetDrive
  307. ■ Description
  308.  
  309.   Reports the current default disk drive
  310.  
  311.  
  312. ■ Summary
  313.  
  314.   INT2 FPENTRY GetDrive( VOID );
  315.  
  316.  
  317. ■ Remarks
  318.  
  319.   GetDrive returns an integer to indicate which disk drive is the
  320.   current default drive where:
  321.  
  322.      Drive A = 1
  323.      Drive B = 2
  324.      Drive C = 3
  325.  
  326.  
  327. ■ Example
  328.  
  329.   #include <fpclib.h>
  330.  
  331.   main()
  332.   {
  333.      printf( "Current Drive is %c", GetDrive()+65 );
  334.   }
  335.  
  336.   The write statement will display the letter of the drive that is the
  337.   current default drive.
  338. ..page
  339. ..head03AGetDTA
  340. ■ Description
  341.  
  342.   Returns the current disk transfer area
  343.  
  344.  
  345. ■ Summary
  346.  
  347.   VOID FPENTRY GetDTA( UINT2 Segment, Offset );
  348.  
  349.   Segment     returns the segment of the current DTA.
  350.  
  351.   Offset      returns the offset of the current DTA.
  352.  
  353.  
  354. ■ Example
  355.  
  356.   #include <fpclib.h>
  357.  
  358.   main()
  359.   {
  360.      UINT Segment,Offset;
  361.  
  362.      GetDTA( Segment, Offset );
  363.      printf("DTA Segment = %4X  DTA Offset = %4X", Segment, Offset );
  364.   }
  365.  
  366.   After the call to GetDTA the integer variables segment and offset
  367.   will contain the Segment:Offset address for the current disk
  368.   transfer area.
  369. ..page
  370. ..head03AGetFileSize
  371. ■ Description
  372.  
  373.   Report the number of bytes in a disk file.
  374.  
  375.  
  376. ■ Summary
  377.  
  378.   INT4 FPENTRY GetFileSize( INT Handle );
  379.  
  380.   Handle      gives a file handle that was assigned to a file using
  381.               the OpenFile or CreateFile operaton.
  382.  
  383.  
  384. ■ Remarks
  385.  
  386.   GetFileSize reports the number of bytes in the file associated with
  387.   the handle number.
  388.  
  389.  
  390. ■ Example
  391.  
  392.   #include <fpclib.h>
  393.  
  394.   main()
  395.   {
  396.      INT   handle;
  397.      UINT4 offset;
  398.  
  399.      Openfile( "file.dat", 2, &handle );
  400.      printf( "Total bytes in file.dat = %u ", GetFileSize( handle ) );
  401.   }
  402.  
  403.   In this example the printf statement will display the total number
  404.   of bytes in the file "file.dat".
  405. ..page
  406. ..head03AGetNDrvs
  407. ■ Description
  408.  
  409.   Report the number of disk drives.
  410.  
  411.  
  412. ■ Summary
  413.  
  414.   INT2 FPENTRY GetNDrvs( VOID );
  415.  
  416.  
  417. ■ Remarks
  418.  
  419.   GetNDrvs reports the total number of diskette and fixed disk drives
  420.   installed for the current system.
  421.  
  422.  
  423. ■ Example
  424.  
  425.   #include <fpclib.h>
  426.  
  427.   main()
  428.   {
  429.      printf("Number of disk drives installed = %u ", GetNDrvs() );
  430.   }
  431.  
  432.   In this example the printf statement will display the numeric value
  433.   for the current number of disk drives currently installed on the
  434.   system.
  435. ..page
  436. ..head03AOpenFile
  437. ■ Description
  438.  
  439.   Open the file given in the string passed.
  440.  
  441.  
  442. ■ Summary
  443.  
  444.   VOID FPENTRY OpenFile( CHAR *Path, INT2 Attr, INT2 *Handle );
  445.  
  446.   Path        the path and filename of the file to open.
  447.  
  448.   Attr        the type of access to be allowed for this file.
  449.  
  450.                  Access Code Description
  451.                  ─────────── ──────────────────
  452.                       0      Read Only access
  453.                       1      Write Only access
  454.                       2      Read/write access
  455.  
  456.   Handle      returns an integer that represents the file handle that
  457.               is associated with the file given in Path.  The file
  458.               handle is to be used when any operations on the file are
  459.               to take place.
  460.  
  461. ■ Remarks
  462.  
  463.   If an error occurred DosErrNo will contain one of the following
  464.   error codes.
  465.  
  466.   DosErrNo Description
  467.   ──────── ───────────────────
  468.      2     File not found
  469.      4     No handle available
  470.      5     access denied
  471.     12     invalid access code
  472.  
  473.  
  474. ■ See Also
  475.  
  476.   CreateFile
  477. ..page
  478. ■ Example
  479.  
  480.   #include <fpclib.h>
  481.  
  482.   main()
  483.   {
  484.      INT handle;
  485.  
  486.      OpenFile( "file.dat", 0, &handle );
  487.  
  488.   }
  489.  
  490.   On return from opening the file, if DosErrNo contains a zero, handle
  491.   will contain the integer of the file handle for the file 'File.dat'.
  492.   The file is opened for read only access.
  493. ..page
  494. ..head03AReadFile
  495. ■ Description
  496.  
  497.   Read a file or device for a specified number of bytes.
  498.  
  499.  
  500. ■ Summary
  501.  
  502.   VOID FPENTRY ReadFile( INT2    Handle,
  503.              INT2    NBytes,
  504.              CHAR  *Buffer,
  505.              UINT2 *RBytes );
  506.  
  507.   Handle      file handle associated with the appropriate file or
  508.               device for the read operation to act on.
  509.  
  510.   NBytes      number of bytes to read from the file or device.
  511.  
  512.   Buffer      buffer area to place the data read.
  513.  
  514.   RBytes      returns the number of bytes actually read from the file
  515.               or device.  If RBytes is zero then an attempt was made
  516.               to read from the end of a file.
  517.  
  518.  
  519. ■ Remarks
  520.  
  521.   If an error occurred DosErrNo will contain one of the following
  522.   error codes.
  523.  
  524.   DosErrNo Description
  525.   ──────── ───────────────────
  526.      5     Access denied
  527.      6     Invalid handle
  528.  
  529.  
  530. ■ Example
  531.  
  532.   #include <fpclib.h>
  533.  
  534.   main()
  535.   {
  536.      CHAR Buffer[128];
  537.      UINT handle,NBytes,RBytes;
  538.  
  539.      OpenFile( "file.dat", 0, &handle );
  540.      FSeek( handle, 0, 0 );
  541.      ReadFile( handle, 128, Buffer, &RBytes );
  542.   }
  543.  
  544.   Assuming no errors, 128 bytes will be read from the file and placed
  545.   into the variable Buffer.  On return from ReadFile the variable
  546.   RBytes will contain the actual number of bytes that were read from
  547.   the file.
  548. ..page
  549. ..head03AResetDisk
  550. ■ Description
  551.  
  552.   Resets the disk and flushes all file buffers.
  553.  
  554.  
  555. ■ Summary
  556.  
  557.   VOID FPENTRY ResetDisk( VOID );
  558.  
  559.  
  560. ■ Remarks
  561.  
  562.   This routine does not close any files.  To ensure that the length of
  563.   a file is recorded properly in the file directory you should first
  564.   close the file before using this routine.
  565. ..page
  566. ..head03AResetErrCodes
  567. ■ Description
  568.  
  569.   Resets global variables that indicate device errors to their initial
  570.   settings.
  571.  
  572.  
  573. ■ Summary
  574.  
  575.   VOID FPENTRY ResetErrCodes( VOID );
  576.  
  577.  
  578. ■ Remarks
  579.  
  580.   The following variables are set as followings:
  581.  
  582.      DosErrNo   =  0
  583.      CErrCode   =  0
  584.      CErrType   = -1
  585.      CErrDrive  = -1
  586.      CErrDevice = ''
  587.  
  588. ■ See Also
  589.  
  590.   SetInt24
  591. ..page
  592. ..head03ARestInt24
  593. ■ Description
  594.  
  595.   Uninstalls or restores the programs critical interrupt error
  596.   handler.
  597.  
  598.  
  599. ■ Summary
  600.  
  601.   VOID FPENTRY RestInt24( VOID );
  602.  
  603.  
  604. ■ See Also
  605.  
  606.   SetInt24
  607.  
  608.  
  609. ■ Remarks
  610.  
  611.   This procedure will uninstall the critical interrupt error handler
  612.   that was installed with the SetInt24 procedure.  This procedure uses
  613.   the SegInt24 and OfsInt24 variables to restore the interrupt handler
  614.   in use before the interrupt handler was installed.
  615. ..page
  616. ..head03ASetDTA
  617. ■ Description
  618.  
  619.   Set the file attribute for the file specified.
  620.  
  621.  
  622. ■ Summary
  623.  
  624.   VOID FPENTRY SetDTA( UINT2 Segment, UINT2 Offset );
  625.  
  626.   Segment     segment address for the new DTA.
  627.  
  628.   Offset      offset within the segment for the new DTA.
  629.  
  630.  
  631. ■ Example
  632.  
  633.   #include <dos.h>
  634.   #include <fpclib.h>
  635.  
  636.   main()
  637.   {
  638.      CHAR Buffer[4096];
  639.  
  640.      SetDTA( FP_SEG( Buffer ), FP_OFF( Buffer ) );
  641.   }
  642.  
  643.   The new DTA will point to the data variable Buffer and all the
  644.   information associated with the Disk Transfer Area will be placed in
  645.   the data variable Buffer until the DTA address is changed.
  646. ..page
  647. ..head03ASetInt24
  648. ■ Description
  649.  
  650.   Initializes the critical error handler routine and its global
  651.   variables for use with your system.
  652.  
  653.  
  654. ■ Summary
  655.  
  656.   VOID FPENTRY SetInt24( VOID );
  657.  
  658.  
  659. ■ Remarks
  660.  
  661.   Only one call needs to be made to this routine for a program that
  662.   wants to use the critical error handler routine.  In the event of a
  663.   critical error, the variables DosErrNo, CErrCode, CErrType,
  664.   CErrDrive and CErrDevice are set to the appropiate values.  Refer to
  665.   the global variable section at the beginning of this chapter for a
  666.   description of each variable name.
  667.  
  668.   The following are the I/O error values that are set in the CErrCode
  669.   global variable.  These codes match the same codes DOS function 59h
  670.   (Get Extended Error Code) return.  Notice that all values are
  671.   hexadecimal.
  672.  
  673.   Error
  674.   Code        Description
  675.   ───── ──────────────────────────────-
  676.    13   Write-protect error
  677.    14   Unknown unit
  678.    15   Disk drive not ready
  679.    16   Unknown command
  680.    17   Data error (bad CRC)
  681.    18   A bad request structure length
  682.    19   Data seek error
  683.    1A   Unknown media type
  684.    1B   Disk sector not found
  685.    1C   Printer is out of paper
  686.    1D   Write fault
  687.    1E   Read fault
  688.    1F   General failure
  689.  
  690.  
  691. ■ See Also
  692.  
  693.   ResetErrCodes, RestInt24
  694. ..page
  695. ■ Example
  696.  
  697.   #include <fpclib.h>
  698.  
  699.   main()
  700.   {
  701.      INT handle;
  702.  
  703.      SetInt24();
  704.  
  705.      CreateFile( "a:file.dat", 0, &handle );
  706.  
  707.      if ( !DosErrNo ) {
  708.         printf( "DosErrNo   = %d\n", DosErrNo   );
  709.         printf( "CErrCode   = %d\n", CErrCode   );
  710.         printf( "CErrType   = %d\n", CErrType   );
  711.         printf( "CErrDrive  = %d\n", CErrDrive  );
  712.         printf( "CErrDevice = %d\n", CErrDevice );
  713.      }
  714.      else {
  715.         printf( "file opened ok..." );
  716.         CloseFile( handle );
  717.      }
  718.   }
  719.  
  720.   If this program was executed with the A: drive door open, a critical
  721.   error would occur.  On return from CreateFile the critical error
  722.   variables should be set to the following values:
  723.  
  724.      DosErrNo   = 3             Path not found
  725.      CErrCode   = 21            Disk drive not ready
  726.      CErrType   = 0             0=Block    1=Character
  727.      CErrDrive  = 0             Drive A=0, B=1, C=2, etc
  728.      CErrDevice = DISKETTE      Device name
  729. ..page
  730. ..head03AWriteFile
  731. ■ Description
  732.  
  733.   Write to a file or device for a specified number of bytes.
  734.  
  735.  
  736. ■ Summary
  737.  
  738.   VOID FPENTRY WriteFile( INT2     Handle,
  739.               INT2     NBytes,
  740.               CHAR    *Buffer,
  741.               UINT2 *WBytes );
  742.  
  743.   Handle      the file handle that is associated with the appropriate
  744.               file or device for the read operation to act on.
  745.  
  746.   NBytes      number of bytes to write to the file or device.
  747.  
  748.   Buffer      this is the data area that contains the data that is to
  749.               be written to the file or device.
  750.  
  751.   WBytes      returns the actual number of bytes that were written out
  752.               to the file or device.
  753.  
  754.  
  755. ■ Remarks
  756.  
  757.   DosErrNo will contain one of the following error codes when an error
  758.   occurs.
  759.  
  760.   DosErrNo    Description
  761.   ──────── ───────────────────
  762.      5     Access denied
  763.      6     Invalid handle
  764.     20     insufficent disk space
  765.  
  766.  
  767. ■ Example
  768.  
  769.   #include <fpclib.h>
  770.   main()
  771.   {
  772.      CHAR  Buffer[128];
  773.      INT   handle, WBytes;
  774.  
  775.      CreateFile( "file.dat", 2, &handle );
  776.      memset( Buffer, 'A', 128 );
  777.      WriteFile( handle, 128, Buffer, &WBytes );
  778.      CloseFile( handle );
  779.   }
  780.  
  781.   This example will create a file and write out 128 A's to the new
  782.   file.  WBytes on return should contain the value 128.
  783. ..page
  784. 
  785.