예제 #1
0
int
__cole_print_tree_indirentry(COLEDIRENT * cde, void *info,
                             COLERRNO * colerrno)
{
/*
 * ATTENTION: if you modify this function so it modifies colerrno:
 *      Modify colerrno comment in the functions that call it,
 *      ie. cole_print_tree().
 */
    char *entry_name;
    int32_t level;
    int32_t i;

    level = *((int32_t *) info);
    for (i = 0; i < level; i++) {
        if (i == level - 1)
            printf("\\--");
        else
            printf("|  ");
    }

    if (cole_direntry_isdir(cde))
        printf("DIR ");
    else if (cole_direntry_isfile(cde))
        printf("FILE");
    else
        printf("????");
    printf(" %7lu", (unsigned long) cole_direntry_getsize(cde));
    printf(" %08x-%08x %08x-%08x",
           (unsigned int)cole_direntry_getdays1(cde),
           (unsigned int)cole_direntry_getsec1(cde),
           (unsigned int)cole_direntry_getdays2(cde), 
           (unsigned int)cole_direntry_getsec2(cde));
    entry_name = cole_direntry_getname(cde);
    if (!isprint(entry_name[0]))
        printf(" '\\x%02x%s'\n", (unsigned int) entry_name[0], entry_name + 1);
    else
        printf(" '%s'\n", entry_name);

    return 0;
}
예제 #2
0
void _cole_fopen_action(COLEDIRENT * cde, void *_info)
{
    struct _cole_fopen_info *info;

    info = (struct _cole_fopen_info *) _info;

    if (!cole_direntry_isfile(cde)) {
        info->colerrno = COLE_EFILENAMEISNOTFILE;
        info->succ = 0;
        return;
    }

    info->file = cole_fopen_direntry(cde, &info->colerrno);
    if (info->file == NULL) {
        /* colerrno is set */
        info->succ = 0;
        return;
    }

    info->succ = 1;
}
int
main (int argc, char **argv)
{
	COLEFS * cfs;
	COLEDIR * cd;
	COLEDIRENT * cde;
	COLEFILE * cf;
	COLERRNO colerrno;
	char * entry_name;
	char buffer[BUFFER_SIZE];
	size_t char_read;
	size_t char_read_total;


	if (argc != 2) {
		fprintf (stderr, "cole demo. cole is a free C OLE library.\n"
			"Usage: demo <FILE>\n");
		return 1;
	}


	/*
	 * version info
	 */
	printf ("Version info: (%d.%d.%d) (%d.%d.%d) (%s)\n",
		COLE_MAJOR_VERSION, COLE_MINOR_VERSION, COLE_MICRO_VERSION,
		cole_major_version, cole_minor_version, cole_micro_version,
		cole_version);
	printf ("Host info: (%s)\n", cole_host_info);


	cfs = cole_mount (argv[1], &colerrno);
	if (cfs == NULL) {
		cole_perror (PRGNAME, colerrno);
		exit (1);
	}



	if (cole_print_tree (cfs, &colerrno)) {
		cole_perror (PRGNAME, colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}


	cd = cole_opendir_rootdir (cfs, &colerrno);
	if (cd == NULL) {
		cole_perror (PRGNAME, colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}
	for (cde = cole_visiteddirentry (cd); cde != NULL;
	     cde = cole_nextdirentry (cd)) {
		if (cole_direntry_isdir (cde))
			printf ("DIR  ");
		else if (cole_direntry_isfile (cde)) {
			printf ("FILE ");
			/* open the file using their direntry */
			cf = cole_fopen_direntry (cde, &colerrno);
			if (cf == NULL) {
				cole_perror ("travel", colerrno);
				cole_closedir (cd, NULL);
				cole_umount (cfs, NULL);
				exit (1);
			}
			if (cole_fclose (cf, &colerrno)) {
				cole_perror (PRGNAME, colerrno);
				cole_closedir (cd, NULL);
				cole_umount (cfs, NULL);
				exit (1);
			}
		} else
			printf ("???? ");
		printf ("%7u ", cole_direntry_getsize (cde));
		entry_name = cole_direntry_getname (cde);
		printf ("%08lx-%08lx %08lx-%08lx\t",
			cole_direntry_getdays1 (cde),
			cole_direntry_getsec1 (cde),
			cole_direntry_getdays2 (cde),
			cole_direntry_getsec2 (cde));
		if (!isprint ((int)entry_name[0]))
			printf ("'\\x%02x%s'\n", entry_name[0], entry_name+1);
		else
			printf ("'%s'\n", entry_name);
	}
	if (cole_closedir (cd, &colerrno)) {
		cole_umount (cfs, NULL);
		exit (1);
	}


	cf = cole_fopen (cfs, "\005SummaryInformation", &colerrno);
	if (cf == NULL) {
		cole_perror (PRGNAME, colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}
	char_read_total = 0;
	printf ("Reading: ");
	while ((char_read = cole_fread (cf, buffer, BUFFER_SIZE, &colerrno))) {
		printf ("[%d]", char_read);
		char_read_total += char_read;
	}
	cole_perror (PRGNAME, colerrno);
	printf ("\nRead %d bytes from the stream '\\005SummaryInformation'\n",
		char_read_total);
	if (cole_fclose (cf, &colerrno)) {
		cole_perror (PRGNAME, colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}



	if (cole_umount (cfs, &colerrno)) {
		cole_perror (PRGNAME, colerrno);
		exit (1);
	}

	exit (0);
}
예제 #4
0
/**
 * cole_fopen_direntry:
 * @coledirentry: directory entry to be opened as file.
 * @colerrno: error value (COLE_EISNOTFILE, COLE_EMEMORY, COLE_ETMPNAM,
 *                         COLE_EOPENFILE, COLE_EINVALIDFILESYSTEM, COLE_EREAD,
 *                         COLE_EWRITE, COLE_EUNKNOWN).
 *
 * Opens a directory entry as file.
 *
 * Returns: a file in success, or NULL in other case.
 */
COLEFILE *cole_fopen_direntry(COLEDIRENT * coledirentry,
                              COLERRNO * colerrno)
{
    COLEFILE *ret;

    if (!cole_direntry_isfile(coledirentry)) {
        if (colerrno != NULL)
            *colerrno = COLE_EISNOTFILE;
        return NULL;
    }

    ret = malloc(sizeof(COLEFILE));
    if (ret == NULL) {
        if (colerrno != NULL)
            *colerrno = COLE_EMEMORY;
        return NULL;
    }
    ret->fs = coledirentry->dir->fs;
    ret->entry = coledirentry->entry;
    switch (__cole_extract_file(&ret->file, &ret->filename,
                                ret->fs->tree[ret->entry].size,
                                ret->fs->tree[ret->entry].start,
                                ret->fs->BDepot, ret->fs->SDepot,
                                ret->fs->sbfile, ret->fs->file)) {
    case 0:
        /* success */
        break;
    case 1:
        if (colerrno != NULL)
            *colerrno = COLE_EMEMORY;
        free(ret);
        return NULL;
    case 2:
        if (colerrno != NULL)
            *colerrno = COLE_ETMPNAM;
        free(ret);
        return NULL;
    case 3:
        if (colerrno != NULL)
            *colerrno = COLE_EOPENFILE;
        free(ret);
        return NULL;
    case 4:
        if (colerrno != NULL)
            *colerrno = COLE_EINVALIDFILESYSTEM;
        free(ret);
        return NULL;
    case 5:
        if (colerrno != NULL)
            *colerrno = COLE_EREAD;
        free(ret);
        return NULL;
    case 6:
        if (colerrno != NULL)
            *colerrno = COLE_EWRITE;
        free(ret);
        return NULL;
    default:
        if (colerrno != NULL)
            *colerrno = COLE_EUNKNOWN;
        free(ret);
        return NULL;
    }
    /* because the original fopen(3) leaves the file pointer
       in the beginning */
    rewind(ret->file);
    ret->pos = 0;
    ret->filesize = ret->fs->tree[ret->entry].size;

    return ret;
}
int
main (int argc, char **argv)
{
	COLEFS * cfs;
	COLEDIR * cd;
	COLEDIRENT * cde;
	COLEFILE * cf;
	char * entry_name;
	COLERRNO colerrno;


	cfs = cole_mount (COLE_TOPSRCDIR"/examples/text.doc", &colerrno);
	if (cfs == NULL) {
		cole_perror (PRGNAME, colerrno);
		exit (1);
	}


	cd = cole_opendir_rootdir (cfs, &colerrno);
	if (cd == NULL) {
		cole_perror (PRGNAME, colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}
	for (cde = cole_visiteddirentry (cd); cde != NULL;
	    cde = cole_nextdirentry (cd)) {
		if (cole_direntry_isdir (cde))
			printf ("DIR ");
		else if (cole_direntry_isfile (cde)) {
			printf ("FILE");
			/* open the file using their direntry */
			cf = cole_fopen_direntry (cde, &colerrno);
			if (cf == NULL) {
				cole_perror ("travel", colerrno);
				cole_closedir (cd, NULL);
				cole_umount (cfs, NULL);
				exit (1);
			}
			/* Here we process cf */
			if (cole_fclose (cf, &colerrno)) {
				cole_perror ("travel", colerrno);
				cole_closedir (cd, NULL);
				cole_umount (cfs, NULL);
				exit (1);
			}
		} else
			printf ("????");
		printf (" %7u", cole_direntry_getsize (cde));
		entry_name = cole_direntry_getname (cde);
		if (!isprint ((int)entry_name[0]))
			printf ("' \\x%02x%s'", entry_name[0], entry_name+1);
		else
			printf ("'%s'", entry_name);
		printf ("\t%08lx-%08lx %08lx-%08lx",
			cole_direntry_getdays1 (cde),
			cole_direntry_getsec1 (cde),
			cole_direntry_getdays2 (cde),
			cole_direntry_getsec2 (cde));
		printf ("\n");
	}
	if (cole_closedir (cd, &colerrno)) {
		cole_perror ("travel", colerrno);
		cole_umount (cfs, NULL);
		exit (1);
	}


	if (cole_umount (cfs, &colerrno)) {
		cole_perror ("travel", colerrno);
		exit (1);
	}

	exit (0);
}