X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fcpp.c;h=29f8541afee2f04e3657e2e98bc08cf424651dc8;hp=2cf4094e93efbd5ef9303c67e23ce75c97fefecc;hb=5ec2f9ac17f56aee266dc78b4bf657f2cf0910b1;hpb=b1d875d13e5a8f7600d3df6b44c75e8613cfe509 diff --git a/src/cpp.c b/src/cpp.c index 2cf4094..29f8541 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -32,6 +32,8 @@ #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) { @@ -100,7 +102,8 @@ static bool psi_cpp_stage1(struct psi_cpp *cpp) 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; } @@ -125,6 +128,9 @@ static bool psi_cpp_stage1(struct psi_cpp *cpp) */ if (token->type == PSI_T_WHITESPACE) { + if (name) { + name = false; + } ws = true; psi_cpp_tokiter_del_cur(cpp, true); continue; @@ -415,19 +421,25 @@ static inline bool try_include(struct psi_cpp *cpp, const char *path, bool *pars 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, ':'))) { @@ -439,7 +451,7 @@ bool psi_cpp_include(struct psi_cpp *cpp, const char *file, unsigned flags) } if (!(flags & PSI_CPP_INCLUDE_NEXT) || !cpp->search) { - cpp->search = &psi_cpp_search[0]; + cpp->search = PSI_G(search_path); } do { @@ -448,7 +460,7 @@ bool psi_cpp_include(struct psi_cpp *cpp, const char *file, unsigned flags) 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; } @@ -456,7 +468,10 @@ bool psi_cpp_include(struct psi_cpp *cpp, const char *file, unsigned flags) break; } } - cpp->search = sep + 1; + + if (sep) { + cpp->search = sep + 1; + } } while (sep); }