Exemplo n.º 1
0
guint
theme_parse_rc_style (GScanner *scanner, GtkRcStyle *rc_style)
{
	ThemeRcData *theme_data;
	guint scope_id;
	guint old_scope;
	guint token;

	if (!scope_id)
		scope_id = g_quark_from_string("theme_engine");

	old_scope = g_scanner_set_scope (scanner, scope_id);
	
#if 0
	if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name)) {
		g_scanner_freeze_symbol_table(scanner);
		for (i = 0; i < n_theme_symbols; i++)
		{
			g_scanner_scope_add_symbol(scanner, scope_id,
						   theme_symbols[i].name,
						   GINT_TO_POINTER(theme_symbols[i].token));
		}
		g_scanner_thaw_symbol_table(scanner);
	}
#endif
	token = g_scanner_peek_next_token (scanner);
	
	while (token != G_TOKEN_RIGHT_CURLY) {
		token = g_scanner_peek_next_token (scanner);
	}
	g_scanner_get_next_token (scanner);
	g_scanner_set_scope (scanner, old_scope);

	theme_data = g_new0 (ThemeRcData, 1);
	rc_style->engine_data = theme_data;

	return G_TOKEN_NONE;
}
Exemplo n.º 2
0
static guint
dwerg_rc_style_parse(GtkRcStyle *rc_style,
  GtkSettings *settings,
  GScanner* scanner)
{
    static GQuark scope_id = 0;
    DwergRcStyle *theme_data = DWERG_RC_STYLE(rc_style);
    theme_data->shadow_color_from = malloc(sizeof(GdkColor));
    theme_data->shadow_color_to = malloc(sizeof(GdkColor));

    guint old_scope;
    guint token;
    guint i;

    /* setup scope, safe old_scope for crash, define tokens */
    if (!scope_id) 
        scope_id = g_quark_from_string("dwerg_theme_engine");
    old_scope = g_scanner_set_scope(scanner, scope_id);
    if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name))
    {
        g_scanner_freeze_symbol_table(scanner);
        for (i = 0; i < G_N_ELEMENTS(theme_symbols); i++)
            g_scanner_scope_add_symbol(scanner, scope_id,
              theme_symbols[i].name,
              GINT_TO_POINTER(theme_symbols[i].token));
        g_scanner_thaw_symbol_table(scanner);
    }

    token = g_scanner_peek_next_token(scanner);
    while (token != G_TOKEN_RIGHT_CURLY)
    {
        switch(token)
        {
            case TOKEN_SHADOW_COLOR_FROM:
                g_print("vla\n");
                token = g_scanner_get_next_token(scanner); 
                if (token != TOKEN_SHADOW_COLOR_FROM)
                    return token;
                token = g_scanner_get_next_token(scanner); 
                if (token != G_TOKEN_EQUAL_SIGN)
                    return token;
                token = gtk_rc_parse_color(scanner,
                    theme_data->shadow_color_from);
                g_print("ja lekker\n");
                break;
            case TOKEN_SHADOW_COLOR_TO:
                token = g_scanner_get_next_token(scanner);
                if (token != TOKEN_SHADOW_COLOR_TO)
                    return token;
                token = g_scanner_get_next_token(scanner);
                if (token != G_TOKEN_EQUAL_SIGN)
                    return token;
                token = gtk_rc_parse_color(scanner,
                    theme_data->shadow_color_to);
                break;
            default:
                g_scanner_get_next_token(scanner);
                token = G_TOKEN_RIGHT_CURLY;
                break;
        }
        if (token != G_TOKEN_NONE) {
            g_free(theme_data);
            return token;
        }
        token = g_scanner_peek_next_token(scanner);
    }
    /* on no error reset the scope */
    g_scanner_get_next_token(scanner);
    g_scanner_set_scope(scanner, old_scope);
    return G_TOKEN_NONE;
}
Exemplo n.º 3
0
Arquivo: prefs.c Projeto: dimkr/dillo
static gint Prefs_load(void)
{
   GScanner *scanner;
   gint fd;
   guint i, expected_token;
   gchar *file;

   /* Here we load and set options from dillorc */
   file = a_Misc_prepend_user_home(".dillo/dillorc");
   fd = open(file, O_RDONLY);
   g_free(file);
   if (fd < 0 && (fd = open(DILLORC_SYS, O_RDONLY)) < 0)
      return FILE_NOT_FOUND;

   fcntl(fd, F_SETFD, FD_CLOEXEC | fcntl(fd, F_GETFD));

   scanner = g_scanner_new(NULL);

   /* Adjust lexing behaviour to suit our needs */
   /* Specifies the chars which can be used in identifiers */
   scanner->config->cset_identifier_nth = (
      G_CSET_a_2_z
      "~+-_:&%#/.0123456789"
      G_CSET_A_2_Z
      G_CSET_LATINS   /*??? I don't know if we need these two */
      G_CSET_LATINC   /*??? */
   );
   /* Specifies the chars which can start identifiers */
   scanner->config->cset_identifier_first = (
      G_CSET_a_2_z
      G_CSET_A_2_Z
      "_0123456789"
   );
   /* Don't return G_TOKEN_SYMBOL, but the symbol's value */
   scanner->config->symbol_2_token = TRUE;
   /* Don't return G_TOKEN_IDENTIFIER, but convert it to string */
   scanner->config->identifier_2_string = TRUE;

   /* load symbols into the scanner */
   g_scanner_freeze_symbol_table(scanner);
   for (i = 0; i < n_symbols; i++)
      g_scanner_add_symbol(scanner, symbols[i].name,
                           GINT_TO_POINTER (symbols[i].token));
   g_scanner_thaw_symbol_table(scanner);

   /* feed in the text */
   g_scanner_input_file(scanner, fd);

   /* give the error handler an idea on how the input is named */
   scanner->input_name = "dillorc";

   /*
    * Scanning loop, we parse the input until it's end is reached,
    * the scanner encountered a lexing error, or our sub routine came
    * across invalid syntax
    */
   do {
      expected_token = Prefs_parser(scanner);

      /* Give an error message upon syntax errors */
      if (expected_token == G_TOKEN_SYMBOL)
         g_scanner_unexp_token (scanner, expected_token, NULL, "symbol", NULL,
                                NULL, FALSE);
      else if (expected_token == G_TOKEN_STRING)
         g_scanner_unexp_token (scanner, expected_token, NULL, "string", NULL,
                                NULL, FALSE);
      else if (expected_token == G_TOKEN_EQUAL_SIGN)
         g_scanner_unexp_token (scanner, expected_token, NULL, "=", NULL,
                                NULL, FALSE);
      g_scanner_peek_next_token (scanner);
   } while ( /* expected_token == G_TOKEN_NONE && */
            scanner->next_token != G_TOKEN_EOF &&
            scanner->next_token != G_TOKEN_ERROR);

   /* give an error message upon syntax errors */
   if (expected_token != G_TOKEN_NONE)
      g_scanner_unexp_token(scanner, expected_token, NULL, "symbol", NULL,
                            NULL, TRUE);

   /* finish parsing */
   g_scanner_destroy(scanner);
   close(fd);
   return PARSE_OK;
}
Exemplo n.º 4
0
static guint
thinice_rc_style_parse (GtkRcStyle *rc_style,
			GtkSettings  *settings,
			GScanner   *scanner)
{
  static GQuark       scope_id = 0;
  ThiniceRcStyle     *theme_data = THINICE_RC_STYLE (rc_style);
  guint               old_scope;
  guint               token;
  guint               i;

  /* Set up a new scope in this scanner. */

  /*
  g_print("theme_parse_rc_style(\"%s\")\n", rc_style->name);
  */
  if (!scope_id)
    scope_id = g_quark_from_string("theme_engine");

  /* If we bail out due to errors, we *don't* reset the scope, so the
   * error messaging code can make sense of our tokens.
   */
  old_scope = g_scanner_set_scope(scanner, scope_id);
  
  /* Now check if we already added our symbols to this scope
   * (in some previous call to theme_parse_rc_style for the
   * same scanner.
   */

  if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name))
    {
      g_scanner_freeze_symbol_table(scanner);
      for (i = 0; i < n_theme_symbols; i++)
        {
          g_scanner_scope_add_symbol(scanner, scope_id,
              theme_symbols[i].name,
              GINT_TO_POINTER(theme_symbols[i].token));
        }
      g_scanner_thaw_symbol_table(scanner);
    }

  /* We're ready to go, now parse the top level */

  /* theme_data = g_new0(ThiniceRcStyle, 1); */
  theme_data->scrollbar_type = DEFAULT_SCROLLSHAPE;
  theme_data->scrollbar_marks = DEFAULT_SCROLLBARMARKS;
  theme_data->scroll_button_marks = DEFAULT_SCROLLBUTTONMARKS;
  theme_data->handlebox_marks = DEFAULT_HANDLEBOXMARKS;
  theme_data->mark_type1 = DEFAULT_MARKTYPE1;
  theme_data->mark_type2 = DEFAULT_MARKTYPE2;

  token = g_scanner_peek_next_token(scanner);
  while (token != G_TOKEN_RIGHT_CURLY)
    {
      switch (token)
	{
        case TOKEN_RECTSCROLLBAR:
          token = theme_parse_boolean(scanner, TOKEN_RECTSCROLLBAR, &i);
          if (token != G_TOKEN_NONE)
            break;
          if (i == FALSE)
            theme_data->scrollbar_type = SCROLL_SHAPED;
          else
            theme_data->scrollbar_type = SCROLL_RECT;
          break;

        case TOKEN_SCROLLBUTTONMARKS:
          token = theme_parse_boolean(scanner, TOKEN_SCROLLBUTTONMARKS, &i);
          if (token != G_TOKEN_NONE)
            break;
          if (i == TRUE)
            theme_data->mark_type2 = MARKS_SLASH;
          else
            theme_data->mark_type2 = MARKS_NOTHING;
          /*
          if (i == TRUE)
            theme_data->scroll_button_marks = MARKS_ON;
          else
            theme_data->scroll_button_marks = MARKS_OFF;
            */
          break;

        case TOKEN_SCROLLBARMARKS:
          token = theme_parse_boolean(scanner, TOKEN_SCROLLBARMARKS, &i);
          if (token != G_TOKEN_NONE)
            break;
          if (i == TRUE)
            theme_data->mark_type1 = MARKS_SLASH;
          else
            theme_data->mark_type1 = MARKS_NOTHING;
          /*
          if (i == TRUE)
            theme_data->scrollbar_marks = MARKS_ON;
          else
            theme_data->scrollbar_marks = MARKS_OFF;
            */
          break;

        case TOKEN_HANDLEBOXMARKS:
          token = theme_parse_boolean(scanner, TOKEN_HANDLEBOXMARKS, &i);
          if (token != G_TOKEN_NONE)
            break;
          if (i == TRUE)
            theme_data->handlebox_marks = MARKS_ON;
          else
            theme_data->handlebox_marks = MARKS_OFF;
          break;

        case TOKEN_MARKTYPE1:
          token = theme_parse_marktype(scanner, TOKEN_MARKTYPE1, &i);
          if (token != G_TOKEN_NONE)
            break;
          theme_data->mark_type1 = i;
          break;

        case TOKEN_MARKTYPE2:
          token = theme_parse_marktype(scanner, TOKEN_MARKTYPE2, &i);
          if (token != G_TOKEN_NONE)
            break;
          theme_data->mark_type2 = i;
          break;

        case TOKEN_PANEDDOTS:
          token = theme_parse_paned(scanner, TOKEN_PANEDDOTS, &i);
          if (token != G_TOKEN_NONE)
            break;
          theme_data->paned_dots = i;
          break;

	default:
	  g_scanner_get_next_token(scanner);
	  token = G_TOKEN_RIGHT_CURLY;
	  break;
	}

      if (token != G_TOKEN_NONE)
	{
	  g_free(theme_data);
	  return token;
	}
      token = g_scanner_peek_next_token(scanner);
    }

  g_scanner_get_next_token(scanner);

  g_scanner_set_scope(scanner, old_scope);

  return G_TOKEN_NONE;
}