home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / flash-c1.zip / CH5_1.DOC < prev    next >
Text File  |  1990-02-11  |  19KB  |  788 lines

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