Back to index

lightning-sunbird  0.9+nobinonly
querymodules.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * Pango
00003  * querymodules.c:
00004  *
00005  * ***** BEGIN LICENSE BLOCK *****
00006  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00007  *
00008  * The contents of this file are subject to the Mozilla Public License Version
00009  * 1.1 (the "License"); you may not use this file except in compliance with
00010  * the License. You may obtain a copy of the License at
00011  * http://www.mozilla.org/MPL/
00012  *
00013  * Software distributed under the License is distributed on an "AS IS" basis,
00014  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00015  * for the specific language governing rights and limitations under the
00016  * License.
00017  *
00018  * The Original Code is the Pango Library (www.pango.org).
00019  *
00020  * The Initial Developer of the Original Code is
00021  * Red Hat Software.
00022  * Portions created by the Initial Developer are Copyright (C) 1999
00023  * the Initial Developer. All Rights Reserved.
00024  *
00025  * Contributor(s):
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "config.h"
00042 
00043 #include <glib.h>
00044 #ifdef HAVE_DIRENT_H
00045 #include <dirent.h>
00046 #endif
00047 #include <gmodule.h>
00048 #include "pango-break.h"
00049 #include "pango-context.h"
00050 #include "pango-utils.h"
00051 #include "pango-engine.h"
00052 
00053 #include <errno.h>
00054 #include <string.h>
00055 #ifdef HAVE_UNISTD_H
00056 #include <unistd.h>
00057 #endif
00058 #include <stdio.h>
00059 
00060 #ifdef G_OS_WIN32
00061 #define SOEXT ".dll"
00062 #ifndef PATH_MAX
00063 #include <stdlib.h>
00064 #define PATH_MAX _MAX_PATH
00065 #endif /* PATH_MAX */
00066 #include <direct.h>         /* for getcwd() with MSVC */
00067 #include <io.h>                    /* for getcwd() with mingw */
00068 #define getcwd _getcwd
00069 #else
00070 #define SOEXT ".so"
00071 #endif
00072 
00073 void 
00074 query_module (const char *dir, const char *name)
00075 {
00076   void (*list) (PangoliteEngineInfo **engines, gint *n_engines);
00077   PangoliteEngine *(*load) (const gchar *id);
00078   void (*unload) (PangoliteEngine *engine);
00079 
00080   GModule *module;
00081   gchar *path;
00082 
00083   if (name[0] == G_DIR_SEPARATOR)
00084     path = g_strdup (name);
00085   else
00086     path = g_strconcat (dir, G_DIR_SEPARATOR_S, name, NULL);
00087   
00088   module = g_module_open (path, 0);
00089 
00090   if (!module)
00091     fprintf(stderr, "Cannot load module %s: %s\n", path, g_module_error());
00092          
00093   if (module &&
00094       g_module_symbol (module, "script_engine_list", (gpointer)&list) &&
00095       g_module_symbol (module, "script_engine_load", (gpointer)&load) &&
00096       g_module_symbol (module, "script_engine_unload", (gpointer)&unload))
00097     {
00098       gint i,j;
00099       PangoliteEngineInfo *engines;
00100       gint n_engines;
00101 
00102       (*list) (&engines, &n_engines);
00103 
00104       for (i=0; i<n_engines; i++)
00105        {
00106          const gchar *quote;
00107          gchar *quoted_path;
00108 
00109          if (strchr (path, ' ') != NULL)
00110            {
00111              quote = "\"";
00112              quoted_path = g_strescape (path, NULL);
00113            }
00114          else
00115            {
00116              quote = "";
00117              quoted_path = g_strdup (path);
00118            }
00119          
00120          g_print ("%s%s%s %s %s %s ", quote, quoted_path, quote,
00121                  engines[i].id, engines[i].engine_type, engines[i].render_type);
00122          g_free (quoted_path);
00123 
00124          for (j=0; j < engines[i].n_ranges; j++)
00125            {
00126              if (j != 0)
00127               g_print (" ");
00128              g_print ("%d-%d:%s",
00129                      engines[i].ranges[j].start,
00130                      engines[i].ranges[j].end,
00131                      engines[i].ranges[j].langs);
00132            }
00133          g_print ("\n");
00134          }
00135     }
00136   else
00137     {
00138       fprintf (stderr, "%s does not export Pangolite module API\n", path);
00139     }
00140 
00141   g_free (path);
00142   if (module)
00143     g_module_close (module);
00144 }                    
00145 
00146 int main (int argc, char **argv)
00147 {
00148   char cwd[PATH_MAX];
00149   int i;
00150   char *path;
00151 
00152   printf ("# Pangolite Modules file\n"
00153          "# Automatically generated file, do not edit\n"
00154          "#\n");
00155 
00156   if (argc == 1)            /* No arguments given */
00157     {
00158       char **dirs;
00159       int i;
00160       
00161       path = pangolite_config_key_get ("Pangolite/ModulesPath");
00162       if (!path)
00163        path = g_strconcat (pangolite_get_lib_subdirectory (),
00164                          G_DIR_SEPARATOR_S "modules",
00165                          NULL);
00166 
00167       printf ("# ModulesPath = %s\n#\n", path);
00168 
00169       dirs = pangolite_split_file_list (path);
00170 
00171       for (i=0; dirs[i]; i++)
00172        {
00173          DIR *dir = opendir (dirs[i]);
00174          if (dir)
00175            {
00176              struct dirent *dent;
00177 
00178              while ((dent = readdir (dir)))
00179               {
00180                 int len = strlen (dent->d_name);
00181                 if (len > 3 && strcmp (dent->d_name + len - strlen (SOEXT), SOEXT) == 0)
00182                   query_module (dirs[i], dent->d_name);
00183               }
00184              
00185              closedir (dir);
00186            }
00187        }
00188     }
00189   else
00190     {
00191       getcwd (cwd, PATH_MAX);
00192       
00193       for (i=1; i<argc; i++)
00194        query_module (cwd, argv[i]);
00195     }
00196   
00197   return 0;
00198 }