Ejemplo n.º 1
0
XfdashboardCssSelector* xfdashboard_css_selector_new_from_scanner_with_priority(GScanner *ioScanner,
																				gint inPriority,
																				XfdashboardCssSelectorParseFinishCallback inFinishCallback,
																				gpointer inUserData)
{
	GObject				*selector;

	g_return_val_if_fail(ioScanner, NULL);
	g_return_val_if_fail(!g_scanner_eof(ioScanner), NULL);

	/* Create selector instance */
	selector=g_object_new(XFDASHBOARD_TYPE_CSS_SELECTOR,
							"priority", inPriority,
							NULL);
	if(!selector)
	{
		g_warning(_("Could not create seleector."));
		return(NULL);
	}

	/* Parse selector from scanner provided  */
	if(!_xfdashboard_css_selector_parse(XFDASHBOARD_CSS_SELECTOR(selector), ioScanner))
	{
		g_object_unref(selector);
		return(NULL);
	}

	/* If a callback is given to call after parsing finished so call it now
	 * to determine if scanner is still in good state. If it is in bad state
	 * then return NULL.
	 */
	if(inFinishCallback)
	{
		gboolean		goodState;

		goodState=(inFinishCallback)(XFDASHBOARD_CSS_SELECTOR(selector), ioScanner, g_scanner_peek_next_token(ioScanner), inUserData);
		if(!goodState)
		{
			g_scanner_unexp_token(ioScanner,
									G_TOKEN_ERROR,
									NULL,
									NULL,
									NULL,
									_("Unexpected state of CSS scanner."),
									TRUE);
			g_object_unref(selector);
			return(NULL);
		}
	}

	/* Return created selector which may be NULL in case of error */
	return(XFDASHBOARD_CSS_SELECTOR(selector));
}
Ejemplo n.º 2
0
XfdashboardCssSelector* xfdashboard_css_selector_new_from_string_with_priority(const gchar *inSelector, gint inPriority)
{
	GObject				*selector;
	GScanner			*scanner;

	g_return_val_if_fail(inSelector || *inSelector, NULL);

	/* Create selector instance */
	selector=g_object_new(XFDASHBOARD_TYPE_CSS_SELECTOR,
							"priority", inPriority,
							NULL);
	if(!selector)
	{
		g_warning(_("Could not create seleector."));
		return(NULL);
	}

	/* Create scanner for requested string */
	scanner=g_scanner_new(NULL);
	g_scanner_input_text(scanner, inSelector, strlen(inSelector));

	/* Parse string with created scanner */
	if(!_xfdashboard_css_selector_parse(XFDASHBOARD_CSS_SELECTOR(selector), scanner))
	{
		g_object_unref(selector);
		selector=NULL;
	}

	/* If scanner does not point to EOF after parsing, it is an error and selector
	 * needs to be destroyed.
	 */
	if(selector &&
		!g_scanner_eof(scanner))
	{
		/* It is not the end of string so print parser error message */
		g_scanner_unexp_token(scanner,
								G_TOKEN_EOF,
								NULL,
								NULL,
								NULL,
								_("Parser did not reach end of stream"),
								TRUE);

		g_object_unref(selector);
		selector=NULL;
	}

	/* Destroy allocated resources */
	g_scanner_destroy(scanner);

	/* Return created selector which may be NULL in case of error */
	return(XFDASHBOARD_CSS_SELECTOR(selector));
}
Ejemplo n.º 3
0
/* Get the next token from the scanner and make sure it is a string. Do not free
the returned value. */
static gchar *
get_string_token(GScanner *tokenizer)
{
	GTokenType token;
	
	if(g_scanner_eof(tokenizer))
	{
		g_warning(_("Unexpected end of field instructions"));
		g_scanner_destroy(tokenizer);
		return NULL;
	}
	token = g_scanner_get_next_token(tokenizer);
	if(token != G_TOKEN_STRING)
	{
		g_warning(_("Expected a string in field instructions"));
		g_scanner_destroy(tokenizer);
		return NULL;
	}
	return tokenizer->value.v_string;
}
Ejemplo n.º 4
0
static void
accel_map_parse_statement (GScanner *scanner)
{
  guint expected_token;

  g_scanner_get_next_token (scanner);

  if (scanner->token == G_TOKEN_SYMBOL)
    {
      guint (*parser_func) (GScanner*);

      parser_func = (guint (*) (GScanner *))scanner->value.v_symbol;

      expected_token = parser_func (scanner);
    }
  else
    expected_token = G_TOKEN_SYMBOL;

  /* skip rest of statement on errrors
   */
  if (expected_token != G_TOKEN_NONE)
    {
      register guint level;

      level = 1;
      if (scanner->token == ')')
	level--;
      if (scanner->token == '(')
	level++;

      while (!g_scanner_eof (scanner) && level > 0)
	{
	  g_scanner_get_next_token (scanner);

	  if (scanner->token == '(')
	    level++;
	  else if (scanner->token == ')')
	    level--;
	}
    }
}
Ejemplo n.º 5
0
/* Consume all the tokens belonging to the switches named here */
static GSList *
get_switches(GScanner *tokenizer, GSList *switcheslist, const gchar *switches, const gchar *argswitches, const gchar *wideswitches, const gchar *wideargswitches)
{
	gboolean found = FALSE;
	
	g_assert(strlen(wideswitches) % 2 == 0);
	g_assert(strlen(wideargswitches) % 2 == 0);

	/* Parse switches until an argument without '\' or unexpected switch */
	while(!g_scanner_eof(tokenizer))
	{
		GTokenType token = g_scanner_peek_next_token(tokenizer);
		found = FALSE;
		
		if(token != G_TOKEN_STRING)
			break;
		if(tokenizer->next_value.v_string[0] == '\\')
		{
			const gchar *ptr;
			for(ptr = switches; *ptr && !found; ptr++)
				if(tokenizer->next_value.v_string[1] == ptr[0] && tokenizer->next_value.v_string[2] == '\0')
				{
					SwitchInfo *info = g_slice_new0(SwitchInfo);
					info->switchname = g_strdup(tokenizer->next_value.v_string + 1);
					info->switcharg = NULL;
					g_scanner_get_next_token(tokenizer);
					switcheslist = g_slist_prepend(switcheslist, info);
					found = TRUE;
				}
			for(ptr = argswitches; *ptr && !found; ptr++)
				if(tokenizer->next_value.v_string[1] == ptr[0] && tokenizer->next_value.v_string[2] == '\0')
				{
					SwitchInfo *info = g_slice_new0(SwitchInfo);
					info->switchname = g_strdup(tokenizer->next_value.v_string + 1);
					g_scanner_get_next_token(tokenizer);
					info->switcharg = g_strdup(get_string_token(tokenizer));
					switcheslist = g_slist_prepend(switcheslist, info);
					found = TRUE;
				}
			for(ptr = wideswitches; *ptr && !found; ptr++)
				if(tokenizer->next_value.v_string[1] == ptr[0] && tokenizer->next_value.v_string[2] == ptr[1] && tokenizer->next_value.v_string[3] == '\0')
				{
					SwitchInfo *info = g_slice_new0(SwitchInfo);
					info->switchname = g_strdup(tokenizer->next_value.v_string + 1);
					info->switcharg = NULL;
					g_scanner_get_next_token(tokenizer);
					switcheslist = g_slist_prepend(switcheslist, info);
					found = TRUE;
				}
			for(ptr = wideargswitches; *ptr && !found; ptr += 2)
				if(tokenizer->next_value.v_string[1] == ptr[0] && tokenizer->next_value.v_string[2] == ptr[1] && tokenizer->next_value.v_string[3] == '\0')
				{
					SwitchInfo *info = g_slice_new0(SwitchInfo);
					info->switchname = g_strdup(tokenizer->next_value.v_string + 1);
					g_scanner_get_next_token(tokenizer);
					info->switcharg = g_strdup(get_string_token(tokenizer));
					switcheslist = g_slist_prepend(switcheslist, info);
					found = TRUE;
				}
		}
		else
			break;

		if(!found)
			break;
		/* Unexpected switch, so it must belong to the next part of the field */
	}

	return switcheslist;
}
Ejemplo n.º 6
0
static gchar*
parse_libtool_archive (const gchar* libtool_name)
{
  const guint TOKEN_DLNAME = G_TOKEN_LAST + 1;
  const guint TOKEN_INSTALLED = G_TOKEN_LAST + 2;
  const guint TOKEN_LIBDIR = G_TOKEN_LAST + 3;
  gchar *lt_dlname = NULL;
  gboolean lt_installed = TRUE;
  gchar *lt_libdir = NULL;
  gchar *name;
  GTokenType token;
  GScanner *scanner;
  
  int fd = g_open (libtool_name, O_RDONLY, 0);
  if (fd < 0)
    {
      gchar *display_libtool_name = g_filename_display_name (libtool_name);
      g_module_set_error_unduped (g_strdup_printf ("failed to open libtool archive \"%s\"", display_libtool_name));
      g_free (display_libtool_name);
      return NULL;
    }
  /* search libtool's dlname specification  */
  scanner = g_scanner_new (NULL);
  g_scanner_input_file (scanner, fd);
  scanner->config->symbol_2_token = TRUE;
  g_scanner_scope_add_symbol (scanner, 0, "dlname", 
			      GUINT_TO_POINTER (TOKEN_DLNAME));
  g_scanner_scope_add_symbol (scanner, 0, "installed", 
			      GUINT_TO_POINTER (TOKEN_INSTALLED));
  g_scanner_scope_add_symbol (scanner, 0, "libdir", 
			      GUINT_TO_POINTER (TOKEN_LIBDIR));
  while (!g_scanner_eof (scanner))
    {
      token = g_scanner_get_next_token (scanner);
      if (token == TOKEN_DLNAME || token == TOKEN_INSTALLED || 
	  token == TOKEN_LIBDIR)
	{
	  if (g_scanner_get_next_token (scanner) != '=' ||
	      g_scanner_get_next_token (scanner) != 
	      (token == TOKEN_INSTALLED ? 
	       G_TOKEN_IDENTIFIER : G_TOKEN_STRING))
	    {
	      gchar *display_libtool_name = g_filename_display_name (libtool_name);
	      g_module_set_error_unduped (g_strdup_printf ("unable to parse libtool archive \"%s\"", display_libtool_name));
	      g_free (display_libtool_name);

	      g_free (lt_dlname);
	      g_free (lt_libdir);
	      g_scanner_destroy (scanner);
	      close (fd);

	      return NULL;
	    }
	  else
	    {
	      if (token == TOKEN_DLNAME)
		{
		  g_free (lt_dlname);
		  lt_dlname = g_strdup (scanner->value.v_string);
		}
	      else if (token == TOKEN_INSTALLED)
		lt_installed = 
		  strcmp (scanner->value.v_identifier, "yes") == 0;
	      else /* token == TOKEN_LIBDIR */
		{
		  g_free (lt_libdir);
		  lt_libdir = g_strdup (scanner->value.v_string);
		}
	    }
	}      
    }

  if (!lt_installed)
    {
      gchar *dir = g_path_get_dirname (libtool_name);
      g_free (lt_libdir);
      lt_libdir = g_strconcat (dir, G_DIR_SEPARATOR_S ".libs", NULL);
      g_free (dir);
    }

  name = g_strconcat (lt_libdir, G_DIR_SEPARATOR_S, lt_dlname, NULL);
  
  g_free (lt_dlname);
  g_free (lt_libdir);
  g_scanner_destroy (scanner);
  close (fd);

  return name;
}
Ejemplo n.º 7
0
static GstFlowReturn
gst_pnmdec_parse_ascii (GstPnmdec * s, const guint8 * b, guint bs)
{
  GScanner *scanner;
  guint i = 0;
  guint target;
  GstMapInfo map;
  guint8 *outdata;

  target = s->size - s->current_size;

  gst_buffer_map (s->buf, &map, GST_MAP_WRITE);

  /* leave the number of bytes already parsed */
  outdata = map.data + s->current_size;
  if (!bs) {
    goto drop_ok;
  }

  if (s->last_byte) {
    while (*b >= '0' && *b <= '9') {
      s->last_byte = 10 * s->last_byte + *b - '0';
      b++;
      if (!--bs) {
        goto drop_error;
      }
    }
    if (s->last_byte > 255) {
      GST_DEBUG_OBJECT (s, "Corrupt ASCII encoded PNM file.");
      goto drop_error;
    }
  }

  if (s->last_byte) {
    outdata[i++] = s->last_byte;
    s->last_byte = 0;
  }

  scanner = g_scanner_new (NULL);
  g_scanner_input_text (scanner, (gchar *) b, bs);
  while (!g_scanner_eof (scanner)) {
    switch (g_scanner_get_next_token (scanner)) {
      case G_TOKEN_INT:
        if (i == target) {
          GST_DEBUG_OBJECT (s, "PNM file contains too much data.");
          g_scanner_destroy (scanner);
          goto drop_error;
        }
        outdata[i++] = scanner->value.v_int;
        break;
      default:
        /* Should we care? */ ;
    }
  }
  g_scanner_destroy (scanner);

  /* If we didn't get the whole image, handle the last byte with care. */
  if (i && i < target && b[bs - 1] > '0' && b[bs - 1] <= '9') {
    s->last_byte = outdata[--i];
  }

  /* Update the number of bytes parsed in this scan */
  s->current_size += i;
  gst_buffer_unmap (s->buf, &map);

  return GST_FLOW_OK;
drop_ok:
  gst_buffer_unmap (s->buf, &map);
  return GST_FLOW_OK;

drop_error:
  gst_buffer_unmap (s->buf, &map);

  return GST_FLOW_ERROR;
}