BinaryConvert.mesa
Pavel, December 20, 1985 6:18:30 pm PST
DIRECTORY
Buttons
USING [Button, ButtonProc, Create],
Convert
USING [RopeFromInt],
MessageWindow
USING [Append, Blink],
Rope
USING [ActionType, Length, Map,
ROPE],
TEditOps
USING [GetSelContents],
TiogaOps
USING [Delete, InsertRope];
BinaryConvert:
CEDAR PROGRAM
IMPORTS
Buttons, Convert, Rope, MessageWindow, TEditOps, TiogaOps
=
BEGIN
ROPE:
TYPE = Rope.
ROPE;
binaryConvertButton: Buttons.Button ←
Buttons.Create[
info: [name: "Binary: 10/8/16"],
proc: BinaryConvertButton];
BinaryConvertButton: Buttons.ButtonProc =
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
{
selRope :
ROPE ← TEditOps.GetSelContents[];
selLength :
INT ← Rope.Length[selRope];
selValue :
INT ← 0;
valueRope :
ROPE;
mapProc : Rope.ActionType = {
[c: CHAR] RETURNS [quit: BOOL ← FALSE]
selValue ← selValue * 256 +
ORD[c];
};
IF selLength = 0 OR selLength > 4
THEN
{
MessageWindow.Append["Make a selection of 1-4 characters.",
TRUE];
MessageWindow.Blink[];
RETURN;
};
[] ← Rope.Map[base: selRope, action: mapProc];
valueRope ← Convert.RopeFromInt[from: selValue,
base: (
SELECT mouseButton
FROM red => 10, yellow => 8,
ENDCASE => 16)];
IF shift
THEN
{
TiogaOps.Delete[];
TiogaOps.InsertRope[valueRope];
}
ELSE
MessageWindow.Append[valueRope,
TRUE];
};
END.