summaryrefslogtreecommitdiff
path: root/fonts/cun/cunsort.c
blob: 43c83de8ce09c8cedc36aa5d45c7f28143d4f699 (plain)
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
#include <stdio.h>
#include <stdlib.h>

struct cun {
	char	let;
	int	wedges;
	int	fnum;
	};

struct cun	d[3000];

int	cundif(c1, c2)
struct cun	*c1, *c2;
{
	if (c1->wedges == c2->wedges)
		return(c2->let - c1->let);
	return(c2->wedges - c1->wedges);
}

void	main()
{
	FILE	*fin;
	int	cnt, start, end;
	char	l;
	char	fname[42];
	char	inbuf[128];

	for (cnt = 0; cnt < 3000; cnt++)
	{
		sprintf(fname, "cun%04d.mf", cnt + 1);
		fin = fopen(fname, "r");
		if (fin == NULL)
			break;
		d[cnt].fnum = cnt + 1;
		while (fgets(inbuf, 128, fin) != NULL)
		{
			if (!strncmp(inbuf, "beginchar(", 10))
			{
				if (inbuf[10] == '\"')
					d[cnt].let = inbuf[11];
				else
					d[cnt].let = atoi(inbuf + 10);
			}
			if (!strncmp(inbuf, "wedgeset(", 9))
			{
				d[cnt].wedges = 0;
				start = atoi(inbuf + 9);
				for (end = 9; inbuf[end]; end++)
					if (inbuf[end] == ',')
					{
						d[cnt].wedges = atoi(inbuf + end + 1) - start + 1;
						break;
					}
			}
		}
		fclose(fin);
	}
	printf("%%%d letters\n", cnt);
	qsort((char *)&d[0], cnt, sizeof(struct cun), cundif);
	fin = fopen("cunsum.mf", "w");
	if (fin == NULL)
	{
		perror("cunsum.mf");
		exit(1);
	}
	printf("\\begin{center}\n");
	printf("\\begin{tabular}{rlrlrlrl}\n");
	end = 0;
	for (start = 0; start < cnt; start++, end++)
	{
		if (start && (d[start].wedges != d[start - 1].wedges))
		{
			if (end%4)
				printf("\\\\\n");
			printf("\\hline\n");
			end = 0;
		}
		if (end%4)
			printf("&");
		l = d[start].let;
		if (((l >= 'a') && (l <= 'z')) || ((l >= 'A') && (l <= 'Z')))
			printf("\\tt %c&\\cun %c", l, l);
		else
			printf("\\tt char%d&\\cun\\char%d",l,l);
		if ((end%4) == 3)
			printf("\\\\\n");
		fprintf(fin, "input cun%04d;\n", d[start].fnum);
	}
	if (start%4)
		printf("\\\\\n");
	printf("\\end{tabular}\n");
	printf("\\end{center}\n");
	fclose(fin);
}