コード例 #1
0
ファイル: cache.c プロジェクト: jspd-group/pegit
void close_cache_file(struct cache *c)
{
    if (c->flushed) {
        fclose(c->cachefile);
        return;
    }
    write_cache_file(c);
}
コード例 #2
0
ファイル: ipdb.c プロジェクト: elkatwork/geoipdb
IPDB * init_db(char * cities_csv_file, char * ranges_csv_file, char * cache_file_name){
  if(DEBUG)
    printf("Initializing db");
  IPDB *db;
  db = (IPDB*)malloc(sizeof(IPDB));
  if (db == NULL) //no memory left
    return NULL;
  db->cities = NULL;
  db->ranges = NULL;
  db->cache_file_name = cache_file_name;

  db->cities_csv_file = cities_csv_file;
  db->max_cities_count = MAX_CITIES_COUNT;
  db->ranges_csv_file = ranges_csv_file;
  db->max_ranges_count = MAX_RANGES_COUNT;

  db->isps_count = 0;

  if(USE_CACHE && read_cache_file(db) > 0){
    if(DEBUG)
      printf("Loaded DB from Cache-File with %i records \n", db->ranges_count);
  }else{
    if(DEBUG)
      printf("Initializing IPDB from CSV-file: %s \n", db->ranges_csv_file);
    read_cities_csv(db);
    if(db->cities_count == 0)
    {
      return NULL;
    }
    sort_cities(db);
    read_ranges_csv(db);
    if(db!=NULL && db->ranges_count > 0 && USE_CACHE)
    {
      if(DEBUG)
        printf("Got %i records from CSV-file, writing to cache...\n", db->ranges_count);
      write_cache_file(db);
    }
  }
  return db;
}
コード例 #3
0
int	main(int argc, char *argv[])
{
	assert(tu_types_validate());

	array<const char*> infiles;

	for (int arg = 1; arg < argc; arg++)
	{
		if (argv[arg][0] == '-')
		{
			// Looks like an option.

			if (argv[arg][1] == 'h')
			{
				// Help.
				print_usage();
				exit(1);
			}
			else if (argv[arg][1] == 'w')
			{
				// Write cache files.
				s_do_output = true;
			}
			else if (argv[arg][1] == 'v')
			{
				// Be verbose; i.e. print log messages to stdout.
				s_verbose = true;

				if (argv[arg][2] == 'a')
				{
					// Enable spew re: action.
					gameswf::set_verbose_action(true);
				}
				else if (argv[arg][2] == 'p')
				{
					// Enable parse spew.
					gameswf::set_verbose_parse(true);
				}
				// ...
			}
		}
		else
		{
			infiles.push_back(argv[arg]);
		}
	}

	if (infiles.size() == 0)
	{
		printf("no input files\n");
		print_usage();
		exit(1);
	}
	gameswf::gc_ptr<gameswf::player> player = new gameswf::player();
	gameswf::register_file_opener_callback(file_opener);
	gameswf::register_log_callback(log_callback);
	gameswf::set_use_cache_files(false);	// don't load old cache files!

	array<movie_data>	data;

	// Play through all the movies.
	for (int i = 0, n = infiles.size(); i < n; i++)
	{
		gameswf::movie_definition*	m = play_movie(player.get_ptr(), infiles[i]);
		if (m == NULL)
		{
			if (s_stop_on_errors)
			{
				// Fail.
				fprintf(stderr, "error playing through movie '%s', quitting\n", infiles[i]);
				exit(1);
			}
		}
		
		movie_data	md;
		md.m_movie = m;
		md.m_filename = infiles[i];
		data.push_back(md);
	}

	// Now append processed data.
	if (s_do_output)
	{
		for (int i = 0, n = data.size(); i < n; i++)
		{
			int	error = write_cache_file(data[i]);
			if (error)
			{
				if (s_stop_on_errors)
				{
					// Fail.
					fprintf(stderr, "error processing movie '%s', quitting\n", data[i].m_filename.c_str());
					exit(1);
				}
			}
		}
	}

	return 0;
}
コード例 #4
0
ファイル: cache.c プロジェクト: jspd-group/pegit
void cache_object_write(struct cache_object *co)
{
    write_cache_file(&co->cc);
    write_index_file(&co->ci);
}