Ejemplo n.º 1
0
static void _text_file(cptr name, _file_fn fn)
{
    FILE    *fff = NULL;
    char    buf[1024];

    path_build(buf, sizeof(buf), ANGBAND_DIR_HELP, name);
    fff = my_fopen(buf, "w");

    if (!fff)
    {
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
        fff = my_fopen(buf, "w");

        if (!fff)
        {
            prt("Failed!", 0, 0);
            (void)inkey();
            return;
        }
    }

    fn(fff);
    fprintf(fff, "\n\n[[[[s|  Automatically generated for PosChengband %d.%d.%d.\n",
            VER_MAJOR, VER_MINOR, VER_PATCH);

    my_fclose(fff);
    msg_format("Created %s", buf);
}
Ejemplo n.º 2
0
// Create DCT From Source Filename & Target Filename (Return 0 On Success)
static int create_binary(const char *source_filename, const char *target_filename) {
  FILE *source_file = NULL;
  long source_size;
  FILE *target_file = NULL;
  long ofs;
  int e = 0;
  source_file = NULL;

  // Open Source File
  source_file = my_fopen(source_filename, "rb", &source_size);
  if(!source_file) goto err;

  // Create Target File
  target_file = my_fopen(target_filename, "wb", NULL);
  if(!target_file) goto err;
  fprintf(stderr, "Creating %s...\n", target_filename);
  ofs = 0;

  // Convert DCT Quantization Block Output
  convert_dct_Y(source_file, target_file, ofs, source_size);
  convert_dct_U(source_file, target_file, ofs, source_size);
  convert_dct_V(source_file, target_file, ofs, source_size);
  
  // Finished
  fprintf(stderr, "Done\n");
  goto no_err;
  err:
  e = 1;
  no_err:
  if(source_file) fclose(source_file);
  if(target_file) fclose(target_file);
  return e;
}
Ejemplo n.º 3
0
static int create_header_files(struct errors *error_head)
{
  uint er_last;
  FILE *er_definef, *sql_statef, *er_namef;
  struct errors *tmp_error;
  DBUG_ENTER("create_header_files");
  LINT_INIT(er_last);

  if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
  {
    DBUG_RETURN(1);
  }
  if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    DBUG_RETURN(1);
  }
  if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    my_fclose(sql_statef, MYF(0));
    DBUG_RETURN(1);
  }

  fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");

  fprintf(er_definef, "#define ER_ERROR_FIRST %d\n", error_head->d_code);

  for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
  {
    /*
       generating mysqld_error.h
       fprintf() will automatically add \r on windows
    */
    fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
	    tmp_error->d_code);
    er_last= tmp_error->d_code;

    /* generating sql_state.h file */
    if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
      fprintf(sql_statef,
	      "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
	      tmp_error->sql_code1, tmp_error->sql_code2);
    /*generating er_name file */
    fprintf(er_namef, "{ \"%s\", %d },\n", tmp_error->er_name,
	    tmp_error->d_code);

  }
  /* finishing off with mysqld_error.h */
  fprintf(er_definef, "#define ER_ERROR_LAST %d\n", er_last);
  my_fclose(er_definef, MYF(0));
  my_fclose(sql_statef, MYF(0));
  my_fclose(er_namef, MYF(0));
  DBUG_RETURN(0);
}
Ejemplo n.º 4
0
SBMLSIM_EXPORT void write_separate_result(myResult* result, const char* file_s, const char* file_p, const char* file_c) {
    FILE *fp_s = NULL;
    FILE *fp_p = NULL;
    FILE *fp_c = NULL;
    int i, j;
    char delimiter = ' ';
    double *value_time_p  = result->values_time;
    double *value_sp_p    = result->values_sp;
    double *value_param_p = result->values_param;
    double *value_comp_p  = result->values_comp;

    if ((fp_s = my_fopen(fp_s, file_s, "w")) == NULL) {
        return;
    }
    if ((fp_p = my_fopen(fp_p, file_p, "w")) == NULL) {
        return;
    }
    if ((fp_c = my_fopen(fp_c, file_c, "w")) == NULL ) {
        return;
    }

    /*  Species */
    for (i = 0; i < result->num_of_rows; i++) {
        fprintf(fp_s, "%.16g", *(value_time_p));
        value_time_p++;
        for (j = 0; j < result->num_of_columns_sp; j++) {
            fprintf(fp_s, "%c%.16g", delimiter, *(value_sp_p));
            value_sp_p++;
        }
        fprintf(fp_s, "\n");
    }
    /*  Parameters */
    value_time_p  = result->values_time;
    for (i = 0; i < result->num_of_rows; i++) {
        fprintf(fp_p, "%.16g", *(value_time_p));
        value_time_p++;
        for (j = 0; j < result->num_of_columns_param; j++) {
            fprintf(fp_p, "%c%.16g", delimiter, *(value_param_p));
            value_param_p++;
        }
        fprintf(fp_p, "\n");
    }
    /*  Compartments */
    value_time_p  = result->values_time;
    for (i = 0; i < result->num_of_rows; i++) {
        fprintf(fp_c, "%.16g", *(value_time_p));
        value_time_p++;
        for (j = 0; j < result->num_of_columns_comp; j++) {
            fprintf(fp_c, "%c%.16g", delimiter, *(value_comp_p));
            value_comp_p++;
        }
        fprintf(fp_c, "\n");
    }
    fclose(fp_s);
    fclose(fp_p);
    fclose(fp_c);
}
Ejemplo n.º 5
0
/**************************************************
  write_matrix_svd

  Writes the vectors in column-major format, for input to SVDpack.
  
*/
int write_matrix_svd(MATRIX_TYPE **matrix,
		     int rows, int columns,
		     char *model_data_dir) {

  FILE *coll_file, *index_file;
  int i, j, non_zero_cnt;
  char pathbuf[BUFSIZ];

  printf("Entering write_matrix_svd; rows = %d and columns = %d.\n",
	 rows, columns);

  /* Open the output files. */
  sprintf( pathbuf, "%s/%s", model_data_dir, COLL_FILE );
  if( !my_fopen( &coll_file, pathbuf, "w"))
    die( "Couldn't open word vector file.\n");
  
  sprintf( pathbuf, "%s/%s", model_data_dir, INDEX_FILE );
  if( !my_fopen( &index_file, pathbuf, "w" ))
    die( "Couldn't open index file.\n");
  
  /* Write the numbers. */
  for( j = 0; j < columns; j++) {
    /*printf("===== Column %d =====\n", j);*/
    
    /* Write the non-zero entries */
    for( i = non_zero_cnt = 0; i < rows; i++) {

      /*printf("matrix[%d][%d] = %" FORMAT_STRING" \n", i, j, matrix[i][j]);*/

      if( matrix[i][j] != (MATRIX_TYPE) 0.0) {
	non_zero_cnt++;
	/*printf("matrix.c: printing to coll_file\n" );*/
	if( fprintf( coll_file, "%d %f\n", 
		     i, (float) matrix[i][j]) < 0) {
	  perror( "Trying to write word vector file");
	  return 0;
	}
      }
    }

    /* Write the number of non-zero cells in this column 
       to the index file. */
    if( fprintf( index_file, "%d\n", non_zero_cnt) < 0) {
      perror( "Trying to write index file");
      return 0;
    }
  }

  my_fclose( &coll_file);
  my_fclose( &index_file);


  return 1;
}
Ejemplo n.º 6
0
void
print_int_matrix3(int ***vptr,
		  int nrmin,
		  int nrmax,
		  int ncmin,
		  int ncmax,
		  int ndmin,
		  int ndmax,
		  char *file)
{
    FILE *outfile;
    int i, j, k;

    outfile = my_fopen(file, "w");

    for(k = nrmin; k <= nrmax; ++k)
	{
	    fprintf(outfile, "Plane %d\n", k);
	    for(j = ncmin; j <= ncmax; ++j)
		{
		    for(i = ndmin; i <= ndmax; ++i)
			{
			    fprintf(outfile, "%d ", vptr[k][j][i]);
			}
		    fprintf(outfile, "\n");
		}
	    fprintf(outfile, "\n");
	}

    fclose(outfile);
}
Ejemplo n.º 7
0
static int upgrade_already_done(void)
{
  FILE *in;
  char upgrade_info_file[FN_REFLEN]= {0};
  char buf[sizeof(MYSQL_SERVER_VERSION)+1];
  char *res;

  if (get_upgrade_info_file_name(upgrade_info_file))
    return 0; /* Could not get filename => not sure */

  if (!(in= my_fopen(upgrade_info_file, O_RDONLY, MYF(0))))
    return 0; /* Could not open file => not sure */

  /*
    Read from file, don't care if it fails since it
    will be detected by the strncmp
  */
  memset(buf, 0, sizeof(buf));
  res= fgets(buf, sizeof(buf), in);

  my_fclose(in, MYF(0));

  if (!res)
    return 0; /* Could not read from file => not sure */

  return (strncmp(res, MYSQL_SERVER_VERSION,
                  sizeof(MYSQL_SERVER_VERSION)-1)==0);
}
Ejemplo n.º 8
0
/** 
 *  write_matrix_matlab()
 *  ---------------------
 *
 *  Write the contents of the rows by columns matrix "matrix" to
 *  the file MATLAB_FILE in model_data_dir, in a format
 *  readable by Matlab.
 *
 */
int write_matrix_matlab(MATRIX_TYPE **matrix,
			int rows, int columns,
			char *model_data_dir) {

  FILE *matlab_file = NULL;
  char pathbuf[BUFSIZ];
  int i, j;

  sprintf( pathbuf, "%s/%s", model_data_dir, MATLAB_FILE );
  if( !my_fopen( &matlab_file, pathbuf, "w" ))
    die( "Couldn't open matlab file.\n");

  
  for (j = 0; j < columns; j++) {
    for (i = 0; i < rows; i++) {

      if( fprintf( matlab_file, "%d %d %f\n", 
		   j, i, (float) matrix[i][j]) < 0) {
	perror( "Trying to write co-occurrence matrix in matlab format");
	return 0;
      }
    }
  }

  my_fclose( &matlab_file);
  return 1;

}
Ejemplo n.º 9
0
//Reads coupling matrix from file and computes its LU decomposition
void read_coupling_matrix(char *fname_in,int nbins_in,
			  gsl_matrix **coupling_matrix_b_out,
			  gsl_permutation **perm_out,
			  int pol1,int pol2)
{
  int sig,n_cl,stat;
  FILE *fi;
  gsl_permutation *perm;
  gsl_matrix *coupling_matrix_b;

  if(pol1) {
    if(pol2) n_cl=4;
    else n_cl=2;
  }
  else {
    if(pol2) n_cl=2;
    else n_cl=1;
  }
  perm=gsl_permutation_alloc(n_cl*nbins_in);
  coupling_matrix_b=gsl_matrix_alloc(n_cl*nbins_in,n_cl*nbins_in);

  fi=my_fopen(fname_in,"rb");
  stat=gsl_matrix_fread(fi,coupling_matrix_b);
  if(stat==GSL_EFAILED)
    report_error(1,"Error reading matrix from file %s\n",fname_in);
  fclose(fi);

  gsl_linalg_LU_decomp(coupling_matrix_b,perm,&sig);
  *coupling_matrix_b_out=coupling_matrix_b;
  *perm_out=perm;
}
Ejemplo n.º 10
0
static void compute_delta_arrays(struct s_router_opts router_opts,
		struct s_det_routing_arch det_routing_arch, t_segment_inf * segment_inf,
		t_timing_inf timing_inf, int longest_length) {

	vpr_printf(TIO_MESSAGE_INFO, "Computing delta_io_to_io lookup matrix, may take a few seconds, please wait...\n");
	compute_delta_io_to_io(router_opts, det_routing_arch, segment_inf, timing_inf);
	vpr_printf(TIO_MESSAGE_INFO, "Computing delta_io_to_clb lookup matrix, may take a few seconds, please wait...\n");
	compute_delta_io_to_clb(router_opts, det_routing_arch, segment_inf, timing_inf);
	vpr_printf(TIO_MESSAGE_INFO, "Computing delta_clb_to_io lookup matrix, may take a few seconds, please wait...\n");
	compute_delta_clb_to_io(router_opts, det_routing_arch, segment_inf, timing_inf);
	vpr_printf(TIO_MESSAGE_INFO, "Computing delta_clb_to_clb lookup matrix, may take a few seconds, please wait...\n");
	compute_delta_clb_to_clb(router_opts, det_routing_arch, segment_inf, timing_inf, longest_length);

#ifdef PRINT_ARRAYS
	lookup_dump = my_fopen(DUMPFILE, "w", 0);
	fprintf(lookup_dump, "\n\nprinting delta_clb_to_clb\n");
	print_array(delta_clb_to_clb, 0, nx - 1, 0, ny - 1);
	fprintf(lookup_dump, "\n\nprinting delta_io_to_clb\n");
	print_array(delta_io_to_clb, 0, nx, 0, ny);
	fprintf(lookup_dump, "\n\nprinting delta_clb_to_io\n");
	print_array(delta_clb_to_io, 0, nx, 0, ny);
	fprintf(lookup_dump, "\n\nprinting delta_io_to_io\n");
	print_array(delta_io_to_io, 0, nx + 1, 0, ny + 1);
	fclose(lookup_dump);
#endif

}
Ejemplo n.º 11
0
// ********************************************************************************************
bool BitStream::OpenRA(const char *file_name)
{
	if (file)
		fclose(file);
	if ((file = my_fopen(file_name, "rb")) != NULL)
		mode = FILE_MODE_READ_RA;

	IO_BUFFER_SIZE = BitStream::DEFAULT_IO_BUFFER_SIZE_RA;
	io_buffer = new uchar[IO_BUFFER_SIZE];
	io_buffer_size = IO_BUFFER_SIZE;

	word_buffer_size = 8;
	io_buffer_pos = IO_BUFFER_SIZE;
	file_pos = 0;

	if (mode == FILE_MODE_READ_RA)
	{
		my_fseek(file, 0, SEEK_END);
		file_size = my_ftell(file);

		my_fseek(file, 0, SEEK_SET);
	} 
	
	return mode == FILE_MODE_READ_RA;
}
Ejemplo n.º 12
0
void *seeki_alloc(char *str)
{
    struct seeki *sip = malloc(sizeof(struct seeki));

    sip->rfp = seek_open(str, 'r');
    sip->wfp = seek_open(str, 'w');
    sip->cfp = seek_open(str, 'c');
    sip->tot_seeks = 0;
    sip->total_sectors = 0.0;
    sip->last_start = sip->last_end = 0;
    memset(&sip->root, 0, sizeof(sip->root));

    if (sps_name) {
        char *oname;

        memset(&sip->sps, 0, sizeof(sip->sps));

        oname = malloc(strlen(sps_name) + strlen(str) + 32);
        sprintf(oname, "%s_%s.dat", sps_name, str);
        if ((sip->sps_fp = my_fopen(oname, "w")) == NULL)
            perror(oname);
        else
            add_file(sip->sps_fp, oname);
    } else
        sip->sps_fp = NULL;

    return sip;
}
Ejemplo n.º 13
0
/* HACK -- Read from file */
bool rd_dungeon_special_ext(int Depth, cptr levelname)
{
	char filename[1024];
	FILE *fhandle;
	FILE *server_handle;
	
	path_build(filename, 1024, ANGBAND_DIR_SAVE, levelname);

	fhandle = my_fopen(filename, "r");

	if (fhandle)
	{
			/* swap out the main file pointer for our level file */
			server_handle = file_handle;
			file_handle = fhandle;

			/* load the level */
			rd_dungeon(TRUE, Depth);

			/* swap the file pointers back */
			file_handle = server_handle;

			/* close the level file */
			my_fclose(fhandle);

			return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 14
0
void read_blif(char* blif_file, int lut_size)
{
    char buffer[BUFSIZE];
    int pass, done, doall;
    blif = my_fopen(blif_file, "r", 0);

    for (doall = 0; doall <= 1; doall++) {
        init_parse(doall);

        /* Three passes to ensure inputs are first blocks, outputs second and    *
         * LUTs and latches third.  Just makes the output netlist more readable. */

        for (pass = 1; pass <= 3; pass++) {
            linenum = 0;   /* Reset line number. */
            done = 0;

            while ((my_fgets(buffer, BUFSIZE, blif) != NULL) && !done) {
                get_tok(buffer, pass, doall, &done, lut_size);
            }

            rewind(blif);   /* Start at beginning of file again */
        }
    }

    fclose(blif);
    check_net(lut_size);
    free_parse();
}
Ejemplo n.º 15
0
void DotGraph::WriteToFile(const char* filename) {
	FILE* file = my_fopen(filename, "w");

	ToStream(file);

	my_fclose(file);
}
Ejemplo n.º 16
0
void
print_place(char *place_file,
	    char *net_file,
	    char *arch_file)
{

/* Prints out the placement of the circuit.  The architecture and    *
 * netlist files used to generate this placement are recorded in the *
 * file to avoid loading a placement with the wrong support files    *
 * later.                                                            */

    FILE *fp;
    int i;

    fp = my_fopen(place_file, "w");

    fprintf(fp, "Netlist file: %s   Architecture file: %s\n", net_file,
	    arch_file);
    fprintf(fp, "Array size: %d x %d logic blocks\n\n", nx, ny);
    fprintf(fp, "#block name\tx\ty\tsubblk\tblock number\n");
    fprintf(fp, "#----------\t--\t--\t------\t------------\n");

    for(i = 0; i < num_blocks; i++)
	{
	    fprintf(fp, "%s\t", block[i].name);
	    if(strlen(block[i].name) < 8)
		fprintf(fp, "\t");

	    fprintf(fp, "%d\t%d\t%d", block[i].x, block[i].y, block[i].z);
	    fprintf(fp, "\t#%d\n", i);
	}

    fclose(fp);
}
Ejemplo n.º 17
0
static void create_mysql_upgrade_info_file(void)
{
  FILE *out;
  char upgrade_info_file[FN_REFLEN]= {0};

  if (get_upgrade_info_file_name(upgrade_info_file))
    return; /* Could not get filename => skip */

  if (!(out= my_fopen(upgrade_info_file, O_TRUNC | O_WRONLY, MYF(0))))
  {
    fprintf(stderr,
            "Could not create the upgrade info file '%s' in "
            "the MySQL Servers datadir, errno: %d\n",
            upgrade_info_file, errno);
    return;
  }

  /* Write new version to file */
  fputs(MYSQL_SERVER_VERSION, out);
  my_fclose(out, MYF(0));

  /*
    Check if the upgrad_info_file was properly created/updated
    It's not a fatal error -> just print a message if it fails
  */
  if (!upgrade_already_done())
    fprintf(stderr,
            "Could not write to the upgrade info file '%s' in "
            "the MySQL Servers datadir, errno: %d\n",
            upgrade_info_file, errno);
  return;
}
Ejemplo n.º 18
0
/*
 * Actually read the savefile
 */
errr rd_savefile(void)
{
	errr err;

	/* Grab permissions */
	safe_setuid_grab();

	/* The savefile is a binary file */
	fff = my_fopen(savefile, "rb");

	/* Drop permissions */
	safe_setuid_drop();

	/* Paranoia */
	if (!fff) return (-1);

	/* Call the sub-function */
	err = rd_savefile_new_aux();

	/* Check for errors */
	if (ferror(fff)) err = -1;

	/* Close the file */
	my_fclose(fff);

	/* Result */
	return (err);
}
Ejemplo n.º 19
0
void pw_ccp(PwParam *p, Mapfile *mapfile, int chr, int chrlen){
  int i;

  printf("Making cross-correlation profile...\n");
  TYPE_WIGARRAY *plus  = chrarray_new(mapfile, chr, chrlen, STRAND_PLUS);
  TYPE_WIGARRAY *minus = chrarray_new(mapfile, chr, chrlen, STRAND_MINUS);

  TYPE_WIGARRAY qnt99 = calc_qnt(plus, chrlen, 0.99);
  for(i=0; i<chrlen; i++){
    if(plus[i]  > qnt99) plus[i]  = qnt99;
    if(minus[i] > qnt99) minus[i] = qnt99;
  }

  char *outputfile = alloc_str_new(p->output_dir, strlen(p->output_prefix) +100);
  sprintf(outputfile, "%s/%s.ccp.xls", p->output_dir, p->output_prefix);
  FILE *OUT = my_fopen(outputfile, FILE_MODE_WRITE);
  fprintf(OUT, "strand-shift\tcross-correlation\n");
  double cc=0;
  int start=1000;
  int num=chrlen-2500;
  for(i=-500; i<1500; i+=5){
    cc = calc_corr(plus + start, minus + start + i, num);
    fprintf(OUT, "%d\t%f\n", i, cc);
  }
  fclose(OUT);
  printf("Output to %s.\n",outputfile);

  MYFREE(outputfile);
  MYFREE(plus);
  MYFREE(minus);
  return;
}
Ejemplo n.º 20
0
void symdirget(char *dir)
{
  char buff[FN_REFLEN];
  char *pos=strend(dir);
  if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK))
  {
    FILE *fp;
    char temp= *(--pos);            /* May be "/" or "\" */
    strmov(pos,".sym");
    fp = my_fopen(dir, O_RDONLY,MYF(0));
    *pos++=temp; *pos=0;	  /* Restore old filename */
    if (fp)
    {
      if (fgets(buff, sizeof(buff)-1, fp))
      {
	for (pos=strend(buff);
	     pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
	     pos --);

	/* Ensure that the symlink ends with the directory symbol */
	if (pos == buff || pos[-1] != FN_LIBCHAR)
	  *pos++=FN_LIBCHAR;

	strmake(dir,buff, (uint) (pos-buff));
      }
      my_fclose(fp,MYF(0));
    }
  }
}
Ejemplo n.º 21
0
void print_result_to_file(myResult* result, const char* file, char delimiter) {
    FILE *fp = NULL;
    if ((fp = my_fopen(fp, file, "w")) != NULL) {
        output_result(result, fp, delimiter);
        fclose(fp);
    }
}
Ejemplo n.º 22
0
SeqSet*
read_fasta(char *seq_f)
{

	FILE *seq_F = my_fopen(seq_f, "r");
	SeqSet *set = (SeqSet*)my_malloc(sizeof(SeqSet));
	set->seqs=NULL;
	set->n_seqs=0;
	set->reserved=0;

	const unsigned int LINE_LENGTH = 500;
	char line[LINE_LENGTH];

	Seq *tmp_S = NULL;
	while (fgets(line, LINE_LENGTH, seq_F) != NULL)
	{
		if (line[0] == '>')
		{
			line[strlen(line)-1] = '\0';
			tmp_S=init_Seq(&line[1], 100);
			add(tmp_S, set);
		}
		else
		{
			if (line[strlen(line)-1] == '\n')
				line[strlen(line)-1] = '\0';
			append(tmp_S, line);
		}
	}
	fclose(seq_F);
	return set;
}
Ejemplo n.º 23
0
// Process file FILE to standard output. Return true if successful.
bool nl_file(char const *file)
{
    MY_FILE *stream;

    if(STREQ(file, "-"))
    {
        have_read_stdin = true;
        stream = my_stdin;
    }
    else
    {
        stream = my_fopen(file, "r");
        if(stream == NULL)
        {
            //fprintf(stderr, "can't open file %s\n", file);
            perror(strerror(errno));
            return false;
        }
    }

    process_file(stream);

    if(my_ferror(stream))
    {
        perror(strerror(errno)); //TODO
        return false;
    }

    if(STREQ(file, "-"))
        my_clearerr(stream);
    else if(my_fclose(stream) == EOF)
        return false;

    return true;
}
Ejemplo n.º 24
0
Archivo: notes.c Proyecto: jcubic/ToME
/*
 * Output a string to the notes file.
 * This is the only function that references that file.
 */
void output_note(char *final_note)
{
	PHYSFS_file *fff;
	char basename[13];
	char buf[1024];

	/* Hack -- extract first 8 characters of name and append an extension */
	(void)strnfmt(basename, sizeof(basename), "%.8s.nte", player_base);
	basename[sizeof(basename) - 1] = '\0';

	/* Build the path */
	path_build(buf, sizeof(buf), TENGINE_DIR_NOTE, basename);

	/* Open notes file */
	fff = my_fopen(buf, "a");

	/* Failure */
	if (!fff) return;

	/* Add note, and close note file */
	my_fputs(fff, final_note);

	/* Close the handle */
	my_fclose(fff);

	/* Done */
	return;
}
Ejemplo n.º 25
0
/*
 * Initialize CHECK_LOAD
 */
errr check_load_init(void)
{

#ifdef CHECK_LOAD

	FILE *fp;

	char buf[1024];

	char temphost[MAXHOSTNAMELEN+1];
	char thishost[MAXHOSTNAMELEN+1];


	/* Build the filename */
	path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "load.txt");

	/* Open the "load" file */
	fp = my_fopen(buf, "r");

	/* No file, no restrictions */
	if (!fp) return (0);

	/* Default load */
	check_load_value = 100;

	/* Get the host name */
	(void)gethostname(thishost, (sizeof thishost) - 1);

	/* Parse it */
	while (0 == my_fgets(fp, buf, sizeof(buf)))
	{
		int value;

		/* Skip comments and blank lines */
		if (!buf[0] || (buf[0] == '#')) continue;

		/* Parse, or ignore */
		if (sscanf(buf, "%s%d", temphost, &value) != 2) continue;

		/* Skip other hosts */
		if (!streq(temphost, thishost) &&
		    !streq(temphost, "localhost")) continue;

		/* Use that value */
		check_load_value = value;

		/* Done */
		break;
	}

	/* Close the file */
	my_fclose(fp);

#endif /* CHECK_LOAD */

	/* Success */
	return (0);
}
Ejemplo n.º 26
0
Archivo: cmd4.c Proyecto: jcubic/ToME
/*
 * Hack -- append all current macros to the given file
 */
static errr macro_dump(cptr fname)
{
	s32b i;

	PHYSFS_file *fff;

	char buf[1024];


	/* Build the filename */
	path_build(buf, 1024, TENGINE_DIR_USER, fname);

	/* Append to the file */
	fff = my_fopen(buf, "a");

	/* Failure */
	if (!fff) return ( -1);


	/* Skip space */
	fprintf(fff, "\n\n");

	/* Start dumping */
	fprintf(fff, "# Automatic macro dump\n\n");

	/* Dump them */
	for (i = 0; i < macro__num; i++)
	{
		/* Start the macro */
		fprintf(fff, "# Macro '%d'\n\n", i);

		/* Extract the action */
		ascii_to_text(buf, macro__act[i]);

		/* Dump the macro */
		fprintf(fff, "A:%s\n", buf);

		/* Extract the action */
		ascii_to_text(buf, macro__pat[i]);

		/* Dump normal macros */
		fprintf(fff, "P:%s\n", buf);

		/* End the macro */
		fprintf(fff, "\n\n");
	}

	/* Start dumping */
	fprintf(fff, "\n\n\n\n");


	/* Close */
	my_fclose(fff);

	/* Success */
	return (0);
}
Ejemplo n.º 27
0
void make_binary(TYPE_WIGARRAY *array, char *outputfile, int binnum){
  FILE *OUT = my_fopen(outputfile, FILE_MODE_WB);
  if(fwrite(array, sizeof(TYPE_WIGARRAY) * binnum, 1, OUT) != 1){
    fprintf(stderr,"[E] fwrite error:%s\n", outputfile);
    exit(1);
  }
  fclose(OUT);
  return;
}
Ejemplo n.º 28
0
static int
readable(char *filename)
{
	FILE       *fp;

	if ((fp = my_fopen(filename, "r")) == NULL)
		return False;
	(void) fclose(fp);
	return True;
}
Ejemplo n.º 29
0
Archivo: luac.c Proyecto: jcubic/ToME
/*
 * Lua source to bytecode loading
 */
PHYSFS_file* efopen(const char* name, const char* mode)
{
	PHYSFS_file* f = my_fopen(name, mode);
	if (f==NULL)
	{
		quit(format("luac: cannot open %sput file '%s' : %s\n",*mode=='r' ? "in" : "out", name, PHYSFS_getLastError()));
		return NULL;
	}
	return f;
}
Ejemplo n.º 30
0
static char * 
ScanAux(char *token, char * reference, int code)
/*************************************************************************
purpose: obtains a reference from .aux file

code=0 means \token{reference}{number}       -> "number"
code=1 means \token{reference}{{sect}{line}} -> "sect"
 ************************************************************************/
{
	static FILE    *fAux = NULL;
	char            AuxLine[2048];
	char            target[512];
	char           *s,*t;
	int				braces;

	if (g_aux_file_missing || strlen(token) == 0) {
		return NULL;
	}

	diagnostics(4,"seeking in .aux for <%s>",reference);
	
	snprintf(target, 512, "\\%s{%s}", token, reference);
	
	if (fAux == NULL && (fAux = my_fopen(g_aux_name, "r")) == NULL) {
		diagnostics(WARNING, "No .aux file.  Run LaTeX to create %s\n", g_aux_name);
		g_aux_file_missing = TRUE;
		return NULL;
	}
	
	rewind(fAux);
	
	while (fgets(AuxLine, 2047, fAux) != NULL) {

		s = strstr(AuxLine, target);
		if (s) {
		
			s += strlen(target);		/* move to \token{reference}{ */			
			if (code==1) s++;			/* move to \token{reference}{{ */

			t = s;					
			braces = 1;
			while ( braces >= 1) {		/* skip matched braces */
				t++;
				if (*t == '{') braces++;
				if (*t == '}') braces--;
				if (*t == '\0') return NULL;
			}
			
			*t = '\0';
			diagnostics(4,"found <%s>",s+1);
			return strdup(s+1);
		}
	}
	return NULL;
}