summaryrefslogtreecommitdiff
path: root/shell/bin/ls.php
diff options
context:
space:
mode:
Diffstat (limited to 'shell/bin/ls.php')
-rw-r--r--shell/bin/ls.php55
1 files changed, 29 insertions, 26 deletions
diff --git a/shell/bin/ls.php b/shell/bin/ls.php
index fa01f2e..aa938c1 100644
--- a/shell/bin/ls.php
+++ b/shell/bin/ls.php
@@ -1,34 +1,37 @@
<?php
-function main($args) {
- if (count($args)<2) {
- $args[]='.';
- }
- $ret=0;
- $me = array_shift($args);
- foreach ($args as $name) {
- if (file_exists($name)) {
- if (is_dir($name)) {
- @$dh = opendir($name);
- if ($dh === false) {
- echo $me.': can not open directory: `'.$name."'\n";
- $ret++;
- } else {
- if (count($args)>1) { echo $name.":\n"; }
- $files = array();
- while (false !== ($file = readdir($dh))) {
- $files[]="$file";
+class p_ls extends prog {
+ public static function main($args, $env) {
+ if (count($args)<2) {
+ $args[]='.';
+ }
+ $ret=0;
+ $me = array_shift($args);
+ foreach ($args as $name) {
+ if (file_exists($name)) {
+ if (is_dir($name)) {
+ @$dh = opendir($name);
+ if ($dh === false) {
+ echo $me.': can not open directory: `'.$name."'\n";
+ $ret++;
+ } else {
+ if (count($args)>1) { echo $name.":\n"; }
+ $files = array();
+ while (false !== ($file = readdir($dh))) {
+ $files[]="$file";
+ }
+ sort($files);
+ echo implode("\n",$files)."\n";
+ closedir($dh);
}
- sort($files);
- echo implode("\n",$files)."\n";
- closedir($dh);
+ } else {
+ echo $name."\n";
}
} else {
- echo $name."\n";
+ echo $me.': file does not exist: `'.$name."'\n";
+ $ret++;
}
- } else {
- echo $me.': file does not exist: `'.$name."'\n";
- $ret++;
}
+ return $ret;
}
- return $ret;
}
+