summaryrefslogtreecommitdiffstats
path: root/generic/tclMain.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclMain.c')
-rw-r--r--generic/tclMain.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/generic/tclMain.c b/generic/tclMain.c
index 5083383..7bc9516 100644
--- a/generic/tclMain.c
+++ b/generic/tclMain.c
@@ -53,7 +53,7 @@ NewNativeObj(
Tcl_DStringInit(&ds);
Tcl_WCharToUtfDString(string, -1, &ds);
#else
- Tcl_ExternalToUtfDString(NULL, (char *)string, -1, &ds);
+ (void)Tcl_ExternalToUtfDString(NULL, (char *)string, -1, &ds);
#endif
return TclDStringToObj(&ds);
}
@@ -194,7 +194,7 @@ Tcl_GetStartupScript(
if (tsdPtr->encoding == NULL) {
*encodingPtr = NULL;
} else {
- *encodingPtr = Tcl_GetString(tsdPtr->encoding);
+ *encodingPtr = TclGetString(tsdPtr->encoding);
}
}
return tsdPtr->path;
@@ -245,7 +245,7 @@ Tcl_SourceRCFile(
c = Tcl_OpenFileChannel(NULL, fullName, "r", 0);
if (c != NULL) {
- Tcl_Close(NULL, c);
+ Tcl_CloseEx(NULL, c, 0);
if (Tcl_EvalFile(interp, fullName) != TCL_OK) {
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan) {
@@ -278,9 +278,9 @@ Tcl_SourceRCFile(
*----------------------------------------------------------------------
*/
-void
+TCL_NORETURN void
Tcl_MainEx(
- int argc, /* Number of arguments. */
+ size_t argc, /* Number of arguments. */
TCHAR **argv, /* Array of argument strings. */
Tcl_AppInitProc *appInitProc,
/* Application-specific initialization
@@ -288,7 +288,7 @@ Tcl_MainEx(
* but before starting to execute commands. */
Tcl_Interp *interp)
{
- int i=0; /* argv[i] index */
+ size_t i=0; /* argv[i] index */
Tcl_Obj *path, *resultPtr, *argvPtr, *appName;
const char *encodingName = NULL;
int code, exitCode = 0;
@@ -297,8 +297,8 @@ Tcl_MainEx(
InteractiveState is;
TclpSetInitialEncodings();
- if (0 < argc) {
- --argc; /* "consume" argv[0] */
+ if (argc + 1 > 1) {
+ --argc; /* consume argv[0] */
++i;
}
TclpFindExecutable ((const char *)argv [0]); /* nb: this could be NULL
@@ -326,15 +326,15 @@ Tcl_MainEx(
*/
/* mind argc is being adjusted as we proceed */
- if ((argc >= 3) && (0 == _tcscmp(TEXT("-encoding"), argv[1]))
+ if ((argc >= 3) && argv[1] && argv[2] && argv[3] && (0 == _tcscmp(TEXT("-encoding"), argv[1]))
&& ('-' != argv[3][0])) {
Tcl_Obj *value = NewNativeObj(argv[2]);
Tcl_SetStartupScript(NewNativeObj(argv[3]),
- Tcl_GetString(value));
+ TclGetString(value));
Tcl_DecrRefCount(value);
argc -= 3;
i += 3;
- } else if ((argc >= 1) && ('-' != argv[1][0])) {
+ } else if ((argc >= 1) && argv[1] && ('-' != argv[1][0])) {
Tcl_SetStartupScript(NewNativeObj(argv[1]), NULL);
argc--;
i++;
@@ -342,17 +342,19 @@ Tcl_MainEx(
}
path = Tcl_GetStartupScript(&encodingName);
- if (path == NULL) {
+ if (path != NULL) {
+ appName = path;
+ } else if (argv[0]) {
appName = NewNativeObj(argv[0]);
} else {
- appName = path;
+ appName = Tcl_NewStringObj("tclsh", -1);
}
Tcl_SetVar2Ex(interp, "argv0", NULL, appName, TCL_GLOBAL_ONLY);
Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewWideIntObj(argc), TCL_GLOBAL_ONLY);
argvPtr = Tcl_NewListObj(0, NULL);
- while (argc--) {
+ while (argc-- && argv[i]) {
Tcl_ListObjAppendElement(NULL, argvPtr, NewNativeObj(argv[i++]));
}
Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY);
@@ -452,7 +454,7 @@ Tcl_MainEx(
while ((is.input != NULL) && !Tcl_InterpDeleted(interp)) {
mainLoopProc = TclGetMainLoop();
if (mainLoopProc == NULL) {
- int length;
+ size_t length;
if (is.tty) {
Prompt(interp, &is);
@@ -473,7 +475,7 @@ Tcl_MainEx(
Tcl_IncrRefCount(is.commandPtr);
}
length = Tcl_GetsObj(is.input, is.commandPtr);
- if (length < 0) {
+ if (length == TCL_INDEX_NONE) {
if (Tcl_InputBlocked(is.input)) {
/*
* This can only happen if stdin has been set to
@@ -738,7 +740,7 @@ StdinProc(
TCL_UNUSED(int) /*mask*/)
{
int code;
- int length;
+ size_t length;
InteractiveState *isPtr = (InteractiveState *)clientData;
Tcl_Channel chan = isPtr->input;
Tcl_Obj *commandPtr = isPtr->commandPtr;
@@ -750,7 +752,7 @@ StdinProc(
Tcl_IncrRefCount(commandPtr);
}
length = Tcl_GetsObj(chan, commandPtr);
- if (length < 0) {
+ if (length == TCL_INDEX_NONE) {
if (Tcl_InputBlocked(chan)) {
return;
}