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