summaryrefslogtreecommitdiff
path: root/miralib/ex/mrev
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/mrev')
-rwxr-xr-xmiralib/ex/mrev22
1 files changed, 22 insertions, 0 deletions
diff --git a/miralib/ex/mrev b/miralib/ex/mrev
new file mode 100755
index 0000000..85b3dc6
--- /dev/null
+++ b/miralib/ex/mrev
@@ -0,0 +1,22 @@
+#! /usr/bin/mira -exec
+main :: [sys_message]
+main = map f (tl $*), if # $* > 1 ||$* is equivalent to argv
+ = [Stdout (revlines $-)], otherwise ||no files, use stdin ($-)
+
+f :: [char]->sys_message
+f fil = Stderr ("mrev: cannot open "++fil++"\n"), if badfile
+ = Stdout (revlines (read fil)), otherwise
+ where
+ badfile = ~ member (filemode fil) 'r'
+
+revlines :: [char]->[char]
+revlines = lay.map reverse.lines
+
+||The usage of this command (from a UNIX shell) is
+|| mrev [file] ...
+||If no files given, takes data from stdin. This is a Miranda version
+||of the UNIX command `rev' which reverses each line of its input.
+
+||This example is a template for turning any Miranda function of type
+||[char]->[char] into a UNIX filter. Replace `revlines' in the above
+||text, by your chosen function.