A C code extension for a crypt command is quite simply, when
an existent implementation (normal in the UNIX libraries)
can be used.
Here is one, that I use:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tcl.h>


/*--------------------------------------------------------------
|
\-------------------------------------------------------------*/
int
tcl_crypt(
    ClientData  dummy,   /* Not used. */
    Tcl_Interp *interp,  /* Current interpreter. */
    int         argc,    /* Number of arguments. */
    char       *argv[]   /* Argument strings. */
)
{
    if (argc < 3) {
        Tcl_AppendResult(interp, "crypt <password> <salt>", (char *) NULL);
        return TCL_ERROR;
    }
    Tcl_AppendResult(interp, crypt(argv[1], argv[2]), (char *) NULL);
    return TCL_OK;
}


/*--------------------------------------------------------------
|
\-------------------------------------------------------------*/
int
TclWWW_Init(
    Tcl_Interp *interp
)
{
    Tcl_CreateCommand(interp, "crypt", tcl_crypt,
        (ClientData)0L,(void (*)()) NULL);

    return TCL_OK;
}

You can call TclWWW_Init in the initialization part of a tclsh/wish.
In the case you want a separate package use the following 
package initialization function instead of TclWWW_Init:

int
Crypt_Init(interp)
    Tcl_Interp *interp;         /* Interpreter in which the package is
                                 * to be made available. */
{

    if (Tcl_PkgProvide(interp, "Crypt", "1.0")  != TCL_OK) {
        return TCL_ERROR;
    }

    Tcl_CreateCommand(interp, "crypt", tcl_crypt,
                      (ClientData)0L,
                      (void (*)()) NULL);
    return TCL_OK;
}

If compiled into a shared library and installed, the usage in Tcl would be then:

  package require crypt 

Best regards
Jochen


>
>On Sun, 28 Sep 1997, Mixer wrote:
>
>> Well I don't have any experience with calling or using extensions, but I did just 
>write a little perl script to do the crypt and called it from the script. Is there a 
>place that you would know of on the net where I could get the info that I need about 
>ext
>> ensions and how to use them?
>
>There are examples in Ousterhout's and Welch's books. Other than that,
>perhaps there's mention in the FAQ's that Larry takes care of.
>
>...RickM...
>
>---------------------------------------------------------------------------
>To unsubscribe from the Visual Tcl mailing list, please send a message
>to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
>message body (where [EMAIL PROTECTED] is your e-mail address).
>


--
-----------------------------------------------------------------------
Jochen Loewer             HP - CSDE Boeblingen        778-6882 (TELnet)
mailto:[EMAIL PROTECTED]           ++49-(0)7031-14-6882  (phone)
-----------------------------------------------------------------------
---------------------------------------------------------------------------
To unsubscribe from the Visual Tcl mailing list, please send a message
to [EMAIL PROTECTED] with "unsubscribe vtcl [EMAIL PROTECTED]" in the
message body (where [EMAIL PROTECTED] is your e-mail address).

Reply via email to