Beispiel #1
0
/* Assign a default value to style_file_name if necessary.  */
void
style_file_prepare ()
{
  if (style_file_name == NULL)
    {
      const char *user_preference = getenv ("PO_STYLE");

      if (user_preference != NULL && user_preference[0] != '\0')
        style_file_name = style_file_lookup (xstrdup (user_preference));
      else
        {
          const char *gettextdatadir;

          /* Make it possible to override the po-default.css location.  This is
             necessary for running the testsuite before "make install".  */
          gettextdatadir = getenv ("GETTEXTDATADIR");
          if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
            gettextdatadir = relocate (GETTEXTDATADIR);

          style_file_name =
            xconcatenated_filename (gettextdatadir, "styles/po-default.css",
                                   NULL);
        }
    }
  else
    style_file_name = style_file_lookup (style_file_name);
}
Beispiel #2
0
/* Lookup the location of the style file.  */
static const char *
style_file_lookup (const char *file_name)
{
  if (!IS_PATH_WITH_DIR (file_name))
    {
      /* It's a file name without a directory specification.
         If it does not exist in the current directory...  */
      struct stat statbuf;

      if (stat (file_name, &statbuf) < 0)
        {
          /* ... but it exists in the styles installation location...  */
          const char *gettextstylesdir = relocate (GETTEXTDATADIR "/styles");
          char *possible_file_name =
            xconcatenated_filename (gettextstylesdir, file_name, NULL);

          if (stat (possible_file_name, &statbuf) >= 0)
            {
              /* ... then use the file in the styles installation directory.  */
              return possible_file_name;
            }
          free (possible_file_name);
        }

      /* Let the CSS library show a warning.  */
    }
  return file_name;
}
void
read_resources_file (message_list_ty *mlp, const char *filename)
{
  const char *args[2];
  const char *gettextexedir;
  const char *gettextlibdir;
  char *assembly_path;
  const char *libdirs[1];
  struct locals locals;

  /* Prepare arguments.  */
  args[0] = filename;
  args[1] = NULL;

  /* Make it possible to override the .exe location.  This is
     necessary for running the testsuite before "make install".  */
  gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
  if (gettextexedir == NULL || gettextexedir[0] == '\0')
    gettextexedir = relocate (LIBDIR "/gettext");

  /* Make it possible to override the .dll location.  This is
     necessary for running the testsuite before "make install".  */
  gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
  if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
    gettextlibdir = relocate (LIBDIR);

  /* Dump the resource and retrieve the resulting output.  */
  assembly_path =
    xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe");
  libdirs[0] = gettextlibdir;
  if (execute_csharp_program (assembly_path, libdirs, 1,
                              args,
                              verbose, false,
                              execute_and_read_po_output, &locals))
    /* An error message should already have been provided.  */
    exit (EXIT_FAILURE);

  /* Add the output to mlp.  */
  {
    message_list_ty *read_mlp = locals.mdlp->item[0]->messages;
    size_t j;

    for (j = 0; j < read_mlp->nitems; j++)
      message_list_append (mlp, read_mlp->item[j]);
  }

  free (assembly_path);
}
Beispiel #4
0
bool
execute_java_class (const char *class_name,
                    const char * const *classpaths,
                    unsigned int classpaths_count,
                    bool use_minimal_classpath,
                    const char *exe_dir,
                    const char * const *args,
                    bool verbose, bool quiet,
                    execute_fn *executer, void *private_data)
{
  bool err = false;
  unsigned int nargs;
  char *old_JAVA_HOME;

  /* Count args.  */
  {
    const char * const *arg;

    for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++)
     ;
  }

  /* First, try a class compiled to a native code executable.  */
  if (exe_dir != NULL)
    {
      char *exe_pathname = xconcatenated_filename (exe_dir, class_name, EXEEXT);
      char *old_classpath;
      char **argv = (char **) xmalloca ((1 + nargs + 1) * sizeof (char *));
      unsigned int i;

      /* Set CLASSPATH.  */
      old_classpath =
        set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                       verbose);

      argv[0] = exe_pathname;
      for (i = 0; i <= nargs; i++)
        argv[1 + i] = (char *) args[i];

      if (verbose)
        {
          char *command = shell_quote_argv (argv);
          printf ("%s\n", command);
          free (command);
        }

      err = executer (class_name, exe_pathname, argv, private_data);

      /* Reset CLASSPATH.  */
      reset_classpath (old_classpath);

      freea (argv);

      goto done1;
    }

  {
    const char *java = getenv ("JAVA");
    if (java != NULL && java[0] != '\0')
      {
        /* Because $JAVA may consist of a command and options, we use the
           shell.  Because $JAVA has been set by the user, we leave all
           all environment variables in place, including JAVA_HOME, and
           we don't erase the user's CLASSPATH.  */
        char *old_classpath;
        unsigned int command_length;
        char *command;
        char *argv[4];
        const char * const *arg;
        char *p;

        /* Set CLASSPATH.  */
        old_classpath =
          set_classpath (classpaths, classpaths_count, false,
                         verbose);

        command_length = strlen (java);
        command_length += 1 + shell_quote_length (class_name);
        for (arg = args; *arg != NULL; arg++)
          command_length += 1 + shell_quote_length (*arg);
        command_length += 1;

        command = (char *) xmalloca (command_length);
        p = command;
        /* Don't shell_quote $JAVA, because it may consist of a command
           and options.  */
        memcpy (p, java, strlen (java));
        p += strlen (java);
        *p++ = ' ';
        p = shell_quote_copy (p, class_name);
        for (arg = args; *arg != NULL; arg++)
          {
            *p++ = ' ';
            p = shell_quote_copy (p, *arg);
          }
        *p++ = '\0';
        /* Ensure command_length was correctly calculated.  */
        if (p - command > command_length)
          abort ();

        if (verbose)
          printf ("%s\n", command);

        argv[0] = "/bin/sh";
        argv[1] = "-c";
        argv[2] = command;
        argv[3] = NULL;
        err = executer (java, "/bin/sh", argv, private_data);

        freea (command);

        /* Reset CLASSPATH.  */
        reset_classpath (old_classpath);

        goto done1;
      }
  }

  /* Unset the JAVA_HOME environment variable.  */
  old_JAVA_HOME = getenv ("JAVA_HOME");
  if (old_JAVA_HOME != NULL)
    {
      old_JAVA_HOME = xstrdup (old_JAVA_HOME);
      unsetenv ("JAVA_HOME");
    }

  {
    static bool gij_tested;
    static bool gij_present;

    if (!gij_tested)
      {
        /* Test for presence of gij: "gij --version > /dev/null"  */
        char *argv[3];
        int exitstatus;

        argv[0] = "gij";
        argv[1] = "--version";
        argv[2] = NULL;
        exitstatus = execute ("gij", "gij", argv, false, false, true, true,
                              true, false, NULL);
        gij_present = (exitstatus == 0);
        gij_tested = true;
      }

    if (gij_present)
      {
        char *old_classpath;
        char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
        unsigned int i;

        /* Set CLASSPATH.  */
        old_classpath =
          set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                         verbose);

        argv[0] = "gij";
        argv[1] = (char *) class_name;
        for (i = 0; i <= nargs; i++)
          argv[2 + i] = (char *) args[i];

        if (verbose)
          {
            char *command = shell_quote_argv (argv);
            printf ("%s\n", command);
            free (command);
          }

        err = executer ("gij", "gij", argv, private_data);

        /* Reset CLASSPATH.  */
        reset_classpath (old_classpath);

        freea (argv);

        goto done2;
      }
  }

  {
    static bool java_tested;
    static bool java_present;

    if (!java_tested)
      {
        /* Test for presence of java: "java -version 2> /dev/null"  */
        char *argv[3];
        int exitstatus;

        argv[0] = "java";
        argv[1] = "-version";
        argv[2] = NULL;
        exitstatus = execute ("java", "java", argv, false, false, true, true,
                              true, false, NULL);
        java_present = (exitstatus == 0);
        java_tested = true;
      }

    if (java_present)
      {
        char *old_classpath;
        char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
        unsigned int i;

        /* Set CLASSPATH.  We don't use the "-classpath ..." option because
           in JDK 1.1.x its argument should also contain the JDK's classes.zip,
           but we don't know its location.  (In JDK 1.3.0 it would work.)  */
        old_classpath =
          set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                         verbose);

        argv[0] = "java";
        argv[1] = (char *) class_name;
        for (i = 0; i <= nargs; i++)
          argv[2 + i] = (char *) args[i];

        if (verbose)
          {
            char *command = shell_quote_argv (argv);
            printf ("%s\n", command);
            free (command);
          }

        err = executer ("java", "java", argv, private_data);

        /* Reset CLASSPATH.  */
        reset_classpath (old_classpath);

        freea (argv);

        goto done2;
      }
  }

  {
    static bool jre_tested;
    static bool jre_present;

    if (!jre_tested)
      {
        /* Test for presence of jre: "jre 2> /dev/null ; test $? = 1"  */
        char *argv[2];
        int exitstatus;

        argv[0] = "jre";
        argv[1] = NULL;
        exitstatus = execute ("jre", "jre", argv, false, false, true, true,
                              true, false, NULL);
        jre_present = (exitstatus == 0 || exitstatus == 1);
        jre_tested = true;
      }

    if (jre_present)
      {
        char *old_classpath;
        char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
        unsigned int i;

        /* Set CLASSPATH.  We don't use the "-classpath ..." option because
           in JDK 1.1.x its argument should also contain the JDK's classes.zip,
           but we don't know its location.  */
        old_classpath =
          set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                         verbose);

        argv[0] = "jre";
        argv[1] = (char *) class_name;
        for (i = 0; i <= nargs; i++)
          argv[2 + i] = (char *) args[i];

        if (verbose)
          {
            char *command = shell_quote_argv (argv);
            printf ("%s\n", command);
            free (command);
          }

        err = executer ("jre", "jre", argv, private_data);

        /* Reset CLASSPATH.  */
        reset_classpath (old_classpath);

        freea (argv);

        goto done2;
      }
  }

#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__
  /* Native Windows, Cygwin */
  {
    static bool jview_tested;
    static bool jview_present;

    if (!jview_tested)
      {
        /* Test for presence of jview: "jview -? >nul ; test $? = 1"  */
        char *argv[3];
        int exitstatus;

        argv[0] = "jview";
        argv[1] = "-?";
        argv[2] = NULL;
        exitstatus = execute ("jview", "jview", argv, false, false, true, true,
                              true, false, NULL);
        jview_present = (exitstatus == 0 || exitstatus == 1);
        jview_tested = true;
      }

    if (jview_present)
      {
        char *old_classpath;
        char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
        unsigned int i;

        /* Set CLASSPATH.  */
        old_classpath =
          set_classpath (classpaths, classpaths_count, use_minimal_classpath,
                         verbose);

        argv[0] = "jview";
        argv[1] = (char *) class_name;
        for (i = 0; i <= nargs; i++)
          argv[2 + i] = (char *) args[i];

        if (verbose)
          {
            char *command = shell_quote_argv (argv);
            printf ("%s\n", command);
            free (command);
          }

        err = executer ("jview", "jview", argv, private_data);

        /* Reset CLASSPATH.  */
        reset_classpath (old_classpath);

        freea (argv);

        goto done2;
      }
  }
#endif

  if (!quiet)
    error (0, 0, _("Java virtual machine not found, try installing gij or set $JAVA"));
  err = true;

 done2:
  if (old_JAVA_HOME != NULL)
    {
      xsetenv ("JAVA_HOME", old_JAVA_HOME, 1);
      free (old_JAVA_HOME);
    }

 done1:
  return err;
}
Beispiel #5
0
static void
output_skeleton (void)
{
  int filter_fd[2];
  pid_t pid;

  /* Compute the names of the package data dir and skeleton files.  */
  char const *m4 = (m4 = getenv ("M4")) ? m4 : M4;
  char const *datadir = pkgdatadir ();
  char *m4sugar = xconcatenated_filename (datadir, "m4sugar/m4sugar.m4", NULL);
  char *m4bison = xconcatenated_filename (datadir, "bison.m4", NULL);
  char *skel = (IS_PATH_WITH_DIR (skeleton)
                ? xstrdup (skeleton)
                : xconcatenated_filename (datadir, skeleton, NULL));

  /* Test whether m4sugar.m4 is readable, to check for proper
     installation.  A faulty installation can cause deadlock, so a
     cheap sanity check is worthwhile.  */
  xfclose (xfopen (m4sugar, "r"));

  /* Create an m4 subprocess connected to us via two pipes.  */

  if (trace_flag & trace_tools)
    fprintf (stderr, "running: %s %s - %s %s\n",
             m4, m4sugar, m4bison, skel);

  /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a
     position-dependent manner.  Keep it as the first argument so that all
     files are traced.

     See the thread starting at
     <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
     for details.  */
  {
    char const *argv[10];
    int i = 0;
    argv[i++] = m4;

    /* When POSIXLY_CORRECT is set, GNU M4 1.6 and later disable GNU
       extensions, which Bison's skeletons depend on.  With older M4,
       it has no effect.  M4 1.4.12 added a -g/--gnu command-line
       option to make it explicit that a program wants GNU M4
       extensions even when POSIXLY_CORRECT is set.

       See the thread starting at
       <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
       for details.  */
    if (*M4_GNU_OPTION)
      argv[i++] = M4_GNU_OPTION;

    argv[i++] = "-I";
    argv[i++] = datadir;
    if (trace_flag & trace_m4)
      argv[i++] = "-dV";
    argv[i++] = m4sugar;
    argv[i++] = "-";
    argv[i++] = m4bison;
    argv[i++] = skel;
    argv[i++] = NULL;
    aver (i <= ARRAY_CARDINALITY (argv));

    /* The ugly cast is because gnulib gets the const-ness wrong.  */
    pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
                            true, filter_fd);
  }

  free (m4sugar);
  free (m4bison);
  free (skel);

  if (trace_flag & trace_muscles)
    muscles_output (stderr);
  {
    FILE *out = xfdopen (filter_fd[1], "w");
    muscles_output (out);
    xfclose (out);
  }

  /* Read and process m4's output.  */
  timevar_push (TV_M4);
  {
    FILE *in = xfdopen (filter_fd[0], "r");
    scan_skel (in);
    /* scan_skel should have read all of M4's output.  Otherwise, when we
       close the pipe, we risk letting M4 report a broken-pipe to the
       Bison user.  */
    aver (feof (in));
    xfclose (in);
  }
  wait_subprocess (pid, "m4", false, false, true, true, NULL);
  timevar_pop (TV_M4);
}
Beispiel #6
0
msgdomain_list_ty *
msgdomain_read_tcl (const char *locale_name, const char *directory)
{
  const char *gettextdatadir;
  char *tclscript;
  size_t len;
  char *frobbed_locale_name;
  char *p;
  char *file_name;
  char *argv[4];
  pid_t child;
  int fd[1];
  FILE *fp;
  msgdomain_list_ty *mdlp;
  int exitstatus;
  size_t k;

  /* Make it possible to override the msgunfmt.tcl location.  This is
     necessary for running the testsuite before "make install".  */
  gettextdatadir = getenv ("GETTEXTDATADIR");
  if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
    gettextdatadir = relocate (GETTEXTDATADIR);

  tclscript = xconcatenated_filename (gettextdatadir, "msgunfmt.tcl", NULL);

  /* Convert the locale name to lowercase and remove any encoding.  */
  len = strlen (locale_name);
  frobbed_locale_name = (char *) xmalloca (len + 1);
  memcpy (frobbed_locale_name, locale_name, len + 1);
  for (p = frobbed_locale_name; *p != '\0'; p++)
    if (*p >= 'A' && *p <= 'Z')
      *p = *p - 'A' + 'a';
    else if (*p == '.')
      {
        *p = '\0';
        break;
      }

  file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg");

  freea (frobbed_locale_name);

  /* Prepare arguments.  */
  argv[0] = "tclsh";
  argv[1] = tclscript;
  argv[2] = file_name;
  argv[3] = NULL;

  if (verbose)
    {
      char *command = shell_quote_argv (argv);
      printf ("%s\n", command);
      free (command);
    }

  /* Open a pipe to the Tcl interpreter.  */
  child = create_pipe_in ("tclsh", "tclsh", argv, DEV_NULL, false, true, true,
                          fd);

  fp = fdopen (fd[0], "r");
  if (fp == NULL)
    error (EXIT_FAILURE, errno, _("fdopen() failed"));

  /* Read the message list.  */
  mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po);

  fclose (fp);

  /* Remove zombie process from process list, and retrieve exit status.  */
  exitstatus =
    wait_subprocess (child, "tclsh", false, false, true, true, NULL);
  if (exitstatus != 0)
    {
      if (exitstatus == 2)
        /* Special exitcode provided by msgunfmt.tcl.  */
        error (EXIT_FAILURE, ENOENT,
               _("error while opening \"%s\" for reading"), file_name);
      else
        error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
               "tclsh", exitstatus);
    }

  free (tclscript);

  /* Move the header entry to the beginning.  */
  for (k = 0; k < mdlp->nitems; k++)
    {
      message_list_ty *mlp = mdlp->item[k]->messages;
      size_t j;

      for (j = 0; j < mlp->nitems; j++)
        if (is_header (mlp->item[j]))
          {
            /* Found the header entry.  */
            if (j > 0)
              {
                message_ty *header = mlp->item[j];
                size_t i;

                for (i = j; i > 0; i--)
                  mlp->item[i] = mlp->item[i - 1];
                mlp->item[0] = header;
              }
            break;
          }
    }

  return mdlp;
}