Ejemplo n.º 1
0
static void
get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *sirq, gint64 *idle)
{
	char buf [256];
	char *s;
	int hz = get_user_hz ();
	guint64	user_ticks = 0, nice_ticks = 0, system_ticks = 0, idle_ticks = 0, irq_ticks = 0, sirq_ticks = 0;
	FILE *f = fopen ("/proc/stat", "r");
	if (!f)
		return;
	if (cpu_id < 0)
		hz *= mono_cpu_count ();
	while ((s = fgets (buf, sizeof (buf), f))) {
		char *data = NULL;
		if (cpu_id < 0 && strncmp (s, "cpu", 3) == 0 && g_ascii_isspace (s [3])) {
			data = s + 4;
		} else if (cpu_id >= 0 && strncmp (s, "cpu", 3) == 0 && strtol (s + 3, &data, 10) == cpu_id) {
			if (data == s + 3)
				continue;
			data++;
		} else {
			continue;
		}
		
		user_ticks = strtoull (data, &data, 10);
		nice_ticks = strtoull (data, &data, 10);
		system_ticks = strtoull (data, &data, 10);
		idle_ticks = strtoull (data, &data, 10);
		/* iowait_ticks = strtoull (data, &data, 10); */
		irq_ticks = strtoull (data, &data, 10);
		sirq_ticks = strtoull (data, &data, 10);
		break;
	}
	fclose (f);

	if (user)
		*user = (user_ticks + nice_ticks) * 10000000 / hz;
	if (systemt)
		*systemt = (system_ticks) * 10000000 / hz;
	if (irq)
		*irq = (irq_ticks) * 10000000 / hz;
	if (sirq)
		*sirq = (sirq_ticks) * 10000000 / hz;
	if (idle)
		*idle = (idle_ticks) * 10000000 / hz;
}
Ejemplo n.º 2
0
static gboolean
looks_like_text (const guchar *data, gsize data_size)
{
  gsize i;
  char c;

  for (i = 0; i < data_size; i++)
    {
      c = data[i];

      if (g_ascii_iscntrl (c) &&
          !g_ascii_isspace (c) &&
          c != '\b')
        return FALSE;
    }
  return TRUE;
}
Ejemplo n.º 3
0
gboolean csv_import_validate_number ( gchar * string )
{
    g_return_val_if_fail ( string, FALSE );

    while ( *string )
    {
	if ( ! g_ascii_isdigit ( * string ) &&
	     ! g_ascii_isspace ( * string ) )
	{
	    return FALSE;
	}

	string ++;
    }

    return TRUE;
}
Ejemplo n.º 4
0
static gboolean
all_whitespace (const char *text,
                gint        text_len)
{
  const char *p   = text;
  const char *end = text + text_len;

  while (p != end)
    {
      if (! g_ascii_isspace (*p))
        return FALSE;

      p = g_utf8_next_char (p);
    }

  return TRUE;
}
Ejemplo n.º 5
0
static GHashTable *
gs_plugin_steam_load_app_manifest (const gchar *fn, GError **error)
{
	GHashTable *manifest = NULL;
	guint i;
	guint j;
	g_autofree gchar *data = NULL;
	g_auto(GStrv) lines = NULL;

	/* get file */
	if (!g_file_get_contents (fn, &data, NULL, error)) {
		gs_utils_error_convert_gio (error);
		return NULL;
	}

	/* parse each line */
	manifest = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	lines = g_strsplit (data, "\n", -1);
	for (i = 0; lines[i] != NULL; i++) {
		gboolean is_key = TRUE;
		const gchar *tmp = lines[i];
		g_autoptr(GString) key = g_string_new ("");
		g_autoptr(GString) value = g_string_new ("");
		for (j = 0; tmp[j] != '\0'; j++) {

			/* alphanum, so either key or value */
			if (g_ascii_isalnum (tmp[j])) {
				g_string_append_c (is_key ? key : value, tmp[j]);
				continue;
			}

			/* first whitespace after the key */
			if (g_ascii_isspace (tmp[j]) && key->len > 0)
				is_key = FALSE;
		}
		if (g_getenv ("GS_PLUGIN_STEAM_DEBUG") != NULL)
			g_debug ("manifest %s=%s", key->str, value->str);
		if (key->len == 0 || value->len == 0)
			continue;
		g_hash_table_insert (manifest,
				     g_strdup (key->str),
				     g_strdup (value->str));
	}
	return manifest;
}
Ejemplo n.º 6
0
Archivo: format-dn.c Proyecto: gpg/gpa
/* Remove trailing white spaces from STRING.  */
static void
trim_trailing_spaces (char *string)
{
  char *p, *mark;
  
  for (mark=NULL, p=string; *p; p++)
    {
      if (g_ascii_isspace (*p))
        {
          if (!mark)
            mark = p;
	}
      else
        mark = NULL;
    }
  if (mark)
    *mark = '\0' ;
}
Ejemplo n.º 7
0
/*
  Translate SPACE to "\\040", etc.
  Taken from gflare plugin
 */
void
gfig_name_encode (gchar *dest,
                  gchar *src)
{
  gint cnt = MAX_LOAD_LINE - 1;

  while (*src && cnt--)
    {
      if (g_ascii_iscntrl (*src) || g_ascii_isspace (*src) || *src == '\\')
        {
          sprintf (dest, "\\%03o", *src++);
          dest += 4;
        }
      else
        *dest++ = *src++;
    }
  *dest = '\0';
}
static void
new_profile_name_entry_changed_callback (GtkEditable *editable, gpointer data)
{
  char *name, *saved_name;
  GtkWidget *create_button;

  create_button = (GtkWidget*) data;

  saved_name = name = gtk_editable_get_chars (editable, 0, -1);

  /* make the create button sensitive only if something other than space has been set */
  while (*name != '\0' && g_ascii_isspace (*name))
    name++;

  gtk_widget_set_sensitive (create_button, *name != '\0' ? TRUE : FALSE);

  g_free (saved_name);
}
Ejemplo n.º 9
0
Archivo: util.c Proyecto: vifino/dwb
/* dwb_navigation_new_from_line(const char *text){{{*/
Navigation * 
dwb_navigation_new_from_line(const char *text) 
{
    char **line;
    Navigation *nv = NULL;
    if (text == NULL)
        return NULL;
    while (g_ascii_isspace(*text))
        text++;

    if (*text != '\0') 
    {
        line = g_strsplit(text, " ", 2);
        nv = dwb_navigation_new(line[0], line[1]);
        g_strfreev(line);
    }
    return nv;
}/*}}}*/
Ejemplo n.º 10
0
void
rsvg_css_parse_number_optional_number (const char *str, double *x, double *y)
{
    char *endptr;

    /* TODO: some error checking */

    *x = g_ascii_strtod (str, &endptr);

    if (endptr && *endptr != '\0')
        while (g_ascii_isspace (*endptr) && *endptr)
            endptr++;

    if (endptr && *endptr)
        *y = g_ascii_strtod (endptr, NULL);
    else
        *y = *x;
}
Ejemplo n.º 11
0
void
oj_program_parse (OJProgram *p, const char *program)
{
  char **lines;
  char *line;
  char *s;
  int i;

  lines = g_strsplit(program, "\n", 0);

  for(i=0;lines[i];i++){
    p->insn = p->insns + p->n_insns;
    line = lines[i];

    s = line;

    g_print("looking at \"%s\"\n", s);

    while (g_ascii_isspace (s[0])) s++;
    if (s[0] == 0 || s[0] == '#') continue;

    p->s = s;
    get_opcode (p);

    get_arg (p, 0);
    if (opcode_list[p->insn->opcode].n_args >= 2) {
      skip_comma (p);
      get_arg (p, 1);
      if (opcode_list[p->insn->opcode].n_args >= 3) {
        skip_comma (p);
        get_arg (p, 2);
      }
    }

    if (p->error) {
      g_print("error on line %d: %s at \"%s\"\n", i, p->error, p->s);
      g_free(p->error);
      p->error = NULL;
    }

    p->n_insns++;
  }
  g_strfreev (lines);
}
Ejemplo n.º 12
0
static gboolean
_parse_hostname(SnmpTrapdHeaderParser *self)
{
  const gchar *hostname_start = *self->input;
  gsize input_left = *self->input_len;

  while (*self->input_len > 0 && !g_ascii_isspace(**self->input))
    {
      ++(*self->input);
      --(*self->input_len);
    }

  gsize hostname_length = input_left - *self->input_len;
  if (hostname_length == 0)
    return FALSE;

  snmptrapd_nv_context_add_name_value(self->nv_context, "hostname", hostname_start, hostname_length);
  return TRUE;
}
Ejemplo n.º 13
0
/* @str points to the start of "#version", "#    version" or "#\tversion", etc */
static const gchar *
_check_valid_version_preprocessor_string (const gchar * str)
{
  gint i = 0;

  if (!str || !str[i])
    return NULL;

  /* there can be whitespace between the '#' and 'version' */
  do {
    i++;
    if (str[i] == '\0' || str[i] == '\n' || str[i] == '\r')
      return NULL;
  } while (g_ascii_isspace (str[i]));
  if (g_strstr_len (&str[i], 7, "version"))
    return &str[i + 7];

  return NULL;
}
Ejemplo n.º 14
0
static void  
parser_end_element (GMarkupParseContext  *context,
                    const gchar          *element_name,
                    gpointer              user_data,
                    GError              **error)
{
  XMLParser *parser = (XMLParser *) user_data;

  switch (parser->state)
    {
    case XML_PARSER_STATE_TOPLEVEL:
      g_assert_not_reached ();
      break;

    default:
      if (parser->end_element)
        {
          gint len;

          /* strip trailing spaces */
          for (len = parser->cdata->len;
               len > 0 && g_ascii_isspace (parser->cdata->str[len-1]);
               len--)
            ; /* do nothing */
           
          g_string_truncate (parser->cdata, len);

          parser->state = parser->end_element (parser->state,
                                               element_name,
                                               parser->cdata->str,
                                               parser->cdata->len,
                                               parser->user_data,
                                               error);
          break;
        }
      /* else fallthru */
    case XML_PARSER_STATE_UNKNOWN:
      parser_end_unknown (parser);
      break;
    }

  g_string_truncate (parser->cdata, 0);
}
Ejemplo n.º 15
0
static void vala_markup_reader_space (ValaMarkupReader* self) {
	g_return_if_fail (self != NULL);
	while (TRUE) {
		gboolean _tmp0_ = FALSE;
		gchar* _tmp1_;
		gchar* _tmp2_;
		gboolean _tmp6_;
		gchar* _tmp7_;
		gchar _tmp8_;
		gchar* _tmp10_;
		gint _tmp11_;
		_tmp1_ = self->priv->current;
		_tmp2_ = self->priv->end;
		if (_tmp1_ < _tmp2_) {
			gchar* _tmp3_;
			gchar _tmp4_;
			gboolean _tmp5_ = FALSE;
			_tmp3_ = self->priv->current;
			_tmp4_ = _tmp3_[0];
			_tmp5_ = g_ascii_isspace (_tmp4_);
			_tmp0_ = _tmp5_;
		} else {
			_tmp0_ = FALSE;
		}
		_tmp6_ = _tmp0_;
		if (!_tmp6_) {
			break;
		}
		_tmp7_ = self->priv->current;
		_tmp8_ = _tmp7_[0];
		if (_tmp8_ == '\n') {
			gint _tmp9_;
			_tmp9_ = self->priv->line;
			self->priv->line = _tmp9_ + 1;
			self->priv->column = 0;
		}
		_tmp10_ = self->priv->current;
		self->priv->current = _tmp10_ + 1;
		_tmp11_ = self->priv->column;
		self->priv->column = _tmp11_ + 1;
	}
}
Ejemplo n.º 16
0
static gboolean
get_arg (OJProgram *p, int i)
{
  char *s;
  char *end;

  if (p->error) return FALSE;

  g_print("looking for arg at \"%s\"\n", p->s);

  s = p->s;
  while (g_ascii_isspace (s[0])) s++;

  switch (s[0]) {
    case 'r':
      p->insn->args[i].type = ARG_REG;
      break;
    case 's':
      p->insn->args[i].type = ARG_SRC;
      break;
    case 'd':
      p->insn->args[i].type = ARG_DEST;
      break;
    default:
      p->s = s;
      p->error = g_strdup ("expected argument");
      return FALSE;
  }
  s++;

  p->insn->args[i].index = strtoul (s, &end, 10);
  if (s == end) {
    p->s = s;
    p->error = strdup ("expected number");
    return FALSE;
  }

  s = end;

  p->s = s;
  return TRUE;
}
Ejemplo n.º 17
0
/* isdumpline assumes that dump lines start with some non-alphanumerics
 * followed by 4 hex numbers - each 8 digits long, each hex number followed
 * by 3 spaces.
 */
static int
isdumpline( gchar *line )
{
    int i, j;

    while (*line && !g_ascii_isalnum(*line))
        line++;

    for (j=0; j<4; j++) {
        for (i=0; i<8; i++, line++)
            if (! g_ascii_isxdigit(*line))
                return FALSE;

        for (i=0; i<3; i++, line++)
            if (*line != ' ')
                return FALSE;
    }

    return g_ascii_isspace(*line);
}
Ejemplo n.º 18
0
void ygtk_html_wrap_set_text (GtkWidget *widget, const gchar *text, gboolean plain_mode)
{
	WebKitWebView *view = WEBKIT_WEB_VIEW (widget);
	// webkit prepends base-uri to non-uri hrefs
	if (plain_mode)
			webkit_web_view_load_string (view, text, "text/plain", "UTF-8", "/");
	else {
		GString *str = NULL;
		int i, last_i = 0;
		for (i = 0; text[i]; i++) {
			if (!strncmp (text+i, "href=", 5)) {
				i += 5;
				if (text[i] == '"')
					i++;
				int j;
				for (j = i; text[j] && text[j] != ':'; j++)
					if (text[j] == '"' || g_ascii_isspace (text[j])) {
						if (!str)
							str = g_string_new ("");
						str = g_string_append_len (str, text+last_i, i-last_i);
						last_i = i;
						str = g_string_append (str, "label:/");
						break;
					}
			}
		}
		if (str) {
			str = g_string_append (str, text+last_i);
			text = g_string_free (str, FALSE);
		}

		const gchar *extra_css = g_object_get_data (G_OBJECT (widget), "extra-css");
		if (!extra_css) extra_css = "";

		gchar *html = g_strdup_printf ("%s\n%s\n%s", CSS, extra_css, text);
		if (str)
			g_free ((gchar *) text);
		webkit_web_view_load_string (view, html, "text/html", "UTF-8", "/");
		g_free (html);
	}
}
Ejemplo n.º 19
0
static gchar *
preset_create_filename (const gchar *basename,
                        const gchar *dest_dir)
{
  gchar *fullpath;
  gchar *safe_name;
  gint   i;
  gint   unum = 1;

  g_return_val_if_fail (basename != NULL, NULL);
  g_return_val_if_fail (dest_dir != NULL, NULL);
  g_return_val_if_fail (g_path_is_absolute (dest_dir), NULL);

  safe_name = g_filename_from_utf8 (basename, -1, NULL, NULL, NULL);

  if (safe_name[0] == '.')
    safe_name[0] = '-';

  for (i = 0; safe_name[i]; i++)
    if (safe_name[i] == G_DIR_SEPARATOR || g_ascii_isspace (safe_name[i]))
      safe_name[i] = '-';

  fullpath = g_build_filename (dest_dir, safe_name, NULL);

  while (g_file_test (fullpath, G_FILE_TEST_EXISTS))
    {
      gchar *filename;

      g_free (fullpath);

      filename = g_strdup_printf ("%s-%d", safe_name, unum++);

      fullpath = g_build_filename (dest_dir, filename, NULL);

      g_free (filename);
    }

  g_free (safe_name);

  return fullpath;
}
Ejemplo n.º 20
0
static void
dump_with_linebreaks (GOutputStream *output,
                      const gchar   *text)
{
  gint len = strlen (text);

  while (len > 0)
    {
      const gchar *t;
      gint         i, space;

      /*  groff doesn't like lines to start with a single quote  */
      if (*text == '\'')
        g_output_stream_printf (output, NULL, NULL, NULL,
                                "\\&");  /*  a zero width space  */

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

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

      g_output_stream_write_all (output, text, i, NULL, NULL, NULL);
      g_output_stream_printf (output, NULL, NULL, NULL,
                              "\n");

      if (*t == '\n')
        g_output_stream_printf (output, NULL, NULL, NULL,
                                ".br\n");

      i++;

      text += i;
      len  -= i;
    }
}
Ejemplo n.º 21
0
static gboolean
parse_textual_date (SoupDate *date, const char *date_string)
{
	/* If it starts with a word, it must be a weekday, which we skip */
	if (g_ascii_isalpha (*date_string)) {
		while (g_ascii_isalpha (*date_string))
			date_string++;
		if (*date_string == ',')
			date_string++;
		while (g_ascii_isspace (*date_string))
			date_string++;
	}

	/* If there's now another word, this must be an asctime-date */
	if (g_ascii_isalpha (*date_string)) {
		/* (Sun) Nov  6 08:49:37 1994 */
		if (!parse_month (date, &date_string) ||
		    !parse_day (date, &date_string) ||
		    !parse_time (date, &date_string) ||
		    !parse_year (date, &date_string))
			return FALSE;

		/* There shouldn't be a timezone, but check anyway */
		parse_timezone (date, &date_string);
	} else {
		/* Non-asctime date, so some variation of
		 * (Sun,) 06 Nov 1994 08:49:37 GMT
		 */
		if (!parse_day (date, &date_string) ||
		    !parse_month (date, &date_string) ||
		    !parse_year (date, &date_string) ||
		    !parse_time (date, &date_string))
			return FALSE;

		/* This time there *should* be a timezone, but we
		 * survive if there isn't.
		 */
		parse_timezone (date, &date_string);
	}
	return TRUE;
}
Ejemplo n.º 22
0
/**
 * base_tool_command_group_add:
 * @group: a #ToolCommandGroup pointer
 * @cmd: (transfer none): the command to add
 *
 * Add @cmd to @group. If a previous command with the same name existed,
 * it is replaced by the new one.
 *
 * @cmd is used as it is (i.e. not copied).
 */
void
base_tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
{
	g_return_if_fail (group);
	g_return_if_fail (cmd);
	g_return_if_fail (cmd->name && *cmd->name && g_ascii_isalpha (*cmd->name));
	g_return_if_fail (cmd->group && *cmd->group);
	if (cmd->name && !cmd->name_args) {
		cmd->name_args = cmd->name;
		gchar *tmp;
		for (tmp = cmd->name_args; *tmp && !g_ascii_isspace(*tmp); tmp++);
		cmd->name = g_strndup (cmd->name_args, tmp - cmd->name_args);
	}

	base_tool_command_group_remove (group, cmd->name);

	group->name_ordered = g_slist_insert_sorted (group->name_ordered, cmd,
						     (GCompareFunc) commands_compare_name);
	group->group_ordered = g_slist_insert_sorted (group->group_ordered, cmd,
						      (GCompareFunc) commands_compare_group);
}
Ejemplo n.º 23
0
static gboolean
get_opcode (OJProgram *p)
{
  char *s;
  char *opcode;
  int opcode_len;
  int i;

  if (p->error) return FALSE;

  g_print("looking for opcode at \"%s\"\n", p->s);

  s = p->s;
  while (g_ascii_isspace (s[0])) s++;
  opcode = s;
  while (g_ascii_isalnum (s[0])) s++;
  opcode_len = s - opcode;

  if (opcode_len == 0) {
    p->error = g_strdup ("expected opcode");
    return FALSE;
  }

  p->insn->opcode = oj_opcode_lookup (opcode, opcode_len);

  for(i=0;i<N_OPCODES;i++){
    if (strlen (opcode_list[i].name) != opcode_len) continue;
    if (strncmp (opcode_list[i].name, opcode, opcode_len) == 0) {
      break;
    }
  }
  if (i == N_OPCODES) {
    p->error = g_strdup ("unknown opcode");
    return FALSE;
  }

  p->insn->opcode = i;
  p->s = s;
  return TRUE;
}
Ejemplo n.º 24
0
static void
as_node_text_cb (GMarkupParseContext *context,
		 const gchar         *text,
		 gsize                text_len,
		 gpointer             user_data,
		 GError             **error)
{
	AsNodeToXmlHelper *helper = (AsNodeToXmlHelper *) user_data;
	AsNodeData *data;
	guint i;

	/* no data */
	if (text_len == 0)
		return;

	/* all whitespace? */
	for (i = 0; i < text_len; i++) {
		if (!g_ascii_isspace(text[i]))
			break;
	}
	if (i >= text_len)
		return;

	/* split up into lines and add each with spaces stripped */
	data = helper->current->data;
	if (data->cdata != NULL) {
		g_set_error (error,
			     AS_NODE_ERROR,
			     AS_NODE_ERROR_INVALID_MARKUP,
			     "<%s> already set '%s' and tried to replace with '%s'",
			     as_tag_data_get_name (data),
			     data->cdata, text);
		return;
	}
	if ((helper->flags & AS_NODE_FROM_XML_FLAG_LITERAL_TEXT) > 0) {
		data->cdata = g_strndup (text, text_len);
	} else {
		data->cdata = as_node_reflow_text (text, text_len);
	}
}
Ejemplo n.º 25
0
/* adapted from sysklogd sources */
static GSList*
parse_syslog ()
{
  char cbuf[BUFSIZ];
  char *cline, *p;
  FILE *cf;
  GSList *logfiles = NULL;

  if ((cf = fopen ("/etc/syslog.conf", "r")) == NULL) {
    return NULL;
  }

  cline = cbuf;
  while (fgets (cline, sizeof (cbuf) - (cline - cbuf), cf) != NULL) {
    gchar **list;
    gint i;

    for (p = cline; g_ascii_isspace (*p); ++p);
    if (*p == '\0' || *p == '#' || *p == '\n')
      continue;

    list = g_strsplit_set (p, ", -\t()\n", 0);

    for (i = 0; list[i]; ++i) {
      if (*list[i] == '/' &&
          g_slist_find_custom (logfiles, list[i],
                               (GCompareFunc) g_ascii_strcasecmp) == NULL)
      {
        logfiles = g_slist_insert (logfiles,
                                   g_strdup (list[i]), 0);
      }
    }

    g_strfreev (list);
  }

  fclose (cf);

  return logfiles;
}
Ejemplo n.º 26
0
/* Tries to parse strings of the file:line style, allowing line field to be missing
 * * filename is filled with the filename, should be freed
 * * line is filled with the line number or -1 */
static void msgwin_parse_generic_line(const gchar *string, gchar **filename, gint *line)
{
	gchar **fields;
	gboolean incertain = TRUE; /* whether we're reasonably certain of the result */

	*filename = NULL;
	*line = -1;

	fields = g_strsplit(string, ":", 2);
	/* extract the filename */
	if (fields[0] != NULL)
	{
		*filename = utils_get_locale_from_utf8(fields[0]);
		if (msgwindow.messages_dir != NULL)
			make_absolute(filename, msgwindow.messages_dir);

		/* now the line */
		if (fields[1] != NULL)
		{
			gchar *end;

			*line = strtol(fields[1], &end, 10);
			if (end == fields[1])
				*line = -1;
			else if (*end == ':' || g_ascii_isspace(*end))
			{	/* if we have a blank or a separator right after the number, assume we really got a
				 * filename (it's a grep-like syntax) */
				incertain = FALSE;
			}
		}

		/* if we aren't sure we got a supposedly correct filename, check it */
		if (incertain && ! g_file_test(*filename, G_FILE_TEST_EXISTS))
		{
			SETPTR(*filename, NULL);
			*line = -1;
		}
	}
	g_strfreev(fields);
}
Ejemplo n.º 27
0
char *
http_path_get_basename (const char *path)
{
  const char *parent;
  char       *basename;
  size_t      len;

  if (path == NULL || *path == '\0')
    return NULL;

  /* remove any leading slashes */
  while (*path != '\0' && (*path == '/' || *path == ' '))
    path++;

  len = strlen (path);
  if (len == 0)
    return g_strdup ("/");

  /* remove any trailing slashes */
  while (len)
    {
      char c = path[len - 1];
      if (!g_ascii_isspace (c) && c != '/')
	break;

      len--;
    }

  parent = g_strrstr_len (path, len, "/");

  if (parent)
    {
      parent++; /* skip the found / char */
      basename = g_strndup (parent, (len - (parent - path)));
    }
  else
    basename = g_strndup (path, len);

  return basename;
}
Ejemplo n.º 28
0
/*  very simplistic CSS style parser  */
static void
svg_parse_gradient_stop_style (SvgStop     *stop,
                               const gchar *style)
{
  const gchar *end;
  const gchar *sep;

  while (*style)
    {
      while (g_ascii_isspace (*style))
        style++;

      for (end = style; *end && *end != ';'; end++)
        /* do nothing */;

      for (sep = style; sep < end && *sep != ':'; sep++)
        /* do nothing */;

      if (end > sep && sep > style)
        {
          gchar *name;
          gchar *value;

          name = g_strndup (style, sep - style);
          sep++;
          value = g_strndup (sep, end - sep - (*end == ';' ? 1 : 0));

          svg_parse_gradient_stop_style_prop (stop, name, value);

          g_free (value);
          g_free (name);
        }

      style = end;

      if (*style == ';')
        style++;
    }
}
Ejemplo n.º 29
0
static gboolean
_has_forbidden_chars(const gchar *s)
{
    gchar forbidden[256];

    if (!s)
        return FALSE;

    // mark special characters forbidden in ZooKeeper paths
    memset(forbidden, 0, 256);
    forbidden['/'] = 1;
    forbidden[','] = 1;
    forbidden[';'] = 1;

    while (*s) {
        if (!g_ascii_isprint(*s)
                || g_ascii_isspace(*s)
                || forbidden[(guint8)*s])
            return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 30
0
/* Scan a line for vi(m)/emacs/kate modelines.
 * Line numbers are counted starting at one.
 */
static void
parse_modeline (gchar           *s,
		gint             line_number,
		gint             line_count,
		ModelineOptions *options)
{
	gchar prev;

	/* look for the beginning of a modeline */
	for (prev = ' '; (s != NULL) && (*s != '\0'); prev = *(s++))
	{
		if (!g_ascii_isspace (prev))
			continue;

		if ((line_number <= 3 || line_number > line_count - 3) &&
		    (strncmp (s, "ex:", 3) == 0 ||
		     strncmp (s, "vi:", 3) == 0 ||
		     strncmp (s, "vim:", 4) == 0))
		{
			gedit_debug_message (DEBUG_PLUGINS, "Vim modeline on line %d", line_number);

		    	while (*s != ':') s++;
		    	s = parse_vim_modeline (s + 1, options);
		}
		else if (line_number <= 2 && strncmp (s, "-*-", 3) == 0)
		{
			gedit_debug_message (DEBUG_PLUGINS, "Emacs modeline on line %d", line_number);

			s = parse_emacs_modeline (s + 3, options);
		}
		else if ((line_number <= 10 || line_number > line_count - 10) &&
			 strncmp (s, "kate:", 5) == 0)
		{
			gedit_debug_message (DEBUG_PLUGINS, "Kate modeline on line %d", line_number);

			s = parse_kate_modeline (s + 5, options);
		}
	}
}