home *** CD-ROM | disk | FTP | other *** search
- head 1.7;
- access;
- symbols
- stage1:1.7;
- locks; strict;
- comment @ * @;
-
-
- 1.7
- date 94.03.10.21.28.26; author peteric; state Exp;
- branches;
- next 1.6;
-
- 1.6
- date 94.03.07.12.55.17; author peteric; state Exp;
- branches;
- next 1.5;
-
- 1.5
- date 94.03.01.23.26.51; author peteric; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 94.02.27.19.36.12; author peteric; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 94.02.13.16.44.05; author peteric; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 94.02.12.20.00.22; author peteric; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 94.02.12.19.52.42; author peteric; state Exp;
- branches;
- next ;
-
-
- desc
- @bison parser for ftree database files.
- @
-
-
- 1.7
- log
- @Multiple pages working!
- @
- text
- @/*************************************************************************
- *
- * $Name$
- *
- * $Author: peteric $
- *
- * $Date: 1994/03/07 12:55:17 $
- *
- * $Revision: 1.6 $
- *
- * Purpose: Parser for ftree database files.
- *
- * $Log: parse.y,v $
- * Revision 1.6 1994/03/07 12:55:17 peteric
- * Passed on as first Version.
- *
- * Revision 1.5 1994/03/01 23:26:51 peteric
- * made ticklen number specified in inches.
- *
- * Revision 1.4 1994/02/27 19:36:12 peteric
- * changed error reporting functions. Mods to add_child to
- * create doubly linked list. added new marriage code & options.
- *
- * Revision 1.3 1994/02/13 16:44:05 peteric
- * Added new notitlebox & titlebox options to modify the title
- * behaviour.
- *
- * Revision 1.2 1994/02/12 20:00:22 peteric
- * added in comments etc.
- *
- *
- *
- *************************************************************************/
-
- %union
- {
- long int inum;
- char *txt;
- float fnum;
- }
-
- %{
-
- #include <string.h>
- #include <stdlib.h>
- #include "ftree.h"
-
- static id_t current_wife_id;
- static id_t current_husband_id;
- static person_t *current_child, *first_child;
- static date_t current_date, marriage_date;
- static person_t current_person;
- static enum mstate_t marriage_state;
- static enum mhint_t marriage_hint;
- static void parsedate(int month, int day, int year);
- static marriage_t *previous_marriage;
- static char *marriage_chart;
-
- %}
-
- %token PERSON ID STRING MONTH INT NUM BORNON DIEDON
- %token OCCUPATION MARRIED WIFE HUSBAND MARRIAGE QMARK
- %token OPENBRA CLOSEBRA COMMA DASH SLASH CHILDREN
- %token SEX MALE FEMALE LIVING DEAD FIRSTNAME FAMILY
- %token VSPACE OUTPUTFILE POINTSIZE IDENT FONT
- %token SYMBOL DATE PERSON TITLE PAGESIZE TICKLEN
- %token ORIENTATION LANDSCAPE PORTRAIT OPTION ROOT
- %token DIVORCED SEPARATED BAPTISED TITLEBOX NOTITLEBOX
- %token LEFT RIGHT BAD THEN HSPACE MULTIPAGE CHARTREF
- %token WIDOWED
- %start file
-
- %type <inum> INT MONTH month day year ID
- %type <txt> STRING
- %type <fnum> NUM
-
- %%
- file : stmt_l
- | blank
-
- stmt_l : stmt
- | stmt_l stmt
-
-
- stmt : stmtperson
- | stmtmarriage
- | stmtoption
-
- blank :
-
- stmtperson : PERSON
- {
- current_person.living = L_UNKNOWN;
- current_person.sex = S_UNKNOWN;
- clear_date(¤t_person.born);
- clear_date(¤t_person.bapt);
- clear_date(¤t_person.died);
- current_person.occupation[0] = '\0';
- current_person.id = 0;
- current_person.firstname[0] = '\0';
- current_person.family[0] = '\0';
- }
- id OPENBRA persdetails CLOSEBRA
- {
- makeperson(¤t_person);
- }
- | error CLOSEBRA
- {
- errmsg("badly formed person construct\n");
- }
-
- id : ID
- {
- current_person.id = $1;
- }
- | blank
- {
- current_person.id = NOID;
- }
- | error
- {
- errmsg("expected ID code\n");
- }
-
-
- persdetails : blank
- | persdetail_l
-
- persdetail_l : persdetail
- | persdetail_l comma persdetail
-
- persdetail : BORNON date
- {
- if (current_person.born.known)
- warnmsg("born specified more than once\n");
- current_person.born = current_date;
- current_date.known = 0;
- }
- | LIVING
- {
- if (current_person.living != L_UNKNOWN)
- warnmsg("living specified more than once\n");
- current_person.living = L_LIVING;
- }
- | DEAD
- {
- if (current_person.living != L_UNKNOWN)
- warnmsg("dead or diedon already specified\n");
- current_person.living = L_DEAD;
- }
- | BAPTISED date
- {
- if (current_person.living != L_UNKNOWN)
- warnmsg("living specified more than once\n");
- current_person.bapt = current_date;
- current_date.known = 0;
- }
- | DIEDON date
- {
- if (current_person.living != L_UNKNOWN)
- warnmsg("living specified more than once\n");
- current_person.died = current_date;
- current_date.known = 0;
- current_person.living = L_DEAD;
- }
- | SEX FEMALE
- {
- if (current_person.sex != S_UNKNOWN)
- warnmsg("sex already specified\n");
- current_person.sex = S_FEMALE;
- }
- | SEX MALE
- {
- if (current_person.sex != S_UNKNOWN)
- warnmsg("sex already specified\n");
- current_person.sex = S_MALE;
- }
- | OCCUPATION STRING
- {
- if (current_person.occupation[0] != '\0')
- warnmsg("occupation already specified\n");
- strcpy(current_person.occupation, $2);
- }
- | FIRSTNAME STRING
- {
- if (current_person.firstname[0] != '\0')
- errmsg("first name '%s' already specified\n", $2);
- if (strlen($2) > NAMELEN)
- {
- warnmsg("first name '%s' too long; name truncated to %d characters\n", $2, NAMELEN);
- strncpy(current_person.firstname, $2, NAMELEN);
- current_person.firstname[NAMELEN-1] = '\0';
- }
- else
- strcpy(current_person.firstname, $2);
- }
- | FAMILY STRING
- {
- if (current_person.family[0] != '\0')
- errmsg("family name '%s' already specified\n", $2);
- if (strlen($2) > NAMELEN)
- {
- warnmsg("family name '%s' too long; name truncated to %d characters\n", $2, NAMELEN);
- strncpy(current_person.family, $2, NAMELEN);
- current_person.family[NAMELEN-1] = '\0';
- }
- else
- strcpy(current_person.family, $2);
- }
- | error CLOSEBRA
- {
- warnmsg("unexpected word in person details list\n");
- }
-
- stmtoption : OPTION OPENBRA optdetails CLOSEBRA
-
- optdetails : blank
- | optdetail_l
-
- optdetail_l : optdetail
- | optdetail_l comma optdetail
-
- optdetail : VSPACE NUM
- {
- glob_opts->vspace = (int)($2 * INCH);
- }
- | HSPACE NUM
- {
- glob_opts->tree_gap = (int)($2 * INCH);
- }
- | ROOT ID
- {
- glob_opts->startperson = $2;
- }
- | OUTPUTFILE STRING
- {
- char *s = (char*)malloc(strlen($2)+1);
- strcpy(s, $2);
- glob_opts->outputfile = s;
- }
- | NOTITLEBOX
- {
- glob_opts->titlegreylevel = 1.0;
- }
- | MULTIPAGE
- {
- glob_opts->multipage = TRUE;
- }
- | TITLEBOX NUM
- {
- glob_opts->titlegreylevel = $2;
- }
- | IDENT POINTSIZE NUM
- {
- glob_opts->identfont.size = $3;
- }
- | IDENT FONT STRING
- {
- char *s = (char*)malloc(strlen($3)+1);
- strcpy(s, $3);
- glob_opts->titlefont.font = s;
- }
- | SYMBOL POINTSIZE NUM
- {
- glob_opts->symfont.size = $3;
- }
- | SYMBOL FONT STRING
- {
- char *s = (char*)malloc(strlen($3)+1);
- strcpy(s, $3);
- glob_opts->symfont.font = s;
- }
- | DATE POINTSIZE NUM
- {
- glob_opts->datefont.size = $3;
- }
- | DATE FONT STRING
- {
- char *s = (char*)malloc(strlen($3)+1);
- strcpy(s, $3);
- glob_opts->datefont.font = s;
- }
- | PERSON POINTSIZE NUM
- {
- glob_opts->personfont.size = $3;
- }
- | PERSON FONT STRING
- {
- char *s = (char*)malloc(strlen($3)+1);
- strcpy(s, $3);
- glob_opts->personfont.font = s;
- }
- | TITLE STRING
- {
- char *s = (char*)malloc(strlen($2)+1);
- strcpy(s, $2);
- glob_opts->titlestr = s;
- }
- | TITLE POINTSIZE NUM
- {
- glob_opts->titlefont.size = $3;
- }
- | TITLE FONT STRING
- {
- char *s = (char*)malloc(strlen($3)+1);
- strcpy(s, $3);
- glob_opts->titlefont.font = s;
- }
- | PAGESIZE STRING
- {
- char *s = (char*)malloc(strlen($2)+1);
- strcpy(s, $2);
- glob_opts->papertype = s;
- }
- | TICKLEN NUM
- {
- glob_opts->ticklen = $2 * INCH;
- }
- | ORIENTATION LANDSCAPE
- {
- glob_opts->landscape = TRUE;
- }
- | ORIENTATION PORTRAIT
- {
- glob_opts->landscape = FALSE;
- }
- | error CLOSEBRA
- {
- errmsg("unexpected word in options list!\n");
- }
-
-
- stmtmarriage : MARRIAGE
- {
- previous_marriage = NULL;
- }
- marriage_def more_marriages
-
- more_marriages : blank
- | comma more_marriage_l
-
- more_marriage_l : THEN marriage_def
- | more_marriage_l comma THEN marriage_def
-
-
- marriage_def : OPENBRA
- {
- current_child = first_child = NULL;
- current_husband_id = NOID;
- current_wife_id = NOID;
- clear_date(¤t_date);
- clear_date(&marriage_date);
- marriage_chart = NULL;
- marriage_state = M_MARRIED;
- marriage_hint = H_CENTERED;
- }
- marriage_l CLOSEBRA
- {
- if (verbose && !marriage_date.known)
- warnmsg("marriage date not specified\n");
-
- if (current_wife_id == NOID || current_husband_id == NOID)
- errmsg("cannot construct a marriage unless both people are identified.\n");
- else
- previous_marriage = makemarriage(previous_marriage, current_husband_id, current_wife_id,
- marriage_date, marriage_state, marriage_hint,
- first_child, current_child);
- }
-
- marriage_l : marrdetail
- | marriage_l comma marrdetail
-
- marrdetail : MARRIED date
- {
- marriage_date = current_date;
- }
- | DIVORCED
- {
- marriage_state = M_DIVORCED;
- }
- | SEPARATED
- {
- marriage_state = M_SEPARATED;
- }
- | WIDOWED
- {
- marriage_state = M_WIDOWED;
- }
- | CHARTREF STRING
- {
- char *s = (char*)malloc(strlen($2)+1);
- strcpy(s, $2);
- marriage_chart = s;
- }
- | LEFT
- {
- marriage_hint = H_LEFT;
- }
- | RIGHT
- {
- marriage_hint = H_RIGHT;
- }
- | WIFE ID
- {
- current_wife_id = $2;
- }
- | HUSBAND ID
- {
- current_husband_id = $2;
- }
- | CHILDREN child_l
- | error CLOSEBRA
- {
- errmsg("unexpected marriage keyword.\n");
- }
-
-
- child_l : child
- | child_l comma child
-
- child : ID
- {
- add_child($1);
- }
-
- date : day dsep month dsep year
- {
- parsedate($3,$1,$5);
- }
-
- day : INT
- {
- $$ = $1;
- }
- | QMARK
- {
- $$ = -1;
- }
- | error
- {
- errmsg("expected day number or ? in date\n");
- }
-
- month : MONTH
- {
- $$ = $1;
- }
- | QMARK
- {
- $$ = -1;
- }
- | error
- {
- errmsg("expected name of month or ? in date\n");
- }
-
- year : INT
- {
- $$ = $1;
- }
- | QMARK
- {
- $$ = -1;
- }
- | error
- {
- errmsg("expected year number or ? in date\n");
- }
-
- dsep : DASH
- | SLASH
- | blank
-
- comma : COMMA
- | blank
-
- %%
-
- static void parsedate(int month, int day, int year)
- {
- current_date.dvalid = (day != -1);
- current_date.mvalid = (month != -1);
- current_date.yvalid = (year != -1);
- current_date.known = (current_date.dvalid || current_date.mvalid || current_date.yvalid);
-
- if (year < 100)
- year += 1900;
-
- current_date.year = year;
- current_date.month = month;
- current_date.day = day;
-
- dbprintf(("parsedate: %s d: %d m: %d y: %d\n", current_date.known ? "known":"unknown", current_date.year,
- current_date.month, current_date.day));
- }
-
- void clear_date(date_t *date)
- {
- date->known = 0;
- date->yvalid = 0;
- date->dvalid = 0;
- date->mvalid = 0;
- }
-
- void add_child(id_t id)
- {
- person_t *q;
-
- q = findperson(id);
- if (q)
- {
- if (first_child == NULL)
- {
- dbprintf(("add_child(%lx): first child\n", id));
- first_child = q;
- q->lastchild = NULL;
- }
- else
- {
- dbprintf(("add_child(%lx): next child\n", id));
- current_child->nextchild = q;
- q->lastchild = current_child;
- }
- q->nextchild = NULL;
- current_child = q;
- }
- else
- {
- fprintf(stderr,"ftree: child '%lx' is not listed.\n", id);
- }
- }
- @
-
-
- 1.6
- log
- @Passed on as first Version.
- @
- text
- @d7 1
- a7 1
- * $Date: 1994/03/01 23:26:51 $
- d9 1
- a9 1
- * $Revision: 1.5 $
- d14 3
- d57 1
- d68 3
- a70 2
- %token DIVORCED SEPERATED BAPTISED TITLEBOX NOTITLEBOX
- %token LEFT RIGHT BAD THEN
- d227 4
- d245 4
- d353 1
- d381 9
- a389 1
- | SEPERATED
- d391 3
- a393 1
- marriage_state = M_SEPERATED;
- @
-
-
- 1.5
- log
- @made ticklen number specified in inches.
- @
- text
- @d7 1
- a7 1
- * $Date: 1994/02/27 19:36:12 $
- d9 1
- a9 1
- * $Revision: 1.4 $
- d14 3
- d327 1
- a327 1
- | THEN more_marriage_l
- d329 2
- a330 2
- more_marriage_l : marriage_def
- | more_marriage_l comma marriage_def
- d351 1
- a351 1
- makemarriage(previous_marriage, current_husband_id, current_wife_id,
- @
-
-
- 1.4
- log
- @changed error reporting functions. Mods to add_child to
- create doubly linked list. added new marriage code & options.
- @
- text
- @d7 1
- a7 1
- * $Date: 1994/02/13 16:44:05 $
- d9 1
- a9 1
- * $Revision: 1.3 $
- d14 4
- d301 1
- a301 1
- glob_opts->ticklen = $2;
- @
-
-
- 1.3
- log
- @Added new notitlebox & titlebox options to modify the title
- behaviour.
- @
- text
- @d7 1
- a7 1
- * $Date: 1994/02/12 20:00:22 $
- d9 1
- a9 1
- * $Revision: 1.2 $
- d14 4
- d27 1
- a27 1
- int inum;
- d33 3
- d38 9
- a46 1
- extern void *malloc();
- a47 9
- char current_wife[128];
- char current_husband[128];
- person_t *current_child, *first_child;
- date_t current_date, marriage_date;
- person_t current_person;
- enum mstate_t marriage_state;
-
- void parsedate(int month, int day, int year);
- void add_child(char *str);
- d55 1
- a55 1
- %token PERSON POINTSIZE FONT TITLE FONT PAGESIZE TICKLEN
- d58 1
- d61 2
- a62 2
- %type <inum> INT MONTH month day year
- %type <txt> STRING ID
- d87 1
- a87 1
- current_person.id[0] = '\0';
- d97 1
- a97 1
- yyerror("badly formed person construct");
- d102 1
- a102 3
- strcpy(current_person.id, $1);
- if (findperson(current_person.id) != NULL)
- yyerror("duplicate id code; ID's must be unique");
- d106 1
- a106 1
- strcpy(current_person.id, "(blank)");
- d110 1
- a110 1
- yyerror("expected ID code");
- d123 1
- a123 1
- yyerror("born specified more than once");
- d130 1
- a130 1
- yyerror("living specified more than once");
- d136 1
- a136 1
- yyerror("dead or diedon already specified");
- d142 1
- a142 1
- yyerror("living specified more than once");
- d149 1
- a149 1
- yyerror("living specified more than once");
- d157 1
- a157 1
- yyerror("sex already specified");
- d163 1
- a163 1
- yyerror("sex already specified");
- d169 1
- a169 1
- yyerror("occupation already specified");
- d175 9
- a183 2
- yyerror("first name already specified");
- strcpy(current_person.firstname, $2);
- d188 9
- a196 2
- yyerror("family name already specified");
- strcpy(current_person.family, $2);
- d198 1
- a198 1
- | error
- d200 1
- a200 1
- yyerror("unexpected symbol person details list!");
- a203 2
- {
- }
- d213 1
- a213 1
- glob_opts->vspace = $2 * INCH;
- d217 1
- a217 3
- char *s = (char*)malloc(strlen($2)+1);
- strcpy(s, $2);
- glob_opts->startperson = s;
- d235 1
- a235 1
- glob_opts->ident.size = $3;
- d241 1
- a241 1
- glob_opts->title.font = s;
- d243 20
- d265 1
- a265 1
- glob_opts->person.size = $3;
- d271 1
- a271 1
- glob_opts->title.font = s;
- d281 1
- a281 1
- glob_opts->title.size = $3;
- d287 1
- a287 1
- glob_opts->title.font = s;
- d307 1
- a307 1
- | error
- d309 1
- a309 1
- yyerror("unexpected symbol options list!");
- d315 13
- d329 2
- a330 2
- current_husband[0] = '\0';
- current_wife[0] = '\0';
- d334 1
- d336 1
- a336 1
- OPENBRA marriage_l CLOSEBRA
- d338 5
- a342 2
- if (current_wife[0] == '\0' || current_husband[0] == '\0')
- yyerror("cannot construct a marriage unless both people are identified.");
- d344 3
- a346 1
- makemarriage(current_husband, current_wife, marriage_date, marriage_state, first_child, current_child);
- d364 8
- d374 1
- a374 1
- strcpy(current_wife, $2);
- d378 1
- a378 1
- strcpy(current_husband, $2);
- d381 1
- a381 1
- | error
- d383 1
- a383 1
- yyerror("unexpected marriage keyword");
- d392 1
- a392 1
- add_child((char*)$1);
- d394 1
- a394 6
- /*
- | error
- {
- yyerror("children list must contain of the ID's of children!");
- }
- */
- d410 1
- a410 1
- yyerror("expected day number or ? in date");
- d423 1
- a423 1
- yyerror("expected name of month or ? in date");
- d436 1
- a436 1
- yyerror("expected year number or ? in date");
- d448 1
- a448 1
- void parsedate(int month, int day, int year)
- a465 1
-
- d474 1
- a474 1
- void add_child(char *str)
- d476 1
- a476 1
- person_t *p, *q;
- d478 1
- a478 1
- q = findperson(str);
- d483 1
- a483 1
- dbprintf(("add_child(%s): first child\n", str));
- d485 1
- d489 3
- a491 3
- dbprintf(("add_child(%s): next child\n", str));
- p = current_child;
- p->nextchild = q;
- d498 1
- a498 1
- fprintf(stderr,"ftree: child '%s' is not listed.\n", str);
- @
-
-
- 1.2
- log
- @added in comments etc.
- @
- text
- @d5 1
- a5 1
- * $Author$
- d7 1
- a7 1
- * $Date$
- d9 1
- a9 1
- * $Revision$
- d13 4
- a16 1
- * $Log$
- d51 1
- a51 2
- %token DIVORCED SEPERATED BAPTISED
-
- d209 8
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d1 17
- @
-