GNU Unifont: src/unicoverage.c File Reference

GNU Unifont 17.0.04 Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes

Macros | Functions
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. More...

## Functions
int | main (int argc, char *argv[])
| The main function. More...
int | nextrange (FILE *coveragefp, unsigned *cstart, unsigned *cend, char *coverstring)
| Get next Unicode range. More...
void | print_subtotal (FILE *outfp, int print_n, int nglyphs, unsigned cstart, unsigned 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.

## Macro Definition Documentation

## ◆ MAXBUF

#define MAXBUF 256

Maximum input line length - 1.

Definition at line 63 of 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 74 of file unicoverage.c.

75{
76
77 int print_n=0; /* print # of glyphs, not percentage */
78 unsigned i; /* loop variable */
79 unsigned slen; /* string length of coverage file line */
80 char inbuf[256]; /* input buffer */
81 unsigned thischar; /* the current character */
82
83 char *infile="", *outfile=""; /* names of input and output files */
84 FILE *infp, *outfp; /* file pointers of input and output files */
85 FILE *coveragefp; /* file pointer to coverage.dat file */
86 unsigned cstart, cend; /* current coverage start and end code points */
87 char coverstring[MAXBUF]; /* description of current coverage range */
88 int nglyphs; /* number of glyphs in this section */
89
90 /* to get next range & name of Unicode glyphs */
91 int nextrange (FILE *coveragefp, unsigned *cstart, unsigned *cend,
92 char *coverstring);
93
94 void print_subtotal (FILE *outfp, int print_n, int nglyphs,
95 unsigned cstart, unsigned cend, char *coverstring);
96
97 if ((coveragefp = fopen ("coverage.dat", "r")) == NULL) {
98 fprintf (stderr, "\nError: data file \"coverage.dat\" not found.\n\n");
99 exit (0);
100 }
101
102 if (argc > 1) {
103 for (i = 1; i < argc; i++) {
104 if (argv[i][0] == '-') { /* this is an option argument */
105 switch (argv[i][1]) {
106 case 'i': /* name of input file */
107 infile = &argv[i][2];
108 break;
109 case 'n': /* print number of glyphs instead of percentage */
110 print_n = 1;
111 case 'o': /* name of output file */
112 outfile = &argv[i][2];
113 break;
114 default: /* if unrecognized option, print list and exit */
115 fprintf (stderr, "\nSyntax:\n\n");
116 fprintf (stderr, " %s -p<Unicode_Page> ", argv[0]);
117 fprintf (stderr, "-i<Input_File> -o<Output_File> -w\n\n");
118 exit (1);
119 }
120 }
121 }
122 }
123 /*
124 Make sure we can open any I/O files that were specified before
125 doing anything else.
126 */
127 if (strlen (infile) > 0) {
128 if ((infp = fopen (infile, "r")) == NULL) {
129 fprintf (stderr, "Error: can't open %s for input.\n", infile);
130 exit (1);
131 }
132 }
133 else {
134 infp = stdin;
135 }
136 if (strlen (outfile) > 0) {
137 if ((outfp = fopen (outfile, "w")) == NULL) {
138 fprintf (stderr, "Error: can't open %s for output.\n", outfile);
139 exit (1);
140 }
141 }
142 else {
143 outfp = stdout;
144 }
145
146 /*
147 Print header row.
148 */
149 if (print_n) {
150 fprintf (outfp, "# Glyphs Range Script\n");
151 fprintf (outfp, "-------- ----- ------\n");
152 }
153 else {
154 fprintf (outfp, "Covered Range Script\n");
155 fprintf (outfp, "------- ----- ------\n\n");
156 }
157
158 slen = nextrange (coveragefp, &cstart, &cend, coverstring);
159 nglyphs = 0;
160
161 /*
162 Read in the glyphs in the file
163 */
164 while (slen != 0 && fgets (inbuf, MAXBUF-1, infp) != NULL) {
165 sscanf (inbuf, "%x", &thischar);
166
167 /* Read a character beyond end of current script. */
168 while (cend < thischar && slen != 0) {
169 print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
170
171 /* start new range total */
172 slen = nextrange (coveragefp, &cstart, &cend, coverstring);
173 nglyphs = 0;
174 }
175 nglyphs++;
176 }
177
178 print_subtotal (outfp, print_n, nglyphs, cstart, cend, coverstring);
179
180 exit (0);
181}
print_subtotal
void print_subtotal(FILE *outfp, int print_n, int nglyphs, unsigned cstart, unsigned cend, char *coverstring)
Print the subtotal for one Unicode script range.
Definition: unicoverage.c:237
MAXBUF
#define MAXBUF
Maximum input line length - 1.
Definition: unicoverage.c:63
nextrange
int nextrange(FILE *coveragefp, unsigned *cstart, unsigned *cend, char *coverstring)
Get next Unicode range.
Definition: unicoverage.c:196
Here is the call graph for this function:

## ◆ nextrange()

int nextrange | ( | FILE * | coveragefp,
|  | unsigned * | cstart,
|  | unsigned * | 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 196 of file unicoverage.c.

199{
200 int i;
201 static char inbuf[MAXBUF];
202 int retval; /* the return value */
203
204 retval = 0;
205
206 do {
207 if (fgets (inbuf, MAXBUF-1, coveragefp) != NULL) {
208 retval = strlen (inbuf);
209 if ((inbuf[0] >= '0' && inbuf[0] <= '9') ||
210 (inbuf[0] >= 'A' && inbuf[0] <= 'F') ||
211 (inbuf[0] >= 'a' && inbuf[0] <= 'f')) {
212 sscanf (inbuf, "%x-%x", cstart, cend);
213 i = 0;
214 while (inbuf[i] != ' ') i++; /* find first blank */
215 while (inbuf[i] == ' ') i++; /* find next non-blank */
216 strncpy (coverstring, &inbuf[i], MAXBUF);
217 }
218 else retval = 0;
219 }
220 else retval = 0;
221 } while (retval == 0 && !feof (coveragefp));
222
223 return (retval);
224}
Here is the caller graph for this function:

## ◆ print_subtotal()

void print_subtotal | ( | FILE * | outfp,
|  | int | print_n,
|  | int | nglyphs,
|  | unsigned | cstart,
|  | unsigned | 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 237 of file unicoverage.c.

238 {
239
240 /* print old range total */
241 if (print_n) { /* Print number of glyphs, not percentage */
242 fprintf (outfp, " %6d ", nglyphs);
243 }
244 else {
245 fprintf (outfp, " %5.1f%%", 100.0*nglyphs/(1+cend-cstart));
246 }
247
248 if (cend < 0x10000)
249 fprintf (outfp, " U+%04X..U+%04X %s",
250 cstart, cend, coverstring);
251 else
252 fprintf (outfp, " U+%05X..U+%05X %s",
253 cstart, cend, coverstring);
254
255 return;
256}
Here is the caller graph for this function: