Debian Codegraph @

key.c

raw symbols SCIP
1 /*** key.c ********************************************************************
2 **
3 ** This file is part of BibTool.
4 ** It is distributed under the GNU General Public License.
5 ** See the file COPYING for details.
6 **
7 ** (c) 1996-2020 Gerd Neugebauer
8 **
9 ** Net: [email protected]
10 **
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License as published by
13 ** the Free Software Foundation; either version 2, or (at your option)
14 ** any later version.
15 **
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
20 **
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 **
25 ******************************************************************************/
26
27 #include <bibtool/general.h>
28 #include <bibtool/symbols.h>
29 #include <bibtool/type.h>
30 #include <bibtool/entry.h>
31 #include <bibtool/error.h>
32 #include <bibtool/key.h>
33 #include <bibtool/rsc.h>
34 #include <bibtool/names.h>
35 #include <bibtool/tex_read.h>
36 #include <bibtool/wordlist.h>
37 #include <bibtool/expand.h>
38 #ifdef HAVE_TIME_H
39 #include <time.h>
40 #endif
41 #include "config.h"
42
43 /*****************************************************************************/
44 /* Internal Programs */
45 /*===========================================================================*/
46
47 #ifdef __STDC__
48 #define _ARG(A) A
49 #else
50 #define _ARG(A) ()
51 #endif
52 static KeyNode new_key_node _ARG((int type,Symbol sym));/* key.c */
53 static bool fmt_digits _ARG((StringBuffer *sb,String s,int mp,int pp,int n,int sel,bool trunc));/* key.c*/
54 static bool fmt_c_words _ARG((String line,int min,int max,bool not,bool ignore));/* key.c*/
55 static bool fmt_c_names _ARG((String line,int min,int max,bool not));/* key.c*/
56 static bool fmt_c_string _ARG((String s,int min,int max,bool not));/* key.c */
57 static bool add_fmt_tree _ARG((char *s,KeyNode *treep));/* key.c */
58 static bool eval__fmt _ARG((StringBuffer *sb,KeyNode kn,Record rec));/* key.c*/
59 static bool eval_fmt _ARG((StringBuffer *sb,KeyNode kn,Record rec,DB db));/* key.c*/
60 static char * itostr _ARG((int i,char *digits)); /* key.c */
61 static int deTeX _ARG((String line,void (*save_fct)_ARG((String)),int commap));/*key.c*/
62 static int fmt__parse _ARG((char **sp,KeyNode *knp));/* key.c */
63 static int fmt_parse _ARG((char **sp,KeyNode *knp));/* key.c */
64 static void Push_Word _ARG((String s)); /* key.c */
65 static void eval__special _ARG((StringBuffer *sb,KeyNode kn,Record rec));/* key.c*/
66 static void fmt_names _ARG((StringBuffer *sb,String line,int maxname,int post,String trans));/* key.c*/
67 static void fmt_string _ARG((StringBuffer *sb,String s,int n,String trans,String sep));/* key.c*/
68 static void fmt_title _ARG((StringBuffer *sb,String line,int len,int in,String trans,bool ignore,Symbol sep));/* key.c*/
69 static void init_key _ARG(()); /* key.c */
70 static void key_init _ARG((void)); /* key.c */
71 static void push_s _ARG((StringBuffer *sb,String s,int max,String trans));/* key.c*/
72 static void push_word _ARG((String s)); /* key.c */
73
74 #ifdef DEBUG
75 static void show_fmt _ARG((KeyNode kn,int in)); /* key.c */
76 #endif
77
78 /*****************************************************************************/
79 /* External Programs */
80 /*===========================================================================*/
81
82 static DB tmp_key_db;
83
84 /*---------------------------------------------------------------------------*/
85
86 #define KEYSTYLE_EMPTY 0x0010
87 #define KEYSTYLE_SHORT 0x0020
88 #define KEYSTYLE_LONG 0x0030
89 #define KEYSTYLE_EXTENDED 0x0040
90
91 static char *percent_chars = "NntTdDsSwWp"; /* */
92
93 #define DetexNone 0
94 #define DetexLower 1
95 #define DetexUpper 2
96
97 static StringBuffer *key_sb = (StringBuffer*)NULL;/* */
98 static StringBuffer *tmp_sb = (StringBuffer*)NULL;/* */
99
100 /*---------------------------------------------------------------------------*/
101
102 static KeyNode key_tree = (KeyNode)0; /* */
103 static KeyNode sort_key_tree = (KeyNode)0; /* */
104
105 static NameNode format[NUMBER_OF_FORMATS]; /* */
106
107 #define SkipSpaces(CP) while (is_space(*CP)) ++(CP)
108 #define SkipAllowed(CP) while (is_allowed(*CP)) ++(CP)
109 #define ParseNumber(CP,N) if (is_digit(*CP)) { N = 0; \
110 while(is_digit(*CP) ){ N = N*10 + (*CP)-'0'; ++CP; }}
111 #define Expect(CP,C,RET) SkipSpaces(CP); \
112 if ( *CP == C ) { ++(CP); } \
113 else { ErrPrintF("*** BibTool: Missing %c",C);\
114 return RET; }
115 #define ExpectVoid(CP,C) SkipSpaces(CP); \
116 if ( *CP == C ) { ++(CP); } \
117 else { ErrPrintF("*** BibTool: Missing %c",C);\
118 return; }
119 #define MakeNode(KNP,TYPE,SP,CP) c = *CP; *CP = '\0'; \
120 *KNP = new_key_node(TYPE,symbol((String)*SP));\
121 *CP = c;
122 #define ParseOrReturn(CP,NODEP,MSG) \
123 if ((ret=fmt_parse(CP,NODEP)) != 0 ) \
124 { DebugPrintF1(MSG); return ret; }
125
126
127 /*****************************************************************************/
128 /*** Private word stack ***/
129 /*****************************************************************************/
130
131 static String *words = (String*)NULL;
132 static size_t words_len = 0;
133 static size_t words_used = 0;
134 #define WordLenInc 16
135
136 #define PushWord(S) if (words_len>words_used) words[words_used++]=S; \
137 else Push_Word(S)
138 #define ResetWords words_used = 0
139
140 /*-----------------------------------------------------------------------------
141 ** Function*: push_word()
142 ** Purpose: Push a word to the stack. Wrapper function.
143 ** Arguments:
144 ** word word to push
145 ** Returns: nothing
146 **___________________________________________________ */
147 static void push_word(word) /* */
148 register String word; /* */
149 { PushWord(word); /* */
150 } /*------------------------*/
151
152 /*-----------------------------------------------------------------------------
153 ** Function*: Push_Word()
154 ** Purpose: Push a word to the stack when no space is left in the
155 ** allocated array.
156 ** Arguments:
157 ** s word to push
158 ** Returns: nothing
159 **___________________________________________________ */
160 static void Push_Word(s) /* */
161 register String s; /* */
162 { register String *wp; /* */
163 /* */
164 words_len += WordLenInc; /* */
165 if (words_len == WordLenInc) /* */
166 { wp = (String*)malloc(words_len*sizeof(String)); }/* */
167 else /* */
168 { wp = (String*)realloc(words,words_len*sizeof(String)); }/* */
169 if (wp == (String*)0) /* */
170 { words_len -= WordLenInc; /* */
171 ERROR((String)"Push_Word() failed: Word not pushed.");/* */
172 return; /* */
173 } /* */
174 /* */
175 words = wp; /* */
176 PushWord(s); /* */
177 } /*------------------------*/
178
179
180 /*****************************************************************************/
181 /*** Key Separator Section ***/
182 /*****************************************************************************/
183
184 #define NoSeps 8
185
186 static Symbol *key_seps = NULL;
187
188 #define DefaultKey key_seps[0]
189 #define InterNameSep key_seps[1]
190 #define NamePreSep key_seps[2]
191 #define NameNameSep key_seps[3]
192 #define NameTitleSep key_seps[4]
193 #define TitleTitleSep key_seps[5]
194 #define KeyNumberSep key_seps[6]
195 #define EtAl key_seps[7]
196
197 /*-----------------------------------------------------------------------------
198 ** Function: set_separator()
199 ** Purpose: Modify the |key_seps| array. This array contains the
200 ** different separators used during key formatting. The
201 ** elements of the array have the following meaning:
202 ** \begin{description}
203 ** \item[0] The default key which is used when the
204 ** formatting instruction fails completely.
205 ** \item[1] The separator which is inserted between
206 ** different names of a multi-authored publication.
207 ** \item[2] The separator inserted between the first name
208 ** and the last name when a name is formatted.
209 ** \item[3] The separator inserted between the last names
210 ** when more then one last name is present
211 ** \item[4] The separator between the name and the title
212 ** of a publication.
213 ** \item[5] The separator inserted between words of the
214 ** title.
215 ** \item[6] The separator inserted before the number
216 ** which might be added to disambiguate reference keys.
217 ** \item[7] The string which is added when a list of
218 ** names is truncated. (|.ea|)
219 ** \end{description}
220 ** Arguments:
221 ** n Array index to modify.
222 ** s New value for the given separator. The new value is
223 ** stored as a symbol. Thus the memory of |s| need not to
224 ** be preserved after this function is completed.
225 ** The characters which are not allowed are silently suppressed.
226 ** Returns: nothing
227 **___________________________________________________ */
228 void set_separator(n, s) /* */
229 register int n; /* */
230 String s; /* */
231 { /* */
232 if (n < 0 || n >= NoSeps) /* */
233 { ERROR("Invalid separator reference."); /* */
234 return; /* */
235 } /* */
236 while (*s && !is_allowed(*s)) { s++; } /* */
237 if (*s && !is_allowed(*s)) /* */
238 { ERROR2("Invalid separator specification: ", s);/* */
239 return; /* */
240 } /* */
241 /* */
242 if (key_seps == NULL) init_key(); /* */
243 /* */
244 if (*s) /* */
245 { key_seps[n] = sym_extract(&s, false); /* */
246 } else { /* */
247 key_seps[n] = sym_empty; /* */
248 } /* */
249 } /*------------------------*/
250
251 /*-----------------------------------------------------------------------------
252 ** Function: get_separator()
253 ** Type: String
254 ** Purpose: Getter for the key separator. The
255 ** elements under the index have the following meaning:
256 ** \begin{description}
257 ** \item[0] The default key which is used when the
258 ** formatting instruction fails completely.
259 ** \item[1] The separator which is inserted between
260 ** different names of a multi-authored publication.
261 ** \item[2] The separator inserted between the first name
262 ** and the last name when a name is formatted.
263 ** \item[3] The separator inserted between the last names
264 ** when more then one last name is present
265 ** \item[4] The separator between the name and the title
266 ** of a publication.
267 ** \item[5] The separator inserted between words of the
268 ** title.
269 ** \item[6] The separator inserted before the number
270 ** which might be added to disambiguate reference keys.
271 ** \item[7] The string which is added when a list of
272 ** names is truncated. (|.ea|)
273 ** \end{description}
274 ** Arguments:
275 ** n the index
276 ** Returns: the separator for the given index or NULL
277 **___________________________________________________ */
278 Symbol get_separator(n) /* */
279 int n; /* */
280 { /* */
281 if (n < 0 || n >= NoSeps) /* */
282 { ERROR("Invalid separator reference."); /* */
283 return NULL; /* */
284 } /* */
285 return key_seps[n]; /* */
286 } /*------------------------*/
287
288
289 /*****************************************************************************/
290 /*** Key Base Section ***/
291 /*****************************************************************************/
292
293 static char * key__base[] =
294 { "0123456789",
295 "_abcdefghijklmnopqrstuvwxyz",
296 "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
297 };
298 #define KEY_BASE_DIGIT 0
299 #define KEY_BASE_LOWER 1
300 #define KEY_BASE_UPPER 2
301 static int key_base = KEY_BASE_DIGIT;
302
303 /*-----------------------------------------------------------------------------
304 ** Function: set_base()
305 ** Purpose: Define the key base. This value determines the format
306 ** of the disambiguation string added to a key if
307 ** required. The following values are considered:
308 ** \begin{itemize}
309 ** \item If the value is |upper| or starts with an upper
310 ** case letter then the disambiguation is done with
311 ** upper-case letters.
312 ** \item If the value is |lower| or starts with a lower
313 ** case letter then the disambiguation is done with
314 ** lower-case letters.
315 ** \item If the value is |digit| or starts with an digit
316 ** then the disambiguation is done with arabic numbers.
317 ** \end{itemize}
318 ** The comparison of the keywords is done case
319 ** insensitive. The special values take precedence before
320 ** the first character rules.
321 **
322 ** If an invalid value is given to this function then an
323 ** error is raised and the program is terminated.
324 ** Arguments:
325 ** value String representation of the new value.
326 ** Returns: nothing
327 **___________________________________________________ */
328 void set_base(value) /* */
329 String value; /* */
330 { /* */
331 if (case_eq(value,(String)"upper")) key_base = KEY_BASE_UPPER;/* */
332 else if (case_eq(value,(String)"lower")) key_base = KEY_BASE_LOWER;/* */
333 else if (case_eq(value,(String)"digit")) key_base = KEY_BASE_DIGIT;/* */
334 else if (is_upper(*value)) key_base = KEY_BASE_UPPER;/* */
335 else if (is_lower(*value)) key_base = KEY_BASE_LOWER;/* */
336 else if (is_digit(*value)) key_base = KEY_BASE_DIGIT;/* */
337 else { ERROR("Unknown base ignored."); } /* */
338 } /*------------------------*/
339
340 /*-----------------------------------------------------------------------------
341 ** Function: get_base()
342 ** Type: String
343 ** Purpose: Getter for the printable representation of the key_base.
344 **
345 ** Arguments: none
346 ** Returns:
347 **___________________________________________________ */
348 String get_base() /* */
349 { /* */
350 switch (key_base) /* */
351 { case KEY_BASE_UPPER: return (String)"upper"; /* */
352 case KEY_BASE_LOWER: return (String)"lower"; /* */
353 case KEY_BASE_DIGIT: return (String)"digit"; /* */
354 default: return s_empty; /* */
355 } /* */
356 } /*------------------------*/
357
358 #define ITOA_LEN 64
359
360 /*-----------------------------------------------------------------------------
361 ** Function*: itostr()
362 ** Purpose: Translate number using the ``digits'' given.
363 ** A static string is returned containing the result.
364 ** This is a routine generalizing |itoa()|.
365 ** Examples:
366 ** itostr(X,"0123456789ABCDEF") returns the hexadecimal representation
367 ** itostr(X,"0123456789") returns the decimal representation
368 ** itostr(X,"01234567") returns the octal representation
369 ** itostr(X,"01") returns the binary representation
370 **
371 ** Arguments:
372 ** i Integer to translate
373 ** digits String of digits to use
374 ** Returns:
375 **___________________________________________________ */
376 static char * itostr(i,digits) /* */
377 register int i; /* */
378 register char *digits; /* */
379 { static char buffer[ITOA_LEN]; /* buffer to store result */
380 register char *bp; /* buffer pointer */
381 register int sign, /* */
382 base; /* */
383 /* */
384 base = strlen(digits); /* how many digits? */
385 bp = buffer+ITOA_LEN-1; /* set pointer to the end.*/
386 *(bp--) = '\0'; /* mark the end. */
387 if (i < 0) { sign = -1; i = -i; } /* */
388 else { sign = 0; if ( i == 0 ) *(bp--) = '0'; } /* */
389 while (i > 0) /* */
390 { *(bp--) = digits[i%base]; /* */
391 i = i/base; /* */
392 } /* */
393 if ( sign ) *bp = '-'; else ++bp; /* */
394 return(bp); /* */
395 } /*------------------------*/
396
397
398 /*****************************************************************************/
399 /*** Key Init Section ***/
400 /*****************************************************************************/
401
402 /*-----------------------------------------------------------------------------
403 ** Function*: init_key()
404 ** Purpose: Global initializations for the key module.
405 ** This function has to be called before some of the
406 ** functions provided in this module are guaranteed to
407 ** work properly.
408 ** Arguments: none
409 ** Returns: nothing
410 **___________________________________________________ */
411 static void init_key() /* */
412 { int i; /* */
413 String s; /* */
414 /* */
415 if (key_seps != NULL) return; /* */
416 /* */
417 key_seps = (Symbol*)malloc(8*sizeof(Symbol)); /* */
418 key_seps[0] = symbol((String)"**key*"); /* */
419 key_seps[1] = symbol((String)"-"); /* */
420 key_seps[2] = symbol((String)"."); /* */
421 key_seps[3] = symbol((String)"."); /* */
422 key_seps[4] = symbol((String)":"); /* */
423 key_seps[5] = symbol((String)"-"); /* */
424 key_seps[6] = symbol((String)"*"); /* */
425 key_seps[7] = symbol((String)".ea"); /* */
426 /* */
427 for (i = 0; i < NUMBER_OF_FORMATS; i++) /* */
428 { format[i] = NameNULL; } /* */
429 /* */
430 if ( format[0] == NameNULL ) /* */
431 { s = newString("%*l"); /* */
432 format[0] = name_format(s); /* */
433 free(s); /* */
434 } /* */
435 NameMid(format[0]) = InterNameSep; /* */
436 /* */
437 if ( format[1] == NameNULL ) /* */
438 { s = newString("%*l%*1f"); /* */
439 format[1] = name_format(s); /* */
440 free(s); /* */
441 } /* */
442 NameMid(format[1]) = InterNameSep; /* */
443 if (NextName(format[1])) /* */
444 { NamePre(NextName(format[1])) = NamePreSep; /* */
445 } /* */
446 } /*------------------------*/
447
448 /*-----------------------------------------------------------------------------
449 ** Function*: key_init()
450 ** Purpose: Perform initializations for key generation.
451 ** The string buffer is opened.
452 ** Ignored words are initialized if necessary.
453 ** Arguments: none
454 ** Returns: nothing
455 **___________________________________________________ */
456 static void key_init() /* */
457 { /* */
458 #ifdef INITIALIZE_IGNORED_WORDS
459 static char *word_list[] = /* default ignored words. */
460 { INITIALIZE_IGNORED_WORDS, NULL }; /* Mark the end with NULL */
461 register char**wp; /* */
462 #endif
463 /* */
464 if ( key_sb == (StringBuffer*)0 ) /* Is it the first time? */
465 { /* */
466 if ( (key_sb=sbopen()) == (StringBuffer*)0 ) /* open string buffer */
467 { OUT_OF_MEMORY("key generation."); } /* */
468 #ifdef INITIALIZE_IGNORED_WORDS
469 for ( wp = word_list; *wp != NULL; ++wp ) /* add ignored words. */
470 { add_ignored_word(symbol((String)*wp)); } /* */
471 #endif
472 } /* */
473 } /*------------------------*/
474
475
476 /*****************************************************************************/
477 /*** Key DeTeX Section ***/
478 /*****************************************************************************/
479
480 #define DeTeX_BUFF_LEN 256
481
482 #define DETEX_FLAG_NONE 0
483 #define DETEX_FLAG_COMMA 1
484 #define DETEX_FLAG_ALLOWED 2
485
486 /*-----------------------------------------------------------------------------
487 ** Function*: deTeX()
488 ** Purpose: Expand TeX sequences or eliminate them.
489 **
490 ** Arguments:
491 ** line string to work on
492 ** save_fct Function pointer which is called to store resulting
493 ** characters.
494 ** flags
495 ** Returns:
496 **___________________________________________________ */
497 static int deTeX(line,save_fct,flags) /* */
498 String line; /* */
499 int flags; /* */
500 void (*save_fct)_ARG((String)); /* */
501 { static String buffer; /* */
502 static size_t len = 0; /* */
503 Uchar c; /* */
504 String s, bp; /* */
505 Uchar last = (Uchar)' '; /* */
506 int wp = 0; /* */
507 int brace; /* */
508 /* */
509 #define SaveWord wp++; (*save_fct)(bp)
510 #define SaveChar(C) *(bp++) = last = C
511 #define StoreChar(C) *(bp++) = C
512 /* */
513 brace = 8 * strlen((char*)line); /* */
514 if ( brace > (int)len ) /* */
515 { if ( len == 0 ) /* */
516 { len = ( brace < DeTeX_BUFF_LEN /* */
517 ? DeTeX_BUFF_LEN : brace ); /* */
518 buffer = (String)malloc(sizeof(Uchar)*len); /* */
519 } /* */
520 else /* */
521 { len = brace; /* */
522 buffer = (String)realloc((char*)buffer, /* */
523 sizeof(Uchar)*len); /* */
524 } /* */
525 if ( buffer == NULL ) /* */
526 { OUT_OF_MEMORY("deTeX()"); } /* */
527 } /* */
528 /* */
529 TeX_open_string(line); /* */
530 bp = buffer; /* */
531 brace = 0; /* */
532 wp = 0; /* */
533 SaveWord; /* */
534 /* */
535 while ( TeX_read(&c, &s) ) /* */
536 { /* */
537 if ( is_alpha(c) /* Letters and */
538 || is_digit(c) /* digits and */
539 || is_extended(c) /* extended chars and */
540 || ( c == (Uchar)'-' && last != c ) ) /* non-repeated hyphens */
541 { SaveChar(c); } /* */
542 else if ( c == (Uchar)'{' ) { ++brace; } /* Count braces. */
543 else if ( c == (Uchar)'}' ) /* */
544 { if ( --brace < 0 ) brace = 0; /* */
545 } /* */
546 else if ( ( c == ',' /* Commas */
547 && (flags&DETEX_FLAG_COMMA) ) /* */
548 || /* or */
549 ( (flags&DETEX_FLAG_ALLOWED) /* allowed characters */
550 && is_allowed(c) ) /* */
551 ) /* */
552 { if ( bp != buffer && *(bp-1) != '\0' ) /* are treated as */
553 { StoreChar('\0'); /* single words upon */
554 SaveWord; /* request, or ignored. */
555 } /* */
556 StoreChar(c); /* */
557 StoreChar('\0'); /* */
558 SaveWord; /* */
559 last = ' '; /* */
560 } /* */
561 else if ( !(flags&DETEX_FLAG_ALLOWED) /* */
562 && is_wordsep(c) /* */
563 && !is_wordsep(last) ) /* Don't repeat spaces. */
564 { if ( brace == 0 ) /* Remember the beginning */
565 { StoreChar('\0'); SaveWord; last = ' '; } /* of the next word. */
566 else /* */
567 { String t; /* */
568 for (t = SymbolValue(InterNameSep); *t; ++t)/* */
569 { SaveChar(*t); } /* */
570 } /* */
571 } /* */
572 } /* */
573 /* */
574 if (buffer) { /* */
575 if ( bp != buffer && *(bp-1) != '\0' ) /* */
576 { StoreChar('\0'); /* */
577 SaveWord; /* */
578 } /* */
579 /* */
580 StoreChar('\0'); /* Mark the end. */
581 /* */
582 if ( bp-buffer >= (int)len ) /* */
583 { ERROR_EXIT("deTeX buffer overflow."); } /* */
584 } /* */
585 /* */
586 TeX_close(); /* */
587 return wp-1; /* */
588 } /*------------------------*/
589
590
591 /*****************************************************************************/
592 /*** Title Formatting Section ***/
593 /*****************************************************************************/
594
595 #define PushS(SB,S) push_s(SB,S,0,trans)
596 #define PushStr(SB,S,M) push_s(SB,S,M,trans)
597 #define PushC(SB,C) (void)sbputchar(trans[(unsigned int)(C)],SB);
598
599 /*-----------------------------------------------------------------------------
600 ** Function*: push_s()
601 ** Purpose: Write a translated string to the key string buffer.
602 ** Arguments:
603 ** s String to translate
604 ** max Maximum number of characters
605 ** trans Translation table
606 ** Returns: nothing
607 **___________________________________________________ */
608 static void push_s(sb,s,max,trans) /* */
609 StringBuffer *sb; /* */
610 String s; /* */
611 int max; /* */
612 String trans; /* */
613 { /* */
614 if ( max <= 0 ) /* */
615 { while ( *s ) /* */
616 { (void)sbputchar(trans[*(s++)],sb); } /* */
617 } /* */
618 else /* */
619 { while ( *s && max-->0 ) /* */
620 { (void)sbputchar(trans[*(s++)],sb); } /* */
621 } /* */
622 } /*------------------------*/
623
624 static WordList ignored_words[32] =
625 { WordNULL, WordNULL, WordNULL, WordNULL,
626 WordNULL, WordNULL, WordNULL, WordNULL,
627 WordNULL, WordNULL, WordNULL, WordNULL,
628 WordNULL, WordNULL, WordNULL, WordNULL,
629 WordNULL, WordNULL, WordNULL, WordNULL,
630 WordNULL, WordNULL, WordNULL, WordNULL,
631 WordNULL, WordNULL, WordNULL, WordNULL,
632 WordNULL, WordNULL, WordNULL, WordNULL
633 };
634
635 /*-----------------------------------------------------------------------------
636 ** Function: add_ignored_word()
637 ** Purpose: Add a new word to the list of ignored words for title
638 ** key generation.
639 ** The argument has to be saved by the caller! This means
640 ** that it is assumed that the argument is a symbol.
641 ** Arguments:
642 ** word Word to add.
643 ** Returns: nothing
644 **___________________________________________________ */
645 void add_ignored_word(word) /* */
646 Symbol word; /* */
647 { /* */
648 key_init(); /* */
649 add_word(word, /* */
650 &ignored_words[(*SymbolValue(word))&31]);/* */
651 DebugPrint2("Adding ignored word ", /* */
652 SymbolValue(word)); /* */
653 } /*------------------------*/
654
655 /*-----------------------------------------------------------------------------
656 ** Function: clear_ignored_words()
657 ** Purpose: Delete the list of ignored words. Afterwards no words are
658 ** recognized as ignored words.
659 ** Arguments: none
660 ** Returns: nothing
661 **___________________________________________________ */
662 void clear_ignored_words() /* */
663 { int i; /* */
664 key_init(); /* */
665 /* */
666 for (i = 0; i < 32; i++) /* */
667 { free_words(&ignored_words[i], NULL); } /* */
668 } /*------------------------*/
669
670 /*-----------------------------------------------------------------------------
671 ** Function: foreach_ignored_word()
672 ** Purpose: Iterator a given function |fct| is applied to each
673 ** ignored word in turn. If the function returns 0 then
674 ** the loop is terminated. The different words are
675 ** visited in a fixed order which does not necessarily
676 ** coincide with the natural order of words. Thus don't
677 ** assume this.
678 ** Arguments:
679 ** fct Function to apply.
680 ** Returns: The return status of the last |fct| call.
681 **___________________________________________________ */
682 bool foreach_ignored_word(fct) /* */
683 bool (*fct)_ARG((Symbol)); /* */
684 { int i; /* */
685 /* */
686 key_init(); /* */
687 /* */
688 for (i = 0; i < 32; i++) /* */
689 { if (!foreach_word(ignored_words[i], fct)) /* */
690 { return false; } /* */
691 } /* */
692 return true; /* */
693 } /*------------------------*/
694
695 /*-----------------------------------------------------------------------------
696 ** Function*: fmt_title()
697 ** Purpose: Format a string according to rules for titles.
698 ** \TeX{} sequences are expanded and some words may be ignored.
699 ** The result is pushed to the local string buffer.
700 ** Arguments:
701 ** line String to format.
702 ** len Number of words to use
703 ** in Number of characters per word to use
704 ** trans Translation table
705 ** ignore Boolean. Certain words are ignored if it is |true|
706 ** sep String separating the words.
707 ** Returns: nothing
708 **___________________________________________________ */
709 static void fmt_title(sb, line, len, in, trans, ignore, sep)/* */
710 StringBuffer *sb; /* */
711 String line; /* */
712 int len; /* */
713 int in; /* */
714 String trans; /* Translation table */
715 bool ignore; /* */
716 Symbol sep; /* */
717 { bool first = true; /* */
718 int nw, i, j; /* */
719 String s; /* */
720 /* */
721 /* if ( len == 0 ) return; */
722 /* */
723 if ( tmp_sb == (StringBuffer*)NULL /* */
724 && (tmp_sb=sbopen()) == (StringBuffer*)NULL )/* */
725 { OUT_OF_MEMORY("fmt_title()"); } /* */
726 /* */
727 ResetWords; /* */
728 nw = deTeX(*line == (Uchar)'{' ? line + 1 : line,/* */
729 push_word, /* */
730 DETEX_FLAG_NONE); /* */
731 /* */
732 for (i = 0; i < nw; ++i) /* */
733 { /* */
734 sbrewind(tmp_sb); /* Reset the string buffer*/
735 for (s = words[i]; *s; ++s) /* Translate the current */
736 { (void)sbputchar(trans[*s],tmp_sb); } /* word into the sbuffer */
737 s = (String)sbflush(tmp_sb); /* Get the translated word*/
738 /* */
739 if ( ! ignore || /* */
740 ! find_word((String)s, /* */
741 ignored_words[(*s)&31] ) ) /* */
742 { if (first) { first = false; } /* */
743 else { PushS(sb, SymbolValue(sep)); } /* */
744 if ( in <= 0 ) /* */
745 { PushS(sb, words[i]); } /* Push the current word */
746 else /* */
747 { for (s = words[i], j = in; /* */
748 *s && j-->0; /* */
749 ++s) /* Push the initial part */
750 { PushC(sb, *s); } /* of the current word. */
751 } /* */
752 if ( len == 1 ) return; /* */
753 if ( len > 0 ) len--; /* */
754 } /* */
755 } /* */
756 } /*------------------------*/
757
758 /*-----------------------------------------------------------------------------
759 ** Function*: fmt_c_words()
760 ** Purpose: Count a list of words.
761 ** Arguments:
762 ** line string to analyze
763 ** min minimum
764 ** max maximum or 0
765 ** not negation flag
766 ** ignore flag to indicate if certain words should be ignored.
767 ** Returns:
768 **___________________________________________________ */
769 static bool fmt_c_words(line, min, max, not, ignore)/* */
770 String line; /* */
771 int min; /* */
772 int max; /* */
773 bool not; /* */
774 bool ignore; /* */
775 { int n, i, nw; /* */
776 /* */
777 ResetWords; /* */
778 nw = deTeX(*line == (Uchar)'{' ? line + 1 : line,/* */
779 push_word, /* */
780 DETEX_FLAG_NONE); /* */
781 n = 0; /* */
782 /* */
783 for (i = 0; i < nw; ++i) /* */
784 { /* */
785 if (!ignore || /* */
786 !find_word(words[i], /* */
787 ignored_words[(*words[i])&31]) )/* */
788 { n++; } /* */
789 } /* */
790 /* */
791 if (n < min || (max > 0 && n > max)) /* */
792 { return (not ? false : true); } /* */
793 /* */
794 return (not ? true : false); /* */
795 } /*------------------------*/
796
797
798 /*****************************************************************************/
799 /*** Name Formatting Section ***/
800 /*****************************************************************************/
801
802
803 /*-----------------------------------------------------------------------------
804 ** Function: def_format_type()
805 ** Purpose:
806 **
807 **
808 ** Arguments:
809 ** s
810 ** Returns: nothing
811 **___________________________________________________ */
812 void def_format_type(s) /* */
813 String s; /* */
814 { int n; /* */
815 String cp; /* */
816 Uchar c; /* */
817 /* */
818 SkipSpaces(s); /* */
819 n = 0; /* */
820 while (is_digit(*s)) { n = n*10 + (*s++) - '0'; }/* */
821 if ( n >= NUMBER_OF_FORMATS ) /* */
822 { WARNING("Format type number is out of range.");/* */
823 return; /* */
824 } /* */
825 if ( rsc_verbose && n <= 1 ) /* */
826 { VerbosePrint3("Name format specifier ", /* */
827 (n == 0 ? "0" : "1"), /* */
828 " has been changed.\n"); /* */
829 } /* */
830 /* */
831 if (key_seps == NULL) { init_key(); } /* */
832 /* */
833 SkipSpaces(s); /* */
834 if ( *s == '=' ) s++; /* */
835 ExpectVoid(s,'"'); /* */
836 cp = s; /* */
837 while ( *cp && *cp != '"' ) cp++; /* */
838 c = *cp; /* */
839 *cp = (Uchar)'\0'; /* */
840 format[n] = name_format(s); /* */
841 *cp = c; /* */
842 } /*------------------------*/
843
844 /*-----------------------------------------------------------------------------
845 ** Function*: fmt_names()
846 ** Purpose: Format a list of names separated by 'and'.
847 ** 'and others' is handled properly.
848 ** Arguments:
849 ** line String to format.
850 ** maxname number of names to consider
851 ** maxlen number of characters per name to consider
852 ** post the number of relevant char
853 ** trans translation table
854 ** Returns: nothing
855 **___________________________________________________ */
856 static void fmt_names(sb,line,maxname,post,trans) /* */
857 StringBuffer *sb; /* */
858 String line; /* Name list string */
859 int maxname; /* number of names b4 etal*/
860 int post; /* number of relevant char*/
861 String trans; /* Translation table */
862 { int wp, /* */
863 i; /* */
864 static bool undef_warning = false; /* */
865 /* */
866 if (maxname == 0) return; /* */
867 /* */
868 if ( post < 0 /* */
869 || post >= NUMBER_OF_FORMATS /* */
870 || format[post] == NameNULL ) /* */
871 { if (undef_warning) /* */
872 { ErrPrintF("*** BibTool: Format %d is not defined. Ignored.\n",/* */
873 post); /* */
874 undef_warning = true; /* */
875 } /* */
876 return; /* */
877 } /* */
878 /* */
879 ResetWords; /* */
880 wp = deTeX(*line == (Uchar)'{' ? line + 1 : line,/* */
881 push_word, /* */
882 DETEX_FLAG_COMMA); /* */
883 words[wp] = StringNULL; /* */
884 /* */
885 for (i = 0; i < wp; i++) /* */
886 { /* */
887 DebugPrintF3("+++ %3d '%s'\n", i, words[i]); /* */
888 /* */
889 if (strcmp((char*)words[i],"and") == 0) /* */
890 { words[i] = SymbolValue(sym_et); } /* */
891 else if (strcmp((char*)words[i], ",") == 0) /* */
892 { words[i] = SymbolValue(sym_comma); } /* */
893 } /* */
894 /* */
895 PushS(sb, /* */
896 pp_list_of_names(words, /* */
897 format[post], /* */
898 trans, /* */
899 maxname, /* */
900 SymbolValue(sym_comma), /* */
901 SymbolValue(sym_et), /* */
902 (char*)SymbolValue(NameNameSep),/* */
903 (char*)SymbolValue(EtAl)));/* */
904 } /*------------------------*/
905
906 /*-----------------------------------------------------------------------------
907 ** Function*: fmt_c_names()
908 ** Purpose: Count a list of names
909 ** Arguments:
910 ** line string to analyze
911 ** min minimum
912 ** max maximum or 0
913 ** not negation flag
914 ** Returns:
915 **___________________________________________________ */
916 static bool fmt_c_names(line,min,max,not) /* */
917 String line; /* Name list string */
918 int min; /* number of relevant char*/
919 int max; /* number of names b4 etal*/
920 bool not; /* negation flag */
921 { int wp, /* */
922 i, /* */
923 n; /* */
924 /* */
925 ResetWords; /* */
926 wp = deTeX(*line == (Uchar)'{' ? line + 1 : line,/* */
927 push_word, /* */
928 DETEX_FLAG_COMMA); /* */
929 words[wp] = NULL; /* */
930 /* */
931 for (i = 0, n = 1; i < wp; i++) /* */
932 { if (strcmp((char*)words[i],"and") == 0) /* */
933 { n++; } /* */
934 } /* */
935 /* */
936 if (n < min || (max > 0 && n > max)) /* */
937 { return (not ? false : true); } /* */
938 /* */
939 return (not ? true : false); /* */
940 } /*------------------------*/
941
942
943 /*****************************************************************************/
944 /*** Number Formatting Section ***/
945 /*****************************************************************************/
946
947 /*-----------------------------------------------------------------------------
948 ** Function*: fmt_digits()
949 ** Purpose: Search a sequence of digits and push at most n of them
950 ** counting from right to the string buffer.
951 ** Example: fmt_digits("jun 1958",2) pushes "58" to the string buffer.
952 ** Arguments:
953 ** sb String buffer to store the result in
954 ** s String to format
955 ** mp Boolean indicating whether padding with 0s should be performed
956 ** (true) or not.
957 ** pp Boolean indicating whether no number should be 0 or fail
958 ** n Length
959 ** sel The number to select.
960 ** trunc Boolean indicating whether or not to truncate the number.
961 ** Returns:
962 **___________________________________________________ */
963 static bool fmt_digits(sb,s,mp,pp,n,sel,trunc) /* */
964 StringBuffer *sb; /* */
965 register String s; /* */
966 int mp; /* */
967 int pp; /* */
968 register int n; /* */
969 int sel; /* */
970 bool trunc; /* */
971 { register String cp; /* */
972 /* */
973 if (n < 0) { n = ( mp ? 1 : 0x7fff ); } /* */
974 /* */
975 cp = s; /* */
976 while (sel-->0) /* */
977 { s = cp; /* */
978 while (*s && !is_digit(*s)) { ++s; } /* search first digit */
979 if ( *s == '\0' ) /* */
980 { cp = s; sel = 0; } /* */
981 else /* */
982 { for (cp = s; *cp && is_digit(*cp); ++cp) {} /* skip over digits */
983 } /* */
984 } /* */
985 /* */
986 if (trunc && cp-s > n) s = cp-n; /* */
987 else if (mp) /* */
988 { while (cp - s < n--) /* */
989 { (void)sbputchar('0', sb); } /* */
990 } /* */
991 if (!mp && *s == '\0') /* */
992 { if (pp) (void)sbputchar('0', sb); /* */
993 else return true; /* */
994 } /* */
995 else /* */
996 { /* */
997 while ( s != cp ) /* */
998 { (void)sbputchar((char)(*s), sb); /* */
999 ++s; /* */
1000 } /* */
1001 } /* */
1002 return false; /* */
1003 } /*------------------------*/
1004
1005
1006 /*****************************************************************************/
1007 /*** String Formatting Section ***/
1008 /*****************************************************************************/
1009
1010 /*-----------------------------------------------------------------------------
1011 ** Function*: fmt_string()
1012 ** Purpose: Push characters from s onto the string buffer.
1013 ** At most n characters are transfered.
1014 ** Letters are translated according to mode.
1015 ** Arguments:
1016 ** s String to format
1017 ** n Length
1018 ** trans Translation table
1019 ** sep Separator
1020 ** Returns: nothing
1021 **___________________________________________________ */
1022 static void fmt_string(sb,s,n,trans,sep) /* */
1023 StringBuffer *sb; /* */
1024 register String s; /* */
1025 register int n; /* */
1026 register String trans; /* */
1027 String sep; /* */
1028 { /* */
1029 while (*s && n > 0) /* */
1030 { if (is_allowed(*s)) /* */
1031 { (void)sbputchar(trans[*s],sb); /* */
1032 n--; /* */
1033 } /* */
1034 else if (is_space(*s)) /* */
1035 { (void)sbputs((char*)sep, sb); /* */
1036 n--; /* */
1037 while (is_space(*s)) s++; /* skip over multiple SPC */
1038 s--; /* */
1039 } /* */
1040 ++s; /* */
1041 } /* */
1042 } /*------------------------*/
1043
1044 /*-----------------------------------------------------------------------------
1045 ** Function*: fmt_c_string()
1046 ** Purpose: Count the number of characters in a string and compare it
1047 ** against an interval.
1048 **
1049 ** Arguments:
1050 ** s string to analyze
1051 ** min minimum
1052 ** max maximum or 0
1053 ** not negation flag
1054 ** Returns:
1055 **___________________________________________________ */
1056 static bool fmt_c_string(s,min,max,not) /* */
1057 register String s; /* */
1058 register int min; /* */
1059 register int max; /* */
1060 register bool not; /* */
1061 { int n = 0; /* */
1062 /* */
1063 while (*s) /* */
1064 { if (is_allowed(*s)) { n++; } /* */
1065 else if (is_space(*s)) /* */
1066 { n += symlen(TitleTitleSep); /* */
1067 while (is_space(*s)) s++; /* skip over multiple SPC */
1068 } /* */
1069 ++s; /* */
1070 } /* */
1071 /* */
1072 if (n < min || (max > 0 && n > max)) /* */
1073 { return (not ? false : true); } /* */
1074 /* */
1075 return (not ? true : false); /* */
1076 } /*------------------------*/
1077
1078 #define IfGetField(S,NAME) if ((S=get_field(tmp_key_db,rec,NAME)) != NULL)
1079
1080 #define GetEntryOrReturn(S,NAME) \
1081 if ((S=get_field(tmp_key_db,rec,NAME)) == NULL) return false
1082
1083 static WordList old_keys = WordNULL;
1084
1085 static Record tmp_rec = NULL;
1086
1087 /*-----------------------------------------------------------------------------
1088 ** Function: start_key_gen()
1089 ** Purpose: Start the key generation.
1090 ** Any recorded keys are discarded.
1091 ** Arguments:
1092 ** Returns: nothing
1093 **___________________________________________________ */
1094 void start_key_gen() /* */
1095 { /* */
1096 free_words(&old_keys, sym_unlink); /* */
1097 init_key(); /* */
1098 } /*------------------------*/
1099
1100 /*-----------------------------------------------------------------------------
1101 ** Function: end_key_gen()
1102 ** Purpose: Finalize the key generation.
1103 ** Any previously recorded keys are discarded.
1104 ** Arguments:
1105 ** Returns: nothing
1106 **___________________________________________________ */
1107 void end_key_gen() /* */
1108 { /* */
1109 free_words(&old_keys,sym_unlink); /* */
1110 } /*------------------------*/
1111
1112 /*-----------------------------------------------------------------------------
1113 ** Function: mark_key()
1114 ** Purpose: Set the key mark for the key symbol of a record.
1115 ** Arguments:
1116 ** db Database containing the record.
1117 ** rec Record to consider
1118 ** Returns: nothing
1119 **___________________________________________________ */
1120 bool mark_key(db,rec) /* */
1121 DB db; /* */
1122 Record rec; /* */
1123 { /* */
1124 POSSIBLY_UNUSED(db); /* */
1125 /* */
1126 if ( IsSpecialRecord(RecordType(rec)) || /* */
1127 *RecordHeap(rec) == NULL ) /* */
1128 { return false; } /* */
1129 /* */
1130 add_word(*RecordHeap(rec), &old_keys); /* */
1131 return false; /* */
1132 } /*------------------------*/
1133
1134 /*-----------------------------------------------------------------------------
1135 ** Function: make_key()
1136 ** Purpose: Generate a key for a given record.
1137 ** Arguments:
1138 ** db Database containing the record.
1139 ** rec Record to consider.
1140 ** Returns: nothing
1141 **___________________________________________________ */
1142 void make_key(db,rec) /* */
1143 DB db; /* */
1144 register Record rec; /* */
1145 { register String kp; /* */
1146 Symbol key; /* */
1147 Symbol old; /* */
1148 int pos; /* */
1149 /* */
1150 if ( IsSpecialRecord(RecordType(rec)) ) return; /* */
1151 /* */
1152 if (key_tree == (KeyNode)NULL) /* */
1153 { *RecordHeap(rec) = sym_empty; /* store an empty key */
1154 return; /* */
1155 } /* */
1156 /* */
1157 if (key_seps == NULL) { init_key(); } /* */
1158 /* */
1159 if (rsc_key_preserve && /* */
1160 *SymbolValue(*RecordHeap(rec)) != '\0' ) /* */
1161 { return; } /* */
1162 /* */
1163 key_init(); /* */
1164 sbrewind(key_sb); /* clear key */
1165 /* */
1166 if (eval_fmt(key_sb, key_tree, rec,db)) /* */
1167 { sbputs((char*)SymbolValue(DefaultKey), key_sb);/* */
1168 } /* */
1169 /* */
1170 SetSym(RecordOldKey(rec), *RecordHeap(rec)); /* */
1171 /* */
1172 #ifndef NEW
1173 #define trans trans_id
1174 ResetWords; /* */
1175 { char * buffer = new_string(sbflush(key_sb)); /* */
1176 int nw = deTeX((String)(*buffer == '{' /* */
1177 ? buffer + 1 /* */
1178 : buffer), /* */
1179 push_word, /* */
1180 DETEX_FLAG_ALLOWED); /* */
1181 int i; /* */
1182 sbrewind(key_sb); /* */
1183 for (i = 0; i < nw; ++i) /* */
1184 { if ( strcmp((char*)words[i], /* */
1185 "\\") ) /* */
1186 PushS(key_sb, words[i]); /* */
1187 } /* */
1188 free(buffer); /* */
1189 } /* */
1190 #undef trans
1191 #endif
1192 pos = sbtell(key_sb); /* */
1193 kp = (String)sbflush(key_sb); /* get collected key */
1194 /* */
1195 if (find_word(kp, old_keys)) /* is key already used? */
1196 { int n = 1; /* Then disambiguate: */
1197 (void)sbseek(key_sb, pos); /* */
1198 (void)sbputs((char*)SymbolValue(KeyNumberSep), /* */
1199 key_sb); /* put separator at end */
1200 pos = sbtell(key_sb); /* */
1201 do /* last symbol was present*/
1202 { (void)sbseek(key_sb, pos); /* */
1203 (void)sbputs(itostr(n++,key__base[key_base]),/* */
1204 key_sb); /* */
1205 kp = (String)sbflush(key_sb); /* get new key */
1206 } while (find_word(kp, old_keys)); /* */
1207 } /* */
1208 /* */
1209 key = symbol(kp); /* */
1210 old = *RecordHeap(rec); /* */
1211 *RecordHeap(rec) = key; /* store new key */
1212 add_word(key, &old_keys); /* remember new key */
1213 /* ---------------------- */
1214 if (rsc_make_alias /* if needed then make */
1215 && !rsc_apply_alias /* */
1216 && old != NULL /* an alias */
1217 && key != old /* */
1218 && *SymbolValue(old)) /* */
1219 { /* */
1220 if (tmp_rec == RecordNULL) /* lacy initialization */
1221 { tmp_rec = new_record(BIB_ALIAS,2); } /* */
1222 /* */
1223 *RecordHeap(tmp_rec) = old; /* */
1224 RecordHeap(tmp_rec)[1] = key; /* */
1225 db_insert(db, copy_record(tmp_rec), false); /* */
1226 } /* */
1227 } /*------------------------*/
1228
1229 /*-----------------------------------------------------------------------------
1230 ** Function: make_sort_key()
1231 ** Purpose:
1232 **
1233 ** Arguments:
1234 ** db Database containing the record.
1235 ** rec Record to consider.
1236 ** Returns: nothing
1237 **___________________________________________________ */
1238 void make_sort_key(db,rec) /* */
1239 DB db; /* */
1240 register Record rec; /* */
1241 { register String kp; /* */
1242 /* */
1243 if ( IsSpecialRecord(RecordType(rec)) ) return; /* */
1244 /* */
1245 key_init(); /* */
1246 sbrewind(key_sb); /* clear key */
1247 /* */
1248 if ( sort_key_tree != (KeyNode)0 /* */
1249 && !eval_fmt(key_sb,sort_key_tree,rec,db) ) /* */
1250 { kp = (String)sbflush(key_sb); /* get collected key */
1251 RecordSortkey(rec) = symbol(kp); /* store new key */
1252 } /* */
1253 else /* If everything fails */
1254 { RecordSortkey(rec) = RecordHeap(rec)[0]; /* use the reference key */
1255 LinkSymbol(RecordHeap(rec)[0]); /* */
1256 } /* */
1257 } /*------------------------*/
1258
1259
1260 /*****************************************************************************/
1261 /*** Key Format Parsing and Evaluating ***/
1262 /*****************************************************************************/
1263
1264 /*-----------------------------------------------------------------------------
1265 ** Function*: new_key_node()
1266 ** Purpose: Allocate a new key node
1267 ** Arguments:
1268 ** type the type
1269 ** sym the symbol
1270 ** Returns: The address of the new node.
1271 ** Upon failure exit() is called.
1272 **___________________________________________________ */
1273 static KeyNode new_key_node(type, sym) /* */
1274 int type; /* */
1275 Symbol sym; /* */
1276 { KeyNode new_node; /* */
1277 if( (new_node=(KeyNode)malloc(sizeof(SKeyNode))) ==/* */
1278 (KeyNode)0 ) /* */
1279 { OUT_OF_MEMORY(" new_node_key_node()"); } /* */
1280 /* */
1281 NodeType(new_node) = type; /* */
1282 NodeSymbol(new_node) = sym; /* */
1283 NodeNext(new_node) = (KeyNode)0; /* */
1284 NodeThen(new_node) = (KeyNode)0; /* */
1285 NodeElse(new_node) = (KeyNode)0; /* */
1286 NodePre(new_node) = -1; /* */
1287 NodePost(new_node) = -1; /* */
1288 return new_node; /* */
1289 } /*------------------------*/
1290
1291 /*-----------------------------------------------------------------------------
1292 ** Function: free_key_node()
1293 ** Purpose: A tree rooted at a given |KeyNode| will be freed.
1294 ** Arguments:
1295 ** kn KeyNode to be freed.
1296 ** Returns: nothing
1297 **___________________________________________________ */
1298 void free_key_node(kn) /* */
1299 KeyNode kn; /* */
1300 { KeyNode next; /* */
1301 /* */
1302 while ( kn != (KeyNode)0 ) /* */
1303 { /* */
1304 free_key_node(NodeThen(kn)); /* */
1305 free_key_node(NodeElse(kn)); /* */
1306 next = NodeNext(kn); /* */
1307 free(kn); /* */
1308 kn = next; /* */
1309 } /* */
1310 } /*------------------------*/
1311
1312 /*-----------------------------------------------------------------------------
1313 ** Function*: add_fmt_tree()
1314 ** Purpose: Extend the format tree
1315 ** Arguments:
1316 ** s the specification of the format
1317 ** treep the pointer to the tree to be extended
1318 ** Returns: |true| iff the operation succeeds
1319 **___________________________________________________ */
1320 static bool add_fmt_tree(s, treep) /* */
1321 char *s; /* */
1322 KeyNode *treep; /* */
1323 { KeyNode kn, kn_or; /* */
1324 int special = 0; /* */
1325 String s0 = (String)s; /* */
1326 /* */
1327 if (s == (char*)NULL) return false; /* */
1328 /* */
1329 if ( strcmp(s,"empty") == 0 ) /* */
1330 { free_key_node(*treep); /* */
1331 *treep = (KeyNode)0; /* */
1332 return true; /* */
1333 } /* */
1334 else if ( strcmp(s,"short" ) == 0 ) /* */
1335 { special = KEYSTYLE_SHORT; } /* */
1336 else if ( strcmp(s,"long" ) == 0 ) /* */
1337 { special = KEYSTYLE_LONG; } /* */
1338 else if ( strcmp(s,"new.short") == 0 || /* */
1339 strcmp(s,"short.need") == 0 ) /* */
1340 { special = KEYSTYLE_SHORT; /* */
1341 rsc_key_preserve = true; /* */
1342 } /* */
1343 else if ( strcmp(s,"new.long" ) == 0 || /* */
1344 strcmp(s,"long.need") == 0 ) /* */
1345 { special = KEYSTYLE_LONG; /* */
1346 rsc_key_preserve = true; /* */
1347 } /* */
1348 /* */
1349 if ( special ) /* */
1350 { free_key_node(*treep); /* */
1351 *treep = new_key_node(NodeSPECIAL, NO_SYMBOL); /* */
1352 NodePre(*treep) = special; /* */
1353 return true; /* */
1354 } /* */
1355 /* */
1356 if ( fmt_parse(&s,&kn) > 0 ) /* */
1357 { error(ERR_POINT|ERR_WARN, /* */
1358 (String)"Format Error. Format ignored.", /* */
1359 StringNULL, StringNULL, s0, (String)s, /* */
1360 0, sym_empty); /* */
1361 return false; /* */
1362 } /* */
1363 if ( *treep == (KeyNode)0 ) { *treep = kn; } /* */
1364 else if ( NodeType(*treep) == NodeSPECIAL ) /* */
1365 { free_key_node(*treep); /* */
1366 *treep = kn; /* */
1367 } /* */
1368 else /* */
1369 { kn_or = new_key_node(NodeOR, NO_SYMBOL); /* */
1370 NodeThen(kn_or) = *treep; /* */
1371 NodeElse(kn_or) = kn; /* */
1372 *treep = kn_or; /* */
1373 } /* */
1374 /* */
1375 #ifdef DEBUG
1376 show_fmt(*treep,0); /* */
1377 #endif
1378 return true; /* */
1379 } /*------------------------*/
1380
1381 /*-----------------------------------------------------------------------------
1382 ** Function: add_format()
1383 ** Purpose: Add a key format specification to the current
1384 ** specification. This specification is used for
1385 ** generating new reference keys. Thus the resource
1386 ** |rsc_make_key| is turned on aswell.
1387 **
1388 ** Several strings are treated special. If a special
1389 ** format is encountered then the effect is that the old
1390 ** key specification is cleared first before the new
1391 ** format is added:
1392 ** \begin{description}
1393 ** \item[empty] The empty format is activated. This means that
1394 ** the format is cleared and without further action the
1395 ** default key will be used.
1396 ** \item[long] The long format is activated. This means that
1397 ** authors names with initials and the first word of
1398 ** the title are used.
1399 ** \item[short] The short format is activated. This means that
1400 ** authors last names and the first word of the title
1401 ** are used.
1402 ** \item[new.long] This means that the long format will
1403 ** be used but only if the record does not have a key
1404 ** already.
1405 ** \item[new.short] This means that the short format will
1406 ** be used but only if the record does not have a key
1407 ** already.
1408 ** \end{description}
1409 ** Arguments:
1410 ** s Specification string
1411 ** Returns: nothing
1412 **___________________________________________________ */
1413 void add_format(s) /* */
1414 register char *s; /* */
1415 { /* */
1416 if (s == NULL) /* */
1417 { WARNING("Missing key format."); /* */
1418 return; /* */
1419 } /* */
1420 rsc_make_key = true; /* */
1421 (void)add_fmt_tree(s,&key_tree); /* */
1422 } /*------------------------*/
1423
1424 /*-----------------------------------------------------------------------------
1425 ** Function: add_sort_format()
1426 ** Purpose: Add a sort key format specification to the current
1427 ** specification. This specification is used for
1428 ** generating new sort keys.
1429 **
1430 ** Several strings are treated special. If a special
1431 ** format is encountered then the effect is that the old
1432 ** key specification is cleared first before the new
1433 ** format is added:
1434 ** \begin{description}
1435 ** \item[empty] The empty format is activated. This means that
1436 ** the format is cleared and without further action the
1437 ** default key will be used.
1438 ** \item[long] The long format is activated. This means that
1439 ** authors names with initials and the first word of
1440 ** the title are used.
1441 ** \item[short] The short format is activated. This means that
1442 ** authors last names and the first word of the title
1443 ** are used.
1444 ** \item[new.long] This means that the long format will
1445 ** be used but only if the record does not have a key
1446 ** already.
1447 ** \item[new.short] This means that the short format will
1448 ** be used but only if the record does not have a key
1449 ** already.
1450 ** \end{description}
1451 ** Arguments:
1452 ** s Specification string
1453 ** Returns: nothing
1454 **___________________________________________________ */
1455 void add_sort_format(s) /* */
1456 register char *s; /* */
1457 { /* */
1458 if ( s == NULL ) /* */
1459 { WARNING("Missing sort key format."); /* */
1460 return; /* */
1461 } /* */
1462 (void)add_fmt_tree(s,&sort_key_tree); /* */
1463 } /*------------------------*/
1464
1465 /*-----------------------------------------------------------------------------
1466 ** Function*: fmt_parse()
1467 ** Purpose: Parse the format specification given in the string *sp.
1468 ** Store the resulting KeyNode tree in *knp.
1469 ** *sp is modified to point to the first character not used.
1470 ** The return value is 0 iff no problem has been detected.
1471 ** Arguments:
1472 ** sp
1473 ** knp
1474 ** Returns: Error code. 0 = success
1475 **___________________________________________________ */
1476 static int fmt_parse(sp,knp) /* */
1477 char **sp; /* */
1478 KeyNode *knp; /* */
1479 { int ret; /* */
1480 KeyNode new; /* */
1481 /* */
1482 *knp = (KeyNode)NULL; /* */
1483 /* */
1484 while ( (ret=fmt__parse(sp,knp)) == 0 ) /* */
1485 { SkipSpaces(*sp); /* */
1486 if ( **sp == '#' ) /* */
1487 { new = new_key_node(NodeOR, NO_SYMBOL); /* */
1488 NodeThen(new) = *knp; /* */
1489 *knp = new; /* */
1490 knp = &NodeElse(new); /* */
1491 (*sp)++; /* */
1492 } /* */
1493 else return 0; /* */
1494 } /* */
1495 DebugPrintF1("<-format"); /* */
1496 return ret; /* return the error code. */
1497 } /*------------------------*/
1498
1499 /*-----------------------------------------------------------------------------
1500 ** Function*: fmt__parse()
1501 ** Purpose:
1502 **
1503 ** Arguments:
1504 ** sp Pointer to the string to be parsed
1505 ** knp Pointer to the key node in which to store the result
1506 ** Returns: Error code or 0 upon success
1507 **___________________________________________________ */
1508 static int fmt__parse(sp,knp) /* */
1509 char **sp; /* */
1510 KeyNode *knp; /* */
1511 { register char *cp; /* */
1512 char c; /* */
1513 int ret; /* */
1514 /* */
1515 cp = *sp; /* */
1516 /* */
1517 while ( *cp != '\0' ) /* */
1518 { /* */
1519 switch ( *cp ) /* */
1520 { case ' ' : case '\t': case '\r': /* Skip over spaces. */
1521 case '\n': case '\f': case '\b': /* */
1522 cp++; break; /* */
1523 case '#': /* Two cases evaluated */
1524 case '}': return 0; /* somewhere else. */
1525 case '%': /* Format specification: */
1526 { int pre = -1, /* */
1527 post = -1, /* %[-][0-9]*[.[0-9]*[a-Z]*/
1528 type = 0; /* ([a-Z]*) */
1529 switch ( *++cp ) /* */
1530 { case '+': type = NodePlusMask; ++cp; break;/* */
1531 case '-': type = NodeMinusMask; ++cp; break;/* */
1532 } /* */
1533 ParseNumber(cp,pre); /* */
1534 if ( *cp == '.' || *cp == ',' || *cp == '-' )/* */
1535 { cp++; /* */
1536 ParseNumber(cp,post); /* */
1537 } /* */
1538 if ( *cp == '#' ) /* */
1539 { cp++; /* */
1540 type |= NodeCountMask; /* */
1541 } /* */
1542 if ( !is_alpha(*cp) ) /* */
1543 { ErrPrintF("*** BibTool: Missing format type before: %s",cp);/* */
1544 *sp = cp; /* */
1545 DebugPrintF1("<-or"); /* */
1546 return 1; /* */
1547 } /* */
1548 if ( strchr(percent_chars,*cp) == (char*)0 )/* */
1549 { ErrPrintF("*** BibTool: Illegal format character: %c",*cp);/* */
1550 *sp = cp; /* */
1551 DebugPrintF1("<-percent"); /* */
1552 return 1; /* */
1553 } /* */
1554 type |= *(cp++); /* */
1555 Expect(cp,'(',1); /* */
1556 SkipSpaces(cp); /* */
1557 *sp = cp; /* */
1558 SkipAllowed(cp); /* */
1559 MakeNode(knp,type,sp,cp) /* */
1560 NodePre(*knp) = pre; /* */
1561 NodePost(*knp) = post; /* */
1562 SkipSpaces(cp); /* */
1563 Expect(cp,')',1); /* */
1564 *sp = cp; /* */
1565 knp = & NodeNext(*knp); /* */
1566 } /* */
1567 break; /* */
1568 /* */
1569 case '(': /* */
1570 cp = (*sp)+1; /* */
1571 SkipSpaces(cp); /* */
1572 *sp = cp; /* */
1573 SkipAllowed(cp); /* */
1574 MakeNode(knp,NodeTEST,sp,cp); /* */
1575 Expect(cp,')',1); /* */
1576 Expect(cp,'{',1); /* */
1577 *sp = cp; /* */
1578 ParseOrReturn(sp,&NodeThen(*knp),"<-then");/* */
1579 Expect(*sp,'}',1); /* */
1580 Expect(*sp,'{',1); /* */
1581 ParseOrReturn(sp,&NodeElse(*knp),"<-else");/* */
1582 Expect(*sp,'}',1); /* */
1583 knp = & NodeNext(*knp); /* */
1584 cp = *sp; /* */
1585 break; /* */
1586 /* */
1587 case '{': /* */
1588 DebugPrintF1("--- parse block\n"); /* */
1589 cp++; /* */
1590 SkipSpaces(cp); /* */
1591 *sp = cp; /* */
1592 ParseOrReturn(sp,knp,"<-block"); /* */
1593 Expect(*sp,'}',1); /* */
1594 knp = & NodeNext(*knp); /* */
1595 cp = *sp; /* */
1596 break; /* */
1597 /* */
1598 default: /* */
1599 *sp = cp; /* */
1600 if ( is_allowed(*cp) ) /* */
1601 { /* */
1602 while ( is_allowed(*cp) ) { ++cp; } /* */
1603 MakeNode(knp,NodeSTRING,sp,cp); /* */
1604 *sp = cp; /* */
1605 knp = & NodeNext(*knp); /* */
1606 } /* */
1607 else /* */
1608 { ERROR2("Parse format. Illegal character ignored: ",cp);/* */
1609 ++cp; /* */
1610 } /* */
1611 } /* */
1612 } /* */
1613 DebugPrintF1("<-fmt"); /* */
1614 return -1; /* Signal end-of-string. */
1615 } /*------------------------*/
1616
1617 /*-----------------------------------------------------------------------------
1618 ** Function*: eval_fmt()
1619 ** Purpose: Evaluate the given KeyNode tree w.r.t. the given Record.
1620 ** Arguments:
1621 ** kn the key node
1622 ** rec the record
1623 ** db the database
1624 ** Returns: |false| upon success.
1625 **___________________________________________________ */
1626 static bool eval_fmt(sb,kn,rec,db) /* */
1627 StringBuffer *sb; /* */
1628 KeyNode kn; /* */
1629 Record rec; /* */
1630 DB db; /* */
1631 { int pos = sbtell(sb); /* */
1632 /* */
1633 tmp_key_db = db; /* */
1634 if ( eval__fmt(sb, kn, rec) != 0 ) /* */
1635 { (void)sbseek(sb, pos); /* */
1636 return true; /* */
1637 } /* */
1638 /* */
1639 return false; /* */
1640 } /*------------------------*/
1641
1642 /*-----------------------------------------------------------------------------
1643 ** Function*: eval__fmt()
1644 ** Purpose: Evaluate the given KeyNode tree w.r.t. the given Record
1645 ** Internal version. trash of conjunctions is not removed.
1646 ** Arguments:
1647 ** sb the sting buffer
1648 ** kn the key node
1649 ** rec the record
1650 ** Returns:
1651 **___________________________________________________ */
1652 static bool eval__fmt(sb,kn,rec) /* */
1653 StringBuffer *sb; /* */
1654 KeyNode kn; /* */
1655 Record rec; /* */
1656 { Symbol s; /* */
1657 int pos; /* */
1658 String trans; /* */
1659 /* */
1660 DebugPrint1("eval__fmt()"); /* */
1661 while ( kn != (KeyNode)0 ) /* */
1662 { /* */
1663 switch ( NodeType(kn) ) /* */
1664 { case NodeSTRING: /* */
1665 DebugPrint3("STRING \"", /* */
1666 SymbolValue(NodeSymbol(kn)), /* */
1667 "\""); /* */
1668 (void)sbputs((char*)SymbolValue(NodeSymbol(kn)),/* */
1669 sb); /* */
1670 break; /* */
1671 case NodeTEST: /* */
1672 #ifdef DEBUG
1673 DebugPrint3("IF_THEN_ELSE (", /* */
1674 SymbolValue(NodeSymbol(kn)), /* */
1675 ")"); /* */
1676 IfGetField(s,NodeSymbol(kn)) /* */
1677 DebugPrint1("Field found. Continuing with THEN part");/* */
1678 else DebugPrint1("Field NOT found. Continuing with ELSE part");/* */
1679 #endif
1680 IfGetField(s, NodeSymbol(kn)) /* */
1681 { (void)eval__fmt(sb, NodeThen(kn),rec); } /* */
1682 else /* */
1683 { (void)eval__fmt(sb, NodeElse(kn),rec); } /* */
1684 break; /* */
1685 /* */
1686 case NodeOR: /* */
1687 DebugPrint1("OR Trying THEN part"); /* */
1688 pos = sbtell(sb); /* */
1689 if ( eval__fmt(sb,NodeThen(kn),rec) != 0 ) /* */
1690 { (void)sbseek(sb,pos); /* */
1691 DebugPrint1("OR THEN part failed. Trying ELSE part.");/* */
1692 if ( eval__fmt(sb,NodeElse(kn),rec) != 0 )/* */
1693 { (void)sbseek(sb,pos); /* */
1694 DebugPrint1("OR ELSE part failed"); /* */
1695 return true; /* */
1696 } /* */
1697 DebugPrint1("OR ELSE part succeeded"); /* */
1698 } /* */
1699 break; /* */
1700 /* */
1701 case NodeSPECIAL: /* */
1702 eval__special(sb,kn,rec); /* */
1703 break; /* */
1704 default: /* */
1705 #ifdef DEBUG
1706 fprintf(err_file,"+++ BibTool: FORMAT %s%d.%d%s%c(%s)\n",/* */
1707 (NodeType(kn)&NodePlusMask /* */
1708 ? "+" /* */
1709 :(NodeType(kn)&NodeMinusMask /* */
1710 ?"-":"")), /* */
1711 NodePre(kn), /* */
1712 NodePost(kn), /* */
1713 (NodeType(kn)&NodeCountMask?"#":""),/* */
1714 NodeType(kn)&0xff, /* */
1715 SymbolValue(NodeSymbol(kn))); /* */
1716 #endif
1717 IfGetField(s, NodeSymbol(kn)) /* */
1718 { /* */
1719 DebugPrint1("Field found"); /* */
1720 /* */
1721 if (NodeType(kn)&NodeMinusMask) /* */
1722 { trans = trans_lower; } /* */
1723 else if (NodeType(kn)&NodePlusMask) /* */
1724 { trans = trans_upper; } /* */
1725 else /* */
1726 { trans = trans_id; } /* */
1727 #define UsePostOr(X) (NodePost(kn) > 0 ? NodePost(kn) : (X))
1728 #define UsePreOr(X) (NodePre(kn) >= 0 ? NodePre(kn) : (X))
1729 #define HasMinus (NodeType(kn)&NodeMinusMask)
1730 #define HasPlus (NodeType(kn)&NodePlusMask)
1731 /* */
1732 switch ( NodeType(kn) & 0x1ff ) /* */
1733 { /* */
1734 case 'p': /* */
1735 fmt_names(sb, /* */
1736 SymbolValue(s), /* */
1737 UsePreOr(2), /* */
1738 UsePostOr(0), /* */
1739 trans); /* */
1740 break; /* */
1741 case 'n': /* */
1742 if (key_seps == NULL) { init_key(); }/* */
1743 NameStrip(format[0]) = UsePostOr(-1);/* */
1744 fmt_names(sb, /* */
1745 SymbolValue(s), /* */
1746 UsePreOr(2), /* */
1747 0, /* */
1748 trans); /* */
1749 break; /* */
1750 case 'N': /* */
1751 if (key_seps == NULL) { init_key(); }/* */
1752 NameStrip(format[1]) = UsePostOr(-1);/* */
1753 if (NextName(format[1])) /* */
1754 { NamePre(NextName(format[1])) = NamePreSep;/* */
1755 } /* */
1756 fmt_names(sb, /* */
1757 SymbolValue(s), /* */
1758 UsePreOr(2), /* */
1759 1, /* */
1760 trans); /* */
1761 break; /* */
1762 case 'T': /* */
1763 fmt_title(sb, /* */
1764 SymbolValue(s), /* */
1765 UsePreOr(1), /* */
1766 UsePostOr(0), /* */
1767 trans, /* */
1768 true, /* */
1769 TitleTitleSep); /* */
1770 break; /* */
1771 case 't': /* */
1772 fmt_title(sb, /* */
1773 SymbolValue(s), /* */
1774 UsePreOr(1), /* */
1775 UsePostOr(0), /* */
1776 trans, /* */
1777 false, /* */
1778 TitleTitleSep); /* */
1779 break; /* */
1780 case 'd': /* */
1781 if ( fmt_digits(sb, /* */
1782 SymbolValue(s), /* */
1783 HasMinus, /* */
1784 HasPlus, /* */
1785 NodePre(kn), /* */
1786 UsePostOr(1), /* */
1787 true) ) /* */
1788 { return true; } /* */
1789 break; /* */
1790 case 'D': /* */
1791 if ( fmt_digits(sb, /* */
1792 SymbolValue(s), /* */
1793 HasMinus, /* */
1794 HasPlus, /* */
1795 NodePre(kn), /* */
1796 UsePostOr(1), /* */
1797 false) ) /* */
1798 { return true; } /* */
1799 break; /* */
1800 case 's': /* */
1801 fmt_string(sb, /* */
1802 SymbolValue(s), /* */
1803 UsePreOr(0xffff), /* */
1804 trans, /* */
1805 SymbolValue(TitleTitleSep));/* */
1806 break; /* */
1807 case 'W': /* */
1808 fmt_title(sb, /* */
1809 SymbolValue(s), /* */
1810 UsePreOr(1), /* */
1811 UsePostOr(0), /* */
1812 trans, /* */
1813 true, /* */
1814 sym_empty); /* */
1815 break; /* */
1816 case 'w': /* */
1817 fmt_title(sb, /* */
1818 SymbolValue(s), /* */
1819 UsePreOr(1), /* */
1820 UsePostOr(0), /* */
1821 trans, /* */
1822 false, /* */
1823 sym_empty); /* */
1824 break; /* */
1825 case 'p' | NodeCountMask: /* */
1826 case 'n' | NodeCountMask: /* */
1827 case 'N' | NodeCountMask: /* */
1828 if (fmt_c_names(SymbolValue(s), /* */
1829 UsePreOr(0), /* */
1830 UsePostOr(0), /* */
1831 HasMinus)) /* */
1832 { return true; } /* */
1833 break; /* */
1834 case 'd' | NodeCountMask: /* */
1835 case 's' | NodeCountMask: /* */
1836 if (fmt_c_string(SymbolValue(s), /* */
1837 UsePreOr(0), /* */
1838 UsePostOr(0), /* */
1839 HasMinus)) /* */
1840 { return true; } /* */
1841 break; /* */
1842 case 'T' | NodeCountMask: /* */
1843 case 'W' | NodeCountMask: /* */
1844 if (fmt_c_words(SymbolValue(s), /* */
1845 UsePreOr(0), /* */
1846 UsePostOr(0), /* */
1847 HasMinus, /* */
1848 true)) /* */
1849 { return true; } /* */
1850 break; /* */
1851 case 't' | NodeCountMask: /* */
1852 case 'w' | NodeCountMask: /* */
1853 if (fmt_c_words(SymbolValue(s), /* */
1854 UsePreOr(0), /* */
1855 UsePostOr(0), /* */
1856 HasMinus, /* */
1857 false)) /* */
1858 { return true; } /* */
1859 break; /* */
1860 default: return true; /* */
1861 } /* */
1862 } /* */
1863 else /* */
1864 { /* */
1865 DebugPrint1("Field not found"); /* */
1866 return true; /* */
1867 } /* */
1868 } /* */
1869 kn = NodeNext(kn); /* */
1870 } /* */
1871 #undef UsePostOr
1872 #undef UsePreOr
1873 #undef HasMinus
1874 #undef HasPlus
1875 return false; /* */
1876 } /*------------------------*/
1877
1878 /*-----------------------------------------------------------------------------
1879 ** Function*: eval__special()
1880 ** Purpose:
1881 **
1882 ** Arguments:
1883 ** sb the target StringBuffer
1884 ** kn the key node
1885 ** rec the record
1886 ** Returns: nothing
1887 **___________________________________________________ */
1888 static void eval__special(sb,kn,rec) /* */
1889 StringBuffer *sb; /* */
1890 KeyNode kn; /* */
1891 Record rec; /* */
1892 { Symbol s; /* */
1893 bool missing = true; /* */
1894 int fmt; /* */
1895 static Symbol s_author = NO_SYMBOL; /* */
1896 static Symbol s_editor = NO_SYMBOL; /* */
1897 static Symbol s_title = NO_SYMBOL; /* */
1898 static Symbol s_booktitle = NO_SYMBOL; /* */
1899 static Symbol s_key = NO_SYMBOL; /* */
1900 /* */
1901 if ( s_author == NO_SYMBOL ) /* */
1902 { s_author = symbol((String)"author"); /* */
1903 s_editor = symbol((String)"editor"); /* */
1904 s_title = symbol((String)"title"); /* */
1905 s_booktitle = symbol((String)"booktitle"); /* */
1906 s_key = symbol((String)"key"); /* */
1907 } /* */
1908 /* */
1909 if (key_seps == NULL) { init_key(); } /* */
1910 /* */
1911 fmt = ( NodePre(kn) == KEYSTYLE_LONG ? 1 : 0 ); /* */
1912 NameStrip(format[fmt]) = NodePost(kn); /* */
1913 /* */
1914 IfGetField(s, s_author) /* */
1915 { fmt_names(sb, /* */
1916 SymbolValue(s), /* */
1917 2, /* */
1918 fmt, /* */
1919 trans_lower); /* */
1920 missing = false; /* */
1921 } /* */
1922 else IfGetField(s, s_editor) /* */
1923 { fmt_names(sb, /* */
1924 SymbolValue(s), /* */
1925 2, /* */
1926 fmt, /* */
1927 trans_lower); /* */
1928 missing = false; /* */
1929 } /* */
1930 /* */
1931 IfGetField(s, s_title) /* */
1932 { (void)sbputs((char*)SymbolValue(NameTitleSep), /* */
1933 sb); /* */
1934 fmt_title(sb, /* */
1935 SymbolValue(s), /* */
1936 1, /* */
1937 0, /* */
1938 trans_lower, /* */
1939 true, /* */
1940 TitleTitleSep); /* */
1941 missing = false; /* */
1942 } /* */
1943 else IfGetField(s, s_booktitle) /* */
1944 { (void)sbputs((char*)SymbolValue(NameTitleSep), /* */
1945 sb); /* */
1946 fmt_title(sb, /* */
1947 SymbolValue(s), /* */
1948 1, /* */
1949 0, /* */
1950 trans_lower, /* */
1951 true, /* */
1952 TitleTitleSep); /* */
1953 missing = false; /* */
1954 } /* */
1955 /* */
1956 if (missing) /* */
1957 { sbrewind(sb); /* */
1958 IfGetField(s, s_key) /* */
1959 { fmt_title(sb, /* */
1960 SymbolValue(s), /* */
1961 1, /* */
1962 0, /* */
1963 trans_lower, /* */
1964 true, /* */
1965 TitleTitleSep); } /* */
1966 else /* */
1967 { (void)sbputs((char*)SymbolValue(DefaultKey), /* */
1968 sb); } /* */
1969 } /* */
1970 } /*------------------------*/
1971
1972 /*-----------------------------------------------------------------------------
1973 ** Function: apply_fmt()
1974 ** Purpose: Expands an arbitrary format specification for a given record.
1975 ** The format specification is given as a string.
1976 ** The result is stored in a string buffer.
1977 ** Arguments:
1978 ** sb Destination string buffer.
1979 ** fmt Format specification,
1980 ** rec Record to consider.
1981 ** db Database containing |rec|.
1982 ** Returns: |1| iff the format is invalid or the evaluation fails. |0|
1983 ** otherwise.
1984 **___________________________________________________ */
1985 int apply_fmt(sb,fmt,rec,db) /* */
1986 StringBuffer *sb; /* */
1987 char *fmt; /* */
1988 Record rec; /* */
1989 DB db; /* */
1990 { static char *old_fmt = NULL; /* */
1991 static KeyNode old_kn = (KeyNode)0; /* */
1992 /* */
1993 if ( old_fmt == NULL /* This is the first time */
1994 || strcmp(fmt,old_fmt) != 0 ) /* or the format needs */
1995 { /* recompilation. */
1996 key_init(); /* */
1997 if ( old_fmt != NULL ) /* */
1998 { free(old_fmt); /* */
1999 free_key_node(old_kn); /* */
2000 old_kn = (KeyNode)0; /* */
2001 } /* */
2002 /* */
2003 old_fmt = new_string(fmt); /* */
2004 if ( !add_fmt_tree(old_fmt, &old_kn) ) /* */
2005 { free(old_fmt); /* */
2006 old_fmt = NULL; /* */
2007 return 1; /* */
2008 } /* */
2009 } /* */
2010 return eval_fmt(sb, old_kn, rec, db); /* */
2011 } /*------------------------*/
2012
2013 /*-----------------------------------------------------------------------------
2014 ** Function: fmt_expand()
2015 ** Purpose: Expands a format specification of the % type into a given
2016 ** string buffer.
2017 **
2018 ** Arguments:
2019 ** sb destination string buffer
2020 ** cp format
2021 ** Returns: The first character after the % format.
2022 **___________________________________________________ */
2023 String fmt_expand(sb,cp,db,rec) /* */
2024 StringBuffer *sb; /* */
2025 Uchar *cp; /* */
2026 DB db; /* */
2027 Record rec; /* */
2028 { Symbol field; /* */
2029 Uchar c; /* */
2030 String trans = trans_id; /* */
2031 String s; /* */
2032 int pre = -1, /* */
2033 post = -1, /* */
2034 type = 0; /* */
2035 /* */
2036 if (key_seps == NULL) init_key(); /* */
2037 /* */
2038 while ( *cp && *cp != (Uchar)'%' ) /* */
2039 { sbputchar((Uchar)*cp,sb); /* */
2040 cp++; /* */
2041 } /* */
2042 DebugPrint2("Expanding ", cp); /* */
2043 /* */
2044 if ( *cp == (Uchar)'%' ) /* */
2045 { /* */
2046 switch ( *++cp ) /* */
2047 { case '+': trans = trans_upper; ++cp; break; /* */
2048 case '-': trans = trans_lower; ++cp; break; /* */
2049 } /* */
2050 ParseNumber(cp,pre); /* */
2051 if ( *cp == '.' || *cp == ',' || *cp == '-' ) /* */
2052 { cp++; /* */
2053 ParseNumber(cp,post); /* */
2054 } /* */
2055 if ( *cp == '#' ) /* */
2056 { cp++; /* */
2057 type |= NodeCountMask; /* */
2058 } /* */
2059 if ( !is_alpha(*cp) ) /* */
2060 { ErrPrintF("*** BibTool: Missing format type before: %s",cp);/* */
2061 return cp; /* */
2062 } /* */
2063 if ( strchr(percent_chars,*cp) == (char*)0 ) /* */
2064 { ErrPrintF("*** BibTool: Illegal format character: %c",*cp);/* */
2065 return cp; /* */
2066 } /* */
2067 type |= *(cp++); /* */
2068 Expect(cp,'(',cp); /* */
2069 SkipSpaces(cp); /* */
2070 s = cp; /* */
2071 SkipAllowed(cp); /* */
2072 c = *cp; /* */
2073 *cp = '\0'; /* */
2074 s = new_string(s);
2075 *cp = c; /* */
2076 field = symbol(s); /* */
2077 (void)free(s);
2078 SkipSpaces(cp); /* */
2079 if ( *cp == ')' ) { cp++; } /* */
2080 else /* */
2081 { ErrPrintF("*** BibTool: Missing ')' in format before: %s\n",cp);/* */
2082 return cp; /* */
2083 } /* */
2084 s = SymbolValue(field); /* */
2085 /* */
2086 if ( (field=get_field(db, rec, field)) != NULL )/* */
2087 { /* */
2088 DebugPrintF2("Field %s found\n", s); /* */
2089 /* */
2090 #define PostOr(X) (post > 0 ? post : (X))
2091 #define PreOr(X) (pre >= 0 ? pre : (X))
2092 #define HasMinus (type&NodeMinusMask)
2093 #define HasPlus (type&NodePlusMask)
2094 switch ( type & 0x1ff ) /* */
2095 { /* */
2096 case 'p': /* */
2097 fmt_names(sb, /* */
2098 SymbolValue(field), /* */
2099 PreOr(2), /* */
2100 PostOr(0), /* */
2101 trans); /* */
2102 break; /* */
2103 case 'n': /* */
2104 NameStrip(format[0]) = PostOr(-1); /* */
2105 fmt_names(sb, /* */
2106 SymbolValue(field), /* */
2107 PreOr(2), /* */
2108 0, /* */
2109 trans); /* */
2110 break; /* */
2111 case 'N': /* */
2112 NameStrip(format[1]) = PostOr(-1); /* */
2113 if (NextName(format[1])) /* */
2114 { NamePre(NextName(format[1])) = NamePreSep;/* */
2115 } /* */
2116 fmt_names(sb, /* */
2117 SymbolValue(field), /* */
2118 PreOr(2), /* */
2119 1, /* */
2120 trans); /* */
2121 break; /* */
2122 case 'T': /* */
2123 fmt_title(sb, /* */
2124 SymbolValue(field), /* */
2125 PreOr(1), /* */
2126 PostOr(0), /* */
2127 trans, /* */
2128 true, /* */
2129 TitleTitleSep); /* */
2130 break; /* */
2131 case 't': /* */
2132 fmt_title(sb, /* */
2133 SymbolValue(field), /* */
2134 PreOr(1), /* */
2135 PostOr(0), /* */
2136 trans, /* */
2137 false, /* */
2138 TitleTitleSep); /* */
2139 break; /* */
2140 case 'd': /* */
2141 (void)fmt_digits(sb, /* */
2142 SymbolValue(field), /* */
2143 HasMinus, /* */
2144 HasPlus, /* */
2145 pre, /* */
2146 PostOr(1), /* */
2147 true); /* */
2148 break; /* */
2149 case 'D': /* */
2150 (void)fmt_digits(sb, /* */
2151 SymbolValue(field), /* */
2152 HasMinus, /* */
2153 HasPlus, /* */
2154 pre, /* */
2155 PostOr(1), /* */
2156 false); /* */
2157 break; /* */
2158 case 's': /* */
2159 fmt_string(sb, /* */
2160 SymbolValue(field), /* */
2161 PreOr(0xffff), /* */
2162 trans, /* */
2163 (String)" "); /* */
2164 break; /* */
2165 case 'W': /* */
2166 fmt_title(sb, /* */
2167 SymbolValue(field), /* */
2168 PreOr(1), /* */
2169 PostOr(0), /* */
2170 trans, /* */
2171 true, /* */
2172 sym_empty); /* */
2173 break; /* */
2174 case 'w': /* */
2175 fmt_title(sb, /* */
2176 SymbolValue(field), /* */
2177 PreOr(1), /* */
2178 PostOr(0), /* */
2179 trans, /* */
2180 false, /* */
2181 sym_empty); /* */
2182 break; /* */
2183 } /* */
2184 } /* */
2185 else /* */
2186 { DebugPrint1("Field not found"); /* */
2187 } /* */
2188 } /* */
2189 /* */
2190 return cp; /* */
2191 } /*------------------------*/
2192 #undef PostOr
2193 #undef PreOr
2194 #undef HasMinus
2195 #undef HasPlus
2196
2197
2198 #ifdef DEBUG
2199 /*-----------------------------------------------------------------------------
2200 ** Function*: show_fmt()
2201 ** Purpose: Print a format tree onto the error stream
2202 ** Arguments:
2203 ** kn
2204 ** in
2205 ** Returns: nothing
2206 **___________________________________________________ */
2207 static void show_fmt(kn,in) /* */
2208 register KeyNode kn; /* */
2209 register int in; /* */
2210 { register int i; /* */
2211 #define NLin(S) ErrC('\n');for(i=in;i>0;i--) ErrC(' '); (void)fputs(S,err_file)
2212 #define ErrS(S) (void)fputs(S,err_file)
2213 /* */
2214 while ( kn != (KeyNode)0 ) /* */
2215 { switch ( NodeType(kn) ) /* */
2216 { case NodeSTRING: /* */
2217 ErrPrintF(" \"%s\"", /* */
2218 SymbolValue(NodeSymbol(kn))); /* */
2219 NLin(""); /* */
2220 break; /* */
2221 case NodeTEST: /* */
2222 ErrPrintF(" (%s)", /* */
2223 SymbolValue(NodeSymbol(kn))); /* */
2224 NLin("{ "); /* */
2225 show_fmt(NodeThen(kn),in+2); /* */
2226 NLin("}"); /* */
2227 NLin("{ "); /* */
2228 show_fmt(NodeElse(kn),in+2); /* */
2229 NLin("}"); /* */
2230 break; /* */
2231 case NodeOR: /* */
2232 ErrS("{ "); /* */
2233 show_fmt(NodeThen(kn),in+2); /* */
2234 ErrS("}"); /* */
2235 NLin("#"); /* */
2236 NLin("{ "); /* */
2237 show_fmt(NodeElse(kn),in+2); /* */
2238 NLin("}"); /* */
2239 break; /* */
2240 default: /* */
2241 fprintf(err_file,"%%%s", /* */
2242 (NodeType(kn)&NodePlusMask?"+": /* */
2243 (NodeType(kn)&NodeMinusMask?"-":"")));/* */
2244 if ( NodePre(kn)>=0 ) /* */
2245 fprintf(err_file,"%d",NodePre(kn)); /* */
2246 if ( NodePost(kn)>=0 ) /* */
2247 fprintf(err_file,".%d",NodePost(kn)); /* */
2248 fprintf(err_file,"%s%c(%s) ", /* */
2249 (NodeType(kn)&NodeCountMask?"#":""),/* */
2250 NodeType(kn)&0xff, /* */
2251 SymbolValue(NodeSymbol(kn))); /* */
2252 } /* */
2253 kn = NodeNext(kn); /* */
2254 } /* */
2255 } /*------------------------*/
2256
2257 #endif
2258
2259
2260 static Symbol sym_user = NO_SYMBOL;
2261 static Symbol sym_host = NO_SYMBOL;
2262
2263 /*-----------------------------------------------------------------------------
2264 ** Function: get_field()
2265 ** Purpose: Evaluate the record |rec|.
2266 ** If name starts with |@| then check the record name.
2267 ** If name starts with |$| then return the special info.
2268 ** Else search in Record |rec| for the field name and return its
2269 ** value. |NULL| is returned to indicate failure.
2270 ** Arguments:
2271 ** rec Record to analyze.
2272 ** name Field name to search for. This has to be a symbol if a
2273 ** normal field is sought. For pseudo fields it can be an
2274 ** arbitrary string.
2275 ** Returns: The address of the value or |NULL|.
2276 **___________________________________________________ */
2277 Symbol get_field(db,rec,name) /* */
2278 DB db; /* */
2279 register Record rec; /* */
2280 register Symbol name; /* */
2281 { String s = SymbolValue(name); /* */
2282 Symbol sym; /* */
2283 DebugPrint2("get_field ", s); /* */
2284 #ifdef HAVE_TIME_H
2285 static struct tm *tp; /* */
2286 static time_t the_time = 0; /* */
2287 static char buffer[32]; /* */
2288 /* */
2289 if ( the_time == 0 ) /* */
2290 { the_time = time(NULL); /* */
2291 tp = localtime(&the_time); /* */
2292 } /* */
2293 #define ReturnTime(F) if ( the_time > 0 ) \
2294 { (void)strftime(buffer,32,F,tp); \
2295 return symbol((String)buffer); } \
2296 LinkSymbol(sym_empty); return sym_empty
2297 #else
2298 #define ReturnTime(F) return sym_empty
2299 #endif
2300 /* */
2301 if (*s == '@') /* */
2302 { sym = EntryName(RecordType(rec)); /* */
2303 if (case_eq(s + 1, SymbolValue(sym))) /* */
2304 { LinkSymbol(sym);
2305 return sym; /* */
2306 }
2307 } /* */
2308 else if (*s == '$') /* */
2309 { ++s; /* */
2310 switch (*s) /* */
2311 { case 'k': case 'K': /* */
2312 if (case_eq(s, (String)"key")) /* */
2313 { return (*SymbolValue(*RecordHeap(rec)) /* */
2314 ? *RecordHeap(rec) /* */
2315 : NO_SYMBOL); /* */
2316 } /* */
2317 break; /* */
2318 case 'd': case 'D': /* */
2319 if (case_eq(s, (String)"default.key")) /* */
2320 { LinkSymbol(DefaultKey); /* */
2321 return DefaultKey; /* */
2322 } /* */
2323 else if (case_eq(s, (String)"day")) /* */
2324 { ReturnTime("%d"); } /* */
2325 break; /* */
2326 case 'f': case 'F': /* */
2327 if (case_eq(s, (String)"fmt.et.al")) /* */
2328 { LinkSymbol(EtAl); /* */
2329 return EtAl; } /* */
2330 else if (case_eq(s, /* */
2331 (String)"fmt.name.pre")) /* */
2332 { LinkSymbol(NamePreSep); /* */
2333 return NamePreSep; } /* */
2334 else if (case_eq(s, /* */
2335 (String)"fmt.inter.name"))/* */
2336 { LinkSymbol(InterNameSep); /* */
2337 return InterNameSep; } /* */
2338 else if (case_eq(s, /* */
2339 (String)"fmt.name.name")) /* */
2340 { LinkSymbol(NameNameSep); /* */
2341 return NameNameSep; } /* */
2342 else if (case_eq(s, /* */
2343 (String)"fmt.name.title"))/* */
2344 { LinkSymbol(NameTitleSep); /* */
2345 return NameTitleSep; } /* */
2346 else if (case_eq(s, /* */
2347 (String)"fmt.title.title"))/* */
2348 { LinkSymbol(TitleTitleSep); /* */
2349 return TitleTitleSep; } /* */
2350 case 'h': case 'H': /* */
2351 if (case_eq(s, (String)"hostname")) /* */
2352 { if (sym_host == NULL) /* */
2353 { s = (String)getenv("HOSTNAME"); /* */
2354 sym_host = symbol(s ? s : s_empty); /* */
2355 } /* */
2356 else /* */
2357 { LinkSymbol(sym_host); } /* */
2358 return sym_host; /* */
2359 } /* */
2360 else if (case_eq(s, (String)"hour")) /* */
2361 { ReturnTime("%H"); } /* */
2362 break; /* */
2363 case 'm': case 'M': /* */
2364 if (case_eq(s, (String)"month")) /* */
2365 { ReturnTime("%m"); } /* */
2366 else if (case_eq(s, (String)"minute")) /* */
2367 { ReturnTime("%M"); } /* */
2368 else if (case_eq(s, (String)"mon")) /* */
2369 { ReturnTime("%B"); } /* */
2370 break; /* */
2371 case 's': case 'S': /* */
2372 if (case_eq(s, (String)"sortkey")) /* */
2373 { LinkSymbol(RecordSortkey(rec)); /* */
2374 return RecordSortkey(rec); } /* */
2375 else if (case_eq(s, (String)"source")) /* */
2376 { LinkSymbol(RecordSource(rec)); /* */
2377 return RecordSource(rec); } /* */
2378 else if (case_eq(s, (String)"second")) /* */
2379 { ReturnTime("%S"); } /* */
2380 break; /* */
2381 case 't': case 'T': /* */
2382 if (case_eq(s, (String)"type")) /* */
2383 { sym = EntryName(RecordType(rec)); /* */
2384 if (sym) LinkSymbol(sym); /* */
2385 return sym; } /* */
2386 else if (case_eq(s, (String)"time")) /* */
2387 { ReturnTime("%H:%M:%S"); } /* */
2388 break; /* */
2389 case 'u': case 'U': /* */
2390 if (case_eq(s, (String)"user")) /* */
2391 { if (sym_user == NULL) /* */
2392 { s = (String)getenv("USER"); /* */
2393 sym_user = symbol(s ? s : s_empty); /* */
2394 } /* */
2395 else /* */
2396 { LinkSymbol(sym_user); } /* */
2397 return sym_user; /* */
2398 } /* */
2399 break; /* */
2400 case 'w': case 'W': /* */
2401 if (case_eq(s, (String)"weekday")) /* */
2402 { ReturnTime("%a"); } /* */
2403 break; /* */
2404 case 'y': case 'Y': /* */
2405 if (case_eq(s, (String)"year")) /* */
2406 { ReturnTime("%Y"); } /* */
2407 break; /* */
2408 } /* */
2409 } /* */
2410 else /* */
2411 { register Symbol *cpp; /* */
2412 Symbol xref; /* */
2413 register int n, count; /* */
2414 /* */
2415 for (count = rsc_xref_limit; /* */
2416 count >= 0; /* */
2417 count-- ) /* Prevent infinite loop */
2418 { /* */
2419 xref = NO_SYMBOL; /* */
2420 for (cpp = RecordHeap(rec), n = RecordFree(rec);/* */
2421 n > 0; /* */
2422 n -= 2 ) /* */
2423 { /* */
2424 if ( *cpp == name && *(cpp+1) != NO_SYMBOL )/* */
2425 { /* */
2426 sym = ( rsc_key_expand_macros /* */
2427 ? expand_rhs(*(cpp+1), /* */
2428 sym_open_brace, /* */
2429 sym_close_brace, /* */
2430 db, /* */
2431 false) /* */
2432 : *(cpp+1) ); /* */
2433 LinkSymbol(sym); /* */
2434 return sym; /* */
2435 } /* */
2436 /* */
2437 if ( *cpp == sym_crossref ) /* */
2438 { xref = *++cpp; } /* */
2439 else cpp++; /* */
2440 cpp++; /* */
2441 } /* */
2442 /* */
2443 if ( xref == NO_SYMBOL ) return NO_SYMBOL; /* No crossref field found*/
2444 xref = expand_rhs(xref, /* */
2445 sym_empty, /* */
2446 sym_empty, /* */
2447 db, /* */
2448 true); /* */
2449 if ( (rec = db_search(db, xref)) == RecordNULL )/* */
2450 { ErrPrintF("*** BibTool: Crossref `%s' not found.\n",/* */
2451 SymbolValue(xref)); /* */
2452 return NO_SYMBOL; /* */
2453 } /* */
2454 DebugPrint2("Following crossref to ", /* */
2455 SymbolValue(xref)); /* */
2456 } /* */
2457 } /* */
2458 /* */
2459 return NO_SYMBOL; /* Nothing found. */
2460 } /*------------------------*/
2461
2462 /*-----------------------------------------------------------------------------
2463 ** Function: set_field()
2464 ** Purpose: Store the given field or pseudo-field in a record.
2465 ** If the field is present then the old value is
2466 ** overwritten. Otherwise a new field is added. Fields
2467 ** starting with a |$| or |@| are treated special. They
2468 ** denote pseudo fields. If such a pseudo field is
2469 ** undefined then the assignment simply fails.
2470 **
2471 ** In contrast to the function |push_to_record()| this
2472 ** function does not assume that the arguments are
2473 ** symbols. In addition to |push_to_record()| it also
2474 ** handles pseudo-fields.
2475 ** Arguments:
2476 ** rec Record to receive the value.
2477 ** name Field name to add.
2478 ** value the new value
2479 ** Returns: |false| if the asignment has succeeded.
2480 **___________________________________________________ */
2481 bool set_field(db,rec,name,value) /* */
2482 DB db; /* */
2483 register Record rec; /* */
2484 Symbol name; /* */
2485 Symbol value; /* */
2486 { int c = *SymbolValue(name); /* */
2487 POSSIBLY_UNUSED(db); /* */
2488 /* */
2489 if (c == '@') /* */
2490 { /* */
2491 } /* */
2492 else if (c == '$') /* */
2493 { String s = ++SymbolValue(name); /* */
2494 switch (c) /* */
2495 { case 'k': case 'K': /* */
2496 if ( case_eq(s, (String)"key") ) /* */
2497 { SetSym(*RecordHeap(rec), value); /* */
2498 return false; /* */
2499 } /* */
2500 break; /* */
2501 case 'd': case 'D': /* */
2502 if ( case_eq(s, (String)"default.key") ) /* */
2503 { SetSym(DefaultKey, value); /* */
2504 return false; /* */
2505 } /* */
2506 break; /* */
2507 case 'f': case 'F': /* */
2508 if ( case_eq(s, (String)"fmt.et.al") ) /* */
2509 { SetSym(EtAl, value); /* */
2510 return false; /* */
2511 } /* */
2512 else if (case_eq(s, (String)"fmt.name.pre"))/* */
2513 { SetSym(NamePreSep, value); /* */
2514 return false; /* */
2515 } /* */
2516 else if (case_eq(s, (String)"fmt.inter.name"))/* */
2517 { SetSym(InterNameSep, value); /* */
2518 return false; /* */
2519 } /* */
2520 else if (case_eq(s, (String)"fmt.name.name"))/* */
2521 { SetSym(NameNameSep, value); /* */
2522 return false; /* */
2523 } /* */
2524 else if (case_eq(s, (String)"fmt.name.title"))/* */
2525 { SetSym(NameTitleSep, value); /* */
2526 return false; /* */
2527 } /* */
2528 else if (case_eq(s, (String)"fmt.title.title"))/* */
2529 { SetSym(TitleTitleSep, value); /* */
2530 return false; /* */
2531 } /* */
2532 case 's': case 'S': /* */
2533 if (case_eq(s, (String)"sortkey")) /* */
2534 { SetSym(RecordSortkey(rec), value); /* */
2535 return false; /* */
2536 } /* */
2537 else if (case_eq(s, (String)"source")) /* */
2538 { SetSym(RecordSource(rec), value); /* */
2539 return false; /* */
2540 } /* */
2541 break; /* */
2542 case 't': case 'T': /* */
2543 if (case_eq(s, (String)"type")) /* */
2544 { rec_type type; /* */
2545 if (IsNormalRecord(RecordType(rec)) && /* */
2546 (type=find_entry_type(SymbolValue(value))) >= 0)/* */
2547 { SetSym(RecordType(rec), type); /* */
2548 return false; /* */
2549 } /* */
2550 } /* */
2551 break; /* */
2552 case 'u': case 'U': /* */
2553 if (case_eq(s, (String)"user")) /* */
2554 { SetSym(sym_user, value); /* */
2555 return false; /* */
2556 } /* */
2557 break; /* */
2558 } /* */
2559 } /* */
2560 else /* */
2561 { push_to_record(rec, name, value, false); /* */
2562 return false; /* */
2563 } /* */
2564 /* */
2565 return true; /* Nothing found. */
2566 } /*------------------------*/