Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199512_2.adf » !Regulars » Regulars/StarInfo/Seery/c/core

Regulars/StarInfo/Seery/c/core

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199512_2.adf » !Regulars
Filename: Regulars/StarInfo/Seery/c/core
Read OK:
File size: 1B75 bytes
Load address: 0000
Exec address: 0000
File contents
/** core.c *******************************************************************
 *
 *  Core routines for 'fittapes'
 *
 *  (c) David Seery 1995
 *
 *****************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "fittapes.h"

/** Anchors ******************************************************************/

Lexeme    lexList_head = NULL, lexList_tail = NULL;
Video     videoList_head = NULL, videoList_tail = NULL;
Category  categoryList_head = NULL, categoryList_tail = NULL;
Programme progList_head = NULL, progList_tail = NULL;
VideoList bestFit = NULL;

/** Globals ******************************************************************/

int main(int argc, char *argv[]);

/** Locals *******************************************************************/

static void parseArgs(int argc, char *argv[]);
static void printInfo(FILE *f);
static void validate(void);
static void printFit(FILE *f);
#if (0)
static void dumpLex(void);
#endif

#define MAX_FILENAME_LENGTH 256

static char sourceFile[MAX_FILENAME_LENGTH] = {0};
static char outputFile[MAX_FILENAME_LENGTH] = {0};

/*****************************************************************************/

int main(int argc, char *argv[])
{
  FILE *f;

  parseArgs(argc,argv);

  lex(sourceFile);

  if (yyparse() != 0)
  {
    printf("[error]: errors in parsing, aborting\n");
    exit(EXIT_FAILURE);
  }

  validate();

  f = fopen(outputFile,"w");
  printInfo(f);

  fit(f);

  printFit(f);

  fclose(f);

  return (EXIT_SUCCESS);
}

/*****************************************************************************/

static void parseArgs(int argc, char *argv[])
{
  boolean sourcePresent = false;
  boolean outputPresent = false;
  int i;

  for (i = 1; i < (argc -1); i++)
  {
    if (strcmp(argv[i],"-s") == 0)
    {
      strcpy(sourceFile,argv[++i]);
      sourcePresent = true;
    }
    else if (strcmp(argv[i],"-o") == 0)
    {
      strcpy(outputFile,argv[++i]);
      outputPresent = true;
    }
    else
    {
      printf("[warning]: unrecognized switch '%s'\n",argv[i]);
    }
  }

  if (sourcePresent == false
      || outputPresent == false)
  {
    printf("[error]: incomplete specification (include -s and -o switches)\n");
    exit(EXIT_FAILURE);
  }
}

static void validate()
{
  Programme p;

  for (p = progList_head; p != NULL; p = p->next)
  {
    if (p->start_hrs == -1 || p->start_mins == -1 || p->start_secs == -1
    	|| p->end_hrs == -1 || p->end_mins == -1 || p->end_secs == -1
    	|| p->length == -1)
    {
      printf("[error]: incomplete declaration of programme '%s'\n",
      	     p->name);
    }
    if (p->type != NULL && (p->precedes != NULL || p->follows != NULL))
    {
      printf("[error]: category and group specified in '%s'\n",p->name);
    }
    if (p->from == NULL)
    {
      printf("[error]: in '%s' no 'from' field declared\n",p->name);
      exit(EXIT_FAILURE);
    }
  }
}

static void printInfo(FILE *f)
{
  Video v;
  Category c;
  Programme p;

  fprintf(f,"FitTapes - Best Fit of Programmes -> Tapes\n"
  	    "******************************************\n\n");

  fprintf(f,"Videos, with lengths\n\n");

  for (v = videoList_head; v != NULL; v = v->next)
  {
    fprintf(f,"\t'%s', length %d seconds\n",v->name,v->length);
  }
  fprintf(f,"\n");

  fprintf(f,"Categories, with allocated numbers\n\n");

  for (c = categoryList_head; c != NULL; c = c->next)
  {
    fprintf(f,"\t'%s', category number %d\n",c->name,c->number);
  }
  fprintf(f,"\n");

  fprintf(f,"Declared programmes\n\n");

  for (p = progList_head; p != NULL; p = p->next)
  {
    fprintf(f,"\tProgramme '%s'\n",p->name);
    if (p->from != NULL)
    {
      fprintf(f,"\t\tSource\t\t= '%s'\n",p->from->name);
    }
    if (p->start_hrs != -1 && p->start_mins != -1 && p->start_secs != -1)
    {
      fprintf(f,"\t\tStart time\t= %.2d:%.2d:%.2d\n",
      	      p->start_hrs,p->start_mins,p->start_secs);
    }
    if (p->end_hrs != -1 && p->end_mins != -1 && p->end_secs != -1)
    {
      fprintf(f,"\t\tEnd time\t= %.2d:%.2d:%.2d\n",
      	      p->end_hrs,p->end_mins,p->end_secs);
    }
    if (p->length != -1)
    {
      fprintf(f,"\t\tTotal length\t= %d seconds\n",p->length);
    }
    if (p->type != NULL)
    {
      fprintf(f,"\t\tCategory\t= %d ('%s')\n",p->type->number,p->type->name);
    }
    if (p->precedes != NULL)
    {
      fprintf(f,"\t\tPrecedes\t'%s'\n",p->precedes);
    }
    if (p->follows != NULL)
    {
      fprintf(f,"\t\tFollows\t\t'%s'\n",p->follows);
    }
  }
}

static void printFit(FILE *f)
{
  VideoList vL;
  ProgrammeList pL;
  int timeoffset;

  fprintf(f,"\n"
  	    "\tListing:\n\n");

  for (vL = bestFit; vL != NULL; vL = vL->next)
  {
    timeoffset = 0;
    fprintf(f,"\tVideo '%s'\n",vL->video->name);
    if (vL->programmes == NULL)
    {
      fprintf(f,"\t\tUnused\n");
    }
    else
    {
      for (pL = vL->programmes; pL != NULL; pL = pL->next)
      {
        fprintf(f,"\t\t'%s'",pL->programme->name);
        if (pL->programme->type != NULL)
        {
          fprintf(f," - '%s'\n",pL->programme->type->name);
        }
        else
        {
          fprintf(f,"\n");
        }
        fprintf(f,"\t\t\t%.2d:%.2d:%.2d - length %.2d:%.2d:%.2d\n",
        	timeoffset/60/60,timeoffset/60%60,timeoffset%60,
        	pL->programme->length/60/60,pL->programme->length/60%60,
        	pL->programme->length%60);
        timeoffset += pL->programme->length;
      }
    }
  }

  fprintf(f,"\n"
  	    "** Copy List **\n\n");
  for (vL = bestFit; vL != NULL; vL = vL->next)
  {
    timeoffset = 0;
    for (pL = vL->programmes; pL != NULL; pL = pL->next)
    {
      fprintf(f,"\tfrom '%s' %.2d:%.2d:%.2d copy %.2d:%.2d:%.2d to '%s' "
      	        "%.2d:%.2d:%.2d\n",
      	      pL->programme->from->name,pL->programme->start_hrs,
      	      pL->programme->start_mins,pL->programme->start_secs,
      	      pL->programme->length/60/60,pL->programme->length/60%60,
      	      pL->programme->length%60,vL->video->name,timeoffset/60/60,
      	      timeoffset/60%60,timeoffset%60);
      timeoffset += pL->programme->length;
    }
  }
}

#if (0)
static void dumpLex()
{
  FILE *ofp = fopen("lexer","w");
  Lexeme ll;
  char lexemes[23][14] = {
    "begin","end","video","e240","e180","e120","e60","categories","programme",
    "from","starts","ends","category","precedes","follows","{","}",",",";",
    "identifier","stringLiteral","constant","endOfStream"
  };

  for (ll = lexList_head; ll != NULL; ll = ll->next)
  {
    fprintf(ofp,"%s\t",lexemes[ll->lexeme_type]);
    switch (ll->lexeme_type)
    {
      case identifier:
        fprintf(ofp,"'%s'\t",ll->lexeme_value.identifierValue);
        break;
      case stringLiteral:
        fprintf(ofp,"\"%s\"\t",ll->lexeme_value.stringLiteralValue);
        break;
      case constant:
        fprintf(ofp,"%d\t",ll->lexeme_value.constantValue);
        break;
    }
    fprintf(ofp,"[line %d of %s]\n",ll->source_line,ll->source_file);
  }
}
#endif
00000000  2f 2a 2a 20 63 6f 72 65  2e 63 20 2a 2a 2a 2a 2a  |/** core.c *****|
00000010  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000040  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 0a 20  |**************. |
00000050  2a 0a 20 2a 20 20 43 6f  72 65 20 72 6f 75 74 69  |*. *  Core routi|
00000060  6e 65 73 20 66 6f 72 20  27 66 69 74 74 61 70 65  |nes for 'fittape|
00000070  73 27 0a 20 2a 0a 20 2a  20 20 28 63 29 20 44 61  |s'. *. *  (c) Da|
00000080  76 69 64 20 53 65 65 72  79 20 31 39 39 35 0a 20  |vid Seery 1995. |
00000090  2a 0a 20 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |*. *************|
000000a0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000000e0  2f 0a 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |/..#include <std|
000000f0  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
00000100  3c 73 74 64 69 6f 2e 68  3e 0a 23 69 6e 63 6c 75  |<stdio.h>.#inclu|
00000110  64 65 20 3c 73 74 72 69  6e 67 2e 68 3e 0a 0a 23  |de <string.h>..#|
00000120  69 6e 63 6c 75 64 65 20  22 66 69 74 74 61 70 65  |include "fittape|
00000130  73 2e 68 22 0a 0a 2f 2a  2a 20 41 6e 63 68 6f 72  |s.h"../** Anchor|
00000140  73 20 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |s **************|
00000150  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000180  2a 2a 2a 2a 2f 0a 0a 4c  65 78 65 6d 65 20 20 20  |****/..Lexeme   |
00000190  20 6c 65 78 4c 69 73 74  5f 68 65 61 64 20 3d 20  | lexList_head = |
000001a0  4e 55 4c 4c 2c 20 6c 65  78 4c 69 73 74 5f 74 61  |NULL, lexList_ta|
000001b0  69 6c 20 3d 20 4e 55 4c  4c 3b 0a 56 69 64 65 6f  |il = NULL;.Video|
000001c0  20 20 20 20 20 76 69 64  65 6f 4c 69 73 74 5f 68  |     videoList_h|
000001d0  65 61 64 20 3d 20 4e 55  4c 4c 2c 20 76 69 64 65  |ead = NULL, vide|
000001e0  6f 4c 69 73 74 5f 74 61  69 6c 20 3d 20 4e 55 4c  |oList_tail = NUL|
000001f0  4c 3b 0a 43 61 74 65 67  6f 72 79 20 20 63 61 74  |L;.Category  cat|
00000200  65 67 6f 72 79 4c 69 73  74 5f 68 65 61 64 20 3d  |egoryList_head =|
00000210  20 4e 55 4c 4c 2c 20 63  61 74 65 67 6f 72 79 4c  | NULL, categoryL|
00000220  69 73 74 5f 74 61 69 6c  20 3d 20 4e 55 4c 4c 3b  |ist_tail = NULL;|
00000230  0a 50 72 6f 67 72 61 6d  6d 65 20 70 72 6f 67 4c  |.Programme progL|
00000240  69 73 74 5f 68 65 61 64  20 3d 20 4e 55 4c 4c 2c  |ist_head = NULL,|
00000250  20 70 72 6f 67 4c 69 73  74 5f 74 61 69 6c 20 3d  | progList_tail =|
00000260  20 4e 55 4c 4c 3b 0a 56  69 64 65 6f 4c 69 73 74  | NULL;.VideoList|
00000270  20 62 65 73 74 46 69 74  20 3d 20 4e 55 4c 4c 3b  | bestFit = NULL;|
00000280  0a 0a 2f 2a 2a 20 47 6c  6f 62 61 6c 73 20 2a 2a  |../** Globals **|
00000290  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000002d0  2f 0a 0a 69 6e 74 20 6d  61 69 6e 28 69 6e 74 20  |/..int main(int |
000002e0  61 72 67 63 2c 20 63 68  61 72 20 2a 61 72 67 76  |argc, char *argv|
000002f0  5b 5d 29 3b 0a 0a 2f 2a  2a 20 4c 6f 63 61 6c 73  |[]);../** Locals|
00000300  20 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  | ***************|
00000310  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000340  2a 2a 2a 2a 2f 0a 0a 73  74 61 74 69 63 20 76 6f  |****/..static vo|
00000350  69 64 20 70 61 72 73 65  41 72 67 73 28 69 6e 74  |id parseArgs(int|
00000360  20 61 72 67 63 2c 20 63  68 61 72 20 2a 61 72 67  | argc, char *arg|
00000370  76 5b 5d 29 3b 0a 73 74  61 74 69 63 20 76 6f 69  |v[]);.static voi|
00000380  64 20 70 72 69 6e 74 49  6e 66 6f 28 46 49 4c 45  |d printInfo(FILE|
00000390  20 2a 66 29 3b 0a 73 74  61 74 69 63 20 76 6f 69  | *f);.static voi|
000003a0  64 20 76 61 6c 69 64 61  74 65 28 76 6f 69 64 29  |d validate(void)|
000003b0  3b 0a 73 74 61 74 69 63  20 76 6f 69 64 20 70 72  |;.static void pr|
000003c0  69 6e 74 46 69 74 28 46  49 4c 45 20 2a 66 29 3b  |intFit(FILE *f);|
000003d0  0a 23 69 66 20 28 30 29  0a 73 74 61 74 69 63 20  |.#if (0).static |
000003e0  76 6f 69 64 20 64 75 6d  70 4c 65 78 28 76 6f 69  |void dumpLex(voi|
000003f0  64 29 3b 0a 23 65 6e 64  69 66 0a 0a 23 64 65 66  |d);.#endif..#def|
00000400  69 6e 65 20 4d 41 58 5f  46 49 4c 45 4e 41 4d 45  |ine MAX_FILENAME|
00000410  5f 4c 45 4e 47 54 48 20  32 35 36 0a 0a 73 74 61  |_LENGTH 256..sta|
00000420  74 69 63 20 63 68 61 72  20 73 6f 75 72 63 65 46  |tic char sourceF|
00000430  69 6c 65 5b 4d 41 58 5f  46 49 4c 45 4e 41 4d 45  |ile[MAX_FILENAME|
00000440  5f 4c 45 4e 47 54 48 5d  20 3d 20 7b 30 7d 3b 0a  |_LENGTH] = {0};.|
00000450  73 74 61 74 69 63 20 63  68 61 72 20 6f 75 74 70  |static char outp|
00000460  75 74 46 69 6c 65 5b 4d  41 58 5f 46 49 4c 45 4e  |utFile[MAX_FILEN|
00000470  41 4d 45 5f 4c 45 4e 47  54 48 5d 20 3d 20 7b 30  |AME_LENGTH] = {0|
00000480  7d 3b 0a 0a 2f 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |};../***********|
00000490  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000004d0  2a 2a 2f 0a 0a 69 6e 74  20 6d 61 69 6e 28 69 6e  |**/..int main(in|
000004e0  74 20 61 72 67 63 2c 20  63 68 61 72 20 2a 61 72  |t argc, char *ar|
000004f0  67 76 5b 5d 29 0a 7b 0a  20 20 46 49 4c 45 20 2a  |gv[]).{.  FILE *|
00000500  66 3b 0a 0a 20 20 70 61  72 73 65 41 72 67 73 28  |f;..  parseArgs(|
00000510  61 72 67 63 2c 61 72 67  76 29 3b 0a 0a 20 20 6c  |argc,argv);..  l|
00000520  65 78 28 73 6f 75 72 63  65 46 69 6c 65 29 3b 0a  |ex(sourceFile);.|
00000530  0a 20 20 69 66 20 28 79  79 70 61 72 73 65 28 29  |.  if (yyparse()|
00000540  20 21 3d 20 30 29 0a 20  20 7b 0a 20 20 20 20 70  | != 0).  {.    p|
00000550  72 69 6e 74 66 28 22 5b  65 72 72 6f 72 5d 3a 20  |rintf("[error]: |
00000560  65 72 72 6f 72 73 20 69  6e 20 70 61 72 73 69 6e  |errors in parsin|
00000570  67 2c 20 61 62 6f 72 74  69 6e 67 5c 6e 22 29 3b  |g, aborting\n");|
00000580  0a 20 20 20 20 65 78 69  74 28 45 58 49 54 5f 46  |.    exit(EXIT_F|
00000590  41 49 4c 55 52 45 29 3b  0a 20 20 7d 0a 0a 20 20  |AILURE);.  }..  |
000005a0  76 61 6c 69 64 61 74 65  28 29 3b 0a 0a 20 20 66  |validate();..  f|
000005b0  20 3d 20 66 6f 70 65 6e  28 6f 75 74 70 75 74 46  | = fopen(outputF|
000005c0  69 6c 65 2c 22 77 22 29  3b 0a 20 20 70 72 69 6e  |ile,"w");.  prin|
000005d0  74 49 6e 66 6f 28 66 29  3b 0a 0a 20 20 66 69 74  |tInfo(f);..  fit|
000005e0  28 66 29 3b 0a 0a 20 20  70 72 69 6e 74 46 69 74  |(f);..  printFit|
000005f0  28 66 29 3b 0a 0a 20 20  66 63 6c 6f 73 65 28 66  |(f);..  fclose(f|
00000600  29 3b 0a 0a 20 20 72 65  74 75 72 6e 20 28 45 58  |);..  return (EX|
00000610  49 54 5f 53 55 43 43 45  53 53 29 3b 0a 7d 0a 0a  |IT_SUCCESS);.}..|
00000620  2f 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |/***************|
00000630  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000660  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2f 0a  |**************/.|
00000670  0a 73 74 61 74 69 63 20  76 6f 69 64 20 70 61 72  |.static void par|
00000680  73 65 41 72 67 73 28 69  6e 74 20 61 72 67 63 2c  |seArgs(int argc,|
00000690  20 63 68 61 72 20 2a 61  72 67 76 5b 5d 29 0a 7b  | char *argv[]).{|
000006a0  0a 20 20 62 6f 6f 6c 65  61 6e 20 73 6f 75 72 63  |.  boolean sourc|
000006b0  65 50 72 65 73 65 6e 74  20 3d 20 66 61 6c 73 65  |ePresent = false|
000006c0  3b 0a 20 20 62 6f 6f 6c  65 61 6e 20 6f 75 74 70  |;.  boolean outp|
000006d0  75 74 50 72 65 73 65 6e  74 20 3d 20 66 61 6c 73  |utPresent = fals|
000006e0  65 3b 0a 20 20 69 6e 74  20 69 3b 0a 0a 20 20 66  |e;.  int i;..  f|
000006f0  6f 72 20 28 69 20 3d 20  31 3b 20 69 20 3c 20 28  |or (i = 1; i < (|
00000700  61 72 67 63 20 2d 31 29  3b 20 69 2b 2b 29 0a 20  |argc -1); i++). |
00000710  20 7b 0a 20 20 20 20 69  66 20 28 73 74 72 63 6d  | {.    if (strcm|
00000720  70 28 61 72 67 76 5b 69  5d 2c 22 2d 73 22 29 20  |p(argv[i],"-s") |
00000730  3d 3d 20 30 29 0a 20 20  20 20 7b 0a 20 20 20 20  |== 0).    {.    |
00000740  20 20 73 74 72 63 70 79  28 73 6f 75 72 63 65 46  |  strcpy(sourceF|
00000750  69 6c 65 2c 61 72 67 76  5b 2b 2b 69 5d 29 3b 0a  |ile,argv[++i]);.|
00000760  20 20 20 20 20 20 73 6f  75 72 63 65 50 72 65 73  |      sourcePres|
00000770  65 6e 74 20 3d 20 74 72  75 65 3b 0a 20 20 20 20  |ent = true;.    |
00000780  7d 0a 20 20 20 20 65 6c  73 65 20 69 66 20 28 73  |}.    else if (s|
00000790  74 72 63 6d 70 28 61 72  67 76 5b 69 5d 2c 22 2d  |trcmp(argv[i],"-|
000007a0  6f 22 29 20 3d 3d 20 30  29 0a 20 20 20 20 7b 0a  |o") == 0).    {.|
000007b0  20 20 20 20 20 20 73 74  72 63 70 79 28 6f 75 74  |      strcpy(out|
000007c0  70 75 74 46 69 6c 65 2c  61 72 67 76 5b 2b 2b 69  |putFile,argv[++i|
000007d0  5d 29 3b 0a 20 20 20 20  20 20 6f 75 74 70 75 74  |]);.      output|
000007e0  50 72 65 73 65 6e 74 20  3d 20 74 72 75 65 3b 0a  |Present = true;.|
000007f0  20 20 20 20 7d 0a 20 20  20 20 65 6c 73 65 0a 20  |    }.    else. |
00000800  20 20 20 7b 0a 20 20 20  20 20 20 70 72 69 6e 74  |   {.      print|
00000810  66 28 22 5b 77 61 72 6e  69 6e 67 5d 3a 20 75 6e  |f("[warning]: un|
00000820  72 65 63 6f 67 6e 69 7a  65 64 20 73 77 69 74 63  |recognized switc|
00000830  68 20 27 25 73 27 5c 6e  22 2c 61 72 67 76 5b 69  |h '%s'\n",argv[i|
00000840  5d 29 3b 0a 20 20 20 20  7d 0a 20 20 7d 0a 0a 20  |]);.    }.  }.. |
00000850  20 69 66 20 28 73 6f 75  72 63 65 50 72 65 73 65  | if (sourcePrese|
00000860  6e 74 20 3d 3d 20 66 61  6c 73 65 0a 20 20 20 20  |nt == false.    |
00000870  20 20 7c 7c 20 6f 75 74  70 75 74 50 72 65 73 65  |  || outputPrese|
00000880  6e 74 20 3d 3d 20 66 61  6c 73 65 29 0a 20 20 7b  |nt == false).  {|
00000890  0a 20 20 20 20 70 72 69  6e 74 66 28 22 5b 65 72  |.    printf("[er|
000008a0  72 6f 72 5d 3a 20 69 6e  63 6f 6d 70 6c 65 74 65  |ror]: incomplete|
000008b0  20 73 70 65 63 69 66 69  63 61 74 69 6f 6e 20 28  | specification (|
000008c0  69 6e 63 6c 75 64 65 20  2d 73 20 61 6e 64 20 2d  |include -s and -|
000008d0  6f 20 73 77 69 74 63 68  65 73 29 5c 6e 22 29 3b  |o switches)\n");|
000008e0  0a 20 20 20 20 65 78 69  74 28 45 58 49 54 5f 46  |.    exit(EXIT_F|
000008f0  41 49 4c 55 52 45 29 3b  0a 20 20 7d 0a 7d 0a 0a  |AILURE);.  }.}..|
00000900  73 74 61 74 69 63 20 76  6f 69 64 20 76 61 6c 69  |static void vali|
00000910  64 61 74 65 28 29 0a 7b  0a 20 20 50 72 6f 67 72  |date().{.  Progr|
00000920  61 6d 6d 65 20 70 3b 0a  0a 20 20 66 6f 72 20 28  |amme p;..  for (|
00000930  70 20 3d 20 70 72 6f 67  4c 69 73 74 5f 68 65 61  |p = progList_hea|
00000940  64 3b 20 70 20 21 3d 20  4e 55 4c 4c 3b 20 70 20  |d; p != NULL; p |
00000950  3d 20 70 2d 3e 6e 65 78  74 29 0a 20 20 7b 0a 20  |= p->next).  {. |
00000960  20 20 20 69 66 20 28 70  2d 3e 73 74 61 72 74 5f  |   if (p->start_|
00000970  68 72 73 20 3d 3d 20 2d  31 20 7c 7c 20 70 2d 3e  |hrs == -1 || p->|
00000980  73 74 61 72 74 5f 6d 69  6e 73 20 3d 3d 20 2d 31  |start_mins == -1|
00000990  20 7c 7c 20 70 2d 3e 73  74 61 72 74 5f 73 65 63  | || p->start_sec|
000009a0  73 20 3d 3d 20 2d 31 0a  20 20 20 20 09 7c 7c 20  |s == -1.    .|| |
000009b0  70 2d 3e 65 6e 64 5f 68  72 73 20 3d 3d 20 2d 31  |p->end_hrs == -1|
000009c0  20 7c 7c 20 70 2d 3e 65  6e 64 5f 6d 69 6e 73 20  | || p->end_mins |
000009d0  3d 3d 20 2d 31 20 7c 7c  20 70 2d 3e 65 6e 64 5f  |== -1 || p->end_|
000009e0  73 65 63 73 20 3d 3d 20  2d 31 0a 20 20 20 20 09  |secs == -1.    .|
000009f0  7c 7c 20 70 2d 3e 6c 65  6e 67 74 68 20 3d 3d 20  ||| p->length == |
00000a00  2d 31 29 0a 20 20 20 20  7b 0a 20 20 20 20 20 20  |-1).    {.      |
00000a10  70 72 69 6e 74 66 28 22  5b 65 72 72 6f 72 5d 3a  |printf("[error]:|
00000a20  20 69 6e 63 6f 6d 70 6c  65 74 65 20 64 65 63 6c  | incomplete decl|
00000a30  61 72 61 74 69 6f 6e 20  6f 66 20 70 72 6f 67 72  |aration of progr|
00000a40  61 6d 6d 65 20 27 25 73  27 5c 6e 22 2c 0a 20 20  |amme '%s'\n",.  |
00000a50  20 20 20 20 09 20 20 20  20 20 70 2d 3e 6e 61 6d  |    .     p->nam|
00000a60  65 29 3b 0a 20 20 20 20  7d 0a 20 20 20 20 69 66  |e);.    }.    if|
00000a70  20 28 70 2d 3e 74 79 70  65 20 21 3d 20 4e 55 4c  | (p->type != NUL|
00000a80  4c 20 26 26 20 28 70 2d  3e 70 72 65 63 65 64 65  |L && (p->precede|
00000a90  73 20 21 3d 20 4e 55 4c  4c 20 7c 7c 20 70 2d 3e  |s != NULL || p->|
00000aa0  66 6f 6c 6c 6f 77 73 20  21 3d 20 4e 55 4c 4c 29  |follows != NULL)|
00000ab0  29 0a 20 20 20 20 7b 0a  20 20 20 20 20 20 70 72  |).    {.      pr|
00000ac0  69 6e 74 66 28 22 5b 65  72 72 6f 72 5d 3a 20 63  |intf("[error]: c|
00000ad0  61 74 65 67 6f 72 79 20  61 6e 64 20 67 72 6f 75  |ategory and grou|
00000ae0  70 20 73 70 65 63 69 66  69 65 64 20 69 6e 20 27  |p specified in '|
00000af0  25 73 27 5c 6e 22 2c 70  2d 3e 6e 61 6d 65 29 3b  |%s'\n",p->name);|
00000b00  0a 20 20 20 20 7d 0a 20  20 20 20 69 66 20 28 70  |.    }.    if (p|
00000b10  2d 3e 66 72 6f 6d 20 3d  3d 20 4e 55 4c 4c 29 0a  |->from == NULL).|
00000b20  20 20 20 20 7b 0a 20 20  20 20 20 20 70 72 69 6e  |    {.      prin|
00000b30  74 66 28 22 5b 65 72 72  6f 72 5d 3a 20 69 6e 20  |tf("[error]: in |
00000b40  27 25 73 27 20 6e 6f 20  27 66 72 6f 6d 27 20 66  |'%s' no 'from' f|
00000b50  69 65 6c 64 20 64 65 63  6c 61 72 65 64 5c 6e 22  |ield declared\n"|
00000b60  2c 70 2d 3e 6e 61 6d 65  29 3b 0a 20 20 20 20 20  |,p->name);.     |
00000b70  20 65 78 69 74 28 45 58  49 54 5f 46 41 49 4c 55  | exit(EXIT_FAILU|
00000b80  52 45 29 3b 0a 20 20 20  20 7d 0a 20 20 7d 0a 7d  |RE);.    }.  }.}|
00000b90  0a 0a 73 74 61 74 69 63  20 76 6f 69 64 20 70 72  |..static void pr|
00000ba0  69 6e 74 49 6e 66 6f 28  46 49 4c 45 20 2a 66 29  |intInfo(FILE *f)|
00000bb0  0a 7b 0a 20 20 56 69 64  65 6f 20 76 3b 0a 20 20  |.{.  Video v;.  |
00000bc0  43 61 74 65 67 6f 72 79  20 63 3b 0a 20 20 50 72  |Category c;.  Pr|
00000bd0  6f 67 72 61 6d 6d 65 20  70 3b 0a 0a 20 20 66 70  |ogramme p;..  fp|
00000be0  72 69 6e 74 66 28 66 2c  22 46 69 74 54 61 70 65  |rintf(f,"FitTape|
00000bf0  73 20 2d 20 42 65 73 74  20 46 69 74 20 6f 66 20  |s - Best Fit of |
00000c00  50 72 6f 67 72 61 6d 6d  65 73 20 2d 3e 20 54 61  |Programmes -> Ta|
00000c10  70 65 73 5c 6e 22 0a 20  20 09 20 20 20 20 22 2a  |pes\n".  .    "*|
00000c20  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000c40  2a 2a 2a 2a 2a 2a 2a 2a  2a 5c 6e 5c 6e 22 29 3b  |*********\n\n");|
00000c50  0a 0a 20 20 66 70 72 69  6e 74 66 28 66 2c 22 56  |..  fprintf(f,"V|
00000c60  69 64 65 6f 73 2c 20 77  69 74 68 20 6c 65 6e 67  |ideos, with leng|
00000c70  74 68 73 5c 6e 5c 6e 22  29 3b 0a 0a 20 20 66 6f  |ths\n\n");..  fo|
00000c80  72 20 28 76 20 3d 20 76  69 64 65 6f 4c 69 73 74  |r (v = videoList|
00000c90  5f 68 65 61 64 3b 20 76  20 21 3d 20 4e 55 4c 4c  |_head; v != NULL|
00000ca0  3b 20 76 20 3d 20 76 2d  3e 6e 65 78 74 29 0a 20  |; v = v->next). |
00000cb0  20 7b 0a 20 20 20 20 66  70 72 69 6e 74 66 28 66  | {.    fprintf(f|
00000cc0  2c 22 5c 74 27 25 73 27  2c 20 6c 65 6e 67 74 68  |,"\t'%s', length|
00000cd0  20 25 64 20 73 65 63 6f  6e 64 73 5c 6e 22 2c 76  | %d seconds\n",v|
00000ce0  2d 3e 6e 61 6d 65 2c 76  2d 3e 6c 65 6e 67 74 68  |->name,v->length|
00000cf0  29 3b 0a 20 20 7d 0a 20  20 66 70 72 69 6e 74 66  |);.  }.  fprintf|
00000d00  28 66 2c 22 5c 6e 22 29  3b 0a 0a 20 20 66 70 72  |(f,"\n");..  fpr|
00000d10  69 6e 74 66 28 66 2c 22  43 61 74 65 67 6f 72 69  |intf(f,"Categori|
00000d20  65 73 2c 20 77 69 74 68  20 61 6c 6c 6f 63 61 74  |es, with allocat|
00000d30  65 64 20 6e 75 6d 62 65  72 73 5c 6e 5c 6e 22 29  |ed numbers\n\n")|
00000d40  3b 0a 0a 20 20 66 6f 72  20 28 63 20 3d 20 63 61  |;..  for (c = ca|
00000d50  74 65 67 6f 72 79 4c 69  73 74 5f 68 65 61 64 3b  |tegoryList_head;|
00000d60  20 63 20 21 3d 20 4e 55  4c 4c 3b 20 63 20 3d 20  | c != NULL; c = |
00000d70  63 2d 3e 6e 65 78 74 29  0a 20 20 7b 0a 20 20 20  |c->next).  {.   |
00000d80  20 66 70 72 69 6e 74 66  28 66 2c 22 5c 74 27 25  | fprintf(f,"\t'%|
00000d90  73 27 2c 20 63 61 74 65  67 6f 72 79 20 6e 75 6d  |s', category num|
00000da0  62 65 72 20 25 64 5c 6e  22 2c 63 2d 3e 6e 61 6d  |ber %d\n",c->nam|
00000db0  65 2c 63 2d 3e 6e 75 6d  62 65 72 29 3b 0a 20 20  |e,c->number);.  |
00000dc0  7d 0a 20 20 66 70 72 69  6e 74 66 28 66 2c 22 5c  |}.  fprintf(f,"\|
00000dd0  6e 22 29 3b 0a 0a 20 20  66 70 72 69 6e 74 66 28  |n");..  fprintf(|
00000de0  66 2c 22 44 65 63 6c 61  72 65 64 20 70 72 6f 67  |f,"Declared prog|
00000df0  72 61 6d 6d 65 73 5c 6e  5c 6e 22 29 3b 0a 0a 20  |rammes\n\n");.. |
00000e00  20 66 6f 72 20 28 70 20  3d 20 70 72 6f 67 4c 69  | for (p = progLi|
00000e10  73 74 5f 68 65 61 64 3b  20 70 20 21 3d 20 4e 55  |st_head; p != NU|
00000e20  4c 4c 3b 20 70 20 3d 20  70 2d 3e 6e 65 78 74 29  |LL; p = p->next)|
00000e30  0a 20 20 7b 0a 20 20 20  20 66 70 72 69 6e 74 66  |.  {.    fprintf|
00000e40  28 66 2c 22 5c 74 50 72  6f 67 72 61 6d 6d 65 20  |(f,"\tProgramme |
00000e50  27 25 73 27 5c 6e 22 2c  70 2d 3e 6e 61 6d 65 29  |'%s'\n",p->name)|
00000e60  3b 0a 20 20 20 20 69 66  20 28 70 2d 3e 66 72 6f  |;.    if (p->fro|
00000e70  6d 20 21 3d 20 4e 55 4c  4c 29 0a 20 20 20 20 7b  |m != NULL).    {|
00000e80  0a 20 20 20 20 20 20 66  70 72 69 6e 74 66 28 66  |.      fprintf(f|
00000e90  2c 22 5c 74 5c 74 53 6f  75 72 63 65 5c 74 5c 74  |,"\t\tSource\t\t|
00000ea0  3d 20 27 25 73 27 5c 6e  22 2c 70 2d 3e 66 72 6f  |= '%s'\n",p->fro|
00000eb0  6d 2d 3e 6e 61 6d 65 29  3b 0a 20 20 20 20 7d 0a  |m->name);.    }.|
00000ec0  20 20 20 20 69 66 20 28  70 2d 3e 73 74 61 72 74  |    if (p->start|
00000ed0  5f 68 72 73 20 21 3d 20  2d 31 20 26 26 20 70 2d  |_hrs != -1 && p-|
00000ee0  3e 73 74 61 72 74 5f 6d  69 6e 73 20 21 3d 20 2d  |>start_mins != -|
00000ef0  31 20 26 26 20 70 2d 3e  73 74 61 72 74 5f 73 65  |1 && p->start_se|
00000f00  63 73 20 21 3d 20 2d 31  29 0a 20 20 20 20 7b 0a  |cs != -1).    {.|
00000f10  20 20 20 20 20 20 66 70  72 69 6e 74 66 28 66 2c  |      fprintf(f,|
00000f20  22 5c 74 5c 74 53 74 61  72 74 20 74 69 6d 65 5c  |"\t\tStart time\|
00000f30  74 3d 20 25 2e 32 64 3a  25 2e 32 64 3a 25 2e 32  |t= %.2d:%.2d:%.2|
00000f40  64 5c 6e 22 2c 0a 20 20  20 20 20 20 09 20 20 20  |d\n",.      .   |
00000f50  20 20 20 70 2d 3e 73 74  61 72 74 5f 68 72 73 2c  |   p->start_hrs,|
00000f60  70 2d 3e 73 74 61 72 74  5f 6d 69 6e 73 2c 70 2d  |p->start_mins,p-|
00000f70  3e 73 74 61 72 74 5f 73  65 63 73 29 3b 0a 20 20  |>start_secs);.  |
00000f80  20 20 7d 0a 20 20 20 20  69 66 20 28 70 2d 3e 65  |  }.    if (p->e|
00000f90  6e 64 5f 68 72 73 20 21  3d 20 2d 31 20 26 26 20  |nd_hrs != -1 && |
00000fa0  70 2d 3e 65 6e 64 5f 6d  69 6e 73 20 21 3d 20 2d  |p->end_mins != -|
00000fb0  31 20 26 26 20 70 2d 3e  65 6e 64 5f 73 65 63 73  |1 && p->end_secs|
00000fc0  20 21 3d 20 2d 31 29 0a  20 20 20 20 7b 0a 20 20  | != -1).    {.  |
00000fd0  20 20 20 20 66 70 72 69  6e 74 66 28 66 2c 22 5c  |    fprintf(f,"\|
00000fe0  74 5c 74 45 6e 64 20 74  69 6d 65 5c 74 3d 20 25  |t\tEnd time\t= %|
00000ff0  2e 32 64 3a 25 2e 32 64  3a 25 2e 32 64 5c 6e 22  |.2d:%.2d:%.2d\n"|
00001000  2c 0a 20 20 20 20 20 20  09 20 20 20 20 20 20 70  |,.      .      p|
00001010  2d 3e 65 6e 64 5f 68 72  73 2c 70 2d 3e 65 6e 64  |->end_hrs,p->end|
00001020  5f 6d 69 6e 73 2c 70 2d  3e 65 6e 64 5f 73 65 63  |_mins,p->end_sec|
00001030  73 29 3b 0a 20 20 20 20  7d 0a 20 20 20 20 69 66  |s);.    }.    if|
00001040  20 28 70 2d 3e 6c 65 6e  67 74 68 20 21 3d 20 2d  | (p->length != -|
00001050  31 29 0a 20 20 20 20 7b  0a 20 20 20 20 20 20 66  |1).    {.      f|
00001060  70 72 69 6e 74 66 28 66  2c 22 5c 74 5c 74 54 6f  |printf(f,"\t\tTo|
00001070  74 61 6c 20 6c 65 6e 67  74 68 5c 74 3d 20 25 64  |tal length\t= %d|
00001080  20 73 65 63 6f 6e 64 73  5c 6e 22 2c 70 2d 3e 6c  | seconds\n",p->l|
00001090  65 6e 67 74 68 29 3b 0a  20 20 20 20 7d 0a 20 20  |ength);.    }.  |
000010a0  20 20 69 66 20 28 70 2d  3e 74 79 70 65 20 21 3d  |  if (p->type !=|
000010b0  20 4e 55 4c 4c 29 0a 20  20 20 20 7b 0a 20 20 20  | NULL).    {.   |
000010c0  20 20 20 66 70 72 69 6e  74 66 28 66 2c 22 5c 74  |   fprintf(f,"\t|
000010d0  5c 74 43 61 74 65 67 6f  72 79 5c 74 3d 20 25 64  |\tCategory\t= %d|
000010e0  20 28 27 25 73 27 29 5c  6e 22 2c 70 2d 3e 74 79  | ('%s')\n",p->ty|
000010f0  70 65 2d 3e 6e 75 6d 62  65 72 2c 70 2d 3e 74 79  |pe->number,p->ty|
00001100  70 65 2d 3e 6e 61 6d 65  29 3b 0a 20 20 20 20 7d  |pe->name);.    }|
00001110  0a 20 20 20 20 69 66 20  28 70 2d 3e 70 72 65 63  |.    if (p->prec|
00001120  65 64 65 73 20 21 3d 20  4e 55 4c 4c 29 0a 20 20  |edes != NULL).  |
00001130  20 20 7b 0a 20 20 20 20  20 20 66 70 72 69 6e 74  |  {.      fprint|
00001140  66 28 66 2c 22 5c 74 5c  74 50 72 65 63 65 64 65  |f(f,"\t\tPrecede|
00001150  73 5c 74 27 25 73 27 5c  6e 22 2c 70 2d 3e 70 72  |s\t'%s'\n",p->pr|
00001160  65 63 65 64 65 73 29 3b  0a 20 20 20 20 7d 0a 20  |ecedes);.    }. |
00001170  20 20 20 69 66 20 28 70  2d 3e 66 6f 6c 6c 6f 77  |   if (p->follow|
00001180  73 20 21 3d 20 4e 55 4c  4c 29 0a 20 20 20 20 7b  |s != NULL).    {|
00001190  0a 20 20 20 20 20 20 66  70 72 69 6e 74 66 28 66  |.      fprintf(f|
000011a0  2c 22 5c 74 5c 74 46 6f  6c 6c 6f 77 73 5c 74 5c  |,"\t\tFollows\t\|
000011b0  74 27 25 73 27 5c 6e 22  2c 70 2d 3e 66 6f 6c 6c  |t'%s'\n",p->foll|
000011c0  6f 77 73 29 3b 0a 20 20  20 20 7d 0a 20 20 7d 0a  |ows);.    }.  }.|
000011d0  7d 0a 0a 73 74 61 74 69  63 20 76 6f 69 64 20 70  |}..static void p|
000011e0  72 69 6e 74 46 69 74 28  46 49 4c 45 20 2a 66 29  |rintFit(FILE *f)|
000011f0  0a 7b 0a 20 20 56 69 64  65 6f 4c 69 73 74 20 76  |.{.  VideoList v|
00001200  4c 3b 0a 20 20 50 72 6f  67 72 61 6d 6d 65 4c 69  |L;.  ProgrammeLi|
00001210  73 74 20 70 4c 3b 0a 20  20 69 6e 74 20 74 69 6d  |st pL;.  int tim|
00001220  65 6f 66 66 73 65 74 3b  0a 0a 20 20 66 70 72 69  |eoffset;..  fpri|
00001230  6e 74 66 28 66 2c 22 5c  6e 22 0a 20 20 09 20 20  |ntf(f,"\n".  .  |
00001240  20 20 22 5c 74 4c 69 73  74 69 6e 67 3a 5c 6e 5c  |  "\tListing:\n\|
00001250  6e 22 29 3b 0a 0a 20 20  66 6f 72 20 28 76 4c 20  |n");..  for (vL |
00001260  3d 20 62 65 73 74 46 69  74 3b 20 76 4c 20 21 3d  |= bestFit; vL !=|
00001270  20 4e 55 4c 4c 3b 20 76  4c 20 3d 20 76 4c 2d 3e  | NULL; vL = vL->|
00001280  6e 65 78 74 29 0a 20 20  7b 0a 20 20 20 20 74 69  |next).  {.    ti|
00001290  6d 65 6f 66 66 73 65 74  20 3d 20 30 3b 0a 20 20  |meoffset = 0;.  |
000012a0  20 20 66 70 72 69 6e 74  66 28 66 2c 22 5c 74 56  |  fprintf(f,"\tV|
000012b0  69 64 65 6f 20 27 25 73  27 5c 6e 22 2c 76 4c 2d  |ideo '%s'\n",vL-|
000012c0  3e 76 69 64 65 6f 2d 3e  6e 61 6d 65 29 3b 0a 20  |>video->name);. |
000012d0  20 20 20 69 66 20 28 76  4c 2d 3e 70 72 6f 67 72  |   if (vL->progr|
000012e0  61 6d 6d 65 73 20 3d 3d  20 4e 55 4c 4c 29 0a 20  |ammes == NULL). |
000012f0  20 20 20 7b 0a 20 20 20  20 20 20 66 70 72 69 6e  |   {.      fprin|
00001300  74 66 28 66 2c 22 5c 74  5c 74 55 6e 75 73 65 64  |tf(f,"\t\tUnused|
00001310  5c 6e 22 29 3b 0a 20 20  20 20 7d 0a 20 20 20 20  |\n");.    }.    |
00001320  65 6c 73 65 0a 20 20 20  20 7b 0a 20 20 20 20 20  |else.    {.     |
00001330  20 66 6f 72 20 28 70 4c  20 3d 20 76 4c 2d 3e 70  | for (pL = vL->p|
00001340  72 6f 67 72 61 6d 6d 65  73 3b 20 70 4c 20 21 3d  |rogrammes; pL !=|
00001350  20 4e 55 4c 4c 3b 20 70  4c 20 3d 20 70 4c 2d 3e  | NULL; pL = pL->|
00001360  6e 65 78 74 29 0a 20 20  20 20 20 20 7b 0a 20 20  |next).      {.  |
00001370  20 20 20 20 20 20 66 70  72 69 6e 74 66 28 66 2c  |      fprintf(f,|
00001380  22 5c 74 5c 74 27 25 73  27 22 2c 70 4c 2d 3e 70  |"\t\t'%s'",pL->p|
00001390  72 6f 67 72 61 6d 6d 65  2d 3e 6e 61 6d 65 29 3b  |rogramme->name);|
000013a0  0a 20 20 20 20 20 20 20  20 69 66 20 28 70 4c 2d  |.        if (pL-|
000013b0  3e 70 72 6f 67 72 61 6d  6d 65 2d 3e 74 79 70 65  |>programme->type|
000013c0  20 21 3d 20 4e 55 4c 4c  29 0a 20 20 20 20 20 20  | != NULL).      |
000013d0  20 20 7b 0a 20 20 20 20  20 20 20 20 20 20 66 70  |  {.          fp|
000013e0  72 69 6e 74 66 28 66 2c  22 20 2d 20 27 25 73 27  |rintf(f," - '%s'|
000013f0  5c 6e 22 2c 70 4c 2d 3e  70 72 6f 67 72 61 6d 6d  |\n",pL->programm|
00001400  65 2d 3e 74 79 70 65 2d  3e 6e 61 6d 65 29 3b 0a  |e->type->name);.|
00001410  20 20 20 20 20 20 20 20  7d 0a 20 20 20 20 20 20  |        }.      |
00001420  20 20 65 6c 73 65 0a 20  20 20 20 20 20 20 20 7b  |  else.        {|
00001430  0a 20 20 20 20 20 20 20  20 20 20 66 70 72 69 6e  |.          fprin|
00001440  74 66 28 66 2c 22 5c 6e  22 29 3b 0a 20 20 20 20  |tf(f,"\n");.    |
00001450  20 20 20 20 7d 0a 20 20  20 20 20 20 20 20 66 70  |    }.        fp|
00001460  72 69 6e 74 66 28 66 2c  22 5c 74 5c 74 5c 74 25  |rintf(f,"\t\t\t%|
00001470  2e 32 64 3a 25 2e 32 64  3a 25 2e 32 64 20 2d 20  |.2d:%.2d:%.2d - |
00001480  6c 65 6e 67 74 68 20 25  2e 32 64 3a 25 2e 32 64  |length %.2d:%.2d|
00001490  3a 25 2e 32 64 5c 6e 22  2c 0a 20 20 20 20 20 20  |:%.2d\n",.      |
000014a0  20 20 09 74 69 6d 65 6f  66 66 73 65 74 2f 36 30  |  .timeoffset/60|
000014b0  2f 36 30 2c 74 69 6d 65  6f 66 66 73 65 74 2f 36  |/60,timeoffset/6|
000014c0  30 25 36 30 2c 74 69 6d  65 6f 66 66 73 65 74 25  |0%60,timeoffset%|
000014d0  36 30 2c 0a 20 20 20 20  20 20 20 20 09 70 4c 2d  |60,.        .pL-|
000014e0  3e 70 72 6f 67 72 61 6d  6d 65 2d 3e 6c 65 6e 67  |>programme->leng|
000014f0  74 68 2f 36 30 2f 36 30  2c 70 4c 2d 3e 70 72 6f  |th/60/60,pL->pro|
00001500  67 72 61 6d 6d 65 2d 3e  6c 65 6e 67 74 68 2f 36  |gramme->length/6|
00001510  30 25 36 30 2c 0a 20 20  20 20 20 20 20 20 09 70  |0%60,.        .p|
00001520  4c 2d 3e 70 72 6f 67 72  61 6d 6d 65 2d 3e 6c 65  |L->programme->le|
00001530  6e 67 74 68 25 36 30 29  3b 0a 20 20 20 20 20 20  |ngth%60);.      |
00001540  20 20 74 69 6d 65 6f 66  66 73 65 74 20 2b 3d 20  |  timeoffset += |
00001550  70 4c 2d 3e 70 72 6f 67  72 61 6d 6d 65 2d 3e 6c  |pL->programme->l|
00001560  65 6e 67 74 68 3b 0a 20  20 20 20 20 20 7d 0a 20  |ength;.      }. |
00001570  20 20 20 7d 0a 20 20 7d  0a 0a 20 20 66 70 72 69  |   }.  }..  fpri|
00001580  6e 74 66 28 66 2c 22 5c  6e 22 0a 20 20 09 20 20  |ntf(f,"\n".  .  |
00001590  20 20 22 2a 2a 20 43 6f  70 79 20 4c 69 73 74 20  |  "** Copy List |
000015a0  2a 2a 5c 6e 5c 6e 22 29  3b 0a 20 20 66 6f 72 20  |**\n\n");.  for |
000015b0  28 76 4c 20 3d 20 62 65  73 74 46 69 74 3b 20 76  |(vL = bestFit; v|
000015c0  4c 20 21 3d 20 4e 55 4c  4c 3b 20 76 4c 20 3d 20  |L != NULL; vL = |
000015d0  76 4c 2d 3e 6e 65 78 74  29 0a 20 20 7b 0a 20 20  |vL->next).  {.  |
000015e0  20 20 74 69 6d 65 6f 66  66 73 65 74 20 3d 20 30  |  timeoffset = 0|
000015f0  3b 0a 20 20 20 20 66 6f  72 20 28 70 4c 20 3d 20  |;.    for (pL = |
00001600  76 4c 2d 3e 70 72 6f 67  72 61 6d 6d 65 73 3b 20  |vL->programmes; |
00001610  70 4c 20 21 3d 20 4e 55  4c 4c 3b 20 70 4c 20 3d  |pL != NULL; pL =|
00001620  20 70 4c 2d 3e 6e 65 78  74 29 0a 20 20 20 20 7b  | pL->next).    {|
00001630  0a 20 20 20 20 20 20 66  70 72 69 6e 74 66 28 66  |.      fprintf(f|
00001640  2c 22 5c 74 66 72 6f 6d  20 27 25 73 27 20 25 2e  |,"\tfrom '%s' %.|
00001650  32 64 3a 25 2e 32 64 3a  25 2e 32 64 20 63 6f 70  |2d:%.2d:%.2d cop|
00001660  79 20 25 2e 32 64 3a 25  2e 32 64 3a 25 2e 32 64  |y %.2d:%.2d:%.2d|
00001670  20 74 6f 20 27 25 73 27  20 22 0a 20 20 20 20 20  | to '%s' ".     |
00001680  20 09 20 20 20 20 20 20  20 20 22 25 2e 32 64 3a  | .        "%.2d:|
00001690  25 2e 32 64 3a 25 2e 32  64 5c 6e 22 2c 0a 20 20  |%.2d:%.2d\n",.  |
000016a0  20 20 20 20 09 20 20 20  20 20 20 70 4c 2d 3e 70  |    .      pL->p|
000016b0  72 6f 67 72 61 6d 6d 65  2d 3e 66 72 6f 6d 2d 3e  |rogramme->from->|
000016c0  6e 61 6d 65 2c 70 4c 2d  3e 70 72 6f 67 72 61 6d  |name,pL->program|
000016d0  6d 65 2d 3e 73 74 61 72  74 5f 68 72 73 2c 0a 20  |me->start_hrs,. |
000016e0  20 20 20 20 20 09 20 20  20 20 20 20 70 4c 2d 3e  |     .      pL->|
000016f0  70 72 6f 67 72 61 6d 6d  65 2d 3e 73 74 61 72 74  |programme->start|
00001700  5f 6d 69 6e 73 2c 70 4c  2d 3e 70 72 6f 67 72 61  |_mins,pL->progra|
00001710  6d 6d 65 2d 3e 73 74 61  72 74 5f 73 65 63 73 2c  |mme->start_secs,|
00001720  0a 20 20 20 20 20 20 09  20 20 20 20 20 20 70 4c  |.      .      pL|
00001730  2d 3e 70 72 6f 67 72 61  6d 6d 65 2d 3e 6c 65 6e  |->programme->len|
00001740  67 74 68 2f 36 30 2f 36  30 2c 70 4c 2d 3e 70 72  |gth/60/60,pL->pr|
00001750  6f 67 72 61 6d 6d 65 2d  3e 6c 65 6e 67 74 68 2f  |ogramme->length/|
00001760  36 30 25 36 30 2c 0a 20  20 20 20 20 20 09 20 20  |60%60,.      .  |
00001770  20 20 20 20 70 4c 2d 3e  70 72 6f 67 72 61 6d 6d  |    pL->programm|
00001780  65 2d 3e 6c 65 6e 67 74  68 25 36 30 2c 76 4c 2d  |e->length%60,vL-|
00001790  3e 76 69 64 65 6f 2d 3e  6e 61 6d 65 2c 74 69 6d  |>video->name,tim|
000017a0  65 6f 66 66 73 65 74 2f  36 30 2f 36 30 2c 0a 20  |eoffset/60/60,. |
000017b0  20 20 20 20 20 09 20 20  20 20 20 20 74 69 6d 65  |     .      time|
000017c0  6f 66 66 73 65 74 2f 36  30 25 36 30 2c 74 69 6d  |offset/60%60,tim|
000017d0  65 6f 66 66 73 65 74 25  36 30 29 3b 0a 20 20 20  |eoffset%60);.   |
000017e0  20 20 20 74 69 6d 65 6f  66 66 73 65 74 20 2b 3d  |   timeoffset +=|
000017f0  20 70 4c 2d 3e 70 72 6f  67 72 61 6d 6d 65 2d 3e  | pL->programme->|
00001800  6c 65 6e 67 74 68 3b 0a  20 20 20 20 7d 0a 20 20  |length;.    }.  |
00001810  7d 0a 7d 0a 0a 23 69 66  20 28 30 29 0a 73 74 61  |}.}..#if (0).sta|
00001820  74 69 63 20 76 6f 69 64  20 64 75 6d 70 4c 65 78  |tic void dumpLex|
00001830  28 29 0a 7b 0a 20 20 46  49 4c 45 20 2a 6f 66 70  |().{.  FILE *ofp|
00001840  20 3d 20 66 6f 70 65 6e  28 22 6c 65 78 65 72 22  | = fopen("lexer"|
00001850  2c 22 77 22 29 3b 0a 20  20 4c 65 78 65 6d 65 20  |,"w");.  Lexeme |
00001860  6c 6c 3b 0a 20 20 63 68  61 72 20 6c 65 78 65 6d  |ll;.  char lexem|
00001870  65 73 5b 32 33 5d 5b 31  34 5d 20 3d 20 7b 0a 20  |es[23][14] = {. |
00001880  20 20 20 22 62 65 67 69  6e 22 2c 22 65 6e 64 22  |   "begin","end"|
00001890  2c 22 76 69 64 65 6f 22  2c 22 65 32 34 30 22 2c  |,"video","e240",|
000018a0  22 65 31 38 30 22 2c 22  65 31 32 30 22 2c 22 65  |"e180","e120","e|
000018b0  36 30 22 2c 22 63 61 74  65 67 6f 72 69 65 73 22  |60","categories"|
000018c0  2c 22 70 72 6f 67 72 61  6d 6d 65 22 2c 0a 20 20  |,"programme",.  |
000018d0  20 20 22 66 72 6f 6d 22  2c 22 73 74 61 72 74 73  |  "from","starts|
000018e0  22 2c 22 65 6e 64 73 22  2c 22 63 61 74 65 67 6f  |","ends","catego|
000018f0  72 79 22 2c 22 70 72 65  63 65 64 65 73 22 2c 22  |ry","precedes","|
00001900  66 6f 6c 6c 6f 77 73 22  2c 22 7b 22 2c 22 7d 22  |follows","{","}"|
00001910  2c 22 2c 22 2c 22 3b 22  2c 0a 20 20 20 20 22 69  |,",",";",.    "i|
00001920  64 65 6e 74 69 66 69 65  72 22 2c 22 73 74 72 69  |dentifier","stri|
00001930  6e 67 4c 69 74 65 72 61  6c 22 2c 22 63 6f 6e 73  |ngLiteral","cons|
00001940  74 61 6e 74 22 2c 22 65  6e 64 4f 66 53 74 72 65  |tant","endOfStre|
00001950  61 6d 22 0a 20 20 7d 3b  0a 0a 20 20 66 6f 72 20  |am".  };..  for |
00001960  28 6c 6c 20 3d 20 6c 65  78 4c 69 73 74 5f 68 65  |(ll = lexList_he|
00001970  61 64 3b 20 6c 6c 20 21  3d 20 4e 55 4c 4c 3b 20  |ad; ll != NULL; |
00001980  6c 6c 20 3d 20 6c 6c 2d  3e 6e 65 78 74 29 0a 20  |ll = ll->next). |
00001990  20 7b 0a 20 20 20 20 66  70 72 69 6e 74 66 28 6f  | {.    fprintf(o|
000019a0  66 70 2c 22 25 73 5c 74  22 2c 6c 65 78 65 6d 65  |fp,"%s\t",lexeme|
000019b0  73 5b 6c 6c 2d 3e 6c 65  78 65 6d 65 5f 74 79 70  |s[ll->lexeme_typ|
000019c0  65 5d 29 3b 0a 20 20 20  20 73 77 69 74 63 68 20  |e]);.    switch |
000019d0  28 6c 6c 2d 3e 6c 65 78  65 6d 65 5f 74 79 70 65  |(ll->lexeme_type|
000019e0  29 0a 20 20 20 20 7b 0a  20 20 20 20 20 20 63 61  |).    {.      ca|
000019f0  73 65 20 69 64 65 6e 74  69 66 69 65 72 3a 0a 20  |se identifier:. |
00001a00  20 20 20 20 20 20 20 66  70 72 69 6e 74 66 28 6f  |       fprintf(o|
00001a10  66 70 2c 22 27 25 73 27  5c 74 22 2c 6c 6c 2d 3e  |fp,"'%s'\t",ll->|
00001a20  6c 65 78 65 6d 65 5f 76  61 6c 75 65 2e 69 64 65  |lexeme_value.ide|
00001a30  6e 74 69 66 69 65 72 56  61 6c 75 65 29 3b 0a 20  |ntifierValue);. |
00001a40  20 20 20 20 20 20 20 62  72 65 61 6b 3b 0a 20 20  |       break;.  |
00001a50  20 20 20 20 63 61 73 65  20 73 74 72 69 6e 67 4c  |    case stringL|
00001a60  69 74 65 72 61 6c 3a 0a  20 20 20 20 20 20 20 20  |iteral:.        |
00001a70  66 70 72 69 6e 74 66 28  6f 66 70 2c 22 5c 22 25  |fprintf(ofp,"\"%|
00001a80  73 5c 22 5c 74 22 2c 6c  6c 2d 3e 6c 65 78 65 6d  |s\"\t",ll->lexem|
00001a90  65 5f 76 61 6c 75 65 2e  73 74 72 69 6e 67 4c 69  |e_value.stringLi|
00001aa0  74 65 72 61 6c 56 61 6c  75 65 29 3b 0a 20 20 20  |teralValue);.   |
00001ab0  20 20 20 20 20 62 72 65  61 6b 3b 0a 20 20 20 20  |     break;.    |
00001ac0  20 20 63 61 73 65 20 63  6f 6e 73 74 61 6e 74 3a  |  case constant:|
00001ad0  0a 20 20 20 20 20 20 20  20 66 70 72 69 6e 74 66  |.        fprintf|
00001ae0  28 6f 66 70 2c 22 25 64  5c 74 22 2c 6c 6c 2d 3e  |(ofp,"%d\t",ll->|
00001af0  6c 65 78 65 6d 65 5f 76  61 6c 75 65 2e 63 6f 6e  |lexeme_value.con|
00001b00  73 74 61 6e 74 56 61 6c  75 65 29 3b 0a 20 20 20  |stantValue);.   |
00001b10  20 20 20 20 20 62 72 65  61 6b 3b 0a 20 20 20 20  |     break;.    |
00001b20  7d 0a 20 20 20 20 66 70  72 69 6e 74 66 28 6f 66  |}.    fprintf(of|
00001b30  70 2c 22 5b 6c 69 6e 65  20 25 64 20 6f 66 20 25  |p,"[line %d of %|
00001b40  73 5d 5c 6e 22 2c 6c 6c  2d 3e 73 6f 75 72 63 65  |s]\n",ll->source|
00001b50  5f 6c 69 6e 65 2c 6c 6c  2d 3e 73 6f 75 72 63 65  |_line,ll->source|
00001b60  5f 66 69 6c 65 29 3b 0a  20 20 7d 0a 7d 0a 23 65  |_file);.  }.}.#e|
00001b70  6e 64 69 66 0a                                    |ndif.|
00001b75