~ubuntu-branches/ubuntu/trusty/lifelines/trusty

« back to all changes in this revision

Viewing changes to src/gedlib/nodeio.c

  • Committer: Bazaar Package Importer
  • Author(s): Felipe Augusto van de Wiel (faw)
  • Date: 2007-08-14 00:02:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20070814000204-mpv5faygl0dgq3qi
Tags: 3.0.61-1
* New upstream release. (Closes: #387856).
* Fixing documentation build problems also fixes FTBFS if built twice in a
  row. (Closes: #424543).
* Adding lynx as a build dependency. This is necessary to generate txt files
  from html, discovered while fixing #424543.
* Upstream fix: charset for gedcom file in unicode. (Closes: #396206).
* Upstream fim: updating documentation about desc-tex2. (Closes: #405501).
* Bumping Standards-Version to 3.7.2 without package changes.
* Dropping local debian patches added upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        , STRING *ptag, STRING *pval, STRING *pmsg);
44
44
static NODE do_first_fp_to_node(FILE *fp, BOOLEAN list, XLAT tt
45
45
        , STRING *pmsg, BOOLEAN *peof);
 
46
static void prefix_file(FILE *fp, XLAT tt);
46
47
static BOOLEAN string_to_line(STRING *ps, INT *plev, STRING *pxref, 
47
48
        STRING *ptag, STRING *pval, STRING *pmsg);
48
49
static STRING swrite_node(INT levl, NODE node, STRING p);
49
50
static STRING swrite_nodes(INT levl, NODE node, STRING p);
50
 
static BOOLEAN write_bom(void);
51
 
static void write_fam_to_file(NODE fam, CNSTRING file, BOOLEAN bom);
52
 
static void write_indi_to_file(NODE indi, CNSTRING file, BOOLEAN bom);
 
51
static BOOLEAN should_write_bom(void);
 
52
static void write_fam_to_file(NODE fam, CNSTRING file);
 
53
static void write_indi_to_file(NODE indi, CNSTRING file);
53
54
static void write_node(INT levl, FILE *fp, XLAT ttm,
54
55
        NODE node, BOOLEAN indent);
55
56
 
553
554
                for (i = 1;  i < levl;  i++)
554
555
                        fprintf(fp, "  ");
555
556
        }
556
 
        fprintf(fp, "%d", levl);
 
557
        fprintf(fp, "%ld", levl);
557
558
        if (nxref(node)) fprintf(fp, " %s", nxref(node));
558
559
        fprintf(fp, " %s", ntag(node));
559
560
        if ((p = nval(node))) {
594
595
{
595
596
        char scratch[600];
596
597
        STRING q = scratch;
597
 
        sprintf(q, "%d ", levl);
 
598
        sprintf(q, "%ld ", levl);
598
599
        q += strlen(q);
599
600
        if (nxref(node)) {
600
601
                strcpy(q, nxref(node));
643
644
        return str;
644
645
}
645
646
/*=====================================
 
647
 * prefix_file_for_edit - write BOM prefix to file if appropriate
 
648
 *  This handles prepending BOM (byte order mark) to UTF-8 files
 
649
 *===================================*/
 
650
void
 
651
prefix_file_for_edit (FILE *fp)
 
652
{
 
653
        XLAT ttmo = transl_get_predefined_xlat(MINED);
 
654
        prefix_file(fp, ttmo);
 
655
}
 
656
/*=====================================
 
657
 * prefix_file_for_gedcom - write BOM prefix to file if appropriate
 
658
 *  This handles prepending BOM (byte order mark) to UTF-8 files
 
659
 *===================================*/
 
660
void
 
661
prefix_file_for_gedcom (FILE *fp)
 
662
{
 
663
        XLAT ttmo = transl_get_predefined_xlat(MINGD);
 
664
        prefix_file(fp, ttmo);
 
665
}
 
666
/*=====================================
 
667
 * prefix_file_for_report - write BOM prefix to file if appropriate
 
668
 *  This handles prepending BOM (byte order mark) to UTF-8 files
 
669
 *===================================*/
 
670
void
 
671
prefix_file_for_report (FILE *fp)
 
672
{
 
673
        XLAT ttmo = transl_get_predefined_xlat(MINRP);
 
674
        prefix_file(fp, ttmo);
 
675
}
 
676
 
 
677
/*=====================================
 
678
 * prefix_file - write BOM prefix to file if appropriate
 
679
 *  This handles prepending BOM (byte order mark) to UTF-8 files
 
680
 *===================================*/
 
681
static void
 
682
prefix_file (FILE *fp, XLAT tt)
 
683
{
 
684
        if (!should_write_bom())
 
685
                return;
 
686
        if (is_codeset_utf8(xl_get_dest_codeset(tt)))
 
687
        {
 
688
                /* 3-byte UTF-8 byte order mark */
 
689
                char bom[] = "\xEF\xBB\xBF";
 
690
                fwrite(bom, strlen(bom), 1, fp);
 
691
        }
 
692
}
 
693
/*=====================================
646
694
 * write_indi_to_file - write node tree into GEDCOM
647
695
 * (no user interaction)
648
696
 *===================================*/
649
697
void
650
 
write_indi_to_file (NODE indi, CNSTRING file, BOOLEAN bom)
 
698
write_indi_to_file (NODE indi, CNSTRING file)
651
699
{
652
700
        FILE *fp;
653
701
        XLAT ttmo = transl_get_predefined_xlat(MINED);
654
702
        NODE name, refn, sex, body, famc, fams;
655
703
        
656
704
        ASSERT(fp = fopen(file, LLWRITETEXT));
657
 
        if (bom && is_codeset_utf8(xl_get_dest_codeset(ttmo))) {
658
 
                char bom[] = "\xEF\xBB\xBF";
659
 
                fwrite(bom, strlen(bom), 1, fp);
660
 
        }
 
705
        prefix_file(fp, ttmo);
 
706
 
661
707
        split_indi_old(indi, &name, &refn, &sex, &body, &famc, &fams);
662
708
        write_nodes(0, fp, ttmo, indi, TRUE, TRUE, TRUE);
663
709
        write_nodes(1, fp, ttmo, name, TRUE, TRUE, TRUE);
674
720
 * (byte order marker)
675
721
 *===================================*/
676
722
static BOOLEAN
677
 
write_bom (void)
 
723
should_write_bom (void)
678
724
{
679
725
#ifdef WIN32
680
726
        return TRUE;
690
736
void
691
737
write_indi_to_file_for_edit (NODE indi, CNSTRING file, RFMT rfmt)
692
738
{
693
 
        BOOLEAN bom = write_bom();
694
739
        annotate_with_supplemental(indi, rfmt);
695
 
        write_indi_to_file(indi, file, bom);
 
740
        write_indi_to_file(indi, file);
696
741
        resolve_refn_links(indi);
697
742
}
698
743
/*=====================================
703
748
void
704
749
write_fam_to_file_for_edit (NODE fam, CNSTRING file, RFMT rfmt)
705
750
{
706
 
        BOOLEAN bom = write_bom();
707
751
        annotate_with_supplemental(fam, rfmt);
708
 
        write_fam_to_file(fam, file, bom);
 
752
        write_fam_to_file(fam, file);
709
753
        resolve_refn_links(fam);
710
754
}
711
755
/*=====================================
713
757
 * (no user interaction)
714
758
 *===================================*/
715
759
static void
716
 
write_fam_to_file (NODE fam, CNSTRING file, BOOLEAN bom)
 
760
write_fam_to_file (NODE fam, CNSTRING file)
717
761
{
718
762
        FILE *fp;
719
763
        XLAT ttmo = transl_get_predefined_xlat(MINED);
720
764
        NODE refn, husb, wife, chil, body;
721
 
        bom = bom; /* unused */
722
765
 
723
766
        ASSERT(fp = fopen(file, LLWRITETEXT));
 
767
        prefix_file(fp, ttmo);
 
768
 
724
769
        split_fam(fam, &refn, &husb, &wife, &chil, &body);
725
770
        write_nodes(0, fp, ttmo, fam,  TRUE, TRUE, TRUE);
726
771
        write_nodes(1, fp, ttmo, refn, TRUE, TRUE, TRUE);