2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
display print functions
Copyright ( C ) Andrew Tridgell 2001
2007-12-14 00:46:33 +03:00
Copyright ( C ) Jelmer Vernooij 2007
2003-08-13 05:53:07 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
/*
2007-10-14 15:00:12 +04:00
this module provides functions for printing internal strings in the
" display charset " .
This charset may be quite different from the chosen unix charset .
2003-08-13 05:53:07 +04:00
Eventually these functions will need to take care of column count constraints
The d_ prefix on print functions in Samba refers to the display character set
conversion
*/
# include "includes.h"
2007-03-07 13:00:14 +03:00
# include "system/locale.h"
2007-12-14 00:46:09 +03:00
# include "param/param.h"
2003-08-13 05:53:07 +04:00
2007-12-14 00:46:33 +03:00
static smb_iconv_t display_cd = ( smb_iconv_t ) - 1 ;
void d_set_iconv ( smb_iconv_t cd )
{
display_cd = cd ;
}
2006-03-07 19:37:35 +03:00
_PUBLIC_ int d_vfprintf ( FILE * f , const char * format , va_list ap ) _PRINTF_ATTRIBUTE ( 2 , 0 )
2003-08-13 05:53:07 +04:00
{
char * p , * p2 ;
2007-12-14 00:46:33 +03:00
int ret , clen ;
2003-08-13 05:53:07 +04:00
va_list ap2 ;
2007-12-14 00:46:33 +03:00
/* If there's nothing to convert, take a shortcut */
if ( display_cd = = ( smb_iconv_t ) - 1 ) {
return vfprintf ( f , format , ap ) ;
}
2005-06-04 10:45:11 +04:00
/* do any message translations */
2006-04-08 20:05:21 +04:00
va_copy ( ap2 , ap ) ;
2005-06-04 10:45:11 +04:00
ret = vasprintf ( & p , format , ap2 ) ;
2007-02-06 08:26:25 +03:00
va_end ( ap2 ) ;
2003-08-13 05:53:07 +04:00
if ( ret < = 0 ) return ret ;
2007-12-14 00:46:33 +03:00
clen = convert_string_talloc_descriptor ( NULL , display_cd , p , ret , ( void * * ) & p2 ) ;
2007-03-07 13:00:14 +03:00
if ( clen = = - 1 ) {
/* the string can't be converted - do the best we can,
filling in non - printing chars with ' ? ' */
int i ;
for ( i = 0 ; i < ret ; i + + ) {
if ( isprint ( p [ i ] ) | | isspace ( p [ i ] ) ) {
fwrite ( p + i , 1 , 1 , f ) ;
} else {
fwrite ( " ? " , 1 , 1 , f ) ;
}
}
SAFE_FREE ( p ) ;
return ret ;
}
2003-08-13 05:53:07 +04:00
/* good, its converted OK */
SAFE_FREE ( p ) ;
ret = fwrite ( p2 , 1 , clen , f ) ;
2007-12-14 00:46:33 +03:00
talloc_free ( p2 ) ;
2003-08-13 05:53:07 +04:00
return ret ;
}
2006-03-07 19:37:35 +03:00
_PUBLIC_ int d_fprintf ( FILE * f , const char * format , . . . ) _PRINTF_ATTRIBUTE ( 2 , 3 )
2003-08-13 05:53:07 +04:00
{
int ret ;
va_list ap ;
va_start ( ap , format ) ;
ret = d_vfprintf ( f , format , ap ) ;
va_end ( ap ) ;
return ret ;
}
2006-03-07 19:37:35 +03:00
_PUBLIC_ int d_printf ( const char * format , . . . ) _PRINTF_ATTRIBUTE ( 1 , 2 )
2003-08-13 05:53:07 +04:00
{
int ret ;
va_list ap ;
va_start ( ap , format ) ;
2007-10-14 15:00:12 +04:00
ret = d_vfprintf ( stdout , format , ap ) ;
2003-08-13 05:53:07 +04:00
va_end ( ap ) ;
return ret ;
}
2007-12-14 00:46:33 +03:00