-
Notifications
You must be signed in to change notification settings - Fork 0
/
k2c.c
47 lines (42 loc) · 759 Bytes
/
k2c.c
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
/*
* UTF-8 to HEX string converter
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ShowUsage();
int main(argc, argv)
int argc;
char *argv[];
{
int ch, oldch = ' ';
if (1 < argc) {
if (strcmp(argv[1], "-h") == 0
|| strcmp(argv[1], "--help") == 0) {
ShowUsage();
exit(0);
}
}
while ((ch = getchar()) != EOF) {
if (ch & 0x80) {
if (oldch & 0x80) {
putchar(' ');
}
printf("%02x", ch);
oldch = ch;
} else {
putchar(ch);
oldch = ch;
}
}
}
int ShowUsage()
{
fprintf(stderr, "Usage: k2c [OPTION]\n");
fprintf(stderr, "\n");
fprintf(stderr, " -h show usage\n");
fprintf(stderr, "\n");
fprintf(stderr,
"convert UTF-8 to HEX string from stdin and output to stdout\n");
return 0;
}