Ejemplo n.º 1
0
void Database::open(const char* filename) {
	this->close();
	
	// Get index filename
	size_t filename_len = strlen(filename);
	index_filename = new char[filename_len + 5];
	memcpy(index_filename, filename, filename_len);
	memcpy(&index_filename[filename_len], ".idx", 5);
	
	Driver* drv = Driver::getInstance();
	drv->open(filename);
	
	this->files.clear();
	
	FILE* idx = fopen(index_filename, "rb");
	if(idx) {
		unsigned int num_indexes = 0;
		unsigned int key_len = 0;
		char* key;
		
		fread((unsigned char*)&num_indexes, 1, sizeof(unsigned int), idx);
		
		while(num_indexes-- > 0) {
			fread((unsigned char*)&key_len, 1, sizeof(unsigned int), idx);
			key = (char*)malloc(key_len + 1);
			fread(key, 1, key_len, idx);
			key[key_len] = 0;
			this->files.insert(std::pair<string, File*>(string(key), read_file_info(idx)));
			free(key);
		}
		
		fclose(idx);
	}
}
Ejemplo n.º 2
0
Archivo: fat.c Proyecto: joshwyant/myos
// Copies the whole file to memory. Returns whether succeeded.
int read_file(const char* filename, void* buffer)
{
    if (!read_file_info(filename)) return 0;
    int cluster = file_info.cluster_low;
    void* tbuffer = kmalloc(cluster_size);
    void* tb; // so that tbuffer is not overwritten
    int bytes_written = 0, i;
    while (cluster < 0xFFF8)
    {
        tb = tbuffer;
        if (!read_cluster(cluster, &tb)) { kfree(tbuffer); return 0; };
        // TODO: use kmcpy (not yet implemented) instead?
        for (i = 0; (i < cluster_size) && (bytes_written < file_info.file_size); i++, bytes_written++)
            ((char*)buffer)[bytes_written] = ((char*)tbuffer)[i];
        cluster = next_cluster(cluster);
    }
    kfree(tbuffer);
    return 1;
}
Ejemplo n.º 3
0
main()
#endif
{
	FILE			*fp = stdin;	  /* File pointer, default stdin */
	CRITICALS		*tuples;
	int				i;
	int				n;
	CUBE_INFO		*p;

	printf("\ntuples - version %1.2f\n\n", VERSION_NUM);

#ifndef NO_CMD_LINE
	/* Check the command line and open file if required */
	command_line(&fp,argc, argv, &n);
#else
	/* Read command info from standard input */
	command_input(&fp, &n);
#endif

	/* Read in info from the file, setting up Fsa and so on... */
	switch (read_file_info(fp)) {
		case FORMAT_ERROR:
			ERROR(FORMAT);
		case NOT_A_GEN:
			ERROR(GEN_ERR);
	}
	fclose(fp);	/* No more reading required */

	tuples = find_n_criticals(n);
	printf("Number of Critical %d-tuples = %d\n\n", n, tuples->num);

	for (i=0; i < tuples->num; i++) {
		printword(stdout, tuples->info[i]->word);
		printf("\t");
		for (p = tuples->info[i]->vert; p != NULL; p = p->next)
			printf("[%d,%d] ", p->pos, p->len);
		printf("\n");
	}
	/* Clean up */
	delete_criticals(tuples);
	return 0;
}
Ejemplo n.º 4
0
Archivo: fat.c Proyecto: joshwyant/myos
int file_open(char *filename, FileStream *fs)
{
    if (!read_file_info(filename))
    {
        fs->data = 0;
        fs->position = 0;
        fs->filesize = 0;
        return 0;
    }
    fs->filesize = file_info.file_size;
    fs->position = 0;
    fs->data = kmalloc(sizeof(struct fsdata));
    fs->data->buffer = kmalloc(cluster_size);
    //const int clusterstacksize = 4;
    //fs->data->clusterstack = kmalloc(clusterstacksize*sizeof(unsigned));
    //fs->data->clusterstacksize = clusterstacksize;
    fs->data->firstcluster = file_info.cluster_low|(fat_type == TFAT32 ? (file_info.cluster_high<<16) : 0);
    fs->data->currentcluster = fs->data->firstcluster;
    fs->data->stack_index = 0;
    void* buffer = fs->data->buffer;
    read_cluster(fs->data->firstcluster, &buffer);
}
Ejemplo n.º 5
0
Archivo: zipk.cpp Proyecto: wangch/zipk
static int btn_click0(Button* btn) {
	OPENFILENAME ofn;       // common dialog box structure
	wchar_t szFile[260];       // buffer for file name

	// Initialize OPENFILENAME
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
   ofn.hwndOwner = g_lv.pw;
	ofn.lpstrFile = szFile;
	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
	// use the contents of szFile to initialize itself.
	ofn.lpstrFile[0] = L'\0';
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = L"zip file\0*.zip\0";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	// Display the Open dialog box. 
	if (::GetOpenFileName(&ofn) == TRUE) {
      std::string path = utf8util::UTF8FromUTF16(ofn.lpstrFile);
      unzClose(g_lv.unz);
      delete g_lv.root;
      g_lv.root = new node;
      g_lv.n = g_lv.root;
      unzFile uf = unzOpen(path.c_str());
      if (!uf) {
         ::MessageBox(0, L"zip 文件错误", L"错误", 0);
         return -1;
      }
      read_file_info(uf);
   }
   ::SendMessage(g_lv.lv, LVM_SETVIEW, LV_VIEW_ICON, 0);
   return 0;
}
Ejemplo n.º 6
0
Archivo: fat.c Proyecto: joshwyant/myos
int file_exists(const char* filename)
{
    return (read_file_info(filename));
}
Ejemplo n.º 7
0
Archivo: fat.c Proyecto: joshwyant/myos
unsigned int file_size(const char* filename)
{
    if (!read_file_info(filename)) return 0;
    return file_info.file_size;
}
Ejemplo n.º 8
0
main()
#endif
{
	FILE			*fp = stdin;	  /* File pointer, default stdin */
	CRITICALS		*tuples, *lower_dim_tuples;
	int				i, temp;
	BOUNDARY		**boundary;
	CUBE			*cube;
	int				n, num_rows, num_cols;
	MATRIX			matrix, tmatrix;

	printf("\ncmat - version %1.2f\n\n", VERSION_NUM);

#ifndef NO_CMD_LINE
	/* Check the command line and open file if required */
	command_line(&fp,argc, argv, &n);
#else
	/* Read command info from standard input */
	command_input(&fp, &n);
#endif

	/* Read in info from the file, setting up Fsa and so on... */
	switch (read_file_info(fp)) {
		case FORMAT_ERROR:
			ERROR(FORMAT);
		case NOT_A_GEN:
			ERROR(GEN_ERR);
	}
	fclose(fp);	/* No more reading required */

	tuples = find_n_criticals(n);
	/* remove_inverse_criticals(&tuples);  We are ignoring inverse tuples */

	/* Calc boundaries and store in an array */
	boundary = NEW(BOUNDARY *, tuples->num);

	for (i = 0; i < tuples->num; i++) {
		boundary[i] = calc_bound(cube =
					create_n_cube(tuples->info[i]->word,
					tuples->info[i]->vert, n), TRIVIAL | RETAIN_INV_TUPLES);
					/* We are ignoring inverse tuples */
		delete_cube(cube);
	}

	lower_dim_tuples = find_n_criticals(n-1);
	/* remove_inverse_criticals(&lower_dim_tuples);  Ignoring inverse tuples */

	num_rows = tuples->num;
	/* Create the matrix */
	matrix = make_matrix_n(boundary, lower_dim_tuples, &num_rows);
	num_cols = lower_dim_tuples->num;

	/* It is often useful to have rows and columns the other way */
	/* Get transpose, and swap rows and cols */
	tmatrix = transpose(matrix, num_cols, num_rows);
	temp = num_rows;
	num_rows = num_cols;
	num_cols = temp;

	/* Display....for now */
	printf("\nMatrix: rows = %d, cols = %d\n\n", num_rows, num_cols);
	show_matrix(stdout, tmatrix, num_cols, num_rows, 20);

	/*printf("\nMatrix after Gaussian Elimination...\n");
	gaussian_elim(matrix, num_cols, num_rows);
	show_matrix(stdout, matrix, num_cols, num_rows);

	rank_criticals_n = count_non_zero_rows(matrix, num_cols, num_rows);*/

	/* Clean up */
	for (i=0; i < tuples->num - Num_gens; i++)
	delete_boundary(boundary[i]);
	free(boundary);
	delete_criticals(tuples);
	delete_criticals(lower_dim_tuples);
	
	delete_matrix(matrix, num_cols);
	delete_matrix(tmatrix, num_rows);

	return 0;
}
Ejemplo n.º 9
0
static GwyContainer*
quesant_load(const gchar *filename,
             G_GNUC_UNUSED GwyRunType mode,
             GError **error)
{
    GwyContainer *container = NULL;
    guchar *buffer = NULL;
    gsize size = 0;
    GError *err = NULL;
    GwySIUnit *units = NULL;
    gint32 power10;
    FileInfo info;
    int row, col;
    GwyDataField *dfield;
    gdouble multiplier;
    const guint16 *p;
    gdouble *d;

    if (!gwy_file_get_contents(filename, &buffer, &size, &err)) {
        err_GET_FILE_CONTENTS(error, &err);
        return NULL;
    }

    if (size <= HEADER_SIZE) {
        gwy_file_abandon_contents(buffer, size, NULL);
        err_TOO_SHORT(error);
        return NULL;
    }

    if (!read_file_info(buffer, size, &info, error)) {
        gwy_file_abandon_contents(buffer, size, NULL);
        return NULL;
    }

    // create units and datafield
    units = gwy_si_unit_new_parse("um", &power10);
    dfield = gwy_data_field_new(info.img_res, info.img_res, 
                                info.real_size * pow10(power10),
                                info.real_size * pow10(power10),
                                FALSE);
    // set units for XY axes
    gwy_data_field_set_si_unit_xy(dfield, units);
    g_object_unref(units);
    // set units for Z axis
    units = gwy_si_unit_new_parse("um", &power10);
    gwy_data_field_set_si_unit_z(dfield, units);
    g_object_unref(units);

    multiplier = info.z_scale * pow10(power10);
    p = info.image_data;
    d = gwy_data_field_get_data(dfield);
    // values are stored in unsigned int16 type
    for (row = 0; row < info.img_res; row++) {
        for (col = 0; col < info.img_res; col++) {
            d[row*info.img_res + col] = GUINT16_FROM_LE(*p) * multiplier;
            p++;
        }
    }

    // create container
    container = gwy_container_new();
    // put datafield into container
    gwy_container_set_object_by_name(container, "/0/data", dfield);
    g_object_unref(dfield);
    gwy_app_channel_title_fall_back(container, 0);
    gwy_file_channel_import_log_add(container, 0, NULL, filename);

    gwy_file_abandon_contents(buffer, size, NULL);
    return container;
}
Ejemplo n.º 10
0
int
main(int argc, char **argv)
{
    const unsigned char *build_file = ".build";
    const unsigned char *version_file = "version.c";
    const unsigned char *versions_file = "db/versions";
    const unsigned char *checksum_prefix = "db/info-";
    unsigned char full_version[1024];
    unsigned char version_string[1024];
    int build = 0;
    struct verdb *latest = NULL;

    version_string[0] = 0;
    read_verdb(versions_file);
    if (verdb_u <= 0) {
        fprintf(stderr, "no latest version info\n");
        exit(1);
    }
    latest = &verdb[verdb_u - 1];
    snprintf(full_version, sizeof(full_version), "%s.%d", latest->version, latest->patch);

    if (argc == 2 && !strcmp(argv[1], "new-minor")) {
        new_minor_version(versions_file, checksum_prefix, NULL);
        exit(0);
    }
    if (argc == 3 && !strcmp(argv[1], "new-major")) {
        new_minor_version(versions_file, checksum_prefix, argv[2]);
        exit(0);
    }

    int changed_flag = 0;
    unsigned char rev_id[1024];
    rev_id[0] = 0;
    if (get_file_type(".git") == FILE_DIR) {
        if (!strcmp(latest->id, "tagged")) {
            unsigned char full_version[1024];
            snprintf(full_version, sizeof(full_version), "%s.%d", latest->version, latest->patch);
            //fprintf(stderr, "Full version: %s\n", full_version);
            unsigned char version_rev_id[1024];
            read_git_commit_id_by_version(version_rev_id, sizeof(version_rev_id), full_version);
            //fprintf(stderr, "Commit ID: %s\n", version_rev_id);
            latest->id = strdup(version_rev_id);
        }

        read_git_status(rev_id, sizeof(rev_id), &changed_flag);
        if (changed_flag < 0) exit(1);
        if (!changed_flag && !strcmp(latest->id, rev_id)) {
            // the version exactly
            snprintf(version_string, sizeof(version_string), "%s", full_version);
            write_build(build_file, 0);
        } else if (!changed_flag) {
            // some SVN rev exactly
            snprintf(version_string, sizeof(version_string), "%s+ (GIT %s)", full_version, rev_id);
            write_build(build_file, 0);
        } else if (!strcmp(latest->id, rev_id)) {
            // some changed version
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            sprintf(version_string, "%s #%d", full_version, build);
        } else {
            // some SVN changed revision
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            snprintf(version_string, sizeof(version_string), "%s+ (GIT %s) #%d", full_version, rev_id, build);
        }
    } else if (get_file_type(".svn") == FILE_DIR) {
        read_svn_status(rev_id, sizeof(rev_id), &changed_flag);
        if (changed_flag < 0) exit(1);
        //printf("changed flag: %d, id: %s\n", changed_flag, rev_id);
        if (!changed_flag && !strcmp(latest->id, rev_id)) {
            // the version exactly
            snprintf(version_string, sizeof(version_string), "%s", full_version);
            write_build(build_file, 0);
        } else if (!changed_flag) {
            // some SVN rev exactly
            snprintf(version_string, sizeof(version_string), "%s+ (SVN r%s)", full_version, rev_id);
            write_build(build_file, 0);
        } else if (!strcmp(latest->id, rev_id)) {
            // some changed version
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            sprintf(version_string, "%s #%d", full_version, build);
        } else {
            // some SVN changed revision
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            snprintf(version_string, sizeof(version_string), "%s+ (SVN r%s) #%d", full_version, rev_id, build);
        }
    } else {
        unsigned char checksum_file[1024];
        snprintf(checksum_file, sizeof(checksum_file), "%s%s", checksum_prefix, full_version);
        if (read_file_info(checksum_file) < 0 || file_info_u <= 0) {
            // no data to compare
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            sprintf(version_string, "%s #%d", full_version, build);
        } else if (has_checksum_changed()) {
            read_build(build_file, &build);
            build++;
            write_build(build_file, build);
            sprintf(version_string, "%s #%d", full_version, build);
        } else {
            snprintf(version_string, sizeof(version_string), "%s", full_version);
            write_build(build_file, 0);
        }
    }

    if (version_string[0]) {
        write_output(version_file, 0, version_string);
    }

    return 0;
}