(c)Copyright Nadezhda Company 1995.

All rights reserved.

SLang is Copyrighted by John E. Davis
---------------------------------------------------------------

     LDBF USER API REFERENCE

This guide contains description of LDBF API for C programming 
and stored procedures.
SLang language is used for writing stored procedures and triggers.
Reference "SLang:" describes prototype for function that called
from SLang scripts.For more detail about SLang language see
slang.txt file.

---------------------------------------------------------------
Date Functions

---------------------------------------------------------------
ldbfdate_assign()

 Usage:  void ldbfdate_assign(char *date,long julian_day)

 Description:  A long integer, in julian date form, is converted
  into a character date, and copied into "date".  "date"
  must point to an array of eight characters.  The character
  form is in the format CCYYMMDD (century, year, month, day).

  This function is the inverse function of ldbfdate().

 See Also   ldbfdate()

 SLang:     char *ldbfLong2Date(long jullian_date)



---------------------------------------------------------------
ldbfday()

 Usage:  int ldbfday(char *date)

 Description:  The day of the month, from 1 to 31, is returned as
  an integer.

  If the date is blank, a zero is returned.

SLang:   char *ldbfToday()  

---------------------------------------------------------------
ldbfdow()

 Usage:  int ldbfdow(char *date)

 Description:  The day of the week, from 1 to 7, is returned as
  an integer according to the following table:

  Day      Numeric Day of Week

  Sunday       1
  Monday       2
  Tuesday      3
  Wednesday    4
  Thursday     5
  Friday       6
  Saturday     7

  If the date is blank, a zero is returned.


SLang:  int ldbfDOW();

---------------------------------------------------------------
ldbfdate_format()

 Usage:  void ldbfdate_format(char *date,char *result,char *picture)

 Description:  The date is formatted into parameter "result" according to
  the date picture parameter "picture".  The special formatting
  characters are C - Century, Y - Year, M - Month, and D - Day.

  If there are more than two "M" characters, a character
  representation of the month is returned.

 Parameters  Name       Use

   date       This is the date in dBASE date format
         (CCYYMMDD).

   result       This is the result.  It must contain
         as many characters as the picture plus
         one for a null at the end.  The result
         will be null terminated.

   picture      This is a character string that contains a
         date picture.

 Example

    char result[20];
       memcpy( dt,0 , sizeof(dt) ) ;  { Oct 02, 1990 }

       { "result" will contain "90.10.02" }
       ldbfdate_format( "19901002", result, "YY.MM.DD" ) ;

       { "result" will contain "1990.10.02" }
       ldbfdate_format( "19901002", result, "CCYY.MM.DD" ) ;

       { "result" will contain "10/02/90" }
       ldbfdate_format( "19901002", result, "MM/DD/YY" ) ;

       { "result" will contain "Oct 02/1990" }
       ldbfdate_format( "19901002", result, "MMM DD/CCYY" )


SLang:   char *ldbfDateFormat(char *date,char *picture)


---------------------------------------------------------------
ldbfdate_init()

 Usage:  void ldbfdate_init(char *date,char *value,char *picture)

 Description:  The date is initialized from parameter "value".  "value"
  is formatted according to picture parameter "picture".

  This is the inverse function of ldbfdate_format().

  If any of the date is missing, the missing portion
  is filled in using the date January 1, 1980.

 Parameters Name      Use

            value     This is a character string which represents
                      a date.

            picture   This is a character string which specifies
                      the format of parameter "value".

 Example

       char day[7];

       { Variable "day" becomes "19901007". ie. Oct 07, 1990 }
       ldbfdate_init( day, "Oct 07/90", "MMM DD/YY" ) ;

       { Variable "day" becomes "19890807". ie. Aug 07, 1989 }
       ldbfdate_init( day, "08/07/1989", "MM/DD/CCYY" ) ;

       { Variable "day" becomes "19890708". ie. July 08, 1989 }
       ldbfdate_init( day, "08/07/1989", "DD/MM/CCYY" ) ;

SLang:  string ldbfDateInit(string date,string picture)

---------------------------------------------------------------
ldbfdate()

 Usage:  long  ldbfdate(char *date)

 Description:  ldbfdate() converts a date from dBASE character
  format to a julian day.

  If the date is a blank, 0 is returned.

 See Also    ldbfdate()  ldbfassign_long()

 Example

       char date[8];
       long julian_day;
       memcpy( date, "19901031", sizeof(date) ) ;

       julian_day =  ldbfdate( date )  +  1 ;

       ldbfdate_assign( date, julian_day )

SLang:   int ldbfDate2Long(char *date)

---------------------------------------------------------------
ldbfmonth()

 Usage:  int ldbfmonth(char 8date)

 Description:  The month of the year, from 1 to 12, is returned as
  an integer.

  If the date is blank, 0 is returned.

SLang:   int ldbfMonth(char *date)


---------------------------------------------------------------
ldbftime_now()

 Usage:  void ldbftime_now(char *time)

 Description:     This function initialized the time to the
        current time from the clock of the computer.

 Parameters     "time" must point to 8 characters of memory.  This memory
        is filled with the time in format "HH:MM:SS".
        HH represents the hour which is between 0 and 24; MM represents
        the minute which is between 0 and 59; and, SS represents the
        second which is between 0 and 59.  Note that "24:00:00" is
        essentially the same time as "00:00:00".  However, "00:00:00"
        represents the start of a new day and
        "24:00:00" represents the end of an old day.

 Return        A reference to the time object is returned.

 Example:

        char  ti[9];
           ldbftime_now( ti ) ;
           ti[8] = char(0) ;  { Add the null for "printf" }
           printf( " The current time is \n", ti )

SLang:  char *ldbfTimeNow()

---------------------------------------------------------------
ldbftoday()

 Usage:  void ldbftoday(char *date)

 Description:  The date is initialized, to the current day, from the
  system clock.

 Example

      char day[9];
      { "day" is initialized to "today" }
      ldbftoday( date )


SLang: char *ldbfToday()

---------------------------------------------------------------
ldbfyear()

 Usage:  int  ldbfyear(char *date)

 Description:  The century/year of the date is returned as an integer.

  If the date is blank, 0 is returned.

 Example

      char day[9];
      int yr;
      memcpy( day, "19900101", sizeof(day) ) ; { Jan 01, 1990 }
      { yr will be "(int) 1990". }
      yr =  ldbfyear( date )



--------------------------------------------------------------------
LDBF Settings and Variables
--------------------------------------------------------------------


--------------------------------------------------------------------
int ldbf_errno;
int last_errno;

 Description:   This is the current error code.  Zero means that there
  is no error and any value less than zero represents an error.
  Occasionaly, a function may set this code value to a positive
  value to indicate a non-error condition.

   Any returned error code will correspond to one of the
  error constants in header file "ldbf.h".  These constants
  are documented in the "Error Messages and Functions" appendix.

  last_errno contains system's error code from the errno variable.

SLang:  integer ldbferrno,integer last_errno;


--------------------------------------------------------------------
ldbfParamStr    - SLang only
 
   Usage:  char *ldbfParamStr;

   Description: This variable contains parameters that was passed
      via ldbfCall command.
--------------------------------------------------------------------
 These variables are may be used in CGI script only.They contain values of
  standard CGI environment variables.
    user_agent              -  Info about the user browser
    accept_type             -  Types accepted by user browser
    auth_type               -  Type of authentication
    query_string            -  Additional query parameters
    path_translated         -  Path of file
    server_protocol         -  Protocol of the server
    server_port             -  TCP Port
    request_method          -  Method,POST,GET,...
    remote_host             -  Name of the remote host
    remote_addr             -  Address of the remote host
    remote_user             -  User name
    script_name             -  Name of the CGI script
    gateway_interface       -  Interface...
    server_software         -  Server's software
    content_length          -  Length of data

--------------------------------------------------------------------
LDBF API (C and SLang)
--------------------------------------------------------------------


---------------------------------------------------------------
ldbfUserName()

   Usage:       char ldbfUserName(char *newname);

   Description:By default, in the UNIX systems user name is equal to 
     your login name.You may change user name by specifing newname.
     If newname is null ldbfUserName returns previous user name.

 SLang: void ldbfUserName(user).
        You may set username only.Nothing is returns.

---------------------------------------------------------------
ldbfPassword()

  Usage:char *ldbfPassword(char *newpasswd,int crypt_pwd);

  Description: Return or specify user password, by default no
    password used.It is primary needed for Windows clients and for more
    securety in the access.
    By default server doesn't perform password checking until
    client request for it.
    When you calling ldbfPassword function you set type of password 
     checking that server'll do:
      - if you set pure ascii password string, server'll crypt it and
        compare with crypted password of existed user.
      - if you set crypted password string, server compared two
        crypted passwords only.
    In order to server may perform password validation it has to
    be run with root privilages(as root or setuid on root).
    If crypt_pwd no-zero, new password is already crypted otherwise 
    password is pure ascii string.
    If crypt_pwd == -1, password validation will be set to default.
    If newpasswd is null ldbfPassword returns previous password.

 SLang: void ldbfPassword(pass).
        You may set password only.Nothing is returns.

---------------------------------------------------------------
ldbfPort()

  Usage: int ldbfPort(int newport);

  Description:There is TCP port which required for connection to server.
    But if you want specify other port or planning load more than one server
    you may specify any TCP port as on server side as on client.

 SLang: void ldbfPort(port). 
        You may set port only, it returns nothing.

---------------------------------------------------------------
ldbfEventHandler()

   Usage:  void *ldbfEventHandler(void (*newevent)());

   Description:This function assigns handler that will process
     all events.Server may send to client some events or
     client may send to another client event.
     In order to handle with events you must specify
     function - event handler.This handler will be called by ldbfCheckEvent.
     Format of event handler should be:

        void user_func(char *event_name,char *data);

       where 
          event_name is name of event 
          data is any data depending on event.

   For example:
         void event_handler(char *name,char *data)
         {
            if(!strcmp(data,"alarm")) {
              fprintf(stdout,"It is time to go home,cir!!!!!");
            }
         }


---------------------------------------------------------------
ldbfCheckEvent()


  Usage:  void ldbfCheckEvent(int sock);

  Description: This function check whether event is received from
       anywhere or not.If so event handler routine will be called.
       You should call this function as frequently as 
       possible in order to handle events that may be sent by server.
       sock is server connection.If you connect more than one server,
       call this function for each connection.


---------------------------------------------------------------
ldbfShutdown();

  Usage : void ldbfShutdown(int sock);

  Description: Tell the server that connection is closed.



---------------------------------------------------------------
ldbfConnect()

  Usage : int ldbfConnect(char *host);

  Description: Make connection to a LDBF server.Host is name of host where
     server running.If host == NULL, localhost is used via UNIX domain socket.
     If connection cannot be established -1 will be returned.
     Otherwise it returns server connection number(or socket).
     Many ldbf-functions required this connection number in order to
     send request to server.
     if you set environment variable LDBFPORT to numeric
     value it'll be used as port number to connect to server.
     Also variable LDBFHOST may be set to host where ldbfd server 
     is running.

 SLang: Returns 1 if connected, otherwise 0.

---------------------------------------------------------------
ldbfCreateAliasDef();

  Usage:  void ldbfCreateAliasDef(int sock,char *alias,char *pathname);

  Descritption: Creates new alias definition.
    You have create permissions in order to perform this operation.
    After alias was created,you can create table itself.

SLang:  void ldbfCreateAliasDef(char *alias,char *pathname);


---------------------------------------------------------------
ldbfExchange()

   Usage : int ldbfExchange(int sock,char *alias,char *path);

   Description: Exchange database file for specified alias.
       You must have rights to execute this command.
       See ldbf.conf for exchange_allow parameter.
       Server closes existing database file and reopen
       specified file under existing alias.All users having this file opened
       continues work with another database file.
       If anyone does transaction on this database it'll be aborted.
       Use this command with CAUTION.Alias definition in ldbf.conf file will be 
       replace with new value.


SLang:  void ldbfExchange(char *alias,char *path)

---------------------------------------------------------------
ldbfCloseall()

  Usage:void  ldbfCloseall(int sock);

  Description: Close all opened databases opened on 
      server with connection sock.
      Memory will be freed automaticly.


SLang: void ldbfCloseAll()

---------------------------------------------------------------
ldbfBegin()

  Usage : int  ldbfBegin(int sock);

  Description:This function starts transaction.
         It returns :
               >= 0 transaction activation successful
               -1 transaction activation failed or disabled(see ldbfErrno)
         When you want to perform a series of operations that you consider
         a unit, you issue ldbfBegin command.This command causes all 
         subsequently altered records to be locked against modification
         by others(although others can view them).When you satisfied that
         the series of operations has produced the desired results, you 
         terminate the transaction with ldbfCommit command.If you are
         not satisfied with results, you can terminate the transaction
         with ldbfAbort command.ldbfAbort restore the database to
         the state that existed when you issue ldbfBegin command - with
         an important exception.All data definition commands are treated
         as singelton transaction: that is, if they were executed
         successfuly, they are commited and are not rolled back.
         Data definition command are those that creates databases, drops it,
         exchanges databases.It is recomended that all data definition
         command not appear witin transaction.
         During transaction processing all modification will be seen
         only by you.When ldbfCommit excecution succeed all users will
         discover your modifications.
         Nested transaction are allowed i.e. you may made transaction in 
         transaction.ldbfCommit flushes all modification but ldbfAbort
         applies to transactions from last ldbfBegin.

    Example:
            ldbfBegin(sock);
              ldbfAppend(...);
              ldbfAppend(...);  
              ldbfBegin(sock);     /* sub-transaction */
                ldbfGo(...);
                ldbfUpdate(...);
                if(.......)      /* condition not true, throw out last update */
                    ldbfAbort(sock);
              ldbfCommit(sock);  /* commit all updates 
                                    update won't be applied */



SLang:  void ldbfBegin()


---------------------------------------------------------------
ldbfAbort()

  Usage: void  ldbfAbort(int sock);
  
  Description: Use ldbfAbort to undo all modifications since the last 
     ldbfBegin command.

  See also : ldbfBegin

SLang: void ldbfAbort()

---------------------------------------------------------------
ldbfCommit()

  Usage: int  ldbfCommit(int sock);

  Description: marks the end of transaction by authorizing all changes
    to the databases since first ldbfBegin command.ldbfCommit releases
    all records locks.
    Returns -1 on error.

  See also: ldbfBegin


SLang: void ldbfCommit()

---------------------------------------------------------------
ldbfSetOnOff()

  Usage: void  ldbfSetOnOff(int sock,int flag,int onoff);

  Description: Sets various system settings.
     See ldbf.h for setting that may be applied for you LDBF envirinment.


 Slang: void ldbfSetOnOff(integer flag,integer onoff);

---------------------------------------------------------------
ldbfSetFilter()

  Usage: void  ldbfSetFilter(DB *data,char *filter);

  Description: Sets filter on specified table.filter is any valid xBase
    expression.Server will return record when this expression true only and
    skip others records.

  Example:       DB *data = ldbfOpen(sock,"cust",0);
                 /* get customers with numbers between 30 and 40 */
                 ldbfSetFilter(data,"no > 30 .and. no < 40");
                 ldbfTop(data);
                 while(!ldbf_errno) {
                   printf("%s %d\n",ldbfValue("cust","name"),
                             ldbfLongValue("cust","no"));
                   ldbfSkip(data,1);
                 }


 Slang: void ldbfSetFilter(char *table,char *filter);

---------------------------------------------------------------
ldbfTableByNo()

      Syntax:  DB *ldbfTableByNo(int no);

      Description:Returns pointer on structure DB that is opened database
         with handle no.
     
---------------------------------------------------------------
ldbfTableByName()

      Syntax:  DB *ldbfTableByName(char *name);

      Description:Returns pointer on structure DB that is opened database
        with alias name.

---------------------------------------------------------------
ldbfCall()
 
  Usage: int  ldbfCall(int sock,char *proc,char *param,void (*func)());
    
  Description: Call procedure stored in the server.
       Stored procedure permits you programm some frequently
       algorithms once and store them on server side.
       Then you grant right to call this procedure for users that
       required those algorithms.This make programming of client
       part more easy.
       You must privide ldbfCall with connection number ,
       procedure name and any parameter string that required stored
       procedure.You may also provide a finction that will process
       result from stored procedure.
       Format of this function should be:
                 void func(long result_count);
                 where 
                    result_count is number of result records returned.
        Use ldbfFetchResult in this function to obtain result records.
	ldbfCall returns -1 on error.

  See also: ldbfTableByNo

SLang:  void ldbfCall(char *proc,char *param)
   Result you may obtain by the ldbfFetchResult function.  

---------------------------------------------------------------
ldbfFetchResult()

  Usage:  RESULT *ldbfFetchResult();
  
  Description:Returns next result record from result set returned by
   function ldbfCall.Returns pointer on RESULT structure or NULL if 
   no more records.
     Fields of structure may has such values:
                 'db' contains alias or empty if result just data
                 'recno' contains record number in case of table record
                 'len' always contains length of data
                 'data' pointers on record contents or any data

     Address of returned structure is valid till next call of ldbfCall.

   Example:
        void cust_fetch(long count)
        {
          RESULT *res;
          DB *tbl;
          if(!count) return;
          while((res = ldbfFetchResult())) {
            if(!strlen(res->alias)) {
               printf("This is just data:%s\n",res->data);
             } else {
               tbl = ldbfTableByName(res->alias);
               printf("This is record #%ld of table %s\n",res->recno,
                 tbl ? tbl->alias : "not opened");
               printf("Record contents:%s\n",res->data);

               /* makes this record current, it may be useful */
               if(tbl) {
                 strcpy(tbl->record,res->data);
                 tbl->recno = res->recno;
               }
            }
          }
        }

        ldbfCall("seek_cust","100",cust_fetch);

  SLang: integer ldbfFetchResult()
    Return 0 if result vaid or -1 if no more result records.
    Result will be put into following variables:
         ldbfResultTable - name of table if result is record or
                           empty string if result is just data
         ldbfResultRecno - record number if ldbfResultTable not empty
         ldbfResultLen   - length of data in the ldbfResultData
         ldbfResultData  - contains data or record contents

   Each next call of ldbfFetchResult overwrites these variables.

---------------------------------------------------------------
ldbfRegisterEvent()

  Usage:  void  ldbfRegisterEvent(int sock,char *event_name);

  Description: Register itself for recieving this event.
     You cannot recieve event until you register for receiving it.
     There is some system event that will be sent you in any case.
     It is:
        "shutdown" -  server is shutdown or internal error, you must
                       exit because execution cannot continue.
        "timeout"  -  client wait reply from server during some defined
                      time and if this time is out this event raised. 
                      This is for information purpose only, you may not
                      check for this event.

  See also: ldbfRaiseEvent

SLang: void ldbfRegisterEvent(char *event)

---------------------------------------------------------------
ldbfRaiseEvent()

  Usage: void  ldbfRaiseEvent(int sock,char *event_name,char *data);

  Description: When you want to send notification to some users
     you may do it with ldbfRaiseEvent.Other side must register
     itself for recieving this event and when condition become true you
     will send event to users.

  Example:
      char time[10];
      ldbfTimeNow(time);   /* time in form hh:mm:ss */
      if(time[0] == '2' && time[1] == '2')  /*  22:00 already */
        ldbfRaiseEvent(sock,"alarm","Let's go home, buddy!!!");


SLang: void ldbfRaiseEvent(char *event,char *data)

--------------------------------------------------------------------
Database Functions


---------------------------------------------------------------
ldbfAppend()

 Usage:   int ldbfAppend(DB *data)

 Description:  ldbfAppend() append a record to the end of a data file.
   After append current record is appended record except case when
   you append in transaction.Valid record number for this appended record
   will be known after commit.

  ldbfAppend() maintains all open index files by adding keys
  to respective tags.
  In addition, ldbfAppend() ensures that any existing memo
  fields are handled correctly.

 Returns  Value      Meaning

          0          Success

          < 0        Error

 Example

      int sock;
      DB *data;
      FIELD *field;


          sock = ldbfConnect(servname);

          data = ldbfOpen( sock, "TESTER" ) ;

          { Append a copy of record two. (Assume record two exists.) }
          ldbfGo(data,2) ;
          ldbfAppend(data) ;

          { Append a copy of record 2 including existing memo entries. }
          ldbfGgo(data,2) ;
          { The true parameter means use memo entries. }
          ldbfAppend(data) ;

          { Set the record buffer to blank, change a fields value, and }
          { append the resulting record. }
          ldbfBlank(data) ;
          field =  ldbfField( data, "FIELD_NAME" ) ;
          ldbfAssign( field, "New Field Value" ) ;
          ldbfAppend(data) ;

          ldbfClose(data) ;
          ldbfShutdown(sock);


SLang: void ldbfAppend(string alias);
       void ldbfRawAppend(string alias,string record_data); 
---------------------------------------------------------------
ldbfBlank()

 Usage:   void ldbfBlank(DB *data)

 Description:  The record buffer for the data file is set to blank.

 See Also   ldbfAppend()

SLang:  void ldbfBlank(char *alias)

---------------------------------------------------------------
ldbfBottom()

 Usage:   int ldbfBottom(DB *data)

 Description:  The bottom record of the data file is read into the
  record buffer and the current record number is updated.
  The selected tag is used to determine
  which is the bottom record.  If no tag is selected,
  the last record of the data file is read.

 Returns  Value     Meaning

          0         Success

          < 0       Error

 See Also   ldbfSkip()

SLang: void ldbfBottom(char *alias,char *tag)

---------------------------------------------------------------
ldbfCreate()

 Usage:   DB *ldbfCreate(int sock,char *name,
                             FIELDINFO *field_info,
                             TAGINFO *tag_info)

 Description:  ldbfCreate() creates a data file, possibly a
  "production" index file, and possibly a memo file.  Note that
  "production" index files are automatically opened, with the
  data file, when ldbfOpen() is called.  A memo file is created
  if the data file contains a memo file.In order to create new alias,this
  alias must exists in ldbf.conf before create.You may use ldbfcreatealiasDef()
  function in order to register alias in ldbf.conf file.

 Parameters Name        Use

            name        The alias name for the database.

            field_info  A pointer to an array of field information.
                        The last entry is null to signal that there
                        are no additional entries.

            tag_info    An array of tag information.
                        The last entry in the array is 
                        null to signal that there
                        are no additional entries.  If this pointer
                        is nil, no index file is created.  

 Returns  Value      Meaning

          <>0      Success. A pointer to the corresponding
                     DB structure is returned.

          0        The data, index, or memo file was not
                     successfully created.  Inspect
                     "ldbf_errno" for more detailed
                     information.  If it is negative, an error
                     occurred.

 Locking     Nothing is locked upon completion.

 Example
      int sock;
      DB *data;
      FIELDINFO dd[3];  { Data Dictionary  }
      TAGINFO t[2];     { Tag Discriptions }

      memset(&dd,0,sizeof(dd));
      memset(&t,0,sizeof(t));
      strcpy(dd[1].name,"Name");
      dd[1].type = 'C';
      dd[1].len = 10;
      dd[1].dec = 0;     { character fields must have 0 decimals }

      strcpy(dd[2].name,"Wage");
      dd[2].type = "N";
      dd[2].len = 7;
      dd[2].dec = 2;
  
      strcpy(t[1].name,"TagThing");
      strcpy(t[1].expression,"Name");
      t[1].filter = 0;
      t[1].unique = 0;
      t[1].descending = 0;

      sock = ldbfConnect(servname);
      data = ldbfCreate( sock, "NEW_DATA", &field_info, &tag_info ) ;


---------------------------------------------------------------
ldbfDelete()

 Usage:   int ldbfDelete(data:PD4DATA)

 Description:  The current record buffer is marked for deletion.

  In addition, the record changed flag is set so that
  the mark will be flushed to disk at an appropriate time.

 Locking  None.

 See Also   ldbfRecall() 

 Example

        {Delete every second record in the data file. }
        int sock,ok;
        DB *file;
     Begin

        sock = ldbfConnect(servname);
        file =  ldnfOpen( sock, "DATA" ) ;

        ok = ldbfTop(file);
        while (ok > 0) {
             ok = ldbfDelete( file ) ;  { Mark the record for deletion }
             ok = ldbfSkip(file,2);
        }

        ldbfCloseall( sock );
        ldbfShutdown(sock);

SLang: void ldbfDelete(char *alias)

---------------------------------------------------------------
ldbfDeleted()

 Usage:   int ldbfDeleted(DB *data)

 Description:  This function returns whether the current record
  is marked for deletion.
  If there is no current record, the result is undefined.

 Returns  Value      Meaning

          0          The record is NOT marked for deletion.

          <> 0       A true (non-zero) return indicates that the
                     record is marked for deletion.

 Locking  None.

SLang: int ldbfDeleted(char *alias)


---------------------------------------------------------------
ldbfSetOnOff()

  Usage: ldbfSetOnOff(int sock,int param,int onoff)

  Description:Set various parameters in your session.
     Currently SET_DELETED implemented only.
 
  Example:
        ldbfSetOnOff(sock,SET_DELETED,1);

---------------------------------------------------------------
ldbfField()

 Usage:   Field *ldbfField(DB *data,char *field_name)

 Description:  A field name is looked up in the data file and a pointer,
  which can be used with field functions, is returned.

 Parameters Parameter "field_name" is a field name of the data file.

 Returns  If the return value is zero, this
  means that the field was not located.  
 Warning  The field pointer returned becomes obselete once the data file
  is closed.

 See Also  ldbfField_number()  ldbfField_j()



---------------------------------------------------------------
ldbfField_j()

 Usage:   FIELD *ldbfField_j(DB *data,int j_field)

 Description:  A pointer to the j_field"th data file field is returned.

  "j_field" must be between one and the number of fields.
  (ie. 1 <= j_field <= data->n_fields )

 Warning  This field pointer becomes obsolete once the data file
  is closed.

 See Also  ldbfField_number()  ldbfField()




---------------------------------------------------------------
ldbfField_number()

 Usage:   int ldbfField_number(DB *data,char *name)

 Description:  A search is made for the specified field name.

 Returns  Value      Meaning

          -1         The field name was not found.

          > 0        The field number of the located field.
                     The field numbers start from one.

 See Also   ldbfField()  ldbfField_j()

 Example


        DB *data;
        FIELD *field;
        int j, i;

        data =  ldbfOpen( sock, "TEST.DBF" ) ;

        for(j = 1;data->n_fields ;j++) {
            field = ldbfField_j( data, j) ;
            i =  ldbfField_number( data, ldbfName(field) ) ;
        }



---------------------------------------------------------------
ldbfGo()

 Usage:   int ldbfGo(DB *data,long record_number)

 Description:  ldbfGo() reads the specified record into the record
  buffer.  In addition, the record number becomes the current
  record number. Access the contents of the record using
  the field functions.

 Returns  Value        Meaning

          0            Success

          < 0          Error


SLang: void ldbfGo(char *alias,long recno)


---------------------------------------------------------------
ldbfLock()

 Usage:   int ldbfLock(DB *data,long record_num)
 
 Description:  A record is locked if it is not already locked.
  Specifically, if the entire file is already locked or
  if the record is
  already locked, ldbfLock() recognizes this and does nothing.

  Before performing the lock, other locks may be
  automatically removed to avoid deadlock.  Any other
  record locks on the data file are removed, any lock
  on the append bytes is removed, and any locked index
  files or tags are unlocked.

 Parameters Name   Use

  record_num  The record to be locked.

 Returns  Value        Meaning

          0            Success

          < 0         Error or The record is locked by another user.


 Example


        DB *data;

        data =  ldbfOpen( sock, "DATA" ) ;

        if(!ldbfLock( data, 5 ))
           printf( " Record 5 is now locked.\n" )  else
           printf(" Record 5 is locked by another\n");



---------------------------------------------------------------
ldbfFlock()

 Usage:   int ldbfFlock(DB *data)

 Description:  The entire data file is locked if it is not
  already locked.  Before the file is locked, any
  locks on individual record locks, append bytes, or
  tags are removed.

 Returns  Value      Meaning

          0          Success

          < 0        Error or The file is already locked.

 See Also  ldbfLock() 


---------------------------------------------------------------
ldbfOpen()

 Usage:   DB *ldbfOpen(int sock,char *name,int mode)

 Description:  ldbfOpen() opens a data file.  In addition, any
  corresponding memo file is opened.  Finally, 
  any "production index file"
  corresponding to the data file is opened.

  Note that a production
  index file is an index file created, at the same time as
  the data file, using ldbfCreate().
  When a production index file is automatically opened, no
  tag is initially selected.

 Parameters Name       Use

            sock      This is a connection number of server returned by 
                      ldbfConnect function.

            name       This is the name of the data file.  If
                       no file name extension is present, extension
                       ".DBF" is used.
            mode       if 0 database opened in normal mode
 			O_EXCL - in exclusive mode
			O_TTS  - flush will be make after each update 

 Returns  Value    Meaning

          0        The data file was not opened.  Use
                   "ldbf_errno" to help determine
                   the cause of the problem.  The problem
                   could be with either the data, index or the
                   memo file.

          Other    A pointer to a DB structure
                   corresponding to the opened data file.

 Locking  None

 See Also  ldbfClose()  ldbfCloseall()

SLang:  int ldbfOpen(char *alias)


---------------------------------------------------------------
ldbfPosition()

 Usage:   int ldbfPosition(DB *data)

 Description:  This is the inverse function of
  ldbfPosition_set().  It returns the
  current position as a int percentage.  For example,
  if the current position
  is half way down the data file, "50" is returned.

  Similar to ldbfPosition_set(int), the currently
  selected tag specifies the ordering.  If no tag is selected,
  record number ordering is used.

  A return of a negative number indicates that there
  was a problem determining the position.  This could
  be an error return or it could indicate that a tag
  was already locked by another user.
  Note that "ldbf_errno" can be
  called to determine if the return is an error.

  The purpose of ldbfPosition() and ldbfPosition_set()
  is to allow the use of scroll bars when developing
  edit and browse functions.

 See Also  ldbfPosition_set()


---------------------------------------------------------------
ldbfPosition_set()

 Usage:   int ldbfPosition_set(DB *data,int per)

 Description:  ldbfPosition_set() goes to a record
  in the data file as calculated from the "double"
  parameter.  This parameter, "per", represents a percentage
  and should be between "0" and "100".  It specifies
  how far down the data file to go.  For example, the call
  "ldbfPosition(0)" would position to the first
  record in the data file; similarly, "ldbfPosition(50)
  would position half way down the data file.  If "per" is
  greater than "100", the data file is positioned to the
  end of the file.

  This function is similar to "top" and "bottom" in that the
  selected tag specifies the ordering.  If there is no
  selected tag, record number ordering is used.

 Returns  Value       Meaning

          0           Success

          < 0         Error



---------------------------------------------------------------
ldbfRecall()

 Usage:   int ldbfRecall(DB *data,long rec)

 Description:  If the specified record is marked for deletion, the mark is
  removed.

SLang:  void ldbfRecall(char *alias)

---------------------------------------------------------------
ldbfRecno()

 Usage:   long  ldbfRecno(DB *data)

 Description:  Returns number of current record.

 SLang: integer ldbfRecno(string db)

---------------------------------------------------------------
ldbfReccount()

 Usage:   long  ldbfReccount(DB *data)

 Description:  The number of records in the data file is returned.  This
  value is determined from the size of the file.

 Returns  Value      Meaning

          >= 0       The number of records in the data file.
          < 0        Error

SLang:  long ldbfReccount(char *alias)

---------------------------------------------------------------
ldbfSetTag()

 Usage:   void ldbfSetTag(DB *data,char *tagname)

 Description:  ldbfSetTag() make specified tag as default.
               ldbfSeek will use this tag.

---------------------------------------------------------------
ldbfSeek()

 Usage:   int ldbfSeek(DB *data,char *ptr)

 Description:  ldbfSeek() searches using the default tag.

  Once the search value is located in the tag, the
  corresponding data file record is read.

 Parameter "ptr" points to a character array containing
  the value to be searched for.

  If the tag is of type Date, the date search value
  should be formatted "CCYYMMDD" (Century, Year, Month, Day).

  If the tag is of type Character, the search value may
  have fewer characters the tag"s key length provided that
  the search value is null {char(0)} terminated.  In this case, a
  search is done for the first key which matches the
  supplied characters.

  If the tag is of type Numeric, the character value
  should represent a number.  Ex:  d4seek( data, "33.7" ) ;

 Returns  Value      Meaning

          0          The search value was found.

          -1         Error
Example

     DB *people;
     FIELD *age_field;
     long julian_day;
     int rc;

     { Assume "people" has a production index file with
        tags NAME_TAG, AGE_TAG, and BIRTH_TAG. }
     people =  ldbfOpen( sock, "people", 0 ) ;

     { Assume NAME_TAG has a Character key expression. }
     strcpy(people->tag, "NAME_TAG" ) ;

     if  (ldbfSeek( people, "FRED " ) == 0 )
        printf( " FRED is in record %d\n", people->recno ) ;

     { Assume AGE_TAG has a Numeric key expression. }
     strcpy( people->tag, "AGE_TAG" ) ;

     age_field = ldbfField( people, "AGE_FIELD" ) ;

     rc =  ldbfSeek( people, "0" ) ;
     if  (rc == 0)
        printf( " The youngest age is: %d", ldbfDouble(age_field)) ;

     { Assume BIRTH_TAG has a Date key expression. }
     strcpy( people->tag, "BIRTH_TAG" ) ;
     d4seek( people, "19600415" ) ;


SLang:  int ldbfSeek(char *alias,char *tag,char *data)
           After search current record position changed
           corresponding of seek result.

        int ldbfFound(char *alias,char *tag,char *data)
           This function does no change record posotion, 
           only checking for presence of data.

 See also: ldbfSetTag

---------------------------------------------------------------
ldbfSkip()

 Usage:   int ldbfSkip(DB *data,long num_records)

 Description:  This function skips "num_records" from the current record
  number.  The selected tag is used.  If no tag
  is selected, record number ordering is used.

  The new record is read into the
  record buffer and becomes the current record.

 Returns  Value      Meaning

          0          Success

          < 0        Error  


     ldbf_errno may contain  :

          -104      Skipped to top record of the file.

          -103      Skipped to the end of the file.

          -105      There was no entry in the selected tag
                     for the current record.

          -150      Either a needed data file record or the tag
                     was locked.


 Example


     { Find the last record in the file whose NAME field contains "John". }
     DB *name_list;
     FIELD *name;
     int ok;

     name_list = ldbfOpen( sock, "NAMES" ,0) ;
     name = ldbfField( name_list, "NAME" ) ;

     ok = ldbfBottom(name_list);
     while (!ok) { 
         if(strncmp(ldbfPtr(name), "John", 4) == 0) {
             printf( " John is in record number: %ld\n",name_list->recno ) ;
             ldbfShutdown(sock);
             exit(0);
         }
         ldbfSkip(name_list,-1);
      }
     printf( " John not Located\n" ) ;


SLang:  void ldbfSkip(char *alias,char *tag,long records)
            In order to use tag specify it as second parameter
            otherwise set tag to blank

---------------------------------------------------------------
ldbfTop()

 Usage:   int ldbfTop(DB *data)

 Description:  The top record of the data file is read into the data file
  record buffer and the current record number is updated.
  The selected tag is used to determine
  which is the top record.  If no tag is selected,
  the first record of the data file is read.

 Returns  Value      Meaning

          0          Success
          < 0        Error or 
                        if ldbf_errno = -103
                               End of File (Empty tag or data file.)

 See Also  ldbfDelete()


SLang: void ldbfTop(char *alias,char *tag)

---------------------------------------------------------------
ldbfFunlock()

 Usage:  void  ldbfFunlock(DB *data)

 Description:  ldbfFunlock() removes all locks on the data file.


 See Also  ldbfUnlock()


---------------------------------------------------------------
ldbfUnlock()

 Usage:  void  ldbfUnlock(DB *data,long rec)

 Description:  ldbfUnlock() removes locks from the specified record
                on the data file.


 See Also  ldbfFunlock()



---------------------------------------------------------------
ldbfZap()

 Usage:   void ldbfZap(DB *data)

 Description:  ldbfZap() removes all records from the
  data file.  

  After ldbfZap() completes, the record buffer is blank
  and the record number is "long(-1)".
  Explicitly call a LDBF function, such as ldbfTop(),
  to position to a desired record.

 Hint  ldbfZap() does not change the memo file. Consequently,
  memo entries referenced by removed records will
  be wasted disk space.

 Warning  Be careful when using this function as it can immediately
  remove large numbers of records.  Database must be opened in 
  exclusive mode.



---------------------------------------------------------------
ldbfDrop()

  Usage: int ldbfDrop(int sock,char *db);

  Description: Tell the server which database we want to remove.
        You must have rights to create or delete databases
        in order to use this function.See create_allow parameter in
        ldbf.conf file.
        db is alias name not database path.
        it returns 0 on success or -1 on error.

SLang: void ldbfDrop(char *alias)

---------------------------------------------------------------
ldbfAliasList()

  Usage:  char *ldbfAliasList(int sock);

  Description: Get list of all databases that may be opened.
      Function returns pointer on string that contain list of all aliases
      separated by ",".
      


---------------------------------------------------------------
ldbfTaginfo()

  Usage: TAGINFO *ldbfTaginfo(DB* data);

  Description: Get tag info of database.You can obtain this information
     without calling this function.Tag information is kept in DB structure.
    
  Example:
      DB *data;
      int i;
      TAGINFO *taginfo;
          . . .
      taginfo = data->tags;      
      for(i = 0;taginfo[i].name[0] != '\0';i++)
        printf("%s|%s|%s|%d%d\n",taginfo[i].name,taginfo[i].expression,
                taginfo[i].filter,taginfo[i].unique,tagonfo[i].descending);



---------------------------------------------------------------
ldbfClose()

  Usage:  void ldbfClose(DB* data);
 
  Description: Close opened database.
        Memory alocated with ldbfOpen call will be freed.
 

SLang:  void ldbfClose(char *alias)

---------------------------------------------------------------
ldbfUpdate()

  Usage: int ldbfUpdate(DB* data);
  
    Description: Updates current record in the database.
       If you modified any field of current record you must
       issue ldbfUpdate in order to write its changes.

 See also: ldbfAppend

SLang:  void ldbfUpdate(string alias)
        void ldbfRawUpdate(string alias,string record_data)

---------------------------------------------------------------
ldbfFlush()

  Usage: void ldbfFlush(DB* data);

  Descritption:This function says to server to flush database on disk.
    It ensures all updates will be written to disk.
    You may specify flush_count=n parameter in the ldbf.conf in order to server
    flushes database every n'th updates.



---------------------------------------------------------------
ldbfInsert()

  Usage:DB *ldbfInsert(long sock,char *data,char *field_list,char *values_list);

  Description: Insert record into database.This command equal to ldbfAppend
      but does not require opened database and defined fields.
      ldbfInsert useful when you just add record to database and do 
      not intend to apply to this database later.
      If field value containes comma ',' then all field value must be commented 
      by double quotas.
      Database will be opened and ldbfInsert return pointer on structure DB.
 
  See also: ldbfModify,ldbfCreate,ldbfAppend

  Example:
      DB *data;
      FIELD *name; 
      data = ldbfInsert(sock,"data","name,address,zip","John,New York,12345");
      if(data) {     /* insert sucessful, data opened , test it */
        name = ldbfField(data,"NAME");
        printf("%s\n",ldbfStr(name));
      }
      /* comment first field because it containes comma
      data = ldbfInsert(sock,"data","name,address,zip","\"Adam Cock,Jr\",New York,12345");

SLang:   void ldbfInsert(char *data,char *field_list,char *values_list);


---------------------------------------------------------------
ldbfModify()

  Usage: DB *ldbfModify(long sock,char *data,char *field_list,char *values_list);

  Descrititon: Updates current record.This command equal to ldbfUpdate
      but does not require opened database and defined fields.
      If field value containes comma ',' then all field value must be commented 
      by double quotas.
      Database will be opened and ldbfModify return pointer on structure DB.

  See also: ldbfInsert,ldbfUpdate

  Example:
      
      ldbfModify(sock,"data","name,address,zip","John,New York,12345");

SLang:   void ldbfModify(char *data,char *field_list,char *values_list);


---------------------------------------------------------------
ldbfCreate()

  Usage: DB *ldbfCreateDBF(long sock,char *data,char *field_list,char *tag_list);

  Descritption: Creates new database.This command equal to ldbfCreate
      but does not require field and tag arrays.
      Database will be opened and ldbfCreate return pointer on structure DB.

      Format:
      field list = field_name(type[,len[,dec]]);field_name(type[,len[,dec]])

      tag list = tag_name(expression[,filter[,unique[,descending]]]);

  See also:ldbfCreate
  
  Example:
        data = ldbfCreateDBF(sock,"data","name(C,25);address(C,50);zip(N,10)", 
                 "name(name);address(address,,1);zip(zip,zip>0,1,1)");


SLang:   void  ldbfCreateDBF(char *data,char *field_list,char *tag_list);


--------------------------------------------------------------------
Error Functions
---------------------------------------------------------------

---------------------------------------------------------------
ldbfErrno()
       Returns value from ldbf_errno variable.For compatibility.



---------------------------------------------------------------
ldbfErr_Text()

  Usage: char *ldbfErr_Text(int error_code)

      Returns error message for specified error code.
  

--------------------------------------------------------------------
Field Functions
---------------------------------------------------------------


---------------------------------------------------------------
ldbfAssign_field()

  Usage:void ldbfAssign_field( FIELD *field_to, FIELD *field_from );

 Description:  The contents of the specified field_to are replaced
  by the contents of field_from. Checking for field types will be done 
  automaticly.

 Seel also: ldbfAssign,ldbfAssign_long



---------------------------------------------------------------
ldbfAssign()

 Usage:  void ldbfAssign(FIELD *field,char *ptr)

 Description:  The existing field"s value is replaced by the
  null {char(0)} terminated character array pointed to by "ptr".

  If the length of the new data is less that the field length,
  the extra space in the field is filled with blanks.
  Alternately, if "ptr" points to too much data, any extra
  data is ignored.

 Example

     FIELD *name,*birth;
     DB *data;

     data  =  ldbfOpen( sock, "PEOPLE" ) ;

     name = ldbfField( data, "NAME" ) ;
     birth = ldbfField( data, "BIRTH" ) ;
     ldbfGo( data, 1 ) ;

     { Blank the Character "NAME" field. }
     ldbfBlank( name ) ;

     { Set the Date field. }
     ldbfAssign( birth, "19601012" ) ;
     ldbfUpdate(data);

     ldbfGo( data, 2 ) ;
     ldbfAssign( name, "AL" ) ;
     ldbfUpdate(data);


---------------------------------------------------------------
ldbfAssign_char()

 Usage:  void ldbfAssign_char(FIELD *field,char chr)

 Description:  The contents of the specified field are replaced
  by the character "chr".  If the field width is
  greater than one, all of the extra characters are blanked.

 See Also   ldbfChar()

 Example

     DB *people;
     FIELD *is_male,*sex;
     long rec_no;

     people = ldbfOpen( sock, "PEOPLE" ) ;

     is_male = ldbfField( people, "IS_MALE" ) ;
     sex =  ldbfField( people, "SEX" ) ;

     { Update the new field "SEX" from the
        old field "IS_MALE". }

     for(rec_no = 1;rec_no < people->reccount;rec_no++) {
         ldbfGo( people, rec_no ) ;
         if ( ldbfChar(is_male) != 'T' ) then
            ldbfAssign_char( sex, "M" )
         else
            ldbfAssign_char( sex, "F" )
         ldbfUpdate(people);
     }



---------------------------------------------------------------
ldbfAssign_double()

Usage:  void f4assign_double(FIELD *field,double value)

 Description:  The contents of the specified field are replaced
  by parameter "value".  There is a right justified
  formatting.

  If the field is of type Numeric or Floating Point,
  then the number of decimals is used to help determine
  the formatting.  Otherwise, zero decimals are used.


---------------------------------------------------------------
ldbfAssign_long()

 Usage:  void ldbfAssign_long(FIELD *field,long value)

 Description:  The contents of the specified field are replaced
  by parameter "value".  There is a right justified
  formatting.

  If the field is of type Numeric or Floating Point,
  any decimals will be filled with zeros.

 Example


  void  add_record( DB *invoice_dbf )
  {
     FIELD *invoice_no;
     long new_invoice_no;

     invoice_no =  ldbfField( invoice_dbf, "INVOICE_NO" ) ;

     ldbfGo( invoice_dbf, ldbfReccount(invoice_dbf) ) ;
     new_invoice_no :=  ldbfLong(invoice_no) + 1 ;

     ldbfAssign_long( invoice_no, new_invoice_no ) ;
     ldbfAppend( invoice_dbf ) ;


---------------------------------------------------------------
ldbfChar()

 Usage:  char ldbfChar(FIELD *field)

 Description:  The first character of the field is returned as an integer.

 See Also  ldbfAssign_char()


---------------------------------------------------------------
ldbfDecimals()

 Usage:  int  ldbfDecimals(FIELD *field)

 Description:  The number of decimals in the field is returned.  Except
  for Numeric or Floating Point fields, this number is
  always zero.

 Example

  void  display_structure( DB *data )
     int j;
     FIELD *field;

     printf( " NAME        TYPE    WIDTH   DECIMALS\n" ) ;
     for(  j = 1;j <= data->n_fields;j++){
         field =  ldbfField_j( data, j ) ;
         printf("%s %c %d %d\n",
           ldbfName(field),
           (char)ldbfType(field),
           ldbfLen(field),
           ldbfDecimals(field) )
     }


---------------------------------------------------------------
ldbfDouble()

 Usage:  double ldbfDouble(FIELD *field)

 Description:  The value of the field is returned as a double.  This
  function assumes that the field contains a numeric value
  and converts that value into a double.

SLang: float ldbfDouble(char *alias,char *field_name)

---------------------------------------------------------------
ldbfLen()

 Usage:  int ldbfLen(FIELD *field)

 Description:  The length of the field is returned.


---------------------------------------------------------------
ldbfLong()

 Usage:  long ldbfLong(FIELD *field)

 Description:  The value of the field is returned as a long integer.
  However, the value returned depends on the type of the field.

  Specifically, if the field is of type Date, the date is
  returned as a julian day.  Alternately, ldbfLong() assumes
  the value of the field is a number.  Consequently,
  ldbfLong() also works for Character fields containing
  a numeric value.

  Any decimals are truncated.  If the value of the field
  overflows the maximum value which can be contained
  by a long integer, the result is undefined.


SLang: long ldbfLong(char *alias,char *field_name)

---------------------------------------------------------------
ldbfName()

 Usage:  char *ldbfName(FIELD *field)

 Description:  The name of the field is returned as a character
  pointer.

---------------------------------------------------------------
ldbfPtr()

 Usage:  char *ldbfPtr(FIELD *field)

 Description:  ldbfPtr() returns a pointer, to the place inside
  the record buffer, where the field information is located.

  In order to effectively use this
  function, it is necessary to know
  how the record buffer is formatted.  Refer to the
  "Field Functions" introduction.

 Warning If the corresponding database is closed and then reopened,
  the pointer must be reassigned.


---------------------------------------------------------------
ldbfStr()

 Usage:  char *ldbfStr(FIELD *field)

 Description:  The field"s contents are copied to an internal
  buffer and a pointer to the buffer is returned.  The buffer is
  terminated by a null character {char(0)}.

 WARNING Each time "ldbfStr" is called, the buffer is overlaid
  with data from the new field.  Consequently, if the fields
  value needs to be saved, it is necessary to copy the fields
  value to a memory area declared by the application.

   Incorrect Example:

      printf( "Field One %s Field Two %s",
               ldbfStr( ldbfField_j(data,1)),
               ldbfStr( ldbffField_j(data,2)) ) ;

  In the above example, "ldbfStr" is evaluated twice
  before "writeln" is called.  Since "ldbfStr" always returns
  the same pointer to the same internal buffer, either
  field one or field two will be printed out twice depending
  on the order the two parameters are evaluated. Refer
  to the correct example below.

 Returns A pointer to the field"s value is returned.  An error is
  indicated by a nil return.

 Hint  This function is useful when you need the field"s value
  ended by a null character.

 Example

  void  display_fields( FIELD *field1,FIELD *field2)
  {
     printf( " Field 1: ", ldbfStr( field1 ) ) ;
     printf( " Field 2: ", ldbfStr( field2 ) )
  }


SLang:  char *ldbfStr(char *alias,char *field_name)

---------------------------------------------------------------
ldbfType()

 Usage:  int ldbfType(FIELD *field)

 Description:  The type of the field, as defined in the data file,
  is returned.

 Returns       Value       Meaning

               "C"    Character Field
               "D"    Date Field
               "L"    Logical Field
               "M"    Memo Field
               "N"    Numeric or Floating Point Field

---------------------------------------------------------------
ldbfValue()

  Usage: char *ldbfValue( char *alias,char *field_name );

  Description: This function is equal to ldbfStr but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfStr

  Example: 
         data = ldbfOpen(sock,"data");
         printf("%s %s \n",ldbfValue("data","name"),ldbfValue("data","address"));


---------------------------------------------------------------
ldbfLongValue()

  Usage:  long ldbfLongValue( char *alias,char *field_name );

  Description:This function is equal to ldbfLong but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfLong

  Example: 
         data = ldbfOpen(sock,"data");
         printf("%ld\n",ldbfLongValue("data","zip"));


---------------------------------------------------------------
ldbfDoubleValue()

  Usage: double ldbfDoubleValue( char *alias,char *field_name );

  Description:This function is equal to ldbfDouble but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfDouble

  Example: 
         data = ldbfOpen(sock,"data");
         printf("%f\n",ldbfDoubleValue("data","money"));

---------------------------------------------------------------
ldbfMemoValue()

  Usage: char *ldbfMemoValue(DB *data,char *field_name,int *memo_len);

  Description:This function return pointer on contents of memo field.
    if you specify memo_len variable function'll put on it size
    of memo contents returned.

  See also: ldbfReplaceMemo

  Example: 
         int memo_len;
         data = ldbfOpen(sock,"data");
         printf("contents of memo:%s\n",ldbfMemoValue(data,"memo",&memo_len));
         printf("size of memo:%ld\n",memo_len);

---------------------------------------------------------------
ldbfReplaceMemo()

  Usage: int ldbfReplaceMemo(DB *data,char *field_name,char *buffer,int len);

  Description:This function updates contents of memo field.

  See also: ldbfMemoValue

  Example: 
         int memo_len;
         char buffer[20] = "memo buffer";
         ldbfReplaceMemo(data,"memo",buffer,strlen(buffer));

---------------------------------------------------------------
ldbfReplace()

  Usage: void ldbfReplace(char *alias,char *field_name,char *value);

  Description:This function is equal to ldbfAssign but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfAssign

  Example: 
         data = ldbfOpen(sock,"data");
         ldbfReplace("data","name","Scott Black");


SLang: void ldbfReplace(char *alias,char *field_name,char *data)

---------------------------------------------------------------
ldbfReplaceLong()

  Usage:  void ldbfReplaceLong(char *alias,char *field_name,long value);

  Description:This function is equal to ldbfAssign_long but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfAssign_long

  Example: 
         data = ldbfOpen(sock,"data");
         ldbfReplaceLong("data","zip",12345);


SLang: void ldbfReplace(char *alias,char *field_name,long data)

---------------------------------------------------------------
ldbfReplaceDouble()

  Usage : void ldbfReplaceDouble(char *alias,char *field_name,double value);

  Description:This function is equal to ldbfAssign_double but you are refer to
     database by alias and to field by its name.Database must be opened
     before you call this function.Do not mix it with ldbfInsert,ldbfModify.

  See also: ldbfAssign_double

  Example: 
         data = ldbfOpen(sock,"data");
         ldbfReplaceDouble("data","money",100.25);


SLang: void ldbfReplace(char *alias,char *field_name,double data)


---------------------------------------------------------------
trim()

  Usage: char *trim(char *s);

  Description: Remove leading and trailing trash characters from string.
    Returns pointer on same string.


---------------------------------------------------------------
wordcnt()
 
  Usage: int wordcnt(char *s,char *delim);
 
  Description:Returns number of words in s delimited with set of char in delim. 

  Example:
      char s[10] = "10,24.45";
      wordcnt(s,",.");       /* returns 3 */


---------------------------------------------------------------
wordpos()

  Usage: int wordpos(int n, char *s,char *delim);

  Description: Returns position of n'th word in the string s.
     Words are separated by set of chars specified in the delim.

  See also: wordcnt,getword


---------------------------------------------------------------
getword()

   Usage: char *getword(int n,char *s,char *delim,char *buf);

   Description: Return n'th word from s and puts it into buf.

   Example:
      char buf[10],s[10] = "10,12,25";
      int i,cnt = wordcnt(s,",");
      if(cnt > 0) 
        for(i = 1;i <= cnt;i++) 
          printf("%s\n",getword(i,s,",",buf);


---------------------------------------------------------------
ldbfatod()
ldbfatoi()
ldbfatol()

  Usage: double ldbfatod( char *str, int len_str );
         int ldbfatoi( char *str, int len_str );
         long ldbfatol( char *str, int len_str );

  Desciption: ldbfatod converts a string to a double.
              ldbfatoi converts a string to a integer.
              ldbfatol converts a string to a long.

---------------------------------------------------------------
ldbfdtoa()
  
   Usage: void ldbfdtoa( double doub_val, char *out_buffer, int len, int dec);
 
   Description: Formats a double to a string.


---------------------------------------------------------------
ldbfltoa()

   Usage:void ldbfltoa( long l_val, char *ptr, int num);
  
   Description: Converts a long to a string.Num is max length of buffer.
       Fill with '0's rather than blanks if 'num' is less than zero.


---------------------------------------------------------------
ldbflower()
ldbflowerKOI()
ldbflowerWIN()
 
   Usage: void ldbflower( char *str );

   Description: Make all chars in the string in lower case.

SLang:
 string ldbfLower(string s)
 string ldbfLowerKOI(string s)
 string ldbfLowerWIN(string s)

---------------------------------------------------------------
ldbfupper()
ldbfupperKOI()
ldbfupperWIN()

   Usage: void ldbfupper( char *str );

   Description: Make all chars in the string in upper case.

SLang:
 string ldbfUpper(sring s)
 string ldbfUpperKOI(string s)
 string ldbfUpperWIN(string s)

---------------------------------------------------------------
ldbfkoi2alt()
ldbfalt2koi()

    Syntax: void ldbfkoi2alt(char *s);
            void ldbfalt2koi(char *s);

    Description:ldbfkoi2alt converts string from the KOI8 codepage into
      the 866 codepage.ldbfalt2koi converts from the 866 coeepage into the 
      KOI8 one.

SLang:
  string ldbfalt2koi(string s);
  string ldbfkoi2alt(string s);
---------------------------------------------------------------
ldbfkoi2win()
ldbfwin2koi()

    Syntax: void ldbfkoi2win(char *s);
            void ldbfwin2koi(char *s);

    Description:ldbfkoi2win converts string from the KOI8 codepage into
      the Windows codepage.ldbfwin2koi converts from the Windows coeepage into 
      the KOI8 one.

SLang:
  string ldbfkoi2win(string s);
  string ldbfwin2koi(string s);
---------------------------------------------------------------
list_fisrt()

   Usage: void *list_first(ldbfList *lst);

   Description:Return first element of list.
 
   Example:
    typedef struct {
      link_list link;
      char name[30];
    } name_item;
    name_item *item;
    ldbfList list;
    memset(&list,0,sizeof(list));
    item = (name_item*)calloc(1,sizeof(name_item));
    strcpy(item->name,"Bill");
    list_add(&list,item);
    strcpy(item->name,"John");
    list_add(&list,item);
    /* print contents of list */
    for(item = (name_item*)list_first(&list);item;
             item = (name_item*)list_next(&list,item))
     printf("%s\n",item->name);


---------------------------------------------------------------
list_last()

   Usage: void * list_last(ldbfList *lst);

   Description:Returns last element of list.
   
    Example: see example above for detail;
       /* print contents of the list begining from end */
      for(item = (name_item*)list_last(&list);item;
             item = (name_item*)list_prev(&list,item))
        printf("%s\n",item->name);


---------------------------------------------------------------
list_next()

   Usage: void * list_next(ldbfList *lst,void *link);

   Description: Returns next element from the list.Link is current 
     element of list.See examples of list_first() and list_last() functions
     for more detail.


---------------------------------------------------------------
list_prev()

  Usage:void *list_prev(ldbfList *lst,void *link);

   Description: Returns prev element from the list.Link is current 
     element of list.See examples of list_first() and list_last() functions
     for more detail.


---------------------------------------------------------------
list_remove()

  Usage:void list_remove(ldbfList *lst,void *link);

  Description: Removes element from list.


---------------------------------------------------------------
list_add()
list_add_after()
list_add_before()

   Usage:  void list_add(ldbfList *lst,void *link);
           void list_add_after(ldbfList *lst,void *anchor,void *link);
           void list_add_before(ldbfList *lst,void *anchor,void *link);
   
   Description:This functions add elemnt to list.
     list_add() adds element to the end of list,list_add_after
     adds element after specified element and list_add_before
     adds element before specified element.See examples for
     list_first().



---------------------------------------------------------------
list_pop()

   Usage:void *list_pop(ldbfList *lst);

   Descriptiton:Removes top element from list.

   Example:
     while((item = (name_item*)list_pop(&list)) {
       free(item);
     }


---------------------------------------------------------------
ldbfAlloc()

  Usage:void *ldbfAlloc(long n);

  Description:Allocates memory block.This function is equal to malloc
    library function.


---------------------------------------------------------------
ldbfFree()

   Usage:void ldbfFree(void *ptr);

   Description:Unallocates memory block allocated by ldbfAlloc.


---------------------------------------------------------------
ldbfdtol()   -   SLang only

  Usage: int ldbfdtol(double data)

  Description: Converts double to long.


---------------------------------------------------------------
ldbfRecord2Result()   -  SLang  only
ldbfStr2Result()
ldbfData2Result()

  Usage:  void Record2Result(string alias)
          void Str2Result(string data)
          void Data2Result(string table,integer recno,string data,integer len)

  Description:If you want return any result from stored procedure
    use these functions.First one put into result buffer contents
    of current record specified database, second puts any string and
    third puts any user defined data into result list.
    Note that each call of this functions adds result to result set that 
    will be returned to client.

  Example:
      define seek_cust()
      {
        ldbfTop("cust","no");
        while(not(ldbferrno)) {
         if(ldbfLongValue("cust","no") == 100)
           ldbfRecord2Result();        % adds record to result set
         ldbfSkip("cust","no",1);
        }
      }
--------------------------------------------------------------------
ldbfResultCount()  - SLang only

    Usage: integer ldbfResultCount()

    Description: Returns number of result items in result set.


--------------------------------------------------------------------
ldbfResult2Record()  - SLang only

    Usage: void ldbfResult2Record()

    Description: Stores current contents of result variables back
       into table.

--------------------------------------------------------------------
ldbfClearResult()

    Usage: void ldbfClearResult()

    Description: Clears result set.Nothing will be returned to client.

 SLang: void ldbfClearResult();

--------------------------------------------------------------------
ldbfSetRecordContents()    - SLang only

    Usage: void ldbfSetRecordContents(string alias,string record)

    Description: Stores string 'record' into record buffer of the current
     record in table 'alias'.

--------------------------------------------------------------------
ldbfNewIndex

   Syntax: void ldbfNewIndex(char *db,char *path)

   Description:Replaces index file of alias db.Operation makes without stopping
 other clients.

--------------------------------------------------------------------
ldbfRecno  - SLang only

   Syntax: integer ldbfRecno(string db)

   Description:Returns current record number.

--------------------------------------------------------------------
ldbfCopyTable  - SLang only

   Syntax: void ldbfldbfCopyTable(string from,string to,string condition)

   Description:Copies records from table 'from' to table 'to'.
    Records copies if condition is true.Both tables must exist.

  Example:
     ldbfCopyTable("customer","customer1","AGE < 30 .and. zip = 800");
    
--------------------------------------------------------------------
ldbfGetHTMLValue  - SLang only (CGI)

   Syntax: string ldbfGetHTMLValue(string str,string Var,string val_list)

   Description: Checks for existing in string str variable 'Var=value'.
       value is any element from list val_list of possible values.
       If this value exists, returns it, otherwise returns empty string.
  
   Example: 
    % date will contain 'date'
    date = ldbfGetHTMLValue("<INPUT TYPE=\"text\" NAME=\"date\" VALUE=\"\">",
        "NAME","date,name,zip,address")   
    
--------------------------------------------------------------------
ldbfReplaceHTMLValue  - SLang only (CGI)

   Syntax: string ldbfReplaceHTMLValue(string str,string Var,string new_val)

   Description:Finds in string str variable 'Var=' and replaces its value
    with 'new_val'.Returns updated string.
    If variable 'Var' doesn't exist, returns just str.
   
   Example:
   % replaces values 'VALUE' with new and returns 
   % <INPUT TYPE="text" NAME="name" VALUE="John Smith"> 
   ldbfPuts(ldbfReplaceHTMLValue("<INPUT TYPE=\"text\" NAME=\"name\" VALUE=\"\">",
          "VALUE","John Smith"));
--------------------------------------------------------------------
ldbfRemoveHTMLValue  - SLang only (CGI)

   Syntax: string ldbfRemoveHTMLValue(string str,string Var)

   Description:Finds in string str variable 'Var=' and removes it with
    its value.
    If variable 'Var' doesn't exist, returns just str.
   
   Example:
   % removes variable 'VALUE' 
   % <INPUT TYPE="text" NAME="name" VALUE="John Smith"> 
   ldbfPuts(ldbfRemoveHTMLValue("<INPUT TYPE=\"text\" NAME=\"name\" VALUE=\"\">");
   % returns <INPUT TYPE="text" NAME="name" > 
--------------------------------------------------------------------
ldbfAddHTMLValue  - SLang only (CGI)

   Syntax: string ldbfAddHTMLValue(string str,string Var)

   Description:Adds variable 'Var' into string 'str'.
   
   Example:
   % adds variable 'VALUE' 
   % <INPUT TYPE="text" NAME="name" > 
   ldbfPuts(ldbfAddHTMLValue("<INPUT TYPE=\"text\" NAME=\"name\">","VALUE=\"John Smith\"");
   % returns <INPUT TYPE="text" NAME="name" VALUE="John Smith"> 

--------------------------------------------------------------------
ldbfGetFieldList  - SLang only
 
  Syntax: string ldbfGetFieldList(string db)
 
  Description:Returns string that contains list of fields of database db,
     separated by comma.

  Example:
       variable fld_list = ldbfGetFieldList("personal");
       % fld_list may contain "name,address,zip,country,phone"
 
--------------------------------------------------------------------
ldbfConsructValues - SLang only (CGI)

   Syntax: string ldbfConstructValues(string db)

   Description:This functions useful for building 3 parameter for 
     functions ldbfInsert and ldbfUpdate.For database 'db'
     it makes string of field values.Values takes using function
     ldbfGetCGIValue.If HTML control exists , its value is put into
     list of values.
  
   Example:
     % This is example of html page
     % .....
     % <INPUT TYPE="text" NAME="name" VALUE="John">
     % <INPUT TYPE="text" NAME="address" VALUE="New York">
     % <INPUT TYPE="text" NAME="zip" VALUE="">
     % <INPUT TYPE="text" NAME="phone" VALUE="2345678">
     % .....
     % updates database "personal"
     % 
     % ldbfConstruct takes values from input controls and
     % constructs values list for "personal"
     % this list wiil look: "John,New York,,2345678
     % ldbfUpdate changes all field except zip
       ldbfUpdate("personal",ldbfGetFieldsList("personal"),
             ldbfConstructValues("personal"));

--------------------------------------------------------------------
ldbfWhatProgram - SLang only (CGI)

   Syntax: string ldbfWhatProgram()

   Description:Returns "ldbfdcgi" or "ldbfcgi".You may use it in S-Lang
    srcipts that runs via ldbfcgi(ldbfcgi).

--------------------------------------------------------------------
ldbfServerID - SLang only (CGI)

   Syntax: void ldbfServerID(integer ID)

   Description:Specify server's ID when connecting to LDBF server via ldbfdcgi.

--------------------------------------------------------------------
ldbfCheckRemote - SLang only (CGI)

   Syntax: integer ldbfCheckRemote(string allowed)

   Description:This function matches remote user with pattern
   specified by string 'allowed'.This string must be in form:
     [user]@[*]hostname
           where '*' means any value before hostname.
   ldbfCheckRemote returns 1 if remote matches our pattern.
   
 Example:

      if(ldbfCheckRemote("@*cs.smu.edu") == 0) {
        ldbfPuts("This CGI can run only from cs.smu.edu domain\n");
        ldbfExit();  
      }

--------------------------------------------------------------------
LDBF Error Codes:
---------------------------------------------------------------



 -10     Closing File

An error occurred while attempting to close a file.

 -160
 -20     Creating File

This error could be caused by specifying an illegal
file name, attempting to create a file which is
open, having a full directory, or by having a disk problem.


 -30     Determining File Length

An error occurred while attempting to determine the length
of a file.


 -40     Setting File Length

An error occurred while setting the length of a file.


 -50     Locking File

An error occurred while trying to lock a file.

 -170
 -60     Opening File

This problem is usually caused by specifying a file
which does not exist.  Another possible cause is an attempt to
open more files than the operating system or compiler can
handle or server has no permissions to open file.

Note that debuggers, Microsoft Windows, and other applications
can all use up available file handles.

  -70     Reading File

An error occurred while reading a file.  This could be
caused by calling ldbfGo() with a non-existent record number.


 -80     Removing File

An error occurred while attempting to remove a file.


 -90     Renaming File

An error occurred while renaming a file.


 -100     Seeking to File Position

An error occurred while attempting to position to a
spot in a file.

 -103     Eof encountered

End of file is reached while skiping or made goto in the database.

 -104     Bof encountered

Top of file is reached while skiping or made goto in the database.

 -105      No record or index entry

There is no specified record or tag entry in the index file.

 -110     Unlocking File

An error occurred while unlocking part of a file.

 -121     Duplicate key in unique index

Duplicate key value while appending to unique index tag.

 -120     Writing to File

This error occurs when the disk is full

 -150     Record or file locked

Database or specified record is locked while attempting to update database.

 -180     No tag selected

There is no selected tag while doing seek in database.

 -200     File is not a Data File

This error occurs when attempting to open a file as
a ".DBF" data file, if the file is not actually a true
data file.  If the file is a data file, its header,
and possibly its data is corrupted.


 -210     Unrecognized Field Name

A function, such as ldbfField(), was called with a field name
not present in the data file.


 -220     Unrecognized Field Type

A data field had an unrecognized field type.  The field
type of each field is specified in the data file header.


  -230     Record Length too Large

The total record length is too large.
The maximum is "USHRT_MAX-2" which is 65535 for
most compilers.


  -300     Tag Entry Missing

A tag entry was not located.  This error occurs when
a key, corresponding to a data file record, should be
in a tag but is not.


 -310     Not a Correct Index File

This error indicates that a file specified as an
index file is not a true index file.  Some
internal index file inconsistency was detected.


 -330     Tag Name not Found

The tag name specified is not an actual tag name.
Make sure the name is correct and that the corresponding
index file is open.


 -340     Unique Key Error

An attempt was made to add a record or create an
index file which would have
resulted in an duplicate tag key for a unique key tag.


 -400     Comma or Bracket Expected

A comma or a right bracket was expected but there
was none.  For example, the expression "SUBSTR( A" would
cause this error because a comma would be expected after
the "A".


  -410     Expression not Complete

The expression was not complete.  For example, the
expression "FIELD_A +" would not be complete because
there should be something else after the "+".



  -420     Data File Name not Located

A data file name was specified but the data file
was not currently open.  For example, if the expression
was "DATA^.FIELD_NAME", but no currently opened data
file has "DATA" as its alias.  


 -430     Number of Parameters is Wrong

The number of parameters specified, in a dBASE expression,
is wrong.


 -440     Overflow while Evaluating Expression

The dBASE expression was too long or complex 
to handle.  Such an expression would be extremely long
and complex.


 -450     Right Bracket Missing

The dBASE expression is missing a right bracket.  Make
sure the expression contains the same number of right
as left brackets.


 -460     Sub-expression Type is Wrong

The type of a sub-expression did not match the
type of an expression operator.  For example,
in the expression "33 .AND. .F.", the "33" is of
type numeric and the operator ".AND." needs logical
operands.


 -470     Unrecognized Function

A specified function was not recognized.  For example,
the expression "SIMPLE(3)" is not valid.


  -480     Unrecognized Operator

A specified operator was not recognized.  For example,
in the dBASE expression "3 } 7", the character "}" is in a place
where a dBASE operator would be expected.


 -490     Unrecognized Value

A character sequence was not recognized as a dBASE
constant, field name, or function.


 -500     Unterminated String

According to dBASE expression syntax, a string
constant starts with a quote character and ends with
the same quote character.  However, there was no ending quote
character to match a starting quote character.


 -910     Unexpected Information

Ldbf discovered an unexpected value in one
of its internal variables.


 -920     Out of Memory

Ldbf tried to allocate some memory from the heap,
in order to complete an function call, but no memory
was available.


 -930     Unexpected Parameter

A LDBF function was passed an unexpected parameter
value.


 -1000   Wrong password

Wrong password was specified during connection to server.


 -1001   Connection refused

Server cannot login user.Call administrator.May be
you have no rights to connect tot server.

 -1002   Transaction error

This error occurs due to system failure of reading or writing
with transaction files.


 -1003   Rule condition

You attempt to append or update record but record contents
does not match conditions defined in ldbf.conf.

 -1004   Syntax error in rule

Read slang.txt documentation about S-lang language.

 -1005   Unrecognized field name in rule

You try refer to field that cannot be accessed during
perform rule.

 -1006	Error creating socket

This is system error.Problem in your TCP/IP kernel.

 -1007	Cannot connect to host

Host cannot be accessed or wrong hostname.


 -1008	Cannot resolve host name

Invalid host name or DNS settings.

 -1009	Connection reset by peer

Connection was droped by server's side.


 -1010  Too big packet

You send to much data to server.

 -1011	Unknown command

Server did not recognize command.

 -1012	Wrong parameters in the command

Server does not perform command.This is internal error

 -1013	You doesn't have DBA privileges

You attempt to perform create or drop or exchange commands but
you are not granted for this.

 -1014	Cannot remove because database is in use

Other user have this database opened.

 -1016  Transaction processing disabled

Call administrator.


 -1017  Read-only database

You attempt to perform updates on read-only database.

 -1018	Not permisions for open

You cannot open this database

  -1019	  Database not opened

You attempt perform database operations on not opened database.

 -1020	Database opened by another

You attempt open database in exclusive mode but it already opened.


 -1021	Internal memory allocation error

Call administartor.

 -1022	Commit processing error

Call administartor.Your transactions may be lost.

 -1023  Stored procedure not found

You attempt to call stored procedure that not desribed in ldbf.conf

 -1024   Alias not found

You attempt to open or do smth with alias that not exist
  
 -1025  Error in SLang script

This error indicate that problem is in stored procedure 
written in SLang language
