unicoverage.c File Reference

unicoverage - Show the coverage of Unicode plane scripts for a GNU Unifont hex glyph file More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
Include dependency graph for unicoverage.c:

Go to the source code of this file.

## Macros

#define | MAXBUF 256
| Maximum input line length - 1.

## Functions

int | main (int argc, char *argv[])
| The main function. More...
int | nextrange (FILE *coveragefp, int *cstart, int *cend, char *coverstring)
| Get next Unicode range. More...
void | print_subtotal (FILE *outfp, int print_n, int nglyphs, int cstart, int cend, char *coverstring)
| Print the subtotal for one Unicode script range. More...

## Detailed Description

unicoverage - Show the coverage of Unicode plane scripts for a GNU Unifont hex glyph file

Author
  Paul Hardy, unifoundry <at> unifoundry.com, 6 January 2008

Copyright
  Copyright (C) 2008, 2013 Paul Hardy

Synopsis: unicoverage [-ifont_file.hex] [-ocoverage_file.txt]

This program requires the file "coverage.dat" to be present in the directory from which it is run.

Definition in file unicoverage.c.

## Function Documentation

## main()

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

The main function.

Parameters

  [in] | argc | The count of command line arguments.
  [in] | argv | Pointer to array of command line arguments.

Returns
  This program exits with status 0.

Definition at line 68 of file unicoverage.c.

{
int print_n=0; /* print # of glyphs, not percentage */
unsigned i; /* loop variable */
unsigned slen; /* string length of coverage file line */
char inbuf[256]; /* input buffer */
unsigned thischar; /* the current character */
char *infile="", *outfile=""; /* names of input and output files */
FILE *infp, *outfp; /* file pointers of input and output files */
FILE *coveragefp; /* file pointer to coverage.dat file */
int cstart, cend; /* current coverage start and end code points */
char coverstring[MAXBUF]; /* description of current coverage range */
int nglyphs; /* number of glyphs in this section */
int nextrange(); /* to get next range & name of Unicode glyphs */
void print_subtotal (FILE *outfp, int print_n, int nglyphs,
int cstart, int cend, char *coverstring);
if ((coveragefp = fopen ("coverage.dat", "r")) == NULL) {
fprintf (stderr, "\nError: data file \"coverage.dat\" not found.\n\n");
exit (0);
}
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') { /* this is an option argument */
switch (argv[i][1]) {
case 'i': /* name of input file */
infile = &argv[i][2];
break;
case 'n': /* print number of glyphs instead of percentage */
print_n = 1;
case 'o': /* name of output file */
outfile = &argv[i][2];
break;
default: /* if unrecognized option, print list and exit */
fprintf (stderr, "\nSyntax:\n\n");
fprintf (stderr, " %s -p<Unicode_Page> ", argv[0]);
fprintf (stderr, "-i<Input_File> -o<Output_File> -w\n\n");
exit (1);
}
}
}
}
/*
Make sure we can open any I/O files that were specified before
doing anything else.
*/
if (strlen (infile) > 0) {
if ((infp = fopen (infile, "r")) == NULL) {
fprintf (stderr, "Error: can't open %s for input.\n", infile);
exit (1);
}
}
else {
infp = stdin;
}
if (strlen (outfile) > 0) {
if ((outfp = fopen (outfile, "w")) == NULL) {
fprintf (stderr, "Error: can't open %s for output.\n", outfile);
exit (1);
}
}
else {
outfp = stdout;
}
/*
Print header row.
*/
if (print_n) {
fprintf (outfp, "# Glyphs Range Script\n");
fprintf (outfp, "-------- ----- ------\n");
}
else {
fprintf (outfp, "Covered Range Script\n");
fprintf (outfp, "------- ----- ------\n\n");
}
slen = nextrange (coveragefp, &cstart, &cend, coverstring);
nglyphs = 0;
/*
Read in the glyphs in the file
*/
while (slen != 0 && fgets (inbuf, MAXBUF-1, infp) != NULL) {
sscanf (inbuf, "%x", &thischar);
/* Read a character beyond end of current script. */
while (cend < thischar && slen != 0) {
print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
/* start new range total */
slen = nextrange (coveragefp, &cstart, &cend, coverstring);
nglyphs = 0;
}
nglyphs++;
}
print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
exit (0);
}
Here is the call graph for this function:

## nextrange()

int nextrange | ( | FILE * | coveragefp,
|  | int * | cstart,
|  | int * | cend,
|  | char * | coverstring
| ) |  |

Get next Unicode range.

This function reads the next Unicode script range to count its glyph coverage.

Parameters

  [in] | coveragefp | File pointer to Unicode script range data file.
  [in] | cstart | Starting code point in current Unicode script range.
  [in] | cend | Ending code point in current Unicode script range.
  [out] | coverstring | String containing <cstart>-<cend> substring.

Returns
  Length of the last string read, or 0 for end of file.

Definition at line 187 of file unicoverage.c.

{
int i;
static char inbuf[MAXBUF];
int retval; /* the return value */
retval = 0;
do {
if (fgets (inbuf, MAXBUF-1, coveragefp) != NULL) {
retval = strlen (inbuf);
if ((inbuf[0] >= '0' && inbuf[0] <= '9') ||
(inbuf[0] >= 'A' && inbuf[0] <= 'F') ||
(inbuf[0] >= 'a' && inbuf[0] <= 'f')) {
sscanf (inbuf, "%x-%x", cstart, cend);
i = 0;
while (inbuf[i] != ' ') i++; /* find first blank */
while (inbuf[i] == ' ') i++; /* find next non-blank */
strncpy (coverstring, &inbuf[i], MAXBUF);
}
else retval = 0;
}
else retval = 0;
} while (retval == 0 && !feof (coveragefp));
return (retval);
}
Here is the caller graph for this function:

## print_subtotal()

void print_subtotal | ( | FILE * | outfp,
|  | int | print_n,
|  | int | nglyphs,
|  | int | cstart,
|  | int | cend,
|  | char * | coverstring
| ) |  |

Print the subtotal for one Unicode script range.

Parameters

  [in] | outfp | Pointer to output file.
  [in] | print_n | 1 = print number of glyphs, 0 = print percentage.
  [in] | nglyphs | Number of glyphs in current range.
  [in] | cstart | Starting code point for current range.
  [in] | cend | Ending code point for current range.
  [in] | coverstring | Character string of "<cstart>-<cend>".

Definition at line 228 of file unicoverage.c.

{
/* print old range total */
if (print_n) { /* Print number of glyphs, not percentage */
fprintf (outfp, " %6d ", nglyphs);
}
else {
fprintf (outfp, " %5.1f%%", 100.0*nglyphs/(1+cend-cstart));
}
if (cend < 0x10000)
fprintf (outfp, " U+%04X..U+%04X %s",
cstart, cend, coverstring);
else
fprintf (outfp, " U+%05X..U+%05X %s",
cstart, cend, coverstring);
return;
}
Here is the caller graph for this function:
MAXBUF
#define MAXBUF
Maximum input line length - 1.
Definition: unicoverage.c:57
print_subtotal
void print_subtotal(FILE *outfp, int print_n, int nglyphs, int cstart, int cend, char *coverstring)
Print the subtotal for one Unicode script range.
Definition: unicoverage.c:228
nextrange
int nextrange(FILE *coveragefp, int *cstart, int *cend, char *coverstring)
Get next Unicode range.
Definition: unicoverage.c:187