GNU Unifont: src/unicoverage.c File Reference

GNU Unifont 15.1.03 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.

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

## 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 60 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 71 of file unicoverage.c.

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

195{
196 int i;
197 static char inbuf[MAXBUF];
198 int retval; /* the return value */
199
200 retval = 0;
201
202 do {
203 if (fgets (inbuf, MAXBUF-1, coveragefp) != NULL) {
204 retval = strlen (inbuf);
205 if ((inbuf[0] >= '0' && inbuf[0] <= '9') ||
206 (inbuf[0] >= 'A' && inbuf[0] <= 'F') ||
207 (inbuf[0] >= 'a' && inbuf[0] <= 'f')) {
208 sscanf (inbuf, "%x-%x", cstart, cend);
209 i = 0;
210 while (inbuf[i] != ' ') i++; /* find first blank */
211 while (inbuf[i] == ' ') i++; /* find next non-blank */
212 strncpy (coverstring, &inbuf[i], MAXBUF);
213 }
214 else retval = 0;
215 }
216 else retval = 0;
217 } while (retval == 0 && !feof (coveragefp));
218
219 return (retval);
220}
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 233 of file unicoverage.c.

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