39 |
#include "m4module.h" |
#include "m4module.h" |
40 |
#include "m4private.h" |
#include "m4private.h" |
41 |
|
|
42 |
static struct m4_search_path_info dirpath; /* the list of path directories */ |
static void search_path_add (m4__search_path_info *, const char *); |
43 |
|
static void search_path_env_init (m4__search_path_info *, char *, boolean); |
44 |
|
|
45 |
|
|
46 |
/* |
/* |
47 |
* General functions for search paths |
* General functions for search paths |
48 |
*/ |
*/ |
49 |
|
|
50 |
struct m4_search_path_info * |
static void |
51 |
m4_search_path_info_new (void) |
search_path_add (m4__search_path_info *info, const char *dir) |
|
{ |
|
|
struct m4_search_path_info *info; |
|
|
|
|
|
info = (struct m4_search_path_info *) |
|
|
xmalloc (sizeof (struct m4_search_path_info)); |
|
|
info->list = NULL; |
|
|
info->list_end = NULL; |
|
|
info->max_length = 0; |
|
|
|
|
|
return info; |
|
|
} |
|
|
|
|
|
void |
|
|
m4_search_path_add (struct m4_search_path_info *info, const char *dir) |
|
52 |
{ |
{ |
53 |
m4_search_path *path; |
m4__search_path *path; |
54 |
|
|
55 |
if (*dir == '\0') |
if (*dir == '\0') |
56 |
dir = "."; |
dir = "."; |
57 |
|
|
58 |
path = (struct m4_search_path *) xmalloc (sizeof (struct m4_search_path)); |
path = XMALLOC (m4__search_path, 1); |
59 |
path->next = NULL; |
path->next = NULL; |
60 |
path->len = strlen (dir); |
path->len = strlen (dir); |
61 |
path->dir = xstrdup (dir); |
path->dir = xstrdup (dir); |
70 |
info->list_end = path; |
info->list_end = path; |
71 |
} |
} |
72 |
|
|
73 |
void |
static void |
74 |
m4_search_path_env_init (struct m4_search_path_info *info, char *path, |
search_path_env_init (m4__search_path_info *info, char *path, boolean isabs) |
|
boolean isabs) |
|
75 |
{ |
{ |
76 |
char *path_end; |
char *path_end; |
77 |
|
|
84 |
if (path_end) |
if (path_end) |
85 |
*path_end = '\0'; |
*path_end = '\0'; |
86 |
if (!isabs || *path == '/') |
if (!isabs || *path == '/') |
87 |
m4_search_path_add (info, path); |
search_path_add (info, path); |
88 |
path = path_end + 1; |
path = path_end + 1; |
89 |
} |
} |
90 |
while (path_end); |
while (path_end); |
91 |
} |
} |
92 |
|
|
93 |
|
|
|
void |
|
|
m4_include_init (void) |
|
|
{ |
|
|
dirpath.list = NULL; |
|
|
dirpath.list_end = NULL; |
|
|
dirpath.max_length = 0; |
|
|
} |
|
|
|
|
|
|
|
94 |
/* Functions for normal input path search */ |
/* Functions for normal input path search */ |
95 |
|
|
96 |
void |
void |
99 |
if (m4_get_no_gnu_extensions_opt (context)) |
if (m4_get_no_gnu_extensions_opt (context)) |
100 |
return; |
return; |
101 |
|
|
102 |
m4_search_path_env_init (&dirpath, getenv ("M4PATH"), FALSE); |
search_path_env_init (m4__get_search_path (context), |
103 |
|
getenv ("M4PATH"), FALSE); |
104 |
} |
} |
105 |
|
|
106 |
void |
void |
109 |
if (m4_get_no_gnu_extensions_opt (context)) |
if (m4_get_no_gnu_extensions_opt (context)) |
110 |
return; |
return; |
111 |
|
|
112 |
m4_search_path_add (&dirpath, dir); |
search_path_add (m4__get_search_path (context), dir); |
113 |
|
|
114 |
#ifdef DEBUG_INCL |
#ifdef DEBUG_INCL |
115 |
fprintf (stderr, "add_include_directory (%s);\n", dir); |
fprintf (stderr, "add_include_directory (%s);\n", dir); |
120 |
m4_path_search (m4 *context, const char *dir, char **expanded_name) |
m4_path_search (m4 *context, const char *dir, char **expanded_name) |
121 |
{ |
{ |
122 |
FILE *fp; |
FILE *fp; |
123 |
struct m4_search_path *incl; |
m4__search_path *incl; |
124 |
char *name; /* buffer for constructed name */ |
char *name; /* buffer for constructed name */ |
125 |
|
|
126 |
/* Look in current working directory first. */ |
/* Look in current working directory first. */ |
136 |
if (*dir == '/' || m4_get_no_gnu_extensions_opt (context)) |
if (*dir == '/' || m4_get_no_gnu_extensions_opt (context)) |
137 |
return NULL; |
return NULL; |
138 |
|
|
139 |
name = (char *) xmalloc (dirpath.max_length + 1 + strlen (dir) + 1); |
name = (char *) xmalloc (m4__get_search_path (context)->max_length + 1 + strlen (dir) + 1); |
140 |
|
|
141 |
for (incl = dirpath.list; incl != NULL; incl = incl->next) |
for (incl = m4__get_search_path (context)->list; incl != NULL; incl = incl->next) |
142 |
{ |
{ |
143 |
strncpy (name, incl->dir, incl->len); |
strncpy (name, incl->dir, incl->len); |
144 |
name[incl->len] = '/'; |
name[incl->len] = '/'; |
171 |
static void |
static void |
172 |
include_dump (void) |
include_dump (void) |
173 |
{ |
{ |
174 |
struct m4_search_path *incl; |
m4__search_path *incl; |
175 |
|
|
176 |
fprintf (stderr, "include_dump:\n"); |
fprintf (stderr, "include_dump:\n"); |
177 |
for (incl = dirpath.list; incl != NULL; incl = incl->next) |
for (incl = m4__get_search_path (context)->list; incl != NULL; incl = incl->next) |
178 |
fprintf (stderr, "\t%s\n", incl->dir); |
fprintf (stderr, "\t%s\n", incl->dir); |
179 |
} |
} |
180 |
|
|