51 broke -E logic completely, rewise it
[tfcrypt.git] / tfc_say.c
1 /*
2  * tfcrypt -- high security Threefish encryption tool.
3  *
4  * tfcrypt is copyrighted:
5  * Copyright (C) 2012-2019 Andrey Rys. All rights reserved.
6  *
7  * tfcrypt is licensed to you under the terms of std. MIT/X11 license:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28
29 #include "tfcrypt.h"
30
31 void tfc_vfsay(FILE *where, tfc_yesno addnl, const char *fmt, va_list ap)
32 {
33         if (!strcmp(fmt, "\n")) {
34                 fputc('\n', where);
35                 return;
36         }
37
38         vfprintf(where, fmt, ap);
39         if (addnl) fputc('\n', where);
40         fflush(where);
41 }
42
43 void tfc_nfsay(FILE *where, const char *fmt, ...)
44 {
45         va_list ap;
46
47         va_start(ap, fmt);
48         tfc_vfsay(where, NO, fmt, ap);
49         va_end(ap);
50 }
51
52 void tfc_esay(const char *fmt, ...)
53 {
54         va_list ap;
55
56         va_start(ap, fmt);
57         tfc_vfsay(stderr, YES, fmt, ap);
58         va_end(ap);
59 }
60
61 void tfc_say(const char *fmt, ...)
62 {
63         va_list ap;
64
65         va_start(ap, fmt);
66         tfc_vfsay(stdout, YES, fmt, ap);
67         va_end(ap);
68 }