-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcltest.c
157 lines (145 loc) · 3.25 KB
/
tcltest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* tclTest.c --
*
* Test driver for TCL.
*
* Copyright 1987-1991 Regents of the University of California
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appears in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /user6/ouster/tcl/tclTest/RCS/tclTest.c,v 1.21 92/01/19 14:15:27 ouster Exp $ SPRITE (Berkeley)";
#endif
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "tcl.h"
extern int exit();
extern int Tcl_DumpActiveMemory();
Tcl_Interp *interp;
Tcl_CmdBuf buffer;
char dumpFile[100];
int quitFlag = 0;
char *initCmd =
"if [file exists [info library]/init.tcl] {source [info library]/init.tcl}";
/* ARGSUSED */
int
cmdCheckmem(clientData, interp, argc, argv)
ClientData clientData;
Tcl_Interp *interp;
int argc;
char *argv[];
{
if (argc != 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" fileName\"", (char *) NULL);
return TCL_ERROR;
}
strcpy(dumpFile, argv[1]);
quitFlag = 1;
return TCL_OK;
}
/* ARGSUSED */
int
cmdEcho(clientData, interp, argc, argv)
ClientData clientData;
Tcl_Interp *interp;
int argc;
char *argv[];
{
int i;
for (i = 1; ; i++) {
if (argv[i] == NULL) {
if (i != argc) {
echoError:
sprintf(interp->result,
"argument list wasn't properly NULL-terminated in \"%s\" command",
argv[0]);
}
break;
}
if (i >= argc) {
goto echoError;
}
fputs(argv[i], stdout);
if (i < (argc-1)) {
printf(" ");
}
}
printf("\n");
return TCL_OK;
}
int
main()
{
char line[1000], *cmd;
int result, gotPartial;
interp = Tcl_CreateInterp();
#ifdef TCL_MEM_DEBUG
Tcl_InitMemory(interp);
#endif
Tcl_CreateCommand(interp, "echo", cmdEcho, (ClientData) "echo",
(Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(interp, "checkmem", cmdCheckmem, (ClientData) 0,
(Tcl_CmdDeleteProc *) NULL);
buffer = Tcl_CreateCmdBuf();
#ifndef TCL_GENERIC_ONLY
result = Tcl_Eval(interp, initCmd, 0, (char **) NULL);
if (result != TCL_OK) {
printf("%s\n", interp->result);
exit(1);
}
#endif
gotPartial = 0;
while (1) {
clearerr(stdin);
if (!gotPartial) {
fputs("% ", stdout);
fflush(stdout);
}
if (fgets(line, 1000, stdin) == NULL) {
if (!gotPartial) {
exit(0);
}
line[0] = 0;
}
cmd = Tcl_AssembleCmd(buffer, line);
if (cmd == NULL) {
gotPartial = 1;
continue;
}
gotPartial = 0;
result = Tcl_RecordAndEval(interp, cmd, 0);
if (result == TCL_OK) {
if (*interp->result != 0) {
printf("%s\n", interp->result);
}
if (quitFlag) {
Tcl_DeleteInterp(interp);
Tcl_DeleteCmdBuf(buffer);
#ifdef TCL_MEM_DEBUG
Tcl_DumpActiveMemory(dumpFile);
#endif
exit(0);
}
} else {
if (result == TCL_ERROR) {
printf("Error");
} else {
printf("Error %d", result);
}
if (*interp->result != 0) {
printf(": %s\n", interp->result);
} else {
printf("\n");
}
}
}
}