/contrib/groff/src/preproc/refer/ref.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 128 lines · 96 code · 10 blank · 22 comment · 0 complexity · c786ba6c0903c6849487408f66cf7143 MD5 · raw file

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