aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--util/ChangeLog7
-rw-r--r--util/miscutil.c54
-rw-r--r--util/strgutil.c33
3 files changed, 94 insertions, 0 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 35e69fb31..e74bf851e 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jul 1 12:47:31 CEST 1999 Werner Koch <[email protected]>
+
+
+ * miscutil.c (make_printable_string): New.
+
+ * strgutil.c (add_to_strlist2,append_to_strlist2): New.
+
Tue Jun 29 21:44:25 CEST 1999 Werner Koch <[email protected]>
diff --git a/util/miscutil.c b/util/miscutil.c
index d982e64af..4244ccce0 100644
--- a/util/miscutil.c
+++ b/util/miscutil.c
@@ -149,6 +149,60 @@ print_string( FILE *fp, const byte *p, size_t n, int delim )
putc(*p, fp);
}
+/****************
+ * This function returns a string which is suitable for printing
+ * Caller must release it with m_free()
+ */
+char *
+make_printable_string( const byte *p, size_t n, int delim )
+{
+ size_t save_n, buflen;
+ const byte *save_p;
+ char *buffer, *d;
+
+ /* first count length */
+ for(save_n = n, save_p = p, buflen=1 ; n; n--, p++ ) {
+ if( iscntrl( *p ) || *p == delim ) {
+ if( *p=='\n' || *p=='\r' || *p=='\f'
+ || *p=='\v' || *p=='\b' || !*p )
+ buflen += 2;
+ else
+ buflen += 3;
+ }
+ else
+ buflen++;
+ }
+ p = save_p;
+ n = save_n;
+ /* and now make the string */
+ d = buffer = m_alloc( buflen );
+ for( ; n; n--, p++ ) {
+ if( iscntrl( *p ) || *p == delim ) {
+ *d++ = '\\';
+ if( *p == '\n' )
+ *d++ = 'n';
+ else if( *p == '\r' )
+ *d++ = 'r';
+ else if( *p == '\f' )
+ *d++ = 'f';
+ else if( *p == '\v' )
+ *d++ = 'v';
+ else if( *p == '\b' )
+ *d++ = 'b';
+ else if( !*p )
+ *d++ = '0';
+ else {
+ sprintf(d, "x%02x", *p );
+ d += 2;
+ }
+ }
+ else
+ *d++ = *p;
+ }
+ *d = 0;
+ return buffer;
+}
+
int
answer_is_yes( const char *s )
diff --git a/util/strgutil.c b/util/strgutil.c
index 94f8a5d6c..b27f9b7b6 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -94,6 +94,25 @@ add_to_strlist( STRLIST *list, const char *string )
return sl;
}
+/****************
+ * ame as add_to_strlist() but if is_utf8 is *not* set a conversion
+ * to UTF8 is done
+ */
+STRLIST
+add_to_strlist2( STRLIST *list, const char *string, int is_utf8 )
+{
+ STRLIST sl;
+
+ if( is_utf8 )
+ sl = add_to_strlist( list, string );
+ else {
+ char *p = native_to_utf8( string );
+ sl = add_to_strlist( list, p );
+ m_free( p );
+ }
+ return sl;
+}
+
STRLIST
append_to_strlist( STRLIST *list, const char *string )
{
@@ -113,6 +132,20 @@ append_to_strlist( STRLIST *list, const char *string )
return sl;
}
+STRLIST
+append_to_strlist2( STRLIST *list, const char *string, int is_utf8 )
+{
+ STRLIST sl;
+
+ if( is_utf8 )
+ sl = append_to_strlist( list, string );
+ else {
+ char *p = native_to_utf8( string );
+ sl = append_to_strlist( list, p );
+ m_free( p );
+ }
+ return sl;
+}
STRLIST