home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Aktief 1995 #3 / CDA3.iso / genealog / pafctool.zip / NOTEDUMP.C < prev    next >
C/C++ Source or Header  |  1992-05-08  |  9KB  |  333 lines

  1. /*
  2.  * Copyright (C) 1992, Stephen A. Wood.  All rights reserved.
  3.  * 
  4.  * This file is part of PAF C-Tools.
  5.  * 
  6.  * These programs are free software; you can redistribute them and/or modify
  7.  * them under the terms of the GNU General Public License as published by the
  8.  * Free Software Foundation; either version 2 of the License, or (at your
  9.  * option) any later version.
  10.  * 
  11.  * These programs are distributed in the hope that they will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13.  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14.  * for more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License along with
  17.  * this program; if not, write to the Free Software Foundation, Inc., 675
  18.  * Mass Ave, Cambridge, MA 02139, USA. The GNU General Public License can be
  19.  * found in the file LICENSE.
  20.  * 
  21.  * The author of PAF C-Tools is Stephen A. Wood.  He may be reached on internet
  22.  * at the address saw@cegaf.gov, or via mail at 328 Dominion Drive, Newport
  23.  * News, VA 23602.
  24.  * 
  25.  * ------------
  26.  * 
  27.  * Dump all the notes in a PAF database to standard output. The output may
  28.  * directed to a file, which can then be edited with any text editor.  The
  29.  * edited notes can then be used to update the PAF database with the program
  30.  * nupdate.
  31.  */
  32.  
  33. #include <stdio.h>
  34. /* #include <time.h> */
  35. #include "pafsubs.h"
  36.  
  37. #define NLINE_MLEN 79
  38. int dumpall_flag=FALSE;        /* Dump entries with no notes too */
  39. int appendpaf_flag=FALSE;    /* Appends PAF fields to end of notes */
  40. char *append_prefix="";        /* Put this string in front of appended info */
  41.  
  42. void printnotes(RECORD_PTR rin);
  43. char *convert_name(char *s, RECORD_PTR * ptrs);
  44. char *convert_place(char *s, RECORD_PTR *ptrs);
  45. char *convert_date(char *s, LONGDATE packed_date);
  46.  
  47. main(int argc, char *argv[])
  48. {
  49.   RECORD_PTR      rin;
  50.   RECORD_PTR      rin_max;
  51.   NAMADD_REC      namadd;
  52.   PAF_FILE       *indiv_file;
  53.   int             anum;
  54.   char *path="";            /* Path for files */
  55.   int bad_syntax=FALSE;
  56.   
  57.   while(argc-- > 1 && !bad_syntax){
  58.     argv++;
  59.     if(argv[0][0] != '-'){
  60.       path = *argv;
  61.     } else
  62.       switch(argv[0][1]){
  63.       case 'e': case 'E':
  64.     dumpall_flag = TRUE;
  65.     break;
  66.       case 'a': case 'A':
  67.     appendpaf_flag = TRUE;
  68.     dumpall_flag = TRUE;
  69.     if(argv[0][2] != '\0') append_prefix = argv[0]+2;
  70.     break;
  71.       case 0:
  72.       case 'h': case 'H':
  73.       default:
  74.     bad_syntax = TRUE;
  75.     break;
  76.       }
  77.   }
  78.   if(bad_syntax) {
  79.     fputs("usage: notedump [path] [-a[PREFIX]] [-e]\n",stderr);
  80.     fputs("  -a appends PAF info to end of each individuals notes\n",stderr);
  81.     fputs("    PREFIX is a optional string written in front appended info\n"
  82.       ,stderr);
  83.     fputs("  -e dumps every individual, even if no notes\n",stderr);
  84.     exit(1);
  85.   }
  86.  
  87.   paf_open_name('r');
  88.   paf_open_indiv('r');
  89.   paf_open_marr('r');
  90.   paf_open_notes('r');
  91.   paf_open_namadd('r');
  92.   
  93.   indiv_file = get_paf_filed(INDIV);
  94.   rin_max = indiv_file->nrec;
  95.   
  96.   get_namadd_rec((RECORD_PTR) 1, &namadd);
  97.   printf("%% %s\n", namadd.name);
  98.   printf("%% %s\n", namadd.addr1);
  99.   printf("%% %s\n", namadd.addr2);
  100.   printf("%% %s\n", namadd.addr3);
  101.   printf("%% %s\n", namadd.phone);
  102.   printf("%%\n");
  103.   
  104.   for (rin = 1; rin <= rin_max; rin++) {
  105.     printnotes(rin);
  106.   }
  107.   return (0);
  108. }
  109.  
  110. void 
  111.   printnotes(RECORD_PTR rin)
  112. {
  113.   INDIV_REC       indiv;
  114.   NOTE_REC        pad;
  115.   int             i;
  116.   char            s1[100],s2[100];
  117.   
  118.   get_indiv_rec(rin, &indiv);
  119.   
  120.   /* Only proceed if individual is not deleted and has a note. */
  121.   if (indiv.sex != 'D' && (indiv.notepad != 0 || dumpall_flag)) {
  122.     printf("%%%% [%d]", rin);
  123.     convert_name(s1, indiv.names);
  124.     printf(" %s ", s1);
  125.     printf(" %%%%");
  126.     /* First note will insert newline */
  127.     {
  128.       int             llen;
  129.       int             newline;
  130.       RECORD_PTR      npad;
  131.       llen = 0;
  132.       newline = 0;
  133.       npad = indiv.notepad;
  134.       while (npad != 0) {    /* Chain through notepads */
  135.     /* printf("[%d]",npad); */
  136.     get_note_rec(npad, &pad);
  137.     npad = pad.next_pad;
  138.     for (i = 0; i < 254; i++) {
  139.       if (pad.notelines[i] == 0)
  140.         if (llen == 0) {
  141.           llen = 1;
  142.         } else if (llen == 1) {
  143.           llen = 0;
  144.           break;    /* Zero length line terminates notes */
  145.         } else {
  146.           llen = 0;
  147.           putchar('\n');
  148.         }
  149.       else if (llen == 0 && pad.notelines[i] == 1) {
  150.         putchar('\n');    /* Start of new note */
  151.         newline = 1;
  152.         llen++;
  153.       } else {
  154.         putchar(pad.notelines[i]);
  155.         llen++;
  156.       }
  157.     }
  158.       }
  159.       if (!newline)
  160.     putchar('\n');    /* Just in case note was blank */
  161.     }
  162.     if (appendpaf_flag) {
  163.       RECORD_PTR next_marriage, srin;
  164.       MARR_REC marr;
  165.       INDIV_REC spouse;
  166.     
  167.       if(*append_prefix != '\0') printf("%s ",append_prefix);
  168.       printf("%s [%.10s]\n", s1,indiv.idnum);/* s is the name */
  169.  
  170.       convert_date(s1,indiv.birthdate);
  171.       convert_place(s2,indiv.birthplace);
  172.       if(s1[0] != 0 || s2[0] != 0) printf("Born: %s %s\n",s1,s2);
  173.  
  174.       convert_date(s1,indiv.christdate);
  175.       convert_place(s2,indiv.christplace);
  176.       if(s1[0] != 0 || s2[0] != 0) printf("Christened: %s %s\n",s1,s2);
  177.  
  178.       convert_date(s1,indiv.deathdate);
  179.       convert_place(s2,indiv.deathplace);
  180.       if(s1[0] != 0 || s2[0] != 0) printf("Died: %s %s\n",s1,s2);
  181.  
  182.       convert_date(s1,indiv.burialdate);
  183.       convert_place(s2,indiv.burialplace);
  184.       if(s1[0] != 0 || s2[0] != 0) printf("Burried: %s %s\n",s1,s2);
  185.  
  186.       next_marriage = indiv.ownmarriage;
  187.       if(next_marriage != 0) printf("Marriages:\n");
  188.       while(next_marriage != 0){
  189.     get_marr_rec(next_marriage,&marr);
  190.     if(indiv.sex == 'M'){
  191.       next_marriage = marr.mnext_husband;
  192.       srin = marr.wife;
  193.     } else {
  194.       next_marriage = marr.mnext_wife;
  195.       srin = marr.husband;
  196.     }
  197.     if(srin != 0) {
  198.       get_indiv_rec(srin,&spouse);
  199.       convert_name(s1, spouse.names);
  200.       printf(" %s [%.10s], ", s1,spouse.idnum);
  201.     } else {
  202.       printf(" Unknown, ");
  203.     }
  204.     convert_date(s1,marr.marriagedate);
  205.     convert_place(s2,marr.marriageplace);
  206.     printf("%s %s",s1,s2);
  207.     if(marr.divorce=='Y') {
  208.       printf(" Divorced\n");
  209.     }
  210.     printf("\n");
  211.       }
  212.     }
  213.     printf("%%%%--------------------------------------------------------------\n");
  214.   }
  215.   return;
  216. }
  217. char *convert_name(char *s, RECORD_PTR * ptrs)
  218. {
  219.   int             i;
  220.   NAME_REC        namrec;
  221.   s[0] = 0;
  222.   
  223. /*  {int flag;
  224.    flag = 0;
  225.    for(i=0; i<5; i++){
  226.      if(ptrs[i] > 864) flag = 1;
  227.    }
  228.    if(flag) printf("Bad nam ids: %d %d %d %d %d\n",ptrs[0],ptrs[1],ptrs[2],ptrs[3]
  229.       ,ptrs[4]);
  230.  }*/
  231.   for (i = 1; i < 4; i++) {    /* Print three given names */
  232.     if (ptrs[i] != 0) {
  233.       get_name_rec(ptrs[i], &namrec);
  234.       strcat(s, namrec.name);
  235.       strcat(s, " ");
  236.     }
  237.   }
  238.   if (ptrs[0] != 0) {        /* Print last name */
  239.     get_name_rec(ptrs[0], &namrec);
  240.     strcat(s, namrec.name);
  241.   } else {
  242.     strcat(s, "????");
  243.   }
  244.   if (ptrs[4] != 0) {        /* Print title */
  245.     get_name_rec(ptrs[4], &namrec);
  246.     strcat(s, ", ");
  247.     strcat(s, namrec.name);
  248.   }
  249.   return(s);
  250. }
  251. char *convert_place(char *s, RECORD_PTR *ptrs)
  252. {
  253.   int i;
  254.   NAME_REC namrec;
  255.   int empty;
  256.  
  257.   s[0] = 0;
  258.   empty = TRUE;
  259.   for(i=0; i<4; i++) {
  260.     if(ptrs[i] != 0) {
  261.       get_name_rec(ptrs[i], &namrec);
  262.       strcat(s, namrec.name);
  263.       empty = FALSE;
  264.     }
  265.     if(i<3) strcat(s,",");
  266.   }
  267.   i=strlen(s);
  268.   while(s[--i] == ',') s[i] = 0;
  269. /*  if(empty) s[0]=0;*/
  270.   return(s);
  271. }
  272.  
  273. char *monthnames[]={"NOMONTH","January","February","March","April",
  274.               "May","June","July","August","September",
  275.               "October","November","December","SEENOTES",
  276.               "SUBMITTED","CLEARED","UNCLEARED","COMPLETED",
  277.               "CANCELLED","STILLBORN","INFANT","DNS/CAN",
  278.               "DNS","BIC","CHILD"};
  279.  
  280. char *convert_date(char *s,LONGDATE packed_date)
  281. {
  282.   int year,month,day,dual;
  283.   int i;
  284.   
  285.   if(packed_date == 0){
  286.     s[0] = 0;
  287.   } else {
  288.     switch((packed_date & 0x30000)>>16)
  289.       {
  290.       case 0:
  291.     strcpy(s,"BEF ");
  292.     i = 4;
  293.     break;
  294.       ca