# HG changeset patch # User Matti Hamalainen # Date 1423500776 -7200 # Node ID 578d9298cc1ef4cf77325d6a7e82e7f6c70aff38 # Parent a765a51cbd5cfec1a82a0bb74ea41196e103e81b Actually, move th_print_wrap() to th_string module. diff -r a765a51cbd5c -r 578d9298cc1e th_string.c --- a/th_string.c Mon Feb 09 18:41:00 2015 +0200 +++ b/th_string.c Mon Feb 09 18:52:56 2015 +0200 @@ -572,3 +572,59 @@ return (len == 6) ? val : -1; } + + +static void th_pad(FILE *outFile, int count) +{ + while (count--) + fputc(' ', outFile); +} + + +void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width) +{ + size_t pos = 0; + BOOL first = TRUE; + + while (str[pos]) + { + // Pre-pad line + int linelen = first ? spad : rpad; + th_pad(fh, first ? 0 : rpad); + first = FALSE; + + // Skip whitespace at line start + while (th_isspace(str[pos]) || str[pos] == '\n') pos++; + + // Handle each word + while (str[pos] && str[pos] != '\n') + { + size_t next; + int wlen; + + // Find word length and next break + for (wlen = 0, next = pos; str[next] && !th_isspace(str[next]) && str[next] != '\n'; next++, wlen++); + + // Check if we have too much of text? + if (linelen + wlen >= width) + break; + + // Print what we have + for (;pos < next; pos++, linelen++) + fputc(str[pos], fh); + + // Check if we are at end of input or hard linefeed + if (str[next] == '\n' || str[next] == 0) + break; + else + { + fputc(str[pos], fh); + pos++; + linelen++; + } + } + fprintf(fh, "\n"); + } +} + + diff -r a765a51cbd5c -r 578d9298cc1e th_string.h --- a/th_string.h Mon Feb 09 18:41:00 2015 +0200 +++ b/th_string.h Mon Feb 09 18:52:56 2015 +0200 @@ -79,6 +79,8 @@ int th_get_hex_triplet(const char *); +void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width); + #ifdef __cplusplus } diff -r a765a51cbd5c -r 578d9298cc1e th_util.c --- a/th_util.c Mon Feb 09 18:41:00 2015 +0200 +++ b/th_util.c Mon Feb 09 18:52:56 2015 +0200 @@ -142,60 +142,6 @@ } -static void th_pad(FILE *outFile, int count) -{ - while (count--) - fputc(' ', outFile); -} - - -void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width) -{ - size_t pos = 0; - BOOL first = TRUE; - - while (str[pos]) - { - // Pre-pad line - int linelen = first ? spad : rpad; - th_pad(fh, first ? 0 : rpad); - first = FALSE; - - // Skip whitespace at line start - while (th_isspace(str[pos]) || str[pos] == '\n') pos++; - - // Handle each word - while (str[pos] && str[pos] != '\n') - { - size_t next; - int wlen; - - // Find word length and next break - for (wlen = 0, next = pos; str[next] && !th_isspace(str[next]) && str[next] != '\n'; next++, wlen++); - - // Check if we have too much of text? - if (linelen + wlen >= width) - break; - - // Print what we have - for (;pos < next; pos++, linelen++) - fputc(str[pos], fh); - - // Check if we are at end of input or hard linefeed - if (str[next] == '\n' || str[next] == 0) - break; - else - { - fputc(str[pos], fh); - pos++; - linelen++; - } - } - fprintf(fh, "\n"); - } -} - - /* Error handling */ int th_get_error() diff -r a765a51cbd5c -r 578d9298cc1e th_util.h --- a/th_util.h Mon Feb 09 18:41:00 2015 +0200 +++ b/th_util.h Mon Feb 09 18:52:56 2015 +0200 @@ -123,8 +123,6 @@ int th_term_width(); int th_term_height(); -void th_print_wrap(FILE *fh, const char *str, int spad, int rpad, int width); - int th_get_error(); int th_errno_to_error(int error); const char *th_error_str(int error);