-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildProperties.cs
89 lines (72 loc) · 1.65 KB
/
BuildProperties.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
namespace BrainfuckCompiler
{
public class BuildProperties
{
public string FileName { get; private set; }
public IOMode IOMode { get; private set; } = IOMode.Console;
public bool LeaveCSource { get; private set; } = false;
/*
* Flags:
* -cio: Specify CommandLineIO
* -fio: Specify FileIO (default)
* -s : Leave the C source file (named temp.c) instead of deleting it
*/
public BuildProperties(string[] args)
{
//Checks to make sure that at least a source file was provided
if (args.Length == 0)
{
Console.WriteLine("Please provide a source file.");
Environment.Exit(-1);
}
//Determine file name location
int FileNameLocation = DetermineFileNameLocation(args);
if(FileNameLocation == -1)
{
Console.WriteLine("Please provide a source file.");
Environment.Exit(-1);
}
FileName = args[FileNameLocation];
if (!File.Exists(FileName))
{
Console.WriteLine("Please provide a source file.");
Environment.Exit(-1);
}
foreach (var arg in args)
{
switch (arg.ToLower())
{
case "-cio":
IOMode = IOMode.Console;
break;
case "-fio":
IOMode = IOMode.File;
break;
case "-s":
LeaveCSource = true;
break;
}
}
}
//I understand this method isn't a good way to determine where the file is
private static int DetermineFileNameLocation(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
if (args[i].Contains('.'))
return i;
}
return -1;
}
}
public enum IOMode
{
File,
Console
}
}