/* euroscore.h */

// include standard C libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

// ensure we have TRUE and FALSE
#ifndef TRUE
#define TRUE  1
#define FALSE 0

// other definitions
#define STRLEN 64

// i.e. ../../images/eurovision/2005/semi/image.jpeg
// or   ../../images/eurovision/2005/final/image.jpeg
//      [-------prefix--------][year][path][image][suffix]
// Don't delete "SEMIPATHOLD", it is used with legacy handling!
#define PATHPREFIX  "../../images/eurovision/"
#define SEMIPATHOLD "/semi/"
#define SEMIPATHONE "/semi1/"
#define SEMIPATHTWO "/semi2/"
#define FINALPATH   "/final/"
#define SUFFIX      ".jpeg"

// country structure
typedef struct countrydef
   // From CSV file
   unsigned char name[STRLEN];
     signed int  score;
   unsigned char image[STRLEN];
   unsigned int  semi;
   unsigned char comment[STRLEN];
   unsigned char pointsto[13][STRLEN]; // allow 13 so we can go ...7,8,[9],10,[11],12
   unsigned char titlename[STRLEN];
   unsigned char refname[STRLEN];
   unsigned char song[STRLEN];

   // Calculated
     signed int  ranking; // is -ve if "joint", i.e. "-4" is joint fourth

// image structure
typedef struct imgsizedef
   unsigned int  width;
   unsigned int  height;

// global function definitions and associated variables

// Country
extern struct countrydef *country;
extern unsigned long countrycount;  // how many we have right now
extern unsigned long countrymax;    // how many we can have before reallocation required
extern int  scorelist[];
extern void country_extendarray(void);
extern void country_tidyup(void);
extern void country_process(void);
extern void country_outputeach(void);
extern void country_gentable(int which);
extern void country_votedforme(int which);
extern char *country_alias(int which, int title);

// CSVloader
extern void csvloader_loadfile(char *file);

// ImageSize
extern struct imgsizedef *imagesize_getimagesize(char *path);

// MemTrace
extern void memtrace_init(void);
extern void memtrace_finish(void);
extern void memtrace_addentry(int base, int size, int method, char *parent);
extern void memtrace_removeentry(int base);
extern void *memtrace_calloc(size_t nmemb, size_t size);
extern void *memtrace_namedcalloc(size_t nmemb, size_t size, char *parent);
extern void memtrace_free(void *ptr);
extern void *memtrace_malloc(size_t size);
extern void *memtrace_namedmalloc(size_t size, char *parent);
extern void *memtrace_realloc(void *ptr, size_t size);
extern void *memtrace_namedrealloc(void *ptr, size_t size, char *parent);
extern void memtrace_checkclaims(FILE *stream);
extern void memtrace_dumpsixtyfour(int address, FILE *stream);

// big nasty global variables :-)
extern FILE *in;
extern FILE *out;
extern unsigned char workspace[1024];
extern unsigned int  year;
extern unsigned int  popularity;