Permalink
Browse files

Merge pull request #30 from rippinblaise/gh-pages

Add in nl and ls utility clones from blaise++
  • Loading branch information...
2 parents 84649bb + 18c5165 commit 3390389aa6581aa443fd60755cc4ddb2ae0ba826 @Whiteknight committed Nov 23, 2011
Showing with 88 additions and 0 deletions.
  1. +37 −0 ls.winxed
  2. +51 −0 nl.winxed
View
@@ -0,0 +1,37 @@
+function show_help(var args) {
+ print("Usage: ");
+ print(args[0]);
+ say(" [directory]");
+ exit(0);
+}
+
+function main[main](var args) {
+ var rosella = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("filesystem");
+ var dirname = ".";
+ for(var i = 1; i < args; i++) {
+ var arg = args[i];
+ if(arg == "-h" || arg == "--help")
+ show_help(args);
+ else
+ dirname = arg;
+ }
+ var dir = new Rosella.FileSystem.Directory(dirname);
+ if(!(dir.exists())) {
+ print("ls: cannot access ");
+ print(dirname);
+ say(": No such file or directory");
+ exit(-1);
+ }
+ var files = dir.get_files();
+ for(var file in files) {
+ print(file.short_name());
+ print(" ");
+ }
+ var dirs = dir.get_subdirectories();
+ for(var curdir in dirs) {
+ print(curdir.short_name());
+ print(" ");
+ }
+ say("");
+}
View
@@ -0,0 +1,51 @@
+function out(var output, var all) {
+ var i = 0;
+ for(string s in output) {
+ if(s != "" || all)
+ print(i++);
+ print(" ");
+ say(s);
+ }
+}
+
+function show_help(var args) {
+ print("Usage: ");
+ print(args[0]);
+ say(" [args] [file]");
+ say(" -a number all lines");
+ say(" -t number only nonempty lines");
+ say(" -h display this help message");
+ exit(0);
+}
+
+function main[main](var args) {
+ var rosella = load_packfile("rosella/core.pbc");
+ var(Rosella.initialize_rosella)("filesystem");
+ var filename = "";
+ var all;
+ for(var i = 1; i < args; i++) {
+ var arg = args[i];
+ if(arg == "-t")
+ all = false;
+ else if(arg == "-a")
+ all = true;
+ else if(arg == "-h" || arg == "--help")
+ show_help(args);
+ else
+ filename = arg;
+ }
+ if(filename == "") {
+ say("Please give a filename");
+ exit(0);
+ }
+ var file = new Rosella.FileSystem.File(filename);
+ if(!(file.exists())) {
+ print("nl: ");
+ print(filename);
+ say(": No such file or directory");
+ exit(-1);
+ }
+ string txt = file.read_all_text();
+ var output = split("\n", txt);
+ out(output, all);
+}

0 comments on commit 3390389

Please sign in to comment.