1 /*
2  * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
3  * All rights reserved.  The file named COPYRIGHT specifies the terms
4  * and conditions for redistribution.
5  */
6 
7 
8 #include "config.h"
9 #ifndef NO_SIO
10 #include "sio.h"
11 #endif
12 
13 #include "str.h"
14 #include "strparse.h"
15 
16 #define INT_NULL			((int *)0)
17 
18 /*
19  * The strx_* functions will never over-run the buffer
20  * The str_* functions may over-run the buffer
21  */
22 
23 /*
24  * Group 1: the strx_* functions
25  */
26 
27 /*
28  * This is the general purpose conversion function. It is invoked
29  * by all the other str[x]_* functions
30  */
strx_printv(int * ccp,char * buf,int len,const char * format,va_list ap)31 void strx_printv( int *ccp, char *buf, int len, const char *format, va_list ap )
32 {
33 #ifndef NO_SIO
34 	__sio_od_t od ;
35 	int cc ;
36 
37    /*
38     * First initialize the descriptor
39 	 * Notice that if no length is given, we initialize buf_end to the
40 	 * highest possible address.
41     */
42    od.buf = buf ;                						/* NOT NEEDED        */
43    od.buf_end = len ? &buf[ len ] : (char *) ~0 ;	/* NEEDED				*/
44    od.buffer_size = 0 ;          						/* NOT NEEDED        */
45    od.start = buf ;              						/* NOT NEEDED        */
46    od.nextb = buf ;              						/* NEEDED            */
47    od.buftype = 0 ;              						/* NOT NEEDED        */
48 
49    /*
50     * Do the conversion
51     */
52    cc = __sio_converter( &od, -1, format, ap ) ;
53 	if ( len == 0 || od.nextb < od.buf_end )
54 		*(od.nextb) = '\0' ;
55    if ( ccp )
56       *ccp = cc ;
57 #endif	/* ! NO_SIO */
58 }
59 
60 
strx_print(int * ccp,char * buf,int len,const char * format,...)61 void strx_print( int *ccp, char *buf, int len, const char *format, ... )
62 {
63 	va_list ap ;
64 
65 	if (len <= 0) {
66 		if( ccp )
67 			*ccp = 0;
68 		return;
69 	}
70 
71 	va_start( ap, format ) ;
72 	strx_printv( ccp, buf, len, format, ap ) ;
73 	va_end( ap ) ;
74 }
75 
76 
strx_sprint(char * buf,int len,const char * format,...)77 char *strx_sprint( char *buf, int len, const char *format, ... )
78 {
79 	va_list ap ;
80 
81 	if (len <= 0) {
82 		return buf;
83 	}
84 	va_start( ap, format ) ;
85 	strx_printv( INT_NULL, buf, len, format, ap ) ;
86 	va_end( ap ) ;
87 	return( buf ) ;
88 }
89 
90 
strx_nprint(char * buf,int len,const char * format,...)91 int strx_nprint( char *buf, int len, const char *format, ...)
92 {
93 	int cc ;
94 	va_list ap ;
95 
96 	if (len <= 0) {
97 		return 0;
98 	}
99 	va_start( ap, format ) ;
100 	strx_printv( &cc, buf, len, format, ap ) ;
101 	va_end( ap ) ;
102 	return( cc ) ;
103 }
104 
105 
strx_nprintv(char * buf,int len,const char * format,va_list ap)106 int strx_nprintv( char *buf, int len, const char *format, va_list ap )
107 {
108 	int cc ;
109 
110 	if (len <= 0) {
111 		return 0;
112 	}
113 	strx_printv( &cc, buf, len, format, ap ) ;
114 	return( cc ) ;
115 }
116 
117 
118