home *** CD-ROM | disk | FTP | other *** search
/ HomeWare 14 / HOMEWARE14.bin / os2 / kfsos220.arj / KFS.DOC < prev    next >
Text File  |  1994-02-15  |  69KB  |  2,643 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 (OS/2 2.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  3
  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 to build and maintain databases on a PC that are 
  111.          logically organized by a user defined key. Records can be read 
  112.          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 OS/2 functions to create and 
  121.          maintain its databases. Therefore, records may be of any length 
  122.          supported by the OS/2 operating system and can be created using 
  123.          the FAT or HPFS file systems. Files may be created on floppy or 
  124.          hard disks, although, as might be expected, hard disk files will 
  125.          provide better performance. KFS databases may be moved or copied 
  126.          using normal OS/2 commands (such as COPY) as long as both file 
  127.          components are moved together (see "Copying Files"). Addition-
  128.          ally, databases built using the KFS functions on the OS/2 
  129.          operating system are compatible with databases built using the 
  130.          language specific KFS functions released as a separate product 
  131.          for DOS and OS/2 1.x. 
  132.          
  133.          The Keyed File System supports most operations normally associ-
  134.          ated with keyed files:
  135.          
  136.          *    Direct reading and writing of records by key.
  137.          
  138.          *    Sequential reading of records in key sequence.
  139.          
  140.          *    Deleting of records by key.
  141.          
  142.          *    Reading records using a partial key.
  143.  
  144.  
  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 2.x or higher.
  185.          
  186.          *    Approx. 180K of disk space including sample programs and 
  187.               utilities.
  188.               
  189.          Keyed File System Components
  190.          
  191.          KFS.H             - The header file for use in C programs that 
  192.                              want to use KFS functions.
  193.          
  194.          KFSOS220.LIB      - A lib used at linkedit time to specify the 
  195.                              KFS functions exist in a DLL.
  196.          
  197.          KFSOS220.DLL      - The DLL containing the KFS routines. This 
  198.                              file must be placed in a directory in your 
  199.                              LIBPATH.
  200.          
  201.          KFSSAMP.C         - A sample program that builds a KFS database 
  202.                              from a sequential file and then uses most of 
  203.                              the functions available in KFS. 
  204.          
  205.          KFSSAMP.DAT       - The sequential input file to the KFSSAMP 
  206.                              program.
  207.          
  208.          KFSSAMP.MAK       - A sample make file for KFSSAMP.C. 
  209.          
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.                                  5
  237.          
  238.          
  239.          
  240.          
  241.          
  242.  
  243.  
  244.  
  245.  
  246.  
  247.          Keyed File System Restrictions
  248.          
  249.          The following restrictions apply to KFS databases:
  250.          
  251.          *    Databases must contain fixed length records.
  252.          
  253.          *    Each record must be at least 5 bytes in length.
  254.          
  255.          *    Numeric keys must be 4 bytes in length but alphabetic keys 
  256.               may be up to 32767 characters in length.
  257.          
  258.          *    Duplicate keys are not allowed (see "Programming Tips and 
  259.               Techniques").
  260.          
  261.          *    The path and file name specified during KFS_Create or 
  262.               KFS_Open for a KFS database cannot be longer than 63 bytes.
  263.          
  264.          *    Files cannot be created using KFS_Open, you must use 
  265.               KFS_Create to create and open a new file and KFS_Open only 
  266.               for an existing file.
  267.          
  268.          *    Two databases with the same "base" name cannot exist in the 
  269.               same directory even if the file extensions are different. 
  270.               That is KFS databases with the base names of MYFILE.001 and 
  271.               MYFILE.002 cannot exist in the same directory, but the 
  272.               names MYFILE1.XXX and MYFILE2.XXX are OK. This is explained 
  273.               further in the section "What Are Keyed Files".
  274.          
  275.          *    You cannot name a KFS database using the extension of .PTR. 
  276.               Thus MYFILE.PTR is invalid. This is also explained in the 
  277.               "What Are Keyed Files" section.
  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.                                  6
  308.          
  309.          
  310.          
  311.          
  312.          
  313.  
  314.  
  315.  
  316.  
  317.  
  318.          Including KFS Routines in Your Program
  319.          
  320.          To include the KFS routines in your C program requires four 
  321.          steps:
  322.          
  323.          1.   Include the KFS.H header file (or similar header file for 
  324.               your language) at the beginning of your program source. For 
  325.               example:
  326.                    #include <KFS.H>
  327.          
  328.          2.   Define any keyed files using the KFS_FILEINFO typedef (or 
  329.               similar structure for a non-C language). For example:
  330.                    KFS_FILEINFO keyedfile;
  331.          
  332.          3.   Include the KFSOS220.LIB file when linking your program. 
  333.               For example, to link an OS/2 program :
  334.                    LINK386 myprog,,,KFSOS220;
  335.          
  336.          4.   Insure that the KFSOS220.DLL file is in a directory in your 
  337.               LIBPATH when the resulting .EXE is executed.
  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.  
  377.  
  378.                                  7
  379.          
  380.          
  381.          
  382.          
  383.          
  384.  
  385.  
  386.  
  387.  
  388.  
  389.          What Are Keyed Files
  390.          
  391.          Keyed File System databases are actually composed of two files, 
  392.          an index file and a data file. These two files work together to 
  393.          provide you with direct access of a record by key while keeping 
  394.          the records in a logical keyed sequence. The name of the data 
  395.          file is the same as the name of the database and is specified by 
  396.          the programmer when the KFS database is created (using the 
  397.          KFS_Create function). This may be any valid OS/2 file name. The 
  398.          index file is automatically given the same base name you speci-
  399.          fied for the database but with an extension of .PTR. For 
  400.          example, specifying a name of CUSTOMER.DAT for a database auto-
  401.          matically causes the creation of an index file with the name of 
  402.          CUSTOMER.PTR. This leads to two restrictions in the Keyed File 
  403.          System:
  404.          
  405.          1)   You cannot name a database using an extension of .PTR.
  406.          
  407.          2)   You cannot have two databases in the same directory with 
  408.               the same base name since this would result in an attempt by 
  409.               KFS to create duplicate .PTR files. For example, MYFILE.001 
  410.               and MYFILE.002 would both result in KFS attempting to cre-
  411.               ate an index file named MYFILE.PTR.
  412.          
  413.          Because these two files work together they must remain physi-
  414.          cally in the same directory. Therefore, if the Keyed File System 
  415.          database is moved, both the data and index files must be moved 
  416.          together.
  417.          
  418.          The format and content of the index file is determined by the 
  419.          Keyed File System, while the format and content of the data file 
  420.          is determined by you when the database is created. When you 
  421.          create a Keyed File System database you must tell the Keyed File 
  422.          System how large each record in the database will be 
  423.          (KFS_recsize), where the key begins in the record (KFS_keypos), 
  424.          and how long the key is (KFS_keylen). Note that the Keyed File 
  425.          System only supports fixed length records (ie. each record in 
  426.          the database is the same length).
  427.          
  428.          The Keyed File System requires that databases are either created 
  429.          or opened before they are used, and that they are closed before 
  430.          the program terminates. With any file system, if a program ter-
  431.          minates abnormally without closing files (such as a system crash 
  432.          because of a power failure) and file buffering is being used 
  433.          (such as is available with HPFS), data that has been "written" 
  434.          by the program but waiting in an output buffer to be physically 
  435.          written to disk may be lost. The Keyed File System makes every 
  436.          attempt to minimize the impact of such a system failure, but 
  437.          since it does utilize two files working together, there are rare 
  438.          times this loss of data may result in the database becoming 
  439.          unusable. Thus special care should be taken by your application 
  440.          user to properly back up the data and index files making up each 
  441.          KFS database. Also, see the section on "Data Recovery" for an 
  442.          example of how to recover a damaged KFS database.
  443.          
  444.  
  445.  
  446.  
  447.  
  448.  
  449.                                  8
  450.          
  451.          
  452.          
  453.          
  454.          
  455.  
  456.  
  457.  
  458.  
  459.  
  460.          Keyed File System Functions
  461.          
  462.          The Keyed File System is a set of 11 routines that provide you 
  463.          with the basic functions required for keyed record access on the 
  464.          PC. These functions are:
  465.          
  466.          KFS_Add
  467.               Adds a new record to a KFS database. The key of the record 
  468.               being added must not already exist in the database.
  469.          
  470.          KFS_Close
  471.               Close an open KFS database.
  472.          
  473.          KFS_Create 
  474.               Create and open a new KFS database. The database must not 
  475.               already exist.
  476.          
  477.          KFS_Delete
  478.               Deletes the record from a KFS database that has the key 
  479.               specified.
  480.          
  481.          KFS_Open
  482.               Open an existing KFS database.
  483.          
  484.          KFS_Read
  485.               Read a record from an open KFS database by key.
  486.          
  487.          KFS_ReadFirst
  488.               Reads the first logical record in a KFS database.
  489.          
  490.          KFS_ReadGen
  491.               For databases with alphabetic keys only. Read a record from 
  492.               an open KFS database using a partial key. If no records 
  493.               match the partial key, the next record in sequence after 
  494.               the key requested is returned in the user area and a code 
  495.               of KFS_Key_Not_Found is returned in KFS_rc.
  496.          
  497.          KFS_ReadGenNumeric 
  498.               For databases with numeric keys only. Read a record from an 
  499.               open KFS database. If the requested key is not found, the 
  500.               next record in sequence after the key requested is returned 
  501.               in the user area and a return code of KFS_Key_Not_Found is 
  502.               returned in KFS_rc.
  503.          
  504.          KFS_ReadNext
  505.               Reads the record in a KFS database that is the next record 
  506.               after the key specified.
  507.          
  508.          KFS_Replace
  509.               Replaces the record in a KFS database that has the same key 
  510.               as the one specified. A record with this key must exist in 
  511.               the database.
  512.          
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.                                  9
  521.          
  522.          
  523.          
  524.          
  525.          
  526.  
  527.  
  528.  
  529.  
  530.  
  531.          The File Information Structure
  532.          
  533.          In order to use the Keyed File System routines, you must provide 
  534.          the KFS functions with a File Information Structure for each 
  535.          database you are going to use in your program. This is a control 
  536.          structure (similar to the C "FILE" typedef) that includes such 
  537.          information about the database as the database name, key length, 
  538.          location of the key within the record, and a return code field 
  539.          for checking the result of KFS operations, as well as control 
  540.          fields used by the KFS functions themselves. Once the database 
  541.          is opened, this structure should not be modified by the appli-
  542.          cation since this may damage the control information used by the 
  543.          KFS functions and the integrity of the database may be compro-
  544.          mised. There is a C typedef named KFS_FILEINFO for this 
  545.          structure defined in the KFS.H header file provided with the 
  546.          system. Also present in this header file are the C prototypes 
  547.          for the KFS functions and the definitions of the KFS return 
  548.          codes. 
  549.          
  550.          To create a KFS database (using the KFS_Create operation), you 
  551.          must provide several important pieces of information about the 
  552.          database. This is done by placing the appropriate values in the 
  553.          following fields in the File Information Structure defined for 
  554.          the file:
  555.          
  556.               KFS_filename
  557.                    Required for KFS_Create or KFS_Open, this field must 
  558.                    contain the name of the database being created or 
  559.                    opened. This is an OS/2 file specification that 
  560.                    includes drive, path, and database name. As mentioned 
  561.                    before the Keyed File System actually creates (or 
  562.                    opens) two files for any KFS database and if these 
  563.                    files are moved, both must be move to the same loca-
  564.                    tion (ie. subdirectory or floppy disk). The first file 
  565.                    will have the name you specify here, while the second 
  566.                    file will have the same base name as the database you 
  567.                    specified but a qualifier of .PTR.    
  568.          
  569.               KFS_keypos
  570.                    KFS_Create only. This is the position of the key 
  571.                    within the record. This position is relative to 0. 
  572.                    That is, if the key begins in the first position of 
  573.                    the record, 0 is placed here by the programmer. If the 
  574.                    key begins in the 5th position of the record, 4 is put 
  575.                    here. 
  576.          
  577.               KFS_keylen
  578.                    KFS_Create only. This is the length of the key in the 
  579.                    record. For example, if the key went from position 5 
  580.                    through position 10 (ie. 6 characters long) in the 
  581.                    data record, 6 would be placed here. For numeric keys, 
  582.                    this field is ignored.
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.                                 10
  591.          
  592.          
  593.          
  594.          
  595.          
  596.  
  597.  
  598.  
  599.  
  600.  
  601.               KFS_recsize
  602.                    KFS_Create only. Place the total size of each data 
  603.                    record, including the key in this field. 
  604.          
  605.               KFS_flags
  606.                    KFS_Create only. These flags specify any special pro-
  607.                    cessing required for the database. The options 
  608.                    available to you are normal pointer file, small 
  609.                    pointer file, numeric keys, and ignore case. These 
  610.                    options are discussed further in the section  "Special
  611.                    Processing".   
  612.          
  613.          Once a KFS database is created, it may be subsequently used by 
  614.          simply specifying the name of the database in the KFS_filename 
  615.          field of the File Information structure and using KFS_Open to 
  616.          open the database. The remaining information about the database 
  617.          (ie. KFS_keypos, KFS_keylen, KFS_recsize, and KFS_flags) is 
  618.          stored with the database when it is created. 
  619.          
  620.          Upon the completion of a KFS operation, the success or failure 
  621.          of the operation is determined by checking the return code pro-
  622.          vided in the database's KFS_FILEINFO field KFS_rc. The valid 
  623.          return codes are defined in the KFS.H header file and are docu-
  624.          mented in Appendix A of this User's Guide.
  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.  
  661.                                 11
  662.          
  663.          
  664.          
  665.          
  666.          
  667.  
  668.  
  669.  
  670.  
  671.  
  672.          Parameters to Keyed File System Functions
  673.          
  674.          The are 11 application interfaces that can be called to perform 
  675.          operations on databases with the Keyed File System. These 
  676.          operations require 1, 2, or 3 parameters depending on the func-
  677.          tion desired.
  678.          
  679.          The first parameter to all of the KFS functions is always the 
  680.          address of the KFS File Information structure (KFS_FILEINFO) for 
  681.          the desired database. As mentioned before, once a database is 
  682.          created or opened this structure should not be changed by the 
  683.          programmer since it is used by the database system to keep track 
  684.          of current information about the database. It is also used to 
  685.          provide feedback to the programmer about the requested opera-
  686.          tion.
  687.          
  688.          The second parameter is necessary for the functions that will be 
  689.          reading data from or writing data to a KFS database. This 
  690.          parameter is the address of an area large enough to contain a 
  691.          record from the database (that is, at least KFS_recsize in 
  692.          length). When a key is required by a specific KFS operation, the 
  693.          system expects the key to be in this area at the same relative 
  694.          position, and with the same length, as the key in a record in 
  695.          the database. For example, to read a record with the key "ABCDE" 
  696.          for a database whose KFS_keypos = 3, KFS_keylen = 5, and 
  697.          KFS_recsize = 80 means that the second parameter would be the 
  698.          address of an area at least 80 bytes in length that contains 
  699.          "ABCDE" in the 4th, 5th, 6th, 7th, and 8th bytes (ie. 
  700.          ...ABCDE..). 
  701.          
  702.          The third parameter is only required on the KFS_ReadGen function 
  703.          and is the length of the portion of the key provided. This 
  704.          parameter is discussed further in the discussion of KFS_ReadGen. 
  705.          The following program segment illustrates how the above param-
  706.          eters would be specified for a typical KFS function call:
  707.          
  708.            #include <kfs.h>
  709.            KFS_FILEINFO file1;
  710.            char recarea[100];
  711.          
  712.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  713.            KFS_Open(&file1);
  714.            if (file1.KFS_rc != KFS_OK)
  715.               printf("Error opening file1\n");
  716.            strcpy(&recarea[file1.KFS_keypos], "A k");
  717.            KFS_ReadGen(&file1, (void *)recarea, 3);
  718.          
  719.          For further examples, see the description of the individual KFS 
  720.          functions and the KFSSAMP.C program provided as part of this 
  721.          package.
  722.          
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.                                 12
  733.          
  734.          
  735.          
  736.          
  737.          
  738.  
  739.  
  740.  
  741.  
  742.  
  743.          Keyed File System Functions
  744.          
  745.          In the description of the following functions the KFS_File_Error 
  746.          is a general error caused by an "unknown error" returned from 
  747.          the operating system and is possible for all functions.
  748.          
  749.          KFS_Add(fs, area)
  750.               Add a data record to a database. 
  751.          
  752.          Parameters
  753.               KFS_FILEINFO *fs
  754.                    A pointer to a KFS file structure.
  755.          
  756.               void *area
  757.                    A pointer to a data area containing the record to be 
  758.                    added. The key to be added must be at KFS_keypos of 
  759.                    this area before the operation is issued.
  760.           
  761.          
  762.          
  763.          Description
  764.               Add a record to the database. Another record with this key 
  765.               must not already exist in the database.
  766.          
  767.          
  768.          Required Fields
  769.               KFS_filename
  770.                    Contains the name of an open database where the record 
  771.                    is to be added.
  772.          
  773.               area
  774.                    The data area pointed to must contain the key of the 
  775.                    record being deleted beginning in KFS_keypos of the 
  776.                    area. 
  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.          Example
  1124.            /* Add a record to a KFS file                              */
  1125.            #include <kfs.h>
  1126.            KFS_FILEINFO file1;
  1127.            typedef struct m {
  1128.               int f1;
  1129.               int f2;
  1130.               char mykey[7];
  1131.               char filler[89];
  1132.            } MYSTRUCT;
  1133.            MYSTRUCT inarea;
  1134.          
  1135.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1136.            KFS_Open(&file1);
  1137.            memset(&inarea.mykey, ' ', sizeof(inarea.mykey));
  1138.            strcpy(&inarea.mykey, "Dkey");
  1139.            KFS_Delete(&file1, (char *)&inarea);
  1140.            switch (file1.KFS_rc) {
  1141.               case KFS_OK:
  1142.                  break;
  1143.               case KFS_No_Space_On_Disk:
  1144.                  printf("Not enough space on disk to add record\n");
  1145.                  break;
  1146.               default:
  1147.                  printf("Error adding record\n");
  1148.            }
  1149.          
  1150.          
  1151.          Possible KFS_rc Values -
  1152.               KFS_OK
  1153.                    The record was deleted successfully.
  1154.          
  1155.               KFS_Key_Not_Found
  1156.                                 18
  1157.          
  1158.          
  1159.          
  1160.          
  1161.          
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.                    A record with the key specified was not found. The 
  1168.                    operation is ignored.
  1169.          
  1170.               KFS_No_Space_On_Disk
  1171.                    There is not enough space on the disk containing the 
  1172.                    KFS database to add a record.
  1173.          
  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.          Parameters -
  1595.               KFS_FILEINFO *fs 
  1596.                    A pointer to a KFS file structure.
  1597.          
  1598.               void *area
  1599.                    A pointer to a data area where the requested record 
  1600.                    will be read. A numeric key must be placed in 
  1601.                    KFS_keypos of this area prior to performing the 
  1602.                    operation.
  1603.           
  1604.          Description
  1605.               If a record in the database matches the key specified it is 
  1606.               read and placed in the data area. KFS_OK is then returned. 
  1607.               If no record matches the numeric key, then the next record 
  1608.               in the database is returned with a return code of 
  1609.               KFS_Key_Not_Found. 
  1610.          
  1611.          
  1612.          Required Fields
  1613.               KFS_filename
  1614.                    Contains the name of an open database.
  1615.          
  1616.               area
  1617.                    The data area pointed to must contain a numeric key at 
  1618.                    KFS_keypos. 
  1619.          
  1620.          Example
  1621.            /* Read a KFS file by numeric key (keypos=4)               */
  1622.            #include <kfs.h>
  1623.            KFS_FILEINFO file1;
  1624.            typedef struct m {
  1625.               int f1;
  1626.               int f2;
  1627.               long mykey;
  1628.               char filler[92];
  1629.            } MYSTRUCT;
  1630.            MYSTRUCT inarea;
  1631.          
  1632.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1633.            KFS_Open(&file1);
  1634.            if (file1.KFS_rc != KFS_OK)
  1635.               printf("Error opening file1\n");
  1636.            inarea.mykey = 1000;
  1637.            KFS_ReadGenNumeric(&file1, (void *)inarea);
  1638.            if (file1.KFS_rc == KFS_Key_Not_Found)
  1639.               printf("There was no key 1000 but got the next key\n");
  1640.            else
  1641.               if (file1.KFS_rc == KFS_OK)
  1642.                  printf("We got the record with key 1000");
  1643.          
  1644.          
  1645.          Possible KFS_rc Values
  1646.               KFS_OK
  1647.                    The record was read successfully.
  1648.          
  1649.               KFS_Key_Not_Found
  1650.                    No record with a key that matched the key specified 
  1651.                                 25
  1652.          
  1653.          
  1654.          
  1655.          
  1656.          
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.                              was found. The next logical record in the database is 
  1663.                    returned.
  1664.          
  1665.               KFS_EOF
  1666.                    The partial key requested could not be found and the 
  1667.                    next position in the database was at end of file.
  1668.  
  1669.  
  1670.  
  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.          Parameters
  1736.               KFS_FILEINFO *fs
  1737.                    A pointer to a KFS file structure.
  1738.          
  1739.               void *area
  1740.                    A pointer to a data area where the requested record 
  1741.                    will be read. The key placed at KFS_keypos of this 
  1742.                    area must be the key of the record before the record 
  1743.                    desired. 
  1744.          
  1745.          Description
  1746.               Read the next logical record from a database. The record 
  1747.               with the next highest key after the key specified in the 
  1748.               data area will be read. The user must provide the key of 
  1749.               the previous record in KFS_keypos of area. This allows the 
  1750.               user to read all records in a database with a succession of 
  1751.               KFS_ReadNext functions. 
  1752.          
  1753.          Required Fields
  1754.               KFS_filename
  1755.                    Contains the name of an open database.
  1756.          
  1757.               area
  1758.                    Contains the key of the record previous to the one to 
  1759.                    be read. 
  1760.           
  1761.          
  1762.          Example
  1763.            /* Read the all of the records sequentially from a file    */
  1764.            #include <kfs.h>
  1765.            KFS_FILEINFO file1;
  1766.            typedef struct m {
  1767.               int f1;
  1768.               int f2;
  1769.               char mykey[7];
  1770.               char filler[89];
  1771.            } MYSTRUCT;
  1772.            MYSTRUCT inarea;
  1773.          
  1774.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1775.            KFS_Open(&file1);
  1776.            if (file1.KFS_rc != KFS_OK)
  1777.               printf("Error opening file1\n");
  1778.              KFS_ReadFirst(&file1, (void *)&inarea);
  1779.            while (file1.KFS_rc != KFS_EOF) {
  1780.               KFS_ReadNext(&file1, (void *)&inarea);
  1781.               if (file1.KFS_rc != KFS_OK) printf("Error");
  1782.            }
  1783.            KFS_Close(&file1);
  1784.          
  1785.          
  1786.          Possible KFS_rc Values
  1787.               KFS_OK
  1788.                    The record was read successfully.
  1789.          
  1790.               KFS_EOF
  1791.                    There are no more records in the dataset. 
  1792.                                 27
  1793.          
  1794.          
  1795.          
  1796.          
  1797.          
  1798.  
  1799.  
  1800.  
  1801.  
  1802.  
  1803.          
  1804.               KFS_Key_Not_Found
  1805.                    A record with the specified key did not exist in the 
  1806.                    database and no record is returned. (i.e. the previous 
  1807.                    record must be found before the "next" record can be 
  1808.                    returned)
  1809.          
  1810.  
  1811.  
  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 and util-
  2234.          ity programs we have provided. These programs will provide some 
  2235.          concrete coding examples of how to use the functions we have 
  2236.          described. Use them to reinforce some of the examples we use in 
  2237.          this section.  
  2238.          
  2239.          *    Ensure that when creating a database that the KFS_flags 
  2240.               field is properly set to one of the valid options.
  2241.          
  2242.          *    When specifying a key in the data area for an operation 
  2243.               that requires a key, make sure that all bytes in the key 
  2244.               field are set to a known value. Remember, the Keyed File 
  2245.               System always assumes the key is KFS_keylen bytes long, 
  2246.               irrespective of any NULLS in the key field. A common mis-
  2247.               take is not to "clear" the key field before moving in a key 
  2248.               that may be shorter than keylen. For example, STRCPY only 
  2249.               moves data until a '00'X is detected in the source. Thus, 
  2250.               if what is being moved in is shorter than KFS_keylen, the 
  2251.               remaining bytes of the key field will remain unchanged (ie. 
  2252.               may contain garbage). Additionally, consider that STRCPY 
  2253.               also moves the terminating NULL character and that will 
  2254.               become part of the key. This may be OK, just realize that 
  2255.               the NULL is there. A good habit to get into when using KFS 
  2256.               functions is illustrated by the following code:
  2257.          
  2258.               #include <kfs.h>
  2259.               KFS_FILEINFO file1;
  2260.               char area[80];
  2261.               memset(&area[file1.KFS_keypos], ' ', file1.KFS_keylen);
  2262.               strcpy(&area[file1.KFS_keypos, newkey);
  2263.          
  2264.               This code sequence initially sets the key field of "area" 
  2265.               to blanks and then copies in the desired key from the 
  2266.               "newkey" variable. 
  2267.          
  2268.          *    You will notice that the Keyed File System does not allow 
  2269.               for duplicate keys. However, with a little thought, the 
  2270.               KFS_ReadGen and KFS_ReadNext functions can be used to pro-
  2271.               vide a similar capability. For example, if you wanted to 
  2272.               have a database whose key was a name field, duplicate names 
  2273.               could be avoided by making the key field the name AND 
  2274.               account number. You could still issue a KFS_ReadGen for 
  2275.               only the name and then use KFS_ReadNext to read the rest of 
  2276.               the records having the same name. 
  2277.          
  2278.          *    If KFS_ReadNext tries to read the next record after the 
  2279.               last logical record in the database (ie. the record with 
  2280.               the highest key) a KFS_EOF is returned. If another 
  2281.               KFS_ReadNext is issued, KFS_EOF will again be returned. 
  2282.               However, other operations (such as KFS_Read) are still 
  2283.               allowed on the database and will result in KFS_rc to be set 
  2284.               to another value (such as KFS_OK if the read is success-
  2285.               ful). Further KFS_ReadNext operations may be performed from 
  2286.               that spot in the database.
  2287.          
  2288.                                 34
  2289.          
  2290.          
  2291.          
  2292.          
  2293.          
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.          *    We mentioned earlier that numeric and alphabetic keys can-
  2300.               not be combined. However, if you keep in mind that shorts 
  2301.               and longs are stored in byte reversed format, you can form 
  2302.               keys that mix data types. The following code segment com-
  2303.               bines an alphabetic customer name and a numeric (i.e. long) 
  2304.               customer number into a single key. The customers names 
  2305.               would be in the database in alphabetic sequence, but cus-
  2306.               tomers with the same name would not necessarily be in 
  2307.               sequence by customer number (customer number 256, stored as 
  2308.               '00010000'x, would be before customer number 255, stored as 
  2309.               'FF000000'x, for example). 
  2310.          
  2311.                    #include <kfs.h>
  2312.                    struct DA {
  2313.                         char custname[40];
  2314.                         long custnum;
  2315.                         char morestuff[40];
  2316.                    } myarea;
  2317.                    KFS_FILEINFO myfile; 
  2318.                       :
  2319.                    myfile.KFS_keypos = 0;
  2320.                    myfile.KFS_keylen = 44;
  2321.                       :
  2322.                    KFS_Create(&myfile);          
  2323.  
  2324.  
  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.                                 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 C 
  2388.          language functions just like any other binary file. Addition-
  2389.          ally, when KFS deletes a record, it is not physically removed 
  2390.          from the data file but only from the .PTR file. However, it is 
  2391.          marked for reuse and a hex 'FF' is placed in the last byte of 
  2392.          the data record when a record is deleted. This hex 'FF' has no 
  2393.          consequence 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.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.                                 37
  2500.          
  2501.          
  2502.          
  2503.          
  2504.          
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.          KFS_No_Space_On_Disk (13)
  2511.               There is no space on the disk containing the KFS database 
  2512.               to add a new record.
  2513.          
  2514.          KFS_Prior_Key_Not_Found (6)
  2515.               The key specified as the prior key in a KFS_ReadNext was 
  2516.               not found in the database.
  2517.          
  2518.          KFS_PTR_File_Open_Error (2)
  2519.               A bad return code was return from the system when trying to 
  2520.               open the pointer file of the database. 
  2521.          
  2522.          KFS_Recordsize_Too_Short (10)
  2523.               The amount specified in KFS_recsize is smaller than 
  2524.               KFS_keypos + KFS_keylen.
  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.                                 38
  2570.          
  2571.          
  2572.          
  2573.          
  2574.          
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.          Appendix B - File Recovery Example
  2581.          
  2582.          The following is an example of a C program that could be used to 
  2583.          recover a KFS database. Assume the damaged database had the 
  2584.          following characteristics:
  2585.          
  2586.               KFS_filename   = C:\DATA\MYFILE.DAT
  2587.               KFS_recsize    = 100
  2588.               KFS_keypos     = 0
  2589.               KFS_keylen     = 15
  2590.          
  2591.          The C program to recover this database could look like this:
  2592.          
  2593.          main()
  2594.          {
  2595.             /* Example of how to recover a KFS file if .PTR is damaged */
  2596.             FILE *old;
  2597.             KFS_FILEINFO new;
  2598.             char dataarea[100];
  2599.          
  2600.             old = fopen("C:\\DATA\\MYFILE.DAT", "rb");
  2601.             new.KFS_recsize = 100;
  2602.             new.KFS_keylen = 15;
  2603.             new.KFS_keypos = 0;
  2604.             new.KFS_flags = KFS_Normal_PTR;
  2605.             strcpy(new.KFS_filename, "C:\\WORK\\MYFILE.DAT");
  2606.             KFS_Create(&new);
  2607.             fread(&dataarea, sizeof(dataarea), 1, old);
  2608.             while(!feof(old))
  2609.             {
  2610.                if (dataarea[new.KFS_recsize - 1] != 0xff)
  2611.                   KFS_Add(&new, &dataarea);
  2612.                fread(&dataarea, sizeof(dataarea), 1, old);
  2613.             }
  2614.             fclose(old);
  2615.             KFS_Close(&new);
  2616.          }
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.                                 39
  2640.          
  2641.          
  2642.          
  2643.