-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy
More file actions
executable file
·29 lines (26 loc) · 696 Bytes
/
copy
File metadata and controls
executable file
·29 lines (26 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env escript
%% copy -- copy input to output
%%
%% We're not defining primitives like in the book,
%% We can't detect ENDFILE with io:get_line/1, and
%% it already receive only one line so no need to
%% detect ASCII NEWLINE as well.
%%
%% Since we can't detect ENDFILE, we can mimic ed(1)
%% behavior so that a "." in an empty line will quit.
%%
%% Correction: we can't detect ENDFILE in Erlang Shell,
%% but when running from terminal as an escript program,
%% you can pattern match Ctrl-D as eof.
copy() ->
Input = ststd:getc(),
copy(Input).
copy(eof) ->
{ok, eof};
copy(".\n") ->
{ok, eof};
copy(Input) ->
ststd:putc(Input),
copy().
main(_) ->
copy().