Category : Files from Magazines
Archive   : DDJ0989.ZIP
Filename : DUNTEMAN.LST

 
Output of file : DUNTEMAN.LST contained in archive : DDJ0989.ZIP
_STRUCTURED PROGRAMMING COLUMN_
by Jeff Duntemann

[LISTING ONE]

{--------------------------------------------------------------}
{ PrinByte }
{ }
{ Byte-value print object for object extendability demo }
{ }
{ by Jeff Duntemann }
{ Turbo Pascal V5.5 }
{ Last modified 5/11/89 }
{--------------------------------------------------------------}


UNIT PrinByte;

INTERFACE

USES Printer;


{--------------------------------------------------------------}
{ The PrintByte object "knows" how to print its byte value in }
{ four different formats: As decimal quantity, hex quantity, }
{ binary quantity, and extended ASCII symbol. It takes the }
{ cautious path in printing symbols, as prints spaces for all }
{ of the "control" characters 0-31, "rubout" ($7F), and char }
{ $FF. If your printer has some means of printing smiley }
{ faces and all that other folderol in the low 32 characters, }
{ override the PrintSymbol method with a new method that uses }
{ whatever mechanism your printers offers to print those }
{ characters "spaced out" by this implementation of the }
{ PrintSymbol method. }
{--------------------------------------------------------------}

TYPE
PrintByte = OBJECT
BV : Byte; { Byte value }
FUNCTION DontPrint(ShouldI : Byte) : Boolean;
PROCEDURE PrintDecimal;
PROCEDURE PrintHex;
PROCEDURE PrintBinary;
PROCEDURE PrintSymbol;
END;


IMPLEMENTATION


{ Returns True for any code that CANNOT be printed verbatim }

FUNCTION PrintByte.DontPrint(ShouldI : Byte) : Boolean;

CONST
NotThese = [0..31,127,255]; { Unprintable codes }

BEGIN
IF ShouldI IN NotThese THEN DontPrint := True
ELSE DontPrint := False;
END;



PROCEDURE PrintByte.PrintDecimal;

BEGIN
Write(LST,BV:3);
END;



PROCEDURE PrintByte.PrintHex;

CONST
HexDigits : ARRAY[0..15] OF Char = '0123456789ABCDEF';

BEGIN
Write(LST,HexDigits[BV SHR 4],HexDigits[BV AND $0F]);
END;



PROCEDURE PrintByte.PrintBinary;

VAR
Index : Integer;

BEGIN
FOR Index := 7 DOWNTO 0 DO
IF Odd(BV SHR Index) THEN Write(LST,'1')
ELSE Write(LST,'0');
END;



PROCEDURE PrintByte.PrintSymbol;

BEGIN
IF DontPrint(BV) THEN
Write(LST,' ')
ELSE
Write(LST,Chr(BV));
END;


END.


[LISTING TWO]

{--------------------------------------------------------------}
{ ASCIIChart }
{ }
{ Object Extendability demo program: Prints an ASCII chart }
{ }
{ Note: This program contains control codes specific to }
{ the HP Laserjet Series II Printer. Use with }
{ other printers may be hazardous to your aesthetic }
{ sensibilities. }
{ }
{ Jeff Duntemann }
{ Turbo Pascal V5.5 }
{ Last modified 6/8/89 }
{--------------------------------------------------------------}



{--------------------------------------------------------------}
{ Run this on an HP Laserjet Series II, and you'll get an }
{ ASCII chart including all the weird characters for which the }
{ Series II has characters in its built-in fonts. If you have }
{ some other printer, you need only modify the PrintSymbol }
{ method to use whatever mechanism your printer has to print }
{ the weird characters. By modifying PrintSymbol you are }
{ extending the object PrintByte defined in unit PRINBYTE.PAS, }
{ WITHOUT needing full source code to PRINBYTE.PAS. }
{--------------------------------------------------------------}



PROGRAM ASCIIChart;


USES Printer, { Standard Borland unit }
PrinByte; { PRINBYTE.PAS from DDJ for September 1989 }


CONST
Title = 'THE EXTENDED ASCII CODE AND SYMBOL SET';
Header = ' Dec Hex Binary Symbol Dec Hex Binary Symbol';
BarChar = Chr(205);
ColChar = Chr(177);
FormFeed = Chr(12);


TYPE

{---------------------------------------------------------------}
{ This is a child object of PrintByte, defined in separate file }
{ PRINBYTE.PAS. Remember: PrintByteHP inherits EVERYTHING }
{ defined in PrintByte. EVERYTHING! The only difference is }
{ that the PrintSymbol method is overridden by an HP Series II }
{ specific symbol-print method. Everything else is EXACTLY as }
{ it is defined in PrintByte. }
{---------------------------------------------------------------}

PrintByteHP = OBJECT(PrintByte)
PROCEDURE PrintSymbol
END;


VAR
I,J,K : Integer;
Char1,Char2 : PrintByteHP; { Instances of PrintByteHP object type }


{--------------------------------------------------------------}
{ This method overrides the PrintSymbol method defined in the }
{ PrintByte parent object defined in PRINCHAR.PAS: }
{--------------------------------------------------------------}

PROCEDURE PrintByteHP.PrintSymbol;

BEGIN
IF DontPrint(BV) THEN { If DontPrint method says so, }
Write(LST,Chr(27),'&p1X',Chr(BV)) { use "transparent data print" }
ELSE { feature to print weird chars }
Write(LST,Chr(BV)); { Otherwise, just print 'em... }
END;



PROCEDURE Spaces(NumberOfSpaces : Integer);

VAR
Index : Integer;

BEGIN
FOR Index := 1 TO NumberOfSpaces DO
Write(LST,' ')
END;



PROCEDURE NewPage;

VAR
Index : Integer;

BEGIN
Write(LST,FormFeed);
END;



PROCEDURE PrintHeader;

VAR
Index : Integer;

BEGIN
Spaces(10);
Writeln(LST,Header);
Spaces(10);
FOR Index := 1 TO 60 DO
Write(LST,BarChar);
Writeln(LST);
END;



{--------------------------------------------------------------}
{ Nothing more elaborate here than printing the byte out as a }
{ decimal number, a hex number, a binary number, and a symbol. }
{ The four "Target." calls are method calls to the object }
{ passed to PrintChar in the Target parameter. }
{--------------------------------------------------------------}

PROCEDURE PrintChar(Target : PrintByteHP);

BEGIN
Spaces(3);
Target.PrintDecimal;
Spaces(3);
Target.PrintHex;
Spaces(3);
Target.PrintBinary;
Spaces(3);
Target.PrintSymbol;
Spaces(4);
END;


{--------------------------------------------------------------}
{ This simply sets the HP Series II to its PC symbol set. }
{--------------------------------------------------------------}

PROCEDURE InitHP;

BEGIN
Write(LST,Chr(27),'(10U'); { Select symbol set 10U }
END;




BEGIN
InitHP; { Select the PC symbol set }
Spaces(10); { Output 10 spaces }
Writeln(LST,Title); { Print out the title string }
Writeln(LST); { Space down one line }
FOR I := 0 TO 3 DO { 256 characters takes 4 pages }
BEGIN
FOR K := 1 TO 3 DO Writeln(LST); { Space down 3 lines }
PrintHeader; { Print the chart header }
FOR J := 0 TO 31 DO { Do 2 columns of 32 chars. }
BEGIN
Char1.BV := (I*64)+J; Char2.BV := (I*64)+J+32;
Spaces(10);
PrintChar(Char1); { Print the left column character }
Write(LST,ColChar); { Print the column separator }
PrintChar(Char2); { Print the right column character }
Writeln(LST);
END;
NewPage; { Issue a form feed to printer }
END;
END.


[LISTING THREE]

{--------------------------------------------------------------}
{ PrinByte }
{ }
{ Byte-value print object for object extendibility demo }
{ }
{ by Jeff Duntemann }
{ QuickPascal V1.0 }
{ Last modified 6/6/89 }
{--------------------------------------------------------------}


UNIT PrinByte;

INTERFACE

USES Printer;


{--------------------------------------------------------------}
{ The PrintByte object "knows" how to print its byte value in }
{ four different formats: As decimal quantity, hex quantity, }
{ binary quantity, and extended ASCII symbol. It takes the }
{ cautious path in printing symbols, as prints spaces for all }
{ of the "control" characters 0-31, "rubout" ($7F), and char }
{ $FF. If your printer has some means of printing smiley }
{ faces and all that other folderol in the low 32 characters, }
{ override the PrintSymbol method with a new method that uses }
{ whatever mechanism your printers offers to print those }
{ characters "spaced out" by this implementation of the }
{ PrintSymbol method. }
{--------------------------------------------------------------}

TYPE
PrintByte = OBJECT
BV : Byte; { Byte value }
FUNCTION DontPrint(ShouldI : Byte) : Boolean;
PROCEDURE PrintDecimal;
PROCEDURE PrintHex;
PROCEDURE PrintBinary;
PROCEDURE PrintSymbol;
END;


IMPLEMENTATION


{ Returns True for any code that CANNOT be printed verbatim }

FUNCTION PrintByte.DontPrint(ShouldI : Byte) : Boolean;

CONST
NotThese = [0..31,127,255]; { Unprintable codes }

BEGIN
IF ShouldI IN NotThese THEN DontPrint := True
ELSE DontPrint := False;
END;



PROCEDURE PrintByte.PrintDecimal;

BEGIN
Write(LST,Self.BV:3);
END;



PROCEDURE PrintByte.PrintHex;

CONST
HexDigits : ARRAY[0..15] OF Char = '0123456789ABCDEF';

BEGIN
WITH Self DO
Write(LST,HexDigits[BV SHR 4],HexDigits[BV AND $0F]);
END;



PROCEDURE PrintByte.PrintBinary;

VAR
Index : Integer;

BEGIN
WITH Self DO
FOR Index := 7 DOWNTO 0 DO
IF Odd(BV SHR Index) THEN Write(LST,'1')
ELSE Write(LST,'0');
END;



PROCEDURE PrintByte.PrintSymbol;

BEGIN
WITH Self DO
IF DontPrint(BV) THEN
Write(LST,' ')
ELSE
Write(LST,Chr(BV));
END;


END.


[LISTING FOUR]

{--------------------------------------------------------------}
{ ASCIIChart }
{ }
{ Object Extendability demo program: Prints an ASCII chart }
{ }
{ Note: This program contains control codes specific to }
{ the HP Laserjet Series II Printer. Use with }
{ other printers may be hazardous to your aesthetic }
{ sensibilities. }
{ }
{ Jeff Duntemann }
{ QuickPascal V1.0 }
{ Last modified 6/6/89 }
{--------------------------------------------------------------}



{--------------------------------------------------------------}
{ Run this on an HP Laserjet Series II, and you'll get an }
{ ASCII chart including all the weird characters for which the }
{ Series II has characters in its built-in fonts. If you have }
{ some other printer, you need only modify the PrintSymbol }
{ method to use whatever mechanism your printer has to print }
{ the weird characters. By modifying PrintSymbol you are }
{ extending the object PrintByte defined in unit PRINBYTE.PAS, }
{ WITHOUT needing full source code to PRINBYTE.PAS. }
{--------------------------------------------------------------}



PROGRAM ASCIIChart;


USES Printer, { Standard Borland unit }
PrinByte; { PRINBYTE.PAS from DDJ for September 1989 }


CONST
Title = 'THE EXTENDED ASCII CODE AND SYMBOL SET';
Header = ' Dec Hex Binary Symbol Dec Hex Binary Symbol';
BarChar = Chr(205);
ColChar = Chr(177);
FormFeed = Chr(12);


TYPE

{---------------------------------------------------------------}
{ This is a child object of PrintByte, defined in separate file }
{ PRINBYTE.PAS. Remember: PrintByteHP inherits EVERYTHING }
{ defined in PrintByte. EVERYTHING! The only difference is }
{ that the PrintSymbol method is overridden by an HP Series II }
{ specific symbol-print method. Everything else is EXACTLY as }
{ it is defined in PrintByte. }
{---------------------------------------------------------------}

PrintByteHP = OBJECT(PrintByte)
PROCEDURE PrintSymbol; OVERRIDE
END;


VAR
I,J,K : Integer;
Char1,Char2 : PrintByteHP; { Instances of PrintByteHP object type }


{--------------------------------------------------------------}
{ This method overrides the PrintSymbol method defined in the }
{ PrintByte parent object defined in PRINCHAR.PAS: }
{--------------------------------------------------------------}

PROCEDURE PrintByteHP.PrintSymbol;

BEGIN
WITH Self DO
IF Self.DontPrint(BV) THEN { If DontPrint method says so, }
Write(LST,Chr(27),'&p1X',Chr(BV)) { use "transparent data print" }
ELSE { feature to print weird chars }
Write(LST,Chr(BV)); { Otherwise, just print 'em... }
END;



PROCEDURE Spaces(NumberOfSpaces : Integer);

VAR
Index : Integer;

BEGIN
FOR Index := 1 TO NumberOfSpaces DO
Write(LST,' ')
END;



PROCEDURE NewPage;

VAR
Index : Integer;

BEGIN
Write(LST,FormFeed);
END;



PROCEDURE PrintHeader;

VAR
Index : Integer;

BEGIN
Spaces(10);
Writeln(LST,Header);
Spaces(10);
FOR Index := 1 TO 60 DO
Write(LST,BarChar);
Writeln(LST);
END;



{--------------------------------------------------------------}
{ Nothing more elaborate here than printing the byte out as a }
{ decimal number, a hex number, a binary number, and a symbol. }
{ The four "Target." calls are method calls to the object }
{ passed to PrintChar in the Target parameter. }
{--------------------------------------------------------------}

PROCEDURE PrintChar(Target : PrintByteHP);

BEGIN
Spaces(3);
Target.PrintDecimal;
Spaces(3);
Target.PrintHex;
Spaces(3);
Target.PrintBinary;
Spaces(3);
Target.PrintSymbol;
Spaces(4);
END;


{--------------------------------------------------------------}
{ This simply sets the HP Series II to its PC symbol set. }
{--------------------------------------------------------------}

PROCEDURE InitHP;

BEGIN
Write(LST,Chr(27),'(10U'); { Select symbol set 10U }
END;




BEGIN
InitHP; { Select the PC symbol set }
New(Char1); New(Char2); { Create objects on the heap }
Spaces(10); { Output 10 spaces }
Writeln(LST,Title); { Print out the title string }
Writeln(LST); { Space down one line }
FOR I := 0 TO 3 DO { 256 characters takes 4 pages }
BEGIN
FOR K := 1 TO 3 DO Writeln(LST); { Space down 3 lines }
PrintHeader; { Print the chart header }
FOR J := 0 TO 31 DO { Do 2 columns of 32 chars. }
BEGIN
Char1.BV := (I*64)+J; Char2.BV := (I*64)+J+32;
Spaces(10);
PrintChar(Char1); { Print the left column character }
Write(LST,ColChar); { Print the column separator }
PrintChar(Char2); { Print the right column character }
Writeln(LST);
END;
NewPage; { Issue a form feed to printer }
END;
END.



  3 Responses to “Category : Files from Magazines
Archive   : DDJ0989.ZIP
Filename : DUNTEMAN.LST

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/