File indexing completed on 2024-04-28 11:21:06
0001 #include <stdio.h> 0002 #include <stdlib.h> 0003 0004 int 0005 main(argc, argv) 0006 char **argv; 0007 { 0008 register int c; 0009 int xp; 0010 int width; 0011 0012 if ( argc != 2 ) { 0013 fprintf(stderr, "usage: %s width\n", argv[0]); 0014 exit(1); 0015 } 0016 else if ( (width=atoi(argv[1])) < 1 ) { 0017 fprintf(stderr, "%s: please set width to > 0\n", argv[0]); 0018 exit(1); 0019 } 0020 0021 0022 for ( xp = 1; (c = getchar()) != EOF; xp++ ) { 0023 while ( c & 0xC0 ) { 0024 /* assume that (1) the output device understands utf-8, and 0025 * (2) the only c & 0x80 input is utf-8. 0026 */ 0027 do { 0028 if ( xp <= width ) 0029 putchar(c); 0030 } while ( (c = getchar()) != EOF && (c & 0x80) && !(c & 0x40) ); 0031 ++xp; 0032 } 0033 if ( c == '\n' ) 0034 xp = 0; 0035 if ( xp <= width ) 0036 putchar(c); 0037 } 0038 exit(0); 0039 }