summaryrefslogtreecommitdiff
path: root/fonts/utilities/ps2mf/ps2mf.c
blob: 1f9a4a40b47e036fa6f427f7029109912aaa6f75 (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
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
/* ps2mf.c */

#define VERSION "1.1 (beta)"

#include <stdio.h>
#ifndef AIX
#include <stdlib.h>
#endif
#include <string.h>
#include "defines.h"
#include "myopen.h"
#include "ps2mf.h"
#include "ps2mfutl.h"
#include "getopt.h"
#ifdef MSDOS
#include <float.h>
#endif

AFM_info_tp * AFM_chars;
configuration_info_tp * TeX_configuration;
ignore_info_tp * ignore_list;
char font_name [255], coding_scheme[255];
float italic_angle;
bool fixed_pitch;
int x_height, font_space, font_quad;
bool x_height_is_defined;
char buffer [255], obuffer [255];
char * param;


void give_usage ()
{
	fprintf (stderr, "Usage: ps2mf <basename>\n");
	fprintf (stderr, "         [-p <someps>[.ps]][-a <someafm>[.afm]]\n");
	fprintf (stderr, "         [-m <somemf>[.mf]][-c <someconf>[.cfg]]\n");
	exit (UNSUCCESSFUL);
}

FILE * ps_file, * afm_file, * mf_file, * conf_file;

#ifdef __STDC__
void preamble (int argc, char ** argv)
#else
void preamble (argc, argv)
int argc;
char ** argv;
#endif
{
	int c, i, lastext;
	bool ps_file_defined, afm_file_defined, mf_file_defined,
		conf_file_defined;
	char * ps_file_name, * afm_file_name, * mf_file_name, * conf_file_name,
		* base_file_name;

	ps_file_defined = FALSE;
	afm_file_defined = FALSE;
	mf_file_defined = FALSE;
	conf_file_defined = FALSE;

	while ((c = getopt (argc, argv, "p:m:a:c:")) != EOF)
	{
		switch (c)
		{
			case 'p':
			{
				ps_file_name = optarg;
				ps_file_defined = TRUE;
			}
			break;
			case 'm':
			{
				mf_file_name = optarg;
				mf_file_defined = TRUE;
			}
			break;
			case 'a':
			{
				afm_file_name = optarg;
				afm_file_defined = TRUE;
			}
			break;
			case 'c':
			{
				conf_file_name = optarg;
				conf_file_defined = TRUE;
			}
			break;
			case '?':
			{
				give_usage ();
			}
			break;
		}
	}
	if (! argv [optind]) give_usage ();
	base_file_name = (char *) my_malloc (sizeof (char)
					     * strlen (argv [optind]) + 5);
	strcpy (base_file_name, argv [optind]);
	lastext = -1;
	for (i = 0; base_file_name [i]; i ++)
	{
		if (base_file_name [i] == '.') lastext = i;
		else
		{
			if (base_file_name [i] == '/') lastext = -1;
		}
	}
	if (lastext != -1) base_file_name [lastext] = '\0';
	ps_file = my_open (ps_file_defined ? ps_file_name : base_file_name,
			   ".ps", "r");
	afm_file = my_open (afm_file_defined ? afm_file_name : base_file_name,
			   ".afm", "r");
	mf_file = my_open (mf_file_defined ? mf_file_name : base_file_name,
			   ".mf", "w");
	conf_file = my_open (conf_file_defined ? conf_file_name : base_file_name,
			     ".cfg", "r");
}

void postamble ()
{
	fclose (ps_file);
	fclose (afm_file);
	fclose (mf_file);
	fclose (conf_file);
}

#ifdef __STDC__
void main (int argc, char ** argv)
#else
void main (argc, argv)
int argc;
char ** argv;
#endif
{
	fprintf (stderr, "This is ps2mf, version %s.\n", VERSION);
	preamble (argc, argv);
	fprintf (stderr, "  Starting to read configuration-file\n");
	parse_config ();
	fprintf (stderr, "  Starting to read fontmetric-file\n");
	parse_AFM ();
	fprintf (stderr, "  Starting to read postscript-file\n");
	parse_PS ();
	postamble ();
	exit (SUCCESSFUL);
}