]> git.donarmstrong.com Git - lilypond.git/blobdiff - kpath-guile/kpath.c
(local-uninstall): remove
[lilypond.git] / kpath-guile / kpath.c
index 0e1616bd26fe78e4d993ce6b34235212e485ca83..64cdb187d921169796a82de363ac7afe3e858792 100644 (file)
 
 #include "guile-compatibility.hh"
 
+#if !HAVE_GETTEXT
+inline char *
+gettext (char const *s)
+{
+  return (char *)s;
+}
+#else
+#include <libintl.h>
+#endif
+
+#define _(x) gettext (x)
+
 #include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
 
-/*
+/* The (?) problem, as far as I (?) can tell, is that MacOS X has its
+   getopt prototype in <unistd.h>, while I think other operating
+   systems have it in other places. <unistd.h> is included by
+   kpathsea.h, so you end up renaming both conflicting prototypes to
+   KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM.
 
-The problem, as far as I can tell, is that MacOS X has its getopt
-prototype in <unistd.h>, while I think other operating systems have it
-in other places. <unistd.h> is included by kpathsea.h, so you end up
-renaming both conflicting prototypes to YAKLUDGE.
-
-I found a somewhat more elegant patch for this: Just #include
-<unistd.h> before defining YAKLUDGE.
-
-*/
+   I (?) found a somewhat more elegant patch for this: Just #include
+   <unistd.h> before defining KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM.  */
 
 #include <unistd.h>    
 
-#if !HAVE_DYNAMIC_LIBKPATHSEA
-
-#define popen REALLYUGLYKLUDGE
-#define pclose ANOTHERREALLYUGLYKLUDGE
-#define getopt YAKLUDGE
+#define popen KPATHSEA_HAS_POPEN_PROTOTYPE_PROBLEM
+#define pclose KPATHSEA_HAS_PCLOSE_PROTOTYPE_PROBLEM
+#define getopt KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM
 
+#if HAVE_KPATHSEA_KPATHSEA_H
 #include <kpathsea/kpathsea.h>
 #include <kpathsea/tex-file.h>
 #endif
 
-static  void *kpathsea_handle = 0;
-static  char *(*dl_kpse_find_file) (char const*, kpse_file_format_type, boolean) = 0;
-static  void (*dl_kpse_maketex_option) (char const*, boolean) = 0;
-static  void (*dl_kpse_set_program_name) (char const*, char const*) = 0;
-static  char const *(*dl_kpse_init_format) (kpse_file_format_type) = 0;
-static  char *(*dl_kpse_var_expand) (char const*) = 0;
-static  kpse_format_info_type (*dl_kpse_format_info)[kpse_last_format] = 0;
+static void *kpathsea_handle = 0;
+static char *(*dl_kpse_find_file) (char const*, kpse_file_format_type, boolean) = 0;
+static void (*dl_kpse_maketex_option) (char const*, boolean) = 0;
+static void (*dl_kpse_set_program_name) (char const*, char const*) = 0;
+static char const *(*dl_kpse_init_format) (kpse_file_format_type) = 0;
+static char *(*dl_kpse_var_expand) (char const*) = 0;
+static kpse_format_info_type (*dl_kpse_format_info)[kpse_last_format] = 0;
 
 kpse_file_format_type
-kpathsea_find_format (const char* name)
+kpathsea_find_format (char const* name)
 {
   int i;
   int len = strlen (name);
@@ -78,38 +86,41 @@ kpathsea_find_format (const char* name)
 //        "Return the absolute file name of @var{name}, "
 //        "or @code{#f} if not found.")
 SCM
-ly_kpathsea_find_file(SCM name)
+ly_kpathsea_find_file (SCM name)
 {
   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
 
-  char const * nm = scm_i_string_chars (name);
-  char *p = (*dl_kpse_find_file) (nm, kpathsea_find_format (nm),
-                                 true);
+  char const *nm = scm_i_string_chars (name);
+  char *p = (*dl_kpse_find_file) (nm, kpathsea_find_format (nm), true);
   if (p)
     return scm_makfrom0str (p);
   return SCM_BOOL_F;
 }
 
 //   "Return the expanded version  @var{var}.")
-SCM ly_kpathsea_expand_variable(SCM var)
+SCM ly_kpathsea_expand_variable (SCM var)
 {
   SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
 
-  char const * nm = scm_i_string_chars (var);
-  char *result =  kpse_var_expand (nm);
-  SCM ret =  scm_makfrom0str (result);
+  char const *nm = scm_i_string_chars (var);
+  char *result = (*dl_kpse_var_expand) (nm);
+  SCM ret = scm_makfrom0str (result);
   free (result);
 
   return ret;
 }
 
+#ifndef DYNAMIC_OBJECT_EXTENSION
+#define DYNAMIC_OBJECT_EXTENSION ".so"
+#endif
+
 
-static char const* LIBKPATHSEA = "libkpathsea.so";
+static char const* LIBKPATHSEA = "libkpathsea" DYNAMIC_OBJECT_EXTENSION;
 
 int
 open_library ()
 {
-#if HAVE_DYNAMIC_LIBKPATHSEA
+#if HAVE_LIBKPATHSEA_SO
   struct
   {
     void **func_pointer;
@@ -132,8 +143,8 @@ open_library ()
       /*
        todo i18n.
        */
-      fprintf (stderr, "can't dlopen: %s: %s", LIBKPATHSEA, dlerror ());
-      fprintf (stderr,"install package: %s or %s",
+      fprintf (stderr, _ ("can't dlopen: %s: %s"), LIBKPATHSEA, dlerror ());
+      fprintf (stderr, _ ("install package: %s or %s"),
               "libkpathsea3 (teTeX 2.x)",
               "libkpathsea4 (teTeX 3.x)");
 
@@ -146,9 +157,9 @@ open_library ()
       *symbols[i].func_pointer = dlsym (kpathsea_handle, symbols[i].name);
       if (!symbols[i].func_pointer)
        {
-         fprintf(stderr, "no such symbol: %s: %s",
-                 symbols[i].name,
-                 dlerror ());
+         fprintf (stderr, _ ("no such symbol: %s: %s"),
+                  symbols[i].name,
+                  dlerror ());
          return 1;
        }
     }
@@ -169,16 +180,19 @@ initialize_kpathsea ()
 {
   if (open_library ())
     {
-      fprintf (stderr, "Error opening kpathsea library. Aborting");
+      fprintf (stderr, _ ("error opening kpathsea library"));
+      fprintf (stderr, _ ("aborting"));
       exit (1);
     }
 
   (*dl_kpse_set_program_name) ("lilypond", "lilypond");
   (*dl_kpse_maketex_option) ("tfm", TRUE);
   
-  SCM find = scm_c_define_gsubr ("ly:kpathsea-find-file", 1, 0, 0, ly_kpathsea_find_file);
+  SCM find = scm_c_define_gsubr ("ly:kpathsea-find-file", 1, 0, 0,
+                                ly_kpathsea_find_file);
   scm_c_export ("ly:kpathsea-find-file", NULL);
-  SCM expand = scm_c_define_gsubr ("ly:kpathsea-expand-variable", 1, 0, 0, ly_kpathsea_find_file);
+  SCM expand = scm_c_define_gsubr ("ly:kpathsea-expand-variable", 1, 0, 0,
+                                  ly_kpathsea_expand_variable);
   scm_c_export ("ly:kpathsea-expand-variable", NULL);
 }