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