home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #3
/
amigamamagazinepolishissue1998.iso
/
bazy
/
amigabase-stamps
/
arexx
/
printpages.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1995-03-11
|
5KB
|
185 lines
/* AREXX-macro used to print text to a printer, with pagenumbers on each page
© 1995 Mads Lie Jensen.
You may change this one as much as you like to!!!
Written with AmigaBase in mind. Ofcourse, it could also have been writen in
AmigaBase, but then would other programs not be able to use it.
This is a prototype of the macro. There are still a few things needed to be
done. But it can be used, if you just remember the following:
There is no checking of linelengths, so if a line is longer than 'chars',
it will print out on two lines, but the program will only think that it printed
one line. This would then cause the page-numbers to be printed on the wrong
pages.
Things to implement:
Possible to select if the 'text' should be printed at the top or bottom
of a page.
Selection of print pitch, like ELITE, CONDENSED and so on.
Select a value to indent all the text by, so you could get a nice left margin
argument-table
--------------
(S) File to print
(I) Lines pr. page
(I) Characters pr. line.
(S) Tekst to print at the bottom line.
%p means insert the current pagenumber.
%m means insert the maximum number of pages.
(I) Justification of the text.
-1 Left justified
0 Centered
1 Right justified
(S) If you want a FormFeed sent after each page, this is YES. All other
values means no.
The following line is used to run the program during development:
rx REXX:MLJ-Products/Printpages.rexx REXX:MLJ-Products/Printpages.rexx 65 80 "Side %p/%m (%p)" 1 YES
*/
SIGNAL ON ERROR
OPTIONS RESULTS
/*TRACE R*/
/* Reads a standard CLI-line with each argument separeted from
each other by spaces and then exchange all blanks between the arguments
with kommas (,). Blanks in strings included in "" is not exchanged.
Lastly, the arguments are trimmed for "-signs, and the number of arguments
and the arguments themselves, are returned
*/
PARSE ARG arguments
i = 0
bracket = 0
argnum = 1
DO i = 1 FOR LENGTH(arguments) BY 1
c = SUBSTR(arguments,i,1)
IF c = '"' THEN bracket = ~bracket
IF (c = ' ' & ~bracket) THEN DO
arguments = DELSTR(arguments,i,1)
arguments = INSERT(',',arguments,i-1,1)
argnum = argnum +1
END
END
IF argnum < 6 | argnum >7 THEN
CALL END('Wrong number of arguments!')
arguments = COMPRESS(arguments,'"')
PARSE VAR arguments file ',' lines ',' chars ',' text ',' just ',' ff .
/* Check if the parameters are legal */
IF ~DATATYPE(lines,'W') | ~DATATYPE(chars,'W') | (just <-1 & just >1) THEN
CALL END('Wrong argument-type(s)!')
/* Set the ff value to something usefull */
IF UPPER(ff) = 'YES' THEN
ff='0C'x
ELSE
ff = ''
IF ~EXISTS(file) THEN
CALL END('File not found!')
IF OPEN('Fromfile',file,'R') THEN DO
/* Get the number of lines in the file. If the final line in your file
has an ending RETURN-code, which normal files normally have, then
the number of lines will be one bigger than the actual number of lines
*/
numlines = 0
DO numlines = numlines +1 UNTIL EOF('Fromfile')
CALL READLN('Fromfile')
END
IF OPEN('printer','PRT:','W') THEN DO
pos = SEEK('Fromfile',0,'BEGIN')
pages = TRUNC(numlines / (lines-1)) + 1
curpage = 0
/* Exchange the %m-sign. This will always be the same value through
the entire document, so theres no need to do this loop more than
once, like the %s-sign which will get a new value for every page.
We can also operate directly on the text-string, since this is
only done once.
*/
position = POS('%m',text)
DO WHILE position > 0
text = DELSTR(text,position,2)
text = INSERT(pages,text,position-1)
position = POS('%m',text)
END
DO pages
/* Write the text */
DO lines - 1
CALL WRITELN('printer',READLN('Fromfile'))
END
curpage = curpage + 1
/* Exchange the %-codes in the text-string with the apropriate values.
We have to operate on a copy of the text-string, or else we won't
be able to find any %p-signs next time we want to.
*/
newtext = text
position = POS('%p',newtext)
DO WHILE position > 0
newtext = DELSTR(newtext,position,2)
newtext = INSERT(curpage,newtext,position-1)
position = POS('%p',newtext)
END
/* Now we calculate the text to write at the bottom line.
If it is to be left justified (-1), we don't need to do anything.
If right (1) justified we must put spaces in front of the text,
until it is exactly the length indicated by 'chars'.
If centered (0), we only pad out with half the numbers of spaces,
as we did with right justification.
*/
SELECT
WHEN just = 1 THEN
newtext = COPIES(' ',(chars - LENGTH(newtext))) || newtext
WHEN just = 0 THEN
newtext = CENTER(newtext,chars)
OTHERWISE
newtext = newtext
END
CALL WRITELN('printer',newtext)
CALL WRITECH('printer',ff)
END
END
ELSE
CALL END('Could not open printer')
END
ELSE
CALL END('Could not open file')
EXIT
END:
PARSE ARG error
SAY error
EXIT