X-Git-Url: http://git.shiar.net/unifont.git/blobdiff_plain/119a78c606ce7e90f07f84f5307628fd5a0837f7..HEAD:/src/unidup.c diff --git a/src/unidup.c b/src/unidup.c index 59a4c81..04fe18f 100644 --- a/src/unidup.c +++ b/src/unidup.c @@ -31,17 +31,32 @@ #define MAXBUF 256 -int main () { +int +main (int argc, char **argv) +{ int ix, iy; char inbuf[MAXBUF]; + char *infile; /* the input file name */ + FILE *infilefp; /* file pointer to input file */ + + if (argc > 1) { + infile = argv[1]; + if ((infilefp = fopen (infile, "r")) == NULL) { + fprintf (stderr, "\nERROR: Can't open file %s\n\n", infile); + exit (EXIT_FAILURE); + } + } + else { + infilefp = stdin; + } ix = -1; - while (fgets(inbuf, MAXBUF-1, stdin) != NULL) { - sscanf(inbuf, "%X", &iy); - if (ix == iy) fprintf(stderr, "Duplicate code point: %04X\n", ix); + while (fgets (inbuf, MAXBUF-1, infilefp) != NULL) { + sscanf (inbuf, "%X", &iy); + if (ix == iy) fprintf (stderr, "Duplicate code point: %04X\n", ix); else ix = iy; } - exit(0); + exit (0); }