Added
Link Here
|
1 |
#include <string.h> |
2 |
#include "chm_lib.h" |
3 |
|
4 |
/* |
5 |
* callback function for enumerate API |
6 |
*/ |
7 |
int _get_name(struct chmFile *h, |
8 |
chmUnitInfo *ui, |
9 |
void *context) |
10 |
{ |
11 |
int i; |
12 |
|
13 |
|
14 |
chm_dir *dirp = (chm_dir *)context; |
15 |
|
16 |
dirp->info=realloc(dirp->info,(dirp->nentries+1)*sizeof (char*)); |
17 |
|
18 |
dirp->info[dirp->nentries] = malloc(sizeof(ui->path)); |
19 |
strcpy(dirp->info[dirp->nentries], ui->path); |
20 |
|
21 |
dirp->nentries++; |
22 |
return CHM_ENUMERATOR_CONTINUE; |
23 |
} |
24 |
|
25 |
chm_dir get_names(struct chmFile *h) |
26 |
//note: you should free() dir.info and all dir.info[i] in caller |
27 |
{ |
28 |
chm_dir dir; |
29 |
|
30 |
dir.nentries=0; |
31 |
dir.info = NULL; |
32 |
|
33 |
if (! chm_enumerate(h, |
34 |
CHM_ENUMERATE_ALL, |
35 |
_get_name, |
36 |
(void *)&dir)) |
37 |
printf(" *** ERROR ***\n"); |
38 |
|
39 |
return dir; |
40 |
} |
41 |
|
42 |
|
43 |
int main() |
44 |
{ |
45 |
int i; |
46 |
|
47 |
struct chmFile *h = chm_open("/home/az/new/txt/chm/reg.chm"); |
48 |
chm_dir dir=get_names(h); |
49 |
for(i=0;i<dir.nentries;i++) |
50 |
printf("%d: %s\n",i,dir.info[i]); |
51 |
|
52 |
return 0; |
53 |
} |
54 |
|