1*** tcl.h.orig	Mon Aug 18 21:11:15 1997
2--- tcl.h	Mon Aug 18 21:11:22 1997
3***************
4*** 918,923 ****
5--- 918,935 ----
6  } Tcl_EolTranslation;
7  
8  /*
9+  * Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
10+  * Support of Tcl-Trf (binio).
11+  *
12+  * Enum for different byteorders.
13+  */
14+ 
15+ typedef enum Tcl_ByteOrder {
16+   TCL_BIGENDIAN,       /* Multibyte words are stored with MSB first */
17+   TCL_SMALLENDIAN      /* Multibyte words are stored with MSB last */
18+ } Tcl_ByteOrder;
19+ 
20+ /*
21   * struct Tcl_ChannelType:
22   *
23   * One such structure exists for each type (kind) of channel.
24***************
25*** 1201,1206 ****
26--- 1213,1224 ----
27  	        	    char *chanName, int *modePtr));
28  EXTERN int		Tcl_GetChannelBufferSize _ANSI_ARGS_((
29      			    Tcl_Channel chan));
30+   /* Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
31+    * Support of Tcl-Trf (binio).
32+    */
33+ EXTERN Tcl_ByteOrder	Tcl_GetChannelByteorder _ANSI_ARGS_((
34+     			    Tcl_Channel chan));
35+ EXTERN Tcl_ByteOrder	Tcl_GetHostByteorder _ANSI_ARGS_((void));
36  EXTERN int		Tcl_GetChannelHandle _ANSI_ARGS_((Tcl_Channel chan,
37  	        	    int direction, ClientData *handlePtr));
38  EXTERN ClientData	Tcl_GetChannelInstanceData _ANSI_ARGS_((
39*** tclIO.c.orig	Mon Aug 18 21:11:15 1997
40--- tclIO.c	Mon Aug 18 21:11:22 1997
41***************
42*** 127,132 ****
43--- 127,136 ----
44                                   * code,  is dynamically allocated. */
45      int	flags;			/* ORed combination of the flags defined
46                                   * below. */
47+   /* Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
48+    * Support of Tcl-Trf (binio).
49+    */
50+   Tcl_ByteOrder      byteOrder; /* byteorder associated to this channel */
51      Tcl_EolTranslation inputTranslation;
52  				/* What translation to apply for end of line
53                                   * sequences on input? */    
54***************
55*** 1194,1199 ****
56--- 1198,1207 ----
57       * indicator (e.g. ^Z) and does not append an EOF indicator to files.
58       */
59  
60+     /* Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
61+      * Support of Tcl-Trf (binio).
62+      */
63+     chanPtr->byteOrder = Tcl_GetHostByteorder ();
64      chanPtr->inputTranslation = TCL_TRANSLATE_AUTO;
65      chanPtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
66      chanPtr->inEofChar = 0;
67***************
68*** 3912,3918 ****
69  {
70      if (interp) {
71  	CONST char *genericopt = 
72! 	    	"blocking buffering buffersize eofchar translation";
73  	char **argv;
74  	int  argc, i;
75  	Tcl_DString ds;
76--- 3920,3926 ----
77  {
78      if (interp) {
79  	CONST char *genericopt = 
80! 	    	"blocking buffering buffersize byteorder eofchar translation";
81  	char **argv;
82  	int  argc, i;
83  	Tcl_DString ds;
84***************
85*** 3945,3950 ****
86--- 3953,4013 ----
87  /*
88   *----------------------------------------------------------------------
89   *
90+  * Tcl_GetChannelByteorder --
91+  *
92+  *	Retrieves the byteorder set for this channel.
93+  *
94+  * Results:
95+  *	The size.
96+  *
97+  * Side effects:
98+  *	None.
99+  *
100+  *----------------------------------------------------------------------
101+  */
102+ 
103+ Tcl_ByteOrder
104+ Tcl_GetChannelByteorder(chan)
105+     Tcl_Channel chan;		/* The channel for which to find the
106+                                  * buffer size. */
107+ {
108+     Channel *chanPtr;
109+ 
110+     chanPtr = (Channel *) chan;
111+     return chanPtr->byteOrder;
112+ }
113+ 
114+ /*
115+  *----------------------------------------------------------------------
116+  *
117+  * Tcl_GetHostByteorder --
118+  *
119+  *	Retrieves the byteorder of the machine we are running on.
120+  *
121+  * Results:
122+  *	The size.
123+  *
124+  * Side effects:
125+  *	None.
126+  *
127+  *----------------------------------------------------------------------
128+  */
129+ 
130+ Tcl_ByteOrder
131+ Tcl_GetHostByteorder()
132+ {
133+   union {
134+     char c[sizeof(short)];
135+     short s;
136+   } order;
137+ 
138+   order.s = 1;
139+   return (order.c[0] == 1) ? TCL_SMALLENDIAN : TCL_BIGENDIAN;
140+ }
141+ 
142+ /*
143+  *----------------------------------------------------------------------
144+  *
145   * Tcl_GetChannelOption --
146   *
147   *	Gets a mode associated with an IO channel. If the optionName arg
148***************
149*** 4046,4051 ****
150--- 4109,4128 ----
151              return TCL_OK;
152          }
153      }
154+     /* Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
155+      * Support of Tcl-Trf (binio).
156+      */
157+     if ((len == 0) || ((len > 2) && (optionName[1] == 'b') &&
158+             (strncmp(optionName, "-byteorder", len) == 0))) {
159+         if (len == 0) {
160+             Tcl_DStringAppendElement(dsPtr, "-byteorder");
161+         }
162+         Tcl_DStringAppendElement(dsPtr,
163+                 (chanPtr->byteOrder == TCL_BIGENDIAN) ? "bigendian" : "smallendian");
164+         if (len > 0) {
165+             return TCL_OK;
166+         }
167+     }
168      if ((len == 0) ||
169              ((len > 1) && (optionName[1] == 'e') &&
170                      (strncmp(optionName, "-eofchar", len) == 0))) {
171***************
172*** 4246,4251 ****
173--- 4323,4358 ----
174              chanPtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE;
175          }
176          return TCL_OK;
177+     }
178+     
179+     /* Andreas Kupries <a.kupries@westend.com>, 05/31/1997.
180+      * Support of Tcl-Trf (binio).
181+      */
182+     if ((len > 2) && (optionName[1] == 'b') &&
183+             (strncmp(optionName, "-byteorder", len) == 0)) {
184+       int nv_len = strlen (newValue);
185+ 
186+       if ((nv_len > 0) && (strncmp (newValue, "smallendian", nv_len) == 0)) {
187+ 	chanPtr->byteOrder = TCL_SMALLENDIAN;
188+         return TCL_OK;
189+       } else if ((nv_len > 0) && (strncmp (newValue, "littleendian", nv_len) == 0)) {
190+ 	chanPtr->byteOrder = TCL_SMALLENDIAN;
191+         return TCL_OK;
192+       } else if ((nv_len > 0) && (strncmp (newValue, "network", nv_len) == 0)) {
193+ 	chanPtr->byteOrder = TCL_BIGENDIAN;
194+         return TCL_OK;
195+       } else if ((nv_len > 0) && (strncmp (newValue, "bigendian", nv_len) == 0)) {
196+ 	chanPtr->byteOrder = TCL_BIGENDIAN;
197+         return TCL_OK;
198+       } 
199+ 
200+       if (interp != (Tcl_Interp *) NULL) {
201+ 	Tcl_AppendResult(interp,
202+ 			 "bad value for -byteorder: ",
203+ 			 "must be one of smallendian, littleendian, bigendian or network",
204+ 			 (char *) NULL);
205+       }
206+       return TCL_ERROR;
207      }
208      
209      if ((len > 1) && (optionName[1] == 'e') &&
210