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