-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (42 loc) · 1.47 KB
/
Copy pathProgram.cs
File metadata and controls
48 lines (42 loc) · 1.47 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
namespace App {
class Program {
// constant
/// <summary>
/// Size of read-write buffer.
/// </summary>
public const int BUFFER_SIZE = 16 * 1024;
// static method
/// <summary>
/// Loving someone isn’t enough to guarantee we will know how to care for them.
/// For this, we need to learn to understand the distinctive way in which they
/// need our love to manifest itself in order for it to feel real to them.
/// : The School of Life
/// </summary>
/// <param name="args">Input arguments.</param>
static void Main(string[] args) {
Params p = new Params(args);
char[] buf = new char[BUFFER_SIZE];
FileMode m = p.Append ? FileMode.Append : FileMode.Create;
TextWriter f = p.File != "" ? new StreamWriter(File.Open(p.File, m)) : null;
while (Transfer(Console.Out, f, Console.In, buf) > 0) ;
if (f != null) f.Close();
}
/// <summary>
/// Transfer text to output writers from input reader.
/// </summary>
/// <param name="o0">Text writer 0.</param>
/// <param name="o1">Text writer 1.</param>
/// <param name="i0">Text reader 0.</param>
/// <param name="buf">Read buffer.</param>
/// <returns>Number of characters transferred.</returns>
private static int Transfer(TextWriter o0, TextWriter o1, TextReader i0, char[] buf) {
int r = i0.ReadBlock(buf, 0, buf.Length);
if (r <= 0) return r;
if (o0 != null) o0.Write(buf, 0, r);
if (o1 != null) o1.Write(buf, 0, r);
return r;
}
}
}