Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add comments
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:63c16ee7d06d883a9fca7d14373019099d99180b
User & Date: brandon 2016-04-06 21:24:41
Context
2016-04-06
21:37
bump version number, update NEWS, and update bootstrap Leaf check-in: 0d6fa61766 user: brandon tags: trunk, v1.2.4
21:24
add comments check-in: 63c16ee7d0 user: brandon tags: trunk
21:06
change the collapse_hyphens function to replace double-hyphen with en dash check-in: 9122a3a97a user: brandon tags: trunk
Changes

Changes to ChangeLog.















1
2
3
4
5
6
7














2014-06-10  Brandon Invergo  <brandon@invergo.net>

	* paperq.in (archive_queue): Declare n as local
	(list_docs): Declare numdocs as local
	(doc_info): Declare doc and key as local

2014-06-09  Brandon Invergo  <brandon@invergo.net>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2016-04-06  Brandon Invergo  <brandon@invergo.net>

	* src/paperbib.c (parse_entry): Use new double_hyphen_to_en_dash
	function.

	* paperq.in (parse_conf): Lots of fixes to bad quoting;
	coding-style updates; generally replace "echo" with "printf" where
	appropriate.  This resulted in some bugfixes, mainly due to
	quoting.

	* src/format_text.c (double_hyphen_to_en_dash): Change
	collapse_hyphens function to replace double-hyphen ('--') with an
	en dash (Unicode 0x2013)

2014-06-10  Brandon Invergo  <brandon@invergo.net>

	* paperq.in (archive_queue): Declare n as local
	(list_docs): Declare numdocs as local
	(doc_info): Declare doc and key as local

2014-06-09  Brandon Invergo  <brandon@invergo.net>

Changes to src/format_text.c.

22
23
24
25
26
27
28

29
30
31
32
33
34
35
..
48
49
50
51
52
53
54


55
56
57
58
59
60
61
..
71
72
73
74
75
76
77


78
79
80
81
82
83
84
..
87
88
89
90
91
92
93



94
95
96
97
98
99
100
...
114
115
116
117
118
119
120




121
122
123
124
125
126
127
...
166
167
168
169
170
171
172



173
174
175
176
177
178
179
...
228
229
230
231
232
233
234


235
236
237
238
239
240
241
#include "format_text.h"
#include "spec_chars.c"

 
int
append_text (uint8_t *buffer, uint8_t *text, int pos)
{

  size_t text_len;
  if (text == NULL)
    {
      return pos;
    }
  if (pos >= BUFSIZE)
    {
................................................................................
  return pos + text_len;
}

 
void
debrace (uint8_t *dest, uint8_t *source)
{


  uint8_t *ptr = u8_strpbrk (source, "{}");
  size_t len = u8_strlen (source);
  while (ptr != NULL)
    {
      if ((size_t)(ptr - source) < len)
        {
          u8_move (ptr, ptr + 1, (len - (ptr - source)) * sizeof (uint8_t));
................................................................................
  dest[len + 1] = '\0';
}

 
void
double_hyphen_to_en_dash (uint8_t *dest, uint8_t *source)
{


  uint8_t *ptr = u8_strstr (source, "--");
  size_t len = u8_strlen (source);
  size_t pos = 0;
  while (ptr != NULL)
    {
      replace_spec_char (ptr, 2, 0x2013, ptr-source, &len);
      ptr = u8_strstr (source, "--");
................................................................................
  dest[len + 1] = '\0';
}

void
replace_spec_char (uint8_t *ptr, int macro_len, ucs4_t new_char, size_t pos,
                   size_t *len)
{



  ucs4_t cur_char = NULL;
  uint8_t *move_to;
  const uint8_t *move_from;
  int i;

  /* The 2 probably shouldn't be hardcoded in the next line */
  if (u8_uctomb (ptr, new_char, 2) < 0)
................................................................................
  *len -= (macro_len + 1) - u8_strmblen (ptr);
}

 
void
special_chars (uint8_t *dest, uint8_t *source)
{




  uint8_t macro[4] = "";
  const uint8_t *next_ptr;
  ucs4_t last_char, cur_char;
  size_t len = u8_strlen (source);
  size_t pos = 0;
  uint8_t *ptr = u8_strchr (source, '\\');
  struct spec_char *schar;
................................................................................
  dest[len + 1] = '\0';
}

 
void
format_authors (char *author_text, uint8_t *author_buffer, int max_authors)
{



  bt_name_format *name_format;
  bt_stringlist *author_list;
  bt_name *name;
  char *author_str;
  char *author_str_form;
  uint8_t *u_author_str_form;
  int i;
................................................................................
  author_buffer[pos] = '\0';
}

 
void
wrap (uint8_t *buffer, uint8_t *text, uint8_t *indent, int column)
{


  uint8_t *ptr;
  int pos = 0;
  const char *locale_encoding = locale_charset ();
  size_t len = u8_strlen (text);
  size_t remain = len;
  size_t indent_len = u8_strlen (indent);
  int line_width = 0;







>







 







>
>







 







>
>







 







>
>
>







 







>
>
>
>







 







>
>
>







 







>
>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "format_text.h"
#include "spec_chars.c"

 
int
append_text (uint8_t *buffer, uint8_t *text, int pos)
{
  /* A helper function to safely append one string to another */
  size_t text_len;
  if (text == NULL)
    {
      return pos;
    }
  if (pos >= BUFSIZE)
    {
................................................................................
  return pos + text_len;
}

 
void
debrace (uint8_t *dest, uint8_t *source)
{
  /* Remove extraneous "quoting" braces found in your typical bibtex
     file */
  uint8_t *ptr = u8_strpbrk (source, "{}");
  size_t len = u8_strlen (source);
  while (ptr != NULL)
    {
      if ((size_t)(ptr - source) < len)
        {
          u8_move (ptr, ptr + 1, (len - (ptr - source)) * sizeof (uint8_t));
................................................................................
  dest[len + 1] = '\0';
}

 
void
double_hyphen_to_en_dash (uint8_t *dest, uint8_t *source)
{
  /* Replace all double-hyphens ("--") in a string to en dashes
     (unicode 0x2013) */
  uint8_t *ptr = u8_strstr (source, "--");
  size_t len = u8_strlen (source);
  size_t pos = 0;
  while (ptr != NULL)
    {
      replace_spec_char (ptr, 2, 0x2013, ptr-source, &len);
      ptr = u8_strstr (source, "--");
................................................................................
  dest[len + 1] = '\0';
}

void
replace_spec_char (uint8_t *ptr, int macro_len, ucs4_t new_char, size_t pos,
                   size_t *len)
{
  /* Replace a set of multiple characters with a single unicode
     character.  E.g. replace "--" with an en dash, or replace \'A
     with an accented 'a' */
  ucs4_t cur_char = NULL;
  uint8_t *move_to;
  const uint8_t *move_from;
  int i;

  /* The 2 probably shouldn't be hardcoded in the next line */
  if (u8_uctomb (ptr, new_char, 2) < 0)
................................................................................
  *len -= (macro_len + 1) - u8_strmblen (ptr);
}

 
void
special_chars (uint8_t *dest, uint8_t *source)
{
  /* Find all escaped special characters (accented characters and
     such) and replace them with their unicode equivalent.  This uses
     the special character definitions in the spec_chars.gperf file
     (which generates spec_chars.c). */
  uint8_t macro[4] = "";
  const uint8_t *next_ptr;
  ucs4_t last_char, cur_char;
  size_t len = u8_strlen (source);
  size_t pos = 0;
  uint8_t *ptr = u8_strchr (source, '\\');
  struct spec_char *schar;
................................................................................
  dest[len + 1] = '\0';
}

 
void
format_authors (char *author_text, uint8_t *author_buffer, int max_authors)
{
  /* Take a standard bibtex list of authors and format it nicely as a
     comma separated list.  Uses the btparse formatting functions for
     this purpose. */
  bt_name_format *name_format;
  bt_stringlist *author_list;
  bt_name *name;
  char *author_str;
  char *author_str_form;
  uint8_t *u_author_str_form;
  int i;
................................................................................
  author_buffer[pos] = '\0';
}

 
void
wrap (uint8_t *buffer, uint8_t *text, uint8_t *indent, int column)
{
  /* Wrap (fold) the given text to fit within a certain number of
     columns. */
  uint8_t *ptr;
  int pos = 0;
  const char *locale_encoding = locale_charset ();
  size_t len = u8_strlen (text);
  size_t remain = len;
  size_t indent_len = u8_strlen (indent);
  int line_width = 0;

Changes to src/paperbib.c.

100
101
102
103
104
105
106

107
108
109
110
111
112
113
...
119
120
121
122
123
124
125


126
127
128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150

151
152
153
154
155
156
157


158
159
160
161
162
163
164
165
166


167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197

198
199
200
201
202
203

204
205
206
207
208
209

210
211
212
213
214
215
216
...
218
219
220
221
222
223
224



225
226
227
228
229
230
231
  uint8_t *pages;
};

 
AST *
get_bibtex_entry (char *key, AST *bibtex_entry)
{

  AST *bibtex_tree;
  ushort btoptions = 0;
  boolean status;
  char *entry_key;
  bibtex_tree = bt_parse_file (NULL, btoptions, &status);
  if (status == FALSE)
    {
................................................................................
    {
      fprintf (stderr, "%s: BibTeX file empty\n; %s\n",
               PACKAGE_NAME, strerror (errno));
      return NULL;
    }
  while (bibtex_entry = bt_next_entry (bibtex_tree, bibtex_entry))
    {


      entry_key = bt_entry_key (bibtex_entry);
      if (!strcmp (key, entry_key))
        {
          break;
        }
    }
  return bibtex_entry;
}

 
struct document
parse_entry (AST *bibtex_entry, int max_authors)
{

  AST *field = NULL;
  char *field_name;
  char *value_text;
  uint8_t *u_value_text;
  uint8_t value_clean[BUFSIZE] = "";
  size_t value_len;
  char author_buffer[AUTHBUFSIZE];
  uint8_t *u_author_buffer;
  struct document doc;

  while (field = bt_next_field (bibtex_entry, field, &field_name))
    {

      value_text = bt_get_text (field);
      if (value_text == NULL)
        continue;
      u_value_text = u8_strconv_from_locale(value_text);
      value_len = u8_strlen (u_value_text);
      if (!u8_strcmp (field_name, "title"))
        {


          debrace (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.title = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.title, value_clean, value_len);
          doc.title[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "author"))
        {


          format_authors (value_text, author_buffer, max_authors);
          u_author_buffer = u8_strconv_from_locale (author_buffer);
          debrace (value_clean, u_author_buffer);
          special_chars (value_clean, u_author_buffer);
          value_len = u8_strlen (value_clean);
          doc.author = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.author, value_clean, value_len);
          doc.author[value_len] = '\0';
          value_clean[0] = '\0';
          free (u_author_buffer);
        }
      else if (!u8_strcmp (field_name, "journal"))
        {

          debrace (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.journal = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.journal, value_text, value_len);
          doc.journal[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "pages"))
        {

          double_hyphen_to_en_dash (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.pages = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.pages, value_text, value_len);
          doc.pages[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "volume"))
        {

          doc.volume = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.volume, value_text, value_len);
          doc.volume[value_len] = '\0';
        }
      else if (!u8_strcmp (field_name, "number"))
        {

          doc.number = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.number, value_text, value_len);
          doc.number[value_len] = '\0';
        }
      else if (!u8_strcmp (field_name, "year"))
        {

          doc.year = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.year, value_text, value_len);
          doc.year[value_len] = '\0';
        }
      free (value_text);
      free (u_value_text);
    }
................................................................................
  return doc;
}

 
int
format_entry (struct document doc, uint8_t *indent, int column)
{



  uint8_t buffer[BUFSIZE] = "";
  uint8_t final[BUFSIZE] = "";
  int pos = 0;
  uint8_t *tok;
  uint8_t *format;
  uint8_t *ptr;
  format = u8_strdup (BIB_FORMAT);







>







 







>
>













>












>







>
>









>
>













>









>









>






>






>







 







>
>
>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  uint8_t *pages;
};

 
AST *
get_bibtex_entry (char *key, AST *bibtex_entry)
{
  /* Locate a specific bibtex entry by key */
  AST *bibtex_tree;
  ushort btoptions = 0;
  boolean status;
  char *entry_key;
  bibtex_tree = bt_parse_file (NULL, btoptions, &status);
  if (status == FALSE)
    {
................................................................................
    {
      fprintf (stderr, "%s: BibTeX file empty\n; %s\n",
               PACKAGE_NAME, strerror (errno));
      return NULL;
    }
  while (bibtex_entry = bt_next_entry (bibtex_tree, bibtex_entry))
    {
      /* Visit each entry sequentially and check if it matches our
         desired key. */
      entry_key = bt_entry_key (bibtex_entry);
      if (!strcmp (key, entry_key))
        {
          break;
        }
    }
  return bibtex_entry;
}

 
struct document
parse_entry (AST *bibtex_entry, int max_authors)
{
  /* Parse a bibtex entry. */
  AST *field = NULL;
  char *field_name;
  char *value_text;
  uint8_t *u_value_text;
  uint8_t value_clean[BUFSIZE] = "";
  size_t value_len;
  char author_buffer[AUTHBUFSIZE];
  uint8_t *u_author_buffer;
  struct document doc;

  while (field = bt_next_field (bibtex_entry, field, &field_name))
    {
      /* Walk through each field in the entry */
      value_text = bt_get_text (field);
      if (value_text == NULL)
        continue;
      u_value_text = u8_strconv_from_locale(value_text);
      value_len = u8_strlen (u_value_text);
      if (!u8_strcmp (field_name, "title"))
        {
          /* Found a title.  Clean it up and copy it into or document
             struct */
          debrace (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.title = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.title, value_clean, value_len);
          doc.title[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "author"))
        {
          /* Found the authors.  Make the author list pretty and store
             that in the struct */
          format_authors (value_text, author_buffer, max_authors);
          u_author_buffer = u8_strconv_from_locale (author_buffer);
          debrace (value_clean, u_author_buffer);
          special_chars (value_clean, u_author_buffer);
          value_len = u8_strlen (value_clean);
          doc.author = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.author, value_clean, value_len);
          doc.author[value_len] = '\0';
          value_clean[0] = '\0';
          free (u_author_buffer);
        }
      else if (!u8_strcmp (field_name, "journal"))
        {
          /* Found the journal.  Clean it up... */
          debrace (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.journal = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.journal, value_text, value_len);
          doc.journal[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "pages"))
        {
          /* Found the page range.  Replace '--' with an en dash */
          double_hyphen_to_en_dash (value_clean, value_text);
          value_len = u8_strlen (value_clean);
          doc.pages = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.pages, value_text, value_len);
          doc.pages[value_len] = '\0';
          value_clean[0] = '\0';
        }
      else if (!u8_strcmp (field_name, "volume"))
        {
          /* Found the journal volume */
          doc.volume = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.volume, value_text, value_len);
          doc.volume[value_len] = '\0';
        }
      else if (!u8_strcmp (field_name, "number"))
        {
          /* Found the issue number */
          doc.number = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.number, value_text, value_len);
          doc.number[value_len] = '\0';
        }
      else if (!u8_strcmp (field_name, "year"))
        {
          /* Found the publication year */
          doc.year = (uint8_t *)malloc (value_len * sizeof (uint8_t) + 1);
          u8_strncpy (doc.year, value_text, value_len);
          doc.year[value_len] = '\0';
        }
      free (value_text);
      free (u_value_text);
    }
................................................................................
  return doc;
}

 
int
format_entry (struct document doc, uint8_t *indent, int column)
{
  /* Print the bibliographic information according to the format in
     BIB_FORMAT.  This consists of tags in braces (e.g. {author},
     {year}, etc.) */
  uint8_t buffer[BUFSIZE] = "";
  uint8_t final[BUFSIZE] = "";
  int pos = 0;
  uint8_t *tok;
  uint8_t *format;
  uint8_t *ptr;
  format = u8_strdup (BIB_FORMAT);