/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution. 
\*************************************************************************/

/*
 * $Log: not supported by cvs2svn $
 * Revision 1.1  1999/06/10 19:47:36  soliday
 * Moved to oag tree.
 *
 * Revision 1.3  1999/06/09 21:42:03  soliday
 * The usage statement was updated to include the new commnads.
 *
 * Revision 1.2  1999/06/08 22:14:32  soliday
 * Removed compiler warnings under Linux.
 *
 * Revision 1.1  1999/04/07 16:11:28  soliday
 * Initial version of the snapshot shared library
 *
 * */

#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <tclSnapshot.h>

static Tcl_HashTable tclSnapshotCmdTable;

typedef struct {
  char *name;     /* sdds xxx command name */
  int (*proc)();  /* command handling function */
} CMD_INFO;

static CMD_INFO tclSnapshotCommands[] = {
  {"write", tclSnapshotWrite},
  {"readRequest", tclSnapshotReadRequest},
  {"readSnapshot", tclSnapshotReadSnapshot},
  {"linkPVs", tclSnapshotLinkPVs},
  {"getPVs", tclSnapshotGetPVs},
  {"putPVs", tclSnapshotPutPVs},
  {(char *)NULL, (int (*)())NULL}
};


/* Function Prototypes */
int tclSnapshotCmd(ClientData dummy, Tcl_Interp *interp, int argc, char *argv[]);
int Tclsnapshot_Init(Tcl_Interp *interp);

int tclSnapshotCmd(ClientData dummy, Tcl_Interp *interp, int argc, char *argv[]) {

  Tcl_HashEntry *entryPtr;
  int (*handler)();

  if (argc < 2) {
    Tcl_SetResult(interp, "snapshot: must specify a sub-command: write, readRequest, readSnapshot, linkPVs, getPVs, or putPVs", \
		  (Tcl_FreeProc *) NULL); 
    return TCL_ERROR;
  }

  entryPtr = Tcl_FindHashEntry(&tclSnapshotCmdTable, argv[1]);
  if (entryPtr == NULL) {
    Tcl_SetResult(interp, "Unknown snapshot command ", (Tcl_FreeProc *) NULL);
    return TCL_ERROR;
  } else {
    handler = (int(*)())Tcl_GetHashValue(entryPtr);
    return ((*handler)(interp, argc, argv));
  }

}

int Tclsnapshot_Init(Tcl_Interp *interp) {
  CMD_INFO *cmd;

  Tcl_CreateCommand(interp, "snapshot", tclSnapshotCmd, (ClientData *) NULL,
		    (Tcl_CmdDeleteProc *)NULL);

  Tcl_InitHashTable(&tclSnapshotCmdTable, TCL_STRING_KEYS);
  for (cmd=tclSnapshotCommands ; cmd->name != NULL ; cmd++) {
    int newEntry;
    Tcl_HashEntry *entryPtr;
    entryPtr = Tcl_CreateHashEntry(&tclSnapshotCmdTable, cmd->name, &newEntry);
    Tcl_SetHashValue(entryPtr, cmd->proc);
  } 
  tclSnapshotInit(interp);
 
  return TCL_OK;
}




