1
2
3
4
5
6 using System;
7 using System.Collections;
8 using System.IO;
9 using paths;
10
11 int main(int argc, const char** argv)
12 {
13 try
14 {
15 List<string> files;
16 for (int i = 1; i < argc; ++i;)
17 {
18 string arg = argv[i];
19 if (arg.StartsWith("--"))
20 {
21 if (arg == "--help")
22 {
23 PrintHelp();
24 return 1;
25 }
26 }
27 else if (arg.StartsWith("-"))
28 {
29 string options = arg.Substring(1);
30 if (options.IsEmpty())
31 {
32 throw Exception("unknown option '" + arg + "'");
33 }
34 else
35 {
36 bool unknown = false;
37 string uo;
38 for (char o : options)
39 {
40 switch (o)
41 {
42 case 'h':
43 {
44 PrintHelp();
45 return 1;
46 }
47 default:
48 {
49 unknown = true;
50 uo.Append(o);
51 break;
52 }
53 }
54 if (unknown)
55 {
56 throw Exception("unknown option '-" + uo + "'");
57 }
58 }
59 }
60 }
61 else
62 {
63 files.Add(arg);
64 }
65 }
66 if (files.IsEmpty())
67 {
68 files.Add(string());
69 }
70 if (!HasEnv("SHELL"))
71 {
72 files = Expand(files);
73 }
74 Catenate(files);
75 }
76 catch (const Exception& ex)
77 {
78 Console.Error() << ex.ToString() << endl();
79 return 1;
80 }
81 return 0;
82 }