1 /*
2 NETWIB
3 Network library
4 Copyright(c) 1999-2010 Laurent Constantin
5 -----
6
7 Main server : http://www.laurentconstantin.com/
8 Backup server : http://laurentconstantin.free.fr/
9 [my current email address is on the web servers]
10
11 -----
12 This file is part of Netwib.
13
14 Netwib is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 3
16 as published by the Free Software Foundation.
17
18 Netwib is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details (http://www.gnu.org/).
22
23 ------------------------------------------------------------------------
24 */
25
26 #include <netwib/inc/maininc.h>
27
28 /*-------------------------------------------------------------*/
netwib_buf_display(netwib_constbuf * pbuf,netwib_encodetype encodetype)29 netwib_err netwib_buf_display(netwib_constbuf *pbuf,
30 netwib_encodetype encodetype)
31 {
32 netwib_string pc;
33 netwib_buf buf;
34 netwib_err ret;
35
36 if (encodetype == NETWIB_ENCODETYPE_DATA) {
37 /* try the quick solution */
38 ret = netwib_constbuf_ref_string(pbuf, &pc);
39 if (ret == NETWIB_ERR_OK) {
40 fprintf(stdout, "%s", pc);
41 fflush(stdout);
42 return(NETWIB_ERR_OK);
43 }
44 /* it did not work, so continue below */
45 }
46
47 netwib_er(netwib_buf_init_mallocdefault(&buf));
48 ret = netwib_buf_encode(pbuf, encodetype, &buf);
49 if (ret == NETWIB_ERR_OK) {
50 netwib_er(netwib_buf_ref_string(&buf, &pc));
51 fprintf(stdout, "%s", pc);
52 fflush(stdout);
53 }
54 netwib_er(netwib_buf_close(&buf));
55
56 return(ret);
57 }
58
59 /*-------------------------------------------------------------*/
netwib_fmt_display(netwib_conststring fmt,...)60 netwib_err netwib_fmt_display(netwib_conststring fmt,
61 ...)
62 {
63 va_list ap;
64 netwib_err ret;
65 netwib_string pc;
66 netwib_buf buf;
67
68 netwib_er(netwib_buf_init_mallocdefault(&buf));
69 va_start(ap, fmt);
70 ret = netwib_priv_buf_append_vfmt(&buf, fmt, &ap);
71 va_end(ap);
72 if (ret == NETWIB_ERR_OK) {
73 netwib_er(netwib_buf_ref_string(&buf, &pc));
74 fprintf(stdout, "%s", pc);
75 fflush(stdout);
76 }
77 netwib_er(netwib_buf_close(&buf));
78
79 return(ret);
80 }
81
82
83