libtcc.c: Completely replace tcc_normalize_inc_dirs.
This commit is contained in:
parent
a7334f791d
commit
c39bc9caa7
1 changed files with 26 additions and 73 deletions
99
libtcc.c
99
libtcc.c
|
@ -1569,81 +1569,34 @@ int is_same_file(const file_info_t *fi1, const file_info_t *fi2)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tcc_normalize_inc_dirs_aux(file_info_t *stats, size_t *pnum, char **path)
|
||||||
|
{
|
||||||
|
size_t i, num = *pnum;
|
||||||
|
if (get_file_info(*path, &stats[num]) || !is_dir(&stats[num]))
|
||||||
|
goto remove;
|
||||||
|
for (i = 0; i < num; i++)
|
||||||
|
if (is_same_file(&stats[i], &stats[num]))
|
||||||
|
goto remove;
|
||||||
|
*pnum = num + 1;
|
||||||
|
return;
|
||||||
|
remove:
|
||||||
|
tcc_free(*path);
|
||||||
|
*path = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove non-existent and duplicate directories from include paths. */
|
||||||
ST_FUNC void tcc_normalize_inc_dirs(TCCState *s)
|
ST_FUNC void tcc_normalize_inc_dirs(TCCState *s)
|
||||||
{
|
{
|
||||||
/* check a preprocessor include dirs and remove not
|
file_info_t *stats =
|
||||||
existing dirs and duplicates:
|
tcc_malloc(((size_t)s->nb_sysinclude_paths + s->nb_include_paths) *
|
||||||
- for each duplicate path keep just the first one
|
sizeof(*stats));
|
||||||
- remove each include_path that exists in sysinclude_paths
|
size_t i, num = 0;
|
||||||
*/
|
for (i = 0; i < s->nb_sysinclude_paths; i++)
|
||||||
file_info_t sysinc_stats[50]; // we don't use VLA in tcc code
|
tcc_normalize_inc_dirs_aux(stats, &num, &s->sysinclude_paths[i]);
|
||||||
file_info_t inc_stats[50];
|
for (i = 0; i < s->nb_include_paths; i++)
|
||||||
int num_sysinc = s->nb_sysinclude_paths;
|
tcc_normalize_inc_dirs_aux(stats, &num, &s->include_paths[i]);
|
||||||
int num_inc = s->nb_include_paths;
|
tcc_free(stats);
|
||||||
char** pp;
|
|
||||||
int i, j, r;
|
|
||||||
|
|
||||||
if ((num_sysinc > 50) || (num_inc > 50)) {
|
|
||||||
tcc_warning("fix a max number of the inc dirs");
|
|
||||||
if (num_sysinc > 50) num_sysinc = 50;
|
|
||||||
if (num_inc > 50) num_inc = 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
pp = s->sysinclude_paths;
|
|
||||||
for (i=0; i < num_sysinc; i++) {
|
|
||||||
file_info_t *st = &sysinc_stats [i];
|
|
||||||
r = get_file_info( pp [i], st);
|
|
||||||
if (r || !is_dir(st)) {
|
|
||||||
tcc_free( pp[i] );
|
|
||||||
pp[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pp = s->include_paths;
|
|
||||||
for (i=0; i < num_inc; i++) {
|
|
||||||
file_info_t *st = &inc_stats [i];
|
|
||||||
r = get_file_info( pp [i], st);
|
|
||||||
if (r || !is_dir(st)) {
|
|
||||||
tcc_free( pp[i] );
|
|
||||||
pp[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0; i < num_inc; i++) {
|
|
||||||
file_info_t *st1 = &inc_stats [i];
|
|
||||||
for (j=i+1; j < num_inc; j++) {
|
|
||||||
file_info_t *st2 = &inc_stats [j];
|
|
||||||
if (is_same_file(st1, st2)) {
|
|
||||||
pp = &s->include_paths[j];
|
|
||||||
if (*pp) {
|
|
||||||
tcc_free( *pp );
|
|
||||||
*pp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (j=0; i < num_sysinc; i++) {
|
|
||||||
file_info_t *st2 = &sysinc_stats [j];
|
|
||||||
if (is_same_file(st1, st2)) {
|
|
||||||
pp = &s->include_paths[i];
|
|
||||||
if (*pp) {
|
|
||||||
tcc_free( *pp );
|
|
||||||
*pp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i=0; i < num_sysinc; i++) {
|
|
||||||
file_info_t *st1 = &sysinc_stats [i];
|
|
||||||
for (j=i+1; j < num_sysinc; j++) {
|
|
||||||
file_info_t *st2 = &sysinc_stats [j];
|
|
||||||
if (is_same_file(st1, st2)) {
|
|
||||||
pp = &s->sysinclude_paths[j];
|
|
||||||
if (*pp) {
|
|
||||||
tcc_free( *pp );
|
|
||||||
*pp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
||||||
|
|
Loading…
Add table
Reference in a new issue