Commit | Line | Data |
---|---|---|
af2a502e C |
1 | // -*- C++ -*- |
2 | /* Copyright (C) 1989, 1990 Free Software Foundation, Inc. | |
3 | Written by James Clark (jjc@jclark.uucp) | |
4 | ||
5 | This file is part of groff. | |
6 | ||
7 | groff is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 1, or (at your option) any later | |
10 | version. | |
11 | ||
12 | groff is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License along | |
18 | with groff; see the file LICENSE. If not, write to the Free Software | |
19 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | #include <assert.h> | |
24 | #include <stdlib.h> | |
25 | #include "font.h" | |
26 | #include "lib.h" | |
27 | ||
28 | #ifndef FONTPATH | |
29 | #define FONTPATH "/usr/local/lib/font:/usr/lib/font" | |
30 | #endif | |
31 | const char *const FONT_ENV_VAR = "GROFF_FONT_PATH"; | |
32 | ||
33 | int font::res = 0; | |
34 | int font::hor = 1; | |
35 | int font::vert = 1; | |
36 | int font::unitwidth = 0; | |
37 | int font::paperwidth = 0; | |
38 | int font::paperlength = 0; | |
39 | int font::biggestfont = 0; | |
40 | int font::spare2 = 0; | |
41 | int font::sizescale = 1; | |
42 | int font::tcommand = 0; | |
43 | const char **font::font_name_table = 0; | |
44 | int *font::sizes = 0; | |
45 | char *font::dev_name = 0; | |
46 | char *font::cl_font_dirs = 0; | |
47 | const char *font::family = 0; | |
48 | const char **font::style_table = 0; | |
49 | ||
50 | void font::command_line_font_dir(const char *dir) | |
51 | { | |
52 | if (cl_font_dirs == 0) { | |
53 | cl_font_dirs = new char[strlen(dir)+1]; | |
54 | strcpy(cl_font_dirs, dir); | |
55 | } | |
56 | else { | |
57 | int len = strlen(cl_font_dirs); | |
58 | int need_colon = 0; | |
59 | if (len > 0 && cl_font_dirs[len-1] != ':') | |
60 | need_colon = 1; | |
61 | char *old_dirs = cl_font_dirs; | |
62 | cl_font_dirs = new char[len + need_colon + strlen(dir) + 1]; | |
63 | strcpy(cl_font_dirs, old_dirs); | |
64 | if (need_colon) | |
65 | strcat(cl_font_dirs, ":"); | |
66 | strcat(cl_font_dirs, dir); | |
67 | delete old_dirs; | |
68 | } | |
69 | } | |
70 | ||
71 | void font::forget_command_line_font_dirs() | |
72 | { | |
73 | delete cl_font_dirs; | |
74 | cl_font_dirs = 0; | |
75 | } | |
76 | ||
77 | FILE *font::open_file(const char *name, char **pathp) | |
78 | { | |
79 | assert(dev_name != 0); | |
80 | const char *dir_vec[3]; | |
81 | dir_vec[0] = cl_font_dirs; | |
82 | dir_vec[1] = getenv(FONT_ENV_VAR); | |
83 | dir_vec[2] = FONTPATH; | |
84 | for (int i = 0; i < 3; i++) | |
85 | if (dir_vec[i] != 0) { | |
86 | const char *dirs = dir_vec[i]; | |
87 | while (*dirs != '\0') { | |
88 | const char *p = strchr(dirs, ':'); | |
89 | if (p != dirs) { | |
90 | if (p == 0) | |
91 | p = strchr(dirs, '\0'); | |
92 | int need_slash = 0; | |
93 | if (p > dirs && p[-1] != '/') | |
94 | need_slash = 1; | |
95 | char *path = new char[(p - dirs) + need_slash + 3 | |
96 | + strlen(dev_name) + 1 | |
97 | + strlen(name) + 1]; | |
98 | memcpy(path, dirs, p - dirs); | |
99 | path[p - dirs] = '\0'; | |
100 | if (need_slash) | |
101 | strcat(path, "/"); | |
102 | strcat(path, "dev"); | |
103 | strcat(path, dev_name); | |
104 | strcat(path, "/"); | |
105 | strcat(path, name); | |
106 | FILE *fp = fopen(path, "r"); | |
107 | if (fp != 0) { | |
108 | *pathp = path; | |
109 | return fp; | |
110 | } | |
111 | delete path; | |
112 | if (*p == '\0') | |
113 | break; | |
114 | } | |
115 | dirs = p + 1; | |
116 | } | |
117 | } | |
118 | return 0; | |
119 | } | |
120 | ||
121 | void font::set_device_name(const char *s) | |
122 | { | |
123 | dev_name = new char[strlen(s)+1]; | |
124 | strcpy(dev_name, s); | |
125 | } | |
126 | ||
127 | const char *font::get_device_name() | |
128 | { | |
129 | return dev_name; | |
130 | } | |
131 |