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