Example #1
0
/**
 * gimp_config_writer_comment:
 * @writer: a #GimpConfigWriter
 * @comment: the comment to write (ASCII only)
 *
 * Appends the @comment to @str and inserts linebreaks and hash-marks to
 * format it as a comment. Note that this function does not handle non-ASCII
 * characters.
 *
 * Since: GIMP 2.4
 **/
void
gimp_config_writer_comment (GimpConfigWriter *writer,
                            const gchar      *comment)
{
  const gchar *s;
  gboolean     comment_mode;
  gint         i, len, space;

#define LINE_LENGTH 75

  g_return_if_fail (writer != NULL);

  if (writer->error)
    return;

  g_return_if_fail (writer->depth == 0);

  if (!comment)
    return;

  comment_mode = writer->comment;
  gimp_config_writer_comment_mode (writer, TRUE);

  len = strlen (comment);

  while (len > 0)
    {
      for (s = comment, i = 0, space = 0;
           *s != '\n' && (i <= LINE_LENGTH || space == 0) && i < len;
           s++, i++)
        {
          if (g_ascii_isspace (*s))
            space = i;
        }

      if (i > LINE_LENGTH && space && *s != '\n')
        i = space;

      g_string_append_len (writer->buffer, comment, i);

      i++;

      comment += i;
      len     -= i;

      if (len > 0)
        gimp_config_writer_newline (writer);
    }

  gimp_config_writer_comment_mode (writer, comment_mode);
  gimp_config_writer_newline (writer);

  if (writer->depth == 0)
    gimp_config_writer_flush (writer);

#undef LINE_LENGTH
}
Example #2
0
static void
dump_gimprc_system (GimpConfig       *rc,
                    GimpConfigWriter *writer,
                    GOutputStream    *output)
{
  GObjectClass  *klass;
  GParamSpec   **property_specs;
  guint          n_property_specs;
  guint          i;

  gimp_config_writer_comment (writer, system_gimprc_header);
  gimp_config_writer_linefeed (writer);

  klass = G_OBJECT_GET_CLASS (rc);
  property_specs = g_object_class_list_properties (klass, &n_property_specs);

  for (i = 0; i < n_property_specs; i++)
    {
      GParamSpec *prop_spec = property_specs[i];
      gchar      *comment;

      if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE))
        continue;

      if (prop_spec->flags & GIMP_CONFIG_PARAM_IGNORE)
        continue;

      comment = dump_describe_param (prop_spec);
      if (comment)
        {
          gimp_config_writer_comment (writer, comment);
          g_free (comment);
        }

      gimp_config_writer_comment_mode (writer, TRUE);
      gimp_config_writer_linefeed (writer);

      gimp_config_serialize_property (rc, prop_spec, writer);

      gimp_config_writer_comment_mode (writer, FALSE);
      gimp_config_writer_linefeed (writer);
    }

  g_free (property_specs);
}