Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
752 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. main(argc, argv)
  4. char **argv;
  5. {
  6. register c;
  7. int xp;
  8. int width;
  9. if ( argc != 2 ) {
  10. fprintf(stderr, "usage: %s width\n", argv[0]);
  11. exit(1);
  12. }
  13. else if ( (width=atoi(argv[1])) < 1 ) {
  14. fprintf(stderr, "%s: please set width to > 0\n", argv[0]);
  15. exit(1);
  16. }
  17. for ( xp = 1; (c = getchar()) != EOF; xp++ ) {
  18. while ( c & 0xC0 ) {
  19. /* assume that (1) the output device understands utf-8, and
  20. * (2) the only c & 0x80 input is utf-8.
  21. */
  22. do {
  23. if ( xp <= width )
  24. putchar(c);
  25. } while ( (c = getchar()) != EOF && (c & 0x80) && !(c & 0x40) );
  26. ++xp;
  27. }
  28. if ( c == '\n' )
  29. xp = 0;
  30. if ( xp <= width )
  31. putchar(c);
  32. }
  33. exit(0);
  34. }