1*** tcl.h.orig	Sat Mar 20 19:59:09 1999
2--- tcl.h	Sat Mar 20 19:59:11 1999
3***************
4*** 1336,1341 ****
5--- 1336,1348 ----
6
7  EXTERN int		Tcl_AppInit _ANSI_ARGS_((Tcl_Interp *interp));
8
9+
10+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
11+  * "Trf-Patch for channels with a switchable byteorder"
12+  */
13+ EXTERN int	Tcl_GetChannelByteorder _ANSI_ARGS_((
14+     			    Tcl_Channel chan));
15+
16  #endif /* RESOURCE_INCLUDED */
17
18  #undef TCL_STORAGE_CLASS
19*** tclIO.c.orig	Thu Mar 11 06:14:58 1999
20--- tclIO.c	Sat Mar 20 19:58:01 1999
21***************
22*** 261,266 ****
23--- 261,270 ----
24  					 * When set, file events will not be
25  					 * delivered for buffered data until
26  					 * the state of the channel changes. */
27+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 03/21/1997.
28+  * "Trf-Patch for channels with a switchable byteorder"
29+  */
30+ #define CHANNEL_IS_SMALLENDIAN	(1<<16)	/* Multibyte words are stored with MSB last  */
31
32  /*
33   * For each channel handler registered in a call to Tcl_CreateChannelHandler,
34***************
35*** 1241,1246 ****
36--- 1245,1264 ----
37      CONST char *name;
38      ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
39
40+     /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
41+      * "Trf-Patch for channels with a switchable byteorder"
42+      * Location: Tcl_CreateChannel.
43+      */
44+     union {
45+ 	char c[sizeof(short)];
46+ 	short s;
47+     } order;
48+
49+     order.s = 1;
50+     if (order.c[0] == 1) {
51+ 	mask |= CHANNEL_IS_SMALLENDIAN;
52+     }
53+
54      chanPtr = (Channel *) ckalloc((unsigned) sizeof(Channel));
55
56      if (chanName != (char *) NULL) {
57***************
58*** 4924,4930 ****
59  {
60      if (interp) {
61  	CONST char *genericopt =
62! 	    	"blocking buffering buffersize eofchar translation";
63  	char **argv;
64  	int  argc, i;
65  	Tcl_DString ds;
66--- 4942,4948 ----
67  {
68      if (interp) {
69  	CONST char *genericopt =
70! 	    	"blocking buffering buffersize byteorder eofchar translation";
71  	char **argv;
72  	int  argc, i;
73  	Tcl_DString ds;
74***************
75*** 4954,4959 ****
76--- 4972,5009 ----
77      return TCL_ERROR;
78  }
79
80+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
81+  * "Trf-Patch for channels with a switchable byteorder"
82+  * Exported functionality.
83+  */
84+
85+ /*
86+  *----------------------------------------------------------------------
87+  *
88+  * Tcl_GetChannelByteorder --
89+  *
90+  *	Retrieves the byteorder set for this channel.
91+  *
92+  * Results:
93+  *	The size.
94+  *
95+  * Side effects:
96+  *	None.
97+  *
98+  *----------------------------------------------------------------------
99+  */
100+
101+ int
102+ Tcl_GetChannelByteorder(chan)
103+     Tcl_Channel chan;		/* The channel for which to find the
104+                                  * buffer size. */
105+ {
106+     Channel *chanPtr;
107+
108+     chanPtr = (Channel *) chan;
109+     return ((chanPtr->flags & CHANNEL_IS_SMALLENDIAN) != 0);
110+ }
111+
112  /*
113   *----------------------------------------------------------------------
114   *
115***************
116*** 5074,5079 ****
117--- 5124,5148 ----
118  	    return TCL_OK;
119  	}
120      }
121+
122+     /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
123+      * "Trf-Patch for channels with a switchable byteorder"
124+      * Location: Tcl_GetChannelOption
125+      */
126+
127+     if ((len == 0) || ((len > 2) && (optionName[1] == 'b') &&
128+ 		       (strncmp(optionName, "-byteorder", len) == 0))) {
129+       if (len == 0) {
130+         Tcl_DStringAppendElement(dsPtr, "-byteorder");
131+       }
132+       Tcl_DStringAppendElement(dsPtr,
133+ 			       (chanPtr->flags & CHANNEL_IS_SMALLENDIAN) ?
134+ 			       "smallendian" : "bigendian");
135+       if (len > 0) {
136+         return TCL_OK;
137+       }
138+     }
139+
140      if ((len == 0) ||
141              ((len > 2) && (optionName[1] == 'e') &&
142                      (strncmp(optionName, "-eofchar", len) == 0))) {
143***************
144*** 5269,5274 ****
145--- 5338,5378 ----
146          if ((chanPtr->bufSize < 10) || (chanPtr->bufSize > (1024 * 1024))) {
147              chanPtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE;
148          }
149+
150+ 	/* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
151+ 	 * "Trf-Patch for channels with a switchable byteorder"
152+ 	 * Location: Tcl_SetChannelOption.
153+ 	 */
154+
155+     } else if ((len > 2) && (optionName[1] == 'b') &&
156+ 	       (strncmp(optionName, "-byteorder", len) == 0)) {
157+       int nv_len = strlen (newValue);
158+
159+       if ((nv_len > 0) &&
160+ 	  (strncmp (newValue, "smallendian", nv_len) == 0)) {
161+ 	chanPtr->flags |= CHANNEL_IS_SMALLENDIAN;
162+ 	return TCL_OK;
163+       } else if ((nv_len > 0) &&
164+ 		 (strncmp (newValue, "littleendian", nv_len) == 0)) {
165+ 	chanPtr->flags |= CHANNEL_IS_SMALLENDIAN;
166+ 	return TCL_OK;
167+       } else if ((nv_len > 0) &&
168+ 		 (strncmp (newValue, "network", nv_len) == 0)) {
169+ 	chanPtr->flags &= ~CHANNEL_IS_SMALLENDIAN;
170+ 	return TCL_OK;
171+       } else if ((nv_len > 0) &&
172+ 		 (strncmp (newValue, "bigendian", nv_len) == 0)) {
173+ 	chanPtr->flags &= ~CHANNEL_IS_SMALLENDIAN;
174+ 	return TCL_OK;
175+       }
176+
177+       if (interp != (Tcl_Interp *) NULL) {
178+ 	Tcl_AppendResult(interp,
179+ 			 "bad value for -byteorder: ",
180+ 			 "must be one of smallendian, littleendian, bigendian or network",
181+ 			 (char *) NULL);
182+       }
183+       return TCL_ERROR;
184      } else if ((len > 2) && (optionName[1] == 'e') &&
185  	    (strncmp(optionName, "-encoding", len) == 0)) {
186  	Tcl_Encoding encoding;
187