当前位置: 首页>>代码示例>>C++>>正文


C++ cfopen函数代码示例

本文整理汇总了C++中cfopen函数的典型用法代码示例。如果您正苦于以下问题:C++ cfopen函数的具体用法?C++ cfopen怎么用?C++ cfopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cfopen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cfopen

/*
 * Open a file for reading. 'path' is the file to open, and 'mode' should
 * be either "r" or "rb".
 *
 * If the file at 'path' does not exist, we append the ".gz" suffix (if 'path'
 * doesn't already have it) and try again. So if you pass "foo" as 'path',
 * this will open either "foo" or "foo.gz".
 */
cfp *cfopen_read(const char *path, const char *mode)
{
	cfp *fp;

#ifdef HAVE_LIBZ
	if (hasSuffix(path, ".gz"))
		fp = cfopen(path, mode, 1);
	else
#endif
	{
		fp = cfopen(path, mode, 0);
#ifdef HAVE_LIBZ
		if (fp == NULL) {
			int fnamelen = strlen(path) + 4;
			char *fname = malloc(fnamelen);

			if (fname == NULL)
				die_horribly(NULL, modulename,
					     "Out of memory\n");

			snprintf(fname, fnamelen, "%s%s", path, ".gz");
			fp = cfopen(fname, mode, 1);
			free(fname);
		}
#endif
	}
	return fp;
}
开发者ID:colinet,项目名称:sqlix,代码行数:36,代码来源:compress.c

示例2: cfopen_read

/*
 * Open a file for reading. 'path' is the file to open, and 'mode' should
 * be either "r" or "rb".
 *
 * If the file at 'path' does not exist, we append the ".gz" suffix (if 'path'
 * doesn't already have it) and try again. So if you pass "foo" as 'path',
 * this will open either "foo" or "foo.gz".
 */
cfp *
cfopen_read(const char *path, const char *mode)
{
	cfp		   *fp;

#ifdef HAVE_LIBZ
	if (hasSuffix(path, ".gz"))
		fp = cfopen(path, mode, 1);
	else
#endif
	{
		fp = cfopen(path, mode, 0);
#ifdef HAVE_LIBZ
		if (fp == NULL)
		{
			char	   *fname;

			fname = psprintf("%s.gz", path);
			fp = cfopen(fname, mode, 1);
			free(fname);
		}
#endif
	}
	return fp;
}
开发者ID:nabeelh,项目名称:postgres,代码行数:33,代码来源:compress_io.c

示例3: cache_program_binary

static void cache_program_binary(GLuint program, const SCP_string& hash) {
	if (!do_shader_caching()) {
		return;
	}
	
	GR_DEBUG_SCOPE("Saving shader binary");

	GLint size;
	glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &size);

	if (size <= 0) {
		// No binary available (I'm looking at you Mesa...)
		return;
	}

	SCP_vector<uint8_t> binary;
	binary.resize((size_t) size);
	GLenum binary_fmt;
	GLsizei length;
	glGetProgramBinary(program, (GLsizei) binary.size(), &length, &binary_fmt, binary.data());
	if (length == 0) {
		return;
	}

	auto base_filename = SCP_string("ogl_shader-") + hash;

	auto metadata_name = base_filename + ".json";
	auto binary_name = base_filename + ".bin";

	auto metadata_fp = cfopen(metadata_name.c_str(), "wb", CFILE_NORMAL, CF_TYPE_CACHE, false,
	                          CF_LOCATION_ROOT_USER | CF_LOCATION_ROOT_GAME | CF_LOCATION_TYPE_ROOT);
	if (!metadata_fp) {
		mprintf(("Could not open shader cache metadata file!\n"));
		return;
	}

	auto metadata = json_pack("{sI}", "format", (json_int_t)binary_fmt);
	if (json_dump_callback(metadata, json_write_callback, metadata_fp, 0) != 0) {
		mprintf(("Failed to write shader cache metadata file!\n"));
		cfclose(metadata_fp);
		return;
	}
	cfclose(metadata_fp);
	json_decref(metadata);

	auto binary_fp = cfopen(binary_name.c_str(), "wb", CFILE_NORMAL, CF_TYPE_CACHE, false,
	                        CF_LOCATION_ROOT_USER | CF_LOCATION_ROOT_GAME | CF_LOCATION_TYPE_ROOT);
	if (!binary_fp) {
		mprintf(("Could not open shader cache binary file!\n"));
		return;
	}
	cfwrite(binary.data(), 1, (int) binary.size(), binary_fp);
	cfclose(binary_fp);
}
开发者ID:DahBlount,项目名称:fs2open.github.com,代码行数:54,代码来源:gropenglshader.cpp

示例4: gr_use_palette_table

void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,fsize;
#ifdef SWAP_0_255
	ubyte c;
#endif

	fp = cfopen( filename, "rb" );

	// the following is a hack to enable the loading of d2 levels
	// even if only the d2 mac shareware datafiles are present.
	// However, if the pig file is present but the palette file isn't,
	// the textures in the level will look wierd...
	if ( fp==NULL)
		fp = cfopen( DEFAULT_LEVEL_PALETTE, "rb" );
	if ( fp==NULL)
		Error("Can open neither palette file <%s> "
		      "nor default palette file <"
		      DEFAULT_LEVEL_PALETTE
		      ">.\n",
		      filename);

	fsize	= cfilelength( fp );
	Assert( fsize == 9472 );
	cfread( gr_palette, 256*3, 1, fp );
	cfread( gr_fade_table, 256*34, 1, fp );
	cfclose(fp);

	// This is the TRANSPARENCY COLOR
	for (i=0; i<GR_FADE_LEVELS; i++ )	{
		gr_fade_table[i*256+255] = 255;
	}

	Num_computed_colors = 0;	//	Flush palette cache.
// swap colors 0 and 255 of the palette along with fade table entries

#ifdef SWAP_0_255
	for (i = 0; i < 3; i++) {
		c = gr_palette[i];
		gr_palette[i] = gr_palette[765+i];
		gr_palette[765+i] = c;
	}

	for (i = 0; i < GR_FADE_LEVELS * 256; i++) {
		if (gr_fade_table[i] == 0)
			gr_fade_table[i] = 255;
	}
	for (i=0; i<GR_FADE_LEVELS; i++)
		gr_fade_table[i*256] = TRANSPARENCY_COLOR;
#endif
}
开发者ID:btb,项目名称:d2x,代码行数:52,代码来源:palette.c

示例5: ExportSolarFrequency

int ExportSolarFrequency (void)
{
  char mkrname[NAMESIZE], tempstr[NAMESIZE];
  int i, j;
  

  // Makes the frequency file
  cfopen ("solar.frq", "w");

  for (i = 1; i<=numberofmarkers(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);

    CopyAlleleFreq(order[i]);

    fprintf(F, "%-18s  ", mkrname);
    for (j=1; j<= NumberOfAlleles(order[i]); j++)
      fprintf(F, "%2d %5.3f  ", j, allelefreq[j]);

    fprintf(F, "\n");
  }

  fclose(F);

  puts("Made Solar frequency file");
  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:29,代码来源:fileio.c

示例6: fs2netd_add_table_validation

void fs2netd_add_table_validation(char *tblname)
{
	uint chksum = 0;

	// if the tbl name isn't valid then just assume that the tbl is too
	if ( (tblname == NULL) || !strlen(tblname) ) {
		return;
	}

	CFILE *tbl = cfopen(tblname, "rt", CFILE_NORMAL, CF_TYPE_TABLES);

	if (tbl == NULL) {
		return;
	}

	cf_chksum_long(tbl, &chksum);

	cfclose(tbl);

	crc_valid_status tbl_crc;

	strncpy(tbl_crc.name, tblname, NAME_LENGTH);
	tbl_crc.crc32 = chksum;
	tbl_crc.valid = 0;

	Table_valid_status.push_back( tbl_crc );
}
开发者ID:n-kawamt,项目名称:fs2open_snapshot,代码行数:27,代码来源:fs2netd_client.cpp

示例7: fs2netd_player_banned

bool fs2netd_player_banned(net_addr *addr)
{
	if ( !Logged_in ) {
		return false;
	}

	char line[32]; // no line should be larger than 16, but let's be safe
	char ip_str[32];
	memset(ip_str, 0, 32);
	memset(line, 0, 32);

	bool retval = false;
	CFILE *banlist_cfg = cfopen("banlist.cfg", "rt", CFILE_NORMAL, CF_TYPE_DATA);

	if (banlist_cfg == NULL) {
		return false;
	}

	psnet_addr_to_string( ip_str, addr );

	while ( !cfeof(banlist_cfg) && !retval ) {
		cfgets(line, 32, banlist_cfg);

		if ( !strnicmp(ip_str, line, strlen(line)) ) {
			retval = true; // BANNINATED!!!
		}
	}

	cfclose(banlist_cfg);

	return retval;
}
开发者ID:n-kawamt,项目名称:fs2open_snapshot,代码行数:32,代码来源:fs2netd_client.cpp

示例8: ExportMerlinFreq

int ExportMerlinFreq (void) {
  int i, k;
  FreqList *fl;
  char mkrname[NAMESIZE], tempstr[NAMESIZE];

  cfopen ("merlin.freq", "w");

  for (i = 1; i<=numberofmarkers(); i++) {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);
    fprintf(F, "M %s\nF ", mkrname);

    fl = FrequencyNumber(i);
    for (k=1; k<= fl->num_alleles; k++)
      fprintf(F, "%-6.4f ",fl->frequency[k]);
    fprintf(F, "\n");
  }

  fclose(F);
  puts("Made Merlin frequency file");
  

  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:25,代码来源:fileio.c

示例9: ExportMerlinMap

int ExportMerlinMap (void)
{
  char mkrname[NAMESIZE], tempstr[NAMESIZE];
  int i;
  double currentpos;

  printf("Which chromosome is this: ");
  InputLine(buf, BUFFERSIZE);

  currentpos = 0;
  // Makes the marker file
  cfopen ("merlin.map", "w");
  fprintf(F, "CHROMOSOME   MARKER          LOCATION\n");
  for (i = 1; i<=numberofmarkers(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);

    fprintf(F, "%-5s  %-18s  %f\n", buf, mkrname, MarkerDistance(0,i));
  }
  fclose(F);
  puts("Made Merlin map file");
  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:25,代码来源:fileio.c

示例10: ExportMerlinDataFile

int ExportMerlinDataFile ()
{
  int i;
  char mkrname[NAMESIZE], tempstr[NAMESIZE];

  // Makes pedigree file
  cfopen ("merlin.dat", "w");


  for (i = 1; i<=numberofmarkers(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);
    fprintf(F, "M %s\n", mkrname);
  }

  for (i = 1; i<=numberoftraits(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(traitnames, i));
    strncpy(mkrname, tempstr, 18);

    fprintf(F, "T %s\n", mkrname);
  }


  fclose(F);
  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:30,代码来源:fileio.c

示例11: ExportSolarMarker

int ExportSolarMarker (individual *indlist)
{
  individual *ind;
  markerlist *marker;
  char mkrname[NAMESIZE], tempstr[NAMESIZE];
  int i;
  

  // Makes the marker file
  cfopen ("solar.mkr", "w");
  fprintf(F, "id");
  for (i = 1; i<=numberofmarkers(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);
    fprintf(F, ",%s", mkrname);
  }
  fprintf(F, "\n");

  for (ind = indlist; ind; ind = ind->next)
  {
    fprintf(F, "%s", ind->id);
    for (i = 1; i<=numberofmarkers(); i++)
    {
      marker = markernumber(ind, order[i]);
      fprintf(F, ",%d/%d", marker->allele1, marker->allele2);
    }
    fprintf(F, "\n");
  }

  fclose(F);
  puts("Made Solar marker file");
  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:35,代码来源:fileio.c

示例12: ExportMendelLocus

void ExportMendelLocus(individual *indlist) {
  int i, j, nAlleles;
  char minibuf[10], tempstr[NAMESIZE];  

  cfopen ("mendel.loc", "w");

  // Make an artificial DISEASE variable
  fprintf(F, "DISEASE AUTOSOME 2 0\n+       .99\n-       .01\n");

  for (i = 0; i < numberofmarkers(); i++) {
    nAlleles = NumberOfAlleles(order[i+1]);

    RemoveWhiteSpace(tempstr, GetName(markernames, order[i+1]));
    strncpy(minibuf, tempstr, 8);
    minibuf[8] = '\0';

    // Prints the locus information
    //    fprintf(F, "%-8s%-8s%2d%2d\n", minibuf,"AUTOSOME", nAlleles, nAlleles*(nAlleles+1)/2);
    fprintf(F, "%-8s%-8s%2d%2d\n", minibuf,"AUTOSOME", nAlleles, 0);

    // Should now print the frequency information

    CopyAlleleFreq(order[i+1]);
    
    for (j=1; j<= NumberOfAlleles(order[i+1]); j++)
      fprintf(F, "%c       %8.5f\n", 64+j, allelefreq[j]);

  }

  fclose(F);

}
开发者ID:ekstroem,项目名称:pedipet,代码行数:32,代码来源:fileio.c

示例13: ExportSolarPedigree

int ExportSolarPedigree (individual *indlist)
{
  individual *ind;
  

  // Checks that data exists
  if (!listlen(indlist))
  {
    // XXX Should create a proper output rutine for warnings
    //    WriteWarning("No pedigree data avaliable for creating SOLAR file\n");
    return -1;
  }

  // Makes pedigree file
  cfopen ("solar.ped", "w");
  fprintf(F, "id,fa,mo,sex\n");  // The first line
  for (ind = indlist; ind; ind = ind->next)
  {
    if (founder(ind))
      fprintf(F, "%s,0,0,%d\n",ind->id, ind->sex);
    else
      fprintf(F, "%s,%s,%s,%d\n",ind->id, ind->father->id, ind->mother->id,ind->sex);
  }
  fclose(F);
  return 0;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:26,代码来源:fileio.c

示例14: ExportCRIMAPPar

int ExportCRIMAPPar(individual *indlist)
{
  int nLoci, i;
  

  nLoci = listlen(indlist->marker);

  cfopen ("crimap.par", "w");
  fprintf(F, "dat_file crimap.dat *\n");
  fprintf(F, "gen_file crimap.gen *\n");
  fprintf(F, "ord_file crimap.ord *\n");
  fprintf(F, "nb_our_alloc 3000000 *\n");
  fprintf(F, "SEX_EQ  1 *\n");
  fprintf(F, "TOL .010000 *\n");
  fprintf(F, "PUK_NUM_ORDERS_TOL  6 *\n");
  fprintf(F, "PK_NUM_ORDERS_TOL  8 *\n");
  fprintf(F, "PUK_LIKE_TOL 3.000 *\n");
  fprintf(F, "PK_LIKE_TOL 3.000 *\n");
  fprintf(F, "use_ord_file  0 *\n");
  fprintf(F, "write_ord_file  1 *\n");
  fprintf(F, "use_haps  1 *\n");
  fprintf(F, "ordered_loci 0 1  *\n");

  fprintf(F, "inserted_loci ");
  for (i=2; i<nLoci; i++)
    fprintf(F, "%d ",i);
  fprintf(F, "  *\n");

  fprintf(F, "END\n");
  fclose(F);

  printf("Created crimap parameter file\n");
  return 0;

}
开发者ID:ekstroem,项目名称:pedipet,代码行数:35,代码来源:fileio.c

示例15: ExportRelpairLocus

int ExportRelpairLocus(int chromosome)
{
  int i, j;
  char mkrname[NAMESIZE], tempstr[NAMESIZE];
  

  cfopen ("relpair.loc", "w");

  for (i = 1; i<=numberofmarkers(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(markernames, order[i]));
    strncpy(mkrname, tempstr, NAMESIZE);
    // Prints the locus information
    fprintf(F, "%-8s%8s%2d%2d%4d%8.5f\n", mkrname, "AUTOSOME", 
	    NumberOfAlleles(order[i]), 0, chromosome, MarkerDistance(0,i)/100);
    // Should now print the frequency information

    CopyAlleleFreq(order[i]);

    for (j=1; j<= NumberOfAlleles(order[i]); j++)
      fprintf(F, "%c       %8.5f\n", 64+j, allelefreq[j]);
  }
    
  fclose(F);

  printf("Created relpair locus file\n");

  return 1;
}
开发者ID:ekstroem,项目名称:pedipet,代码行数:30,代码来源:fileio.c


注:本文中的cfopen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。