#include <stdio.h>       /* Standard I/O is all we really need from the system */
#include "kf-api.h"      /* The KF-API prototypes ensure proper type checking! */


/* Try a DEFINE=__MYDATE__="`AmigaDate`" as part of the compiler's command
 * line, provided, of course, you have a program named 'AmigaDate' available
 * which produces a proper format for output, such as: "(17.1.95)"
 *    If you don't use it, the statement below will use the standard SAS/C
 * __AMIGADATE__ instead, which is buggy with 6.51 (whenever BOTH month AND
 * day occupy 2 digits.)
 */
#ifndef __MYDATE__
#define __MYDATE__ __AMIGADATE__
#endif


/* ALWAYS a good idea to have in the code! */
char const VER[] = "$VER: KFDemo 1.0 "__MYDATE__;


int main( int argc, char *argv[] ) {

  KFHANDLE myHandle;       /* defines an active connection to the server */
  extern BOOL KFAPISilentRun;   /* defined in kf-api.c */


  KFAPISilentRun = TRUE;   /* stop those pesky status messages while the
                            * server is being started...
                            */

  /* try to establish a connection to the server; this will attempt to
   * start the server if it is not already running!  If the server cannot
   * be started, it may take as much as 10 seconds for the command to try
   * a second time before deciding that not even slow floppy drives should
   * take that long.
   */
  if( (myHandle = KFLogin("First Test Project")) != NULL ) {

    /* If we get here, then the server is running and we are connected
     * to it with a default database ready to be examined!
     */

    /* ask the server how many connections it can handle */
    ULONG maxlogins = KFMaxClients( myHandle );
    if( maxlogins <= 2 )
      printf("Unregistered");
    else
    if( maxlogins <= 32767 )
      printf("Beta release");
    else
      printf("Registered");
    printf(" server software is ready!\n");

    /* ask the server to give us some status information */
    if( KFStatus( myHandle ) )
      printf("********************\n"
             "%s\n"
             "********************\n",myHandle->Buffer);
    else
      printf("Status information could not be obtained!\n");

    /* logout from the server again (i.e. disconnect) */
    KFLogout( myHandle );
  } else
    printf("The KFServer couldn't be started?!\n");
} /* main() */
