Exemplo n.º 1
0
static gboolean
po_file_is_empty (po_file_t file)
{
  const gchar *const *domains = po_file_domains (file);

  for (; *domains != NULL; domains++)
    {
      po_message_iterator_t iter = po_message_iterator (file, *domains);
      if (po_next_message (iter) != NULL)
        {
          po_message_iterator_free (iter);
          return FALSE;
        }
      po_message_iterator_free (iter);
    }
  return TRUE;
}
Exemplo n.º 2
0
/**
 * gtr_po_parse:
 * @po: a #GtrPo
 * @location: the file to open
 * @error: a variable to store the errors
 *
 * Parses all things related to the #GtrPo and initilizes all neccessary
 * variables.
 **/
gboolean
gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
{
  GtrMsg *msg;
  po_message_t message;
  po_message_iterator_t iter;
  const gchar *const *domains;
  gint i = 0;
  gint pos = 1;
  GtrPoPrivate *priv = gtr_po_get_instance_private (po);

  g_return_val_if_fail (GTR_IS_PO (po), FALSE);
  g_return_val_if_fail (location != NULL, FALSE);

  if (message_error != NULL)
    {
      g_free (message_error);
      message_error = NULL;
    }

  /*
   * Get filename path.
   */
  priv->location = g_file_dup (location);

  if (!_gtr_po_load_ensure_utf8 (po, error))
    {
      g_object_unref (po);
      return FALSE;
    }

  /*
   * No need to return; this can be corrected by the user
   */
  if (message_error != NULL)
    {
      g_set_error (error,
                   GTR_PO_ERROR, GTR_PO_ERROR_RECOVERY, "%s", message_error);
    }

  /*
   * Determine the message domains to track
   */
  if (!(domains = po_file_domains (priv->gettext_po_file)))
    {
      if (*error != NULL)
        g_clear_error (error);
      g_set_error (error,
                   GTR_PO_ERROR,
                   GTR_PO_ERROR_GETTEXT,
                   _("Gettext returned a null message domain list."));
      g_object_unref (po);
      return FALSE;
    }
  while (domains[i])
    {
      priv->domains = g_list_append (priv->domains, g_strdup (domains[i]));
      i++;
    }

  /*
   * Determine whether first message is the header or not, and
   * if so, process it seperately. Otherwise, treat as a normal
   * message.
   */
  priv->messages = NULL;
  iter = priv->iter;

  /* Post-process these into a linked list of GtrMsgs. */
  while ((message = po_next_message (iter)))
    {
      /*FIXME: We have to change this:
       * we have to add a gtr_msg_is_obsolete fund msg.c
       * and detect if we want obsoletes messages in show message
       */
      if (!po_message_is_obsolete (message))
        {
          /* Unpack into a GtrMsg */
          msg = _gtr_msg_new (iter, message);

          /* Set position in PO file */
          gtr_msg_set_po_position (msg, pos++);

          /* Build up messages */
          priv->messages = g_list_prepend (priv->messages, msg);
        }
    }

  if (priv->messages == NULL)
    {
      if (*error != NULL)
        g_clear_error (error);
      g_set_error (error,
                   GTR_PO_ERROR,
                   GTR_PO_ERROR_OTHER,
                   _("No messages obtained from parser."));
      g_object_unref (po);
      return FALSE;
    }

  priv->messages = g_list_reverse (priv->messages);

  /*
   * Set the current message to the first message.
   */
  priv->current = g_list_first (priv->messages);

  gtr_po_update_translated_count (po);

  /* Initialize Tab state */
  priv->state = GTR_PO_STATE_SAVED;
  return TRUE;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	po_file_t po;
	po_message_iterator_t it;
	const char * const * domains;

	if(!argv[1])
	{
		fprintf(stderr,"usage: %s <pofile> [ask|fix]\n",argv[0]);
		return 0;
	}

	if(argv[2])
	{
		if(!strncmp(argv[2], "ask", 3))
		{
			solution_mode=1;
		} else if(!strncmp(argv[2], "fix", 3)) {
			solution_mode=2;
		} else {
			fprintf(stderr,"usage: %s <pofile> [ask|fix]\n",argv[0]);
			return 0;
		}
	}

	po = po_file_read(argv[1], &po_xerror_handler);

	if(!po)
	{
		fprintf(stderr,"Couldn't read the input po file\n");
		return 0;
	}

	domains = po_file_domains(po);

	if(!domains)
	{
		fprintf(stderr,"Couldn't find the message domains in the po file\n");
		return 0;
	}

	while(*domains)
	{
		it = po_message_iterator(po,*domains);
		process_messages(it);
		po_message_iterator_free(it);
		domains++;
	}

	if(total_errors == 0 && total_warnings == 0)
	{
		fprintf(stderr,"No errors found\n");
	} else if(solution_mode==0) {
		fprintf(stderr,"%d warnings, %d errors\n",total_warnings,total_errors);
	} else {
		fprintf(stderr,"%d warnings, %d errors, %d fixes, %d removed, %d ignored\n",total_warnings,total_errors, total_fix, total_remove, total_ignore);
		if(total_fix || total_remove)
		{
			int s = 0;
			printf("Commit changes to file? (y)es, (n)o:");
			while(s != 'y' && s != 'n') s = getchar();
			if(s == 'y')
			{
				if(po_file_write(po, argv[1], &po_xerror_handler)) printf("Changes committed.");
				else printf("Error writing file.");
			} else {
				printf("Changes discarded.");
			}
		}
	}

	po_file_free(po);

	return 0;
}