xref: /netbsd-src/external/gpl2/groff/dist/src/preproc/refer/ref.h (revision 89a07cf815a29524268025a1139fac4c5190f765)
1 /*	$NetBSD: ref.h,v 1.1.1.1 2016/01/13 18:41:49 christos Exp $	*/
2 
3 // -*- C++ -*-
4 /* Copyright (C) 1989, 1990, 1991, 1992, 2005 Free Software Foundation, Inc.
5      Written by James Clark (jjc@jclark.com)
6 
7 This file is part of groff.
8 
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13 
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING.  If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22 
23 // declarations to avoid friend name injection problems
24 int compare_reference(const reference &, const reference &);
25 int same_reference(const reference &, const reference &);
26 int same_year(const reference &, const reference &);
27 int same_date(const reference &, const reference &);
28 int same_author_last_name(const reference &, const reference &, int);
29 int same_author_name(const reference &, const reference &, int);
30 
31 struct label_info;
32 
33 enum label_type { NORMAL_LABEL, SHORT_LABEL };
34 const int N_LABEL_TYPES = 2;
35 
36 struct substring_position {
37   int start;
38   int length;
substring_positionsubstring_position39   substring_position() : start(-1) { }
40 };
41 
42 class int_set {
43   string v;
44 public:
int_set()45   int_set() { }
46   void set(int i);
47   int get(int i) const;
48 };
49 
50 class reference {
51 private:
52   unsigned h;
53   reference_id rid;
54   int merged;
55   string sort_key;
56   int no;
57   string *field;
58   int nfields;
59   unsigned char field_index[256];
60   enum { NULL_FIELD_INDEX = 255 };
61   string label;
62   substring_position separator_pos;
63   string short_label;
64   substring_position short_separator_pos;
65   label_info *label_ptr;
66   string authors;
67   int computed_authors;
68   int last_needed_author;
69   int nauthors;
70   int_set last_name_unambiguous;
71 
72   int contains_field(char) const;
73   void insert_field(unsigned char, string &s);
74   void delete_field(unsigned char);
75   void set_date(string &);
76   const char *get_sort_field(int i, int si, int ssi, const char **endp) const;
77   int merge_labels_by_parts(reference **, int, label_type, string &);
78   int merge_labels_by_number(reference **, int, label_type, string &);
79 public:
80   reference(const char * = 0, int = -1, reference_id * = 0);
81   ~reference();
82   void output(FILE *);
83   void print_sort_key_comment(FILE *);
84   void set_number(int);
get_number()85   int get_number() const { return no; }
hash()86   unsigned hash() const { return h; }
87   const string &get_label(label_type type) const;
88   const substring_position &get_separator_pos(label_type) const;
is_merged()89   int is_merged() const { return merged; }
90   void compute_sort_key();
91   void compute_hash_code();
92   void pre_compute_label();
93   void compute_label();
94   void immediate_compute_label();
95   int classify();
96   void merge(reference &);
97   int merge_labels(reference **, int, label_type, string &);
98   int get_nauthors() const;
99   void need_author(int);
100   void set_last_name_unambiguous(int);
101   void sortify_authors(int, string &) const;
102   void canonicalize_authors(string &) const;
103   void sortify_field(unsigned char, int, string &) const;
104   const char *get_author(int, const char **) const;
105   const char *get_author_last_name(int, const char **) const;
106   const char *get_date(const char **) const;
107   const char *get_year(const char **) const;
108   const char *get_field(unsigned char, const char **) const;
get_label_ptr()109   const label_info *get_label_ptr() const { return label_ptr; }
110   const char *get_authors(const char **) const;
111   // for sorting
112   friend int compare_reference(const reference &r1, const reference &r2);
113   // for merging
114   friend int same_reference(const reference &, const reference &);
115   friend int same_year(const reference &, const reference &);
116   friend int same_date(const reference &, const reference &);
117   friend int same_author_last_name(const reference &, const reference &, int);
118   friend int same_author_name(const reference &, const reference &, int);
119 };
120 
121 const char *find_year(const char *, const char *, const char **);
122 const char *find_last_name(const char *, const char *, const char **);
123 
124 const char *nth_field(int i, const char *start, const char **endp);
125 
126 void capitalize(const char *ptr, const char *end, string &result);
127 void reverse_name(const char *ptr, const char *end, string &result);
128 void uppercase(const char *ptr, const char *end, string &result);
129 void lowercase(const char *ptr, const char *end, string &result);
130 void abbreviate_name(const char *ptr, const char *end, string &result);
131