Пример #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
/**
 * cole_opendir_direntry:
 * @coledirentry: directory entry to be opened as directory.
 * @colerrno: error value (COLE_EISNOTDIR, COLE_EMEMORY).
 *
 * Opens a directory entry as directory.
 *
 * Returns: a directory in success, or NULL in other case.
 */
COLEDIR *
cole_opendir_direntry (COLEDIRENT *coledirentry, COLERRNO *colerrno)
{
	COLEDIR *ret;

	if (!cole_direntry_isdir (coledirentry)) {
		if (colerrno != NULL) *colerrno = COLE_EISNOTDIR;
		return NULL;
	}

	ret = malloc (sizeof (COLEDIR));
	if (ret == NULL) {
		if (colerrno != NULL) *colerrno = COLE_EMEMORY;
		return NULL;
	}
	ret->fs = coledirentry->dir->fs;
	ret->entry = coledirentry->entry;
	ret->visited_entry.dir = ret;
	ret->visited_entry.entry = ret->fs->tree[ ret->entry ].dir;

	return ret;
}
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
int
__cole_recurse_tree(COLEDIR * _cd, long level, void *info,
                    COLE_RECURSE_DIR_FUNC * inroot,
                    COLE_RECURSE_DIRENT_FUNC * indirentry,
                    COLE_RECURSE_DIR_FUNC * indir,
                    COLE_RECURSE_DIR_FUNC * outdir,
                    COLE_RECURSE_VISIT_DIR_FUNC * visitdir,
                    COLERRNO * colerrno)
{
/*
 * ATTENTION: if you modify __cole_recurse_tree() so it modifies colerrno
 * besides in calling inroot, indirentry, indir, outdir, cole_opendir_direntry
 * or cole_closedir:
 *      Modify colerrno comment in the functions that call it,
 *      ie. cole_recurse_tree().
 */

    /* ATTENTION: This is a recursive function */
    COLEDIRENT *cde;
    COLEDIR *cd;

    if (level == 1) {
        /* The following lines are only executed on Root Entry */
        if (inroot != NULL) {
            if ((*inroot) (_cd, info, colerrno)) {
                /* colerrno is set */
                return 1;
            }
        }
    }

    /* Iterate through childrens */
    for (cde = cole_visiteddirentry(_cd); cde != NULL;
         cde = cole_nextdirentry(_cd)) {
        if (indirentry != NULL) {
            if ((*indirentry) (cde, info, colerrno)) {
                /* colerrno is set */
                return 1;
            }
        }

        /* RECURSIVE CALL */
        if (cole_direntry_isdir(cde)) {
            cd = cole_opendir_direntry(cde, colerrno);
            if (cd == NULL) {
                /* colerrno is set */
                return 1;
            }

            if (indir != NULL) {
                if ((*indir) (cd, info, colerrno)) {
                    /* colerrno is set */
                    cole_closedir(cd, NULL);
                    return 1;
                }
            }

            if ((visitdir == NULL) || ((*visitdir) (cd, info))) {
                if (__cole_recurse_tree(cd, level + 1, info,
                                        inroot, indirentry,
                                        indir, outdir,
                                        visitdir, colerrno)) {
                    /* colerrno is set */
                    cole_closedir(cd, NULL);
                    return 1;
                }
            }

            if (outdir != NULL) {
                if ((*outdir) (cd, info, colerrno)) {
                    /* colerrno is set */
                    cole_closedir(cd, NULL);
                    return 1;
                }
            }

            if (cole_closedir(cd, colerrno)) {
                /* colerrno is set */
                return 1;
            }
        }
    }

    return 0;
}
Пример #5
0
int
__cole_locate_filename_indirentry(COLEDIRENT * cde, void *_info, COLERRNO * colerrno)
{
    char *entry_name;
    struct __cole_locate_filenameinfo *info;
    char *pcurrent;
    char *pentry_name;

    info = (struct __cole_locate_filenameinfo *) _info;
    entry_name = cole_direntry_getname(cde);
    for (pcurrent = info->current, pentry_name = entry_name;
         *pcurrent && *pentry_name && *pcurrent != '/';
         pcurrent++, pentry_name++) {
        if (*pcurrent != *pentry_name) {
            info->visitdir = 0; /* don't visit this directory */
            return 0;           /* don't break recurse */
        }
    }
    
    switch (*pentry_name) {
    case 0:
        switch (*pcurrent) {
        case '/':
            if (!cole_direntry_isdir(cde)) {
                if (colerrno != NULL)
                    *colerrno = COLE_EMEMBERISNOTDIR;
                return 1;       /* break recurse */
            }
            pcurrent++;         /* jump the '/' character */
            info->current = pcurrent;

            /* check if it's the last component of filename */
            if (!(*info->current)) {
                /* last component of filename reached */
                if (info->action != NULL) {
                    (*(info->action)) (cde, info->info);
                }

                if (colerrno != NULL)
                    *colerrno = COLE_ELAST + 1;
                return 1;       /* break recurse */
            }
            info->visitdir = 1; /* visit this directory */
            return 0;           /* don't break recurse */
        case 0:
            /* last component of filename reached */
            if (info->action != NULL) {
                (*(info->action)) (cde, info->info);
            }

            if (colerrno != NULL)
                *colerrno = COLE_ELAST + 1;
            return 1;           /* break recurse */
        default:
            info->visitdir = 0; /* don't visit this directory */
            return 0;           /* don't break recurse */
        }
    default:
        switch (*pcurrent) {
        case 0:
            info->visitdir = 0; /* don't visit this directory */
            return 0;           /* don't break recurse */
        case '/':
            info->visitdir = 0; /* don't visit this directory */
            return 0;           /* don't break recurse */
        default:
            if (colerrno != NULL)
                *colerrno = COLE_EUNKNOWN;
            return 1;           /* break recurse */
        }
    }

}
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);
}