File: show-ucs-data.c

package info (click to toggle)
glibc 2.23-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 233,552 kB
  • sloc: ansic: 987,702; asm: 260,118; sh: 10,380; makefile: 9,474; python: 3,957; cpp: 3,956; perl: 2,207; awk: 1,907; pascal: 1,527; yacc: 291; sed: 80
file content (69 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (30)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

int
main (int argc, char *argv[])
{
  int n;
  char *line = NULL;
  size_t len = 0;

  if (argc == 1)
    {
      static char *new_argv[] = { NULL, (char *) "/dev/stdin", NULL };
      argv = new_argv;
      argc = 2;
    }

  for (n = 1; n < argc; ++n)
    {
      FILE *fp = fopen (argv[n], "r");
      if (fp == NULL)
	continue;

      while (! feof (fp))
	{
	  ssize_t cnt = getline (&line, &len, fp);
	  char *runp;
	  if (cnt <= 0)
	    break;

	  runp = line;
	  do
	    {
	      if (runp[0] == '<' && runp[1] == 'U' && isxdigit (runp[2])
		  && isxdigit (runp[3]) && isxdigit (runp[4])
		  && isxdigit (runp[5]) && runp[6] == '>')
		{
		  unsigned int val = strtoul (runp + 2, NULL, 16);

		  //putchar ('<');
		  if (val < 128)
		    putchar (val);
		  else if (val < 0x800)
		    {
		      putchar (0xc0 | (val >> 6));
		      putchar (0x80 | (val & 0x3f));
		    }
		  else
		    {
		      putchar (0xe0 | (val >> 12));
		      putchar (0x80 | ((val >> 6) & 0x3f));
		      putchar (0x80 | (val & 0x3f));
		    }
		  //putchar ('>');
		  runp += 7;
		}
	      else
		putchar (*runp++);
	    }
	  while (runp < &line[cnt]);
	}

      fclose (fp);
    }

  return 0;
}