示例#1
0
bool load_vector_from_file(t_int_vec& v, const std::string& file, uint8_t num_bytes=1, uint8_t max_int_width=64)
{
    if ((uint8_t)0 == num_bytes) {  // if byte size is variable read int_vector<0> from file
        if (t_int_vec::fixed_int_width==0) {
            return load_from_file(v, file);
        } else {
            int_vector<t_int_vec::fixed_int_width-t_int_vec::fixed_int_width> v0;
            bool success = load_from_file(v0, file);
            v.resize(v0.size());
            for (size_t i=0; i<v0.size(); ++i) {
                v[i] = v0[i];
            }
            return success;
        }
    } else if (num_bytes == 'd') {
        uint64_t x = 0, max_x = 0;
        isfstream in(file);
        if (!in) {
            return false;
        } else {
            std::vector<uint64_t> tmp;
            while (in >> x) {
                tmp.push_back(x);
                max_x = std::max(x, max_x);
            }
            v.width(bits::hi(max_x)+1); v.resize(tmp.size());
            for (size_t i=0; i < tmp.size(); ++i) {
                v[i] = tmp[i];
            }
            return true;
        }
    } else {
示例#2
0
int main(int argc, char *argv[])
{
  if (argc >= 2) {
    FILE *fp = fopen(argv[1], "r");
    load_from_file(fp);
    fclose(fp);
  } else {
    printf("Loading query from STDIN\n");
    load_from_file(stdin);
  }

  start(argc, argv, NULL);

  start_recognition(loaded_query, loaded_unknown);

  register_cb_recognized(result);

  while (!done) {
    usleep(100000);
  }

  abort_recognition();

  stop();
  return 0;
}
示例#3
0
文件: kvconfig.cpp 项目: dulton/d3100
	KVConfig(const char *fname)
	{
		fname_ = fname;
		fname_session_ = fname_ + ".session";

		load_from_file(fname_);
		load_from_file(fname_session_);
	}
示例#4
0
void KVConfig::reload()
{
    {
        ost::MutexLock al(cs_);
        kvs_.clear();
    }
    
    load_from_file(filename_.c_str());
    
    std::string sess_fname = filename_ + ".session";
    load_from_file(sess_fname.c_str());
}
示例#5
0
/*
 * Load a stored sequence
 */
void partMover::sequence_load(GtkFileChooser *button, partMover *currentPart )
{
  gchar* filePath = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(button));
  if (filePath == NULL) return;
  load_from_file(filePath, currentPart);
  return;
}
示例#6
0
文件: data.c 项目: anarsoul/libfprint
/** \ingroup print_data
 * Loads a previously stored print from disk. The print must have been saved
 * earlier using the fp_print_data_save() function.
 *
 * A return code of -ENOENT indicates that the fingerprint requested could not
 * be found. Other error codes (both positive and negative) are possible for
 * obscure error conditions (e.g. corruption).
 *
 * \param dev the device you are loading the print for
 * \param finger the finger of the file you are loading
 * \param data output location to put the corresponding stored print. Must be
 * freed with fp_print_data_free() after use.
 * \returns 0 on success, non-zero on error
 */
API_EXPORTED int fp_print_data_load(struct fp_dev *dev,
	enum fp_finger finger, struct fp_print_data **data)
{
	gchar *path;
	struct fp_print_data *fdata;
	int r;

	if (!base_store)
		storage_setup();

	path = get_path_to_print(dev, finger);
	r = load_from_file(path, &fdata);
	g_free(path);
	if (r)
		return r;

	if (!fp_dev_supports_print_data(dev, fdata)) {
		fp_err("print data is not compatible!");
		fp_print_data_free(fdata);
		return -EINVAL;
	}

	*data = fdata;
	return 0;
}
示例#7
0
	  void PARTICLEOBJ::load(HANDLE hFile) 
	  {
		  load_object_basics(this);
		  load_property("mute",P_INT,&mute);
    	  load_property("palette-file",P_STRING,palettefile);
		  if (strcmp(palettefile,"none"))
		  {
			char szFileName[MAX_PATH] = "";
			strcpy(szFileName,GLOBAL.resourcepath);
			strcat(szFileName,"PALETTES\\");
			strcat(szFileName,palettefile);
			if (!load_from_file(szFileName, cols, sizeof(cols) ))
			{    
				report_error(szFileName);
				report_error("Could not load Color Palette ");
			}
			else
			{
				for (t=0;t<128;t++)
				{
					colors[t][0]=(float)((cols[t]&0xff)/256.0);
					colors[t][1]=(float)(((cols[t]>>8)&0xff)/256.0);
					colors[t][2]=(float)((cols[t]>>16)/256.0);
				}

			}
		  } 
示例#8
0
static SCM fetch_node(SCM smob, SCM args) {
	MAKE_NODE * node;
	SCM payload;
	char *buf;
	node = (MAKE_NODE *)SCM_SMOB_DATA(smob);
	scm_lock_mutex(node->mutex);
	if (!node->dirty) {
		payload = node->payload;
		scm_unlock_mutex(node->mutex);
		return payload;
		}
	//log_msg("REGENERATE %08x\n", (unsigned long)smob);
	node->dirty = 0;
	switch (node->type) {
	case TYPE_DATUM: break;
	case TYPE_FILE:
		buf = load_from_file(node->filepath);
		if (buf != NULL)
			node->payload = scm_take_locale_string(buf);
		else node->payload = SCM_BOOL_F;
		break;
	case TYPE_CHAIN:
		node->payload = scm_apply_0(node->callback, args);
		break;
		}
	payload = node->payload;
	scm_unlock_mutex(node->mutex);
	scm_remember_upto_here_2(smob, args);
	scm_remember_upto_here_1(payload);
	return payload;
	}
示例#9
0
int main(int c, char *v[]){

	string pattern;

	if (c < 2) {
		printf ("Usage: testprog <pattern>\n");
		return 1;
	}

	FRLZSI t2(pattern);
	load_from_file(t2,"test");
	//Pattern einlesen + suchen
	fstream dat(v[1], ios::in);
	while(!dat.eof()){
		getline(dat,pattern);
		if(!pattern.empty()){
			cout << "Pattern: " << pattern.size() << endl;
			t2.search_pattern(pattern);
			vector<pair<int,int>> projekt_treffer;
			t2.return_treffer(projekt_treffer);
			cout << "Treffer: " << projekt_treffer.size() << endl;
		}
	}
	dat.close();
	return EXIT_SUCCESS;
}
示例#10
0
int
samdb_load(samdb_args_t *args) {
	FILE *file;

	if (sam_db_connect(args->con) < 0) {
		fprintf(stderr, "Can't connect to %s database.\n",
		    args->fsname);
		return (-1);
	}

	if (inode_load) {
		/* Read inodes, loading each inode using callback function */
		if (read_inodes(args->con->mount_point,
		    load_inode, args->con) < 0) {
			fprintf(stderr, "Error reading inodes\n");
			return (-1);
		}
	} else {
		if (loadfile == NULL) {
			file = stdin;
		} else if ((file = fopen(loadfile, "r")) == NULL) {
			fprintf(stderr, "Can't open %s for read.\n", loadfile);
			return (-1);
		}

		if (load_from_file(args->con, file) < 0) {
			fprintf(stderr, "Error loading database.\n");
		}
		fclose(file);
	}

	return (0);
}
示例#11
0
int main(int argc, char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    if (argc < 3) {
        // LCOV_EXCL_START
        cout << "Usage: " << argv[0] << " test_file temp_file [in-memory]" << endl;
        cout << " (1) Generates a WT out of test_file; stores it in temp_file." << endl;
        cout << "     If `in-memory` is specified, the in-memory construction is tested." << endl;
        cout << " (2) Performs tests." << endl;
        cout << " (3) Deletes temp_file." << endl;
        return 1;
        // LCOV_EXCL_STOP
    }
    test_file = argv[1];
    temp_file = argv[2];
    in_memory = argc > 3;
    if (in_memory) {
        int_vector<> data;
        load_from_file(data, test_file);
        test_file = ram_file_name(test_file);
        store_to_file(data, test_file);
        temp_file = ram_file_name(temp_file);
    }
    return RUN_ALL_TESTS();
}
示例#12
0
Tile::Tile(const char *filename) {
	data = NULL;
	width = 0;
	height = 0;

	status = load_from_file(filename);
}
示例#13
0
/* Load config */
int config68_load(const char * appname)
{
  appname = appname ? appname : config68_def_name;
  return config68_use_registry
    ? load_from_registry(appname)
    : load_from_file(appname)
    ;
}
示例#14
0
int main(int argc,char **argv) {
#if (MATRIX_TEST)
	matrix_test();
#elif (MATRIX_UTIL_TEST)
	matrix_util_test();
#else
	//unsigned int layer_sizes[] = {400, 25, 10};
	unsigned int num_layers = 3;
	unsigned int num_labels = 10;
	double lambda = 0.8;
	
	/*
	if(argc < 2)
	{
		printf("need exactly 1 argument for vector length\n");
		return 0;
	}
    unsigned int iteration_number = atoi(argv[1]);
   	*/

	unsigned int iteration_number = 100;

	matrix_list_t* theta = matrix_list_constructor(2);
	//theta->matrix_list[0] = matrix_random(25, 401, .12);
	//theta->matrix_list[1] = matrix_random(10, 26, .12);
	theta->matrix_list[0] = load_from_file("theta1.csv", 25, 401);
	theta->matrix_list[1] = load_from_file("theta2.csv", 10, 26);
	
	assert(theta->num == 2);
	assert(theta->matrix_list[0]->rows == 25 && theta->matrix_list[0]->cols == 401);
	assert(theta->matrix_list[1]->rows == 10 && theta->matrix_list[1]->cols == 26);
	/*
	matrix_t* X = load_from_file("X.csv", 5000, 400);
	matrix_t* tmp = load_from_file("y.csv", 5000, 1);
	matrix_t* y = matrix_transpose(tmp);
	free_matrix(tmp);
	*/
	gradient_descent(&theta, num_layers, num_labels, lambda, iteration_number);

	//free_matrix(X);
	//free_matrix(y);
	free_matrix_list(theta);
#endif
	return 1;
}
	Recorders::Recorders(std::string path) {
		
		if (!filesystem::exist(path.c_str()))
			throw("Error: Missing input file!");

		load_from_file(path);

		Recorders::Recorders();
	}
示例#16
0
    const sf::Image& ImageLoader::load_from_file(const std::string& file_name)
    {
        auto* image = load_from_file(file_name, std::nothrow);
        if (!image)
        {
            throw ImageLoadError(file_name);
        }

        return *image;
    }
示例#17
0
int KVConfig::reload()
{
    kvs_.clear();

    load_from_file(filename_.c_str());

//  std::string tmp = filename_ + ".session";
//  load_from_file(tmp.c_str());
    return 0;
}
示例#18
0
void IconFactory::add(const Gtk::StockID& stock_id, const std::string& filename) {
	Glib::RefPtr<Gdk::Pixbuf> pixbuf = load_from_file(filename);
	if(!pixbuf) {
		std::cerr << "unable to load file " << filename << std::endl;
		return;
	}
	Gtk::IconSet* set = new Gtk::IconSet(pixbuf);
	m_iconset.push_back(set);
	Gtk::IconFactory::add(stock_id, *set);
}
示例#19
0
/*
 * delete device
 */
void
delete_device(int force)
{
	struct node *np,*next,*end;

	if (device_ring == NULL)
		return;
	end = device_ring->prev;
	for(np = device_ring; ;np = next) {
		next = np->next;
		if (force || !(NODE_STATUS(np) & USBMGR_ST_ACTIVE)) {
			char path[PATH_MAX+1];

			if (NODE_TYPE(np) & USBMGR_TYPE_SCRIPT) {
				if (check_vendor_file(np,path,BUILD_SCRIPT) == INVALID) {
					search_class_file(np,path,BUILD_SCRIPT);
				}
				if (load_from_file(np,path,SCRIPT_STOP) == 0)
					syslog(LOG_INFO,mesg[MSG_STOP],path);
			}
			if ((check_vendor_file(np,path,BUILD_MODULE) == INVALID)  &&
				(search_class_file(np,path,BUILD_MODULE) == INVALID)) {
				beep(INVALID);
				DPRINTF(LOG_DEBUG,"not identify device -> beep fail");
			} else {
				beep(GOOD);
				DPRINTF(LOG_DEBUG,"identify device -> beep good");
				load_from_file(np,path,MODULE_UNLOAD);
			}
			delete_node_data_link(&device_ring,np);
		} else {
			NODE_STATUS(np) &= ~USBMGR_ST_ACTIVE;
		}
		if (np == end)
			break;
	}
#ifdef	DEBUG
	if (force)
		printf("device_ring %p\n",device_ring);
#endif
}
zz::map::map( const char* filename )
    : _max( INT_MIN ), _mins( ), _width( -1 ), _height( -1 ), _player_one( -1, -1 ), _player_two( -1, -1 ), _locations( ) {
    FILE* f = fopen( filename, "r" );
    if( f ) {
        load_from_file( f );
        fclose( f );
    } else {
        fprintf( stderr, "could not open map: %s\n", filename );
        fflush( stderr );
        exit( EXIT_FAILURE );
    }
}
示例#21
0
void Game::reset_level_commit()
{
	level_reset_requested = false;
	entities.clear();
	entities_to_activate.clear();
	entities_to_add.clear();
	actions.clear();
	auto ilosc_zyc = gracz ? gracz->life_count() : 3;
	auto pl = std::make_shared<Samolot>(Zespolona(320, 0), ilosc_zyc);
	gracz = pl;
	entities.push_back(pl);
	load_from_file();
}
示例#22
0
    rank_bm25(collection& col)
    {
        load_from_file(doc_lengths,col.file_map[KEY_DOCLEN]);
        num_docs = doc_lengths.size();
        {
            sdsl::int_vector_mapper<> text(col.file_map[KEY_TEXT]);
            num_terms = text.size() - num_docs;
        }
        avg_doc_len = (double)num_terms / (double)num_docs;

        LOG(INFO) << "num docs : " << num_docs;
        LOG(INFO) << "avg doc len : " << avg_doc_len;
    }
示例#23
0
int load_dic(Dic *dic)
{
	int r=0;


	r = load_from_file(&(dic->ins32), &(dic->sz32), "lib/instructions_32bits.dic");

	if(r != 0)
		return r;

	// on range le dictionnaire (règle le problème d'opcodes ayant le même début)
	qsort(dic->ins32, dic->sz32, sizeof(Instruction), cmp_ins);


	r =  load_from_file(&(dic->ins16), &(dic->sz16), "lib/instructions_16bits.dic");

	qsort(dic->ins16, dic->sz16, sizeof(Instruction), cmp_ins);


	// On copie les mnémoniques
	strcpy(dic->states_tab[0], "EQ");
	strcpy(dic->states_tab[1], "NE");
	strcpy(dic->states_tab[2], "HS");
	strcpy(dic->states_tab[3], "LO");
	strcpy(dic->states_tab[4], "MI");
	strcpy(dic->states_tab[5], "PL");
	strcpy(dic->states_tab[6], "VS");
	strcpy(dic->states_tab[7], "VC");
	strcpy(dic->states_tab[8], "HI");
	strcpy(dic->states_tab[9], "LS");
	strcpy(dic->states_tab[10], "GE");
	strcpy(dic->states_tab[11], "LT");
	strcpy(dic->states_tab[12], "GT");
	strcpy(dic->states_tab[13], "LE");
	strcpy(dic->states_tab[14], "AL");


	return r;
}
int main(int argc, char **argv) {
    char * fname = NULL;
    int c;

    pid1 = pid2 = -1;
    sock = -1;

    while ((c = getopt(argc, argv, "hus:f:")) != -1) {
        switch (c) {
            case 'f':
                fname = optarg;
                break;
            case 's':
                sock = atoi(optarg);
                if (sock <= 2 || sock > 1024)
                    usage("bad descriptor number for sock");
                break;
            case 'h':
            case 'u':
                usage(NULL);
            default:
                usage("unknown argument");
        }
    }

    if (argc == 1)
        usage(NULL);

    if (optind < argc && fname)
        usage("can't load shellcode both from argument and file");
    
    if (!(optind < argc) && !fname)
        usage("please provide shellcode via either argument or file");

    if (optind < argc) {
        copy_from_argument(argv[optind]);
    }
    else {
        load_from_file(fname);
    }

    //create socket if needed
    if (sock != -1) {
        int created_sock = create_sock(sock);
        printf("Created socket %d\n", created_sock);
    }

    run_shellcode(buf);
    return 100;
}
示例#25
0
文件: makelang.c 项目: c10ud/CHDK
void load_conditions(char *file)
{
    lang_conditions = 0;

    char *buf = load_from_file(file);

    if (!buf)
        return;

    lang_conditions = malloc(sizeof(char*) * (GUI_LANG_ITEMS+1));
    memset(lang_conditions, 0, sizeof(char*) * (GUI_LANG_ITEMS+1));

    char *p, *e;
    char name[500];
    char index[20];
    char cond[200];
    int i;

    e = buf;
    while (e && *e)
    {
        p = e;
        if (strncmp(p, "#define", 7) == 0)
        {
            p = next_token(p+7, name);
            if (p)
            {
                p = next_token(p, index);
                if (p)
                {
                    p = next_token(p, cond);
                    if (p && (strcmp(cond, "//CONDITIONAL:") == 0))
                    {
                        p = next_token(p, cond);
                        if (p)
                        {
                            i = atoi(index);
                            lang_conditions[i] = malloc(strlen(cond)+1);
                            strcpy(lang_conditions[i], cond);
                        }
                    }
                }
            }
        }
        e = strpbrk(e, "\n");
        if (e) e++;
    }

    free(buf);
}
示例#26
0
/**
 * Load all kind of PEM encoded credentials.
 */
static void *pem_load(credential_type_t type, int subtype, va_list args)
{
	char *file = NULL;
	int fd = -1;
	chunk_t pem = chunk_empty;
	identification_t *subject = NULL;
	int flags = 0;

	while (TRUE)
	{
		switch (va_arg(args, builder_part_t))
		{
			case BUILD_FROM_FILE:
				file = va_arg(args, char*);
				continue;
			case BUILD_FROM_FD:
				fd = va_arg(args, int);
				continue;
			case BUILD_BLOB_PEM:
				pem = va_arg(args, chunk_t);
				continue;
			case BUILD_SUBJECT:
				subject = va_arg(args, identification_t*);
				continue;
			case BUILD_X509_FLAG:
				flags = va_arg(args, int);
				continue;
			case BUILD_END:
				break;
			default:
				return NULL;
		}
		break;
	}

	if (pem.len)
	{
		return load_from_blob(pem, type, subtype, subject, flags);
	}
	if (file)
	{
		return load_from_file(file, type, subtype, subject, flags);
	}
	if (fd != -1)
	{
		return load_from_fd(fd, type, subtype, subject, flags);
	}
	return NULL;
}
示例#27
0
文件: main.c 项目: amendiola/sngrep
/**
 * @brief Main function logic
 *
 * Parse command line options and start running threads
 *
 * @note There are no params actually... if you supply one 
 *    param, I will assume we are running offline mode with
 *    a pcap file. Otherwise the args will be passed to ngrep
 *    without any type of validation.
 *
 */
int
main(int argc, char* argv[])
{

    int ret;
    //! ngrep thread attributes
    pthread_attr_t attr;
    //! ngrep running thread
    pthread_t exec_t;

    // Initialize configuration options
    init_options();

    // Parse arguments.. I mean..
    if (argc < 2) {
        // No arguments!
        usage(argv[0]);
        return 1;
    } else if (argc == 2) {
        // Show offline mode in ui
        set_option_value("running.mode", "Offline");
        set_option_value("running.file", argv[1]);

        // Assume Offline mode with pcap file
        if (load_from_file(argv[1]) != 0) {
            fprintf(stderr, "Error loading data from pcap file %s\n", argv[1]);
            return 1;
        }
    } else {
        // Show online mode in ui
        set_option_value("running.mode", "Online");

        // Assume online mode, launch ngrep in a thread
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        if (pthread_create(&exec_t, &attr, (void *) online_capture, argv)) {
            fprintf(stderr, "Unable to create Exec Thread!\n");
            return 1;
        }
        pthread_attr_destroy(&attr);
    }

    // Initialize interface
    // This is a blocking call. Interface have user action loops.
    init_interface();
    // Leaving!
    return ret;
}
示例#28
0
void SqliteDatabase::loadDatabase(const path &dbname)
{
    if (isLoaded())
        return;

    close();

    LOG_TRACE(logger, "Opening database: " << dbname);

    if (read_only)
        db = load_from_file_to_memory(dbname.string());
    else
        db = load_from_file(dbname.string(), read_only);

    name = dbname.string();
    fullName = dbname;
}
示例#29
0
文件: toy.cpp 项目: DawidK1/AiRRepo
Toy::Toy(int id, float price){
    if(_counter == 0){
        load_from_file();
    }

    if((id >= -1) && (id < _toylist.current_size()))
        _id = id;
    else
        _id = -1;

    if(price > 0)
        _price = price;
    else
        _price = 0;

    _counter ++;
}
示例#30
0
static alpm_pkghash_t *scan_for_targets(alpm_pkghash_t *cache, int dirfd, DIR *dirp,
                                        alpm_list_t *targets, const char *arch)
{
    const struct dirent *dp;

    while ((dp = readdir(dirp))) {
        if (dp->d_type != DT_REG && dp->d_type != DT_UNKNOWN)
            continue;

        struct pkg *pkg = load_from_file(dirfd, dp->d_name, arch);
        if (!pkg)
            continue;

        if (targets == NULL || match_targets(pkg, targets))
            cache = pkgcache_add(cache, pkg);
    }

    return cache;
}