programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Print Paging and Code Cleanup

From: Mike Ghan <mikeghan_at_logix-controls.com>
Date: Mon, 13 Oct 2003 12:50:42 -0700

Bob,

I have a couple of print examples at

http://logix-controls.com/SwiftForth/PrintRich.htm

http://logix-controls.com/SwiftForth/PrintExample.htm

Hope this helps,

Mike

-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
Behalf
Of Bob Nash
Sent: Monday, October 13, 2003 11:13 AM
To: sftalk
Subject: [sftalk] Print Paging and Code Cleanup

Here is some kind of working code for printing a log file from within
a =
turnkey app. PRINT-LOG is attached to a menu item (DailyFile$ is set
=
elsewhere). =20

My problem: I have not been able to get paging to work (e.g., EOP
COUNT =
TYPE in ?PAGE does not do a page eject). Otherwise, it works ok but I
=
am sure that there must be a much simpler way to do this (this was a =
quick hack, be gentle). I had the expectation that the WINPRINT =
personality would patch up user variables such as PAGE, but I guess
not. =
 Also, I am maintaining a number of paging values that must have =
equivalents already defined.

Any suggestions on how to clean up my code and make the paging work?
It =
would also be nice to change fonts, do boldface, etc. Is there an
easy =
way to do this?

\ ------------ Start of Semi-Working Printing Code -----------

PRINTING +ORDER

1 VALUE LOG-PAGE#
1 VALUE LOG-#PAGES
0 VALUE LOG-#LINES
0 VALUE LOG-LINE#
50 VALUE LOG-#LINES/PAGE
256 CONSTANT |MAX-RECORD| \ max size of log record

: .FILLER ( a n n1 -- ) \ output n1 copies of string=20
>R 2DUP PAD PLACE R> 1- 0 MAX 0 DO 2DUP PAD APPEND LOOP 2DROP=20
   PAD COUNT TYPE ;

: .CRLF ( n -- ) 0 MAX 250 MIN 0 DO <CRLF> COUNT TYPE LOOP ;

: .PRINT-HEADER ( -- )
   S" Log File: " TYPE DailyFile$ ZCOUNT TYPE=20
   SPACE SPACE DATE SPACE SPACE TIME
   S" " 30 .FILLER =20
   S" Page " TYPE LOG-PAGE# (.) TYPE S" of " TYPE LOG-#PAGES (.) =
TYPE
   1 .CRLF S" -" 100 .FILLER 2 .CRLF ;

CREATE EOP 1 C, $0C C, 0 C,

: ?PAGE ( -- ) \ check for page eject
   LOG-LINE# LOG-#LINES/PAGE < NOT IF
      EOP COUNT TYPE 4 .CRLF 1 +TO LOG-PAGE# .PRINT-HEADER =20
      0 TO LOG-LINE#
   THEN ;

: ?!#LINES ( fid -- ) \ read file to set #pages & #lines
   0 TO LOG-#LINES
   LOCALS| fid | fid FILE-SIZE DROP=20
   10 UM/MOD NIP 0 DO
      PAD |MAX-RECORD| fid READ-LINE DROP NOT IF DROP LEAVE THEN
      ( -- #read) DROP 1 +TO LOG-#LINES=20
   LOOP
   LOG-#LINES LOG-#LINES/PAGE /MOD SWAP 0> IF 1+ THEN TO
LOG-#PAGES=20
   fid REWIND-FILE DROP ;
   =20
: (PRINT-LOG) ( fid -- ) LOCALS| fid |=20
   1 TO LOG-PAGE#
   fid ?!#LINES .PRINT-HEADER
   LOG-#LINES 0 DO
      PAD 256 fid READ-LINE DROP IF=20
         ?DUP IF PAD SWAP TYPE 1 .CRLF THEN
      ELSE DROP LEAVE THEN
      1 +TO LOG-LINE# ?PAGE
   LOOP ;

: PRINT-LOG =20
   STOP-DELOGGING
   WINPRINT OPEN-PERSONALITY
      DailyFile$ ZCOUNT R/W OPEN-FILE IF=20
         DROP ( bogus fid)
         S" Couldn't Open " TYPE DailyFile$ ZCOUNT TYPE
      ELSE
         DUP (PRINT-LOG) CLOSE-FILE DROP
      THEN
   CLOSE-PERSONALITY
   START-DELOGGING ;

PRINTING -ORDER =20
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Oct 13 2003 - 12:55:12 PDT

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:33 PST