blob: 85b3dc617612c355e575a2aeb0e0bcfe1688e4f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.
|