GNU Unifont: src/unicoverage.c File Reference

GNU Unifont 15.1.02 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, 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.

## Macro Definition Documentation

## ◆ MAXBUF

#define MAXBUF 256

Maximum input line length - 1.

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

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

190{
191 int i;
192 static char inbuf[MAXBUF];
193 int retval; /* the return value */
194
195 retval = 0;
196
197 do {
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);
204 i = 0;
205 while (inbuf[i] != ' ') i++; /* find first blank */
206 while (inbuf[i] == ' ') i++; /* find next non-blank */
207 strncpy (coverstring, &inbuf[i], MAXBUF);
208 }
209 else retval = 0;
210 }
211 else retval = 0;
212 } while (retval == 0 && !feof (coveragefp));
213
214 return (retval);
215}
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.

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