Tcl Extension Architecture (TEA) Sample Extension

Check-in [d6489437c8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Little changes, enough to make everything compile with a C++ compiler
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d6489437c8395f899368fe77a5e3c339de39ab6fb0426c90787ac8dd4d447c8e
User & Date: jan.nijtmans 2019-08-30 15:15:35.600
Context
2019-08-30
15:16
Update to latest TEA and latest nmake build files check-in: 976e90dcdf user: jan.nijtmans tags: trunk
15:15
Little changes, enough to make everything compile with a C++ compiler check-in: d6489437c8 user: jan.nijtmans tags: trunk
2018-08-13
08:30
Replace broken autoconf tokens. Untangle CFLAGS_DEFAULT, CFLAGS_WARNING, and SHLIB_CFLAGS from CFLAGS. check-in: 4767411521 user: pooryorick tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/sample.c.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 * Side effects:
 *	Contents of state pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void
SHA1Transform(state, buffer)
    sha_uint32_t state[5];	/* State variable */
    unsigned char buffer[64];	/* Modified buffer */
{
#if (!defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN))
    unsigned char *p;
#endif
    sha_uint32_t a, b, c, d, e;
    typedef union {
	unsigned char c[64];







|
|
|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 * Side effects:
 *	Contents of state pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void
SHA1Transform(
    sha_uint32_t state[5],	/* State variable */
    unsigned char buffer[64])	/* Modified buffer */
{
#if (!defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN))
    unsigned char *p;
#endif
    sha_uint32_t a, b, c, d, e;
    typedef union {
	unsigned char c[64];
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
 *
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void SHA1Init(context)
    SHA1_CTX* context;		/* Context to initialize */
{
    /*
     * SHA1 initialization constants
     */

    context->state[0] = 0x67452301;
    context->state[1] = 0xEFCDAB89;







|
|







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
 *
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void SHA1Init(
    SHA1_CTX* context)		/* Context to initialize */
{
    /*
     * SHA1 initialization constants
     */

    context->state[0] = 0x67452301;
    context->state[1] = 0xEFCDAB89;
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void
SHA1Update(context, data, len)
    SHA1_CTX* context;		/* Context to update */
    unsigned char* data;	/* Data used for update */
    unsigned int len;		/* Length of data */
{
    unsigned int i, j;

    j = (context->count[0] >> 3) & 63;
    if ((context->count[0] += len << 3) < (len << 3)) {
	context->count[1]++;
    }







|
|
|
|







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void
SHA1Update(
    SHA1_CTX* context,		/* Context to update */
    unsigned char* data,	/* Data used for update */
    unsigned int len)		/* Length of data */
{
    unsigned int i, j;

    j = (context->count[0] >> 3) & 63;
    if ((context->count[0] += len << 3) < (len << 3)) {
	context->count[1]++;
    }
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
 *
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void SHA1Final(context, digest)
    SHA1_CTX* context;		/* Context to pad */
    unsigned char digest[20];	/* Returned message digest */
{
    sha_uint32_t i, j;
    unsigned char finalcount[8];

    for (i = 0; i < 8; i++) {
	/*
	 * This statement is independent of the endianness







|
|
|







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
 *
 * Side effects:
 *	Contents of context pointer are changed.
 *
 *----------------------------------------------------------------------
 */

void SHA1Final(
    SHA1_CTX* context,		/* Context to pad */
    unsigned char digest[20])	/* Returned message digest */
{
    sha_uint32_t i, j;
    unsigned char finalcount[8];

    for (i = 0; i < 8; i++) {
	/*
	 * This statement is independent of the endianness
Changes to generic/tclsample.c.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sample.h"

#define TCL_READ_CHUNK_SIZE 4096

static unsigned char itoa64f[] =
        "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_,";

static int numcontexts = 0;
static SHA1_CTX *sha1Contexts = NULL;
static int *ctxtotalRead = NULL;

static int Sha1_Cmd(ClientData clientData, Tcl_Interp *interp,







|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sample.h"

#define TCL_READ_CHUNK_SIZE 4096

static const unsigned char itoa64f[] =
        "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_,";

static int numcontexts = 0;
static SHA1_CTX *sha1Contexts = NULL;
static int *ctxtotalRead = NULL;

static int Sha1_Cmd(ClientData clientData, Tcl_Interp *interp,
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
Sha1_Cmd(
    ClientData clientData,	/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter */
    int objc,			/* Number of arguments */
    Tcl_Obj *const objv[]	/* Argument strings */
    )
{
    /*
     * The default base is hex







|







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
Sha1_Cmd(
    ClientData dummy,	/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter */
    int objc,			/* Number of arguments */
    Tcl_Obj *const objv[]	/* Argument strings */
    )
{
    /*
     * The default base is hex
75
76
77
78
79
80
81

82
83
84
85
86
87
88
    char *bufPtr;
    int maxbytes = 0;
    int doinit = 1;
    int dofinal = 1;
    Tcl_Obj *descriptorObj = NULL;
    int totalRead = 0;
    int i, j, n, mask, bits, offset;


    /*
     * For binary representation + null char
     */

    char buf[129];
    unsigned char digest[DIGESTSIZE];







>







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    char *bufPtr;
    int maxbytes = 0;
    int doinit = 1;
    int dofinal = 1;
    Tcl_Obj *descriptorObj = NULL;
    int totalRead = 0;
    int i, j, n, mask, bits, offset;
    (void)dummy;

    /*
     * For binary representation + null char
     */

    char buf[129];
    unsigned char digest[DIGESTSIZE];
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
		/*
		 * Allocate a new context.
		 */

		numcontexts++;
		sha1Contexts = (SHA1_CTX *) realloc((void *) sha1Contexts,
			numcontexts * sizeof(SHA1_CTX));
		ctxtotalRead = realloc((void *) ctxtotalRead,
			numcontexts * sizeof(int));
	    }
	    ctxtotalRead[contextnum] = 0;
	    SHA1Init(&sha1Context);
	    sprintf(buf, "sha1%d", contextnum);
	    Tcl_AppendResult(interp, buf, (char *)NULL);
	    return TCL_OK;
	case SHAOPT_CHAN:
	    chan = Tcl_GetChannel(interp, Tcl_GetString(objv[a]), &mode);
	    if (chan == (Tcl_Channel) NULL) {
		return TCL_ERROR;
	    }
	    if ((mode & TCL_READABLE) == 0) {







|





|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
		/*
		 * Allocate a new context.
		 */

		numcontexts++;
		sha1Contexts = (SHA1_CTX *) realloc((void *) sha1Contexts,
			numcontexts * sizeof(SHA1_CTX));
		ctxtotalRead = (int *)realloc(ctxtotalRead,
			numcontexts * sizeof(int));
	    }
	    ctxtotalRead[contextnum] = 0;
	    SHA1Init(&sha1Context);
	    sprintf(buf, "sha1%d", contextnum);
	    Tcl_AppendResult(interp, buf, NULL);
	    return TCL_OK;
	case SHAOPT_CHAN:
	    chan = Tcl_GetChannel(interp, Tcl_GetString(objv[a]), &mode);
	    if (chan == (Tcl_Channel) NULL) {
		return TCL_ERROR;
	    }
	    if ((mode & TCL_READABLE) == 0) {
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
	char *string;
	if (chan != (Tcl_Channel) NULL) {
	    goto wrongArgs;
	}
	string = Tcl_GetStringFromObj(stringObj, &totalRead);
	SHA1Update(&sha1Context, (unsigned char *) string, totalRead);
    } else if (chan != (Tcl_Channel) NULL) {
	bufPtr = ckalloc((unsigned) TCL_READ_CHUNK_SIZE);
	totalRead = 0;
	while ((n = Tcl_Read(chan, bufPtr,
		maxbytes == 0
		? TCL_READ_CHUNK_SIZE
		: (TCL_READ_CHUNK_SIZE < maxbytes
		? TCL_READ_CHUNK_SIZE
		: maxbytes))) != 0) {







|







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	char *string;
	if (chan != (Tcl_Channel) NULL) {
	    goto wrongArgs;
	}
	string = Tcl_GetStringFromObj(stringObj, &totalRead);
	SHA1Update(&sha1Context, (unsigned char *) string, totalRead);
    } else if (chan != (Tcl_Channel) NULL) {
	bufPtr = (char *)ckalloc(TCL_READ_CHUNK_SIZE);
	totalRead = 0;
	while ((n = Tcl_Read(chan, bufPtr,
		maxbytes == 0
		? TCL_READ_CHUNK_SIZE
		: (TCL_READ_CHUNK_SIZE < maxbytes
		? TCL_READ_CHUNK_SIZE
		: maxbytes))) != 0) {
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    	    offset += 8;
        }
        offset -= n;
        buf[j++] = itoa64f[(bits>>8)&mask];
    }
    buf[j++] = itoa64f[(bits>>8)&mask];
    buf[j++] = '\0';
    Tcl_AppendResult (interp, buf, (char *)NULL);
    if (contextnum > 0) {
	ctxtotalRead[contextnum] = -1;
    }
    return TCL_OK;

wrongArgs:
    Tcl_AppendResult (interp, "wrong # args: should be either:\n",
	    "  ",
	    Tcl_GetString(objv[0]),
	    " ?-log2base log2base? -string string\n",
	    " or\n",
	    "  ",
	    Tcl_GetString(objv[0]),
	    " ?-log2base log2base? ?-copychan chanID? -chan chanID\n",







|






|







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
    	    offset += 8;
        }
        offset -= n;
        buf[j++] = itoa64f[(bits>>8)&mask];
    }
    buf[j++] = itoa64f[(bits>>8)&mask];
    buf[j++] = '\0';
    Tcl_AppendResult(interp, buf, NULL);
    if (contextnum > 0) {
	ctxtotalRead[contextnum] = -1;
    }
    return TCL_OK;

wrongArgs:
    Tcl_AppendResult(interp, "wrong # args: should be either:\n",
	    "  ",
	    Tcl_GetString(objv[0]),
	    " ?-log2base log2base? -string string\n",
	    " or\n",
	    "  ",
	    Tcl_GetString(objv[0]),
	    " ?-log2base log2base? ?-copychan chanID? -chan chanID\n",
338
339
340
341
342
343
344



345
346
347
348
349
350
351
352
 * Side effects:
 *	The Sample package is created.
 *	One new command "sha1" is added to the Tcl interpreter.
 *
 *----------------------------------------------------------------------
 */




int
Sample_Init(Tcl_Interp *interp)
{
    /*
     * This may work with 8.0, but we are using strictly stubs here,
     * which requires 8.1.
     */
    if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {







>
>
>
|







339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
 * Side effects:
 *	The Sample package is created.
 *	One new command "sha1" is added to the Tcl interpreter.
 *
 *----------------------------------------------------------------------
 */

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */
DLLEXPORT int
Sample_Init(Tcl_Interp *interp)
{
    /*
     * This may work with 8.0, but we are using strictly stubs here,
     * which requires 8.1.
     */
    if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
361
362
363
364
365
366
367



    numcontexts = 1;
    sha1Contexts = (SHA1_CTX *) malloc(sizeof(SHA1_CTX));
    ctxtotalRead = (int *) malloc(sizeof(int));
    ctxtotalRead[0] = 0;

    return TCL_OK;
}










>
>
>
365
366
367
368
369
370
371
372
373
374
    numcontexts = 1;
    sha1Contexts = (SHA1_CTX *) malloc(sizeof(SHA1_CTX));
    ctxtotalRead = (int *) malloc(sizeof(int));
    ctxtotalRead[0] = 0;

    return TCL_OK;
}
#ifdef __cplusplus
}
#endif  /* __cplusplus */