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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
/*
* functional font
*/
#include "defs.h"
#include "global.h"
#include "funcfont.h"
#ifdef KPATHSEA
extern struct str_llist_elt *value; /* Forward declaration */
#include <kpathsea/config.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/tex-file.h>
#endif
int functype_init();
int functype_access();
void init_func_fontinfo();
struct fontop funcop = {
"func",
functype_init,
functype_access,
init_func_fontinfo,
};
functype_init(desc, ff)
char *desc;
struct funcfont **ff;
{
char *d, *e;
struct fontop *fop;
BOOLEAN body;
int numbody;
struct ffinfo *ffi;
struct funcfont *ffs, **nextff;
struct funcfont *ffnew;
struct fontop *findcondop();
extern struct fontop falseop;
for (ffs = NULL, nextff = &ffs, numbody = 0;;) {
if (!getstrtok(desc, '(', &d))
return FALSE;
if ((fop = findcondop(desc)) != NULL) {
body = FALSE;
} else if ((fop = findfontop(desc)) != NULL && fop != &funcop) {
body = TRUE;
numbody++;
} else {
Warning("illegal functional font %s", desc);
return FALSE;
}
if (!getstrtok(d, ')', &e))
return FALSE;
if (!fop->fo_init(d, &ffi))
return FALSE;
ffnew = NEW(struct funcfont, "funcfont init");
ffnew->ff_fop = fop;
ffnew->ff_body = body;
ffnew->ff_info = (struct ffinfo *)ffi;
ffnew->ff_next = NULL;
*nextff = ffnew;
nextff = &(ffnew->ff_next);
skipstrblank(e, &d);
if (*d == '\0')
break;
else if (*d == ',')
skipstrblank(e+1, &desc);
else
return FALSE;
}
if (numbody == 0) {
ffnew = NEW(struct funcfont, "funcfont init");
ffnew->ff_fop = &falseop;
ffnew->ff_body = TRUE;
ffnew->ff_info = NULL;
ffnew->ff_next = NULL;
*nextff = ffnew;
}
*ff = ffs;
return TRUE;
}
functype_access(ff, fe, acca)
struct funcfont *ff;
struct font_entry *fe;
struct accarg *acca;
{
struct funcfont *ffnew;
for (; ff != NULL; ff = ff->ff_next) {
#ifdef DEBUG
if (Debuguser)
(void)fprintf(stderr, "trying to apply %s to %s\n",
ff->ff_fop->fo_type, fe->n);
#endif
if (ff->ff_fop->fo_access(ff->ff_info, fe, acca)) {
if (ff->ff_body) {
ffnew = NEW(struct funcfont, "funcfont access");
*ffnew = *ff;
ffnew->ff_info = (struct ffinfo *)fe->finfo;
fe->finfo = (struct finfo *)ffnew;
}
} else
return FALSE;
}
return TRUE;
}
void
init_func_fontinfo(fe)
struct font_entry *fe;
{
struct funcfont *ff;
ff = (struct funcfont *)fe->finfo;
fe->finfo = (struct finfo *)ff->ff_info;
ff->ff_fop->fo_initfontinfo(fe);
}
/* funcfont conditions
*/
extern struct fontop
cexecop, /* execfont.c */
existop,
preop,
notpreop,
falseop;
struct fontop *condops[] = {
&cexecop,
&existop,
&preop,
¬preop,
&falseop,
NULL
};
struct fontop *
findcondop(type)
char *type;
{
struct fontop **fo;
for (fo = condops; *fo != NULL; fo++)
if (STREQ((*fo)->fo_type, type))
return *fo;
return NULL;
}
/* ARGSUSED */
void
init_dummy_fontinfo(fe)
struct font_entry *fe;
{
Fatal("%s implementation error: init_dummy_fontinfo", G_progname);
}
int false_access();
struct fontop falseop = {
"false",
pathtype_init,
false_access,
init_dummy_fontinfo, /* never called */
};
/* ARGSUSED */
int
false_access(proto, fe, acca)
char *proto;
struct font_entry *fe;
struct accarg *acca;
{
return FALSE;
}
int exist_access();
struct fontop existop = {
"exist",
pathtype_init,
exist_access,
init_dummy_fontinfo, /* never called */
};
int
exist_access(proto, fe, acca)
char *proto;
struct font_entry *fe;
struct accarg *acca;
{
BOOLEAN ok;
#ifdef KPATHSEA
char *path, *base, *filename;
const_string savepath;
kpse_format_info_type *spec = &kpse_format_info[kpse_texsource_format];
#endif
#ifdef KPATHSEA
pavek(fe->name, &path, &base, proto, acca);
if (path == NULL || base == NULL)
return FALSE;
spec->path = NULL;
spec->override_path = path;
kpse_init_format(kpse_texsource_format);
filename = kpse_path_search(spec->path, base, false);
if (ok = (filename != NULL))
strcpy(fe->name, filename);
#else
pave(fe->name, proto, acca);
ok = access(fe->name, R_OK) == 0;
#endif
#ifdef DEBUG
if (Debuguser)
(void)fprintf(stderr, " condition: exist %s\n", fe->name);
#endif
return ok;
}
int pre_access();
int notpre_access();
struct fontop preop = {
"pre",
pathtype_init,
pre_access,
init_dummy_fontinfo, /* never called */
};
struct fontop notpreop = {
"!pre",
pathtype_init,
notpre_access,
init_dummy_fontinfo, /* never called */
};
int
pre_access(proto, fe, acca)
char *proto;
struct font_entry *fe;
struct accarg *acca;
{
#ifdef DEBUG
if (Debuguser)
(void)fprintf(stderr, " condition: pre(%s) %s\n", proto, fe->n);
#endif
return !strncmp(fe->n, proto, strlen(proto));
}
int
notpre_access(proto, fe, acca)
char *proto;
struct font_entry *fe;
struct accarg *acca;
{
#ifdef DEBUG
if (Debuguser)
(void)fprintf(stderr, " condition: !pre(%s) %s\n", proto, fe->n);
#endif
return strncmp(fe->n, proto, strlen(proto));
}
|