No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / groff / src / libs / libgroff / errarg.cpp
blob705050f819d70bb53db1ef2e9d6d2c0a148adffa
1 /* $NetBSD$ */
3 // -*- C++ -*-
4 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2002
5 Free Software Foundation, Inc.
6 Written by James Clark (jjc@jclark.com)
8 This file is part of groff.
10 groff is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 groff is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License along
21 with groff; see the file COPYING. If not, write to the Free Software
22 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include <stdio.h>
25 #include "assert.h"
26 #include "errarg.h"
28 errarg::errarg(const char *p) : type(STRING)
30 s = p ? p : "(null)";
33 errarg::errarg() : type(EMPTY)
37 errarg::errarg(int nn) : type(INTEGER)
39 n = nn;
42 errarg::errarg(unsigned int uu) : type(UNSIGNED_INTEGER)
44 u = uu;
47 errarg::errarg(char cc) : type(CHAR)
49 c = cc;
52 errarg::errarg(unsigned char cc) : type(CHAR)
54 c = cc;
57 errarg::errarg(double dd) : type(DOUBLE)
59 d = dd;
62 int errarg::empty() const
64 return type == EMPTY;
67 extern "C" {
68 const char *i_to_a(int);
69 const char *ui_to_a(unsigned int);
72 void errarg::print() const
74 switch (type) {
75 case INTEGER:
76 fputs(i_to_a(n), stderr);
77 break;
78 case UNSIGNED_INTEGER:
79 fputs(ui_to_a(u), stderr);
80 break;
81 case CHAR:
82 putc(c, stderr);
83 break;
84 case STRING:
85 fputs(s, stderr);
86 break;
87 case DOUBLE:
88 fprintf(stderr, "%g", d);
89 break;
90 case EMPTY:
91 break;
95 errarg empty_errarg;
97 void errprint(const char *format,
98 const errarg &arg1,
99 const errarg &arg2,
100 const errarg &arg3)
102 assert(format != 0);
103 char c;
104 while ((c = *format++) != '\0') {
105 if (c == '%') {
106 c = *format++;
107 switch(c) {
108 case '%':
109 fputc('%', stderr);
110 break;
111 case '1':
112 assert(!arg1.empty());
113 arg1.print();
114 break;
115 case '2':
116 assert(!arg2.empty());
117 arg2.print();
118 break;
119 case '3':
120 assert(!arg3.empty());
121 arg3.print();
122 break;
123 default:
124 assert(0);
127 else
128 putc(c, stderr);