]> granicus.if.org Git - php/commitdiff
MFB __DIR__ constant support
authorStanislav Malyshev <stas@php.net>
Tue, 12 Feb 2008 01:04:08 +0000 (01:04 +0000)
committerStanislav Malyshev <stas@php.net>
Tue, 12 Feb 2008 01:04:08 +0000 (01:04 +0000)
ext/standard/string.c
ext/tokenizer/tokenizer_data.c

index faf5513a72babd245dd9d79180aa829acd7b0453..bcb6083cead762274ea7de3e60374406a41feaa7 100644 (file)
@@ -2000,94 +2000,7 @@ PHP_FUNCTION(basename)
    Returns directory name component of path */
 PHPAPI int php_u_dirname(UChar *path, int len)
 {
-       register UChar *end = path + len - 1;
-       unsigned int len_adjust = 0;
-
-#ifdef PHP_WIN32
-       /* Note that on Win32 CWD is per drive (heritage from CP/M).
-        * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
-        */
-       if ((2 <= len) && u_isalpha((UChar32)path[0]) && ((UChar)0x3a /*':'*/ == path[1])) {
-               /* Skip over the drive spec (if any) so as not to change */
-               path += 2;
-               len_adjust += 2;
-               if (2 == len) {
-                       /* Return "c:" on Win32 for dirname("c:").
-                        * It would be more consistent to return "c:."
-                        * but that would require making the string *longer*.
-                        */
-                       return len;
-               }
-       }
-#elif defined(NETWARE)
-       /*
-        * Find the first occurence of : from the left
-        * move the path pointer to the position just after :
-        * increment the len_adjust to the length of path till colon character(inclusive)
-        * If there is no character beyond : simple return len
-        */
-       UChar *colonpos = NULL;
-       colonpos = u_strchr(path, (UChar) 0x3a /*':'*/);
-       if(colonpos != NULL) {
-               len_adjust = ((colonpos - path) + 1);
-               path += len_adjust;
-               if(len_adjust == len) {
-               return len;
-               }
-       }
-#endif
-
-       if (len == 0) {
-               /* Illegal use of this function */
-               return 0;
-       }
-
-       /* Strip trailing slashes */
-       while (end >= path && IS_U_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               /* The path only contained slashes */
-               path[0] = DEFAULT_U_SLASH;
-               path[1] = 0;
-               return 1 + len_adjust;
-       }
-
-       /* Strip filename */
-       while (end >= path && !IS_U_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               /* No slash found, therefore return '.' */
-#ifdef NETWARE
-               if(len_adjust == 0) {
-                       path[0] = (UChar) 0x2e /*'.'*/;
-                       path[1] = 0;
-                       return 1; //only one character
-               }
-               else {
-                       path[0] = 0;
-                       return len_adjust;
-               }
-#else
-               path[0] = (UChar) 0x2e /*'.'*/;
-               path[1] = 0;
-               return 1 + len_adjust;
-#endif
-       }
-
-       /* Strip slashes which came before the file name */
-       while (end >= path && IS_U_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               path[0] = DEFAULT_U_SLASH;
-               path[1] = 0;
-               return 1 + len_adjust;
-       }
-       *(end+1) = 0;
-
-       return (size_t)(end + 1 - path) + len_adjust;
+       return zend_u_dirname(path, len);
 }
 /* }}} */
 
@@ -2095,94 +2008,7 @@ PHPAPI int php_u_dirname(UChar *path, int len)
    Returns directory name component of path */
 PHPAPI int php_dirname(char *path, int len)
 {
-       register char *end = path + len - 1;
-       unsigned int len_adjust = 0;
-
-#ifdef PHP_WIN32
-       /* Note that on Win32 CWD is per drive (heritage from CP/M).
-        * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
-        */
-       if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
-               /* Skip over the drive spec (if any) so as not to change */
-               path += 2;
-               len_adjust += 2;
-               if (2 == len) {
-                       /* Return "c:" on Win32 for dirname("c:").
-                        * It would be more consistent to return "c:."
-                        * but that would require making the string *longer*.
-                        */
-                       return len;
-               }
-       }
-#elif defined(NETWARE)
-       /*
-        * Find the first occurence of : from the left
-        * move the path pointer to the position just after :
-        * increment the len_adjust to the length of path till colon character(inclusive)
-        * If there is no character beyond : simple return len
-        */
-       char *colonpos = NULL;
-       colonpos = strchr(path, ':');
-       if(colonpos != NULL) {
-               len_adjust = ((colonpos - path) + 1);
-               path += len_adjust;
-               if(len_adjust == len) {
-               return len;
-               }
-       }
-#endif
-
-       if (len == 0) {
-               /* Illegal use of this function */
-               return 0;
-       }
-
-       /* Strip trailing slashes */
-       while (end >= path && IS_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               /* The path only contained slashes */
-               path[0] = DEFAULT_SLASH;
-               path[1] = '\0';
-               return 1 + len_adjust;
-       }
-
-       /* Strip filename */
-       while (end >= path && !IS_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               /* No slash found, therefore return '.' */
-#ifdef NETWARE
-               if(len_adjust == 0) {
-                       path[0] = '.';
-                       path[1] = '\0';
-                       return 1; //only one character
-               }
-               else {
-                       path[0] = '\0';
-                       return len_adjust;
-               }
-#else
-               path[0] = '.';
-               path[1] = '\0';
-               return 1 + len_adjust;
-#endif
-       }
-
-       /* Strip slashes which came before the file name */
-       while (end >= path && IS_SLASH_P(end)) {
-               end--;
-       }
-       if (end < path) {
-               path[0] = DEFAULT_SLASH;
-               path[1] = '\0';
-               return 1 + len_adjust;
-       }
-       *(end+1) = '\0';
-
-       return (size_t)(end + 1 - path) + len_adjust;
+       return zend_dirname(path, len);
 }
 /* }}} */
 
index 05545ed25c70c03ba22b5d5298cc8f33b6a282b1..e9641945747b25ddebfa9b02cd82c55f77b09150 100644 (file)
@@ -139,6 +139,7 @@ void tokenizer_register_constants(INIT_FUNC_ARGS) {
        REGISTER_LONG_CONSTANT("T_FUNC_C", T_FUNC_C, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("T_LINE", T_LINE, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("T_FILE", T_FILE, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("T_DIR", T_DIR, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("T_COMMENT", T_COMMENT, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("T_DOC_COMMENT", T_DOC_COMMENT, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("T_OPEN_TAG", T_OPEN_TAG, CONST_CS | CONST_PERSISTENT);
@@ -271,6 +272,7 @@ char *get_token_type_name(int token_type)
                case T_FUNC_C: return "T_FUNC_C";
                case T_LINE: return "T_LINE";
                case T_FILE: return "T_FILE";
+               case T_DIR: return "T_DIR";
                case T_COMMENT: return "T_COMMENT";
                case T_DOC_COMMENT: return "T_DOC_COMMENT";
                case T_OPEN_TAG: return "T_OPEN_TAG";