unifont-6.3.20131215.tar.gz
[unifont.git] / src / unidup.c
index 59a4c817075e08c0f83a8dabb7df08b6e8011715..04fe18fbdda85b540d2a18033b9a6344c2c08beb 100644 (file)
 #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);
 }