1 /* title.h -- fprintf that underlines
2    Copyright (c) 1988, 89, 90, 91, 92, 93 Miguel Santana
3    Copyright (c) 1995, 96, 97, 98 Akim Demaille, Miguel Santana
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 
19 /*
20  * Note:
21  * very strong inspiration was taken in error.[ch] by
22  * David MacKenzie <djm@gnu.ai.mit.edu>
23  */
24 
25 /* Get prototypes for the functions defined here.  */
26 #if HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 #include <stdio.h>
31 
32 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
33 # if __STDC__
34 #  include <stdarg.h>
35 #  define VA_START(args, lastarg) va_start(args, lastarg)
36 # else
37 #  include <varargs.h>
38 #  define VA_START(args, lastarg) va_start(args)
39 # endif
40 #else
41 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
42 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
43 #endif
44 
45 # ifndef __attribute__
46 /* This feature is available in gcc versions 2.5 and later.  */
47 #  if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
48 #   define __attribute__(Spec) /* empty */
49 #  endif
50 /* The __-protected variants of `format' and `printf' attributes
51    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
52 #  if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
53 #   define __format__ format
54 #   define __printf__ printf
55 #  endif
56 # endif
57 
58 #include "title.h"
59 #include "printlen.h"
60 
61 /* Print the message FORMAT, which is a printf-style
62    format string*/
63 
64 void
65 #if defined(VA_START) && __STDC__
title(FILE * stream,char c,int center_p,const char * format,...)66 title (FILE * stream, char c, int center_p, const char *format, ...)
67 #else
68 title (stream, c, center_p, format, va_alist)
69      FILE * stream;
70      char c;
71      int center_p;
72      char *format;
73      va_dcl
74 #endif
75 {
76   int len;
77   int padding;
78 #ifdef VA_START
79   va_list args;
80 #endif
81 
82 #ifdef VA_START
83   VA_START (args, format);
84 
85   len = vprintflen (format, args);
86   if (format [strlen (format) - 1] == '\n')
87     len --;
88   if (center_p)
89     for (padding = 0 ; padding < 79 - len ; padding += 2)
90       putc (' ', stream);
91   va_end(args);
92   VA_START(args, format);
93 # if HAVE_VPRINTF || _LIBC
94   vfprintf (stream, format, args);
95 # else
96   _doprnt (format, args, stream);
97 # endif
98   va_end (args);
99 #else
100   fprintf (stream, format, a1, a2, a3, a4, a5, a6, a7, a8);
101 #endif
102   /* We suppose that \n can only be met at the end of format, not
103    * of one of its arguments */
104   if (format [strlen (format) - 1] != '\n')
105     putc ('\n', stream);
106 
107   /* Draw the line */
108   if (center_p)
109     for (padding = 0 ; padding < 79 - len ; padding += 2)
110       putc (' ', stream);
111   for (/* nothing */ ; len ; len --)
112     putc (c, stream);
113   putc ('\n', stream);
114 
115   fflush (stream);
116 }
117