File: byteorder.patch

package info (click to toggle)
tcltrf 2.1.4-dfsg3-8
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,656 kB
  • sloc: ansic: 73,139; sh: 3,155; tcl: 1,343; makefile: 182; exp: 22
file content (218 lines) | stat: -rw-r--r-- 6,351 bytes parent folder | download | duplicates (6)
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
210
211
212
213
214
215
216
217
218
*** tcl.h.orig	Fri Jun 12 15:52:49 1998
--- tcl.h	Wed Jun 17 21:28:59 1998
***************
*** 1432,1437 ****
--- 1432,1444 ----
  	        	    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 int	Tcl_GetChannelByteorder _ANSI_ARGS_((
+     			    Tcl_Channel chan));
+ 
  EXTERN int		Tcl_GetChannelHandle _ANSI_ARGS_((Tcl_Channel chan,
  	        	    int direction, ClientData *handlePtr));
  EXTERN ClientData	Tcl_GetChannelInstanceData _ANSI_ARGS_((
*** tclIO.c.orig	Fri Jun 12 15:52:49 1998
--- tclIO.c	Wed Jun 17 21:28:59 1998
***************
*** 154,159 ****
--- 154,165 ----
  				 * data bytes.  May be TCL_ENCODING_START
  				 * before converting first byte and
  				 * TCL_ENCODING_END when EOF is seen. */
+ 
+   /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+    * Support of Tcl-Trf (binio).
+    */
+   int byteOrder; /* byteorder associated to this channel */
+ 
      Tcl_EolTranslation inputTranslation;
  				/* What translation to apply for end of line
                                   * sequences on input? */    
***************
*** 465,470 ****
--- 471,484 ----
  static int		WriteChars _ANSI_ARGS_((Channel *chanPtr,
  			    CONST char *src, int srcLen));
  
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+  * Support of Tcl-Trf (binio).
+  */
+ static int Tcl_GetHostByteorder _ANSI_ARGS_ (());
+ 
+ #define TCL_BIGENDIAN   (0) /* Multibyte words are stored with MSB first */
+ #define TCL_SMALLENDIAN (1) /* Multibyte words are stored with MSB last  */
+ 
  
  /*
   *---------------------------------------------------------------------------
***************
*** 1273,1278 ****
--- 1287,1297 ----
       * 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;
***************
*** 4890,4896 ****
  {
      if (interp) {
  	CONST char *genericopt = 
! 	    	"blocking buffering buffersize eofchar translation";
  	char **argv;
  	int  argc, i;
  	Tcl_DString ds;
--- 4909,4915 ----
  {
      if (interp) {
  	CONST char *genericopt = 
! 	    	"blocking buffering buffersize byteorder eofchar translation";
  	char **argv;
  	int  argc, i;
  	Tcl_DString ds;
***************
*** 4920,4925 ****
--- 4939,5002 ----
      return TCL_ERROR;
  }
  
+ /* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+  * Support of Tcl-Trf (binio).
+  */
+ /*
+  *----------------------------------------------------------------------
+  *
+  * Tcl_GetChannelByteorder --
+  *
+  *	Retrieves the byteorder set for this channel.
+  *
+  * Results:
+  *	The size.
+  *
+  * Side effects:
+  *	None.
+  *
+  *----------------------------------------------------------------------
+  */
+ 
+ int
+ 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.
+  *
+  *----------------------------------------------------------------------
+  */
+ 
+ static int
+ Tcl_GetHostByteorder()
+ {
+   union {
+     char c[sizeof(short)];
+     short s;
+   } order;
+ 
+   order.s = 1;
+   return (order.c[0] == 1) ? TCL_SMALLENDIAN : TCL_BIGENDIAN;
+ }
+ 
  /*
   *----------------------------------------------------------------------
   *
***************
*** 5040,5045 ****
--- 5117,5139 ----
  	    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 > 2) && (optionName[1] == 'e') &&
                      (strncmp(optionName, "-eofchar", len) == 0))) {
***************
*** 5235,5240 ****
--- 5329,5367 ----
          if ((chanPtr->bufSize < 10) || (chanPtr->bufSize > (1024 * 1024))) {
              chanPtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE;
          }
+ 
+ 	/* Andreas Kupries <andreas_kupries@users.sourceforge.net>, 05/31/1997.
+ 	 * Support of Tcl-Trf (binio).
+ 	 */
+     } else 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;
      } else if ((len > 2) && (optionName[1] == 'e') &&
  	    (strncmp(optionName, "-encoding", len) == 0)) {
  	Tcl_Encoding encoding;