10 static int cfile_cmp(void *o1
, void *o2
)
12 struct cfile
*c1
= *(struct cfile
**) o1
;
13 struct cfile
*c2
= *(struct cfile
**) o2
;
14 return -strcmp(c1
->name
, c2
->name
);
17 struct project
*project_init(char *root
)
19 struct project
*project
;
20 struct dirent
*dirent
;
21 DIR *dir
= opendir(root
);
22 project
= xmalloc(sizeof(*project
));
23 project
->files
= xmalloc(sizeof(*project
->files
) * MAXFILES
);
25 while ((dirent
= readdir(dir
))) {
27 char *name
= dirent
->d_name
;
28 if (startswith(name
, "."))
30 if (endswith(name
, ".h") || endswith(name
, ".c")) {
31 cfile
= cfile_init(name
);
33 project
->files
[project
->count
++] = cfile
;
36 qsort(project
->files
, project
->count
,
37 sizeof(*project
->files
), cfile_cmp
);
41 void project_free(struct project
*project
)
47 struct cfile
*project_find(struct project
*project
, char *filename
)
50 for (i
= 0; i
< project
->count
; i
++)
51 if (!strcmp(project
->files
[i
]->name
, filename
))
52 return project
->files
[i
];