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