-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (64 loc) · 2.06 KB
/
Program.cs
File metadata and controls
73 lines (64 loc) · 2.06 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.IO;
using log4net;
using log4net.Config;
namespace ArithmeticCoding.Console
{
static class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
try
{
SetupLogging();
if (args.Length != 3)
{
ShowHelp();
return;
}
switch (args[0])
{
case "-c":
case "c":
Compress(args[1], args[2]);
break;
case "-d":
case "d":
Decompress(args[1], args[2]);
break;
default:
ShowHelp();
break;
}
}
catch (Exception e)
{
Log.Error(e);
System.Console.WriteLine(e.Message);
}
}
private static void SetupLogging()
{
XmlConfigurator.Configure(new FileInfo("log4net.config"));
}
private static void ShowHelp()
{
string fileName = Path.GetFileName(Environment.GetCommandLineArgs()[0]);
System.Console.WriteLine("Usage: {0} -c input output", fileName);
System.Console.WriteLine(" {0} -d input output", fileName);
System.Console.WriteLine();
System.Console.WriteLine("Use -c to compress input into output.");
System.Console.WriteLine("Use -d to decompress input into output.");
System.Console.WriteLine("Input and output are paths to the corresponding files.");
}
private static void Compress(string inputFile, string outputFile)
{
ArithmeticCoding.Compress(inputFile, outputFile);
}
private static void Decompress(string inputFile, string outputFile)
{
ArithmeticCoding.Decompress(inputFile, outputFile);
}
}
}