ref.h revision 75584
175584Sru// -*- C++ -*-
275584Sru/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
375584Sru     Written by James Clark (jjc@jclark.com)
475584Sru
575584SruThis file is part of groff.
675584Sru
775584Srugroff is free software; you can redistribute it and/or modify it under
875584Sruthe terms of the GNU General Public License as published by the Free
975584SruSoftware Foundation; either version 2, or (at your option) any later
1075584Sruversion.
1175584Sru
1275584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
1375584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
1475584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1575584Srufor more details.
1675584Sru
1775584SruYou should have received a copy of the GNU General Public License along
1875584Sruwith groff; see the file COPYING.  If not, write to the Free Software
1975584SruFoundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2075584Sru
2175584Srustruct label_info;
2275584Sru
2375584Sruenum label_type { NORMAL_LABEL, SHORT_LABEL };
2475584Sruconst int N_LABEL_TYPES = 2;
2575584Sru
2675584Srustruct substring_position {
2775584Sru  int start;
2875584Sru  int length;
2975584Sru  substring_position() : start(-1) { }
3075584Sru};
3175584Sru
3275584Sruclass int_set {
3375584Sru  string v;
3475584Srupublic:
3575584Sru  int_set() { }
3675584Sru  void set(int i);
3775584Sru  int get(int i) const;
3875584Sru};
3975584Sru
4075584Sruclass reference {
4175584Sruprivate:
4275584Sru  unsigned h;
4375584Sru  reference_id rid;
4475584Sru  int merged;
4575584Sru  string sort_key;
4675584Sru  int no;
4775584Sru  string *field;
4875584Sru  int nfields;
4975584Sru  unsigned char field_index[256];
5075584Sru  enum { NULL_FIELD_INDEX = 255 };
5175584Sru  string label;
5275584Sru  substring_position separator_pos;
5375584Sru  string short_label;
5475584Sru  substring_position short_separator_pos;
5575584Sru  label_info *label_ptr;
5675584Sru  string authors;
5775584Sru  int computed_authors;
5875584Sru  int last_needed_author;
5975584Sru  int nauthors;
6075584Sru  int_set last_name_unambiguous;
6175584Sru
6275584Sru  int contains_field(char) const;
6375584Sru  void insert_field(unsigned char, string &s);
6475584Sru  void delete_field(unsigned char);
6575584Sru  void set_date(string &);
6675584Sru  const char *get_sort_field(int i, int si, int ssi, const char **endp) const;
6775584Sru  int merge_labels_by_parts(reference **, int, label_type, string &);
6875584Sru  int merge_labels_by_number(reference **, int, label_type, string &);
6975584Srupublic:
7075584Sru  reference(const char * = 0, int = -1, reference_id * = 0);
7175584Sru  ~reference();
7275584Sru  void output(FILE *);
7375584Sru  void print_sort_key_comment(FILE *);
7475584Sru  void set_number(int);
7575584Sru  int get_number() const { return no; }
7675584Sru  unsigned hash() const { return h; }
7775584Sru  const string &get_label(label_type type) const;
7875584Sru  const substring_position &get_separator_pos(label_type) const;
7975584Sru  int is_merged() const { return merged; }
8075584Sru  void compute_sort_key();
8175584Sru  void compute_hash_code();
8275584Sru  void pre_compute_label();
8375584Sru  void compute_label();
8475584Sru  void immediate_compute_label();
8575584Sru  int classify();
8675584Sru  void merge(reference &);
8775584Sru  int merge_labels(reference **, int, label_type, string &);
8875584Sru  int get_nauthors() const;
8975584Sru  void need_author(int);
9075584Sru  void set_last_name_unambiguous(int);
9175584Sru  void sortify_authors(int, string &) const;
9275584Sru  void canonicalize_authors(string &) const;
9375584Sru  void sortify_field(unsigned char, int, string &) const;
9475584Sru  const char *get_author(int, const char **) const;
9575584Sru  const char *get_author_last_name(int, const char **) const;
9675584Sru  const char *get_date(const char **) const;
9775584Sru  const char *get_year(const char **) const;
9875584Sru  const char *get_field(unsigned char, const char **) const;
9975584Sru  const label_info *get_label_ptr() const { return label_ptr; }
10075584Sru  const char *get_authors(const char **) const;
10175584Sru  // for sorting
10275584Sru  friend int compare_reference(const reference &r1, const reference &r2);
10375584Sru  // for merging
10475584Sru  friend int same_reference(const reference &, const reference &);
10575584Sru  friend int same_year(const reference &, const reference &);
10675584Sru  friend int same_date(const reference &, const reference &);
10775584Sru  friend int same_author_last_name(const reference &, const reference &, int);
10875584Sru  friend int same_author_name(const reference &, const reference &, int);
10975584Sru};
11075584Sru
11175584Sruconst char *find_year(const char *, const char *, const char **);
11275584Sruconst char *find_last_name(const char *, const char *, const char **);
11375584Sru
11475584Sruconst char *nth_field(int i, const char *start, const char **endp);
11575584Sru
11675584Sruvoid capitalize(const char *ptr, const char *end, string &result);
11775584Sruvoid reverse_name(const char *ptr, const char *end, string &result);
11875584Sruvoid uppercase(const char *ptr, const char *end, string &result);
11975584Sruvoid lowercase(const char *ptr, const char *end, string &result);
12075584Sruvoid abbreviate_name(const char *ptr, const char *end, string &result);
121