URI:
       add wrap.c - randomcrap - random crap programs of varying quality
  HTML git clone git://git.codemadness.org/randomcrap
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 598277aab5416bb3cd13d0199ca09ba908ead6f3
   DIR parent 3460be2b98420fda3f4a6017615054da29f931d5
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed,  8 Mar 2023 21:50:36 +0100
       
       add wrap.c
       
       Flawed but simple word-like-wrapping tool.
       
       Diffstat:
         A wrap.c                              |      24 ++++++++++++++++++++++++
       
       1 file changed, 24 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/wrap.c b/wrap.c
       @@ -0,0 +1,24 @@
       +#include <stdio.h>
       +
       +int
       +main(void)
       +{
       +        /* softwrap: try to wrap on word boundary, otherwise hardwrap */
       +        int c, i = 0, sw = 72, hw = 79; 
       +
       +        while ((c = getchar()) != EOF) {
       +                putchar(c);
       +                if (c == '\n') {
       +                        i = 0;
       +                } else if (i > hw || (i > sw && (c == ' ' || c == '\t'))) {
       +                        putchar('\n');
       +                        i = 0;
       +                } else {
       +                        /* start of rune, wrongly assume 1 rune is 1 column for now */
       +                        if (!(c & 0x80))
       +                                i++;
       +                }
       +        }
       +
       +        return 0;
       +}