Hi, I am new to GTK+ and I am using it to develop a little GUI app to
download some data through the parallel port of a pc.
I am using the WIN 32 libraries with Visual C++ 6.0 and so far so good for
the GUI part.
Now I am trying to use the GScanner from GLIB  to parse my data and it is
working fine if I use a variable containing the text to parse.
The problem I have it's when I try to set-up the scanner to use a text file
This what I have done and I am getting the following message " test text:1:
error: unexpected end of file, expected symbol "
Can someone help me?

Thank you!

St�phan Meszaros
E-mail: [EMAIL PROTECTED]

scanner_test.c
/* This code is based on the example from the FAQ section 8 */
/* define enumeration values to be returned for specific symbols */
enum {
  SYMBOL_MODULE = G_TOKEN_LAST + 1,
  SYMBOL_COMPONENT = G_TOKEN_LAST + 2,
  SYMBOL_START_ADDRESS = G_TOKEN_LAST + 3,
  SYMBOL_DATA = G_TOKEN_LAST + 4,
};

/* symbol array */
static const struct {
  gchar *symbol_name;
  guint  symbol_token;
} symbols[] = {
  { "module", SYMBOL_MODULE, },
  { "component", SYMBOL_COMPONENT, },
  { "start_address", SYMBOL_START_ADDRESS, },
  { "data", SYMBOL_DATA, },
  { NULL, 0, },
}, *symbol_p = symbols;

int
main (int argc, char *argv[])
{
  GScanner *scanner;
  guint expected_token;
  gint fh;
  FILE *stream;
  char inbuf[128];
  gint count = 0;

  /* Open a file handle. */
  fh = _open( "parse_it.txt", _O_TEXT );
  scanner = g_scanner_new (NULL);
  g_scanner_input_file(scanner,fh);
  g_scanner_sync_file_offset(scanner);
  scanner->config->symbol_2_token = TRUE;
          
   /* load symbols into the scanner */
  while (symbol_p->symbol_name)
  {
          g_scanner_add_symbol (scanner,
                            symbol_p->symbol_name,
                            GINT_TO_POINTER (symbol_p->symbol_token));
      symbol_p++;
  }

  /* feed in the text */
  //g_scanner_input_text (scanner, test_text, strlen (test_text));

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

  /* scanning loop, we parse the input untill it's end is reached,
   * the scanner encountered a lexing error, or our sub routine came
   * across invalid syntax
   */
  do
    {
      /*parse_symbol is my parsing function*/
      expected_token = parse_symbol (scanner);
      
      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);

  /* finsish parsing */
  g_scanner_destroy (scanner);
  _close( fh );

  return 0;
}

-- 
To unsubscribe: mail -s unsubscribe [EMAIL PROTECTED] < /dev/null

Reply via email to