/* !VoteFile application.

   Version 2.01:

     * Written in C
     * Compatible with CastAWote 3

    1996 Richard Murray, 6th January 1996

   *** ACORN C RELEASE 4 VERSION ***

   This build provides user prompting.

*/



/* ANSI includes */

#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "swis.h"
#include "bbc.h"
#include "kernel.h"
#include "sprite.h"



/* Define a few variables... */

char creator[255];
char system_addr[255];
int  voted_for;
char question[255];
char software_options[255];
char additional_one[255];
char additional_two[255];
char additional_three[255];
char option_one_text[255];
int  option_one_result;
char option_two_text[255];
int  option_two_result;
char option_three_text[255];
int  option_three_result;
char option_four_text[255];
int  option_four_result;
char option_five_text[255];
int  option_five_result;
char option_six_text[255];
int  option_six_result;
char option_seven_text[255];
int  option_seven_result;
char option_eight_text[255];
int  option_eight_result;

FILE *file_handle;
FILE *fix_handle;
int  number_of_votes;
char junk[255];
int  length_of_string;
int  junk_variable;
int  file_length;
int  fastmode;
int  fixit;
int  easteregg;
int  currvote;
char oldnull[] = "{/}";
int  questionerror;
int  totalquestionerror;
_kernel_swi_regs r;
/* Easter egg! */
#define Radius  64
#define RadDiv2 Radius>>1
#define Step    Radius>>3


/* Procedure/function declarations */

void read_string(FILE *file, char *string);
int read_word(FILE *file);
void write_string(FILE *file, char *string);
void write_word(FILE *file, int num);
void loadquestion(void);
void examinequestion(void);
void updatequestion(void);
void doeasteregg(void);
int balls64_fnrgb(void);



/* Main program code */

int main(int argc, char *argv[])
{
   fastmode = FALSE;
   fixit = FALSE;

   /* Check CLI parameters */
   if (argc == 2)
   {
      junk_variable = strcmp(argv[1],"FAST");
      if (junk_variable == NULL)
         fastmode = TRUE;
      junk_variable = strcmp(argv[1],"FIX");
      if (junk_variable == NULL)
      {
         fastmode = TRUE;
         fixit = TRUE;
      }
      junk_variable = strcmp(argv[1],"EGG");
      if (junk_variable == NULL)
         easteregg = TRUE;
   }

   /* Print a really simple header */
   bbc_mode(12);
   bbc_colour(6);
   if (easteregg == TRUE)
   {
      doeasteregg();
      exit(EXIT_SUCCESS);
   }
   printf("\nWelcome,\n");
   printf("  This program performs a basic validity check on the CastAWote 'data' file.\n");
   if (fixit == TRUE )
      printf("\a  [This program is running in 'fix' mode]\n");

   printf("\nVersion 2.01, Richard Murray 06-01-1996 (Acorn version, C)\n\n");

   /* Then try to open the file */
   if (( file_handle = fopen("<CastAWoteA$Dir>.Data.Data","rb") ) == NULL)
   {
      /* If unsuccessful, barf tidily */
      bbc_colour(1);
      printf("\nERROR! ");
      bbc_colour(7);
      printf("Sorry, the CastAWote data file cannot be opened. Aborting...\n");
      exit(EXIT_FAILURE);
   }

   /* Then try to open the 'fix' file */
   if (fixit == TRUE )
   {
      if (( fix_handle = fopen("<CastAWoteA$Dir>.Data.Fix_Data","wb") ) == NULL)
      {
         /* If unsuccessful, barf tidily */
         bbc_colour(1);
         printf("\nERROR! ");
         bbc_colour(7);
         printf("Sorry, the CastAWote fix file cannot be created. Aborting...\n");
         exit(EXIT_FAILURE);
      }
   }

   /* File length checking code... The HARD way. :-) */
   file_length = 0;
   while ( !feof(file_handle) )
   {
      junk_variable = fgetc(file_handle);
      file_length++;
   }
   bbc_colour(6);
   rewind(file_handle);

   if ( file_length < 55 )
   {
      bbc_colour(1);
      printf("\nERROR! ");
      bbc_colour(7);
      printf("Sorry, this Data file is too short. Aborting...\n");
      exit(EXIT_FAILURE);
   }

   /* First 'string' can be ignored */
   read_string(file_handle, junk);
   if (fixit == TRUE )
      write_string(fix_handle,"*** < ...eliFetoV yb detaerc elif atad etoWAtsaC > ***");

   /* Number of questions */
   number_of_votes = read_word(file_handle);
   if (fixit == TRUE )
      write_word(fix_handle,number_of_votes);

   printf("Preparing to scan %d votes in this database\n",number_of_votes);

   bbc_colour(7);

   if (fastmode != TRUE)
   {
      printf("Please press a key to begin...\n");
      junk_variable = -1;
      while (junk_variable == -1)
      {
         _kernel_swi(OS_ReadC,&r,&r);
         junk_variable = r.r[0];
      }
   }

   currvote=1;
   while(currvote <= number_of_votes)
   {
      questionerror = 0;
      loadquestion();
      examinequestion();
      if (fixit == TRUE )
         updatequestion();
      currvote++;
   }

   /* If fixing, finish up the file */
   if (fixit == TRUE )
   {
      write_string(fix_handle,"elif fo dnE");
      fprintf(fix_handle,"\n\n\nThis file was fixed and recreated by:\n");
      fprintf(fix_handle,"VoteFile version 2.01 (6th January 1994) *ACORN VERSION*\n");
      fprintf(fix_handle,"(C) copyright 1996 Richard Murray\n\n\n");
   }

   /* Print some statistics */
   printf("\n\nA total of %d errors were ",totalquestionerror);
   if (fixit == TRUE )
   {
      printf("found and fixed...\n");
   }
   else
   {
      printf("found...\n");
   }

   bbc_colour(2);
   printf("\n\nBYE!\n");
   fclose(file_handle);
   if ( fixit == TRUE )
      fclose(fix_handle);
   if (fastmode == TRUE )
      os_swi1(Wimp_CommandWindow,-1);
   sprintf(junk,"Set Vote$File$Errors %d",totalquestionerror);
   os_cli(junk);
   exit(totalquestionerror);
}



/* Word/string INPUT#/PRINT# handler */

void read_string(FILE *file, char *string)
{
   int len, i;
   i = fgetc(file);
   if (i != 0x00)
   {
      printf("Oooopppps! Major errors when reading a string.\n");
      printf("I'm looking for a '[00]' byte and didn't find one.\n");
      printf("There is a possibility your votes data is corrupted.\n");
      fclose(file_handle);
      if ( fixit == TRUE )
         fclose(fix_handle);
      exit(2);
   }

   len = fgetc(file);
   if (len>0)
     for (i=len-1;i>=0;i--)
     {
        string[i] = fgetc(file);
     }
     string[len] = '\0';
}


int read_word(FILE *file)
{
   int num;
   num = fgetc(file);
   if (num != 0x40)
   {
      printf("Oooopppps! Major errors when reading a word.\n");
      printf("I'm looking for a '[40]' byte ('@') and didn't find one.\n");
      printf("There is a possibility your votes data is corrupted.\n");
      fclose(file_handle);
      if ( fixit == TRUE )
         fclose(fix_handle);
      exit(2);
   }

   num = fgetc(file);
   num = (num << 8) | fgetc(file);
   num = (num << 8) | fgetc(file);
   num = (num << 8) | fgetc(file);
   return num;
}


void write_string(FILE *file, char *string)
{
   int len = strlen(string);
   int i;
   fputc(0x00, file);
   fputc(len, file);
   for (i=len-1;i>=0;i--)
   {
      fputc(string[i], file);
   }
}


void write_word(FILE *file, int num)
{
   fputc(0x40, file);
   fputc((0xff & (num >> 24)), file);
   fputc((0xff & (num >> 16)), file);
   fputc((0xff & (num >> 8)), file);
   fputc((0xff & num), file);
}




/* Loader */

void loadquestion(void)
{
   read_string(file_handle,creator);
   read_string(file_handle,system_addr);
   voted_for = read_word(file_handle);
   read_string(file_handle,question);
   read_string(file_handle,software_options);
   read_string(file_handle,additional_one);
   read_string(file_handle,additional_two);
   read_string(file_handle,additional_three);
   read_string(file_handle,option_one_text);
   option_one_result = read_word(file_handle);
   read_string(file_handle,option_two_text);
   option_two_result = read_word(file_handle);
   read_string(file_handle,option_three_text);
   option_three_result = read_word(file_handle);
   read_string(file_handle,option_four_text);
   option_four_result = read_word(file_handle);
   read_string(file_handle,option_five_text);
   option_five_result = read_word(file_handle);
   read_string(file_handle,option_six_text);
   option_six_result = read_word(file_handle);
   read_string(file_handle,option_seven_text);
   option_seven_result = read_word(file_handle);
   read_string(file_handle,option_eight_text);
   option_eight_result = read_word(file_handle);
}

void updatequestion(void)
{
   write_string(fix_handle,creator);
   write_string(fix_handle,system_addr);
   write_word(fix_handle,voted_for);
   write_string(fix_handle,question);
   write_string(fix_handle,software_options);
   write_string(fix_handle,additional_one);
   write_string(fix_handle,additional_two);
   write_string(fix_handle,additional_three);
   write_string(fix_handle,option_one_text);
   write_word(fix_handle,option_one_result);
   write_string(fix_handle,option_two_text);
   write_word(fix_handle,option_two_result);
   write_string(fix_handle,option_three_text);
   write_word(fix_handle,option_three_result);
   write_string(fix_handle,option_four_text);
   write_word(fix_handle,option_four_result);
   write_string(fix_handle,option_five_text);
   write_word(fix_handle,option_five_result);
   write_string(fix_handle,option_six_text);
   write_word(fix_handle,option_six_result);
   write_string(fix_handle,option_seven_text);
   write_word(fix_handle,option_seven_result);
   write_string(fix_handle,option_eight_text);
   write_word(fix_handle,option_eight_result);
}



/* Examine code */

void examinequestion(void)
{
   char fixstring[]="<invalid data fixed by VoteFile>";

   printf("%c",12);
   bbc_colour(7);
   printf("\nExamining question #%d (of #%d)...\n\n",currvote,number_of_votes);
   bbc_colour(2);
   printf("Question creator  : %s\n",creator);
   printf("BBS and fido addr : %s\n",system_addr);
   printf("Number voted      : %d\n",voted_for);
   printf("Question          : %s\n",question);
   printf("Software options  : %s\n",software_options);
   printf("Add'l info line 1 : %s\n",additional_one);
   printf("Add'l info line 2 : %s\n",additional_two);
   printf("Add'l info line 3 : %s\n",additional_three);
   printf("Question 1 text   : %s\n",option_one_text);
   printf("Question 1 votes  : %d\n",option_one_result);
   printf("Question 2 text   : %s\n",option_two_text);
   printf("Question 2 votes  : %d\n",option_two_result);
   printf("Question 3 text   : %s\n",option_three_text);
   printf("Question 3 votes  : %d\n",option_three_result);
   printf("Question 4 text   : %s\n",option_four_text);
   printf("Question 4 votes  : %d\n",option_four_result);
   printf("Question 5 text   : %s\n",option_five_text);
   printf("Question 5 votes  : %d\n",option_five_result);
   printf("Question 6 text   : %s\n",option_six_text);
   printf("Question 6 votes  : %d\n",option_six_result);
   printf("Question 7 text   : %s\n",option_seven_text);
   printf("Question 7 votes  : %d\n",option_seven_result);
   printf("Question 8 text   : %s\n",option_eight_text);
   printf("Question 8 votes  : %d\n",option_eight_result);

   bbc_colour(6);
   printf("Examining...");

   /* Look for '{/}' */
   junk_variable = strcmp(creator,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nCREATOR string is outmoded '{/}' null.");
      strcpy(creator,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(system_addr,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSYSTEM_ADDR string is outmoded '{/}' null.");
      strcpy(system_addr,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(question,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nQUESTION string is outmoded '{/}' null.");
      strcpy(question,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(software_options,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSOFTWARE_OPTIONS string is outmoded '{/}' null.");
      strcpy(software_options,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(additional_one,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nADDITIONAL_INFO_1 string is outmoded '{/}' null.");
      strcpy(additional_one,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(additional_two,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nADDITIONAL_INFO_2 string is outmoded '{/}' null.");
      strcpy(additional_two,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(additional_three,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nADDITIONAL_INFO_3 string is outmoded '{/}' null.");
      strcpy(additional_three,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_one_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_1_TEXT string is outmoded '{/}' null.");
      strcpy(option_one_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_two_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_2_TEXT string is outmoded '{/}' null.");
      strcpy(option_two_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_three_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_3_TEXT string is outmoded '{/}' null.");
      strcpy(option_three_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_four_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_4_TEXT string is outmoded '{/}' null.");
      strcpy(option_four_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_five_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_5_TEXT string is outmoded '{/}' null.");
      strcpy(option_five_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_six_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_6_TEXT string is outmoded '{/}' null.");
      strcpy(option_six_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_seven_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_7_TEXT string is outmoded '{/}' null.");
      strcpy(option_seven_text,fixstring);
      bbc_colour(6);
   }
   junk_variable = strcmp(option_eight_text,oldnull);
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_8_TEXT string is outmoded '{/}' null.");
      strcpy(option_eight_text,fixstring);
      bbc_colour(6);
   }

   /* Check the lengths of the strings */
   junk_variable = strlen(creator);
   if ( junk_variable < 2 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nCREATOR text is too short (less than 2 characters).");
      strcpy(creator,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nCREATOR text is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      creator[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(system_addr);
   if ( junk_variable < 3 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSYSTEM_ADDR text is too short (less than 3 characters).");
      strcpy(system_addr,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSYSTEM_ADDR text is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      system_addr[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(question);
   if ( junk_variable < 3 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nQUESTION text is too short (less than 3 characters).");
      strcpy(question,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nQUESTION text is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      question[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(software_options);
   if ( junk_variable < 3 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSOFTWARE_OPTIONS text is too short (less than 3 characters).");
      strcpy(software_options,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nSOFTWARE_OPTIONS text is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      software_options[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_one_text);
   if ( junk_variable < 1 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_1 has no text!.");
      strcpy(option_one_text,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_1 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_one_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_two_text);
   if ( junk_variable < 1 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_2 has no text!.");
      strcpy(option_two_text,fixstring);
      bbc_colour(6);
   }
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_2 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_two_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_three_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_3 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_three_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_four_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_4 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_four_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_five_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_5 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_five_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_six_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_6 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_six_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_seven_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_7 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_seven_text[60]=0;
      bbc_colour(6);
   }
   junk_variable = strlen(option_eight_text);
   if ( junk_variable > 60 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOPTION_8 is too long (over 60 characters).");
      printf("\n  - this could cause serious problems!");
      option_eight_text[60]=0;
      bbc_colour(6);
   }

   /* Is CREATOR anonymous? */
   junk_variable=strcmp(creator,"Anonymous");
   if ( junk_variable == NULL )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nThe creator of this question is Anonymous.");
      bbc_colour(6);
   }

   /* Check to see if the additional info lines are 'sensible' */
   if (strlen(additional_one) == 0 && strlen(additional_two) != 0 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nWeird additional info strings (check 1)");
      bbc_colour(6);
   }
   if (strlen(additional_two) == 0 && strlen(additional_three) != 0 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nWeird additional info strings (check 2)");
      bbc_colour(6);
   }
   if (strlen(additional_one) == 0 && strlen(additional_three) != 0 )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nWeird additional info strings (check 3)");
      bbc_colour(6);
   }

   /* Check to see if end-points are overrun */
   if (strlen(option_three_text) == 0 )
   {
      if (strlen(option_four_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 4 extended beyond end-point (3;4).");
         strcpy(option_four_text,"");
         bbc_colour(6);
      }
      if (strlen(option_five_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 5 extended beyond end-point (3;5).");
         strcpy(option_five_text,"");
         bbc_colour(6);
      }
      if (strlen(option_six_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 6 extended beyond end-point (3;6).");
         strcpy(option_six_text,"");
         bbc_colour(6);
      }
      if (strlen(option_seven_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 7 extended beyond end-point (3;7).");
         strcpy(option_seven_text,"");
         bbc_colour(6);
      }
      if (strlen(option_eight_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 8 extended beyond end-point (3;8).");
         strcpy(option_eight_text,"");
         bbc_colour(6);
      }
   }
   if (strlen(option_four_text) == 0 )
   {
      if (strlen(option_five_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 5 extended beyond end-point (4;5).");
         strcpy(option_five_text,"");
         bbc_colour(6);
      }
      if (strlen(option_six_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 6 extended beyond end-point (4;6).");
         strcpy(option_six_text,"");
         bbc_colour(6);
      }
      if (strlen(option_seven_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 7 extended beyond end-point (4;7).");
         strcpy(option_seven_text,"");
         bbc_colour(6);
      }
      if (strlen(option_eight_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 8 extended beyond end-point (4;8).");
         strcpy(option_eight_text,"");
         bbc_colour(6);
      }
   }
   if (strlen(option_five_text) == 0 )
   {
      if (strlen(option_six_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 6 extended beyond end-point (5;6).");
         strcpy(option_six_text,"");
         bbc_colour(6);
      }
      if (strlen(option_seven_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 7 extended beyond end-point (5;7).");
         strcpy(option_seven_text,"");
         bbc_colour(6);
      }
      if (strlen(option_eight_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 8 extended beyond end-point (5;8).");
         strcpy(option_eight_text,"");
         bbc_colour(6);
      }
   }
   if (strlen(option_six_text) == 0 )
   {
      if (strlen(option_seven_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 7 extended beyond end-point (6;7).");
         strcpy(option_seven_text,"");
         bbc_colour(6);
      }
      if (strlen(option_eight_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 8 extended beyond end-point (6;8).");
         strcpy(option_eight_text,"");
         bbc_colour(6);
      }
   }
   if (strlen(option_seven_text) == 0 )
   {
      if (strlen(option_eight_text) != 0 )
      {
         questionerror++;
         bbc_colour(3);
         printf("\nOption 8 extended beyond end-point (7;8).");
         strcpy(option_eight_text,"");
         bbc_colour(6);
      }
   }

   /* Check to see if null votes have results */
   if (strlen(option_three_text) == 0 && option_three_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 3 has no text but does have a result.");
      option_three_result = 0;
      bbc_colour(6);
   }

   if (strlen(option_four_text) == 0 && option_four_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 4 has no text but does have a result.");
      option_four_result = 0;
      bbc_colour(6);
   }
   if (strlen(option_five_text) == 0 && option_five_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 5 has no text but does have a result.");
      option_five_result = 0;
      bbc_colour(6);
   }
   if (strlen(option_six_text) == 0 && option_six_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 6 has no text but does have a result.");
      option_six_result = 0;
      bbc_colour(6);
   }
   if (strlen(option_seven_text) == 0 && option_seven_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 7 has no text but does have a result.");
      option_seven_result = 0;
      bbc_colour(6);
   }
   if (strlen(option_eight_text) == 0 && option_eight_result != 0)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nOption 8 has no text but does have a result.");
      option_eight_result = 0;
      bbc_colour(6);
   }

   /* See if there are any residual 'tagged' votes from version 2 code */
   if (option_seven_result == -1)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nThis vote has been marked as 'tagged' by old software.");
      option_seven_result = 0;
      bbc_colour(6);
   }
   if (option_eight_result == -1)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nThis vote has been marked as 'tagged' by old software.");
      option_eight_result = 0;
      bbc_colour(6);
   }

   /* Do the votes add up? */
   junk_variable = option_one_result;
   junk_variable += option_two_result;
   junk_variable += option_three_result;
   junk_variable += option_four_result;
   junk_variable += option_five_result;
   junk_variable += option_six_result;
   junk_variable += option_seven_result;
   junk_variable += option_eight_result;
   if (junk_variable != voted_for)
   {
      questionerror++;
      bbc_colour(3);
      printf("\nThe option results (%d) do not equal the total (%d).",junk_variable,voted_for);
      voted_for = junk_variable;
      bbc_colour(6);
   }

   /* See if this vote has been updated for new software */
   junk_variable = strcspn(software_options,"");
   if ( junk_variable == strlen(software_options) )
   {
      questionerror++;
      bbc_colour(3);
      printf("\nThis vote has not been updated, please run the votes convertor.");
      printf("\n  - you will find this in the 'VoteConv' directory.");
      strcpy(system_addr,"<bbsname> @ 0:0/0.0");
      strcpy(software_options,"CastAWote 3.00 alpha/- (ArcBBS)  0000000000000000");
      bbc_colour(6);
   }

   if (questionerror == 0)
   {
      printf("...okay!\n");
   }
   else
   {
      printf("\n...question %d contains %d error(s), use !VoteEdit to repair.\n",currvote,questionerror);
      if (fixit == TRUE )
         printf("[fixed!]");
      totalquestionerror+=questionerror;
   }
   bbc_colour(7);
   if (fastmode != TRUE)
   {
      if (currvote != number_of_votes)
      {
         printf("Please press a key to continue...\n");
         junk_variable = -1;
         while (junk_variable == -1)
         {
            _kernel_swi(OS_ReadC,&r,&r);
            junk_variable = r.r[0];
         }
      }
      else
      {
         printf("Please press a key to finish...\n");
         junk_variable = -1;
         while (junk_variable == -1)
         {
            _kernel_swi(OS_ReadC,&r,&r);
            junk_variable = r.r[0];
         }
      }
   }
}



/* Easter egg code! */

void doeasteregg(void)
{
   int base;
   int x;
   int orgx;
   int orgy;
   int t;
   double l;
   bbc_mode(15);
   while (TRUE != FALSE)
   {
      orgx = (int)(((float)rand()/(float)RAND_MAX)*1300)+1;
      orgy = (int)(((float)rand()/(float)RAND_MAX)*1024)+1;
      l=log(512/Radius)/log(2);
      base = balls64_fnrgb();
      for (x=Radius; x>=Step; x-=Step)
      {
         t=(int) l;
         bbc_vduq(23,17,2,512-(x<<t),0,0,0,0,0);
         if (x<=RadDiv2)
            bbc_gcol(0,base+0x15);
         else
            bbc_gcol(0,base);
         bbc_move(orgx-x/3,orgy-x/3);
         bbc_plot(0x9D,orgx+x,orgy);
      }
   }
}

int balls64_fnrgb(void)
{
  return( (int)(((float)rand()/(float)RAND_MAX)*3)*1 +
          (int)(((float)rand()/(float)RAND_MAX)*3)*4 +
          (int)(((float)rand()/(float)RAND_MAX)*3)*16);
}

