/* Application Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include "SXWindowTheme.h" /* Read configuration from FILE_NAME. */ static int read_config_file (char *file_name) { xmlDocPtr doc; xmlNodePtr cur, child; /* Build an XML tree from a the file. */ doc = xmlParseFile (file_name); if (doc == NULL) return 1; /* ??? errno. */ /* Check the document is of the right kind. */ cur = xmlDocGetRootElement (doc); if (cur == NULL) { fprintf (stderr,"empty document\n"); xmlFreeDoc (doc); return 2; } if (xmlStrcmp (cur->name, (const xmlChar *) "crust")) { fprintf (stderr,"document of the wrong type, root node != crust"); xmlFreeDoc (doc); return 1; } cur = cur->xmlChildrenNode; while (cur && xmlIsBlankNode (cur)) { cur = cur -> next; } if (cur == 0) return 2; /* Main level. */ while (cur) { if (! xmlStrcmp (cur->name, (const xmlChar *) "directories")) { /* Found .... */ child = cur->xmlChildrenNode; while (child) { printf ("child name: %s\n", child->name); if (! xmlStrcmp (child->name, (const xmlChar *) "directory")) { char *type; type = xmlGetProp (child, (const xmlChar *) "type"); if (type && !strcmp (type, "font")) { char *directory; directory = xmlNodeListGetString (doc, child->xmlChildrenNode, 1); GFFontScanDirectory (directory); } else printf ("no type: %s\n", type); } child = child->next; } printf ("should parse directories\n"); } else if (! xmlStrcmp (cur->name, (const xmlChar *) "theme")) { char *file_name; file_name = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1); if (SXWindowThemeInitialize (file_name) == 0) { fprintf (stderr, "no theme\n"); exit (1); } } cur = cur->next; } xmlCleanupParser (); return 0; } /* ... */ static int load_configuration () { struct passwd *pw; int err; /* We try to load configuration files from users home directory first. Files that we try are: ~/.crustrc and ~/.crust/crustrc */ pw = getpwuid (getuid ()); if (pw) { char full_path [256]; snprintf (full_path, sizeof full_path, "%s/.crustrc", pw->pw_dir); err = read_config_file (full_path); if (! err) return 0; snprintf (full_path, sizeof full_path, "%s/.crust/crustrc", pw->pw_dir); err = read_config_file (full_path); if (! err) return 0; } /* Try to load the global configuration file. */ return read_config_file (INSTALL_PREFIX "/etc/crustrc"); } /* Initialize a shared application named APPNAME. */ void SFApplicationInitShared (char *appname, int *argcp, char ***argvp) { /* Try to load configuration file. */ if (load_configuration ()) { CFLog ("*** SFApplicationInitShared: Failed to load configuration\n"); exit (1); } } /* Initialize a standalone application named APPNAME. */ void SFApplicationInit (char *appname, int *argcp, char ***argvp) { /* Try to load configuration file. */ if (load_configuration ()) { CFLog ("*** SFApplicationInit: Failed to load configuration\n"); exit (1); } }