XFormat.mesa
Copyright (C) Xerox Corporation 1983, 1986. All rights reserved.
Tim Diebert: November 25, 1986 10:27:31 am PST
DIRECTORY
Basics USING [UnsafeBlock],
BasicTime USING [GMT, nullGMT],
IO USING [STREAM],
NSString USING [Character, String],
TTY USING [Handle],
XNS USING [Address, Host, Net, Socket];
XFormat: CEDAR DEFINITIONS = BEGIN
OPEN nss: NSString;
Types
FormatProc: TYPE = PROCEDURE [r: nss.String, h: Handle];
ClientData: TYPE = REF ANY;
Handle: TYPE = REF Object;
Object: TYPE = RECORD [
proc: FormatProc,
stream: REF ANYNIL,
data: ClientData ← NIL];
DateFormat: TYPE = {dateOnly, timeOnly, dateAndTime};
NetFormat: TYPE = {octal, hex, productSoftware};
NumberFormat: TYPE = RECORD [
base: [2..36] ← 10,
zerofill: BOOLEANFALSE,
signed: BOOLEANFALSE,
columns: [0..255] ← 0];
ErrorCode: TYPE = {invalidFormat, nilData};
Error: ERROR [code: ErrorCode];
Constants
OctalFormat: NumberFormat = [base: 8, zerofill: FALSE, signed: FALSE, columns: 0];
DecimalFormat: NumberFormat = [base: 10, zerofill: FALSE, signed: TRUE, columns: 0];
UnsignedDecimalFormat: NumberFormat =
[base: 10, zerofill: FALSE, signed: FALSE, columns: 0];
HexFormat: NumberFormat = [base: 16, zerofill: FALSE, signed: FALSE, columns: 0];
Format procedures
Blanks: PROCEDURE [h: Handle, n: CARDINAL ← 1];
send n blanks to h.
Block: PROCEDURE [h: Handle, block: Basics.UnsafeBlock];
Char: PROCEDURE [h: Handle, char: CHAR];
CR: PROCEDURE [h: Handle, n: CARDINAL ← 1];
send n carriage returns to h.
Date: PROCEDURE [h: Handle, time: BasicTime.GMT ← BasicTime.nullGMT,
format: DateFormat ← dateAndTime];
Line: PROCEDURE [h: Handle, r: REF TEXT, n: CARDINAL ← 1];
send r followed by n carriage returns to h.
NSString: PROCEDURE [h: Handle, s: nss.String];
NSChar: PROCEDURE [h: Handle, char: nss.Character];
NSLine: PROCEDURE [h: Handle, s: nss.String, n: CARDINAL ← 1];
Reader: PROCEDURE [h: Handle, r: REF TEXT];
ReaderBody: PROCEDURE [h: Handle, rb: REF TEXT];
String: PROCEDURE [h: Handle, s: REF TEXT];
Numeric procs
Decimal: PROCEDURE [h: Handle, n: LONG UNSPECIFIED] = INLINE
{h.Number[n: n, format: DecimalFormat]};
Hex: PROCEDURE [h: Handle, n: LONG UNSPECIFIED] = INLINE
{h.Number[n: n, format: HexFormat]};
Number: PROCEDURE [h: Handle, n: LONG UNSPECIFIED, format: NumberFormat];
Octal: PROCEDURE [h: Handle, n: LONG UNSPECIFIED];
Adds 'B after number if > 7.
Network related procs
HostNumber: PROCEDURE [h: Handle, hostNumber: XNS.Host, format: NetFormat];
NetworkAddress: PROCEDURE [h: Handle, networkAddress: XNS.Address,
format: NetFormat];
NetworkNumber: PROCEDURE [h: Handle, networkNumber: XNS.Net, format: NetFormat];
SocketNumber: PROCEDURE [h: Handle, socketNumber: XNS.Socket,
format: NetFormat];
SetDefaultOutputSink: PROCEDURE [new: Object] RETURNS [old: Object];
proc = NIL in Format procs will direct output to the default output sink.
NSStringProc: FormatProc; -- expects clientData to be a NSString.String;
StreamProc: FormatProc; -- expects clientData to be a IO.STREAM;
TTYProc: FormatProc; -- expects clientData to be a TTY.Handle;
NSStringObject: PROCEDURE [s: nss.String] RETURNS [Handle];
StreamObject: PROCEDURE [sH: IO.STREAM] RETURNS [Handle];
TTYObject: PROCEDURE [h: TTY.Handle] RETURNS [Handle];
END. -- XFormat.mesa