[svn:parrot] r36027 - trunk/languages/pipp/src/common
[email protected] Mon, 26 Jan 2009 05:03:42 -0800 (PST)
| Newsgroups | perl.cvs.parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: bernhard
Date: Mon Jan 26 05:03:41 2009
New Revision: 36027
Modified:
trunk/languages/pipp/src/common/php_filesystem.pir
Log:
[Pipp] Fiddle with 'dirname'
Modified: trunk/languages/pipp/src/common/php_filesystem.pir
==============================================================================
--- trunk/languages/pipp/src/common/php_filesystem.pir (original)
+++ trunk/languages/pipp/src/common/php_filesystem.pir Mon Jan 26 05:03:41 2009
@@ -43,11 +43,51 @@
$P0 = split '/', $S0
L2:
- $S0 = pop $P0
+ .local int last_nonempty_has_been_popped
+ last_nonempty_has_been_popped = 0
+
+ # _dumper(path)
+ # _dumper($P0)
+ # an absolute path gives at least two components
+ $I0 = elements $P0
+ if $I0 <= 1 goto return_pwd
+
+ # check for an absolute path
+ .local int is_abs_path
+ is_abs_path = 0
+ $S0 = $P0[0]
+ ne $S0, '', abs_path
+ is_abs_path = 1
+ abs_path:
+
+ pop_empty:
+ # pop empty path components
+ $I0 = elements $P0
+ if $I0 == 0 goto return_root_or_pwd
+ $S0 = $P0[-1]
+ ne $S0, '', check_already_popped
+ $S0 = pop $P0
+ goto pop_empty
+
+ check_already_popped:
+ if last_nonempty_has_been_popped goto return_join
+ $S0 = pop $P0
+ last_nonempty_has_been_popped = 1
+ goto pop_empty
+
+ return_root_or_pwd:
+ if is_abs_path goto return_root
+ goto return_pwd
+
+ return_root:
+ .RETURN_STRING(slash)
+
+ return_pwd:
+ .RETURN_STRING('.')
+
+ return_join:
$S0 = join slash_str, $P0
- ne $S0, '', L3
- $S0 = slash
- L3:
+ eq $S0, '', return_root_or_pwd
.RETURN_STRING($S0)
.end