2 * Copyright (c) 2003 Matthijs Hollemans
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
31 ptr_list_t include_dirs
;
32 ptr_list_t input_files
;
38 char rdef_err_file
[B_PATH_NAME_LENGTH
];
39 char rdef_err_msg
[1024];
43 free_ptr_list(ptr_list_t
&list
)
45 for (ptr_iter_t i
= list
.begin(); i
!= list
.end(); ++i
) {
61 rdef_add_include_dir(const char *dir
, bool toEndOfList
)
65 char *path
= (char *)malloc(strlen(dir
) + 2);
67 rdef_err
= B_NO_MEMORY
;
75 include_dirs
.push_back(path
);
77 include_dirs
.push_front(path
);
84 rdef_remove_include_dir(const char *dir
)
86 size_t length
= strlen(dir
);
88 if (dir
[length
- 1] != '/')
91 for (ptr_iter_t i
= include_dirs
.begin(); i
!= include_dirs
.end(); ++i
) {
92 char *path
= (char *)*i
;
94 if (!strncmp(dir
, path
, length
)
95 && path
[length
+ (noSlash
? 1 : 0)] == '\0') {
96 // we found the entry in the list, let's remove it
97 include_dirs
.erase(i
);
103 return B_ENTRY_NOT_FOUND
;
108 rdef_free_include_dirs()
110 free_ptr_list(include_dirs
);
115 rdef_add_input_file(const char *file
)
119 char *temp
= strdup(file
);
121 rdef_err
= B_NO_MEMORY
;
125 input_files
.push_back(temp
);
131 rdef_free_input_files()
133 free_ptr_list(input_files
);
138 rdef_set_flags(uint32 flags_
)
156 rdef_err_file
[0] = '\0';
157 rdef_err_msg
[0] = '\0';
162 open_file_from_include_dir(const char *filename
, char *outname
)
164 for (ptr_iter_t i
= include_dirs
.begin(); i
!= include_dirs
.end(); ++i
) {
165 char tmpname
[B_PATH_NAME_LENGTH
];
166 strcpy(tmpname
, (char *)*i
);
167 strcat(tmpname
, filename
);
169 if (access(tmpname
, R_OK
) == 0) {
170 strcpy(outname
, tmpname
);