changeset 161:a765a51cbd5c

Make th_print_wrap() function public and move the code to th_util.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Feb 2015 18:41:00 +0200
parents a69764b4305f
children 578d9298cc1e
files th_args.c th_util.c th_util.h
diffstat 3 files changed, 56 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/th_args.c	Mon Feb 09 04:18:18 2015 +0200
+++ b/th_args.c	Mon Feb 09 18:41:00 2015 +0200
@@ -158,60 +158,6 @@
 
 /* Print help for commandline arguments/options
  */
-static void th_pad(FILE *outFile, int count)
-{
-    while (count--)
-        fputc(' ', outFile);
-}
-
-
-static 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");
-    }
-}
-
-
 void th_args_help(FILE *fh,
     const th_optarg_t *opts, const int numOpts,
     const int flags)
--- a/th_util.c	Mon Feb 09 04:18:18 2015 +0200
+++ b/th_util.c	Mon Feb 09 18:41:00 2015 +0200
@@ -142,6 +142,60 @@
 }
 
 
+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()
--- a/th_util.h	Mon Feb 09 04:18:18 2015 +0200
+++ b/th_util.h	Mon Feb 09 18:41:00 2015 +0200
@@ -123,6 +123,8 @@
 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);