unifont-6.3.20131215.tar.gz
[unifont.git] / src / unidup.c
1 /*
2    unidup - check for duplicate code points in sorted unifont.hex file.
3
4    Synopsis: unidup < unifont_file.hex
5
6              [Hopefully there won't be any output!]
7
8    Author: Paul Hardy, unifoundry <at> unifoundry.com, December 2007
9
10    Copyright (C) 2007, 2008, 2013 Paul Hardy
11
12    LICENSE:
13
14       This program is free software: you can redistribute it and/or modify
15       it under the terms of the GNU General Public License as published by
16       the Free Software Foundation, either version 2 of the License, or
17       (at your option) any later version.
18
19       This program is distributed in the hope that it will be useful,
20       but WITHOUT ANY WARRANTY; without even the implied warranty of
21       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22       GNU General Public License for more details.
23
24       You should have received a copy of the GNU General Public License
25       along with this program.  If not, see <http://www.gnu.org/licenses/>.
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #define MAXBUF 256
32
33
34 int
35 main (int argc, char **argv)
36 {
37
38    int ix, iy;
39    char inbuf[MAXBUF];
40    char *infile;   /* the input file name */
41    FILE *infilefp; /* file pointer to input file */
42
43    if (argc > 1) {
44       infile = argv[1];
45       if ((infilefp = fopen (infile, "r")) == NULL) {
46          fprintf (stderr, "\nERROR: Can't open file %s\n\n", infile);
47          exit (EXIT_FAILURE);
48       }
49    }
50    else {
51       infilefp = stdin;
52    }
53
54    ix = -1;
55
56    while (fgets (inbuf, MAXBUF-1, infilefp) != NULL) {
57       sscanf (inbuf, "%X", &iy);
58       if (ix == iy) fprintf (stderr, "Duplicate code point: %04X\n", ix);
59       else ix = iy;
60    }
61    exit (0);
62 }