Ejemplo n.º 1
0
static void player_filter_load_patterns (void) {
  char *fn;
  int fd;
  GScanner *scanner;
  int retval;
  int i;

  fn = file_in_dir (user_rcdir, PLAYERS_FILE);
  fd = open (fn, O_RDONLY);

  if (fd < 0) {
    g_free (fn);
    return;
  }

  scanner = g_scanner_new (&patterns_scanner_config);

  for (i = TOKEN_STRING; i <= TOKEN_REGEXP; i++) {
    g_scanner_add_symbol (scanner, mode_symbols[i - TOKEN_STRING], 
                                                                GINT_TO_POINTER(i));
  }

  g_scanner_input_file (scanner, fd);

  do {
    retval = player_pattern_parse_statement (scanner, fn);
  } while (retval);

  g_scanner_destroy (scanner);
  g_free (fn);
  close (fd);

  if (filters[FILTER_PLAYER].changed != FILTER_NOT_CHANGED)
    filters[FILTER_PLAYER].last_changed = filter_time_inc();
}
Ejemplo n.º 2
0
/**
 * gtk_accel_map_load_fd:
 * @fd: a valid readable file descriptor
 *
 * Filedescriptor variant of gtk_accel_map_load().
 *
 * Note that the file descriptor will not be closed by this function.
 */
void
gtk_accel_map_load_fd (gint fd)
{
  GScanner *scanner;

  g_return_if_fail (fd >= 0);

  /* create and setup scanner */
  scanner = g_scanner_new (NULL);
  g_scanner_input_file (scanner, fd);

  gtk_accel_map_load_scanner (scanner);

  g_scanner_destroy (scanner);
}
Ejemplo n.º 3
0
/*
 * static JConfig *j_config_parse_any(JConfigCtxt *cfc,
 *                                    const gchar *input_name,
 *                                    gint input_fd,
 *                                    const gchar *input_string,
 *                                    gint input_len)
 *                                 
 * The real initial parsing routine.
 * Creates the JConfig and structures and then
 * calls j_config_parse_base();
 *                                                                 
 * some of this is ripped from gtkrc.c
 */
static JConfig *j_config_parse_any(JConfigCtxt *cfc,
                                   const gchar *input_name,
                                   gint input_fd,
                                   const gchar *input_string,
                                   gint input_len)
{
    GScanner *scanner;
    
    scanner = g_scanner_new((GScannerConfig *)&test_config);
    
    if (input_fd >= 0)
    {
        g_assert(input_string == NULL);
        g_scanner_input_file(scanner, input_fd);
    }
    else
    {
        g_assert(input_string != NULL);
        g_assert(input_len >= 0);
        g_scanner_input_text(scanner, input_string, input_len);
    }
    scanner->input_name = input_name;
    
    cfc->cf = j_config_config_new();
    if (cfc->cf == NULL)
    {
        if (cfc->verbose)
        {
            g_warning("Unable to create a JConfig structure: %s\n",
                      g_strerror(errno));
        }
        cfc->error = TRUE;
        return(NULL);
    }

    cfc->cf->filename = g_strdup(input_name);
    j_config_parse_base(scanner, cfc);
    
    g_scanner_destroy(scanner);
    
    return(cfc->cf);
}  /* j_config_parse_any() */
Ejemplo n.º 4
0
/*
Creates a GScanner to parse the given file. Configures the Scanner to find all whole words.
@param {char *} filename - path of the file to parse
@returns {GScanner *} - pointer to the GScanner struct
*/
GScanner* make_scanner(char* filename){
  int fd = g_open(filename, O_RDONLY, NULL);
  if (fd == -1){
    g_printf("Error occur while opening %s\n.", filename);
    exit(1);
  }
  GScanner* scanner = g_scanner_new(NULL);
  if (scanner == NULL) {
    g_printf("Scanner not created, allocation failed.\n");
    exit(1);
  }
  scanner->input_name = filename;
  g_scanner_input_file(scanner, fd);
  scanner->config->scan_identifier_1char = 1;
  scanner->config->cset_skip_characters = " \t\r\n\"'?.-()!";
  scanner->config->cset_identifier_first = G_CSET_a_2_z G_CSET_A_2_Z;
  scanner->config->cset_identifier_nth = G_CSET_a_2_z G_CSET_A_2_Z;
  scanner->config->scan_string_sq = 0;
  scanner->config->scan_string_dq = 0;
  return scanner;
}
Ejemplo n.º 5
0
void test_parse_rcp(void)
{
	GScanner *scan;
	FILE *fp;
	GTokenType tok;

	fp = fopen("test.rcp", "r");
	if (fp == NULL) {
		err_printf("cannot open test.rcp\n");
		return;
	}

	scan = init_scanner();
	g_scanner_input_file(scan, fileno(fp));
	do {
		tok = g_scanner_get_next_token(scan);
		print_token(scan, tok);
	} while (tok != G_TOKEN_EOF);
	g_scanner_destroy(scan);

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

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

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

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

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

  return name;
}
Ejemplo n.º 9
0
Archivo: prefs.c Proyecto: dimkr/dillo
static gint Prefs_load(void)
{
   GScanner *scanner;
   gint fd;
   guint i, expected_token;
   gchar *file;

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

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

   scanner = g_scanner_new(NULL);

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

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

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

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

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

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

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

   /* finish parsing */
   g_scanner_destroy(scanner);
   close(fd);
   return PARSE_OK;
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
/* read a star file frame (one s-expression) from the given file pointer,
   and return the stf of the root node */
struct stf *stf_read_frame(FILE *fp)
{
	GScanner *scan;
	GTokenType tok;
	int level = 0;
	int minus = 0;
	GList *sl;
	struct stf *ret = NULL;
	struct stf *lstf[STF_MAX_DEPTH];
	struct stf *stf=NULL, *nstf = NULL;

	lstf[0] = NULL;
	scan = init_scanner();
	g_scanner_input_file(scan, fileno(fp));
	do {
		tok = g_scanner_get_next_token(scan);
//		d3_printf("level %d ", level);
//		print_token(scan, tok);
		if (level == 0 && tok != '(')
			continue;
		if (level == 1 && tok == ')') {
			ret = lstf[0];
			break;
		}
		if (minus)
			minus --;
		switch(tok) {
		case '(':
			if (level >= STF_MAX_DEPTH - 1)
				break;
			nstf = stf_new();
			lstf[level] = nstf;
			if (level > 0) {
				stf->next = nstf;
				STF_SET_LIST(nstf, stf_new());
				stf = STF_LIST(nstf);
			} else {
				stf = nstf;
			}
			level ++;
			break;
		case ')':
			stf = lstf[level-1];
			level --;
			break;
		case G_TOKEN_SYMBOL:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_SYMBOL(stf, intval(scan));
			if (intval(scan) == SYM_STARS) {
				sl = read_star_list(scan);
				if (sl == NULL)
					break;
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
				STF_SET_GLIST(stf, sl);
			}
			break;
		case '-':
			minus = 2;
			break;
		case G_TOKEN_FLOAT:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_DOUBLE(stf, minus?-floatval(scan):floatval(scan));
			break;
		case G_TOKEN_STRING:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_STRING(stf, strdup(stringval(scan)));
			break;
		case G_TOKEN_IDENTIFIER:
			err_printf("unexpected identifier: %s\n", stringval(scan));
//			if (!STF_IS_NIL(stf)) {
//				nstf = stf_new();
//				stf->next = nstf;
//				stf = nstf;
//			}
//			STF_SET_IDENT(stf, strdup(stringval(scan)));
//			break;
		default:
			err_printf("unexected token %d\n", tok);
			break;
		}
	} while (tok != G_TOKEN_EOF);
	g_scanner_sync_file_offset(scan);
	g_scanner_destroy(scan);
	return ret;
}
Ejemplo n.º 12
0
GPtrArray *
read_langconf_from (gchar *filename)
{
    GScanner *scanner;
    GTokenType ttype;
    gint fd;
    struct langconf *conf = NULL;
    enum parser_state state;
    GPtrArray *lang_conf;
    gboolean error_occured = FALSE;

    fd = open (filename, O_RDONLY);
    if (fd < 0)
    {
        /*g_printf ("%s: couldn't open\n", filename);*/
        return NULL;
    }

    state = PARSER_INIT;
    lang_conf = g_ptr_array_new ();

    scanner = g_scanner_new (&scanner_conf);
/*    scanner = g_scanner_new (NULL);*/
    g_scanner_input_file (scanner, fd);
    scanner->input_name = filename;

   for (ttype = g_scanner_get_next_token (scanner);
             ttype != G_TOKEN_EOF;
             ttype = g_scanner_get_next_token (scanner))
    {
        gint line = g_scanner_cur_line (scanner);
        /* guint pos = g_scanner_cur_position (scanner);*/
        error_occured = FALSE;

        if(state == PARSER_INIT || state == PARSER_LETTER)
        {
            if (ttype == G_TOKEN_STRING &&
                    strcmp (scanner->value.v_string, "language") == 0)
            {
                if (conf)
                {
                    g_ptr_array_add (lang_conf, conf);
                    DEBUGMSG ("lang %s added\n", conf->lang);
                }
                state = PARSER_LANG;
                conf = g_new0 (struct langconf, 1);
                conf->alphabet = g_ptr_array_new ();
                conf->weights = g_array_new (TRUE, TRUE, sizeof (gint));
                continue;
            }
            else if (state == PARSER_INIT)
            {
                LANGCONF_ERROR_MSG ("keyword language expected", filename, line);
                error_occured = TRUE;
                break;
            }
        }

        switch (state)
        {
            case PARSER_INIT:
                g_assert_not_reached ();
                break;
                   
            case PARSER_LANG:
                if (ttype != G_TOKEN_STRING)
                {
                    LANGCONF_ERROR_MSG ("language name expected after keyword language", filename, line);
                    error_occured = TRUE;
                    break;
                }
                conf->lang = g_strdup (scanner->value.v_string);
                state = PARSER_DICTFILE_KEYWORD;
                break;

            case PARSER_DICTFILE_KEYWORD:
                if (ttype != G_TOKEN_STRING || 
                    strcmp (scanner->value.v_string, "dictfile") != 0)
                {
                    LANGCONF_ERROR_MSG ("keyword \"dictfile\" expected",
                            filename, line);
                    error_occured = TRUE;
                    break;
                }
                state = PARSER_DICTFILE;
                break;

            case PARSER_DICTFILE:
                if (ttype != G_TOKEN_STRING)
                {
                    LANGCONF_ERROR_MSG ("dict filename expected", filename,
                                        line);
                    error_occured = TRUE;
                    break;
                }
                conf->dictf = g_strdup (scanner->value.v_string);
                state = PARSER_LETTER;
                break;

             case PARSER_LETTER:
                if (ttype != G_TOKEN_STRING ||
                        strlen(scanner->value.v_string) > MAX_LETTER_LENGTH)
                {
                    LANGCONF_ERROR_MSG ("letter expected", filename, line);
                    error_occured = TRUE;
                    break;
                }
                g_ptr_array_add (conf->alphabet, 
                        g_strdup (scanner->value.v_string));
                state = PARSER_WEIGHT;
                break;

            case PARSER_WEIGHT:
                if (ttype != G_TOKEN_INT)
                {
                    LANGCONF_ERROR_MSG ("number expected", filename, line);
                    error_occured = TRUE;
                    break;
                }
                g_array_append_val (conf->weights, scanner->value.v_int);
                state = PARSER_LETTER;
                break;
        }

        if (error_occured)
            break;

    } /* for get_next_token */
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
static GslWaveFileInfo*
gslwave_load_file_info (gpointer      data,
			const gchar  *_file_name,
			GslErrorType *error_p)
{
  FileInfo *fi = NULL;
  gboolean in_wave = FALSE, abort = FALSE;
  GslRing *wave_names = NULL;
  GScanner *scanner;
  gchar *cwd, *file_name;
  gint fd;
  guint i;

  if (g_path_is_absolute (_file_name))
    {
      gchar *p = strrchr (_file_name, G_DIR_SEPARATOR);

      g_assert (p != NULL);
      cwd = g_strndup (_file_name, p - _file_name + 1);
      file_name = g_strdup (_file_name);
    }
  else
    {
      cwd = g_get_current_dir ();
      file_name = g_strdup_printf ("%s%c%s", cwd, G_DIR_SEPARATOR, _file_name);
    }

  fd = open (file_name, O_RDONLY);
  if (fd < 0)
    {
      *error_p = GSL_ERROR_OPEN_FAILED;
      g_free (cwd);
      g_free (file_name);
      return NULL;
    }

  scanner = g_scanner_new (NULL);
  scanner->config->symbol_2_token = TRUE;
  g_scanner_scope_add_symbol (scanner, 0, "wave", GUINT_TO_POINTER (GSL_WAVE_TOKEN_WAVE));
  g_scanner_scope_add_symbol (scanner, 0, "name", GUINT_TO_POINTER (GSL_WAVE_TOKEN_NAME));
  g_scanner_input_file (scanner, fd);
  while (!abort)
    {
      g_scanner_get_next_token (scanner);
      switch (scanner->token)
	{
	case GSL_WAVE_TOKEN_WAVE:
	  if (g_scanner_peek_next_token (scanner) == '{')
	    {
	      g_scanner_get_next_token (scanner); /* eat '{' */
	      in_wave = TRUE;
	    }
	  break;
	case '{':
	  if (gslwave_skip_rest_statement (scanner, 1) != G_TOKEN_NONE)
	    abort = TRUE;
	  break;
	case GSL_WAVE_TOKEN_NAME:
	  if (in_wave && g_scanner_peek_next_token (scanner) == '=')
	    {
	      g_scanner_get_next_token (scanner); /* eat '=' */
	      if (g_scanner_peek_next_token (scanner) == G_TOKEN_STRING)
		{
		  gchar *wave_name;
		  
		  g_scanner_get_next_token (scanner); /* eat string */
		  wave_name = g_strdup (scanner->value.v_string);
		  if (gslwave_skip_rest_statement (scanner, 1) == G_TOKEN_NONE)
		    {
		      in_wave = FALSE;
		      wave_names = gsl_ring_append (wave_names, wave_name);
		    }
		  else
		    {
		      g_free (wave_name);
		      abort = TRUE;
		    }
		}
	    }
	  break;
	default:
	  if (scanner->token == G_TOKEN_EOF || scanner->token == G_TOKEN_ERROR)
	    abort = TRUE;
	  break;
	}
    }
  g_scanner_destroy (scanner);
  close (fd);

  if (wave_names)
    {
      GslRing *ring;

      fi = gsl_new_struct0 (FileInfo, 1);
      fi->wfi.n_waves = gsl_ring_length (wave_names);
      fi->wfi.waves = g_malloc0 (sizeof (fi->wfi.waves[0]) * fi->wfi.n_waves);
      for (i = 0, ring = wave_names; i < fi->wfi.n_waves; i++, ring = ring->next)
	fi->wfi.waves[i].name = ring->data;
      gsl_ring_free (wave_names);
      fi->cwd = cwd;
    }
  else
    g_free (cwd);
  g_free (file_name);

  /* FIXME: empty wave error? */

  return fi ? &fi->wfi : NULL;
}
Ejemplo n.º 15
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);
}