Пример #1
0
/**
 * gimp_config_deserialize_return:
 * @scanner:        a #GScanner
 * @expected_token: the expected token
 * @nest_level:     the nest level
 *
 * Returns:
 *
 * Since: 2.4
 **/
gboolean
gimp_config_deserialize_return (GScanner     *scanner,
                                GTokenType    expected_token,
                                gint          nest_level)
{
  GTokenType next_token;

  g_return_val_if_fail (scanner != NULL, FALSE);

  next_token = g_scanner_peek_next_token (scanner);

  if (expected_token != G_TOKEN_LEFT_PAREN)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, expected_token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
      return FALSE;
    }
  else
    {
      if (nest_level > 0 && next_token == G_TOKEN_RIGHT_PAREN)
        {
          return TRUE;
        }
      else if (next_token != G_TOKEN_EOF)
        {
          g_scanner_get_next_token (scanner);
          g_scanner_unexp_token (scanner, expected_token, NULL, NULL, NULL,
                                 _("fatal parse error"), TRUE);
          return FALSE;
        }
    }

  return TRUE;
}
Пример #2
0
/*
  Function to parse the body of a class.
  Current token is '{'.

  CBODY:= '}'   //This is an empty class body
         | CLASSMETHODS '}'

 */
static void parseCBody(void)
{
    PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;

    while(g_scanner_peek_next_token(gScanner)!= G_TOKEN_EOF && g_scanner_peek_next_token(gScanner)!='}')
    {
        PSYMBOL pCurSymbol;
        GTokenValue value;

        /* Method implementations must start with "public" which is registered as a symbol. Here we check if
         the token is a symbol. */
        exitIfNotMatchNext(G_TOKEN_SYMBOL, "Method implementation must start with 'public'.");

        value=gScanner->value;
        pCurSymbol=value.v_symbol;

        /* Check if token is "public". */
        if(!pCurSymbol || pCurSymbol->uiSymbolToken!=NOMC_SYMBOL_PUBLIC)
        {
            g_scanner_unexp_token(gScanner,
                                  G_TOKEN_SYMBOL,
                                  NULL, NULL, NULL,
                                  "'impl'.",
                                  TRUE); /* is_error */
            cleanupAndExit(1);
        }

        /* Get name, parameters and stuff. Print the body. */
        parseClassMethod();
    };

    exitIfNotMatchNext('}',  "No closing of 'class' section.");
}
Пример #3
0
void parseMetaClass(void)
{
    GTokenValue value;

    if(!matchNext('='))
    {
        getNextToken(); /* Make sure error references the correct token */
        g_scanner_unexp_token(gScanner,
                              ';',
                              NULL,
                              NULL,
                              NULL,
                              "Error in metaclass definition.",
                              TRUE); /* is_error */
        exit(1);
    }

    /* Get the identifier */
    if(!matchNext(G_TOKEN_IDENTIFIER))
    {
        g_scanner_unexp_token(gScanner,
                              G_TOKEN_IDENTIFIER,
                              NULL,
                              NULL,
                              NULL,
                              "Class name is not a valid identifier.",
                              TRUE); /* is_error */
        exit(1);
    }
    value=gScanner->value;
    pParseInfo->pCurInterface->chrMetaClass=g_strdup(value.v_identifier);

    if(!matchNext(';'))
    {
        getNextToken(); /* Make sure error references the correct token */
        g_scanner_unexp_token(gScanner,
                              ';',
                              NULL,
                              NULL,
                              NULL,
                              "Error in metaclass definition.",
                              TRUE); /* is_error */
        exit(1);
    }
}
Пример #4
0
static void mod_g_scanner_unexp(GScanner *scanner, GTokenType expected_token,
                                const gchar *identifier_spec,
                                const gchar *symbol_spec, GError **err)
{
  scanner->msg_handler = my_handler;
  scanner->user_data = err;
  g_scanner_unexp_token(scanner, expected_token, identifier_spec, symbol_spec,
                        NULL, NULL, TRUE);
}
Пример #5
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));
}
Пример #6
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));
}
static gboolean
gimp_color_profile_store_load (GimpColorProfileStore  *store,
                               const gchar            *filename,
                               GError                **error)
{
  GScanner   *scanner;
  GTokenType  token;
  gint        i = 0;

  scanner = gimp_scanner_new_file (filename, error);
  if (! scanner)
    return FALSE;

  g_scanner_scope_add_symbol (scanner, 0, "color-profile", NULL);

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          token = gimp_color_profile_store_load_profile (store, scanner, i++);
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_LEFT_PAREN;
          break;

        default: /* do nothing */
          break;
        }
    }

  if (token != G_TOKEN_LEFT_PAREN)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
    }

  gimp_scanner_destroy (scanner);

  return TRUE;
}
Пример #8
0
/*
 Parse the class name. If we already encountered this class the name is registered as a
 symbol. IF this is the first time the name is an identifier.

 Note that the current token is the 'class' keyword.

 CLASSIDENT:=  G_TOKEN_IDENTIFIER
             | IDL_SYMBOL_INTERFACE
 */
static gchar* parseClassIdent(void)
{
    PPARSEINFO pParseInfo=(PPARSEINFO)gScanner->user_data;

    if(matchNext(G_TOKEN_IDENTIFIER))
    {
        /* Save interface info */
        GTokenValue value=gScanner->value;

        return g_strdup(value.v_identifier);
    }
    else
    {
        PSYMBOL pCurSymbol;
        GTokenValue value;

        /* If the interface name is a symbol, it means the interface was
         already registered before. Maybe because of a forward statement.
         We will check that in the function which called us. */
        exitIfNotMatchNext(G_TOKEN_SYMBOL, "Keyword 'class' must be followed by an identifier");

        /* Check if it's one of our interface symbols */
        value=gScanner->value;
        pCurSymbol=value.v_symbol;
        if(IDL_SYMBOL_REGINTERFACE!=pCurSymbol->uiSymbolToken)
        {
            /* No, some other symbol */
            g_scanner_unexp_token(gScanner,
                                  G_TOKEN_SYMBOL,
                                  NULL, NULL, NULL,
                                  "Keyword 'class' is not followed by a valid identifier.",
                                  TRUE); /* is_error */
            cleanupAndExit(1);
        }

        /* Save interface name */
        return g_strdup(pCurSymbol->chrSymbolName);
    }
}
Пример #9
0
static GslWaveDsc*
gslwave_load_wave_dsc (gpointer         data,
		       GslWaveFileInfo *file_info,
		       guint            nth_wave,
		       GslErrorType    *error_p)
{
  GScanner *scanner;
  WaveDsc *dsc;
  guint token, i;
  gint fd;

  fd = open (file_info->file_name, O_RDONLY);
  if (fd < 0)
    {
      *error_p = GSL_ERROR_OPEN_FAILED;
      return NULL;
    }

  scanner = g_scanner_new (NULL);
  scanner->config->symbol_2_token = TRUE;
  scanner->input_name = file_info->file_name;
  g_scanner_input_file (scanner, fd);
  for (i = GSL_WAVE_TOKEN_WAVE; i < GSL_WAVE_TOKEN_LAST_FIELD; i++)
    g_scanner_scope_add_symbol (scanner, 0, gsl_wave_token (i), GUINT_TO_POINTER (i));
  for (i = GSL_WAVE_TOKEN_BIG_ENDIAN; i < GSL_WAVE_TOKEN_LAST_DATA; i++)
    g_scanner_scope_add_symbol (scanner, 0, gsl_wave_token (i), GUINT_TO_POINTER (i));

 continue_scanning:
  dsc = gsl_new_struct0 (WaveDsc, 1);
  dsc->wdsc.name = NULL;
  dsc->wdsc.n_chunks = 0;
  dsc->wdsc.chunks = NULL;
  dsc->wdsc.n_channels = 1;
  dsc->format = GSL_WAVE_FORMAT_SIGNED_16;
  dsc->byte_order = G_LITTLE_ENDIAN;
  dsc->dfl_mix_freq = 44100;
  if (g_scanner_get_next_token (scanner) != GSL_WAVE_TOKEN_WAVE)
    token = GSL_WAVE_TOKEN_WAVE;
  else
    token = gslwave_parse_wave_dsc (scanner, dsc, file_info->waves[nth_wave].name);
  if (token != G_TOKEN_NONE || scanner->parse_errors)
    {
      gslwave_wave_dsc_free (dsc);
      dsc = NULL;
      if (!scanner->parse_errors)
	g_scanner_unexp_token (scanner, token, "identifier", "keyword", NULL, "discarding wave", TRUE); /* FIXME */
    }
  else
    {
      if (dsc->wdsc.n_chunks && dsc->wdsc.name)
	{
	  /* found the correctly named wave and parsed it */
	}
      else
	{
	  /* got invalid/wrong wave */
	  gslwave_wave_dsc_free (dsc);
	  dsc = NULL;
	  goto continue_scanning;	/* next attempt */
	}
    }
  g_scanner_destroy (scanner);
  close (fd);

  return dsc ? &dsc->wdsc : NULL;
}
Пример #10
0
void
session_init (Gimp *gimp)
{
  gchar      *filename;
  GScanner   *scanner;
  GTokenType  token;
  GError     *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = session_filename (gimp);

  scanner = gimp_scanner_new_file (filename, &error);

  if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
    {
      g_clear_error (&error);
      g_free (filename);

      filename = g_build_filename (gimp_sysconf_directory (),
                                   "sessionrc", NULL);
      scanner = gimp_scanner_new_file (filename, NULL);
    }

  if (! scanner)
    {
      g_clear_error (&error);
      g_free (filename);
      return;
    }

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  g_scanner_scope_add_symbol (scanner, 0, "session-info",
                              GINT_TO_POINTER (SESSION_INFO));
  g_scanner_scope_add_symbol (scanner, 0,  "hide-docks",
                              GINT_TO_POINTER (HIDE_DOCKS));
  g_scanner_scope_add_symbol (scanner, 0,  "single-window-mode",
                              GINT_TO_POINTER (SINGLE_WINDOW_MODE));
  g_scanner_scope_add_symbol (scanner, 0,  "last-tip-shown",
                              GINT_TO_POINTER (LAST_TIP_SHOWN));

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          if (scanner->value.v_symbol == GINT_TO_POINTER (SESSION_INFO))
            {
              GimpDialogFactory      *factory      = NULL;
              GimpSessionInfo        *info         = NULL;
              gchar                  *factory_name = NULL;
              gchar                  *entry_name   = NULL;
              GimpDialogFactoryEntry *entry        = NULL;

              token = G_TOKEN_STRING;

              if (! gimp_scanner_parse_string (scanner, &factory_name))
                break;

              /* In versions <= GIMP 2.6 there was a "toolbox", a
               * "dock", a "display" and a "toplevel" factory. These
               * are now merged to a single gimp_dialog_factory_get_singleton (). We
               * need the legacy name though, so keep it around.
               */
              factory = gimp_dialog_factory_get_singleton ();

              info = gimp_session_info_new ();

              /* GIMP 2.6 has the entry name as part of the
               * session-info header, so try to get it
               */
              gimp_scanner_parse_string (scanner, &entry_name);
              if (entry_name)
                {
                  /* Previously, GimpDock was a toplevel. That is why
                   * versions <= GIMP 2.6 has "dock" as the entry name. We
                   * want "dock" to be interpreted as 'dock window'
                   * however so have some special-casing for that. When
                   * the entry name is "dock" the factory name is either
                   * "dock" or "toolbox".
                   */
                  if (strcmp (entry_name, "dock") == 0)
                    {
                      entry =
                        gimp_dialog_factory_find_entry (factory,
                                                        (strcmp (factory_name, "toolbox") == 0 ?
                                                         "gimp-toolbox-window" :
                                                         "gimp-dock-window"));
                    }
                  else
                    {
                      entry = gimp_dialog_factory_find_entry (factory,
                                                              entry_name);
                    }
                }

              /* We're done with these now */
              g_free (factory_name);
              g_free (entry_name);

              /* We can get the factory entry either now (the GIMP <=
               * 2.6 way), or when we deserialize (the GIMP 2.8 way)
               */
              if (entry)
                {
                  gimp_session_info_set_factory_entry (info, entry);
                }

              /* Always try to deserialize */
              if (gimp_config_deserialize (GIMP_CONFIG (info), scanner, 1, NULL))
                {
                  /* Make sure we got a factory entry either the 2.6
                   * or 2.8 way
                   */
                  if (gimp_session_info_get_factory_entry (info))
                    {
                      GIMP_LOG (DIALOG_FACTORY,
                                "successfully parsed and added session info %p",
                                info);

                      gimp_dialog_factory_add_session_info (factory, info);
                    }
                  else
                    {
                      GIMP_LOG (DIALOG_FACTORY,
                                "failed to parse session info %p, not adding",
                                info);
                    }

                  g_object_unref (info);
                }
              else
                {
                  g_object_unref (info);
                  break;
                }
            }
          else if (scanner->value.v_symbol == GINT_TO_POINTER (HIDE_DOCKS))
            {
              gboolean hide_docks;

              token = G_TOKEN_IDENTIFIER;

              if (! gimp_scanner_parse_boolean (scanner, &hide_docks))
                break;

              g_object_set (gimp->config,
                            "hide-docks", hide_docks,
                            NULL);
            }
          else if (scanner->value.v_symbol == GINT_TO_POINTER (SINGLE_WINDOW_MODE))
            {
              gboolean single_window_mode;

              token = G_TOKEN_IDENTIFIER;

              if (! gimp_scanner_parse_boolean (scanner, &single_window_mode))
                break;

              g_object_set (gimp->config,
                            "single-window-mode", single_window_mode,
                            NULL);
            }
          else if (scanner->value.v_symbol == GINT_TO_POINTER (LAST_TIP_SHOWN))
            {
              gint last_tip_shown;

              token = G_TOKEN_INT;

              if (! gimp_scanner_parse_int (scanner, &last_tip_shown))
                break;

              g_object_set (gimp->config,
                            "last-tip-shown", last_tip_shown,
                            NULL);
            }
          token = G_TOKEN_RIGHT_PAREN;
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_LEFT_PAREN;
          break;

        default: /* do nothing */
          break;
        }
    }

  if (token != G_TOKEN_LEFT_PAREN)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
    }

  if (error)
    {
      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
      g_clear_error (&error);

      gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
    }

  gimp_scanner_destroy (scanner);
  g_free (filename);

  dialogs_load_recent_docks (gimp);
}
Пример #11
0
/*----------------------- read conf (.guvcviewrc(-videoX)) file -----------------------*/
int
readConf(struct GLOBAL *global)
{
	int ret=0;
//	int signal=1; /*1=>+ or -1=>-*/
	GScanner  *scanner;
	GTokenType ttype;
	GScannerConfig config =
	{
		" \t\r\n",                     /* characters to skip */
		G_CSET_a_2_z "_" G_CSET_A_2_Z, /* identifier start */
		G_CSET_a_2_z "_." G_CSET_A_2_Z G_CSET_DIGITS,/* identifier cont. */
		"#\n",                         /* single line comment */
		FALSE,                         /* case_sensitive */
		TRUE,                          /* skip multi-line comments */
		TRUE,                          /* skip single line comments */
		FALSE,                         /* scan multi-line comments */
		TRUE,                          /* scan identifiers */
		TRUE,                          /* scan 1-char identifiers */
		FALSE,                         /* scan NULL identifiers */
		FALSE,                         /* scan symbols */
		FALSE,                         /* scan binary */
		FALSE,                         /* scan octal */
		TRUE,                          /* scan float */
		TRUE,                          /* scan hex */
		FALSE,                         /* scan hex dollar */
		TRUE,                          /* scan single quote strings */
		TRUE,                          /* scan double quote strings */
		TRUE,                          /* numbers to int */
		FALSE,                         /* int to float */
		TRUE,                          /* identifier to string */
		TRUE,                          /* char to token */
		FALSE,                         /* symbol to token */
		FALSE,                         /* scope 0 fallback */
		TRUE                           /* store int64 */
	};

	int fd = g_open (global->confPath, O_RDONLY, 0);

	if (fd < 0 )
	{
		printf("Could not open %s for read,\n will try to create it\n",global->confPath);
		ret=writeConf(global, global->videodevice);
	}
	else
	{
		scanner = g_scanner_new (&config);
		g_scanner_input_file (scanner, fd);
		scanner->input_name = global->confPath;

		for (ttype = g_scanner_get_next_token (scanner);
			ttype != G_TOKEN_EOF;
			ttype = g_scanner_get_next_token (scanner))
		{
			if (ttype == G_TOKEN_STRING)
			{
				//printf("reading %s...\n",scanner->value.v_string);
				char *name = g_strdup (scanner->value.v_string);
				ttype = g_scanner_get_next_token (scanner);
				if (ttype != G_TOKEN_EQUAL_SIGN)
				{
					g_scanner_unexp_token (scanner,
						G_TOKEN_EQUAL_SIGN,
						NULL,
						NULL,
						NULL,
						NULL,
						FALSE);
				}
				else
				{
					ttype = g_scanner_get_next_token (scanner);
					/*check for signed integers*/
					if(ttype == '-')
					{
						//signal = -1;
						ttype = g_scanner_get_next_token (scanner);
					}

					if (ttype == G_TOKEN_STRING)
					{
						//signal=1; /*reset signal*/
						//if (g_strcmp0(name,"video_device")==0)
						//{
						//	g_snprintf(global->videodevice,15,"%s",scanner->value.v_string);
						//}

						/*must check for defaults since ReadOpts runs before ReadConf*/
						if (g_strcmp0(name,"resolution")==0)
						{
							if(global->flg_res < 1)
								sscanf(scanner->value.v_string,"%ix%i",
									&(global->width),
									&(global->height));
						}
						else if (g_strcmp0(name,"windowsize")==0)
						{
							sscanf(scanner->value.v_string,"%ix%i",
								&(global->winwidth), &(global->winheight));
						}
						else if (g_strcmp0(name,"mode")==0)
						{
							if(global->flg_mode < 1)
							{
								/*use fourcc but keep it compatible with luvcview*/
								if(g_strcmp0(scanner->value.v_string,"yuv") == 0)
									g_snprintf(global->mode,5,"yuyv");
								else
									g_snprintf(global->mode,5,"%s",scanner->value.v_string);
							}
						}
						else if (g_strcmp0(name,"fps")==0)
						{
							sscanf(scanner->value.v_string,"%i/%i",
								&(global->fps_num), &(global->fps));
						}
#if 0
						else if (g_strcmp0(name,"image_path")==0)
						{
							if(global->flg_imgFPath < 1)
							{
								global->imgFPath = splitPath(scanner->value.v_string,global->imgFPath);
								/*get the file type*/
								global->imgFormat = check_image_type(global->imgFPath[0]);
							}
						}
						else if ((g_strcmp0(name,"video_path")==0) || (g_strcmp0(name,"avi_path")==0))
						{
							if(global->vidfile == NULL)
							{
								global->vidFPath=splitPath(scanner->value.v_string,global->vidFPath);
								/*get the file type (0-avi 1-matroska)*/
								global->VidFormat = check_video_type(global->vidFPath[0]);
							}
						}
						else
						{
							printf("unexpected string value (%s) for %s\n",
								scanner->value.v_string, name);
						}
#endif
					}
					else if (ttype==G_TOKEN_INT)
					{
						if (g_strcmp0(name,"stack_size")==0)
						{
							global->stack_size = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vid_sleep")==0)
						{
							global->vid_sleep = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"cap_meth")==0)
						{
							if(!(global->flg_cap_meth))
								global->cap_meth = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vpane")==0)
						{
							global->boxvsize = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"spinbehave")==0)
						{
							global->spinbehave = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"fps")==0)
						{
							/*parse non-quoted fps values*/
							int line = g_scanner_cur_line(scanner);

							global->fps_num = scanner->value.v_int;
							ttype = g_scanner_peek_next_token (scanner);
							if(ttype=='/')
							{
								/*get '/'*/
								ttype = g_scanner_get_next_token (scanner);
								ttype = g_scanner_peek_next_token (scanner);
								if(ttype==G_TOKEN_INT)
								{
									ttype = g_scanner_get_next_token (scanner);
									global->fps = scanner->value.v_int;
								}
								else if (scanner->next_line>line)
								{
									/*start new loop*/
									break;
								}
								else
								{
									ttype = g_scanner_get_next_token (scanner);
									g_scanner_unexp_token (scanner,
										G_TOKEN_NONE,
										NULL,
										NULL,
										NULL,
										"bad value for fps",
										FALSE);
								}
							}
						}
						else if (strcmp(name,"fps_display")==0)
						{
							if(global->flg_FpsCount < 1)
								global->FpsCount = (short) scanner->value.v_int;
						}
						else if (g_strcmp0(name,"auto_focus")==0)
						{
							global->autofocus = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"bpp")==0)
						{
							global->bpp = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"hwaccel")==0)
						{
							if(global->flg_hwaccel < 1)
								global->hwaccel = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vid_codec")==0 || (g_strcmp0(name,"avi_format")==0))
						{
							global->VidCodec = scanner->value.v_int;
						}
						else if ((g_strcmp0(name,"vid_inc")==0) || (g_strcmp0(name,"avi_inc")==0))
						{
							global->vid_inc = (DWORD) scanner->value.v_int;
							g_snprintf(global->vidinc_str,20,_("File num:%d"),global->vid_inc);
						}
						else if (g_strcmp0(name,"frame_flags")==0)
						{
							global->Frame_Flags = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"image_inc")==0)
						{
							if(global->image_timer <= 0)
							{
								global->image_inc = (DWORD) scanner->value.v_int;
								g_snprintf(global->imageinc_str,20,_("File num:%d"),global->image_inc);
							}
						}
						/*
						else
						{
							printf("unexpected integer value (%lu) for %s\n",
								scanner->value.v_int, name);
							printf("Strings must be quoted\n");
						}
						*/
					}
					else if (ttype==G_TOKEN_FLOAT)
					{
						printf("unexpected float value (%f) for %s\n", scanner->value.v_float, name);
					}
					else if (ttype==G_TOKEN_CHAR)
					{
						printf("unexpected char value (%c) for %s\n", scanner->value.v_char, name);
					}
					else
					{
						g_scanner_unexp_token (scanner,
							G_TOKEN_NONE,
							NULL,
							NULL,
							NULL,
							"string values must be quoted - skiping",
							FALSE);
						int line = g_scanner_cur_line (scanner);
						int stp=0;

						do
						{
							ttype = g_scanner_peek_next_token (scanner);
							if(scanner->next_line > line)
							{
								//printf("next line reached\n");
								stp=1;
								break;
							}
							else
							{
								ttype = g_scanner_get_next_token (scanner);
							}
						}
						while (!stp);
					}
				}
				g_free(name);
			}
		}

		g_scanner_destroy (scanner);
		close (fd);

		if (global->debug)
		{
			g_printf("video_device: %s\n",global->videodevice);
//			g_printf("vid_sleep: %i\n",global->vid_sleep);
			g_printf("cap_meth: %i\n",global->cap_meth);
			g_printf("resolution: %i x %i\n",global->width,global->height);
//			g_printf("windowsize: %i x %i\n",global->winwidth,global->winheight);
//			g_printf("vert pane: %i\n",global->boxvsize);
//			g_printf("spin behavior: %i\n",global->spinbehave);
//			g_printf("mode: %s\n",global->mode);
			g_printf("fps: %i/%i\n",global->fps_num,global->fps);
			g_printf("Display Fps: %i\n",global->FpsCount);
			g_printf("bpp: %i\n",global->bpp);
			g_printf("hwaccel: %i\n",global->hwaccel);
//			g_printf("avi_format: %i\n",global->VidCodec);
			g_printf("Pan Step: %i degrees\n",global->PanStep);
			g_printf("Tilt Step: %i degrees\n",global->TiltStep);
			g_printf("Video Filter Flags: %i\n",global->Frame_Flags);
//			g_printf("image inc: %d\n",global->image_inc);
		}
	}

	return (ret);
}
Пример #12
0
GSList *
plug_in_rc_parse (Gimp    *gimp,
                  GFile   *file,
                  GError **error)
{
  GScanner   *scanner;
  GEnumClass *enum_class;
  GSList     *plug_in_defs     = NULL;
  gint        protocol_version = GIMP_PROTOCOL_VERSION;
  gint        file_version     = PLUG_IN_RC_FILE_VERSION;
  GTokenType  token;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  scanner = gimp_scanner_new_gfile (file, error);

  if (! scanner)
    return NULL;

  enum_class = g_type_class_ref (GIMP_TYPE_ICON_TYPE);

  g_scanner_scope_add_symbol (scanner, 0,
                              "protocol-version",
                              GINT_TO_POINTER (PROTOCOL_VERSION));
  g_scanner_scope_add_symbol (scanner, 0,
                              "file-version",
                              GINT_TO_POINTER (FILE_VERSION));
  g_scanner_scope_add_symbol (scanner, 0,
                              "plug-in-def", GINT_TO_POINTER (PLUG_IN_DEF));

  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "proc-def", GINT_TO_POINTER (PROC_DEF));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "locale-def", GINT_TO_POINTER (LOCALE_DEF));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "help-def", GINT_TO_POINTER (HELP_DEF));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "has-init", GINT_TO_POINTER (HAS_INIT));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "proc-arg", GINT_TO_POINTER (PROC_ARG));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "menu-path", GINT_TO_POINTER (MENU_PATH));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "icon", GINT_TO_POINTER (ICON));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "load-proc", GINT_TO_POINTER (LOAD_PROC));
  g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF,
                              "save-proc", GINT_TO_POINTER (SAVE_PROC));

  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "extension", GINT_TO_POINTER (EXTENSION));
  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "prefix", GINT_TO_POINTER (PREFIX));
  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "magic", GINT_TO_POINTER (MAGIC));
  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "mime-type", GINT_TO_POINTER (MIME_TYPE));
  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "handles-uri", GINT_TO_POINTER (HANDLES_URI));
  g_scanner_scope_add_symbol (scanner, LOAD_PROC,
                              "thumb-loader", GINT_TO_POINTER (THUMB_LOADER));

  g_scanner_scope_add_symbol (scanner, SAVE_PROC,
                              "extension", GINT_TO_POINTER (EXTENSION));
  g_scanner_scope_add_symbol (scanner, SAVE_PROC,
                              "prefix", GINT_TO_POINTER (PREFIX));
  g_scanner_scope_add_symbol (scanner, SAVE_PROC,
                              "mime-type", GINT_TO_POINTER (MIME_TYPE));
  g_scanner_scope_add_symbol (scanner, SAVE_PROC,
                              "handles-uri", GINT_TO_POINTER (HANDLES_URI));

  token = G_TOKEN_LEFT_PAREN;

  while (protocol_version == GIMP_PROTOCOL_VERSION   &&
         file_version     == PLUG_IN_RC_FILE_VERSION &&
         g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          switch (GPOINTER_TO_INT (scanner->value.v_symbol))
            {
            case PROTOCOL_VERSION:
              token = G_TOKEN_INT;
              if (gimp_scanner_parse_int (scanner, &protocol_version))
                token = G_TOKEN_RIGHT_PAREN;
              break;

            case FILE_VERSION:
              token = G_TOKEN_INT;
              if (gimp_scanner_parse_int (scanner, &file_version))
                token = G_TOKEN_RIGHT_PAREN;
              break;

            case PLUG_IN_DEF:
              g_scanner_set_scope (scanner, PLUG_IN_DEF);
              token = plug_in_def_deserialize (gimp, scanner, &plug_in_defs);
              g_scanner_set_scope (scanner, 0);
              break;
            default:
              break;
            }
              break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_LEFT_PAREN;
          break;

        default: /* do nothing */
          break;
        }
    }

  if (protocol_version != GIMP_PROTOCOL_VERSION   ||
      file_version     != PLUG_IN_RC_FILE_VERSION ||
      token            != G_TOKEN_LEFT_PAREN)
    {
      if (protocol_version != GIMP_PROTOCOL_VERSION)
        {
          g_set_error (error,
                       GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_VERSION,
                       _("Skipping '%s': wrong GIMP protocol version."),
                       gimp_file_get_utf8_name (file));
        }
      else if (file_version != PLUG_IN_RC_FILE_VERSION)
        {
          g_set_error (error,
                       GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_VERSION,
                       _("Skipping '%s': wrong pluginrc file format version."),
                       gimp_file_get_utf8_name (file));
        }
      else
        {
          g_scanner_get_next_token (scanner);
          g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                                 _("fatal parse error"), TRUE);
        }

      g_slist_free_full (plug_in_defs, (GDestroyNotify) g_object_unref);
      plug_in_defs = NULL;
    }

  g_type_class_unref (enum_class);

  gimp_scanner_destroy (scanner);

  return g_slist_reverse (plug_in_defs);
}
Пример #13
0
/**
 * gimp_scanner_parse_color:
 * @scanner: A #GScanner created by gimp_scanner_new_file() or
 *           gimp_scanner_new_string()
 * @dest: Pointer to a color to store the result
 *
 * Return value: %TRUE on success
 *
 * Since: 2.4
 **/
gboolean
gimp_scanner_parse_color (GScanner *scanner,
                          GimpRGB  *dest)
{
  guint      scope_id;
  guint      old_scope_id;
  GTokenType token;
  GimpRGB    color = { 0.0, 0.0, 0.0, 1.0 };

  scope_id = g_quark_from_static_string ("gimp_scanner_parse_color");
  old_scope_id = g_scanner_set_scope (scanner, scope_id);

  if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "color-rgb"))
    {
      g_scanner_scope_add_symbol (scanner, scope_id,
                                  "color-rgb", GINT_TO_POINTER (COLOR_RGB));
      g_scanner_scope_add_symbol (scanner, scope_id,
                                  "color-rgba", GINT_TO_POINTER (COLOR_RGBA));
      g_scanner_scope_add_symbol (scanner, scope_id,
                                  "color-hsv", GINT_TO_POINTER (COLOR_HSV));
      g_scanner_scope_add_symbol (scanner, scope_id,
                                  "color-hsva", GINT_TO_POINTER (COLOR_HSVA));
    }

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          {
            gdouble  col[4]     = { 0.0, 0.0, 0.0, 1.0 };
            gint     n_channels = 4;
            gboolean is_hsv     = FALSE;
            gint     i;

            switch (GPOINTER_TO_INT (scanner->value.v_symbol))
              {
              case COLOR_RGB:
                n_channels = 3;
                /* fallthrough */
              case COLOR_RGBA:
                break;

              case COLOR_HSV:
                n_channels = 3;
                /* fallthrough */
              case COLOR_HSVA:
                is_hsv = TRUE;
                break;
              }

            token = G_TOKEN_FLOAT;

            for (i = 0; i < n_channels; i++)
              {
                gboolean negate = FALSE;

                if (g_scanner_peek_next_token (scanner) == '-')
                  {
                    negate = TRUE;
                    g_scanner_get_next_token (scanner);
                  }

                if (! gimp_scanner_parse_float (scanner, &col[i]))
                  goto finish;

                if (negate)
                  col[i] = - col[i];
              }

            if (is_hsv)
              {
                GimpHSV hsv;

                gimp_hsva_set (&hsv, col[0], col[1], col[2], col[3]);
                gimp_hsv_clamp (&hsv);

                gimp_hsv_to_rgb (&hsv, &color);
              }
            else
              {
                gimp_rgba_set (&color, col[0], col[1], col[2], col[3]);
                gimp_rgb_clamp (&color);
              }

            token = G_TOKEN_RIGHT_PAREN;
          }
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_NONE; /* indicates success */
          goto finish;

        default: /* do nothing */
          break;
        }
    }

 finish:

  if (token != G_TOKEN_NONE)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
    }
  else
    {
      *dest = color;
    }

  g_scanner_set_scope (scanner, old_scope_id);

  return (token == G_TOKEN_NONE);
}
Пример #14
0
/**
 * gimp_scanner_parse_matrix2:
 * @scanner: A #GScanner created by gimp_scanner_new_file() or
 *           gimp_scanner_new_string()
 * @dest: Pointer to a matrix to store the result
 *
 * Return value: %TRUE on success
 *
 * Since: 2.4
 **/
gboolean
gimp_scanner_parse_matrix2 (GScanner    *scanner,
                            GimpMatrix2 *dest)
{
  guint        scope_id;
  guint        old_scope_id;
  GTokenType   token;
  GimpMatrix2  matrix;

  scope_id = g_quark_from_static_string ("gimp_scanner_parse_matrix");
  old_scope_id = g_scanner_set_scope (scanner, scope_id);

  if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "matrix"))
    g_scanner_scope_add_symbol (scanner, scope_id,
                                "matrix", GINT_TO_POINTER (0));

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          {
            token = G_TOKEN_FLOAT;

            if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][0]))
              goto finish;
            if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][1]))
              goto finish;
            if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][0]))
              goto finish;
            if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][1]))
              goto finish;

            token = G_TOKEN_RIGHT_PAREN;
          }
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_NONE; /* indicates success */
          goto finish;

        default: /* do nothing */
          break;
        }
    }

 finish:

  if (token != G_TOKEN_NONE)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
    }
  else
    {
      *dest = matrix;
    }

  g_scanner_set_scope (scanner, old_scope_id);

  return (token == G_TOKEN_NONE);
}
Пример #15
0
void parse_config (GromitData *data)
{
  GromitPaintContext *context=NULL;
  GromitPaintContext *context_template=NULL;
  GScanner *scanner;
  GTokenType token;
  gchar *filename;
  int file;

  gchar *name, *copy;

  GromitPaintType type;
  GdkRGBA *fg_color=NULL;
  guint width, arrowsize, minwidth;

  filename = g_strjoin (G_DIR_SEPARATOR_S,
                        g_get_user_config_dir(), "gromit-mpx.cfg", NULL);
  file = open (filename, O_RDONLY);

  if (file < 0)
    {
      g_printerr ("Could not open %s: %s\n", filename, g_strerror (errno));
      /* try global config file */
      g_free (filename);
      filename = g_strdup ("/etc/gromit-mpx/gromit-mpx.cfg");
      file = open (filename, O_RDONLY);

      if (file < 0)
        {
          g_printerr ("Could not open %s: %s\n", filename, g_strerror (errno));
          g_free (filename);
          return;
        }
    }

  scanner = g_scanner_new (NULL);
  scanner->input_name = filename;
  scanner->config->case_sensitive = 0;
  scanner->config->scan_octal = 0;
  scanner->config->identifier_2_string = 0;
  scanner->config->char_2_token = 1;
  scanner->config->numbers_2_int = 1;
  scanner->config->int_2_float = 1;

  g_scanner_scope_add_symbol (scanner, 0, "PEN",    (gpointer) GROMIT_PEN);
  g_scanner_scope_add_symbol (scanner, 0, "ERASER", (gpointer) GROMIT_ERASER);
  g_scanner_scope_add_symbol (scanner, 0, "RECOLOR",(gpointer) GROMIT_RECOLOR);

  g_scanner_scope_add_symbol (scanner, 1, "BUTTON1", (gpointer) 1);
  g_scanner_scope_add_symbol (scanner, 1, "BUTTON2", (gpointer) 2);
  g_scanner_scope_add_symbol (scanner, 1, "BUTTON3", (gpointer) 3);
  g_scanner_scope_add_symbol (scanner, 1, "BUTTON4", (gpointer) 4);
  g_scanner_scope_add_symbol (scanner, 1, "BUTTON5", (gpointer) 5);
  g_scanner_scope_add_symbol (scanner, 1, "SHIFT",   (gpointer) 11);
  g_scanner_scope_add_symbol (scanner, 1, "CONTROL", (gpointer) 12);
  g_scanner_scope_add_symbol (scanner, 1, "META",    (gpointer) 13);
  g_scanner_scope_add_symbol (scanner, 1, "ALT",     (gpointer) 13);

  g_scanner_scope_add_symbol (scanner, 2, "size",      (gpointer) 1);
  g_scanner_scope_add_symbol (scanner, 2, "color",     (gpointer) 2);
  g_scanner_scope_add_symbol (scanner, 2, "arrowsize", (gpointer) 3);
  g_scanner_scope_add_symbol (scanner, 2, "minsize",   (gpointer) 4);

  g_scanner_set_scope (scanner, 0);
  scanner->config->scope_0_fallback = 0;

  g_scanner_input_file (scanner, file);

  token = g_scanner_get_next_token (scanner);
  while (token != G_TOKEN_EOF)
    {

      /*
       * New tool definition
       */

      if (token == G_TOKEN_STRING)
        {
          name = parse_name (scanner);
          token = g_scanner_cur_token(scanner);

          if (token != G_TOKEN_EQUAL_SIGN)
            {
              g_scanner_unexp_token (scanner, G_TOKEN_EQUAL_SIGN, NULL,
                                     NULL, NULL, "aborting", TRUE);
              exit (1);
            }

          token = g_scanner_get_next_token (scanner);

          /* defaults */

          type = GROMIT_PEN;
          width = 7;
          arrowsize = 0;
          minwidth = 1;
          fg_color = data->red;

          if (token == G_TOKEN_SYMBOL)
            {
              type = (GromitPaintType) scanner->value.v_symbol;
              token = g_scanner_get_next_token (scanner);
            }
          else if (token == G_TOKEN_STRING)
            {
              copy = parse_name (scanner);
              token = g_scanner_cur_token(scanner);
              context_template = g_hash_table_lookup (data->tool_config, copy);
              if (context_template)
                {
                  type = context_template->type;
                  width = context_template->width;
                  arrowsize = context_template->arrowsize;
                  minwidth = context_template->minwidth;
                  fg_color = context_template->paint_color;
                }
              else
                {
                  g_printerr ("WARNING: Unable to copy \"%s\": "
                              "not yet defined!\n", copy);
                }
            }
          else
            {
              g_printerr ("Expected Tool-definition "
                          "or name of template tool\n");
              exit (1);
            }

          /* Are there any tool-options?
           */

          if (token == G_TOKEN_LEFT_PAREN)
            {
              GdkRGBA *color = NULL;
              g_scanner_set_scope (scanner, 2);
              scanner->config->int_2_float = 1;
              token = g_scanner_get_next_token (scanner);
              while (token != G_TOKEN_RIGHT_PAREN)
                {
                  if (token == G_TOKEN_SYMBOL)
                    {
                      if ((intptr_t) scanner->value.v_symbol == 1)
                        {
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_EQUAL_SIGN)
                            {
                              g_printerr ("Missing \"=\"... aborting\n");
                              exit (1);
                            }
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_FLOAT)
                            {
                              g_printerr ("Missing Size (float)... aborting\n");
                              exit (1);
                            }
                          width = (guint) (scanner->value.v_float + 0.5);
                        }
                      else if ((intptr_t) scanner->value.v_symbol == 2)
                        {
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_EQUAL_SIGN)
                            {
                              g_printerr ("Missing \"=\"... aborting\n");
                              exit (1);
                            }
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_STRING)
                            {
                              g_printerr ("Missing Color (string)... "
                                          "aborting\n");
                              exit (1);
                            }
                          color = g_malloc (sizeof (GdkRGBA));
                          if (gdk_rgba_parse (color, scanner->value.v_string))
                            {
			      fg_color = color;
                            }
                          else
                            {
                              g_printerr ("Unable to parse color. "
                                          "Keeping default.\n");
                              g_free (color);
                            }
                          color = NULL;
                        }
                      else if ((intptr_t) scanner->value.v_symbol == 3)
                        {
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_EQUAL_SIGN)
                            {
                              g_printerr ("Missing \"=\"... aborting\n");
                              exit (1);
                            }
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_FLOAT)
                            {
                              g_printerr ("Missing Arrowsize (float)... "
                                          "aborting\n");
                              exit (1);
                            }
                          arrowsize = scanner->value.v_float;
                        }
                      else if ((intptr_t) scanner->value.v_symbol == 4)
                        {
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_EQUAL_SIGN)
                            {
                              g_printerr ("Missing \"=\"... aborting\n");
                              exit (1);
                            }
                          token = g_scanner_get_next_token (scanner);
                          if (token != G_TOKEN_FLOAT)
                            {
                              g_printerr ("Missing Minsize (float)... "
                                          "aborting\n");
                              exit (1);
                            }
                          minwidth = scanner->value.v_float;
                        }
		      else
                        {
                          g_printerr ("Unknown tool type?????\n");
                        }
                    }
                  else
                    {
                      g_printerr ("skipped token!!!\n");
                    }
                  token = g_scanner_get_next_token (scanner);
                }
              g_scanner_set_scope (scanner, 0);
              token = g_scanner_get_next_token (scanner);
            }

          /*
           * Finally we expect a semicolon
           */

          if (token != ';')
            {
              g_printerr ("Expected \";\"\n");
              exit (1);
            }

          context = paint_context_new (data, type, fg_color, width, arrowsize, minwidth);
          g_hash_table_insert (data->tool_config, name, context);
        }
      else
        {
          g_printerr ("Expected name of Tool to define\n");
          exit(1);
        }

      token = g_scanner_get_next_token (scanner);
    }
  g_scanner_destroy (scanner);
  close (file);
  g_free (filename);
}
Пример #16
0
/*
  Parse the class version. Note that the identifier is the current symbol..

  CV:= IDL_SYMBOL_CLSVERSION '(' NUM ',' NUM ')' ';'
 */
void parseClassVersion(void)
{
  GTokenValue value;

  if(!matchNext('('))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            '(',
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }

  if(!matchNext(G_TOKEN_INT))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            G_TOKEN_INT,
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }
  value=gScanner->value;
  pParseInfo->pCurInterface->ulMajor=value.v_int;

  if(!matchNext(','))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            ',',
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }
  if(!matchNext(G_TOKEN_INT))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            G_TOKEN_INT,
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }
  value=gScanner->value;
  pParseInfo->pCurInterface->ulMinor=value.v_int;

  if(!matchNext(')'))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            ')',
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }
  if(!matchNext(';'))
    {
      getNextToken(); /* Make sure error references the correct token */
      g_scanner_unexp_token(gScanner,
                            ';',
                            NULL,
                            NULL,
                            NULL,
                            "Error in NOMCLASSVERSION()",
                            TRUE); /* is_error */
      exit(1);
    }
}
Пример #17
0
/*----------------------- read conf (.config/guvcview/videoX) file -----------------------*/
int
readConf(struct GLOBAL *global)
{
	int ret=0;
	//int signal=1; /*1=>+ or -1=>-*/
	GScanner  *scanner;
	GTokenType ttype;
	GScannerConfig config =
	{
		" \t\r\n",                     /* characters to skip */
		G_CSET_a_2_z "_" G_CSET_A_2_Z, /* identifier start */
		G_CSET_a_2_z "_." G_CSET_A_2_Z G_CSET_DIGITS,/* identifier cont. */
		"#\n",                         /* single line comment */
		FALSE,                         /* case_sensitive */
		TRUE,                          /* skip multi-line comments */
		TRUE,                          /* skip single line comments */
		FALSE,                         /* scan multi-line comments */
		TRUE,                          /* scan identifiers */
		TRUE,                          /* scan 1-char identifiers */
		FALSE,                         /* scan NULL identifiers */
		FALSE,                         /* scan symbols */
		FALSE,                         /* scan binary */
		FALSE,                         /* scan octal */
		TRUE,                          /* scan float */
		TRUE,                          /* scan hex */
		FALSE,                         /* scan hex dollar */
		TRUE,                          /* scan single quote strings */
		TRUE,                          /* scan double quote strings */
		TRUE,                          /* numbers to int */
		FALSE,                         /* int to float */
		TRUE,                          /* identifier to string */
		TRUE,                          /* char to token */
		FALSE,                         /* symbol to token */
		FALSE,                         /* scope 0 fallback */
		TRUE                           /* store int64 */
	};

	int fd = g_open (global->confPath, O_RDONLY, 0);

	if (fd < 0 )
	{
		printf("Could not open %s for read,\n will try to create it\n",global->confPath);
		ret=writeConf(global, global->videodevice);
	}
	else
	{
		scanner = g_scanner_new (&config);
		g_scanner_input_file (scanner, fd);
		scanner->input_name = global->confPath;
		//temp codec values
		int ac_bit_rate =-1, vc_bit_rate=-1, vc_fps=-1, vc_qmax=-1, vc_qmin=-1, vc_max_qdiff=-1, vc_dia=-1;
		int vc_pre_dia=-1, vc_pre_me=-1, vc_me_pre_cmp=-1, vc_me_cmp=-1, vc_me_sub_cmp=-1, vc_last_pred=-1;
		int vc_gop_size=-1, vc_subq=-1, vc_framerefs=-1, vc_mb_decision=-1, vc_trellis=-1, vc_me_method=-1;
		int vc_mpeg_quant=-1, vc_max_b_frames=-1, vc_num_threads=-1, vc_flags=-1, vc_monotonic_pts=-1;
		float vc_qcompress=-1, vc_qblur=-1;
		int VMAJOR =-1, VMINOR=-1, VMICRO=-1;

		for (ttype = g_scanner_get_next_token (scanner);
			ttype != G_TOKEN_EOF;
			ttype = g_scanner_get_next_token (scanner))
		{
			if (ttype == G_TOKEN_STRING)
			{
				//printf("reading %s...\n",scanner->value.v_string);
				char *name = g_strdup (scanner->value.v_string);
				ttype = g_scanner_get_next_token (scanner);
				if (ttype != G_TOKEN_EQUAL_SIGN)
				{
					g_scanner_unexp_token (scanner,
						G_TOKEN_EQUAL_SIGN,
						NULL,
						NULL,
						NULL,
						NULL,
						FALSE);
				}
				else
				{
					ttype = g_scanner_get_next_token (scanner);
					/*check for signed integers*/
					if(ttype == '-')
					{
						//signal = -1;
						ttype = g_scanner_get_next_token (scanner);
					}

					if (ttype == G_TOKEN_STRING)
					{

						if (g_strcmp0(name,"version")==0)
						{
							sscanf(scanner->value.v_string,"%i.%i.%i",
								&(VMAJOR),
								&(VMINOR),
								&(VMICRO));
						}
						else if (g_strcmp0(name,"resolution")==0)
						{
							if(global->flg_res < 1) /*must check for defaults since ReadOpts runs before ReadConf*/
								sscanf(scanner->value.v_string,"%ix%i",
									&(global->width),
									&(global->height));
						}
						else if (g_strcmp0(name,"windowsize")==0)
						{
							sscanf(scanner->value.v_string,"%ix%i",
								&(global->winwidth), &(global->winheight));
						}
						else if (g_strcmp0(name,"mode")==0)
						{
							if(global->flg_mode < 1)
							{
								/*use fourcc but keep it compatible with luvcview*/
								if(g_strcmp0(scanner->value.v_string,"yuv") == 0)
									g_snprintf(global->mode,5,"yuyv");
								else
									g_snprintf(global->mode,5,"%s",scanner->value.v_string);
							}
						}
						else if (g_strcmp0(name,"fps")==0)
						{
							sscanf(scanner->value.v_string,"%i/%i",
								&(global->fps_num), &(global->fps));
						}
						else if (g_strcmp0(name,"image_path")==0)
						{
							if(global->flg_imgFPath < 1)
							{
								global->imgFPath = splitPath(scanner->value.v_string,global->imgFPath);
								/*get the file type*/

								global->imgFormat = check_image_type(global->imgFPath[0]);
							}
							else
							{
							    /* check if new file != old file */
							    gchar * newPath = g_strjoin ("/", global->imgFPath[1], global->imgFPath[0], NULL);
							    //printf("image path: %s\n old path: %s\n", newPath, scanner->value.v_string);
							    if(g_strcmp0(scanner->value.v_string, newPath) !=0)
	                            {
	                                /* reset counter */
	                                //printf("reset counter from: %i\n", global->image_inc);
	                                if(global->image_inc > 0)
	                                {
	                                    global->image_inc = 1;
	                                    //g_snprintf(global->imageinc_str,20,_("File num:%d"),global->image_inc);
	                                }
	                            }
	                            g_free(newPath);
							}
						}
						else if ((g_strcmp0(name,"video_path")==0) || (g_strcmp0(name,"avi_path")==0))
						{
							if(global->vidfile == NULL)
							{
								global->vidFPath=splitPath(scanner->value.v_string,global->vidFPath);
							}
						}
						else if (g_strcmp0(name,"profile_path")==0)
						{
							if(global->lprofile < 1)
								global->profile_FPath=splitPath(scanner->value.v_string,
									global->profile_FPath);
						}
						else
						{
							printf("unexpected string value (%s) for %s\n",
								scanner->value.v_string, name);
						}
					}
					else if (ttype==G_TOKEN_INT)
					{
						if (g_strcmp0(name,"stack_size")==0)
						{
							global->stack_size = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vid_sleep")==0)
						{
							global->vid_sleep = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"cap_meth")==0)
						{
							if(!(global->flg_cap_meth))
								global->cap_meth = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"spinbehave")==0)
						{
							global->spinbehave = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"default_action")==0)
						{
							global->default_action = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"fps")==0)
						{
							/*parse non-quoted fps values*/
							int line = g_scanner_cur_line(scanner);

							global->fps_num = scanner->value.v_int;
							ttype = g_scanner_peek_next_token (scanner);
							if(ttype=='/')
							{
								/*get '/'*/
								ttype = g_scanner_get_next_token (scanner);
								ttype = g_scanner_peek_next_token (scanner);
								if(ttype==G_TOKEN_INT)
								{
									ttype = g_scanner_get_next_token (scanner);
									global->fps = scanner->value.v_int;
								}
								else if (scanner->next_line>line)
								{
									/*start new loop*/
									break;
								}
								else
								{
									ttype = g_scanner_get_next_token (scanner);
									g_scanner_unexp_token (scanner,
										G_TOKEN_NONE,
										NULL,
										NULL,
										NULL,
										"bad value for fps",
										FALSE);
								}
							}
						}
						else if (strcmp(name,"fps_display")==0)
						{
							if(global->flg_FpsCount < 1)
								global->FpsCount = (short) scanner->value.v_int;
						}
						else if (g_strcmp0(name,"auto_focus")==0)
						{
							global->autofocus = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"bpp")==0)
						{
							global->bpp = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"hwaccel")==0)
						{
							if(global->flg_hwaccel < 1)
								global->hwaccel = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vid_codec")==0 || (g_strcmp0(name,"avi_format")==0))
						{
							global->VidCodec = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vid_format")==0)
						{
							global->VidFormat = scanner->value.v_int;
						}
						else if ((g_strcmp0(name,"vid_inc")==0) || (g_strcmp0(name,"avi_inc")==0))
						{
							global->vid_inc = (DWORD) scanner->value.v_int;
						}
						else if (g_strcmp0(name,"sound")==0)
						{
							global->Sound_enable = (short) scanner->value.v_int;
						}
						else if (g_strcmp0(name,"snd_api")==0)
						{
							global->Sound_API = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"snd_device")==0)
						{
							global->Sound_UseDev = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"snd_samprate")==0)
						{
							global->Sound_SampRateInd = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"snd_numchan")==0)
						{
							global->Sound_NumChanInd = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"snd_delay")==0)
						{
							global->Sound_delay = scanner->value.v_int64;
						}
						else if (g_strcmp0(name,"aud_codec")==0)
						{
							global->AudCodec = scanner->value.v_int;
							global->Sound_Format = get_aud4cc(global->AudCodec);
						}
						else if (g_strcmp0(name,"frame_flags")==0)
						{
							global->Frame_Flags = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"osd_flags")==0)
						{
							global->osdFlags = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"image_inc")==0)
						{
							global->image_inc = (DWORD) scanner->value.v_int;
						}
						else if (g_strcmp0(name,"acodec_bit_rate")==0)
						{
						    ac_bit_rate = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_bit_rate")==0)
						{
						    vc_bit_rate = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_fps")==0)
						{
						    vc_fps = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_monotonic_pts")==0)
						{
						    vc_monotonic_pts = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_qmax")==0)
						{
						    vc_qmax = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_qmin")==0)
						{
						    vc_qmin = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_max_qdiff")==0)
						{
						    vc_max_qdiff = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_dia")==0)
						{
						    vc_dia = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_pre_dia")==0)
						{
						    vc_pre_dia = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_pre_me")==0)
						{
						    vc_pre_me= scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_me_pre_cmp")==0)
						{
						    vc_me_pre_cmp = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_me_cmp")==0)
						{
						    vc_me_cmp = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_me_sub_cmp")==0)
						{
						    vc_me_sub_cmp = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_last_pred")==0)
						{
						    vc_last_pred = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_gop_size")==0)
						{
						    vc_gop_size = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_subq")==0)
						{
						    vc_subq = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_framerefs")==0)
						{
						    vc_framerefs = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_mb_decision")==0)
						{
						    vc_mb_decision = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_trellis")==0)
						{
						    vc_trellis = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_me_method")==0)
						{
						    vc_me_method = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_mpeg_quant")==0)
						{
						    vc_mpeg_quant = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_max_b_frames")==0)
						{
						    vc_max_b_frames = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_flags")==0)
						{
						    vc_flags = scanner->value.v_int;
						}
						else if (g_strcmp0(name,"vcodec_num_threads")==0)
						{
						    vc_num_threads = scanner->value.v_int;
						}
						else
						{
							printf("unexpected integer value (%lu) for %s\n",
								scanner->value.v_int, name);
							printf("Strings must be quoted\n");
						}
					}
					else if (ttype==G_TOKEN_FLOAT)
					{
					    if (g_strcmp0(name,"vcodec_qcompress")==0)
						{
						    vc_qcompress = scanner->value.v_float;
						}
						else if (g_strcmp0(name,"vcodec_qblur")==0)
						{
						    vc_qblur = scanner->value.v_float;
						}
						else
						    printf("unexpected float value (%f) for %s\n", scanner->value.v_float, name);
					}
					else if (ttype==G_TOKEN_CHAR)
					{
						printf("unexpected char value (%c) for %s\n", scanner->value.v_char, name);
					}
					else
					{
						g_scanner_unexp_token (scanner,
							G_TOKEN_NONE,
							NULL,
							NULL,
							NULL,
							"string values must be quoted - skiping",
							FALSE);
						int line = g_scanner_cur_line (scanner);
						int stp=0;

						do
						{
							ttype = g_scanner_peek_next_token (scanner);
							if(scanner->next_line > line)
							{
								//printf("next line reached\n");
								stp=1;
								break;
							}
							else
							{
								ttype = g_scanner_get_next_token (scanner);
							}
						}
						while (!stp);
					}
				}
				g_free(name);
			}
		}

		g_scanner_destroy (scanner);
		close (fd);

		//get pointers to codec properties
        vcodecs_data *vcodec_defaults = get_codec_defaults(global->VidCodec);
        acodecs_data *acodec_defaults = get_aud_codec_defaults(get_ind_by4cc(global->Sound_Format));

        if (ac_bit_rate >= 0) acodec_defaults->bit_rate = ac_bit_rate;
        if (vc_bit_rate >= 0) vcodec_defaults->bit_rate = vc_bit_rate;
        if (vc_fps >= 0) vcodec_defaults->fps = vc_fps;
        //from 1.5.3 onwards we set version on conf file and monotonic is set by default for all codecs
        if ((vc_monotonic_pts >= 0) && (VMAJOR > 0)) vcodec_defaults->monotonic_pts = vc_monotonic_pts;
		if (vc_qmax >= 0) vcodec_defaults->qmax = vc_qmax;
		if (vc_qmin >= 0) vcodec_defaults->qmin = vc_qmin;
		if (vc_max_qdiff >=0) vcodec_defaults->max_qdiff = vc_max_qdiff;
		if (vc_dia >=0) vcodec_defaults->dia = vc_dia;
		if (vc_pre_dia >=0) vcodec_defaults->pre_dia = vc_pre_dia;
		if (vc_pre_me >=0) vcodec_defaults->pre_me = vc_pre_me;
		if (vc_me_pre_cmp >=0) vcodec_defaults->me_pre_cmp = vc_me_pre_cmp;
		if (vc_me_cmp >=0) vcodec_defaults->me_cmp = vc_me_cmp;
		if (vc_me_sub_cmp >=0) vcodec_defaults->me_sub_cmp = vc_me_sub_cmp;
		if (vc_last_pred >= 0) vcodec_defaults->last_pred = vc_last_pred;
		if (vc_gop_size >= 0) vcodec_defaults->gop_size = vc_gop_size;
		if (vc_subq >=0) vcodec_defaults->subq = vc_subq;
		if (vc_framerefs >=0) vcodec_defaults->framerefs = vc_framerefs;
		if (vc_mb_decision >=0) vcodec_defaults->mb_decision = vc_mb_decision;
		if (vc_trellis >=0) vcodec_defaults->trellis = vc_trellis;
		if (vc_me_method >=0) vcodec_defaults->me_method = vc_me_method;
		if (vc_mpeg_quant >=0) vcodec_defaults->mpeg_quant = vc_mpeg_quant;
		if (vc_max_b_frames >=0) vcodec_defaults->max_b_frames = vc_max_b_frames;
		if (vc_num_threads >=0) vcodec_defaults->num_threads = vc_num_threads;
        if (vc_flags >=0) vcodec_defaults->flags = vc_flags;
        if (vc_qcompress >= 0) vcodec_defaults->qcompress = vc_qcompress;
		if (vc_qblur >=0) vcodec_defaults->qblur = vc_qblur;

        if(global->vid_inc>0)
		{
			uint64_t suffix = get_file_suffix(global->vidFPath[1], global->vidFPath[0]);
			fprintf(stderr, "Video file suffix detected: %" PRIu64 "\n", suffix);
			if(suffix >= G_MAXUINT64)
			{
				global->vidFPath[0] = add_file_suffix(global->vidFPath[0], suffix);
				suffix = 0;
			}
			if(suffix > 0)
				global->vid_inc = suffix + 1;
		}

		if(global->image_inc>0)
		{
			uint64_t suffix = get_file_suffix(global->imgFPath[1], global->imgFPath[0]);
			fprintf(stderr, "Image file suffix detected: %" PRIu64 "\n", suffix);
			if(suffix >= G_MAXUINT64)
			{
				global->imgFPath[0] = add_file_suffix(global->imgFPath[0], suffix);
				suffix = 0;
			}
			if(suffix > 0)
				global->image_inc = suffix + 1;
		}

		if (global->debug)
		{
			g_print("video_device: %s\n",global->videodevice);
			g_print("vid_sleep: %i\n",global->vid_sleep);
			g_print("cap_meth: %i\n",global->cap_meth);
			g_print("resolution: %i x %i\n",global->width,global->height);
			g_print("windowsize: %i x %i\n",global->winwidth,global->winheight);
			g_print("spin behavior: %i\n",global->spinbehave);
			g_print("default action: %i\n",global->default_action);
			g_print("mode: %s\n",global->mode);
			g_print("fps: %i/%i\n",global->fps_num,global->fps);
			g_print("Display Fps: %i\n",global->FpsCount);
			g_print("bpp: %i\n",global->bpp);
			g_print("hwaccel: %i\n",global->hwaccel);
			g_print("avi_format: %i\n",global->VidCodec);
			g_print("sound: %i\n",global->Sound_enable);
			g_print("sound Device: %i\n",global->Sound_UseDev);
			g_print("sound samp rate: %i\n",global->Sound_SampRateInd);
			g_print("sound Channels: %i\n",global->Sound_NumChanInd);
			g_print("Sound delay: %llu nanosec\n",(unsigned long long) global->Sound_delay);
			g_print("Sound Format: %i \n",global->Sound_Format);
			g_print("Pan Step: %i degrees\n",global->PanStep);
			g_print("Tilt Step: %i degrees\n",global->TiltStep);
			g_print("Video Filter Flags: %i\n",global->Frame_Flags);
			g_print("image inc: %" PRIu64 "\n",global->image_inc);
			g_print("profile(default):%s/%s\n",global->profile_FPath[1],global->profile_FPath[0]);
		}
	}

	return (ret);
}
Пример #18
0
static gchar* parse_name (GScanner *scanner)
{
  GTokenType token;

  guint buttons = 0;
  guint modifier = 0;
  guint len = 0;
  gchar *name;

  token = g_scanner_cur_token(scanner);

  if (token != G_TOKEN_STRING)
    {
      g_scanner_unexp_token (scanner, G_TOKEN_STRING, NULL,
                             NULL, NULL, "aborting", TRUE);
      exit (1);
    }

  len = strlen (scanner->value.v_string);
  name = g_strndup (scanner->value.v_string, len + 3);

  token = g_scanner_get_next_token (scanner);

  /*
   * Are there any options to limit the scope of the definition?
   */

  if (token == G_TOKEN_LEFT_BRACE)
    {
      g_scanner_set_scope (scanner, 1);
      scanner->config->int_2_float = 0;
      modifier = buttons = 0;
      while ((token = g_scanner_get_next_token (scanner))
             != G_TOKEN_RIGHT_BRACE)
        {
          if (token == G_TOKEN_SYMBOL)
            {
              if ((intptr_t) scanner->value.v_symbol < 11)
                 buttons |= 1 << ((intptr_t) scanner->value.v_symbol - 1);
              else
                 modifier |= 1 << ((intptr_t) scanner->value.v_symbol - 11);
            }
          else if (token == G_TOKEN_INT)
            {
              if (scanner->value.v_int <= 5 && scanner->value.v_int > 0)
                buttons |= 1 << (scanner->value.v_int - 1);
              else
                g_printerr ("Only Buttons 1-5 are supported!\n");
            }
          else
            {
              g_printerr ("skipped token\n");
            }
        }
      g_scanner_set_scope (scanner, 0);
      scanner->config->int_2_float = 1;
      token = g_scanner_get_next_token (scanner);
    }

  name [len] = 124;
  name [len+1] = buttons + 64;
  name [len+2] = modifier + 48;
  name [len+3] = 0;

  return name;
}
Пример #19
0
void
gimp_modules_load (Gimp *gimp)
{
  gchar    *filename;
  gchar    *path;
  GScanner *scanner;
  gchar    *module_load_inhibit = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->no_interface)
    return;

  filename = gimp_personal_rc_file ("modulerc");

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  scanner = gimp_scanner_new_file (filename, NULL);
  g_free (filename);

  if (scanner)
    {
      GTokenType  token;
      GError     *error = NULL;

#define MODULE_LOAD_INHIBIT 1

      g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit",
                                  GINT_TO_POINTER (MODULE_LOAD_INHIBIT));

      token = G_TOKEN_LEFT_PAREN;

      while (g_scanner_peek_next_token (scanner) == token)
        {
          token = g_scanner_get_next_token (scanner);

          switch (token)
            {
            case G_TOKEN_LEFT_PAREN:
              token = G_TOKEN_SYMBOL;
              break;

            case G_TOKEN_SYMBOL:
              if (scanner->value.v_symbol == GINT_TO_POINTER (MODULE_LOAD_INHIBIT))
                {
                  token = G_TOKEN_STRING;

                  if (! gimp_scanner_parse_string_no_validate (scanner,
                                                               &module_load_inhibit))
                    goto error;
                }
              token = G_TOKEN_RIGHT_PAREN;
              break;

            case G_TOKEN_RIGHT_PAREN:
              token = G_TOKEN_LEFT_PAREN;
              break;

            default: /* do nothing */
              break;
            }
        }

#undef MODULE_LOAD_INHIBIT

      if (token != G_TOKEN_LEFT_PAREN)
        {
          g_scanner_get_next_token (scanner);
          g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                                 _("fatal parse error"), TRUE);
        }

    error:

      if (error)
        {
          gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
          g_clear_error (&error);
        }

      gimp_scanner_destroy (scanner);
    }

  if (module_load_inhibit)
    {
      gimp_module_db_set_load_inhibit (gimp->module_db, module_load_inhibit);
      g_free (module_load_inhibit);
    }

  path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
  gimp_module_db_load (gimp->module_db, path);
  g_free (path);
}
Пример #20
0
void
session_init (Gimp *gimp)
{
  gchar      *filename;
  GScanner   *scanner;
  GTokenType  token;
  GError     *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  filename = session_filename (gimp);

  scanner = gimp_scanner_new_file (filename, &error);

  if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
    {
      g_clear_error (&error);
      g_free (filename);

      filename = g_build_filename (gimp_sysconf_directory (),
                                   "sessionrc", NULL);
      scanner = gimp_scanner_new_file (filename, NULL);
    }

  if (! scanner)
    {
      g_clear_error (&error);
      g_free (filename);
      return;
    }

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));

  g_scanner_scope_add_symbol (scanner, 0, "session-info",
                              GINT_TO_POINTER (SESSION_INFO));
  g_scanner_scope_add_symbol (scanner, 0,  "last-tip-shown",
                              GINT_TO_POINTER (LAST_TIP_SHOWN));

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          if (scanner->value.v_symbol == GINT_TO_POINTER (SESSION_INFO))
            {
              g_scanner_set_scope (scanner, SESSION_INFO);
              token = gimp_session_info_deserialize (scanner, SESSION_INFO);

              if (token == G_TOKEN_RIGHT_PAREN)
                g_scanner_set_scope (scanner, 0);
              else
                break;
            }
          else if (scanner->value.v_symbol == GINT_TO_POINTER (LAST_TIP_SHOWN))
            {
              GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);

              token = G_TOKEN_INT;

              if (! gimp_scanner_parse_int (scanner, &config->last_tip))
                break;
            }
          token = G_TOKEN_RIGHT_PAREN;
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_LEFT_PAREN;
          break;

        default: /* do nothing */
          break;
        }
    }

  if (token != G_TOKEN_LEFT_PAREN)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);
    }

  if (error)
    {
      gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message);
      g_clear_error (&error);

      gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
    }

  gimp_scanner_destroy (scanner);
  g_free (filename);
}
Пример #21
0
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;
}
Пример #22
0
int
main (int   argc,
      char *argv[])
{
    const gchar *gobject_marshallers[] = {
#include	"gmarshal.strings"
    };
    GScanner *scanner;
    GSList *slist, *files = NULL;
    gint i;

    /* parse args and do fast exits */
    parse_args (&argc, &argv);

    /* list input files */
    for (i = 1; i < argc; i++)
        files = g_slist_prepend (files, argv[i]);
    if (files)
        files = g_slist_reverse (files);
    else
        files = g_slist_prepend (files, "/dev/stdin");

    /* setup auxiliary structs */
    scanner = g_scanner_new (&scanner_config_template);
    fout = stdout;
    marshallers = g_hash_table_new (g_str_hash, g_str_equal);

    /* add standard marshallers of the GObject library */
    if (std_includes)
        for (i = 0; i < G_N_ELEMENTS (gobject_marshallers); i++)
        {
            gchar *tmp = g_strdup (gobject_marshallers[i]);

            g_hash_table_insert (marshallers, tmp, tmp);
        }

    /* put out initial heading */
    g_fprintf (fout, "\n");

    if (gen_cheader && std_includes)
    {
        g_fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix);
        g_fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix);
    }

    if ((gen_cheader || gen_cbody) && std_includes)
        g_fprintf (fout, "#include\t<glib-object.h>\n\n");

    if (gen_cheader)
        g_fprintf (fout, "G_BEGIN_DECLS\n");

    /* generate necessary preprocessor directives */
    if (gen_cbody)
        put_marshal_value_getters ();

    /* process input files */
    for (slist = files; slist; slist = slist->next)
    {
        gchar *file = slist->data;
        gint fd;

        if (strcmp (file, "/dev/stdin") == 0)
            /* Mostly for Win32. This is equivalent to opening /dev/stdin */
            fd = dup (0);
        else
            fd = g_open (file, O_RDONLY, 0);

        if (fd < 0)
        {
            g_warning ("failed to open \"%s\": %s", file, g_strerror (errno));
            exit_status |= 1;
            continue;
        }

        /* set file name for error reports */
        scanner->input_name = file;

        /* parse & process file */
        g_scanner_input_file (scanner, fd);

        /* scanning loop, we parse the input until its end is reached,
         * or our sub routine came across invalid syntax
         */
        do
        {
            guint expected_token = G_TOKEN_NONE;

            switch ((guint) g_scanner_peek_next_token (scanner))
            {
            case '\n':
                /* eat newline and restart */
                g_scanner_get_next_token (scanner);
                continue;
            case G_TOKEN_EOF:
                /* done */
                break;
            default:
                /* parse and process signatures */
            {
                Signature signature = { NULL, NULL, NULL };
                GList *node;

                expected_token = parse_line (scanner, &signature);

                /* once we got a valid signature, process it */
                if (expected_token == G_TOKEN_NONE)
                    process_signature (&signature);

                /* clean up signature contents */
                g_free (signature.ploc);
                if (signature.rarg)
                    g_free (signature.rarg->keyword);
                g_free (signature.rarg);
                for (node = signature.args; node; node = node->next)
                {
                    InArgument *iarg = node->data;

                    g_free (iarg->keyword);
                    g_free (iarg);
                }
                g_list_free (signature.args);
            }
            break;
            }

            /* bail out on errors */
            if (expected_token != G_TOKEN_NONE)
            {
                g_scanner_unexp_token (scanner, expected_token, "type name", NULL, NULL, NULL, TRUE);
                exit_status |= 1;
                break;
            }

            g_scanner_peek_next_token (scanner);
        }
        while (scanner->next_token != G_TOKEN_EOF);

        close (fd);
    }

    /* put out trailer */
    if (gen_cheader)
    {
        g_fprintf (fout, "\nG_END_DECLS\n");

        if (std_includes)
            g_fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix);
    }
    g_fprintf (fout, "\n");

    /* clean up */
    g_slist_free (files);
    g_scanner_destroy (scanner);
    g_hash_table_foreach_remove (marshallers, string_key_destroy, NULL);
    g_hash_table_destroy (marshallers);

    return exit_status;
}
Пример #23
0
/* Parse selector */
static GTokenType _xfdashboard_css_selector_parse_css_simple_selector(XfdashboardCssSelector *self,
																		GScanner *inScanner,
																		XfdashboardCssSelectorRule *ioRule)
{
	GTokenType		token;

	g_return_val_if_fail(XFDASHBOARD_IS_CSS_SELECTOR(self), G_TOKEN_ERROR);
	g_return_val_if_fail(inScanner, G_TOKEN_ERROR);
	g_return_val_if_fail(ioRule, G_TOKEN_ERROR);

	/* Parse type of selector. It is optional as '*' can be used as wildcard */
	token=g_scanner_peek_next_token(inScanner);
	switch((guint)token)
	{
		case '*':
			g_scanner_get_next_token(inScanner);
			ioRule->type=g_strdup("*");

			/* Check if next token follows directly after this identifier.
			 * It is determined by checking if scanner needs to move more than
			 * one (the next) character. If there is a gap then either a new
			 * selector follows or it is a new typeless selector.
			 */
			token=g_scanner_peek_next_token(inScanner);
			if(inScanner->next_line==g_scanner_cur_line(inScanner) &&
				(inScanner->next_position-g_scanner_cur_position(inScanner))>1)
			{
				return(G_TOKEN_NONE);
			}
			break;

		case G_TOKEN_IDENTIFIER:
			g_scanner_get_next_token(inScanner);
			ioRule->type=g_strdup(inScanner->value.v_identifier);

			/* Check if next token follows directly after this identifier.
			 * It is determined by checking if scanner needs to move more than
			 * one (the next) character. If there is a gap then either a new
			 * selector follows or it is a new typeless selector.
			 */
			token=g_scanner_peek_next_token(inScanner);
			if(inScanner->next_line==g_scanner_cur_line(inScanner) &&
				(inScanner->next_position-g_scanner_cur_position(inScanner))>1)
			{
				return(G_TOKEN_NONE);
			}
			break;

		default:
			break;
	}

	/* Here we look for '#', '.' or ':' and return if we find anything else */
	token=g_scanner_peek_next_token(inScanner);
	while(token!=G_TOKEN_NONE)
	{
		switch((guint)token)
		{
			/* Parse ID */
			case '#':
				g_scanner_get_next_token(inScanner);
				token=g_scanner_get_next_token(inScanner);
				if(token!=G_TOKEN_IDENTIFIER)
				{
					g_scanner_unexp_token(inScanner,
											G_TOKEN_IDENTIFIER,
											NULL,
											NULL,
											NULL,
											_("Invalid name identifier"),
											TRUE);
					return(G_TOKEN_ERROR);
				}

				ioRule->id=g_strdup(inScanner->value.v_identifier);
				break;

			/* Parse class */
			case '.':
				g_scanner_get_next_token(inScanner);
				token=g_scanner_get_next_token(inScanner);
				if(token!=G_TOKEN_IDENTIFIER)
				{
					g_scanner_unexp_token(inScanner,
											G_TOKEN_IDENTIFIER,
											NULL,
											NULL,
											NULL,
											_("Invalid class identifier"),
											TRUE);
					return(G_TOKEN_ERROR);
				}

				if(ioRule->classes)
				{
					/* Remember old classes as it can only be freed afterwards */
					gchar		*oldClasses=ioRule->classes;

					/* Create new list of classes */
					ioRule->classes=g_strconcat(ioRule->classes,
												".",
												inScanner->value.v_identifier,
												NULL);

					/* Now free old classes */
					g_free(oldClasses);
				}
					else
					{
						ioRule->classes=g_strdup(inScanner->value.v_identifier);
					}
				break;

			/* Parse pseudo-class */
			case ':':
				g_scanner_get_next_token(inScanner);
				token=g_scanner_get_next_token(inScanner);
				if(token!=G_TOKEN_IDENTIFIER)
				{
					g_scanner_unexp_token(inScanner,
											G_TOKEN_IDENTIFIER,
											NULL,
											NULL,
											NULL,
											_("Invalid pseudo-class identifier"),
											TRUE);
					return(G_TOKEN_ERROR);
				}

				if(ioRule->pseudoClasses)
				{
					/* Remember old pseudo-classes as it can only be freed afterwards */
					gchar		*oldPseudoClasses=ioRule->pseudoClasses;

					/* Create new list of pseudo-classes */
					ioRule->pseudoClasses=g_strconcat(ioRule->pseudoClasses,
														":",
														inScanner->value.v_identifier,
														NULL);

					/* Now free old pseudo-classes */
					g_free(oldPseudoClasses);
				}
					else
					{
						ioRule->pseudoClasses=g_strdup(inScanner->value.v_identifier);
					}
				break;

			default:
				return(G_TOKEN_NONE);
		}

		/* Get next token */
		token=g_scanner_peek_next_token(inScanner);
	}

	/* Successfully parsed */
	return(G_TOKEN_NONE);
}
Пример #24
0
void
gimp_unitrc_load (Gimp *gimp)
{
  GFile      *file;
  GScanner   *scanner;
  GTokenType  token;
  GError     *error = NULL;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  file = gimp_directory_file ("unitrc", NULL);

  if (gimp->be_verbose)
    g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));

  scanner = gimp_scanner_new_gfile (file, &error);

  if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
    {
      g_clear_error (&error);
      g_object_unref (file);

      file = gimp_sysconf_directory_file ("unitrc", NULL);

      scanner = gimp_scanner_new_gfile (file, NULL);
    }

  if (! scanner)
    {
      g_clear_error (&error);
      g_object_unref (file);
      return;
    }

  g_scanner_scope_add_symbol (scanner, 0,
                              "unit-info", GINT_TO_POINTER (UNIT_INFO));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "factor", GINT_TO_POINTER (UNIT_FACTOR));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "digits", GINT_TO_POINTER (UNIT_DIGITS));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "symbol", GINT_TO_POINTER (UNIT_SYMBOL));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "abbreviation", GINT_TO_POINTER (UNIT_ABBREV));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "singular", GINT_TO_POINTER (UNIT_SINGULAR));
  g_scanner_scope_add_symbol (scanner, UNIT_INFO,
                              "plural", GINT_TO_POINTER (UNIT_PLURAL));

  token = G_TOKEN_LEFT_PAREN;

  while (g_scanner_peek_next_token (scanner) == token)
    {
      token = g_scanner_get_next_token (scanner);

      switch (token)
        {
        case G_TOKEN_LEFT_PAREN:
          token = G_TOKEN_SYMBOL;
          break;

        case G_TOKEN_SYMBOL:
          if (scanner->value.v_symbol == GINT_TO_POINTER (UNIT_INFO))
            {
              g_scanner_set_scope (scanner, UNIT_INFO);
              token = gimp_unitrc_unit_info_deserialize (scanner, gimp);

              if (token == G_TOKEN_RIGHT_PAREN)
                g_scanner_set_scope (scanner, 0);
            }
          break;

        case G_TOKEN_RIGHT_PAREN:
          token = G_TOKEN_LEFT_PAREN;
          break;

        default: /* do nothing */
          break;
        }
    }

  if (token != G_TOKEN_LEFT_PAREN)
    {
      g_scanner_get_next_token (scanner);
      g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
                             _("fatal parse error"), TRUE);

      gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
      g_clear_error (&error);

      gimp_config_file_backup_on_error (file, "unitrc", NULL);
    }

  gimp_scanner_destroy (scanner);
  g_object_unref (file);
}
Пример #25
0
static GTokenType _xfdashboard_css_selector_parse_css_rule(XfdashboardCssSelector *self,
															GScanner *inScanner)
{
	XfdashboardCssSelectorPrivate	*priv;
	GTokenType						token;
	XfdashboardCssSelectorRule		*rule, *parentRule;

	g_return_val_if_fail(XFDASHBOARD_IS_CSS_SELECTOR(self), G_TOKEN_ERROR);
	g_return_val_if_fail(inScanner, G_TOKEN_ERROR);

	priv=self->priv;

	/* Parse comma-seperated selectors until a left curly bracket is found */
	parentRule=NULL;
	rule=NULL;

	token=g_scanner_peek_next_token(inScanner);
	while(token!=G_TOKEN_EOF)
	{
		switch((guint)token)
		{
			case G_TOKEN_IDENTIFIER:
			case '*':
			case '#':
			case '.':
			case ':':
				/* Set last selector as parent if available */
				if(rule) parentRule=rule;
					else parentRule=NULL;

				/* Create new selector */
				rule=_xfdashboard_css_selector_rule_new(inScanner->input_name,
														priv->priority,
														g_scanner_cur_line(inScanner),
														g_scanner_cur_position(inScanner));
				priv->rule=rule;

				/* Check if there was a previous selector and if so, the new one
				 * should use the previous selector to match an ancestor
				 */
				if(parentRule)
				{
					rule->parentRule=parentRule;
					rule->parentRuleMode=XFDASHBOARD_CSS_SELECTOR_RULE_MODE_ANCESTOR;
				}

				/* Parse selector */
				token=_xfdashboard_css_selector_parse_css_simple_selector(self, inScanner, rule);
				if(token!=G_TOKEN_NONE) return(token);
				break;

			case '>':
				g_scanner_get_next_token(inScanner);

				/* Set last selector as parent selector */
				if(!rule)
				{
					g_scanner_unexp_token(inScanner,
											G_TOKEN_IDENTIFIER,
											NULL,
											NULL,
											NULL,
											_("No parent when parsing '>'"),
											TRUE);
					return(G_TOKEN_ERROR);
				}
				parentRule=rule;

				/* Create new selector */
				rule=_xfdashboard_css_selector_rule_new(inScanner->input_name,
														priv->priority,
														g_scanner_cur_line(inScanner),
														g_scanner_cur_position(inScanner));
				priv->rule=rule;

				/* Link parent to the new selector as parent selector */
				rule->parentRule=parentRule;
				rule->parentRuleMode=XFDASHBOARD_CSS_SELECTOR_RULE_MODE_PARENT;


				/* Parse selector */
				token=_xfdashboard_css_selector_parse_css_simple_selector(self, inScanner, rule);
				if(token!=G_TOKEN_NONE) return(token);
				break;

			default:
				/* Stop at first invalid character in stream and
				 * return with success result.
				 */
				return(G_TOKEN_NONE);
		}

		/* Continue parsing with next token */
		token=g_scanner_peek_next_token(inScanner);
	}

	/* Eat "eof" token */
	if(token==G_TOKEN_EOF) token=g_scanner_get_next_token(inScanner);

	/* Successfully parsed */
	return(G_TOKEN_EOF);
}