home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
game
/
think
/
chaos
/
src
/
out.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-03
|
31KB
|
1,241 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: Out.c,v $
$Revision: 3.4 $
$Date: 1994/12/03 18:02:26 $
This file contains most of the 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
/*
PointsToA() creates a string holding the number of points from p.
Inputs: s - the string where the result should be written
p - the number of points
*/
void PointsToA(char *s, long p)
{ if (WinnerPoints%2 || DrawPoints%2)
{ sprintf(s, "%ld%s", p/2, (p%2)?".5":" ");
}
else
{ sprintf(s, "%ld", p/2);
}
}
/*
tdwz() returns the DW (German rating number) of a player as short.
*/
int tdwz(struct Player *t)
{ long dwz;
#ifdef AMIGA
if (StrToLong((STRPTR) t->DWZ, &dwz) < 0)
{ dwz = 0;
}
#else
dwz = atol(t->DWZ);
#endif
return ((short) dwz);
}
/*
RatingToA() gets a string from a DWZ or ELO number.
Inputs: s - the string, that should be written
w - the rating number (Note, that this must not be the
Player->DWZ field itself, because this is a string!)
*/
static void RatingToA(char *s, int w)
{ if(w == 0)
{ *s = '\0';
}
else
{ sprintf(s, "%d", w);
}
}
/*
lprint() is used to buffer the output which will be done later with
ProcessOutput(). It can work in two modes: The first is building a list
of lines, the second is collecting ALL lines in a single string.
The latter is needed on the Amiga for using a FloatText gadget while the
list is needed for output on the printer.
Inputs: line - the string holding the line
Result: TRUE, if successfull, FALSE otherwise
*/
int lprint(char *line)
{ extern struct MinList OutputList;
extern void *OutputMemList;
extern int OutputLineLen, OutputLineMaxLen;
extern char*OutputLine;
extern int OutputReturnCode;
struct MinNode *n;
char *ptr;
int i, len;
/*
Get length of string, ignore trailing blanks.
*/
for (i = 1, len = 0, ptr = line; *ptr != '\0'; ptr++, i++)
{ if (*ptr != ' ')
{ len = i;
}
}
if (OutputLineMaxLen == -1)
{ if ((n = GetMem(&OutputMemList, sizeof(*n)+len+1)) == NULL)
{ OutputReturnCode = RETURN_ERROR;
return(FALSE);
}
strncpy((char *) (n+1), line, len);
((char *) (n+1))[len] = '\0';
AddTail((struct List *) &OutputList, (struct Node *) n);
}
else
{ while (OutputLineLen + len + 2 > OutputLineMaxLen)
{ if ((ptr = GetMem(&OutputMemList, OutputLineMaxLen += 16384)) == NULL)
{ OutputReturnCode = RETURN_ERROR;
return(FALSE);
}
if (OutputLine != NULL)
{ strcpy(ptr, OutputLine);
PutMem(OutputLine);
}
OutputLine = ptr;
}
strncpy(OutputLine+OutputLineLen, line, len);
OutputLine[OutputLineLen += len] = '\n';
OutputLine[++OutputLineLen] = '\0';
}
return(TRUE);
}
/*
longlprint() does the same job as lprint(), but can process text with
more than one line. The lines are split and lprint is called for each
line.
Inputs: txt - the string holding the text; note, that a single line must
not extend 512 characters!
Result: TRUE, if successfull, FALSE otherwise
*/
int longlprint(char *txt)
{ char line[512];
char *lptr;
char c;
while (*txt != '\0')
{ lptr = line;
while ((c = *txt) != '\0' && c != '\n')
{ *(lptr++) = *(txt++);
}
*lptr = '\0';
if (!lprint(line))
{ return(FALSE);
}
if (c == '\n')
{ txt++;
}
}
return(TRUE);
}
/*
This function prints the list of players.
Inputs: filename - destination file; see InitOutput()
device - device; see InitOutput()
longformat - TRUE, if long format, FALSE otherwise
*/
void OutPlayerList(char *filename, int device, int longformat)
{ struct Player *t;
int i, lines;
char head[301];
char line1[121], line2[121], line3[121];
char dwz[6], elo[6];
if (longformat == FALSE)
{ lines = 1;
sprintf(head, "%-4s %-30s %6s %6s %s",
GetChaosString(MSG_NUMBER),
GetChaosString(MSG_NAME_OUTPUT),
GetChaosString(MSG_DWZ_OUTPUT),
GetChaosString(MSG_ELO_OUTPUT),
GetChaosString(MSG_CHESSCLUB_OUTPUT));
}
else
{ lines = 4;
sprintf(head, "%-4s %-30s %-30s %s\n"
" %-30s %-30s %s\n"
" %-15s %s%s%s %s%s%s%s%s %s\n",
GetChaosString(MSG_NUMBER),
GetChaosString(MSG_NAME_OUTPUT),
GetChaosString(MSG_STREET_OUTPUT),
GetChaosString(MSG_DWZ_OUTPUT),
GetChaosString(MSG_CHESSCLUB_OUTPUT),
GetChaosString(MSG_VILLAGE_OUTPUT),
GetChaosString(MSG_ELO_OUTPUT),
GetChaosString(MSG_BIRTHDAY_OUTPUT),
GetChaosString(MSG_SENIOR_SHORT),
GetChaosString(MSG_JUNIOR_SHORT),
GetChaosString(MSG_WOMAN_SHORT),
GetChaosString(MSG_JUNIORA_SHORT),
GetChaosString(MSG_JUNIORB_SHORT),
GetChaosString(MSG_JUNIORC_SHORT),
GetChaosString(MSG_JUNIORD_SHORT),
GetChaosString(MSG_JUNIORE_SHORT),
GetChaosString(MSG_PHONE_OUTPUT));
}
if (!InitOutput((char *) GetChaosString(MSG_PLAYER_LIST_TITLE),
head, head, filename, "#?.plst", device, lines, lines))
{ TerminateOutput();
return;
}
for (t = (struct Player *) PlayerList.lh_Head, i = 1;
t->Tn_Node.ln_Succ != NULL;
t = (struct Player *) t->Tn_Node.ln_Succ, i++)
{ RatingToA(dwz, tdwz(t));
RatingToA(elo, (int) t->ELO);
if (!longformat)
{ sprintf(line1, "%-4d %-30s %6s %6s %-30s", i, t->Name, dwz, elo,
t->ChessClub);
if (!lprint(line1))
{ TerminateOutput();
return;
}
}
else
{ sprintf(line1, "%-4d %-30s %-30s %s", i, t->Name, t->Street, dwz);
sprintf(line2, " %-30s %-30s %s", t->ChessClub, t->Village, elo);
sprintf(line3, " %-15s %s%s%s %s%s%s%s%s %s",
t->BirthDay,
(t->Flags & TNFLAGSF_SENIOR) ?
(char *) GetChaosString(MSG_SENIOR_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIOR) ?
(char *) GetChaosString(MSG_JUNIOR_SHORT) : " ",
(t->Flags & TNFLAGSF_WOMAN) ?
(char *) GetChaosString(MSG_WOMAN_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIORA) ?
(char *) GetChaosString(MSG_JUNIORA_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIORB) ?
(char *) GetChaosString(MSG_JUNIORB_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIORC) ?
(char *) GetChaosString(MSG_JUNIORC_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIORD) ?
(char *) GetChaosString(MSG_JUNIORD_SHORT) : " ",
(t->Flags & TNFLAGSF_JUNIORE) ?
(char *) GetChaosString(MSG_JUNIORE_SHORT) : " ",
t->PhoneNr);
if (!lprint(line1) || !lprint(line2) ||
!lprint(line3) || !lprint(""))
{ TerminateOutput();
return;
}
}
}
ProcessOutput();
TerminateOutput();
}
/*
This function prints the results of one round.
Inputs: filename - destination file; see InitOutput()
device - output device; see InitOutput()
Round - number of the round, that should be printed
*/
void OutRound(char *filename, int device, int Round)
{ void *memlist;
struct MinList *rlist;
struct GameNode *gn;
char head[81];
char title[81];
if ((rlist = GetRound(&memlist, Round, TRUE,
(device == DEVICE_Screen) ? 0 : 1))
== NULL)
{ return;
}
sprintf(head, "%4s %-30s:%-30s %s"