home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
game
/
think
/
chaos
/
src
/
outami.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-19
|
12KB
|
483 lines
/* Chaos: The Chess HAppening Organisation System V5.3
Copyright (C) 1993 Jochen Wiedmann
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$RCSfile: OutAmi.c,v $
$Revision: 3.2 $
$Date: 1994/11/19 19:32:01 $
These are the system dependent output functions.
Computer: Amiga 1200 Compiler: Dice 2.07.54 (3.0)
Author: Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Tel. 07123 / 14881
Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
*/
#ifndef CHAOS_H
#include "chaos.h"
#endif
#ifdef AMIGA
#ifndef EXEC_EXECBASE_H
#include <exec/libraries.h>
#endif
#ifndef PREFS_PREFHDR_H
#include <prefs/prefhdr.h>
#endif
#ifndef PREFS_PRINTERTXT_H
#include <prefs/printertxt.h>
#endif
#ifndef CLIB_IFFPARSE_PROTOS_H
#include <clib/iffparse_protos.h>
#endif
#ifdef AZTEC
#ifndef __PRAMASE_IFFPARSE_LIB_H
#include <pragmas/iffparse_lib.h>
#endif
#endif /* AZTEC */
#if defined(_DCC) || defined(__SASC) || defined(__MAXON__)
#ifndef PRAMASE_IFFPARSE_PRAGMAS_H
#include <pragmas/iffparse_pragmas.h>
#endif
#endif /* _DCC || __SASC || __MAXON */
#ifdef __GNUC__
#ifndef _INLINE_IFFPARSE_H
#include <inline/iffparse.h>
#endif
#endif /* __GNUC__ */
#endif /* AMIGA */
/*
The following function makes text being centered on the printer.
This isn't needed at all and might be a stub function on other systems
than the Amiga.
Inputs: device - the device to which the output goes
Results: TRUE, if successfull, FALSE otherwise
*/
int CenterText(int device)
#ifdef AMIGA /* The following lines produce centered output */
{
if ((device == DEVICE_PrinterLQ || device == DEVICE_PrinterDraft) &&
!lprint("\2331 F"))
{ return(FALSE);
}
return(TRUE);
}
#endif /* AMIGA */
/*
The InitOutput() function gets called by output functions before they
do any output via lprint() or longlprint().
Inputs: title - the printed document's title
prthead - the head to print above each page (printer output)
scrhead - the head to appear on top of the output window
(screen output)
filename - the destination file (used if output to file only);
this can be NULL, in which case InitOutput() brings
up a filerequester asking for the filename
device - the output device: DEVICE_Screen, DEVICE_PrinterDraft,
DEVICE_PrinterLQ, Device_FileAscii or DEVICE_FileTeX
prtlines - the number of lines, that one item needs on the
printer
scrlines - the number of lines, that one item needs on the
screen
Result: TRUE, if successfull, FALSE otherwise
*/
static char *titleOutput;
static char *prtheadOutput;
static char *scrheadOutput;
static char *filenameOutput;
static int deviceOutput;
static int prtlinesOutput;
static int scrlinesOutput;
void *OutputMemList;
struct MinList OutputList;
char *OutputLine;
int OutputLineLen;
int OutputLineMaxLen;
int OutputReturnCode;
int InitOutput(char *title, char *prthead, char *scrhead, char *filename,
char *ending, int device, int prtlines, int scrlines)
#ifdef AMIGA
{
prtlinesOutput = prtlines;
scrlinesOutput = scrlines;
OutputReturnCode = 0;
OutputMemList = NULL;
OutputLine = NULL;
OutputLineLen = OutputLineMaxLen = (device == DEVICE_Screen) ? 0 : -1;
deviceOutput = device;
NewList((struct List *) &OutputList);
if ((device == DEVICE_FileAscii || device == DEVICE_FileTeX) &&
filename == NULL)
{ if ((filename = FileRequest(NULL,
(char *) GetChaosString(WND_ASCIIFILE_TITLE),
(device == DEVICE_FileTeX) ? "#?.tex" : ending,
TRUE))
== NULL)
{ OutputReturnCode = RETURN_WARN;
return(FALSE);
}
}
if (!(titleOutput = GetStringMem(&OutputMemList, title)) ||
!(prtheadOutput = GetStringMem(&OutputMemList, prthead)) ||
!(scrheadOutput = GetStringMem(&OutputMemList, scrhead)) ||
(filename != NULL &&
!(filenameOutput = GetStringMem(&OutputMemList, filename))))
{ TerminateOutput();
OutputReturnCode = RETURN_ERROR;
return(FALSE);
}
return(TRUE);
}
#endif /* AMIGA */
/*
TerminateOutput() gets called from the output functions if an error
occurs or if the output is ended.
*/
void TerminateOutput(void)
#ifdef AMIGA
{
PutMemList(&OutputMemList);
}
#endif /* AMIGA */
/*
ProcessOutput() gets called, if a list of lines to be printed is setup
with lprint or "by hand". (see OutRound)
Inputs: list - list of lines to be printed; this can be NULL, in which
case OutputList is assumed
*/
void ProcessOutput(void)
#ifdef AMIGA
{ struct MinNode *line;
/*
Output to a file is rather simple...
*/
if (deviceOutput == DEVICE_FileAscii || deviceOutput == DEVICE_FileTeX)
{ FILE *fh;
if ((fh = fopen(filenameOutput, "w")) == NULL)
{ ShowError((char *) GetChaosString(MSG_NO_WRITE_FILE),
filenameOutput, IoErr());
OutputReturnCode = RETURN_ERROR;
return;
}
if (deviceOutput == DEVICE_FileAscii &&
(fputs(TrnName, fh) < 0 || fputs("\n\n", fh) < 0 ||
fputs(titleOutput, fh) < 0 || fputs("\n\n", fh) < 0 ||
fputs(prtheadOutput, fh) < 0 || fputs("\n\n", fh) < 0))
{ OutputReturnCode = RETURN_ERROR;
}
else
{ for(line = OutputList.mlh_Head; line->mln_Succ != NULL;
line = line->mln_Succ)
{ if (fputs((char *) (line+1), fh) < 0 ||
fputc('\n', fh) == EOF)
{ OutputReturnCode = RETURN_ERROR;
break;
}
}
}
fclose(fh);
}
/*
Output to the printer is a little bit more complicated, because it
is page oriented. The largest problem is to get the paper length.
Sigh! Why are the new preferences that complicated?
*/
else if (deviceOutput != DEVICE_Screen)
{ int paperlen, pagenr, lines;
FILE *fh;
int j, writeerr;
/*
Get the paperlength
*/
struct Preferences Prefs;
GetPrefs(&Prefs, sizeof(Prefs));
paperlen = Prefs.PaperLength;
#ifdef V39_INCLUDES
{ struct IFFHandle *iffhandle;
struct StoredProperty *sp;
int ifferr;
extern struct Library *IFFParseBase;
extern struct Library *SysBase;
if(IFFParseBase != NULL && SysBase->lib_Version >= 37)
{ if ((iffhandle = AllocIFF()) != NULL)
{ if ((iffhandle->iff_Stream = Open((STRPTR) "ENV:SYS/Printer.prefs",
MODE_OLDFILE))
!= NULL)
{ InitIFFasDOS(iffhandle);
if (OpenIFF(iffhandle, IFFF_READ) == 0)
{ if (PropChunk(iffhandle, ID_PREF, ID_PTXT) == 0)
{ for(;;)
{ ifferr = ParseIFF(iffhandle, IFFPARSE_STEP);
if (ifferr != 0)
{ if (ifferr == IFFERR_EOC)
{ continue;
}
else
{ break;
}
}
if ((sp = FindProp(iffhandle, ID_PREF, ID_PTXT))
!= NULL)
{ paperlen = ((struct PrinterTxtPrefs *)
(sp->sp_Data))->pt_PaperLength;
break;
}
}
}
CloseIFF(iffhandle);
}
Close(iffhandle->iff_Stream);
}
FreeIFF(iffhandle);
}
}
}
#endif
if ((fh = fopen("prt:", "w")) == NULL)
{ ShowError((char *) GetChaosString(MSG_NO_PRINTER));
OutputReturnCode = RETURN_ERROR;
return;
}
writeerr = TRUE;
/*
Put application into sleep mode.
*/
set(App, MUIA_Application_Sleep, TRUE);
/*
Put printer into draft or LQ mode
*/
if (fprintf(fh, "%s",
(deviceOutput == DEVICE_PrinterDraft) ?
"\2331\"z" : "\2332\"z") < 0)
{ goto WriteError;
}
line = OutputList.mlh_Head;
pagenr = 0;
while (line->mln_Succ != NULL)