* src/libs/libgroff/tmpfile.cpp [__MSDOS__, _Win32]
[s-roff.git] / src / libs / libgroff / errarg.cpp
blob2ddc0cc5dc111d78082bca2564d4c25f0a93adb4
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2002
3 Free Software Foundation, Inc.
4 Written by James Clark (jjc@jclark.com)
6 This file is part of groff.
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING. If not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <stdio.h>
23 #include "assert.h"
24 #include "errarg.h"
26 errarg::errarg(const char *p) : type(STRING)
28 s = p ? p : "(null)";
31 errarg::errarg() : type(EMPTY)
35 errarg::errarg(int nn) : type(INTEGER)
37 n = nn;
40 errarg::errarg(unsigned int uu) : type(UNSIGNED_INTEGER)
42 u = uu;
45 errarg::errarg(char cc) : type(CHAR)
47 c = cc;
50 errarg::errarg(unsigned char cc) : type(CHAR)
52 c = cc;
55 errarg::errarg(double dd) : type(DOUBLE)
57 d = dd;
60 int errarg::empty() const
62 return type == EMPTY;
65 extern "C" {
66 const char *i_to_a(int);
67 const char *ui_to_a(unsigned int);
70 void errarg::print() const
72 switch (type) {
73 case INTEGER:
74 fputs(i_to_a(n), stderr);
75 break;
76 case UNSIGNED_INTEGER:
77 fputs(ui_to_a(u), stderr);
78 break;
79 case CHAR:
80 putc(c, stderr);
81 break;
82 case STRING:
83 fputs(s, stderr);
84 break;
85 case DOUBLE:
86 fprintf(stderr, "%g", d);
87 break;
88 case EMPTY:
89 break;
93 errarg empty_errarg;
95 void errprint(const char *format,
96 const errarg &arg1,
97 const errarg &arg2,
98 const errarg &arg3)
100 assert(format != 0);
101 char c;
102 while ((c = *format++) != '\0') {
103 if (c == '%') {
104 c = *format++;
105 switch(c) {
106 case '%':
107 fputc('%', stderr);
108 break;
109 case '1':
110 assert(!arg1.empty());
111 arg1.print();
112 break;
113 case '2':
114 assert(!arg2.empty());
115 arg2.print();
116 break;
117 case '3':
118 assert(!arg3.empty());
119 arg3.print();
120 break;
121 default:
122 assert(0);
125 else
126 putc(c, stderr);