#define PSI_CPP_PREDEF
#include "php_psi_cpp.h"
+#include "php_psi.h"
+
static void free_cpp_def(zval *p)
{
if (Z_TYPE_P(p) == IS_PTR) {
struct psi_token *token = psi_cpp_tokiter_current(cpp);
/* strip comments and attributes */
- if (token->type == PSI_T_COMMENT || token->type == PSI_T_CPP_ATTRIBUTE) {
+ if (token->type == PSI_T_COMMENT
+ || token->type == PSI_T_CPP_ATTRIBUTE) {
psi_cpp_tokiter_del_cur(cpp, true);
continue;
}
*/
if (token->type == PSI_T_WHITESPACE) {
+ if (name) {
+ name = false;
+ }
ws = true;
psi_cpp_tokiter_del_cur(cpp, true);
continue;
if (is_eol) {
size_t processed = 0;
+ bool parsed = psi_parser_process(cpp->parser, parser_tokens, &processed);
- if (!psi_parser_process(cpp->parser, parser_tokens, &processed)) {
- psi_plist_free(parser_tokens);
- return false;
- }
+ /* EOL */
psi_plist_pop(parser_tokens, NULL);
psi_plist_clean(parser_tokens);
do_cpp = false;
+
+ if (!parsed) {
+ psi_plist_free(parser_tokens);
+ return false;
+ }
} else {
/* leave EOLs in the input stream, else we might end up
- * with a hash not preceeded with a new line after include */
+ * with a hash not preceded with a new line after include */
psi_cpp_tokiter_del_cur(cpp, false);
}
bool psi_cpp_include(struct psi_cpp *cpp, const char *file, unsigned flags)
{
- char path[PATH_MAX];
bool parsed = false;
- int p_len, f_len = strlen(file) - 2;
+ int f_len = strlen(file);
- if (file[1] == '/') {
- if (PATH_MAX > (p_len = snprintf(path, PATH_MAX, "%.*s", f_len, file + 1))) {
- if ((flags & PSI_CPP_INCLUDE_ONCE) && zend_hash_str_exists(&cpp->once, path, p_len)) {
- return true;
- }
- return try_include(cpp, path, &parsed) && parsed;
+ if (!(flags & PSI_CPP_INCLUDE_NEXT) || *file == '/') {
+ /* first try as is, full or relative path */
+ if ((flags & PSI_CPP_INCLUDE_ONCE) && zend_hash_str_exists(&cpp->once, file, f_len)) {
+ return true;
}
- } else {
+ if (try_include(cpp, file, &parsed)) {
+ /* found */
+ return parsed;
+ }
+ }
+
+ /* look through search paths */
+ if (*file != '/') {
+ char path[PATH_MAX];
const char *sep;
+ int p_len;
if ((flags & PSI_CPP_INCLUDE_NEXT) && cpp->search) {
if ((sep = strchr(cpp->search, ':'))) {
}
if (!(flags & PSI_CPP_INCLUDE_NEXT) || !cpp->search) {
- cpp->search = &psi_cpp_search[0];
+ cpp->search = PSI_G(search_path);
}
do {
sep = strchr(cpp->search, ':');
d_len = sep ? sep - cpp->search : strlen(cpp->search);
- if (PATH_MAX > (p_len = snprintf(path, PATH_MAX, "%.*s/%.*s", d_len, cpp->search, f_len, file + 1))) {
+ if (PATH_MAX > (p_len = snprintf(path, PATH_MAX, "%.*s/%.*s", d_len, cpp->search, f_len, file))) {
if ((flags & PSI_CPP_INCLUDE_ONCE) && zend_hash_str_exists(&cpp->once, path, p_len)) {
return true;
}
break;
}
}
- cpp->search = sep + 1;
+
+ if (sep) {
+ cpp->search = sep + 1;
+ }
} while (sep);
}