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>
Go to the source code of this file.
|  | 
| #define | MAXBUF   256 | 
|  | Maximum input line length - 1. 
 | 
|  | 
|  | 
| 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... 
 | 
|  | 
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.
◆ 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.
   77    char *infile=
"", *outfile=
"";  
 
   86                         int cstart, 
int cend, 
char *coverstring);
 
   88    if ((coveragefp = fopen (
"coverage.dat", 
"r")) == NULL) {
 
   89       fprintf (stderr, 
"\nError: data file \"coverage.dat\" not found.\n\n");
 
   94       for (i = 1; i < argc; i++) {
 
   95          if (argv[i][0] == 
'-') {  
 
  103                   outfile = &argv[i][2];
 
  106                   fprintf (stderr, 
"\nSyntax:\n\n");
 
  107                   fprintf (stderr, 
"   %s -p<Unicode_Page> ", argv[0]);
 
  108                   fprintf (stderr, 
"-i<Input_File> -o<Output_File> -w\n\n");
 
  118    if (strlen (infile) > 0) {
 
  119       if ((infp = fopen (infile, 
"r")) == NULL) {
 
  120          fprintf (stderr, 
"Error: can't open %s for input.\n", infile);
 
  127    if (strlen (outfile) > 0) {
 
  128       if ((outfp = fopen (outfile, 
"w")) == NULL) {
 
  129          fprintf (stderr, 
"Error: can't open %s for output.\n", outfile);
 
  141       fprintf (outfp, 
"# Glyphs      Range        Script\n");
 
  142       fprintf (outfp, 
"--------      -----        ------\n");
 
  145       fprintf (outfp, 
"Covered      Range        Script\n");
 
  146       fprintf (outfp, 
"-------      -----        ------\n\n");
 
  149    slen = 
nextrange (coveragefp, &cstart, &cend, coverstring);
 
  155    while (slen != 0 && fgets (inbuf, 
MAXBUF-1, infp) != NULL) {
 
  156       sscanf (inbuf, 
"%x", &thischar);
 
  159       while (cend < thischar && slen != 0) {
 
  160          print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
 
  163          slen = 
nextrange (coveragefp, &cstart, &cend, coverstring);
 
  169    print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
 
void print_subtotal(FILE *outfp, int print_n, int nglyphs, int cstart, int cend, char *coverstring)
Print the subtotal for one Unicode script range.
#define MAXBUF
Maximum input line length - 1.
int nextrange(FILE *coveragefp, int *cstart, int *cend, char *coverstring)
Get next Unicode range.
 
 
 
◆ 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.
  192    static char inbuf[
MAXBUF];
 
  198       if (fgets (inbuf, 
MAXBUF-1, coveragefp) != NULL) {
 
  199          retval = strlen (inbuf);
 
  200          if ((inbuf[0] >= 
'0' && inbuf[0] <= 
'9') ||
 
  201              (inbuf[0] >= 
'A' && inbuf[0] <= 
'F') ||
 
  202              (inbuf[0] >= 
'a' && inbuf[0] <= 
'f')) {
 
  203             sscanf (inbuf, 
"%x-%x", cstart, cend);
 
  205             while (inbuf[i] != 
' ') i++;  
 
  206             while (inbuf[i] == 
' ') i++;  
 
  207             strncpy (coverstring, &inbuf[i], 
MAXBUF);
 
  212    } 
while (retval == 0 && !feof (coveragefp));
 
 
 
 
◆ 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.
  233       fprintf (outfp, 
" %6d ", nglyphs);
 
  236       fprintf (outfp, 
" %5.1f%%", 100.0*nglyphs/(1+cend-cstart));
 
  240       fprintf (outfp, 
"  U+%04X..U+%04X   %s",
 
  241                cstart, cend, coverstring);
 
  243       fprintf (outfp, 
" U+%05X..U+%05X  %s",
 
  244                cstart, cend, coverstring);