|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
Copyright 1991, 1998 The Open Group
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
Permission to use, copy, modify, distribute, and sell this software and its
|
|
rpm-build |
8fda73 |
documentation for any purpose is hereby granted without fee, provided that
|
|
rpm-build |
8fda73 |
the above copyright notice appear in all copies and that both that
|
|
rpm-build |
8fda73 |
copyright notice and this permission notice appear in supporting
|
|
rpm-build |
8fda73 |
documentation.
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
The above copyright notice and this permission notice shall be included in
|
|
rpm-build |
8fda73 |
all copies or substantial portions of the Software.
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
rpm-build |
8fda73 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
rpm-build |
8fda73 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
rpm-build |
8fda73 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
rpm-build |
8fda73 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
rpm-build |
8fda73 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
Except as contained in this notice, the name of The Open Group shall not be
|
|
rpm-build |
8fda73 |
used in advertising or otherwise to promote the sale, use or other dealings
|
|
rpm-build |
8fda73 |
in this Software without prior written authorization from The Open Group.
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* Author: Keith Packard, MIT X Consortium
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* dirfile.c
|
|
rpm-build |
8fda73 |
*
|
|
rpm-build |
8fda73 |
* Read fonts.dir and fonts.alias files
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
#ifdef HAVE_CONFIG_H
|
|
rpm-build |
8fda73 |
#include <config.h>
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
#include "libxfontint.h"
|
|
rpm-build |
8fda73 |
#include <X11/fonts/fntfilst.h>
|
|
rpm-build |
8fda73 |
#include <stdio.h>
|
|
rpm-build |
8fda73 |
#include <sys/types.h>
|
|
rpm-build |
8fda73 |
#include <sys/stat.h>
|
|
rpm-build |
8fda73 |
#include <fcntl.h>
|
|
rpm-build |
8fda73 |
#include <errno.h>
|
|
rpm-build |
8fda73 |
#include <limits.h>
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static Bool AddFileNameAliases ( FontDirectoryPtr dir );
|
|
rpm-build |
8fda73 |
static int ReadFontAlias ( char *directory, Bool isFile,
|
|
rpm-build |
8fda73 |
FontDirectoryPtr *pdir );
|
|
rpm-build |
8fda73 |
static int lexAlias ( FILE *file, char **lexToken );
|
|
rpm-build |
8fda73 |
static int lexc ( FILE *file );
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
int
|
|
rpm-build |
8fda73 |
FontFileReadDirectory (const char *directory, FontDirectoryPtr *pdir)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
char file_name[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
char font_name[MAXFONTNAMELEN];
|
|
rpm-build |
8fda73 |
char dir_file[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
char dir_path[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
char *ptr;
|
|
rpm-build |
8fda73 |
FILE *file = 0;
|
|
rpm-build |
8fda73 |
int file_fd,
|
|
rpm-build |
8fda73 |
count,
|
|
rpm-build |
8fda73 |
num_fonts,
|
|
rpm-build |
8fda73 |
status;
|
|
rpm-build |
8fda73 |
struct stat statb;
|
|
rpm-build |
8fda73 |
static char format[24] = "";
|
|
rpm-build |
8fda73 |
#if defined(WIN32)
|
|
rpm-build |
8fda73 |
int i;
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
FontDirectoryPtr dir = NullFontDirectory;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (strlen(directory) + 1 + sizeof(FontDirFile) > sizeof(dir_file))
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/* Check for font directory attributes */
|
|
rpm-build |
8fda73 |
#if !defined(WIN32)
|
|
rpm-build |
8fda73 |
if ((ptr = strchr(directory, ':'))) {
|
|
rpm-build |
8fda73 |
#else
|
|
rpm-build |
8fda73 |
/* OS/2 and WIN32 path might start with a drive letter, don't clip this */
|
|
rpm-build |
8fda73 |
if ((ptr = strchr(directory+2, ':'))) {
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
strncpy(dir_path, directory, ptr - directory);
|
|
rpm-build |
8fda73 |
dir_path[ptr - directory] = '\0';
|
|
rpm-build |
8fda73 |
} else {
|
|
rpm-build |
8fda73 |
strcpy(dir_path, directory);
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
strcpy(dir_file, dir_path);
|
|
rpm-build |
8fda73 |
if (dir_file[strlen(dir_file) - 1] != '/')
|
|
rpm-build |
8fda73 |
strcat(dir_file, "/");
|
|
rpm-build |
8fda73 |
strcat(dir_file, FontDirFile);
|
|
rpm-build |
8fda73 |
#ifndef WIN32
|
|
rpm-build |
8fda73 |
file_fd = open(dir_file, O_RDONLY | O_NOFOLLOW);
|
|
rpm-build |
8fda73 |
if (file_fd >= 0) {
|
|
rpm-build |
8fda73 |
file = fdopen(file_fd, "rt");
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
#else
|
|
rpm-build |
8fda73 |
file = fopen(dir_file, "rt");
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
if (file) {
|
|
rpm-build |
8fda73 |
#ifndef WIN32
|
|
rpm-build |
8fda73 |
if (fstat (fileno(file), &statb) == -1)
|
|
rpm-build |
8fda73 |
#else
|
|
rpm-build |
8fda73 |
if (stat (dir_file, &statb) == -1)
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
count = fscanf(file, "%d\n", &num_fonts);
|
|
rpm-build |
8fda73 |
if ((count == EOF) || (count != 1)) {
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
dir = FontFileMakeDir(directory, num_fonts);
|
|
rpm-build |
8fda73 |
if (dir == NULL) {
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
dir->dir_mtime = statb.st_mtime;
|
|
rpm-build |
8fda73 |
if (format[0] == '\0')
|
|
rpm-build |
8fda73 |
sprintf(format, "%%%ds %%%d[^\n]\n",
|
|
rpm-build |
8fda73 |
MAXFONTFILENAMELEN-1, MAXFONTNAMELEN-1);
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
while ((count = fscanf(file, format, file_name, font_name)) != EOF) {
|
|
rpm-build |
8fda73 |
#if defined(WIN32)
|
|
rpm-build |
8fda73 |
/* strip any existing trailing CR */
|
|
rpm-build |
8fda73 |
for (i=0; i
|
|
rpm-build |
8fda73 |
if (font_name[i]=='\r') font_name[i] = '\0';
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
if (count != 2) {
|
|
rpm-build |
8fda73 |
FontFileFreeDir (dir);
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* We blindly try to load all the font files specified.
|
|
rpm-build |
8fda73 |
* In theory, we might want to warn that some of the fonts
|
|
rpm-build |
8fda73 |
* couldn't be loaded.
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
FontFileAddFontFile (dir, font_name, file_name);
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
} else if (errno != ENOENT) {
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
status = ReadFontAlias(dir_path, FALSE, &dir;;
|
|
rpm-build |
8fda73 |
if (status != Successful) {
|
|
rpm-build |
8fda73 |
if (dir)
|
|
rpm-build |
8fda73 |
FontFileFreeDir (dir);
|
|
rpm-build |
8fda73 |
return status;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
if (!dir)
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
FontFileSortDir(dir);
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
*pdir = dir;
|
|
rpm-build |
8fda73 |
return Successful;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
Bool
|
|
rpm-build |
8fda73 |
FontFileDirectoryChanged(FontDirectoryPtr dir)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
char dir_file[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
struct stat statb;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (strlen(dir->directory) + sizeof(FontDirFile) > sizeof(dir_file))
|
|
rpm-build |
8fda73 |
return FALSE;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
strcpy (dir_file, dir->directory);
|
|
rpm-build |
8fda73 |
strcat (dir_file, FontDirFile);
|
|
rpm-build |
8fda73 |
if (stat (dir_file, &statb) == -1)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
if (errno != ENOENT || dir->dir_mtime != 0)
|
|
rpm-build |
8fda73 |
return TRUE;
|
|
rpm-build |
8fda73 |
return FALSE; /* doesn't exist and never did: no change */
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
if (dir->dir_mtime != statb.st_mtime)
|
|
rpm-build |
8fda73 |
return TRUE;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if ((strlen(dir->directory) + sizeof(FontAliasFile)) > sizeof(dir_file))
|
|
rpm-build |
8fda73 |
return FALSE;
|
|
rpm-build |
8fda73 |
strcpy (dir_file, dir->directory);
|
|
rpm-build |
8fda73 |
strcat (dir_file, FontAliasFile);
|
|
rpm-build |
8fda73 |
if (stat (dir_file, &statb) == -1)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
if (errno != ENOENT || dir->alias_mtime != 0)
|
|
rpm-build |
8fda73 |
return TRUE;
|
|
rpm-build |
8fda73 |
return FALSE; /* doesn't exist and never did: no change */
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
if (dir->alias_mtime != statb.st_mtime)
|
|
rpm-build |
8fda73 |
return TRUE;
|
|
rpm-build |
8fda73 |
return FALSE;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* Make each of the file names an automatic alias for each of the files.
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static Bool
|
|
rpm-build |
8fda73 |
AddFileNameAliases(FontDirectoryPtr dir)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
int i;
|
|
rpm-build |
8fda73 |
char copy[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
char *fileName;
|
|
rpm-build |
8fda73 |
FontTablePtr table;
|
|
rpm-build |
8fda73 |
FontRendererPtr renderer;
|
|
rpm-build |
8fda73 |
int len;
|
|
rpm-build |
8fda73 |
FontNameRec name;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
table = &dir->nonScalable;
|
|
rpm-build |
8fda73 |
for (i = 0; i < table->used; i++) {
|
|
rpm-build |
8fda73 |
if (table->entries[i].type != FONT_ENTRY_BITMAP)
|
|
rpm-build |
8fda73 |
continue;
|
|
rpm-build |
8fda73 |
fileName = table->entries[i].u.bitmap.fileName;
|
|
rpm-build |
8fda73 |
renderer = FontFileMatchRenderer (fileName);
|
|
rpm-build |
8fda73 |
if (!renderer)
|
|
rpm-build |
8fda73 |
continue;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
len = strlen (fileName) - renderer->fileSuffixLen;
|
|
rpm-build |
8fda73 |
if (len >= sizeof(copy))
|
|
rpm-build |
8fda73 |
continue;
|
|
rpm-build |
8fda73 |
CopyISOLatin1Lowered (copy, fileName, len);
|
|
rpm-build |
8fda73 |
copy[len] = '\0';
|
|
rpm-build |
8fda73 |
name.name = copy;
|
|
rpm-build |
8fda73 |
name.length = len;
|
|
rpm-build |
8fda73 |
name.ndashes = FontFileCountDashes (copy, len);
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (!FontFileFindNameInDir(table, &name)) {
|
|
rpm-build |
8fda73 |
if (!FontFileAddFontAlias (dir, copy, table->entries[i].name.name))
|
|
rpm-build |
8fda73 |
return FALSE;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
return TRUE;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* parse the font.alias file. Format is:
|
|
rpm-build |
8fda73 |
*
|
|
rpm-build |
8fda73 |
* alias font-name
|
|
rpm-build |
8fda73 |
*
|
|
rpm-build |
8fda73 |
* To imbed white-space in an alias name, enclose it like "font name"
|
|
rpm-build |
8fda73 |
* in double quotes. \ escapes and character, so
|
|
rpm-build |
8fda73 |
* "font name \"With Double Quotes\" \\ and \\ back-slashes"
|
|
rpm-build |
8fda73 |
* works just fine.
|
|
rpm-build |
8fda73 |
*
|
|
rpm-build |
8fda73 |
* A line beginning with a ! denotes a newline-terminated comment.
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
/*
|
|
rpm-build |
8fda73 |
* token types
|
|
rpm-build |
8fda73 |
*/
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
#define NAME 0
|
|
rpm-build |
8fda73 |
#define NEWLINE 1
|
|
rpm-build |
8fda73 |
#define DONE 2
|
|
rpm-build |
8fda73 |
#define EALLOC 3
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static int
|
|
rpm-build |
8fda73 |
ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
char alias[MAXFONTNAMELEN];
|
|
rpm-build |
8fda73 |
char font_name[MAXFONTNAMELEN];
|
|
rpm-build |
8fda73 |
char alias_file[MAXFONTFILENAMELEN];
|
|
rpm-build |
8fda73 |
int file_fd;
|
|
rpm-build |
8fda73 |
FILE *file = 0;
|
|
rpm-build |
8fda73 |
FontDirectoryPtr dir;
|
|
rpm-build |
8fda73 |
int token;
|
|
rpm-build |
8fda73 |
char *lexToken;
|
|
rpm-build |
8fda73 |
int status = Successful;
|
|
rpm-build |
8fda73 |
struct stat statb;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (strlen(directory) >= sizeof(alias_file))
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
dir = *pdir;
|
|
rpm-build |
8fda73 |
strcpy(alias_file, directory);
|
|
rpm-build |
8fda73 |
if (!isFile) {
|
|
rpm-build |
8fda73 |
if (strlen(directory) + 1 + sizeof(FontAliasFile) > sizeof(alias_file))
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
if (directory[strlen(directory) - 1] != '/')
|
|
rpm-build |
8fda73 |
strcat(alias_file, "/");
|
|
rpm-build |
8fda73 |
strcat(alias_file, FontAliasFile);
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
#ifndef WIN32
|
|
rpm-build |
8fda73 |
file_fd = open(alias_file, O_RDONLY | O_NOFOLLOW);
|
|
rpm-build |
8fda73 |
if (file_fd >= 0) {
|
|
rpm-build |
8fda73 |
file = fdopen(file_fd, "rt");
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
#else
|
|
rpm-build |
8fda73 |
file = fopen(alias_file, "rt");
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (!file)
|
|
rpm-build |
8fda73 |
return ((errno == ENOENT) ? Successful : BadFontPath);
|
|
rpm-build |
8fda73 |
if (!dir)
|
|
rpm-build |
8fda73 |
*pdir = dir = FontFileMakeDir(directory, 10);
|
|
rpm-build |
8fda73 |
if (!dir)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
fclose (file);
|
|
rpm-build |
8fda73 |
return AllocError;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
#ifndef WIN32
|
|
rpm-build |
8fda73 |
if (fstat (fileno (file), &statb) == -1)
|
|
rpm-build |
8fda73 |
#else
|
|
rpm-build |
8fda73 |
if (stat (alias_file, &statb) == -1)
|
|
rpm-build |
8fda73 |
#endif
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
fclose (file);
|
|
rpm-build |
8fda73 |
return BadFontPath;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
dir->alias_mtime = statb.st_mtime;
|
|
rpm-build |
8fda73 |
while (status == Successful) {
|
|
rpm-build |
8fda73 |
token = lexAlias(file, &lexToken);
|
|
rpm-build |
8fda73 |
switch (token) {
|
|
rpm-build |
8fda73 |
case NEWLINE:
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case DONE:
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return Successful;
|
|
rpm-build |
8fda73 |
case EALLOC:
|
|
rpm-build |
8fda73 |
status = AllocError;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case NAME:
|
|
rpm-build |
8fda73 |
if (strlen(lexToken) >= sizeof(alias)) {
|
|
rpm-build |
8fda73 |
status = BadFontPath;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
strcpy(alias, lexToken);
|
|
rpm-build |
8fda73 |
token = lexAlias(file, &lexToken);
|
|
rpm-build |
8fda73 |
switch (token) {
|
|
rpm-build |
8fda73 |
case NEWLINE:
|
|
rpm-build |
8fda73 |
if (strcmp(alias, "FILE_NAMES_ALIASES"))
|
|
rpm-build |
8fda73 |
status = BadFontPath;
|
|
rpm-build |
8fda73 |
else if (!AddFileNameAliases(dir))
|
|
rpm-build |
8fda73 |
status = AllocError;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case DONE:
|
|
rpm-build |
8fda73 |
status = BadFontPath;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case EALLOC:
|
|
rpm-build |
8fda73 |
status = AllocError;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case NAME:
|
|
rpm-build |
8fda73 |
if (strlen(lexToken) >= sizeof(font_name)) {
|
|
rpm-build |
8fda73 |
status = BadFontPath;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
CopyISOLatin1Lowered(alias, alias, strlen(alias));
|
|
rpm-build |
8fda73 |
CopyISOLatin1Lowered(font_name, lexToken, strlen(lexToken));
|
|
rpm-build |
8fda73 |
if (!FontFileAddFontAlias (dir, alias, font_name))
|
|
rpm-build |
8fda73 |
status = AllocError;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
fclose(file);
|
|
rpm-build |
8fda73 |
return status;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
#define QUOTE 0
|
|
rpm-build |
8fda73 |
#define WHITE 1
|
|
rpm-build |
8fda73 |
#define NORMAL 2
|
|
rpm-build |
8fda73 |
#define END 3
|
|
rpm-build |
8fda73 |
#define NL 4
|
|
rpm-build |
8fda73 |
#define BANG 5
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static int charClass;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static int
|
|
rpm-build |
8fda73 |
lexAlias(FILE *file, char **lexToken)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
int c;
|
|
rpm-build |
8fda73 |
char *t;
|
|
rpm-build |
8fda73 |
enum state {
|
|
rpm-build |
8fda73 |
Begin, Normal, Quoted, Comment
|
|
rpm-build |
8fda73 |
} state;
|
|
rpm-build |
8fda73 |
int count;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static char *tokenBuf = (char *) NULL;
|
|
rpm-build |
8fda73 |
static int tokenSize = 0;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
t = tokenBuf;
|
|
rpm-build |
8fda73 |
count = 0;
|
|
rpm-build |
8fda73 |
state = Begin;
|
|
rpm-build |
8fda73 |
for (;;) {
|
|
rpm-build |
8fda73 |
if (count == tokenSize) {
|
|
rpm-build |
8fda73 |
int nsize;
|
|
rpm-build |
8fda73 |
char *nbuf;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
if (tokenSize >= (INT_MAX >> 2))
|
|
rpm-build |
8fda73 |
/* Stop before we overflow */
|
|
rpm-build |
8fda73 |
return EALLOC;
|
|
rpm-build |
8fda73 |
nsize = tokenSize ? (tokenSize << 1) : 64;
|
|
rpm-build |
8fda73 |
nbuf = realloc(tokenBuf, nsize);
|
|
rpm-build |
8fda73 |
if (!nbuf)
|
|
rpm-build |
8fda73 |
return EALLOC;
|
|
rpm-build |
8fda73 |
tokenBuf = nbuf;
|
|
rpm-build |
8fda73 |
tokenSize = nsize;
|
|
rpm-build |
8fda73 |
t = tokenBuf + count;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
c = lexc(file);
|
|
rpm-build |
8fda73 |
switch (charClass) {
|
|
rpm-build |
8fda73 |
case QUOTE:
|
|
rpm-build |
8fda73 |
switch (state) {
|
|
rpm-build |
8fda73 |
case Begin:
|
|
rpm-build |
8fda73 |
case Normal:
|
|
rpm-build |
8fda73 |
state = Quoted;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case Quoted:
|
|
rpm-build |
8fda73 |
state = Normal;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case Comment:
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case WHITE:
|
|
rpm-build |
8fda73 |
switch (state) {
|
|
rpm-build |
8fda73 |
case Begin:
|
|
rpm-build |
8fda73 |
case Comment:
|
|
rpm-build |
8fda73 |
continue;
|
|
rpm-build |
8fda73 |
case Normal:
|
|
rpm-build |
8fda73 |
*t = '\0';
|
|
rpm-build |
8fda73 |
*lexToken = tokenBuf;
|
|
rpm-build |
8fda73 |
return NAME;
|
|
rpm-build |
8fda73 |
case Quoted:
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
/* fall through */
|
|
rpm-build |
8fda73 |
case NORMAL:
|
|
rpm-build |
8fda73 |
switch (state) {
|
|
rpm-build |
8fda73 |
case Begin:
|
|
rpm-build |
8fda73 |
state = Normal;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case Comment:
|
|
rpm-build |
8fda73 |
continue;
|
|
rpm-build |
8fda73 |
default:
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
*t++ = c;
|
|
rpm-build |
8fda73 |
++count;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case END:
|
|
rpm-build |
8fda73 |
case NL:
|
|
rpm-build |
8fda73 |
switch (state) {
|
|
rpm-build |
8fda73 |
case Begin:
|
|
rpm-build |
8fda73 |
case Comment:
|
|
rpm-build |
8fda73 |
*lexToken = (char *) NULL;
|
|
rpm-build |
8fda73 |
return charClass == END ? DONE : NEWLINE;
|
|
rpm-build |
8fda73 |
default:
|
|
rpm-build |
8fda73 |
*t = '\0';
|
|
rpm-build |
8fda73 |
*lexToken = tokenBuf;
|
|
rpm-build |
8fda73 |
ungetc(c, file);
|
|
rpm-build |
8fda73 |
return NAME;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case BANG:
|
|
rpm-build |
8fda73 |
switch (state) {
|
|
rpm-build |
8fda73 |
case Begin:
|
|
rpm-build |
8fda73 |
state = Comment;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case Comment:
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
default:
|
|
rpm-build |
8fda73 |
*t++ = c;
|
|
rpm-build |
8fda73 |
++count;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
static int
|
|
rpm-build |
8fda73 |
lexc(FILE *file)
|
|
rpm-build |
8fda73 |
{
|
|
rpm-build |
8fda73 |
int c;
|
|
rpm-build |
8fda73 |
|
|
rpm-build |
8fda73 |
c = getc(file);
|
|
rpm-build |
8fda73 |
switch (c) {
|
|
rpm-build |
8fda73 |
case EOF:
|
|
rpm-build |
8fda73 |
charClass = END;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case '\\':
|
|
rpm-build |
8fda73 |
c = getc(file);
|
|
rpm-build |
8fda73 |
if (c == EOF)
|
|
rpm-build |
8fda73 |
charClass = END;
|
|
rpm-build |
8fda73 |
else
|
|
rpm-build |
8fda73 |
charClass = NORMAL;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case '"':
|
|
rpm-build |
8fda73 |
charClass = QUOTE;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case ' ':
|
|
rpm-build |
8fda73 |
case '\t':
|
|
rpm-build |
8fda73 |
charClass = WHITE;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case '\r':
|
|
rpm-build |
8fda73 |
case '\n':
|
|
rpm-build |
8fda73 |
charClass = NL;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
case '!':
|
|
rpm-build |
8fda73 |
charClass = BANG;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
default:
|
|
rpm-build |
8fda73 |
charClass = NORMAL;
|
|
rpm-build |
8fda73 |
break;
|
|
rpm-build |
8fda73 |
}
|
|
rpm-build |
8fda73 |
return c;
|
|
rpm-build |
8fda73 |
}
|