void
message_comment_dot_append (message_ty *mp, const char *s)
{
  if (mp->comment_dot == NULL)
    mp->comment_dot = string_list_alloc ();
  string_list_append (mp->comment_dot, s);
}
示例#2
0
void
po_message_set_extracted_comments (po_message_t message, const char *comments)
{
  message_ty *mp = (message_ty *) message;
  string_list_ty *slp = string_list_alloc ();

  {
    char *copy = xstrdup (comments);
    char *rest;

    rest = copy;
    while (*rest != '\0')
      {
	char *newline = strchr (rest, '\n');

	if (newline != NULL)
	  {
	    *newline = '\0';
	    string_list_append (slp, rest);
	    rest = newline + 1;
	  }
	else
	  {
	    string_list_append (slp, rest);
	    break;
	  }
      }
    free (copy);
  }

  if (mp->comment_dot != NULL)
    string_list_free (mp->comment_dot);

  mp->comment_dot = slp;
}
示例#3
0
/* Append a directory to the end of the list of directories.  */
void
dir_list_append (const char *s)
{
  if (directory == NULL)
    directory = string_list_alloc ();
  string_list_append_unique (directory, s);
}
/* Read list of filenames from a file.  */
string_list_ty *
read_names_from_file (const char *file_name)
{
  size_t line_len = 0;
  char *line_buf = NULL;
  FILE *fp;
  string_list_ty *result;

  if (strcmp (file_name, "-") == 0)
    fp = stdin;
  else
    {
      fp = fopen (file_name, "r");
      if (fp == NULL)
	error (EXIT_FAILURE, errno,
	       _("error while opening \"%s\" for reading"), file_name);
    }

  result = string_list_alloc ();

  while (!feof (fp))
    {
      /* Read next line from file.  */
      int len = getline (&line_buf, &line_len, fp);

      /* In case of an error leave loop.  */
      if (len < 0)
	break;

      /* Remove trailing '\n' and trailing whitespace.  */
      if (len > 0 && line_buf[len - 1] == '\n')
	line_buf[--len] = '\0';
      while (len > 0
	     && (line_buf[len - 1] == ' '
		 || line_buf[len - 1] == '\t'
		 || line_buf[len - 1] == '\r'))
	line_buf[--len] = '\0';

      /* Test if we have to ignore the line.  */
      if (*line_buf == '\0' || *line_buf == '#')
	continue;

      string_list_append_unique (result, line_buf);
    }

  /* Free buffer allocated through getline.  */
  if (line_buf != NULL)
    free (line_buf);

  /* Close input stream.  */
  if (fp != stdin)
    fclose (fp);

  return result;
}