Esempio n. 1
0
/* Older version for binary backward compatibility.  */
po_file_t
po_file_read (const char *filename)
{
  FILE *fp;
  po_file_t file;

  if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
    {
      filename = _("<stdin>");
      fp = stdin;
    }
  else
    {
      fp = fopen (filename, "r");
      if (fp == NULL)
	return NULL;
    }

  file = (struct po_file *) xmalloc (sizeof (struct po_file));
  file->real_filename = filename;
  file->logical_filename = filename;
  file->mdlp = read_catalog_stream (fp, file->real_filename,
				    file->logical_filename, &input_format_po);
  file->domains = NULL;

  if (fp != stdin)
    fclose (fp);
  return file;
}
static bool
execute_and_read_po_output (const char *progname,
                            const char *prog_path, char **prog_argv,
                            void *private_data)
{
  struct locals *l = (struct locals *) private_data;
  pid_t child;
  int fd[1];
  FILE *fp;
  int exitstatus;

  /* Open a pipe to the C# execution engine.  */
  child = create_pipe_in (progname, prog_path, prog_argv, NULL, false,
                          true, true, fd);

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

  /* Read the message list.  */
  l->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, progname, false, false, true, true, NULL);
  if (exitstatus != 0)
    error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
           progname, exitstatus);

  return false;
}
Esempio n. 3
0
po_file_t
po_file_read (const char *filename, po_xerror_handler_t handler)
{
  FILE *fp;
  po_file_t file;

  if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
    {
      filename = _("<stdin>");
      fp = stdin;
    }
  else
    {
      fp = fopen (filename, "r");
      if (fp == NULL)
	return NULL;
    }

  /* Establish error handler around read_catalog_stream().  */
  po_xerror =
    (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *))
    handler->xerror;
  po_xerror2 =
    (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *))
    handler->xerror2;
  gram_max_allowed_errors = UINT_MAX;

  file = (struct po_file *) xmalloc (sizeof (struct po_file));
  file->real_filename = filename;
  file->logical_filename = filename;
  file->mdlp = read_catalog_stream (fp, file->real_filename,
				    file->logical_filename, &input_format_po);
  file->domains = NULL;

  /* Restore error handler.  */
  po_xerror  = textmode_xerror;
  po_xerror2 = textmode_xerror2;
  gram_max_allowed_errors = 20;

  if (fp != stdin)
    fclose (fp);
  return file;
}
Esempio n. 4
0
po_file_t
po_file_read_v2 (const char *filename, po_error_handler_t handler)
{
  FILE *fp;
  po_file_t file;

  if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
    {
      filename = _("<stdin>");
      fp = stdin;
    }
  else
    {
      fp = fopen (filename, "r");
      if (fp == NULL)
	return NULL;
    }

  /* Establish error handler around read_catalog_stream().  */
  po_error             = handler->error;
  po_error_at_line     = handler->error_at_line;
  po_multiline_warning = handler->multiline_warning;
  po_multiline_error   = handler->multiline_error;
  gram_max_allowed_errors = UINT_MAX;

  file = (struct po_file *) xmalloc (sizeof (struct po_file));
  file->real_filename = filename;
  file->logical_filename = filename;
  file->mdlp = read_catalog_stream (fp, file->real_filename,
				    file->logical_filename, &input_format_po);
  file->domains = NULL;

  /* Restore error handler.  */
  po_error             = error;
  po_error_at_line     = error_at_line;
  po_multiline_warning = multiline_warning;
  po_multiline_error   = multiline_error;
  gram_max_allowed_errors = 20;

  if (fp != stdin)
    fclose (fp);
  return file;
}
Esempio n. 5
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 = concatenated_pathname (gettextdatadir, "msgunfmt.tcl", NULL);

  /* Convert the locale name to lowercase and remove any encoding.  */
  len = strlen (locale_name);
  frobbed_locale_name = (char *) xallocsa (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 = concatenated_pathname (directory, frobbed_locale_name, ".msg");

  freesa (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);
  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;
}