/*
* Printing a text file
* This is a very simple demonstration that shows how to use the
* Print Manager to print a text file.
*/
// Assumes inclusion of
#include <PrintTraps.h>
#include
#include < pascal.h>
/* Do you want to prompt for the page setup? */
/* Globals */
FILE *aRandomFile;
/* Prototypes */
void Init(void);
Boolean DoneDrawingPagesOfATextFile(FILE *someFile); void PrintStuff(void);
FILE *GotATextFile(void);
void
Init(void)
{
}
Boolean DoneDrawingPagesOfATextFile(FILE *someFile) {
short i;
for (i = 1; i <= 50; ++i) {
if (feof(someFile))
fgets((char *)aStringOfText, 255, someFile);
CtoPstr((char *)aStringOfText);
/*
* Carrige return characters mess up DrawString, so they are removed.
* Also, tabs are not handled correctly. They are left as an exercise
* for the programmer!
*/
if (aStringOfText[aStringOfText[0]] == '\n')
aStringOfText[aStringOfText[0]] = ' ';
}
}
void PrintStuff(void)
{
if (DoPageSetUp)
else
if (ok)
{
/*
* Now draw a single page. You decide how many pages are drawn, and
* what is drawn in each page. QuickDraw commands are automatically
* translated into commands to the printer. You could draw multiple pages
* like this.
*/
while (!DoneDrawingPagesOfATextFile(aRandomFile)) {
PrClosePage( printPort); /* Close the currently open page. */ PrOpenPage( printPort, nil); /* and open a new one. */ }
/* Print spooled document, if any. */
if ((**hPrint).prJob.bJDocLoop == bSpoolLoop && PrError() ==
noErr)
}
else {
/* You will want to add error handling here... */
}
}
/* Open any text file */
FILE * GotATextFile(void)
{
FILE *someFile;
SFGetFile(where, "\p", nil, 1, theTypeList, nil, &theReply); if (theReply.good) {
someFile = fopen(PtoCstr((char *)theReply.fName), "r");
return someFile;
}
}
main()
{
Init();
if (aRandomFile = GotATextFile()) {
PrintStuff();
f close(aRandomFile);
}
}