Exemplo n.º 1
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;
}
Exemplo n.º 2
0
int fm_search(char *pattern, int pat_len, char *infile_name)
{
  void fatal_error(char *);
  void read_prologue(bwi_out *);

  bwi_out s_main;
  bwi_out *s = &s_main; 
  int num_occ,sp,ep;

  Report_occ = 0;
  Locate_occ = 0;
  Display_occ = 0;
  Oneline_report = 0;
  Type_mem_ops = EXT_MEM;
  Cache_percentage = 0;
 
  if (check_bwi_suffix(infile_name) == 0)
    fatal_error("The file name must end with .bwi -main-\n");  

  my_open_file(infile_name);

  init_bwi_cache();

  read_prologue(s); 

  num_occ = bwsearch(s, pattern, pat_len, &sp, &ep);

  my_fclose(Infile);

  return num_occ;
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
FILE *my_fopen(const char *filename, int flags, myf MyFlags)
{
  FILE *fd;
  char type[5];
  char *dup_filename= NULL;
  DBUG_ENTER("my_fopen");
  DBUG_PRINT("my",("Name: '%s'  flags: %d  MyFlags: %d",
		   filename, flags, MyFlags));

  make_ftype(type,flags);

#ifdef _WIN32
  fd= my_win_fopen(filename, type);
#else
  fd= fopen(filename, type);
#endif
  if (fd != 0)
  {
    /*
      The test works if MY_NFILE < 128. The problem is that fileno() is char
      on some OS (SUNOS). Actually the filename save isn't that important
      so we can ignore if this doesn't work.
    */

    int filedesc= my_fileno(fd);
    if ((uint)filedesc >= my_file_limit)
    {
      mysql_mutex_lock(&THR_LOCK_open);
      my_stream_opened++;
      mysql_mutex_unlock(&THR_LOCK_open);
      DBUG_RETURN(fd);				/* safeguard */
    }
    dup_filename= my_strdup(key_memory_my_file_info, filename, MyFlags);
    if (dup_filename != NULL)
    {
      mysql_mutex_lock(&THR_LOCK_open);
      my_file_info[filedesc].name= dup_filename;
      my_stream_opened++;
      my_file_total_opened++;
      my_file_info[filedesc].type= STREAM_BY_FOPEN;
      mysql_mutex_unlock(&THR_LOCK_open);
      DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
      DBUG_RETURN(fd);
    }
    (void) my_fclose(fd,MyFlags);
    set_my_errno(ENOMEM);
  }
  else
    set_my_errno(errno);
  DBUG_PRINT("error",("Got error %d on open",my_errno()));
  if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
  {
    char errbuf[MYSYS_STRERROR_SIZE];
    my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
             EE_CANTCREATEFILE,
             MYF(0), filename,
             my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno()));
  }
  DBUG_RETURN((FILE*) 0);
} /* my_fopen */
Exemplo n.º 8
0
Arquivo: notes.c Projeto: 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;
}
Exemplo n.º 9
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));
    }
  }
}
Exemplo n.º 10
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;

}
Exemplo n.º 11
0
FILE *my_fopen(const char *filename, int flags, myf MyFlags)
{
  FILE *fd;
  char type[5];
  DBUG_ENTER("my_fopen");
  DBUG_PRINT("my",("Name: '%s'  flags: %d  MyFlags: %d",
		   filename, flags, MyFlags));
  /* 
    if we are not creating, then we need to use my_access to make sure  
    the file exists since Windows doesn't handle files like "com1.sym" 
    very  well 
  */
#ifdef __WIN__
  if (check_if_legal_filename(filename))
  {
    errno= EACCES;
    fd= 0;
  }
  else
#endif
  {
    make_ftype(type,flags);
    fd = fopen(filename, type);
  }
  
  if (fd != 0)
  {
    /*
      The test works if MY_NFILE < 128. The problem is that fileno() is char
      on some OS (SUNOS). Actually the filename save isn't that important
      so we can ignore if this doesn't work.
    */
    if ((uint) fileno(fd) >= my_file_limit)
    {
      thread_safe_increment(my_stream_opened,&THR_LOCK_open);
      DBUG_RETURN(fd);				/* safeguard */
    }
    pthread_mutex_lock(&THR_LOCK_open);
    if ((my_file_info[fileno(fd)].name = (char*)
	 my_strdup(filename,MyFlags)))
    {
      my_stream_opened++;
      my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
      pthread_mutex_unlock(&THR_LOCK_open);
      DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
      DBUG_RETURN(fd);
    }
    pthread_mutex_unlock(&THR_LOCK_open);
    (void) my_fclose(fd,MyFlags);
    my_errno=ENOMEM;
  }
  else
    my_errno=errno;
  DBUG_PRINT("error",("Got error %d on open",my_errno));
  if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
    my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
	     EE_CANTCREATEFILE,
	     MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
  DBUG_RETURN((FILE*) 0);
} /* my_fopen */
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
void DotGraph::WriteToFile(const char* filename) {
	FILE* file = my_fopen(filename, "w");

	ToStream(file);

	my_fclose(file);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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);
}
Exemplo n.º 16
0
Arquivo: cmd4.c Projeto: 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);
}
Exemplo n.º 17
0
/*
 * Read special static pre-designed dungeon levels
 * 
 * Special pre-designed levels are stored in separate
 * files with the filename "server-level-<num>" where num is
 * the level number.  Level files are searched for at runtime
 * and loaded if present.
 */
static errr rd_dungeon_special()
{
	char filename[1024];
	char levelname[32];
	FILE *fhandle;
	FILE *server_handle;
	int i,num_levels,j=0,k=0;
	
	/* Clear all the special levels */
	for(i=0;i<MAX_SPECIAL_LEVELS;i++)
	{
		special_levels[i] = -999;
	}
	
	/* Vanilla Mangand doesn't have special static pre-designed levels */
	if ((!cfg_ironman) || (!cfg_more_towns)) return 0;
	
	num_levels = 0;
	/* k = E/W, J = N/S for wilderness towns */
/*	for(k=0;k<MAX_DEPTH;k++)
	{
	for(j=0;j<MAX_DEPTH;j++)
	{*/
	for(i=0;i<MAX_DEPTH;i++)
	{
		/* build a file name */
		sprintf(levelname,"server.level.%i.%i.%i",k,j,i);
		path_build(filename, 1024, ANGBAND_DIR_SAVE, levelname);
		/* open the file if it exists */
		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(FALSE, 0);
			/* swap the file pointers back */
			file_handle = server_handle;
			/* close the level file */
			my_fclose(fhandle);
			/* we have an arbitrary max number of levels */
			if(num_levels + 1 > MAX_SPECIAL_LEVELS)
			{
				note("Too many special pre-designed level files!");
				break;
			}
			/* add this depth to the special level list */
			special_levels[num_levels++] = i;
		}
	}
/*	}
	}*/
	return 0;
}
Exemplo n.º 18
0
/*!
 * @brief キャラクタダンプを作って BUFに保存
 * @param dumpbuf 伝送内容バッファ
 * @return エラーコード
 */
static errr make_dump(BUF* dumpbuf)
{
	char		buf[1024];
	FILE *fff;
	char file_name[1024];

	/* Open a new file */
	fff = my_fopen_temp(file_name, 1024);
	if (!fff)
	{
#ifdef JP
		msg_format("一時ファイル %s を作成できませんでした。", file_name);
#else
		msg_format("Failed to create temporary file %s.", file_name);
#endif
		msg_print(NULL);
		return 1;
	}

	/* 一旦一時ファイルを作る。通常のダンプ出力と共通化するため。 */
	(void)make_character_dump(fff);

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

	/* Open for read */
	fff = my_fopen(file_name, "r");

	while (fgets(buf, 1024, fff))
	{
		(void)buf_sprintf(dumpbuf, "%s", buf);
	}

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

	/* Remove the file */
	fd_kill(file_name);

	/* Success */
	return (0);
}
Exemplo n.º 19
0
/*
 * Close fff, and report success/failure.
 */
static void my_fclose_wiz(void)
{
	if (ferror(fff) || my_fclose(fff))
	{
		msg_print("Cannot close spoiler file.");
	}
	else
	{
		msg_print("Successfully created a spoiler file.");
	}
}
Exemplo n.º 20
0
static int
match_rhosts_entry(char *path, char *rhost, char *ruser)
{
	MY_FILE	*fp;
	char	buf[512+1];
	char	*luser;
	char	*lhost;
	char	ruserq[512+1];
	char	logb[LOG_BUF_SIZE] = {'\0' } ;

	if ((fp=my_fopen(path, "r")) == NULL) {
		sprintf(logb,
			"open of file %s failed! Need SYSTEM or Everyone read access",
			path);
		log_err(-1, "match_rhosts_entry", logb);
		return (-1);
	}

	sprintf(ruserq, "\"%s\"", ruser);

	while (my_fgets(buf, sizeof(buf), fp) != NULL) {
		buf[strlen(buf)-1] = '\0';

		lhost = strtok((char *)buf, " \t");
		luser = strtok(NULL, " \t");
		sprintf(logb,"match_rhosts_entry: scanning (%s,%s)...", lhost, luser);
		log_event(PBSEVENT_SYSTEM | PBSEVENT_ADMIN | PBSEVENT_FORCE| PBSEVENT_DEBUG, PBS_EVENTCLASS_FILE, LOG_NOTICE, "", logb);
		if( (lhost && strcmpi(lhost, rhost) == 0) && \
		    (luser && \
			(strcmpi(luser, ruser) == 0 ||
			strcmpi(luser, ruserq) == 0))) {
			my_fclose(fp);
			return (1);
		}
	}
	sprintf(logb,"match_rhosts_entry: did not match (%s,%s) in %s", rhost,
		ruser, path);
	log_err(-1, "match_rhosts_entry", logb);
	my_fclose(fp);
	return (0);
}
Exemplo n.º 21
0
FILE *my_fopen(const char *filename, int flags, myf MyFlags)
{
  FILE *fd;
  char type[5];
  DBUG_ENTER("my_fopen");
  DBUG_PRINT("my",("Name: '%s'  flags: %d  MyFlags: %d",
		   filename, flags, MyFlags));

  make_ftype(type,flags);

#ifdef _WIN32
  fd= my_win_fopen(filename, type);
#else
  fd= fopen(filename, type);
#endif
  if (fd != 0)
  {
    /*
      The test works if MY_NFILE < 128. The problem is that fileno() is char
      on some OS (SUNOS). Actually the filename save isn't that important
      so we can ignore if this doesn't work.
    */

    int filedesc= my_fileno(fd);
    if ((uint)filedesc >= my_file_limit)
    {
      thread_safe_increment(my_stream_opened,&THR_LOCK_open);
      DBUG_RETURN(fd);				/* safeguard */
    }
    mysql_mutex_lock(&THR_LOCK_open);
    if ((my_file_info[filedesc].name= (char*)
	 my_strdup(filename,MyFlags)))
    {
      my_stream_opened++;
      my_file_total_opened++;
      my_file_info[filedesc].type= STREAM_BY_FOPEN;
      mysql_mutex_unlock(&THR_LOCK_open);
      DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
      DBUG_RETURN(fd);
    }
    mysql_mutex_unlock(&THR_LOCK_open);
    (void) my_fclose(fd,MyFlags);
    my_errno=ENOMEM;
  }
  else
    my_errno=errno;
  DBUG_PRINT("error",("Got error %d on open",my_errno));
  if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
    my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
	     EE_CANTCREATEFILE,
	     MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
  DBUG_RETURN((FILE*) 0);
} /* my_fopen */
Exemplo n.º 22
0
/* Include a header file or footer file */
void cro_includefile(FILE *outf, Outchoices *od, char *name, char type) {
  FILE *inf;
  char buffer[BLOCKSIZE];
  size_t n;

  if ((inf = my_fopen(name, (type == 'h')?"header file":"footer file")) !=
      NULL) {
    while ((n = fread(buffer, 1, BLOCKSIZE, inf)))  /* single equals */
      fwrite((void *)buffer, 1, n, outf);
    (void)my_fclose(inf, name, (type == 'h')?"header file":"footer file");
  }
}
Exemplo n.º 23
0
void DAC_Buffer_Process_Stereo_S16bit_PhotoFrame()
{
	int i, halfBufferSize = dac_intr.bufferSize >> 1;
	uint32_t *pabuf;
	uint8_t *outbuf;

	if(SOUND_DMA_HALF_TRANS_BB){ // Half
		SOUND_DMA_CLEAR_HALF_TRANS_BB = 1;
		outbuf = (uint8_t*)dac_intr.buff;
		pabuf = (uint32_t*)outbuf;
	} else if(SOUND_DMA_FULL_TRANS_BB) {	// Full
		SOUND_DMA_CLEAR_FULL_TRANS_BB = 1;
		outbuf = (uint8_t*)&dac_intr.buff[halfBufferSize];
		pabuf = (uint32_t*)outbuf;
	}

	my_fread(outbuf, 1, halfBufferSize, dac_intr.fp);
	for(i = 0;i < halfBufferSize >> 2;i += 8){ // signed to unsigned
		pabuf[0] ^= 0x80008000;
		pabuf[1] ^= 0x80008000;
		pabuf[2] ^= 0x80008000;
		pabuf[3] ^= 0x80008000;
		pabuf[4] ^= 0x80008000;
		pabuf[5] ^= 0x80008000;
		pabuf[6] ^= 0x80008000;
		pabuf[7] ^= 0x80008000;
		pabuf += 8;
	}
	dac_intr.sound_reads += halfBufferSize;

	if(dac_intr.sound_reads > (halfBufferSize * 10)){
		AUDIO_OUT_ENABLE;
	}

	if(dac_intr.sound_reads >= dac_intr.contentSize){
		NVIC_InitTypeDef NVIC_InitStructure;

	    AUDIO_OUT_SHUTDOWN;
	    DMA_ITConfig(DMA1_Stream1, DMA_IT_TC | DMA_IT_HT, DISABLE);
	    DMA_Cmd(DMA1_Stream1, DISABLE);

		/* Disable DMA1_Stream1 gloabal Interrupt */
		NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream1_IRQn;
		NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
		NVIC_Init(&NVIC_InitStructure);

		my_fclose(dac_intr.fp);
		dac_intr.fp = '\0';

		dac_intr.comp = 1;
	}
}
Exemplo n.º 24
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);
}
Exemplo n.º 25
0
/*
 * Initialize CHECK_TIME
 */
errr check_time_init(void)
{

#ifdef CHECK_TIME

	FILE *fp;

	char buf[1024];


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

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

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

	/* Assume restrictions */
	check_time_flag = TRUE;

	/* Parse the file */
	while (0 == my_fgets(fp, buf, sizeof(buf)))
	{
		/* Skip comments and blank lines */
		if (!buf[0] || (buf[0] == '#')) continue;

		/* Chop the buffer */
		buf[sizeof(days[0]) - 1] = '\0';

		/* Extract the info */
		if (prefix(buf, "SUN:")) my_strcpy(days[0], buf, sizeof(days[0]));
		if (prefix(buf, "MON:")) my_strcpy(days[1], buf, sizeof(days[1]));
		if (prefix(buf, "TUE:")) my_strcpy(days[2], buf, sizeof(days[2]));
		if (prefix(buf, "WED:")) my_strcpy(days[3], buf, sizeof(days[3]));
		if (prefix(buf, "THU:")) my_strcpy(days[4], buf, sizeof(days[4]));
		if (prefix(buf, "FRI:")) my_strcpy(days[5], buf, sizeof(days[5]));
		if (prefix(buf, "SAT:")) my_strcpy(days[6], buf, sizeof(days[6]));
	}

	/* Close it */
	my_fclose(fp);

#endif /* CHECK_TIME */

	/* Success */
	return (0);
}
Exemplo n.º 26
0
int doc_display_help_aux(cptr file_name, cptr topic, rect_t display)
{
    int     rc = _OK;
    FILE   *fp = NULL;
    char    path[1024];
    char    caption[1024];
    doc_ptr doc = NULL;
    int     top = 0;

    /* Check for file_name#topic from a lazy client */
    if (!topic)
    {
        cptr pos = strchr(file_name, '#');
        if (pos)
        {
            string_ptr name = string_copy_sn(file_name, pos - file_name);
            int        result = doc_display_help_aux(string_buffer(name), pos + 1, display);

            string_free(name);
            return result;
        }
    }

    sprintf(caption, "Help file '%s'", file_name);
    path_build(path, sizeof(path), ANGBAND_DIR_HELP, file_name);
    fp = my_fopen(path, "r");
    if (!fp)
    {
        cmsg_format(TERM_VIOLET, "Cannot open '%s'.", file_name);
        msg_print(NULL);
        return _OK;
    }

    doc = doc_alloc(MIN(80, display.cx));
    doc_read_file(doc, fp);
    my_fclose(fp);

    if (topic)
    {
        doc_pos_t pos = doc_find_bookmark(doc, topic);
        if (doc_pos_is_valid(pos))
            top = pos.y;
    }

    rc = doc_display_aux(doc, caption, top, display);
    doc_free(doc);
    return rc;
}
Exemplo n.º 27
0
Arquivo: luac.c Projeto: jcubic/ToME
/*
 * Compiles src lua source to dest lua bytecode
 * Bytecode is quicker to load as it is preparsed and optimized.
 * This function does NOT understands ToME virtual paths they
 * need to be converted first, this is intentionnal
 */
s32b tome_compile_lua(char *src)
{
	char *split;
	char dest[2048];
	Proto *tf;
	PHYSFS_file *dump;

	/* Clear error state */
	PHYSFS_getLastError();

        /* A new empty lua state */
	compile_lua_state = lua_open(0);

	tf = load(src);

        /* If we dump we need to optimize */
	if (tome_compile_lua_optimizing) luaU_optchunk(tf);

	/* Dump to a file */

	if (tome_compile_lua_stripping) strip(tf);

	/* Make up the destination file .lua => .lb */
	strncpy(dest, src, 2048);
	dest[strlen(dest) - 2] = 'b';
	dest[strlen(dest) - 1] = '\0';

	/* Make sure distination exists */
	split = strrchr(dest, '/');
	*split = '\0';
	PHYSFS_mkdir(dest);
	*split = '/';

	dump = efopen(dest, "wb");
	if (dump == NULL)
		quit("Could not compile lua: error writting");
	PHYSFS_getLastError();
	luaU_dumpchunk_file(tf, dump);
	my_fclose(dump);

	/* Clean up */
/* For a strange reasons this totaly panics lua ... 	lua_close(compile_lua_state); */

	return 0;
}
Exemplo n.º 28
0
static int read_chuukei_prf(cptr prf_name)
{
	char buf[1024];
	FILE *fp;

	path_build(buf, sizeof(buf), ANGBAND_DIR_XTRA, prf_name);
	fp = my_fopen(buf, "r");

	if (!fp) return (-1);

	/* 初期化 */
	server_port = -1;
	server_name[0] = 0;
	browse_delay = DEFAULT_DELAY;

	while (0 == my_fgets(fp, buf, sizeof(buf)))
	{
		/* サーバ名 */
		if (!strncmp(buf, "server:", 7))
		{
			strncpy(server_name, buf + 7, MAX_HOSTNAME - 1);
			server_name[MAX_HOSTNAME - 1] = '\0';
		}

		/* ポート番号 */
		if (!strncmp(buf, "port:", 5))
		{
			server_port = atoi(buf + 5);
		}

		/* ディレイ */
		if (!strncmp(buf, "delay:", 6))
		{
			browse_delay = atoi(buf + 6);
		}
	}

	my_fclose(fp);

	/* prfファイルが完全でない */
	if (server_port == -1 || server_name[0] == 0) return (-1);

	return (0);
}
Exemplo n.º 29
0
uint my_get_large_page_size_int(void)
{
  FILE *f;
  uint size = 0;
  char buf[256];
  DBUG_ENTER("my_get_large_page_size_int");

  if (!(f = my_fopen("/proc/meminfo", O_RDONLY, MYF(MY_WME))))
    goto finish;

  while (fgets(buf, sizeof(buf), f))
    if (sscanf(buf, "Hugepagesize: %u kB", &size))
      break;

  my_fclose(f, MYF(MY_WME));
  
finish:
  DBUG_RETURN(size * 1024);
}
Exemplo n.º 30
0
void mut_do_cmd_knowledge(void)
{
	FILE *fff;
	char file_name[1024];

	/* Open a new file */
	fff = my_fopen_temp(file_name, 1024);

	/* Dump the mutations to file */
	if (fff) mut_dump_file(fff);

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

	/* Display the file contents */
	show_file(TRUE, file_name, T("Mutations", "突然変異"), 0, 0);

	/* Remove the file */
	fd_kill(file_name);
}