File: print.c

package info (click to toggle)
bibtool 2.68%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 2,608 kB
  • sloc: ansic: 11,808; perl: 8,145; makefile: 550; sh: 307; tcl: 51
file content (651 lines) | stat: -rw-r--r-- 29,517 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*** print.c ******************************************************************
** 
** This file is part of BibTool.
** It is distributed under the GNU General Public License.
** See the file COPYING for details.
** 
** (c) 1996-2020 Gerd Neugebauer
** 
** Net: gene@gerd-neugebauer.de
** 
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
**-----------------------------------------------------------------------------
** Description:
**	This module provides also access to the functions and
**	variables defined in |entry.c|. Consult also the documentation
**	of this file for details.
**
**
******************************************************************************/

#include <bibtool/general.h>
#include <bibtool/symbols.h>
#include <bibtool/print.h>
#include <bibtool/entry.h>
#include <bibtool/rsc.h>
#include <bibtool/macros.h>
#include <bibtool/sbuffer.h>
#include <bibtool/expand.h>
#include <bibtool/error.h>

/*****************************************************************************/
/* Internal Programs							     */
/*===========================================================================*/

#ifdef __STDC__
#define _ARG(A) A
#else
#define _ARG(A) ()
#endif
 char * sput_record _ARG((Record rec,DB db,String start));/* print.c         */
 static int fput_char _ARG((int c));		   /* print.c                */
 static int sput_char _ARG((int c));		   /* print.c                */
 static void indent _ARG((int col,int (*fct)_ARG((int))));/* print.c         */
 static void line_breaking _ARG((String t,int align,int (*fct)_ARG((int))));/* print.c*/
 static void print_equation _ARG((String pre,Symbol s,Symbol t,int align,int (*fct)_ARG((int))));/* print.c*/
 static void puts_in _ARG((String s,int in,int (*fct)_ARG((int))));/* print.c */
 void fput_record _ARG((FILE *file,Record rec,DB db,String start));/* print.c*/
 void put_record _ARG((int (*fct)_ARG((int)),Record rec,DB db,String start));/* print.c*/
 void set_key_type _ARG((String  s));		   /* print.c                */
 void set_symbol_type _ARG((String  s));	   /* print.c                */

/*****************************************************************************/
/* External Programs							     */
/*===========================================================================*/

/*---------------------------------------------------------------------------*/

#define TAB_WIDTH 8

 static int symbol_type = SYMBOL_TYPE_LOWER;	   /*                        */

 static String s_upper = (String)"upper";	   /*                        */
 static String s_lower = (String)"lower";	   /*                        */
 static String s_cased = (String)"cased";	   /*                        */

/*-----------------------------------------------------------------------------
** Function:	set_symbol_type()
** Purpose:	Function to set the symbol type which is used by the
**		printing routine. The argument is a string describing
**		the value to use. Possible values are |"upper"|,
**		|"lower"|, and |"cased"|. The comparison of the values
**		is performed case insensitive.
**
**		If no appropriate value is found then an error message
**		is issued as the only action.
**		
**		This function is called from \File{rsc.c}.
** Arguments:
**	s	String description of the value.
** Returns:	nothing
**___________________________________________________			     */
void set_symbol_type(s)				   /*			     */
  register String  s;				   /*			     */
{ if ( case_eq(s, s_upper) )			   /*			     */
  { symbol_type = SYMBOL_TYPE_UPPER; }		   /*			     */
  else if ( case_eq(s, s_cased) )		   /*			     */
  { symbol_type = SYMBOL_TYPE_CASED; }		   /*			     */
  else if ( case_eq(s, s_lower) )		   /*			     */
  { symbol_type = SYMBOL_TYPE_LOWER; }		   /*			     */
  else						   /*			     */
  { Err("Unknown symbol type ignored.\n"); }	   /*			     */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	get_symbol_type()
** Type:	String
** Purpose:	Getter for the symbol type.
** Arguments:	none
** Returns:	one of the values SYMBOL\_TYPE\_UPPER, SYMBOL\_TYPE\_LOWER,
**		or SYMBOL\_TYPE\_CASED as defined in header \textsf{type.h}
**___________________________________________________			     */
String get_symbol_type()			   /*                        */
{ switch (symbol_type)				   /*                        */
  { case SYMBOL_TYPE_UPPER: return s_upper;	   /*                        */
    case SYMBOL_TYPE_LOWER: return s_lower;	   /*                        */
    case SYMBOL_TYPE_CASED: return s_cased;	   /*                        */
    default: return NULL;			   /*                        */
  }						   /*                        */
}						   /*------------------------*/

#ifdef MAYBE_IN_THE_NEXT_RELEASE

 static int key_type = SYMBOL_TYPE_LOWER;	   /*                        */

/*-----------------------------------------------------------------------------
** Function*:	set_key_type()
** Purpose:	Wrapper function to set the static variable key_type.
**		This function is called from rsc.c
** Arguments:
**	s	String description of the value.
** Returns:	nothing
**___________________________________________________			     */
void set_key_type(s)				   /*			     */
  register String  s;				   /*			     */
{ if ( case_cmp(s,s_upper) )			   /*			     */
  { key_type = SYMBOL_TYPE_UPPER; }		   /*			     */
  else if ( case_cmp(s,s_cased) )		   /*			     */
  { key_type = SYMBOL_TYPE_CASED; }		   /*			     */
  else if ( case_cmp(s,s_lower) )		   /*			     */
  { key_type = SYMBOL_TYPE_LOWER; }		   /*			     */
  else						   /*			     */
  { Err("Unknown key type ignored.\n"); }	   /*			     */
}						   /*------------------------*/
#endif

						   /*------------------------*/
 static int column = 0;				   /* The current column of  */
						   /*  the output stream is  */
						   /*  kept in this variable.*/

#define NL	(void)(*fct)('\n'),column=0
#define PUTC(C) (void)((*fct)(C),++column)
#define PUTS(S) puts_in((String)(S), 0, fct)

/*-----------------------------------------------------------------------------
** Function:	puts_in()
** Purpose:	Print a string and update current column.
** Arguments:
**	s	string to be printed.
**	in	indentation. Alignment column.
**	fct	function to use for writing a character.
** Returns:	nothing
**___________________________________________________			     */
static void puts_in(s,in,fct)			   /*			     */
  register String s;				   /*			     */
  register int  in;				   /*                        */
  int (*fct)_ARG((int));			   /*                        */
{						   /*			     */
  while ( *s )					   /*			     */
  { (void)(*fct)(*s);			   	   /*                        */
    switch ( *(s++) )				   /*			     */
    { case '\t':				   /*                        */
	column += TAB_WIDTH - (column%TAB_WIDTH);  /*                        */
	break;					   /*	                     */
      case '\n':				   /*                        */
	column = 0;			   	   /*                        */
        if ( in > 0 ) indent(in, fct);		   /*                        */
        break;  				   /*			     */
      default: ++column;			   /*			     */
    }						   /*			     */
  }						   /*			     */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	indent()
** Purpose:	Add spaces or tabs to indent to the given column.
**		If the current column is beyond col then nothing happens.
**		The resource use.tabs can be used to disable the use of TAB.
** Arguments:
**	col	Target column
**	fct	function to use for writing a character.
** Returns:	nothing
**___________________________________________________			     */
static void indent(col,fct)			   /*			     */
  register int col;				   /*			     */
  int (*fct)_ARG((int));			   /*                        */
{						   /*			     */
  if ( col > rsc_linelen ) col = rsc_linelen;	   /*                        */
  while ( column < col )			   /*			     */
  { if (   rsc_use_tabs				   /*	TAB is allowed and   */
	&& column+TAB_WIDTH-(column%TAB_WIDTH) <= col )/* enough space left  */
    { (void)(*fct)('\t');			   /*	then put a TAB and   */
      column += TAB_WIDTH - (column%TAB_WIDTH);	   /*	update column.	     */
    }						   /*			     */
    else					   /* otherwise		     */
    { (void)(*fct)(' ');			   /*  write a single space  */
      ++column;					   /*  and advance column.   */
    }						   /*			     */
  }						   /*			     */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	line_breaking()
** Purpose:	Write out a right hand side of an equation.
**		If it does not fit break the line into several parts and
**		print them on successive lines.
**		Temporarily end marks are placed inside the string,
**		but the old contents has been restored at the end.
** Arguments:
**	t	string to print.
**	align	starting column for continuation lines.
**	fct	function to use for writing a character.
** Returns:	nothing
**___________________________________________________			     */
static void line_breaking(t, align, fct)	   /*			     */
  register String t;				   /* string to print.	     */
  int		 align;				   /* alignment column	     */
  int            (*fct)_ARG((int));		   /*                        */
{ register String s;			   	   /* intermediate pointer   */
  char		  end_c;			   /* temp. character.	     */
  int		  brace,			   /* brace counter	     */
		  len;				   /* length of rem. output  */
  bool		  first = true;			   /* indicator for #	     */
						   /*			     */
  while (is_space(*t)) ++t;			   /* skip leading spaces    */
						   /*			     */
  indent(align, fct);				   /* goto alignment column  */
						   /*			     */
  while (*t)					   /* as long as sth to print*/
  { s = t;					   /*			     */
						   /*			     */
    switch (*t)				   	   /*			     */
    { case '"':					   /* QUOTED PART	     */
	for ( len = 2, ++t;			   /*			     */
	     *t && *t != '\"';			   /* Search terminating "   */
	     ++t, ++len )			   /*			     */
	{ if ( *t == '\\' && *(t+1) != '\0' )	   /* skip over quoted and   */
	  { ++t; ++len; }			   /*  similar constructs.   */
	}					   /*			     */
	if ( *t ) ++t;				   /* skip after end, if poss*/
	if ( *t ) { end_c = *t; *t = '\0'; }	   /* save char and mark end.*/
	else	  { end_c = *t; }		   /*			     */
	break;					   /*			     */
      case '{':					   /* BRACED PART	     */
	brace = 1;				   /*			     */
	for ( len = 2, ++t;			   /* find matching brace.   */
	     *t && brace > 0;			   /*			     */
	     ++t, ++len )			   /*			     */
	{ switch ( *t )				   /*			     */
	  { case '\\': if ( *(t+1) ) ++t; break;   /* ignore \{ \} etc	     */
	    case '{': ++brace; break;		   /*			     */
	    case '}': brace--; break;		   /*			     */
	  }					   /*			     */
	}					   /*			     */
	if ( *t ) { end_c = *t; *t = '\0'; }	   /* save char and mark end.*/
	else	  { end_c = *t; }		   /*			     */
	break;					   /*			     */
      default:					   /* Now we should have a   */
	while ( is_allowed(*t) ) ++t;		   /*	SYMBOL		     */
	end_c = *t; *t = '\0';			   /*			     */
	s = SymbolValue(get_item(symbol(s),	   /*                        */
				 symbol_type));	   /*			     */
	len = strlen((char*)s);			   /*			     */
    }						   /*			     */
						   /* Now s is a single	     */
						   /*  string to print.	     */
						   /* t points to the closing*/
						   /*  '\0' of s	     */
						   /* end_c is the old *t    */
    while ( *s )				   /*			     */
    { if ( len + (first?0:3) <= rsc_linelen - column)/* Is there enough space*/
      { if ( !first ) PUTS(" # ");	   	   /* Maybe add separator    */
	puts_in(s, align, fct);			   /* write it out	     */
	s = t;					   /* and we are done	     */
      }						   /*			     */
      else if ( !first )			   /* If sth has been before */
      { puts_in((String)"\n# ", align - 2, fct);   /*  start a new line	     */
	first = true;				   /*			     */
      }						   /* Now we have to break   */
      else					   /*  a single entry	     */
      { Uchar  save_c;			   	   /*                        */
	String save_ptr,		   	   /*                        */
	       ptr;			   	   /*			     */
						   /*			     */
        if ( 0 <= rsc_linelen - column )	   /*                        */
	  save_ptr = s + rsc_linelen - column;	   /* Potential end	     */
	else					   /*                        */
	  save_ptr = s;				   /*                        */
 						   /*                        */
	for ( ptr = s;				   /* Search next newline    */
	      ptr < save_ptr && *ptr != '\n';	   /*  or end of region      */
	      ptr++ ) {}			   /*                        */
 						   /*                        */
	if ( *ptr == '\n' )			   /*                        */
	{ save_ptr = ptr;			   /*                        */
	  *save_ptr = '\0';	   		   /* Save and mark end.     */
	  puts_in(s, align, fct);		   /*                        */
	  NL;					   /*                        */
	  indent(align,fct);	   		   /*			     */
	  *save_ptr = '\n';			   /* Restore end	     */
	  len += s - save_ptr - 1;		   /* Update the length	     */
	  s = save_ptr + 1;			   /*			     */
	}					   /*                        */
	else					   /*                        */
	{					   /*                        */
	  while ( save_ptr != s && *save_ptr != ' ' )/*                      */
	  { save_ptr--; }			   /* Find a  SPC  backward  */
	  					   /*			     */
	  if ( save_ptr == s  )			   /* If no SPC found then   */
	  { while ( *save_ptr && *save_ptr != ' ' )/*  search one forward.   */
	    { save_ptr++; }	   		   /*                        */
	  }					   /*                        */
	  len += s - save_ptr;			   /* Update the length	     */
	  save_c = *save_ptr; *save_ptr = '\0';	   /* Save and mark end.     */
	  puts_in(s, align, fct);		   /*                        */
	  if (save_c != 0)			   /*                        */
	  { NL;					   /*                        */
	    indent(align, fct);	   		   /*			     */
	  }					   /*                        */
	  *save_ptr = save_c;			   /* Restore end	     */
	  s = save_ptr;	   			   /*			     */
	  while ( is_space(*s) ) { s++; len--; }   /* Skip spaces	     */
	}					   /*                        */
      }						   /*			     */
    }						   /*			     */
    *t = end_c;					   /* Restore the end	     */
						   /*			     */
    while ( *t && *t != '#' ) ++t;		   /* Search next #	     */
    if ( *t ) ++t;				   /* Skip beyond the #	     */
    while ( is_space(*t) ) ++t;			   /* Ignore following spaces*/
    first = false;				   /*			     */
  }						   /*			     */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	print_equation()
** Purpose:	Print something of the form  s = t 
**		If desired it can be indented. t is broken if it doesn't fit
**		in one line.
** Arguments:
**	pre	string to be printed before s.
**	s	left hand side
**	t	right hand side
**	align	target column. If negative no indentation is performed.
**	fct	function to use for writing a character.
** Returns:	nothing
**___________________________________________________'			     */
static void print_equation(pre, lhs, rhs, align, fct)/*			     */
  String pre;					   /*                        */
  Symbol lhs;				   	   /*			     */
  Symbol rhs;				   	   /*			     */
  int  align;				   	   /*			     */
  int (*fct)_ARG((int));			   /*                        */
{						   /*			     */
  if ( align < 0 )				   /*			     */
  { PUTS(pre);		   			   /*			     */
    PUTS(SymbolValue(get_item(lhs, symbol_type))); /*			     */
    PUTS(rsc_print_we ? " = " : "=");		   /*                        */
  }						   /*			     */
  else						   /*			     */
  { indent(rsc_indent, fct);			   /*			     */
    PUTS(pre);		   			   /*			     */
    PUTS(SymbolValue(get_item(lhs, symbol_type))); /*			     */
    if ( column >= align - 2 && rsc_print_we )	   /*                        */
    { PUTC(' '); }				   /*                        */
    else if ( rsc_eq_right )			   /*                        */
    { indent(align - 2, fct); }			   /*			     */
    else if ( column < align || rsc_print_we )	   /*                        */
    { PUTC(' '); }	   			   /*                        */
    PUTC('=');					   /*			     */
    if ( rsc_print_we )	{ PUTC(' '); }		   /*                        */
    line_breaking(SymbolValue(rhs), align, fct);   /*			     */
  }						   /*			     */
}						   /*------------------------*/

 static FILE * ofile=NULL;

/*-----------------------------------------------------------------------------
** Function:	fput_char()
** Purpose:	Output function which places the character on the |ofile| 
**		stream.
** Arguments:
**	c	Character to print.
** Returns:	The return status of |fputc()|.
**___________________________________________________			     */
static int fput_char(c)				   /*                        */
  int c;					   /*                        */
{ return fputc(c, ofile);			   /*                        */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	fput_record()
** Purpose:	Format and print a complete record onto a given stream.
**		for further details see |put_record()|.
** Arguments:
**	file	Stream to print onto.
**	db	Database containing the record.
**	rec	Record to print.
**	start	Initial string used before the type. Should be "@" normally.
** Returns:	nothing
**___________________________________________________			     */
void fput_record(file, rec, db, start)	   	   /*			     */
  FILE	 *file;			   		   /*                        */
  DB	 db;			   		   /*                        */
  Record rec;			   		   /* record to print	     */
  String start;		   	   	   	   /* initial string = "@"   */
{						   /*                        */
  ofile = file;					   /*                        */
  put_record(fput_char, rec, db, start);	   /*                        */
}						   /*------------------------*/

 static StringBuffer *osb = NULL;

/*-----------------------------------------------------------------------------
** Function:	sput_char()
** Purpose:	Output function which places the character on the |osb| 
**		string buffer.
** Arguments:
**	c	Character to print.
** Returns:	The return status of |fputc()|.
**___________________________________________________			     */
static int sput_char(c)				   /*                        */
  int c;					   /*                        */
{ return sbputchar(c, osb);			   /*                        */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	sput_record()
** Purpose:	Format and print a complete record into a string and return it.
**		The string returned points to static memory which is
**		reused upon the next invocation of this function.
** Arguments:
**	file	Stream to print onto.
**	db	Database containing the record.
**	rec	Record to print.
**	start	Initial string used before the type. Should be "@" normally.
** Returns:	The string containing the printed representation.
**___________________________________________________			     */
char * sput_record(rec, db, start)	   	   /*			     */
  DB	 db;			   		   /*                        */
  Record rec;			   		   /* record to print	     */
  String start;		   	   	   	   /* initial string = "@"   */
{						   /*                        */
  if ( osb == NULL ) osb = sbopen();		   /*                        */
  sbrewind(osb);				   /*                        */
  put_record(sput_char, rec, db, start);	   /*                        */
  return sbflush(osb);				   /*                        */
}						   /*------------------------*/

/*-----------------------------------------------------------------------------
** Function:	put_record()
** Purpose:	Format and print a complete record.
**		The record type and several resources are taken into
**		account. The following external variables (from
**		|rsc.c|) are taken into account:
**		\begin{description}
**		\item[rsc\_parentheses] If this boolean variable is
**		  |true| then |(| and |)| are used to delimit the
**		  record. Otherwise |{| and |}| are used.
**		\item[rsc\_col\_p] This integer variable controls the
**		  indentation of preamble records.
**		\item[rsc\_col\_s] This integer variable controls the
**		  indentation of string records.
**		\item[rsc\_expand\_macros] If this boolean variable is
**		  set then macros are expanded before the record is
**		  printed. This does not effect the internal
**		  representation. 
**		\item[rsc\_col] This integer variable controls the
**		  indentation of normal records.
**		\item[rsc\_col\_key] This integer variable controls the
**		  indentation of the key in a normal record.
**		\item[rsc\_newlines] This integer variable controls
**		  the number of newlines printed after a normal record.
**		\item[rsc\_linelen] This integer variable controls
**		  the length of the line. The line breaking algorithm
**		  is applied if this column is about to be violated.
**		\item[rsc\_indent] This integer variable controls the
**		  indentation of equations.
**		\item[rsc\_eq\_right] This boolean variable controls
**		  the alignment of the |=| in equations. It it is set
**		  then the equality sign is flushed right. Otherwise it
**		  is flushed left.
**		\end{description}
**
**		The field in the record are sorted with
**		|sort_record()| before they are printed.
**
**		In normal records all fields not starting with an
**		allowed character are ignored. Thus it is possible to
**		store private and invisible information in a
**		field. Simply start the field name with an not allowed
**		character like |%|.
** Arguments:
**	fct	function to use for writing a character.
**	db	Database containing the record.
**	rec	Record to print.
**	start	Initial string used before the type. Should be "@" normally.
** Returns:	nothing
**___________________________________________________			     */
void put_record(fct, rec, db, start)		   /*                        */
  int	       (*fct)_ARG((int));		   /*                        */
  Record       rec;				   /*                        */
  DB	       db;				   /*                        */
  String       start;		   	   	   /* initial string = "@"   */
{ Symbol       *hp;			   	   /* heap pointer	     */
  unsigned int i;			   	   /*			     */
  char	       open_brace, close_brace;		   /*			     */
  static int   first = 1;			   /*                        */
  						   /*                        */
  sort_record(rec);				   /*                        */
 						   /*                        */
  hp = RecordHeap(rec);				   /*			     */
  if ( rsc_no_nl && first ) { first = 0; }	   /*                        */
  else if ( IsNormalRecord(RecordType(rec)) ) { NL; }/*			     */
 						   /*                        */
  if ( *SymbolValue(RecordComment(rec)) )	   /*                        */
  { PUTS(SymbolValue(RecordComment(rec)));	   /*                        */
    NL;						   /*                        */
  }						   /*                        */
 						   /*                        */
  if (rsc_parentheses)			   	   /*                        */
  { open_brace  = '(';			   	   /*                        */
    close_brace = ')';			   	   /*                        */
  }						   /*                        */
  else						   /*                        */
  { open_brace  = '{';			   	   /*                        */
    close_brace = '}';			   	   /*                        */
  }						   /*                        */
 						   /*                        */
  switch (RecordType(rec))			   /*			     */
  { case BIB_COMMENT:				   /*			     */
#ifdef OLD
      indent(rsc_col_c, fct);			   /*			     */
      PUTS(*hp);				   /*			     */
      PUTC(' ');				   /*                        */
      NL;				   	   /*			     */
#endif
      break;					   /*			     */
    case BIB_PREAMBLE:				   /*			     */
      PUTS(start);				   /*			     */
      PUTS(SymbolValue(EntryName(RecordType(rec))));/*			     */
      PUTC(open_brace);				   /*			     */
      indent(rsc_col_p,fct);			   /*			     */
      line_breaking(SymbolValue(*hp),		   /*                        */
		    rsc_col_p,			   /*                        */
		    fct);	   		   /*			     */
      PUTC(' ');				   /*                        */
      PUTC(close_brace);			   /*                        */
      NL;				   	   /*			     */
      break;					   /*			     */
    case BIB_STRING:				   /*			     */
      PUTS(start);				   /*			     */
      PUTS(SymbolValue(EntryName(RecordType(rec))));/*			     */
      PUTC(open_brace);				   /*			     */
      print_equation(s_empty,			   /*                        */
		     *hp,		   	   /*                        */
		     *(hp+1),	   		   /*                        */
		     rsc_col_s,			   /*                        */
		     fct);			   /*		             */
      PUTC(' ');				   /*                        */
      PUTC(close_brace);			   /*                        */
      NL;				   	   /*			     */
      break;					   /*			     */
    case BIB_ALIAS:				   /*			     */
      PUTS(start);				   /*			     */
      PUTS(SymbolValue(EntryName(RecordType(rec))));/*			     */
      PUTC(open_brace);				   /*			     */
      print_equation(s_empty,			   /*                        */
		     *hp,		   	   /*                        */
		     *(hp+1),	   		   /*                        */
		     rsc_col_s,			   /*                        */
		     fct);			   /*		             */
      PUTC(' ');				   /*                        */
      PUTC(close_brace);			   /*                        */
      NL;				   	   /*			     */
      break;					   /*			     */
    case BIB_INCLUDE:				   /*			     */
      PUTS(start);				   /*			     */
      PUTS(SymbolValue(EntryName(RecordType(rec))));/*			     */
      PUTC(open_brace);				   /*			     */
      PUTS(SymbolValue(*RecordHeap(rec)));	   /*			     */
      PUTC(close_brace);			   /*                        */
      NL;				   	   /*			     */
      break;					   /*			     */
    case BIB_MODIFY:				   /*			     */
    default:					   /*			     */
 						   /*                        */
      if (RecordType(rec) == type_xdata		   /*                        */
	  && rsc_expand_xdata) return;		   /*                        */
 						   /*                        */
      PUTS(start);				   /*			     */
      PUTS(SymbolValue(EntryName(RecordType(rec))));/*			     */
      PUTC(open_brace);				   /*			     */
      { String comma1 = s_empty,		   /*                        */
	       comma2 = (String)",";		   /*                        */
 						   /*                        */
        if (rsc_print_ce)			   /*                        */
	{ comma1 = comma2;			   /*                        */
	  comma2 = s_empty;			   /*                        */
	}					   /*                        */
 						   /*                        */
        for ( i = RecordFree(rec); i > 0; i -= 2 ) /*			     */
	{		   			   /* No deleted or          */
	  if (*hp && is_allowed(*SymbolValue(*hp)))/*   private entry        */
	  { 					   /*                        */
	    if ( *(hp+1) )			   /* If equation	     */
	    { PUTS(comma1);			   /*                        */
	      NL;			   	   /*                        */
	      print_equation(comma2,		   /*                        */
			     *hp,	   	   /*                        */
			     (rsc_expand_macros	   /*                        */
			      ? expand_rhs(*(hp+1),/*                        */
					   (rsc_braces/*                     */
					    ? sym_open_brace/*               */
					    : sym_double_quote),/*           */
					   (rsc_braces/*                     */
					    ? sym_close_brace/*              */
					    : sym_double_quote),/*           */
					   db,	   /*                        */
					   false)  /*                        */
			      : *(hp+1) ),	   /*                        */
			     rsc_col,		   /*                        */
			     fct);		   /*                        */
	    }					   /*			     */
	    else				   /* Otherwise print a key  */
	    { indent(rsc_col_key, fct);		   /*			     */
	      PUTS(SymbolValue(get_key(*hp)));	   /*			     */
	    }					   /*			     */
	  }					   /*			     */
	  hp += 2;				   /* Goto next pair.	     */
	}					   /*                        */
      }						   /*			     */
      if (rsc_print_tc) { PUTC(','); }		   /*                        */
      NL;					   /*                        */
      PUTC(close_brace);	   	   	   /*                        */
      for ( i = rsc_newlines; i > 0; --i ) { NL; } /*                        */
  }						   /*			     */
}						   /*------------------------*/