aboutsummaryrefslogtreecommitdiffstats
path: root/troff/troff.d/otfdump.c
blob: 283e6ae07d1d6ba7ef627273affecd3b444baa52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
 *
 * Sccsid @(#)otfdump.c	1.15 (gritter) 3/16/06
 */

static enum show {
	SHOW_CHARS		= 001,
	SHOW_KERNPAIRS		= 002,
	SHOW_SUBSTITUTIONS	= 004,
	SHOW_NAME		= 010
} show;

#include <stdarg.h>

static void	print(enum show, const char *, ...);

#define	DUMP
#include <stdio.h>
#include <unistd.h>
#include "otf.c"
#include "afm.c"

#include <libgen.h>

static const char	*progname;
struct dev	dev;
char	*chname;
short	*chtab;
int	nchtab;

static int	prname;

static void
print(enum show s, const char *fmt, ...)
{
	va_list	ap;

	if (show & s) {
		if (prname)
			printf("%s: ", filename);
		va_start(ap, fmt);
		vprintf(fmt, ap);
		va_end(ap);
		putchar('\n');
	}
}

void
verrprint(const char *s, va_list ap)
{
	fprintf(stderr, "%s: ", progname);
	vfprintf(stderr, s, ap);
	putc('\n', stderr);
}

void
errprint(const char *s, ...)
{
	va_list	ap;

	va_start(ap, s);
	verrprint(s, ap);
	va_end(ap);
}

static void
devinit(void)
{
	dev.res = 72000;
	dev.hor = dev.vert = 1;
	dev.unitwidth = 1;
	dev.afmfonts = 1;
}

static void
usage(void)
{
	errprint("usage: %s [-ckns] font ...", progname);
	exit(2);
}

static int
dump(const char *name)
{
	struct afmtab	A;
	struct stat	st;
	FILE	*fp;
	char	*cp;

	if ((fp = fopen(filename = name, "r")) == NULL) {
		errprint("%s: cannot open", filename);
		return 1;
	}
	memset(&A, 0, sizeof A);
	a = &A;
	a->file = a->path = (char *)filename;
	a->base = strdup(filename);
	a->base = basename(a->base);
	if ((cp = strrchr(a->base, '.')) != NULL)
		*cp = '\0';
	if (fstat(fileno(fp), &st) < 0) {
		errprint("%s: cannot stat", filename);
		return 1;
	}
	size = st.st_size;
	contents = malloc(size);
	if (fread(contents, 1, size, fp) != size) {
		errprint("%s: cannot read", filename);
		return 1;
	}
	fclose(fp);
	return otfget(a, contents, size) != 0;
}

int
main(int argc, char **argv)
{
	int	i, e = 0;

	progname = basename(argv[0]);
	devinit();
	while ((i = getopt(argc, argv, "ckns")) != EOF) {
		switch (i) {
		case 'c':
			show |= SHOW_CHARS;
			break;
		case 'k':
			show |= SHOW_KERNPAIRS;
			break;
		case 'n':
			show |= SHOW_NAME;
			break;
		case 's':
			show |= SHOW_SUBSTITUTIONS;
			break;
		default:
			usage();
		}
	}
	if (show == 0)
		show = 0xFFFFFFFF;
	if (argc < optind + 1)
		usage();
	prname = argc > optind + 1;
	for (i = optind; i < argc; i++)
		e |= dump(argv[i]);
	return e;
}

void
afmaddchar(struct afmtab *a, int C, int tp, int cl, int WX, int B[4], char *N,
		enum spec s, int gid)
{
	if (N)
		print(SHOW_CHARS, "char %s width %d", N, _unitconv(WX));
}

void
afmalloc(struct afmtab *a, int n)
{
}

void
afmaddkernpair(struct afmtab *a, int ch1, int ch2, int k)
{
}

static void
kernpair(int first, int second, int x)
{
	char	*s1, *s2;

	if (x) {
		s1 = GID2SID(first);
		s2 = GID2SID(second);
		if (s1 && s2)
			print(SHOW_KERNPAIRS, "kernpair %s %s width %d",
				s1, s2, _unitconv(x));
	}
}

static void
kerninit(void)
{
}

static void
kernfinish(void)
{
}