Exemplo n.º 1
0
/*
 * 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;
}
Exemplo n.º 2
0
/*
 * 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;
}
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);
}
Exemplo n.º 4
0
Arquivo: palette.c Projeto: btb/d2x
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
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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 );
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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);

}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;

}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
int med_save_mine(char * filename)
{
	FILE * SaveFile;
	char ErrorMessage[256];

	SaveFile = cfopen( filename, CF_WRITE_MODE );
	if (!SaveFile)
	{
		char fname[20];
		_splitpath( filename, NULL, NULL, fname, NULL );

		sprintf( ErrorMessage, \
			"ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n" 
			, filename, fname, fname );
		sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
		MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
		return 1;
	}

	save_mine_data(SaveFile);
	
	//==================== CLOSE THE FILE =============================
	cfclose(SaveFile);

	return 0;

}
Exemplo n.º 17
0
void songs_init()
{
	int i;
	char inputline[80+1];
	CFILE * fp;

	if ( Songs_initialized ) return;

	fp = cfopen( "descent.sng", "rb" );
	if ( fp == NULL )	{
		Error( "Couldn't open descent.sng" );
	}

	i = 0;
	while (cfgets(inputline, 80, fp )) {
		char *p = strchr(inputline,'\n');
		if (p) *p = '\0';
		if ( strlen( inputline ) )	{
			Assert( i < MAX_SONGS );
			sscanf( inputline, "%s %s %s", Songs[i].filename, Songs[i].melodic_bank_file, Songs[i].drum_bank_file );
			//printf( "%d. '%s' '%s' '%s'\n",i,  Songs[i].filename, Songs[i].melodic_bank_file, Songs[i].drum_bank_file );
			i++;
		}
	}
	Songs_initialized = 1;
	cfclose(fp);
}
Exemplo n.º 18
0
void snd_spew_info()
{
	int idx;
	char txt[512] = "";
	CFILE *out = cfopen("sounds.txt", "wt", CFILE_NORMAL, CF_TYPE_DATA);
	if(out == NULL){
		return;
	}
	
	cfwrite_string("Sounds loaded :\n", out);

	// spew info for all sounds
	for(idx=0; idx<MAX_SOUNDS; idx++){
		if(!(Sounds[idx].flags & SND_F_USED)){
			continue;
		}
		
		sprintf(txt, "%s (%ds)\n", Sounds[idx].filename, Sounds[idx].info.duration); 
		cfwrite_string(txt, out);
	}

	// close the outfile
	if(out != NULL){
		cfclose(out);
		out = NULL;
	}
}
Exemplo n.º 19
0
void palette_load_table( char * filename )
{
	int i;
	int w, h;
	int pcx_error;

	strcpy( palette_base_filename, filename );
	char * p = strchr(palette_base_filename,'.');
	if ( p )	{
		*p = 0;
	}

	pcx_error = pcx_read_header(palette_base_filename, NULL, &w, &h, NULL, palette_org );
	if ( pcx_error != PCX_ERROR_NONE )	{
		// Read the old .256 file
		CFILE *fp;
		int fsize;
		fp = cfopen( palette_base_filename, "rb" );
		if ( fp==NULL)
			Error( LOCATION, "Can't open palette file <%s>",palette_base_filename);

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

		for (i=0; i<768; i++ )	{	
			palette_org[i] = ubyte((palette_org[i]*255)/63);
		}
	}

	palette_base_loaded = 1;

	gr_set_palette(palette_base_filename, palette_org);
}
Exemplo n.º 20
0
void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,fsize;

	fp = cfopen( filename, "rb" );
	if ( fp==NULL)
		Error("Can't open palette file <%s>",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.
#if defined(POLY_ACC)
    pa_update_clut(gr_palette, 0, 256, 0);
#endif
}
Exemplo n.º 21
0
// Reads header information from the JPEG file into the bitmap pointer
// 
// filename - name of the JPEG bitmap file
// w - (output) width of the bitmap
// h - (output) height of the bitmap
// bpp - (output) bits per pixel of the bitmap
//
// returns - JPEG_ERROR_NONE if successful, otherwise error code
//
int jpeg_read_header(const char *real_filename, CFILE *img_cfp, int *w, int *h, int *bpp, ubyte *palette)
{
	CFILE *jpeg_file = NULL;
	char filename[MAX_FILENAME_LEN];

	if (img_cfp == NULL) {
		strcpy_s( filename, real_filename );

		char *p = strchr( filename, '.' );

		if ( p )
			*p = 0;

		strcat_s( filename, ".jpg" );

		jpeg_file = cfopen( filename , "rb" );

		if ( !jpeg_file ) {
			return JPEG_ERROR_READING;
		}
	} else {
		jpeg_file = img_cfp;
	}

	Assert( jpeg_file != NULL );

	if (jpeg_file == NULL)
		return JPEG_ERROR_READING;

	// set the basic/default error code
	Jpeg_Set_Error(JPEG_ERROR_NONE);

	// initialize error message handler and decompression struct
	jpeg_info.err = jpeg_std_error(&jpeg_err);
	jpeg_err.error_exit = jpg_error_exit;
	jpeg_err.output_message = jpg_output_message;

	jpeg_create_decompress(&jpeg_info);

	// setup to read data via CFILE
	jpeg_cfile_src(&jpeg_info, jpeg_file);

	jpeg_read_header(&jpeg_info, TRUE);

	// send the info back out
	if (w) *w = jpeg_info.image_width;
	if (h) *h = jpeg_info.image_height;
	if (bpp) *bpp = (jpeg_info.num_components * 8);

	// cleanup
	jpeg_destroy_decompress(&jpeg_info);

	if (img_cfp == NULL) {
		cfclose(jpeg_file);
		jpeg_file = NULL;
	}

	return jpeg_error_code;
}
void fiction_viewer_load(const char *filename, const char *font_filename, const char *voice_filename)
{
	int file_length;
	Assertion(filename, "Invalid fictionviewer filename pointer given!");
	Assertion(font_filename, "Invalid fictionviewer font filename pointer given!");
	Assertion(voice_filename, "Invalid fictionviewer voice filename pointer given!");

	// just to be sure
	if (Fiction_viewer_text != NULL)
	{
		Int3();
		fiction_viewer_reset();
	}

	// save our filenames
	strcpy_s(Fiction_viewer_filename, filename);
	strcpy_s(Fiction_viewer_font_filename, font_filename);
	strcpy_s(Fiction_viewer_voice_filename, voice_filename);

	// see if we have a matching font
	Fiction_viewer_fontnum = gr_get_fontnum(Fiction_viewer_font_filename);
	if (Fiction_viewer_fontnum < 0 && !Fred_running)
		strcpy_s(Fiction_viewer_font_filename, "");

	Fiction_viewer_voice = audiostream_open(Fiction_viewer_voice_filename, ASF_VOICE);
	if (Fiction_viewer_voice < 0 && !Fred_running)
		strcpy_s(Fiction_viewer_voice_filename, "");

	if (!strlen(filename))
		return;

	// load up the text
	CFILE *fp = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_FICTION);
	if (fp == NULL)
	{
		Warning(LOCATION, "Unable to load fiction file '%s'.", filename);
		return;
	}

	// we don't need to copy the text in Fred
	if (!Fred_running)
	{
		// allocate space
		file_length = cfilelength(fp);
		Fiction_viewer_text = (char *) vm_malloc(file_length + 1);
		Fiction_viewer_text[file_length] = '\0';

		// copy all the text
		cfread(Fiction_viewer_text, file_length, 1, fp);
	}

	// we're done, close it out
	cfclose(fp);
}
Exemplo n.º 23
0
// reads header information from the PCX file into the bitmap pointer
int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal )
{
	PCXHeader header;
	CFILE * PCXfile;
	char filename[MAX_FILENAME_LEN];
		
	strcpy( filename, real_filename );
	char *p = strchr( filename, '.' );
	if ( p ) *p = 0;
	strcat( filename, ".pcx" );

	PCXfile = cfopen( filename , "rb" );
	if ( !PCXfile )
		return PCX_ERROR_OPENING;

	// read 128 char PCX header
	if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1)	{
		cfclose( PCXfile );
		return PCX_ERROR_NO_HEADER;
	}
        header.Xmin = INTEL_SHORT( header.Xmin );
        header.Ymin = INTEL_SHORT( header.Ymin );
        header.Xmax = INTEL_SHORT( header.Xmax );
        header.Ymax = INTEL_SHORT( header.Ymax );
        header.Hdpi = INTEL_SHORT( header.Hdpi );
        header.Vdpi = INTEL_SHORT( header.Vdpi );
        for ( int i=0; i<16; i++ ){
            for ( int j=0; j<3; j++){
                header.ColorMap[i][j] = INTEL_INT( header.ColorMap[i][j] );
            }
        }
        header.BytesPerLine = INTEL_SHORT( header.BytesPerLine );
        for ( int i=0; i<60; i++ ){
            header.filler[i] = INTEL_INT( header.filler[i] );
        }

	// Is it a 256 color PCX file?
	if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5))	{
		cfclose( PCXfile );
		return PCX_ERROR_WRONG_VERSION;
	}

	if (w) *w = header.Xmax - header.Xmin + 1;
	if (h) *h = header.Ymax - header.Ymin + 1;
	
	if ( pal ) {
		cfseek( PCXfile, -768, CF_SEEK_END );
		cfread( pal, 3, 256, PCXfile );
	}

	cfclose(PCXfile);
	return PCX_ERROR_NONE;
}
Exemplo n.º 24
0
void readinputinfo(char *filename)
{
  
  cfopen (DESCFILE,"r");

  getbuf ();

  while (buf[0] != EOF)
  {

  }
  fclose(F);
}
Exemplo n.º 25
0
/*
 * Open a file for writing. 'path' indicates the path name, and 'mode' must
 * be a filemode as accepted by fopen() and gzopen() that indicates writing
 * ("w", "wb", "a", or "ab").
 *
 * If 'compression' is non-zero, a gzip compressed stream is opened, and
 * and 'compression' indicates the compression level used. The ".gz" suffix
 * is automatically added to 'path' in that case.
 */
cfp *
cfopen_write(const char *path, const char *mode, int compression)
{
	cfp		   *fp;

	if (compression == 0)
		fp = cfopen(path, mode, 0);
	else
	{
#ifdef HAVE_LIBZ
		char	   *fname;

		fname = psprintf("%s.gz", path);
		fp = cfopen(fname, mode, 1);
		free(fname);
#else
		exit_horribly(modulename, "not built with zlib support\n");
		fp = NULL;				/* keep compiler quiet */
#endif
	}
	return fp;
}
Exemplo n.º 26
0
void fs2netd_update_ban_list()
{
	int rc = 0;

	// don't bother with this if we aren't on FS2NetD
	if ( !Om_tracker_flag ) {
		return;
	}

	if ( !(Game_mode & GM_MULTIPLAYER) ) {
		return;
	}

	if (!Is_connected) {
		return;
	}


	// destroy the file prior to updating
	cf_delete( "banlist.cfg", CF_TYPE_DATA );

	do_full_packet = 1;

	In_process = true;

	if (Is_standalone) {
		do { rc = fs2netd_update_ban_list_do(); } while (!rc);
	} else {
		rc = popup_till_condition(fs2netd_update_ban_list_do, XSTR("&Cancel", 779), XSTR("Requesting IP ban list", -1));
	}

	In_process = false;


	if (FS2NetD_ban_list) {
		CFILE *banlist_cfg = cfopen("banlist.cfg", "wt", CFILE_NORMAL, CF_TYPE_DATA);

		if (banlist_cfg != NULL) {
			for (int i = 0; i < FS2NetD_ban_list_count; i++) {
				cfputs( FS2NetD_ban_list[i].ip_mask, banlist_cfg );
			}

			cfclose(banlist_cfg);
		}

		delete[] FS2NetD_ban_list;
	}

	FS2NetD_ban_list = NULL;
	FS2NetD_ban_list_count = -1;
}
Exemplo n.º 27
0
/*
 * Open a file for writing. 'path' indicates the path name, and 'mode' must
 * be a filemode as accepted by fopen() and gzopen() that indicates writing
 * ("w", "wb", "a", or "ab").
 *
 * If 'compression' is non-zero, a gzip compressed stream is opened, and
 * and 'compression' indicates the compression level used. The ".gz" suffix
 * is automatically added to 'path' in that case.
 */
cfp *
cfopen_write(const char *path, const char *mode, int compression)
{
	cfp		   *fp;

	if (compression == 0)
		fp = cfopen(path, mode, 0);
	else
	{
#ifdef HAVE_LIBZ
		int			fnamelen = strlen(path) + 4;
		char	   *fname = pg_malloc(fnamelen);

		snprintf(fname, fnamelen, "%s%s", path, ".gz");
		fp = cfopen(fname, mode, 1);
		free(fname);
#else
		exit_horribly(modulename, "not built with zlib support\n");
		fp = NULL;				/* keep compiler quiet */
#endif
	}
	return fp;
}
Exemplo n.º 28
0
Arquivo: titles.c Projeto: btb/d1x
// -----------------------------------------------------------------------------
//	Load Descent briefing text.
void load_screen_text(char *filename, char **buf)
{
	CFILE	*tfile;
	CFILE *ifile;
	int	len, i;
	int	have_binary = 0;

	if ((tfile = cfopen(filename,"rb")) == NULL) {
		char nfilename[30], *ptr;

		strcpy(nfilename, filename);
		if ((ptr = strrchr(nfilename, '.')))
			*ptr = '\0';
		strcat(nfilename, ".txb");
		if ((ifile = cfopen(nfilename, "rb")) == NULL)
			Error("Cannot open file %s or %s", filename, nfilename);
		have_binary = 1;

		len = cfilelength(ifile);
		MALLOC(*buf,char, len);
		cfread(*buf, 1, len, ifile);
		cfclose(ifile);
	} else {
Exemplo n.º 29
0
int ExportSolarPhenotype (individual *indlist)
{
  individual *ind;
  char mkrname[NAMESIZE], tempstr[NAMESIZE];
  int i;
  double currentpos, value;
  

  currentpos = 0;
  // Makes the marker file
  cfopen ("solar.phe", "w");

  // Prints the trait names
  fprintf(F,"id");
  for (i = 1; i<=numberoftraits(); i++)
  {
    // Remove white spaces in marker name
    RemoveWhiteSpace(tempstr, GetName(traitnames, i));
    strncpy(mkrname, tempstr, 18);

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

  for (ind = indlist; ind; ind = ind->next)
  {
    fprintf(F, "%s", ind->id);
    for (i = 1; i<=numberoftraits(); i++)
    {
      fprintf(F, ",");
      if (!traitmiss(ind, i)) {
	value = trait(ind, i);
	// Print only integer part if it is an integer
	if ( (int) value == value) {
	  fprintf(F, "%d", (int) value);
	}
	else {
	  fprintf(F, "%f", value);
	}
      }
    }
    fprintf(F,"\n");
  }

  fclose(F);
  puts("Made Solar phenotype file");
  return 0;
}
Exemplo n.º 30
0
// open the externalization file for use during parsing (call before parsing a given file)
void lcl_ext_open()
{
	// if the file is already open, do nothing
	Assert(Lcl_ext_file == NULL);	

	// if we're running in the default language, do nothing
	if(Lcl_current_lang == LCL_DEFAULT_LANGUAGE){
		return;
	}

	// otherwise open the file
	Lcl_ext_file = cfopen(Lcl_ext_filename, "rt");
	if(Lcl_ext_file == NULL){
		return;
	}		
}