dir.c revision 41c30155
11.16Schopps/* 21.5Schopps * Copyright 1999 SuSE, Inc. 31.6Schopps * 41.6Schopps * Permission to use, copy, modify, distribute, and sell this software and its 51.6Schopps * documentation for any purpose is hereby granted without fee, provided that 61.7Schopps * the above copyright notice appear in all copies and that both that 71.1Smw * copyright notice and this permission notice appear in supporting 81.7Schopps * documentation, and that the name of SuSE not be used in advertising or 91.7Schopps * publicity pertaining to distribution of the software without specific, 101.7Schopps * written prior permission. SuSE makes no representations about the 111.7Schopps * suitability of this software for any purpose. It is provided "as is" 121.7Schopps * without express or implied warranty. 131.7Schopps * 141.7Schopps * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 151.7Schopps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE 161.7Schopps * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 171.7Schopps * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 181.7Schopps * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 191.7Schopps * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 201.7Schopps * 211.7Schopps * Author: Keith Packard, SuSE, Inc. 221.7Schopps */ 231.7Schopps 241.7Schopps#ifdef HAVE_CONFIG_H 251.7Schopps#include <config.h> 261.7Schopps#endif 271.7Schopps#include "builtin.h" 281.7Schopps 291.7Schoppsstatic BuiltinDirPtr 301.7SchoppsBuiltinDirsDup (const BuiltinDirPtr a_dirs, 311.7Schopps int a_dirs_len) 321.7Schopps{ 331.7Schopps BuiltinDirPtr dirs=NULL ; 341.7Schopps int i=0 ; 351.7Schopps 361.7Schopps if (!a_dirs) 371.7Schopps return NULL ; 381.7Schopps 391.7Schopps dirs = calloc (a_dirs_len, sizeof (BuiltinDirRec)) ; 401.9Schopps if (!dirs) 411.9Schopps return NULL ; 421.9Schopps 431.9Schopps for (i=0; i < a_dirs_len; i++) { 441.9Schopps dirs[i].file_name = strdup(a_dirs[i].file_name); 451.9Schopps dirs[i].font_name = strdup(a_dirs[i].font_name); 461.9Schopps } 471.1Smw return dirs ; 481.1Smw} 491.1Smw 501.1Smw/** 511.1Smw * Copy a_save back into a_cur 521.1Smw * @param a_cur the instance of BuiltinDir to restore 531.1Smw * @param a_saved the saved instance of BuiltinDir to copy into a_cur 541.1Smw * @return 0 if went okay, 1 otherwise. 551.1Smw */ 561.1Smwstatic int 571.7SchoppsBuiltinDirRestore (BuiltinDirPtr a_cur, 581.1Smw const BuiltinDirPtr a_saved) 591.4Smw{ 601.7Schopps if (!a_cur) 611.7Schopps return 1 ; 621.1Smw if (!a_saved) 631.7Schopps return 0 ; 641.7Schopps 651.7Schopps if (a_saved->font_name) 661.7Schopps memmove (a_cur->font_name, a_saved->font_name, strlen (a_saved->font_name)) ; 671.7Schopps return 0 ; 681.7Schopps} 691.7Schopps 701.7Schopps 711.7Schoppsstatic int 721.7SchoppsBuiltinDirsRestore (BuiltinDirPtr a_cur_tab, 731.7Schopps const BuiltinDirPtr a_saved_tab, 741.7Schopps int a_tab_len) 751.7Schopps{ 761.7Schopps int i=0 ; 771.7Schopps 781.7Schopps if (!a_cur_tab) 791.7Schopps return 1 ; 801.7Schopps if (!a_saved_tab) 811.7Schopps return 0 ; 821.7Schopps 831.7Schopps for (i=0 ; i < a_tab_len; i++) { 841.7Schopps if (BuiltinDirRestore (&a_cur_tab[i], &a_saved_tab[i])) 851.7Schopps return 1 ; 861.7Schopps } 871.7Schopps return 0 ; 881.7Schopps} 891.7Schopps 901.7Schoppsstatic BuiltinAliasPtr 911.7SchoppsBuiltinAliasesDup (const BuiltinAliasPtr a_aliases, 921.7Schopps int a_aliases_len) 931.7Schopps{ 941.7Schopps BuiltinAliasPtr aliases=NULL ; 951.7Schopps int i=0 ; 961.7Schopps 971.7Schopps if (!a_aliases) 981.7Schopps return NULL ; 991.7Schopps 1001.7Schopps aliases = calloc (a_aliases_len, sizeof (BuiltinAliasRec)) ; 1011.7Schopps if (!aliases) 1021.7Schopps return NULL ; 1031.7Schopps 1041.7Schopps for (i=0; i < a_aliases_len; i++) { 1051.7Schopps aliases[i].font_name = strdup(a_aliases[i].font_name); 1061.7Schopps } 1071.7Schopps return aliases ; 1081.7Schopps} 1091.7Schopps 1101.7Schopps/** 1111.7Schopps * Copy a_save back into a_cur 1121.7Schopps * @param a_cur the instance of BuiltinAlias to restore 1131.7Schopps * @param a_saved the saved instance of BuiltinAlias to copy into a_cur 1141.7Schopps * @return 0 if went okay, 1 otherwise. 1151.7Schopps */ 1161.7Schoppsstatic int 1171.7SchoppsBuiltinAliasRestore (BuiltinAliasPtr a_cur, 1181.7Schopps const BuiltinAliasPtr a_save) 1191.7Schopps{ 1201.7Schopps if (!a_cur) 1211.7Schopps return 1 ; 1221.7Schopps if (!a_save) 1231.7Schopps return 0 ; 1241.7Schopps if (a_save->alias_name) 1251.7Schopps memmove (a_cur->alias_name, a_save->alias_name, strlen (a_save->alias_name)) ; 1261.7Schopps if (a_save->font_name) 1271.7Schopps memmove (a_cur->font_name, a_save->font_name, strlen (a_save->font_name)) ; 1281.7Schopps return 0 ; 1291.7Schopps} 1301.7Schopps 1311.7Schoppsstatic int 1321.7SchoppsBuiltinAliasesRestore (BuiltinAliasPtr a_cur_tab, 1331.7Schopps const BuiltinAliasPtr a_saved_tab, 1341.7Schopps int a_tab_len) 1351.7Schopps{ 1361.7Schopps int i=0 ; 1371.7Schopps 1381.7Schopps if (!a_cur_tab) 1391.7Schopps return 1 ; 1401.7Schopps if (!a_saved_tab) 1411.7Schopps return 0 ; 1421.7Schopps 1431.7Schopps for (i=0 ; i < a_tab_len; i++) { 1441.7Schopps if (BuiltinAliasRestore (&a_cur_tab[i], &a_saved_tab[i])) 1451.7Schopps return 1 ; 1461.7Schopps } 1471.7Schopps return 0 ; 1481.10Schopps} 1491.10Schopps 1501.10Schoppsint 1511.10SchoppsBuiltinReadDirectory (char *directory, FontDirectoryPtr *pdir) 1521.16Schopps{ 1531.16Schopps FontDirectoryPtr dir; 1541.16Schopps int i; 1551.16Schopps 1561.10Schopps static BuiltinDirPtr saved_builtin_dir; 1571.10Schopps static BuiltinAliasPtr saved_builtin_alias; 1581.10Schopps 1591.10Schopps dir = FontFileMakeDir ("", builtin_dir_count); 1601.16Schopps 1611.16Schopps if (saved_builtin_dir) 1621.7Schopps { 1631.10Schopps BuiltinDirsRestore ((BuiltinDirPtr) builtin_dir, 1641.10Schopps saved_builtin_dir, 1651.10Schopps builtin_dir_count) ; 1661.13Schopps } 1671.10Schopps else 1681.7Schopps { 1691.7Schopps saved_builtin_dir = BuiltinDirsDup ((const BuiltinDirPtr) builtin_dir, 1701.7Schopps builtin_dir_count) ; 1711.7Schopps } 1721.10Schopps 1731.10Schopps if (saved_builtin_alias) 1741.10Schopps { 1751.10Schopps BuiltinAliasesRestore ((BuiltinAliasPtr) builtin_alias, 1761.10Schopps saved_builtin_alias, 1771.10Schopps builtin_alias_count) ; 1781.10Schopps } 1791.10Schopps else 1801.10Schopps { 1811.10Schopps saved_builtin_alias = BuiltinAliasesDup ((const BuiltinAliasPtr) builtin_alias, 1821.10Schopps builtin_alias_count) ; 1831.10Schopps } 1841.10Schopps 1851.10Schopps for (i = 0; i < builtin_dir_count; i++) 1861.10Schopps { 1871.10Schopps if (!FontFileAddFontFile (dir, 1881.7Schopps (char *) builtin_dir[i].font_name, 1891.7Schopps (char *) builtin_dir[i].file_name)) 1901.7Schopps { 1911.7Schopps FontFileFreeDir (dir); 1921.7Schopps return BadFontPath; 1931.7Schopps } 1941.7Schopps } 1951.7Schopps for (i = 0; i < builtin_alias_count; i++) 1961.7Schopps { 1971.7Schopps if (!FontFileAddFontAlias (dir, 1981.7Schopps (char *) builtin_alias[i].alias_name, 1991.7Schopps (char *) builtin_alias[i].font_name)) 2001.7Schopps { 2011.7Schopps FontFileFreeDir (dir); 2021.7Schopps return BadFontPath; 2031.7Schopps } 2041.7Schopps } 2051.7Schopps FontFileSortDir (dir); 2061.7Schopps *pdir = dir; 2071.7Schopps return Successful; 2081.7Schopps} 2091.7Schopps