| ︙ | | |
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
|
Tcl_Obj *objPtr);
static void UpdateStringOfByteArray(Tcl_Obj *listPtr);
static void DeleteScanNumberCache(Tcl_HashTable *numberCachePtr);
static int NeedReversing(int format);
static void CopyNumber(const void *from, void *to,
size_t length, int type);
/* Binary ensemble commands */
static Tcl_ObjCmdProc BinaryFormatCmd;
static Tcl_ObjCmdProc BinaryScanCmd;
static Tcl_ObjCmdProc2 BinaryFormatCmd;
static Tcl_ObjCmdProc2 BinaryScanCmd;
/* Binary encoding sub-ensemble commands */
static Tcl_ObjCmdProc BinaryEncodeHex;
static Tcl_ObjCmdProc BinaryDecodeHex;
static Tcl_ObjCmdProc BinaryEncode64;
static Tcl_ObjCmdProc BinaryDecode64;
static Tcl_ObjCmdProc BinaryEncodeUu;
static Tcl_ObjCmdProc BinaryDecodeUu;
static Tcl_ObjCmdProc2 BinaryEncodeHex;
static Tcl_ObjCmdProc2 BinaryDecodeHex;
static Tcl_ObjCmdProc2 BinaryEncode64;
static Tcl_ObjCmdProc2 BinaryDecode64;
static Tcl_ObjCmdProc2 BinaryEncodeUu;
static Tcl_ObjCmdProc2 BinaryDecodeUu;
/*
* The following tables are used by the binary encoders
*/
static const char HexDigits[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
|
| ︙ | | |
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
-
+
-
+
-
+
|
*----------------------------------------------------------------------
*/
static int
BinaryFormatCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int arg; /* Index of next argument to consume. */
Tcl_Size arg; /* Index of next argument to consume. */
int value = 0; /* Current integer value to be packed.
* Initialized to avoid compiler warning. */
char cmd; /* Current format character. */
Tcl_Size count; /* Count associated with current format
Tcl_Size count; /* Count associated with current format
* character. */
int flags; /* Format field flags */
const char *format; /* Pointer to current position in format
* string. */
Tcl_Obj *resultPtr = NULL; /* Object holding result buffer. */
unsigned char *buffer; /* Start of result buffer. */
unsigned char *cursor; /* Current position within result buffer. */
|
| ︙ | | |
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
|
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
|
-
+
-
+
-
+
|
*----------------------------------------------------------------------
*/
static int
BinaryScanCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int arg; /* Index of next argument to consume. */
Tcl_Size arg; /* Index of next argument to consume. */
int value = 0; /* Current integer value to be packed.
* Initialized to avoid compiler warning. */
char cmd; /* Current format character. */
Tcl_Size count; /* Count associated with current format
Tcl_Size count; /* Count associated with current format
* character. */
int flags; /* Format field flags */
const char *format; /* Pointer to current position in format
* string. */
Tcl_Obj *resultPtr = NULL; /* Object holding result buffer. */
unsigned char *buffer; /* Start of result buffer. */
const char *errorString;
|
| ︙ | | |
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
|
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
|
-
+
-
-
-
+
+
+
-
+
|
(*formatPtr)++;
*flagsPtr |= BINARY_UNSIGNED;
}
if (**formatPtr == '*') {
(*formatPtr)++;
*countPtr = BINARY_ALL;
} else if (isdigit(UCHAR(**formatPtr))) { /* INTL: digit */
unsigned long long count;
unsigned long count;
errno = 0;
count = strtoull(*formatPtr, (char **) formatPtr, 10);
if (errno || (count > TCL_SIZE_MAX)) {
*countPtr = TCL_SIZE_MAX;
count = strtoul(*formatPtr, (char **) formatPtr, 10);
if (errno || (count > (unsigned long) INT_MAX)) {
*countPtr = INT_MAX;
} else {
*countPtr = count;
*countPtr = (int) count;
}
} else {
*countPtr = BINARY_NOCOUNT;
}
return 1;
}
|
| ︙ | | |
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
|
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
|
-
+
|
*----------------------------------------------------------------------
*/
static int
BinaryEncodeHex(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj = NULL;
unsigned char *data = NULL;
unsigned char *cursor = NULL;
Tcl_Size offset = 0, count = 0;
|
| ︙ | | |
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
|
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
|
-
+
-
-
+
+
|
*----------------------------------------------------------------------
*/
static int
BinaryDecodeHex(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj = NULL;
unsigned char *data, *datastart, *dataend;
unsigned char *begin, *cursor, c;
int i, index, value, pure = 1, strict = 0;
Tcl_Size size, cut = 0, count = 0;
int index, value, pure = 1, strict = 0;
Tcl_Size i, size, cut = 0, count = 0;
int ucs4;
enum {OPT_STRICT };
static const char *const optStrings[] = { "-strict", NULL };
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?options? data");
return TCL_ERROR;
|
| ︙ | | |
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
|
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
|
-
+
-
-
-
+
+
+
|
} \
} while (0)
static int
BinaryEncode64(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj;
unsigned char *data, *limit;
Tcl_WideInt maxlen = 0;
const char *wrapchar = "\n";
Tcl_Size wrapcharlen = 1;
int index, purewrap = 1;
Tcl_Size i, offset, size, outindex = 0, count = 0;
Tcl_Size i, wrapcharlen = 1;
int index, outindex = 0, purewrap = 1;
Tcl_Size offset, size, count = 0;
enum { OPT_MAXLEN, OPT_WRAPCHAR };
static const char *const optStrings[] = { "-maxlen", "-wrapchar", NULL };
if (objc < 2 || objc % 2 != 0) {
Tcl_WrongNumArgs(interp, 1, objv,
"?-maxlen len? ?-wrapchar char? data");
return TCL_ERROR;
|
| ︙ | | |
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
|
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
|
-
+
-
-
-
+
+
-
+
|
*----------------------------------------------------------------------
*/
static int
BinaryEncodeUu(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj;
unsigned char *data, *start, *cursor;
int i, bits;
unsigned int n;
int lineLength = 61;
int bits, lineLength = 61;
Tcl_Size rawLength;
const unsigned char SingleNewline[] = { UCHAR('\n') };
const unsigned char *wrapchar = SingleNewline;
Tcl_Size j, rawLength, offset, count = 0, wrapcharlen = sizeof(SingleNewline);
Tcl_Size n, i, j, offset, count = 0, wrapcharlen = sizeof(SingleNewline);
enum { OPT_MAXLEN, OPT_WRAPCHAR } index;
static const char *const optStrings[] = { "-maxlen", "-wrapchar", NULL };
if (objc < 2 || objc % 2 != 0) {
Tcl_WrongNumArgs(interp, 1, objv,
"?-maxlen len? ?-wrapchar char? data");
return TCL_ERROR;
|
| ︙ | | |
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
|
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
|
-
+
-
-
+
+
|
*----------------------------------------------------------------------
*/
static int
BinaryDecodeUu(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj = NULL;
unsigned char *data, *datastart, *dataend;
unsigned char *begin, *cursor;
int i, index, pure = 1, strict = 0, lineLen;
Tcl_Size size, count = 0;
int index, pure = 1, strict = 0, lineLen;
Tcl_Size i, size, count = 0;
unsigned char c;
int ucs4;
enum { OPT_STRICT };
static const char *const optStrings[] = { "-strict", NULL };
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?options? data");
|
| ︙ | | |
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
|
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
|
-
-
+
+
-
-
+
+
|
}
/*
* Translate that grouping into (up to) three binary bytes output.
*/
if (lineLen > 0) {
*cursor++ = (unsigned char)(((d[0] - 0x20) & 0x3F) << 2)
| (((d[1] - 0x20) & 0x3F) >> 4);
*cursor++ = (unsigned char)((((d[0] - 0x20) & 0x3F) << 2)
| (((d[1] - 0x20) & 0x3F) >> 4));
if (--lineLen > 0) {
*cursor++ = (unsigned char)(((d[1] - 0x20) & 0x3F) << 4)
| (((d[2] - 0x20) & 0x3F) >> 2);
*cursor++ = (unsigned char)((((d[1] - 0x20) & 0x3F) << 4)
| (((d[2] - 0x20) & 0x3F) >> 2));
if (--lineLen > 0) {
*cursor++ = (unsigned char)((((d[2] - 0x20) & 0x3F) << 6)
| (((d[3] - 0x20) & 0x3F)));
lineLen--;
}
}
}
|
| ︙ | | |
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
|
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
|
-
+
-
-
+
+
|
*----------------------------------------------------------------------
*/
static int
BinaryDecode64(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Size objc,
Tcl_Obj *const objv[])
{
Tcl_Obj *resultObj = NULL;
unsigned char *data, *datastart, *dataend, c = '\0';
unsigned char *begin = NULL;
unsigned char *cursor = NULL;
int pure = 1, strict = 0;
int i, index, cut = 0;
Tcl_Size size, count = 0;
int index, cut = 0;
Tcl_Size i, size, count = 0;
int ucs4;
enum { OPT_STRICT };
static const char *const optStrings[] = { "-strict", NULL };
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?options? data");
return TCL_ERROR;
|
| ︙ | | |