1/* $NetBSD$ */ 2 3// -*- C++ -*- 4/* Copyright (C) 1989, 1990, 1991, 1992, 2005 Free Software Foundation, Inc. 5 Written by James Clark (jjc@jclark.com) 6 7This file is part of groff. 8 9groff is free software; you can redistribute it and/or modify it under 10the terms of the GNU General Public License as published by the Free 11Software Foundation; either version 2, or (at your option) any later 12version. 13 14groff is distributed in the hope that it will be useful, but WITHOUT ANY 15WARRANTY; without even the implied warranty of MERCHANTABILITY or 16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17for more details. 18 19You should have received a copy of the GNU General Public License along 20with groff; see the file COPYING. If not, write to the Free Software 21Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23// declarations to avoid friend name injection problems 24int compare_reference(const reference &, const reference &); 25int same_reference(const reference &, const reference &); 26int same_year(const reference &, const reference &); 27int same_date(const reference &, const reference &); 28int same_author_last_name(const reference &, const reference &, int); 29int same_author_name(const reference &, const reference &, int); 30 31struct label_info; 32 33enum label_type { NORMAL_LABEL, SHORT_LABEL }; 34const int N_LABEL_TYPES = 2; 35 36struct substring_position { 37 int start; 38 int length; 39 substring_position() : start(-1) { } 40}; 41 42class int_set { 43 string v; 44public: 45 int_set() { } 46 void set(int i); 47 int get(int i) const; 48}; 49 50class reference { 51private: 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 &); 79public: 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); 85 int get_number() const { return no; } 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; 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; 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 121const char *find_year(const char *, const char *, const char **); 122const char *find_last_name(const char *, const char *, const char **); 123 124const char *nth_field(int i, const char *start, const char **endp); 125 126void capitalize(const char *ptr, const char *end, string &result); 127void reverse_name(const char *ptr, const char *end, string &result); 128void uppercase(const char *ptr, const char *end, string &result); 129void lowercase(const char *ptr, const char *end, string &result); 130void abbreviate_name(const char *ptr, const char *end, string &result); 131