From: nishi Date: Tue, 6 Feb 2024 10:53:55 +0000 (+0000) Subject: bugfix X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=d690b76d721ae728e59d7eea94232ba68aa96419;p=libw3.git bugfix git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@180 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Library/Tcl.c b/Library/Tcl.c index 93688d5..03c58a5 100644 --- a/Library/Tcl.c +++ b/Library/Tcl.c @@ -20,8 +20,8 @@ void tcl_w3_data_handler(struct W3* w3, char* data, size_t size) { for(i = 0; __dictionary[i] != NULL; i += 2) { if(__dictionary[i + 1] == w3) { if(w3->tcl_data != NULL) { + write(1, data, size); Tcl_ObjSetVar2(w3->tcl_in, Tcl_NewStringObj("event_size", 10), NULL, Tcl_NewLongObj(size), 0); - Tcl_ObjSetVar2(w3->tcl_in, Tcl_NewStringObj("event_data", 10), NULL, Tcl_NewStringObj(data, size), 0); char* data1 = malloc(size + 1); memcpy(data1, data, size); data1[size] = 0; @@ -33,7 +33,6 @@ void tcl_w3_data_handler(struct W3* w3, char* data, size_t size) { free(data1); Tcl_UnsetVar(w3->tcl_in, "event_data_nulend", 0); Tcl_UnsetVar(w3->tcl_in, "event_size", 0); - Tcl_UnsetVar(w3->tcl_in, "event_data", 0); } } } @@ -180,9 +179,9 @@ int Tcl_W3FIOCmd(ClientData dummy, Tcl_Interp* interp, int objc, Tcl_Obj* CONST __files[incr] = oldfiles[incr]; __files[incr + 1] = oldfiles[incr + 1]; incr += 2; - printf("woo"); } - oldfiles[incr] = NULL; + __files[incr] = NULL; + free(oldfiles); Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); return TCL_OK; } @@ -211,6 +210,16 @@ int Tcl_W3Cmd(ClientData dummy, Tcl_Interp* interp, int objc, Tcl_Obj* CONST obj return TCL_ERROR; } char* name = Tcl_GetString(objv[2]); + if(__dictionary != NULL){ + int i; + for(i = 0; __dictionary[i] != NULL; i += 2){ + if(strcasecmp(__dictionary[i], name) == 0){ + const char* errmsg = "argument error: a client named that already exists"; + Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); + return TCL_ERROR; + } + } + } char* protocol = Tcl_GetString(objv[3]); char* hostname = Tcl_GetString(objv[4]); int port = atoi(Tcl_GetString(objv[5])); @@ -339,6 +348,48 @@ int Tcl_W3Cmd(ClientData dummy, Tcl_Interp* interp, int objc, Tcl_Obj* CONST obj const char* errmsg = "argument error: a client named that does not exist"; Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); } + } else if(strcasecmp(subcommand, "destroy") == 0) { + if(objc != 3) { + const char* errmsg = "argument error: arguments should be \"w3 destroy name\""; + Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); + return TCL_ERROR; + } + char* name = Tcl_GetString(objv[2]); + if(__dictionary == NULL) { + const char* errmsg = "argument error: a client named that does not exist"; + Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); + } else { + int i; + int except = -1; + int len = 0; + for(i = 0; __dictionary[i] != NULL; i += 2) { + if(strcasecmp((char*)__dictionary[i], name) == 0) { + W3_Free(__dictionary[i + 1]); + free(__dictionary[i]); + except = i; + break; + } + } + for(len = 0; __dictionary[len] != NULL; len++) + ; + if(except != -1) { + void** olddict = __dictionary; + __dictionary = malloc(sizeof(*__dictionary) * (len - 1)); + int incr = 0; + for(i = 0; olddict[i] != NULL; i += 2) { + if(except == i) continue; + __dictionary[incr] = olddict[incr]; + __dictionary[incr + 1] = olddict[incr + 1]; + incr += 2; + } + __dictionary[incr] = NULL; + free(olddict); + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + return TCL_OK; + } + const char* errmsg = "argument error: a client named that does not exist"; + Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); + } } else { const char* errmsg = "argument error: invalid subcommand"; Tcl_SetObjResult(interp, Tcl_NewStringObj(errmsg, strlen(errmsg))); diff --git a/W3Version.h.p b/W3Version.h.p index 0fb1423..8388dfe 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.3B" \ +#define LIBW3_VERSION "2.3C" \ SUFFIX #ifdef __cplusplus