home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-11-24 | 31.7 KB | 1,005 lines |
-
-
-
-
-
-
-
- ###### ###### ###### ####### #####
- # # # # # # # # # #
- # # # # # # # # #
- # # ###### # # # # #
- # # # # ### # # # # #
- # # # # ### # # # # # #
- ###### ###### ### ###### ####### #####
-
-
- # # # #####
- # # ## # #
- # # # # #
- # # # #####
- # # # ### #
- # # # ### #
- # ##### ### #######
-
-
-
- (c) 1987 Ken Harris
- 901 E. Hampton
- Milwaukee, WI 53217
- (414) 962-1961
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /****************************************************************************/
- /* */
- /* This software is made available on an AS-IS basis. Unrestricted */
- /* use is granted provided that the copywrite notice remains intack. */
- /* The author makes no warranties expressed or implied; however, any */
- /* feedback is welcome. */
- /* */
- /****************************************************************************/
-
-
- V1.2 Release Notes:
- ---- ------- -----
-
- (1) The DB_READ_LAST and DB_READ_PREV routines have been added
- to allow backwards traversal. The routines work for all three
- file types. DB_DELETE should not be used with these routines.
- The delete routine sets the current record pointer so that a
- subsequent DB_READ_NEXT will work correctly. A DB_READ_PREV
- loop with DB_DELETES will result in skipped records.
-
-
- (2) A number of bugs in the file create routine have been fixed.
-
-
- (3) A file corruption bug in the index delete routine has been
- fixed.
-
-
- (4) The distribution has been divided into three separately
- compiled files.
-
-
- (5) Large memory model now works correctly.
-
-
- (6) A lot of "warning" type problems have been cleaned up.
-
- (7) Just before releasing V1.2 Microsoft C V5.0 rolled in
- the door so I was able to fix a couple of problems.
- There are still some warning messages while compiling
- db_main.c. This is the result of ",..." type declarations
- used to prevent type checking of the user_data argument.
- User programs don't have to type cast user_data to char*
- to avoid warnings.
-
- (8) I have avoided the temptation of using too many of the
- ANSI C extensions for those folks with old compilers.
- Also I'd rather not fill the code with a zillion IFDEF's.
-
-
- +----------+ ------------------- +----------+
- | db_Intro | - DB Introduction - | db_Intro |
- +----------+ ------------------- +----------+
-
-
-
- o Description
-
- This document describes the DB package for maintaining
- data files. The package consists of a library of file handling
- routines which may be linked with user programs.
-
- The following three file organizations are supported:
-
- (1) Sequential - The file is a sequential stream of records.
-
- (2) Index - Data records are stored in an index sequential
- organization.
-
- (3) Random - Data records are stored using a hashed method.
-
-
- The following operations are supported:
-
- db_add - Add a New Record to a Data Set
- db_create - Create a New Data Set
- db_close - Close an Open Data Set
- db_delete - Delete the Current Record
- db_error_msg - Get Error Message Text
- db_find - Find a Record by Key
- db_get_rec_no - Get Relative Record #
- db_open - Open an Existing Data Set
- db_read_atr - Read Attribute Data
- db_read_direct - Read by Record #
- db_read_first - Read First Record
- db_read_next - Read Next Record
- db_update - Update the Current Record
- db_update_atr - Update Attribute Data
-
-
- +------+ ------------------------------- +------+
- | db.h | - Data Set Structures Defines - | db.h |
- +------+ ------------------------------- +------+
-
-
-
- o Summary
-
- #include <db.h>
-
-
-
- o Description
-
- This header file contains the definitions for the global
- structures that are used by all of the DB routines. It
- should be included in any program that calls DB routines.
- The user program needs only to declare DATA_SET descriptor
- pointers for the data sets that are to be used. The
- DATA_SET descriptor pointer is used to refer to the data
- sets.
-
-
- A global variable db_error is used to return a status
- value after any call to a DB routine. The header file
- includes constant declarations for db_error values.
- The user program can check for specific conditions
- such as DB_END_OF_FILE. A function call db_error_msg()
- can be used to get the error message text corresponding
- to the value of db_error.
-
- +--------+ ------------------------------------ +--------+
- | db_add | - Add a New Record to a Data Set - | db_add |
- +--------+ ------------------------------------ +--------+
-
-
-
- o Summary
-
- #include <db.h>
-
- ulong db_add(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to add a new record to a data set.
- The data set is specified by the input ds and user_data
- points to the data record to be added.
-
- For Indexed and Random data sets, the first field of the
- data record (user_data) must contain the record key value.
-
- The value of Current Record (used by db_read_next) is reset
- to NONE by this operation.
-
-
-
- o Returns
-
- The relative record number of the new record is returned.
- If an error occurs a zero value is returned and the global
- db_error contains the error number.
-
-
-
- +----------+ ---------------------------- +----------+
- | db_close | - Close an Open Data Set - | db_close |
- +----------+ ---------------------------- +----------+
-
-
-
- o Summary
-
- #include <db.h>
-
- DATA_SET db_close(ds)
- DATA_SET ds;
-
-
-
- o Description
-
- This function terminates all processing for an open data set.
- The associated file is closed and all dynamic storage is
- released.
-
-
-
- o Returns
-
- The completion status of the function is returned in the
- global db_error. The function itself returns a NULL pointer
- value.
-
- +-----------+ ------------------------- +-----------+
- | db_create | - Create a New Data Set - | db_create |
- +-----------+ ------------------------- +-----------+
-
-
-
- o Summary
-
- #include <db.h>
-
- DATA_SET db_create(path, fname, fhdr)
- char *path, *fname;
- FILE_HDR fhdr;
-
-
-
- o Description
-
- This function is used to create a new data set. The inputs
- are as follows:
-
- path - Path name of data directory
- fname - File name of new data set
- fhdr - Pointer to the file header structure
-
-
- The structure information about the data set is passed in
- a file header record. For a create ONLY, the user program
- must allocate a file header record for the data set and fill
- in the necessary values. This is a kludge that will be
- replaced by a utility program of some sort to do file
- creates. The following file header fields are required:
-
- Sequential Organization
- fh_file_type = DB_SEQ
- fh_data_size = nn
-
- Indexed Organization
- fh_file_type = DB_INDEX
- fh_data_size = nn (includes key size)
- fh_key_size = nn
-
- Random Organization
- fh_file_type = DB_RANDOM
- fh_data_size = nn (includes key size)
- fh_key_size = nn
- fh_base_size = nn
-
-
-
- The following fields may optionally be specified:
-
- fh_block_size = nn
- fh_atr_size = nn
- fh_file_stat = DB_DUP_ALLOWED (Index only)
-
-
-
-
- o Returns
-
- This function returns a pointer to the data set descriptor
- block for the newly created data set. This value should be
- used for future references to the data set. The status of
- the data set is open.
-
- The return status is available in the global db_error. If
- an error occurs the new data set is not created and a null
- descriptor pointer is returned.
-
- +-----------+ ------------------------------- +-----------+
- | db_delete | - Delete the Current Record - | db_delete |
- +-----------+ ------------------------------- +-----------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_delete(ds)
- DATA_SET ds;
-
-
-
- o Description
-
- This function is used to delete the Current Record from the
- data set specified by ds.
-
- This function must be preceeded by some function that
- establishes the Current Record for the data set.
-
-
-
- o Returns
-
- The completion status is returned in the global db_error.
- A non-zero value indicates an error. The Current Record
- for the data set is reset to NONE.
-
- +----------+ ------------------------- +----------+
- | db_error | - Global Error Status - | db_error |
- +----------+ ------------------------- +----------+
-
-
-
- o Summary
-
- extern int db_error;
-
-
-
- o Description
-
- This global variable contains the completion status of
- the most recent db_xxxx call. The following values and
- associated constants are defined for V1.1:
-
-
- DB_FILE_NOT_FOUND 1
- DB_READ_ERROR 2
- DB_END_OF_FILE 3
- DB_WRITE_ERROR 4
- DB_FILE_NOT_CREATED 5
- DB_FILE_NOT_OPEN 6
- DB_INVALID_BLOCK 7
- DB_BUFFER_ERROR 8
- DB_NO_CURRENT_REC 9
- DB_DELETED_REC 10
- DB_INVALID_FREE 11
- DB_INVALID_BLK_SIZE 12
- DB_INVALID_INDEX 13
- DB_REC_NOT_FOUND 14
- DB_DUP_NOT_ALLOWED 15
- DB_INVALID_REQUEST 16
- DB_INVALID_RANDOM 17
- DB_INVALID_FHDR 18
- DB_VERSION_ERROR 19
-
-
- +--------------+ ---------------------------- +--------------+
- | db_error_msg | - Get Error Message Text - | db_error_msg |
- +--------------+ ---------------------------- +--------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- char *db_error_msg(error)
- int error;
-
-
-
- o Description
-
- This function is used to get an error message corresponding
- to the error number returned in db_error.
-
-
-
- o Returns
-
- A pointer to the error message is returned.
-
-
- +---------+ -------------------------- +---------+
- | db_find | - Find a Record by Key - | db_find |
- +---------+ -------------------------- +---------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_find(ds, user_data, key, key_size)
- DATA_SET ds;
- char *user_data;
- char *key;
- int key_size;
-
-
-
- o Description
-
- This function is used to find a record by key value. The
- following are inputs:
-
- ds - specifies the data set
- user_data - pointer to the destination buffer
- key - pointer to key value
- key_size - length of the key field
-
- The key_length field allows for matching less than the
- entire record key in an Index data set. A key_size of zero
- defaults to entire key length. For a Random data set, the
- key_length field is ignored.
-
- This function is not valid for Sequential data sets.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
-
- +---------------+ --------------------------- +---------------+
- | db_get_rec_no | - Get Relative Record # - | db_get_rec_no |
- +---------------+ --------------------------- +---------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- ulong db_get_rec_no(ds)
- DATA_SET ds;
-
-
-
- o Description
-
- This function returns the Relative Record Number for the
- Current Record in the data set specified by ds. The
- Relative Record Number for records in sequential data
- sets is fixed; however, for records in Index and Random
- data sets the value may be changed due to reorganizations
- that occur when adds and deletes take place.
- occur.
-
-
-
- o Returns
-
- The value of the relative record number is returned.
- If there is an error, a NULL value is returned and the
- global db_error contains the error code.
-
-
- +---------+ ------------------------------- +---------+
- | db_open | - Open an Existing Data Set - | db_open |
- +---------+ ------------------------------- +---------+
-
-
-
- o Summary
-
- #include <db.h>
-
- DATA_SET db_create(path, fname)
- char *path, *fname;
-
-
-
- o Description
-
- This function is used to open an existing data set. The inputs
- are as follows:
-
- path - Path name of data directory
- fname - File name of the data set
-
-
-
- o Returns
-
- This function returns a pointer to the data set descriptor
- block for the data set. This value should be used for future
- references to the data set.
-
- If an error occurs a NULL value is returned and the global
- db_error contains the error number.
-
-
-
-
- +-------------+ ------------------------- +-------------+
- | db_read_atr | - Read Attribute Data - | db_read_atr |
- +-------------+ ------------------------- +-------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_atr(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read the attribute record for a
- data set. The data set is specified by ds and user_data
- points to the destination buffer.
-
- The attribute data is a single user-define record that
- may be used to store some global data for the data set.
-
-
-
-
- o Returns
-
- The attribute record is read into the buffer pointed to by
- user_data. The completion status is returned in the global
- db_error. A non-zero value indicates an error.
-
- +----------------+ ----------------------- +----------------+
- | db_read_direct | - Read by Record # - | db_read_direct |
- +----------------+ ----------------------- +----------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_direct(ds, rec_no, user_data)
- DATA_SET ds;
- ulong rec_no;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read a record directly by using its
- Relative Record Number. The data set is specified by ds,
- the Relative Record Number is rec_no and user_data points
- to the destination buffer.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
- +---------------+ ----------------------- +---------------+
- | db_read_first | - Read First Record - | db_read_first |
- +---------------+ ----------------------- +---------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_first(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read the first record from a data set.
- The data set is specified by ds and user_data points to the
- destination buffer for the record.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
- +--------------+ ---------------------- +--------------+
- | db_read_last | - Read Last Record - | db_read_last |
- +--------------+ ---------------------- +--------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_last(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read the last record from a data set.
- The data set is specified by ds and user_data points to the
- destination buffer for the record.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
- +--------------+ ---------------------- +--------------+
- | db_read_next | - Read Next Record - | db_read_next |
- +--------------+ ---------------------- +--------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_next(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read the next record from a data set.
- The data set is specified by ds and user_data points to the
- destination buffer for the record.
-
- This function must be preceeded by some function that
- establishes the Current Record for the data set. For example
- db_read_first followed by db_read_next until end of file
- occurs. The value of Current Record is reset to NONE by
- a db_add.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
- +--------------+ ---------------------- +--------------+
- | db_read_prev | - Read Prev Record - | db_read_prev |
- +--------------+ ---------------------- +--------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_read_prev(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to read the previous record from a data
- set. The data set is specified by ds and user_data points to
- the destination buffer for the record.
-
- This function must be preceeded by some function that
- establishes the Current Record for the data set. For example
- db_read_last followed by db_read_prev until end of file
- occurs. The value of Current Record is reset to NONE by
- a db_add.
-
- db_read_prev should not be used with db_delete. db_delete
- positions the current pointer so that a db_read_next will
- be correct. A db_read_prev loop with deletes will skip
- records.
-
-
-
- o Returns
-
- The data record is read into the buffer pointed to by
- user_data. The read record becomes the Current Record
- for this data set. The completion status is returned
- in the global db_error. A non-zero value indicates an
- error.
-
-
-
- +-----------+ ------------------------------- +-----------+
- | db_update | - Update the Current Record - | db_update |
- +-----------+ ------------------------------- +-----------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_update(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to update the Current Record for the
- data set specified by ds. The contents of the data record
- pointed to by user_data are written back to the data set.
-
- This function must be preceeded by some function that
- establishes the Current Record for the data set.
-
-
-
- o Returns
-
- The completion status is returned in the global db_error.
- A non-zero value indicates an error. The Current Record
- for the data set is reset to NONE.
-
-
- +---------------+ --------------------------- +---------------+
- | db_update_atr | - Update Attribute Data - | db_update_atr |
- +---------------+ --------------------------- +---------------+
-
-
-
- o Summary
-
- #include <db.h>
-
- void db_update_atr(ds, user_data)
- DATA_SET ds;
- char *user_data;
-
-
-
- o Description
-
- This function is used to update the attribute record for a
- data set. The data set is specified by ds and user_data
- points to the source buffer to be written to the attribute
- area for the data set.
-
- The attribute data is a single user-define record that
- may be used to store some global data for the data set.
-
-
-
-
- o Returns
-
- The completion status is returned in the global db_error.
- A non-zero value indicates an error.
-
-
- +-------------+ ------------------------------ +-------------+
- | fname_dflts | - Merge File Name Defaults - | fname_dflts |
- +-------------+ ------------------------------ +-------------+
-
-
-
- o Summary
-
- char *fname_dflts(fname, dflt)
- char *fname, *dflt;
-
-
-
- o Description
-
- This function merges a file name string with a
- default file name. For example the following would
- force a default extension of ".c" if no extension
- was present.
-
- x = fname_dflts(fname,".c");
-
-
-
- o Returns
-
- A pointer to the resulting static string is returned.
-
-
- +--------+ ----------------------- +--------+
- | fparse | - Parse a File Spec - | fparse |
- +--------+ ----------------------- +--------+
-
-
-
- o Summary
-
- fparse(fstr, o_node, o_dev, o_dir, o_file, o_ext, o_ver)
- char *fstr, *o_node, *o_dev, *o_dir, *o_file, *o_ext, *o_ver;
-
-
-
- o Description
-
- This function parses a file specification fstr into component
- parts. Not all of these components apply to generic MS-DOS.
-
- o_node - Node name
- o_dev - Device name
- o_dir - Directory Path
- o_file - File name
- o_ext - File extension
- o_ver - Version number
-
-
-
- o Returns
-
- The component strings are copied into the buffers pointed
- to by the o_* args.
-
-
- +--------+ ------------------- +--------+
- | memedt | - Edit a Buffer - | memedt |
- +--------+ ------------------- +--------+
-
-
-
- o Summary
-
- void memedt(mem, cnt, flag)
- char *mem;
- int cnt, flag;
-
-
-
- o Description
-
- This function performs an edit on the string mem of
- length count. The flag specifies edit options:
-
- 1 - trim parity bit
- 2 - discard all spaces and tabs
- 4 - discard excess characters
- 8 - discard leading spaces & tabs
- 16 - reduce spaces and tabs to 1
- 32 - convert to upper case
- 64 - *** not used ***
- 128 - discard trailing spaces & tabs
- 256 - don't alter char in quotes
-
-
-
- o Returns
-
- The string is edited in place.
-
-
- +------+ -------------------------- +------+
- | sort | - Callable Record Sort - | sort |
- +------+ -------------------------- +------+
-
-
-
- o Summary
-
- void sort_init(rec_size, spec_str)
- int rec_size;
- char *spec_str;
-
- void sort_release(data_rec)
- char *data_rec;
-
- void sort_merge()
-
- char *sort_return(data_rec)
- char *data_rec;
-
-
-
- o Description
-
- This set of functions provides a callable record sort
- facility:
-
- sort_init - Initialize the sort. This must be done first.
- rec_size = the size of the data record
- spec_str = string of sort specs separated
- by commas. "spec,spec,spec..."
- spec = XXn.n
- ||| |
- ||| +--- size of field (bytes)
- ||+----- starting position (1 relative)
- ||
- |+------ Format A = Alpha
- | U = Unsigned integer
- | I = Integer
- | R = Real
- |
- +------- Sequence A = Ascending
- D = Descending
-
- sort_release - Release a record to the sort. data_rec
- points to the data.
-
- sort_merge - Do the sort merge operation.
-
- sort_return - Return a record from the sort and put
- it in data_rec. A pointer to the data
- record is returned. A NULL value indicates
- end of file.
-
-
-
- o Returns
-
- If a sort error occurs an error message is printed and
- the program aborts.
-
- +--------+ ------------------- +--------+
- | stredt | - Edit a String - | stredt |
- +--------+ ------------------- +--------+
-
-
-
- o Summary
-
- void stredt(str, flag)
- char *str;
- int flag;
-
-
-
- o Description
-
- This function performs an edit on the null terminated
- string str. The flag specifies edit options:
-
- 1 - trim parity bit
- 2 - discard all spaces and tabs
- 4 - discard excess characters
- 8 - discard leading spaces & tabs
- 16 - reduce spaces and tabs to 1
- 32 - convert to upper case
- 64 - *** not used ***
- 128 - discard trailing spaces & tabs
- 256 - don't alter char in quotes
-
-
-
- o Returns
-
- The string is edited in place.
-
-