[comp.sources.misc] v18i083: scene - a simple play description to TeX converter, Part01/01

wollman@emily.UVM.EDU (Garrett Wollman) (04/27/91)

Submitted-by: Garrett Wollman <wollman@emily.UVM.EDU>
Posting-number: Volume 18, Issue 83
Archive-name: scene/part01

This is a quick hack I wrote to alleviate some of the teduim of
describing the structure of a play or book in TeX.  Basically, it
reads in a very simple and laconic input file and writes out the Plain
TeX code to print it up semi-decently (well enough for my purposes).
Not warranted to do anything other than take up disk space; see the
README file for details on how to use it.

Garrett
------cut here-------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Makefile scene.l scene.c
# Wrapped by wollman@emily on Wed Apr 17 19:42:41 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2851 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
This is about all the documentation to the Scene program as you are
going to get...
X
Scene is a program for taking laconic input files, which describe the
sequence of scenes in a play or book, and outputting a semi-nice
X(readable, at any rate) Plain TeX file which gives the same
information.  As an added bonus, I have added a bit of code to
calculate character windows (so that you can see if a character
disappears after scene 23) and print those out, too.  This program was
a very quick hack--there are many built-in, magic-number limits which
I never bothered to do right; in fact, none of these limits are even
checked.  For my purposes, I deemed the simplicity of this approach to
far outweigh the extra time I would have to spend debugging a more
correct implementation.  However, I designed the limits with a huge
project of my own in mind, so you probably won't run into them--and
they're easy enough to change.  If I have spare time, there might even
be a "scene 2.0" which fixes these.
X
The scanner is written in flex; although it is probably compatible
with "regular" lex, I can't see any reason why one would want to use
old lex when you can use flex instead.  The package comes with a
pre-flexed scene.c, just in case you don't have it.  [You should.]
X
The language accepted by the scene program is very simple.  It
consists of the following (case-insensitive) operations:
X
s	start a new scene
c	add a character to a scene
b	identify the "book" from which the scene comes.  Books are
X	remembered across scenes.
X#	identify the page number (must be a single decimal number)
m	identify the music associated with this scene
a	identify the artist, composer, or musician
e	end the scene file and spit out the last scene
X
Commands are always separated by newlines; there is never any
whitespace between a command and its argument.
X
You may invoke scene either within a pipeline or stand-alone ("scene
foo.scn"); in either case output will be on stdout and errors to
stderr.
X
XErrors may be:
X
What does ? mean?	Your file included a "?" which the scanner
X			interpreted as a command, but which is not one
X			of the valid commands.
X
Invalid null ?, ignoring
X			Your file included a "?" command which had a
X			null argument; it was ignored.
X
Invalid page number, ignoring
X			Your file included a page number which was not
X			a decimal number.  It was ignored.  This
X			warning was put in primarily to ensure that
X			the scanner would have no backtracking.
X
To make the program, just edit the Makefile to reflect your desires
and run make.  There is no install target.  Maybe in the next version
X(a trademarked response of <insert PC software company>).
X
X-GAWollman
X--
Garrett A. Wollman - wollman@griffin.uvm.edu
X
Send contributions for Software Patents mailing list to softpats@uvmvm.uvm.edu
Send subscription requests to listserv@uvmvm.uvm.edu.
X
END_OF_FILE
if test 2851 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(726 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Hello, Emacs, please use -*- Fundamental -*- mode.
X#
X# Makefile for Scene
X#
X
CDEBUGFLAGS=
CC=gcc
X#
X# Our favorite CFLAGS.  If you're not using gcc, you probably will want
X# to move the '-O' to CDEBUGFLAGS.  I am, however, and I want the optimizer
X# on at all times.
X#
CFLAGS=${CDEBUGFLAGS} -O -fstrength-reduce -fcombine-regs -fforce-mem \
X	-fforce-addr -fdelayed-branch -fcaller-saves -finline-functions
X
X#
X# I guess you can probably use "regular" lex here... why would you want to?
X#
LEX=flex -b -Cfe
X
X.l.c:
X	$(LEX) $*.l
X	rm -f $*.c
X	mv lex.yy.c $*.c
X
X.c.o:
X	$(CC) $(CFLAGS) -c $*.c
X
all:	scene
X
scene:	scene.o
X	$(CC) -o scene scene.o
X
scene.o:	scene.c
X
scene.c:	scene.l
X
clean:
X	rm -f scene.c *.o scene *~ lex.backtrack
X
END_OF_FILE
if test 726 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'scene.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scene.l'\"
else
echo shar: Extracting \"'scene.l'\" \(6224 characters\)
sed "s/^X//" >'scene.l' <<'END_OF_FILE'
X%{ / -*- Mode: Fundamental -*-
X
X/*
X * scene - a scene-file processor for TeX
X */
X
X/*
X * Copyright 1991, Garrett A. Wollman
X *
X * The recipient is licensed to compile, modify, and distribute this work
X * provided that this comment remains intact and unmodified in any such
X * versions, and the documentation (such as it is) is included.
X * Modified version must clearly be marked as such.
X *
X * If this program is of any use to anybody, I would appreciate hearing
X * about it.  Please send E-mail to wollman@sadye.uvm.edu (in bangland,
X * ...uunet!uvm-gen!griffin!wollman).
X */
X
X/* These prototypes are fairly standard... although it should
X * probably be "void *" as the first parm to qsort()
X */
extern void volatile exit(int);
extern void qsort(char *,int,int,int (*)(const void *,const void *));
X
int scene_no;
X
X/*
X * Look, I told you this was a quick hack, didn't I?
X * The program doesn't even check if you overrun any
X * of these fixed limits.  Boo! Hiss!  But I can't be
X * bothered to do it right so long as it still works
X * for me.
X */
X
struct character {
X	char name[255];
X	short scenes[512];
X	int num_scenes;
X} chars[256];
X
struct scene {
X	char book[32];
X	int chars[64];
X	int num_chars;
X	int page;
X	char music[64];
X	char musicby[64];
X} scenes[640];
X
X/* some more prototypes */
static void add_char_to_scene(char *);
static void write_scene(void);
static void sort_scene_chars(void);
static int sort_int_by_char(const void *,const void *);
static int sort_char_by_name(const void *,const void *);
X
extern int strcmp(const char *,const char *);
extern char *strcpy(char *,const char *);
extern char *strcat(char *,const char *);
X
X/* some more local data */
char curr_book[256];
int curr_page;
X
X%}
X
X%%
X
X"\n"		;
X
X"S"|"s"		{
X			write_scene();
X			scene_no++;
X		}
X
X("C"|"c")[^\n]+	{
X			add_char_to_scene(yytext + 1);
X		}
X
X("B"|"b")[^\n]+	{
X			strcpy(curr_book,yytext + 1);
X			strcpy(scenes[scene_no - 1].book,yytext + 1);
X		}
X
X"#"[0-9]+	{
X			sscanf(yytext,"#%d",&(scenes[scene_no - 1].page));
X		}
X
X"#"[^0-9]+	{
X			fprintf(stderr,"Invalid page number, ignoring\n");
X		}
X
X("M"|"m")[^\n]+	{
X			strcpy(scenes[scene_no - 1].music,yytext + 1);
X		}
X
X("A"|"a")[^\n]+ {
X			strcpy(scenes[scene_no - 1].musicby,yytext + 1);
X		}
X
X[CcBb#MmAa]"\n"	{
X			fprintf(stderr,"Invalid null %c, ignoring\n",yytext[0]);
X		}
X
X[Ee]"\n"	{
X			write_scene();
X			return(0);
X		}
X
X.		{
X			fprintf(stderr,"What does %c mean?\n",yytext[0]);
X		}
X
X%%
X
void add_char_to_scene(char *thechar) {
X	int i;
X
X	i = 0;
X	while(chars[i].num_scenes) {
X		if(!strcmp(chars[i].name,thechar))
X			break;
X		i++;
X	}
X
X	if(chars[i].num_scenes) {
X		chars[i].num_scenes++;
X		chars[i].scenes[chars[i].num_scenes-1] = scene_no;
X	} else {
X		strcpy(chars[i].name,thechar);
X		chars[i].scenes[0] = scene_no;
X		chars[i].num_scenes = 1;
X	}
X
X	scenes[scene_no-1].chars[scenes[scene_no-1].num_chars] = i;
X	scenes[scene_no-1].num_chars++;
X}
X
void write_scene(void) {
X	static int first = 1;
X	int i;
X
X	if(first) {
X		first = 0;
X		return;
X	}
X
X	if(!scenes[scene_no-1].book[0]) {
X	  strcpy(scenes[scene_no-1].book,curr_book);
X	}
X
X	printf("\\vskip 12pt\nScene {\\scenef %d}\n\n",scene_no);
X	printf("from {\\bookf %s}, p. %d\n\n",scenes[scene_no-1].book,
X					    scenes[scene_no-1].page);
X	printf("Characters: ");
X	
X	sort_scene_chars();
X
X	for(i=0; i<scenes[scene_no-1].num_chars; i++) {
X		printf("%s{\\charf %s}",
X		       i?",\n":"",
X		       chars[scenes[scene_no-1].chars[i]].name);
X	}
X	printf("%s.\n\n",i?"":"Narrator");
X
X	if(scenes[scene_no-1].music[0]) {
X	  printf("Music: {\\musicf ``%s''}, %s",
X		 scenes[scene_no-1].music,
X		 scenes[scene_no-1].musicby);
X	}
X
X	printf("\n\n");
X}
X
static void sort_scene_chars(void) {
X  int i;
X
X  qsort((char *)scenes[scene_no-1].chars,scenes[scene_no-1].num_chars,
X	sizeof scenes[scene_no-1].chars[0],
X	sort_int_by_char);
X}
X
static int sort_int_by_char(const void *a,const void *b) {
X  int i = *(const int *)a,j = *(const int *)b;
X
X  return(strcmp(chars[i].name,chars[j].name));
X}
X
static int sort_char_by_name(const void *a,const void *b) {
X  const char *n = ((const struct character *)a)->name;
X  const char *o = ((const struct character *)b)->name;
X
X  return(strcmp(n,o));
X}
X
X/*
X * WARNING
X * This function destroys the mapping from scens[i].chars[i] to
X * an actual character.  It MUST BE CALLED LAST (or at least after
X * this mapping is no longer needed.
X */
static void anal_chars(void) {
X  int i,j,last,olast;
X
X  for(i=0; chars[i].num_scenes; i++); /* i is now number of characters */
X
X  qsort((char *)chars,i,sizeof chars[0],sort_char_by_name);
X
X  printf("\\vskip 0pt plus 1filll\n{\\bigfont Character Windows}\n\n");
X
X  for(i=0; chars[i].num_scenes; i++) {
X    printf("\\vskip 12pt\nCharacter %s appears in scenes: \n",chars[i].name);
X
X    last = 0; olast = 0;
X
X    /* look, this could be a lot smarter if I felt like working on it more.
X       If I ever get around to it, maybe.  Maybe. */
X
X    for(j=0; j < chars[i].num_scenes; j++) {
X      if(last && (chars[i].scenes[j] == last + 1)) {
X	/*
X	 * The last one we got was one less than this one, so keep on
X	 * going.
X	 */
X	olast = last++;
X      } else if(last) {
X	/*
X	 * The last one we got was something else, so output the
X	 * last one, a comma, and then this one.
X	 */
X	if(olast) {
X	  printf("--%d",last);
X	  olast = 0;
X	}
X
X	printf(", %d",last=chars[i].scenes[j]);
X      } else {
X	/*
X	 * The first scene: just print it.
X	 */
X	printf("%d",last=chars[i].scenes[j]); /* side effect */
X      }
X    }
X    if(last && olast) {
X      printf("--%d",last);
X    }
X    printf(".\n\n");
X  }
X}
X
X
void main(int argc,char **argv) {
X  argc--; argv++;
X  if(argc) {
X    if(!freopen(*argv,"r",stdin)) {
X      fprintf(stderr,"scene: cannot open input file %s\n",*argv);
X      exit(1);
X    }
X  }
X
X  /* USER CUSTOMIZATION
X   * You may want to change some of these definitions, especially
X   * if your printer has good fonts of its own.
X   */
X  printf("\\font\\scenef=cmbx10 scaled \\magstep2\n"
X	 "\\font\\bookf=cmti10 scaled \\magstephalf\n"
X	 "\\font\\charf=cmbx10 scaled \\magstep1\n"
X	 "\\font\\musicf=cmsl10 scaled \\magstephalf\n"
X	 "\\font\\bodyfont=cmr10 scaled \\magstephalf\n"
X	 "\\font\\bigfont=cmr10 scaled \\magstep2\n"
X	 "{\\bodyfont\n");
X
X  yylex();
X  anal_chars();
X  printf("}\\end\n");
X  exit(0);
X}
X
END_OF_FILE
if test 6224 -ne `wc -c <'scene.l'`; then
    echo shar: \"'scene.l'\" unpacked with wrong size!
fi
# end of 'scene.l'
fi
if test -f 'scene.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scene.c'\"
else
echo shar: Extracting \"'scene.c'\" \(30114 characters\)
sed "s/^X//" >'scene.c' <<'END_OF_FILE'
X/* A lexical scanner generated by flex */
X
X/* scanner skeleton version:
X * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
X */
X
X#define FLEX_SCANNER
X
X#include <stdio.h>
X
X
X/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
X#ifdef c_plusplus
X#ifndef __cplusplus
X#define __cplusplus
X#endif
X#endif
X
X
X#ifdef __cplusplus
X
X#include <stdlib.h>
X#include <osfcn.h>
X
X/* use prototypes in function declarations */
X#define YY_USE_PROTOS
X
X/* the "const" storage-class-modifier is valid */
X#define YY_USE_CONST
X
X#else	/* ! __cplusplus */
X
X#ifdef __STDC__
X
X#ifdef __GNUC__
X#include <stddef.h>
void *malloc( size_t );
void free( void* );
X#else
X#include <stdlib.h>
X#endif	/* __GNUC__ */
X
X#define YY_USE_PROTOS
X#define YY_USE_CONST
X
X#endif	/* __STDC__ */
X#endif	/* ! __cplusplus */
X
X
X#ifdef __TURBOC__
X#define YY_USE_CONST
X#endif
X
X
X#ifndef YY_USE_CONST
X#define const
X#endif
X
X
X#ifdef YY_USE_PROTOS
X#define YY_PROTO(proto) proto
X#else
X#define YY_PROTO(proto) ()
X/* we can't get here if it's an ANSI C compiler, or a C++ compiler,
X * so it's got to be a K&R compiler, and therefore there's no standard
X * place from which to include these definitions
X */
char *malloc();
int free();
int read();
X#endif
X
X
X/* amount of stuff to slurp up with each read */
X#ifndef YY_READ_BUF_SIZE
X#define YY_READ_BUF_SIZE 8192
X#endif
X
X/* returned upon end-of-file */
X#define YY_END_TOK 0
X
X/* copy whatever the last rule matched to the standard output */
X
X/* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
X/* this used to be an fputs(), but since the string might contain NUL's,
X * we now use fwrite()
X */
X#define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
X
X/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
X * is returned in "result".
X */
X#define YY_INPUT(buf,result,max_size) \
X	if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
X	    YY_FATAL_ERROR( "read() in flex scanner failed" );
X#define YY_NULL 0
X
X/* no semi-colon after return; correct usage is to write "yyterminate();" -
X * we don't want an extra ';' after the "return" because that will cause
X * some compilers to complain about unreachable statements.
X */
X#define yyterminate() return ( YY_NULL )
X
X/* report a fatal error */
X
X/* The funky do-while is used to turn this macro definition into
X * a single C statement (which needs a semi-colon terminator).
X * This avoids problems with code like:
X *
X * 	if ( something_happens )
X *		YY_FATAL_ERROR( "oops, the something happened" );
X *	else
X *		everything_okay();
X *
X * Prior to using the do-while the compiler would get upset at the
X * "else" because it interpreted the "if" statement as being all
X * done when it reached the ';' after the YY_FATAL_ERROR() call.
X */
X
X#define YY_FATAL_ERROR(msg) \
X	do \
X		{ \
X		(void) fputs( msg, stderr ); \
X		(void) putc( '\n', stderr ); \
X		exit( 1 ); \
X		} \
X	while ( 0 )
X
X/* default yywrap function - always treat EOF as an EOF */
X#define yywrap() 1
X
X/* enter a start condition.  This macro really ought to take a parameter,
X * but we do it the disgusting crufty way forced on us by the ()-less
X * definition of BEGIN
X */
X#define BEGIN yy_start = 1 + 2 *
X
X/* action number for EOF rule of a given start state */
X#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
X
X/* special action meaning "start processing a new file" */
X#define YY_NEW_FILE \
X	do \
X		{ \
X		yy_init_buffer( yy_current_buffer, yyin ); \
X		yy_load_buffer_state(); \
X		} \
X	while ( 0 )
X
X/* default declaration of generated scanner - a define so the user can
X * easily add parameters
X */
X#define YY_DECL int yylex YY_PROTO(( void )) 
X
X/* code executed at the end of each rule */
X#define YY_BREAK break;
X
X#define YY_END_OF_BUFFER_CHAR 0
X
X#ifndef YY_BUF_SIZE
X#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
X#endif
X
typedef struct yy_buffer_state *YY_BUFFER_STATE;
X
X#define YY_CHAR char
X# line 1 "scene.l"
X#define INITIAL 0
X# line 2 "scene.l"
X
X/*
X * scene - a scene-file processor for TeX
X */
X
X/*
X * Copyright 1991, Garrett A. Wollman
X *
X * The recipient is licensed to compile, modify, and distribute this work
X * provided that this comment remains intact and unmodified in any such
X * versions, and the documentation (such as it is) is included.
X * Modified version must clearly be marked as such.
X *
X * If this program is of any use to anybody, I would appreciate hearing
X * about it.  Please send E-mail to wollman@sadye.uvm.edu (in bangland,
X * ...uunet!uvm-gen!griffin!wollman).
X */
X
X/* These prototypes are fairly standard... although it should
X * probably be "void *" as the first parm to qsort()
X */
extern void volatile exit(int);
extern void qsort(char *,int,int,int (*)(const void *,const void *));
X
int scene_no;
X
X/*
X * Look, I told you this was a quick hack, didn't I?
X * The program doesn't even check if you overrun any
X * of these fixed limits.  Boo! Hiss!  But I can't be
X * bothered to do it right so long as it still works
X * for me.
X */
X
struct character {
X	char name[255];
X	short scenes[512];
X	int num_scenes;
X} chars[256];
X
struct scene {
X	char book[32];
X	int chars[64];
X	int num_chars;
X	int page;
X	char music[64];
X	char musicby[64];
X} scenes[640];
X
X/* some more prototypes */
static void add_char_to_scene(char *);
static void write_scene(void);
static void sort_scene_chars(void);
static int sort_int_by_char(const void *,const void *);
static int sort_char_by_name(const void *,const void *);
X
extern int strcmp(const char *,const char *);
extern char *strcpy(char *,const char *);
extern char *strcat(char *,const char *);
X
X/* some more local data */
char curr_book[256];
int curr_page;
X
X# line 68 "scene.l"
static short int yy_nxt[][16] =
X    {
X        0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
X        0,    0,    0,    0,    0,    0,
X
X        3,    4,    5,    6,    4,    7,    8,    9,   10,   11,
X       12,    7,    8,    9,   11,   12,
X
X        3,    4,    5,    6,    4,    7,    8,    9,   10,   11,
X       12,    7,    8,    9,   11,   12,
X
X       -3,   -3,   -3,   -3,   -3,   -3,   -3,   -3,   -3,   -3,
X       -3,   -3,   -3,   -3,   -3,   -3,
X
X        3,   -4,   -4,   -4,   -4,   -4,   -4,   -4,   -4,   -4,
X       -4,   -4,   -4,   -4,   -4,   -4,
X
X        3,   -5,   -5,   -5,   -5,   -5,   -5,   -5,   -5,   -5,
X       -5,   -5,   -5,   -5,   -5,   -5,
X
X        3,   13,   14,   13,   15,   13,   13,   13,   13,   13,
X       13,   13,   13,   13,   13,   13,
X
X        3,   16,   17,   16,   16,   16,   16,   16,   16,   16,
X       16,   16,   16,   16,   16,   16,
X
X        3,   18,   17,   18,   18,   18,   18,   18,   18,   18,
X       18,   18,   18,   18,   18,   18,
X
X        3,   19,   17,   19,   19,   19,   19,   19,   19,   19,
X       19,   19,   19,   19,   19,   19,
X
X        3,  -10,   20,  -10,  -10,  -10,  -10,  -10,  -10,  -10,
X      -10,  -10,  -10,  -10,  -10,  -10,
X
X        3,   21,   17,   21,   21,   21,   21,   21,   21,   21,
X       21,   21,   21,   21,   21,   21,
X
X        3,  -12,  -12,  -12,  -12,  -12,  -12,  -12,  -12,  -12,
X      -12,  -12,  -12,  -12,  -12,  -12,
X
X        3,   13,   13,   13,  -13,   13,   13,   13,   13,   13,
X       13,   13,   13,   13,   13,   13,
X
X        3,   13,   13,   13,  -14,   13,   13,   13,   13,   13,
X       13,   13,   13,   13,   13,   13,
X
X        3,  -15,  -15,  -15,   15,  -15,  -15,  -15,  -15,  -15,
X      -15,  -15,  -15,  -15,  -15,  -15,
X
X        3,   16,  -16,   16,   16,   16,   16,   16,   16,   16,
X       16,   16,   16,   16,   16,   16,
X
X        3,  -17,  -17,  -17,  -17,  -17,  -17,  -17,  -17,  -17,
X      -17,  -17,  -17,  -17,  -17,  -17,
X
X        3,   18,  -18,   18,   18,   18,   18,   18,   18,   18,
X       18,   18,   18,   18,   18,   18,
X
X        3,   19,  -19,   19,   19,   19,   19,   19,   19,   19,
X       19,   19,   19,   19,   19,   19,
X
X        3,  -20,  -20,  -20,  -20,  -20,  -20,  -20,  -20,  -20,
X      -20,  -20,  -20,  -20,  -20,  -20,
X
X        3,   21,  -21,   21,   21,   21,   21,   21,   21,   21,
X       21,   21,   21,   21,   21,   21
X
X    } ;
X
X
X/* done after the current pattern has been matched and before the
X * corresponding action - sets up yytext
X */
X#define YY_DO_BEFORE_ACTION \
X	yytext = yy_bp; \
X	yyleng = yy_cp - yy_bp; \
X	yy_hold_char = *yy_cp; \
X	*yy_cp = '\0'; \
X	yy_c_buf_p = yy_cp;
X
X#define EOB_ACT_CONTINUE_SCAN 0
X#define EOB_ACT_END_OF_FILE 1
X#define EOB_ACT_LAST_MATCH 2
X
X/* return all but the first 'n' matched characters back to the input stream */
X#define yyless(n) \
X	do \
X		{ \
X		/* undo effects of setting up yytext */ \
X		*yy_cp = yy_hold_char; \
X		yy_c_buf_p = yy_cp = yy_bp + n; \
X		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
X		} \
X	while ( 0 )
X
X#define unput(c) yyunput( c, yytext )
X
X
struct yy_buffer_state
X    {
X    FILE *yy_input_file;
X
X    YY_CHAR *yy_ch_buf;		/* input buffer */
X    YY_CHAR *yy_buf_pos;	/* current position in input buffer */
X
X    /* size of input buffer in bytes, not including room for EOB characters*/
X    int yy_buf_size;	
X
X    /* number of characters read into yy_ch_buf, not including EOB characters */
X    int yy_n_chars;
X
X    int yy_eof_status;		/* whether we've seen an EOF on this buffer */
X#define EOF_NOT_SEEN 0
X    /* "pending" happens when the EOF has been seen but there's still
X     * some text process
X     */
X#define EOF_PENDING 1
X#define EOF_DONE 2
X    };
X
static YY_BUFFER_STATE yy_current_buffer;
X
X/* we provide macros for accessing buffer states in case in the
X * future we want to put the buffer states in a more general
X * "scanner state"
X */
X#define YY_CURRENT_BUFFER yy_current_buffer
X
X
X/* yy_hold_char holds the character lost when yytext is formed */
static YY_CHAR yy_hold_char;
X
static int yy_n_chars;		/* number of characters read into yy_ch_buf */
X
X
X
X#ifndef YY_USER_ACTION
X#define YY_USER_ACTION
X#endif
X
X#ifndef YY_USER_INIT
X#define YY_USER_INIT
X#endif
X
extern YY_CHAR *yytext;
extern int yyleng;
extern FILE *yyin, *yyout;
X
YY_CHAR *yytext;
int yyleng;
X
XFILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
X
X#define YY_END_OF_BUFFER 13
typedef int yy_state_type;
static const short int yy_accept[22] =
X    {   0,
X        0,    0,   13,   11,    1,   11,   11,   11,   11,   11,
X       11,    2,    6,    6,    5,    8,    9,    4,    3,   10,
X        7
X    } ;
X
static const YY_CHAR yy_ec[128] =
X    {   0,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    3,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1,    4,    4,    4,
X        4,    4,    4,    4,    4,    4,    4,    1,    1,    1,
X        1,    1,    1,    1,    5,    6,    7,    1,    8,    1,
X        1,    1,    1,    1,    1,    1,    9,    1,    1,    1,
X        1,    1,   10,    1,    1,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,   11,   12,   13,    1,
X
X        8,    1,    1,    1,    1,    1,    1,    1,   14,    1,
X        1,    1,    1,    1,   15,    1,    1,    1,    1,    1,
X        1,    1,    1,    1,    1,    1,    1
X    } ;
X
X/* the intent behind this definition is that it'll catch
X * any uses of REJECT which flex missed
X */
X#define REJECT reject_used_but_not_detected
X#define yymore() yymore_used_but_not_detected
X#define YY_MORE_ADJ 0
X
X/* these variables are all declared out here so that section 3 code can
X * manipulate them
X */
X/* points to current character in buffer */
static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */
X
X/* flag which is used to allow yywrap()'s to do buffer switches
X * instead of setting up a fresh yyin.  A bit of a hack ...
X */
static int yy_did_buffer_switch_on_eof;
X
static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
void yyrestart YY_PROTO(( FILE *input_file ));
void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
X
X#define yy_new_buffer yy_create_buffer
X
X#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
X#else
static int input YY_PROTO(( void ));
X#endif
X
YY_DECL
X    {
X    register yy_state_type yy_current_state;
X    register YY_CHAR *yy_cp, *yy_bp;
X    register int yy_act;
X
X
X
X
X    if ( yy_init )
X	{
X	YY_USER_INIT;
X
X	if ( ! yy_start )
X	    yy_start = 1;	/* first start state */
X
X	if ( ! yyin )
X	    yyin = stdin;
X
X	if ( ! yyout )
X	    yyout = stdout;
X
X	if ( yy_current_buffer )
X	    yy_init_buffer( yy_current_buffer, yyin );
X	else
X	    yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
X
X	yy_load_buffer_state();
X
X	yy_init = 0;
X	}
X
X    while ( 1 )		/* loops until end-of-file is reached */
X	{
X	yy_cp = yy_c_buf_p;
X
X	/* support of yytext */
X	*yy_cp = yy_hold_char;
X
X	/* yy_bp points to the position in yy_ch_buf of the start of the
X	 * current run.
X	 */
X	yy_bp = yy_cp;
X
X	yy_current_state = yy_start;
yy_match:
X	while ( (yy_current_state = yy_nxt[yy_current_state][yy_ec[*yy_cp]]) > 0 )
X	    ++yy_cp;
X
X	yy_current_state = -yy_current_state;
X
yy_find_action:
X	yy_act = yy_accept[yy_current_state];
X
X	YY_DO_BEFORE_ACTION;
X	YY_USER_ACTION;
X
do_action:	/* this label is used only to access EOF actions */
X
X
X	switch ( yy_act )
X	    {
case 1:
X# line 70 "scene.l"
X;
X	YY_BREAK
case 2:
X# line 72 "scene.l"
X{
X			write_scene();
X			scene_no++;
X		}
X	YY_BREAK
case 3:
X# line 77 "scene.l"
X{
X			add_char_to_scene(yytext + 1);
X		}
X	YY_BREAK
case 4:
X# line 81 "scene.l"
X{
X			strcpy(curr_book,yytext + 1);
X			strcpy(scenes[scene_no - 1].book,yytext + 1);
X		}
X	YY_BREAK
case 5:
X# line 86 "scene.l"
X{
X			sscanf(yytext,"#%d",&(scenes[scene_no - 1].page));
X		}
X	YY_BREAK
case 6:
X# line 90 "scene.l"
X{
X			fprintf(stderr,"Invalid page number, ignoring\n");
X		}
X	YY_BREAK
case 7:
X# line 94 "scene.l"
X{
X			strcpy(scenes[scene_no - 1].music,yytext + 1);
X		}
X	YY_BREAK
case 8:
X# line 98 "scene.l"
X{
X			strcpy(scenes[scene_no - 1].musicby,yytext + 1);
X		}
X	YY_BREAK
case 9:
X# line 102 "scene.l"
X{
X			fprintf(stderr,"Invalid null %c, ignoring\n",yytext[0]);
X		}
X	YY_BREAK
case 10:
X# line 106 "scene.l"
X{
X			write_scene();
X			return(0);
X		}
X	YY_BREAK
case 11:
X# line 111 "scene.l"
X{
X			fprintf(stderr,"What does %c mean?\n",yytext[0]);
X		}
X	YY_BREAK
case 12:
X# line 115 "scene.l"
XECHO;
X	YY_BREAK
X	    case YY_STATE_EOF(INITIAL):
X		yyterminate();
X
X	    case YY_END_OF_BUFFER:
X		{
X		/* amount of text matched not including the EOB char */
X		int yy_amount_of_matched_text = yy_cp - yytext - 1;
X
X		/* undo the effects of YY_DO_BEFORE_ACTION */
X		*yy_cp = yy_hold_char;
X
X		/* note that here we test for yy_c_buf_p "<=" to the position
X		 * of the first EOB in the buffer, since yy_c_buf_p will
X		 * already have been incremented past the NUL character
X		 * (since all states make transitions on EOB to the end-
X		 * of-buffer state).  Contrast this with the test in yyinput().
X		 */
X		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
X		    /* this was really a NUL */
X		    {
X		    yy_state_type yy_next_state;
X
X		    yy_c_buf_p = yytext + yy_amount_of_matched_text;
X
X		    yy_current_state = yy_get_previous_state();
X
X		    /* okay, we're now positioned to make the
X		     * NUL transition.  We couldn't have
X		     * yy_get_previous_state() go ahead and do it
X		     * for us because it doesn't know how to deal
X		     * with the possibility of jamming (and we
X		     * don't want to build jamming into it because
X		     * then it will run more slowly)
X		     */
X
X		    yy_next_state = yy_try_NUL_trans( yy_current_state );
X
X		    yy_bp = yytext + YY_MORE_ADJ;
X
X		    if ( yy_next_state )
X			{
X			/* consume the NUL */
X			yy_cp = ++yy_c_buf_p;
X			yy_current_state = yy_next_state;
X			goto yy_match;
X			}
X
X		    else
X			{
X			    yy_cp = yy_c_buf_p;
X			goto yy_find_action;
X			}
X		    }
X
X		else switch ( yy_get_next_buffer() )
X		    {
X		    case EOB_ACT_END_OF_FILE:
X			{
X			yy_did_buffer_switch_on_eof = 0;
X
X			if ( yywrap() )
X			    {
X			    /* note: because we've taken care in
X			     * yy_get_next_buffer() to have set up yytext,
X			     * we can now set up yy_c_buf_p so that if some
X			     * total hoser (like flex itself) wants
X			     * to call the scanner after we return the
X			     * YY_NULL, it'll still work - another YY_NULL
X			     * will get returned.
X			     */
X			    yy_c_buf_p = yytext + YY_MORE_ADJ;
X
X			    yy_act = YY_STATE_EOF((yy_start - 1) / 2);
X			    goto do_action;
X			    }
X
X			else
X			    {
X			    if ( ! yy_did_buffer_switch_on_eof )
X				YY_NEW_FILE;
X			    }
X			}
X			break;
X
X		    case EOB_ACT_CONTINUE_SCAN:
X			yy_c_buf_p = yytext + yy_amount_of_matched_text;
X
X			yy_current_state = yy_get_previous_state();
X
X			yy_cp = yy_c_buf_p;
X			yy_bp = yytext + YY_MORE_ADJ;
X			goto yy_match;
X
X		    case EOB_ACT_LAST_MATCH:
X			yy_c_buf_p =
X			    &yy_current_buffer->yy_ch_buf[yy_n_chars];
X
X			yy_current_state = yy_get_previous_state();
X
X			yy_cp = yy_c_buf_p;
X			yy_bp = yytext + YY_MORE_ADJ;
X			goto yy_find_action;
X		    }
X		break;
X		}
X
X	    default:
X#ifdef FLEX_DEBUG
X		printf( "action # %d\n", yy_act );
X#endif
X		YY_FATAL_ERROR(
X			"fatal flex scanner internal error--no action found" );
X	    }
X	}
X    }
X
X
X/* yy_get_next_buffer - try to read in a new buffer
X *
X * synopsis
X *     int yy_get_next_buffer();
X *     
X * returns a code representing an action
X *     EOB_ACT_LAST_MATCH - 
X *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
X *     EOB_ACT_END_OF_FILE - end of file
X */
X
static int yy_get_next_buffer()
X
X    {
X    register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
X    register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
X    register int number_to_move, i;
X    int ret_val;
X
X    if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
X	YY_FATAL_ERROR(
X		"fatal flex scanner internal error--end of buffer missed" );
X
X    /* try to read more data */
X
X    /* first move last chars to start of buffer */
X    number_to_move = yy_c_buf_p - yytext;
X
X    for ( i = 0; i < number_to_move; ++i )
X	*(dest++) = *(source++);
X
X    if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
X	/* don't do the read, it's not guaranteed to return an EOF,
X	 * just force an EOF
X	 */
X	yy_n_chars = 0;
X
X    else
X	{
X	int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
X
X	if ( num_to_read > YY_READ_BUF_SIZE )
X	    num_to_read = YY_READ_BUF_SIZE;
X
X	else if ( num_to_read <= 0 )
X	    YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
X
X	/* read in more data */
X	YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
X		  yy_n_chars, num_to_read );
X	}
X
X    if ( yy_n_chars == 0 )
X	{
X	if ( number_to_move == 1 )
X	    {
X	    ret_val = EOB_ACT_END_OF_FILE;
X	    yy_current_buffer->yy_eof_status = EOF_DONE;
X	    }
X
X	else
X	    {
X	    ret_val = EOB_ACT_LAST_MATCH;
X	    yy_current_buffer->yy_eof_status = EOF_PENDING;
X	    }
X	}
X
X    else
X	ret_val = EOB_ACT_CONTINUE_SCAN;
X
X    yy_n_chars += number_to_move;
X    yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
X    yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
X
X    /* yytext begins at the second character in yy_ch_buf; the first
X     * character is the one which preceded it before reading in the latest
X     * buffer; it needs to be kept around in case it's a newline, so
X     * yy_get_previous_state() will have with '^' rules active
X     */
X
X    yytext = &yy_current_buffer->yy_ch_buf[1];
X
X    return ( ret_val );
X    }
X
X
X/* yy_get_previous_state - get the state just before the EOB char was reached
X *
X * synopsis
X *     yy_state_type yy_get_previous_state();
X */
X
static yy_state_type yy_get_previous_state()
X
X    {
X    register yy_state_type yy_current_state;
X    register YY_CHAR *yy_cp;
X
X    yy_current_state = yy_start;
X
X    for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
X	{
X	yy_current_state = yy_nxt[yy_current_state][(*yy_cp ? yy_ec[*yy_cp] : 1)];
X	}
X
X    return ( yy_current_state );
X    }
X
X
X/* yy_try_NUL_trans - try to make a transition on the NUL character
X *
X * synopsis
X *     next_state = yy_try_NUL_trans( current_state );
X */
X
X#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
X#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
register yy_state_type yy_current_state;
X#endif
X
X    {
X    register int yy_is_jam;
X
X    yy_current_state = yy_nxt[yy_current_state][1];
X    yy_is_jam = (yy_current_state <= 0);
X
X    return ( yy_is_jam ? 0 : yy_current_state );
X    }
X
X
X#ifdef YY_USE_PROTOS
static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
X#else
static void yyunput( c, yy_bp )
YY_CHAR c;
register YY_CHAR *yy_bp;
X#endif
X
X    {
X    register YY_CHAR *yy_cp = yy_c_buf_p;
X
X    /* undo effects of setting up yytext */
X    *yy_cp = yy_hold_char;
X
X    if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X	{ /* need to shift things up to make room */
X	register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
X	register YY_CHAR *dest =
X	    &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
X	register YY_CHAR *source =
X	    &yy_current_buffer->yy_ch_buf[number_to_move];
X
X	while ( source > yy_current_buffer->yy_ch_buf )
X	    *--dest = *--source;
X
X	yy_cp += dest - source;
X	yy_bp += dest - source;
X	yy_n_chars = yy_current_buffer->yy_buf_size;
X
X	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
X	    YY_FATAL_ERROR( "flex scanner push-back overflow" );
X	}
X
X    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
X	yy_cp[-2] = '\n';
X
X    *--yy_cp = c;
X
X    /* note: the formal parameter *must* be called "yy_bp" for this
X     *       macro to now work correctly
X     */
X    YY_DO_BEFORE_ACTION; /* set up yytext again */
X    }
X
X
X#ifdef __cplusplus
static int yyinput()
X#else
static int input()
X#endif
X
X    {
X    int c;
X    YY_CHAR *yy_cp = yy_c_buf_p;
X
X    *yy_cp = yy_hold_char;
X
X    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
X	{
X	/* yy_c_buf_p now points to the character we want to return.
X	 * If this occurs *before* the EOB characters, then it's a
X	 * valid NUL; if not, then we've hit the end of the buffer.
X	 */
X	if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
X	    /* this was really a NUL */
X	    *yy_c_buf_p = '\0';
X
X	else
X	    { /* need more input */
X	    yytext = yy_c_buf_p;
X	    ++yy_c_buf_p;
X
X	    switch ( yy_get_next_buffer() )
X		{
X		case EOB_ACT_END_OF_FILE:
X		    {
X		    if ( yywrap() )
X			{
X			yy_c_buf_p = yytext + YY_MORE_ADJ;
X			return ( EOF );
X			}
X
X		    YY_NEW_FILE;
X
X#ifdef __cplusplus
X		    return ( yyinput() );
X#else
X		    return ( input() );
X#endif
X		    }
X		    break;
X
X		case EOB_ACT_CONTINUE_SCAN:
X		    yy_c_buf_p = yytext + YY_MORE_ADJ;
X		    break;
X
X		case EOB_ACT_LAST_MATCH:
X#ifdef __cplusplus
X		    YY_FATAL_ERROR( "unexpected last match in yyinput()" );
X#else
X		    YY_FATAL_ERROR( "unexpected last match in input()" );
X#endif
X		}
X	    }
X	}
X
X    c = *yy_c_buf_p;
X    yy_hold_char = *++yy_c_buf_p;
X
X    return ( c );
X    }
X
X
X#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
X#else
void yyrestart( input_file )
XFILE *input_file;
X#endif
X
X    {
X    yy_init_buffer( yy_current_buffer, input_file );
X    yy_load_buffer_state();
X    }
X
X
X#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
X#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
X#endif
X
X    {
X    if ( yy_current_buffer == new_buffer )
X	return;
X
X    if ( yy_current_buffer )
X	{
X	/* flush out information for old buffer */
X	*yy_c_buf_p = yy_hold_char;
X	yy_current_buffer->yy_buf_pos = yy_c_buf_p;
X	yy_current_buffer->yy_n_chars = yy_n_chars;
X	}
X
X    yy_current_buffer = new_buffer;
X    yy_load_buffer_state();
X
X    /* we don't actually know whether we did this switch during
X     * EOF (yywrap()) processing, but the only time this flag
X     * is looked at is after yywrap() is called, so it's safe
X     * to go ahead and always set it.
X     */
X    yy_did_buffer_switch_on_eof = 1;
X    }
X
X
X#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
X#else
void yy_load_buffer_state()
X#endif
X
X    {
X    yy_n_chars = yy_current_buffer->yy_n_chars;
X    yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
X    yyin = yy_current_buffer->yy_input_file;
X    yy_hold_char = *yy_c_buf_p;
X    }
X
X
X#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
X#else
YY_BUFFER_STATE yy_create_buffer( file, size )
XFILE *file;
int size;
X#endif
X
X    {
X    YY_BUFFER_STATE b;
X
X    b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
X
X    if ( ! b )
X	YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X    b->yy_buf_size = size;
X
X    /* yy_ch_buf has to be 2 characters longer than the size given because
X     * we need to put in 2 end-of-buffer characters.
X     */
X    b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
X
X    if ( ! b->yy_ch_buf )
X	YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
X
X    yy_init_buffer( b, file );
X
X    return ( b );
X    }
X
X
X#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
X#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
X#endif
X
X    {
X    if ( b == yy_current_buffer )
X	yy_current_buffer = (YY_BUFFER_STATE) 0;
X
X    free( (char *) b->yy_ch_buf );
X    free( (char *) b );
X    }
X
X
X#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
X#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
XFILE *file;
X#endif
X
X    {
X    b->yy_input_file = file;
X
X    /* we put in the '\n' and start reading from [1] so that an
X     * initial match-at-newline will be true.
X     */
X
X    b->yy_ch_buf[0] = '\n';
X    b->yy_n_chars = 1;
X
X    /* we always need two end-of-buffer characters.  The first causes
X     * a transition to the end-of-buffer state.  The second causes
X     * a jam in that state.
X     */
X    b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
X    b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
X
X    b->yy_buf_pos = &b->yy_ch_buf[1];
X
X    b->yy_eof_status = EOF_NOT_SEEN;
X    }
X# line 115 "scene.l"
X
X
void add_char_to_scene(char *thechar) {
X	int i;
X
X	i = 0;
X	while(chars[i].num_scenes) {
X		if(!strcmp(chars[i].name,thechar))
X			break;
X		i++;
X	}
X
X	if(chars[i].num_scenes) {
X		chars[i].num_scenes++;
X		chars[i].scenes[chars[i].num_scenes-1] = scene_no;
X	} else {
X		strcpy(chars[i].name,thechar);
X		chars[i].scenes[0] = scene_no;
X		chars[i].num_scenes = 1;
X	}
X
X	scenes[scene_no-1].chars[scenes[scene_no-1].num_chars] = i;
X	scenes[scene_no-1].num_chars++;
X}
X
void write_scene(void) {
X	static int first = 1;
X	int i;
X
X	if(first) {
X		first = 0;
X		return;
X	}
X
X	if(!scenes[scene_no-1].book[0]) {
X	  strcpy(scenes[scene_no-1].book,curr_book);
X	}
X
X	printf("\\vskip 12pt\nScene {\\scenef %d}\n\n",scene_no);
X	printf("from {\\bookf %s}, p. %d\n\n",scenes[scene_no-1].book,
X					    scenes[scene_no-1].page);
X	printf("Characters: ");
X	
X	sort_scene_chars();
X
X	for(i=0; i<scenes[scene_no-1].num_chars; i++) {
X		printf("%s{\\charf %s}",
X		       i?",\n":"",
X		       chars[scenes[scene_no-1].chars[i]].name);
X	}
X	printf("%s.\n\n",i?"":"Narrator");
X
X	if(scenes[scene_no-1].music[0]) {
X	  printf("Music: {\\musicf ``%s''}, %s",
X		 scenes[scene_no-1].music,
X		 scenes[scene_no-1].musicby);
X	}
X
X	printf("\n\n");
X}
X
static void sort_scene_chars(void) {
X  int i;
X
X  qsort((char *)scenes[scene_no-1].chars,scenes[scene_no-1].num_chars,
X	sizeof scenes[scene_no-1].chars[0],
X	sort_int_by_char);
X}
X
static int sort_int_by_char(const void *a,const void *b) {
X  int i = *(const int *)a,j = *(const int *)b;
X
X  return(strcmp(chars[i].name,chars[j].name));
X}
X
static int sort_char_by_name(const void *a,const void *b) {
X  const char *n = ((const struct character *)a)->name;
X  const char *o = ((const struct character *)b)->name;
X
X  return(strcmp(n,o));
X}
X
X/*
X * WARNING
X * This function destroys the mapping from scens[i].chars[i] to
X * an actual character.  It MUST BE CALLED LAST (or at least after
X * this mapping is no longer needed.
X */
static void anal_chars(void) {
X  int i,j,last,olast;
X
X  for(i=0; chars[i].num_scenes; i++); /* i is now number of characters */
X
X  qsort((char *)chars,i,sizeof chars[0],sort_char_by_name);
X
X  printf("\\vskip 0pt plus 1filll\n{\\bigfont Character Windows}\n\n");
X
X  for(i=0; chars[i].num_scenes; i++) {
X    printf("\\vskip 12pt\nCharacter %s appears in scenes: \n",chars[i].name);
X
X    last = 0; olast = 0;
X
X    /* look, this could be a lot smarter if I felt like working on it more.
X       If I ever get around to it, maybe.  Maybe. */
X
X    for(j=0; j < chars[i].num_scenes; j++) {
X      if(last && (chars[i].scenes[j] == last + 1)) {
X	/*
X	 * The last one we got was one less than this one, so keep on
X	 * going.
X	 */
X	olast = last++;
X      } else if(last) {
X	/*
X	 * The last one we got was something else, so output the
X	 * last one, a comma, and then this one.
X	 */
X	if(olast) {
X	  printf("--%d",last);
X	  olast = 0;
X	}
X
X	printf(", %d",last=chars[i].scenes[j]);
X      } else {
X	/*
X	 * The first scene: just print it.
X	 */
X	printf("%d",last=chars[i].scenes[j]); /* side effect */
X      }
X    }
X    if(last && olast) {
X      printf("--%d",last);
X    }
X    printf(".\n\n");
X  }
X}
X
X
void main(int argc,char **argv) {
X  argc--; argv++;
X  if(argc) {
X    if(!freopen(*argv,"r",stdin)) {
X      fprintf(stderr,"scene: cannot open input file %s\n",*argv);
X      exit(1);
X    }
X  }
X
X  /* USER CUSTOMIZATION
X   * You may want to change some of these definitions, especially
X   * if your printer has good fonts of its own.
X   */
X  printf("\\font\\scenef=cmbx10 scaled \\magstep2\n"
X	 "\\font\\bookf=cmti10 scaled \\magstephalf\n"
X	 "\\font\\charf=cmbx10 scaled \\magstep1\n"
X	 "\\font\\musicf=cmsl10 scaled \\magstephalf\n"
X	 "\\font\\bodyfont=cmr10 scaled \\magstephalf\n"
X	 "\\font\\bigfont=cmr10 scaled \\magstep2\n"
X	 "{\\bodyfont\n");
X
X  yylex();
X  anal_chars();
X  printf("}\\end\n");
X  exit(0);
X}
X
END_OF_FILE
if test 30114 -ne `wc -c <'scene.c'`; then
    echo shar: \"'scene.c'\" unpacked with wrong size!
fi
# end of 'scene.c'
fi
echo shar: End of shell archive.
exit 0


-- 
Garrett A. Wollman - wollman@emily.uvm.edu

Disclaimer:  I'm not even sure this represents *my* opinion, never
mind UVM's, EMBA's, EMBA-CF's, or indeed anyone else's.

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.