コード例 #1
0
ファイル: file.c プロジェクト: Alexander--/samba
static bool test_file_load_save(struct torture_context *tctx)
{
	size_t len;
	char *data;
	TALLOC_CTX *mem_ctx = tctx;
	
	torture_assert(tctx, file_save(TEST_FILENAME, TEST_DATA, strlen(TEST_DATA)),
				   "saving file");

	torture_assert_file_contains_text(tctx, TEST_FILENAME, TEST_DATA, 
								      "file contents");

	data = file_load(TEST_FILENAME, &len, 0, mem_ctx);
	torture_assert(tctx, data, "loading file");

	torture_assert_int_equal(tctx, len, strlen(TEST_DATA), "Length");
	
	torture_assert_mem_equal(tctx, data, TEST_DATA, len, "Contents");

	data = file_load(TEST_FILENAME, &len, 5, mem_ctx);

	torture_assert_int_equal(tctx, len, 5, "Length");

	torture_assert_mem_equal(tctx, data, TEST_DATA, len, "Contents");

	unlink(TEST_FILENAME);
	return true;
}
コード例 #2
0
ファイル: slotshandler.cpp プロジェクト: sebhz/caprice32
void loadSlots() {
   memset(&driveA, 0, sizeof(t_drive)); // clear disk drive A data structure
   file_load(CPC.drvA_file, DSK_A);
   memset(&driveB, 0, sizeof(t_drive)); // clear disk drive B data structure
   file_load(CPC.drvB_file, DSK_B);
   file_load(CPC.tape_file, OTHER);
   file_load(CPC.snap_file, OTHER);
   // Cartridge was loaded by emulator_init if needed
}
コード例 #3
0
ファイル: util_file.c プロジェクト: schidler/flyzjhz-rt-n56u
void *map_file(char *fname, size_t size)
{
    size_t s2 = 0;
    void *p = NULL;
#ifdef HAVE_MMAP
    int fd;
    fd = open(fname, O_RDONLY, 0);
    if (fd == -1) {
        DEBUG(2,("map_file: Failed to load %s - %s\n", fname, strerror(errno)));
        return NULL;
    }
    p = mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0);
    close(fd);
    if (p == MAP_FAILED) {
        DEBUG(1,("map_file: Failed to mmap %s - %s\n", fname, strerror(errno)));
        return NULL;
    }
#endif
    if (!p) {
        p = file_load(fname, &s2, 0);
        if (!p) {
            return NULL;
        }
        if (s2 != size) {
            DEBUG(1,("map_file: incorrect size for %s - got %lu expected %lu\n",
                     fname, (unsigned long)s2, (unsigned long)size));
            SAFE_FREE(p);
            return NULL;
        }
    }
    return p;
}
コード例 #4
0
ファイル: bdplus_config.c プロジェクト: mwgoldsmith/bdplus
static int _load_aes_keys(bdplus_aes_key_t *aes_keys, const char *base)
{
    char *path = str_printf("%s/" AES_KEYS_FILE, base);
    uint8_t *keys;
    uint32_t size = 0;
    uint32_t num_keys, ii;

    if (!path) {
        return -1;
    }

    keys = (uint8_t *)file_load(path, &size);
    X_FREE(path);

    num_keys = size / 16;
    if (num_keys > MAX_AES_KEYS) {
        num_keys = MAX_AES_KEYS;
    }
    if (num_keys * 16 != size) {
        BD_DEBUG(DBG_FILE | DBG_CRIT, "Invalid AES key file size\n");
    }

    for (ii = 0; ii < num_keys; ii++) {
        memcpy(aes_keys[ii].key, keys + 16*ii, 16);
    }

    X_FREE(keys);
    return num_keys > 6 ? (int)num_keys : -1;
}
コード例 #5
0
/*
 * Load specified KLD. If path is omitted, then try to locate it via
 * search path.
 */
int
file_loadkernel(char *filename, int argc, char *argv[])
{
    struct preloaded_file	*fp, *last_file;
    int				err;

    /* 
     * Check if KLD already loaded
     */
    fp = file_findfile(filename, NULL);
    if (fp) {
	command_seterr("warning: KLD '%s' already loaded", filename);
	free(filename);
	return (0);
    }
    for (last_file = preloaded_files; 
	 last_file != NULL && last_file->f_next != NULL;
	 last_file = last_file->f_next)
	;

    do {
	err = file_load(filename, loadaddr, &fp);
	if (err)
	    break;
	fp->f_args = unargv(argc, argv);
	loadaddr = fp->f_addr + fp->f_size;
	file_insert_tail(fp);		/* Add to the list of loaded files */
    } while(0);
    if (err == EFTYPE)
	command_seterr("don't know how to load module '%s'", filename);
    if (err && fp)
	file_discard(fp);
    free(filename);
    return (err);
}
コード例 #6
0
ファイル: casset.c プロジェクト: marioux/Corange
void asset_reload_all() {

  debug("Reloading All Assets...");

  list* asset_names = list_new();

  for(int i = 0; i < asset_dict->size; i++) {
    struct bucket* b = asset_dict->buckets[i];
    while(b != NULL) {
      char* new_name = malloc(strlen(b->key)+1);
      strcpy(new_name, b->key);
      list_push_back(asset_names, new_name);
      b = b->next;
    }
  }

  for(int i = 0; i < asset_names->num_items; i++) {
    file_unload(P(list_get(asset_names, i)));
  }

  for(int i = 0; i < asset_names->num_items; i++) {
    /*
    ** Assets can reload their child assets before we do
    ** So it is important we check before loading again
    */
    if (!file_isloaded(P(list_get(asset_names, i)))) {
      file_load(P(list_get(asset_names, i)));
    }
  }

  list_delete_with(asset_names, free);

  asset_cache_flush();
}
コード例 #7
0
ファイル: conf.c プロジェクト: wwttt2004/torrentkino
void conf_hostname( struct obj_conf *conf, BEN *opts ) {
	BEN *value = NULL;
	char *f = NULL;
	char *p = NULL;
	
	/* Hostname from args */
	value = ben_searchDictStr( opts, "-a" );
	if( value != NULL && ben_str_size( value ) >= 1 ) {
		snprintf( conf->hostname, BUF_SIZE, "%s", (char *)value->v.s->s );
		return;
	} else {
		strncpy( conf->hostname, "bulk.p2p", BUF_OFF1 );
	}

	/* Hostname from file */
	if( ! file_isreg( CONF_HOSTFILE ) ) {
		return;
	}

	f = (char *) file_load( CONF_HOSTFILE, 0, file_size( CONF_HOSTFILE ) );

	if( f == NULL ) {
		return;
	}
		
	if( ( p = strchr( f, '\n')) != NULL ) {
		*p = '\0';
	}

	snprintf( conf->hostname, BUF_SIZE, "%s.p2p", f );

	myfree( f );
}
コード例 #8
0
ファイル: casset.c プロジェクト: marioux/Corange
void folder_load(fpath folder) {

  folder = asset_map_filename(folder);
  debug("Loading Folder: '%s'", folder.ptr);

  DIR* dir = opendir(folder.ptr);
  if (dir == NULL) {
    error("Could not open directory '%s' to load.", folder.ptr);
  }

  struct dirent* ent;
  while ((ent = readdir(dir)) != NULL) {

    if ((strcmp(ent->d_name,".") != 0) &&
        (strcmp(ent->d_name,"..") != 0)) {

      fpath filename = folder;

      // If does not end in "/" then copy it.
      if (folder.ptr[strlen(folder.ptr)-1] != '/') {
        strcat(filename.ptr, "/");
      }

      strcat(filename.ptr, ent->d_name);

      if (!file_isloaded(filename)) {
        file_load(filename);
      }
    }
  }

  closedir(dir);
}
コード例 #9
0
ファイル: casset.c プロジェクト: marioux/Corange
asset_hndl asset_hndl_new_load(fpath path) {
  asset_hndl ah = asset_hndl_new(path);
  if (!file_isloaded(ah.path)) {
    file_load(ah.path);
  }
  return ah;
}
コード例 #10
0
ファイル: main.c プロジェクト: andreiw/iQUIK
static quik_err_t
load_image(path_t *path,
           vaddr_t *where,
           length_t *len)
{
   quik_err_t err;

   printk("Loading '%P'\n", path);
   err = file_len(path, len);
   if (err != ERR_NONE) {
      printk("Error fetching size for '%P': %r\n",
             path, err);
      return err;
   }

   *where = (vaddr_t) prom_claim_chunk((void *) *where, *len);
   if (*where == (vaddr_t) -1) {
      printk("Couldn't claim 0x%x bytes to load '%P'\n", *len, path);
      return ERR_NO_MEM;
   }

   err = file_load(path, (void *) *where);
   if (err != ERR_NONE) {
      printk("Error loading '%P': %r\n", path, err);
      prom_release((void *) *where, *len);
      return err;
   }

   return ERR_NONE;
}
コード例 #11
0
ファイル: stats-module.c プロジェクト: hariskar/mpdcron
/* Module functions */
static int
init(const struct mpdcron_config *conf, GKeyFile *fd)
{
	GError *error;
	g_debug("Initializing");

	/* Load configuration */
	if (file_load(conf, fd) < 0)
		return MPDCRON_INIT_FAILURE;

	/* Initialize database */
	error = NULL;
	if (!db_init(globalconf.dbpath, true, false, &error)) {
		g_critical("Failed to initialize database `%s': %s",
				globalconf.dbpath, error->message);
		g_error_free(error);
		file_cleanup();
		return MPDCRON_INIT_FAILURE;
	}

	/* Initialize, bind and start the server */
	server_init();
	for (unsigned int i = 0; globalconf.addrs[i] != NULL; i++) {
		if (strncmp(globalconf.addrs[i], "any", 4) == 0)
			server_bind(NULL, globalconf.port);
		else if (globalconf.addrs[i][0] == '/')
			server_bind(globalconf.addrs[i], -1);
		else
			server_bind(globalconf.addrs[i], globalconf.port);
	}
	server_start();

	timer = g_timer_new();
	return MPDCRON_INIT_SUCCESS;
}
コード例 #12
0
ファイル: pbonebook.c プロジェクト: nhlinhmisfit/CandC-
void main()
{
	while(1)
	{
		system("cls");
		printf("*** MENU ***\n");
		printf("1. INPUT\n");
		printf("2. PRINT\n");
		printf("   21. SORT PRINT(by name)\n");
		printf("3. SEARCH\n");
		printf("4. MODIFY\n");
		printf("5. DELETE\n");
		printf("6. FILE SAVE\n");
		printf("7. FILE LOAD\n");
		printf("8. EXIT\n");
		printf("CHOICE [  ]\b\b\b");

		switch(getnum())
		{
		case 1 : input(); break;
		case 2 : print(); break;
		case 3 : search(0); break;
		case 4 : modify_del(1); break;
		case 5 : modify_del(2); break;
		case 6 : file_save(); break;
		case 7 : file_load(); break;
		case 8 : end();
		case 21 : sort_print(); break;
		default : printf("Please choice again...\n");
			getch();
		}
	}
}
コード例 #13
0
ファイル: params.c プロジェクト: pombredanne/cliffs
static myFILE *OpenConfFile( char *FileName )
  /* ------------------------------------------------------------------------ **
   * Open a configuration file.
   *
   *  Input:  FileName  - The pathname of the config file to be opened.
   *
   *  Output: A pointer of type (char **) to the lines of the file
   *
   * ------------------------------------------------------------------------ **
   */
  {
  char *func = "params.c:OpenConfFile() -";
  extern BOOL in_client;
  int lvl = in_client?1:0;
  myFILE *ret;

  ret = (myFILE *)malloc(sizeof(*ret));
  if (!ret) return NULL;

  ret->buf = file_load(FileName, &ret->size);
  if( NULL == ret->buf )
    {
    DEBUG( lvl,
      ("%s Unable to open configuration file \"%s\":\n\t%s\n",
      func, FileName, strerror(errno)) );
    free(ret);
    return NULL;
    }

  ret->p = ret->buf;
  return( ret );
  } /* OpenConfFile */
コード例 #14
0
ファイル: jsubsys.c プロジェクト: Artanejp/XM7-for-SDL
/*
 *      日本語サブCPU
 *      初期化
 */
BOOL FASTCALL
jsubsys_init(void)
{
	/*
	 * 一度、全てクリア
	 */
	jsubrom = NULL;
	jdicrom = NULL;
	jsub_sram = NULL;
	jsub_available = TRUE;
	jsub_enable = TRUE;
	jsub_address = 0;

	/*
	 * メモリ確保
	 */
	jsubrom = (BYTE *) malloc(0x4000);
	if (jsubrom == NULL) {
		return FALSE;
	}
	jdicrom = (BYTE *) malloc(0x40000);
	if (jdicrom == NULL) {
		return FALSE;
	}
	jsub_sram = (BYTE *) malloc(0x2000);
	if (jsub_sram == NULL) {
		return FALSE;
	}

	/*
	 * ROMファイル読み込み
	 */
	if (!file_load(JSUBSYS_ROM, jsubrom, 0x4000)) {
		jsub_available = FALSE;
	}
	if (!file_load(DICT_ROM, jdicrom, 0x40000)) {
		jsub_available = FALSE;
	}

	/*
	 * メモリアクセス関数設定
	 */
	jsubcpu.readmem = jsubmem_readb;
	jsubcpu.writemem = jsubmem_writeb;

	return TRUE;
}
コード例 #15
0
ファイル: vsuti.cpp プロジェクト: svilendobrev/svd_bin
int file_load( const char* fname, void *buff, int size )
{
  FILE *f = fopen( fname, "rb" );
  if (!f) return 1;
  int res = file_load( f, buff, size );
  fclose( f );
  return res;
};
コード例 #16
0
ファイル: page.c プロジェクト: henryxlau/OS
bool page_load(struct page *p, void *fp_addr)
{
	lock_acquire(&load);
	p->kpage = get_frame(PAL_USER);

	lock_release(&load);
	set_page_frame(p->kpage, p);

	pin_frame(p->kpage);

	if(p->kpage == NULL)
	{
		unpin_frame(p->kpage);
		return false;
	}

	bool temp = true;

	if(p->type == S)
	{
		temp = swap_load(p->kpage, p);
	}
	else if(p->type == F)
	{
		temp = file_load(p->kpage, p);
	}
	else
	{
		temp = zero_load(p->kpage);
	}

	if(!temp)
	{
		unpin_frame(p->kpage);
		return false;
	}

	pagedir_clear_page(p->dir, fp_addr);
	if(!pagedir_set_page(p->dir, fp_addr, p->kpage, p->write))
	{
		unpin_frame(p->kpage);
		return false;
	}
	else if(!pagedir_get_page(p->dir, fp_addr))
	{
		unpin_frame(p->kpage);
		return false;
	}

	p->load = true;

	pagedir_set_dirty(p->dir, fp_addr, false);
	pagedir_set_accessed(p->dir, fp_addr, true);

	unpin_frame(p->kpage);

	return true;
}
コード例 #17
0
//open browsing view when open is clicked in menubar
void ExampleWindow::on_menu_folder_open()
{
		Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN);
		dialog.set_transient_for(*this);
		//Add response buttons the the dialog:
		dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
		dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
		//Add filters, so that only certain file types can be selected:
		Glib::RefPtr<Gtk::FileFilter> filter_text = Gtk::FileFilter::create();
		filter_text->set_name("Text files");
		filter_text->add_mime_type("text/plain");
		dialog.add_filter(filter_text);
		Glib::RefPtr<Gtk::FileFilter> filter_cpp = Gtk::FileFilter::create();
		filter_cpp->set_name("C/C++ files");
		filter_cpp->add_mime_type("text/x-c");
		filter_cpp->add_mime_type("text/x-c++");
		filter_cpp->add_mime_type("text/x-c-header");
		dialog.add_filter(filter_cpp);
		Glib::RefPtr<Gtk::FileFilter> filter_any = Gtk::FileFilter::create();
		filter_any->set_name("Any files");
		filter_any->add_pattern("*");
		dialog.add_filter(filter_any);
		//Show the dialog and wait for a user response:
		int result = dialog.run();
		//Handle the response:
		switch(result)
		{
				case(Gtk::RESPONSE_OK):
						{
								std::cout << "Open clicked." << std::endl;
								//Notice that this is a std::string, not a Glib::ustring.
								std::string filename = dialog.get_filename();
								std::cout << "File selected: " << filename << std::endl;
								std::ifstream file_load(filename.c_str());
								if(file_load.is_open()){
										std::string _temp ;
										Glib::ustring file_text = "" ;
										while(std::getline(file_load,_temp)){
												file_text += _temp+'\n' ;
										}
										editor_buffer->set_text(file_text) ;
										m_Notebook.set_current_page(1);
								}
								break;
						}
				case(Gtk::RESPONSE_CANCEL):
						{
								std::cout << "Cancel clicked." << std::endl;
								break;
						}
				default:
						{
								std::cout << "Unexpected button clicked." << std::endl;
								break;
						}
		}
}
コード例 #18
0
ファイル: bdplus_config.c プロジェクト: mwgoldsmith/bdplus
static int _load_ram(bdplus_ram_t **p, const char *base, uint32_t address, const char *file)
{
    bdplus_ram_t *ram;

    if (!*p) {
        *p = calloc(1, sizeof(bdplus_ram_t));
        if (!*p) {
            return 0;
        }
    }
    ram = *p;

    void *tmp = ram->area;
    ram->area = realloc(ram->area, (ram->num_area + 1) * sizeof(*ram->area));
    if (!ram->area) {
        X_FREE(tmp);
        BD_DEBUG(DBG_CRIT, "out of memory\n");
        return 0;
    }

    memset(&ram->area[ram->num_area], 0, sizeof(ram->area[ram->num_area]));
    ram->area[ram->num_area].start_address = address;

    if (!strcmp(file, "PSR")) {
        ram->area[ram->num_area].type = MEM_TYPE_PSR;
        BD_DEBUG(DBG_BDPLUS, "mapped PSR register file to 0x%x\n", address);

    } else if (!strcmp(file, "GPR")) {
        ram->area[ram->num_area].type = MEM_TYPE_PSR;
        BD_DEBUG(DBG_BDPLUS, "mapped GPR register file to 0x%x\n", address);

    } else {
        /* load from file */
        char *path = str_printf("%s/%s", base, file);
        if (!path) {
            return 0;
        }

        ram->area[ram->num_area].memory = file_load(path, &ram->area[ram->num_area].size);
        ram->area[ram->num_area].mem    = ram->area[ram->num_area].memory;
        X_FREE(path);

        if (!ram->area[ram->num_area].mem) {
            return 0;
        }

        BD_DEBUG(DBG_BDPLUS, "mapped %d bytes from %s to 0x%x\n",
                 ram->area[ram->num_area].size, file, address);
    }

    ram->num_area++;

    return 1;
}
コード例 #19
0
ファイル: main.c プロジェクト: hwansunkim/openann
int main(int argc, char **argv)
{
	int i, j, count, nocount, ret;
	double 	*data, *ptr_d;
	double  *dataset, *ptr_ds;
	int 	size;
	int	input_size, output_size, numofdata, data_size;
	int key;
	data = (double*)malloc(sizeof(double)*1024*20000);
	ret = file_load(argv[1], data, &size);
	numofdata = (int)data[0];
	input_size = (int)data[1];
	output_size = (int)data[2];
	data_size = input_size + output_size;
	dataset = (double*)malloc(sizeof(double)*data_size*numofdata);
	ptr_d = &data[3];
	ptr_ds = dataset;
	memcpy(ptr_ds, ptr_d, sizeof(double)*data_size);
	ptr_d += data_size;
	ptr_ds += data_size;
	count = 1;
	nocount = 0;
	for(i = 1; i < numofdata; i++)
	{
		key = 1;
		for(j = 0; j < count; j++)
		{
			if(diff(data_size, ptr_d, dataset+data_size*j))
			{
				key = 0;
				nocount++;
			}
		}	
		if(key)
		{
			memcpy(ptr_ds, ptr_d, sizeof(double)*data_size);
			ptr_ds += data_size;
			count++;
		}
		ptr_d += data_size;
	}
	#if 1
	printf("%d %d %d\n",count, input_size, output_size);
	for(j=0; j < count; j++)
	{
		for(i=0; i < input_size; i++)
		{
			printf("%g ",dataset[j*data_size + i]);
		}	
			printf("\n%g\n",dataset[j*data_size + i]);
	}
#endif
	return 0;
}
コード例 #20
0
ファイル: gui_dialog.c プロジェクト: Bhattiasif/gdis
static void file_name_activate(GtkTreeView *treeview, GtkTreePath *treepath)
{
gchar *text;
GtkTreeIter iter;
GtkTreeModel *treemodel;

treemodel = gtk_tree_view_get_model(treeview);
gtk_tree_model_get_iter(treemodel, &iter, treepath);
gtk_tree_model_get(treemodel, &iter, FILE_PATH, &text, -1);
file_load(text, NULL);
g_free(text);
}
コード例 #21
0
ファイル: rom.c プロジェクト: rchyla/9tcfg
void
maprom_enable(BYTE *path)
{
	BYTE *rombuf;
	ULONG romsize;
	UBYTE r1, r2;

	r1 = cfgreg_read(CFG_R1_OFFSET);
	r2 = cfgreg_read(CFG_R2_OFFSET);

	/* do some sanity checks first */	
	if (r1 & CFG_R1_SHADOWROM) {
		printf("Cannot use MAPROM if Shadow ROM enabled. Please disable Shadow ROM and reboot first!\n");
		return;
	}

	if (r2 & CFG_R2_MAPROM_STATUS) {
		printf("Cannot load new ROM if MAPROM currently active. Please disable MAPROM and reboot first!\n");
		return;
	}

	if (r2 & CFG_R2_68KMODE_STATUS) {
		printf("Cannot use MAPROM if running on 68000! Please reenable 68020 and reboot first.\n");
		return;
	}

#ifdef DEBUG
	printf("DEBUG: will load ROM from %s\n", path);
#endif /* DEBUG */

	romsize = file_size(path);

#ifdef DEBUG
	printf("DEBUG: m'kay so apparanetly loaded ROM has size: %lx\n", romsize);
#endif /* DEBUG */

	rombuf = (char*) malloc(romsize);

#ifdef DEBUG
	printf("DEBUG: allocated %x bytes at address %p, ready to load data\n", (unsigned int) romsize, (void*) rombuf);
#endif /* DEBUG */

	file_load(path, rombuf, romsize);

	rom_copy_self(rombuf, romsize);
	/*rom_copy_bank(rombuf, romsize);*/

	cfgreg_set(CFG_R1_OFFSET, CFG_R1_MAPROM); 

	free(rombuf);
	printf("Your Amiga should be restarted now...\n");
}
コード例 #22
0
ファイル: casset.c プロジェクト: marioux/Corange
void asset_reload_type_id(type_id type) {

  debug("Reloading Assets of type '%s'...", type_id_name(type));

  fpath ext;

  /* Find the file extension for given type */
  for(int i=0; i < num_asset_handlers; i++) {
    asset_handler handler = asset_handlers[i];
    if (handler.type == type) {
      strcpy(ext.ptr, handler.extension);
      break;
    }
  }

  list* asset_names = list_new();

  for(int i = 0; i < asset_dict->size; i++) {
    struct bucket* b = asset_dict->buckets[i];
    while(b != NULL) {
      fpath bucket_ext;
      SDL_PathFileExtension(bucket_ext.ptr, b->key);

      if (strcmp(bucket_ext.ptr, ext.ptr) == 0) {
        char* new_name = malloc(strlen(b->key)+1);
        strcpy(new_name, b->key);
        list_push_back(asset_names, new_name);
      }

      b = b->next;
    }
  }

  for(int i = 0; i < asset_names->num_items; i++) {
    file_unload(P(list_get(asset_names, i)));
  }

  for(int i = 0; i < asset_names->num_items; i++) {
    /*
    ** Assets can reload their child assets before we do
    ** So it is important we check before loading again
    */
    if (!file_isloaded(P(list_get(asset_names, i)))) {
      file_load(P(list_get(asset_names, i)));
    }
  }

  list_delete_with(asset_names, free);

  asset_cache_flush();
}
コード例 #23
0
ファイル: scrobbler-module.c プロジェクト: sdelafond/mpdcron
/* Module functions */
static int
init(G_GNUC_UNUSED const struct mpdcron_config *conf, GKeyFile *fd)
{
	/* Parse configuration */
	if (file_load(fd) < 0)
		return MPDCRON_INIT_FAILURE;
	if (http_client_init() < 0)
		return MPDCRON_INIT_FAILURE;
	as_init(file_config.scrobblers);

	timer = g_timer_new();
	save_source_id = g_timeout_add_seconds(file_config.journal_interval, timer_save_journal, NULL);

	return MPDCRON_INIT_SUCCESS;
}
コード例 #24
0
int main(int argc, char *argv[])
{

	if(argc < 3) {
		fprintf(stderr, "Usage:\n%s fontdesc.def outfile.iff\n", argv[0]);
		return 0;
	}

	def = file_new(argv[1], 0);
	if(!def) {
		fprintf(stderr, "Can't find font definition '%s'\n", argv[1]);
		return 1;
	}
	file_load(def);
	if(!def->buf) {
		file_free(def);
		fprintf(stderr, "Not enough memory to load %s\n", argv[1]);
		return 2;
	}

	if(!parse_def()) {
		file_free(def);
		return 1;
	}

	font = iff_new(argv[2], MAKE_ID('F','O','N','T'));
	if(!font) {
		file_free(def);
	}

	iff_newchunk(font, MAKE_ID('N','A','M','E'));
	iff_writechunkdata(font, name, strlen(name)+1);
	iff_endchunk(font);

	iff_newchunk(font, MAKE_ID('F','I','L','E'));
	iff_writechunkdata(font, file, strlen(file)+1);
	iff_endchunk(font);

	iff_newchunk(font, MAKE_ID('A','U','T','H'));
	iff_writechunkdata(font, author, strlen(author)+1);
	iff_endchunk(font);

	parse_letters();

	iff_close(font);
	file_free(def);
	return 0;
}
コード例 #25
0
ファイル: gui.c プロジェクト: uyjulian/tilp_and_gfm
GLADE_CB void
on_open_clicked                        (GtkToolButton   *toolbutton,
                                        gpointer         user_data)
{
	gchar *fn;

	if(user_data == NULL)
	{
		if(GFMFile.contents.group || GFMFile.contents.tigroup)
		{
			int result = msgbox_two(MSGBOX_YESNO, _("Do you want to save previous file?"));
			if(result == MSGBOX_YES)
				on_save_clicked(toolbutton,user_data);
		}

		fn = (char *)create_fsel(inst_paths.home_dir, "", "*.73?;*.82?;*.83?;*.8X?;*.85?;*.86?;*.89?;*.92?;*.9x?;*.V2?;*.tig", FALSE);
		if(fn == NULL)
			return;
	}
	else
	{
		// command line
		fn = (char *)user_data;
	}

	if(tifiles_file_is_tigroup(fn))
		GFMFile.type = TIFILE_TIGROUP;
	else if(tifiles_file_is_regular(fn))
		GFMFile.type = TIFILE_GROUP;
	else
		return;

	file_load(fn);

	g_free(GFMFile.filename);
	GFMFile.filename = g_strdup(fn);

	enable_save(FALSE);
	enable_tree(TRUE);

	ctree_refresh();
	labels_refresh();

	g_free(inst_paths.home_dir);
	inst_paths.home_dir = g_path_get_dirname(GFMFile.filename);
}
コード例 #26
0
ファイル: bdplus_config.c プロジェクト: mwgoldsmith/bdplus
static int _load_dev_discovery(bdplus_dev_t *dev, const char *base)
{
    unsigned ii;

    for (ii = 0; ii < MAX_DEV_DISCOVERY; ii++) {
        char *path = str_printf("%s/" DEV_DISCOVERY_FILE, base, ii + 1);
        if (!path) {
            break;
        }
        dev[ii].mem = (uint8_t *)file_load(path, &dev[ii].size);
        X_FREE(path);
        if (!dev[ii].mem) {
            break;
        }
    }

    return ii >= 5 ? 0 : -1;
}
コード例 #27
0
ファイル: bdplus_config.c プロジェクト: mwgoldsmith/bdplus
static int _load_ecdsa_keys(bdplus_ecdsa_key_t *ecdsa_keys, const char *base)
{
    const char *p;
    char *path = str_printf("%s/" ECDSA_KEYS_FILE, base);
    char *cfg;
    int   num_ecdsa_keys = 0;

    if (!path) {
        return -1;
    }

    cfg = file_load(path, NULL);
    X_FREE(path);

    /* parse keys */
    p = cfg;
    while (*p) {
        char key_d[41], key_Qx[41], key_Qy[41];

        p = str_skip_white(p);
        if (*p == '#') {
            /* comment */
        }
        else if (3 == sscanf(p, "%40s %40s %40s", key_d, key_Qx, key_Qy)) {
            if (num_ecdsa_keys >= MAX_ECDSA_KEYS) {
                BD_DEBUG(DBG_FILE | DBG_CRIT, "Too many ECDSA keys\n");
                break;
            }
            memcpy(ecdsa_keys[num_ecdsa_keys].d,  key_d, 40);
            memcpy(ecdsa_keys[num_ecdsa_keys].Qx, key_Qx, 40);
            memcpy(ecdsa_keys[num_ecdsa_keys].Qy, key_Qy, 40);
            num_ecdsa_keys++;
        }
        else {
            BD_DEBUG(DBG_FILE | DBG_CRIT, "invalid line in config file: %4.4s...\n", p);
        }
        p = str_next_line(p);
    }

    X_FREE(cfg);
    return num_ecdsa_keys > 0 ? 0 : -1;
}
コード例 #28
0
ファイル: bdplus_config.c プロジェクト: mwgoldsmith/bdplus
static int _load_memory(bdplus_ram_t **ram, const char *base)
{
    const char *p;
    char *path;
    char *cfg = NULL;

    path = str_printf("%s/" MEMORY_MAP_FILE, base);
    if (path) {
        cfg = file_load(path, NULL);
        X_FREE(path);
    }

    if (!cfg) {
        BD_DEBUG(DBG_FILE | DBG_CRIT, "Error loading memory map file '"MEMORY_MAP_FILE"'\n");
        return -1;
    }

    /* parse memory map file */

    p = cfg;
    while (*p) {
        uint32_t address;
        char name[64];

        p = str_skip_white(p);

        if (*p == '#') {
            /* comment */
        }
        else if (2 == sscanf(p, "%x %63s", &address, name)) {
            name[sizeof(name) - 1] = 0;
            _load_ram(ram, base, address, name);
        }
        else {
            BD_DEBUG(DBG_FILE | DBG_CRIT, "invalid line in config file: %4.4s...\n", p);
        }
        p = str_next_line(p);
    }

    X_FREE(cfg);
    return 0;
}
コード例 #29
0
ファイル: obj.cpp プロジェクト: KarlZylinski/skugga
LoadedMesh obj_load(Allocator* alloc, const char* filename)
{
    LoadedFile lf = file_load(alloc, filename);

    if (!lf.valid)
        return {false};

    ParsedData pd = parse(alloc, lf.file.data, lf.file.size);
    Mesh m = {};
    m.vertices = dynamic_array_create<Vertex>(alloc);
    m.indices = dynamic_array_create<unsigned>(alloc);

    for (unsigned i = 0; i < pd.faces.num; ++i)
    {
        const ParsedFace& f = pd.faces[i];
        add_vertex_to_mesh(&m, pd.vertices[f.v1], pd.normals[f.n1], pd.uvs[f.u1], {1.0f, 0.0f, 1.0f, 1.0f});
        add_vertex_to_mesh(&m, pd.vertices[f.v2], pd.normals[f.n2], pd.uvs[f.u2], {1.0f, 0.0f, 1.0f, 1.0f});
        add_vertex_to_mesh(&m, pd.vertices[f.v3], pd.normals[f.n3], pd.uvs[f.u3], {1.0f, 0.0f, 1.0f, 1.0f});
    }

    return {true, m};
}
コード例 #30
0
ファイル: params.c プロジェクト: jameshilliard/WECB-BH-GPL
static myFILE *OpenConfFile( const char *FileName )
{
	const char *func = "params.c:OpenConfFile() -";
	int lvl = lp_is_in_client() ? 1 : 0;
	myFILE *ret;

	ret = SMB_MALLOC_P(myFILE);
	if (!ret)
		return NULL;

	ret->buf = file_load(FileName, &ret->size, 0);
	if( NULL == ret->buf ) {
		DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n",
			func, FileName, strerror(errno)) );
		SAFE_FREE(ret);
		return NULL;
	}

	ret->p = ret->buf;
	ret->end_section_p = NULL;
	return( ret );
}