| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#include <bibtool/bibtool.h> |
| 65 |
#include <bibtool/sbuffer.h> |
| 66 |
#include <bibtool/crossref.h> |
| 67 |
#include <bibtool/check.h> |
| 68 |
#include <bibtool/io.h> |
| 69 |
#ifdef HAVE_LIBKPATHSEA |
| 70 |
#ifdef __STDC__ |
| 71 |
#define HAVE_PROTOTYPES |
| 72 |
#endif |
| 73 |
#include <kpathsea/debug.h> |
| 74 |
#endif |
| 75 |
#include "config.h" |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
#ifdef __STDC__ |
| 82 |
#define _ARG(A) A |
| 83 |
#else |
| 84 |
#define _ARG(A) () |
| 85 |
#endif |
| 86 |
int main _ARG((int argc,char *argv[])); |
| 87 |
static bool do_keys _ARG((DB db,Record rec)); |
| 88 |
static bool do_no_keys _ARG((DB db,Record rec)); |
| 89 |
static bool update_crossref _ARG((DB db,Record rec)); |
| 90 |
static int rec_gt _ARG((Record r1,Record r2)); |
| 91 |
static int rec_gt_cased _ARG((Record r1,Record r2)); |
| 92 |
static int rec_lt _ARG((Record r1,Record r2)); |
| 93 |
static int rec_lt_cased _ARG((Record r1,Record r2)); |
| 94 |
static void usage _ARG((bool fullp)); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
#ifndef __STDC__ |
| 103 |
#ifndef HAVE_GETENV |
| 104 |
|
| 105 |
char * getenv _ARG((char *name)); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
char * getenv(name) |
| 111 |
char *name; |
| 112 |
{ return (char*)NULL; |
| 113 |
} |
| 114 |
#endif |
| 115 |
#endif |
| 116 |
|
| 117 |
|
| 118 |
#ifndef OptionLeadingCharacter |
| 119 |
#define OptionLeadingCharacter '-' |
| 120 |
#endif |
| 121 |
|
| 122 |
static char *use[] = |
| 123 |
{ "bibtool [options] [%co outfile] [[%ci] infile] ...\n", |
| 124 |
"\n\tOptions:\n", |
| 125 |
"\t%cA<c>\t\tKind of disambiguating key strings: <c>=0|a|A\n", |
| 126 |
"\t%cc\t\tInclude crossreferenced entries into the output (toggle)\n", |
| 127 |
"\t%cd\t\tCheck double entries (toggle)\n", |
| 128 |
"\t%cf <format>\tKey generation enabled (formatted key)\n", |
| 129 |
"\t%cF\t\tKey generation enabled with formatted key\n", |
| 130 |
"\t%ch\t\tPrint this help info and exit\n", |
| 131 |
"\t[%ci] infile\tSpecify input file. If %ci omitted it may not start\n", |
| 132 |
"\t\t\twith a %c. If absent stdin is taken to read from.\n", |
| 133 |
"\t\t\tMultiple input files may be given.\n", |
| 134 |
"\t%ck\t\tKey generation enabled.\n", |
| 135 |
"\t%cK\t\tKey generation enabled (long key).\n", |
| 136 |
"\t%cm macfile\tDump macros to macfile. - is stdout\n", |
| 137 |
"\t%cM macfile\tDump used macros to macfile. - is stdout\n", |
| 138 |
"\t%co outfile\tSpecify output file as next argument\n", |
| 139 |
"\t\t\tIf absent stdout is taken to write to.\n", |
| 140 |
"\t%cq\t\tQuiet mode. No warnings.\n", |
| 141 |
"\t%cr resource\tLoad resource file (several are possible).\n", |
| 142 |
"\t%cR\t\tLoad default resource file here.\n", |
| 143 |
"\t%cs\t\tSort.\n", |
| 144 |
"\t%cS\t\tSort reverse.\n", |
| 145 |
"\t%cv\t\tEnable verbose mode.\n", |
| 146 |
"\t%cV\t\tPrint version and exit.\n", |
| 147 |
"\t%cx file\t\tExtract from aux file.\n", |
| 148 |
"\t%cX <regex>\tExtract regular expression.\n", |
| 149 |
"\t%c- <rsc>\tEvaluate one resource command <rsc>.\n", |
| 150 |
"\t%c@\t\tPrint statistics (short).\n", |
| 151 |
"\t%c#\t\tPrint statistics.\n", |
| 152 |
#ifdef SYMBOL_DUMP |
| 153 |
"\t%c$\t\tSymbol table output (debugging only)\n", |
| 154 |
#endif |
| 155 |
0L, |
| 156 |
"Copyright (C) 2019 Gerd Neugebauer", |
| 157 |
"[email protected]" |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static void usage(fullp) |
| 173 |
bool fullp; |
| 174 |
{ static char *comma = ", "; |
| 175 |
char *sep = " "; |
| 176 |
POSSIBLY_UNUSED(comma); |
| 177 |
POSSIBLY_UNUSED(sep); |
| 178 |
|
| 179 |
show_version(); |
| 180 |
|
| 181 |
if (fullp) |
| 182 |
{ register char **cpp; |
| 183 |
for (cpp = use; *cpp; cpp++) |
| 184 |
{ ErrPrintF2(*cpp, |
| 185 |
OptionLeadingCharacter, |
| 186 |
OptionLeadingCharacter); |
| 187 |
} |
| 188 |
ErrPrint("\n"); |
| 189 |
} |
| 190 |
|
| 191 |
ErrPrintF("Library path: %s", |
| 192 |
(rsc_v_rsc == NULL |
| 193 |
? "none" |
| 194 |
: (char*)rsc_v_rsc)); |
| 195 |
|
| 196 |
ErrPrint("\nSpecial configuration options:"); |
| 197 |
#define SPECIAL_OPTIONS " none" |
| 198 |
#ifdef HAVE_LIBKPATHSEA |
| 199 |
ErrPrintF("%skpathsea",sep); |
| 200 |
sep = comma; |
| 201 |
#undef SPECIAL_OPTIONS |
| 202 |
#define SPECIAL_OPTIONS "" |
| 203 |
#endif |
| 204 |
#ifndef REGEX |
| 205 |
ErrPrintF("%sNO regex",sep); |
| 206 |
sep = comma; |
| 207 |
#undef SPECIAL_OPTIONS |
| 208 |
#define SPECIAL_OPTIONS "" |
| 209 |
#endif |
| 210 |
#ifdef EMTEX_LIKE_PATH |
| 211 |
ErrPrintF("%semTeX like path",sep); |
| 212 |
#undef SPECIAL_OPTIONS |
| 213 |
#define SPECIAL_OPTIONS "" |
| 214 |
#endif |
| 215 |
ErrPrintF("%s\n",SPECIAL_OPTIONS); |
| 216 |
} |
| 217 |
|
| 218 |
#define UnknownWarning(X) WARNING2("Unknown flag ignored: ", X) |
| 219 |
#define NoSFileWarning WARNING("Missing select option. Flag ignored.") |
| 220 |
#define NoFileError(X) WARNING3("File ", SymbolValue(X), " not found.") |
| 221 |
#define MissingPattern WARNING("Missing pattern.") |
| 222 |
#define MissingResource WARNING("Missing resource.") |
| 223 |
#define NoRscError(X) WARNING3("Resource file ", X, " not found.") |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
static bool keep_selected(db, rec) |
| 241 |
DB db; |
| 242 |
Record rec; |
| 243 |
{ |
| 244 |
if (!is_selected(db, rec)) |
| 245 |
{ SetRecordDELETED(rec); } |
| 246 |
|
| 247 |
return false; |
| 248 |
} |
| 249 |
|
| 250 |
#ifdef UNUSED |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
static bool keep_xref(db,rec) |
| 262 |
DB db; |
| 263 |
Record rec; |
| 264 |
{ |
| 265 |
if (!RecordIsDELETED(rec)) |
| 266 |
{ Symbol key; |
| 267 |
int count; |
| 268 |
|
| 269 |
for (count = rsc_xref_limit; |
| 270 |
count >= 0; |
| 271 |
count--) |
| 272 |
{ |
| 273 |
if ((key = get_field(db,rec,sym_crossref)) == NULL) |
| 274 |
{ return false; } |
| 275 |
|
| 276 |
key = expand_rhs(key, |
| 277 |
sym_empty, |
| 278 |
sym_empty, |
| 279 |
db, |
| 280 |
true); |
| 281 |
if ((rec=db_search(db, key)) == RecordNULL) |
| 282 |
{ ErrPrintF("*** BibTool: Crossref `%s' not found.\n", |
| 283 |
SymbolValue(key)); |
| 284 |
return false; |
| 285 |
} |
| 286 |
|
| 287 |
if (!RecordIsDELETED(rec)) { return false; } |
| 288 |
ClearRecordDELETED(rec); |
| 289 |
} |
| 290 |
|
| 291 |
ErrPrintF("*** BibTool: Crossref limit exceeded; `%s' possibly looped.\n", |
| 292 |
SymbolValue(key)); |
| 293 |
} |
| 294 |
return false; |
| 295 |
} |
| 296 |
#endif |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
static void write_macros(m_file, the_db) |
| 309 |
char* m_file; |
| 310 |
DB the_db; |
| 311 |
{ FILE * file; |
| 312 |
|
| 313 |
if (m_file == NULL || *m_file == 0) return; |
| 314 |
|
| 315 |
if (rsc_verbose) |
| 316 |
{ VerbosePrint1("Writing macros"); } |
| 317 |
|
| 318 |
if (strcmp(m_file,"-") == 0 || |
| 319 |
(file=fopen(m_file,"w")) == NULL) |
| 320 |
{ file = stdout; } |
| 321 |
print_db(file,the_db,rsc_all_macs?"s":"S"); |
| 322 |
if (file != stdout) { fclose(file); } |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
static void read_in_files(db) |
| 336 |
DB db; |
| 337 |
{ int i; |
| 338 |
Symbol in; |
| 339 |
|
| 340 |
for (i = 0; i < get_no_inputs(); i++) |
| 341 |
{ in = get_input_file(i); |
| 342 |
if (read_db(db, SymbolValue(in), rsc_verbose)) |
| 343 |
{ NoFileError(in); } |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
static void write_output(db) |
| 357 |
DB db; |
| 358 |
{ FILE *file; |
| 359 |
Symbol o_file = get_output_file(); |
| 360 |
|
| 361 |
if (o_file == NO_SYMBOL) |
| 362 |
{ file = stdout; } |
| 363 |
else if (*o_file == '\0') |
| 364 |
{ return; } |
| 365 |
else if ((file=fopen((char*)SymbolValue(o_file),"w")) == NULL) |
| 366 |
{ file = stdout; |
| 367 |
} |
| 368 |
|
| 369 |
if (rsc_select) { rsc_del_q = false; } |
| 370 |
|
| 371 |
{ char * print_spec = (char*)rsc_print_et; |
| 372 |
|
| 373 |
if (rsc_expand_macros) |
| 374 |
{ char * cp; |
| 375 |
print_spec = new_string(print_spec); |
| 376 |
for (cp=print_spec; *cp; cp++) |
| 377 |
{ if (*cp == 's' || |
| 378 |
*cp == 'S' || |
| 379 |
*cp == '$' ) *cp = ' '; |
| 380 |
} |
| 381 |
} |
| 382 |
print_db(file, db, print_spec); |
| 383 |
if (rsc_expand_macros) free(print_spec); |
| 384 |
} |
| 385 |
|
| 386 |
if (file != stdout) { fclose(file); } |
| 387 |
} |
| 388 |
|
| 389 |
#define Toggle(X) X = !(X) |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
int main(argc,argv) |
| 406 |
int argc; |
| 407 |
char *argv[]; |
| 408 |
{ DB the_db; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
int i; |
| 416 |
bool need_rsc = true; |
| •417 |
int (*fct)(struct rECORD *, struct rECORD *); |
| 418 |
int c_len; |
| 419 |
int *c = NULL; |
| 420 |
|
| 421 |
init_error(stderr); |
| 422 |
init_bibtool(argv[0]); |
| 423 |
|
| 424 |
for (i = 1; i < argc; i++) |
| 425 |
{ char *ap; |
| 426 |
if (*(ap=argv[i]) != OptionLeadingCharacter) |
| 427 |
{ save_input_file(symbol((String)argv[i])); |
| 428 |
} |
| 429 |
else |
| 430 |
{ switch (*++ap) |
| 431 |
{ case 'A': set_base((String)(ap+1)); break; |
| 432 |
case 'c': Toggle(rsc_xref_select); break; |
| 433 |
case 'd': Toggle(rsc_double_check); break; |
| 434 |
#ifdef HAVE_LIBKPATHSEA |
| 435 |
case 'D': kpathsea_debug=atoi(++ap); break; |
| 436 |
#endif |
| 437 |
case 'f': add_format(argv[++i]); |
| 438 |
case 'F': rsc_make_key = true; break; |
| 439 |
case 'h': usage(true); return 1; |
| 440 |
case 'i': save_input_file(symbol((String)argv[++i])); break; |
| 441 |
case 'K': add_format("long"); break; |
| 442 |
case 'k': add_format("short"); break; |
| 443 |
case 'M': |
| 444 |
case 'm': rsc_all_macs = (*ap=='m'); |
| 445 |
save_macro_file(symbol((String)argv[++i])); |
| 446 |
break; |
| 447 |
case 'o': |
| 448 |
if (++i < argc) |
| 449 |
{ save_output_file(symbol((String)argv[i])); } |
| 450 |
else |
| 451 |
{ WARNING((String)"Missing output file name"); } |
| 452 |
break; |
| 453 |
case 'q': Toggle(rsc_quiet); break; |
| 454 |
case 'r': |
| 455 |
if (++i < argc && load_rsc((String)(argv[i]))) |
| 456 |
{ need_rsc = false; } |
| 457 |
else |
| 458 |
{ NoRscError(argv[i]); } |
| 459 |
break; |
| 460 |
case 'R': need_rsc |= !search_rsc();break; |
| 461 |
case 's': Toggle(rsc_sort); break; |
| 462 |
case 'S': |
| 463 |
Toggle(rsc_sort); |
| 464 |
Toggle(rsc_sort_reverse); |
| 465 |
break; |
| 466 |
case 'v': Toggle(rsc_verbose); break; |
| 467 |
case 'V': usage(false); return 1; |
| 468 |
case 'x': |
| 469 |
rsc_all_macs = false; |
| 470 |
if (++i < argc) |
| 471 |
{ read_aux((String)(argv[i]), |
| 472 |
save_input_file, |
| 473 |
*++ap=='v'); |
| 474 |
} |
| 475 |
else |
| 476 |
{ NoSFileWarning; } |
| 477 |
break; |
| 478 |
case 'X': |
| 479 |
rsc_all_macs = false; |
| 480 |
if (++i < argc) { save_regex((String)argv[i]); } |
| 481 |
else { MissingPattern; } |
| 482 |
break; |
| 483 |
case '#': Toggle(rsc_cnt_all); break; |
| 484 |
case '@': Toggle(rsc_cnt_used); break; |
| 485 |
case '-': |
| 486 |
if (*++ap) { (void)use_rsc((String)ap); } |
| 487 |
else if (++i<argc){ (void)use_rsc((String)argv[i]); } |
| 488 |
else { MissingResource; } |
| 489 |
break; |
| 490 |
#ifdef SYMBOL_DUMP |
| 491 |
case '$': Toggle(rsc_dump_symbols); break; |
| 492 |
#endif |
| 493 |
default: |
| 494 |
UnknownWarning(ap); |
| 495 |
usage(true); |
| 496 |
return 1; |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
if (need_rsc) { (void)search_rsc(); } |
| 502 |
|
| 503 |
if (get_no_inputs() == 0) |
| 504 |
{ save_input_file(symbol((String)"-")); } |
| 505 |
|
| 506 |
init_read(); |
| 507 |
|
| 508 |
the_db = new_db(); |
| 509 |
|
| 510 |
read_in_files(the_db); |
| 511 |
|
| 512 |
db_forall(the_db, keep_selected); |
| 513 |
|
| 514 |
apply_aux(the_db); |
| 515 |
|
| 516 |
if (rsc_xref_select) db_xref_undelete(the_db); |
| 517 |
|
| 518 |
if (rsc_cnt_all || rsc_cnt_used) |
| 519 |
{ int i; |
| 520 |
int * cnt = db_count(the_db,&c_len); |
| 521 |
|
| 522 |
if ((c=(int*)malloc(c_len*sizeof(int))) == NULL) |
| 523 |
{ rsc_cnt_all = rsc_cnt_used = 0; } |
| 524 |
else |
| 525 |
{ for (i = 0; i < c_len; i++) c[i] = cnt[i]; |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
if (rsc_expand_crossref || rsc_expand_xdata) |
| 530 |
{ |
| 531 |
db_forall(the_db,expand_crossref); |
| 532 |
} |
| 533 |
|
| 534 |
if (rsc_sort || rsc_make_key || need_sort_key) { |
| 535 |
DebugPrint1("start keygen"); |
| 536 |
start_key_gen(); |
| 537 |
} |
| 538 |
|
| 539 |
if (rsc_make_key) |
| 540 |
{ |
| 541 |
if (rsc_key_preserve) |
| 542 |
{ db_forall(the_db, mark_key); } |
| 543 |
|
| 544 |
DebugPrint1("rewinding"); |
| 545 |
db_rewind(the_db); |
| 546 |
|
| 547 |
DebugPrint1("do_keys"); |
| 548 |
db_forall(the_db, do_keys); |
| 549 |
|
| 550 |
DebugPrint1("update crossref"); |
| 551 |
db_forall(the_db, update_crossref); |
| 552 |
|
| 553 |
DebugPrint1("end keygen"); |
| 554 |
end_key_gen(); |
| 555 |
} |
| 556 |
else |
| 557 |
{ |
| 558 |
db_forall(the_db,do_no_keys); |
| 559 |
} |
| 560 |
|
| 561 |
if (rsc_sort) |
| 562 |
{ |
| 563 |
if (rsc_sort_cased) |
| 564 |
{ if (rsc_sort_reverse) fct = rec_lt_cased; |
| 565 |
else fct = rec_gt_cased; |
| 566 |
} |
| 567 |
else |
| 568 |
{ if (rsc_sort_reverse) fct = rec_lt; |
| 569 |
else fct = rec_gt; |
| 570 |
} |
| 571 |
db_sort(the_db, fct); |
| 572 |
} |
| 573 |
|
| 574 |
if (rsc_srt_macs) |
| 575 |
{ db_mac_sort(the_db); } |
| 576 |
|
| 577 |
apply_checks(the_db); |
| 578 |
|
| 579 |
write_output(the_db); |
| 580 |
|
| 581 |
write_macros(get_macro_file(), the_db); |
| 582 |
|
| 583 |
if (rsc_cnt_all || rsc_cnt_used) |
| 584 |
{ int i; |
| 585 |
int *cnt = db_count(the_db, (int*)NULL); |
| 586 |
|
| 587 |
ErrC('\n'); |
| 588 |
for (i = 0; i < c_len; ++i) |
| 589 |
{ if (rsc_cnt_all || c[i] > 0) |
| 590 |
{ ErrPrintF3("--- %-15s %5d read %5d written\n", |
| 591 |
SymbolValue(get_entry_type(i)), |
| 592 |
c[i], |
| 593 |
cnt[i]); |
| 594 |
} |
| 595 |
} |
| 596 |
free(c); |
| 597 |
} |
| 598 |
|
| 599 |
#ifdef SYMBOL_DUMP |
| 600 |
if (rsc_dump_symbols) sym_dump(); |
| 601 |
#endif |
| 602 |
|
| 603 |
#ifdef FREE_MEMORY |
| 604 |
free_db(the_db); |
| 605 |
the_db = NULL; |
| 606 |
sym_gc(); |
| 607 |
#ifdef SYMBOL_DUMP |
| 608 |
sym_dump(); |
| 609 |
#endif |
| 610 |
#endif |
| 611 |
return 0; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
static int rec_gt(r1, r2) |
| 625 |
Record r1; |
| 626 |
Record r2; |
| 627 |
{ return symcmp(RecordSortkey(r1), |
| 628 |
RecordSortkey(r2)) < 0; |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
static int rec_lt(r1, r2) |
| 642 |
Record r1; |
| 643 |
Record r2; |
| 644 |
{ return symcmp(RecordSortkey(r1), |
| 645 |
RecordSortkey(r2)) > 0; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
static int rec_gt_cased(r1, r2) |
| 659 |
Record r1; |
| 660 |
Record r2; |
| 661 |
{ return symcmp(get_key(RecordSortkey(r1)), |
| 662 |
get_key(RecordSortkey(r2))) < 0; |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
static int rec_lt_cased(r1, r2) |
| 676 |
Record r1; |
| 677 |
Record r2; |
| 678 |
{ return symcmp(get_key(RecordSortkey(r1)), |
| 679 |
get_key(RecordSortkey(r2))) > 0; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
static bool do_keys(db, rec) |
| 690 |
DB db; |
| 691 |
Record rec; |
| 692 |
{ |
| 693 |
rewrite_record(db, rec); |
| 694 |
sort_record(rec); |
| 695 |
make_key(db,rec); |
| 696 |
if (rsc_sort || rsc_double_check || need_sort_key) |
| 697 |
{ make_sort_key(db,rec); } |
| 698 |
return false; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
static bool do_no_keys(db, rec) |
| 710 |
DB db; |
| 711 |
Record rec; |
| 712 |
{ |
| 713 |
rewrite_record(db, rec); |
| 714 |
sort_record(rec); |
| 715 |
mark_key(db,rec); |
| 716 |
if (rsc_sort || rsc_double_check || need_sort_key) |
| 717 |
{ make_sort_key(db,rec); } |
| 718 |
return false; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
static bool update_crossref(db, rec) |
| 732 |
DB db; |
| 733 |
Record rec; |
| 734 |
{ register Symbol *hp; |
| 735 |
register int i; |
| 736 |
Symbol s; |
| 737 |
String t; |
| 738 |
|
| 739 |
if (!RecordIsXREF(rec)) return false; |
| 740 |
|
| 741 |
for (i = RecordFree(rec), hp = RecordHeap(rec); |
| 742 |
i > 0 && *hp != sym_crossref; |
| 743 |
i -= 2, hp += 2) |
| 744 |
{ } |
| 745 |
if (i <= 0) |
| 746 |
{ DebugPrint1("*** No crossref found."); |
| 747 |
return false; |
| 748 |
} |
| 749 |
|
| 750 |
t = SymbolValue(*++hp); t++; |
| 751 |
sp_open(t); |
| 752 |
if ((s = SParseSymbol(&t)) == NO_SYMBOL) |
| 753 |
{ return false; } |
| 754 |
|
| 755 |
if ((s = db_new_key(db, s)) == NO_SYMBOL) |
| 756 |
{ ERROR2("Crossref not found: ",(char*)s); |
| 757 |
return false; |
| 758 |
} |
| 759 |
if (rsc_key_case) { s = get_key(s); } |
| 760 |
if ((t=(String)malloc((size_t)symlen(s) + 3)) |
| 761 |
== StringNULL) |
| 762 |
{ OUT_OF_MEMORY("update_crossref()"); } |
| 763 |
|
| 764 |
(void)sprintf((char*)t, |
| 765 |
(*SymbolValue(*hp) == '"' |
| 766 |
? "\"%s\"" |
| 767 |
: "{%s}"), |
| 768 |
SymbolValue(s)); |
| 769 |
*hp = symbol(t); |
| 770 |
free(t); |
| 771 |
return false; |
| 772 |
} |
| 773 |
|
| 774 |
#ifdef DEBUG |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
void printchar(c) |
| 783 |
register char c; |
| 784 |
{ ErrC(c); |
| 785 |
} |
| 786 |
#endif |