| 1 |
/*- |
| 2 |
****************************************************************************** |
| 3 |
****************************************************************************** |
| 4 |
** |
| 5 |
** MODULE |
| 6 |
** |
| 7 |
** file: utils.c |
| 8 |
** |
| 9 |
** DESCRIPTION |
| 10 |
** |
| 11 |
** A 32-bit implementation of BibTeX v0.99c for MS-DOS, OS/2 2.x, |
| 12 |
** Unix and VMS. This C language implementation is based on the |
| 13 |
** original WEB source but it has been enhanced to support 8-bit input |
| 14 |
** characters and a very large processing capacity. |
| 15 |
** |
| 16 |
** For documentation describing how to use and build this program, |
| 17 |
** see the 00README.TXT file that accompanies this distribution. |
| 18 |
** |
| 19 |
** MODULE CONTENTS |
| 20 |
** |
| 21 |
** This module contains the new utility functions that will be used in |
| 22 |
** the program. The functions are declared in alphabetical order. |
| 23 |
** Functions defined in this module are: |
| 24 |
** |
| 25 |
** close_file |
| 26 |
** debug_msg |
| 27 |
** find_file |
| 28 |
** open_ip_file |
| 29 |
** open_op_file |
| 30 |
** mymalloc |
| 31 |
** myrealloc |
| 32 |
** parse_cmd_line |
| 33 |
** report_bibtex_capacity |
| 34 |
** report_search_paths |
| 35 |
** set_array_sizes |
| 36 |
** usage |
| 37 |
** |
| 38 |
** 8-bit support functions: |
| 39 |
** |
| 40 |
** c8read_csf |
| 41 |
** c8initialise |
| 42 |
** c8read_lowercase |
| 43 |
** c8read_lowupcase |
| 44 |
** c8read_uppercase |
| 45 |
** c8read_order |
| 46 |
** c8report_8bit_handling |
| 47 |
** |
| 48 |
** AUTHORS |
| 49 |
** |
| 50 |
** Original WEB translation to C, conversion to "big" (32-bit) capacity, |
| 51 |
** addition of run-time selectable capacity and 8-bit support extensions |
| 52 |
** by: |
| 53 |
** |
| 54 |
** Niel Kempson |
| 55 |
** Snowy Owl Systems Limited, Cheltenham, England |
| 56 |
** E-mail: [email protected] |
| 57 |
** |
| 58 |
** 8-bit support extensions also by: |
| 59 |
** |
| 60 |
** Alejandro Aguilar-Sierra |
| 61 |
** Centro de Ciencias de la Atm\'osfera, |
| 62 |
** Universidad Nacional Aut\'onoma de M\'exico, M\'exico |
| 63 |
** E-mail: [email protected] |
| 64 |
** |
| 65 |
** COPYRIGHT |
| 66 |
** |
| 67 |
** This implementation copyright (c) 1991-1995 by Niel Kempson |
| 68 |
** and copyright (c) 1995 by Alejandro Aguilar-Sierra. |
| 69 |
** |
| 70 |
** This program is free software; you can redistribute it and/or |
| 71 |
** modify it under the terms of the GNU General Public License as |
| 72 |
** published by the Free Software Foundation; either version 1, or |
| 73 |
** (at your option) any later version. |
| 74 |
** |
| 75 |
** This program is distributed in the hope that it will be useful, |
| 76 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 77 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 78 |
** General Public License for more details. |
| 79 |
** |
| 80 |
** You should have received a copy of the GNU General Public License |
| 81 |
** along with this program; if not, write to the Free Software |
| 82 |
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 83 |
** |
| 84 |
** In other words, you are welcome to use, share and improve this |
| 85 |
** program. You are forbidden to forbid anyone else to use, share |
| 86 |
** and improve what you give them. Help stamp out software-hoarding! |
| 87 |
** |
| 88 |
** ACKNOWLEDGEMENT |
| 89 |
** |
| 90 |
** The original BibTeX was written by Oren Patashnik using Donald |
| 91 |
** Knuth's WEB system. This format produces a PASCAL program for |
| 92 |
** execution and a TeX documented version of the source code. This |
| 93 |
** program started as a (manual) translation of the WEB source into C. |
| 94 |
** |
| 95 |
** CHANGE LOG |
| 96 |
** |
| 97 |
** $Log: utils.c,v $ |
| 98 |
** Revision 3.71 1996/08/18 20:37:06 kempson |
| 99 |
** Official release 3.71 (see HISTORY file for details). |
| 100 |
** |
| 101 |
** Revision 3.70 1996/04/08 10:08:40 kempson |
| 102 |
** Final documentation & cosmetic changes for official release 3.70. |
| 103 |
** |
| 104 |
** Revision 3.6 1995/10/21 22:20:42 kempson |
| 105 |
** Fixed numerous bugs, improved error reporting and added the --wolfgang |
| 106 |
** option. |
| 107 |
** |
| 108 |
** Revision 3.5 1995/09/24 20:44:37 kempson |
| 109 |
** Many changes for final beta test version. |
| 110 |
** |
| 111 |
** Revision 3.4 1995/04/09 22:15:43 kempson |
| 112 |
** Placed under RCS control |
| 113 |
** |
| 114 |
****************************************************************************** |
| 115 |
****************************************************************************** |
| 116 |
*/ |
| 117 |
|
| 118 |
#ifdef HAVE_CONFIG_H |
| 119 |
#include <config.h> |
| 120 |
#endif |
| 121 |
|
| 122 |
#include <stdarg.h> |
| 123 |
#ifdef WIN32 |
| 124 |
#if !defined(KPATHSEA) |
| 125 |
#include <getopt.h> |
| 126 |
#endif |
| 127 |
#else |
| 128 |
#include <unistd.h> |
| 129 |
#endif |
| 130 |
|
| 131 |
#ifdef KPATHSEA |
| 132 |
#include <kpathsea/config.h> |
| 133 |
#include <kpathsea/c-fopen.h> |
| 134 |
#include <kpathsea/tex-file.h> |
| 135 |
#include <kpathsea/paths.h> |
| 136 |
#include <kpathsea/variable.h> |
| 137 |
#include <kpathsea/lib.h> |
| 138 |
#include <kpathsea/getopt.h> |
| 139 |
#endif |
| 140 |
|
| 141 |
#include "sysdep.h" |
| 142 |
#include "bibtex.h" |
| 143 |
#include "datatype.h" |
| 144 |
#include "gblprocs.h" |
| 145 |
#include "gblvars.h" |
| 146 |
#include "utils.h" |
| 147 |
#include "version.h" |
| 148 |
|
| 149 |
#if defined(WIN32) && defined(KPATHSEA) |
| 150 |
#undef fopen |
| 151 |
#define fopen fsyscp_fopen |
| 152 |
#undef vfprintf |
| 153 |
#define vfprintf win32_vfprintf |
| 154 |
#endif |
| 155 |
|
| 156 |
/* |
| 157 |
** Useful macros to keep the code nicely formatted. |
| 158 |
*/ |
| 159 |
#define FSE(_a) fprintf (stderr, _a); |
| 160 |
#define FSO(_a) fprintf (TERM_OUT, _a); |
| 161 |
#define LOG_CAPACITY(_a) \ |
| 162 |
FPRINTF (log_file, " %-15s = %7ld\n", #_a, (long) _a) |
| 163 |
#define ISEMPTYSTR(_a) ((_a == NULL) || (*_a == '\0')) |
| 164 |
#define NULLCHECK(_a) (ISEMPTYSTR(_a) ? "<undefined>" : _a) |
| 165 |
|
| 166 |
|
| 167 |
/*- |
| 168 |
** Options supported by the program and parsed by getopt(). Each option |
| 169 |
** can be specified by a "traditional" single character argument |
| 170 |
** preceeded by a dash (e.g. "-7") or a more descriptive parameter |
| 171 |
** preceeded by two dashes (e.g. "--ascii"). Each option is also defined |
| 172 |
** as either not taking a value, optinally taking a value or requiring a |
| 173 |
** value. |
| 174 |
*/ |
| 175 |
#define VALUE_NONE 0 |
| 176 |
#define VALUE_REQD 1 |
| 177 |
#define VALUE_OPT 2 |
| 178 |
|
| 179 |
static struct option long_options[] = { |
| 180 |
#ifndef UTF_8 |
| 181 |
{"8bit", VALUE_NONE, 0, '8'}, |
| 182 |
{"csfile", VALUE_REQD, 0, 'c'}, |
| 183 |
#endif |
| 184 |
{"debug", VALUE_REQD, 0, 'd'}, |
| 185 |
{"help", VALUE_NONE, 0, '?'}, |
| 186 |
{"statistics", VALUE_NONE, 0, 's'}, |
| 187 |
{"trace", VALUE_NONE, 0, 't'}, |
| 188 |
#ifndef UTF_8 |
| 189 |
{"traditional", VALUE_NONE, 0, '7'}, |
| 190 |
#endif |
| 191 |
{"version", VALUE_NONE, 0, 'v'}, |
| 192 |
|
| 193 |
#ifdef UTF_8 |
| 194 |
{"language", VALUE_REQD, 0, 'l'}, |
| 195 |
{"location", VALUE_REQD, 0, 'o'}, |
| 196 |
#endif |
| 197 |
|
| 198 |
{"big", VALUE_NONE, 0, 'B'}, |
| 199 |
{"huge", VALUE_NONE, 0, 'H'}, |
| 200 |
{"wolfgang", VALUE_NONE, 0, 'W'}, |
| 201 |
{"min_crossrefs", VALUE_REQD, 0, 'M'}, |
| 202 |
|
| 203 |
{"mcites", VALUE_REQD, 0, '\x0A'}, /* obsolete */ |
| 204 |
{"mentints", VALUE_REQD, 0, '\x0B'}, /* obsolete */ |
| 205 |
{"mentstrs", VALUE_REQD, 0, '\x0C'}, /* obsolete */ |
| 206 |
{"mfields", VALUE_REQD, 0, '\x0D'}, /* obsolete */ |
| 207 |
{"mpool", VALUE_REQD, 0, '\x0E'}, /* obsolete */ |
| 208 |
{"mstrings", VALUE_REQD, 0, '\x0F'}, |
| 209 |
{"mwizfuns", VALUE_REQD, 0, '\x10'}, /* obsolete */ |
| 210 |
{0, 0, 0, 0} |
| 211 |
}; |
| 212 |
|
| 213 |
static const char *getopt_str = |
| 214 |
#ifndef UTF_8 |
| 215 |
"78c:" |
| 216 |
#endif |
| 217 |
"d:?stv" |
| 218 |
#ifdef UTF_8 |
| 219 |
"l:o:" |
| 220 |
#endif |
| 221 |
"BHM:W"; |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
/* |
| 226 |
** Forward declaration of private functions and variables used in this |
| 227 |
** module for 8-bit support. |
| 228 |
*/ |
| 229 |
#ifdef SUPPORT_8BIT |
| 230 |
static int c8read_csf (void); |
| 231 |
static void c8read_lowupcase (void); |
| 232 |
static void c8read_lowercase (void); |
| 233 |
static void c8read_order (void); |
| 234 |
static void c8read_uppercase (void); |
| 235 |
static void c8report_8bit_handling (void); |
| 236 |
|
| 237 |
static FILE *c8_cs_file; |
| 238 |
static int c8_line; |
| 239 |
static int sort_weight; |
| 240 |
#endif /* SUPPORT_8BIT */ |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
/*- |
| 245 |
**============================================================================ |
| 246 |
** allocate_arrays() |
| 247 |
** |
| 248 |
** Allocate memory dynamically for the large arrays whose size is fixed, |
| 249 |
** regardless of the amount memory of memory available. If these arrays are |
| 250 |
** declared statically, the linker will complain about an overflowing text |
| 251 |
** segment. |
| 252 |
** |
| 253 |
** Allocate memory dynamically for the large arrays whose size is set |
| 254 |
** dynamically, depending on the amount memory of memory available. |
| 255 |
** |
| 256 |
** AlphaFile_T bib_file[Max_Bib_Files + 1]; |
| 257 |
** StrNumber_T bib_list[Max_Bib_Files + 1]; |
| 258 |
** ASCIICode_T buffer[Buf_Size + 1]; |
| 259 |
** StrNumber_T cite_info[Max_Cites + 1]; |
| 260 |
** StrNumber_T cite_list[Max_Cites + 1]; |
| 261 |
** Boolean_T entry_exists[Max_Cites + 1]; |
| 262 |
** Integer_T entry_ints[Max_Ent_Ints + 1]; |
| 263 |
** ASCIICode_T entry_strs[Max_Ent_Strs + 1][Ent_Str_Size + 1]; |
| 264 |
** ASCIICode_T ex_buf[Buf_Size + 1]; |
| 265 |
** StrNumber_T field_info[Max_Fields + 1]; |
| 266 |
** FnClass_T fn_type[Hash_Size + 1]; |
| 267 |
** Integer_T glb_str_end[Max_Glob_Strs]; |
| 268 |
** StrNumber_T glb_str_ptr[Max_Glob_Strs]; |
| 269 |
** ASCIICode_T global_strs[Max_Glob_Strs][Glob_Str_Size + 1];; |
| 270 |
** StrIlk_T hash_ilk[Hash_Size + 1]; |
| 271 |
** HashPointer_T hash_next[Hash_Size + 1]; |
| 272 |
** StrNumber_T hash_text[Hash_Size + 1]; |
| 273 |
** Integer_T ilk_info[Hash_Size + 1]; |
| 274 |
** Integer_T lit_stack[Lit_Stk_Size + 1]; |
| 275 |
** StkType_T lit_stk_type[Lit_Stk_Size + 1]; |
| 276 |
** ASCIICode_T name_sep_char[Buf_Size + 1]; |
| 277 |
** BufPointer_T name_tok[Buf_Size + 1]; |
| 278 |
** ASCIICode_T out_buf[Buf_Size + 1]; |
| 279 |
** StrNumber_T s_preamble[Max_Bib_Files + 1]; |
| 280 |
** ASCIICode_T str_pool[Pool_Size + 1]; |
| 281 |
** PoolPointer_T str_start[Max_Strings + 1]; |
| 282 |
** ASCIICode_T sv_buffer[Buf_Size + 1]; |
| 283 |
** HashPtr2_T type_list[Max_Cites + 1]; |
| 284 |
** HashPtr2_T wiz_functions[Wiz_Fn_Space + 1]; |
| 285 |
**============================================================================ |
| 286 |
*/ |
| 287 |
static void allocate_arrays (void) |
| 288 |
{ |
| 289 |
unsigned long bytes_required; |
| 290 |
|
| 291 |
debug_msg (DBG_MEM, "Starting to allocate memory for arrays ... "); |
| 292 |
|
| 293 |
/* |
| 294 |
** AlphaFile_T bib_file[Max_Bib_Files + 1]; |
| 295 |
*/ |
| 296 |
bytes_required = (Max_Bib_Files + 1) * (unsigned long) sizeof (AlphaFile_T); |
| 297 |
bib_file = (AlphaFile_T *) mymalloc (bytes_required, "bib_file"); |
| 298 |
|
| 299 |
/* |
| 300 |
** StrNumber_T bib_list[Max_Bib_Files + 1]; |
| 301 |
*/ |
| 302 |
bytes_required = (Max_Bib_Files + 1) * (unsigned long) sizeof (StrNumber_T); |
| 303 |
bib_list = (StrNumber_T *) mymalloc (bytes_required, "bib_list"); |
| 304 |
|
| 305 |
/* |
| 306 |
** ASCIICode_T buffer[Buf_Size + 1]; |
| 307 |
*/ |
| 308 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 309 |
buffer = (ASCIICode_T *) mymalloc (bytes_required, "buffer"); |
| 310 |
|
| 311 |
/* |
| 312 |
** StrNumber_T cite_info[Max_Cites + 1]; |
| 313 |
*/ |
| 314 |
bytes_required = (Max_Cites + 1) * (unsigned long) sizeof (StrNumber_T); |
| 315 |
cite_info = (StrNumber_T *) mymalloc (bytes_required, "cite_info"); |
| 316 |
|
| 317 |
/* |
| 318 |
** StrNumber_T cite_list[Max_Cites + 1]; |
| 319 |
*/ |
| 320 |
bytes_required = (Max_Cites + 1) * (unsigned long) sizeof (StrNumber_T); |
| 321 |
cite_list = (StrNumber_T *) mymalloc (bytes_required, "cite_list"); |
| 322 |
|
| 323 |
/* |
| 324 |
** Boolean_T entry_exists[Max_Cites + 1]; |
| 325 |
*/ |
| 326 |
bytes_required = (Max_Cites + 1) * (unsigned long) sizeof (Boolean_T); |
| 327 |
entry_exists = (Boolean_T *) mymalloc (bytes_required, "entry_exists"); |
| 328 |
|
| 329 |
/* |
| 330 |
** Boolean_T entry_ints[Max_Ent_Ints + 1]; |
| 331 |
** allocated when num_ent_ints and num_cites are known |
| 332 |
*/ |
| 333 |
entry_ints = NULL; |
| 334 |
|
| 335 |
/* |
| 336 |
** ASCIICode_T entry_strs[Max_Ent_Strs + 1][Ent_Str_Size + 1]; |
| 337 |
** allocated when num_ent_strs and num_cites are known |
| 338 |
*/ |
| 339 |
entry_strs = NULL; |
| 340 |
|
| 341 |
/* |
| 342 |
** ASCIICode_T ex_buf[Buf_Size + 1]; |
| 343 |
*/ |
| 344 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 345 |
ex_buf = (ASCIICode_T *) mymalloc (bytes_required, "ex_buf"); |
| 346 |
|
| 347 |
/* |
| 348 |
** StrNumber_T field_info[Max_Fields + 1]; |
| 349 |
*/ |
| 350 |
bytes_required = (Max_Fields + 1) * (unsigned long) sizeof (StrNumber_T); |
| 351 |
field_info = (StrNumber_T *) mymalloc (bytes_required, "field_info"); |
| 352 |
|
| 353 |
/* |
| 354 |
** FnClass_T fn_type[Hash_Size + 1]; |
| 355 |
*/ |
| 356 |
bytes_required = (Hash_Size + 1) * (unsigned long) sizeof (FnClass_T); |
| 357 |
fn_type = (FnClass_T *) mymalloc (bytes_required, "fn_type"); |
| 358 |
|
| 359 |
/* |
| 360 |
** Integer_T glb_str_end[Max_Glob_Strs]; |
| 361 |
*/ |
| 362 |
bytes_required = Max_Glob_Strs * (unsigned long) sizeof (Integer_T); |
| 363 |
glb_str_end = (Integer_T *) mymalloc (bytes_required, "glb_str_end"); |
| 364 |
|
| 365 |
/* |
| 366 |
** StrNumber_T glb_str_ptr[Max_Glob_Strs]; |
| 367 |
*/ |
| 368 |
bytes_required = Max_Glob_Strs * (unsigned long) sizeof (StrNumber_T); |
| 369 |
glb_str_ptr = (StrNumber_T *) mymalloc (bytes_required, "glb_str_ptr"); |
| 370 |
|
| 371 |
/* |
| 372 |
** ASCIICode_T global_strs[Max_Glob_Strs][Glob_Str_Size + 1]; |
| 373 |
*/ |
| 374 |
bytes_required = (unsigned long) (Max_Glob_Strs) |
| 375 |
* (Glob_Str_Size + 1) |
| 376 |
* (unsigned long) sizeof (ASCIICode_T); |
| 377 |
global_strs = (ASCIICode_T *) mymalloc (bytes_required, "global_strs"); |
| 378 |
|
| 379 |
/* |
| 380 |
** StrIlk_T hash_ilk[Hash_Size + 1]; |
| 381 |
*/ |
| 382 |
bytes_required = (Hash_Size + 1) * (unsigned long) sizeof (StrIlk_T); |
| 383 |
hash_ilk = (StrIlk_T *) mymalloc (bytes_required, "hash_ilk"); |
| 384 |
|
| 385 |
/* |
| 386 |
** HashPointer_T hash_next[Hash_Size + 1]; |
| 387 |
*/ |
| 388 |
bytes_required = (Hash_Size + 1) * (unsigned long) sizeof (HashPointer_T); |
| 389 |
hash_next = (HashPointer_T *) mymalloc (bytes_required, "hash_next"); |
| 390 |
|
| 391 |
/* |
| 392 |
** StrNumber_T hash_text[Hash_Size + 1]; |
| 393 |
*/ |
| 394 |
bytes_required = (Hash_Size + 1) * (unsigned long) sizeof (StrNumber_T); |
| 395 |
hash_text = (StrNumber_T *) mymalloc (bytes_required, "hash_text"); |
| 396 |
|
| 397 |
/* |
| 398 |
** Integer_T ilk_info[Hash_Size + 1]; |
| 399 |
*/ |
| 400 |
bytes_required = (Hash_Size + 1) * (unsigned long) sizeof (Integer_T); |
| 401 |
ilk_info = (Integer_T *) mymalloc (bytes_required, "ilk_info"); |
| 402 |
|
| 403 |
/* |
| 404 |
** Integer_T lit_stack[Lit_Stk_Size + 1]; |
| 405 |
*/ |
| 406 |
bytes_required = (Lit_Stk_Size + 1) * (unsigned long) sizeof (Integer_T); |
| 407 |
lit_stack = (Integer_T *) mymalloc (bytes_required, "lit_stack"); |
| 408 |
|
| 409 |
/* |
| 410 |
** StkType_T lit_stk_type[Lit_Stk_Size + 1]; |
| 411 |
*/ |
| 412 |
bytes_required = (Lit_Stk_Size + 1) * (unsigned long) sizeof (StkType_T); |
| 413 |
lit_stk_type = (StkType_T *) mymalloc (bytes_required, "lit_stk_type"); |
| 414 |
|
| 415 |
/* |
| 416 |
** ASCIICode_T name_sep_char[Buf_Size + 1]; |
| 417 |
*/ |
| 418 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 419 |
name_sep_char = (ASCIICode_T *) mymalloc (bytes_required, "name_sep_char"); |
| 420 |
|
| 421 |
/* |
| 422 |
** BufPointer_T name_tok[Buf_Size + 1]; |
| 423 |
*/ |
| 424 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (BufPointer_T); |
| 425 |
name_tok = (BufPointer_T *) mymalloc (bytes_required, "name_tok"); |
| 426 |
|
| 427 |
/* |
| 428 |
** ASCIICode_T out_buf[Buf_Size + 1]; |
| 429 |
*/ |
| 430 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 431 |
out_buf = (ASCIICode_T *) mymalloc (bytes_required, "out_buf"); |
| 432 |
|
| 433 |
/* |
| 434 |
** StrNumber_T s_preamble[Max_Bib_Files + 1]; |
| 435 |
*/ |
| 436 |
bytes_required = (Max_Bib_Files + 1) * (unsigned long) sizeof (StrNumber_T); |
| 437 |
s_preamble = (StrNumber_T *) mymalloc (bytes_required, "s_preamble"); |
| 438 |
|
| 439 |
/* |
| 440 |
** ASCIICode_T str_pool[Pool_Size + 1]; |
| 441 |
*/ |
| 442 |
bytes_required = (Pool_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 443 |
str_pool = (ASCIICode_T *) mymalloc (bytes_required, "str_pool"); |
| 444 |
|
| 445 |
/* |
| 446 |
** PoolPointer_T str_start[Max_Strings + 1]; |
| 447 |
*/ |
| 448 |
bytes_required = (Max_Strings + 1) * (unsigned long) sizeof (PoolPointer_T); |
| 449 |
str_start = (PoolPointer_T *) mymalloc (bytes_required, "str_start"); |
| 450 |
|
| 451 |
/* |
| 452 |
** ASCIICode_T sv_buffer[Buf_Size + 1]; |
| 453 |
*/ |
| 454 |
bytes_required = (Buf_Size + 1) * (unsigned long) sizeof (ASCIICode_T); |
| 455 |
sv_buffer = (ASCIICode_T *) mymalloc (bytes_required, "sv_buffer"); |
| 456 |
|
| 457 |
/* |
| 458 |
** HashPtr2_T type_list[Max_Cites + 1]; |
| 459 |
*/ |
| 460 |
bytes_required = (Max_Cites + 1) * (unsigned long) sizeof (HashPtr2_T); |
| 461 |
type_list = (HashPtr2_T *) mymalloc (bytes_required, "type_list"); |
| 462 |
|
| 463 |
/* |
| 464 |
** HashPtr2_T wiz_functions[Wiz_Fn_Space + 1]; |
| 465 |
*/ |
| 466 |
bytes_required = (Wiz_Fn_Space + 1) * (unsigned long) sizeof (HashPtr2_T); |
| 467 |
wiz_functions = (HashPtr2_T *) mymalloc (bytes_required, "wiz_functions"); |
| 468 |
|
| 469 |
} /* allocate_arrays () */ |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
/*- |
| 474 |
**============================================================================ |
| 475 |
** checkdbg() |
| 476 |
** |
| 477 |
** Examine a string representing different debug options, usually provided |
| 478 |
** as a value to a command line option, and return the value as a long |
| 479 |
** integer. Return 0 (no debugging) if a valid option was not parsed. |
| 480 |
**============================================================================ |
| 481 |
*/ |
| 482 |
static int checkdbg (char *str) |
| 483 |
{ |
| 484 |
int dbgval = 0; |
| 485 |
|
| 486 |
if ((str == NULL) || (*str == '\0')) |
| 487 |
return (0); |
| 488 |
|
| 489 |
if (strstr (str, "all") != NULL) |
| 490 |
dbgval |= DBG_ALL; |
| 491 |
if (strstr (str, "csf") != NULL) |
| 492 |
dbgval |= DBG_CSF; |
| 493 |
if (strstr (str, "io") != NULL) |
| 494 |
dbgval |= DBG_IO; |
| 495 |
if (strstr (str, "mem") != NULL) |
| 496 |
dbgval |= DBG_MEM; |
| 497 |
if (strstr (str, "misc") != NULL) |
| 498 |
dbgval |= DBG_MISC; |
| 499 |
if (strstr (str, "search") != NULL) |
| 500 |
dbgval |= DBG_SRCH; |
| 501 |
|
| 502 |
return (dbgval); |
| 503 |
} /* checkdbg() */ |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
/*- |
| 508 |
**============================================================================ |
| 509 |
** checklong() |
| 510 |
** |
| 511 |
** Examine a string representing an integer, usually provided as a value to |
| 512 |
** a command line option, and return the value as a long integer. |
| 513 |
** Return -1 if a valid integer was not parsed. |
| 514 |
**============================================================================ |
| 515 |
*/ |
| 516 |
static long checklong (char *str) |
| 517 |
{ |
| 518 |
long value; |
| 519 |
char *endptr; |
| 520 |
int len; |
| 521 |
|
| 522 |
len = strlen (str); |
| 523 |
value = strtol (str, &endptr, 10); |
| 524 |
|
| 525 |
if (str == endptr) |
| 526 |
return (-1); |
| 527 |
if ((endptr - str) < len) |
| 528 |
return (-1); |
| 529 |
|
| 530 |
return (value); |
| 531 |
} /* checklong() */ |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
/*- |
| 536 |
**============================================================================ |
| 537 |
** close_file() |
| 538 |
** |
| 539 |
** Close a file - as long as it's open. |
| 540 |
**============================================================================ |
| 541 |
*/ |
| 542 |
void close_file (const AlphaFile_T file_pointer) |
| 543 |
{ |
| 544 |
if (file_pointer != NULL) |
| 545 |
fclose (file_pointer); |
| 546 |
} /* close_file() */ |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
/*- |
| 551 |
**============================================================================ |
| 552 |
** debug_msg() |
| 553 |
** |
| 554 |
** Write a debugging message to the stderr stream, but only if the |
| 555 |
** appropriate debugging option has been selected. |
| 556 |
**============================================================================ |
| 557 |
*/ |
| 558 |
void debug_msg (const int status, const char *printf_fmt, ...) |
| 559 |
{ |
| 560 |
va_list printf_args; |
| 561 |
const char *prefix; |
| 562 |
|
| 563 |
switch (status) { |
| 564 |
case DBG_CSF: |
| 565 |
if ((Flag_debug & DBG_CSF) == 0) return; |
| 566 |
prefix = "D-CSF"; |
| 567 |
break; |
| 568 |
case DBG_IO: |
| 569 |
if ((Flag_debug & DBG_IO) == 0) return; |
| 570 |
prefix = "D-I/O"; |
| 571 |
break; |
| 572 |
case DBG_MEM: |
| 573 |
if ((Flag_debug & DBG_MEM) == 0) return; |
| 574 |
prefix = "D-MEM"; |
| 575 |
break; |
| 576 |
case DBG_MISC: |
| 577 |
if ((Flag_debug & DBG_MISC) == 0) return; |
| 578 |
prefix = "D-MSC"; |
| 579 |
break; |
| 580 |
case DBG_SRCH: |
| 581 |
if ((Flag_debug & DBG_SRCH) == 0) return; |
| 582 |
prefix = "D-SCH"; |
| 583 |
break; |
| 584 |
default: |
| 585 |
return; |
| 586 |
} |
| 587 |
|
| 588 |
if (printf_fmt != NULL) { |
| 589 |
fprintf (stderr, "%s: ", prefix); |
| 590 |
va_start (printf_args, printf_fmt); |
| 591 |
vfprintf (stderr, printf_fmt, printf_args); |
| 592 |
va_end (printf_args); |
| 593 |
fprintf (stderr, "\n"); |
| 594 |
fflush (stderr); |
| 595 |
} |
| 596 |
} /* debug_msg () */ |
| 597 |
|
| 598 |
|
| 599 |
#ifndef KPATHSEA |
| 600 |
/*- |
| 601 |
**============================================================================ |
| 602 |
** find_file() |
| 603 |
** |
| 604 |
** Search along a path for a file. The search path is specified by the |
| 605 |
** value of an environment variable which can contain multiple directories, |
| 606 |
** separated by an appropriate delimiter. The best known example is the |
| 607 |
** PATH environment variable found on DOS, OS/2 and Unix. |
| 608 |
** |
| 609 |
** If the environment variable is not specified, or it has not been set, |
| 610 |
** a 'fallback' path will be used. The current working directory will be |
| 611 |
** searched first, then directories along the search path define dby the |
| 612 |
** environment variable or fallback path. |
| 613 |
** |
| 614 |
** If the file is found along the search path, a value of 0 is returned and |
| 615 |
** the full file specification is stored in parameter full_file_spec. If |
| 616 |
** the file was not found, -1 is returned. |
| 617 |
**============================================================================ |
| 618 |
*/ |
| 619 |
int find_file (const char *envvar_name, const char *fallback_path, |
| 620 |
const char *filename, char *full_file_spec) |
| 621 |
{ |
| 622 |
char c; |
| 623 |
int len = 0; |
| 624 |
char *search_path; |
| 625 |
|
| 626 |
debug_msg (DBG_SRCH, "find_file: searching for file name `%s'", |
| 627 |
filename); |
| 628 |
debug_msg (DBG_SRCH, |
| 629 |
"find_file: environment variable for search path = `%s'", |
| 630 |
(envvar_name == NULL) ? "NULL" : envvar_name); |
| 631 |
debug_msg (DBG_SRCH, "find_file: fallback path = `%s'", |
| 632 |
(fallback_path == NULL) ? "NULL" : fallback_path); |
| 633 |
|
| 634 |
if ((envvar_name == NULL) || (*envvar_name == '\0')) { |
| 635 |
search_path = NULL; |
| 636 |
debug_msg (DBG_SRCH, |
| 637 |
"find_file: no environment variable specified"); |
| 638 |
} else { |
| 639 |
search_path = getenv (envvar_name); |
| 640 |
debug_msg (DBG_SRCH, "find_file: %s = `%s'", envvar_name, |
| 641 |
(search_path == NULL) ? "NULL" : search_path); |
| 642 |
} |
| 643 |
|
| 644 |
/* |
| 645 |
** If we have a NULL search path because an environment variable name was |
| 646 |
** not specified or specified but not defined, we use the fallback |
| 647 |
** search path. |
| 648 |
*/ |
| 649 |
if (search_path == NULL) { |
| 650 |
debug_msg (DBG_SRCH, "find_file: using fallback search path `%s'", |
| 651 |
(fallback_path == NULL) ? "NULL" : fallback_path); |
| 652 |
search_path = (char *) fallback_path; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
/* |
| 657 |
** Work along the search path looking for the wanted file. Stop when |
| 658 |
** the first match is found. |
| 659 |
*/ |
| 660 |
while (1) { |
| 661 |
full_file_spec[len] = '\0'; |
| 662 |
|
| 663 |
/* |
| 664 |
** If the path is not empty, and it doesn't end in '/' or '\', |
| 665 |
** append a trailing '/'. |
| 666 |
*/ |
| 667 |
if (len != 0) { |
| 668 |
c = full_file_spec[len - 1]; |
| 669 |
if ((c != '/') && (c != '\\')) |
| 670 |
strcat (full_file_spec, "/"); |
| 671 |
} |
| 672 |
|
| 673 |
/* |
| 674 |
** Append the filename to the path and then test whether the |
| 675 |
** file exists. If not, return -1 and an empty string. |
| 676 |
*/ |
| 677 |
strcat (full_file_spec, filename); |
| 678 |
debug_msg (DBG_SRCH, "find_file: trying `%s'", full_file_spec); |
| 679 |
|
| 680 |
if (access (full_file_spec, 0) == 0) |
| 681 |
break; |
| 682 |
|
| 683 |
if ((search_path == NULL) || (*search_path == '\0')) { |
| 684 |
full_file_spec[0] = '\0'; |
| 685 |
return (-1); |
| 686 |
} |
| 687 |
|
| 688 |
len = 0; |
| 689 |
|
| 690 |
for (;;) { |
| 691 |
if ((*search_path != PATH_DELIM) && (*search_path != '\0')) { |
| 692 |
if (*search_path == '\\') |
| 693 |
full_file_spec[len] = '/'; |
| 694 |
else |
| 695 |
full_file_spec[len] = *search_path; |
| 696 |
|
| 697 |
++len; |
| 698 |
++search_path; |
| 699 |
} else |
| 700 |
break; |
| 701 |
} /* end for (;;) */ |
| 702 |
|
| 703 |
if (*search_path != '\0') |
| 704 |
++search_path; |
| 705 |
} /* end while (1) */ |
| 706 |
|
| 707 |
debug_msg (DBG_SRCH, "find_file: returning `%s'", full_file_spec); |
| 708 |
return (0); |
| 709 |
} /* find_file() */ |
| 710 |
#endif /* ! KPATHSEA */ |
| 711 |
|
| 712 |
|
| 713 |
/*- |
| 714 |
**============================================================================ |
| 715 |
** mymalloc() |
| 716 |
** |
| 717 |
** Allocate memory for a specified array and check whether the allocation |
| 718 |
** was successful. If not, issue an error message and cause the program |
| 719 |
** to stop with a fatal exit status. |
| 720 |
** Allocate at least 1 byte, otherwise malloc may return NULL. |
| 721 |
**============================================================================ |
| 722 |
*/ |
| 723 |
void *mymalloc (const unsigned long bytes_required, const char *array_name) |
| 724 |
{ |
| 725 |
void *ptr; |
| 726 |
|
| 727 |
ptr = malloc (bytes_required ? bytes_required : 1); |
| 728 |
|
| 729 |
if (ptr == NULL) { |
| 730 |
printf ("\nFatal error: couldn't allocate %lu bytes for array `%s'", |
| 731 |
bytes_required, array_name); |
| 732 |
mark_fatal (); |
| 733 |
debug_msg (DBG_MISC, "calling longjmp (Exit_Program_Flag) ... "); |
| 734 |
longjmp (Exit_Program_Flag, 1); |
| 735 |
} else { |
| 736 |
debug_msg (DBG_MEM, "allocated %7lu bytes for array `%s'", |
| 737 |
bytes_required, array_name); |
| 738 |
} |
| 739 |
|
| 740 |
return (ptr); |
| 741 |
} /* mymalloc () */ |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
/*- |
| 746 |
**============================================================================ |
| 747 |
** myrealloc() |
| 748 |
** |
| 749 |
** Reallocate memory for a specified array and check whether the allocation |
| 750 |
** was successful. If not, issue an error message and cause the program |
| 751 |
** to stop with a fatal exit status. |
| 752 |
** Allocate at least 1 byte, otherwise realloc may return NULL. |
| 753 |
**============================================================================ |
| 754 |
*/ |
| 755 |
void *myrealloc (void *old_ptr, const unsigned long bytes_required, const char *array_name) |
| 756 |
{ |
| 757 |
void *ptr; |
| 758 |
|
| 759 |
if (old_ptr == NULL) |
| 760 |
return mymalloc (bytes_required, array_name); |
| 761 |
|
| 762 |
ptr = realloc (old_ptr, bytes_required ? bytes_required : 1); |
| 763 |
|
| 764 |
if (ptr == NULL) { |
| 765 |
printf ("\nFatal error: couldn't reallocate %lu bytes for array `%s'", |
| 766 |
bytes_required, array_name); |
| 767 |
mark_fatal (); |
| 768 |
debug_msg (DBG_MISC, "calling longjmp (Exit_Program_Flag) ... "); |
| 769 |
longjmp (Exit_Program_Flag, 1); |
| 770 |
} else { |
| 771 |
debug_msg (DBG_MEM, "reallocated %7lu bytes for array `%s'", |
| 772 |
bytes_required, array_name); |
| 773 |
} |
| 774 |
|
| 775 |
return (ptr); |
| 776 |
} /* myrealloc () */ |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
/*- |
| 781 |
**============================================================================ |
| 782 |
** open_ip_file() |
| 783 |
** |
| 784 |
** Open a file for input after locating it using one of the five predefined |
| 785 |
** search strategies defined by the parameter "search_path". This parameter |
| 786 |
** can take 5 values: |
| 787 |
** |
| 788 |
** AUX_FILE - used for locating .aux files. Search for the file along the |
| 789 |
** path defined by the environment variable AUX_INPUT_ENVVAR or |
| 790 |
** if it is not defined, use the fallback path defined by |
| 791 |
** AUX_INPUT_PATH. |
| 792 |
** |
| 793 |
** BIB_FILE - used for locating .bib files. Search for the file along the |
| 794 |
** path defined by the environment variable BIB_INPUT_ENVVAR or |
| 795 |
** if it is not defined, use the fallback path defined by |
| 796 |
** BIB_INPUT_PATH. |
| 797 |
** |
| 798 |
** BST_FILE - used for locating .bst files. Search for the file along the |
| 799 |
** path defined by the environment variable BST_INPUT_ENVVAR or |
| 800 |
** if it is not defined, use the fallback path defined by |
| 801 |
** BST_INPUT_PATH. |
| 802 |
** |
| 803 |
** CSF_FILE - used for locating .csf files. Search for the file along the |
| 804 |
** path defined by the environment variable CSF_INPUT_ENVVAR or |
| 805 |
** if it is not defined, use the fallback path defined by |
| 806 |
** CSF_INPUT_PATH. |
| 807 |
** |
| 808 |
** NO_SEARCH_PATH - only look for the file in the current directory. |
| 809 |
** |
| 810 |
** Searching for the file is delegated to the function find_file(), and |
| 811 |
** only if it was successful, does this function attempt to open the file. |
| 812 |
**============================================================================ |
| 813 |
*/ |
| 814 |
FILE *open_ip_file (Integer_T search_path) |
| 815 |
{ |
| 816 |
const char *filename = (const char *) name_of_file; |
| 817 |
#ifdef KPATHSEA |
| 818 |
string full_filespec; |
| 819 |
#else |
| 820 |
char full_filespec[FILE_NAME_SIZE + 1]; |
| 821 |
#endif |
| 822 |
FILE *fptr; |
| 823 |
int status; |
| 824 |
|
| 825 |
switch (search_path) { |
| 826 |
case AUX_FILE_SEARCH_PATH: |
| 827 |
#ifdef KPATHSEA |
| 828 |
status = ((full_filespec = kpse_find_file(filename, kpse_tex_format, false)) == NULL); |
| 829 |
#else |
| 830 |
status = find_file (AUX_INPUT_ENVVAR, AUX_INPUT_PATH, |
| 831 |
filename, full_filespec); |
| 832 |
#endif |
| 833 |
break; |
| 834 |
case BIB_FILE_SEARCH_PATH: |
| 835 |
#ifdef KPATHSEA |
| 836 |
status = ((full_filespec = kpse_find_file(filename, kpse_bib_format, false)) == NULL); |
| 837 |
#else |
| 838 |
status = find_file (BIB_INPUT_ENVVAR, BIB_INPUT_PATH, |
| 839 |
filename, full_filespec); |
| 840 |
#endif |
| 841 |
break; |
| 842 |
case BST_FILE_SEARCH_PATH: |
| 843 |
#ifdef KPATHSEA |
| 844 |
status = ((full_filespec = kpse_find_file(filename, kpse_bst_format, false)) == NULL); |
| 845 |
#else |
| 846 |
status = find_file (BST_INPUT_ENVVAR, BST_INPUT_PATH, |
| 847 |
filename, full_filespec); |
| 848 |
#endif |
| 849 |
break; |
| 850 |
case CSF_FILE_SEARCH_PATH: |
| 851 |
#ifdef KPATHSEA |
| 852 |
status = ((full_filespec = kpse_find_file(filename, kpse_bst_format, false)) == NULL); |
| 853 |
#else |
| 854 |
status = find_file (CSF_INPUT_ENVVAR, CSF_INPUT_PATH, |
| 855 |
filename, full_filespec); |
| 856 |
#endif |
| 857 |
break; |
| 858 |
case NO_SEARCH_PATH: |
| 859 |
default: |
| 860 |
#ifdef KPATHSEA |
| 861 |
status = ((full_filespec = kpse_find_file(filename, kpse_program_text_format, false)) == NULL); |
| 862 |
#else |
| 863 |
status = find_file (NULL, NULL, filename, full_filespec); |
| 864 |
#endif |
| 865 |
break; |
| 866 |
} /* end switch (search_path) */ |
| 867 |
|
| 868 |
/* |
| 869 |
** find_file() will return zero if the file was found somewhere |
| 870 |
** along the search path. If it does, try to open the file. |
| 871 |
*/ |
| 872 |
if (status == 0) { |
| 873 |
debug_msg (DBG_IO, "open_ip_file: trying to open `%s' ... ", |
| 874 |
full_filespec); |
| 875 |
#ifdef KPATHSEA |
| 876 |
if (!kpse_in_name_ok(full_filespec)) |
| 877 |
goto not_ok; |
| 878 |
fptr = fopen (full_filespec, FOPEN_R_MODE); |
| 879 |
free (full_filespec); |
| 880 |
#else |
| 881 |
# if defined(MSDOS) || defined(OS2) |
| 882 |
fptr = fopen (full_filespec, "rt"); |
| 883 |
# endif |
| 884 |
|
| 885 |
# if defined(UNIX) || defined(VMS) |
| 886 |
fptr = fopen (full_filespec, "r"); |
| 887 |
#endif |
| 888 |
#endif /* ! KPATHSEA */ |
| 889 |
} |
| 890 |
|
| 891 |
/* |
| 892 |
** Otherwise, return a NULL pointer. |
| 893 |
*/ |
| 894 |
else { |
| 895 |
not_ok: |
| 896 |
debug_msg (DBG_IO, "open_ip_file: unable to open `%s' ... ", |
| 897 |
full_filespec); |
| 898 |
fptr = NULL; |
| 899 |
} |
| 900 |
return (fptr); |
| 901 |
} /* open_ip_file() */ |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
/*- |
| 906 |
**============================================================================ |
| 907 |
** open_op_file() |
| 908 |
** |
| 909 |
** Open a file for output in the current working directory. If the operating |
| 910 |
** system makes a distinction between text and non-text files, make sure |
| 911 |
** that the file is opened in "text" mode. |
| 912 |
**============================================================================ |
| 913 |
*/ |
| 914 |
FILE *open_op_file (void) |
| 915 |
{ |
| 916 |
const char *tmp_file_name = (const char *) name_of_file; |
| 917 |
FILE *fptr; |
| 918 |
|
| 919 |
debug_msg (DBG_IO, "open_op_file: trying to open `%s' ... ", |
| 920 |
tmp_file_name); |
| 921 |
|
| 922 |
/* |
| 923 |
** Make sure that we open the output file as a "text" file. This |
| 924 |
** varies according to the operating system. |
| 925 |
*/ |
| 926 |
#if defined(KPATHSEA) |
| 927 |
if (kpse_out_name_ok(tmp_file_name)) |
| 928 |
fptr = fopen(tmp_file_name, FOPEN_W_MODE); |
| 929 |
else |
| 930 |
fptr = NULL; |
| 931 |
#else |
| 932 |
# if defined(MSDOS) || defined(OS2) |
| 933 |
fptr = fopen (tmp_file_name, "wt"); |
| 934 |
# endif |
| 935 |
|
| 936 |
# ifdef UNIX |
| 937 |
fptr = fopen (tmp_file_name, "w"); |
| 938 |
# endif |
| 939 |
|
| 940 |
# ifdef VMS |
| 941 |
fptr = fopen (tmp_file_name, "w", "rfm=var", "rat=cr"); |
| 942 |
# endif |
| 943 |
#endif /* ! KPATHSEA */ |
| 944 |
|
| 945 |
if (fptr == NULL) { |
| 946 |
printf ("open_op_file: error opening `%s'\n", tmp_file_name); |
| 947 |
} |
| 948 |
return (fptr); |
| 949 |
} /* open_op_file() */ |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
/*- |
| 954 |
**============================================================================ |
| 955 |
** parse_cmd_line() |
| 956 |
** |
| 957 |
** Parse the command line used to launch BibTeX and set options accordingly. |
| 958 |
** Most of the work is done by the GNU getopt() function to support these |
| 959 |
** long and short options: |
| 960 |
** |
| 961 |
** -? --help display this help text |
| 962 |
** -7 --traditional operate in the traditional 7-bit mode |
| 963 |
** -8 --8bit force 8-bit mode, even if no CS file |
| 964 |
** -c --csfile FILE read FILE as the BibTeX character set |
| 965 |
** and sort definition file |
| 966 |
** -d --debug TYPE report debugging information. TYPE is one or |
| 967 |
** more of all, csf, io, mem, misc, search. |
| 968 |
** -s --statistics report internal statistics |
| 969 |
** -t --trace report execution tracing |
| 970 |
** -v --version report BibTeX version\n |
| 971 |
** -B --big set large BibTeX capacity |
| 972 |
** -H --huge set huge BibTeX capacity |
| 973 |
** -W --wolfgang set really huge BibTeX capacity for Wolfgang |
| 974 |
** -M --min_crossrefs ## set ## as the minimum number of cross refs |
| 975 |
** required for automatic inclusion of the cross |
| 976 |
** referenced entry in the citation list |
| 977 |
** (default = 2) |
| 978 |
** --mcites ## ignored |
| 979 |
** --mentints ## ignored |
| 980 |
** --mentstrs ## ignored |
| 981 |
** --mfields ## ignored |
| 982 |
** --mpool ## ignored |
| 983 |
** --mstrings ## allow ## unique strings |
| 984 |
** --mwizfuns ## ignored |
| 985 |
**============================================================================ |
| 986 |
*/ |
| 987 |
void parse_cmd_line (int argc, char **argv) |
| 988 |
{ |
| 989 |
int c; |
| 990 |
int no_files; |
| 991 |
|
| 992 |
Flag_7bit = FALSE; |
| 993 |
#ifdef UTF_8 |
| 994 |
Flag_8bit = TRUE; |
| 995 |
#else |
| 996 |
Flag_8bit = FALSE; |
| 997 |
#endif |
| 998 |
Flag_big = FALSE; |
| 999 |
Flag_debug = FALSE; |
| 1000 |
Flag_huge = FALSE; |
| 1001 |
Flag_wolfgang = FALSE; |
| 1002 |
Flag_stats = FALSE; |
| 1003 |
Flag_trace = FALSE; |
| 1004 |
Str_auxfile = NULL; |
| 1005 |
Str_csfile = NULL; |
| 1006 |
#ifdef UTF_8 |
| 1007 |
Flag_language = FALSE; |
| 1008 |
Str_language = NULL; |
| 1009 |
Flag_location = FALSE; |
| 1010 |
Str_location = NULL; |
| 1011 |
#endif |
| 1012 |
|
| 1013 |
while (1) { |
| 1014 |
int option_index = 0; |
| 1015 |
|
| 1016 |
c = getopt_long (argc, argv, getopt_str, long_options, &option_index); |
| 1017 |
|
| 1018 |
if (c == EOF) |
| 1019 |
break; |
| 1020 |
|
| 1021 |
switch (c) { |
| 1022 |
case '?': /**************** -?, --help ***************/ |
| 1023 |
usage (NULL); |
| 1024 |
break; |
| 1025 |
|
| 1026 |
#ifndef UTF_8 |
| 1027 |
case '7': /**************** -7, --traditional ********/ |
| 1028 |
Flag_7bit = TRUE; |
| 1029 |
break; |
| 1030 |
|
| 1031 |
case '8': /**************** -8, --8bit ***************/ |
| 1032 |
Flag_8bit = TRUE; |
| 1033 |
break; |
| 1034 |
#endif |
| 1035 |
|
| 1036 |
case 'B': /**************** -B, --big ****************/ |
| 1037 |
Flag_big = TRUE; |
| 1038 |
break; |
| 1039 |
|
| 1040 |
#ifndef UTF_8 |
| 1041 |
case 'c': /**************** -c, --csfile *************/ |
| 1042 |
Str_csfile = strdup (optarg); |
| 1043 |
break; |
| 1044 |
#endif |
| 1045 |
|
| 1046 |
case 'd': /**************** -d, --debug **************/ |
| 1047 |
if ((optarg == NULL) || (*optarg == '\0')) |
| 1048 |
Flag_debug = DBG_ALL; |
| 1049 |
else |
| 1050 |
Flag_debug = checkdbg (optarg); |
| 1051 |
break; |
| 1052 |
|
| 1053 |
case 'H': /**************** -H, --huge ***************/ |
| 1054 |
Flag_huge = TRUE; |
| 1055 |
break; |
| 1056 |
|
| 1057 |
#ifdef UTF_8 |
| 1058 |
case 'l': /**************** -l, --language ***********/ |
| 1059 |
Flag_language =TRUE; |
| 1060 |
Str_language = optarg; |
| 1061 |
break; |
| 1062 |
#endif |
| 1063 |
|
| 1064 |
case 'M': /**************** -M, --min_crossrefs ******/ |
| 1065 |
M_min_crossrefs = checklong (optarg); |
| 1066 |
if (M_min_crossrefs < 0) { |
| 1067 |
mark_fatal (); |
| 1068 |
usage ("invalid minimum cross references `%s'\n", optarg); |
| 1069 |
} |
| 1070 |
break; |
| 1071 |
|
| 1072 |
#ifdef UTF_8 |
| 1073 |
case 'o': /**************** -o, --location ***********/ |
| 1074 |
Flag_location =TRUE; |
| 1075 |
Str_location = optarg; |
| 1076 |
break; |
| 1077 |
#endif |
| 1078 |
|
| 1079 |
case 's': /**************** -s, --statistics *********/ |
| 1080 |
Flag_stats = TRUE; |
| 1081 |
break; |
| 1082 |
|
| 1083 |
case 't': /**************** -t, --trace **************/ |
| 1084 |
Flag_trace = TRUE; |
| 1085 |
break; |
| 1086 |
|
| 1087 |
case 'v': /**************** -v, --version ************/ |
| 1088 |
FPRINTF (TERM_OUT, "%s-x%s (%s)\n", BANNER, EXT_VERSION, TL_VERSION); |
| 1089 |
FPRINTF (TERM_OUT, "Implementation: %s\n", IMPLEMENTATION); |
| 1090 |
FPRINTF (TERM_OUT, "Release version: %s\n", VERSION); |
| 1091 |
#ifdef UTF_8 |
| 1092 |
{ |
| 1093 |
UVersionInfo icuVersion; |
| 1094 |
char icu_version[U_MAX_VERSION_STRING_LENGTH] = ""; |
| 1095 |
u_getVersion(icuVersion); |
| 1096 |
u_versionToString(icuVersion, icu_version); |
| 1097 |
FPRINTF (TERM_OUT, "Compiled with: ICU version %s\n", icu_version); |
| 1098 |
} |
| 1099 |
#endif |
| 1100 |
|
| 1101 |
debug_msg (DBG_MISC, |
| 1102 |
"calling longjmp (Exit_Program_Flag) ... "); |
| 1103 |
longjmp (Exit_Program_Flag, 1); |
| 1104 |
break; |
| 1105 |
|
| 1106 |
case 'W': /**************** -W, --wolfgang ***********/ |
| 1107 |
Flag_wolfgang = TRUE; |
| 1108 |
break; |
| 1109 |
|
| 1110 |
case '\x0A': /**************** --mcites *****************/ |
| 1111 |
case '\x0B': /**************** --mentints ***************/ |
| 1112 |
case '\x0C': /**************** --mentstrs ***************/ |
| 1113 |
case '\x0D': /**************** --mfields ****************/ |
| 1114 |
case '\x0E': /**************** --mpool *****************/ |
| 1115 |
case '\x10': /**************** --mwizfuns ***************/ |
| 1116 |
(void) checklong (optarg); /******** ignored ********/ |
| 1117 |
break; |
| 1118 |
|
| 1119 |
case '\x0F': /**************** --mstrings ***************/ |
| 1120 |
M_strings = checklong (optarg); |
| 1121 |
if (M_strings < 0) { |
| 1122 |
mark_fatal (); |
| 1123 |
usage ("invalid max number of strings `%s'\n", optarg); |
| 1124 |
} |
| 1125 |
break; |
| 1126 |
|
| 1127 |
default: /**************** Unknown argument ********/ |
| 1128 |
mark_fatal (); |
| 1129 |
usage ("unknown option"); |
| 1130 |
} /* end switch (c) */ |
| 1131 |
} /* end while (1) */ |
| 1132 |
|
| 1133 |
#ifdef KPATHSEA |
| 1134 |
kpse_set_program_name(argv[0], PROGNAME); |
| 1135 |
|
| 1136 |
#ifdef WIN32 |
| 1137 |
{ |
| 1138 |
int ac; |
| 1139 |
char **av, *enc; |
| 1140 |
|
| 1141 |
enc = kpse_var_value("command_line_encoding"); |
| 1142 |
if (get_command_line_args_utf8(enc, &ac, &av)) { |
| 1143 |
argc = ac; |
| 1144 |
argv = av; |
| 1145 |
} |
| 1146 |
} |
| 1147 |
#endif |
| 1148 |
#endif |
| 1149 |
|
| 1150 |
/* |
| 1151 |
** Check that a single .aux file was specified. |
| 1152 |
*/ |
| 1153 |
no_files = argc - optind; |
| 1154 |
|
| 1155 |
if (no_files == 1) |
| 1156 |
Str_auxfile = argv[optind]; |
| 1157 |
else if (no_files < 1) { |
| 1158 |
mark_fatal (); |
| 1159 |
usage ("no aux file specified"); |
| 1160 |
} else { |
| 1161 |
mark_fatal (); |
| 1162 |
usage ("only one aux file may be specified"); |
| 1163 |
} |
| 1164 |
|
| 1165 |
/* |
| 1166 |
** Check for contradictory options |
| 1167 |
*/ |
| 1168 |
if (Flag_7bit && Flag_8bit) { |
| 1169 |
mark_fatal (); |
| 1170 |
usage ("can't specify --traditional and --8bit"); |
| 1171 |
} |
| 1172 |
|
| 1173 |
if ((Flag_big && Flag_huge) || (Flag_big && Flag_wolfgang) |
| 1174 |
|| (Flag_huge && Flag_wolfgang)) { |
| 1175 |
mark_fatal (); |
| 1176 |
usage ("can only specify one of --big, --huge and --wolfgang"); |
| 1177 |
} |
| 1178 |
|
| 1179 |
if ((Str_csfile != NULL) && (Flag_7bit)) { |
| 1180 |
mark_fatal (); |
| 1181 |
usage ("can't specify --csfile and --traditional"); |
| 1182 |
} |
| 1183 |
|
| 1184 |
if ((Str_csfile != NULL) && (Flag_8bit)) { |
| 1185 |
mark_fatal (); |
| 1186 |
usage ("can't specify --csfile and --8bit"); |
| 1187 |
} |
| 1188 |
|
| 1189 |
/* |
| 1190 |
** Check for options which have not been #defined into the code |
| 1191 |
*/ |
| 1192 |
#ifndef DEBUG |
| 1193 |
if (Flag_debug) |
| 1194 |
FSO ("BibTeX: debugging support was not compiled into this version\n"); |
| 1195 |
#endif /* DEBUG */ |
| 1196 |
|
| 1197 |
#ifndef STAT |
| 1198 |
if (Flag_stats) |
| 1199 |
FSO ("BibTeX: statistics support was not compiled into this version\n"); |
| 1200 |
#endif /* STAT */ |
| 1201 |
|
| 1202 |
#ifndef TRACE |
| 1203 |
if (Flag_trace) |
| 1204 |
FSO ("BibTeX: tracing support was not compiled into this version\n"); |
| 1205 |
#endif /* TRACE */ |
| 1206 |
|
| 1207 |
|
| 1208 |
} /* parse_cmd_line() */ |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
/*- |
| 1213 |
**============================================================================ |
| 1214 |
** report_bibtex_capacity() |
| 1215 |
** |
| 1216 |
** If the log file has been opened, indicate BibTeX's capacity by reporting |
| 1217 |
** the size/values of some key values and arrays. Anything in mixed case |
| 1218 |
** has been set at run-time. |
| 1219 |
**============================================================================ |
| 1220 |
*/ |
| 1221 |
void report_bibtex_capacity (void) |
| 1222 |
{ |
| 1223 |
if (log_file != NULL) { |
| 1224 |
FPRINTF (log_file, "BibTeX's capacity set as follows:\n\n"); |
| 1225 |
LOG_CAPACITY (AUX_STACK_SIZE); |
| 1226 |
LOG_CAPACITY (Buf_Size); |
| 1227 |
LOG_CAPACITY (Ent_Str_Size); |
| 1228 |
LOG_CAPACITY (Glob_Str_Size); |
| 1229 |
LOG_CAPACITY (Hash_Prime); |
| 1230 |
LOG_CAPACITY (Hash_Size); |
| 1231 |
LOG_CAPACITY (Lit_Stk_Size); |
| 1232 |
LOG_CAPACITY (Max_Bib_Files); |
| 1233 |
LOG_CAPACITY (Max_Cites); |
| 1234 |
LOG_CAPACITY (Max_Fields); |
| 1235 |
LOG_CAPACITY (Max_Glob_Strs); |
| 1236 |
LOG_CAPACITY (Max_Print_Line); |
| 1237 |
LOG_CAPACITY (Max_Strings); |
| 1238 |
LOG_CAPACITY (Min_Crossrefs); |
| 1239 |
LOG_CAPACITY (MIN_PRINT_LINE); |
| 1240 |
LOG_CAPACITY (Pool_Size); |
| 1241 |
LOG_CAPACITY (SINGLE_FN_SPACE); |
| 1242 |
LOG_CAPACITY (Wiz_Fn_Space); |
| 1243 |
FPRINTF (log_file, "\n"); |
| 1244 |
} |
| 1245 |
} /* report_bibtex_capacity() */ |
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
/*- |
| 1250 |
**============================================================================ |
| 1251 |
** report_search_paths() |
| 1252 |
** |
| 1253 |
** Report the environment variables and fallback search paths used by |
| 1254 |
** BibTeX for locating input files. |
| 1255 |
**============================================================================ |
| 1256 |
*/ |
| 1257 |
void report_search_paths (void) |
| 1258 |
{ |
| 1259 |
#ifndef KPATHSEA |
| 1260 |
/* |
| 1261 |
** Define a couple of useful macros to simplify reporting of the desired |
| 1262 |
** information. |
| 1263 |
*/ |
| 1264 |
#define REPORT_SEARCH_PATH(_a,_b,_c) \ |
| 1265 |
debug_msg (DBG_SRCH, "Search strategy for %s files:", _a); \ |
| 1266 |
debug_msg (DBG_SRCH, " search path environment variable: %s", NULLCHECK (_b)); \ |
| 1267 |
if (! ISEMPTYSTR (_b)) { \ |
| 1268 |
char *ptr; \ |
| 1269 |
ptr = getenv (_b); \ |
| 1270 |
debug_msg (DBG_SRCH, " %s value: %s", _b, NULLCHECK (ptr)); \ |
| 1271 |
} \ |
| 1272 |
debug_msg (DBG_SRCH, " fallback search path: %s", NULLCHECK (_c)); |
| 1273 |
|
| 1274 |
|
| 1275 |
#define REPORT_SEARCH_FILE(_a,_b,_c) \ |
| 1276 |
debug_msg (DBG_SRCH, "Default %s file:", _a); \ |
| 1277 |
debug_msg (DBG_SRCH, " file name environment variable: %s", NULLCHECK (_b)); \ |
| 1278 |
if (! ISEMPTYSTR (_b)) { \ |
| 1279 |
char *ptr; \ |
| 1280 |
ptr = getenv (_b); \ |
| 1281 |
debug_msg (DBG_SRCH, " %s value: %s", _b, NULLCHECK (ptr)); \ |
| 1282 |
} \ |
| 1283 |
debug_msg (DBG_SRCH, " fallback file name: %s", NULLCHECK (_c)); |
| 1284 |
|
| 1285 |
/* |
| 1286 |
** Now report the information. |
| 1287 |
*/ |
| 1288 |
REPORT_SEARCH_PATH (".aux", AUX_INPUT_ENVVAR, AUX_INPUT_PATH); |
| 1289 |
REPORT_SEARCH_PATH (".bib", BIB_INPUT_ENVVAR, BIB_INPUT_PATH); |
| 1290 |
REPORT_SEARCH_PATH (".bst", BST_INPUT_ENVVAR, BST_INPUT_PATH); |
| 1291 |
REPORT_SEARCH_PATH (".csf", CSF_INPUT_ENVVAR, CSF_INPUT_PATH); |
| 1292 |
|
| 1293 |
REPORT_SEARCH_FILE (".csf", CSF_FILE_ENVVAR, CSF_FILE_NAME); |
| 1294 |
#endif /* ! KPATHSEA */ |
| 1295 |
} /* report_search_paths() */ |
| 1296 |
|
| 1297 |
|
| 1298 |
/*- |
| 1299 |
**============================================================================ |
| 1300 |
** setup_bound_variable() |
| 1301 |
** |
| 1302 |
** Obtain parameters from environment or configuration file, |
| 1303 |
** or use the default value. |
| 1304 |
**============================================================================ |
| 1305 |
*/ |
| 1306 |
static void setup_bound_variable (Integer_T *var, const char *name, |
| 1307 |
unsigned long def_value, unsigned long min_value) |
| 1308 |
{ |
| 1309 |
#ifdef KPATHSEA |
| 1310 |
char *expansion = kpse_var_value (name); |
| 1311 |
const char *me = kpse_invocation_name; |
| 1312 |
const char *src = " or texmf.cnf"; |
| 1313 |
#else |
| 1314 |
char *expansion = getenv (name); |
| 1315 |
const char *me = PROGNAME; |
| 1316 |
const char *src = ""; |
| 1317 |
#endif |
| 1318 |
int threshold = min_value ? min_value : def_value; |
| 1319 |
|
| 1320 |
*var = def_value; |
| 1321 |
if (expansion) { |
| 1322 |
int conf_val = atoi (expansion); |
| 1323 |
if (conf_val < threshold) |
| 1324 |
fprintf (stderr, |
| 1325 |
"%s: Bad value (%ld) in environment%s for %s, keeping %ld.\n", |
| 1326 |
me, (long) conf_val, src, name, def_value); |
| 1327 |
else |
| 1328 |
*var = conf_val; |
| 1329 |
#ifdef KPATHSEA |
| 1330 |
free (expansion); |
| 1331 |
#endif |
| 1332 |
} |
| 1333 |
} /* setup_bound_variable() */ |
| 1334 |
|
| 1335 |
/*- |
| 1336 |
**============================================================================ |
| 1337 |
** setup_params() |
| 1338 |
** |
| 1339 |
** Determine |ent_str_size|, |glob_str_size|, and |max_strings| from the |
| 1340 |
** environment, configuration file, or default value. Set |
| 1341 |
** |hash_size:=max_strings|, but not less than |HASH_SIZE|. |
| 1342 |
**============================================================================ |
| 1343 |
*/ |
| 1344 |
static void setup_params (void) |
| 1345 |
{ |
| 1346 |
setup_bound_variable (&Ent_Str_Size, "ent_str_size", ENT_STR_SIZE, 0); |
| 1347 |
setup_bound_variable (&Glob_Str_Size, "glob_str_size", GLOB_STR_SIZE, 0); |
| 1348 |
setup_bound_variable (&Max_Strings, "max_strings", MAX_STRINGS, 0); |
| 1349 |
setup_bound_variable (&Max_Print_Line, "max_print_line", MAX_PRINT_LINE, MIN_PRINT_LINE); |
| 1350 |
|
| 1351 |
/* Obsolete: Max_Strings specified via command line. */ |
| 1352 |
if (Flag_big) |
| 1353 |
Max_Strings = 10000; |
| 1354 |
if (Flag_huge) |
| 1355 |
Max_Strings = 19000; |
| 1356 |
if (Flag_wolfgang) |
| 1357 |
Max_Strings = 30000; |
| 1358 |
if (M_strings > 0) |
| 1359 |
Max_Strings = M_strings; |
| 1360 |
|
| 1361 |
if (Max_Strings < MAX_STRINGS) |
| 1362 |
Max_Strings = MAX_STRINGS; |
| 1363 |
Hash_Size = Max_Strings; |
| 1364 |
if (Hash_Size < HASH_SIZE) |
| 1365 |
Hash_Size = HASH_SIZE; |
| 1366 |
} /* setup_params() */ |
| 1367 |
|
| 1368 |
|
| 1369 |
/*- |
| 1370 |
**============================================================================ |
| 1371 |
** compute_hash_prime() |
| 1372 |
** |
| 1373 |
** We use the algorithm from Knuth's \.{primes.web} to compute |
| 1374 |
** |hash_prime| as the smallest prime number not less than 85\% |
| 1375 |
** of |hash_size| (and |>=128|). |
| 1376 |
** |
| 1377 |
** This algorithm uses two arrays |primes| and |mult|. We use the |
| 1378 |
** already allocated |hash_next| and |hash_text| for that purpose. |
| 1379 |
**============================================================================ |
| 1380 |
*/ |
| 1381 |
#define primes hash_next |
| 1382 |
#define mult hash_text |
| 1383 |
static void compute_hash_prime (void) |
| 1384 |
{ |
| 1385 |
Integer32_T Hash_Want = (Hash_Size / 20) * 17; /* 85\% of |hash_size| */ |
| 1386 |
Integer32_T k = 1; /*number of prime numbers $p_i$ in |primes| */ |
| 1387 |
Integer32_T j = 1; /* a prime number candidate */ |
| 1388 |
Integer32_T o = 2; /* number of odd multiples of primes in |mult| */ |
| 1389 |
Integer32_T square = 9; /* $p_o^2$ */ |
| 1390 |
Integer32_T n; /* loop index */ |
| 1391 |
Boolean_T j_prime; /* is |j| a prime? */ |
| 1392 |
|
| 1393 |
debug_msg (DBG_MEM, "Computing Hash_Prime ... "); |
| 1394 |
|
| 1395 |
primes[k] = Hash_Prime = 2; |
| 1396 |
while (Hash_Prime < Hash_Want) { |
| 1397 |
do { |
| 1398 |
j += 2; |
| 1399 |
if (j == square) { |
| 1400 |
mult[o++] = j; |
| 1401 |
j += 2; |
| 1402 |
square = primes[o] * primes[o]; |
| 1403 |
} |
| 1404 |
n = 2; |
| 1405 |
j_prime = TRUE; |
| 1406 |
while ((n < o) && j_prime) { |
| 1407 |
while (mult[n] < j) |
| 1408 |
mult[n] += 2 * primes[n]; |
| 1409 |
if (mult[n++] == j) |
| 1410 |
j_prime = FALSE; |
| 1411 |
} |
| 1412 |
} while (!j_prime); |
| 1413 |
primes[++k] = Hash_Prime = j; |
| 1414 |
} |
| 1415 |
} /* compute_hash_prime() */ |
| 1416 |
|
| 1417 |
|
| 1418 |
/*- |
| 1419 |
**============================================================================ |
| 1420 |
** set_array_sizes() |
| 1421 |
** |
| 1422 |
** Allocate memory dynamically for the large arrays whose size is set |
| 1423 |
** dynamically, depending on the amount memory of memory available. |
| 1424 |
** |
| 1425 |
** On virtual memory operating systems, there is not normally a problem |
| 1426 |
** allocating memory; the array sizes can be predetermined and memory |
| 1427 |
** allocated at run-time. |
| 1428 |
** |
| 1429 |
** Parameter Cmd Standard --big --huge --wolfgang |
| 1430 |
** ------------------------------------------------------------------ |
| 1431 |
** Buf_Size *** initialy 20000, increased as required *** |
| 1432 |
** Hash_Prime *** computed from Hash_Size *** |
| 1433 |
** Hash_Size *** determined from Max_Strings *** |
| 1434 |
** Max_Bib_Files *** initialy 20, increased as required *** |
| 1435 |
** Max_Cites *** initialy 750, increased as required *** |
| 1436 |
** Max_Ent_Ints *** as required *** |
| 1437 |
** Max_Ent_Strs *** as required *** |
| 1438 |
** Max_Fields *** initialy 5000, increased as required *** |
| 1439 |
** Max_Strings Y 4,000 10,000 19,000 30,000 |
| 1440 |
** Pool_Size *** initialy 65,000, increased as required *** |
| 1441 |
** Wiz_Fn_Space *** initialy 3000, increased as required *** |
| 1442 |
** ------------------------------------------------------------------ |
| 1443 |
** |
| 1444 |
**============================================================================ |
| 1445 |
*/ |
| 1446 |
void set_array_sizes (void) |
| 1447 |
{ |
| 1448 |
debug_msg (DBG_MEM, "Setting BibTeX's capacity ... "); |
| 1449 |
|
| 1450 |
Max_Strings = 4000; |
| 1451 |
Min_Crossrefs = 2; |
| 1452 |
|
| 1453 |
setup_params (); |
| 1454 |
Buf_Size = BUF_SIZE; |
| 1455 |
|
| 1456 |
Lit_Stk_Size = LIT_STK_SIZE; |
| 1457 |
|
| 1458 |
Max_Bib_Files = MAX_BIB_FILES; |
| 1459 |
|
| 1460 |
Max_Cites = MAX_CITES; |
| 1461 |
|
| 1462 |
Max_Fields = MAX_FIELDS; |
| 1463 |
|
| 1464 |
if (M_min_crossrefs > 0) |
| 1465 |
Min_Crossrefs = M_min_crossrefs; |
| 1466 |
|
| 1467 |
Pool_Size = POOL_SIZE; |
| 1468 |
|
| 1469 |
Wiz_Fn_Space = WIZ_FN_SPACE; |
| 1470 |
|
| 1471 |
|
| 1472 |
allocate_arrays (); |
| 1473 |
compute_hash_prime (); |
| 1474 |
|
| 1475 |
|
| 1476 |
debug_msg (DBG_MEM, "Hash_Prime = %d, Hash_Size = %d", |
| 1477 |
Hash_Prime, Hash_Size); |
| 1478 |
debug_msg (DBG_MEM, "Buf_Size = %d, Max_Bib_Files = %d", |
| 1479 |
Buf_Size, Max_Bib_Files); |
| 1480 |
debug_msg (DBG_MEM, "Max_Cites = %d, Max_Fields = %d", |
| 1481 |
Max_Cites, Max_Fields); |
| 1482 |
debug_msg (DBG_MEM, "Max_Strings = %d, Pool_Size = %d", |
| 1483 |
Max_Strings, Pool_Size); |
| 1484 |
debug_msg (DBG_MEM, "Min_Crossrefs = %d, Wiz_Fn_Space = %d", |
| 1485 |
Min_Crossrefs, Wiz_Fn_Space); |
| 1486 |
|
| 1487 |
|
| 1488 |
/*- |
| 1489 |
** Check that the key values are sensible. These checks are stolen |
| 1490 |
** from initialize(), but the error messages are more informative. |
| 1491 |
*/ |
| 1492 |
debug_msg(DBG_MISC, "Sanity checking capacity values ... "); |
| 1493 |
|
| 1494 |
if (Hash_Prime < 128) |
| 1495 |
usage ("Hash_Prime (%d) must be >= 128", Hash_Prime); |
| 1496 |
|
| 1497 |
if (Hash_Prime > Hash_Size) |
| 1498 |
usage ("Hash_Prime (%d) must be <= Hash_Size (%d)", |
| 1499 |
Hash_Prime, Hash_Size); |
| 1500 |
|
| 1501 |
/* |
| 1502 |
** The original WEB version of BibTeX imposed a maximum value of |
| 1503 |
** 16321 on Hash_Prime. A WEB constant was defined: |
| 1504 |
** |
| 1505 |
** MAX_HASH_VALUE = (Hash_Prime + Hash_Prime - 2 + 127) |
| 1506 |
** |
| 1507 |
** but, because WEB constants are limited to 32767, Hash_Prime was |
| 1508 |
** consequently limited to a maximum of (32767 + 2 - 127) / 2 = 16321. |
| 1509 |
** |
| 1510 |
** We're using C #defines, so that limit doesn't apply. The |
| 1511 |
** following original sanity check is therefore commented out. |
| 1512 |
** |
| 1513 |
** if (Hash_Prime >= (16384 - 64)) |
| 1514 |
** usage ("Hash_Prime (%d) must be < %d", Hash_Prime, (16384-64)); |
| 1515 |
*/ |
| 1516 |
|
| 1517 |
if (Max_Strings > Hash_Size) |
| 1518 |
usage ("Max_Strings (%d) must be <= Hash_Size (%d)", |
| 1519 |
Max_Strings, Hash_Size); |
| 1520 |
|
| 1521 |
if (Max_Cites > Max_Strings) |
| 1522 |
usage ("Max_Cites (%d) must be <= Max_Strings (%d)", |
| 1523 |
Max_Cites, Max_Strings); |
| 1524 |
|
| 1525 |
} /* set_array_sizes() */ |
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
/*- |
| 1530 |
**============================================================================ |
| 1531 |
** usage() |
| 1532 |
** |
| 1533 |
** Display a helpful message reporting the command line options |
| 1534 |
** supported by this version of BibTeX. If a message string is |
| 1535 |
** provided, this is displayed first. |
| 1536 |
**============================================================================ |
| 1537 |
*/ |
| 1538 |
void usage (const char *printf_fmt, ...) |
| 1539 |
{ |
| 1540 |
va_list printf_args; |
| 1541 |
|
| 1542 |
if (printf_fmt != NULL) { |
| 1543 |
#ifdef UTF_8 |
| 1544 |
fprintf (stderr, "BibTeXu: "); |
| 1545 |
#else |
| 1546 |
fprintf (stderr, "BibTeX8: "); |
| 1547 |
#endif |
| 1548 |
va_start (printf_args, printf_fmt); |
| 1549 |
vfprintf (stderr, printf_fmt, printf_args); |
| 1550 |
va_end (printf_args); |
| 1551 |
fprintf (stderr, "\n"); |
| 1552 |
} |
| 1553 |
|
| 1554 |
FSO ("\nUsage: " PROGNAME " [options] aux-file\n\n"); |
| 1555 |
FSO (" Valid options are:\n\n"); |
| 1556 |
FSO (" -? --help display this help text\n"); |
| 1557 |
|
| 1558 |
#ifndef UTF_8 |
| 1559 |
FSO (" -7 --traditional operate in the original 7-bit mode\n"); |
| 1560 |
FSO (" -8 --8bit force 8-bit mode, no CS file used\n"); |
| 1561 |
FSO (" -c --csfile FILE read FILE as the BibTeX character set\n"); |
| 1562 |
FSO (" and sort definition file\n"); |
| 1563 |
#endif |
| 1564 |
|
| 1565 |
#ifdef DEBUG |
| 1566 |
FSO (" -d --debug TYPE report debugging information. TYPE is one\n"); |
| 1567 |
FSO (" or more of all, csf, io, mem, misc, search.\n"); |
| 1568 |
#endif /* DEBUG */ |
| 1569 |
|
| 1570 |
#ifdef STAT |
| 1571 |
FSO (" -s --statistics report internal statistics\n"); |
| 1572 |
#endif /* STAT */ |
| 1573 |
|
| 1574 |
#ifdef TRACE |
| 1575 |
FSO (" -t --trace report execution tracing\n"); |
| 1576 |
#endif /* TRACE */ |
| 1577 |
|
| 1578 |
FSO (" -v --version report BibTeX version\n\n"); |
| 1579 |
|
| 1580 |
#ifdef UTF_8 |
| 1581 |
FSO (" -l --language LANG use language LANG, ex: -l fr\n"); |
| 1582 |
FSO (" -o --location LOC use location LOC, ex: -o fr\n\n"); |
| 1583 |
#endif |
| 1584 |
|
| 1585 |
FSO (" -B --big same as --mstrings 10000\n"); |
| 1586 |
FSO (" -H --huge same as --mstrings 19000\n"); |
| 1587 |
FSO (" -W --wolfgang same as --mstrings 30000\n"); |
| 1588 |
FSO (" -M --min_crossrefs ## set min_crossrefs to ##\n"); |
| 1589 |
FSO (" --mstrings ## allow ## unique strings\n"); |
| 1590 |
FSO ("\nEmail bug reports to " PACKAGE_BUGREPORT ".\n"); |
| 1591 |
|
| 1592 |
debug_msg (DBG_MISC, "calling longjmp (Exit_Program_Flag) ... "); |
| 1593 |
longjmp (Exit_Program_Flag, 1); |
| 1594 |
} /* usage() */ |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
/*- |
| 1599 |
****************************************************************************** |
| 1600 |
****************************************************************************** |
| 1601 |
** |
| 1602 |
** Functions specifically for 8-bit support. |
| 1603 |
** |
| 1604 |
** c8read_csf |
| 1605 |
** c8initialise |
| 1606 |
** c8read_lowercase |
| 1607 |
** c8read_lowupcase |
| 1608 |
** c8read_uppercase |
| 1609 |
** c8read_order |
| 1610 |
** c8report_8bit_handling |
| 1611 |
** |
| 1612 |
****************************************************************************** |
| 1613 |
****************************************************************************** |
| 1614 |
*/ |
| 1615 |
#ifdef SUPPORT_8BIT |
| 1616 |
|
| 1617 |
/* |
| 1618 |
** Useful definitions. |
| 1619 |
*/ |
| 1620 |
#define c8is_alpha(c) (isalpha(c) || c > 127) |
| 1621 |
#define c8is_alphanumeric(c) (isalnum(c) || c > 127) |
| 1622 |
#define SORT_LAST 4095 |
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
/*- |
| 1627 |
**============================================================================ |
| 1628 |
** c8initialise () |
| 1629 |
** |
| 1630 |
** Initialise BibTeX's handling of 8-bit character sets. The steps are: |
| 1631 |
** |
| 1632 |
** o initialise default behaviour for sorting and upper/lowercase |
| 1633 |
** o if appropriate, read and parse the CS file |
| 1634 |
** o use CS data to set behaviour for sorting and upper/lowercase |
| 1635 |
** o update xchr/xord arrays for 8-bit characters. These arrays |
| 1636 |
** are initialised for ASCII character sets in the original |
| 1637 |
** initialize() function. Further initialisation for 8-bit |
| 1638 |
** characters is performed here to minimise "contamination" of |
| 1639 |
** the original BibTeX code. |
| 1640 |
** |
| 1641 |
** We have to deal with three modes of operation: |
| 1642 |
** |
| 1643 |
** --traditional - the original BibTeX behaviour |
| 1644 |
** --8bit - every character with a code > 127 is treated as |
| 1645 |
** a letter |
| 1646 |
** default - a CS file is read and parsed to define sorting order |
| 1647 |
** and how 8-bit characters should be handled |
| 1648 |
**============================================================================ |
| 1649 |
*/ |
| 1650 |
void c8initialise (void) |
| 1651 |
{ |
| 1652 |
int ascii_case_diff = 'a' - 'A'; |
| 1653 |
int c; |
| 1654 |
int status; |
| 1655 |
|
| 1656 |
/* |
| 1657 |
** Traditional mode (--traditional, -7) results in identical behaviour |
| 1658 |
** to the original BibTeX. |
| 1659 |
** |
| 1660 |
** o sort order by character code value ('A'=65 ... 'z'=122) |
| 1661 |
** o upper/lowercase relationships for A..Za..z established |
| 1662 |
** o no CS file read |
| 1663 |
** o only characters < 128 allowed |
| 1664 |
** o no need to update xchr/xord arrays |
| 1665 |
*/ |
| 1666 |
if (Flag_7bit) { |
| 1667 |
|
| 1668 |
for (c = 0; c <= 255; c++) { |
| 1669 |
c8order[c] = c; |
| 1670 |
c8lowcase[c] = (UChar_T) c; |
| 1671 |
c8upcase[c] = (UChar_T) c; |
| 1672 |
} |
| 1673 |
|
| 1674 |
for (c = 'A'; c <= 'Z'; c++) { |
| 1675 |
c8lowcase[c] = (UChar_T) (c + ascii_case_diff); |
| 1676 |
c8upcase[c + ascii_case_diff] = (UChar_T) c; |
| 1677 |
} |
| 1678 |
|
| 1679 |
for (c = 128; c <= 255; c++) |
| 1680 |
lex_class[c] = ILLEGAL; |
| 1681 |
} |
| 1682 |
|
| 1683 |
/* |
| 1684 |
** Raw 8-bit (--8bit, -8). |
| 1685 |
** |
| 1686 |
** o sort order by character code value ('A'=65 ... 'z'=122) |
| 1687 |
** o upper/lowercase relationships for A..Za..z established |
| 1688 |
** o no CS file read |
| 1689 |
** o need to update xchr/xord arrays |
| 1690 |
** o characters > 127 allowed and all treated as type ALPHA |
| 1691 |
*/ |
| 1692 |
else if (Flag_8bit) { |
| 1693 |
|
| 1694 |
for (c = 0; c <= 255; c++) { |
| 1695 |
c8order[c] = c; |
| 1696 |
c8lowcase[c] = (UChar_T) c; |
| 1697 |
c8upcase[c] = (UChar_T) c; |
| 1698 |
} |
| 1699 |
|
| 1700 |
for (c = 'A'; c <= 'Z'; c++) { |
| 1701 |
c8lowcase[c] = (UChar_T) (c + ascii_case_diff); |
| 1702 |
c8upcase[c + ascii_case_diff] = (UChar_T) c; |
| 1703 |
} |
| 1704 |
|
| 1705 |
for (c = 128; c <= 255; c++) |
| 1706 |
xchr[c] = (char) c; |
| 1707 |
|
| 1708 |
for (c = 128; c <= 255; c++) |
| 1709 |
xord[xchr[c]] = (ASCIICode_T) c; |
| 1710 |
|
| 1711 |
for (c = 128; c <= 255; c++) |
| 1712 |
lex_class[c] = ALPHA; |
| 1713 |
} |
| 1714 |
|
| 1715 |
/* |
| 1716 |
** Default initialisation using CS file. |
| 1717 |
** |
| 1718 |
** o no sort order defined - all set to weight SORT_LAST |
| 1719 |
** o upper/lowercase relationships for A..Za..z established |
| 1720 |
** o only characters < 128 allowed initially |
| 1721 |
** o a CS file is read and parsed by BibTeX to modify these defaults |
| 1722 |
** o need to update xchr/xord/lex_class arrays after reading CS file |
| 1723 |
*/ |
| 1724 |
else { |
| 1725 |
|
| 1726 |
for (c = 0; c <= 255; c++) { |
| 1727 |
c8order[c] = SORT_LAST; |
| 1728 |
c8lowcase[c] = (UChar_T) c; |
| 1729 |
c8upcase[c] = (UChar_T) c; |
| 1730 |
} |
| 1731 |
|
| 1732 |
c8order[32] = 0; |
| 1733 |
|
| 1734 |
for (c = 'A'; c <= 'Z'; c++) { |
| 1735 |
c8lowcase[c] = (UChar_T) (c + ascii_case_diff); |
| 1736 |
c8upcase[c + ascii_case_diff] = (UChar_T) c; |
| 1737 |
} |
| 1738 |
|
| 1739 |
for (c = 128; c <= 255; c++) |
| 1740 |
xchr[c] = (char) c; |
| 1741 |
|
| 1742 |
for (c = 128; c <= 255; c++) |
| 1743 |
xord[xchr[c]] = (ASCIICode_T) c; |
| 1744 |
|
| 1745 |
for (c = 128; c <= 255; c++) |
| 1746 |
lex_class[c] = ILLEGAL; |
| 1747 |
|
| 1748 |
/* |
| 1749 |
** Read the CS file. If it was read and parsed OK, update the |
| 1750 |
** definition of 8-bit characters. If an 8-bit character is defined |
| 1751 |
** in any section of the CS file, it is treated as type ALPHA. |
| 1752 |
*/ |
| 1753 |
if ((status = c8read_csf ()) == TRUE) { |
| 1754 |
|
| 1755 |
for (c = 128; c <= 255; c++) |
| 1756 |
if ((c8order[c] != SORT_LAST) |
| 1757 |
|| (c8lowcase[c] != c) |
| 1758 |
|| (c8upcase[c] != c)) |
| 1759 |
lex_class[c] = ALPHA; |
| 1760 |
} |
| 1761 |
} /* end if (Flag_7bit) */ |
| 1762 |
|
| 1763 |
/* |
| 1764 |
** If the CSF debugging option has been selected, report results. |
| 1765 |
*/ |
| 1766 |
if ((Flag_debug & DBG_CSF)) |
| 1767 |
c8report_8bit_handling (); |
| 1768 |
|
| 1769 |
} /* c8initialise () */ |
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
/*- |
| 1774 |
**============================================================================ |
| 1775 |
** c8read_csf() |
| 1776 |
** |
| 1777 |
** Read the Case and Sorting definitions (CS) File. Steps taken are: |
| 1778 |
** |
| 1779 |
** o determine which CS file should be opened |
| 1780 |
** o open the CS file |
| 1781 |
** o look for valid CS file sections (\lowupcase, \lowercase, |
| 1782 |
** \uppercase, \order) and delegate parsing of each section to the |
| 1783 |
** appropriate function |
| 1784 |
** o close the CS file |
| 1785 |
** |
| 1786 |
** Returns TRUE if a CS file was successfully read and parsed, FALSE |
| 1787 |
** otherwise. |
| 1788 |
**============================================================================ |
| 1789 |
*/ |
| 1790 |
int c8read_csf (void) |
| 1791 |
{ |
| 1792 |
int c, i; |
| 1793 |
int in_comment; |
| 1794 |
#define SX_BUF_SIZE 15 |
| 1795 |
/* a section name: "order", "uppercase", "lowercase", or "lowupcase". */ |
| 1796 |
char sx[SX_BUF_SIZE + 1]; |
| 1797 |
#ifndef KPATHSEA |
| 1798 |
char *value; |
| 1799 |
#endif |
| 1800 |
|
| 1801 |
/* |
| 1802 |
** Construct the name of the CS file to be used: |
| 1803 |
** |
| 1804 |
** 1. If the --csfile option was specified, use its value. |
| 1805 |
** or |
| 1806 |
** 2. If CSF_FILE_ENVVAR is defined to a non-empty value, it |
| 1807 |
** contains the name of an environment variable. The value of |
| 1808 |
** this environment variable will be used as the default CS file. |
| 1809 |
*/ |
| 1810 |
if (Str_csfile == NULL) { |
| 1811 |
#ifdef KPATHSEA |
| 1812 |
#ifndef CSF_FILE_ENVVAR |
| 1813 |
#define CSF_FILE_ENVVAR "BIBTEX_CSFILE" |
| 1814 |
#endif |
| 1815 |
/* Default value from environment or texmf.cnf */ |
| 1816 |
Str_csfile = kpse_var_value (CSF_FILE_ENVVAR); |
| 1817 |
if (Str_csfile == NULL) /* Use fallback value */ |
| 1818 |
Str_csfile = xstrdup ("88591lat.csf"); |
| 1819 |
#else |
| 1820 |
if (strlen (CSF_FILE_ENVVAR) != 0) { |
| 1821 |
debug_msg (DBG_CSF, "c8read_csf: --csfile not set, checking '%s'", |
| 1822 |
CSF_FILE_ENVVAR); |
| 1823 |
value = getenv (CSF_FILE_ENVVAR); |
| 1824 |
|
| 1825 |
if (value == NULL) |
| 1826 |
debug_msg (DBG_CSF, "c8read_csf: %s = `NULL'", CSF_FILE_ENVVAR); |
| 1827 |
else |
| 1828 |
debug_msg (DBG_CSF, "c8read_csf: %s = `%s'", |
| 1829 |
CSF_FILE_ENVVAR, value); |
| 1830 |
/* |
| 1831 |
** If the environment variable has a non-empty value, use it |
| 1832 |
** as the file specifaction for the default CS file. |
| 1833 |
*/ |
| 1834 |
if ((value != NULL) && (*value != '\0')) |
| 1835 |
Str_csfile = strdup (value); |
| 1836 |
else { |
| 1837 |
PRINT_LN ("Warning: cannot open CS file: --csfile not specfied"); |
| 1838 |
PRINT_LN2 ("and environment variable %s has no value.", |
| 1839 |
CSF_FILE_ENVVAR); |
| 1840 |
return FALSE; |
| 1841 |
} |
| 1842 |
} else { |
| 1843 |
PRINT_LN ("Warning: cannot open CS file: --csfile not specified"); |
| 1844 |
PRINT_LN ("and default environment variable not specified."); |
| 1845 |
return FALSE; |
| 1846 |
} /* if (strlen (CSF_FILE_ENVVAR) != 0) */ |
| 1847 |
#endif /* KPATHSEA */ |
| 1848 |
} /* if (Str_csfile == NULL) */ |
| 1849 |
/* |
| 1850 |
** Make sure that we have ended up with a CS file name. If not, |
| 1851 |
** return FALSE; |
| 1852 |
*/ |
| 1853 |
if ((Str_csfile == NULL) || (*Str_csfile == '\0')) { |
| 1854 |
PRINT_LN ("Warning: cannot open CS file: empty --csfile value specified."); |
| 1855 |
return FALSE; |
| 1856 |
} |
| 1857 |
|
| 1858 |
/* |
| 1859 |
** If the CS file name doesn't contain a '.', append ".csf". |
| 1860 |
*/ |
| 1861 |
free (name_of_file); |
| 1862 |
name_of_file = (unsigned char *) mymalloc (strlen (Str_csfile) + 5, "name_of_file"); |
| 1863 |
strcpy ((char *)name_of_file, Str_csfile); |
| 1864 |
|
| 1865 |
if (strchr ((char *)name_of_file, '.') == NULL) |
| 1866 |
strcat ((char *)name_of_file, ".csf"); |
| 1867 |
name_length = strlen ((char *)name_of_file); |
| 1868 |
|
| 1869 |
debug_msg (DBG_CSF, "c8read_csf: trying to open CS file `%s' ...", |
| 1870 |
name_of_file); |
| 1871 |
|
| 1872 |
/* |
| 1873 |
** Attempt to open the CS file, using the CS file search path if |
| 1874 |
** necessary. If the open fails, return FALSE. |
| 1875 |
*/ |
| 1876 |
if (! a_open_in (&c8_cs_file, CSF_FILE_SEARCH_PATH)) { |
| 1877 |
PRINT_LN2 ("Error: cannot open CS file: %s", name_of_file); |
| 1878 |
return FALSE; |
| 1879 |
} |
| 1880 |
PRINT_LN2 ("The 8-bit codepage and sorting file: %s", name_of_file); |
| 1881 |
|
| 1882 |
/* |
| 1883 |
** The main loop for reading the CS file. |
| 1884 |
*/ |
| 1885 |
c8_line = 1; |
| 1886 |
while (! feof (c8_cs_file)) { |
| 1887 |
|
| 1888 |
/* |
| 1889 |
** Read the CS file until a '\\' character is found, denoting the |
| 1890 |
** start of a major section. Comments begin with a '%' and |
| 1891 |
** anything else on the same line is ignored. |
| 1892 |
*/ |
| 1893 |
in_comment = FALSE; |
| 1894 |
do { |
| 1895 |
c = getc (c8_cs_file); |
| 1896 |
|
| 1897 |
if (c == '\n') { |
| 1898 |
++c8_line; |
| 1899 |
in_comment = FALSE; |
| 1900 |
} |
| 1901 |
if (c == '%') |
| 1902 |
in_comment = TRUE; |
| 1903 |
if ((c == '\\') && (in_comment == FALSE)) |
| 1904 |
break; |
| 1905 |
} while (!feof (c8_cs_file)); |
| 1906 |
|
| 1907 |
/* |
| 1908 |
** If we break out of the do loop on EOF, there were no more |
| 1909 |
** sections in the CS file. Exit the main reading loop. |
| 1910 |
*/ |
| 1911 |
if (feof (c8_cs_file)) |
| 1912 |
break; |
| 1913 |
|
| 1914 |
/* |
| 1915 |
** After '\', a section name must be found. This name is a word |
| 1916 |
** composed only of lower case ASCII letters. |
| 1917 |
*/ |
| 1918 |
i = 0; |
| 1919 |
|
| 1920 |
do { |
| 1921 |
c = getc (c8_cs_file); |
| 1922 |
if ((c >= 'a') && (c <= 'z')) |
| 1923 |
sx[i++] = c; |
| 1924 |
else |
| 1925 |
break; |
| 1926 |
} while (!feof (c8_cs_file) && (i < SX_BUF_SIZE)); |
| 1927 |
sx[i] = '\0'; |
| 1928 |
|
| 1929 |
/* |
| 1930 |
** A '{' should follow the section name, but it could be preceeded |
| 1931 |
** by whitespace, comments or newlines. |
| 1932 |
*/ |
| 1933 |
if (c != '{') |
| 1934 |
do { |
| 1935 |
if (c == '\n') { |
| 1936 |
++c8_line; |
| 1937 |
in_comment = FALSE; |
| 1938 |
} |
| 1939 |
if (c == '%') |
| 1940 |
in_comment = TRUE; |
| 1941 |
if ((c == '{') && (in_comment == FALSE)) |
| 1942 |
break; |
| 1943 |
c = getc (c8_cs_file); |
| 1944 |
} while (!feof (c8_cs_file)); |
| 1945 |
|
| 1946 |
|
| 1947 |
/* |
| 1948 |
** The major sections supported in the CS file are: \order{}, |
| 1949 |
** \uppercase{}, \lowercase{} and \lowupcase{}. Anything else will |
| 1950 |
** be ignored. Known sections are processed until they terminate |
| 1951 |
** and then the loop starts again. |
| 1952 |
*/ |
| 1953 |
if (strcmp (sx, "order") == 0) |
| 1954 |
c8read_order (); |
| 1955 |
else if (strcmp (sx, "uppercase") == 0) |
| 1956 |
c8read_uppercase (); |
| 1957 |
else if (strcmp (sx, "lowercase") == 0) |
| 1958 |
c8read_lowercase (); |
| 1959 |
else if (strcmp (sx, "lowupcase") == 0) |
| 1960 |
c8read_lowupcase (); |
| 1961 |
else { |
| 1962 |
PRINT_LN2 ("Unknown section on line in CS file %s", Str_csfile); |
| 1963 |
PRINT_LN3 ("%04d: \\%s", c8_line, buffer); |
| 1964 |
} |
| 1965 |
} /* while (! feof (c8_cs_file)) */ |
| 1966 |
|
| 1967 |
/* |
| 1968 |
** Finished reading, close the CS file then return TRUE. |
| 1969 |
*/ |
| 1970 |
close_file (c8_cs_file); |
| 1971 |
free (Str_csfile); |
| 1972 |
return TRUE; |
| 1973 |
} /* c8read_csf () */ |
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
/*- |
| 1978 |
**============================================================================ |
| 1979 |
** c8read_lowercase() |
| 1980 |
** |
| 1981 |
** Read and parse the \lowercase section of the CS file. This section is |
| 1982 |
** used to define the upper -> lower case relationship of pairs of specified |
| 1983 |
** characters. It should normally only be used if the relationship |
| 1984 |
** isn't symmetrical - use \lowupcase if it is. |
| 1985 |
** |
| 1986 |
** The syntax of the \lowercase section is: |
| 1987 |
** |
| 1988 |
** \lowercase{ |
| 1989 |
** <UC-val-1> <LC-val-1> % Comment begins with a percent sign |
| 1990 |
** <UC-val-2> <LC-val-2> <UC-val-3> <LC-val-3> |
| 1991 |
** ... |
| 1992 |
** <UC-val-N> <LC-val-N> |
| 1993 |
** } |
| 1994 |
** |
| 1995 |
** Notes: |
| 1996 |
** |
| 1997 |
** o characters can be entered normally, or in TeX notation for |
| 1998 |
** character codes, i.e. ^^XX, where XX is the hexadecimal value. |
| 1999 |
** |
| 2000 |
** o reading of the \lowercase section ends when the first '}' character |
| 2001 |
** is reached, so '}' can't be included in a case relationship pair. |
| 2002 |
** You can't use ^^7d either. |
| 2003 |
** |
| 2004 |
** o '%' is used to introduce a trailing comment, so '%' can't be included |
| 2005 |
** in the \lowercase section. You can't use ^^25 either. |
| 2006 |
** |
| 2007 |
** o you cannot redefine the lower case equivalent of an ASCII character |
| 2008 |
** (code < 128). In other words, all "left hand" characters in the |
| 2009 |
** relationship pairs must have codes > 127. |
| 2010 |
**============================================================================ |
| 2011 |
*/ |
| 2012 |
static void c8read_lowercase (void) |
| 2013 |
{ |
| 2014 |
int c; |
| 2015 |
int uppercase_val; |
| 2016 |
|
| 2017 |
debug_msg (DBG_CSF, "reading the \\lowercase section ... "); |
| 2018 |
uppercase_val = -1; |
| 2019 |
|
| 2020 |
/* |
| 2021 |
** Keep reading characters until the end of the section is encountered |
| 2022 |
** at a '}' or EOF is reached. |
| 2023 |
*/ |
| 2024 |
c = getc (c8_cs_file); |
| 2025 |
|
| 2026 |
while ((c != '}') && !feof (c8_cs_file)) { |
| 2027 |
|
| 2028 |
/* |
| 2029 |
** Characters may be specified using the TeX syntax for the |
| 2030 |
** 8-bit code, i.e. ^^XX, where XX is the hexadecimal value. |
| 2031 |
** We should really check the result of this fscanf(). Read the |
| 2032 |
** character code and then start the while loop again. |
| 2033 |
*/ |
| 2034 |
if (c == '^') |
| 2035 |
fscanf (c8_cs_file, "^%x", &c); |
| 2036 |
|
| 2037 |
/* |
| 2038 |
** If we have reached the end of a line, simply increment the |
| 2039 |
** line count. |
| 2040 |
*/ |
| 2041 |
if (c == '\n') { |
| 2042 |
c8_line++; |
| 2043 |
} |
| 2044 |
|
| 2045 |
/* |
| 2046 |
** If we encounter a '%', it signifies the start of a comment. |
| 2047 |
** Ignore characters until the end of line is reached. |
| 2048 |
*/ |
| 2049 |
else if (c == '%') { |
| 2050 |
do { |
| 2051 |
c = getc(c8_cs_file); |
| 2052 |
} while ((c != '\n') && (! feof( c8_cs_file))); |
| 2053 |
continue; |
| 2054 |
} |
| 2055 |
|
| 2056 |
/* |
| 2057 |
** The normal case is for alpha characters to be included in the |
| 2058 |
** case relationship. Alpha characters are assumed to be ASCII |
| 2059 |
** alpha (A..Za..z) plus any character with a code > 127. |
| 2060 |
*/ |
| 2061 |
else if (c8is_alpha (c)) { |
| 2062 |
|
| 2063 |
/* |
| 2064 |
** The case relationship consists of a pair of alpha characters |
| 2065 |
** separated by whitespace. In the \lowercase section, the pair |
| 2066 |
** is in the order <uppercase-char> <lowercase-char>. We |
| 2067 |
** must remember which character we are looking for - this is |
| 2068 |
** achieved by setting uppercase_val to -1 when we are |
| 2069 |
** looking for the first character of a pair. |
| 2070 |
** |
| 2071 |
** If uppercase_val is < 0, we treat the current character as |
| 2072 |
** the upper case member of the pair and set uppercase_val |
| 2073 |
** accordingly. |
| 2074 |
*/ |
| 2075 |
if (uppercase_val < 0) |
| 2076 |
uppercase_val = c; |
| 2077 |
else { |
| 2078 |
|
| 2079 |
/* |
| 2080 |
** We are not allowed to redefine the lower case |
| 2081 |
** equivalent of an ASCII character. |
| 2082 |
*/ |
| 2083 |
if (uppercase_val < 127) { |
| 2084 |
PRINT_LN2 ("Error: attempt to redefine lower case of " |
| 2085 |
"an ASCII character [0x%02x]", uppercase_val); |
| 2086 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2087 |
c8_line, Str_csfile); |
| 2088 |
} |
| 2089 |
|
| 2090 |
/* |
| 2091 |
** All OK, so set the appropriate element of the c8lowcase |
| 2092 |
** array and reset the value of uppercase_val to signify |
| 2093 |
** that we are looking for the next pair. |
| 2094 |
*/ |
| 2095 |
else { |
| 2096 |
c8lowcase[uppercase_val] = c; |
| 2097 |
uppercase_val = -1; |
| 2098 |
} |
| 2099 |
} |
| 2100 |
} /* end if */ |
| 2101 |
|
| 2102 |
/* |
| 2103 |
** Get the next character from the file and start the loop again. |
| 2104 |
*/ |
| 2105 |
c = getc (c8_cs_file); |
| 2106 |
} /* end while */ |
| 2107 |
|
| 2108 |
/* |
| 2109 |
** The only normal reason for breaking out of the while loop is that |
| 2110 |
** we encountered '}' at the end of the \lowercase section. Two |
| 2111 |
** conditions should be true: |
| 2112 |
** |
| 2113 |
** (uppercase_val = -1) - there is an unmatched character |
| 2114 |
** (c == '}') - the terminating '}' has been read |
| 2115 |
*/ |
| 2116 |
if (uppercase_val != -1){ |
| 2117 |
PRINT_LN ("Error: unmatched character pair in \\lowercase section"); |
| 2118 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2119 |
} |
| 2120 |
|
| 2121 |
if (c != '}') { |
| 2122 |
PRINT_LN ("Error: unexpected end of file in \\lowercase section"); |
| 2123 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2124 |
} |
| 2125 |
|
| 2126 |
debug_msg (DBG_CSF, "finished reading the \\lowercase section."); |
| 2127 |
} /* c8read_lowercase () */ |
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
/*- |
| 2132 |
**============================================================================ |
| 2133 |
** c8read_lowupcase() |
| 2134 |
** |
| 2135 |
** Read and parse the \lowupcase section of the CS file. This section is |
| 2136 |
** used to define the lower -> upper and upper -> lower case relationship |
| 2137 |
** of pairs of specified characters. It is only used if the relationship |
| 2138 |
** is symmetrical - use \lowercase or \uppercase if it isn't. |
| 2139 |
** |
| 2140 |
** The syntax of the \lowupcase section is: |
| 2141 |
** |
| 2142 |
** \uppercase{ |
| 2143 |
** <LC-val-1> <UC-val-1> % Comment begins with a percent sign |
| 2144 |
** <LC-val-2> <UC-val-2> <LC-val-3> <UC-val-3> |
| 2145 |
** ... |
| 2146 |
** <LC-val-N> <UC-val-N> |
| 2147 |
** } |
| 2148 |
** |
| 2149 |
** Notes: |
| 2150 |
** |
| 2151 |
** o characters can be entered normally, or in TeX notation for |
| 2152 |
** character codes, i.e. ^^XX, where XX is the hexadecimal value. |
| 2153 |
** |
| 2154 |
** o reading of the \lowupcase section ends when the first '}' character |
| 2155 |
** is reached, so '}' can't be included in a case relationship pair. |
| 2156 |
** You can't use ^^7d either. |
| 2157 |
** |
| 2158 |
** o '%' is used to introduce a trailing comment, so '%' can't be included |
| 2159 |
** in the \lowupcase section. You can't use ^^25 either. |
| 2160 |
** |
| 2161 |
** o you cannot redefine the lower or upper case equivalent of an ASCII |
| 2162 |
** character (code < 128). In other words, all characters in the |
| 2163 |
** relationship pairs must have codes > 127. |
| 2164 |
**============================================================================ |
| 2165 |
*/ |
| 2166 |
static void c8read_lowupcase (void) |
| 2167 |
{ |
| 2168 |
int c; |
| 2169 |
int lowercase_val; |
| 2170 |
|
| 2171 |
debug_msg (DBG_CSF, "reading the \\lowupcase section ... "); |
| 2172 |
lowercase_val = -1; |
| 2173 |
|
| 2174 |
/* |
| 2175 |
** Keep reading characters until the end of the section is encountered |
| 2176 |
** at a '}' or EOF is reached. |
| 2177 |
*/ |
| 2178 |
c = getc (c8_cs_file); |
| 2179 |
|
| 2180 |
while ((c != '}') && !feof (c8_cs_file)) { |
| 2181 |
|
| 2182 |
/* |
| 2183 |
** Characters may be specified using the TeX syntax for the |
| 2184 |
** 8-bit code, i.e. ^^XX, where XX is the hexadecimal value. |
| 2185 |
** We should really check the result of this fscanf(). |
| 2186 |
*/ |
| 2187 |
if (c == '^') |
| 2188 |
fscanf (c8_cs_file, "^%x", &c); |
| 2189 |
|
| 2190 |
/* |
| 2191 |
** If we have reached the end of a line, simply increment the |
| 2192 |
** line count. |
| 2193 |
*/ |
| 2194 |
if (c == '\n') { |
| 2195 |
c8_line++; |
| 2196 |
} |
| 2197 |
|
| 2198 |
/* |
| 2199 |
** If we encounter a '%', it signifies the start of a comment, |
| 2200 |
** unless it was translated from a ^^xx sequence. |
| 2201 |
** Ignore characters until the end of line is reached. |
| 2202 |
*/ |
| 2203 |
else if (c == '%') { |
| 2204 |
do { |
| 2205 |
c = getc(c8_cs_file); |
| 2206 |
} while ((c != '\n') && (! feof( c8_cs_file))); |
| 2207 |
continue; |
| 2208 |
} |
| 2209 |
|
| 2210 |
/* |
| 2211 |
** The normal case is for alpha characters to be included in the |
| 2212 |
** case relationship. Alpha characters are assumed to be ASCII |
| 2213 |
** alpha (A..Za..z) plus any character with a code > 127. |
| 2214 |
*/ |
| 2215 |
else if (c8is_alpha (c)) { |
| 2216 |
|
| 2217 |
/* |
| 2218 |
** The case relationship consists of a pair of alpha characters |
| 2219 |
** separated by whitespace. In the \lowupcase section, the pair |
| 2220 |
** is in the order <lowercase-char> <uppercase-char>. We |
| 2221 |
** must remember which character we are looking for - this is |
| 2222 |
** achieved by setting lowercase_val to -1 when we are |
| 2223 |
** looking for the first character of a pair. |
| 2224 |
** |
| 2225 |
** If lowercase_val is < 0, we treat the current character as |
| 2226 |
** the lower case member of the pair and set lowercase_val |
| 2227 |
** accordingly. |
| 2228 |
*/ |
| 2229 |
if (lowercase_val < 0) |
| 2230 |
lowercase_val = c; |
| 2231 |
else { |
| 2232 |
|
| 2233 |
/* |
| 2234 |
** We are not allowed to redefine the lower or upper case |
| 2235 |
** equivalent of an ASCII character. |
| 2236 |
*/ |
| 2237 |
if (lowercase_val < 127) { |
| 2238 |
PRINT_LN2 ("Error: attempt to redefine upper case of " |
| 2239 |
"an ASCII character [0x%02x]", lowercase_val); |
| 2240 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2241 |
c8_line, Str_csfile); |
| 2242 |
} |
| 2243 |
else if (c < 127) { |
| 2244 |
PRINT_LN2 ("Error: attempt to redefine lower case of " |
| 2245 |
"an ASCII character [0x%02x]", c); |
| 2246 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2247 |
c8_line, Str_csfile); |
| 2248 |
} |
| 2249 |
|
| 2250 |
/* |
| 2251 |
** All OK, so set the appropriate element of the c8lowcase |
| 2252 |
** and c8upcase arrays, then reset the value of lowercase_val |
| 2253 |
** to signify that we are looking for the next pair. |
| 2254 |
*/ |
| 2255 |
else { |
| 2256 |
c8lowcase[c] = lowercase_val; |
| 2257 |
c8upcase[lowercase_val] = c; |
| 2258 |
lowercase_val = -1; |
| 2259 |
} |
| 2260 |
} |
| 2261 |
} /* end if */ |
| 2262 |
|
| 2263 |
/* |
| 2264 |
** Get the next character from the file and start the loop again. |
| 2265 |
*/ |
| 2266 |
c = getc (c8_cs_file); |
| 2267 |
} /* end while */ |
| 2268 |
|
| 2269 |
/* |
| 2270 |
** The only normal reason for breaking out of the while loop is that |
| 2271 |
** we encountered '}' at the end of the \lowupcase section. Two |
| 2272 |
** conditions should be true: |
| 2273 |
** |
| 2274 |
** (lowercase_val = -1) - there is an unmatched character |
| 2275 |
** (c == '}') - the terminating '}' has been read |
| 2276 |
*/ |
| 2277 |
if (lowercase_val != -1){ |
| 2278 |
PRINT_LN ("Error: unmatched character pair in \\lowupcase section"); |
| 2279 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2280 |
} |
| 2281 |
|
| 2282 |
if (c != '}') { |
| 2283 |
PRINT_LN ("Error: unexpected end of file in \\lowupcase section"); |
| 2284 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2285 |
} |
| 2286 |
|
| 2287 |
debug_msg (DBG_CSF, "finished reading the \\lowupcase section."); |
| 2288 |
} /* c8read_lowupcase () */ |
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
/*- |
| 2293 |
**============================================================================ |
| 2294 |
** c8read_order() |
| 2295 |
** |
| 2296 |
** Read and parse the \order section of the CS file. This section is |
| 2297 |
** used to define the sorting order of characters in the 8-bit character |
| 2298 |
** set. |
| 2299 |
** |
| 2300 |
** The syntax of the \order section is: |
| 2301 |
** |
| 2302 |
** \order{ |
| 2303 |
** <char-1> % Comment begins with a percent sign |
| 2304 |
** <char-2> <char-3> |
| 2305 |
** <char-4> - <char-5> |
| 2306 |
** <char-4> _ <char-5> |
| 2307 |
** ... |
| 2308 |
** <char-n> |
| 2309 |
** } |
| 2310 |
** |
| 2311 |
** Notes: |
| 2312 |
** |
| 2313 |
** o characters can be entered normally, or in TeX notation for |
| 2314 |
** character codes, i.e. ^^XX, where XX is the hexadecimal value. |
| 2315 |
** |
| 2316 |
** o reading of the \order section ends when the first '}' character |
| 2317 |
** is reached, so '}' can't be included in the \order section. You |
| 2318 |
** can't use ^^7d either. |
| 2319 |
** |
| 2320 |
** o '%' is used to introduce a trailing comment, so '%' can't be included |
| 2321 |
** in the \order section. You can't use ^^25 either. |
| 2322 |
** |
| 2323 |
** o All characters on the same line are given the same sorting weight. |
| 2324 |
** |
| 2325 |
** o The construct <char-1> <underscore> <char-2> is used to denote that |
| 2326 |
** all characters in the range <char-1> to <char-2> should be given the |
| 2327 |
** same sorting weight. For example, "A _ Z a _ z" would cause all |
| 2328 |
** ASCII alphabetical characters to have the same sorting weight and |
| 2329 |
** would be equivalent to placing all 26 characters on the same line. |
| 2330 |
** |
| 2331 |
** o The construct <char-1> <hyphen> <char-2> is used to denote that all |
| 2332 |
** characters in the range <char-1> to <char-2> should be given an |
| 2333 |
** ascending set of sorting weights, starting with <char-1> and |
| 2334 |
** ending with <char-2>. For example, "A - Z" would cause all |
| 2335 |
** upper case ASCII alphabetical characters to be sorted in |
| 2336 |
** ascending order and would be equivalent to placing 'A' on the |
| 2337 |
** first line, 'B' on the second, through to 'Z' on the 26th line. |
| 2338 |
** |
| 2339 |
** o the characters at the beginning of the order section are given a |
| 2340 |
** lower sorting weight than characters occuring later. When |
| 2341 |
** sorting alphabetically, characters with the lowest weight come |
| 2342 |
** first. |
| 2343 |
** |
| 2344 |
** o all characters not in the \order section (including ASCII characters) |
| 2345 |
** are given the same very high sorting weight to ensure that they |
| 2346 |
** come last when sorting alphabetically. |
| 2347 |
**============================================================================ |
| 2348 |
*/ |
| 2349 |
static void c8read_order (void) |
| 2350 |
{ |
| 2351 |
int c, i; |
| 2352 |
int c_previous = 0; |
| 2353 |
int c_previous_previous = 0; |
| 2354 |
int seen_chars; |
| 2355 |
|
| 2356 |
debug_msg (DBG_CSF, "reading the \\order section ... "); |
| 2357 |
sort_weight = 1; |
| 2358 |
seen_chars = FALSE; |
| 2359 |
|
| 2360 |
/* |
| 2361 |
** Keep reading characters until the end of the section is |
| 2362 |
** encountered at a '}' or EOF is reached. |
| 2363 |
*/ |
| 2364 |
c = getc (c8_cs_file); |
| 2365 |
|
| 2366 |
while ((c != '}') && (! feof (c8_cs_file))) { |
| 2367 |
|
| 2368 |
/* |
| 2369 |
** If we have reached the end of a line, the next line denotes |
| 2370 |
** characters with an increased sorting weight. Any other |
| 2371 |
** characters with a value less than ' ' are ignored. |
| 2372 |
*/ |
| 2373 |
if (c == '\n') { |
| 2374 |
if (seen_chars) |
| 2375 |
sort_weight++; |
| 2376 |
c8_line++; |
| 2377 |
seen_chars = FALSE; |
| 2378 |
} |
| 2379 |
else if (c < ' ') { |
| 2380 |
debug_msg (DBG_CSF, "ignoring char 0x%02X on line %d of CS file", |
| 2381 |
c, c8_line); |
| 2382 |
} |
| 2383 |
else if (c > ' ') { |
| 2384 |
|
| 2385 |
/* |
| 2386 |
** Characters may be specified using the TeX syntax for the |
| 2387 |
** 8-bit code, i.e. ^^XX, where XX is the hexadecimal value. |
| 2388 |
** We should really check the result of this fscanf(). Read the |
| 2389 |
** character code and then start the while loop again. |
| 2390 |
*/ |
| 2391 |
if (c == '^') |
| 2392 |
fscanf (c8_cs_file, "^%x", &c); |
| 2393 |
|
| 2394 |
/* |
| 2395 |
** If we encounter a '%', it signifies the start of a comment. |
| 2396 |
** Ignore characters until the end of line is reached. |
| 2397 |
*/ |
| 2398 |
if (c == '%') { |
| 2399 |
do { |
| 2400 |
c = getc(c8_cs_file); |
| 2401 |
} while ((c != '\n') && (! feof( c8_cs_file))); |
| 2402 |
continue; |
| 2403 |
} |
| 2404 |
|
| 2405 |
/* |
| 2406 |
** The normal case is for alpha characters to be included |
| 2407 |
** in the sorting sequence. Alpha characters are ASCII alpha |
| 2408 |
** plus any character with a code > 127. |
| 2409 |
*/ |
| 2410 |
else if (c8is_alphanumeric (c) || c == ' ') { |
| 2411 |
|
| 2412 |
/* |
| 2413 |
** If the previous char was '-', we expect this char to |
| 2414 |
** terminate a "X-Y" sequence. The character before |
| 2415 |
** the '-' must also be an alpha type. The characters in |
| 2416 |
** the sequence are assigned an increasing sort weight. |
| 2417 |
*/ |
| 2418 |
if (c_previous == '-') { |
| 2419 |
if (c8is_alphanumeric (c_previous_previous)) { |
| 2420 |
for (i = c_previous_previous; i < c; i++) |
| 2421 |
c8order[i] = sort_weight++; |
| 2422 |
seen_chars = TRUE; |
| 2423 |
} else { |
| 2424 |
PRINT_LN ("Error: non-alphanumeric character " |
| 2425 |
"starts X-Y sequence"); |
| 2426 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2427 |
c8_line, Str_csfile); |
| 2428 |
} |
| 2429 |
|
| 2430 |
/* |
| 2431 |
** If the previous char was '_', we expect this char to |
| 2432 |
** terminate a "X_Y" sequence. The character before |
| 2433 |
** the '_' must also be an alpha type. The characters in |
| 2434 |
** the sequence are assigned the same sort weight. |
| 2435 |
*/ |
| 2436 |
} else if (c_previous == '_') { |
| 2437 |
if (c8is_alphanumeric (c_previous_previous)) { |
| 2438 |
for (i = c_previous_previous; i < c; i++) |
| 2439 |
c8order[i] = sort_weight; |
| 2440 |
seen_chars = TRUE; |
| 2441 |
} else { |
| 2442 |
PRINT_LN ("Error: non-alphanumeric character " |
| 2443 |
"starts X_Y sequence"); |
| 2444 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2445 |
c8_line, Str_csfile); |
| 2446 |
} |
| 2447 |
} |
| 2448 |
c8order[c] = sort_weight; |
| 2449 |
seen_chars = TRUE; |
| 2450 |
} |
| 2451 |
|
| 2452 |
/* |
| 2453 |
** The only other non-alpha characters allowed are '-' & '_'. |
| 2454 |
*/ |
| 2455 |
else if ((c != '-') && (c != '_')) { |
| 2456 |
PRINT_LN ("Error: only '-' or '_' may follow an " |
| 2457 |
"alpha character"); |
| 2458 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2459 |
c8_line, Str_csfile); |
| 2460 |
} |
| 2461 |
|
| 2462 |
/* |
| 2463 |
** Keep an up-to-date note of the two previous values of c. |
| 2464 |
*/ |
| 2465 |
c_previous_previous = c_previous; |
| 2466 |
c_previous = c; |
| 2467 |
} /* end if */ |
| 2468 |
|
| 2469 |
/* |
| 2470 |
** Get the next character and start the loop again. |
| 2471 |
*/ |
| 2472 |
c = getc (c8_cs_file); |
| 2473 |
} /* end while */ |
| 2474 |
|
| 2475 |
/* |
| 2476 |
** If c isn't '}', we ran into EOF. |
| 2477 |
*/ |
| 2478 |
if (c != '}') { |
| 2479 |
PRINT_LN ("Error: unexpected end of file in \\order section"); |
| 2480 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2481 |
} |
| 2482 |
debug_msg (DBG_CSF, "finished reading the \\order section."); |
| 2483 |
} /* c8read_order () */ |
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
/*- |
| 2488 |
**============================================================================ |
| 2489 |
** c8read_uppercase() |
| 2490 |
** |
| 2491 |
** Read and parse the \uppercase section of the CS file. This section is |
| 2492 |
** used to define the lower -> upper case relationship of pairs of specified |
| 2493 |
** characters. It should normally only be used if the relationship |
| 2494 |
** isn't symmetrical - use \lowupcase if it is. |
| 2495 |
** |
| 2496 |
** The syntax of the \uppercase section is: |
| 2497 |
** |
| 2498 |
** \uppercase{ |
| 2499 |
** <LC-val-1> <UC-val-1> % Comment begins with a percent sign |
| 2500 |
** <LC-val-2> <UC-val-2> <LC-val-3> <UC-val-3> |
| 2501 |
** ... |
| 2502 |
** <LC-val-N> <UC-val-N> |
| 2503 |
** } |
| 2504 |
** |
| 2505 |
** Notes: |
| 2506 |
** |
| 2507 |
** o characters can be entered normally, or in TeX notation for |
| 2508 |
** character codes, i.e. ^^XX, where XX is the hexadecimal value. |
| 2509 |
** |
| 2510 |
** o reading of the \uppercase section ends when the first '}' character |
| 2511 |
** is reached, so '}' can't be included in a case relationship pair. |
| 2512 |
** You can't use ^^7d either. |
| 2513 |
** |
| 2514 |
** o '%' is used to introduce a trailing comment, so '%' can't be included |
| 2515 |
** in the \uppercase section. You can't use ^^25 either. |
| 2516 |
** |
| 2517 |
** o you cannot redefine the upper case equivalent of an ASCII character |
| 2518 |
** (code < 128). In other words, all "left hand" characters in the |
| 2519 |
** relationship pairs must have codes > 127. |
| 2520 |
**============================================================================ |
| 2521 |
*/ |
| 2522 |
static void c8read_uppercase (void) |
| 2523 |
{ |
| 2524 |
int c; |
| 2525 |
int lowercase_val; |
| 2526 |
|
| 2527 |
debug_msg (DBG_CSF, "reading the \\uppercase section ... "); |
| 2528 |
lowercase_val = -1; |
| 2529 |
|
| 2530 |
/* |
| 2531 |
** Keep reading characters until the end of the section is encountered |
| 2532 |
** at a '}' or EOF is reached. |
| 2533 |
*/ |
| 2534 |
c = getc (c8_cs_file); |
| 2535 |
|
| 2536 |
while ((c != '}') && (! feof (c8_cs_file))) { |
| 2537 |
|
| 2538 |
/* |
| 2539 |
** Characters may be specified using the TeX syntax for the |
| 2540 |
** 8-bit code, i.e. ^^XX, where XX is the hexadecimal value. |
| 2541 |
** We should really check the result of this fscanf(). |
| 2542 |
*/ |
| 2543 |
if (c == '^') |
| 2544 |
fscanf (c8_cs_file, "^%x", &c); |
| 2545 |
|
| 2546 |
/* |
| 2547 |
** If we have reached the end of a line, simply increment the |
| 2548 |
** line count. |
| 2549 |
*/ |
| 2550 |
if (c == '\n') { |
| 2551 |
c8_line++; |
| 2552 |
} |
| 2553 |
|
| 2554 |
/* |
| 2555 |
** If we encounter a '%', it signifies the start of a comment. |
| 2556 |
** Ignore characters until the end of line is reached. |
| 2557 |
*/ |
| 2558 |
else if (c == '%') { |
| 2559 |
do { |
| 2560 |
c = getc(c8_cs_file); |
| 2561 |
} while ((c != '\n') && (! feof( c8_cs_file))); |
| 2562 |
continue; |
| 2563 |
} |
| 2564 |
|
| 2565 |
/* |
| 2566 |
** The normal case is for alpha characters to be included in the |
| 2567 |
** case relationship. Alpha characters are assumed to be ASCII |
| 2568 |
** alpha (A..Za..z) plus any character with a code > 127. |
| 2569 |
*/ |
| 2570 |
else if (c8is_alpha (c)) { |
| 2571 |
|
| 2572 |
/* |
| 2573 |
** The case relationship consists of a pair of alpha characters |
| 2574 |
** separated by whitespace. In the \uppercase section, the pair |
| 2575 |
** is in the order <lowercase-char> <uppercase-char>. We |
| 2576 |
** must remember which character we are looking for - this is |
| 2577 |
** achieved by setting lowercase_val to -1 when we are |
| 2578 |
** looking for the first character of a pair. |
| 2579 |
** |
| 2580 |
** If lowercase_val is < 0, we treat the current character as |
| 2581 |
** the lower case member of the pair and set lowercase_val |
| 2582 |
** accordingly. |
| 2583 |
*/ |
| 2584 |
if (lowercase_val < 0) |
| 2585 |
lowercase_val = c; |
| 2586 |
else { |
| 2587 |
|
| 2588 |
/* |
| 2589 |
** We are not allowed to redefine the upper case |
| 2590 |
** equivalent of an ASCII character. |
| 2591 |
*/ |
| 2592 |
if (lowercase_val < 127) { |
| 2593 |
PRINT_LN2 ("Error: attempt to redefine upper case of " |
| 2594 |
"an ASCII character [0x%02x]", lowercase_val); |
| 2595 |
PRINT_LN3 ("Context: line %04d: of CS file %s", |
| 2596 |
c8_line, Str_csfile); |
| 2597 |
} |
| 2598 |
|
| 2599 |
/* |
| 2600 |
** All OK, so set the appropriate element of the c8lowcase |
| 2601 |
** array and reset the value of lowercase_val to signify |
| 2602 |
** that we are looking for the next pair. |
| 2603 |
*/ |
| 2604 |
else { |
| 2605 |
c8upcase[lowercase_val] = c; |
| 2606 |
lowercase_val = -1; |
| 2607 |
} |
| 2608 |
} |
| 2609 |
} /* end if */ |
| 2610 |
|
| 2611 |
/* |
| 2612 |
** Get the next character from the file and start the loop again. |
| 2613 |
*/ |
| 2614 |
c = getc (c8_cs_file); |
| 2615 |
} /* end while */ |
| 2616 |
|
| 2617 |
/* |
| 2618 |
** The only normal reason for breaking out of the while loop is that |
| 2619 |
** we encountered '}' at the end of the \uppercase section. Two |
| 2620 |
** conditions should be true: |
| 2621 |
** |
| 2622 |
** (lowercase_val = -1) - there is an unmatched character |
| 2623 |
** (c == '}') - the terminating '}' has been read |
| 2624 |
*/ |
| 2625 |
if (lowercase_val != -1){ |
| 2626 |
PRINT_LN ("Error: unmatched character pair in \\uppercase section"); |
| 2627 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2628 |
} |
| 2629 |
|
| 2630 |
if (c != '}') { |
| 2631 |
PRINT_LN ("Error: unexpected end of file in \\uppercase section"); |
| 2632 |
PRINT_LN3 ("Context: line %04d: of CS file %s", c8_line, Str_csfile); |
| 2633 |
} |
| 2634 |
|
| 2635 |
debug_msg (DBG_CSF, "finished reading the \\uppercase section."); |
| 2636 |
} /* c8read_uppercase () */ |
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
/* |
| 2641 |
**============================================================================ |
| 2642 |
** c8report_8bit_handling() |
| 2643 |
** |
| 2644 |
** Report the internal status of BibTeX's 8-bit character set handling. The |
| 2645 |
** information reported is: |
| 2646 |
** |
| 2647 |
** o 8-bit characters defined as type ALPHA |
| 2648 |
** o character codes with upper case equivalents |
| 2649 |
** o character codes with lower case equivalents |
| 2650 |
** o the character codes in sorting weight order |
| 2651 |
**============================================================================ |
| 2652 |
*/ |
| 2653 |
void c8report_8bit_handling (void) |
| 2654 |
{ |
| 2655 |
int c; |
| 2656 |
int column; |
| 2657 |
int weight; |
| 2658 |
|
| 2659 |
/* |
| 2660 |
** Exit immediately if the CSF debugging option hasn't been selected. |
| 2661 |
*/ |
| 2662 |
if ((Flag_debug & DBG_CSF) == 0) |
| 2663 |
return; |
| 2664 |
|
| 2665 |
/* |
| 2666 |
** Report the 8-bit characters defined as type ALPHA, 16 to a row. |
| 2667 |
*/ |
| 2668 |
fprintf (stderr, "\nD-CSF: 8-bit ALPHA characters\n"); |
| 2669 |
fprintf (stderr, "D-CSF: ----------------------\n"); |
| 2670 |
|
| 2671 |
for (c = 128; c <= 255; c += 16) { |
| 2672 |
fprintf (stderr, "D-CSF: %02x: ", c); |
| 2673 |
|
| 2674 |
for (column = 0; column < 16; column++) { |
| 2675 |
if (lex_class[c + column] == ALPHA) |
| 2676 |
fprintf (stderr, "%c ", c + column); |
| 2677 |
else |
| 2678 |
fputs (". ", stderr); |
| 2679 |
} |
| 2680 |
fputc ('\n', stderr); |
| 2681 |
} |
| 2682 |
|
| 2683 |
/* |
| 2684 |
** Report the lower / upper case relationships, three pairs to a row. |
| 2685 |
*/ |
| 2686 |
fprintf (stderr, "\nD-CSF: Characters with upper case equivalents\n"); |
| 2687 |
fprintf (stderr, "D-CSF: --------------------------------------"); |
| 2688 |
column = 0; |
| 2689 |
|
| 2690 |
for (c = 1; c <= 255; c++) |
| 2691 |
if (c8upcase[c] != c) { |
| 2692 |
if ((column % 3) == 0) |
| 2693 |
fprintf (stderr, "\nD-CSF: %c [%02x] <<< %c [%02x]", |
| 2694 |
c, (int) c, c8upcase[c], (int) c8upcase[c]); |
| 2695 |
else |
| 2696 |
fprintf (stderr, " %c [%02x] <<< %c [%02x]", |
| 2697 |
c, (int) c, c8upcase[c], (int) c8upcase[c]); |
| 2698 |
++column; |
| 2699 |
} |
| 2700 |
|
| 2701 |
/* |
| 2702 |
** Report the upper / lower case relationships, three pairs to a row. |
| 2703 |
*/ |
| 2704 |
fprintf (stderr, "\n\nD-CSF: Characters with lower case equivalents\n"); |
| 2705 |
fprintf (stderr, "D-CSF: --------------------------------------"); |
| 2706 |
column = 0; |
| 2707 |
|
| 2708 |
for (c = 1; c <= 255; c++) |
| 2709 |
if (c8lowcase[c] != c) { |
| 2710 |
if ((column % 3) == 0) |
| 2711 |
fprintf (stderr, "\nD-CSF: %c [%02x] >>> %c [%02x]", |
| 2712 |
c, (int) c, c8lowcase[c], (int) c8lowcase[c]); |
| 2713 |
else |
| 2714 |
fprintf (stderr, " %c [%02x] >>> %c [%02x]", |
| 2715 |
c, (int) c, c8lowcase[c], (int) c8lowcase[c]); |
| 2716 |
++column; |
| 2717 |
} |
| 2718 |
|
| 2719 |
/* |
| 2720 |
** Report character codes in sorting weight order. If BibTeX is |
| 2721 |
** operating in --traditional or --8bit mode, sorting order is simply |
| 2722 |
** character code order. In that case, just give an abbreviated |
| 2723 |
** summary. |
| 2724 |
*/ |
| 2725 |
fprintf (stderr, "\n\nD-CSF: Characters in sorting order\n"); |
| 2726 |
fprintf (stderr, "D-CSF: ---------------------------\n"); |
| 2727 |
|
| 2728 |
if (Flag_7bit || Flag_8bit) { |
| 2729 |
fprintf (stderr, "D-CSF: 00: [00]\n"); |
| 2730 |
fprintf (stderr, "D-CSF: 01: [01]\n"); |
| 2731 |
fprintf (stderr, "D-CSF: .. ....\n"); |
| 2732 |
fprintf (stderr, "D-CSF: 41: A [41]\n"); |
| 2733 |
fprintf (stderr, "D-CSF: .. ....\n"); |
| 2734 |
fprintf (stderr, "D-CSF: 5a: Z [5a]\n"); |
| 2735 |
fprintf (stderr, "D-CSF: .. ....\n"); |
| 2736 |
fprintf (stderr, "D-CSF: 61: a [61]\n"); |
| 2737 |
fprintf (stderr, "D-CSF: .. ....\n"); |
| 2738 |
fprintf (stderr, "D-CSF: 7a: z [7a]\n"); |
| 2739 |
fprintf (stderr, "D-CSF: .. ....\n"); |
| 2740 |
fprintf (stderr, "D-CSF: fe: [fe]\n"); |
| 2741 |
fprintf (stderr, "D-CSF: ff: [ff]\n\n"); |
| 2742 |
} |
| 2743 |
|
| 2744 |
/* |
| 2745 |
** When a CS file has been used, sort_weight will be set to the value of |
| 2746 |
** the highest sorting weight. Report every character with a given |
| 2747 |
** sorting weight, for 0 <= weight < sort_weight. |
| 2748 |
*/ |
| 2749 |
else { |
| 2750 |
for (weight = 0; weight < sort_weight; weight++) { |
| 2751 |
fprintf (stderr, "D-CSF: %02x: ", weight); |
| 2752 |
|
| 2753 |
for (c = 0; c <= 255; c++) { |
| 2754 |
if (c8order[c] == weight) |
| 2755 |
fprintf (stderr, "%c [%02x] ", c, c); |
| 2756 |
} |
| 2757 |
fputc ('\n', stderr); |
| 2758 |
} |
| 2759 |
fprintf (stderr, "D-CSF: (All other characters are sorted " |
| 2760 |
"equally after any of the above.)\n\n"); |
| 2761 |
} |
| 2762 |
} /* c8report_8bit_handling() */ |
| 2763 |
|
| 2764 |
|
| 2765 |
#endif /* SUPPORT_8BIT */ |