File: mystrings.c

package info (click to toggle)
enca 1.13-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,440 kB
  • ctags: 1,230
  • sloc: sh: 11,125; ansic: 10,330; xml: 2,926; makefile: 698; perl: 232
file content (45 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <ctype.h>
#include <stdio.h>

#define isbinary(x) (iscntrl(x) && !isspace(x))
#define istext(x) (islower(x) || isupper(x) || (x) > 127)

#define MINTEXT 4

#define FILL_CHARACTER ' '

int
main(void)
{
  int mode;
  unsigned char old[MINTEXT - 1];
  int c;

  mode = 0;
  while ((c = getchar()) != EOF) {
    if (isbinary(c)) {
      if (mode == 0) putchar('\n');
      mode = MINTEXT;
    }
    else {
      if (mode > 0) {
        if (istext(c)) {
          mode--;
          if (mode == 0) {
            int j;
            for (j = 0; j < MINTEXT-1; j++)
              putchar(old[j]);

            putchar(c);
          }
          else old[MINTEXT - mode - 1] = c;
        }
        else mode = MINTEXT;
      }
      else putchar(c);
    }
  }
  if (mode == 0) putchar('\n');

  return 0;
}