forked from dsopscak/utf8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonascii_main.c
51 lines (43 loc) · 1.05 KB
/
nonascii_main.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
48
49
50
/* nonascii_main.c */
#include <stdio.h>
int nonascii(FILE *, void (*)(int, int, int));
static void myprint(int c, int line, int pos)
{
printf("(%x) %d:%d\n", c, line, pos);
}
int
main(int argc, char *argv[])
{
void (*print)(int, int, int) = NULL;
FILE *the_file = stdin;
char *the_file_name = NULL;
if (argc > 1)
{
if (argv[1][0] == '-')
{
print = myprint;
if (argc > 2)
{
the_file_name = argv[2];
the_file = fopen(argv[2], "rb");
}
}
else
{
the_file_name = argv[1];
the_file = fopen(argv[1], "rb");
}
}
if (the_file == NULL)
{
if (the_file_name)
perror(the_file_name);
else
fprintf(stderr, "Looks like stdin is NULL\n");
return -1;
}
if (argc > 2)
printf("Scanning %s:\n", argv[2]);
/* reverse logic for shell */
return !nonascii(the_file, print);
}