summaryrefslogtreecommitdiffstats
path: root/generic/tclIOGT.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclIOGT.c')
-rw-r--r--generic/tclIOGT.c166
1 files changed, 73 insertions, 93 deletions
diff --git a/generic/tclIOGT.c b/generic/tclIOGT.c
index 4d5c0b3..7ba2f2a 100644
--- a/generic/tclIOGT.c
+++ b/generic/tclIOGT.c
@@ -4,8 +4,8 @@
* Implements a generic transformation exposing the underlying API at the
* script level. Contributed by Andreas Kupries.
*
- * Copyright © 2000 Ajuba Solutions
- * Copyright © 1999-2000 Andreas Kupries (a.kupries@westend.com)
+ * Copyright (c) 2000 Ajuba Solutions
+ * Copyright (c) 1999-2000 Andreas Kupries (a.kupries@westend.com)
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -22,15 +22,13 @@
static int TransformBlockModeProc(ClientData instanceData,
int mode);
static int TransformCloseProc(ClientData instanceData,
- Tcl_Interp *interp, int flags);
+ Tcl_Interp *interp);
static int TransformInputProc(ClientData instanceData, char *buf,
int toRead, int *errorCodePtr);
static int TransformOutputProc(ClientData instanceData,
const char *buf, int toWrite, int *errorCodePtr);
-#ifndef TCL_NO_DEPRECATED
static int TransformSeekProc(ClientData instanceData, long offset,
int mode, int *errorCodePtr);
-#endif
static int TransformSetOptionProc(ClientData instanceData,
Tcl_Interp *interp, const char *optionName,
const char *value);
@@ -41,8 +39,8 @@ static void TransformWatchProc(ClientData instanceData, int mask);
static int TransformGetFileHandleProc(ClientData instanceData,
int direction, ClientData *handlePtr);
static int TransformNotifyProc(ClientData instanceData, int mask);
-static long long TransformWideSeekProc(ClientData instanceData,
- long long offset, int mode, int *errorCodePtr);
+static Tcl_WideInt TransformWideSeekProc(ClientData instanceData,
+ Tcl_WideInt offset, int mode, int *errorCodePtr);
/*
* Forward declarations of internal procedures. Secondly the procedures for
@@ -108,7 +106,7 @@ typedef struct ResultBuffer ResultBuffer;
static inline void ResultClear(ResultBuffer *r);
static inline void ResultInit(ResultBuffer *r);
static inline int ResultEmpty(ResultBuffer *r);
-static inline size_t ResultCopy(ResultBuffer *r, unsigned char *buf,
+static inline int ResultCopy(ResultBuffer *r, unsigned char *buf,
size_t toRead);
static inline void ResultAdd(ResultBuffer *r, unsigned char *buf,
size_t toWrite);
@@ -118,22 +116,18 @@ static inline void ResultAdd(ResultBuffer *r, unsigned char *buf,
* transformations.
*/
-static const Tcl_ChannelType transformChannelType = {
+static Tcl_ChannelType transformChannelType = {
"transform", /* Type name. */
TCL_CHANNEL_VERSION_5, /* v5 channel */
- TCL_CLOSE2PROC, /* Close proc. */
+ TransformCloseProc, /* Close proc. */
TransformInputProc, /* Input proc. */
TransformOutputProc, /* Output proc. */
-#ifndef TCL_NO_DEPRECATED
TransformSeekProc, /* Seek proc. */
-#else
- NULL, /* Seek proc. */
-#endif
TransformSetOptionProc, /* Set option proc. */
TransformGetOptionProc, /* Get option proc. */
TransformWatchProc, /* Initialize notifier. */
TransformGetFileHandleProc, /* Get OS handles out of channel. */
- TransformCloseProc, /* close2proc */
+ NULL, /* close2proc */
TransformBlockModeProc, /* Set blocking/nonblocking mode.*/
NULL, /* Flush proc. */
TransformNotifyProc, /* Handling of events bubbling up. */
@@ -217,7 +211,7 @@ struct TransformChannelData {
* a transformation of incoming data. Also
* serves as buffer of all data not yet
* consumed by the reader. */
- size_t refCount;
+ int refCount;
};
static void
@@ -231,12 +225,12 @@ static void
ReleaseData(
TransformChannelData *dataPtr)
{
- if (dataPtr->refCount-- > 1) {
+ if (--dataPtr->refCount) {
return;
}
ResultClear(&dataPtr->result);
Tcl_DecrRefCount(dataPtr->command);
- ckfree(dataPtr);
+ ckfree((char *) dataPtr);
}
/*
@@ -257,6 +251,7 @@ ReleaseData(
*----------------------------------------------------------------------
*/
+ /* ARGSUSED */
int
TclChannelTransform(
Tcl_Interp *interp, /* Interpreter for result. */
@@ -266,7 +261,7 @@ TclChannelTransform(
Channel *chanPtr; /* The actual channel. */
ChannelState *statePtr; /* State info for channel. */
int mode; /* Read/write mode of the channel. */
- Tcl_Size objc;
+ int objc;
TransformChannelData *dataPtr;
Tcl_DString ds;
@@ -274,7 +269,7 @@ TclChannelTransform(
return TCL_ERROR;
}
- if (TCL_OK != TclListObjLength(interp, cmdObjPtr, &objc)) {
+ if (TCL_OK != Tcl_ListObjLength(interp, cmdObjPtr, &objc)) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("-command value is not a list", -1));
return TCL_ERROR;
@@ -292,7 +287,7 @@ TclChannelTransform(
* regime of the underlying channel and to use the same for us too.
*/
- dataPtr = (TransformChannelData *)ckalloc(sizeof(TransformChannelData));
+ dataPtr = (TransformChannelData *) ckalloc(sizeof(TransformChannelData));
dataPtr->refCount = 1;
Tcl_DStringInit(&ds);
@@ -318,8 +313,8 @@ TclChannelTransform(
dataPtr->self = Tcl_StackChannel(interp, &transformChannelType, dataPtr,
mode, chan);
if (dataPtr->self == NULL) {
- Tcl_AppendPrintfToObj(Tcl_GetObjResult(interp),
- "\nfailed to stack channel \"%s\"", Tcl_GetChannelName(chan));
+ Tcl_AppendResult(interp, "\nfailed to stack channel \"",
+ Tcl_GetChannelName(chan), "\"", NULL);
ReleaseData(dataPtr);
return TCL_ERROR;
}
@@ -383,7 +378,7 @@ ExecuteCallback(
* interpreters. */
{
Tcl_Obj *resObj; /* See below, switch (transmit). */
- Tcl_Size resLen;
+ int resLen;
unsigned char *resBuf;
Tcl_InterpState state = NULL;
int res = TCL_OK;
@@ -409,7 +404,7 @@ ExecuteCallback(
/*
* Use a byte-array to prevent the misinterpretation of binary data coming
- * through as Utf while at the tcl level.
+ * through as UTF while at the tcl level.
*/
Tcl_ListObjAppendElement(NULL, command, Tcl_NewByteArrayObj(buf, bufLen));
@@ -417,7 +412,7 @@ ExecuteCallback(
/*
* Step 2, execute the command at the global level of the interpreter used
* to create the transformation. Destroy the command afterward. If an
- * error occurred and the current interpreter is defined and not equal to
+ * error occured and the current interpreter is defined and not equal to
* the interpreter for the callback, then copy the error message into
* current interpreter. Don't copy if in preservation mode.
*/
@@ -508,7 +503,7 @@ TransformBlockModeProc(
ClientData instanceData, /* State of transformation. */
int mode) /* New blocking mode. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
if (mode == TCL_MODE_NONBLOCKING) {
dataPtr->flags |= CHANNEL_ASYNC;
@@ -538,14 +533,9 @@ TransformBlockModeProc(
static int
TransformCloseProc(
ClientData instanceData,
- Tcl_Interp *interp,
- int flags)
+ Tcl_Interp *interp)
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
-
- if ((flags & (TCL_CLOSE_READ | TCL_CLOSE_WRITE)) != 0) {
- return EINVAL;
- }
+ TransformChannelData *dataPtr = instanceData;
/*
* Important: In this procedure 'dataPtr->self' already points to the
@@ -568,7 +558,7 @@ TransformCloseProc(
* Now flush data waiting in internal buffers to output and input. The
* input must be done despite the fact that there is no real receiver for
* it anymore. But the scripts might have sideeffects other parts of the
- * system rely on (f.e. signalling the close to interested parties).
+ * system rely on (f.e. signaling the close to interested parties).
*/
PreserveData(dataPtr);
@@ -626,7 +616,7 @@ TransformInputProc(
int toRead,
int *errorCodePtr)
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
int gotBytes, read, copied;
Tcl_Channel downChan;
@@ -693,7 +683,7 @@ TransformInputProc(
* Already saw EOF from downChan; don't ask again.
* NOTE: Could move this up to avoid the last maxRead
* execution. Believe this would still be correct behavior,
- * but the test suite tests the whole command callback
+ * but the test suite tests the whole command callback
* sequence, so leave it unchanged for now.
*/
@@ -706,6 +696,7 @@ TransformInputProc(
read = Tcl_ReadRaw(downChan, buf, toRead);
if (read < 0) {
+
if (Tcl_InputBlocked(downChan) && (gotBytes > 0)) {
/*
* Zero bytes available from downChan because blocked.
@@ -793,7 +784,7 @@ TransformOutputProc(
int toWrite,
int *errorCodePtr)
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
/*
* Should assert(dataPtr->mode & TCL_WRITABLE);
@@ -838,7 +829,6 @@ TransformOutputProc(
*----------------------------------------------------------------------
*/
-#ifndef TCL_NO_DEPRECATED
static int
TransformSeekProc(
ClientData instanceData, /* The channel to manipulate. */
@@ -846,9 +836,9 @@ TransformSeekProc(
int mode, /* How to move. */
int *errorCodePtr) /* Location of error flag. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
Tcl_Channel parent = Tcl_GetStackedChannel(dataPtr->self);
- const Tcl_ChannelType *parentType = Tcl_GetChannelType(parent);
+ Tcl_ChannelType *parentType = Tcl_GetChannelType(parent);
Tcl_DriverSeekProc *parentSeekProc = Tcl_ChannelSeekProc(parentType);
if ((offset == 0) && (mode == SEEK_CUR)) {
@@ -885,7 +875,6 @@ TransformSeekProc(
return parentSeekProc(Tcl_GetChannelInstanceData(parent), offset, mode,
errorCodePtr);
}
-#endif
/*
*----------------------------------------------------------------------
@@ -907,24 +896,22 @@ TransformSeekProc(
*----------------------------------------------------------------------
*/
-static long long
+static Tcl_WideInt
TransformWideSeekProc(
ClientData instanceData, /* The channel to manipulate. */
- long long offset, /* Size of movement. */
+ Tcl_WideInt offset, /* Size of movement. */
int mode, /* How to move. */
int *errorCodePtr) /* Location of error flag. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
Tcl_Channel parent = Tcl_GetStackedChannel(dataPtr->self);
- const Tcl_ChannelType *parentType = Tcl_GetChannelType(parent);
-#ifndef TCL_NO_DEPRECATED
+ Tcl_ChannelType *parentType = Tcl_GetChannelType(parent);
Tcl_DriverSeekProc *parentSeekProc = Tcl_ChannelSeekProc(parentType);
-#endif
Tcl_DriverWideSeekProc *parentWideSeekProc =
Tcl_ChannelWideSeekProc(parentType);
- void *parentData = Tcl_GetChannelInstanceData(parent);
+ ClientData parentData = Tcl_GetChannelInstanceData(parent);
- if ((offset == 0) && (mode == SEEK_CUR)) {
+ if ((offset == Tcl_LongAsWide(0)) && (mode == SEEK_CUR)) {
/*
* This is no seek but a request to tell the caller the current
* location. Simply pass the request down.
@@ -932,14 +919,10 @@ TransformWideSeekProc(
if (parentWideSeekProc != NULL) {
return parentWideSeekProc(parentData, offset, mode, errorCodePtr);
-#ifndef TCL_NO_DEPRECATED
- } else if (parentSeekProc) {
- return parentSeekProc(parentData, 0, mode, errorCodePtr);
-#endif
- } else {
- *errorCodePtr = EINVAL;
- return -1;
}
+
+ return Tcl_LongAsWide(parentSeekProc(parentData, 0, mode,
+ errorCodePtr));
}
/*
@@ -967,29 +950,25 @@ TransformWideSeekProc(
* If we have a wide seek capability, we should stick with that.
*/
- if (parentWideSeekProc == NULL) {
- /*
- * We're transferring to narrow seeks at this point; this is a bit complex
- * because we have to check whether the seek is possible first (i.e.
- * whether we are losing information in truncating the bits of the
- * offset). Luckily, there's a defined error for what happens when trying
- * to go out of the representable range.
- */
+ if (parentWideSeekProc != NULL) {
+ return parentWideSeekProc(parentData, offset, mode, errorCodePtr);
+ }
-#ifndef TCL_NO_DEPRECATED
- if (offset<LONG_MIN || offset>LONG_MAX) {
- *errorCodePtr = EOVERFLOW;
- return -1;
- }
+ /*
+ * We're transferring to narrow seeks at this point; this is a bit complex
+ * because we have to check whether the seek is possible first (i.e.
+ * whether we are losing information in truncating the bits of the
+ * offset). Luckily, there's a defined error for what happens when trying
+ * to go out of the representable range.
+ */
- return parentSeekProc(parentData, offset,
- mode, errorCodePtr);
-#else
- *errorCodePtr = EINVAL;
- return -1;
-#endif
+ if (offset<Tcl_LongAsWide(LONG_MIN) || offset>Tcl_LongAsWide(LONG_MAX)) {
+ *errorCodePtr = EOVERFLOW;
+ return Tcl_LongAsWide(-1);
}
- return parentWideSeekProc(parentData, offset, mode, errorCodePtr);
+
+ return Tcl_LongAsWide(parentSeekProc(parentData, Tcl_WideAsLong(offset),
+ mode, errorCodePtr));
}
/*
@@ -1017,7 +996,7 @@ TransformSetOptionProc(
const char *optionName,
const char *value)
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
Tcl_Channel downChan = Tcl_GetStackedChannel(dataPtr->self);
Tcl_DriverSetOptionProc *setOptionProc;
@@ -1055,7 +1034,7 @@ TransformGetOptionProc(
const char *optionName,
Tcl_DString *dsPtr)
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
Tcl_Channel downChan = Tcl_GetStackedChannel(dataPtr->self);
Tcl_DriverGetOptionProc *getOptionProc;
@@ -1095,16 +1074,17 @@ TransformGetOptionProc(
*----------------------------------------------------------------------
*/
+ /* ARGSUSED */
static void
TransformWatchProc(
ClientData instanceData, /* Channel to watch. */
int mask) /* Events of interest. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
Tcl_Channel downChan;
/*
- * The caller expressed interest in events occurring for this channel. We
+ * The caller expressed interest in events occuring for this channel. We
* are forwarding the call to the underlying channel now.
*/
@@ -1179,7 +1159,7 @@ TransformGetFileHandleProc(
int direction, /* Direction of interest. */
ClientData *handlePtr) /* Place to store the handle into. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)instanceData;
+ TransformChannelData *dataPtr = instanceData;
/*
* Return the handle belonging to parent channel. IOW, pass the request
@@ -1211,12 +1191,12 @@ static int
TransformNotifyProc(
ClientData clientData, /* The state of the notified
* transformation. */
- int mask) /* The mask of occurring events. */
+ int mask) /* The mask of occuring events. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)clientData;
+ TransformChannelData *dataPtr = clientData;
/*
- * An event occurred in the underlying channel. This transformation doesn't
+ * An event occured in the underlying channel. This transformation doesn't
* process such events thus returns the incoming mask unchanged.
*/
@@ -1256,7 +1236,7 @@ static void
TransformChannelHandlerTimer(
ClientData clientData) /* Transformation to query. */
{
- TransformChannelData *dataPtr = (TransformChannelData *)clientData;
+ TransformChannelData *dataPtr = clientData;
dataPtr->timer = NULL;
if (!(dataPtr->watchMask&TCL_READABLE) || ResultEmpty(&dataPtr->result)) {
@@ -1294,7 +1274,7 @@ ResultClear(
r->used = 0;
if (r->allocated) {
- ckfree(r->buf);
+ ckfree((char *) r->buf);
r->buf = NULL;
r->allocated = 0;
}
@@ -1306,7 +1286,7 @@ ResultClear(
* ResultInit --
*
* Initializes the specified buffer structure. The structure will contain
- * valid information for an empty buffer.
+ * valid information for an emtpy buffer.
*
* Side effects:
* See above.
@@ -1368,13 +1348,13 @@ ResultEmpty(
*----------------------------------------------------------------------
*/
-static inline size_t
+static inline int
ResultCopy(
ResultBuffer *r, /* The buffer to read from. */
unsigned char *buf, /* The buffer to copy into. */
size_t toRead) /* Number of requested bytes. */
{
- if (ResultEmpty(r)) {
+ if (r->used == 0) {
/*
* Nothing to copy in the case of an empty buffer.
*/
@@ -1431,17 +1411,17 @@ ResultAdd(
unsigned char *buf, /* The buffer to read from. */
size_t toWrite) /* The number of bytes in 'buf'. */
{
- if ((r->used + toWrite + 1) > r->allocated) {
+ if (r->used + toWrite > r->allocated) {
/*
* Extension of the internal buffer is required.
*/
if (r->allocated == 0) {
r->allocated = toWrite + INCREMENT;
- r->buf = (unsigned char *)ckalloc(r->allocated);
+ r->buf = UCHARP(ckalloc(r->allocated));
} else {
r->allocated += toWrite + INCREMENT;
- r->buf = (unsigned char *)ckrealloc(r->buf, r->allocated);
+ r->buf = UCHARP(ckrealloc((char *) r->buf, r->allocated));
}
}