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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
*** tcl.h.orig Mon Aug 18 21:11:15 1997
--- tcl.h Mon Aug 18 21:11:22 1997
***************
*** 918,923 ****
--- 918,935 ----
} Tcl_EolTranslation;
/*
+ * Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ *
+ * Enum for different byteorders.
+ */
+
+ typedef enum Tcl_ByteOrder {
+ TCL_BIGENDIAN, /* Multibyte words are stored with MSB first */
+ TCL_SMALLENDIAN /* Multibyte words are stored with MSB last */
+ } Tcl_ByteOrder;
+
+ /*
* struct Tcl_ChannelType:
*
* One such structure exists for each type (kind) of channel.
***************
*** 1201,1206 ****
--- 1213,1224 ----
char *chanName, int *modePtr));
EXTERN int Tcl_GetChannelBufferSize _ANSI_ARGS_((
Tcl_Channel chan));
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ */
+ EXTERN Tcl_ByteOrder Tcl_GetChannelByteorder _ANSI_ARGS_((
+ Tcl_Channel chan));
+ EXTERN Tcl_ByteOrder Tcl_GetHostByteorder _ANSI_ARGS_((void));
EXTERN int Tcl_GetChannelHandle _ANSI_ARGS_((Tcl_Channel chan,
int direction, ClientData *handlePtr));
EXTERN ClientData Tcl_GetChannelInstanceData _ANSI_ARGS_((
*** tclIO.c.orig Mon Aug 18 21:11:15 1997
--- tclIO.c Mon Aug 18 21:11:22 1997
***************
*** 127,132 ****
--- 127,136 ----
* code, is dynamically allocated. */
int flags; /* ORed combination of the flags defined
* below. */
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ */
+ Tcl_ByteOrder byteOrder; /* byteorder associated to this channel */
Tcl_EolTranslation inputTranslation;
/* What translation to apply for end of line
* sequences on input? */
***************
*** 1194,1199 ****
--- 1198,1207 ----
* indicator (e.g. ^Z) and does not append an EOF indicator to files.
*/
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ */
+ chanPtr->byteOrder = Tcl_GetHostByteorder ();
chanPtr->inputTranslation = TCL_TRANSLATE_AUTO;
chanPtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
chanPtr->inEofChar = 0;
***************
*** 3912,3918 ****
{
if (interp) {
CONST char *genericopt =
! "blocking buffering buffersize eofchar translation";
char **argv;
int argc, i;
Tcl_DString ds;
--- 3920,3926 ----
{
if (interp) {
CONST char *genericopt =
! "blocking buffering buffersize byteorder eofchar translation";
char **argv;
int argc, i;
Tcl_DString ds;
***************
*** 3945,3950 ****
--- 3953,4013 ----
/*
*----------------------------------------------------------------------
*
+ * Tcl_GetChannelByteorder --
+ *
+ * Retrieves the byteorder set for this channel.
+ *
+ * Results:
+ * The size.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+ Tcl_ByteOrder
+ Tcl_GetChannelByteorder(chan)
+ Tcl_Channel chan; /* The channel for which to find the
+ * buffer size. */
+ {
+ Channel *chanPtr;
+
+ chanPtr = (Channel *) chan;
+ return chanPtr->byteOrder;
+ }
+
+ /*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_GetHostByteorder --
+ *
+ * Retrieves the byteorder of the machine we are running on.
+ *
+ * Results:
+ * The size.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+ Tcl_ByteOrder
+ Tcl_GetHostByteorder()
+ {
+ union {
+ char c[sizeof(short)];
+ short s;
+ } order;
+
+ order.s = 1;
+ return (order.c[0] == 1) ? TCL_SMALLENDIAN : TCL_BIGENDIAN;
+ }
+
+ /*
+ *----------------------------------------------------------------------
+ *
* Tcl_GetChannelOption --
*
* Gets a mode associated with an IO channel. If the optionName arg
***************
*** 4046,4051 ****
--- 4109,4128 ----
return TCL_OK;
}
}
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ */
+ if ((len == 0) || ((len > 2) && (optionName[1] == 'b') &&
+ (strncmp(optionName, "-byteorder", len) == 0))) {
+ if (len == 0) {
+ Tcl_DStringAppendElement(dsPtr, "-byteorder");
+ }
+ Tcl_DStringAppendElement(dsPtr,
+ (chanPtr->byteOrder == TCL_BIGENDIAN) ? "bigendian" : "smallendian");
+ if (len > 0) {
+ return TCL_OK;
+ }
+ }
if ((len == 0) ||
((len > 1) && (optionName[1] == 'e') &&
(strncmp(optionName, "-eofchar", len) == 0))) {
***************
*** 4246,4251 ****
--- 4323,4358 ----
chanPtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE;
}
return TCL_OK;
+ }
+
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ * Support of Tcl-Trf (binio).
+ */
+ if ((len > 2) && (optionName[1] == 'b') &&
+ (strncmp(optionName, "-byteorder", len) == 0)) {
+ int nv_len = strlen (newValue);
+
+ if ((nv_len > 0) && (strncmp (newValue, "smallendian", nv_len) == 0)) {
+ chanPtr->byteOrder = TCL_SMALLENDIAN;
+ return TCL_OK;
+ } else if ((nv_len > 0) && (strncmp (newValue, "littleendian", nv_len) == 0)) {
+ chanPtr->byteOrder = TCL_SMALLENDIAN;
+ return TCL_OK;
+ } else if ((nv_len > 0) && (strncmp (newValue, "network", nv_len) == 0)) {
+ chanPtr->byteOrder = TCL_BIGENDIAN;
+ return TCL_OK;
+ } else if ((nv_len > 0) && (strncmp (newValue, "bigendian", nv_len) == 0)) {
+ chanPtr->byteOrder = TCL_BIGENDIAN;
+ return TCL_OK;
+ }
+
+ if (interp != (Tcl_Interp *) NULL) {
+ Tcl_AppendResult(interp,
+ "bad value for -byteorder: ",
+ "must be one of smallendian, littleendian, bigendian or network",
+ (char *) NULL);
+ }
+ return TCL_ERROR;
}
if ((len > 1) && (optionName[1] == 'e') &&
|