Beispiel #1
0
void
run_gnuplot (int argc, char *argv[])
{
  char  *plot_filename;
  char  *data_filename;
  FILE  *fp;
  int   i;
     
  plot_filename = (char *) (*__gmp_allocate_func)
    (strlen (option_gnuplot_basename) + 20);
  data_filename = (char *) (*__gmp_allocate_func)
    (strlen (option_gnuplot_basename) + 20);
      
  sprintf (plot_filename, "%s.gnuplot", option_gnuplot_basename);
  sprintf (data_filename, "%s.data",    option_gnuplot_basename);

  fp = fopen_for_write (plot_filename);

  fprintf (fp, "# Generated with:\n");
  fprintf (fp, "#");
  for (i = 0; i < argc; i++)
    fprintf (fp, " %s", argv[i]);
  fprintf (fp, "\n");
  fprintf (fp, "\n");

  fprintf (fp, "reset\n");

  /* Putting the key at the top left is usually good, and you can change it
     interactively if it's not. */
  fprintf (fp, "set key left\n");

  /* designed to make it possible to see crossovers easily */
  fprintf (fp, "set data style lines\n");

  fprintf (fp, "plot ");
  for (i = 0; i < num_choices; i++)
    {
      fprintf (fp, " \"%s\" using 1:%d", data_filename, i+2);
      fprintf (fp, " title \"%s\"", choice[i].name);

      if (i != num_choices-1)
        fprintf (fp, ", \\");
      fprintf (fp, "\n");
    }

  fprintf (fp, "load \"-\"\n");
  fclose_written (fp, plot_filename);

  fp = fopen_for_write (data_filename);

  /* Unbuffered so you can see where the program was up to if it crashes or
     you kill it. */
  setbuf (fp, NULL);

  run_all (fp);
  fclose_written (fp, data_filename);
}
Beispiel #2
0
int logger_main(int argc UNUSED_PARAM, char **argv)
{
	char *str_p, *str_t;
	int opt;
	int i = 0;
	FILE *f = NULL;

	/* Fill out the name string early (may be overwritten later) */
	str_t = uid2uname_utoa(geteuid());

	/* Parse any options */
	opt = getopt32(argv, "p:st:c", &str_p, &str_t);

	if (opt & 0x2) /* -s */
		i |= LOG_PERROR;
	if (opt & 0x8) { /* -c */
		f = fopen_for_write(DEV_CONSOLE);
		if (!f)
			bb_error_msg("can't open console: %d %s\n", errno, strerror(errno));
	}
	//if (opt & 0x4) /* -t */
	openlog(str_t, i, 0);
	i = LOG_USER | LOG_WARNING;
	if (opt & 0x1) /* -p */
		i = pencode(str_p);

	argv += optind;
	if (!argv[0]) {
		while (fgets(strbuf, COMMON_BUFSIZE, stdin)) {
			if (strbuf[0]
			 && NOT_LONE_CHAR(strbuf, '\n')
			) {
				/* Neither "" nor "\n" */
				syslog(i, "%s", strbuf);
				if (f)
					fprintf(f, "%s", strbuf);
			}
		}
	} else {
		char *message = NULL;
		int len = 0;
		int pos = 0;
		do {
			len += strlen(*argv) + 1;
			message = xrealloc(message, len + 1);
			sprintf(message + pos, " %s", *argv),
			pos = len;
		} while (*++argv);
		syslog(i, "%s", message + 1); /* skip leading " " */
		if (f)
			fprintf(f, "%s", message + 1);
	}

	closelog();
	if (f)
		fclose(f);
	return EXIT_SUCCESS;
}
Beispiel #3
0
static int write_str_to_file(const char *fname, const char *str)
{
	FILE *fp = fopen_for_write(fname);
	if (!fp)
		return 1;
	fputs(str, fp);
	fclose(fp);
	return 0;
}
Beispiel #4
0
UserStream::UserStream(const char* filename, bool load) : 
fpr(NULL), 
fpw(NULL)
{
	if(load)
		fpr = r3d_open(filename, "rb");
	else
		fpw = fopen_for_write(filename, "wb");
}
Beispiel #5
0
void CGameRewards::ExportDefaultRewards()
{
	const char* fname = "@rewards.txt";
	FILE* f = fopen_for_write(fname, "wt");
	for(int i=0; i<RWD_MAX_REWARD_ID; i++)
	{
		const rwd_s& rwd = GetRewardData(i);
		if(!rwd.IsSet) continue;
		fprintf(f, "\tSetReward(%d, \"%s\", %d, %d, %d, %d, %d, %d);\n",
			i, 
			rwd.Name.c_str(), 
			rwd.GD_CQ, rwd.HP_CQ,
			rwd.GD_DM, rwd.HP_DM,
			rwd.GD_SB, rwd.HP_SB);
	}
	fclose(f);

	ShellExecute(NULL, "open", "@rewards.txt", "", "", SW_SHOW);
	MessageBox(NULL, "ExportDefaultRewards success", "ExportDefaultRewards", MB_OK);
	TerminateProcess(r3d_CurrentProcess, 0);
}
Beispiel #6
0
static void save_input_to_file(void)
{
	const char *msg = "";
	char *current_line;
	unsigned i;
	FILE *fp;

	print_statusline("Log file: ");
	current_line = less_gets(sizeof("Log file: ")-1);
	if (current_line[0]) {
		fp = fopen_for_write(current_line);
		if (!fp) {
			msg = "Error opening log file";
			goto ret;
		}
		for (i = 0; i <= max_fline; i++)
			fprintf(fp, "%s\n", flines[i]);
		fclose(fp);
		msg = "Done";
	}
 ret:
	print_statusline(msg);
	free(current_line);
}
Beispiel #7
0
FileSerialStream::FileSerialStream(const char *fileName)
: writtenBytes(0)
, f(fopen_for_write(fileName, "wb"))
{

}
static errcode_t test_open(const char *name, int flags, io_channel *channel)
{
	io_channel	io = NULL;
	struct test_private_data *data = NULL;
	errcode_t	retval;
	char		*value;

	if (name == 0)
		return EXT2_ET_BAD_DEVICE_NAME;
	retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
	if (retval)
		return retval;
	memset(io, 0, sizeof(struct struct_io_channel));
	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
	retval = ext2fs_get_mem(sizeof(struct test_private_data), &data);
	if (retval) {
		retval = EXT2_ET_NO_MEMORY;
		goto cleanup;
	}
	io->manager = test_io_manager;
	retval = ext2fs_get_mem(strlen(name)+1, &io->name);
	if (retval)
		goto cleanup;

	strcpy(io->name, name);
	io->private_data = data;
	io->block_size = 1024;
	io->read_error = 0;
	io->write_error = 0;
	io->refcount = 1;

	memset(data, 0, sizeof(struct test_private_data));
	data->magic = EXT2_ET_MAGIC_TEST_IO_CHANNEL;
	if (test_io_backing_manager) {
		retval = test_io_backing_manager->open(name, flags,
						       &data->real);
		if (retval)
			goto cleanup;
	} else
		data->real = 0;
	data->read_blk =	test_io_cb_read_blk;
	data->write_blk =	test_io_cb_write_blk;
	data->set_blksize =	test_io_cb_set_blksize;
	data->write_byte =	test_io_cb_write_byte;

	data->outfile = NULL;
	if ((value = getenv("TEST_IO_LOGFILE")) != NULL)
		data->outfile = fopen_for_write(value);
	if (!data->outfile)
		data->outfile = stderr;

	data->flags = 0;
	if ((value = getenv("TEST_IO_FLAGS")) != NULL)
		data->flags = strtoul(value, NULL, 0);

	data->block = 0;
	if ((value = getenv("TEST_IO_BLOCK")) != NULL)
		data->block = strtoul(value, NULL, 0);

	data->read_abort_count = 0;
	if ((value = getenv("TEST_IO_READ_ABORT")) != NULL)
		data->read_abort_count = strtoul(value, NULL, 0);

	data->write_abort_count = 0;
	if ((value = getenv("TEST_IO_WRITE_ABORT")) != NULL)
		data->write_abort_count = strtoul(value, NULL, 0);

	*channel = io;
	return 0;

cleanup:
	ext2fs_free_mem(&io);
	ext2fs_free_mem(&data);
	return retval;
}