/* das ist ein -*- C -*- Programm */

/* this definition is from tclInt.h 
 * the first FOUR entries match EXACT the Interp struct from 
 * tclInt.h; we can't include tclInt.h, since it conflicts with
 * Xt' Arg structure.
 */
typedef struct Interp {
    /*
     * Note:  the first three fields must match exactly the fields in
     * a Tcl_Interp struct (see tcl.h).  If you change one, be sure to
     * change the other.
     */

    char *result;               /* Points to result returned by last
                                 * command. */
    Tcl_FreeProc *freeProc;     /* Zero means result is statically allocated.
                                 * If non-zero, gives address of procedure
                                 * to invoke to free the result.  Must be
                                 * freed by Tcl_Eval before executing next
                                 * command. */
    int errorLine;              /* When TCL_ERROR is returned, this gives
                                 * the line number within the command where
                                 * the error occurred (1 means first line). */
    Tcl_HashTable commandTable; /* Contains all of the commands currently
                                 * registered in this interpreter.  Indexed
                                 * by strings; values have type (Command *). */
    } Interp;

extern void wafeRegisterCmd(
#if NeedFunctionPrototypes
    int, String
#endif
);

extern void wafeUnregisterCmd(
#if NeedFunctionPrototypes
    int
#endif
);

extern void wafeSetCommunicationVariableCmd(
#if NeedFunctionPrototypes
    String, int, String
#endif
);

extern XtInputId wafeAddInputCmd(
#if NeedFunctionPrototypes
    int, XtPointer, String, String
#endif
);

extern void wafeRemoveInputCmd(
#if NeedFunctionPrototypes
    XtInputId 
#endif
);



static int
alias(newCmdName,oldCmdName)
String newCmdName;
String oldCmdName;
    {
    XtPointer cmdPtr;
    Interp *iPtr = (Interp *) wafeInterpreter;
    Tcl_HashEntry *hPtr;
    int newEntry;    

    if ((hPtr = Tcl_FindHashEntry(&iPtr->commandTable, newCmdName)) != NULL)
	{
	fprintf(stderr,
		"Wafe(alias): can't alias to '%s': command already exists\n",
		newCmdName);
        /* Tcl_AppendResult(wafeInterpreter, "can't alias to \"", newCmdName,
                "\": command already exists", (char *) NULL); */
        return 0;
	}
    
    if ((hPtr = Tcl_FindHashEntry(&iPtr->commandTable, oldCmdName)) == NULL)
	{
	fprintf(stderr,
		"Wafe(alias): can't alias '%s': command doesn't exist\n",
		oldCmdName);
        /* Tcl_AppendResult(wafeInterpreter, "can't alias \"", oldCmdName,
                "\":  command doesn't exist", (char *) NULL); */
        return 0;
	}

    cmdPtr = (XtPointer) Tcl_GetHashValue(hPtr);
    hPtr = Tcl_CreateHashEntry(&iPtr->commandTable, newCmdName, &newEntry);
    Tcl_SetHashValue(hPtr, cmdPtr);
    return 1;
}
