home *** CD-ROM | disk | FTP | other *** search
/ HomeWare 14 / HOMEWARE14.bin / prog / kfs.arj / KFS.DOC < prev    next >
Text File  |  1994-02-15  |  69KB  |  2,646 lines

  1.          
  2.  
  3.  
  4.  
  5.  
  6.  
  7.          
  8.          
  9.          
  10.          
  11.          
  12.          
  13.          
  14.          
  15.          
  16.          
  17.          
  18.          
  19.          
  20.                          KEYED FILE SYSTEM - User's Guide
  21.          
  22.                           Version 2.0 (DOS and OS/2 1.x)
  23.          
  24.          
  25.                        (c) 1993 APT Computer Solutions, Inc.
  26.          
  27.          
  28.          
  29.          
  30.  
  31.          
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                                          Table of Contents
  38.          
  39.          Introduction  1
  40.          
  41.          System Components and Requirements  2
  42.          System Requirements  2
  43.          Keyed File System Components  2
  44.          Keyed File System Restrictions  2
  45.          
  46.          Including KFS Routines in Your Program  4
  47.          
  48.          What Are Keyed Files  5
  49.          
  50.          Keyed File System Functions  7
  51.          
  52.          The File Information Structure  8
  53.          
  54.          Parameters to Keyed File System Functions 10
  55.          
  56.          Keyed File System Functions 11
  57.          KFS_Add 11
  58.          KFS_Close 13
  59.          KFS_Create 14
  60.          KFS_Delete 16
  61.          KFS_Open 18
  62.          KFS_Read 19
  63.          KFS_ReadFirst 20
  64.          KFS_ReadGen 21
  65.          KFS_ReadGenNumeric 23
  66.          KFS_ReadNext 25
  67.          KFS_Replace 27
  68.          Interdependencies of the KFS operations 29
  69.          
  70.          Special Processing 30
  71.          KFS_Small_PTR 30
  72.          KFS_Numeric_Key 30
  73.          KFS_Ignore_Case 31
  74.          
  75.          Programming Hints and Tips 32
  76.          
  77.          Data Recovery 34
  78.          
  79.          Appendix A - Keyed File System Return Codes 35
  80.          
  81.          Appendix B - File Recovery Example 37
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.                                  3
  97.          
  98.          
  99.          
  100.          
  101.          
  102.  
  103.  
  104.  
  105.  
  106.  
  107.          Introduction
  108.          
  109.          The Keyed File System is a set of routines that allow you to 
  110.          write programs in C to build and maintain databases on a PC that 
  111.          are logically organized by a user defined key. Records can be 
  112.          read or written directly using an alphabetic or numeric key. An 
  113.          alphabetic key can be a string consisting of any combination of 
  114.          ASCII characters up to 32,767 characters in length. You may also 
  115.          have 4 byte signed numeric keys contained in the normal Intel 
  116.          80x86 long integer format. Note that a database may have alpha-
  117.          betic keys or numeric keys but not both (however, see 
  118.          "Programming Hints & Tips" for hints about combining keys).
  119.          
  120.          The Keyed File System uses normal DOS and OS/2 functions to 
  121.          create and maintain its databases. Therefore, records may be of 
  122.          any length supported by the DOS or OS/2 operating systems and 
  123.          can be created using the FAT or HPFS (OS/2 only) file systems. 
  124.          Files may be created on floppy or hard disks, although, as might 
  125.          be expected, hard disk files will provide better performance. 
  126.          KFS databases may be moved or copied using normal DOS or OS/2 
  127.          commands (such as COPY) as long as both file components are 
  128.          moved together (see "Copying Files"). Additionally, databases 
  129.          built using the KFS functions on one operating system are com-
  130.          patible with databases built using the KFS functions on the 
  131.          other operating system. Thus, databases built by programs run-
  132.          ning under DOS may be subsequently used by programs running 
  133.          under OS/2.
  134.          
  135.          The Keyed File System supports most operations normally associ-
  136.          ated with keyed files:
  137.          
  138.          *    Direct reading and writing of records by key.
  139.          
  140.          *    Sequential reading of records in key sequence.
  141.          
  142.          *    Deleting of records by key.
  143.          
  144.          *    Reading records using a partial key.
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.                                  4
  167.          
  168.          
  169.          
  170.          
  171.          
  172.  
  173.  
  174.  
  175.  
  176.  
  177.          System Components and Requirements
  178.          
  179.          System Requirements
  180.          
  181.               The minimum system required to run programs that use the 
  182.          Keyed File System are:
  183.          
  184.          *    OS/2 1.2 or higher, or DOS 3.3 or higher.
  185.          
  186.          *    Approx. 180K of disk space including sample programs and 
  187.               utilities.
  188.               
  189.          *    Microsoft C compiler and libraries, version 6.0 (OS/2 and 
  190.               DOS) or 7.0 (DOS only).
  191.          
  192.          
  193.          Keyed File System Components
  194.          
  195.          KFS.H             - The header file for use in C programs that 
  196.                              want to use KFS functions.
  197.          
  198.          KFSMSC6O.LIB      - A lib used at linkedit time to include the 
  199.                              KFS functions when building OS/2 programs 
  200.                              written in Microsoft C Version 6.0.
  201.          
  202.          KFSMSC6D.LIB      - A lib used at linkedit time to include the 
  203.                              KFS functions when building DOS programs 
  204.                              written in Microsoft C Version 6.0.
  205.          
  206.          KFSMSC7.LIB       - A lib used at linkedit time to include the 
  207.                              KFS functions when building DOS programs 
  208.                              written in Microsoft C Version 7.0.
  209.          
  210.          KFSSAMP.C         - A sample program that builds a KFS database 
  211.                              from a sequential file and then uses most of 
  212.                              the functions available in KFS. 
  213.          
  214.          KFSSAMP.DAT       - The sequential input file to the KFSSAMP 
  215.                              program.
  216.          
  217.          KFSSAMP.MAK       - A sample make file for KFSSAMP.C. 
  218.          
  219.          
  220.          Keyed File System Restrictions
  221.          
  222.          The following restrictions apply to KFS databases:
  223.          
  224.          *    Databases must contain fixed length records.
  225.          
  226.          *    Each record must be at least 5 bytes in length.
  227.          
  228.          *    Numeric keys must be 4 bytes in length but alphabetic keys 
  229.               may be up to 32767 characters in length.
  230.          
  231.          *    Duplicate keys are not allowed (see "Programming Tips and 
  232.               Techniques").
  233.          
  234.          *    The path and file name specified during KFS_Create or 
  235.               KFS_Open for a KFS database cannot be longer than 63 bytes.
  236.          
  237.                                  5
  238.          
  239.          
  240.          
  241.          
  242.          
  243.  
  244.  
  245.  
  246.  
  247.  
  248.          *    Files cannot be created using KFS_Open, you must use 
  249.               KFS_Create to create a new file and KFS_Open after a file 
  250.               exists.
  251.          
  252.          *    Two databases with the same "base" name cannot exist in the 
  253.               same directory even if the file extensions are different. 
  254.               That is KFS databases with the base names of MYFILE.001 and 
  255.               MYFILE.002 cannot exist in the same directory, but the 
  256.               names MYFILE1.XXX and MYFILE2.XXX are OK. This is explained 
  257.               further in the section "What Are Keyed Files".
  258.          
  259.          *    You cannot name a KFS database using the extension of .PTR. 
  260.               Thus MYFILE.PTR is invalid. This is also explained in the 
  261.               "What Are Keyed Files" section.
  262.  
  263.          
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.                                  6
  309.          
  310.          
  311.          
  312.          
  313.          
  314.  
  315.  
  316.  
  317.  
  318.  
  319.          Including KFS Routines in Your Program
  320.          
  321.          To include the KFS routines in your C program requires three 
  322.          steps:
  323.          
  324.          1.   Include the KFS.H header file at the beginning of your 
  325.               program source. For example:
  326.                    #include <KFS.H>
  327.          
  328.          2.   Define any keyed files using the KFS_FILEINFO typedef. For 
  329.               example:
  330.                    KFS_FILEINFO keyedfile;
  331.          
  332.          3.   Include the appropriate KFS---.LIB file when linking your 
  333.               program. For example, to link a DOS program compiled with 
  334.               MS/C version 6.0 would be:
  335.                    LINK myprog,,,KFSMSC6D;
  336.          
  337.          For a complete example of a program using some KFS functions, 
  338.          look at the KFSSAMP.C file included with this package.
  339.          
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.                                  7
  380.          
  381.          
  382.          
  383.          
  384.          
  385.  
  386.  
  387.  
  388.  
  389.  
  390.          What Are Keyed Files
  391.          
  392.          Keyed File System databases are actually composed of two files, 
  393.          an index file and a data file. These two files work together to 
  394.          provide you with direct access of a record by key while keeping 
  395.          the records in a logical keyed sequence. The name of the data 
  396.          file is the same as the name of the database and is specified by 
  397.          the programmer when the KFS database is created (using the 
  398.          KFS_Create function). This may be any valid DOS or OS/2 file 
  399.          name. The index file is automatically given the same base name 
  400.          you specified for the database but with an extension of .PTR. 
  401.          For example, specifying a name of CUSTOMER.DAT for a database 
  402.          automatically causes the creation of an index file with the name 
  403.          of CUSTOMER.PTR. This leads to two restrictions in the Keyed 
  404.          File System:
  405.          
  406.          1)   You cannot name a database using an extension of .PTR.
  407.          
  408.          2)   You cannot have two databases in the same directory with 
  409.               the same base name since this would result in an attempt by 
  410.               KFS to create duplicate .PTR files. For example, MYFILE.001 
  411.               and MYFILE.002 would both result in KFS attempting to cre-
  412.               ate an index file named MYFILE.PTR.
  413.          
  414.          Because these two files work together they must remain physi-
  415.          cally in the same directory. Therefore, if the Keyed File System 
  416.          database is moved, both the data and index files must be moved 
  417.          together.
  418.          
  419.          The format and content of the index file is determined by the 
  420.          Keyed File System, while the format and content of the data file 
  421.          is determined by you when the database is created. When you 
  422.          create a Keyed File System database you must tell the Keyed File 
  423.          System how large each record in the database will be 
  424.          (KFS_recsize), where the key begins in the record (KFS_keypos), 
  425.          and how long the key is (KFS_keylen). Note that the Keyed File 
  426.          System only supports fixed length records (ie. each record in 
  427.          the database is the same length).
  428.          
  429.          The Keyed File System requires that databases are either created 
  430.          or opened before they are used, and that they are closed before 
  431.          the program terminates. With any file system, if a program ter-
  432.          minates abnormally without closing files (such as a system crash 
  433.          because of a power failure) and file buffering is being used 
  434.          (such as is available with HPFS or DOS lazy writing), data that 
  435.          has been "written" by the program but waiting in an output 
  436.          buffer to be physically written to disk may be lost. The Keyed 
  437.          File System makes every attempt to minimize the impact of such a 
  438.          system failure, but since it does utilize two files working 
  439.          together, there are rare times this loss of data may result in 
  440.          the database becoming unusable. Thus special care should be 
  441.          taken by your application user to properly back up the data and 
  442.          index files making up each KFS database. Also, see the section 
  443.          on "Data Recovery" for an example of how to recover a damaged 
  444.          KFS database.
  445.          
  446.  
  447.  
  448.  
  449.  
  450.                                  8
  451.          
  452.          
  453.          
  454.          
  455.          
  456.  
  457.  
  458.  
  459.  
  460.  
  461.          Keyed File System Functions
  462.          
  463.          The Keyed File System is a set of 11 routines that provide you 
  464.          with the basic functions required for keyed record access on the 
  465.          PC. These functions are:
  466.          
  467.          KFS_Add
  468.               Adds a new record to a KFS database. The key of the record 
  469.               being added must not already exist in the database.
  470.          
  471.          KFS_Close
  472.               Close an open KFS database.
  473.          
  474.          KFS_Create 
  475.               Create and open a new KFS database. The database must not 
  476.               already exist.
  477.          
  478.          KFS_Delete
  479.               Deletes the record from a KFS database that has the key 
  480.               specified.
  481.          
  482.          KFS_Open
  483.               Open an existing KFS database.
  484.          
  485.          KFS_Read
  486.               Read a record from an open KFS database by key.
  487.          
  488.          KFS_ReadFirst
  489.               Reads the first logical record in a KFS database.
  490.          
  491.          KFS_ReadGen
  492.               For databases with alphabetic keys only. Read a record from 
  493.               an open KFS database using a partial key. If no records 
  494.               match the partial key, the next record in sequence after 
  495.               the key requested is returned in the user area and a code 
  496.               of KFS_Key_Not_Found is returned in KFS_rc.
  497.          
  498.          KFS_ReadGenNumeric 
  499.               For databases with numeric keys only. Read a record from an 
  500.               open KFS database. If the requested key is not found, the 
  501.               next record in sequence after the key requested is returned 
  502.               in the user area and a return code of KFS_Key_Not_Found is 
  503.               returned in KFS_rc.
  504.          
  505.          KFS_ReadNext
  506.               Reads the record in a KFS database that is the next record 
  507.               after the key specified.
  508.          
  509.          KFS_Replace
  510.               Replaces the record in a KFS database that has the same key 
  511.               as the one specified. A record with this key must exist in 
  512.               the database.
  513.          
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.                                  9
  522.          
  523.          
  524.          
  525.          
  526.          
  527.  
  528.  
  529.  
  530.  
  531.  
  532.          The File Information Structure
  533.          
  534.          In order to use the Keyed File System routines, you must provide 
  535.          the KFS functions with a File Information Structure for each 
  536.          database you are going to use in your program. This is a control 
  537.          structure (similar to the C "FILE" typedef) that includes such 
  538.          information about the database as the database name, key length, 
  539.          location of the key within the record, and a return code field 
  540.          for checking the result of KFS operations, as well as control 
  541.          fields used by the KFS functions themselves. Once the database 
  542.          is opened, this structure should not be modified by the appli-
  543.          cation since this may damage the control information used by the 
  544.          KFS functions and the integrity of the database may be compro-
  545.          mised. There is a C typedef named KFS_FILEINFO for this 
  546.          structure defined in the KFS.H header file provided with the 
  547.          system. Also present in this header file are the C prototypes 
  548.          for the KFS functions and the definitions of the KFS return 
  549.          codes. 
  550.          
  551.          To create a KFS database (using the KFS_Create operation), you 
  552.          must provide several important pieces of information about the 
  553.          database. This is done by placing the appropriate values in the 
  554.          following fields in the File Information Structure defined for 
  555.          the file:
  556.          
  557.               KFS_filename
  558.                    Required for KFS_Create or KFS_Open, this field must 
  559.                    contain the name of the database being created or 
  560.                    opened. This is a DOS or OS/2 file specification that 
  561.                    includes drive, path, and database name. As mentioned 
  562.                    before the Keyed File System actually creates (or 
  563.                    opens) two files for any KFS database and if these 
  564.                    files are moved, both must be move to the same loca-
  565.                    tion (ie. subdirectory or floppy disk). The first file 
  566.                    will have the name you specify here, while the second 
  567.                    file will have the same base name as the database you 
  568.                    specified but a qualifier of .PTR.    
  569.          
  570.               KFS_keypos
  571.                    KFS_Create only. This is the position of the key 
  572.                    within the record. This position is relative to 0. 
  573.                    That is, if the key begins in the first position of 
  574.                    the record, 0 is placed here by the programmer. If the 
  575.                    key begins in the 5th position of the record, 4 is put 
  576.                    here. 
  577.          
  578.               KFS_keylen
  579.                    KFS_Create only. This is the length of the key in the 
  580.                    record. For example, if the key went from position 5 
  581.                    through position 10 (ie. 6 characters long) in the 
  582.                    data record, 6 would be placed here. For numeric keys, 
  583.                    this field is ignored.
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                 10
  592.          
  593.          
  594.          
  595.          
  596.          
  597.  
  598.  
  599.  
  600.  
  601.  
  602.               KFS_recsize
  603.                    KFS_Create only. Place the total size of each data 
  604.                    record, including the key in this field. 
  605.          
  606.               KFS_flags
  607.                    KFS_Create only. These flags specify any special pro-
  608.                    cessing required for the database. The options 
  609.                    available to you are normal pointer file, small 
  610.                    pointer file, numeric keys, and ignore case. These 
  611.                    options are discussed further in the section  "Special
  612.                    Processing".   
  613.          
  614.          Once a KFS database is created, it may be subsequently used by 
  615.          simply specifying the name of the database in the KFS_filename 
  616.          field of the File Information structure and using KFS_Open to 
  617.          open the database. The remaining information about the database 
  618.          (ie. KFS_keypos, KFS_keylen, KFS_recsize, and KFS_flags) is 
  619.          stored with the database when it is created. 
  620.          
  621.          Upon the completion of a KFS operation, the success or failure 
  622.          of the operation is determined by checking the return code pro-
  623.          vided in the database's KFS_FILEINFO field KFS_rc. The valid 
  624.          return codes are defined in the KFS.H header file and are docu-
  625.          mented in Appendix A of this User's Guide.
  626.          
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.                                 11
  663.          
  664.          
  665.          
  666.          
  667.          
  668.  
  669.  
  670.  
  671.  
  672.  
  673.          Parameters to Keyed File System Functions
  674.          
  675.          The are 11 application interfaces that can be called to perform 
  676.          operations on databases with the Keyed File System. These 
  677.          operations require 1, 2, or 3 parameters depending on the func-
  678.          tion desired.
  679.          
  680.          The first parameter to all of the KFS functions is always the 
  681.          address of the KFS File Information structure (KFS_FILEINFO) for 
  682.          the desired database. As mentioned before, once a database is 
  683.          created or opened this structure should not be changed by the 
  684.          programmer since it is used by the database system to keep track 
  685.          of current information about the database. It is also used to 
  686.          provide feedback to the programmer about the requested opera-
  687.          tion.
  688.          
  689.          The second parameter is necessary for the functions that will be 
  690.          reading data from or writing data to a KFS database. This 
  691.          parameter is the address of an area large enough to contain a 
  692.          record from the database (that is, at least KFS_recsize in 
  693.          length). When a key is required by a specific KFS operation, the 
  694.          system expects the key to be in this area at the same relative 
  695.          position, and with the same length, as the key in a record in 
  696.          the database. For example, to read a record with the key "ABCDE" 
  697.          for a database whose KFS_keypos = 3, KFS_keylen = 5, and 
  698.          KFS_recsize = 80 means that the second parameter would be the 
  699.          address of an area at least 80 bytes in length that contains 
  700.          "ABCDE" in the 4th, 5th, 6th, 7th, and 8th bytes (ie. 
  701.          ...ABCDE..). 
  702.          
  703.          The third parameter is only required on the KFS_ReadGen function 
  704.          and is the length of the portion of the key provided. This 
  705.          parameter is discussed further in the discussion of KFS_ReadGen. 
  706.          The following program segment illustrates how the above param-
  707.          eters would be specified for a typical KFS function call:
  708.          
  709.            #include <kfs.h>
  710.            KFS_FILEINFO file1;
  711.            char recarea[100];
  712.          
  713.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  714.            KFS_Open(&file1);
  715.            if (file1.KFS_rc != KFS_OK)
  716.               printf("Error opening file1\n");
  717.            strcpy(&recarea[file1.KFS_keypos], "A k");
  718.            KFS_ReadGen(&file1, (void *)recarea, 3);
  719.          
  720.          For further examples, see the description of the individual KFS 
  721.          functions and the KFSSAMP.C program provided as part of this 
  722.          package.
  723.          
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.                                 12
  734.          
  735.          
  736.          
  737.          
  738.          
  739.  
  740.  
  741.  
  742.  
  743.  
  744.          Keyed File System Functions
  745.          
  746.          In the description of the following functions the KFS_File_Error 
  747.          is a general error caused by an "unknown error" returned from 
  748.          the operating system and is possible for all functions.
  749.          
  750.          KFS_Add(fs, area)
  751.               Add a data record to a database. 
  752.          
  753.          Parameters
  754.               KFS_FILEINFO *fs
  755.                    A pointer to a KFS file structure.
  756.          
  757.               void *area
  758.                    A pointer to a data area containing the record to be 
  759.                    added. The key to be added must be at KFS_keypos of 
  760.                    this area before the operation is issued.
  761.           
  762.          
  763.          
  764.          Description
  765.               Add a record to the database. Another record with this key 
  766.               must not already exist in the database.
  767.          
  768.          
  769.          Required Fields
  770.               KFS_filename
  771.                    Contains the name of an open database where the record 
  772.                    is to be added.
  773.          
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.                                 13
  805.          
  806.          
  807.          
  808.          
  809.          
  810.  
  811.  
  812.  
  813.  
  814.  
  815.          Example
  816.            /* Add a record to a KFS file                              */
  817.            #include <kfs.h>
  818.            KFS_FILEINFO file1;
  819.            typedef struct m {
  820.               int f1;
  821.               int f2;
  822.               char mykey[7];
  823.               char filler[89];
  824.            } MYSTRUCT;
  825.            MYSTRUCT inarea;
  826.          
  827.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  828.            KFS_Open(&file1);
  829.            if (file1.KFS_rc != KFS_OK)
  830.               printf("Error opening file1\n");
  831.            strcpy(&inarea.mykey, "Newkey");
  832.            inarea.f1 = 0;    /* Just some data in record */ 
  833.            inarea.f2 = 15;   /* Just some data in record */
  834.            KFS_Add(&file1, (void *)&inarea);
  835.            switch (file1.KFS_rc) {
  836.               case KFS_Key_Already_Exists :
  837.                  printf("Key already in file");
  838.               case KFS_OK:
  839.                  break;
  840.               default:
  841.                  printf("Error adding record");
  842.            }
  843.          
  844.          
  845.          Possible KFS_rc Values
  846.               KFS_OK
  847.                    The record was added successfully.
  848.          
  849.               KFS_Key_Already_Exists
  850.                    A record with the same key as the record being added 
  851.                    already exists in the database. The operation is 
  852.                    ignored.
  853.          
  854.               KFS_File_Error
  855.                    An unknown error occurred when attempting to add a 
  856.                    record to a KFS database.
  857.          
  858.               KFS_No_Space_On_Disk
  859.                    There was not enough space on the disk containing the 
  860.                    KFS file to contain another data and pointer record.
  861.          
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.                                 14
  876.          
  877.          
  878.          
  879.          
  880.          
  881.  
  882.  
  883.  
  884.  
  885.  
  886.          KFS_Close(fs)
  887.               Close a database.
  888.          
  889.          
  890.          Parameters
  891.               KFS_FILEINFO *fs
  892.                    A pointer to a KFS file structure.
  893.          
  894.          
  895.          Description
  896.               Close a database. The database must then be opened before 
  897.               further processing can occur.
  898.          
  899.          
  900.          Required Fields
  901.               KFS_filename
  902.                    Contains the name of an opened database.
  903.          
  904.          
  905.          Example
  906.            /* Close a KFS file                                         */
  907.            #include <kfs.h>
  908.            KFS_FILEINFO file1;
  909.            .
  910.            .
  911.            KFS_Close(&file1);
  912.            
  913.          
  914.          Possible KFS_rc Values
  915.               KFS_OK
  916.                    The database was closed successfully.
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.                                 15
  946.          
  947.          
  948.          
  949.          
  950.          
  951.  
  952.  
  953.  
  954.  
  955.  
  956.          KFS_Create(fs)
  957.               Create a new, empty database and open it.
  958.          
  959.          Parameters
  960.               KFS_FILEINFO *fs
  961.                    A pointer to a KFS file structure.
  962.          
  963.          
  964.          Description
  965.               Create an empty database from the information supplied in 
  966.               the KFS_FILEINFO structure. At the conclusion of a suc-
  967.               cessful operation the database is opened and may be used 
  968.               without the need to call the KFS_Open function. If a data-
  969.               base already exists with this name, an error is returned.
  970.          
  971.          
  972.          Required Fields
  973.               KFS_keypos
  974.                    Contains the position of the key in the records of the 
  975.                    new database. This position is relative to 0.
  976.          
  977.               KFS_keylen
  978.                    Contains the length of the key. 
  979.          
  980.               KFS_recsize
  981.                    Contains the size of each of the keyed records to be 
  982.                    built.
  983.          
  984.               KFS_filename
  985.                    Contains the name of the database to be created. If 
  986.                    the name has a qualifier, it cannot be PTR. Also, the 
  987.                    base portion of the name cannot be the same as any 
  988.                    other database even if the qualifiers are unique.
  989.          
  990.               KFS_flags
  991.                    Specifies some additional information about the data-
  992.                    base (See the "Special Processing" section for more 
  993.                    discussion of these options). The valid settings for 
  994.                    this field are:
  995.          
  996.                         KFS_Normal_PTR
  997.                              The normal pointer file organization is 
  998.                              used. This results in the initial allocation 
  999.                              of the .PTR file of about 8K but results in 
  1000.                              good performance for large databases.
  1001.          
  1002.                         KFS_Small_PTR
  1003.                              The organization of the pointer file will be 
  1004.                              changed to save space on the initial allo-
  1005.                              cation of the database. This option should 
  1006.                              be specified only when the database will be 
  1007.                              a small one since larger databases having 
  1008.                              this option are slower than for databases 
  1009.                              created with KFS_Normal_PTR.     
  1010.          
  1011.                         KFS_Numeric_Keys
  1012.                              The keys in the database will be numeric 
  1013.                              keys stored in the Intel long integer for-
  1014.                              mat. This option also implies a small 
  1015.                              pointer file. 
  1016.                                 16
  1017.          
  1018.          
  1019.          
  1020.          
  1021.          
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.          
  1028.                         KFS_Ignore_Case
  1029.                              The case of the keys in the database is 
  1030.                              ignored. That is, a key of "ABCDE" and "ab-
  1031.                              cde" will be treated as the same key.
  1032.          
  1033.          Example
  1034.            /* Create and open a KFS file with alphabetic keys starting */
  1035.            /* in the 5th position of the record and 7 bytes long       */ 
  1036.            #include <kfs.h>
  1037.            KFS_FILEINFO file1;
  1038.            char recarea[100];
  1039.          
  1040.            file1.KFS_flags = KFS_Normal_PTR;
  1041.            file1.KFS_keypos = 4;
  1042.            file1.KFS_keylen = 7;
  1043.            file1.KFS_recsize = 100;
  1044.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1045.            KFS_Create(&file1);
  1046.            if (file1.KFS_rc != KFS_OK)
  1047.               printf("Error creating file1\n");
  1048.          
  1049.          
  1050.          Possible KFS_rc Values
  1051.               KFS_OK
  1052.                    The database was created successfully. 
  1053.          
  1054.               KFS_Keyed_File_Already_Exists
  1055.                    A database with this name already exists.
  1056.          
  1057.               KFS_Invalid_File_Name 
  1058.                    The file name and associated path name is longer than 
  1059.                    63 characters. 
  1060.          
  1061.               KFS_PTR_File_Open_Error
  1062.                    An unknown error occurred while attempting to open the 
  1063.                    PTR file associated with the database. This error can 
  1064.                    occur if there is not enough space on the disk to 
  1065.                    allocate the pointer file or if a .PTR file by this 
  1066.                    name already exists. 
  1067.          
  1068.               KFS_Data_File_Open_Error
  1069.                    An unknown error occurred while attempting to open the 
  1070.                    data file associated with the database.
  1071.          
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.                                 17
  1088.          
  1089.          
  1090.          
  1091.          
  1092.          
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.          KFS_Delete(fs, area)
  1099.               Delete a record from the database. 
  1100.          
  1101.          
  1102.          Parameters
  1103.               KFS_FILEINFO *fs
  1104.                    A pointer to a KFS file structure.
  1105.          
  1106.               void *area
  1107.                    A pointer to a data area containing the key of the 
  1108.                    record to be deleted. This key must be placed at 
  1109.                    KFS_keypos of this area before the operation is 
  1110.                    issued.
  1111.          
  1112.          Description
  1113.               Delete a record from the database.
  1114.          
  1115.          
  1116.          Required Fields
  1117.               KFS_filename
  1118.                    Contains the name of an opened database.
  1119.          
  1120.               area
  1121.                    The data area pointed to must contain the key of the 
  1122.                    record being deleted beginning in KFS_keypos of the 
  1123.                    area. 
  1124.          
  1125.          
  1126.          Example
  1127.            /* Add a record to a KFS file                              */
  1128.            #include <kfs.h>
  1129.            KFS_FILEINFO file1;
  1130.            typedef struct m {
  1131.               int f1;
  1132.               int f2;
  1133.               char mykey[7];
  1134.               char filler[89];
  1135.            } MYSTRUCT;
  1136.            MYSTRUCT inarea;
  1137.          
  1138.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1139.            KFS_Open(&file1);
  1140.            memset(&inarea.mykey, ' ', sizeof(inarea.mykey));
  1141.            strcpy(&inarea.mykey, "Dkey");
  1142.            KFS_Delete(&file1, (char *)&inarea);
  1143.            switch (file1.KFS_rc) {
  1144.               case KFS_OK:
  1145.                  break;
  1146.               case KFS_No_Space_On_Disk:
  1147.                  printf("Not enough space on disk to add record\n");
  1148.                  break;
  1149.               default:
  1150.                  printf("Error adding record\n");
  1151.          
  1152.            }
  1153.          
  1154.          Possible KFS_rc Values -
  1155.               KFS_OK
  1156.                    The record was deleted successfully.
  1157.          
  1158.                                 18
  1159.          
  1160.          
  1161.          
  1162.          
  1163.          
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.               KFS_Key_Not_Found
  1170.                    A record with the key specified was not found. The 
  1171.                    operation is ignored.
  1172.          
  1173.               KFS_No_Space_On_Disk
  1174.                    There is not enough space on the disk containing the 
  1175.                    KFS database to add a record.
  1176.          
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.                                 19
  1230.          
  1231.          
  1232.          
  1233.          
  1234.          
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.          KFS_Open(fs)
  1241.               Open an existing database. 
  1242.          
  1243.          Parameters
  1244.               KFS_FILEINFO *fs
  1245.                    A pointer to a KFS file structure.
  1246.          
  1247.          
  1248.          Description
  1249.               Open an existing database for processing. All databases 
  1250.               must be opened before any processing may be done on those 
  1251.               databases. 
  1252.          
  1253.          
  1254.          Required Fields
  1255.               KFS_filename
  1256.                    Contains the name of an existing database to be 
  1257.                    opened.
  1258.          
  1259.          
  1260.          Example
  1261.            /* Open a KFS file                                          */
  1262.            #include <kfs.h>
  1263.            KFS_FILEINFO file1;
  1264.            char recarea[100];
  1265.          
  1266.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1267.            KFS_Open(&file1);
  1268.            if (file1.KFS_rc != KFS_OK)
  1269.               printf("Error opening file1\n");
  1270.          
  1271.          
  1272.          Possible KFS_rc Values
  1273.               KFS_OK 
  1274.                    The database was opened successfully.
  1275.          
  1276.               KFS_Keyed_File_Does_Not_Exist 
  1277.                    The database does not exist.
  1278.          
  1279.               KFS_Invalid_File_Name
  1280.                    The database name and associated path name is longer 
  1281.                    than 63 characters. 
  1282.          
  1283.               KFS_PTR_File_Open_Error
  1284.                    An unknown error occurred while attempting to open the 
  1285.                    PTR file associated with the database. 
  1286.          
  1287.               KFS_Data_File_Open_Error
  1288.                    An unknown error occurred while attempting to open the 
  1289.                    data file associated with the database. 
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.                                 20
  1300.          
  1301.          
  1302.          
  1303.          
  1304.          
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.          KFS_Read(fs, area)
  1311.               Read a record by key from the database. 
  1312.          
  1313.          
  1314.          Parameters
  1315.               KFS_FILEINFO *fs
  1316.                    A pointer to a KFS file structure.
  1317.          
  1318.               void *area
  1319.                    A pointer to a data area where the requested record 
  1320.                    will be read. The key to be read must be placed at 
  1321.                    KFS_keypos of this area before the operation is 
  1322.                    issued.
  1323.          
  1324.          
  1325.          Description
  1326.               Read a record by key from a database.
  1327.          
  1328.          
  1329.          Required Fields
  1330.               KFS_filename
  1331.                    Contains the name of an open database.
  1332.          
  1333.               area
  1334.                    The data area pointed to must contain the key of the 
  1335.                    record being read beginning at position KFS_keypos. 
  1336.          
  1337.          
  1338.          Example
  1339.            /* Read a KFS file by key (keypos=4, keylen=7)              */
  1340.            #include <kfs.h>
  1341.            KFS_FILEINFO file1;
  1342.            char recarea[100];
  1343.          
  1344.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1345.            KFS_Open(&file1);
  1346.            if (file1.KFS_rc != KFS_OK)
  1347.               printf("Error opening file1\n");
  1348.            memset(recarea, ' ', sizeof(recarea));
  1349.            /* Note - we kept the terminating NULL as part of the key   */
  1350.            strcpy(&recarea[file1.KFS_keypos], "A key");
  1351.            KFS_Read(&file1, (void *)recarea);
  1352.            if (file1.KFS_rc != KFS_OK)
  1353.               printf("Error reading keyed record from file1\n");
  1354.          
  1355.          
  1356.          Possible KFS_rc Values
  1357.               KFS_OK
  1358.                    The record was read successfully.
  1359.          
  1360.               KFS_Key_Not_Found
  1361.                    A record with the key specified was not found. The 
  1362.                    operation is ignored.
  1363.          
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.                                 21
  1371.          
  1372.          
  1373.          
  1374.          
  1375.          
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.          KFS_ReadFirst(fs, area)
  1382.               Read the first record in keyed sequence in the database. 
  1383.          
  1384.          
  1385.          Parameters
  1386.               KFS_FILEINFO *fs 
  1387.                    A pointer to a KFS file structure.
  1388.          
  1389.               void *area
  1390.                    A pointer to a data area where the first record in the 
  1391.                    KFS database will be read.
  1392.          
  1393.          
  1394.          Description
  1395.               Read the first record from a database. The record with the 
  1396.               lowest key will be read and placed in the data area. 
  1397.          
  1398.          
  1399.          Required Fields
  1400.               KFS_filename
  1401.                    Contains the name of an open database.
  1402.          
  1403.          
  1404.          Example
  1405.            /* Read the all of the records sequentially from a file    */
  1406.            #include <kfs.h>
  1407.            KFS_FILEINFO file1;
  1408.            char recarea[100];
  1409.            
  1410.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1411.            KFS_Open(&file1);
  1412.            if (file1.KFS_rc != KFS_OK)
  1413.               printf("Error opening file1\n");
  1414.            KFS_ReadFirst(&file1, recarea);
  1415.            if (file1.KFS_rc != KFS_OK) printf("Error");
  1416.          
  1417.          
  1418.          Possible KFS_rc Values -
  1419.               KFS_OK
  1420.                    The record was read successfully.
  1421.          
  1422.               KFS_Keyed_File_Empty
  1423.                    No records were found in the database. The operation 
  1424.                    is ignored.
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.                                 22
  1441.          
  1442.          
  1443.          
  1444.          
  1445.          
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.          KFS_ReadGen(fs, area, length)
  1452.               Read a record using a partial key. 
  1453.          
  1454.          Parameters
  1455.               KFS_FILEINFO *fs
  1456.                    A pointer to a KFS file structure.
  1457.          
  1458.               void *area
  1459.                    A pointer to a data area where the requested record 
  1460.                    will be read. The partial key to be used must be 
  1461.                    placed at KFS_keypos of this area before the operation 
  1462.                    is issued.
  1463.          
  1464.               int length
  1465.                    The length of the partial key at KFS_keypos. If the 
  1466.                    length specified is 0, the first record in the data-
  1467.                    base is read.This length must be less than or equal to 
  1468.                    KFS_keylen.
  1469.          
  1470.          Description
  1471.               Read the first record in the database whose first portion 
  1472.               matches that of the partial key supplied. If no record 
  1473.               matches the partial key, the next logical record in the 
  1474.               database is returned.
  1475.          
  1476.          
  1477.          Required Fields
  1478.               KFS_filename
  1479.                    Must contain the name of an open database.
  1480.          
  1481.               area
  1482.                    The data area pointed to must contain the key of the 
  1483.                    record being read. 
  1484.          
  1485.          
  1486.          Example
  1487.            /* Read a KFS file by partial key (keypos=4, keylen=7)     */
  1488.            #include <kfs.h>
  1489.            KFS_FILEINFO file1;
  1490.            char recarea[100];
  1491.          
  1492.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1493.            KFS_Open(&file1);
  1494.            if (file1.KFS_rc != KFS_OK)
  1495.               printf("Error opening file1\n");
  1496.            strcpy(&recarea[file1.KFS_keypos], "A k");
  1497.            KFS_ReadGen(&file1, (void *)recarea, 3);
  1498.            if (file1.KFS_rc == KFS_Key_Not_Found)
  1499.               printf("We had no key match but got the next key\n");
  1500.            else
  1501.               if (file1.KFS_rc == KFS_OK)
  1502.                  printf("We got a record with a key starting with 'A 
  1503.          k'");
  1504.          
  1505.          Possible KFS_rc Values -
  1506.               KFS_OK
  1507.                    The partial key matched an existing record and this 
  1508.                    record was read successfully.
  1509.          
  1510.               KFS_Key_Not_Found
  1511.                                 23
  1512.          
  1513.          
  1514.          
  1515.          
  1516.          
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.                    No record with a key that matched the partial key 
  1523.                    specified was found. The next logical record in the 
  1524.                    database is returned.
  1525.          
  1526.               KFS_EOF
  1527.                    The partial key requested could not be found and the 
  1528.                    next position in the database was end of file.
  1529.          
  1530.               KFS_Key_Length_Invalid
  1531.                    A length greater than KFS_keylen was supplied in the 
  1532.                    parameter list.
  1533.          
  1534.               KFS_Invalid_Request
  1535.                    A KFS_ReadGen operation was attempted on a database 
  1536.                    with numeric keys.
  1537.          
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.                                 24
  1583.          
  1584.          
  1585.          
  1586.          
  1587.          
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.          KFS_ReadGenNumeric(fs, area)
  1594.               Read a numeric record, return the next record if not found. 
  1595.          
  1596.          
  1597.          Parameters -
  1598.               KFS_FILEINFO *fs 
  1599.                    A pointer to a KFS file structure.
  1600.          
  1601.               void *area
  1602.                    A pointer to a data area where the requested record 
  1603.                    will be read. A numeric key must be placed in 
  1604.                    KFS_keypos of this area prior to performing the 
  1605.                    operation.
  1606.           
  1607.          
  1608.          Description
  1609.               If a record in the database matches the key specified it is 
  1610.               read and placed in the data area. KFS_OK is then returned. 
  1611.               If no record matches the numeric key, then the next record 
  1612.               in the database is returned with a return code of 
  1613.               KFS_Key_Not_Found. 
  1614.          
  1615.          
  1616.          Required Fields
  1617.               KFS_filename
  1618.                    Contains the name of an open database.
  1619.          
  1620.               area
  1621.                    The data area pointed to must contain a numeric key at 
  1622.                    KFS_keypos. 
  1623.          
  1624.          
  1625.          Example
  1626.            /* Read a KFS file by numeric key (keypos=4)               */
  1627.            #include <kfs.h>
  1628.            KFS_FILEINFO file1;
  1629.            typedef struct m {
  1630.               int f1;
  1631.               int f2;
  1632.               long mykey;
  1633.               char filler[92];
  1634.            } MYSTRUCT;
  1635.            MYSTRUCT inarea;
  1636.          
  1637.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1638.            KFS_Open(&file1);
  1639.            if (file1.KFS_rc != KFS_OK)
  1640.               printf("Error opening file1\n");
  1641.            inarea.mykey = 1000;
  1642.            KFS_ReadGenNumeric(&file1, (void *)inarea);
  1643.            if (file1.KFS_rc == KFS_Key_Not_Found)
  1644.               printf("There was no key 1000 but got the next key\n");
  1645.          
  1646.            else
  1647.               if (file1.KFS_rc == KFS_OK)
  1648.                  printf("We got the record with key 1000");
  1649.          
  1650.          Possible KFS_rc Values
  1651.               KFS_OK
  1652.                    The record was read successfully.
  1653.                                 25
  1654.          
  1655.          
  1656.          
  1657.          
  1658.          
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.          
  1665.               KFS_Key_Not_Found
  1666.                    No record with a key that matched the key specified 
  1667.                    was found. The next logical record in the database is 
  1668.                    returned.
  1669.          
  1670.               KFS_EOF
  1671.                    The partial key requested could not be found and the 
  1672.                    next position in the database was at end of file.
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.                                 26
  1724.          
  1725.          
  1726.          
  1727.          
  1728.          
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.          KFS_ReadNext(fs, area)
  1735.               Read the next record in keyed sequence in the database. 
  1736.          
  1737.          
  1738.          Parameters
  1739.               KFS_FILEINFO *fs
  1740.                    A pointer to a KFS file structure.
  1741.          
  1742.               void *area
  1743.                    A pointer to a data area where the requested record 
  1744.                    will be read. The key placed at KFS_keypos of this 
  1745.                    area must be the key of the record before the record 
  1746.                    desired. 
  1747.          
  1748.          
  1749.          Description
  1750.               Read the next logical record from a database. The record 
  1751.               with the next highest key after the key specified in the 
  1752.               data area will be read. The user must provide the key of 
  1753.               the previous record in KFS_keypos of area. This allows the 
  1754.               user to read all records in a database with a succession of 
  1755.               KFS_ReadNext functions. 
  1756.          
  1757.          
  1758.          Required Fields
  1759.               KFS_filename
  1760.                    Contains the name of an open database.
  1761.          
  1762.               area
  1763.                    Contains the key of the record previous to the one to 
  1764.                    be read. 
  1765.           
  1766.          
  1767.          Example
  1768.            /* Read the all of the records sequentially from a file    */
  1769.            #include <kfs.h>
  1770.            KFS_FILEINFO file1;
  1771.            typedef struct m {
  1772.               int f1;
  1773.               int f2;
  1774.               char mykey[7];
  1775.               char filler[89];
  1776.            } MYSTRUCT;
  1777.            MYSTRUCT inarea;
  1778.          
  1779.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1780.            KFS_Open(&file1);
  1781.            if (file1.KFS_rc != KFS_OK)
  1782.               printf("Error opening file1\n");
  1783.              KFS_ReadFirst(&file1, (void *)&inarea);
  1784.            while (file1.KFS_rc != KFS_EOF) {
  1785.               KFS_ReadNext(&file1, (void *)&inarea);
  1786.          
  1787.               if (file1.KFS_rc != KFS_OK) printf("Error");
  1788.            }
  1789.            KFS_Close(&file1);
  1790.          
  1791.          Possible KFS_rc Values
  1792.               KFS_OK
  1793.                    The record was read successfully.
  1794.                                 27
  1795.          
  1796.          
  1797.          
  1798.          
  1799.          
  1800.  
  1801.  
  1802.  
  1803.  
  1804.  
  1805.          
  1806.               KFS_EOF
  1807.                    There are no more records in the dataset. 
  1808.          
  1809.               KFS_Key_Not_Found
  1810.                    A record with the specified key did not exist in the 
  1811.                    database and no record is returned. (i.e. the previous 
  1812.                    record must be found before the "next" record can be 
  1813.                    returned)
  1814.          
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.                                 28
  1866.          
  1867.          
  1868.          
  1869.          
  1870.          
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.          KFS_Replace(fs, area)
  1877.               Replace the record with the specified key.  
  1878.          
  1879.          
  1880.          Parameters
  1881.               KFS_FILEINFO *fs
  1882.                    A pointer to a KFS file structure.
  1883.          
  1884.               void *area
  1885.                    A pointer to a data area containing the record that 
  1886.                    will replace the record with the specified key in the 
  1887.                    database. 
  1888.          
  1889.          
  1890.          Description
  1891.               Replace the record with the corresponding key in the data-
  1892.               base with the record in area. If the record does not exist 
  1893.               in the database, the operation is ignored and a 
  1894.               KFS_Key_Not_found is returned. No prior read of the record 
  1895.               being replaced must be done. 
  1896.          
  1897.          
  1898.          Required Fields
  1899.               KFS_filename
  1900.                    Contains the name of an open database.
  1901.          
  1902.               area
  1903.                    Contains the record that will replace the one in the 
  1904.                    database.
  1905.           
  1906.          
  1907.          Example
  1908.            /* Replace a record in a KFS file                          */
  1909.            #include <kfs.h>
  1910.            KFS_FILEINFO file1;
  1911.            typedef struct m {
  1912.               int f1;
  1913.               int f2;
  1914.               char mykey[7];
  1915.               char filler[89];
  1916.            } MYSTRUCT;
  1917.            MYSTRUCT inarea;
  1918.          
  1919.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1920.            KFS_Open(&file1);
  1921.            strcpy(&inarea.mykey, "Oldkey");
  1922.            /* Note - we would not have to read to replace             */
  1923.            KFS_Read(&file1, (void *)&inarea);
  1924.            inarea.f2 = 77;
  1925.            KFS_Replace(&file1, (void *)&inarea);
  1926.            switch (file1.KFS_rc) {
  1927.               case KFS_Key_Not_Found :
  1928.          
  1929.                  printf("Record was not in file");
  1930.               case KFS_OK:
  1931.                  break;
  1932.               default:
  1933.                  printf("Error replacing record");
  1934.            }
  1935.          
  1936.                                 29
  1937.          
  1938.          
  1939.          
  1940.          
  1941.          
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.          Possible KFS_rc Values -
  1948.               KFS_OK
  1949.                    The record was read successfully.
  1950.          
  1951.               KFS_Key_Not_Found
  1952.                    A record with the key specified was not found. The 
  1953.                    operation is ignored.
  1954.          
  1955.               KFS_File_Error
  1956.                    An unknown error occurred when attempting to replace 
  1957.                    the requested record.
  1958.          
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.                                 30
  2008.          
  2009.          
  2010.          
  2011.          
  2012.          
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.          Interdependencies of the KFS operations
  2019.          
  2020.          Except for the requirements for opening databases first and 
  2021.          closing databases last, there is no specific dependencies 
  2022.          between KFS operations. That is, there is no requirement to call 
  2023.          a specific function before another function can be called. For 
  2024.          example, it is not necessary to read a specific record before 
  2025.          replacing it with KFS_Replace. The same is true if you want to 
  2026.          delete a record, it is not necessary to read it first. Simi-
  2027.          larly, you can issue a KFS_ReadNext after any other operation, 
  2028.          as long as the key of an existing record is present in the data 
  2029.          area so that KFS_ReadNext can read the record with the next 
  2030.          highest key.
  2031.          
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.                                 31
  2079.          
  2080.          
  2081.          
  2082.          
  2083.          
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.          Special Processing
  2090.          
  2091.          There are a few special options that may be chosen when creating 
  2092.          a database with the Keyed File System that allow for special 
  2093.          uses of databases. These options are enabled by setting certain 
  2094.          bits in the KFS_flags field of the File Information Structure. 
  2095.          If none of the options are desired, the flags field should be 
  2096.          set to KFS_Normal_PTR. Normally, databases are relatively large 
  2097.          databases (such as customer record databases) with keys that 
  2098.          contain primarily letters (people's names, for example) and the 
  2099.          Keyed File System was designed to handle these databases most 
  2100.          efficiently. Some assumptions are made about the number and type 
  2101.          of keys that will exist in the database when it is created and 
  2102.          results in creating an initial .PTR file of about 8K bytes. 
  2103.          Because of this initial allocation, the .PTR file is normally 
  2104.          slow to grow. However, for some applications, the assumptions 
  2105.          made by the Keyed File System may not be correct. Three options 
  2106.          are provided to enable the programmer to select a more efficient 
  2107.          initial .PTR allocation or to utilize various types of keys. 
  2108.          
  2109.          
  2110.          KFS_Small_PTR
  2111.           
  2112.          For applications that need relatively small databases (up to a 
  2113.          few hundred records), the KFS_Small_PTR option provides a way to 
  2114.          greatly reduce the initial size of the .PTR file from 8K to a 
  2115.          few hundred bytes. However, using this option will result in 
  2116.          slower execution speed if the database does grow large. Note 
  2117.          that this does not prohibit the database from becoming large, 
  2118.          just that performance is slower should it do so.
  2119.          
  2120.          The option is enabled by setting the KFS_flags field to 
  2121.          KFS_Small_PTR. In C this could be done by the following code :
  2122.          
  2123.            #include <kfs.h>
  2124.            KFS_FILEINFO file1;
  2125.            file1.KFS_flags = KFS_Small_PTR;
  2126.          
  2127.          
  2128.          KFS_Numeric_Key
  2129.          
  2130.          For applications whose keys are all numbers, it would be more 
  2131.          efficient of these numbers could be stored in the normal way 
  2132.          that the Intel 80x86 stores numbers. That is, in byte reversed 
  2133.          binary form (ie. short, int, or long in C terminology). The 
  2134.          Keyed File System provides the KFS_Numeric_Key option that 
  2135.          allows the key to be stored in the 4 byte Intel integer format 
  2136.          (ie. C's "long int"). Using this option will cause the system to 
  2137.          assume that KFS_keypos indicates the beginning of a 4 byte key 
  2138.          that is a number stored in integer form. KFS_keylen is ignored 
  2139.          when this option is specified. 
  2140.            
  2141.          
  2142.          The option is enabled by setting the KFS_flags field to 
  2143.          KFS_Numeric_Key. In C this could be done by the following code :
  2144.          
  2145.            #include <kfs.h>
  2146.            KFS_FILEINFO file1;
  2147.            file1.KFS_flags = KFS_Numeric_Key;
  2148.          
  2149.                                 32
  2150.          
  2151.          
  2152.          
  2153.          
  2154.          
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.          
  2161.          KFS_Ignore_Case
  2162.          
  2163.          Normally, databases created with alphabetic keys are sensitive 
  2164.          to the case of the keys. That is, keys "ABCDE" and "abcde" 
  2165.          indicate the keys of two different records. However, setting 
  2166.          this option allows case to be ignored for databases that have 
  2167.          alphabetic keys. Then a database created with this option would 
  2168.          treat the keys "ABCDE" and "abcde" as the key to the same 
  2169.          record.
  2170.          
  2171.          The option can be combined with the KFS_Normal_PTR or 
  2172.          KFS_Small_PTR options and is enabled by setting the KFS_flags 
  2173.          field to KFS_Ignore_Case. In C this could be done by the fol-
  2174.          lowing code :
  2175.          
  2176.            #include <kfs.h>
  2177.            KFS_FILEINFO file1;
  2178.            file1.KFS_flags = KFS_Normal_PTR | KFS_Ignore_Case;
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.                                 33
  2220.          
  2221.          
  2222.          
  2223.          
  2224.          
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.          Programming Hints and Tips
  2231.          
  2232.          In this section we will try to provide some hints, examples, 
  2233.          and, hopefully, the answers to some questions to help an appli-
  2234.          cation developer in using the Keyed File System. As part of the 
  2235.          KFS package we have included the source to the sample and util-
  2236.          ity programs we have provided. These programs will provide some 
  2237.          concrete coding examples of how to use the functions we have 
  2238.          described. Use them to reinforce some of the examples we use in 
  2239.          this section.  
  2240.          
  2241.          *    Ensure that when creating a database that the KFS_flags 
  2242.               field is properly set to one of the valid options.
  2243.          
  2244.          *    When specifying a key in the data area for an operation 
  2245.               that requires a key, make sure that all bytes in the key 
  2246.               field are set to a known value. Remember, the Keyed File 
  2247.               System always assumes the key is KFS_keylen bytes long, 
  2248.               irrespective of any NULLS in the key field. A common mis-
  2249.               take is not to "clear" the key field before moving in a key 
  2250.               that may be shorter than keylen. For example, STRCPY only 
  2251.               moves data until a '00'X is detected in the source. Thus, 
  2252.               if what is being moved in is shorter than KFS_keylen, the 
  2253.               remaining bytes of the key field will remain unchanged (ie. 
  2254.               may contain garbage). Additionally, consider that STRCPY 
  2255.               also moves the terminating NULL character and that will 
  2256.               become part of the key. This may be OK, just realize that 
  2257.               the NULL is there. A good habit to get into when using KFS 
  2258.               functions is illustrated by the following code:
  2259.          
  2260.               #include <kfs.h>
  2261.               KFS_FILEINFO file1;
  2262.               char area[80];
  2263.               memset(&area[file1.KFS_keypos], ' ', file1.KFS_keylen);
  2264.               strcpy(&area[file1.KFS_keypos, newkey);
  2265.          
  2266.               This code sequence initially sets the key field of "area" 
  2267.               to blanks and then copies in the desired key from the 
  2268.               "newkey" variable. 
  2269.          
  2270.          *    You will notice that the Keyed File System does not allow 
  2271.               for duplicate keys. However, with a little thought, the 
  2272.               KFS_ReadGen and KFS_ReadNext functions can be used to pro-
  2273.               vide a similar capability. For example, if you wanted to 
  2274.               have a database whose key was a name field, duplicate names 
  2275.               could be avoided by making the key field the name AND 
  2276.               account number. You could still issue a KFS_ReadGen for 
  2277.               only the name and then use KFS_ReadNext to read the rest of 
  2278.               the records having the same name. 
  2279.          
  2280.          *    If KFS_ReadNext tries to read the next record after the 
  2281.               last logical record in the database (ie. the record with 
  2282.               the highest key) a KFS_EOF is returned. If another 
  2283.               KFS_ReadNext is issued, KFS_EOF will again be returned. 
  2284.               However, other operations (such as KFS_Read) are still 
  2285.               allowed on the database and will result in KFS_rc to be set 
  2286.               to another value (such as KFS_OK if the read is success-
  2287.               ful). Further KFS_ReadNext operations may be performed from 
  2288.               that spot in the database.
  2289.          
  2290.                                 34
  2291.          
  2292.          
  2293.          
  2294.          
  2295.          
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.          *    We mentioned earlier that numeric and alphabetic keys can-
  2302.               not be combined. However, if you keep in mind that shorts 
  2303.               and longs are stored in byte reversed format, you can form 
  2304.               keys that mix data types. The following code segment com-
  2305.               bines an alphabetic customer name and a numeric (i.e. long) 
  2306.               customer number into a single key. The customers names 
  2307.               would be in the database in alphabetic sequence, but cus-
  2308.               tomers with the same name would not necessarily be in 
  2309.               sequence by customer number (customer number 256, stored as 
  2310.               '00010000'x, would be before customer number 255, stored as 
  2311.               'FF000000'x, for example). 
  2312.          
  2313.                    #include <kfs.h>
  2314.                    struct DA {
  2315.                         char custname[40];
  2316.                         long custnum;
  2317.                         char morestuff[40];
  2318.                    } myarea;
  2319.                    KFS_FILEINFO myfile; 
  2320.                       :
  2321.                    myfile.KFS_keypos = 0;
  2322.                    myfile.KFS_keylen = 44;
  2323.                       :
  2324.                    KFS_Create(&myfile);          
  2325.  
  2326.  
  2327.  
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.                                 35
  2361.          
  2362.          
  2363.          
  2364.          
  2365.          
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.          Data Recovery
  2372.          
  2373.          Most programmers are familiar with damaged data files caused by 
  2374.          unusual system problems (power failures or system crashes) while 
  2375.          a file is being written to disk. While these problems are rare, 
  2376.          they do occur. The Keyed File System contains code that attempts 
  2377.          to minimize the impact of such a system failure, but this impact 
  2378.          cannot be eliminated completely. Since the Keyed File System 
  2379.          uses two related DOS files (an index file and a data file) to 
  2380.          manage a database, damage to one of these files can cause the 
  2381.          database to become unusable. With a little planning, however, a 
  2382.          programmer can frequently recover a damaged KFS database with 
  2383.          little or no loss of data. To do this requires a little knowl-
  2384.          edge of the internals of KFS. 
  2385.          
  2386.          The data file that makes up a KFS database is a normal DOS 
  2387.          binary file. That is, each "logical" record is KFS_recsize bytes 
  2388.          long and does not contain a CR/LF at the end of each record. 
  2389.          Thus, these records can be read using operating system or C 
  2390.          language functions just like any other binary file. Addition-
  2391.          ally, when KFS deletes a record, it is not physically removed 
  2392.          from the data file but only from the .PTR file. However, it is 
  2393.          marked for reuse and a hex 'FF' is placed in the last byte of 
  2394.          the data record when a record is deleted. This hex 'FF' has no 
  2395.          consequence to KFS since deleted records are tracked another way 
  2396.          internally, but can be useful for a programmer wanting to 
  2397.          recover a damaged KFS database by using only the data file. If, 
  2398.          when writing an application, a programmer using the Keyed File 
  2399.          System ensures that the last byte of each data record cannot 
  2400.          normally be hex 'FF', then recovering a KFS database can be 
  2401.          relatively simple. A database recovery program can be written 
  2402.          that simply reads the data portion of the damaged KFS database 
  2403.          as fixed length binary records, checks to ensure the last byte 
  2404.          of each record is not hex 'FF' (remember, hex 'FF' means the 
  2405.          record has been deleted), and uses the KFS_Add operation to add 
  2406.          the record to a new KFS database. At the conclusion of such a 
  2407.          recovery program, the new KFS database would contain all of the 
  2408.          undamaged records that existed in the original KFS database. A 
  2409.          simple example of this technique appears in Appendix B.
  2410.          
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.                                 36
  2432.          
  2433.          
  2434.          
  2435.          
  2436.          
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.          Appendix A - Keyed File System Return Codes
  2443.          
  2444.          The following is a list of return codes generated by the Keyed 
  2445.          File System. These definitions are found in the supplied header 
  2446.          file (KFS.H). 
  2447.          
  2448.          KFS_OK (0)
  2449.               The operation completed successfully. 
  2450.          
  2451.          KFS_Data_File_Open_Error (3)
  2452.               A bad return code was return from the system when trying to 
  2453.               open the data file of the database.
  2454.          
  2455.          KFS_EOF (-1)
  2456.               End of file was reached on the data database during a 
  2457.               KFS_ReadNext. The database remains open and subsequent 
  2458.               keyed operations are allowed.
  2459.          
  2460.          KFS_File_Error (8)
  2461.               An unknown error was returned by the operating system.
  2462.          
  2463.          KFS_File_Already_Exists (9)
  2464.               You are trying to create a database that already exists in 
  2465.               this directory.
  2466.          
  2467.          KFS_Invalid_File_Name (1) 
  2468.               The database name requested in KFS_filename is longer than 
  2469.               the 63 characters allowed by the Keyed File System. 
  2470.          
  2471.          KFS_Invalid_Request (11)
  2472.               You are attempting to do a KFS_ReadGen on a database with 
  2473.               numeric keys. Use a KFS_ReadGenNumeric function instead.
  2474.          
  2475.          KFS_Key_Already_Exists (4)
  2476.               A record with the key specified already exists in the 
  2477.               database.
  2478.          
  2479.          KFS_Key_Length_Invalid (12)
  2480.               The length of the partial key specified for a KFS_ReadGen 
  2481.               was either 0 or greater than the key length for this data-
  2482.               base.
  2483.          
  2484.          KFS_Key_Not_Found (5)
  2485.               A record with the key specified does not exist in the 
  2486.               database.
  2487.          
  2488.          KFS_Keyed_File_Empty (7)
  2489.               When attempting to execute a KFS_ReadFirst operation it was 
  2490.               discovered that the database had no records. 
  2491.          
  2492.          
  2493.          
  2494.          
  2495.               KFS_No_Space_On_Disk (13)
  2496.               There is no space on the disk containing the KFS database 
  2497.               to add a new record.
  2498.          
  2499.          KFS_Prior_Key_Not_Found (6)
  2500.               The key specified as the prior key in a KFS_ReadNext was 
  2501.               not found in the database.
  2502.                                 37
  2503.          
  2504.          
  2505.          
  2506.          
  2507.          
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.          
  2514.          KFS_PTR_File_Open_Error (2)
  2515.               A bad return code was return from the system when trying to 
  2516.               open the pointer file of the database. 
  2517.          
  2518.          KFS_Recordsize_Too_Short (10)
  2519.               The amount specified in KFS_recsize is smaller than 
  2520.               KFS_keypos + KFS_keylen.
  2521.  
  2522.  
  2523.  
  2524.  
  2525.  
  2526.  
  2527.  
  2528.  
  2529.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.                                 38
  2573.          
  2574.          
  2575.          
  2576.          
  2577.          
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  
  2583.          Appendix B - File Recovery Example
  2584.          
  2585.          The following is an example of a C program that could be used to 
  2586.          recover a KFS database. Assume the damaged database had the 
  2587.          following characteristics:
  2588.          
  2589.               KFS_filename   = C:\DATA\MYFILE.DAT
  2590.               KFS_recsize    = 100
  2591.               KFS_keypos     = 0
  2592.               KFS_keylen     = 15
  2593.          
  2594.          The C program to recover this database could look like this:
  2595.          
  2596.          main()
  2597.          {
  2598.             /* Example of how to recover a KFS file if .PTR is damaged */
  2599.             FILE *old;
  2600.             KFS_FILEINFO new;
  2601.             char dataarea[100];
  2602.          
  2603.             old = fopen("C:\\DATA\\MYFILE.DAT", "rb");
  2604.             new.KFS_recsize = 100;
  2605.             new.KFS_keylen = 15;
  2606.             new.KFS_keypos = 0;
  2607.             new.KFS_flags = KFS_Normal_PTR;
  2608.             strcpy(new.KFS_filename, "C:\\WORK\\MYFILE.DAT");
  2609.             KFS_Create(&new);
  2610.             fread(&dataarea, sizeof(dataarea), 1, old);
  2611.             while(!feof(old))
  2612.             {
  2613.                if (dataarea[new.KFS_recsize - 1] != 0xff)
  2614.                   KFS_Add(&new, &dataarea);
  2615.                fread(&dataarea, sizeof(dataarea), 1, old);
  2616.             }
  2617.             fclose(old);
  2618.             KFS_Close(&new);
  2619.          }
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.                                 39
  2643.          
  2644.          
  2645.          
  2646.