589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
}
/*
*----------------------------------------------------------------------
*
* TclInitBinaryCmd --
*
* This function is called to create the "binary" Tcl command. See the user
* documentation for details on what it does.
*
* Results:
* A command token for the new command.
*
* Side effects:
* Creates a new binary command as a mapped ensemble.
*
*----------------------------------------------------------------------
*/
Tcl_Command
TclInitBinaryCmd(Tcl_Interp *interp)
{
Tcl_Namespace *nsTclPtr, *nsBinPtr, *nsEncPtr, *nsDecPtr;
Tcl_Command binEnsemble, encEnsemble, decEnsemble;
Tcl_Obj *binDict, *encDict, *decDict;
/*
* FIX ME: I so ugly - please make me pretty ...
*/
nsTclPtr = Tcl_FindNamespace(interp, "::tcl",
NULL, TCL_CREATE_NS_IF_UNKNOWN);
if (nsTclPtr == NULL) {
Tcl_Panic("unable to find or create ::tcl namespace!");
}
nsBinPtr = Tcl_FindNamespace(interp, "::tcl::binary",
NULL, TCL_CREATE_NS_IF_UNKNOWN);
if (nsBinPtr == NULL) {
Tcl_Panic("unable to find or create ::tcl::binary namespace!");
}
binEnsemble = Tcl_CreateEnsemble(interp, "::binary",
nsBinPtr, TCL_ENSEMBLE_PREFIX);
nsEncPtr = Tcl_FindNamespace(interp, "::tcl::binary::encode",
NULL, TCL_CREATE_NS_IF_UNKNOWN);
if (nsEncPtr == NULL) {
Tcl_Panic("unable to find or create ::tcl::binary::encode namespace!");
}
encEnsemble = Tcl_CreateEnsemble(interp, "encode",
nsBinPtr, 0);
nsDecPtr = Tcl_FindNamespace(interp, "::tcl::binary::decode",
NULL, TCL_CREATE_NS_IF_UNKNOWN);
if (nsDecPtr == NULL) {
Tcl_Panic("unable to find or create ::tcl::binary::decode namespace!");
}
decEnsemble = Tcl_CreateEnsemble(interp, "decode",
nsBinPtr, 0);
TclNewObj(binDict);
Tcl_DictObjPut(NULL, binDict, Tcl_NewStringObj("format",-1),
Tcl_NewStringObj("::tcl::binary::format",-1));
Tcl_DictObjPut(NULL, binDict, Tcl_NewStringObj("scan",-1),
Tcl_NewStringObj("::tcl::binary::scan",-1));
Tcl_DictObjPut(NULL, binDict, Tcl_NewStringObj("encode",-1),
Tcl_NewStringObj("::tcl::binary::encode",-1));
Tcl_DictObjPut(NULL, binDict, Tcl_NewStringObj("decode",-1),
Tcl_NewStringObj("::tcl::binary::decode",-1));
Tcl_CreateObjCommand(interp, "::tcl::binary::format",
BinaryFormatCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "::tcl::binary::scan",
BinaryScanCmd, NULL, NULL);
Tcl_SetEnsembleMappingDict(interp, binEnsemble, binDict);
TclNewObj(encDict);
Tcl_DictObjPut(NULL, encDict, Tcl_NewStringObj("hex",-1),
Tcl_NewStringObj("::tcl::binary::encode::hex",-1));
Tcl_DictObjPut(NULL, encDict, Tcl_NewStringObj("uuencode",-1),
Tcl_NewStringObj("::tcl::binary::encode::uuencode",-1));
Tcl_DictObjPut(NULL, encDict, Tcl_NewStringObj("base64",-1),
Tcl_NewStringObj("::tcl::binary::encode::base64",-1));
Tcl_CreateObjCommand(interp, "::tcl::binary::encode::hex",
BinaryEncodeHex, (ClientData)HexDigits, NULL);
Tcl_CreateObjCommand(interp, "::tcl::binary::encode::uuencode",
BinaryEncode64, (ClientData)UueDigits, NULL);
Tcl_CreateObjCommand(interp, "::tcl::binary::encode::base64",
BinaryEncode64, (ClientData)B64Digits, NULL);
Tcl_SetEnsembleMappingDict(interp, encEnsemble, encDict);
TclNewObj(decDict);
Tcl_DictObjPut(NULL, decDict, Tcl_NewStringObj("hex",-1),
Tcl_NewStringObj("::tcl::binary::decode::hex",-1));
Tcl_DictObjPut(NULL, decDict, Tcl_NewStringObj("uuencode",-1),
Tcl_NewStringObj("::tcl::binary::decode::uuencode",-1));
Tcl_DictObjPut(NULL, decDict, Tcl_NewStringObj("base64",-1),
Tcl_NewStringObj("::tcl::binary::decode::base64",-1));
Tcl_CreateObjCommand(interp, "::tcl::binary::decode::hex",
BinaryDecodeHex, (ClientData)NULL, NULL);
Tcl_CreateObjCommand(interp, "::tcl::binary::decode::uuencode",
BinaryDecodeUu, (ClientData)NULL, NULL);
Tcl_CreateObjCommand(interp, "::tcl::binary::decode::base64",
BinaryDecode64, (ClientData)NULL, NULL);
Tcl_SetEnsembleMappingDict(interp, decEnsemble, decDict);
return binEnsemble;
}
/*
*----------------------------------------------------------------------
*
* BinaryFormatCmd --
*
|
|
|
<
|
<
|
<
<
<
|
<
|
|
<
<
<
<
|
<
|
|
<
|
|
|
|
<
|
|
|
|
<
|
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
<
<
<
|
|
|
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
}
/*
*----------------------------------------------------------------------
*
* TclInitBinaryCmd --
*
* This function is called to create the "binary" Tcl command. See the
* user documentation for details on what it does.
*
* Results:
* A command token for the new command.
*
* Side effects:
* Creates a new binary command as a mapped ensemble.
*
*----------------------------------------------------------------------
*/
Tcl_Command
TclInitBinaryCmd(Tcl_Interp *interp)
{
const EnsembleImplMap binaryMap[] = {
{ "format", BinaryFormatCmd, NULL },
{ "scan", BinaryScanCmd, NULL },
{ "encode", NULL, NULL },
{ "decode", NULL, NULL },
{ NULL, NULL, NULL }
};
const EnsembleImplMap encodeMap[] = {
{ "hex", BinaryEncodeHex, NULL, NULL, (ClientData)HexDigits },
{ "uuencode", BinaryEncode64, NULL, NULL, (ClientData)UueDigits },
{ "base64", BinaryEncode64, NULL, NULL, (ClientData)B64Digits },
{ NULL, NULL, NULL }
};
const EnsembleImplMap decodeMap[] = {
{ "hex", BinaryDecodeHex, NULL },
{ "uuencode", BinaryDecodeUu, NULL },
{ "base64", BinaryDecode64, NULL },
{ NULL, NULL, NULL }
};
Tcl_Command binaryEnsemble;
binaryEnsemble = TclMakeEnsemble(interp, "binary", binaryMap);
TclMakeEnsemble(interp, "binary encode", encodeMap);
TclMakeEnsemble(interp, "binary decode", decodeMap);
return binaryEnsemble;
}
/*
*----------------------------------------------------------------------
*
* BinaryFormatCmd --
*
|