@@ -12,23 +12,140 @@ static class Program
12
12
{
13
13
static void Main ( string [ ] args )
14
14
{
15
- string code = ">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+." ;
16
- string code2 = "++++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++<<<<<<<<<<<<<-]>>>>>>>>--------.>>---.>>--------..>---------.<<<<<<<<<--------.>>>----.>>>>-----.>++.++.<-.----.<.>>>.<<<<<<<<<+." ;
15
+ // string code = ">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.";
16
+ // string code2 = "++++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++<<<<<<<<<<<<<-]>>>>>>>>--------.>>---.>>--------..>---------.<<<<<<<<<--------.>>>----.>>>>-----.>++.++.<-.----.<.>>>.<<<<<<<<<+.";
17
17
18
- //Bitmap bmp = new Bitmap("E:\\Desktop\\Untitled.png");
19
- //Bitmap newBmp = Braincopter.Encode(bmp, code);
20
- //string newCode = Braincopter.Decode(newBmp);
18
+ if ( args . Length == 0 )
19
+ {
20
+ PrintHelp ( ) ;
21
+ return ;
22
+ }
21
23
22
- Bitmap bmp = Brainloller . Encode ( code2 , 22 , Color . Firebrick ) ;
23
- bmp . Save ( "E:\\ Desktop\\ brain.png" ) ;
24
+ switch ( args [ 0 ] )
25
+ {
26
+ case "encode" :
27
+ if ( args . Length != 5 )
28
+ {
29
+ Console . WriteLine ( "Wrong number of parameters." ) ;
30
+ return ;
31
+ }
24
32
25
- //Bitmap bmp = new Bitmap("E:\\Desktop\\brain.png");
26
- //string code3 = Brainloller.Decode(bmp);
27
- //Brainfuck.Run(code3);
33
+ if ( args [ 1 ] == "brainloller" )
34
+ {
35
+ StreamReader reader = new StreamReader ( args [ 2 ] ) ;
36
+ string code = reader . ReadToEnd ( ) ;
37
+ reader . Close ( ) ;
38
+ Bitmap newBmp = Brainloller . Encode ( code , int . Parse ( args [ 3 ] ) , Color . Firebrick ) ;
39
+ newBmp . Save ( args [ 4 ] ) ;
40
+ }
41
+ else if ( args [ 1 ] == "braincopter" )
42
+ {
43
+ StreamReader reader = new StreamReader ( args [ 2 ] ) ;
44
+ string code = reader . ReadToEnd ( ) ;
45
+ reader . Close ( ) ;
46
+ Bitmap original = new Bitmap ( args [ 3 ] ) ;
47
+ Bitmap newBmp = Braincopter . Encode ( original , code ) ;
48
+ newBmp . Save ( args [ 4 ] ) ;
49
+ }
50
+ else
51
+ {
52
+ Console . WriteLine ( "Unrecognized language." ) ;
53
+ }
54
+ break ;
55
+ case "decode" :
56
+ if ( args [ 1 ] == "brainloller" )
57
+ {
58
+ Bitmap img = new Bitmap ( args [ 2 ] ) ;
59
+ string code = Brainloller . Decode ( img ) ;
60
+ StreamWriter writer = new StreamWriter ( args [ 3 ] ) ;
61
+ writer . WriteLine ( code ) ;
62
+ writer . Close ( ) ;
63
+ }
64
+ else if ( args [ 1 ] == "braincopter" )
65
+ {
66
+ Bitmap img = new Bitmap ( args [ 2 ] ) ;
67
+ string code = Braincopter . Decode ( img ) ;
68
+ StreamWriter writer = new StreamWriter ( args [ 3 ] ) ;
69
+ writer . WriteLine ( code ) ;
70
+ writer . Close ( ) ;
71
+ }
72
+ else
73
+ {
74
+ Console . WriteLine ( "Unrecognized language." ) ;
75
+ }
76
+ break ;
77
+ case "reduce" :
78
+ if ( args . Length != 4 )
79
+ {
80
+ Console . WriteLine ( "Wrong number of parameters." ) ;
81
+ return ;
82
+ }
28
83
29
- //Brainfuck.Run(newCode);
84
+ Bitmap bmp = new Bitmap ( args [ 1 ] ) ;
85
+ Bitmap save = Brainloller . Reduce ( bmp , int . Parse ( args [ 2 ] ) ) ;
86
+ save . Save ( args [ 3 ] ) ;
87
+ break ;
88
+ case "enlarge" :
89
+ if ( args . Length != 4 )
90
+ {
91
+ Console . WriteLine ( "Wrong number of parameters." ) ;
92
+ return ;
93
+ }
30
94
31
- Console . ReadLine ( ) ;
95
+ Bitmap src = new Bitmap ( args [ 1 ] ) ;
96
+ Bitmap New = Brainloller . Enlarge ( src , int . Parse ( args [ 2 ] ) ) ;
97
+ New . Save ( args [ 3 ] ) ;
98
+ break ;
99
+ case "run" :
100
+ if ( args . Length != 2 )
101
+ {
102
+ Console . WriteLine ( "Wrong number of parameters." ) ;
103
+ return ;
104
+ }
105
+
106
+ StreamReader read = new StreamReader ( args [ 1 ] ) ;
107
+ Brainfuck . Run ( read . ReadToEnd ( ) ) ;
108
+ read . Close ( ) ;
109
+ break ;
110
+ case "help" :
111
+ default :
112
+ PrintHelp ( ) ;
113
+ break ;
114
+ }
115
+ }
116
+
117
+ static void PrintHelp ( )
118
+ {
119
+ Console . WriteLine ( "Usage: bftools <operation> <language> <params>" ) ;
120
+ Console . WriteLine ( ) ;
121
+ Console . WriteLine ( "Intro" ) ;
122
+ Console . WriteLine ( "======" ) ;
123
+ Console . WriteLine ( "This utility SAVES images in PNG format, so watch your extensions." ) ;
124
+ Console . WriteLine ( "This utility READS images in all formats supported by the .NET framework." ) ;
125
+ Console . WriteLine ( ) ;
126
+ Console . WriteLine ( "Encoding" ) ;
127
+ Console . WriteLine ( "=========" ) ;
128
+ Console . WriteLine ( "bftools encode brainloller <input file> <image width> <output image>" ) ;
129
+ Console . WriteLine ( "bftools encode braincopter <input file> <original image> <output image>" ) ;
130
+ Console . WriteLine ( ) ;
131
+ Console . WriteLine ( "Decoding" ) ;
132
+ Console . WriteLine ( "=========" ) ;
133
+ Console . WriteLine ( "bftools decode brainloller <input image> <output file>" ) ;
134
+ Console . WriteLine ( "bftools decode braincopter <input image> <output file>" ) ;
135
+ Console . WriteLine ( ) ;
136
+ Console . WriteLine ( "Running" ) ;
137
+ Console . WriteLine ( "========" ) ;
138
+ Console . WriteLine ( "bftools run <input file>" ) ;
139
+ Console . WriteLine ( ) ;
140
+ Console . WriteLine ( "Image operations" ) ;
141
+ Console . WriteLine ( "=================" ) ;
142
+ Console . WriteLine ( "bftools enlarge <input image> <factor> <output image>" ) ;
143
+ Console . WriteLine ( "bftools reduce <input image> <factor> <output image>" ) ;
144
+ Console . WriteLine ( ) ;
145
+ Console . WriteLine ( "Getting help" ) ;
146
+ Console . WriteLine ( "=============" ) ;
147
+ Console . WriteLine ( "bftools help" ) ;
148
+ Console . WriteLine ( ) ;
32
149
}
33
150
}
34
151
}
0 commit comments