home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / CB4_MAN.ZIP / CB4_MAN.TXT
Encoding:
Text File  |  1990-06-21  |  237.2 KB  |  8,626 lines

  1.                   CODE BASE 4
  2.  
  3. LEARNING CODE BASE
  4.  
  5.    Code Base is a "C" library for database and screen management. Its
  6.    compatibility with dBASE allows it to work with any other dBASE compatible
  7.    product.
  8.  
  9.    As Code Base uses the same naming conventions as dBASE, it is easy to
  10.    learn. Anyone who is acquainted with the "C" programining language and
  11.    understands a few database fundamentals will have no trouble learning Code
  12.    Base.
  13.  
  14.    All users should progress through this section on learning Code Base. The
  15.    part on Code Base Internals should be read even if it is not completely
  16.    understood.
  17.  
  18.    Anyone who plans to use Code Base in a Multi-User environemnt will need to
  19.    read the chapter "Multi-User Considerations".
  20.  
  21.    The most important information in the "Routine Descriptions" chapter is in
  22.    the sections on "Database", "Field", "Windowing", "Menuing", and "Get"
  23.    routines.
  24.  
  25.    Those interested in filtering and relations should refer to the "Extend
  26.    Routines".
  27.  
  28.  
  29. BASIC TERMS
  30.  
  31.    Following are some definitions of terms which are used throughout the Code
  32.    Base manual.
  33.  
  34.    Database
  35.  
  36.     A database is a file which stores your data. For example, a mailing
  37.     list database contains the names and addresses of people.
  38.  
  39.  
  40.    Record
  41.  
  42.     Database information is organized into records. Each record in a
  43.     mailing list database contains information on one person.
  44.  
  45.  
  46.    Record Buffer
  47.  
  48.     For each database, Code Base allocates memory for one record worth of
  49.     information. Each of these memory areas is called a 'record buffer'.
  50.     Many of the high level Code Base database routines, such as 'd4go',
  51.     automatically use this memory buffer. A pointer to the record buffer
  52.     can be obtained using routine 'f4record'. The next section on Code
  53.     Base Internals describes the format of the record buffer.
  54.  
  55.  
  56.    Record Number
  57.  
  58.     Each record in a database is assigned a sequential record number
  59.     starting from one. There is a current record number which corresponds
  60.     to the record in the record buffer. The current record number can be
  61.     obtained with routine 'd4recno'.
  62.  
  63.  
  64.    Field
  65.  
  66.     Records are organized into fields. A database field describes one
  67.     category of information in each database record. The fields in a
  68.     mailing list database could be last name, address, city, and phone
  69.     number. LAST_NAME, ADDRESS, CITY, and PHONE_NUM are examples of
  70.     corresponding field names.
  71.  
  72.     Fields are type Character, Numeric, Floating Point, Logical, Date, or
  73.     Memo. The field type is important because it determines the category
  74.     of information the field stores. Field names and field types are
  75.     deteremined when a database is created.
  76.  
  77.  
  78.    Index File
  79.  
  80.     It may be necessary to examine a database in different orders at
  81.     different times. A mailing list database might need to be sorted by
  82.     the LAST_NAME some times and by the field ADDRESS at others. It would
  83.     take a long time to resort a large database every time a new order
  84.     was required.
  85.  
  86.     Consequently, index files are created to permanently contain sorted
  87.     information. An index file contains one sort order for one database.
  88.     Index files have a B+ Tree structure. This means that the sorted
  89.     information can be located quickly and efficiently.
  90.  
  91.  
  92.    Expression of an Index File
  93.  
  94.     Index files also contain information on how the database is to be
  95.     sorted. This information is called an expression. LAST_NAME is an
  96.     example of an expression; it means the index file contains a sort by
  97.     the field LAST_NAME.
  98.  
  99.  
  100.    Reference Number
  101.  
  102.     Code Base uses reference numbers for almost everything. Every
  103.     database, index file, field, get entry area, window or menu item used
  104.     by Code Base has a corresponding reference number. These reference
  105.     numbers are used as parameters to many Code Base routines.
  106.  
  107.  
  108.  
  109. DATABASE CONCEPTS
  110.  
  111.    Following are some basic concepts which the rest of this user's guide
  112.    assumes you under stand.
  113.  
  114.    By using Code Base, it is possible to save and access hundreds of
  115.    megabytes worth of information. This information is saved on disk in
  116.    database files. Only portions of the total available information is
  117.    manipulated at one time.
  118.  
  119.    It is possible to have several database files open at once. However, only
  120.    one database file is selected at a time.
  121.  
  122.    The database routines work with the selected database. Opening and closing
  123.    databases takes a lot of computer time but selecting between open
  124.    databases is almost instantaneous.
  125.  
  126.    For each open database there is a area in memory called a record buffer.
  127.    the exact format of the record buffer is described in the Appendix on Code
  128.    Base internals. Many of the high level database management routines work
  129.    with the record buffer. For example, routine 'd4go' reads a database
  130.    record from disk into the record buffer. Conversly, routine 'd4write'
  131.    either writes or appends the record in the record buffer to the database
  132.    file.
  133.  
  134.    To access and modify the record buffer, field routines are available. For
  135.    example, routine 'f4replace' changes the value of a field within the
  136.    record buffer.
  137.  
  138.    Every database can have a set of open index files. Each index file
  139.    corresponds to a specific database and when the database is modified
  140.    using 'd4write', all corresponding index files are automatically
  141.    maintained. Every database may have its own 'selected' index file. High
  142.    level database management routines such as 'd4seek' and 'd4skip' use the
  143.    currently selected index file of the currently selected database. Low
  144.    level index file routines such as 'i4seek' and 'i4skip' are not normally
  145.    used directly.
  146.  
  147.    Memo files are used for saving variable length text. For efficiency, every
  148.    field is saved in a fixed amount of space within a database record. A memo
  149.    field takes up exactly ten bytes worth of space within the database record
  150.    and a variable amount of space within a seperate memo file. A memo file
  151.    has the same file name as the corresponding database file except that the
  152.    file name extension is changed from "DBF" to "DBT". The same memo file is
  153.    used for all of the memo fields of a particular database file.
  154.  
  155.  
  156. GETTING STARTED
  157.  
  158.    Complete the following steps before working with Code Base for the first
  159.    time.
  160.  
  161.     1. Make a working version of the diskettes.
  162.  
  163.     2. Install Code Base.
  164.  
  165.     3. Run "d4learn" to experiment with the Code Base routines. Read the
  166.        documentation in the user's guide on a particular routine before
  167.        trying to use it.
  168.  
  169.     4. Read "Using Code Base with Turbo C", "Using Code Base with Quick
  170.        C", or "Using Code Base with Microsoft C".
  171.  
  172.     5. Read "Create Your own Code Base Applications.
  173.  
  174.  
  175.    Installing Code Base
  176.  
  177.     To use Code Base it is only necessary to copy the appropriate library
  178.     file, headers files and configuration information. However, to
  179.     compile Code Base routines, it is also necessary to copy the source
  180.     code.
  181.  
  182.     1. Copy one of the three pre-built library from the appriopate library
  183.        diskette.  If none of these library options are appropriate, refer
  184.        to the appendix on library building.
  185.  
  186.            File Name      Use
  187.  
  188.            T4.LIB         A Turbo C compatible large memory model library.
  189.  
  190.            M4.LIB         A Microsoft C and Quick C compatible large
  191.                   memory model library.
  192.  
  193.            M4CLIP.LIB     A Microsoft C and Quick C compatible large
  194.                   memory model library. This library was compiled
  195.                   for Clipper NTX file compatibility.
  196.  
  197.  
  198.     Turbo C Example:
  199.  
  200.            COPY A:\T4.LIB  C:\TC\LIB
  201.  
  202.        The above "COPY" command transfers the Turbo C compatible Code Base
  203.        library from the Code Base TC library diskette in "Drive A:" to the
  204.        library directory "\TC\LIB" on 'Drive C:'.
  205.  
  206.        As the library "T4.LIB" was constructed using the large memory
  207.        model, all source files in the application must be compiled with the
  208.        large memory model.
  209.  
  210.  
  211.     Microsoft C Example:
  212.  
  213.            COPY A:\M4.LIB  C:\MSC
  214.  
  215.        In this example, the Microsoft C compatible Code Base library
  216.        M4.LIB" is copied to directory "C:\MSC".  To use Microsoft C with
  217.        OS/2, refer to the appendix on library building.
  218.  
  219.  
  220.     Quick C:
  221.  
  222.        Refer to Microsoft C.  Note that it is impossible to use the Code
  223.        Base prebuilt libraries with the Quick C 1.0 interactive environment
  224.        because it needs medium memory model libraries.  If you need medium
  225.        memory model library, refer to the appendix on library building.
  226.  
  227.  
  228.     2. Copy header files from the Header, Example and Source diskette.
  229.        Note that the Turbo C header files are the same as the Microsoft
  230.        and Quick C header files:
  231.  
  232.        Example:
  233.  
  234.            COPY  A:\INCLUDE\*.*  C:\TC\INCLUDE
  235.  
  236.        The above command copies all of the Code Base header files from the
  237.        Header diskette to a Turbo C "Include" directory.  These header
  238.        files are necessary for using Code Base.
  239.  
  240.  
  241.     3. If you plan to use the Code Base source files, insert the Code
  242.        Base source diskette in "Drive A:" and copy the source files to
  243.        the appropriate source directory.
  244.  
  245.        Example:
  246.  
  247.            COPY  A:\*.C  C:\MSC
  248.  
  249.        Then place the Header, Example and Source Disk and copy the
  250.        remaining source files from subdirectory "source".
  251.  
  252.        Example:
  253.  
  254.            COPY  A:\SOURCE\*.C  C:\MSC
  255.  
  256.     Run "d4learn"
  257.  
  258.        To help learn Code Base, program "d4learn" has been included it
  259.        the 'example' subdirectory of the Header, Source and Example
  260.        diskette. Using pulldown menus, a Code Base routine is selected.
  261.        After "d4learn" has prompted for the routine parameters, the
  262.        routine is executed and the result is displayed.
  263.  
  264.        Hint:
  265.  
  266.            Source code for program "d4learn.exe" is contained in file
  267.            "d4learn.c" in the same subdirectory. This program, as well as
  268.            the programs in files 'w4example.c', 'x4multi.c',
  269.            'c4convert.c' and 'd4example.c' are good examples of how to
  270.            call Code Base routines. Very high level Code Base routines
  271.            contained in files 'x4list.c', 'x4edit.c', and 'x4.c' can also
  272.            be used as examples.
  273.  
  274.  
  275.     Using Code Base with Turbo C
  276.  
  277.        In order to use the Code Base library "T4.LIB" in Turbo C's
  278.        interactive environment, a "project" file is needed. The project
  279.        file "D4LEARN.PRJ", used to create program "D4LEARN.EXE", is on
  280.        the Code Base TC library diskette. It contains the following two
  281.        lines:
  282.  
  283.            D4LEARN.C
  284.            T4.LIB
  285.  
  286.        In addition, there is a file "TURBOC.CFG" which specifies options
  287.        for the "TCC" turbo compiler. This file should contain the
  288.        following line:
  289.  
  290.            -LC:\TC\LIB  -IC:\TC\INCLUDE   -ml -c -DTURBO -N
  291.  
  292.        This line specifies the library directory, the include directory,
  293.        the large memory model, to compile only, and defines the "TURBO"
  294.        switch. The "TURBO" switch specifies to use any Turbo C specific
  295.        source code.  Code Base source code uses the "TURBO" switch in
  296.        "#ifef" and "#ifndef" preprocessor directives to the compiler.
  297.  
  298.        When using the Turbo C interactive environment, make sure to
  299.        specify the correct memory model. If problems, such as obscure
  300.        undefined externals, occur during linking, try rebuilding the Code
  301.        Base library using the same copilation options as you normally use.
  302.  
  303.        The Turbo C default stack size is 3000 bytes. When working with
  304.        large index files, it is safest to increase the maximum by adding
  305.        the following line of code to the top of your program:
  306.  
  307.            extern unsigned  _stklen = 1000 ;
  308.  
  309.  
  310.  
  311.     Using Code Base with Quick C
  312.  
  313.        In order to use the Code Base library "M4.LIB" in Quick C's
  314.        interactive environment, it is necessary to use "MAKE" files. If
  315.        Quick C 1.0 is being used, it is also necessary to build a custom
  316.        Code Base library. To build a make file to compile and link
  317.        program "D4LEARN.EXE", add the files "D4LEARN.C" AND "M4.LIB"
  318.        using the Quick C menu options.
  319.  
  320.        Make sure that the large memory model is specified and extra stack
  321.        space is allocated. It is safest to use about 10K of stack space.
  322.        These are also menu options in the Quick C interactive environment.
  323.  
  324.        The Quick C command line compiler "QCL.EXE" is used in the same
  325.        manner as the Microsoft C compiler "CL.EXE". Refer to "Using Code
  326.        Base with Microsoft C".
  327.  
  328.  
  329.     Using Code Base with Microsoft C
  330.  
  331.        When compiling with "CL.EXE" command line compiler, specify the
  332.        large memory model, and extra stack space.
  333.  
  334.        Example:
  335.  
  336.            CL  /AL  D4LEARN*.C  /link  M4.LIB  /STACK:1000
  337.  
  338.        Refer to the compiler's user's guide for compelte information on
  339.        compiling and linking options.
  340.  
  341.  
  342.     Creating a Code Base Application
  343.  
  344.        In Code Base application source files, the following "#include"
  345.        directives are often used:
  346.  
  347.            #include  <d4base.h>
  348.            #include  <w4.h>
  349.  
  350.        If you have placed the Code Base header files in your source
  351.        directory rather than your include directory, use the following
  352.        "#include" directives instead:
  353.  
  354.            #include  "d4base.h"
  355.            #include  "w4.h"
  356.  
  357.        File 'd4base.h' defines structures and prototypes for Code Base's
  358.        data management routines. 'w4.h' defines the structure and
  359.        prototypes for Code Base's screen management routines.
  360.  
  361.  
  362.  
  363.     Example:
  364.  
  365.         /* This example is in file "d4example.c" */
  366.  
  367.         #include    "d4base.h"
  368.         #include    "w4.h"
  369.  
  370.         #ifdef TURBO
  371.         extern unsigned     _stklen = 1000 ;
  372.         #endif
  373.  
  374.         main()
  375.         {
  376.         int     j ;
  377.         long    ref ;
  378.  
  379.         /* Initialize Code Base and clear the screen */
  380.         d4init() ;
  381.         w4clear( -1 ) ;
  382.  
  383.         /* Open the database */
  384.         if ( d4use( "d4learn" ) < 0 )
  385.             exit ( 1 ) ;
  386.  
  387.         w4( 0,5, "D4LEARN.DBF  Field Names: " ) ;
  388.         for( j=1; j <= f4num_fields() ; j++ )
  389.         {
  390.             ref = f4j_ref( j ) ;
  391.  
  392.             /* Display the field name */
  393.             w4( j,8, f4name( ref ) ) ;
  394.         }
  395.  
  396.         w4cursor( j,0 ) ;
  397.  
  398.         w4exit( 0 ) ;
  399.         }
  400.  
  401.  
  402.  
  403.  
  404. ROUTINE DESCRIPITIONS
  405.  
  406.    There is a description of all of Code Base's exteranl routines which could
  407.    be called from an user's program.
  408.  
  409.    To use the database management portion of Code Base effectively, it is best
  410.    to be familiar with all the database and field routines, and a few of the
  411.    index file routines.  In addition, the extended routines are important for
  412.    those who wish to use the relations and filters.
  413.  
  414.    For screen management, consult the windowing, menuing and get routines.
  415.    First learn how to use the windowing routines.  Menuing and get routines
  416.    build upon the windowing to allow capablities such as pulldown menus and
  417.    full screen data entry.
  418.  
  419.    The 'conversion', 'utility', 'memory handling' and 'expression evaluation'
  420.    routines could be of general use to any applications programmer.
  421.  
  422.    Those wishing a quick overview of the Code Base routines could read the
  423.    routine section introductions and the experiment with program 'd4learn'.
  424.  
  425.  
  426.  
  427. CONVERSION ROUTIONS
  428.  
  429.    Conversion routines change information from one format to another.
  430.  
  431.  
  432. c4atod
  433.  
  434.    Usage
  435.           double  c4atod( (char *) str, (int) len_str )
  436.  
  437.    Description
  438.           'c4atod' converts an ASCII string of a specific length into
  439.           a '(double)'.
  440.  
  441.    Return
  442.           The converted result.
  443.  
  444.    Example
  445.           doub_result = c4atod( " 67.3", 5) ;
  446.  
  447.  
  448. c4atoi
  449.  
  450.    Usage
  451.           int  c4atoi( (char *) str, (int)  len_str)
  452.  
  453.    Description
  454.           'c4atoi' converts an ASCII character sting of a specified
  455.           length into an integer.
  456.  
  457.    Return
  458.           The converted integer result.
  459.  
  460.  
  461. c4atol
  462.  
  463.    Usage
  464.           int  c4atol( (char *) str, (int)  len_str)
  465.  
  466.    Description
  467.           A character sting of a specified length into an long integer.
  468.  
  469.    Return
  470.           The converted long integer result.
  471.  
  472.  
  473. c4dtoa
  474.  
  475.    Usage
  476.           char *  c4dtoa( (double) doub_value, (int) len, (int) dec )
  477.  
  478.    Description
  479.           'c4dtoa' converts a '(double)' into a character string.
  480.           This string will be formatted according to the specified
  481.           length and number of decimals.  If there is an overflow,
  482.           the string will be filled with asterisks ('*').
  483.  
  484.    Return
  485.           A pointer to an internal static buffer containing the
  486.           converted string is returned.
  487.  
  488.  
  489. c4dtok
  490.  
  491.    Usage
  492.           int c4dtok( (int) index_ref, (double) doub_val,
  493.                   (char *) key_val )
  494.  
  495.    Description
  496.           'c4dtok' is used in Clipper compatible programs, when
  497.           working with Numeric keys, to convert a '(double)' into an
  498.           ASCII charater string.  This string will be formatted for
  499.           use with Code Base index file routines such as 'i4seek'.
  500.  
  501.    Parameters
  502.           Name        Use
  503.  
  504.           index_ref   The index file reference number.
  505.  
  506.           double_val  The 'double' to be converted.
  507.  
  508.           key_val     A pointer to where the converted result should
  509.                   be placed. The buffer length must be greater
  510.                   than the index file key length. In general,
  511.                   this will never be greater than 32 characters.
  512.  
  513.    Return
  514.           Value       Meaning
  515.  
  516.            0          Sucess
  517.  
  518.           -1          Error
  519.  
  520.  
  521. c4dt_dbf
  522.  
  523.    Usage
  524.           void c4dt_dbf( (char *) dbf_date, (double *) index_date )
  525.  
  526.    Description
  527.           In index files dates are stored as a double and in
  528.           databases they are stored as an ASCII string.
  529.  
  530.           'c4dt_dbf' converts a date from index file format to
  531.           database format.
  532.  
  533.    Parameters
  534.           Name        Use
  535.  
  536.           index_date  Points to the index file format date. This is
  537.                   the julian day as a (double).
  538.  
  539.           dbf_date    Points to storage where the result is to be
  540.                   placed. The format is "CCYYMMDD" or century,
  541.                   year, month, day. Consequenlty, 8 bytes of
  542.                   memory must be available.
  543.  
  544.  
  545. c4dt_format
  546.  
  547.    Usage
  548.           char *  c4dt_format( (char *) dbf_date, (char *) picture )
  549.  
  550.    Description
  551.           Converts between the database date format and other date
  552.           formats.
  553.  
  554.    Parameters
  555.           Name        Use
  556.  
  557.           dbf_date    This is the database date which is an ASCII
  558.                   string of lenght 8 formatted "CCYYMMDD"
  559.                   (century, year, month, day).
  560.  
  561.           picture     The picture specifies how the date is to be
  562.                   formatted.
  563.  
  564.                   Examples:
  565.  
  566.                   YY.MM.DD
  567.                   CCYY.MM.DD
  568.                   MM/DD/YY
  569.                   DD-MM/YY
  570.                   DD-MM/CCYY
  571.                   MMM DD/YY
  572.  
  573.                   The 'Y', 'M' and 'D' characters specify the
  574.                   year, month, and day respectively. If there
  575.                   are more than 2 'M' characters, a Character
  576.                   reprensentation of the month is returned.
  577.  
  578.    Returns
  579.           A pointer to an internal static buffer is returned. This
  580.           buffer contains the converted result.
  581.  
  582.    Example
  583.           /* '*result_ptr' will contain "88.01.30" */
  584.           result_ptr = cdt_format("19880130", "YY.MM.DD");
  585.  
  586.  
  587. c4dt_index
  588.  
  589.    Usage
  590.           int  cd4t_index( (char *) dbf_date, (double *) index_date )
  591.  
  592.    Description
  593.           'c4dt_index' is the opposite of routine 'c4dt_dbf'. Dates
  594.           are converted from database format to index file format.
  595.  
  596.    Parameters
  597.           Name        Use
  598.  
  599.           dbf_date    Points to database date to be converted. The
  600.                   format is "CCYYMMDD" or century, year, month,
  601.                   day.
  602.  
  603.           index_date  Points to the index file format date where the
  604.                   result is to be placed. This is the julian_day
  605.                   as a (double).
  606.  
  607.    Returns
  608.           Value       Meaning
  609.  
  610.            0          Success.
  611.  
  612.           -1          Illegal Date (No Error Displayed).
  613.  
  614.           -2          Null Date (Blank Information).
  615.  
  616.  
  617. c4dt_unformat
  618.  
  619.    Usage
  620.           char *  c4dt_unformat( (char *) date_data, (char *) picture )
  621.  
  622.    Description
  623.           Converts to the database date format from a specified date
  624.           format. If the supplied date dose not contain complete date
  625.           information, the default century is '1990', the default
  626.           year is '80', the default year is '80', the default month
  627.           is January, and the default day of the month is '1'.
  628.  
  629.           The database date format is "CCYYMMDD".
  630.  
  631.    Parameters
  632.           Name        Use
  633.  
  634.           date_data   This is the date information.
  635.  
  636.           picture     The picture specifies the format of the date
  637.                   data.
  638.  
  639.    Returns
  640.           A pointer to an internal static buffer is returned. This
  641.           buffer contains the converted database format date.
  642.  
  643.    See Also
  644.           c4dt_format
  645.  
  646.  
  647. c4encode
  648.  
  649.    Usage
  650.           void  c4encode( (char *) to, (char *) from, (char *) t_to,
  651.                   (char *) t_from )
  652.  
  653.    Description
  654.           Characters are moved from the string 'from' to the string
  655.           'to'. The format of the result in 'to' is specified by
  656.           template 't_to'. The format of the source string 'from' is
  657.           specified by the template in 't_from'.
  658.  
  659.           There are nor predetermined formatting charaters. However,
  660.           if a character in 't_from' matches a character in 't_to',
  661.           the corresponding character in 'from' is moved to the
  662.           corresponding position in 'to'.
  663.  
  664.    Parameters
  665.           Name        Use
  666.  
  667.           to          The destination of the converted information.
  668.  
  669.           form        The information to be converted.
  670.  
  671.           t_to        A template of the destination formatting.
  672.  
  673.           t_from      A template of the source inforamtion.
  674.  
  675.    Example
  676.           /* The result put into 'to' will be " 3 2 1" */
  677.           c4encode( to, "123", "C B A", "ABC" );
  678.  
  679.    Note
  680.           As in the example, any charaters in 't_to' which do not
  681.           match characters in 't_from' are copied to corresponding
  682.           position in 'to'.
  683.  
  684.  
  685. c4ltoa
  686.  
  687.    Usage
  688.           char *  c4ltoa( (long) long_value, (char *) result_ptr,
  689.           (int) result_len )
  690.  
  691.    Description
  692.           A '(long)' is converted into character format as specified
  693.           by the length parameter. The result character value is
  694.           right justified inside the allotted space.
  695.  
  696.    Parameters
  697.           Name        Use
  698.  
  699.           long_value  The value to be converted.
  700.  
  701.           result_ptr  A pointer to where the result should be
  702.                   returned. At least 'result_len' bytes worth of
  703.                   storage should be allocated by the caller.
  704.  
  705.           result_len  This is the length of the result string. If
  706.                   'result_len' is less than zero, any preceding
  707.                   characters are filled by zeros.
  708.  
  709.    Return
  710.           The return is parameter 'result_ptr' which is a '(char *)'
  711.           pointer to the result.
  712.  
  713.    Hint
  714.           Other numeric data types can be converted by 'c4ltoa' by
  715.           casting them as a '(long)'.
  716.  
  717.    Note
  718.           A null terminating character is NOT placed at the end of
  719.           the converted result. Only 'result_len' characters are
  720.           modified.
  721.  
  722.    Example
  723.           char *  test_routine( value, ptr )
  724.           int     value;
  725.           char *  ptr;
  726.           {
  727.                c4ltoa( (long) value, ptr, 10 );
  728.                return( ptr );
  729.           }
  730.  
  731.  
  732.  
  733. c4key
  734.  
  735.    Usage
  736.           void  c4key( (char *) in_key, (char *) out_str,
  737.                   (char) key_type )
  738.  
  739.    Description
  740.           Routine 'c4key' converts the key value returned by 'i4eval'
  741.           into printable character format.
  742.  
  743.    Parameters
  744.           Name        Use
  745.  
  746.           in_key      A pointer to the index file key.
  747.  
  748.           out_str     A pointer to a buffer where the result should
  749.                   be returned. Make sure 'out_str' points to 64
  750.                   (or more) bytes of memory.
  751.  
  752.           key_type    The type of the index file. This value may is
  753.                   returned by routine 'i4type()'.
  754.  
  755.  
  756.  
  757. c4trim_n
  758.  
  759.    Usage
  760.           void  c4trim_n( (char *) str, (int) n_ch )
  761.  
  762.    Description
  763.           Routine 'c4trim_n' trims the blanks off of string 'str'. A
  764.           null character is placed in the last byte in the string to
  765.           ensure it is null terminated.
  766.  
  767.    Parameters
  768.           Name        Use
  769.  
  770.           str         A pointer to the string.
  771.  
  772.           n_ch        The number of bytes of memory declared for the
  773.                   sting.
  774.  
  775.  
  776.  
  777.  
  778. DATABASE ROUTINES
  779.  
  780.    The database routines correspond to high level dBASE commands. They are
  781.    use to store and retrive information from database files.
  782.  
  783.    Database routines use an inplicit selected database. This selected
  784.    database is the last database opened or the database last selected with
  785.    routine "d4select". Consequently, it is possible to have many databases
  786.    open at on time.
  787.  
  788.    Each database also has a current record number, a record buffer, and a
  789.    selected index file. Whenever a routine uses or changes either the current
  790.    record or the selected index file, it will be noted in the database
  791.    routine documentation.
  792.  
  793.    The various record positioning routines such as 'd4bottom' and 'd4go' read
  794.    the new current record into the buffer. Routine 'd4write' writes or
  795.    appends the record buffer. To access and modify the record buffer, refer
  796.    to the field routines.
  797.  
  798.    WORKING WITH MULTIPLE FILES
  799.  
  800.    To work with more than one database, save the database refernece number
  801.    returned by 'd4use'. Then use 'd4select' to switch between databases with
  802.    the appropriate database reference number as a parameter. Similarily, the
  803.    reference number returned by 'i4open' can be use by routine 'i4select'.
  804.  
  805.  
  806. d4bottom
  807.  
  808.    Usage
  809.           int  d4bottom()
  810.  
  811.    Description
  812.           Go to the bottom of the database using the selected index
  813.           file. If no index file is selected, go to the last record
  814.           of the database.
  815.  
  816.    Returns
  817.           Value       Meaning
  818.  
  819.            0          Success.
  820.  
  821.            3          End of File.
  822.  
  823.           -1          Error.
  824.  
  825.  
  826.    Locking
  827.           The bottom record and any selected index file are locked.
  828.  
  829.    Example
  830.           if ( d4bottom() < 0 )
  831.               return -1;
  832.  
  833.  
  834. d4close
  835.  
  836.     Usage
  837.           int  d4close()
  838.  
  839.     Description
  840.           Closes the selected database and all of its index files.
  841.  
  842.     Returns
  843.           Value       Meaning
  844.  
  845.            0          Success.
  846.  
  847.           -1          There was an error closing one of the files.
  848.  
  849.    Example
  850.           /*    Source Code for 'd4close_all' */
  851.  
  852.           d4close_all()
  853.           {
  854.               /*  'v4last_base' is an internal Code Base variable. It
  855.               contains the database reference number of the last
  856.               opened database. If no databases are open, it is
  857.               '(int) -1'.  */
  858.  
  859.               while( v4last_base >= 0 )
  860.               if ( d4close () < 0 ) return 1;
  861.  
  862.               return 0;
  863.           }
  864.  
  865.  
  866. d4close_all
  867.  
  868.    Usage
  869.           int d4close_all()
  870.  
  871.    Description
  872.           All open database, index, and memo files are closed.
  873.  
  874.    Returns
  875.           Value       Meaning
  876.  
  877.            0          Success.
  878.  
  879.           -1          There was an error closing one of the files.
  880.  
  881.    Locking
  882.           Unlocks the databases and index files.
  883.  
  884.  
  885. d4create
  886.  
  887.    Usage
  888.           int  d4create( (char *) name, (int) n_fields,
  889.                   (FIELD *) fields, (int) safety)
  890.  
  891.    Description
  892.           A database is created, opened and selected. If the database
  893.           is already open and safety is off, it will be closed,
  894.           deleted, and then created once more according to the
  895.           parameter specifications.
  896.  
  897.    Parameters
  898.           Name        Use
  899.  
  900.           name        The file name to be created.
  901.  
  902.           num_fields  The number of fields in the database.
  903.  
  904.           fields      A pointer to an array defining the database
  905.                   fields. There are 'num_fields' entries in this
  906.                   array. The 'offset' portion of the field
  907.                   descripition is computed by the 'd4use'
  908.                   routine. Refer to the example.
  909.  
  910.           safety      A logical (int) specifying whether any existing
  911.                   file with the same name should be removed:
  912.                  0 - Remove existing file.
  913.                  1 - Return with error return if the file
  914.                      exists.
  915.  
  916.    Note
  917.           As in the example, it is possible to create databases with
  918.           six different field types:
  919.  
  920.           Type Code   Meaning
  921.  
  922.             C         Character Field. The number of decimals is
  923.                   always zero. The dBASE maximum field width is
  924.                   255. However, if the greater than 255, the
  925.                   database will still be Clipper compatible.
  926.  
  927.             N         Numeric Field. This field t;ype has a maximum
  928.                   width of 17. If the number of decimals is
  929.                   greater than zero, is should be at least two
  930.                   less than field width.
  931.  
  932.             F         Floating Point Field. Code Base treats floating
  933.                   point fields the same as numeric fields.
  934.  
  935.             D         Date Field. The width of a date filed is
  936.                   always 8.
  937.  
  938.             L         Logical Field. The width of a logical field is
  939.                   always 1. It can have a true or false value.
  940.  
  941.             M         Memo Field. The width of a memo field is always
  942.                   10. If the database has one or more memo
  943.                   fields, a separate memo file is created. Memo
  944.                   fields are used to store variable length text.
  945.                   Refer to the memo file moudule.
  946.  
  947.    Returns
  948.           Value       Meaning
  949.  
  950.           >= 0        The database reference number corresponding to
  951.                   the database.
  952.  
  953.           -1          Error.
  954.  
  955.    Locking
  956.           Locks record one and the record count bytes.
  957.  
  958.    Example
  959.           #include  <d4base.h>
  960.  
  961.           static FIELD  fields[] =
  962.           {
  963.               /* Field Name,   Type, Width, Dec, Offset */
  964.                {"FIRST_NAME",  'C',  25,    0,   0},
  965.                {"BIRTH_DATE",  'D',   8,    0,   0},
  966.                {"AMOUNT    ",  'N',  12,    2,   0},
  967.                {"FLOAT_VAL ",  'F',  14,    4,   0},
  968.                {"TRUE_FALSE",  'L',   1,    0,   0},
  969.                {"MEMO_INFO ",  'M',  10,    0,   0}
  970.           };
  971.  
  972.           int create_base()
  973.           {
  974.               return( d4create( "BASE.DBF", 4, fields, 1) );
  975.           }
  976.  
  977.  
  978. d4delete
  979.  
  980.    Usage
  981.           int  d4delete( (long) record_number)
  982.  
  983.    Descripition
  984.           Marks the specified record for deletion. The record is
  985.           read, the deletion flag is changed to an asterisk ('*') and
  986.           the record is written.
  987.  
  988.    Returns
  989.           Value       Meaning
  990.  
  991.            1          Record Dose Not Exist.
  992.  
  993.            0          Success.
  994.  
  995.           -1          Error.
  996.  
  997.    Locking
  998.           The record is locked.
  999.  
  1000.    Hint
  1001.           If the reocrd has already been read into the record buffer,
  1002.           and fields have been modified in memory, delete the record
  1003.           directly. This is done by changing the first byte of the
  1004.           record buffer to an asterisk ('*'). Then record is written
  1005.           to disk:
  1006.  
  1007.           /*  Read from disk into the record buffer  */
  1008.           d4go( record_no );
  1009.  
  1010.           /*  Modify a field in memory */
  1011.           f4replace( field_ref, "New Data" );
  1012.  
  1013.           /*  Mark the record for deletion. 'f4record' returns a
  1014.           pointer to the record buffer. The first byte of this buffer
  1015.           is the deletion flag.  */
  1016.  
  1017.           *f4record() = '*' ;
  1018.  
  1019.           /*  Write the record to disk.  */
  1020.           d4write( record_no );
  1021.  
  1022.    Example
  1023.           d4delete(1L) ; /* Mark Record 1 for deletion */
  1024.  
  1025.  
  1026. d4deleted
  1027.  
  1028.    Usage
  1029.           int  d4deleted()
  1030.  
  1031.    Description
  1032.           Specifies whether the current record is marked for
  1033.           deletion. If there is no current record, the result is
  1034.           undefined.
  1035.  
  1036.    Returns
  1037.           Value       Meaning
  1038.  
  1039.           0           The record is NOT marked for deletion.
  1040.  
  1041.           1           The record is marked for deletion.
  1042.  
  1043.    Locking
  1044.           No locking.
  1045.  
  1046.    Example
  1047.           if ( d4deleted() ) delete_work() ;
  1048.           /* The above code is equivalent to:
  1049.              if ( * (char *) f4record() == '*' )
  1050.               delete_work() ;
  1051.           */
  1052.  
  1053. d4go
  1054.  
  1055.    Usage
  1056.           int  d4go( (long) record_number )
  1057.  
  1058.    Description
  1059.           Reads the specified record into the record buffer. This
  1060.           record also becomes the current record number. If the
  1061.           record does not exist, the record buffer is initialized to
  1062.           blanks.
  1063.  
  1064.    Returns
  1065.           Value       Meaning
  1066.  
  1067.            1          The record does not exist.
  1068.  
  1069.            0          Success.
  1070.  
  1071.           -1          Error.
  1072.  
  1073.    Locking
  1074.           The record is locked.
  1075.  
  1076.    Hint
  1077.           The database buffer may be accessed using the "Field"
  1078.           routines.
  1079.  
  1080.    Example
  1081.           rc = d4go( 2L ) ;  /* Go to record 2 */
  1082.  
  1083.  
  1084. d4init
  1085.  
  1086.    Usage
  1087.           int  d4init()
  1088.  
  1089.    Description
  1090.           'd4init' initializes various Code Base variables. When
  1091.           necessay, routines 'd4use' and 'd4create' will call
  1092.           'd4init' automactically.
  1093.  
  1094.    Note
  1095.           The first time one of either 'd4init' or 'w4define' is
  1096.           called, a default window is defined. This window, which
  1097.           contains the entire screen, is used by 'u4error' to display
  1098.           error messages.
  1099.  
  1100.    Return
  1101.           Value       Meaning
  1102.  
  1103.            0          Success.
  1104.  
  1105.           -1          Out of Memory.
  1106.  
  1107.    Example
  1108.           #include <d4base.h>
  1109.  
  1110.           main()
  1111.           {
  1112.               d4init();  /* Initialize memory structures */
  1113.               .
  1114.               .
  1115.               exit(0) ;
  1116.           }
  1117.  
  1118. d4init_memory
  1119.  
  1120.    Usage
  1121.           int  d4init_memory( (int) num_base, (int) num_index,
  1122.                   num_blocks, eval_space )
  1123.  
  1124.    Description
  1125.           'd4init_memory' can be used as a sophisticated replacement
  1126.           for 'd4init'. Use 'd4init_memory' to explicity specfiy
  1127.           inital memory allocation.
  1128.  
  1129.           Parameters 'num_base' and 'num_index' are not limits.
  1130.           However, if the exact number of index files and databases
  1131.           are specifed, no memory will be wasted and memory
  1132.           fragmentation will be reduced.
  1133.  
  1134.    Parameters
  1135.           Name        Use
  1136.  
  1137.           num_base    The number of databases to allocate memory for.
  1138.  
  1139.           num_index   The number of index files to allocate memroy for.
  1140.  
  1141.           num_blocks  The number of index file blocks to allocate
  1142.                   memory for. Blocks are used to buffer index
  1143.                   file data. If 'i4reindex' or 'i4index' are
  1144.                   called, this number should never be below
  1145.                   '(int) 10'.
  1146.  
  1147.                   For maximum speed, this number can be as high
  1148.                   as '(int) 100' when using dBASE index file
  1149.                   compatibility and '(int) 50' when using Clipper
  1150.                   index file compatibility. Note that these large
  1151.                   numbers are only feasable when using the
  1152.                   compact, large, or huge memory models.
  1153.  
  1154.           eval_space  This is the number of bytes of memory which are
  1155.                   allocated for the expression evaluation module.
  1156.                   The default 3k of memory is plenty for even
  1157.                   most complicated dBASE expressions. The
  1158.                   expression evaluation module will generate an
  1159.                   error message if too little memory is available.
  1160.  
  1161.    Returns
  1162.           Value       Meaning
  1163.  
  1164.            0          Success.
  1165.  
  1166.           -1          Out of memory. Unless 'u4error' is modified,
  1167.                   this is a critical error and will never occur.
  1168.  
  1169.    Example
  1170.           /* These are the defaults supplied by 'd4init' */
  1171.  
  1172.           d4init()
  1173.           {
  1174.               return( d4init_memory( 10, 10, 12, 3000) );
  1175.           }
  1176.  
  1177. d4lock
  1178.  
  1179.    Usage
  1180.           int  d4lock( (long) lock_code, (int) do_wait )
  1181.  
  1182.    Description
  1183.           'd4lock' is used to lock the selected database. The whole
  1184.           file may be locked, a specific record may be locked, or the
  1185.           record count bytes may be locked. If a record is already
  1186.           locked, locking another record automatically unlocks the
  1187.           first record.
  1188.  
  1189.           If you have already locked the specified portion of the
  1190.           database, 'd4lock' will detect this and return immediately
  1191.           with a succesfull return. In addition, if 'do_wait' is
  1192.           FALSE (0), 'd4lock' will return immediately; or, if
  1193.           'do_wait' is TRUE (non-zero), 'd4lock' will wait until the
  1194.           specified file portion is available, lock it, and then
  1195.           return successfully. For example, when the complete file is
  1196.           locked, any call to 'd4lock' will return successfully.
  1197.  
  1198.    Parameters
  1199.           Name        Value        Meaning
  1200.  
  1201.           lock_code   >0           Lock the Specified Record.
  1202.                   -1           Lock the Whole File.
  1203.                    0           Lock the Record Count Bytes.
  1204.  
  1205.  
  1206.           do_wait      0           Do not Wait.
  1207.                    1           Wait until Locked.
  1208.  
  1209.    Returns
  1210.           Value       Meaning
  1211.  
  1212.            0          Success.
  1213.  
  1214.            1          Record Does not Exist.
  1215.  
  1216.           -1          Error.
  1217.  
  1218.           -2          Locked by another user and 'do_wait' is zero.
  1219.  
  1220.    Example
  1221.           /* Wait for the entire file to be locked */
  1222.           rc = d4lock( -1L, 1 );
  1223.  
  1224. d4pack
  1225.  
  1226.    Usage
  1227.           int d4pack()
  1228.  
  1229.    Description
  1230.           'd4pack' removes all the records in the selected database
  1231.           which have been marked for deletion.
  1232.  
  1233.    Returns
  1234.           Value       Meaning
  1235.  
  1236.            0          Success.
  1237.  
  1238.           -1          Error.
  1239.  
  1240.    Locking
  1241.           The database and its index files are locked for the
  1242.           duration of the pack and then are all unlocked.
  1243.  
  1244.    See Also
  1245.           d4delete, d4recall
  1246.  
  1247.    Example
  1248.           d4delete( 2L );
  1249.           d4pack();
  1250.  
  1251.  
  1252. d4ptr
  1253.  
  1254.    Usage
  1255.           BASE *  d4ptr()
  1256.  
  1257.    Description
  1258.           Returns a pointer to the database structure which describes
  1259.           the currently selected database.
  1260.  
  1261.           If no database has been opened, '(BASE *) 0' is returned.
  1262.  
  1263.    Warning
  1264.           If any calls to 'd4use', 'd4close', or 'd4close_all' is
  1265.           made, this pointer becomes obsolete and 'd4ptr' must be
  1266.           called again.
  1267.  
  1268.    Example
  1269.           # include <d4base.h>
  1270.  
  1271.           /* Get the selected database's record length */
  1272.           int buffer_len()
  1273.           {
  1274.               return( d4ptr() ->buffer_len );
  1275.           }
  1276.  
  1277.  
  1278. d4recall
  1279.  
  1280.    Usage
  1281.           int  d4recall( (long) record_number )
  1282.  
  1283.    Description
  1284.           If the specifed record is marked for deletion, the mark is
  1285.           removed. The record is read into the record buffer, the
  1286.           deletion flag is changed into a blank character, and then
  1287.           the record is written again.
  1288.  
  1289.    Returns
  1290.           Value       Meaning
  1291.  
  1292.            1          No such record.
  1293.  
  1294.            0          Success.
  1295.  
  1296.           -1          Error reading or writing the database.
  1297.  
  1298.    Locking
  1299.           The record is locked.
  1300.  
  1301.    See Also
  1302.           d4delete, d4pack
  1303.  
  1304.    Example
  1305.           d4recall( 2L );
  1306.  
  1307.  
  1308. d4reccount
  1309.    Usage
  1310.           long  d4reccount()
  1311.  
  1312.    Description
  1313.           The number of records in the database is returned. This
  1314.           value is determined from the size of the file.
  1315.           Consequently, Code Base does not need to do any locking to
  1316.           do this operation.
  1317.  
  1318.    Returns
  1319.           Value       Meaning
  1320.  
  1321.           >= 0        The number of records in the database.
  1322.  
  1323.             -1        No database is selected.
  1324.  
  1325.    Locking
  1326.           None.
  1327.  
  1328.    Example
  1329.           /* Dump the contents of the database to the current window */
  1330.  
  1331.           for ( rec = 1L; rec <= d4reccount(); rec++ )
  1332.               w4( w4row() + 1, 0, f4record() );
  1333.  
  1334.  
  1335. d4recno
  1336.  
  1337.    Usage
  1338.           long  d4recno()
  1339.  
  1340.    Description
  1341.           The current number is returned.
  1342.  
  1343.    Returns
  1344.           Value       Meaning
  1345.  
  1346.           >= 1        The current record number.
  1347.  
  1348.              0        There is no current record number.
  1349.  
  1350.    Example
  1351.           /* Read the next record */
  1352.           d4go( d4recno() + 1L );
  1353.  
  1354.  
  1355. d4ref
  1356.  
  1357.    Usage
  1358.           int  d4ref( (char *) name )
  1359.  
  1360.    Description
  1361.           Returns a reference integer to a specified database. If no
  1362.           file extension is specified, '.DBF' is assumed. This is the
  1363.           same reference number which was returned when the database
  1364.           was orginally opened.
  1365.  
  1366.    Returns
  1367.           Value       Meaning
  1368.  
  1369.           >= 0        The database reference number.
  1370.             -1        The database is not open.
  1371.  
  1372.    Example
  1373.           d4select( d4ref( "ACCOUNT.DBF" ) );
  1374.  
  1375.  
  1376. d4seek
  1377.  
  1378.    Usage
  1379.           int  d4seek( (void *) search_string )
  1380.  
  1381.    Description
  1382.           d4seek searches using the selected index file. If no index
  1383.           file is selected, the last opened index file for the
  1384.           database is used. If the search string is located, 'd4go'
  1385.           is called to go to the associated record.
  1386.  
  1387.           When searching index files with date keys, a character
  1388.           string with a "CCYYMMDD" format is used.
  1389.  
  1390.           In addition, if the index file has a numeric key, use a
  1391.           pointer to a 'double' as a search parameter. When the
  1392.           search value is in character format, covert it into a
  1393.           double and then cast it's pointer as a '(void *)'. Refer to
  1394.           the examples below.
  1395.  
  1396.    Returns
  1397.           Value       Meaning
  1398.  
  1399.            0          The value was found.
  1400.  
  1401.            1          Inexact Find; if the seach value was found but
  1402.                   had fewer characters than the index file
  1403.                   keys, '(int) 1' is returned.
  1404.  
  1405.                   Example:
  1406.                  If "Jackson" was the index file key value,
  1407.                  'd4seek( "Jack" )' would locate "Jackson"
  1408.                  but would return '(int) 1' rather than
  1409.                  '(int) 0'.
  1410.  
  1411.                   This return is not possible for index files
  1412.                   with numeric or date keys.
  1413.  
  1414.            2          On Record After; If the search value is not
  1415.                   located, the record immediatley after the key
  1416.                   will be read and the return will be '(int) 2'.
  1417.  
  1418.            3          End of File; If the search value is greater
  1419.                   than any value in the index file, '(int) 3' is
  1420.                   returned.
  1421.  
  1422.           -1          Error.
  1423.  
  1424.    Locking
  1425.           The current index file and the located record are all locked.
  1426.  
  1427.    Examples
  1428.           void  search_examples()
  1429.           {
  1430.               double doub_srch ;
  1431.               int    rc ;
  1432.  
  1433.               /* Search for a Date Value */
  1434.               i4select( i4ref( "DATE.NDX" ) ) ;
  1435.               rc = d4seek( "19880130" ) ;
  1436.  
  1437.               /* Search for a Numeric value */
  1438.               i4select( i4ref( "NUMBER.NDX" ) ) ;
  1439.               doub_srch = c4atod( "195.3", 5) ;
  1440.               rc = d4seek( &doub_srch ) ;
  1441.  
  1442.               /* Search for a Character String. The index file key
  1443.              expression could be "UPPER(NAME)". Using the 'UPPER'
  1444.              function makes the search case insensitive.
  1445.               /*
  1446.               i4select( i4ref( "NAME.NDX" ) ) ;
  1447.               rc = d4seek( "JACK" ) ;
  1448.  
  1449.               /* Search for Last Name plus First Name. In this
  1450.              example, the index file key expression is
  1451.              "LAST+FIRST". LAST is a 15 character field and FIRST
  1452.              is a 10 character field. The complete search key is
  1453.              provided. Consequently, 'd4seek' will return with an
  1454.              exact find if the record is located.
  1455.               /*
  1456.               i4select( i4ref( "FULL_NAME" ) ) ;
  1457.               rc = d4seek( "SMITH          JOHN      " );
  1458.           }
  1459.  
  1460. d4select
  1461.  
  1462.    Usage
  1463.           int  d4select( (int) base_ref );
  1464.  
  1465.    Description
  1466.           Select the database which the other database routines will
  1467.           act on. The 'base_ref' is the reference number which is
  1468.           returned by the 'd4use' and 'd4ref' routines. If 'base_ref'
  1469.           is '(int) -1', no selection is made. Regardless, the
  1470.           previously selected database reference number is returned.
  1471.  
  1472.    Returns
  1473.           Value       Meaning
  1474.  
  1475.           >= 0        The previous database reference number.
  1476.  
  1477.             -1        No database was previously selected.
  1478.  
  1479.    Example
  1480.           /* Initialize some variables */
  1481.           invoice_ref = d4use( "INVOICE" ) ;
  1482.           invoice_name = f4ref( "NAME" ) ;
  1483.  
  1484.           customer_ref = d4use( "CUSTOMER" ) ;
  1485.           name_index_ref = i4open( "CUS_NAME" ) ;
  1486.               .
  1487.               .
  1488.           /* Position to the top of "INVOICE.DBF". Save the current
  1489.              database's reference number.
  1490.           */
  1491.           prev_ref = d4select( invoice_ref ) ;
  1492.           d4top() ;
  1493.  
  1494.           /* Lookup field "NAME" from "INVOICE.DBF" in index file
  1495.              "CUS_NAME.NDX" of database "CUSTOMER.DBF".
  1496.           */
  1497.           d4select( customer_ref ) ;
  1498.           i4select( name_index_ref ) ;
  1499.           d4seek( f4str( invoice_name ) ) ;
  1500.  
  1501.           /* Select the previous database */
  1502.           d4select( prev_ref ) ;
  1503.  
  1504. d4skip
  1505.  
  1506.    Usage
  1507.           int  d4skip( (long) num_records )
  1508.  
  1509.    Description
  1510.           This routine skips 'num_records' from the current record
  1511.           number. The selected index file will be used. If no index
  1512.           file is selected, record number ordering will be used.
  1513.  
  1514.           After the new record is located, it will be read into the
  1515.           record buffer and will become the current record.
  1516.  
  1517.    Returns
  1518.           Value       Meaning
  1519.  
  1520.            0          Success.
  1521.  
  1522.            1          Skipped to top of the file.
  1523.  
  1524.            3          Skipped to the end of the file.
  1525.  
  1526.           -1          Error.
  1527.  
  1528.    Locking
  1529.           The current index file and the new record are locked.
  1530.  
  1531.    Example
  1532.           rc = d4skip( -1L ) ; /* Skip back one record */
  1533.  
  1534.  
  1535. d4top
  1536.  
  1537.    Usage
  1538.           int  d4top()
  1539.  
  1540.    Description
  1541.           The top record in the index file is read. If no index file
  1542.           is selected, this will be record one.
  1543.  
  1544.    Returns
  1545.           Value       Meaning
  1546.  
  1547.            0          Success.
  1548.  
  1549.            3          End of File(The database is empty.)
  1550.  
  1551.           -1          Error.
  1552.  
  1553.    Locking
  1554.           The top record is locked. If and index file has been
  1555.           selected, it will also be locked.
  1556.  
  1557.    Example
  1558.           if ( (rc = d4top() ) < 0 )   return -1 ;
  1559.           if ( rc == 3 )  do_eof_action() ;
  1560.  
  1561.  
  1562. d4unlock
  1563.  
  1564.    Usage
  1565.           int  d4unlock( (long) lock_code )
  1566.  
  1567.    Description
  1568.           'd4unlock' removes locks on the currently selected database
  1569.           as specified by the parameter. If the specified locks do
  1570.           not exist, 'd4unlock' does nothing and returns 'Success'.
  1571.  
  1572.    Parameter
  1573.           Value       Meaning
  1574.  
  1575.            1          If a specific record is locked, it will be
  1576.                   unlocked.
  1577.  
  1578.           -1          Unlock all locks on the currently selected
  1579.                   database and its index files.
  1580.  
  1581.            0          Unlock only the Record Count Bytes.
  1582.  
  1583.    Return
  1584.           Value       Meaning
  1585.  
  1586.            0          Success.
  1587.  
  1588.           -1          Error.
  1589.  
  1590.    Example
  1591.           /* Unlock the selected database and its index files */
  1592.           d4unlock( -1L ) ;
  1593.  
  1594.  
  1595. d4use
  1596.  
  1597.    Usage
  1598.           int  d4use( (char *) name )
  1599.  
  1600.    Description
  1601.           Opens and selects the specified database. If no file
  1602.           extension is specified, ".DBF" is assumed.
  1603.  
  1604.    Returns
  1605.           Value       Meaning
  1606.  
  1607.           >= 0        The database reference number corresponding to
  1608.                   the database. This number can be used as a
  1609.                   parameter to routine "d4select".
  1610.  
  1611.             -1        Error.
  1612.  
  1613.    Locking
  1614.           Unlocked on completion.
  1615.  
  1616.    Example
  1617.           account_ref = d4use( "ACCOUNT.DBF" ) ;
  1618.  
  1619.           /* Note that the two backslashes are interpreted by the 'C'
  1620.              compiler as a single backslash.
  1621.           */
  1622.           cust_ref = d4use( "C:\\data\\customer" );
  1623.  
  1624.  
  1625. d4use_excl
  1626.  
  1627.    Usage
  1628.           int  d4use_excl( (char *) name )
  1629.  
  1630.    Description
  1631.           This routine is identical to 'd4use' except that it locks a
  1632.           database after it has been opened.
  1633.  
  1634.    Hint
  1635.           If you are writing a single user application, use
  1636.           'd4use_excl' rather than 'd4use'.  In response, the program
  1637.           will execute slightly faster.
  1638.  
  1639.    Example
  1640.           d4use_excl( name )
  1641.           char *name ;
  1642.           {
  1643.               int rc ;
  1644.               if ( (rc = d4use(name) ) < 0 )  return -1 ;
  1645.               if ( d4lock( -1L,1 ) < 0 )  return -1 ;
  1646.               return( rc ) ;
  1647.           }
  1648.  
  1649.  
  1650. d4write
  1651.  
  1652.    Usage
  1653.           int  d4write( (long) record_number )
  1654.  
  1655.    Description
  1656.           'd4write' writes the record buffer to the specified record
  1657.           number. All opened index files are maintained. If the
  1658.           'record_number' is 0L or is greater than the number of
  1659.           records in the database, the record buffer is appeneded to
  1660.           the database.
  1661.  
  1662.    Returns
  1663.           Value       Meaning
  1664.  
  1665.            0          Success.
  1666.  
  1667.           -1          Error.
  1668.  
  1669.           -2          There was a duplicate key for an unique key
  1670.                   index file. Consequently, the record was not
  1671.                   written.
  1672.  
  1673.                   By default, external variable 'v4unique_error'
  1674.                   is set to '(int) 1'. If this variable is
  1675.                   changed to '(int) 0', routine d4write will
  1676.                   never return '(int) -2'. Instead, the record is
  1677.                   written, no entry is made in the unique key
  1678.                   index file, and '(int) 0' is returned.
  1679.  
  1680.    Locking
  1681.           If the record already exists, it is locked; if the record
  1682.           is being appended, no locking is necessary. All of the
  1683.           index files are locked before they are updated.
  1684.  
  1685.    Example
  1686.           /*  Append a blank record */
  1687.  
  1688.           /* Blank the record buffer */
  1689.           d4go( OL ) ;
  1690.  
  1691.           /* Append the record in the record buffer to the end of the
  1692.              database
  1693.           */
  1694.           d4write( OL );
  1695.  
  1696.  
  1697. d4zap
  1698.  
  1699.    Usage
  1700.           int  d4zap( (long) start_rec, (long) end_rec )
  1701.  
  1702.    Description
  1703.           The stated range of records are removed. If "end_rec" is
  1704.           less than "start_rec", no records are removed. All index
  1705.           files are re-indexed. Record number ordering is always used.
  1706.  
  1707.    Returns
  1708.           Value       Meaning
  1709.  
  1710.            0          Success.
  1711.  
  1712.           -1          Error.
  1713.  
  1714.    Locking
  1715.           The database and index files are locked while 'd4zap' is
  1716.           executing and then are unlocked.
  1717.  
  1718.    Warning
  1719.           Be careful when using this routine as it can immediately
  1720.           remove large numbers of records.
  1721.  
  1722.    Example
  1723.           /* Zap the entire database */
  1724.           d4zap( 1L, d4reccount() );
  1725.  
  1726.  
  1727.  
  1728. EXPRESSION EVALUATION ROUTINES
  1729.  
  1730.    It is necessary to evaluate dBASE expressions. For Example, 'i4index' is
  1731.    passed a dBASE expression as a parameter. The appendices on expressions
  1732.    and functions describe dBASE expressions in-depth.
  1733.  
  1734.    Code Base evaluates expressions as a two step process. First, the
  1735.    expression is pseudo-compiled. The the pseudo-compiled expression is
  1736.    executed to return the result. This is efficient when expressions are
  1737.    evaluated repeatedly as the pseudo-compiled form only needs to be
  1738.    generated once.
  1739.  
  1740.    For those who only wish to calculate an expression once, 'e4eval' is
  1741.    available. Otherwise, call 'e4parse' to pseudo-compile the expression and
  1742.    then call 'e4exec' whenever the pseudo-compiled expression needs to be
  1743.    interpreted.
  1744.  
  1745.    Hint:
  1746.     Avoid using the expression evaluation module to do calcuations which
  1747.     might have been done using the field routines. Otherwise, the
  1748.     application will execute more slowly than it should. The expression
  1749.     evaluation module is more suited for doing calcualtions in response
  1750.     to interactive queries.
  1751.  
  1752.  
  1753. e4eval
  1754.  
  1755.    Usage
  1756.           void *  e4eval( (char *) exprt_ptr )
  1757.  
  1758.    Description
  1759.           'e4eval' evaluates a dBASE expression and returns a pointer
  1760.           to an internal static buffer containing the result.
  1761.  
  1762.    Parameter
  1763.           'expr_ptr' is a pointer to a dBASE expression. This
  1764.           expression may contain field names, functions, operators,
  1765.           and references to other databases.
  1766.  
  1767.           For more information, refer to the appendices on expressions.
  1768.  
  1769.    Returns
  1770.           The result can be in a different format depending on its
  1771.           type:
  1772.  
  1773.           Type        Format
  1774.  
  1775.           Date        CCYYMMDD (Century, Year, Month, Day).
  1776.  
  1777.           Character   ASCII String.
  1778.  
  1779.           Numeric     Double.
  1780.  
  1781.           Logical     int (0 for false, other for true).
  1782.  
  1783.           (void *) 0  Error.
  1784.  
  1785.    Note
  1786.           The type of the result can be determined by calling 'e4type'.
  1787.  
  1788.    Example
  1789.           /* AMOUNT - A numeric field of the selected database */
  1790.           /* CENTS  - A numeric field of BASE.DBF */
  1791.           printf ( "\n Expression Result: %f",
  1792.              e4eval( "AMOUNT* (100 + BASE->CENTS)" ) ) ;
  1793.  
  1794.  
  1795. e4exec
  1796.  
  1797.    Usage
  1798.           void *  e4exec( (char *) compile_ptr )
  1799.  
  1800.    Description
  1801.           The pseudo-compiled expression from the routine 'e4parse'
  1802.           is interpreted. A pointer to an internal static buffer
  1803.           containing the result is returned.
  1804.  
  1805.    Parameters
  1806.           'compile_ptr' points to the 'pseudo-compiled' form of the
  1807.           expression.
  1808.  
  1809.    Returns
  1810.           Refer to 'e4eval'. The returns are identical.
  1811.  
  1812.    Example
  1813.           void exec_amount()
  1814.           {
  1815.               char *   compile_ptr ;
  1816.               char *   result_ptr ;
  1817.  
  1818.               e4parse( "AMOUNT", &compile_ptr ) ;
  1819.               result_ptr = e4exec( compile_ptr ) ;
  1820.  
  1821.               /* Check the type of  *result_ptr */
  1822.               if ( e4type() == 'N' )
  1823.              printf( "\n Numeric Result:  %f",
  1824.                   *((double *) result_ptr) ) ;
  1825.               if ( e4type() == 'C' )
  1826.              printf( "\n Character Result:  %S",
  1827.                   (char *) result_ptr) ;
  1828.               /* Free the Memory Allocated by e4parse */
  1829.               free( compile_ptr );
  1830.           }
  1831.  
  1832.  
  1833. e4parse
  1834.  
  1835.    Usage
  1836.           int  e4parse( (char *) expr_ptr, (char **) &compile_ptr )
  1837.  
  1838.    Description
  1839.           'e4parse' pseudo-compiles a dBASE expression so that it can
  1840.           be efficiently interpreted by 'e4exec'.
  1841.  
  1842.           Memory is allocated for the pseudo-compiled expression
  1843.           with 'malloc'. Consequently, after the compiled expression
  1844.           is no longer needed, it is necessary to free it with a call
  1845.           to 'free'.
  1846.  
  1847.    Warning
  1848.           If a reference database is closed and re-opened, it is
  1849.           necessay to pseudo-compile the expression again.
  1850.  
  1851.    Returns
  1852.           Value       Meaning
  1853.  
  1854.           >= 0        The number of bytes in the pseudo-compiled
  1855.                   expression.
  1856.  
  1857.             -1        Error.
  1858.  
  1859. e4priority
  1860.  
  1861.    Usage
  1862.           int  e4priority( (char) operator_char )
  1863.  
  1864.    Return
  1865.           'e4priority' returns the numerical priority of a charcater
  1866.           operator.
  1867.  
  1868.    Note
  1869.           This function is intended primarily for use by 'e4parse'.
  1870.  
  1871.    Example
  1872.           The priority for the operator '*' is greater than the
  1873.           priority of the '+' operator.
  1874.  
  1875.  
  1876. e4name
  1877.  
  1878.    Usage
  1879.           char *  e4name( (char) op_code )
  1880.  
  1881.    Return
  1882.           Returns a pointer to the name of the operator corresponding
  1883.           to an internal 'op_code'.
  1884.  
  1885.    Note
  1886.           This routine is used to generate error information on
  1887.           illegal expressions.
  1888.  
  1889.  
  1890. e4type
  1891.  
  1892.    Usage
  1893.           char  e4type()
  1894.  
  1895.    Description
  1896.           'e4type' returns the type of the last expression evaluated
  1897.           by 'e4exec' or 'e4eval'.
  1898.  
  1899.    Returns
  1900.           Value       Meaning
  1901.  
  1902.           'C'         Character
  1903.  
  1904.           'N'         Numeric
  1905.  
  1906.           'D'         Date
  1907.  
  1908.           'L'         Logical
  1909.  
  1910.  
  1911.  
  1912. FIELD ROUTINES
  1913.  
  1914.    The field routines manipulate the record buffer and return field
  1915.    information. Note that there is only one record buffer per database and
  1916.    that the database routines read nad write that buffer.
  1917.  
  1918.    There are two methods which can be used to manipulate the record buffer.
  1919.    First, routines such as 'f4replace' and 'f4ptr' can be used with field
  1920.    reference numbers. The advantage of this method is that an executable
  1921.    program can work flawlessly after database fields are are added, removed
  1922.    or modified. In addition, the programmer does not have to understand the
  1923.    internal formatting of a database record buffer.
  1924.  
  1925.    If the programmer understands the internal format of record buffer( see
  1926.    Code Base Internals), the record buffers can be manipulated directly. The
  1927.    best technique is to use 'f4record' to assign a structure pointer to the
  1928.    begninning of the internal Code Base record buffer. Structure memebers
  1929.    would correspond to the different database fields.
  1930.  
  1931.    Hint:
  1932.     If field reference numbers are used, it works well to open the
  1933.     databases at the beginning of the program and assign field reference
  1934.     values to long integer variables immediately. By declaring the field
  1935.     reference variables globally, they can be used from any routine! In
  1936.     addition, Code Base knows which field reference number corresponds to
  1937.     which database. Consequently, it never matters which database is
  1938.     selected useing the field routines!!
  1939.  
  1940.    Warining:
  1941.     Do not assume that the field reference number for the first field is
  1942.     zero, and that the field reference number is one for the second
  1943.     field, ...  This is only true for the first database which is opened
  1944.     and may not be true in subsequent versions of Code Base. Call 'f4ref'
  1945.     or 'f4j_ref' to obtain field reference numbers.
  1946.  
  1947.  
  1948. f4decimals
  1949.  
  1950.    Usage
  1951.           int  f4decimals( (long) field_ref )
  1952.  
  1953.    Description
  1954.           If 'field_ref' corresponds to a numeric field, 'f4decimals'
  1955.           returns the number of decimals in the field. Otherwise,
  1956.           zero is returned.
  1957.  
  1958.    Returns
  1959.           Value       Meaning
  1960.  
  1961.           >= 0        The number of decimals.
  1962.  
  1963.             -1        Illegal Parameter.
  1964.  
  1965.  
  1966. f4j_ref
  1967.  
  1968.    Usage
  1969.           long  f4j_ref( (int) j_field )
  1970.  
  1971.    Description
  1972.           'f4j_ref' returns a field reference number corresponding to
  1973.           the j'th database field. The field reference number will be
  1974.           for the selected database.
  1975.  
  1976.    Note
  1977.           'j_field' must be between one and the number of fields.
  1978.           (ie. 1 <= j_field <= f4num_fields() )
  1979.  
  1980.    Returns
  1981.           Value       Meaning
  1982.  
  1983.           >= 0        A field reference number.
  1984.  
  1985.             -1        Illegal Parameter.
  1986.  
  1987.    Hint
  1988.           Field reference numbers are in consecutive order.
  1989.           Consequently f4j_ref(j)+1 is equal to f4j_ref(j+1) as long
  1990.           as the database has more than 'j' fields.
  1991.  
  1992.    Warning
  1993.           The field reference number is only valid while the database
  1994.           is open. If the database is closed and opened again,
  1995.           'f4j_ref' must be called again to obtain the field
  1996.           reference number.
  1997.  
  1998.    Example:
  1999.           /* Print out the Database Field Names */
  2000.           for ( j = 1; j <= f4num_fields(); j++ )
  2001.               w4( j, 0, f4name( f4j_ref(j) ) ) ;
  2002.  
  2003.  
  2004. f4name
  2005.  
  2006.    Usage
  2007.           char *  f4name( (long) field_ref )
  2008.  
  2009.    Description
  2010.           'f4name' returns a pointer to the field's name. A null
  2011.           pointer is returned if the field reference number is not
  2012.           valid.
  2013.  
  2014.  
  2015. f4num_fields
  2016.  
  2017.    Usage
  2018.           int  f4num_fields()
  2019.  
  2020.    Description
  2021.           'f4num_fields' returns the number of fields in the
  2022.           currently selected database. If no datbase is open, -1 is
  2023.           returned.
  2024.  
  2025.  
  2026. f4ptr
  2027.  
  2028.    Usage
  2029.           char *  f4ptr( (long) field_ref )
  2030.  
  2031.    Description
  2032.           'f4ptr' returns a pointer, within the database buffer, to
  2033.           the specified field. As the pointer points directly to the
  2034.           data, it is not null terminated. The field data is followed
  2035.           immediately by the data of the next field. A null pointer
  2036.           is returned to indicate an illegal parameter.
  2037.  
  2038.    Note
  2039.           All data in the record buffer is stored as ASCII
  2040.           characters. Numeric fields are formatted according to their
  2041.           width and decimal places; logical fields contain 'T','t',
  2042.           'Y', or 'y' to represent TRUE or contain 'F','f','N', or
  2043.           'n' to represent FALSE; finally, date fields are formatted
  2044.           'CCYYMMDD" (Century, Year, Month, Day). For example, the
  2045.           buffer for a numeric field with a width of five and two
  2046.           decimal places would store '(double) 3.4' as "3.40"; the
  2047.           date March 15, 1988 would be stored as "19880315".
  2048.  
  2049.    Warning
  2050.           If the corresponding database is closed and then reopened,
  2051.           the pointer must be reassigned.
  2052.  
  2053.  
  2054. f4record
  2055.  
  2056.    Usage
  2057.           void *  f4record()
  2058.  
  2059.    Description
  2060.           Routine 'f4record' returns a pointer to the beginning of
  2061.           the record buffer.
  2062.  
  2063.           The returned pointer could be assigned to a 'C' structure
  2064.           pointer for direct data access. As all database fields are
  2065.           internally stored in ASCII format, the members of the 'C"
  2066.           structure will all be of type 'char' or and array of type
  2067.           'char'. Structure members correspond, in order, to the
  2068.           database fields. In addition, the number of 'char' array
  2069.           elements of each structure member will correspond to the
  2070.           widths of each database field.
  2071.  
  2072.    Note
  2073.           As explained in the Appendix on 'Conde Base Internals', the
  2074.           format of the Code Base record buffer is identical to the
  2075.           way dBASE stores its record data on disk. All data is in
  2076.           ASCII and there are no seperators between fields.
  2077.  
  2078.           The first byte of the record buffer is a deletion flag
  2079.           which is an asterisk ('*') if the record is marked for
  2080.           deletion and is otherwise blank.
  2081.  
  2082.    Warning
  2083.           If the database is closed and reopened, the pointer must be
  2084.           reassigned.
  2085.  
  2086.    Example:
  2087.           typedef struct
  2088.           {
  2089.               char deleted ;          /* The deletion flag */
  2090.               char last_name[30] ;    /* Field 1.  Width 30 */
  2091.               char first_name[20] ;   /* Field 2.  Width 20 */
  2092.           } NAME ;
  2093.  
  2094.           /*
  2095.            This routine directly modifies the internal Code Base
  2096.            record buffer and then writes it.
  2097.            */
  2098.  
  2099.           void append_record()
  2100.           {
  2101.               NAME  *name_ptr ;
  2102.  
  2103.              /*
  2104.               'name_ptr' will point to the internal Code Base
  2105.               record buffer
  2106.               */
  2107.               name_ptr = (NAME *) f4record() ;
  2108.  
  2109.               /* Initialize the Record */
  2110.               memset( name_ptr, (int) ' ', sizeof(NAME) ) ;
  2111.  
  2112.               /* Copy the Data */
  2113.               memcpy( name_ptr->last_name, "JONES", 5 ) ;
  2114.               memcpy( name_ptr->first_name, "FRED", 4 ) ;
  2115.  
  2116.               d4write(0L) ;   /* Append the New Record */
  2117.  
  2118.  
  2119. f4record_width
  2120.  
  2121.    Usage
  2122.           int  f4record_width()
  2123.  
  2124.    Returns
  2125.           'f4record_width' returns the total number of characters in
  2126.           the record buffer. This is the sum of the field widths plus
  2127.           one for the deletion flag.
  2128.  
  2129.  
  2130.  f4ref
  2131.  
  2132.    Usage
  2133.           long  f4ref( (char *) field_name )
  2134.  
  2135.    Description
  2136.           'f4ref' returns a field reference number corresponding to
  2137.           the field name specified by the parameter. The field name
  2138.           can contain upper or lower case. In addition, it may be
  2139.           ended by a blank or a NULL.
  2140.  
  2141.           The database corresponding to the field name must be
  2142.           selected before calling 'f4ref'.
  2143.  
  2144.    Warning        The field reference number is only valid while the database
  2145.  
  2146.                  is open. If the database is closed and opened again,
  2147.           'f4ref' must be called again ot obtain the field reference
  2148.           number for a field. In addition, the field's database must
  2149.           be selected before calling 'f4ref'.
  2150.  
  2151.    Returns
  2152.           Value       Meaning
  2153.  
  2154.           >= 0        A field reference number.
  2155.  
  2156.             -1        Invalid Field Name (No Error Displayed).
  2157.  
  2158.    Hint
  2159.           Call 'f4ref' once for a particular field and assign the
  2160.           result to a variable as a reference to the field. If the
  2161.           variables are used throughout several source code files,
  2162.           set up an include file to declare all field reference
  2163.           variables as externals.
  2164.  
  2165.    Example
  2166.           #include <d4base.h>
  2167.  
  2168.           long m_name, m_address ;  /* Declare Globally */
  2169.  
  2170.           main()
  2171.           {
  2172.                d4use( "MAILING" ) ;
  2173.                m_name = f4ref( "NAME" ) ;
  2174.                m_address = f4ref( "ADDRESS" ) ;
  2175.                f4replace( m_name, "JOHN SMITH" ) ;
  2176.                do_work() ;
  2177.           }
  2178.  
  2179.  
  2180. f4replace
  2181.  
  2182.    Usage
  2183.           int  f4replace( (long) field_ref, (void *) value )
  2184.  
  2185.    Description
  2186.           This routine assigns a value to the field of a database
  2187.           buffer. The 'value' parameter is a pointer to he field's
  2188.           new value. The type of value depends on the type of the
  2189.           corresponding field. If the field is of type character or
  2190.           date, value should be a '(char *)'; if the field is of type
  2191.           numeric, value should be a '(double *)'; finally, if value
  2192.           is of type logical, value should be an '(int *)'.
  2193.  
  2194.           By convention, null characters are not allowed in database
  2195.           data. Consequently, if value is a string with less
  2196.           characters than database field, 'f4replace' will supply
  2197.           extra blank characters. On the other hand, if value has
  2198.           more characters than the database field, the extra
  2199.           characters will be ignored.
  2200.  
  2201.           Numeric doubles will be formatted in the field buffer
  2202.           according to the field's width and decimal specifications.
  2203.  
  2204.           Dates should be in the standard database date format:
  2205.           "CCYYMMDD" (Century, Year, Month, Day).
  2206.  
  2207.           Finally, logicals should be zero for FALSE and non zero for
  2208.           TRUE.
  2209.  
  2210.    Returns
  2211.           Value       Meaning
  2212.  
  2213.            0          Success.
  2214.  
  2215.           -1          Error.
  2216.  
  2217.           -2          Illegal date. The date field was set to blank.
  2218.  
  2219.           -3          The numeric value was too large or small to fit
  2220.                   into the field. The field was filled with
  2221.                   asterisks (*'s).
  2222.  
  2223.           -4          Null Pointer.
  2224.  
  2225.           -5          Illegal field reference number.
  2226.  
  2227.  
  2228. f4str
  2229.  
  2230.    Usage
  2231.           char *  f4str( (long) field_ref )
  2232.  
  2233.    Description
  2234.           The field's contents are copied to an internal static
  2235.           buffer and a pointer to the buffer is returned. The string
  2236.           will be terminated by a null character.
  2237.  
  2238.    Returns
  2239.           A pointer to the field's value is returned. An error is
  2240.           indicated by a NULL ((char *) 0) return.
  2241.  
  2242.    Hint
  2243.           This function is useful when you need the field's value
  2244.           ended by a null character.
  2245.  
  2246.    Warning
  2247.           Each time 'f4str' is called, the static buffer is overlaid
  2248.           with data from the nrw field.
  2249.  
  2250.    Example
  2251.           void  say_field( field_name )
  2252.           char *  field_name ;
  2253.           {
  2254.              char *  ptr ;
  2255.  
  2256.              ptr = f4str( f4ref( field_name ) ) ;
  2257.              w4( w4row()+1, 0, ptr ) ;
  2258.           }
  2259.  
  2260. f4true
  2261.  
  2262.    Usage
  2263.           int  f4true( (long) field_ref )
  2264.  
  2265.    Description
  2266.           'f4true()' is used to determine if a logical field is true
  2267.           or false.
  2268.  
  2269.    Returns
  2270.           Value       Meaning
  2271.  
  2272.            1          The field is true.
  2273.            0          The field is false.
  2274.           -1          Error.
  2275.  
  2276.  
  2277. f4type
  2278.  
  2279.    Usage
  2280.           char  f4type( (long) field_ref )
  2281.  
  2282.    Description
  2283.           All fields are of type Character, Numeric, Floating Point,
  2284.           Date, or Logical. 'f4type' returns the type of a specified
  2285.           field. Floating point fileds are the same as numerice
  2286.           fields. To maintain compatibility with dBASE III, avoid
  2287.           using floating point fields.
  2288.  
  2289.    Returns
  2290.           Value       Meaning
  2291.  
  2292.           'C'         Character.
  2293.  
  2294.           'N'         Numeric.
  2295.  
  2296.           'F'         Floating Point.
  2297.  
  2298.           'D'         Date.
  2299.  
  2300.           'L'         Logical.
  2301.  
  2302.           'M'         Memo.
  2303.  
  2304.           '\0'        Error.
  2305.  
  2306.  
  2307. f4value
  2308.  
  2309.    Usage
  2310.           double  f4value( (long) field_ref )
  2311.  
  2312.    Description
  2313.           'f4value' is used to return the value of a numeric field as
  2314.           a '(double)'.
  2315.  
  2316.    Returns
  2317.           The value of the field. If 'field_ref' is not a legitimate
  2318.           field reference number, the result is undefined.
  2319.  
  2320.  
  2321. f4width
  2322.  
  2323.    Usage
  2324.           int  f4width( (long) field_ref )
  2325.  
  2326.    Description
  2327.           All fields have a fixed width in bytes (characters).
  2328.           'f4width' returns the width of the specified field.
  2329.  
  2330.    Returns
  2331.           Value       Meaning
  2332.  
  2333.           >= 0        The field width.
  2334.  
  2335.             -1        Error.
  2336.  
  2337.  
  2338.  
  2339. GET ROUTINES
  2340.  
  2341.    The Get Routines build upon the Windowing Routines to interactively enter
  2342.    information into any "C" variable or any database field.
  2343.  
  2344.    Some features include picture templates, user defined input validation,
  2345.    delimiters, special get attributes, and scrolling within any entry area.
  2346.  
  2347.    There are serval Get Routine categories:
  2348.  
  2349.        Category          Routines in Category
  2350.  
  2351.        Get Initialize    g4, g4double, g4field, g4int, g4logical, g4long,
  2352.              g4numeric
  2353.        Pre-Modifier      g4attribute, g4delimiter
  2354.        Post-Modifier     g4call, g4message, g4picture, g4upper, g4valid,
  2355.              g4width
  2356.        Miscellaneous     g4alloc, g4bell, g4bell_set, g4display, g4read,
  2357.              g4release
  2358.  
  2359.    To use the Get Routines it is necessay to combine at least one 'Get
  2360.    Initialize' routine with 'g4read'. (Remember to call 'w4define', 'd4init',
  2361.    'd4use', or 'd4create' to create a window for the entry areas. 'd4init',
  2362.    'd4use' and 'd4create' the default window.)
  2363.  
  2364.    Get Example:
  2365.  
  2366.        g4int( 5,5, &i_value ) ;   /* Define the Get */
  2367.        g4read() ;  /* Do the Read */
  2368.  
  2369.    In general, a series of Get Initialize routines are called to specify what
  2370.    information is to be read from which portions of the selected window.
  2371.    Then 'g4read' is called to interact with the user to obtain the
  2372.    information specified by the previous Get Initialize routines.
  2373.    Post-Modifier routintes are called after a Get Initialize routine and
  2374.    effect only the entry area created as a result of that Get Initialize
  2375.    call. Pre-Modifier routines are called before the corresponding Get
  2376.    Initialize routines. They change settings which effect all entry areas
  2377.    created by subsequent Get Initialize calls.
  2378.  
  2379.    Saved Get information is attached logically to the currently selected
  2380.    window. If the window is closed all of the saved information is released.
  2381.  
  2382.    The routine declarations are in header file 'w4.h'.
  2383.  
  2384.  
  2385. g4
  2386.  
  2387.    Usage
  2388.           void  g4( (int) row, (int) column, (char * ) str )
  2389.  
  2390.    Get Category
  2391.           Get Initialize
  2392.  
  2393.    Description
  2394.           'g4' specifies an entry area for the read of a character
  2395.           buffer.
  2396.  
  2397.           By default, 'str' must point to a null terminated character
  2398.           string. However, if a picture is specified, the length of
  2399.           the picture will specify the length of the buffer.
  2400.           Altemately, a call to 'g4width' takes precedence over both
  2401.           the picture and the string lengths.
  2402.  
  2403.    Parameters
  2404.           Name        Use
  2405.  
  2406.           row         The entry area's row.
  2407.  
  2408.           column      The entry area's column.
  2409.  
  2410.           str         A pointer to the string which is initially
  2411.                   displayed in the entry area. This string will
  2412.                   be replaced by the final result.
  2413.  
  2414.  
  2415. g4alloc
  2416.  
  2417.    Usage
  2418.           GET *g4alloc( (int) row, (int) column, (void *) data_ptr,
  2419.                   (char) type )
  2420.  
  2421.    Description
  2422.           This is a low level routine which is used by higher level
  2423.           Get Initialize routines.
  2424.  
  2425.    Parameters
  2426.           Name        Use
  2427.  
  2428.           row         The entry area's row.
  2429.  
  2430.           column      The entry area's column.
  2431.  
  2432.           data_ptr    A pointer to the default value which is
  2433.                   initially displayed in the entry area. This
  2434.                   default will be overlaid with the result.
  2435.  
  2436.           type        A code used to represent the type of data
  2437.                   entry. The legitimate codes are as follows:
  2438.  
  2439.                  Code      Meaning
  2440.  
  2441.                  'C'       Character.
  2442.                  'D'       Date.
  2443.                  'L'       Logical.
  2444.                  'N'       Numeric.
  2445.                  'd'       double.
  2446.                  'l'       long.
  2447.                  'i'       integer.
  2448.  
  2449.    Returns
  2450.           A pointer to a 'GET' data structure is returned. This
  2451.           structure is used to store various pieces of information
  2452.           specified by the Get Initialize routine, the Pre-Modifier
  2453.           routines, and the Post-Modifier routines.
  2454.  
  2455.           '(GET *) 0' is returned if there is no memory left and if
  2456.           'u4error' has been modified to return on this error.
  2457.  
  2458.  
  2459. g4attribute
  2460.  
  2461.    Usage
  2462.           long  g4attribute( (long) attribute )
  2463.  
  2464.    Get Category
  2465.           Pre-Modifier
  2466.  
  2467.    Description
  2468.           Every entry area can have its own attribute character.
  2469.           'g4attribute' sets the 'get attribute' for entry areas
  2470.           corresponding to subsequent Get Initialize routines calls.
  2471.  
  2472.    Parameter
  2473.           The new attribute character is represented as an intger
  2474.           between '(int) 0' and '(int) 0xFF'. If the 'attribute'
  2475.           parameter is not a legitimate attribute character, the
  2476.           current 'get attribute' is not changed.
  2477.  
  2478.    Returns
  2479.           The current 'get attribute' character is returned.
  2480.  
  2481.    See Also
  2482.           Refer to 'w4attribute' for more information on attributes.
  2483.  
  2484.  
  2485. g4bell
  2486.  
  2487.    Usage
  2488.           void  g4bell()
  2489.  
  2490.    Description
  2491.           Causes the computer to sound its bell.
  2492.  
  2493.    Note
  2494.           'g4bell_set' must be called first to set the bell switch on.
  2495.  
  2496.  
  2497. g4bell_set
  2498.  
  2499.    Usage
  2500.           void  g4bell_set( (int) switch )
  2501.  
  2502.    Description
  2503.           'g4bell_set' turns the bell switch on or off. If the bell
  2504.           is switch on then routine 'g4bell' sounds the bell and
  2505.           'g4read' will sound the bell after an entry area is filled.
  2506.  
  2507.    Parameter
  2508.           'switch' is zero to turn the switch off and is non-zero to
  2509.           turn the switch on.
  2510.  
  2511.  
  2512. g4call
  2513.  
  2514.    Usage
  2515.           void  g4call( (GET_ROUTINE *) routine, (int) call_data )
  2516.  
  2517.    Get Category
  2518.           Post-Modifier
  2519.  
  2520.    Description
  2521.           The main purpose of 'call' routines is to allow data entry,
  2522.           by menus, into entry areas. Code Base supplies two 'call'
  2523.           routines for this purpose: 'g4menu' and 'g4menu_help'.
  2524.           Refer to these routines and to routine 'n4get_calc'.
  2525.  
  2526.           It is possible, although difficult, to write a specialized
  2527.           'call' routine or to modify 'g4menu' or 'g4menu_help'. To
  2528.           do so, it may be necessary to learn how routine 'g4read'
  2529.           works by stepping through it with a debugger. The following
  2530.           information defines a 'call' routine:
  2531.  
  2532.           'g4call' specifies a routine, corresponding to an entry
  2533.           area, which 'g4read' calls before requesting any keyboard
  2534.           input from the user. The routine is only called when
  2535.           'g4read' is on the entry area which has just been defined.
  2536.  
  2537.           A user defined 'call' routine must be of type
  2538.           'GET_ROUTINE'. This means the routine follows the following
  2539.           calling conventions:
  2540.  
  2541.               int  call_routine( (GET *) get_ptr, (char *)
  2542.                     data_buffer, (int) call_data )
  2543.  
  2544.           Call routine parameter 'get_ptr' points to a structure of
  2545.           type 'GET'. This structure stores information about the
  2546.           defined entry area.
  2547.  
  2548.           Parameter 'data_buffer' points to the currently entered
  2549.           information. Regardless of the data type being entered,
  2550.           'data_buffer' always contains ASCII characters.
  2551.  
  2552.           'call_data' is the integer passed in the call to routine
  2553.           'g4call'. The meaning of this integer parameter is defined
  2554.           by the specific 'call' routine.
  2555.  
  2556.           Depending on the value returned by the 'call' routine,
  2557.           'g4read' performs a different action:
  2558.  
  2559.           Value       Action
  2560.  
  2561.           > 0         'g4read' will take this as input data, exactly
  2562.                   as if it was read from the keyboard.
  2563.             0         Read the next keyboard character as normal
  2564.                   input data.
  2565.            -1         Call this call routine again without getting
  2566.                   any keyboard data from the user.
  2567.  
  2568.  
  2569.  
  2570. g4char
  2571.  
  2572.    Usage
  2573.           int  g4char()
  2574.  
  2575.    Returns
  2576.           'g4char' reads a character from the keyboard and returns it
  2577.           as an integer.
  2578.  
  2579.           A special header file, 'g4char.h', has been provided which
  2580.           defines all of the special extended character set key
  2581.           codes. For example, F1 is defined to be 0x3B00. This is the
  2582.           value returned by 'g4char' when function key 1 is pressed.
  2583.  
  2584.  
  2585. g4date
  2586.  
  2587.    Usage
  2588.           void  g4date( (int) row, (int) column, (char *) date_ptr )
  2589.  
  2590.    Description
  2591.           'g4date' specifies the entry area for the read of a date.
  2592.           When using the default picture of "MMM/DD/YY", the month is
  2593.           entered as three characters (ex. "Jan").
  2594.  
  2595.    Parameters
  2596.           Name        Use
  2597.  
  2598.           row         The entry area's row.
  2599.  
  2600.           column      The entry area's column.
  2601.  
  2602.           date_ptr    A pointer to the 'date' which is initially
  2603.                   displayed in the entry area. This 'date', of
  2604.                   format "CCYYMMDD", will be overlaid with the
  2605.                   final result.
  2606.  
  2607.  
  2608. g4delimiter
  2609.  
  2610.    Usage
  2611.           char *  g4delimiter( (char *) delimiter )
  2612.  
  2613.    Get Category
  2614.           Pre-Modifier
  2615.  
  2616.    Description
  2617.           Subsequent 'get' calls will use the specified delimiter
  2618.           characters.
  2619.  
  2620.    Parameter
  2621.           'delimiter' points to a string of up to two delimiter
  2622.           characters. These characters will appear on each side of
  2623.           the corresponding entry area respectively. If the string
  2624.           contains a single character, it will be used to delimit
  2625.           both ends of the entry area.
  2626.  
  2627.    Returns
  2628.           A pointer to the two current delimiter characters is
  2629.           returned. This string in NOT null terminated.
  2630.  
  2631.  
  2632. g4display
  2633.  
  2634.    Usage
  2635.           void  g4display()
  2636.  
  2637.    Description
  2638.           All of the default 'get' values will be displayed in their
  2639.           entry areas using the current 'get' attribute.
  2640.  
  2641.  
  2642. g4double
  2643.  
  2644.    Usage
  2645.           void g4double( (int) row, (int) column, (double *)
  2646.                   double_ptr )
  2647.  
  2648.    Get Category
  2649.           Get Initialize
  2650.  
  2651.    Description
  2652.           'g4double' specifies an entry area for the read of a
  2653.           double. By default, the entry area is formatted with two
  2654.           decimal places and a total width of eight.
  2655.  
  2656.    Parameters
  2657.           Name        Use
  2658.  
  2659.           row         The entry area's row.
  2660.  
  2661.           column      The entry area's column.
  2662.  
  2663.           double_ptr  A pointer to the 'double' which is initially
  2664.                   displayed in the entry area. This 'double' will
  2665.                   be overlaid with the final result.
  2666.  
  2667.    Note
  2668.           'g4picture' changes the format of a 'double' read.
  2669.  
  2670.    Example
  2671.           g4double( 5, 5, &value ) ;
  2672.           g4picture( "######.###" ) ;
  2673.           g4read() ;
  2674.  
  2675.  
  2676. g4field
  2677.  
  2678.    Usage
  2679.           void  g4field( (int) row, (int) column, (long) field_ref )
  2680.  
  2681.    Get Category
  2682.           Get Initialize
  2683.  
  2684.    Description
  2685.           'g4field' specifies an entry area for the read of a
  2686.           database field.
  2687.  
  2688.    Parameters
  2689.           Name        Use
  2690.  
  2691.           row         The entry area's row.
  2692.  
  2693.           column      The entry area's column.
  2694.  
  2695.           field_ref   The field reference number of the field to be
  2696.                   entered.
  2697.  
  2698.    Example
  2699.           g4field( ++r,c, f4ref( "LAST_NAME" ) ) ;
  2700.           g4read() ;
  2701.  
  2702.    See Also
  2703.           Field Routines
  2704.  
  2705.  
  2706. g4init
  2707.  
  2708.    Usage
  2709.           void  g4int( (int) row, (int) column, (int *) int_ptr )
  2710.  
  2711.    Get Category
  2712.           Get Initialize
  2713.  
  2714.    Description
  2715.           'g4init' specifies an entry area for the read of an
  2716.           integer. By default, the entry will be formatted with be
  2717.           formatted with a width of 4.
  2718.  
  2719.    Parameters
  2720.           Name        Use
  2721.  
  2722.           row         The entry area's row.
  2723.  
  2724.           column      The entry area's column.
  2725.  
  2726.           int_ptr     A pointer to the 'integer' which is initially
  2727.                   displayed in the entry area. This 'integer'
  2728.                   will be overlaid with the final result.
  2729.  
  2730.    Example
  2731.           g4int( r,c, &i_value ) ;
  2732.           g4picture( "999999" ) ;   /* Change the Format */
  2733.           g4read() ;
  2734.  
  2735.  
  2736. g4logical
  2737.  
  2738.    Usage
  2739.           void  g4logical( (int) row, (int) column,
  2740.                   (int *) logical_ptr )
  2741.  
  2742.    Get Category
  2743.           Get Initialize
  2744.  
  2745.    Description
  2746.           'g4logical' specifies an entry area for the read of a
  2747.           logical character: 'T','t','F','f','Y','y','N' or 'n'.
  2748.  
  2749.           The logical value is stored as an integer where zero
  2750.           represents false ('F','f','N' and 'n') and a non-zero value
  2751.           represents true('T','t','Y' and 'y').
  2752.  
  2753.    Parameters
  2754.           Name           Use
  2755.  
  2756.           row            The entry area's row.
  2757.  
  2758.           column         The entry area's column.
  2759.  
  2760.           logical_ptr    A pointer to a logical value represented as
  2761.                  an 'integer'. This value will be initially
  2762.                  displayed in the entry area. The 'integer'
  2763.                  will be overlaid with the final result.
  2764.  
  2765.    Hint
  2766.           The only valid picture characters which may be used
  2767.           'g4logical' are 'L' (default) and 'Y'.
  2768.  
  2769.           To obtain a logical character result,use routine 'g4' with
  2770.           the appropriate picture.
  2771.  
  2772.  
  2773. g4long
  2774.  
  2775.    Usage
  2776.           void  g4long( (int) row, (int) column, (long *) long_ptr )
  2777.  
  2778.    Get Category
  2779.           Get Initialize
  2780.  
  2781.    Description
  2782.           'g4long' specifies an entry area for the read of long
  2783.           integer. By default, the entry area width is eight.
  2784.  
  2785.    Parameters
  2786.           Name        Use
  2787.  
  2788.           row         The entry area's row.
  2789.  
  2790.           column      The entry area's column.
  2791.  
  2792.           long_ptr    A pointer to the '(long)' which is initially
  2793.                   displayed in the entry area. This long will be
  2794.                   overlaid with the final result.
  2795.  
  2796.  
  2797. g4menu
  2798.  
  2799.    Usage
  2800.           int  g4menu( (GET *) get_ptr, (char *) buffer,
  2801.                   (int) window_ref )
  2802.  
  2803.    Description
  2804.           If 'g4menu' is the call routine for an entry area, a menu
  2805.           is used to enter information into the entry area. The only
  2806.           entry possibilities will be text descriptions of the
  2807.           different menu items.
  2808.  
  2809.           'g4menu' is not called directly. It is used as a parameter
  2810.           to 'g4call':
  2811.  
  2812.               g4call( g4menu, window_ref ) ;
  2813.  
  2814.           'window_ref' is the window reference number corresponding
  2815.           to the menu. 'g4menu' uses the following algorithm:
  2816.  
  2817.               1.   Activate the menu using routine 'n4activate' and
  2818.                the window reference number 'window_ref' which has
  2819.                been saved by routine 'g4call'.
  2820.  
  2821.               2.   Transfer the text from the menu item choice to the
  2822.                internal Code Base 'buffer' parameter. 'g4menu'
  2823.                knows the format of 'buffer' from the information
  2824.                in the structure pointed to by 'get_ptr'.
  2825.  
  2826.           Refer to the menuing routines and to routine 'n4get_calc'
  2827.           to learn how to easily build the entry menu.
  2828.  
  2829.    Returns
  2830.           There are some keyboard characters such as SHIT_TAB, TAB,
  2831.           CTRL_HOME, CTRL_END, ESC, and CTRL_C which normally cause
  2832.           'g4read' to transfer between entry zones or to return. If
  2833.           these are pressed while the entry menu is present,
  2834.           'n4activate' returns this information to 'g4menu'. 'g4menu'
  2835.           then recognizes these characters as commands to 'g4read'
  2836.           and passes them along performing no other action.
  2837.           Otherwise, the entry data is selected and 'g4menu' returns
  2838.           RETURN to instruct 'g4read' to move to the next entry zone.
  2839.  
  2840.  
  2841. g4menu_help
  2842.  
  2843.    Usage
  2844.           g4menu_help( (GET *) get_ptr, (char *) buffer,
  2845.                   (int) window_ref )
  2846.  
  2847.    Description
  2848.           'g4menu_help' is almost identical to 'g4menu'. However, it
  2849.           allows the user to either data as normal or to use a menu
  2850.           as a set of possible entry choices.
  2851.  
  2852.           Specificaly, 'g4menu_help' reads all of the keyboard data
  2853.           looking for the press of the F1 help key. If F1 is pressed
  2854.           'g4menu_help' calls 'g4menu' so that the data can be
  2855.           entered using a menu. Otherwise, the keyboard data is
  2856.           returned to 'g4read' so that it can be used as normally
  2857.           entered data.
  2858.  
  2859.  
  2860. g4message
  2861.  
  2862.    Usage
  2863.           void  g4message( (char *) message )
  2864.  
  2865.    Get Category
  2866.           Post-Modifier
  2867.  
  2868.    Description
  2869.           'g4message' specifies a message corresponding to an entry
  2870.           area which has just been created using a 'Post-Modifier'
  2871.           routine.
  2872.  
  2873.    Parameters
  2874.           This a pointer to a message string which is associated with
  2875.           the entry area. The message string is automatically
  2876.           displayed when the entry area is moved upon.
  2877.  
  2878.    See Also
  2879.           'g4message_do'
  2880.  
  2881.  
  2882. g4message_do
  2883.  
  2884.    Usage
  2885.           void  g4message_do( (char *) message )
  2886.  
  2887.    Description
  2888.           This routine is called by 'g4read' to display the message
  2889.           strings specified by 'g4message'.
  2890.  
  2891.           'g4message_do' immediately displays a text string at the
  2892.           absoulte screen coordinates specified by external integer
  2893.           variables 'v4get_row' and 'v4get_col'. By default, these
  2894.           variables are '(int) 24' and '(int) 0' respectively. If the
  2895.           string is not long enough to display to the end of the
  2896.           screen, extra blank characters are displayed. If 'ptr' is
  2897.           '(char *) 0', the row starting form 'v4get_col', is blanked.
  2898.  
  2899.    Parameters
  2900.           'message' points to the message string.
  2901.  
  2902.  
  2903. g4numeric
  2904.  
  2905.    Usage
  2906.           void  g4numeric( (int) row, (int) column, (char *) num_str )
  2907.  
  2908.    Get Category
  2909.           Get Initialize
  2910.  
  2911.    Description
  2912.           'g4numeric' reads a numeric value as a character string.
  2913.  
  2914.           The width and the number of decimals are specified by the
  2915.           default value or by a picture.
  2916.  
  2917.    Parameters
  2918.           Name        Use
  2919.  
  2920.           row         The entry area's row.
  2921.  
  2922.           column      The entry area's column.
  2923.  
  2924.           num_str     A pointer to the string which is initially
  2925.                   displayed in the entry area. This string will
  2926.                   be replaced by the final result.
  2927.  
  2928.  
  2929. g4picture
  2930.  
  2931.    Usage
  2932.           void  g4picture( (char *) picture )
  2933.  
  2934.    Get Category
  2935.           Post-Modifier
  2936.  
  2937.    Description
  2938.           'g4picture' specifies an entry template for the previously
  2939.           called Get Initialize routine. The entry template
  2940.           identifies which input characters are legitimate for which
  2941.           entry positions.
  2942.  
  2943.    Parameters
  2944.           Characters in the string 'picture' have special meaning:
  2945.  
  2946.           Character   Meaning
  2947.  
  2948.           !           Convert to Upper Case.
  2949.  
  2950.           9           0-9.
  2951.  
  2952.           #           +,-,<space>, or 0-9.
  2953.  
  2954.           A           Letters Only (A-Z or a-z).
  2955.  
  2956.           L           y,Y,n,N,t,T,f, or F Only; Converts to T and F.
  2957.  
  2958.           N           Digits or Letters Only.
  2959.  
  2960.           X           Any Character.
  2961.  
  2962.           Y           y,Y,n, or N Only; Converts to Y and N.
  2963.  
  2964.           The character which can be entered into any character
  2965.           position is determined by the corresponding character in
  2966.           the picture template. If the character in the picture
  2967.           template is not a special picture character, it is entered
  2968.           as data.
  2969.  
  2970.           When entering date information, different picture
  2971.           characters apply:
  2972.  
  2973.           Character          Meaning
  2974.  
  2975.           C                  Second digit of the Century.
  2976.           CC                 First two digits of the Century.
  2977.           YY                 First two digits of the Year.
  2978.           DD                 Numeric Representation of the Day.
  2979.           MM                 Numeric Representation of the Month.
  2980.           MMM to MMMMMMMMM   Character Representation of the Month.
  2981.  
  2982.    Example
  2983.           g4( 8,10, telephone_string ) ;
  2984.           g4picture( "999-999-9999" ) ;
  2985.  
  2986.           /* Get a Date */
  2987.           g4( 9,10, date_value ) ;
  2988.           g4picture( "MM/DD/CCYY") ;   /* Ex. 01/30/1989 */
  2989.           g4read() ;
  2990.  
  2991.  
  2992. g4read
  2993.  
  2994.    Usage
  2995.           int  g4read()
  2996.  
  2997.    Description
  2998.           'g4read' interacts with the user to enter data using
  2999.           previously defined entry areas. These entry areas must have
  3000.           previously been defined for the selected window.
  3001.  
  3002.           The user can press the following keys to command 'g4read'
  3003.           to perform certain actions:
  3004.  
  3005.           Key                Action
  3006.  
  3007.           <Enter> or <Tab>   Moves to the next entry area. If there
  3008.                      is no 'next entry area', the read is
  3009.                      completed.
  3010.  
  3011.           <Shift Tab>        Moves to the previous entry area if one
  3012.                      exists.
  3013.  
  3014.           <Left Arrow>       Moves the cursor one position to the left.
  3015.  
  3016.           <Right Arrow>      Moves the cursor one position to the
  3017.                      right.
  3018.  
  3019.           <Ins>              Toggles between replace and insert
  3020.                      modes. When in insert mode the cursor is
  3021.                      slightly larger.
  3022.  
  3023.           <Del>              Deletes the character under the cursor.
  3024.  
  3025.           <Back Space>       Deletes the character to the left of the
  3026.                      cursor.
  3027.  
  3028.           <Esc>              Aborts the 'read'. 'g4read' will
  3029.                      immediately return.
  3030.  
  3031.           <Home>             Moves the cursor to the first postition
  3032.                      in the entry area.
  3033.  
  3034.           <End>              Moves the cursor to the end of the
  3035.                      entered information.
  3036.  
  3037.           <Ctrl Home>        Moves to the first entry area.
  3038.  
  3039.           <Ctrl End>         Moves to the last entry area.
  3040.  
  3041.           <Ctrl W>           All of these keys complete the read
  3042.           <Ctrl Q>           provided the validation routine for the
  3043.           <PgDn>             entry area returns a non-zero value.
  3044.           <PgUp>
  3045.           <Ctrl Left>
  3046.           <Ctrl Right>
  3047.  
  3048.    Returns
  3049.           The control character code pressed to cause an exit from
  3050.           the full screen edit. If the edit ended because the maximum
  3051.           amount of data was entered, '(int) 13' (carriage return) is
  3052.           returned.
  3053.  
  3054.    Hint
  3055.           Depending on the exiting character, the application could
  3056.           perform different actions.
  3057.  
  3058.  
  3059. g4release
  3060.  
  3061.    Usage
  3062.           void  g4release( (int) do_release )
  3063.  
  3064.    Description
  3065.           'g4release' sets whether 'g4read' can be called serval
  3066.           times in a row. By default, after a call to 'g4read' all of
  3067.           the 'get' information is released. However, this default
  3068.           can be changed.
  3069.  
  3070.    Parameter
  3071.           If 'do_release' is true (non-zero), all previously saved
  3072.           'get' information is immediately released. In addtion,
  3073.           'g4read' will release 'get' information before it returns.
  3074.  
  3075.           Otherwise if 'do_release' is false (zero), 'g4read' will
  3076.           not release 'get' information before it returns.
  3077.  
  3078.    Example
  3079.           d4learn_append()
  3080.           {
  3081.               int     row, i, rc ;
  3082.  
  3083.               if( d4use( "D4LEARN.DBF" ) 0 ) return -1 ;
  3084.  
  3085.               row = 5;
  3086.  
  3087.               /* Set up 'get' information */
  3088.               for ( i = 1; i <= f4num_fields(); i++ )
  3089.               g4field( row++, 20, f4j_ref(i) ) ;
  3090.  
  3091.               g4release( 0 ) ;    /* Do not Release */
  3092.  
  3093.               /* Append until <Esc> (27) is pressed */
  3094.               while( g4read() != 27 )
  3095.               d4write( 0L ) ;
  3096.  
  3097.               /* Release the 'get' information */
  3098.               g4release( 1 ) ;
  3099.  
  3100.               return 0;
  3101.           }
  3102.  
  3103. g4upper
  3104.  
  3105.    Usage
  3106.           void  g4upper()
  3107.  
  3108.    Get Category
  3109.           Post-Modifier
  3110.  
  3111.    Description
  3112.           All characters, for the previously specified entry area,
  3113.           will be converted to upper case as they are being entered.
  3114.  
  3115.  
  3116. g4valid
  3117.  
  3118.    Usage
  3119.           void  g4valid( (*routine) () )
  3120.  
  3121.    Get Category
  3122.           Post-Modifier
  3123.  
  3124.    Description
  3125.           'g4valid' specifies a validation routine for the previous
  3126.           Get Initialize routine. Routine 'g4read' calls the
  3127.           validation routine after information has been entered into
  3128.           the entry area. The validation routine is passed a pointer
  3129.           to the entry area's GET structure.
  3130.  
  3131.           If the validation routine returns '(int) 0', this validates
  3132.           the entry; if it returns a non-zero value, 'g4read' remains
  3133.           on the same entry area. It is the reponsibility of the
  3134.           validation routine to display an appropriate error message.
  3135.  
  3136.    Hint
  3137.           Try studying the examples in file 'w4example.c'
  3138.  
  3139.    Example
  3140.           #include <w4.h>
  3141.  
  3142.           int check_entry( get_ptr )
  3143.           GET *get_ptr ;
  3144.           {
  3145.               int *result_ptr ;
  3146.  
  3147.               result_ptr = (int *) get_ptr-> data ;
  3148.               if ( *result_ptr != -1 && *result_ptr != 1 )
  3149.               {
  3150.               w4( 0,0, "Enter -1 or 1 (Press a key) " )
  3151.               g4char() ;
  3152.               w4repeat( 0,0, (int) ' ', 80) ;
  3153.               return -1;      /* Not Valid */
  3154.               }
  3155.  
  3156.               return 0 ;  /* Vaild */
  3157.           }
  3158.  
  3159.           void valid_test()
  3160.           {
  3161.               int  i_data ;
  3162.  
  3163.               i_data = 1 ;
  3164.  
  3165.               g4int( 10,10, &i_data ) ;
  3166.               g4valid( check_entry ) ;
  3167.               g4read() ;
  3168.  
  3169.               w4( 12,10, "The result is: " ) ;
  3170.               w4int( 12, w4col(), i_data ) ;
  3171.           }
  3172.  
  3173.  
  3174. g4width
  3175.  
  3176.    Usage
  3177.           void  g4width( (int) width_str, (int) width_screen )
  3178.  
  3179.    Get Category
  3180.           Post-Modifier
  3181.  
  3182.    Description
  3183.           'g4width' explicitly specifies data widths and screen
  3184.           display widths.
  3185.  
  3186.           When entering character data, if there is more data in the
  3187.           string than room on the screen, only a subset of the string
  3188.           is displayed at one time.
  3189.  
  3190.    Parameters
  3191.           Name           Use
  3192.  
  3193.           width_str      This is the amount of character data in the
  3194.                  string parameter specified by Get-Initialize
  3195.                  routine 'g4'.
  3196.  
  3197.                  The data width is not flexible for 'g4double',
  3198.                  'g4int', 'g4field', 'g4logical', 'g4numeric',
  3199.                  and 'g4long'. For these cases, 'width_str'
  3200.                  should be '(int) 0'.
  3201.  
  3202.           width_scrren   This is the width of the entry area defined
  3203.                  by the previous Get Initialize routine.
  3204.  
  3205.  
  3206.  
  3207. MEMORY HANDLING ROUTINES
  3208.    This module provides memory handling for Code Base's Database, Index file,
  3209.    Block, Windowing, Menuing and Get memory structures. Using this memory
  3210.    handler, there is no Code Base specified limit to the number of opened
  3211.    databases or opened index files. In addition, small chunks of memory can
  3212.    be allocated and freed with little overhead.
  3213.  
  3214.    The first tow integers of each chunk of memory are reserved as pointers.
  3215.    These pointers are used to create double linked lists of allocated memory
  3216.    chunks.
  3217.  
  3218.  
  3219. h4add
  3220.  
  3221.    Usage
  3222.           int  h4add( (char **) ptr_ref_ptr, (int) mem_ref,
  3223.                   (int) add_ref, (int) add_before )
  3224.  
  3225.    Description
  3226.           'h4add' adds an allocated memory chunk to a double linked
  3227.           list.  It should not already be on one.
  3228.  
  3229.    Parameters
  3230.           Name           Use
  3231.  
  3232.           ptr_ref_ptr    A pointer to the base memory pointer. This
  3233.                  is the same value as was initially passed to
  3234.                  routine 'h4create'.
  3235.  
  3236.           mem_ref        A reference integer to the memory chunk.
  3237.  
  3238.           add_ref        The reference number to the memory chunk to
  3239.                  be inserted into the double linked list
  3240.                  either before or after 'mem_ref'.
  3241.  
  3242.           add_before     This value is '(int) 1' (true) if the memory
  3243.                  chunk is to be before 'mem_ref' and is
  3244.                  '(int) 0' (false) if the memory chunk is to
  3245.                  be after 'mem_ref'.
  3246.  
  3247.    Returns
  3248.           The value in parameter 'add_ref'.
  3249.  
  3250.    See Also
  3251.           'h4remove'
  3252.  
  3253.  
  3254. h4alloc
  3255.    Usage
  3256.           char *  h4alloc( (unsigned int) num_bytes )
  3257.  
  3258.    Description
  3259.           'h4alloc' allocates 'num_bytes' of memory and returns a
  3260.           pointer to allocated memory. The allocated memory is
  3261.           completely initialized to zeros.
  3262.  
  3263.    Return
  3264.           Normally, 'u4error' exits if there is not enough memory.
  3265.           However, if 'u4error' has been modified to return rather
  3266.           than exit, 'h4alloc' will return '(char *) 0' if no
  3267.           additional memory is available.
  3268.  
  3269.  
  3270. h4create
  3271.  
  3272.    Usage
  3273.           int  h4create( (char **) ptr_ref_ptr, (int) units,
  3274.                   (int) size, (int) expand_units )
  3275.  
  3276.    Description
  3277.           'h4create' does the initializing of a memory structure to
  3278.           be used with the Code Base memory handler.
  3279.  
  3280.    Parameters
  3281.           Name           Use
  3282.  
  3283.           ptr_ref_ptr    This is a pointer to the base memory pointer
  3284.                  for the memory structure.
  3285.  
  3286.           units          The number of chunks to be initially
  3287.                  allocated.
  3288.  
  3289.           size           The number of bytes in the memory structure.
  3290.  
  3291.           expand_units   The number of chunks to expand the structure
  3292.                  by when there are no more chunks available.
  3293.  
  3294.    Returns
  3295.           a '(int) -1' is returned to indicate the requested memory
  3296.           is not available. This error will only occur if 'u4error'
  3297.           has been modified not to exit an out of memory error.
  3298.  
  3299.  
  3300. h4free
  3301.  
  3302.    Usage
  3303.           int  h4free( (char **) ptr_ref_ptr, (int) mem_ref )
  3304.  
  3305.    Description
  3306.           'h4free' returns a chunk of memory to the pool of available
  3307.           memory.
  3308.  
  3309.    Parameters
  3310.           Name           Use
  3311.  
  3312.           ptr_ref_ptr    A pointer to the base memory pointer. This
  3313.                  is the value as was initially passed to
  3314.                  routine 'h4create'.
  3315.  
  3316.           mem_ref        A reference integer to the storage being
  3317.                  freed. This is the same integer which was
  3318.                  returned by 'h4get'.
  3319.  
  3320.    Return
  3321.           The reference integer to the previous memory chunk is
  3322.           returned. If a previous chunk does not exist, a reference
  3323.           integer to the next memory chunk will be returned. If there
  3324.           is no next memory chunk, '(int) -1' is returned.
  3325.  
  3326.  
  3327. h4free_chain
  3328.  
  3329.    Usage
  3330.           void  h4free_chain( (char **) ptr_ref_ptr, (int) mem_ref )
  3331.  
  3332.    Description
  3333.           'h4free_chain' calls 'h4free'repeatedly to free an entire
  3334.           chain of memory. This routine can be used as an example
  3335.           for 'h4free'.
  3336.  
  3337.    Source
  3338.           /* Source for 'h4free_chain' */
  3339.  
  3340.           void h4free_chain( ptr_ref_ptr, mem_ref)
  3341.           char  **ptr_ref_ptr ;
  3342.           int   mem_ref ;
  3343.           {
  3344.             while ( mem_ref = 0 )
  3345.                 mem_ref = h4free( ptr_ref_ptr, mem_ref ) ;
  3346.           }
  3347.  
  3348.  
  3349. h4free_memory
  3350.  
  3351.    Usage
  3352.           void  h4free_memory( (void *) ptr )
  3353.  
  3354.    Description
  3355.           This routine acts exactly like the 'free' routine in the
  3356.           standard library. It is necessary because the 'free'
  3357.           routine is not available under the current version of
  3358.           Microsoft Windows.
  3359.  
  3360.  
  3361. h4get
  3362.  
  3363.    Usage
  3364.           int  h4get( (char **) ptr_ref_ptr, (int) mem_ref )
  3365.  
  3366.    Description
  3367.           A chunk of memory is allocated.
  3368.  
  3369.    Parameters
  3370.           Name           Use
  3371.  
  3372.           ptr_ref_ptr    A pointer to the base memory pointer. This
  3373.                  is the same value as was initially passed to
  3374.                  routine 'h4create'.
  3375.  
  3376.           mem_ref        The allocated memory chunk is placed on a
  3377.                  double linked list just after the memory
  3378.                  chunk specified by 'mem_ref'. If 'mem_ref'
  3379.                  is '-1' a new double linked list is created.
  3380.                  Otherwise, 'mem_ref' must have previously
  3381.                  been returned by 'h4get'.
  3382.  
  3383.    Returns
  3384.           A memory reference number to the allocated memory chunk is
  3385.           returned. This number can be zero or greater.
  3386.  
  3387.           A return of '(int) -1' means that no additional memory is
  3388.           available. This error only occurs if 'u4error' has been
  3389.           modified to return on an out of memory error.
  3390.  
  3391.  
  3392. h4remove
  3393.  
  3394.    Usage
  3395.           int  h4remove( (char **) ptr_ref_ptr, (int) mem_ref )
  3396.  
  3397.    Description
  3398.           'h4remove' removes a memory chunk from its double linked
  3399.           list chain but does not free it.
  3400.  
  3401.           'h4remove' can be sued in conjunction with 'h4add' to
  3402.           transfer a memory chunk from one linked list to another.
  3403.           They can also be used to change the ordering of a linked
  3404.           list.
  3405.  
  3406.    Parameters
  3407.           Name           Use
  3408.  
  3409.           ptr_ref_ptr    A pointer to the base memory pointer. This
  3410.                  is the same value as was initially passed to
  3411.                  routine 'h4create'.
  3412.  
  3413.           mem_ref        A reference integer to the memory chunk.
  3414.  
  3415.    Returns
  3416.           Like 'h4free', the reference to the previous memory chunk
  3417.           is returned. If a previous chunk does not exist, a
  3418.           reference integer to the next memory chunk will be
  3419.           returned. If there is no next memory chunk, '(int) -1' is
  3420.           returned.
  3421.  
  3422.  
  3423. MEMORY HANDLING EXAMPLES:
  3424.  
  3425.     void mem_test()
  3426.     {
  3427.     struct test
  3428.     {
  3429.         int     next, prev ;
  3430.         char    name[20] ;
  3431.         char    city[25] ;
  3432.     } *test_ptr ;
  3433.  
  3434.     int chain_one, chain_two ;
  3435.  
  3436.     h4create( (char **) &test_ptr, 10, sizeof(struct test), 5);
  3437.  
  3438.     /* Allocate a chunk for 'chain_one' */
  3439.     chain_one = h4get( &test_ptr, -1 ) ;
  3440.  
  3441.     /* Allocate another chunk for 'chain_one' */
  3442.     chain_one = h4get( &test_ptr, chain_one ) ;
  3443.  
  3444.     /* Assign some data */
  3445.     strcpy( test_ptr[chain_one].name, "JACKSON" ) ;
  3446.     strcpy( test_ptr[chain_one].city, "LONDON" ) ;
  3447.  
  3448.     /* Allocate a chunk for 'chain_two' */
  3449.     chain_two = h4get( &test_ptr, -1 ) ;
  3450.  
  3451.     /* Free the most recently allocated chunk of 'chain_one' */
  3452.     chain_one = h4free( &test_ptr, chain_one );
  3453.     }
  3454.  
  3455.  
  3456.  
  3457. INDEX FILE ROUTINES
  3458.  
  3459.    Index files are used to quickly and efficiently create sorted orders for
  3460.    database files. Index files contain keys and corresponding record numbers.
  3461.    The key of an index file corresponds to a dBASE expression which is
  3462.    specified when the index file is created.
  3463.  
  3464.    Most routines in this module specify 'index_ref' as a parameter. This is
  3465.    an index reference number which is used to specify the index file.
  3466.  
  3467.    Many of the index file routines are used indirectly by routines in the
  3468.    database module. However, routines
  3469.    "i4open","i4close","i4index","i4reindex","i4select", and "i4unlock" will
  3470.    be used directly.
  3471.  
  3472.    For each index file there is an internal pointer which points to a
  3473.    key/record number combination it the index file. A memory structure,
  3474.    containing this key/record number combination, can be accessed by calling
  3475.    routine 'b4key'. This internal pointer is set by routines 'i4top',
  3476.    'i4bottom','i4go', and 'i4seek'. Futhermore, routine 'i4skip' changes the
  3477.    internal pointer relative to the current pointer's postion.
  3478.  
  3479.    Like database files, index files may be locked or unlocked. Whenever an
  3480.    index file routine, which sets the internal pointer, is called, the index
  3481.    file will automatically be locked. Index files can be unlocked by higher
  3482.    level database routines and certain index file routines like 'i4unlock'
  3483.    or 'i4close'. Note that when an index file is unlocked, its internal
  3484.    pointer becomes undefined.
  3485.  
  3486.    Hint:
  3487.        The following routines are usually not needed by the applications
  3488.        programmer: 'i4add', 'i4bottom', 'i4go', 'i4remove', 'i4seek',
  3489.        'i4skip', 'i4top', and 'i4type'. They are called by higher level
  3490.        database routines.
  3491.  
  3492.  
  3493. i4add
  3494.  
  3495.     Usage
  3496.           int  i4add( (int) index_ref, (char *) key_ptr,
  3497.                   (long) rec_num)
  3498.  
  3499.     Description
  3500.           'i4add' adds a key and a corresponding record number to the
  3501.           index file.
  3502.  
  3503.    Parameters
  3504.           Name        Use
  3505.  
  3506.           index_ref   The index file reference number.
  3507.  
  3508.           key_ptr     The key to be added.
  3509.  
  3510.           rec_num     The record number corresponding to the key.
  3511.  
  3512.    Returns
  3513.           Value       Meaning
  3514.  
  3515.            0          Success.
  3516.  
  3517.           -1          Error.
  3518.  
  3519.            1          The key alread exists and this index file must
  3520.                   have a unique key. (See i4index).
  3521.  
  3522.            2          The record number already exists. Note that
  3523.                   'i4add' does not always  detect duplicate
  3524.                   record numbers.
  3525.  
  3526.    Locking
  3527.           If the index file is unlocked, it will be locked.
  3528.  
  3529.  
  3530. i4bottom
  3531.  
  3532.    Usage
  3533.           int  i4bottom( (int) index_ref )
  3534.  
  3535.    Description
  3536.           Positions the index file's pointer to its last position.
  3537.  
  3538.    Returns
  3539.           Value       Meaning
  3540.  
  3541.            0          Success.
  3542.  
  3543.           -1          Error.
  3544.  
  3545.            3          End of File.(This occours when the index file
  3546.                   is empty.)
  3547.  
  3548.    Locking
  3549.           If the index file is unlocked, it will be locked.
  3550.  
  3551.  
  3552. i4check
  3553.  
  3554.    Usage
  3555.           long  i4check( index_ref )
  3556.  
  3557.    Description
  3558.           'i4check' is used to verify that an index file is
  3559.           completely accurate. This routine is intended to be used as
  3560.           a debugging tool.
  3561.  
  3562.           Sometimes when databases are updated, not all of the
  3563.           corresponding index files are open. Consequently,
  3564.           non-opened index files become out-of-date. 'i4check' is
  3565.           used to verify that this is not happening.
  3566.  
  3567.    Returns
  3568.           Value       Meaning
  3569.  
  3570.            0          Success, the index file is correct.
  3571.  
  3572.           >0          No index file key for this record number.
  3573.  
  3574.           -1          Error.
  3575.  
  3576.           -2          'i4check' only works for databases with less
  3577.                   than 512,000 records. Alternately, there is not
  3578.                   enough memory to perform the index file check.
  3579.  
  3580.           -3          Index file references a record which does not
  3581.                   exist.
  3582.  
  3583.           -4          There are two index file entries for the same
  3584.                   record.
  3585.  
  3586.           -5          The index key for a specific record is out of
  3587.                   date.
  3588.  
  3589.           -6          Index file keys are out of order.
  3590.  
  3591.    Locking
  3592.           The index file and the corresponding database are locked.
  3593.  
  3594.  
  3595. i4close
  3596.  
  3597.    Usage
  3598.           int  i4close( (int) index_ref )
  3599.  
  3600.    Description
  3601.           'i4close' closes the specified index file.
  3602.  
  3603.    Returns
  3604.           Value       Meaning
  3605.  
  3606.            0          Success.
  3607.  
  3608.           -1          Error.
  3609.  
  3610.  
  3611. i4eval
  3612.  
  3613.    Usage
  3614.           char *  i4eval( (int) index_ref )
  3615.  
  3616.    Description
  3617.           'i4eval' evaluates the index file expression corresponding
  3618.           to the specified index file and returns a pointer to the
  3619.           result. This result is in an internal static buffer. The
  3620.           calculation is based on the record currently in the
  3621.           database buffer.
  3622.  
  3623.           When using Clipper option, the result is formattted as a
  3624.           character string. For dBASE, the result will be formatted
  3625.           differently depending on the type of the index file
  3626.           expression.
  3627.  
  3628.           Expression Type          Result Format
  3629.  
  3630.               Character            Character String.
  3631.               Date                 Double representing Julian Day.
  3632.               Numeric              Double.
  3633.               Logical              A logical is not legitimate.
  3634.  
  3635.    Returns
  3636.           Value           Meaning
  3637.  
  3638.           Pointer         Pointer to result.
  3639.  
  3640.           Null Pointer    Error.
  3641.  
  3642.  
  3643. i4free
  3644.  
  3645.    Usage
  3646.           int  i4free( (int) index_ref )
  3647.  
  3648.    Description
  3649.           Buffered information associated with the index file is
  3650.           written to disk and the available memory is put into a pool
  3651.           to be made available to other index files.
  3652.  
  3653.    Hint
  3654.           It may be worth calling 'i4free' if a particular index file
  3655.           is not going to be used for a while.
  3656.  
  3657.    Returns
  3658.           Value       Meaning
  3659.  
  3660.            0          Success.
  3661.  
  3662.           -1          Error.
  3663.  
  3664.  
  3665. i4go
  3666.  
  3667.    Usage
  3668.           int  i4go( (int) index_ref, (char *) key_ptr,
  3669.                   (long) record_number )
  3670.  
  3671.    Description
  3672.           Sets the internal pointer of the index file to the key,
  3673.           record number combination specified by the parameters.
  3674.  
  3675.    Parameters
  3676.           Name            Use
  3677.  
  3678.           index_ref       The index reference number.
  3679.  
  3680.           key_ptr         The key's value.
  3681.  
  3682.           record_number   The record number corresponding to the key.
  3683.  
  3684.    Returns
  3685.           Value       Meaning
  3686.  
  3687.            0          Success.
  3688.  
  3689.            1          The key was located but the record number was
  3690.                   not. The internal pointer will point to the key
  3691.                   just after the specified key.
  3692.  
  3693.            2          The key was not located. The internal pointer
  3694.                   will point to the key just after the specified
  3695.                   key.
  3696.  
  3697.            3          The key was not located and the end of the file
  3698.                   was reached. The internal pointer points to the
  3699.                   end of the file.
  3700.            4          The key was located but the end of the file was
  3701.                   reached before the record could be found.
  3702.  
  3703.           -1          Error.
  3704.  
  3705.    Locking
  3706.           The index file is locked.
  3707.  
  3708.    Hint
  3709.           This routine is useful for locating a specific database
  3710.           record in the index file and then skipping to the next
  3711.           record using the index files sorted order.
  3712.  
  3713.  
  3714. i4index
  3715.  
  3716.    Usage
  3717.           int  i4index( (char *) name, (char *) expr, (int) unique,
  3718.                   (int) safety )
  3719.  
  3720.    Description
  3721.           The index file is created, opened, and selected. This index
  3722.           file will belong to the currently selected database. If
  3723.           safety is off and the file is already open, the file will
  3724.           be closed, deleted, and then created once more according to
  3725.           the parameter specifications.
  3726.  
  3727.           If no file extension is specified, ".NDX" is appended to
  3728.           the name.
  3729.  
  3730.    Parameters
  3731.           Name        Use
  3732.  
  3733.           name        The name of the new index file.
  3734.  
  3735.           expr        A dBASE expression specifying the sort order.
  3736.                   Refer to the appendix on expressions.
  3737.  
  3738.           unique      Specifies whether each key in the index file
  3739.                   must be unique. When using Clipper option,
  3740.                   setting this flag to Unique results in
  3741.                   incompatibility with Clipper. 1 - Unique; else,
  3742.                   Not Unique.
  3743.  
  3744.           safety      Specifies whether any existing file should be
  3745.                   removed.
  3746.                   1 - Do not remove existing file. Return an
  3747.                   error if one exists.
  3748.                   0 - Remove any existing file with the same name.
  3749.  
  3750.    Returns
  3751.           Value       Meaning
  3752.  
  3753.           >= 0        The index file reference number.
  3754.  
  3755.             -1        Error.
  3756.  
  3757.    Locking
  3758.           The index file is not locked.
  3759.  
  3760.    Example
  3761.           i4index( "TEST", "LAST_NAME+FIRST_NAME", 0,0 ) ;
  3762.           i4index( "TEST_TWO", "UPPER(NAME)", 0,0 ) ;
  3763.  
  3764.  
  3765. i4lock
  3766.  
  3767.    Usage
  3768.           int  i4lock( (int) index_ref, (int) do_wait )
  3769.  
  3770.    Description
  3771.           If the index file is already locked an immediate succesful
  3772.           return will be made. Otherwise, an attempt is made to lock
  3773.           the index file. If 'do_wait' is FALSE (0), and the file is
  3774.           locked by another user, '(int) -2' is returned. However,
  3775.           if 'do_wait" is TRUE (1), 'i4lock' keeps trying (once per
  3776.           second) until it succeeds.
  3777.  
  3778.    Returns
  3779.           Value       Meaning
  3780.  
  3781.            0          Success.
  3782.  
  3783.           -1          Error.
  3784.  
  3785.           -2          Locked by another user.
  3786.  
  3787.  
  3788. i4open
  3789.  
  3790.    Usage
  3791.           int  i4open( (char *) file_name )
  3792.  
  3793.    Description
  3794.           'i4open' opens and selects the specified index file. The
  3795.           corresponding database must be selected.
  3796.  
  3797.           If the file name does not have any extension, the '.NDX'
  3798.           extension will be provided.
  3799.  
  3800.    Returns
  3801.           Value       Meaning
  3802.  
  3803.           >= 0        The index file reference number associated with
  3804.                   the newly opened index file.
  3805.  
  3806.             -1        Error.
  3807.  
  3808.  
  3809. i4ref
  3810.  
  3811.    Usage
  3812.           int  i4ref( (char *) name )
  3813.  
  3814.    Description
  3815.           'i4ref' returns the index file reference number of a
  3816.           previously opened index file.  This is the same number
  3817.           which was returned when the index file was originally opened.
  3818.  
  3819.           If no extension is present in the file name. ".NDX" is
  3820.           automatically used.
  3821.  
  3822.    Returns
  3823.           Value       Meaning
  3824.  
  3825.           >= 0        The index file reference number.
  3826.  
  3827.             -1        Error; the index file is not currently open.
  3828.  
  3829.  
  3830. i4reindex
  3831.  
  3832.    Usage
  3833.           int  i4reindex( (int) index_ref )
  3834.  
  3835.    Description
  3836.           'i4reindex' reindexes the specified index file. If
  3837.           'index_ref' is negative, all the index files for the
  3838.           current database will be reindexed.
  3839.  
  3840.           'i4free' is called for all index files. Consequently, all
  3841.           current index file positions are lost. Note that this does
  3842.           not matter when using high level database routines such as
  3843.           'd4skip' and 'd4seek'.
  3844.  
  3845.    Returns
  3846.           Value       Meaning
  3847.  
  3848.            0          Success.
  3849.  
  3850.           -1          Error.
  3851.  
  3852.    Hint
  3853.           When the contents of a database are changed without the
  3854.           corresponding index file being open the index file will not
  3855.           be updated. Before using an index file which is not up to
  3856.           date, it should be reindexed.
  3857.  
  3858.  
  3859. i4remove
  3860.  
  3861.    Usage
  3862.           int  i4remove( (int) index_ref, (char *) key_ptr,
  3863.                  (long) rec_num )
  3864.  
  3865.    Description
  3866.           'i4remove' removes the key/record number combination from
  3867.           the index file.
  3868.  
  3869.    Parameters
  3870.           Name        Use
  3871.  
  3872.           index_ref   The index file reference number.
  3873.  
  3874.           key_ptr     The value of the key.
  3875.  
  3876.           rec_num     The record number corresponding to the key value.
  3877.  
  3878.    Returns
  3879.           Value       Meaning
  3880.  
  3881.            1          The key was not located and consequently could
  3882.                   not be removed.
  3883.  
  3884.            0          Success.
  3885.  
  3886.           -1          Error.
  3887.  
  3888.    Locking
  3889.           The index file is locked.
  3890.  
  3891.  
  3892.  
  3893. i4seek
  3894.    Usage
  3895.           int  i4seek( (int) index_ref , (void *) key_ptr 0
  3896.  
  3897.    Description
  3898.           The internal pointer is positioned to point to the first
  3899.           entry corresponding to the specified key value.
  3900.  
  3901.    Parameters
  3902.           Name        Use
  3903.  
  3904.           index_ref   The index reference number.
  3905.  
  3906.           key_ptr     The value of the key.
  3907.  
  3908.    Returns
  3909.           There are several possible returns which indicate the
  3910.           result of the search.  For a complete explanation of the
  3911.           following returns, refer to 'd4seek'.
  3912.  
  3913.           Value       Meaning
  3914.  
  3915.            0          Exact find.
  3916.  
  3917.            1          Inexact find.
  3918.  
  3919.            2          On key after.
  3920.  
  3921.            3          End of file.
  3922.  
  3923.           -1          Error.
  3924.  
  3925.    Locking
  3926.           The index file is locked.
  3927.  
  3928.    See Also
  3929.           'b4key'
  3930.  
  3931.  
  3932. i4seek_ref
  3933.  
  3934.    Usage
  3935.           int  i4seek_ref()
  3936.  
  3937.    Description
  3938.           'i4seek_ref' returns the index file reference number to the
  3939.           index file which would be used by 'd4seek'. This is
  3940.           normally the currently selected index file. However, if
  3941.           there is no currently selected index file, the reference
  3942.           number to the last opened index file is used instead. If
  3943.           there are no open index files for the database '(int) -1'
  3944.           is returned.
  3945.  
  3946.  
  3947. i4selected
  3948.  
  3949.    Usage
  3950.           int  i4select( (int) index_ref )
  3951.  
  3952.    Description
  3953.           'i4select' selects the specified index file. Subsequently,
  3954.           the database routines 'd4seek','d4top', and 'd4bottom', use
  3955.           the selected index file for their logical positioning. If
  3956.           'index_ref' is '(int) -1', record number ordering is
  3957.           selected.
  3958.  
  3959.    Returns
  3960.           Value       Meaning
  3961.  
  3962.           >= 0        The previously selected index file reference
  3963.                   number.
  3964.  
  3965.             -1        There was no previously selected index file.
  3966.                   Record number ordering was previously selected.
  3967.  
  3968.    Locking
  3969.           The previously selected index file is unlocked.
  3970.  
  3971.  
  3972.  
  3973. i4skip
  3974.  
  3975.    Usage
  3976.           long  i4skip( (int) index_ref, (long) n )
  3977.  
  3978.    Description
  3979.           'i4skip' skips the internal pointer the specified number of
  3980.           records. This skipping is done using the logical order
  3981.           defined by the index file.
  3982.  
  3983.           If there is no current position, (ex. the file is unlocked)
  3984.           skipping is relative to the top logical position.
  3985.  
  3986.           When skipping from an end of file or beginning of file
  3987.           position, skipping is done from the bottom or top position
  3988.           respectively.
  3989.  
  3990.    Parameters
  3991.           Name        Use
  3992.  
  3993.           index_ref   The index reference number.
  3994.  
  3995.           n           The number of records to skip.
  3996.  
  3997.    Returns
  3998.           'i4skip' returns the number of records actually skipped. If
  3999.           this number requested, an end of file or beginning of file
  4000.           has been reached.
  4001.  
  4002.           If an error occurs, '-n' is returned. Note that 'i4skip'
  4003.           returns immediately with a '(long) 0' if zero records and
  4004.           requested. Consequently, and error will never occur when
  4005.           'n' is '(long) 0'.
  4006.  
  4007.    Locking
  4008.           The index file is locked.
  4009.  
  4010.  
  4011. i4top
  4012.  
  4013.    Usage
  4014.           int  i4top( (int) index_ref )
  4015.  
  4016.    Description
  4017.           The index file's internal pointer is set to the top position.
  4018.  
  4019.    Returns
  4020.           Value       Meaning
  4021.  
  4022.            0          Success.
  4023.  
  4024.           -1          Error.
  4025.  
  4026.            3          End of file. (The index file is empty.)
  4027.  
  4028.    Locking
  4029.           The index file is locked.
  4030.  
  4031.  
  4032.  
  4033. i4type
  4034.  
  4035.    Usage
  4036.           char  i4type( (int) index_ref )
  4037.  
  4038.    Description
  4039.           The type of index file is returned as a character.
  4040.  
  4041.    Returns
  4042.           Value       Meaning
  4043.  
  4044.           C           Character Type.
  4045.  
  4046.           D           Date Type.
  4047.  
  4048.           N           Numeric Type.
  4049.  
  4050.    Example
  4051.           if ( i4type( i_ref) == 'C' ) do_true() ;
  4052.  
  4053.  
  4054. i4unlock
  4055.  
  4056.    Usage
  4057.           int  i4unlock( (int) index_ref )
  4058.  
  4059.    Description
  4060.           If 'index_ref' is '(int) -1' all of the index files
  4061.           corresponding to the currently selected database are
  4062.           unlocked. Otherwise, the specified index file is unlocked.
  4063.  
  4064.    Returns
  4065.           Value       Meaning
  4066.  
  4067.            0          Success.
  4068.  
  4069.           -1          Error.
  4070.  
  4071.    Locking
  4072.           Index files are unlocked as described above.
  4073.  
  4074.  
  4075. i4unselect
  4076.  
  4077.    Usage
  4078.           void  i4unseletect()
  4079.  
  4080.    Description
  4081.           Record number ordering is chosen for the selected database.
  4082.  
  4083.    Returns
  4084.           'i4unselet' always returns '(int) 0'
  4085.  
  4086.    Locking
  4087.           If an index file was selected, it is unlocked.
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093. MEMO ROUTINES
  4094.  
  4095.    Memo Routines record variable length test into memo files. Memo file text
  4096.    always associated with a memo field or a particular database record.
  4097.    Consequently, memo file routines, like the field routines, use a field
  4098.    reference number. Refer to the field routines for more information about
  4099.    field reference numbers.
  4100.  
  4101.    Code Base provides two sets of memo file routines. The first set, as
  4102.    documented in this chapter, has routine names starting with 'm4'. The
  4103.    other set, has routine names starting with 'm3'. With respect to memo file
  4104.    compatibility, dBASE III, dBASE III PLUS, Clipper, and the 'm3' Code Base
  4105.    memo file routines are all identical. Likewise, with respect to memo file
  4106.    compatibility, dBASE IV and the 'm4' Code Base routines are identical.
  4107.  
  4108.    From a functionality point of view, the 'm3' routines and the 'm4'
  4109.    routines are indentical. Consequently, the documentation on the 'm4'
  4110.    routines also applies to the 'm3' routines. However, due to a more
  4111.    sophisticated dBASE IV memo file format, the 'm4' routines always recover
  4112.    disk space when re-writing memo file information.
  4113.  
  4114.    A special routine, 'm4convert', has been provided to convert dBASE III
  4115.    memo files so that they can be used with the 'm4' routines. Another
  4116.    special routine, 'm4renamed', is used after renaming dBASE IV memo file.
  4117.    Once a converted memo file has been modified using the 'm4' routines, it
  4118.    can no longer be used by the 'm3' routines. Before this modification using
  4119.    a 'm4' routine, a converted memo file can be used normally with the 'm3'
  4120.    routines and can be read with the 'm4' routines.
  4121.  
  4122.    All memo file locking and unlocking is automatic.
  4123.  
  4124.    Warning
  4125.  
  4126.        dBASE IV users should not create memo files using a block size
  4127.        different from the default size of 512 bytes. This is because dBASE IV
  4128.        has a bug which immediately corrupts memo files, with a greater block
  4129.        size, after they have been renamed under DOS. For this reason,
  4130.        'd4create' always creates memo files with the default block size,
  4131.        explicit file conversion is necessary using 'm4convert', and
  4132.        'm4renamed' is used after renameing memo files.
  4133.  
  4134.  
  4135. m4check
  4136.  
  4137.    Usage
  4138.           (long *)  m4check( (long) field_ref )
  4139.  
  4140.    Description
  4141.           'm4check' analyses the contents of a memo file to determine
  4142.           how data is being stored internally. To understand the
  4143.           values returned, it is necessary to realize that when memo
  4144.           file space is freed, the free entries are chained together.
  4145.           The when additional space is needed, the free space can be
  4146.           used before additional space is allocated at the end of the
  4147.           file.
  4148.  
  4149.           Call 'm4check' using 'd4learn'. It is probably not
  4150.           necessary to call 'm4check' from your own programs.
  4151.  
  4152.    Returns
  4153.           A null pointer is returned to indicate that there is a
  4154.           problem with the memo file specified by 'field_ref'. Either
  4155.           the 'field_ref' parameter is bad, the memo file does not
  4156.           exist, the memo file is corrupted, or not enough memory is
  4157.           available to perform the check..
  4158.  
  4159.           Otherwise, a pointer to an array of 5 long integers is
  4160.           returned. These long integers specify the following facts
  4161.           respectively:
  4162.  
  4163.           Return No.  Meaning
  4164.  
  4165.            0          The number of free entries. This number should
  4166.                   be as low as possible.
  4167.  
  4168.            1          The total number of free blocks (512 bytes per
  4169.                   block). There may be more free blocks than free
  4170.                   entries as each entry can consist of one or
  4171.                   more blocks.
  4172.  
  4173.            2          The number of adjacent entries. This number
  4174.                   should be as low as possible as it is better to
  4175.                   have one large free entry than several small
  4176.                   adjacent entries.
  4177.  
  4178.            3          The number of lost blocks. This is memo file
  4179.                   space which is not used and is not in the free
  4180.                   chain.
  4181.  
  4182.            4          The number of used blocks.
  4183.  
  4184.  
  4185. m4convert
  4186.  
  4187.    Usage
  4188.           int  m4convert( (char *) file_name )
  4189.  
  4190.    Description
  4191.           'm4convert' writes some information to a memo file so that
  4192.           a dBASE III memo file can be used with the other 'm4'
  4193.           routines. It is safe to use 'm4convert' on dBASE III memo
  4194.           files or dBASE IV memo files with the default block size.
  4195.  
  4196.    Returns
  4197.           Value       Meaning
  4198.  
  4199.            0          Success.
  4200.  
  4201.           -1          Error.
  4202.  
  4203.    See Also
  4204.           The memo file routines introduction.
  4205.  
  4206.  
  4207. m4edit
  4208.  
  4209.    Usage
  4210.           int  m4edit( (long) field_ref, (long) rec_num,
  4211.                   (char *) editor_name, (int) max_size )
  4212.  
  4213.    Description
  4214.           The memo file data is copied to a temporary file and a
  4215.           program is executed with the temporary file name as a
  4216.           parameter. Then the contents of the temporary file are
  4217.           copied back to the memo file. The first four characters of
  4218.           the temporary file name start with "MEMO" and the last four
  4219.           characters change to ensure the temporary file did not
  4220.           previously exist.
  4221.  
  4222.           Consequently, any editor which accepts a file name as a
  4223.           parameter can be used to modify the contents of a memo field.
  4224.  
  4225.           This routine is not available under the Unix/Xenix version.
  4226.  
  4227.    Parameters
  4228.           Value           Meaning
  4229.  
  4230.           field_ref       Identifies the memo field.
  4231.  
  4232.           rec_num         The database record number.
  4233.  
  4234.           editor_name     The name of a program which accepts a file
  4235.                   name as a parameter.
  4236.  
  4237.           max_size        The maximum length of the memo field. This
  4238.                   amount of memory is temporarily allocated
  4239.                   to hold the contents of the memo field.
  4240.  
  4241.    Returns
  4242.           Value       Meaning
  4243.  
  4244.            0          Success.
  4245.  
  4246.           -1          Error.
  4247.  
  4248.            1          Not Enough Memory.
  4249.  
  4250.                   No error message is displayed.
  4251.  
  4252.    Locking
  4253.           Record 'rec_num" is locked. The memo file is locked and
  4254.           unlocked automatically. As the temporary file is created in
  4255.           the current directory, this routines works in a multi_user
  4256.           environment provided each user has a different directory.
  4257.  
  4258.    Example
  4259.           m4edit( f4ref("MEMO_FLD"), 2L, "PROG", 5000 ) ;
  4260.  
  4261.  
  4262. m4exist
  4263.  
  4264.    Usage
  4265.           int  m4exist( (long) field_ref )
  4266.  
  4267.    Description
  4268.           'm4exist' determines if memo field data is present without
  4269.           reading the memo file.
  4270.  
  4271.    Returns
  4272.           Value       Meaning
  4273.  
  4274.            0          No memo field data is present for the current
  4275.                   record.
  4276.  
  4277.            1          Memo field data is present.
  4278.  
  4279.    Note
  4280.           The data currently in record buffer is used.
  4281.  
  4282.  
  4283. m4read
  4284.  
  4285.    Usage
  4286.           int  m4read( (long) field_ref, (long) rec_num,
  4287.                   (char *) str, (int) str_len )
  4288.  
  4289.    Description
  4290.           'm4read' reads a memo field into string 'str'. At most,
  4291.           'str_len' characters are read. On completion, 'str' is null
  4292.           terminated. In addition, routine 'd4go' is called to read
  4293.           record 'rec_num' into the record buffer.
  4294.  
  4295.    Parameters
  4296.           Name        Use
  4297.  
  4298.           field_ref   The field reference number of the memo field.
  4299.  
  4300.           rec_num     The record number of the memo data.
  4301.  
  4302.           str         A pointer to where the memo text is placed.
  4303.  
  4304.           str_len     The number of bytes of space declared for
  4305.                   string 'str'.
  4306.  
  4307.    Returns
  4308.           Value       Meaning
  4309.  
  4310.           >= 0        The number of characters actually read.
  4311.  
  4312.             -1        Error.
  4313.  
  4314.    Locking
  4315.           Record 'rec_num' is locked. The memo file is locked and
  4316.           unlocked automatically.
  4317.  
  4318.  
  4319. m4renamed
  4320.  
  4321.    Usage
  4322.           int  m4renamed( (char *) file_name )
  4323.  
  4324.    Description
  4325.           'm4renamed' is called after a dBASE IV memo file has been
  4326.           renamed under DOS. When renaming a memo file, it is
  4327.           important to rename the corresponding database at the same
  4328.           time. Memo files should have the same name as the
  4329.           corresponding database except for the tile extension which
  4330.           is ".DBT" for memo files.
  4331.  
  4332.    Parameter
  4333.           'file_name' is the name of the memo file which is to be
  4334.           renamed.
  4335.  
  4336.    Returns
  4337.           Value       Meaning
  4338.  
  4339.            0          Success.
  4340.  
  4341.           -1          Error.
  4342.  
  4343. m4write
  4344.  
  4345.    Usage
  4346.           int  m4write( (long) field_ref, (long) rec_num,
  4347.                   (char *) str, (int) str_len )
  4348.  
  4349.    Description
  4350.           Information is written to the memo field specified by
  4351.           'field_ref'. In the process, routine 'd4go' is called to
  4352.           read the contents of 'rec_num' and then 'd4write' is called
  4353.           to write the altered contents.
  4354.  
  4355.    Parameter
  4356.           Name        Use
  4357.  
  4358.           field_ref   The field reference number of the memo field.
  4359.  
  4360.           rec_num     The record number of the memo data.
  4361.  
  4362.           str         The string to be written.
  4363.  
  4364.           str_len     The number of characters to write.
  4365.  
  4366.    Returns
  4367.           Value       Meaning
  4368.  
  4369.           >= 0        The number of characters written.
  4370.  
  4371.             -1        Error.
  4372.  
  4373.    Locking
  4374.           Record 'rec_num' is locked. The memo file is locked and
  4375.           unlocked automatically.
  4376.  
  4377.    Warning
  4378.           The contents of the record buffer are changed.
  4379.  
  4380.  
  4381.  
  4382.  
  4383. MENUING ROUTINES
  4384.  
  4385.    Using the versatile Code Base Menuing Routines, it is possible to build
  4386.    almost any kind of menu. Specifically, pulldown, popup, vertical,
  4387.    horizontal, and lotus style menus can all be created.
  4388.  
  4389.    Any Code Base menu corresponds to a specific window. The characteristics
  4390.    of the menu window, such as the dimensions, all apply to the menu. Each
  4391.    menu has a number of menu items. These menu items correspond to the
  4392.    possible menu choices. The terms "pulldown menu" and "Lotus menu" are not
  4393.    actually a single menu according to the strict definition of a Code BAse
  4394.    "menu". Pulldown and Lotus menus actually consist of a main menu and a
  4395.    number of sub-menus.
  4396.  
  4397.    The following routines provide settings for the menu of the currently
  4398.    selected window:
  4399.  
  4400.        Routine                Quick Description
  4401.  
  4402.        n4attribute            Sets the default attribute for menu items.
  4403.        n4horizontal           Specifies a horizontal menu.
  4404.        n4item_width           The spacing between horizontal menu items.
  4405.  
  4406.    These routines provide settings which apply to a specific menu item:
  4407.  
  4408.        Routine                Quick Description
  4409.  
  4410.        n4attribute_item       Sets a specific display attribute for a menu
  4411.                   item.
  4412.        n4message              Specifies a message for the menu item
  4413.        n4key                  Sets a specific key to activate the menu item.
  4414.        n4skip_over            Specifies whether a menu item may be selected.
  4415.  
  4416.    Any menu item can have a corresponding 'action routine' and a 'reaction
  4417.    routine'. If a menu item has an action routine, the action routine is
  4418.    called when the menu item is activated. The reaction routine is called
  4419.    when the menu prompt is moved to the menu item.
  4420.  
  4421.    Action and reaction routines all have integer return codes which instruct
  4422.    routine 'n4activate', the menu activation routine, to do the following:
  4423.  
  4424.        Value      Meaning
  4425.  
  4426.        < 0        Return from the menu activation routine 'n4activate' with
  4427.           the same value as a return code.
  4428.      0        Read a command character from the keyboard.
  4429.        > 0        Interpret the value as a command character exactly as if it
  4430.           had been read from the keyboard.
  4431.  
  4432.    It is important to realize that routine 'n4activate' can be used as both
  4433.    an action or a reaction routine. In these cases, 'n4activate' calls itself
  4434.    to create a sub-menu. This happens when using Lotus or pulldown menus.
  4435.  
  4436.    There are extensive menuing examples in file 'w4example.c'. In addition,
  4437.    there is a short, yet complete and standalone, pulldown menu example under
  4438.    routine 'n4pulldown'.
  4439.  
  4440.  
  4441. n4
  4442.  
  4443.    Usage
  4444.           int  n4( (char *) label )
  4445.  
  4446.    Description
  4447.           Routine 'n4' defines a single menu item. Either all menu
  4448.           items, for a particular menu, should be defined with
  4449.           routine 'n4' or all menu items should be defined with
  4450.           routine 'n4item'. If the menu items are defined with
  4451.           routine 'n4item', the position of the menu items are
  4452.           specified exactly. However, when using routine 'n4' the
  4453.           positions are calculated and menu item scrolling is
  4454.           possible. Scrolling occurs when there is not enough room in
  4455.           the window for all of the menu items at once.
  4456.  
  4457.    Parameters
  4458.           'label' is a pointr to the menu item text which is
  4459.           displayed as part of the menu. The pointer should point to
  4460.           permanent rather than temporary memory as 'n4' saves only a
  4461.           copy of the pointer. If the text pointed to by 'label'
  4462.           changes, the the display text changes.
  4463.  
  4464.    Returns
  4465.           A menu item reference number, for the new menu item is
  4466.           returned.
  4467.  
  4468.  
  4469. n4action
  4470.  
  4471.    Usage
  4472.           int n4action( (ACTION *) action_routine, [p1,] [p2,] ... )
  4473.  
  4474.    Description
  4475.           'n4action' specifies an action routine for the menu item
  4476.           which has just bee created using either 'n4' or 'n4item'.
  4477.  
  4478.           It is also possible to call 'n4action' with a null action
  4479.           routine and a single integer parameter. In this case,
  4480.           'n4activate' will return the integer parameter. In this
  4481.           case, 'n4activate' will return the integer parameter if the
  4482.           corresponding menu item is chosen:
  4483.  
  4484.               n4action( (ACTION *) 0, integer_code ) ;
  4485.  
  4486.    Parameters
  4487.           'action_routine' is the name of a routine which is to be
  4488.           called by 'n4activate' when the menu item is activated.
  4489.  
  4490.           Parameters 'p1','p2',... are a variable number of
  4491.           parameters of optional type which are passed to the action
  4492.           routine when it is called. However, there can be a mazimum
  4493.           of four integers worth of parameters. Note if you wish to
  4494.           pass non integer data, the effect of this restriction is
  4495.           compiler and memory model dependent. That noted, for the
  4496.           Quick C, Microsoft C and Turbo C compilers on the IBM PC
  4497.           this restriction translates to the following parameter
  4498.           maximums:
  4499.  
  4500.               1. Four Integers.
  4501.               2. Two Pointers (Any memory model).
  4502.               3. Two Longs.
  4503.               4. One Pointer and Two Integers.
  4504.               5. One Long and Two Integers.
  4505.               6. One Pointer and One Long.
  4506.               7. One Double.
  4507.  
  4508.           To be safe with all compiliers, make the restriction one
  4509.           integer, one long or one pointer. To make a large amount of
  4510.           data available to an action routine, pass a pointer to a
  4511.           structure or an array containing the data.
  4512.  
  4513.    Hint
  4514.           Routine 'n4activate' can be used as an action routine to
  4515.           define a sub-menu. In this case 'n4activate' will call
  4516.           itself. This is an example of 'recursion'.
  4517.  
  4518.    Example
  4519.           #include <w4.h>
  4520.  
  4521.           typedef  struct
  4522.           {
  4523.               int     num_pieces ;
  4524.               long    piece_info[100] ;
  4525.               char    descriptionsp[100][20] ;
  4526.           }   MENU_DATA ;
  4527.  
  4528.           /* These routines are user defined */
  4529.           static  int get_data( MENU_DATA * ) ;
  4530.           static  int process_data( MENU_DATA * ) ;
  4531.           static  int sub_option_one_routine( void ) ;
  4532.           static  int sub_option_two_routine( void ) ;
  4533.  
  4534.           main()
  4535.           {
  4536.               int     main_menu_ref, sub_menu_ref;
  4537.               long    action_data[100] ;
  4538.  
  4539.               /* 'n4calc' fills in the window dimensions */
  4540.               main_menu_ref = w4define( -1,-1,-1,-1 ) ;
  4541.  
  4542.               /* Define three menu items */
  4543.               n4 ( "Sub Menu" ) ;
  4544.               n4action( n4activate, &sub_menu_ref ) ;
  4545.  
  4546.               n4( "Get Data" ) ;
  4547.               n4action( get_data, &action_data ) ;
  4548.  
  4549.               n4( "Process Data" ) ;
  4550.               n4action( process_data, &action_data ) ;
  4551.  
  4552.               /* Define the sub_menu */
  4553.               sub_menu_ref = w4define( -1,-1,-1,-1 ) ;
  4554.  
  4555.               n4( "Sub Option One" ) ;
  4556.               n4action( sub_option_one_routine ) ;
  4557.  
  4558.               n4( "Sub Option Two" ) ;
  4559.               n4action( sub_option_two_routine ) ;
  4560.  
  4561.               /* Automatically calculate the menu
  4562.              coordinates, sizes, and assign a default
  4563.              menu border for a vertical menu. */
  4564.  
  4565.               n4calc( main_menu_ref, 6,12 ) ;
  4566.  
  4567.               /* Activate the constructed system of menus */
  4568.               n4activate( &main_menu_ref ) ;
  4569.  
  4570.               w4exit (0) ;
  4571.           }
  4572.  
  4573.  
  4574. n4activate
  4575.  
  4576.    Usage
  4577.           int  n4activate( (int *) window_ref_ptr )
  4578.  
  4579.    Description
  4580.           'n4activate' activates a menu. In doing so, the associated
  4581.           window is also activated. 'n4activate' is the largest, most
  4582.           important, menuing routine. All of the other menu routines
  4583.           are called to prepare for the call to 'n4activate'.
  4584.  
  4585.           Before 'n4activate' returns, the menu window is deactivated
  4586.           and the previously selected window is re-selected.
  4587.  
  4588.    Parameters
  4589.           A menu is uniquely identified by the window reference
  4590.           number of the window which contains it. 'window_ref_ptr' is
  4591.           a pointer to the window's window reference number.
  4592.  
  4593.    Returns
  4594.           'n4activate' returns any negative value returned by an
  4595.           action or reaction routine. In addition, if a menu item has
  4596.           an action routine integer parameter, but a null action
  4597.           routine pointer, the action routine parameter is returned
  4598.           when the menu item is activated. Using this techinque, an
  4599.           'n4activate' can return an integer code corresponding to a
  4600.           menu choice.
  4601.  
  4602.           Some characters, when entered from the keyboard, cause
  4603.           'n4activate' to exit. If such a character is entered,
  4604.           'n4activate' returns it on exit. Characters which cause
  4605.           'n4activate' to exit are specified by routine
  4606.           'n4key_special'. In addition, for horizontal menus, the up
  4607.           and down arrow keys may cause 'n4activate' to return.
  4608.           Likewise, for vertical menus, the right and left arrow keys
  4609.           may cause 'n4activate' to exit. Refer to routine
  4610.           'n4arrow_exit'.
  4611.  
  4612.           Positive characters returned by action and reaction
  4613.           routines are treated as keyboard input by 'n4activate'.
  4614.           Consequently, if a character entered from the keyboard
  4615.           causes 'n4activate' to return, the same character returned
  4616.           by an action or reaction routine causes 'n4activate' to
  4617.           return. In this case, 'n4activate' returns the character
  4618.           value causing the exit.
  4619.  
  4620.           Finally, 'n4activate' returns zero if there are no menu
  4621.           items in the window or if the window is too samll.
  4622.  
  4623.    Note
  4624.           When using 'n4activate' as a parameter to routine
  4625.           'n4action' or 'n4reaction', it is convenient to be able to
  4626.           reference menus which have not yet been defined. This is
  4627.           why the parameter to 'n4activate' is a pointer to the
  4628.           window reference number of the menu's window.
  4629.  
  4630.           In the example under routine 'n4action', notice how a
  4631.           pointer to the variable 'sub_menu_ref' is passed to
  4632.           routine 'n4activate'. Later in the program, 'sub_menu_ref'
  4633.           is assigned a specific window reference number.
  4634.  
  4635.    See Also
  4636.           Menu Routines introduction, 'n4key_special'
  4637.  
  4638.  
  4639. n4arrow_exit
  4640.  
  4641.    Usage
  4642.           void  n4arrow_exit()
  4643.  
  4644.    Description
  4645.           Normally, <up> and <down> arrows are ignored in horizontal
  4646.           menus. In addition, <left> and <right> arrows are ignored
  4647.           in vertical menus. By calling 'n4arrow_exit' this default
  4648.           is changed for the menu of the currently selected window.
  4649.           When an arrow key, which otherwise would have been ignored,
  4650.           is pressed, 'n4activate' will return the character key code
  4651.           of the arrow key.
  4652.  
  4653.    Note
  4654.           This feature is necessary for pulldown menus. When a <Left>
  4655.           or <Right> arrow key is pressed, when using a pulldown menu
  4656.           system, the arrow key command must be returned to the top
  4657.           horizontal menu.
  4658.  
  4659.  
  4660. n4attribute
  4661.  
  4662.    Usage
  4663.           void  n4attribute( (long) attribute,
  4664.                   (long) attribute_prompt )
  4665.  
  4666.    Description
  4667.           'n4attribute' sets default attributes for the menu items of
  4668.           the currently selected window.
  4669.  
  4670.    Parameters
  4671.           Name                Use
  4672.  
  4673.           attribute           This is the default character for
  4674.                       subsequently defined menu items.  The
  4675.                       attribute for any particular menu item
  4676.                       can be set using routine
  4677.                       'n4attribute_item'.  If this routine is
  4678.                       not called, the default is F_WHITE.
  4679.  
  4680.           attribute_prompt    When interacting with a menu, the menu
  4681.                       prompt is always 'on' a particular menu
  4682.                       item. This menu item is always
  4683.                       displayed with a different attribute to
  4684.                       distinguish if from the other menu
  4685.                       items. 'attribute_prompt' specifieds
  4686.                       that special attribute for the menu of
  4687.                       the currently selected window. If this
  4688.                       routine is not called, the menu prompt
  4689.                       attributes is B_WHITE (inverse video).
  4690.  
  4691.  
  4692.  
  4693. n4attribute_item
  4694.  
  4695.    Usage
  4696.           void  n4attribute_item( (int) item_ref, (long) attribute )
  4697.  
  4698.    Description
  4699.           'n4attribute_item' assigns an attribute to a specifid menu
  4700.           item.
  4701.  
  4702.    Parameters
  4703.           Name        Use
  4704.  
  4705.           item_ref    The menu item reference number.
  4706.           attribute   The attribute to be assigned to the menu item.
  4707.  
  4708.    Example
  4709.           item_ref = n4item( 2,2, "Choice One" ) ;
  4710.           n4attribute_item( item_ref, F_BLUE ) ;
  4711.  
  4712.  
  4713. n4calc
  4714.  
  4715.    Usage
  4716.           void  n4calc( (int) w_ref, (int) start_row, (int) start_col )
  4717.  
  4718.    Description
  4719.           'n4calc' sets the window dimensions for the specified
  4720.           window. The window dimensions will be large contain the
  4721.           window's menu.
  4722.  
  4723.           In addition, 'n4calc' makes the menu window a popup window
  4724.           and assigns a single line border.
  4725.  
  4726.           If 'n4calc' detects any sub-menus, it calls itself
  4727.           recursively to define the window dimensions of the
  4728.           sub-menu's windows. The sub-menu's  windows are also made
  4729.           popup and assigned single line borders.
  4730.  
  4731.    Parameters
  4732.           Name        Use
  4733.  
  4734.           w_ref       The window reference number.
  4735.  
  4736.           start_row   The menu window's starting row.
  4737.  
  4738.           start_col   The menu window's starting column. The starting
  4739.                   column may be changed by 'n4calc' if the
  4740.                   specified value is so large the menu cannot fit
  4741.                   on the screen.
  4742.  
  4743.    Hint
  4744.           If you want the menu to be as far to the right as possible,
  4745.           set parameter 'start_col' to '(int) 79'.
  4746.  
  4747.           Like 'n4pulldown' and 'n4lotus','n4calc' lets the
  4748.           programmer quickly generate impressive looking menus.
  4749.  
  4750.    Example
  4751.           n4calc( w_ref, 0, 79 ) ;
  4752.  
  4753.           /* Replace the single line border set by 'n4calc' with a
  4754.              double line border. */
  4755.           w4border( DOUBLE, F_BLUE ) ;
  4756.  
  4757.  
  4758. n4get_calc
  4759.  
  4760.    Usage
  4761.           void  n4get_calc( (int) w_ref )
  4762.  
  4763.    Description
  4764.           It is possible to use menus to enter data into entry zones
  4765.           specified by the 'get' rouitnes. This is done using
  4766.           routine 'g4call' in conjunction with 'g4menu' or
  4767.           'g4menu_help'.
  4768.  
  4769.           When using a menu for this purpose, 'n4get_calc' will
  4770.           calculate the dimensions and position the menu.
  4771.  
  4772.    Parameters
  4773.           'w_ref' is the window corresponding to the 'get' entry areas.
  4774.  
  4775.    See Also
  4776.           Routines 'n4calc', 'n4pulldown' and 'n4lotus' use the same
  4777.           concept but calculate window positions and widths for
  4778.           different purposes.
  4779.  
  4780.    Example
  4781.           /* Example for 'n4get_calc' */
  4782.           #include "w4.h"
  4783.  
  4784.           static  char    last_name[20] ;
  4785.  
  4786.           void    enter_data()
  4787.           {
  4788.               int     get_ref, menu_ref ;
  4789.  
  4790.               menu_ref = w4define( -1,-1,-1,-1 ) ;
  4791.               n4( "Tim Jones" ) ;
  4792.               n4( "Fred Calvert" );
  4793.               n4( "Kenneth Powers" );
  4794.  
  4795.               get_ref = w4define( 10,15, 14,65 ) ;
  4796.               w4activate( get_ref ) ;
  4797.               w4( 1, 5, "Enter Last Name: " ) ;
  4798.  
  4799.               g4( 1, w4col(), last_name );
  4800.               g4width( (int) sizeof(last_name), (int)
  4801.                   sizeof(last_name) ;
  4802.               g4call( g4menu_help, menu_ref ) ;
  4803.               g4message( "Press <F1> for Help" ) ;
  4804.  
  4805.               /* 'g4call' saves the pointer to routine 'g4menu_help'
  4806.               and the menu reference number 'menu_ref'.
  4807.               Routine 'n4get_calc' looks at all of the 'gets'
  4808.               scheduled for window 'get_ref'. It recognizes the
  4809.               address of call routine 'g4menu_help' and knows
  4810.               the saved parameter 'menu_ref' must be a window
  4811.               reference number. Then it calculates appropriate
  4812.               window dimensions and an appropriate position for
  4813.               the menu window identified by 'menu_ref'. */
  4814.  
  4815.               n4get_calc( get_ref ) ;
  4816.               g4read() ;              /* And so on ... */
  4817.           }
  4818.  
  4819.  
  4820. n4horizontal
  4821.  
  4822.    Usage
  4823.           void  n4horizontal()
  4824.  
  4825.    Description
  4826.           By default, a menu is vertical. 'n4horizontal' changes that
  4827.           default to horizontal. The difference between a
  4828.           'horizontal' and a 'vertical' menu is that up and down
  4829.           arrow keys are used in vertical menus and left and right
  4830.           arrow keys are used in vertical menus.
  4831.  
  4832.  
  4833. n4item
  4834.  
  4835.    Usage
  4836.           int  n4item( (int) row, (int) column, (char *) label )
  4837.  
  4838.    Description
  4839.           'n4item' defines a single menu item within a window. It is
  4840.           identical to routine 'n4' except that the two additional
  4841.           parameters, 'row' and 'column', specify where the menu item
  4842.           is to be placed within the window.
  4843.  
  4844.           In order to successfully use 'n4item', all of the menu
  4845.           items in the window must be specified with routine
  4846.           'n4item'. In addition, every call to 'n4item', for the
  4847.           window, must have positive 'row' and 'column' parameters.
  4848.  
  4849.    Parameters
  4850.           Name        Use
  4851.  
  4852.           row         The row, within the selected window, to place
  4853.                   the menu item.
  4854.  
  4855.           column      The column, within the selected window, to
  4856.                   place the menu item.
  4857.  
  4858.           label       A pointer to the display text which identifies
  4859.                   the menu item to the user.
  4860.  
  4861.    Returns
  4862.           The menu reference number corresponding to the new menu item.
  4863.  
  4864.    Note
  4865.           Routine 'n4' calls routine 'n4item' substituting '(int) -1'
  4866.           for the row and column parameters.
  4867.  
  4868.  
  4869. n4item_text
  4870.  
  4871.    Usage
  4872.           (char *)  n4item_text( (int) item_ref )
  4873.  
  4874.    Description
  4875.           'n4item_text' returns a pointer to the text of the menu
  4876.           item specified by parameter 'item_ref'.
  4877.  
  4878.  
  4879. n4item_width
  4880.  
  4881.    Usage
  4882.           void  n4item_width( (int) width )
  4883.  
  4884.    Description
  4885.           'n4item_width' helps determine the appearance of the menu
  4886.           defined in the current window. This is only relevant when
  4887.           routine 'n4', rather than 'n4item', is used to define the
  4888.           menu items.
  4889.  
  4890.           'n4item_width' is used mainly to give horizontal menus
  4891.           exact column spacing. By default, there is only one column
  4892.           per menu. Consequently, it is critical to call
  4893.           'n4item_width' for horizontal menus where Code Base
  4894.           calculates the menu item positions. In addition, by using
  4895.           'n4item_width', it is possible for a menu to have several
  4896.           columns and/or rows.
  4897.  
  4898.    Parameter
  4899.           'width' specifies the number of characters in one menu
  4900.           column. The total number of menu columns can be determined
  4901.           by dividing the window width by the 'width' parameter.
  4902.  
  4903.    Example
  4904.           main()
  4905.           {
  4906.               int     w_ref ;
  4907.  
  4908.               /* Defines a Horizontal Menu with 2 rows and 4
  4909.               columns */
  4910.               w_ref = w4define( 0,0, 1,79 ) ;
  4911.               n4horizontal() ;
  4912.               n4item_width( 20 ) ;
  4913.               .
  4914.               .
  4915.           }
  4916.  
  4917.  
  4918. n4key
  4919.  
  4920.    Usage
  4921.           void  n4key( (int) chr, (int) activate, (int) highlight_pos )
  4922.  
  4923.    Description
  4924.           By default, it is possible to actiavte a menu item by
  4925.           pressing a key corresponding to the first character of the
  4926.           menu item description. In addition, when the description is
  4927.           displayed, this same character is displayed with an intense
  4928.           attribute.
  4929.  
  4930.           'n4key' changes the above defaults.
  4931.  
  4932.    Parameters
  4933.           Name            Use
  4934.  
  4935.           chr             Pressing this character causes the menu
  4936.                   prompt to move to the menu item.  If 'chr' is
  4937.                   zero, no character will correspond to the
  4938.                   menu item.
  4939.  
  4940.           activate        If 'activate' is TRUE (non-zero), pressing
  4941.                   the menu key activates the menu item.
  4942.                   However, if 'activate' if FALSE (zero),
  4943.                   pressing the menu key causes the menu prompt
  4944.                   to move to the menu item.
  4945.  
  4946.           highlight_pos   This number specifies which character of
  4947.                   the menu item description is displayed with
  4948.                   a F_INTENSE attribute. Zero specifies the
  4949.                   first character, on the second, and so on.
  4950.                   If 'highlight_pos' is '(int) -1', no
  4951.                   character will be highlighted.
  4952.  
  4953.  
  4954. n4key_set
  4955.  
  4956.    Usage
  4957.           void  n4key_set( (int) set_code, (int) ignore_case )
  4958.  
  4959.    Description
  4960.           'n4key_set' specifies some keyboard input options. These
  4961.           options apply to the currently selected menu window.
  4962.  
  4963.    Parameters
  4964.           Name            Value    Meaning
  4965.  
  4966.           set_code        0        Ignore any keyboard input except for
  4967.                        the arrow keys, <Return>, <PgUp>,
  4968.                        <PgDn>, <Home>, <End>, and the
  4969.                        special keys set by routine
  4970.                        'n4key_special'.
  4971.  
  4972.                   1        Default.  Move the menu prompt to
  4973.                        the first menu item which matches
  4974.                        the entered key.  Refer to routine
  4975.                        'n4key'.
  4976.  
  4977.                   2        The user is allowed to search for a
  4978.                        menu item by entering a string of
  4979.                        characters to search for.  In this
  4980.                        case, the menu prompt moves to the
  4981.                        item corresponding to the entered
  4982.                        characters.  Matching characters are
  4983.                        displayed intensely and blinking.
  4984.  
  4985.           ignore_case     0        FALSE. Be case sensitive.
  4986.  
  4987.                   1        This is the default, TRUE. All
  4988.                        characters are considered
  4989.                        uppercase for the purposes of
  4990.                        search comparison.
  4991.  
  4992.  
  4993. n4key_special
  4994.  
  4995.    Usage
  4996.           void  n4key_special( (int) up_key, (int) exit_key,
  4997.                   (int) return_start, (int) return_end )
  4998.  
  4999.    Description
  5000.           This routine specifies some keyboard characters which, when
  5001.           entered, cause 'n4activate' to do something special. These
  5002.           special characters apply to subsequently defined menu
  5003.           windows. Consequently, each menu window can have its own
  5004.           set of special characters.
  5005.  
  5006.    Parameters
  5007.           Name            Use
  5008.  
  5009.           up_key          This key causes 'n4activate' to return.
  5010.                   However if 'n4activate' has called itself
  5011.                   recursively, creating a submenu only the
  5012.                   lowest level submenu returns.  By default,
  5013.                   this is the <Esc> key.
  5014.  
  5015.           exit_key        This key causes 'n4activate' to return.  If
  5016.                   'n4activate' has called itself recursively,
  5017.                   creating a submenu, all of the 'n4activate'
  5018.                   routines will return the entered 'exit_key'.
  5019.                   By default, this key is <Ctrl C>.  In Lotus
  5020.                   style menus this key is '/'.
  5021.  
  5022.           return_start    This is a range of keys which cause
  5023.                   'n4activate' to return. Theses keys are
  5024.                   slightly different than the 'up_key' as the
  5025.                   only apply if the key otherwise does
  5026.                   nothing else.
  5027.  
  5028.           return_end      This feature can be useful in pulldown
  5029.                   menus when a set of characters, such as
  5030.                   the <Alt> keys, could potentially activate
  5031.                   menu items in the top horizontal menu.
  5032.  
  5033.    Hint
  5034.           The numeric value for special keys are in 'g4char.h'. For
  5035.           example, ALT_A is defined to be 0x1E00 and ALT_Q is defined
  5036.           to be 0x1000. Notice that ALT_Q < ALT_A ! consequently, the
  5037.           range ALT_A to ALT_Z does not include ALT_Q. (The original
  5038.           designers of the IBM PC assigned these out of order codes. )
  5039.  
  5040.  
  5041. n4lotus
  5042.  
  5043.    Usage
  5044.           n4lotus( (int) window_ref )
  5045.  
  5046.    Descripiton
  5047.           Once the menu items of a lotus menu have been defined,
  5048.           'n4lotus' can be used to calculate the window positions and
  5049.           dimensions. It also specifies popup menu windows and
  5050.           changes the position 'n4message_do' displays at, to the
  5051.           appropriate position.
  5052.  
  5053.           If the starting (row, column) position of the main lotus
  5054.           menu window has been defined using 'w4define', it will be
  5055.           used. This would move the entire menu relative to the new
  5056.           starting position.
  5057.  
  5058.    Parameters
  5059.           'window_ref' is the menu reference number of the main lotus
  5060.           menu.
  5061.  
  5062.    Example
  5063.           #include <w4.h>
  5064.           #include <g4char.h>
  5065.  
  5066.           main()
  5067.           {
  5068.               int  main_ref, one_ref ;
  5069.  
  5070.               w4clear(-1) ;   /* Clear the screen */
  5071.  
  5072.               /* Position the lotus menu at the bottom of the
  5073.              screen. ie (23,0) */
  5074.               main_ref = w4define ( 23,0, -1,-1 ) ;
  5075.               n4( "One" ) ;
  5076.               n4message( "Sub Choice 1     Sub Choice 2" ) ;
  5077.               n4action( n4activate, &one_ref ) ;
  5078.  
  5079.               /* Routine 'two_action' is executed if 'Two' is
  5080.              chosen.  */
  5081.  
  5082.               n4( "Two" ) ;
  5083.               n4message( "Two Action" ) ;
  5084.               n4action( two_action ) ;
  5085.  
  5086.               /* Define the sub-menu which is displayed if main menu
  5087.              choice 'One' is chosen */
  5088.  
  5089.               one_ref = w4define( -1,-1,-1,-1 ) ;
  5090.               n4( "Sub Choice 1" ) ;
  5091.               n4action( w4display, "Sub Choice 1", (char *) 0 ) ;
  5092.  
  5093.               n4( "Sub Choice 2")
  5094.               n4action( w4display, "Sub Choice 2", (char *) 0 ) ;
  5095.  
  5096.               /* Turn the menus into a 'lotus' menu */
  5097.               n4lotus( main_ref ) ;
  5098.  
  5099.               /* Activate the menuing system */
  5100.               while( n4activate( &main_ref ) == (int) '/' ) ;
  5101.  
  5102.               w4exit(0) ;
  5103.           }
  5104.  
  5105.  
  5106. n4message
  5107.  
  5108.    Usage
  5109.           n4message( (char *) message )
  5110.  
  5111.    Description
  5112.           'n4message' specifies a message corresponding to the menu
  5113.           item which has just been created using 'n4' or 'n4item'.
  5114.  
  5115.    Parameters
  5116.           Name        Use
  5117.  
  5118.           message     This message is associated with the last
  5119.                   defined menu item. The message is automatically
  5120.                   displayed when the menu prompt is moved to the
  5121.                   menu item.
  5122.  
  5123.    See Also
  5124.           'n4message_do'; An example is under routine 'n4lotus'.
  5125.  
  5126.  
  5127. n4message_do
  5128.  
  5129.    Usage
  5130.           n4message_do( (char *) message )
  5131.  
  5132.    Description
  5133.           This routine is called by 'n4activate' to display the
  5134.           message strings specified by 'n4message'.
  5135.  
  5136.           'n4message_do' immediately displays a text string at the
  5137.           absolute screen coordinates specified by external integer
  5138.           variables 'v4menu_row' and 'v4menu_col'. By default, these
  5139.           variables are 24 and 0 respectively. If the string is not
  5140.           long enough to display to the end of the screen, extra
  5141.           blank characters are displayed. If 'ptr' is '(char *) 0',
  5142.           the row, starting from 'v4menu_col', is blanked.
  5143.  
  5144.    Parameters
  5145.           'message' points to the message string.
  5146.  
  5147.  
  5148. n4pulldown
  5149.  
  5150.    Usage
  5151.           void  n4pulldown( (int) window_ref )
  5152.  
  5153.    Description
  5154.           Once the windows and menu items for a pulldown menu system
  5155.           have been defined, 'n4pulldown' can be used to calculate
  5156.           window dimensions and positions. In addition, 'n4pulldown'
  5157.           assigns borders, specifies popup menus, specifies the main
  5158.           menu as horizontal, and assigns special keys normally
  5159.           specified with routines 'n4key_special'.
  5160.  
  5161.           If the starting (row,column) position of the main menu
  5162.           window has been defined in the call ot 'w4define', those
  5163.           coordinates are the top left corner of the pulldown menu.
  5164.           Otherwise, the pulldown menu will be positioned at
  5165.           coordinates (0,0).
  5166.  
  5167.    Parameters
  5168.           'window_ref' is the window reference number of the pulldown
  5169.           menu's horizontal menu bar.
  5170.  
  5171.    Example
  5172.           #include <d4base.h>
  5173.           #include <w4.h>
  5174.           #include <stdlib.h>
  5175.  
  5176.           main()
  5177.           {
  5178.               int     horizontal_ref, sub_one, sub_two ;
  5179.               char    no_flds[20], *rec_ptr ;
  5180.  
  5181.               /* Open the database */
  5182.               if ( d4use( "TEST.DBF" ) < 0 ) exit (1) ;
  5183.  
  5184.               w4clear( -1 ) ;         /* Clear the Window */
  5185.               w4cursor( -1, -1 ) ;    /* Remove the cursor */
  5186.  
  5187.               /* Calculate some display information */
  5188.               itoa( f4num_fields(), no_flds, 10 ) ;
  5189.               rec_ptr = f4record();
  5190.  
  5191.               /* Define the horizontal menu bar. */
  5192.               horizontal_ref = w4define( -1,-1,-1,-1 ) ;
  5193.               /* Define the main menu items */
  5194.               n4( "Position Database" ) ;
  5195.               n4reaction( n4activate, &sub_one ) ;
  5196.  
  5197.               n4( "Display" ) ;
  5198.               n4reaction( n4activate, &sub_two ) ;
  5199.  
  5200.               /* Define the 'Display' sub_menu */
  5201.               sub_two = w4define( -1,-1,-1,-1 ) ;
  5202.  
  5203.               n4( "Database Record" ) ;
  5204.               n4action( w4display, rec_ptr, (char *) 0 ) ;
  5205.  
  5206.               n4( "Number of Fields" ) ;
  5207.               n4action( w4display, no_flds, (char *) 0 ) ;
  5208.  
  5209.               /* Turn the menus into a pulldown menu. */
  5210.               n4pulldown( horizontal_ref ) ;
  5211.  
  5212.               /* Activate the menuing pulldown system */
  5213.               n4activate( &horiziontal_ref ) ;
  5214.  
  5215.               w4close( horizontal_ref ) ;
  5216.               w4close( sub_one ) ;
  5217.               w4close( sub_two ) ;
  5218.  
  5219.               w4exit(0) ;
  5220.           }
  5221.  
  5222.  
  5223. n4reaction
  5224.  
  5225.    Usage
  5226.           n4reaction( (ACTION *) reaction_routine, [p1,] [p2,] [p3,]
  5227.                   [p4,] )
  5228.  
  5229.    Description
  5230.           'n4reaction' specifies a reaction routine for the menu item
  5231.           which has just been defined using either 'n4' or 'n4item'.
  5232.           The reaction routine is executed when the menu prompt moves
  5233.           to the corresponding menu item through arrowing or an
  5234.           appropriate key selection. 'n4activate' is used as a
  5235.           reaction routine to automatically activate the pulldown
  5236.           part of a pulldown menu system.
  5237.  
  5238.           'n4reaction' differs from 'n4action' only in that it
  5239.           specifies a 'reaction' routine rather than a 'action'
  5240.           routine.
  5241.  
  5242.    See Also
  5243.           Menuing routines introduction and 'n4action'.
  5244.  
  5245.    Example
  5246.           n4( "Menu Option With a Reaction Routine" ) ;
  5247.           n4reaction( n4activate, &menu_window_ref_no ) ;
  5248.  
  5249.  
  5250. n4refresh
  5251.  
  5252.    Usage
  5253.           void  n4refresh( (int) window_ref )
  5254.  
  5255.    Description
  5256.           This routine is called by action or reaction routines when
  5257.           they change the display attribute attribute or label of a
  5258.           menu item. It instructs 'n4activate' to refresh the menu
  5259.           window after the action or reaction routine returns.
  5260.  
  5261.    Parameters
  5262.           'window_ref' identifies the window to be refreshed.
  5263.  
  5264.  
  5265. n4search
  5266.  
  5267.    Usage
  5268.           int  n4search( (char *) description_ptr )
  5269.  
  5270.    Descripiton
  5271.           'n4search' searches within the selected window for a
  5272.           particular menu item description.
  5273.  
  5274.    Parameters
  5275.           'description_ptr' points to a menu item description.
  5276.           'n4search' looks for this menu item within the selected
  5277.           window.
  5278.  
  5279.    Returns
  5280.           Value       Meaning
  5281.  
  5282.             -1        The description was not located.
  5283.  
  5284.           >= 0        The menu item reference number whose menu item
  5285.                   descripiton matches 'description_ptr'.
  5286.  
  5287.    Note
  5288.           'n4search' is called by routien 'g4menu' so that the
  5289.           initially active menu item corresponds to the original
  5290.           contents of the entry area.
  5291.  
  5292.           After calling 'n4search', the returned menu item reference
  5293.           number is often used as a parameter to routine
  5294.           'n4start_item'.
  5295.  
  5296.  
  5297. n4skip_over
  5298.  
  5299.    Usage
  5300.           int  n4skip_over( (int) menu_ref, (int) flag )
  5301.  
  5302.    Description
  5303.           'n4skip_over' specifies whether the menu prompt can move to
  5304.           a particular menu item. This is useful for menu items which
  5305.           are documenting text rather than a valid choice. It is also
  5306.           used so that a menu item temporarily cannot be activated.
  5307.  
  5308.    Parameters
  5309.           Name        Use
  5310.  
  5311.           menu_ref    A menu item reference number.
  5312.  
  5313.           flag        TRUE (non-zero) if the menu item is to be
  5314.                   skipped over  and FALSE (zero) if the menu item
  5315.                   is to be used.
  5316.  
  5317.    Returns
  5318.           The prviously set flag value is returned.
  5319.  
  5320.  
  5321.  
  5322. n4start_item
  5323.  
  5324.    Usage
  5325.           void  n4start_item( (int) start_item_ref )
  5326.  
  5327.    Description
  5328.           By default, the menu prompt starts on the first menu item.
  5329.           However, 'n4start_item' can force the menu prompt to start
  5330.           on any menu item.
  5331.  
  5332.           As Code Base knows which window correponds to the menu item
  5333.           reference number, it does not matter which window is
  5334.           selected.
  5335.  
  5336.    Parameters
  5337.           The menu prompt starts on the menu item specified by the
  5338.           menu item reference number 'start_item_ref'.
  5339.  
  5340.  
  5341.  
  5342. UTILITY ROUTINES
  5343.  
  5344.    The utility routines are low level general purpose routines.
  5345.  
  5346.  
  5347. u4error
  5348.  
  5349.    Usage
  5350.           int  u4error( (int) error_num, (char *) string 1,
  5351.                   (char *) string 2, ..., (char *) string n,
  5352.                   (char *) 0 )
  5353.  
  5354.    Description
  5355.           'u4error' is called whenever an error occurs. Normally,
  5356.           error information is sent to the default window. However,
  5357.           if the 'u4error' has been recompilied with the 'NOIO'
  5358.           switch defined, error information is sent to standard out.
  5359.           The error information consists of the error number,
  5360.           information corresponding to the error number, and all of
  5361.           the additional parameters strings.
  5362.  
  5363.           Refer to the Appendix on Error Messages for additional
  5364.           information on error handling.
  5365.  
  5366.    Parameters
  5367.           Only the 'error_num' parameter and the last '(char *) 0'
  5368.           parameter are required. There is an optional list of error
  5369.           strings. The '(char *) 0' is a signal that there are no
  5370.           additional parameters.
  5371.  
  5372.    Returns
  5373.           For critical errors, 'u4error' exits to the operating
  5374.           system. For less critical errors, 'u4error' waits until a
  5375.           key is pressed and the value of the pressed key is returned.
  5376.  
  5377.  
  5378. u4file_first
  5379.  
  5380.    Usage
  5381.           int  u4file_first( (char *) pattern, (char *) first_match )
  5382.  
  5383.    Description
  5384.           'u4file_first' works with routine 'u4file_next' to obtain a
  5385.           list of file names corresponding to a particluar DOS wild
  5386.           card file specification. It is available for DOS users
  5387.           only. When using wild cards, an '*' matches any sequence of
  5388.           file characters and '?' matches any single file character.
  5389.           For more information on wild card file specifications,
  5390.           refer to DOS 'dir' command.
  5391.  
  5392.           'u4file_first' is used to obtain the first matching file
  5393.           name. Subsequent matching names are obtained using routine
  5394.           'u4file_next'.
  5395.  
  5396.    Parameters
  5397.           Name            Use
  5398.  
  5399.           pattern         The DOS file pattern which may contain wild
  5400.                   card characters.  The Unix/Xenix version of
  5401.                   Code Base currently ignores the 'pattern'
  5402.                   parameter.
  5403.  
  5404.           first_match     This is a pointer to a least 14 characters
  5405.                   of data. 'u4file_first' copies the first
  5406.                   matching file name to this data space.
  5407.  
  5408.    Returns
  5409.           'u4file_first' and 'u4file_next' follow the return
  5410.           conventions of DOS interrupt 0x211, types 0x4E and 0x4F.
  5411.  
  5412.           Value       Meaning
  5413.  
  5414.            0          Success.
  5415.            2          Invalid File Specification.
  5416.           18          No File Match.
  5417.  
  5418.    Example
  5419.           for ( rc = u4file_first( "*.*",ptr); rc == 0;
  5420.                   rc = u4file_next(ptr) )
  5421.           {
  5422.                w4( w4row()+1,0,ptr) ; /* Display file name */
  5423.           }
  5424.  
  5425.  
  5426. u4file_next
  5427.  
  5428.    Usage
  5429.           int  u4file_next( (char *) next_match )
  5430.  
  5431.    Description
  5432.           'u4file_next' works with 'u4file_first' to find the next
  5433.           matching file pattern.
  5434.  
  5435.    Parameters
  5436.           'next_match' is a pointer to at least 14 characters of
  5437.           available data. The next matching file name is copied into
  5438.           this data space.
  5439.  
  5440.    Returns
  5441.           Value       Meaning
  5442.  
  5443.            0          Success.
  5444.  
  5445.           18          No More File Matches.
  5446.  
  5447.  
  5448. u4lock
  5449.  
  5450.    Usage
  5451.           int  u4lock( (int) dos_file, (long) offset, (long)
  5452.                   num_bytes, (int) do_wait )
  5453.  
  5454.    Description
  5455.           'u4lock' locks a section of any file. If 'do_wait' is TRUE
  5456.           (non-zero) 'u4lock' waits as long as necessary to lock
  5457.           information. Otherwise, 'u4lock' returns immediately.
  5458.  
  5459.    Parameters
  5460.           Name        Use
  5461.  
  5462.           dos_file    A file handle corresponding to the file to be
  5463.                   locked.
  5464.  
  5465.           off_set     The byte number, from the beginning of the
  5466.                   file, to start the locking at. Offset '(int) 0'
  5467.                   corresponding to the first byte of the file.
  5468.  
  5469.           num_bytes   The number of bytes to be locked.
  5470.  
  5471.           do_wait     Wait if TRUE (non-zero).
  5472.  
  5473.    Returns
  5474.           Value       Meaning
  5475.  
  5476.            0          Success or Single User Environment.
  5477.           -1          Error.
  5478.           -2          Information locked by another user.
  5479.  
  5480.  
  5481. u4name_char
  5482.  
  5483.    Usage
  5484.           int  u4name_char( (char) test_char )
  5485.  
  5486.  
  5487.    Description
  5488.           Returns true if the test character is a valid character for
  5489.           a file name. Otherwise, false is returned.
  5490.  
  5491.    Returns
  5492.           Zero represents false; any other return represents true.
  5493.  
  5494.    Example
  5495.           if ( ! u4name_char( name_char ) )
  5496.               printf("\n Illegal Name Chr: %c", name_char ) ;
  5497.  
  5498.  
  5499. u4name_full
  5500.  
  5501.    Usage
  5502.           void u4name_full( (char *) result, (char *) name,
  5503.                   (char *) extension )
  5504.  
  5505.    Descripiton
  5506.           'u4name_full' adds a default file name extension to a file
  5507.           name. If the name already has an extension, the original
  5508.           name is returned.
  5509.  
  5510.    Parameters
  5511.           Name        Use
  5512.  
  5513.           result      The file name, complete with a file extension,
  5514.                   is copied to 'result'. Up to 68 bytes of memory
  5515.                   may be required for '* result'.
  5516.  
  5517.           name        This is a null terminated string representing
  5518.                   the original file name.
  5519.  
  5520.           extension   A three character file name extension. It may
  5521.                   optionally be preceded by a period ('.').
  5522.  
  5523.  
  5524.  
  5525. u4name_part
  5526.  
  5527.    Usage
  5528.           void  u4name_part( (char *) result, (char *) name,
  5529.                   (int) give_dir, (int) give_ext )
  5530.  
  5531.    Description
  5532.           'u4name_part' takes a file name and removes the directory
  5533.           and/or extension part of it.
  5534.  
  5535.    Parameters
  5536.           Name        Use
  5537.  
  5538.           result      This parameter points the an area in memory
  5539.                   where the resulting file name should be placed.
  5540.  
  5541.           name        The starting file name.
  5542.  
  5543.           give_dir    'give_dir' it TRUE (non-zero) if the directory
  5544.                   part of the file name is to be part of the
  5545.                   resulting file name. Otherwise,
  5546.                   'give_directory' should be FALSE (zero).
  5547.  
  5548.           give_ext    'give_ext' is TRUE (non-zero) if the extension
  5549.                   part of the file name is to be part of the
  5550.                   resulting file name. Otherwise, 'give_ext'
  5551.                   should be FALSE (zero).
  5552.  
  5553.  
  5554. u4open
  5555.  
  5556.    Usage
  5557.           int  u4open( (char *) file_name, (int) code )
  5558.  
  5559.    Description
  5560.           'u4open' opens a file.
  5561.  
  5562.    Parameters
  5563.           Name        Use
  5564.  
  5565.           file_name   The name of the file to be opened.
  5566.  
  5567.           code        This code specifies how to open the file:
  5568.  
  5569.                   0 - Open; the file must already exist.
  5570.                   1 - Create; the file must not yet exist.
  5571.                   2 - Create; erase any existing file.
  5572.  
  5573.    Returns
  5574.           Value       Meaning
  5575.  
  5576.           >= 0        The file handle of the opened file.
  5577.  
  5578.             -1        Error.
  5579.  
  5580.  
  5581. u4sort
  5582.  
  5583.    Usage
  5584.           void  u4sort( (void *) base, (size_t) num, (size_t) width,
  5585.                   (int) (*compare) ((void *) el, (void *) e2))
  5586.  
  5587.    Description
  5588.           'u4sort' is a replacement for the 'qsort' routine in the
  5589.           Turbo C and Microsoft C runtime libraries. It is included
  5590.           for efficiency reasons. Parameter 'width' cannot be larger
  5591.           than the maximum index file key size. This is 100 when
  5592.           using dBASE 'NDX' files and 338 when using Clipper 'NTX'
  5593.           files.
  5594.  
  5595.  
  5596. u4unlock
  5597.  
  5598.    Usage
  5599.           int  u4unlock( (int) dos_file, (long) offset,
  5600.                   (long) num_bytes )
  5601.  
  5602.    Description
  5603.           'u4unlock' unlocks a section of any file. This section must
  5604.           have previously been locked.
  5605.  
  5606.    Parameters
  5607.           Name        Use
  5608.  
  5609.           dos_file    A file handle corresponding to the file to be
  5610.                   unlocked.
  5611.  
  5612.           off_set     The byte number, from the beginning of the
  5613.                   file, to start the unlocking at. Offset
  5614.                   '(int) 0' corresponds to the first byte of the
  5615.                   file.
  5616.  
  5617.           num_bytes   The number of bytes to be unlocked.
  5618.  
  5619.    Returns
  5620.           Value       Meaning
  5621.  
  5622.            0          Success.
  5623.  
  5624.           -1          Error.
  5625.  
  5626.    Note
  5627.           Success is always returned in a single user environment.
  5628.  
  5629.  
  5630.  
  5631.  
  5632. WINDOWING ROUTINES
  5633.  
  5634.    Windowing routines are used to send and read information to and from the
  5635.    display screen. They also are used to send information to output handles.
  5636.    Both the menuing and get routines extensively use the windowing routines.
  5637.  
  5638.    Screen windows have a designated rectangular area on the screen, and an
  5639.    attribute character. Windows can have borders or titles. They can be
  5640.    popup, and can have a memory copy of their contents for restoring
  5641.    purposes. All windows have a current (row, column) position.
  5642.  
  5643.    the windowing routines allow convenient output of database fields adn the
  5644.    various C data types: (long), (double), (int), and (char *). There are
  5645.    also routines for cursor manipulation, text centering, and window clearing.
  5646.  
  5647.    Only one window can be selected at a time. Many window routines, such as
  5648.    'w4popup', specify the characteristics of the selected window. In
  5649.    addition, the output routines, such as 'w4int', use the selected window.
  5650.  
  5651.    Although it is possible to send output to a window after selecting it, is
  5652.    usually best to call 'w4activate' first. This will allow smooth operation
  5653.    of popups, automatic border creation, and window deactivation.
  5654.  
  5655.    When writing to a window, the top row and leftmost column are numbered zero.
  5656.  
  5657.    There are extensive examples of the windowing routines in file
  5658.    'w4example.c' on the example diskette.
  5659.  
  5660. Window Concepts
  5661.  
  5662.    Normally, the programmer displays information in the last activated window.
  5663.    However, Code Base 4 does not restrict against selecting a window and
  5664.    displaying information in it. Note that if this is donw, 'w4deactivate'
  5665.    may not restore the screen as expected.
  5666.  
  5667.    Code Base remembers the order in which windows were activated. It is
  5668.    possible to re-activate a window using 'w4activate' without ever
  5669.    deactivating it. When a window is re-activated, it becomes the last
  5670.    activated window. If the last activate window is a memory window (see
  5671.    'w4memory'), its contents are saved to memory when another window is
  5672.    activated or re-activated. Consequently, the window can be restored from
  5673.    memory if it is re-activated later.
  5674.  
  5675.    When a popup window is deactivated, the underlying text is easily
  5676.    restored. Otherwise, Code Base attempts to restore the screen by
  5677.    reactivating all of the active windows in the order in which they were
  5678.    originally activated. This only works properly if the windows being
  5679.    activated are memory windows.
  5680.  
  5681. Note
  5682.  
  5683.    1. Several windows may be active at once. A window is activated with
  5684.       routine "w4activate".
  5685.  
  5686.    2. There is only one "last activated" window. Normally, the programmer
  5687.       will only display information if the "last activated" window.
  5688.  
  5689.    3. There is only one selected window. A window is selected with routine
  5690.       "w4select".
  5691.  
  5692.    4. The selected window does not have to be an active window. It can be any
  5693.       window.
  5694.  
  5695.  
  5696. Windowing Example:
  5697.  
  5698.    #include <w4.h>
  5699.  
  5700.    main()
  5701.    {
  5702.        int     window_ref ;
  5703.  
  5704.        /* Define the Window */
  5705.        window_ref = w4define( 10,30, 14,50 ) ;
  5706.  
  5707.        /* Set the window's attribute and border */
  5708.        w4attribute( B_BLINK | F_WHITE ) ;
  5709.        w4border( DOUBLE, F_BLUE ) ;
  5710.  
  5711.        /* Activate the window */
  5712.        w4activate( window_ref ) ;
  5713.  
  5714.        /* Center the output on row 1 */
  5715.        w4centre( 1, "Hello World" ) ;
  5716.  
  5717.        /* Wait for a character to be pressed */
  5718.        g4char() ;
  5719.  
  5720.        /* Deactivate the window */
  5721.        w4deactivate( window_ref ) ;
  5722.  
  5723.        /* Free the window's allocated memory */
  5724.        w4close( window_ref ) ;
  5725.  
  5726.        w4exit(0) ;
  5727.    }
  5728.  
  5729.  
  5730.  
  5731. w4
  5732.  
  5733.    Usage
  5734.           void  w4( (int) row, (int) column, (char *) str )
  5735.  
  5736.    Description
  5737.           The null terminated character string is displayed at the
  5738.           specified (row,column) coordinates.
  5739.  
  5740.    Parameters
  5741.           Name        Use
  5742.  
  5743.           row         The output row.
  5744.  
  5745.           col         The output column.
  5746.  
  5747.           str         The output string.
  5748.  
  5749.    Example
  5750.           w4( 5,2, "Display at row five and column two !" ) ;
  5751.  
  5752.  
  5753. w4activate
  5754.  
  5755.    Usage
  5756.           void  w4activate( (int) window_ref )
  5757.  
  5758.    Description
  5759.           if the window is currently active and selected, nothing
  5760.           happens.
  5761.  
  5762.           Otherwise, 'w4activate' selects and displays the window. If
  5763.           the window has previously been activated and a memory copy
  5764.           of the window has been saved (see 'w4memory'), then this
  5765.           memory copy is restored. In addition, if the window is a
  5766.           popup window, underlying screen information is saved.
  5767.  
  5768.           If the window was not previously active or if it is not a
  5769.           memory window, it is cleared.
  5770.  
  5771.    Parameters
  5772.           'window_ref' is the window reference number of the window
  5773.           to activate.
  5774.  
  5775.    Example
  5776.           w4activate( w4define( 5,10, 20,70 ) ) ;
  5777.  
  5778.  
  5779. w4attribute
  5780.  
  5781.    Usage
  5782.           long  w4attribute( (long) attribute )
  5783.  
  5784.    Description
  5785.           Every time output is sent directly to an output window on
  5786.           an IBM PC or compatible, if has a corresponding attribute
  5787.           character. This routine sets which attribute character is
  5788.           used for the selected window.
  5789.  
  5790.           Attribute characters have the following format:
  5791.  
  5792.           Bit Number  Meaning
  5793.  
  5794.           0           Foreground blue.
  5795.           1           Foreground green.
  5796.           2           Foreground red.
  5797.           3           Foreground intensity.
  5798.           4           Background blue.
  5799.           5           Background green.
  5800.           6           Background red.
  5801.           7           Background blinking.
  5802.  
  5803.           Header file 'w4.h' defines attributes for the standard
  5804.           colors: F_BLUE, F_GREEN, F_RED, F_INTENSE, F_WHITE, B_BLUE,
  5805.           B_GREEN, B_RED, B_BLINK, AND B_WHITE.
  5806.  
  5807.    Example
  5808.           /* Set to intense white */
  5809.           w4attribute( F_WHITE | F_INTENSE ) ;
  5810.  
  5811.    Warning
  5812.           This routine is specific to IBM PC'S and compatibles.
  5813.  
  5814.  
  5815.  
  5816. w4border
  5817.  
  5818.    Usage
  5819.           void  w4border( (char *) box_chars, (long) attribute )
  5820.  
  5821.    Description
  5822.           The window border, of the currently selected window, is set
  5823.           to the specified box charcters. This border is displayed
  5824.           just within the window bounds. Row zero of the window
  5825.           becomes the row just below the top border row and column
  5826.           zero becomes the column just to the right of the left
  5827.           border column.
  5828.  
  5829.    Parameters
  5830.           Name        Use
  5831.  
  5832.           box_chars   A string of eight characters which make up the
  5833.                   characters in the box. They are in the
  5834.                   following order:
  5835.  
  5836.                   Top.
  5837.                   Bottom.
  5838.                   Left Side.
  5839.                   Right Side.
  5840.                   Upper Left Corner.
  5841.                   Upper Right Corner.
  5842.                   Lower Left Corner.
  5843.                   Lower Right Corner.
  5844.  
  5845.                   Code Base saves a pointer to the 'box_chars'
  5846.                   string. Consequently, 'box_chars' should be a
  5847.                   static memory variable, a constant, or declared
  5848.                   in the 'main' program.
  5849.  
  5850.           attribute   This is the attribute character for the border.
  5851.  
  5852.    Note
  5853.           Header file 'w4.h' defines some strings for common borders:
  5854.           SINGLE, DOUBLE, DOUBLE_TOP, and PANEL. It also defines some
  5855.           common attributes.
  5856.  
  5857.    Example
  5858.           w_ref = w4define( 0,0, 24,79 ) ;
  5859.           w4border(  SINGLE, F_WHITE ) ;
  5860.           w4activate( w_ref ) ;
  5861.  
  5862.  
  5863.  
  5864. w4box
  5865.  
  5866.    Usage
  5867.           void w4box( (char *) box_chars, (int) start_row,
  5868.                   (int) start_col, (int) end_row, (int) end_col )
  5869.  
  5870.    Description
  5871.           'w4box' draws a box in the selected window. The window
  5872.           attribute character is used.
  5873.  
  5874.    Parameters
  5875.           Refer to 'w4border' for the definition of parameter
  5876.           'box_chars'. Parameters 'start_row', 'start_col',
  5877.           'end_row', and 'end_col' outline the dimensions of the box.
  5878.  
  5879.    Example
  5880.           /* Outline the complete screen with a box */
  5881.           w_ref = w4define( 0,0, 24,79 ) ;
  5882.           w4box( SINGLE, 0,0, 24,79 ) ;
  5883.           w4close( w_ref ) ;
  5884.  
  5885.  
  5886. w4centre
  5887.  
  5888.    Usage
  5889.           void  v4centre( (int) row, (char *) str )
  5890.  
  5891.    Description
  5892.           A string is centered on the specified row within the
  5893.           selected window.
  5894.  
  5895.    Parameters
  5896.           Name        Use
  5897.  
  5898.           row         The output row.
  5899.  
  5900.           str         The output string.
  5901.  
  5902.  
  5903. w4clear
  5904.  
  5905.    Usage
  5906.           void  w4clear( (int) row )
  5907.  
  5908.    Description
  5909.           The selected window is cleared starting from the specified
  5910.           row. In addition, the current (row,column) position is
  5911.           changed to (row,0).
  5912.  
  5913.           If 'row' is '(int) -1', the entire screen is cleared and
  5914.           the current (row,column) position is not changed.
  5915.  
  5916.  
  5917. w4close
  5918.  
  5919.    Usage
  5920.           void  w4close( (int) window_ref )
  5921.  
  5922.    Description
  5923.           'w4close' frees all of the memory assoicated with the
  5924.           window. Once a window is closed, it no longer exists.
  5925.           Closing a window, does not effect the screen. If necessary,
  5926.           deactivate the window before closing it.
  5927.  
  5928.           If the window being closed was previously selected, the
  5929.           last activated window is automatically selected. If there
  5930.           was no last activated window, the selected window is
  5931.           undefined and must be determined with another windowing
  5932.           routine such as 'w4select'.
  5933.  
  5934.    Parameter
  5935.           The window reference number of the window to be closed.
  5936.  
  5937.  
  5938. w4col
  5939.  
  5940.    Usage
  5941.           int  w4col()
  5942.  
  5943.    Returns
  5944.           The current column is returned.
  5945.  
  5946.  
  5947. w4cursor
  5948.  
  5949.    Usage
  5950.           void  w4cursor( (int) row, (int) column )
  5951.  
  5952.    Description
  5953.           The cursor is positioned at the specified coordinates
  5954.           within the selected window. If either parameter value is
  5955.           negative, the cursor will disappear off the screen.
  5956.  
  5957.           Calling 'w4cursor' does not effect the current (row,column)
  5958.           position within the selected window.
  5959.  
  5960.    Warning
  5961.           Some computers 'hang' if the cursor is not positioned on
  5962.           the screen before programs exit. Refer to routine 'w4exit'
  5963.           and the example.
  5964.  
  5965.    Example
  5966.           /* Following is the source code for 'w4exit' */
  5967.           w4exit( rc )
  5968.           int   rc ;
  5969.           {
  5970.               w4select( vdefault_window ) ;
  5971.               w4cursor( 23, 0 ) ;
  5972.               exit( rc ) ;
  5973.           }
  5974.  
  5975.  
  5976. w4cursor_size
  5977.  
  5978.    Usage
  5979.           void  w4cursor_size( (int) start_size, (int) end_size )
  5980.  
  5981.    Description
  5982.           The cursor size is set.
  5983.  
  5984.    Parameters
  5985.           Name        Use
  5986.  
  5987.           start_size  The top position of the displayable cursor.
  5988.                   This value ranges between 0 and the 'end_size'.
  5989.  
  5990.           end_size    The bottom position of the displayable cursor.
  5991.                   This value ranges between 0 and 7.
  5992.  
  5993.    Warning
  5994.           This routine is specific to IBM PC's and compatibles.
  5995.  
  5996.  
  5997.  
  5998. w4deactivate
  5999.  
  6000.    Usage
  6001.           w4deactivate( (int) window_ref )
  6002.  
  6003.    Description
  6004.           If the window is an active, selected, popup window, the the
  6005.           window disappears from the screen and the underlying text
  6006.           is restored.
  6007.  
  6008.           Otherwise, the screen is restored by reactivating other
  6009.           windows. This makes use of the fact that, through a call
  6010.           to 'w4memory', windows can have a copy of their contents
  6011.           saved. Any previously activated window, whose contents had
  6012.           been saved, will be reactivated. These windows will be
  6013.           reactivated in the order in which they were originally
  6014.           activated. It may be impossible to reconstruct the screen
  6015.           if there are overwritten windows for which there is not a
  6016.           memory copy.
  6017.  
  6018.           After a window is deactivated, the last activated window is
  6019.           automatically selected.
  6020.  
  6021.    Parameter
  6022.           The window reference number of the window to be closed.
  6023.  
  6024.    Example
  6025.           /* Defined a bordered, popup window for the screen's left
  6026.              side. */
  6027.  
  6028.           w_ref = w4define( 0.,13, 24,79 ) ;
  6029.           w4border( DOUBLE, F_WHITE ) ;
  6030.           w4popup() ;
  6031.           w4activate( w_ref ) ;
  6032.           .
  6033.           .
  6034.           w4deactivate( w_ref ) ;
  6035.           w4close( w_ref ) ;
  6036.  
  6037.  
  6038.  
  6039. w4define
  6040.  
  6041.    Usage
  6042.           int  w4define( (int) top_row, (int) left_column,
  6043.                   (int) bottom_row, (int) right_column )
  6044.  
  6045.    Description
  6046.           'w4define' creates a window. It is necessary to do this
  6047.           before almost any other routines in the 'Window', 'Get' or
  6048.           'Menu' modules can be called.
  6049.  
  6050.           After the window is created, it is selected.
  6051.  
  6052.    Parameters
  6053.           The parameters describe the dimensions of the window. The
  6054.           row and column coordinates are relative to the top and left
  6055.           side of the screen. Row zero is the top screen row and
  6056.           column zero is leftmost column.
  6057.  
  6058.    Returns
  6059.           A reference number corresponding to the new window is
  6060.           returned.
  6061.  
  6062.    Note
  6063.           'd4init' calss 'w4define' to create a default window with a
  6064.           reference number in external integer variable
  6065.           'v4default_window'. This window covers the entire screen.
  6066.           If 'd4init' has not been called, 'w4define' will create the
  6067.           default window.
  6068.  
  6069.    Example
  6070.           #include <w4.h>
  6071.  
  6072.           main()
  6073.           {
  6074.               int     error_window, main_window, top_window,
  6075.                   bottom_window ;
  6076.               error_window = w4define( 11,25, 16,55 ) ;
  6077.               w4popup() ;
  6078.               w4border( DOUBLE, F_RED ) ;
  6079.               w4attribute( F_RED | B_BLINK ) ;
  6080.  
  6081.               main_window = w4define( 0,0, 24,79 ) ;
  6082.               w4memory() ;
  6083.  
  6084.               top_window = w4define( 0,0, 12,79 ) ;
  6085.               w4memory() ;
  6086.               w4border( SINGLE, F_WHITE ) ;
  6087.  
  6088.               bottom_window = w4define( 13,0, 24,79 ) ;
  6089.               w4memory() ;
  6090.               w4border( SINGLE, F_WHITE ) ;
  6091.  
  6092.               application() ;
  6093.               w4exit(0) ;
  6094.           }
  6095.  
  6096.  
  6097.  
  6098. w4display
  6099.  
  6100.    Usage
  6101.           int  w4display( (char *) title, (char *) m1,
  6102.                   (char *) m2, ..., (char *) 0 )
  6103.  
  6104.    Descripiton
  6105.           'w4display' creates a popup window and displays message
  6106.           strings in it. The window is created just large enough to
  6107.           contain the message strings in an attractive manner. Once
  6108.           the message strings have been displayed, 'w4display' waits
  6109.           for the user to press a key. Then the popup window is
  6110.           deactivated and closed.
  6111.  
  6112.    Parameters
  6113.           Name        Use
  6114.  
  6115.           title       The window's title. If this is the only
  6116.                   parameter, the title is displayed in the middle
  6117.                   of the window.
  6118.  
  6119.           m1,m2,...   An unspecified number of message strings to
  6120.                   display.
  6121.  
  6122.           (char *) 0  A required parameter.
  6123.  
  6124.    Return
  6125.           The character pressed.
  6126.  
  6127.    Example
  6128.           rc = w4display( " Entry Error: ",
  6129.                   "Only Blanks were Entered",
  6130.                   "",
  6131.                   "Continue (Y/N) ?",
  6132.                   (char *) 0 ) ;
  6133.           if ( rc == (int) 'n' || rc == (int) 'N' )
  6134.               w4exit(1) ;
  6135.  
  6136.  
  6137. w4double
  6138.  
  6139.    Usage
  6140.           void  w4double( (int) row, (int) column,
  6141.                   (double) double_value, (int) len, (int) dec )
  6142.  
  6143.    Description
  6144.           A double value is displayed.
  6145.  
  6146.    Parameters
  6147.           Name            Use
  6148.  
  6149.           row             The output row.
  6150.  
  6151.           column          The output column.
  6152.  
  6153.           double_value    The double to display.
  6154.  
  6155.           len             The output length.
  6156.  
  6157.           dec             The number of decimals to display.
  6158.  
  6159.  
  6160.  
  6161. w4eject
  6162.  
  6163.    Usage
  6164.           void  w4eject()
  6165.  
  6166.    Description
  6167.           a form feed character is sent to the current window's
  6168.           output handle. In addition, the current (row,column)
  6169.           position is set to (0,0).
  6170.  
  6171.  
  6172. w4exit
  6173.  
  6174.    Usage
  6175.           void  w4exit( exit_rc )
  6176.  
  6177.    Description
  6178.           'w4exit' positions the cursor to row 23 and column 0 of the
  6179.           screen and then exits by calling the standard exit routine
  6180.           'exit' with a return code of 'exit_rc'.
  6181.  
  6182.           'w4exit' is necessary because some computers fo not respond
  6183.           normally if a program exits with the cursor off of the
  6184.           screen.
  6185.  
  6186.    Warning
  6187.           Do not use 'w4exit' if the dimensions of the default window
  6188.           have been changed or if the default window is closed.
  6189.  
  6190.  
  6191. w4field
  6192.  
  6193.    Usage
  6194.           void  w4field( (int) row, (int) column, (long) field_ref )
  6195.  
  6196.    Description
  6197.           'w4field' displays the value of a database field.
  6198.  
  6199.    Parameters
  6200.           Name        Use
  6201.  
  6202.           row         The output row.
  6203.  
  6204.           column      The output column.
  6205.  
  6206.           field_ref   The field reference number of the field to
  6207.                   display.
  6208.  
  6209.  
  6210. w4handle
  6211.  
  6212.    Usage
  6213.           int  w4handle( (int) hand )
  6214.  
  6215.    Description
  6216.           'w4handle' specifies the handle to be associated with the
  6217.           selected window. Subsequent output form the windowing
  6218.           routines will be written to this handle. If the handle is
  6219.           associated with a file, make sure the file has been opened
  6220.           in binary mode.
  6221.  
  6222.           Menuing and data entry should not be attempted on a window
  6223.           associated with an output handle which is not '(int) -1'.
  6224.  
  6225.    Parameter
  6226.           'hand' can have the following possible values:
  6227.  
  6228.           Value       Meaning
  6229.  
  6230.              -2       Do not change the handle. Just return the value
  6231.                   of the current handle.
  6232.  
  6233.              -1       Send output directly to the video memory.
  6234.  
  6235.               0       Standard input handle.
  6236.  
  6237.               1       Standard output handle.
  6238.  
  6239.               2       Standard error handle.
  6240.  
  6241.               3       Standard auxiliary handle.
  6242.  
  6243.               4       Standard printer.
  6244.  
  6245.            >= 5       These handles will normally correspond to
  6246.                   opened files.
  6247.  
  6248.    Return
  6249.           Returns the value of the previous output handle.
  6250.  
  6251.  
  6252. w4height
  6253.  
  6254.    Usage
  6255.           int  w4height( (int) new_height )
  6256.  
  6257.    Description
  6258.           'w4height'sets and returns the number of rows in the
  6259.           selected window.
  6260.  
  6261.           Calling 'w4height' does not effect what has been displayed
  6262.           on the screen. However, any popup or saved screen memory is
  6263.           freed and reallocated. Consequently, it may be best to
  6264.           avoid changing a window's height when the selected window
  6265.           is active.
  6266.  
  6267.           The new height only counts the rows within the window
  6268.           borders.
  6269.  
  6270.    Parameter
  6271.           If 'new_height' is greater than zero, it becomes the new
  6272.           number of rows in the window.
  6273.  
  6274.    Returns
  6275.           The current height is returned.
  6276.  
  6277.  
  6278. w4init
  6279.  
  6280.    Usage
  6281.           int  w4init( (int) num_window, (int) num_get, (int) num_menu)
  6282.  
  6283.    Description
  6284.           if 'w4init' is not called directly, it is called
  6285.           automactically by 'd4init', 'w4define', and 'w4clear(-1)'.
  6286.           Consequently, if 'w4init' is called explicitly, it should
  6287.           be called before any other Code Base routine is called.
  6288.  
  6289.           By calling 'w4init' to exactly specify the number of
  6290.           windows, get entry areas and menu item numbers, overall
  6291.           memory usage and fragmentation is reduced. Even if 'w4init'
  6292.           is called, Code Base will still allocate extra memory for
  6293.           additional windows, entry areas, or menu items as required.
  6294.  
  6295.           The number of windows in use at any one time is the number
  6296.           of times 'w4define' is called minus the number of times
  6297.           'w4close' is called plus one for the default window.
  6298.  
  6299.           The number of entry areas in use at any one time is
  6300.           determined by the number of Get Initialize routines which
  6301.           have been called. Memory for an entry area is normally
  6302.           released automatically by 'g4read'.
  6303.  
  6304.           similarily, the number of menu items in use depends on the
  6305.           number of calls to 'n4' and 'n4item'. Menu item memory is
  6306.           normally released when a window is closed.
  6307.  
  6308.           By default, 'd4init' calls 'w4init' as follows:
  6309.  
  6310.               w4init( 5, 0, 0 ) ;
  6311.  
  6312.           By default, 'w4define' and 'w4clear' call 'w4init' as
  6313.           follows:
  6314.  
  6315.                w4init( 10, 0, 0 ) ;
  6316.  
  6317.    Returns
  6318.           Value       Meaning
  6319.  
  6320.            0          Success.
  6321.  
  6322.           -1          Out of memory. Unless 'u4error' is modified,
  6323.                   this is a critical error and will never be
  6324.                   returned.
  6325.  
  6326.  
  6327. w4int
  6328.  
  6329.    Usage          void  w4int( (int) row, (int) column, (int) int_value,
  6330.                   (int) len )
  6331.  
  6332.    Descripiton
  6333.           An integer is displayed.
  6334.  
  6335.    Parameters
  6336.           Name        Use
  6337.  
  6338.           row         The output row.
  6339.  
  6340.           column      The output column.
  6341.  
  6342.           int_value   The integer to be displayed.
  6343.  
  6344.           len         The output length.
  6345.  
  6346.    Example
  6347.           w4( w4row() + 1, 2, "Amount:") ;
  6348.           w4init( w4row(), w4col(), i_amount, 6 ) ;
  6349.  
  6350.  
  6351. w4long
  6352.  
  6353.    Usage
  6354.           void  w4long( (int) row, (int) column, (long) long_value,
  6355.                   (int) len )
  6356.  
  6357.    Description
  6358.           A long integer is displayed.
  6359.  
  6360.    Parameters
  6361.           Name        Use
  6362.  
  6363.           row         The output row.
  6364.  
  6365.           column      The output column.
  6366.  
  6367.           long_value  The long to be displayed.
  6368.  
  6369.           len         The output length.
  6370.  
  6371.    Example
  6372.           w4long( ++r,c,l_value, 8 ) ;
  6373.  
  6374.  
  6375. w4memory
  6376.  
  6377.    Usage
  6378.           void  w4memory()
  6379.  
  6380.    Description
  6381.           'w4memory' causes a copy of the currently selected window
  6382.           to be kept in memory. Consequently, when the window is
  6383.           re-activated, its image can be restored from memory. In
  6384.           addition, if the selected window is overlaid with another
  6385.           window which is subsequently deactivated, the selected
  6386.           window's contents can be redisplayed.
  6387.  
  6388.    Hint
  6389.           When different windows of different sizes are randomly
  6390.           activated, it is often best to use 'w4memory' so that the
  6391.           previous contents of the windows can be restored.
  6392.  
  6393.    See Also
  6394.           w4deactivate.
  6395.  
  6396.  
  6397. w4num
  6398.  
  6399.    Usage
  6400.           void  w4num( (int) row, (int) column, (char *) str,
  6401.                   (int) num )
  6402.  
  6403.    Description
  6404.           A string of a specified length is displayed.
  6405.  
  6406.    Parameters
  6407.           Name        Use
  6408.  
  6409.           row         The output row.
  6410.  
  6411.           column      The output column.
  6412.  
  6413.           str         The output string.
  6414.  
  6415.           num         The number of characters to output.
  6416.  
  6417.    Example
  6418.           /* Output five characteres */
  6419.           w4num( r,c, str, 5 ) ;
  6420.  
  6421.  
  6422. w4num_att
  6423.  
  6424.    Usage
  6425.           void  w4num_att( (int) row, (int) col, (char *) str,
  6426.                   (int) num, (long) attribute )
  6427.  
  6428.    Description
  6429.           'w4numm_att' is identical to 'w4num' except that it has one
  6430.           additional parameter. This parameter, 'attribute',
  6431.           specifies the attribute of the display string.
  6432.  
  6433.    See Also
  6434.           w4attribute.
  6435.  
  6436.  
  6437. w4out
  6438.  
  6439.    Usage          void  w4out( (char *) str )
  6440.  
  6441.    Description
  6442.           The string 'str' is displayed at the current (row,column)
  6443.           position.
  6444.  
  6445.  
  6446. w4popup
  6447.  
  6448.    Usage
  6449.           void  w4popup()
  6450.  
  6451.    Description
  6452.           The selected window becomes a popup window. This means that
  6453.           when a window is activated and then deactivated the text
  6454.           under the window can be restored quickly.
  6455.  
  6456.    Note
  6457.           Calls to 'n4lotus', 'n4pulldown', 'n4get_calc' and 'n4calc'
  6458.           automatically make the relevant windows popup windows.
  6459.  
  6460.  
  6461. w4position
  6462.  
  6463.    Usage
  6464.           void  w4position( (int) row, (int) column )
  6465.  
  6466.    Descripiton
  6467.           The current (row,column) position is set. If the selected
  6468.           window has an output handle, an appropriate number of
  6469.           carriage return, line feed, form feed and space characters
  6470.           will be sent to position the corresponding file or device
  6471.           to the new current position.
  6472.  
  6473.           Regardless, 'w4position' does not effect the cursor position.
  6474.  
  6475.    Parameters
  6476.           Name        Use
  6477.  
  6478.           row         The new row position.
  6479.  
  6480.           column      The new column position.
  6481.  
  6482.  
  6483.  
  6484. w4read
  6485.  
  6486.    Usage
  6487.           void  w4read( (int) row, (int) col, (char *) data_buffer,
  6488.                   (int) len_data )
  6489.  
  6490.    Description
  6491.           Routine 'w4read' reads information from video memory. The
  6492.           information is in video memory format: (character,
  6493.           attribute).
  6494.  
  6495.    Parameters
  6496.           Name            Use
  6497.  
  6498.           row             The screen row relative to the top of the
  6499.                   screen.
  6500.  
  6501.           col             The screen column relative to the top of the
  6502.                   screen.
  6503.  
  6504.           data_buffer     A pointer to a buffer where the data is to
  6505.                   be placed.
  6506.  
  6507.           len_data        The number of bytes to read. This is twice
  6508.                   the number of screen characters read as the
  6509.                   attributes are read as well.
  6510.  
  6511.    Portability
  6512.           This routine is not available under the Unix/Xenix verison
  6513.           of Code Base.
  6514.  
  6515.    Example
  6516.           static char    scr_data[25*80*2] ;
  6517.  
  6518.           char *   read_screen()
  6519.           {
  6520.              /* Read the entire screen */
  6521.              w4read( 0,0, scr_data, sizeof(scr_data) ) ;
  6522.              return( scr_data ) ;
  6523.           }
  6524.  
  6525.  
  6526. w4read_window
  6527.  
  6528.    Usage
  6529.           void  w4read_window( (int) window_ref, (char *) ptr )
  6530.  
  6531.    Description
  6532.           Character information, for the entire window, is read from
  6533.           video memory. This information is read as (character,
  6534.           attribute) pairs. If the window contains a border, the
  6535.           border information is not read.
  6536.  
  6537.    Parameters
  6538.           Name        Use
  6539.  
  6540.           window_ref  The reference number of the window to be read.
  6541.  
  6542.           ptr         A pointer to where the information is to be
  6543.                   stored. Make sure there is enough memory to
  6544.                   contain the window.
  6545.  
  6546.    Portability
  6547.           This routine is not available under the Unix/Xenix verison
  6548.           of Code Base.
  6549.  
  6550.    Example
  6551.           static  char  window_info[200] ;
  6552.  
  6553.           read_example_one()
  6554.           {
  6555.               int     w_ref ;
  6556.  
  6557.               w_ref = w4define( 2,2, 11,11 ) ;
  6558.  
  6559.               /* Read the 200 bytes of window information */
  6560.               /* Note: ( 11-2+1) * (11-2+1) is 100
  6561.              characters. This becomes 200 bytes at 2 bytes per
  6562.              character */
  6563.  
  6564.               w4read_window( w_ref, window_info ) ;
  6565.  
  6566.               w4close( w_ref ) ;
  6567.           }
  6568.  
  6569.           read_example_two()
  6570.           {
  6571.               int     w_ref ;
  6572.  
  6573.               w_ref = w4define( 1,1, 12,12 ) ;
  6574.               w4border( SINGLE, F_WHITE ) ;
  6575.  
  6576.               /* Read the same 200 bytes of window information as in
  6577.              'save_example_one'. The border information is not
  6578.              read. */
  6579.  
  6580.               w4read_window( w_ref, window_info ) ;
  6581.  
  6582.               w4close( w_ref ) ;
  6583.           }
  6584.  
  6585.  
  6586. w4repeat
  6587.  
  6588.    Usage
  6589.           void  w4repeat( (int) row, (int) column, (char) chr,
  6590.                   (int) num_repeat )
  6591.  
  6592.    Desciption
  6593.           A character is displayed repeatedly.
  6594.  
  6595.    Parameters
  6596.           Name        Use
  6597.  
  6598.           row         The output row.
  6599.  
  6600.           column      The output column.
  6601.  
  6602.           chr         The display character.
  6603.  
  6604.           num_repeat  The number of times to display 'chr'.
  6605.  
  6606.  
  6607. w4row
  6608.  
  6609.    Usage
  6610.           int  w4row()
  6611.  
  6612.    Descripiton
  6613.           The current row position is returned.
  6614.  
  6615.  
  6616. w4scroll
  6617.  
  6618.    Usage
  6619.           void  w4scroll( (int) num_lines )
  6620.  
  6621.    Description
  6622.           The window is scrolled up or down.
  6623.  
  6624.    Parameters
  6625.           Parameter 'no_lines' specifies the number of lines the
  6626.           window is to be scrolled. If 'no_lines' is positive, the
  6627.           window is scrolled up. Otherwise, the window is scrolled
  6628.           down.
  6629.  
  6630.    Portability
  6631.           Under Unix/Xenix this routine does not work on windows with
  6632.           borders.
  6633.  
  6634.  
  6635. w4select
  6636.  
  6637.    Usage          int  w4select( (int) window_ref )
  6638.  
  6639.    Description
  6640.           The specified window becomes the currently selected window.
  6641.           If 'window_ref' is less than zero, the currently selected
  6642.           window does not change.
  6643.  
  6644.    Returns
  6645.           'w4select' returns the previously selected window reference
  6646.           number.
  6647.  
  6648.    Example
  6649.           previous_ref = w4select( new_ref ) ;
  6650.           w4centre( 1, "Output Window" ) ;
  6651.           w4select( previous_ref ) ;
  6652.  
  6653.    Example 2
  6654.           /* Find the current window reference number */
  6655.           current_ref = w4select( -1 ) ;
  6656.  
  6657.  
  6658. w4title
  6659.  
  6660.    Usage
  6661.           void  w4title( (int) row, (int) col, (char *) title,
  6662.                   (int) title_attribute )
  6663.  
  6664.    Description
  6665.           'w4title' specifes a string of character data which is
  6666.           automatically displayed when the currently selected window
  6667.           is activated. Unlike other window display routines,
  6668.           'w4title' ignores the presence of a border for the purposes
  6669.           of calculating the (row,col) placement. This makes it
  6670.           possible to overlay the window border with title information.
  6671.  
  6672.    Parameters
  6673.           Name        Use
  6674.  
  6675.           row         The title's row.
  6676.  
  6677.           col         The window's column. If 'col' is less than
  6678.                   zero, the title is centered.
  6679.  
  6680.           title       A pointer to the 'title' string.
  6681.  
  6682.           attribute   The display attribute of the 'title' string.
  6683.  
  6684.    Warning
  6685.           Code Base only saves a pointer to the title string.
  6686.           Consequently, the 'title' pointer should not point to
  6687.           temporay memory. If the information 'title' points to
  6688.           changes, the window's title changes.
  6689.  
  6690.    Example
  6691.           w_ref = w4define( 5,10, 10,20 ) ;
  6692.           w4border( DOUBLE, F_WHITE ) ;
  6693.  
  6694.           /* Define a title to be centered over the top border row */
  6695.           w4title( 0,-1, " Data Entry Window ", B_WHITE ) ;
  6696.  
  6697.  
  6698. w4width
  6699.  
  6700.    Usage
  6701.           int  w4width( (int) new_width )
  6702.  
  6703.    Description
  6704.           'w4width' sets and returns the number of columns per row
  6705.           for the selected window.
  6706.  
  6707.           Calling 'w4width' does not effect what has been displayed
  6708.           on the screen. However, any popup or saved screen memory is
  6709.           freed and reallocated. Consequently, it may be best to
  6710.           avoid changing a window's width when the window is active.
  6711.  
  6712.           The new width only counts the columns within the window
  6713.           borders.
  6714.  
  6715.    Parameter
  6716.           If 'new_width' is greater than zero, it becomes the new
  6717.           number of columns per row.
  6718.  
  6719.    Returns
  6720.           The current width is returned.
  6721.  
  6722.    Example
  6723.           void  shrink_window( w_ref )
  6724.           {
  6725.               int  prev_ref ;
  6726.  
  6727.                prev_ref = w4select( w_ref ) ;
  6728.  
  6729.                w4width( w4width(-1) -1 ) ;
  6730.                w4height( w4height(-1) -1 ) ;
  6731.  
  6732.                w4select( prev_ref ) ;
  6733.           }
  6734.  
  6735.  
  6736. w4write
  6737.  
  6738.    Usage
  6739.           void  w4write( (int) row, (int) col, (char *) data_ptr,
  6740.                   (int) len_data )
  6741.  
  6742.    Description
  6743.           Routine 'w4write' writes information from a memory buffers
  6744.           directly into video memory. The memory buffer information
  6745.           must be in video memory format: (character,attribute).
  6746.  
  6747.    Parameters
  6748.           Name        Use
  6749.  
  6750.           row         The screen row relative to the top of the screen.
  6751.  
  6752.           col         The screen column relative to the top of the
  6753.                   screen.
  6754.  
  6755.           data_ptr    A pointer to the data buffer to be written.
  6756.  
  6757.           len_data    The number of bytes to write. As the write data
  6758.                   contains attributes, there are twice as many
  6759.                   bytes as screen characters.
  6760.  
  6761.    Note
  6762.           This routine is the opposite to 'w4read'. These routines
  6763.           are low level and consequently are used by other Code Base
  6764.           windowing routines. 'w4write' is not available under the
  6765.           Unix/Xenix version of Code Base.
  6766.  
  6767.    Example
  6768.           /* Code fragment from 'w4write_window' */
  6769.           int         i, data_width ;
  6770.           WINDOW      *window_ptr ;
  6771.  
  6772.           window_ptr = v4window+ window_ref ;
  6773.           data_width = window_ptr->width * 2 ;
  6774.  
  6775.           for ( i=0; i < window_ptr->height; i++ )
  6776.           {
  6777.                w4write( window_ptr->start_row+i,
  6778.                 window_ptr->start_col, ptr, data_width ) ;
  6779.               ptr += data_width ;
  6780.           }
  6781.  
  6782. w4write_att
  6783.  
  6784.    Usage
  6785.           void  w4write_att( (int) row, (int) col, (char *) data_ptr,
  6786.                   (int) len_data, (long) attribute )
  6787.  
  6788.    Description
  6789.           'w4write_att' is the samne as 'w4write' except the
  6790.           data_buffer contains only character data. All of the data
  6791.           is displayed with the specified attribute character.
  6792.  
  6793.    Parameters
  6794.           Name        Use
  6795.  
  6796.           row         The screen row relative to the top of the screen.
  6797.  
  6798.           col         The screen column relative to the top of the
  6799.                   screen.
  6800.  
  6801.           data_ptr    A pointer to the display data.
  6802.  
  6803.           len_data    The number of data characters to write. This is
  6804.                   the same as the number of bytes of data.
  6805.  
  6806.           attribute   This is the attribute of all of the characters
  6807.                   which are displayed.
  6808.  
  6809.    Portability
  6810.           This routine is not available under the Unix/Xenix version
  6811.           of Code Base.
  6812.  
  6813.  
  6814. w4write_window
  6815.  
  6816.    Usage
  6817.           void  w4write_window( window_ref, ptr )
  6818.  
  6819.    Description
  6820.           'w4write_window' is used to display information read with
  6821.           'w4read_window'. It assumes that the window has not changed
  6822.           size. In addition, it assumes that the window has not
  6823.           aquired or lost a border.
  6824.  
  6825.    Parameters
  6826.           Name        Use
  6827.  
  6828.           window_ref  The reference number of the window to display.
  6829.  
  6830.           ptr         A pointer to where the display information is
  6831.                   stored. There should be enough (character,
  6832.                   attribute) pairs to fill the entire window.
  6833.  
  6834.    Portability
  6835.           This routine is not available under the Unix/Xenix version
  6836.           of Code Base.
  6837.  
  6838.    Example
  6839.           #include <w4.h>
  6840.  
  6841.           void  copy_window()
  6842.           {
  6843.                int   w_ref ;
  6844.  
  6845.                char  window_data[400] ;
  6846.  
  6847.                w_ref = w4define( 0,0, 9,19 ) ;
  6848.                w4read_window( w_ref, window_data ) ;
  6849.                w4close( w_ref ) ;
  6850.  
  6851.                /* Display the information at row 15 */
  6852.                w_ref = w4define ( 15,0, 24,19 ) ;
  6853.                w4write_window( w_ref, window_data ) ;
  6854.                w4close( w_ref ) ;
  6855.           }
  6856.  
  6857.  
  6858.  
  6859.  
  6860. EXTEND ROUTINES
  6861.  
  6862.    The extended routines implement high level database functionality. As they
  6863.    use lower level Code Base routines, they can by use as Code Base examples.
  6864.    In particular, routines 'x4sum', x4replace', 'x4list' and 'x4edit' are
  6865.    good examples. Other extended routines can be used as examples for more
  6866.    advanced users.
  6867.  
  6868.    Routines 'x4seek', 'x4skip', 'x4top', 'x4go' and 'x4bottom' use filtering
  6869.    and relations set by routines 'x4relate' and 'x4filter'.
  6870.  
  6871.  
  6872. x4blank
  6873.  
  6874.    Usage
  6875.           int  x4blank()
  6876.  
  6877.    Description
  6878.           'x4blank' determines if the current record of the current
  6879.           database is blank. This routine is included primarily as an
  6880.           example of how to write a routine which works with
  6881.           'x4fileter'.
  6882.  
  6883.    Returns
  6884.           Value       Meaning
  6885.  
  6886.           1           The record is blank.
  6887.  
  6888.           0           The record is not blank.
  6889.  
  6890.    See Also
  6891.           'x4filter'.
  6892.  
  6893.  
  6894. x4bottom
  6895.  
  6896.    Usage
  6897.           int  x4bottom()
  6898.  
  6899.    Description
  6900.           This is the same as 'd4bottom' except filtering and
  6901.           relations are used.
  6902.  
  6903.  
  6904. x4buffer
  6905.  
  6906.    Usage
  6907.           int  x4buffer( (long) start_record, (char *) buffer,
  6908.           (unsigned int) len_buffer )
  6909.  
  6910.    Description
  6911.           'x4buffer' sequentially reads as many database records as
  6912.           possible into the memory buffer. Once the records have been
  6913.           read using 'x4buffer', 'x4buffer_copy' can be called to
  6914.           copy individual records into the database's internal record
  6915.           buffer. At this point, the record can be accessed and
  6916.           modified using the field routines.
  6917.  
  6918.    Parameters
  6919.           Name            Use
  6920.  
  6921.           start_record    This is the starting record number to be
  6922.                   read.
  6923.  
  6924.           buffer          A memory buffer where the records are to be
  6925.                   placed.  This memory is allocated by the
  6926.                   programmer.
  6927.  
  6928.           len_buffer      The number of bytes of memory allocated
  6929.                   for 'buffer'.
  6930.  
  6931.    Returns
  6932.           'x4buffer' returns number of records which have been read
  6933.           into the memory buffer. This will never be more than the
  6934.           buffer length divided by the record width.
  6935.  
  6936.           If an error occurs, '(int) -1' is returned.
  6937.  
  6938.  
  6939. x4buffer_copy
  6940.  
  6941.    Usage
  6942.           void  x4buffer_copy( (int) i, (char *) buffer )
  6943.  
  6944.    Description
  6945.           'x4buffer_copy' copies a database record form a large
  6946.           memory buffer into the internal database record buffer.
  6947.           Then the record can be accessed and modified using the
  6948.           field routines.
  6949.  
  6950.    Parameters
  6951.           Name        Use
  6952.  
  6953.           i           A record number offset specifying which
  6954.                   database record should be transfered. For
  6955.                   example, if 'i' is zero, the first record in
  6956.                   the memory buffer is transfered; and if 'i' is
  6957.                   one, the second record is transfered.
  6958.  
  6959.           buffer      This is the memory buffer containing the
  6960.                   database records.
  6961.  
  6962.    See Also
  6963.           'x4buffer'.
  6964.  
  6965.  
  6966. x4edit
  6967.  
  6968.    Usage
  6969.           int  x4edit()
  6970.  
  6971.    Description
  6972.           The current database is edited, interactively, one record
  6973.           at a time. Initially, the record in the database buffer
  6974.           will be displayed for modification.
  6975.  
  6976.           If there is a currently selected index file, it will be
  6977.           used to determine the record ordering.
  6978.  
  6979.           When using 'x4edit', the following keys perform the
  6980.           following actions:
  6981.  
  6982.           Key         Action
  6983.  
  6984.           <Alt A>     Add Record.
  6985.  
  6986.           <Alt B>     Move to the bottom record.
  6987.  
  6988.           <Alt D>     Mark the record for deletion.
  6989.  
  6990.           <Alt I>     Insert a blank record at current record.
  6991.  
  6992.           <Alt R>     Move to a specified record.
  6993.  
  6994.           <Alt S>     Seek a record.
  6995.  
  6996.           <Alt T>     Move to the top record.
  6997.  
  6998.           <Alt U>     Undo the record deletion mark.
  6999.  
  7000.           <PgUp>      Move to the previous record.
  7001.  
  7002.           <PgDn>      Move to the next record.
  7003.  
  7004.           <Ctrl W>    Write the displayed record and then exit.
  7005.  
  7006.           <Esc>       Exit without writing the displayed record.
  7007.  
  7008.           <F1>        Help.
  7009.  
  7010.    Note
  7011.           The avoe key assignments do not follow any particular
  7012.           convetion or standard.
  7013.  
  7014.    Returns
  7015.           The exit key is returned. The possibilites are currently
  7016.           <Esc> and <Ctrl W>. On error, '(int) -1' is returned.
  7017.  
  7018.    See Also
  7019.           'g4read'.
  7020.  
  7021.  
  7022. x4filter
  7023.  
  7024.    Usage
  7025.           int  x4filter( (*filter_routine) () )
  7026.  
  7027.    Description
  7028.           Routine 'x4filter' works with routines 'x4seek', 'x4skip',
  7029.           'x4top', and 'x4bottom' to make it appear that certain
  7030.           records do not exist.
  7031.  
  7032.           For example, 'x4top' calls 'd4top' and then linearly skips
  7033.           through the database, using 'd4skip', until a record is
  7034.           located which should not be filtered.
  7035.  
  7036.           When 'x4filter' is called, the specified filter routine is
  7037.           added to a list of filter routines attached to the current
  7038.           database. Each filter routine should return a logical 'int'
  7039.           according to the following conventions:
  7040.  
  7041.           Filter Return   Meaning
  7042.  
  7043.            1              Filter the record.
  7044.  
  7045.            0              Use the record.
  7046.  
  7047.           -1              Error.
  7048.  
  7049.           For a record to be used, all of the filter routines
  7050.           attached to the database must return a '(int) 0' value.
  7051.  
  7052.    Parameters
  7053.           The parameter is a filter routine.
  7054.  
  7055.    Returns
  7056.           '(int) -1' is returned to indicate out of memory. Unless
  7057.           'u4error' has been modified, this is a critical error and
  7058.           will never return to 'x4filter'.
  7059.  
  7060.    Warning
  7061.           Do not get the return convention of Code Base filtering
  7062.           routines backwards. Do not leave in the brackets as in
  7063.           "x4filter( d4deleted() )".
  7064.  
  7065.    Example
  7066.           /* Filter all deleted and blank records */
  7067.           x4filter( d4deleted ) ;
  7068.           x4filter( x4blank ) ;
  7069.               .
  7070.           /* Remove the 'x4blank' filtering */
  7071.           x4filter_pop() ;
  7072.               .
  7073.           /* Remove all of the filtering */
  7074.           x4filter_reset() ;
  7075.  
  7076.  
  7077. x4filter_pop
  7078.  
  7079.    Usage
  7080.           int  x4filter_pop()
  7081.  
  7082.    Desciption
  7083.           The last filter routine specified is popped from the list
  7084.           of filter routines attached to the current database. It is
  7085.           possible to remove several routines from the list by
  7086.           calling 'x4filter_pop' repeatedly.
  7087.  
  7088.    Returns
  7089.           Value       Meaning
  7090.  
  7091.            0          Success.
  7092.  
  7093.           -1          No filters are attached to the current database.
  7094.  
  7095.  
  7096. x4filter_reset
  7097.  
  7098.    Usage
  7099.           void  x4filter_reset()
  7100.  
  7101.    Description
  7102.           All of the filter routines attached to the current database
  7103.           are removed from the list.
  7104.  
  7105.    See Also
  7106.           x4filter.
  7107.  
  7108.  
  7109. x4filter_do
  7110.  
  7111.    Usage
  7112.           int  x4filter_do()
  7113.  
  7114.    Description
  7115.           All of the filtering routines for the current database are
  7116.           evaluated to determine whether the current database record
  7117.           should be filtered.
  7118.  
  7119.           The filtering routine uses the record currently in the
  7120.           database buffer.
  7121.  
  7122.    Returns
  7123.           Value       Meaning
  7124.  
  7125.            0          Use the record.
  7126.  
  7127.            1          Filter the record.
  7128.  
  7129.           -1          Error.
  7130.  
  7131.  
  7132. x4go
  7133.  
  7134.    Usage
  7135.           int  x4go( (long) rec_num )
  7136.  
  7137.    Description
  7138.           This routine is the same as 'd4go' except relations are used.
  7139.  
  7140.  
  7141. x4insert
  7142.  
  7143.    Usage
  7144.           int  x4insert( (long) rec_num )
  7145.  
  7146.    Description
  7147.           The record in the record buffer becomes record 'rec_num'.
  7148.           All of the previous records from 'rec_num' to the end of
  7149.           the database are copied forward one record to insert the
  7150.           new record.
  7151.  
  7152.           For example, 'x4insert(2L)' would create a new Record 2. If
  7153.           the database previously had 3 records, the old Record 2
  7154.           becomes Record 3 and the old Record 3 becomes Record 4.
  7155.  
  7156.           After the record is inserted, all of the index files for
  7157.           the database are reindexed to maintain their correctness.
  7158.  
  7159.    Returns
  7160.           Value       Meaning
  7161.  
  7162.            0          Success.
  7163.  
  7164.           -1          Error.
  7165.  
  7166.    Warning
  7167.           This routine can take a long time to execute for large
  7168.           databases.
  7169.  
  7170.  
  7171. x4list
  7172.  
  7173.    Usage
  7174.           int  x4list()
  7175.  
  7176.    Descripiton
  7177.           The contents of the database are written to the current
  7178.           output device. Filtering specified by 'x4filter' is used.
  7179.  
  7180.    Returns
  7181.           Value       Meaning
  7182.  
  7183.            0          Success.
  7184.  
  7185.           -1          Error.
  7186.  
  7187.  
  7188.     Usage
  7189.           int x4relate( (char *) expr, (int) base_ref, (int)
  7190.                   index_ref, (long) miss_code )
  7191.  
  7192.     Description
  7193.           Routine 'x4relate' creates a relation between a controlling
  7194.           database and a related database. The selected database
  7195.           becomes the controlling database and the specified database
  7196.           becomes the related database. Afterwards, when a
  7197.           controlling database is repositoned with an extend routine,
  7198.           such as 'x4seek' or 'x4top', all of the related database is
  7199.           repositioned with an extended routine, such as 'x4seek' or
  7200.           'x4top', all of the related databases are repositioned
  7201.           automatically.
  7202.  
  7203.           When a relation is processed the expression 'expr' is
  7204.           evaluated. If an index file was specified for the related
  7205.           database, the expression is looked up in the index file to
  7206.           move to a record in the related database. However,if no
  7207.           index file was specified, the 'expr' should return a
  7208.           numeric value  whick is interpreted as a record number.
  7209.           This record number specifies a new record in the related
  7210.           database.
  7211.  
  7212.     Parameter
  7213.           Name        Use
  7214.  
  7215.           expr        An expression which specifies either a key to
  7216.                   be locked up in the index file or  a record
  7217.                   number.
  7218.  
  7219.           base_ref    The database reference number corresponding to
  7220.                   an index file of the related database.
  7221.  
  7222.           index_ref   An index file reference number corresponding to
  7223.                   an index file of the related database.
  7224.                   If 'expr' is to specify a record number, this
  7225.                   parameter should be '(int) -1'.
  7226.  
  7227.           miss_code   This code determines the action if a record is
  7228.                   not located:
  7229.  
  7230.                   Code Value   Meaning
  7231.  
  7232.                  0         Use a Blank Record.
  7233.  
  7234.                 -1         Generate an Error Message.
  7235.  
  7236.                   >= 1         A default record number.
  7237.  
  7238.  
  7239.  
  7240. x4relate_do
  7241.  
  7242.     Usage
  7243.           int  x4relate_do()
  7244.  
  7245.     Description
  7246.           All of the relations for the current database are processed.
  7247.  
  7248.     Returns
  7249.           Value       Meaning
  7250.  
  7251.            0          Success.
  7252.  
  7253.           -1          Error.
  7254.  
  7255.     See Also
  7256.           'x4relate'.
  7257.  
  7258.  
  7259. x4relate_reset
  7260.  
  7261.     Usage
  7262.           void  x4relate_reset()
  7263.  
  7264.     Description
  7265.           All of the relations for the currently selected database
  7266.           are removed.
  7267.  
  7268.     Returns
  7269.           Value       Meaning
  7270.  
  7271.            0          Success.
  7272.           -1          Error.
  7273.  
  7274.  
  7275.  
  7276. x4replace
  7277.  
  7278.     Usage
  7279.           int  x4replace( (long) field_ref, (long) rec_num,
  7280.                   (void *) value )
  7281.  
  7282.     Description
  7283.           The record is read, the fields value is changed, and then
  7284.           the record is written.
  7285.  
  7286.     Parameters
  7287.           Name        Use
  7288.  
  7289.           field_ref   The field reference number.
  7290.  
  7291.           rec_num     The record number.
  7292.  
  7293.           value       The new value of the field. Refer to
  7294.                   'f4replace' for the format of this value.
  7295.  
  7296.     Returns
  7297.           Value       Meaning
  7298.  
  7299.            0          Success.
  7300.  
  7301.           -1          Error.
  7302.  
  7303.  
  7304. x4seek
  7305.  
  7306.     Usage
  7307.           int  x4seek( (char *) search_string )
  7308.  
  7309.     Description
  7310.           This routine is the same as 'd4seek' except filtering and
  7311.           relations are used.
  7312.  
  7313. x4skip
  7314.  
  7315.     Usage
  7316.           int  x4skip( (long) num_records )
  7317.  
  7318.     Description
  7319.           This routine is the same as 'd4skip' except filtering and
  7320.           relations are used.
  7321.  
  7322.  
  7323. x4sum
  7324.  
  7325.     Usage
  7326.           double  x4sum( (long) field_ref )
  7327.  
  7328.     Description
  7329.           The field specified by the field reference number is
  7330.           summed. Filtering is used to determine which records are
  7331.           used in the summation.
  7332.  
  7333.     Returns
  7334.           The summation is returned as a double. If an error
  7335.           occurs, '(double) 0.0' is returned.
  7336.  
  7337.  
  7338. x4top
  7339.  
  7340.     Usage
  7341.           int  x4top()
  7342.  
  7343.     Description
  7344.           This routine is the same as 'd4top' execpt filtering and
  7345.           relations are used.
  7346.  
  7347.  
  7348.  
  7349. MULTI-USER CONSIDERATIONS
  7350.  
  7351.     When using Code Base in a single user environment, you may safely ignore
  7352.     all the multi-user aspects of Code Base. However, if you plant to use
  7353.     Code Base with OS/2 or on a network where there are multiple sessions, it
  7354.  
  7355.     is necessary to learn about the multi-user features of Code Base.
  7356.  
  7357.     Code Base is also compatible with Clipper locking and unlocking protocol.
  7358.     Consequently, if a Clipper application and Code Base application are
  7359.     executed at the same time on a network, they understand each others file
  7360.     and record locking !!
  7361.  
  7362.  
  7363.  
  7364. LOCKING AND UNLOCKING
  7365.  
  7366.     In a multi-user enviroment, it is necessary to avoid having users reading
  7367.     and writing to and from the same disk record at the same time.
  7368.     Consequently, disk information is dedicated to one session before it is
  7369.     written or read.
  7370.  
  7371.     Dedicating disk information to one session is called "locking" it and
  7372.     freeing disk information for general use is called "unlocking" it.
  7373.  
  7374.     Code Base routines keep track of what files or portions of files have
  7375.     been locked and unlocked. Disk information will automatically be locked
  7376.     by Code Base before it is written or read.
  7377.  
  7378.     This means that the Code Base user only needs to unlock files at
  7379.     appropriate times. Doing so allows other users to access the previoulsy
  7380.     locked areas.
  7381.  
  7382.     Unlocking a database does not necessarily unlock all of the database's
  7383.     index files. It may be necessary to explicitly unlock them with routine
  7384.     'i4unlock'.
  7385.  
  7386.     Note that Code Base will only lock a single database record or the whole
  7387.     database. If it is necessary to lock serval records at once, use routine
  7388.     'd4lock' to lock the entire database.
  7389.  
  7390.     Hint:
  7391.  
  7392.       In a multi-user database enviroment, it is safest to assume any
  7393.       disk resident information could immediately be different once it
  7394.       has been unlocked.
  7395.  
  7396.  
  7397.  
  7398. RECORD COUNT BYTES
  7399.  
  7400.     The record count bytes specify how many records are currently in the
  7401.     database. These bytes can be locked and unlocked just like a database
  7402.     record. However, as Code Base locks and unlocks the record count bytes,
  7403.     it is generally not necessary to lock and unlock them in application
  7404.     programs.
  7405.  
  7406.     Code Base calculates the number of records in the database from the
  7407.     length of file. Consequently, the record count bytes are used by Code
  7408.     Base only when they are updated after the number of database records has
  7409.     been changed.
  7410.  
  7411.  
  7412.  
  7413. DEAD LOCK
  7414.  
  7415.     Dead lock is a situation to be avoided. It occurs when two sessions wait
  7416.     for each other indefinitely.
  7417.  
  7418.     A dead lock example is Session One waiting for file 'A' which is locked
  7419.     by Session Two and Session Two waiting for file 'B' which is locked by
  7420.     Session One. Since each session is waiting for each other, nothing will
  7421.     ever happen.
  7422.  
  7423.     A simple way to avoid deadlock is to have all sessions execute locks in
  7424.     the same order. In the previous deadlock example, file 'A' could always
  7425.     be locked before file 'B'. Then Session Two would unlock file 'B' before
  7426.     attempting to lock file 'A'. Session One could then lock file 'B',
  7427.     complete what it needs to do and then unlock the files for Session Two.
  7428.  
  7429.     Hint:
  7430.  
  7431.      It is important either explicity unlock index files or to unlock
  7432.      with 'd4unlock(-1)'.
  7433.  
  7434.     Note:
  7435.  
  7436.       Code Base 4 always locks index files before locking database
  7437.       records or files. Consequently, in order to avoid deadlock, you
  7438.       should make sure the database is not locked when an index file is
  7439.       locked.
  7440.  
  7441.  
  7442.  
  7443. APPENDIX A - BLOCK ROUTINES
  7444.  
  7445.     The block routines are low level routines called by the index file
  7446.     routines. Index file information is organized into a hierarchy of blocks.
  7447.     Block routines read, write, and manipulate those blocks.
  7448.  
  7449. b4add
  7450.  
  7451.     Usage
  7452.           int  b4add( (int) index_ref, (KEY *) key_ptr )
  7453.  
  7454.     Description
  7455.           Adds a key to the current block. 'b4add' is designed to
  7456.           work with 'i4add' to add a key to an index file.
  7457.  
  7458.     Returns
  7459.           Value       Meaning
  7460.  
  7461.            0          Success.
  7462.  
  7463.           -1          Error.
  7464.  
  7465.  
  7466. b4down
  7467.  
  7468.     Usage
  7469.           long  b4down( (int) index_ref, (int) direction )
  7470.  
  7471.     Description
  7472.           Reads one level deeper down the hierarchy of blocks.
  7473.  
  7474.     Parameters
  7475.           Name        Use
  7476.  
  7477.           index_ref   The index file reference number.
  7478.  
  7479.           direction   Specifies which direction to traverse down the
  7480.                   tree. If 'direction' is less than zero, the
  7481.                   tree is traversed left, and if 'direction' is
  7482.                   greater than zero, the tree is traversed right.
  7483.  
  7484.     Returns
  7485.           Value       Meaning
  7486.  
  7487.           >= 0        Block reference number of the new block.
  7488.  
  7489.             -1        At the bottom level. Cannot read futher down.
  7490.  
  7491.             -2        Read Error.
  7492.  
  7493.             -3        Out of Memory.
  7494.  
  7495.  
  7496. b4key
  7497.  
  7498.     Usage
  7499.           KEY *  b4key( (int) index_ref )
  7500.  
  7501.     Description
  7502.           Returns a pointer to the current key of the current block
  7503.           of the specified index file. Refer to 'd4base.h' for a
  7504.           definition of the 'KEY' structure.
  7505.  
  7506.     Returns
  7507.           If '(KEY *) 0' is returned, there is no current key.
  7508.  
  7509.  
  7510. b4remove
  7511.  
  7512.     Usage
  7513.           int  b4remove( (int) index_ref )
  7514.  
  7515.     Description
  7516.           The current key is removed from the current block. No
  7517.           writing is done to disk.
  7518.  
  7519.     Returns
  7520.           Value       Meaning
  7521.  
  7522.           >= 0        Number of Keys left in Block.
  7523.  
  7524.              0        Success.
  7525.  
  7526.             -1        Error.
  7527.  
  7528.  
  7529.  
  7530. b4search
  7531.  
  7532.     Usage
  7533.           int  b4search( (int)  index_ref, (char *) srch_ptr )
  7534.  
  7535.  
  7536.     Description
  7537.           The current block of the specified index file is searched
  7538.           for the value pointed to by 'srch_ptr'.
  7539.  
  7540.     Returns
  7541.           Value       Meaning
  7542.  
  7543.           0           Complete Match.
  7544.  
  7545.           1           Inexact Match.
  7546.  
  7547.           2           After the specified key.
  7548.  
  7549.           3           After the Block.
  7550.  
  7551.  
  7552.  
  7553. b4skip
  7554.  
  7555.     Usage
  7556.           int  b4skip( (int) index_ref, (long) num_skip )
  7557.  
  7558.     Description
  7559.           A specified number of keys are skipped. Skipping is
  7560.           relative to the current key of the current block.
  7561.  
  7562.     Parameters
  7563.           Name        Use
  7564.  
  7565.           index_ref   The index file reference number.
  7566.  
  7567.           num_skip    The number of keys to skip. This can be a
  7568.                   negative number.
  7569.  
  7570.     Returns
  7571.           The number of keys actually skipped. When an error occurs,
  7572.           'num_skip' with an opposite sign is returned.
  7573.  
  7574.  
  7575. b4up
  7576.  
  7577.     Usage
  7578.           int  b4up( (int) index_ref )
  7579.  
  7580.     Description
  7581.           Frees the current block and moves one block up the
  7582.           hierarchy of blocks. This is the opposite to routine
  7583.           'b4down'.
  7584.  
  7585.     Returns
  7586.           Value       Meaning
  7587.  
  7588.           >= 0        The block reference number of the new block.
  7589.  
  7590.             -1        The current block is the root block. Nothing
  7591.                   was done.
  7592.  
  7593.             -2        No block is present.
  7594.  
  7595.  
  7596. b4write
  7597.  
  7598.     Usage
  7599.           int  b4write( (int) index_ref )
  7600.  
  7601.     Description
  7602.           The current block of the specified index file is written to
  7603.           disk.
  7604.  
  7605.     Returns
  7606.           Value       Meaning
  7607.  
  7608.            0          Success.
  7609.  
  7610.           -1          Error.
  7611.  
  7612.  
  7613. APPENDIX B - COMPATIBILITY ISSUES
  7614.  
  7615.     Code Base can use the data, index and memo files of dBASE III, dBASE III
  7616.     PLUS, dBASE IV or Clipper. For Clipper compatible index files, refer to
  7617.     the appendix on Library Building. To use dBASE III, dBASE III PLUS or
  7618.     Clipper compatible memo files, refer to the chapeter on memo files.
  7619.  
  7620.     Consequently, Code Base can be used with any dBASE package which conforms
  7621.     to the dBASE file standard. Some popular programs that will work with
  7622.     Code Base are as follows:
  7623.  
  7624.           1. "dBEditor(TM)" from Sequiter Software Inc.
  7625.  
  7626.           2.  "R&R Relational Report Writer from Concentric Data
  7627.                Systems Inc.
  7628.  
  7629.           3.  "FoxBASE" (data files) from Fox Software.
  7630.  
  7631.           4.  "dBXL(TM)" from Wordtech Systems.
  7632.  
  7633.           5.  "dSALVATE" from Comtech Publishing Ltd.
  7634.  
  7635.  
  7636. OS/2, MICROSOFT WINDOWS
  7637.  
  7638.     Code Base contains a OS/2 and Microsoft Windows compatibility switches.
  7639.     Refer to the Appendix on Library Building.
  7640.  
  7641.  
  7642. dBASE IV
  7643.  
  7644.     Code Base is compatible with dBASE IV database (DBF), index (NDX) and
  7645.     memo file (DBT) file formats.
  7646.  
  7647.  
  7648.  
  7649. UNIX, XENIX
  7650.  
  7651.     There is a special version of Code Base for Unix/Xenix.
  7652.  
  7653.  
  7654.  
  7655.  
  7656. APPENDIX C - ERROR MESSAGES
  7657.  
  7658.     Code Base sends all error messages through a single routine which writes
  7659.     the error message and then sets the global error code: 'extern int
  7660.     v4error'.
  7661.  
  7662.     Consequently, it is easy to customize your own error handling by changing
  7663.     the Code Base routine 'u4error'.
  7664.  
  7665.     Whenever an error occurs, Code Base calls 'u4error'. Some critical errors
  7666.     cause Code Base to immediately halt. However, an error return is usually
  7667.     made.
  7668.  
  7669.     Following is a completer list of error messages which are organized by
  7670.     error number.
  7671.  
  7672.     General Disk Access Errors
  7673.  
  7674.     100    Creating File.
  7675.  
  7676.            This error could be caused by specifying an illegal file name,
  7677.            attempting to create a file which is open, or having a full
  7678.            directory or a disk problem.
  7679.  
  7680.  
  7681.     120    Opening File.
  7682.  
  7683.            This problem is usually caused by specifying a file which does
  7684.            not exist. Another possible cause is an attempt to open more
  7685.            files than the operating system can handle. Up to 20 files can
  7686.            be opened under DOS if "FILES=20" is specified in the
  7687.            "CONFIG.SYS" file.
  7688.  
  7689.  
  7690.     140    Reading File.
  7691.  
  7692.            A problem reading a file could be caused by a disk failure.
  7693.  
  7694.  
  7695.     160    Writing File.
  7696.  
  7697.            This error will occur when the disk is full.
  7698.  
  7699.  
  7700.     180    Closing File.
  7701.  
  7702.            An error occured while attempting to close a file.
  7703.  
  7704.  
  7705.  
  7706.     Database Specific Errors
  7707.  
  7708.     200    File is not a Database.
  7709.  
  7710.            This error occurs when routine "d4use" attempts to open a file
  7711.            which is not a database file.
  7712.  
  7713.  
  7714.     240    No Open Database.
  7715.  
  7716.            Open a database with "d4create" or "d4use" before calling a
  7717.            database routine.
  7718.  
  7719.  
  7720.     260    Record Length is Too Large.
  7721.  
  7722.            The current maximum record length is 32666.
  7723.  
  7724.  
  7725.     Index File Specific Errors
  7726.  
  7727.     300    Building Index File.
  7728.  
  7729.            Either there was insufficient memory, or there were too many
  7730.            records in the database to index. Try using the large memory
  7731.            model.
  7732.  
  7733.  
  7734.     310    Closing Index File.
  7735.  
  7736.            This error indicates that routine "i4close" was passed an
  7737.            illegal index reference number or that the index file could
  7738.            not be closed.
  7739.  
  7740.  
  7741.     320    File is not an Index File.
  7742.  
  7743.            This error occures when routine "i4open" attempts to open a
  7744.            file which is not a legitimate index file for the
  7745.            corresponding database.
  7746.  
  7747.  
  7748.     330    Index File is Missing a Key.
  7749.  
  7750.  
  7751.            The index file key, corresponding to an existing database
  7752.            record, does not exist.
  7753.  
  7754.  
  7755.     340    Key is not Unique.
  7756.  
  7757.            When an index file is created with the "Unique" flag on, all
  7758.            keys in the index file must be unique. An attempt to add a
  7759.            second key with the same value, causes this error.
  7760.  
  7761.  
  7762.     350    Key Evaluates to a Logical Result.
  7763.  
  7764.            Only character, numeric and date keys are allowed for index
  7765.            files.
  7766.  
  7767.  
  7768.     360    Key Length or Type has Changed.
  7769.  
  7770.            Once an index file has been created, the length or type of its
  7771.            key should not change. This can happen when the structure of
  7772.            the index files database is changed. For example, if an index
  7773.            file is indexed on a particular field and the field's type is
  7774.            changed from character to numeric, the index file will no
  7775.            longer be valid.
  7776.  
  7777.  
  7778.     370    Key Length over 100 Characters.
  7779.  
  7780.            A maximum of 100 characters are allowed for an index file key.
  7781.            This key length is determined by the expressin corresponding
  7782.            to the index file's key.
  7783.  
  7784.  
  7785.     380    Seek on Database with no Index File.
  7786.  
  7787.            Routine "d4seek" can only be made on a database with a
  7788.            corresponding index file.
  7789.  
  7790.            Routine "i4select" was passed and index reference number which
  7791.            does not correspond to an index file.
  7792.  
  7793.  
  7794.     Multi-User Errors
  7795.  
  7796.     400    Locking a File.
  7797.  
  7798.            There was a problem locking a database or index file.
  7799.  
  7800.     450    Unlocking a File.
  7801.  
  7802.            There was a problem unlocking a database or index file.
  7803.  
  7804.  
  7805.  
  7806.     Expression Evaluation Errors
  7807.  
  7808.     500    Database not Located while Evaluating Expression
  7809.  
  7810.            The database specified in the expression was not located.
  7811.  
  7812.  
  7813.     510    Executing Null Expression.
  7814.  
  7815.            Routine "e4exec" was passed a null pointer which should have
  7816.            been a pointer to a pseudo-compiled expression.
  7817.  
  7818.  
  7819.     515    Illegal Date.
  7820.  
  7821.            An illegal date was encountered when seeking or evaluating a
  7822.            date value.
  7823.  
  7824.  
  7825.     520    Expecting "," or ")" while Evaluating Expression.
  7826.  
  7827.            The expression is probably missing a comma or a right bracket.
  7828.  
  7829.  
  7830.     530    Expression is not Complete.
  7831.  
  7832.            The expression could not be evaluated because it is not a
  7833.            legitimate dBASE expression.
  7834.  
  7835.  
  7836.     540    Overflow while Evaluating Expression.
  7837.  
  7838.            The expression was too large or complex for Code Base. Code
  7839.            Base exits immediately if this error occurs.
  7840.  
  7841.  
  7842.     550    Parameter or Operator has the wrong Type.
  7843.  
  7844.            The expression 3+"A" would generate this error message. The
  7845.            operator '+' cannot add three to the letter "A". "A" is of
  7846.            type character rather than type numeric.
  7847.  
  7848.            Expression "SUBSTR(33,1,4)" would also generate this error
  7849.            message. In this case, the parameter 33 is the wrong type. The
  7850.            first parameter of function SUBSTR should be character.
  7851.  
  7852.     560    Right Bracket Missing in Expression.
  7853.  
  7854.            Make sure the expression has enough right brackets.
  7855.  
  7856.  
  7857.     570    Unrecognized Function in Expression.
  7858.  
  7859.            There was an attempt to use a function which is not supported
  7860.            by Code Base. Refer to the Appendix on Functions. Carefully
  7861.            check the function's spelling.
  7862.  
  7863.     575    Unrecognized Operator in Expression.
  7864.  
  7865.            Code Base supports a number of operators such as "+" and "/".
  7866.            You are attempting to use an operator which is not supported
  7867.            by Code Base.
  7868.  
  7869.  
  7870.     580    Unrecognized Value in Expression.
  7871.  
  7872.            There is a value in the expression which is not recognized as
  7873.            a field, string, number, logical value, or function.
  7874.  
  7875.  
  7876.     590    Unterminated String in Expression.
  7877.  
  7878.            A character sting's left quotes does not have a corresponding
  7879.            right quote.
  7880.  
  7881.  
  7882.     595    Wrong Number of Parameters in Expression.
  7883.  
  7884.            An expression function or operator was given an illegal number
  7885.            of parameters.
  7886.  
  7887.  
  7888.    Memo File Errors
  7889.  
  7890.     600    Editing Memo File with Editor.
  7891.  
  7892.            Either the specified editor program is not present or there is
  7893.            not enough memory.
  7894.  
  7895.  
  7896.     620    Memo File Name Inconsistency.
  7897.  
  7898.            You have either renamed a dBASE IV memo file without calling
  7899.            'm4renamed' or a non-dBASE IV memo file is being used with the
  7900.            dBASE IV memo file routines. Refer to 'm4convert'.
  7901.  
  7902.  
  7903.     640    Memo File Entry is over 32767 bytes.
  7904.  
  7905.            The maximum memo file entry size is 32767 bytes.
  7906.  
  7907.  
  7908.  
  7909.  
  7910.    Windowing and Menuing Errors
  7911.  
  7912.     800    Illegal Related Database.
  7913.  
  7914.            The related database was the same as the controlling database
  7915.            when defining a database 'relation'.
  7916.  
  7917.  
  7918.     820    No Controlling Database.
  7919.  
  7920.            No valid controlling database was specified when defining a
  7921.            database 'relation'.
  7922.  
  7923.  
  7924.     840    Relating Databases.
  7925.  
  7926.            An error occured while automatically positioning a related
  7927.            database.
  7928.  
  7929.  
  7930.  
  7931.    Critical Errors
  7932.  
  7933.     900    Out of Memory.
  7934.  
  7935.            An attempt was made to allocate some memory and no more was
  7936.            available.
  7937.  
  7938.  
  7939.     920    Memory Allocation.
  7940.  
  7941.            An attempt was made to allocate more than 0xFFE0 bytes of
  7942.            memory at once. This can be caused by opening too many files,
  7943.            or having too many windows, entry areas or index file blocks.
  7944.  
  7945.  
  7946.     950    Overwritten Memory.
  7947.  
  7948.            Code Base failed on an internal consistency check. This error
  7949.            occures when the application program has overwritten memory
  7950.            which Code Base uses.
  7951.  
  7952.  
  7953.     980    No Error Window.
  7954.  
  7955.            A default window is defined when either 'd4init' or 'w4define'
  7956.            is called for the first time. This error is reported on
  7957.            standard out if 'u4error' is called and the default window has
  7958.            not yet been defined.
  7959.  
  7960.  
  7961.  
  7962. APPENDIX D - EXPRESSIONS
  7963.  
  7964.     In Code Base, expressions are represented as a character string and are
  7965.     evaluated in the expression evaluation module.  Expressions are used to
  7966.     define the keys of an index file.  They can be useful for other
  7967.     purposes such as interactive queries.
  7968.  
  7969.    General Expression Information
  7970.  
  7971.     All expressions return a value of a specific type.  This type can be
  7972.     Numeric, Character, Date or Logical.
  7973.  
  7974.     A common form of an expression is the name of a field.  In this case,
  7975.     the type of the expression is the type of field.
  7976.  
  7977.     Field names, constants, and functions may all be used as parts of an
  7978.     expression.  These parts can be combined with other functions or with
  7979.     operators.
  7980.  
  7981.  
  7982.    Expression Constants
  7983.  
  7984.     Expression can onsist of a Numeric, Character or Logical constant.
  7985.     However, expressions which are constants are usally not very useful.
  7986.     Constants are usually used within a more complicated expression.
  7987.  
  7988.     A Numeric constant represents a number. For example. 5, 7.3, and -18
  7989.     are all Numeric constants.
  7990.  
  7991.     Character constants are letters with quote marks around them. "This
  7992.     is data", 'This is data', and "John Smith" are all examples of
  7993.     Character constants. If you wish to specify a character constant with
  7994.     a single quote or a double quote contained inside it, use the other
  7995.     type of quote to mark the Character constant. For example, "Man's"
  7996.     and '"Ok"' ar both legitimate Character constants.
  7997.  
  7998.     .TRUE., .FALSE. are the only legitimate Logical constants. .T. and
  7999.     .F. are legitimate abbreviations.
  8000.  
  8001.  
  8002.    Expression Operators
  8003.  
  8004.     Operators like '+', '*', or '<' are used to manipulate constants and
  8005.     fields. For example, 3+8 is an example of an expression in which the
  8006.     Add operator acts on tow numeric constants to return the numeric
  8007.     value 11.
  8008.  
  8009.     The values an operator acts on must have a type appropriate for the
  8010.     operator. For example, the Divide (/) operator acts on two numeric
  8011.     values.
  8012.  
  8013.  
  8014.     Precedence
  8015.  
  8016.     Operators have a precedence which specifies operator evaluation
  8017.     order. The precedence of each operator is specified in the following
  8018.     tables which describe the various operators. The higher the
  8019.     precedence, the earlier the operation will be performed. For example,
  8020.     Divide has a precedence of 6 and Plus has a precedence of 5 which
  8021.     means Divide is evaluated before Plus. Consequently, 1+4/2 is 3.
  8022.  
  8023.     Evaluation order can be made explicit by using brackets. For example,
  8024.     1+2 * 3 returns 7 and (1+2) * 3 returns 9.
  8025.  
  8026.  
  8027.     Numeric Operators
  8028.  
  8029.     The numeric operators all operate on Numeric values.
  8030.  
  8031.     Operator Name             Symbol        Precedence
  8032.  
  8033.     Add                       +             5
  8034.     Subtract                  -             5
  8035.     Multiply                  *             6
  8036.     Divide                    /             6
  8037.     Exponentiation            ** or ^       7
  8038.  
  8039.  
  8040.     Character Operators
  8041.  
  8042.     There are two character operators, named "Concatenate I" and
  8043.     "Concatenate II", which combine two character values into one. They
  8044.     are distinguished from the Add and Subtract operators by the types of
  8045.     the values they operate on.
  8046.  
  8047.     Operator Name             Symbol        Precedence
  8048.  
  8049.     Concatenate I             +             5
  8050.     Concatenate II            -             5
  8051.  
  8052.     Examples:
  8053.  
  8054.            "John  "+"Smith"   becomes       "John  Smith"
  8055.            "ABC"+"DEF"        becomes       "ABCDEF"
  8056.  
  8057.  
  8058.     Concatenate II is slightly different as any spaces at the end of the
  8059.     first Character value are moved to the end of the result.
  8060.  
  8061.     Examples:
  8062.  
  8063.            "John  "-"Smith"   becomes       "JohnSmith  "
  8064.            "ABC"-"DEF"        becomes       "ABCDEF"
  8065.            "A "-"D "          becomes       "AD  "
  8066.  
  8067.  
  8068.     Relational Operators
  8069.  
  8070.     Relational Operators are operators which return a Logical result
  8071.     (which is either true or false). All operators except Contain operate
  8072.     on Numeric, Character or Date values. Contain operates on two values
  8073.     of type character and returns true if the first is contained in the
  8074.     second.
  8075.  
  8076.     Operator Name             Symbol        Precedence
  8077.  
  8078.     Equal To                  =             4
  8079.     Not Equal To              <> or #       4
  8080.     Less Than                 <             4
  8081.     Greater Than              >             4
  8082.     Less Than or Equal To     < =           4
  8083.     Greater Than or Equal To  > =           4
  8084.     Contain                   $             4
  8085.  
  8086.  
  8087.     Example:
  8088.  
  8089.            "CD"$"ABCD"        returns true
  8090.            8<7                returns false
  8091.  
  8092.  
  8093.     Logical Operators
  8094.  
  8095.     Logical Operators return a Logical Result and operate on two Logical
  8096.     values.
  8097.  
  8098.     Operator Name             Symbol        Precedence
  8099.  
  8100.     Not                       .NOT.         1
  8101.     Or                        .OR.          2
  8102.     And                       .AND.         3
  8103.  
  8104.     Examples:
  8105.  
  8106.            .NOT. .T.          returns false
  8107.            .T. .AND. .F.      returns false.
  8108.  
  8109.  
  8110.  
  8111.    Expression Functions
  8112.  
  8113.     A function can be used as an expression or as part of an expression.
  8114.     Like operators, constants, and fields, functions return a value.
  8115.     Functions always have a function name and are followed by a left and
  8116.     right bracket. Values (parameters) may be inside the brackets.
  8117.  
  8118.     Warning
  8119.  
  8120.            These are not C functions to be called directly from C
  8121.            programs. These are dBASE functions which are recognized by
  8122.            the dBASE expression evaluation module.
  8123.  
  8124.    Function List
  8125.  
  8126.    CTOD( Char_Value )
  8127.  
  8128.     The character to date function converts a character value into a date
  8129.     value:
  8130.  
  8131.     CTOD( "19881130" )
  8132.  
  8133.     The character representation is always in the format "CCYYMMDD".
  8134.  
  8135.  
  8136.    DTOC( Date_Value ) and DTOS ( Date_Value )
  8137.  
  8138.     The date to character function converts a date value into a character
  8139.     value. The format of the resulting character value is "CCYYMMDD".
  8140.  
  8141.     DTOC( DATE() )
  8142.  
  8143.     returns the character value "19870530" if the date is May 30, 1987.
  8144.  
  8145.  
  8146.    DATE()
  8147.  
  8148.     The system date is returned.
  8149.  
  8150.  
  8151.    DEL()
  8152.  
  8153.     Returns "*" if the current record is marked for deletion.
  8154.     Otherwise " " is returned.
  8155.  
  8156.  
  8157.    DELETED()
  8158.  
  8159.     Returns .TRUE. if the current record is marked for deletion.
  8160.  
  8161.  
  8162.    IIF( Log_Value, True_Result, False_Result )
  8163.  
  8164.     If Log_Value is .TRUE. then IIF returns the True_Result value:
  8165.     otherwise, IIF returns the False_Result value.
  8166.  
  8167.     Examples:
  8168.  
  8169.            1. IIF( VALUE < 0, "Less than zero", "Greater than zero" )
  8170.            2. IIF( NAME = "John", "The name is John", "Not John" )
  8171.  
  8172.    RECCOUNT()
  8173.     The record count function returns the total number of records in the
  8174.     database:
  8175.  
  8176.     RECCOUNT()
  8177.  
  8178.     returns 10 if there are ten records in the database.
  8179.  
  8180.  
  8181.    RECNO()
  8182.  
  8183.     The record number function returns the record number to the current
  8184.     record.
  8185.  
  8186.  
  8187.    STR( Number, Length, Decimals )
  8188.  
  8189.     The string function converts a numeric value into a character value.
  8190.     "Length is the number of characters in the new string, including the
  8191.     decimal point. "Decimals" is the number of decimal places desired. If
  8192.     the number is too big for the alloted space, "*'s" will be filled in
  8193.     instead.
  8194.  
  8195.     Examples:
  8196.  
  8197.            1. STR( 5.7, 4, 2 )    returns "5.70"
  8198.  
  8199.           The number 5.7 is converted to a string of length 4. In
  8200.           addition, there will be 2 decimal places.
  8201.  
  8202.            2. STR( 5.7, 3, 2 )    returns "***"
  8203.  
  8204.           The number 5.7 cannot fit into string of length 3 if it is
  8205.           to have 2 decimal places. Consequently, "*'s" are filled in.
  8206.  
  8207.  
  8208.    SUBSTR( Char_Value, Start_Position, Num_Chars )
  8209.  
  8210.     A substring of the Character value is returned. The substring will be
  8211.     Num_Chars long, and will start at the Start_Position character of
  8212.     Char_Value.
  8213.  
  8214.     Examples:
  8215.  
  8216.            1. SUBSTR( "ABCDE", 2, 3 )       returns "BCD"
  8217.            2. SUBSTR( "Mr. Smith", 5, 1 )   returns "S"
  8218.  
  8219.  
  8220.    TIME()
  8221.  
  8222.     The time function returns the system time as a character
  8223.     representation. It uses the following format: HH:MM:SS.
  8224.  
  8225.     Examples:
  8226.  
  8227.            1. TIME()      returns 12:00:00  if it is noon.
  8228.            2. TIME()      returns 13:30:00  if it is one thirty PM.
  8229.  
  8230.  
  8231.    UPPER( Char_Value )
  8232.  
  8233.     A character string is converted to uppercase and the result is
  8234.     returned.
  8235.  
  8236.  
  8237.    VAL( Char_Value )
  8238.  
  8239.     The value function converts a character value to a numeric value.
  8240.  
  8241.     Examples:
  8242.  
  8243.            1. VAL( "10" )         returns 10
  8244.            2. VAL("-8.7" )        returns -8.7
  8245.  
  8246.  
  8247.  
  8248. APPENDIX E - LIBRARY BUILDING
  8249.  
  8250.    The files used to build the Code Base libraries are included on the
  8251.    repective library diskette:
  8252.  
  8253.     File      Purpose
  8254.  
  8255.     T4.BAT    To compile the files and build Turbo C compatible library
  8256.           "T4.LIB".
  8257.  
  8258.     M4.BAT    To compile the files and build the Mircosoft C and Quick C
  8259.           compatible library "M4.LIB".
  8260.  
  8261.     M4        An input file for the library builder 'lib.exe'. This file
  8262.           is used by the batch command file 'M4.BAT'.
  8263.  
  8264.    These files can be modified to build a custom Code Base library using any
  8265.    memory model or floating point option. Just do the following.
  8266.  
  8267.    1. Erase all existing Code Base object modules:
  8268.  
  8269.     erase ?4*.obj
  8270.  
  8271.  
  8272.    2. Copy the Code Base source files from the source diskette to the
  8273.       appropriate directory on your hard drive.
  8274.  
  8275.     copy a:*.* c:\c
  8276.  
  8277.  
  8278.    3. Copy the header files to your hard drive. These files are present on
  8279.       the Code base Microsoft library diskette.
  8280.  
  8281.     copy a:\include\*.h c:\c\include
  8282.  
  8283.  
  8284.    4. Copy file 'w4asm.obj' which is on the Code Base 4 MC library diskette.
  8285.       The assembler source code to 'w4asm.obj' is also on the same diskette
  8286.       and was compiled with Microsof Macro Assmebler 5.1.
  8287.  
  8288.  
  8289.    5. Copy the appropriate command files. These files are present on the Code
  8290.       Base library diskettes. Note that the pre-built libraries which are
  8291.       used for both Quick C and Microsoft C were generated using the C
  8292.       optimizing compiler with full optimization.
  8293.  
  8294.     copy a:t4.bat c:\c
  8295.  
  8296.            or
  8297.  
  8298.     copy a:m4.bat c:\c
  8299.     copy a:m4     c:\c
  8300.  
  8301.  
  8302.    6. Set the compiler options. Quick C and Microsoft C options are specified
  8303.       in the file 'm4.bat'. Turbo C compilations options are specified in
  8304.       file 'turbo.cfg'. To compile using Quick C, file 'm4.bat' needs to be
  8305.       changed so that the compiler 'QCL.EXE' is excuted rather than Microsoft
  8306.       C compiler 'CL.EXE'.
  8307.  
  8308.       For more information, refer to the documentation which came with your
  8309.       compiler.
  8310.  
  8311.  
  8312.    7. Start the compilation and library building.
  8313.  
  8314.     t4  (Execute 't4.bat')
  8315.  
  8316.            or
  8317.  
  8318.     m4  (Execute 'm4.bat')
  8319.  
  8320.  
  8321.    8.   Erase the generated object files.
  8322.  
  8323.  
  8324.    Codebase Compilation Switches
  8325.  
  8326.     Code Base contains several compilation switches. For example, there
  8327.     are switches for the OS/2 operating system, the Clipper NTX file
  8328.     compatibility option or Turbo C compatibility. The default is
  8329.     compatibility with dBASE, DOS ( versions 2.0 through 4.0), and
  8330.     Microsoft C (Quick C).
  8331.  
  8332.     Switch        Effect
  8333.  
  8334.     CLIPPER       This switch is used throughout to make Code Base
  8335.               compatiable with Clipper NTX files.  Regardless of how
  8336.               this switch is set, Code Base will be compatible with
  8337.               both Clipper and dBASE data files.
  8338.  
  8339.               When using Clipper Index Files, routines 'i4seek',
  8340.               'i4go', 'i4add' and 'i4remove' all expect Numeric Keys to
  8341.               formatted as ASCII with leading zeros.  However, the high
  8342.               level database routines operate identically.  To call
  8343.               'i4seek', 'i4go', 'i4add' or 'i4remove' directly, first
  8344.               call routine 'c4dtok' to transform the 'double' to the
  8345.               correct format.
  8346.  
  8347.     NOIO          This switch removes all references to the screen
  8348.               management routines from Code Base.  Instead, the
  8349.               standard library routine 'write' sends output to standard
  8350.               out.  Currently, the only routines effected are
  8351.               'u4error', 'd4init', and 'd4init_memory'.
  8352.  
  8353.     OS2           This switch is used in files 'w4.c' and 'g4.c' so Code
  8354.               Base uses the OS/2 video I/O calls rather than calls to
  8355.               library routine 'int86'.
  8356.  
  8357.  
  8358.     SMALL         All references to index file routines are removed from
  8359.               Code BASE.  This allows the creation of applications with
  8360.               very small EXE files.  If this switch is selected, do not
  8361.               use any index file routines, extend routines, and the
  8362.               following database routines: d4bottom, d4seek, d4skip,
  8363.               and d4top.
  8364.  
  8365.     TURBO         This switch makes Code Base compatible with Turbo C.  It
  8366.               is necessary slight differences between the Turbo C and
  8367.               Microsoft runtime libraries.
  8368.  
  8369.     WINDOWS_L     This switch lets the database management routines be
  8370.               used from Microsof Windows with the Medium or Small
  8371.               memory models. It is used in the memory allocation
  8372.               module and the 'u4error' routine.
  8373.  
  8374.     WINDOGS_G     This seitch lets the database management routines be
  8375.               used from Microsoft Windows with the Large or Compact
  8376.               memory models.
  8377.  
  8378.  
  8379.     Examples:
  8380.  
  8381.            Compiling with Microsoft C and OS/2 using the Large Memory
  8382.            Model:
  8383.  
  8384.           CL -Ox -Z1 -DOS2  -AL  -c  ?4*.c
  8385.  
  8386.  
  8387.            The switches '-Ox' and '-Z1' specify maximum optimization, and
  8388.            that there is to be no information relating to automatic
  8389.            library loading within the generated object modules. This
  8390.            information is not necessary in the Code Base library because
  8391.            it will be present in the application object modules.
  8392.  
  8393.            Compiling with Microsoft C for Quick C (Medium Memory Model)
  8394.            using the Clipper option:
  8395.  
  8396.           CL -Ox -Z1 -DCLIPPER -AM -c ?4*.c
  8397.  
  8398.  
  8399.            To compile with Turbo C using the small memory model, the
  8400.            Clipper compatibility option, and stack overflow logic, the
  8401.            file "turbo.cfg" would contain the following:
  8402.  
  8403.           -LC:\TC\LIB -IC:\TC\INCLUDE  -ms -c -DTURBO -DCLIPPER -N
  8404.  
  8405.            This assumes that the Turbo C library files are in directory
  8406.            "C:\TC\LIB" and that the Turbo C header files are in
  8407.            directory "C:\TC\INCLUDE".
  8408.  
  8409.  
  8410.  
  8411. APPENDIX F - Technical Support
  8412.  
  8413.    Before calling Sequiter Software Inc. for technical support on Code Base,
  8414.    do the following:
  8415.  
  8416.     1. Experiment with program 'd4learn' to learn the routines in question.
  8417.  
  8418.     2. Consult the programs on the library diskettes.
  8419.  
  8420.     3. Read the appropriate sections of the Code Base manual carefully.
  8421.        Make sure you understand what is being explained.
  8422.  
  8423.     4. Try writing a short program to illustrate the problem you are
  8424.        having. This process often solves the problem.
  8425.  
  8426.     5. If you are using Turbo C, make sure the TURBO conditional
  8427.        compilation switch is defined.
  8428.  
  8429.     6. If you are experiencing errors at link time, make sure that all of
  8430.        the object modules and libraries have been compiled in a
  8431.        consistent manner. They should all be compiled using the same
  8432.        memory model, and the same compilation switches. For example, if
  8433.        the Code Base library you are using was compiled using Turbo C 2.0
  8434.        with the 'CLIPPER' switch defined, make sure that your own code
  8435.        was compiled in the same manner. The 'readme' file on the MC
  8436.        library diskette specifies which versions of the supported
  8437.        compilers which were used to construct the prebuilt Code Base
  8438.        libraries. If there are undefined exteranl messages, note that all
  8439.        externals defined by Code Base 4 contain the character '4' in the
  8440.        second character position of the external name.
  8441.  
  8442.     7. If the trouble stems form a problem with general 'C' programming
  8443.        concepts consult your 'C' manuals.
  8444.  
  8445.     8. If you have any suggestions on how to improve Code Base, or if you
  8446.        have any Code Base applications which you would like to submit as
  8447.        freeware, we would like to hear from you. Please mail your
  8448.        comments to the address on the back of the manual.
  8449.  
  8450.  
  8451. APPEXDIX G - CODE BASE INTERNALS
  8452.  
  8453.    To understanding how Code Base operates, it is useful to understand the
  8454.    basics of how Code Base operates internally. However, it is not neccessary
  8455.    to be familiar with this material to use Code Base. Understanding this
  8456.    information should also assist anyone examing Code Base source code or
  8457.    those wishing to supplement Code Base library with their own routines.
  8458.  
  8459.    Record Buffer Format
  8460.  
  8461.     A Code Base record buffer uses the same storage format as the records
  8462.     stored on disk. They start with a one character record deletion flag.
  8463.     This flag is normally blank and is an asterisk ('*') when the record
  8464.     is marked for deletion. Following the deletion flag are all of the
  8465.     database fields in consecutive order. There are no special characters
  8466.     delimiting the field data. For example, if the first database field
  8467.     had a width of three, it would be contained in the second through
  8468.     fourth bytes of the record buffer. The second field would be stored
  8469.     immediately after the first field.
  8470.  
  8471.     All field types are stored as ASCII. For example, a numeric field
  8472.     with a width of 5 and 2 decimals could contain ASCII '5.70'. This
  8473.     would represent five decimal seven.
  8474.  
  8475.            Field Type         Storage Format
  8476.  
  8477.            Numeric            Right justified ASCII.
  8478.  
  8479.            Floating Point     Same as numeric.
  8480.  
  8481.            Date               CCYYMMDD (Ex. '19891231')
  8482.                   (Century, Year, Month Day)
  8483.  
  8484.            Logicals           'T', 't', 'Y' and 'y' for TRUE
  8485.                   'F', 'f', 'N' and 'n' for FALSE
  8486.  
  8487.            Memo               Ten characters of ASCII representing a
  8488.                   position in the corresponding memo file.
  8489.  
  8490.  
  8491.    Field Reference Numbers
  8492.  
  8493.     The database structure, of type 'BASE', contains a member which is a
  8494.     pointer to a structure array of type '(FIELD *)'. This array, defined
  8495.     by 'd4use', contains all of the field information associated with a
  8496.     database. The 'FIELD' structure is defined as follows:
  8497.  
  8498.            typedef struct
  8499.            {
  8500.           char        name[11] ;   /* Field Name */
  8501.           int         type ;       /* Field Type */
  8502.           char        width ;      /* Field Width */
  8503.           int         decimals ;   /* Number of Decimals */
  8504.           int         offset ;     /* Offset into Record Buffer */
  8505.            }  FIELD ;
  8506.  
  8507.     A field reference number is a long integer broken into two parts. The
  8508.     high order tow bytes contains the corresponding database reference
  8509.     number and the low order two bytes are an index into the '(FIELD *)'
  8510.     structure array. Consequently, the source code to routine 'f4j_ref'
  8511.     is as follows:
  8512.  
  8513.            long   f4j_ref( j_ref )
  8514.            int    j_ref ;
  8515.            {
  8516.           if ( j_ref > f4num_fields() || j_ref < 1 )
  8517.               return ( -1L ) ;
  8518.           else
  8519.               return ( (long) v4cur_vbase << 16 |
  8520.                   (long) (j_ref -1 ) ) ;
  8521.            }
  8522.  
  8523.  
  8524.    Code Base Memory Usage
  8525.  
  8526.     Code Base external variable names all start with 'v4'. There are
  8527.     several important variables which all point to arrays of structures:
  8528.     v4base, v4index, v4block, v4window, v4menu and v4get. Each structure
  8529.     of these structure arrays correspond to either a database, index
  8530.     file, index file B+ Tree node, window, menu item or get entry area
  8531.     respectively.
  8532.  
  8533.     Each of the Code Base structure arrays are mainpulated with the Code
  8534.     Base memory handling routines. This means if there is not enough
  8535.     space in a structure array to handle any particular routine call, the
  8536.     structure array is reallocated with a larger size. As a result, Code
  8537.     Base is built for the use of an unlimited number of databases, index
  8538.     files, windows, menus and get entry areas. Note that this memory
  8539.     reallocation will not occur very often.
  8540.  
  8541.     The Code Base memory handling routines also maintain a set of double
  8542.     linked lists for every memory structure. In addition to a double
  8543.     linked lists ou unused array structure entries, each structure array
  8544.     maintains the following double linked lists:
  8545.  
  8546.            Array          Double Linked List Usage
  8547.  
  8548.            v4base         Uses a double linked list of open databases.
  8549.                   The database reference number to the last
  8550.                   opened database is contained in the external
  8551.                   integer variable 'v4last_base'. Similarily, the
  8552.                   reference number to the currently selected
  8553.                   database is contained in external integer
  8554.                   variable 'v4cur_base'.
  8555.  
  8556.            v4index        There is a double linked list of open index
  8557.                   files for every open database which has one or
  8558.                   more index files. An index file reference
  8559.                   number, for each double linked list, is saved.
  8560.                   This reference number is contained in the
  8561.                   corresponding database structure. Similarily,
  8562.                   the reference number of the currently selected
  8563.                   index file is saved. Refer to the structure of
  8564.                   type 'BASE' and 'INDEX' which are defined in
  8565.                   header file 'd4base.h'.
  8566.  
  8567.            v4block        There is a double linked list of index file B+
  8568.                   Tree nodes in memory for each index file. The
  8569.                   reference number to each of these double linked
  8570.                   lists is contained in the corresponding index
  8571.                   file structure.
  8572.  
  8573.            v4window       There is one double linked list of defined
  8574.                   windows. The reference number to the first
  8575.                   defined, last defined, and currently selected
  8576.                   windows, are defined in external integer
  8577.                   variables 'v4first_window', 'v4last_window'
  8578.                   and 'v4cur_window' respectively. As windows
  8579.                   becomve activated, the ordering of this double
  8580.                   linked list changes. It becomes the order in
  8581.                   which the windows were activated.
  8582.  
  8583.            v4menu         There is a double linked list of menu items for
  8584.                   each window containing a menu. The reference
  8585.                   number to the first and last defined menu
  8586.                   items, of a window, are contained in the
  8587.                   corresponding window structure. Refer to header
  8588.                   file 'w4.h'.
  8589.  
  8590.     All reference numbers, except for field reference numbers, are
  8591.     subscripts into the corresponding structure array. For example, the
  8592.     first time routine 'd4use' is called, it returns a database reference
  8593.     number of '(int) 0'. This means that structure entry v4base[0]
  8594.     contains the information about the database. The source code to
  8595.     routine 'd4recno' provides insight as to how reference numbers are
  8596.     used:
  8597.  
  8598.            long  d4recno()
  8599.            {
  8600.           /* 'v4cur_base' is the currently selected database
  8601.              reference number */
  8602.  
  8603.           if ( v4base[v4cur_base].rec_num <= 0 )
  8604.               return( 0L ) ;
  8605.           else
  8606.               return( v4base[v4cur_base].rec_num ) ;
  8607.            }
  8608.  
  8609.     The double linked lists, mentioned above, are easily maitained by
  8610.     defining the first two members, of each structure array, to be the
  8611.     next and previous reference numbers respectively. As the reference
  8612.     numbers are fixed integers, the double linked lists are kept intact
  8613.     when a memory structure is reallocated. In addtion, if exact memory
  8614.     copies of the memory structures are saved to disk adn then read back,
  8615.     the double linked lists will be maintained. Sequiter's dBEditor
  8616.     product makes use of this fact.
  8617.  
  8618.     A reference number of '(int) -1', means that there is no structure
  8619.     entry, For example, if 'v4last_base' is '(int) -1', there are no open
  8620.     databases. Similarily, if there is one database open,
  8621.     'v4base[v4last_base].prev' is '(int) -1' as the double linked list of
  8622.     open databases would only have one entry.
  8623.  
  8624.  
  8625.  
  8626.