diff options
author | dgp <dgp@users.sourceforge.net> | 2007-05-29 14:05:53 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2007-05-29 14:05:53 (GMT) |
commit | 460524e86d044884041f17b82af28c073181165d (patch) | |
tree | f70e6ee746559976d6db52f5b1328a1e723419ae | |
parent | 9190f533c5cb5bf91aa76adf0fb9cfcc90775c07 (diff) | |
download | tcl-460524e86d044884041f17b82af28c073181165d.zip tcl-460524e86d044884041f17b82af28c073181165d.tar.gz tcl-460524e86d044884041f17b82af28c073181165d.tar.bz2 |
restore line endings
-rw-r--r-- | unix/dltest/pkga.c | 276 | ||||
-rw-r--r-- | unix/dltest/pkgb.c | 328 | ||||
-rw-r--r-- | unix/dltest/pkgc.c | 330 | ||||
-rw-r--r-- | unix/dltest/pkgd.c | 330 | ||||
-rw-r--r-- | unix/dltest/pkge.c | 92 | ||||
-rw-r--r-- | unix/dltest/pkgf.c | 92 | ||||
-rw-r--r-- | unix/dltest/pkgua.c | 668 |
7 files changed, 1058 insertions, 1058 deletions
diff --git a/unix/dltest/pkga.c b/unix/dltest/pkga.c index d206010..b282614 100644 --- a/unix/dltest/pkga.c +++ b/unix/dltest/pkga.c @@ -1,138 +1,138 @@ -/*
- * pkga.c --
- *
- * This file contains a simple Tcl package "pkga" that is intended for
- * testing the Tcl dynamic loading facilities.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkga.c,v 1.9 2007/05/02 21:28:09 dkf Exp $
- */
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int Pkga_EqObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-static int Pkga_QuoteObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkga_EqObjCmd --
- *
- * This procedure is invoked to process the "pkga_eq" Tcl command. It
- * expects two arguments and returns 1 if they are the same, 0 if they
- * are different.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkga_EqObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- int result;
- CONST char *str1, *str2;
- int len1, len2;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "string1 string2");
- return TCL_ERROR;
- }
-
- str1 = Tcl_GetStringFromObj(objv[1], &len1);
- str2 = Tcl_GetStringFromObj(objv[2], &len2);
- if (len1 == len2) {
- result = (Tcl_UtfNcmp(str1, str2, len1) == 0);
- } else {
- result = 0;
- }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkga_QuoteObjCmd --
- *
- * This procedure is invoked to process the "pkga_quote" Tcl command. It
- * expects one argument, which it returns as result.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkga_QuoteObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument strings. */
-{
- if (objc != 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "value");
- return TCL_ERROR;
- }
- Tcl_SetObjResult(interp, objv[1]);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkga_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkga_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkga", "1.0");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
+/* + * pkga.c -- + * + * This file contains a simple Tcl package "pkga" that is intended for + * testing the Tcl dynamic loading facilities. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkga.c,v 1.10 2007/05/29 14:05:53 dgp Exp $ + */ +#include "tcl.h" + +/* + * Prototypes for procedures defined later in this file: + */ + +static int Pkga_EqObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +static int Pkga_QuoteObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + +/* + *---------------------------------------------------------------------- + * + * Pkga_EqObjCmd -- + * + * This procedure is invoked to process the "pkga_eq" Tcl command. It + * expects two arguments and returns 1 if they are the same, 0 if they + * are different. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkga_EqObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + int result; + CONST char *str1, *str2; + int len1, len2; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "string1 string2"); + return TCL_ERROR; + } + + str1 = Tcl_GetStringFromObj(objv[1], &len1); + str2 = Tcl_GetStringFromObj(objv[2], &len2); + if (len1 == len2) { + result = (Tcl_UtfNcmp(str1, str2, len1) == 0); + } else { + result = 0; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkga_QuoteObjCmd -- + * + * This procedure is invoked to process the "pkga_quote" Tcl command. It + * expects one argument, which it returns as result. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkga_QuoteObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument strings. */ +{ + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "value"); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, objv[1]); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkga_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkga_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkga", "1.0"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkga_eq", Pkga_EqObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkga_quote", Pkga_QuoteObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index 0f102e3..1a60f05 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -1,164 +1,164 @@ -/*
- * pkgb.c --
- *
- * This file contains a simple Tcl package "pkgb" that is intended for
- * testing the Tcl dynamic loading facilities. It can be used in both
- * safe and unsafe interpreters.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkgb.c,v 1.6 2007/05/02 21:28:09 dkf Exp $
- */
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int Pkgb_SubObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-static int Pkgb_UnsafeObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgb_SubObjCmd --
- *
- * This procedure is invoked to process the "pkgb_sub" Tcl command. It
- * expects two arguments and returns their difference.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgb_SubObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- int first, second;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "num num");
- return TCL_ERROR;
- }
- if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) {
- return TCL_ERROR;
- }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgb_UnsafeObjCmd --
- *
- * This procedure is invoked to process the "pkgb_unsafe" Tcl command. It
- * just returns a constant string.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgb_UnsafeObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgb_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgb_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgb", "2.3");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateObjCommand(interp, "pkgb_unsafe", Pkgb_UnsafeObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgb_SafeInit --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an unsafe interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgb_SafeInit(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgb", "2.3");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, (ClientData) 0,
- (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
+/* + * pkgb.c -- + * + * This file contains a simple Tcl package "pkgb" that is intended for + * testing the Tcl dynamic loading facilities. It can be used in both + * safe and unsafe interpreters. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkgb.c,v 1.7 2007/05/29 14:05:53 dgp Exp $ + */ +#include "tcl.h" + +/* + * Prototypes for procedures defined later in this file: + */ + +static int Pkgb_SubObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +static int Pkgb_UnsafeObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + +/* + *---------------------------------------------------------------------- + * + * Pkgb_SubObjCmd -- + * + * This procedure is invoked to process the "pkgb_sub" Tcl command. It + * expects two arguments and returns their difference. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgb_SubObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + int first, second; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "num num"); + return TCL_ERROR; + } + if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgb_UnsafeObjCmd -- + * + * This procedure is invoked to process the "pkgb_unsafe" Tcl command. It + * just returns a constant string. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgb_UnsafeObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgb_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgb_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgb", "2.3"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgb_unsafe", Pkgb_UnsafeObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgb_SafeInit -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an unsafe interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgb_SafeInit( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgb", "2.3"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, (ClientData) 0, + (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} diff --git a/unix/dltest/pkgc.c b/unix/dltest/pkgc.c index 8d32f89..6f16bf3 100644 --- a/unix/dltest/pkgc.c +++ b/unix/dltest/pkgc.c @@ -1,165 +1,165 @@ -/*
- * pkgc.c --
- *
- * This file contains a simple Tcl package "pkgc" that is intended for
- * testing the Tcl dynamic loading facilities. It can be used in both
- * safe and unsafe interpreters.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkgc.c,v 1.6 2007/05/02 21:28:09 dkf Exp $
- */
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int Pkgc_SubObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]);
-static int Pkgc_UnsafeObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]);
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgc_SubObjCmd --
- *
- * This procedure is invoked to process the "pkgc_sub" Tcl command. It
- * expects two arguments and returns their difference.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgc_SubObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- int first, second;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "num num");
- return TCL_ERROR;
- }
- if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) {
- return TCL_ERROR;
- }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgc_UnsafeCmd --
- *
- * This procedure is invoked to process the "pkgc_unsafe" Tcl command. It
- * just returns a constant string.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgc_UnsafeObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgc_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to a normal (unsafe/trusted)
- * interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgc_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateObjCommand(interp, "pkgc_unsafe", Pkgc_UnsafeObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgc_SafeInit --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to a safe interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgc_SafeInit(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, (ClientData) 0,
- (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
+/* + * pkgc.c -- + * + * This file contains a simple Tcl package "pkgc" that is intended for + * testing the Tcl dynamic loading facilities. It can be used in both + * safe and unsafe interpreters. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkgc.c,v 1.7 2007/05/29 14:05:53 dgp Exp $ + */ +#include "tcl.h" + +/* + * Prototypes for procedures defined later in this file: + */ + +static int Pkgc_SubObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]); +static int Pkgc_UnsafeObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]); + +/* + *---------------------------------------------------------------------- + * + * Pkgc_SubObjCmd -- + * + * This procedure is invoked to process the "pkgc_sub" Tcl command. It + * expects two arguments and returns their difference. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgc_SubObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + int first, second; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "num num"); + return TCL_ERROR; + } + if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgc_UnsafeCmd -- + * + * This procedure is invoked to process the "pkgc_unsafe" Tcl command. It + * just returns a constant string. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgc_UnsafeObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgc_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to a normal (unsafe/trusted) + * interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgc_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgc_unsafe", Pkgc_UnsafeObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgc_SafeInit -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to a safe interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgc_SafeInit( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, (ClientData) 0, + (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} diff --git a/unix/dltest/pkgd.c b/unix/dltest/pkgd.c index 3744018..92c47a0 100644 --- a/unix/dltest/pkgd.c +++ b/unix/dltest/pkgd.c @@ -1,165 +1,165 @@ -/*
- * pkgd.c --
- *
- * This file contains a simple Tcl package "pkgd" that is intended for
- * testing the Tcl dynamic loading facilities. It can be used in both
- * safe and unsafe interpreters.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkgd.c,v 1.6 2007/05/02 21:28:09 dkf Exp $
- */
-
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int Pkgd_SubObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-static int Pkgd_UnsafeObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgd_SubObjCmd --
- *
- * This procedure is invoked to process the "pkgd_sub" Tcl command. It
- * expects two arguments and returns their difference.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgd_SubObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- int first, second;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "num num");
- return TCL_ERROR;
- }
- if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) {
- return TCL_ERROR;
- }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgd_UnsafeCmd --
- *
- * This procedure is invoked to process the "pkgd_unsafe" Tcl command. It
- * just returns a constant string.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-Pkgd_UnsafeObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgd_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgd_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgd", "7.3");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- Tcl_CreateObjCommand(interp, "pkgd_unsafe", Pkgd_UnsafeObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgd_SafeInit --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to a safe interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgd_SafeInit(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- code = Tcl_PkgProvide(interp, "Pkgd", "7.3");
- if (code != TCL_OK) {
- return code;
- }
- Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, (ClientData) 0,
- (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
+/* + * pkgd.c -- + * + * This file contains a simple Tcl package "pkgd" that is intended for + * testing the Tcl dynamic loading facilities. It can be used in both + * safe and unsafe interpreters. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkgd.c,v 1.7 2007/05/29 14:05:53 dgp Exp $ + */ + +#include "tcl.h" + +/* + * Prototypes for procedures defined later in this file: + */ + +static int Pkgd_SubObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +static int Pkgd_UnsafeObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + +/* + *---------------------------------------------------------------------- + * + * Pkgd_SubObjCmd -- + * + * This procedure is invoked to process the "pkgd_sub" Tcl command. It + * expects two arguments and returns their difference. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgd_SubObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + int first, second; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "num num"); + return TCL_ERROR; + } + if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgd_UnsafeCmd -- + * + * This procedure is invoked to process the "pkgd_unsafe" Tcl command. It + * just returns a constant string. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +Pkgd_UnsafeObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgd_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgd_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgd", "7.3"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateObjCommand(interp, "pkgd_unsafe", Pkgd_UnsafeObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgd_SafeInit -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to a safe interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgd_SafeInit( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + code = Tcl_PkgProvide(interp, "Pkgd", "7.3"); + if (code != TCL_OK) { + return code; + } + Tcl_CreateObjCommand(interp, "pkgd_sub", Pkgd_SubObjCmd, (ClientData) 0, + (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} diff --git a/unix/dltest/pkge.c b/unix/dltest/pkge.c index 2eeaa73..98a35a0 100644 --- a/unix/dltest/pkge.c +++ b/unix/dltest/pkge.c @@ -1,46 +1,46 @@ -/*
- * pkge.c --
- *
- * This file contains a simple Tcl package "pkge" that is intended for
- * testing the Tcl dynamic loading facilities. Its Init procedure returns
- * an error in order to test how this is handled.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkge.c,v 1.7 2007/05/02 21:28:09 dkf Exp $
- */
-
-#include "tcl.h"
-
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkge_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * Returns TCL_ERROR and leaves an error message in interp->result.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkge_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- static char script[] = "if 44 {open non_existent}";
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- return Tcl_Eval(interp, script);
-}
+/* + * pkge.c -- + * + * This file contains a simple Tcl package "pkge" that is intended for + * testing the Tcl dynamic loading facilities. Its Init procedure returns + * an error in order to test how this is handled. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkge.c,v 1.8 2007/05/29 14:05:53 dgp Exp $ + */ + +#include "tcl.h" + + +/* + *---------------------------------------------------------------------- + * + * Pkge_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * Returns TCL_ERROR and leaves an error message in interp->result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkge_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + static char script[] = "if 44 {open non_existent}"; + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + return Tcl_Eval(interp, script); +} diff --git a/unix/dltest/pkgf.c b/unix/dltest/pkgf.c index b8913e1..c32aaf0 100644 --- a/unix/dltest/pkgf.c +++ b/unix/dltest/pkgf.c @@ -1,46 +1,46 @@ -/*
- * pkgf.c --
- *
- * This file contains a simple Tcl package "pkgf" that is intended for
- * testing the Tcl dynamic loading facilities. Its Init procedure returns
- * an error in order to test how this is handled.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkgf.c,v 1.6 2007/05/02 21:28:09 dkf Exp $
- */
-
-#include "tcl.h"
-
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgf_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * Returns TCL_ERROR and leaves an error message in interp->result.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgf_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- static char script[] = "if 44 {open non_existent}";
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
- return Tcl_Eval(interp, script);
-}
+/* + * pkgf.c -- + * + * This file contains a simple Tcl package "pkgf" that is intended for + * testing the Tcl dynamic loading facilities. Its Init procedure returns + * an error in order to test how this is handled. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkgf.c,v 1.7 2007/05/29 14:05:53 dgp Exp $ + */ + +#include "tcl.h" + + +/* + *---------------------------------------------------------------------- + * + * Pkgf_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * Returns TCL_ERROR and leaves an error message in interp->result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgf_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + static char script[] = "if 44 {open non_existent}"; + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + return Tcl_Eval(interp, script); +} diff --git a/unix/dltest/pkgua.c b/unix/dltest/pkgua.c index 158193c..4c2c713 100644 --- a/unix/dltest/pkgua.c +++ b/unix/dltest/pkgua.c @@ -1,334 +1,334 @@ -/*
- * pkgua.c --
- *
- * This file contains a simple Tcl package "pkgua" that is intended for
- * testing the Tcl dynamic unloading facilities.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- * Copyright (c) 2004 Georgios Petasis
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: pkgua.c,v 1.4 2007/05/02 21:28:09 dkf Exp $
- */
-
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int PkguaEqObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-static int PkguaQuoteObjCmd(ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
-
-/*
- * In the following hash table we are going to store a struct that holds all
- * the command tokens created by Tcl_CreateObjCommand in an interpreter,
- * indexed by the interpreter. In this way, we can find which command tokens
- * we have registered in a specific interpreter, in order to unload them. We
- * need to keep the various command tokens we have registered, as they are the
- * only safe way to unregister our registered commands, even if they have been
- * renamed.
- *
- * Note that this code is utterly single-threaded.
- */
-
-static Tcl_HashTable interpTokenMap;
-static int interpTokenMapInitialised = 0;
-#define MAX_REGISTERED_COMMANDS 2
-
-
-static void
-PkguaInitTokensHashTable(void)
-{
- if (interpTokenMapInitialised) {
- return;
- }
- Tcl_InitHashTable(&interpTokenMap, TCL_ONE_WORD_KEYS);
- interpTokenMapInitialised = 1;
-}
-
-void
-PkguaFreeTokensHashTable(void)
-{
- Tcl_HashSearch search;
- Tcl_HashEntry *entryPtr;
-
- for (entryPtr = Tcl_FirstHashEntry(&interpTokenMap, &search);
- entryPtr != NULL; entryPtr = Tcl_NextHashEntry(&search)) {
- Tcl_Free((char *) Tcl_GetHashValue(entryPtr));
- }
- interpTokenMapInitialised = 0;
-}
-
-static Tcl_Command *
-PkguaInterpToTokens(
- Tcl_Interp *interp)
-{
- int newEntry;
- Tcl_Command *cmdTokens;
- Tcl_HashEntry *entryPtr =
- Tcl_CreateHashEntry(&interpTokenMap, (char *) interp, &newEntry);
-
- if (newEntry) {
- cmdTokens = (Tcl_Command *)
- Tcl_Alloc(sizeof(Tcl_Command) * (MAX_REGISTERED_COMMANDS+1));
- for (newEntry=0 ; newEntry<MAX_REGISTERED_COMMANDS+1 ; ++newEntry) {
- cmdTokens[newEntry] = NULL;
- }
- Tcl_SetHashValue(entryPtr, (ClientData) cmdTokens);
- } else {
- cmdTokens = (Tcl_Command *) Tcl_GetHashValue(entryPtr);
- }
- return cmdTokens;
-}
-
-static void
-PkguaDeleteTokens(
- Tcl_Interp *interp)
-{
- Tcl_HashEntry *entryPtr =
- Tcl_FindHashEntry(&interpTokenMap, (char *) interp);
-
- if (entryPtr) {
- Tcl_Free((char *) Tcl_GetHashValue(entryPtr));
- Tcl_DeleteHashEntry(entryPtr);
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * PkguaEqObjCmd --
- *
- * This procedure is invoked to process the "pkgua_eq" Tcl command. It
- * expects two arguments and returns 1 if they are the same, 0 if they
- * are different.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-PkguaEqObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument objects. */
-{
- int result;
- CONST char *str1, *str2;
- int len1, len2;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "string1 string2");
- return TCL_ERROR;
- }
-
- str1 = Tcl_GetStringFromObj(objv[1], &len1);
- str2 = Tcl_GetStringFromObj(objv[2], &len2);
- if (len1 == len2) {
- result = (Tcl_UtfNcmp(str1, str2, len1) == 0);
- } else {
- result = 0;
- }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * PkguaQuoteObjCmd --
- *
- * This procedure is invoked to process the "pkgua_quote" Tcl command. It
- * expects one argument, which it returns as result.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-PkguaQuoteObjCmd(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *CONST objv[]) /* Argument strings. */
-{
- if (objc != 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "value");
- return TCL_ERROR;
- }
- Tcl_SetObjResult(interp, objv[1]);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgua_Init --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgua_Init(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- int code, cmdIndex = 0;
- Tcl_Command *cmdTokens;
-
- if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
- return TCL_ERROR;
- }
-
- /*
- * Initialise our Hash table, where we store the registered command tokens
- * for each interpreter.
- */
-
- PkguaInitTokensHashTable();
-
- code = Tcl_PkgProvide(interp, "Pkgua", "1.0");
- if (code != TCL_OK) {
- return code;
- }
-
- Tcl_SetVar(interp, "::pkgua_loaded", ".", TCL_APPEND_VALUE);
-
- cmdTokens = PkguaInterpToTokens(interp);
- cmdTokens[cmdIndex++] =
- Tcl_CreateObjCommand(interp, "pkgua_eq", PkguaEqObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- cmdTokens[cmdIndex++] =
- Tcl_CreateObjCommand(interp, "pkgua_quote", PkguaQuoteObjCmd,
- (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgua_SafeInit --
- *
- * This is a package initialization procedure, which is called by Tcl
- * when this package is to be added to an unsafe interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgua_SafeInit(
- Tcl_Interp *interp) /* Interpreter in which the package is to be
- * made available. */
-{
- return Pkgua_Init(interp);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgua_Unload --
- *
- * This is a package unloading initialization procedure, which is called
- * by Tcl when this package is to be unloaded form an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgua_Unload(
- Tcl_Interp *interp, /* Interpreter from which the package is to be
- * unloaded. */
- int flags) /* Flags passed by the unloading mechanism */
-{
- int code, cmdIndex;
- Tcl_Command *cmdTokens = PkguaInterpToTokens(interp);
-
- for (cmdIndex=0 ; cmdIndex<MAX_REGISTERED_COMMANDS ; cmdIndex++) {
- if (cmdTokens[cmdIndex] == NULL) {
- continue;
- }
- code = Tcl_DeleteCommandFromToken(interp, cmdTokens[cmdIndex]);
- if (code != TCL_OK) {
- return code;
- }
- }
-
- PkguaDeleteTokens(interp);
-
- Tcl_SetVar(interp, "::pkgua_detached", ".", TCL_APPEND_VALUE);
-
- if (flags == TCL_UNLOAD_DETACH_FROM_PROCESS) {
- /*
- * Tcl is ready to detach this library from the running application.
- * We should free all the memory that is not related to any
- * interpreter.
- */
-
- PkguaFreeTokensHashTable();
- Tcl_SetVar(interp, "::pkgua_unloaded", ".", TCL_APPEND_VALUE);
- }
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgua_SafeUnload --
- *
- * This is a package unloading initialization procedure, which is called
- * by Tcl when this package is to be unloaded form an interpreter.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgua_SafeUnload(
- Tcl_Interp *interp, /* Interpreter from which the package is to be
- * unloaded. */
- int flags) /* Flags passed by the unloading mechanism */
-{
- return Pkgua_Unload(interp, flags);
-}
+/* + * pkgua.c -- + * + * This file contains a simple Tcl package "pkgua" that is intended for + * testing the Tcl dynamic unloading facilities. + * + * Copyright (c) 1995 Sun Microsystems, Inc. + * Copyright (c) 2004 Georgios Petasis + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: pkgua.c,v 1.5 2007/05/29 14:05:53 dgp Exp $ + */ + +#include "tcl.h" + +/* + * Prototypes for procedures defined later in this file: + */ + +static int PkguaEqObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +static int PkguaQuoteObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); + +/* + * In the following hash table we are going to store a struct that holds all + * the command tokens created by Tcl_CreateObjCommand in an interpreter, + * indexed by the interpreter. In this way, we can find which command tokens + * we have registered in a specific interpreter, in order to unload them. We + * need to keep the various command tokens we have registered, as they are the + * only safe way to unregister our registered commands, even if they have been + * renamed. + * + * Note that this code is utterly single-threaded. + */ + +static Tcl_HashTable interpTokenMap; +static int interpTokenMapInitialised = 0; +#define MAX_REGISTERED_COMMANDS 2 + + +static void +PkguaInitTokensHashTable(void) +{ + if (interpTokenMapInitialised) { + return; + } + Tcl_InitHashTable(&interpTokenMap, TCL_ONE_WORD_KEYS); + interpTokenMapInitialised = 1; +} + +void +PkguaFreeTokensHashTable(void) +{ + Tcl_HashSearch search; + Tcl_HashEntry *entryPtr; + + for (entryPtr = Tcl_FirstHashEntry(&interpTokenMap, &search); + entryPtr != NULL; entryPtr = Tcl_NextHashEntry(&search)) { + Tcl_Free((char *) Tcl_GetHashValue(entryPtr)); + } + interpTokenMapInitialised = 0; +} + +static Tcl_Command * +PkguaInterpToTokens( + Tcl_Interp *interp) +{ + int newEntry; + Tcl_Command *cmdTokens; + Tcl_HashEntry *entryPtr = + Tcl_CreateHashEntry(&interpTokenMap, (char *) interp, &newEntry); + + if (newEntry) { + cmdTokens = (Tcl_Command *) + Tcl_Alloc(sizeof(Tcl_Command) * (MAX_REGISTERED_COMMANDS+1)); + for (newEntry=0 ; newEntry<MAX_REGISTERED_COMMANDS+1 ; ++newEntry) { + cmdTokens[newEntry] = NULL; + } + Tcl_SetHashValue(entryPtr, (ClientData) cmdTokens); + } else { + cmdTokens = (Tcl_Command *) Tcl_GetHashValue(entryPtr); + } + return cmdTokens; +} + +static void +PkguaDeleteTokens( + Tcl_Interp *interp) +{ + Tcl_HashEntry *entryPtr = + Tcl_FindHashEntry(&interpTokenMap, (char *) interp); + + if (entryPtr) { + Tcl_Free((char *) Tcl_GetHashValue(entryPtr)); + Tcl_DeleteHashEntry(entryPtr); + } +} + +/* + *---------------------------------------------------------------------- + * + * PkguaEqObjCmd -- + * + * This procedure is invoked to process the "pkgua_eq" Tcl command. It + * expects two arguments and returns 1 if they are the same, 0 if they + * are different. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +PkguaEqObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ +{ + int result; + CONST char *str1, *str2; + int len1, len2; + + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "string1 string2"); + return TCL_ERROR; + } + + str1 = Tcl_GetStringFromObj(objv[1], &len1); + str2 = Tcl_GetStringFromObj(objv[2], &len2); + if (len1 == len2) { + result = (Tcl_UtfNcmp(str1, str2, len1) == 0); + } else { + result = 0; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(result)); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * PkguaQuoteObjCmd -- + * + * This procedure is invoked to process the "pkgua_quote" Tcl command. It + * expects one argument, which it returns as result. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +static int +PkguaQuoteObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument strings. */ +{ + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "value"); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, objv[1]); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgua_Init -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgua_Init( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + int code, cmdIndex = 0; + Tcl_Command *cmdTokens; + + if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { + return TCL_ERROR; + } + + /* + * Initialise our Hash table, where we store the registered command tokens + * for each interpreter. + */ + + PkguaInitTokensHashTable(); + + code = Tcl_PkgProvide(interp, "Pkgua", "1.0"); + if (code != TCL_OK) { + return code; + } + + Tcl_SetVar(interp, "::pkgua_loaded", ".", TCL_APPEND_VALUE); + + cmdTokens = PkguaInterpToTokens(interp); + cmdTokens[cmdIndex++] = + Tcl_CreateObjCommand(interp, "pkgua_eq", PkguaEqObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + cmdTokens[cmdIndex++] = + Tcl_CreateObjCommand(interp, "pkgua_quote", PkguaQuoteObjCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgua_SafeInit -- + * + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an unsafe interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgua_SafeInit( + Tcl_Interp *interp) /* Interpreter in which the package is to be + * made available. */ +{ + return Pkgua_Init(interp); +} + +/* + *---------------------------------------------------------------------- + * + * Pkgua_Unload -- + * + * This is a package unloading initialization procedure, which is called + * by Tcl when this package is to be unloaded form an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgua_Unload( + Tcl_Interp *interp, /* Interpreter from which the package is to be + * unloaded. */ + int flags) /* Flags passed by the unloading mechanism */ +{ + int code, cmdIndex; + Tcl_Command *cmdTokens = PkguaInterpToTokens(interp); + + for (cmdIndex=0 ; cmdIndex<MAX_REGISTERED_COMMANDS ; cmdIndex++) { + if (cmdTokens[cmdIndex] == NULL) { + continue; + } + code = Tcl_DeleteCommandFromToken(interp, cmdTokens[cmdIndex]); + if (code != TCL_OK) { + return code; + } + } + + PkguaDeleteTokens(interp); + + Tcl_SetVar(interp, "::pkgua_detached", ".", TCL_APPEND_VALUE); + + if (flags == TCL_UNLOAD_DETACH_FROM_PROCESS) { + /* + * Tcl is ready to detach this library from the running application. + * We should free all the memory that is not related to any + * interpreter. + */ + + PkguaFreeTokensHashTable(); + Tcl_SetVar(interp, "::pkgua_unloaded", ".", TCL_APPEND_VALUE); + } + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Pkgua_SafeUnload -- + * + * This is a package unloading initialization procedure, which is called + * by Tcl when this package is to be unloaded form an interpreter. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +Pkgua_SafeUnload( + Tcl_Interp *interp, /* Interpreter from which the package is to be + * unloaded. */ + int flags) /* Flags passed by the unloading mechanism */ +{ + return Pkgua_Unload(interp, flags); +} |