C-CS PortWizard
C:/Users/Brad/Documents/School Assignments/Year 2/Semester 2 v2/Software Quality 2/Assignment 3/ccsportwizard/CCSPortWizard/CCSPortWizard/Program.cs
1 
8 using System;
9 using System.Collections.Generic;
10 using System.Linq;
11 using System.Text;
12 using System.Threading.Tasks;
13 using System.Text.RegularExpressions;
14 using System.IO;
15 
16 namespace CCSPortWizard
17 {
18  internal class Program
19  {
20  private static void Main(string[] args)
21  {
26  string CSNamespace = "";
27  string InputLines;
28  int DestinationIndex;
29  int SourceIndex;
30  StreamReader SourceFile;
31  StreamWriter DestinationFile;
32  Match SyntaxMatch;
33  Console.Clear();
34  Console.ForegroundColor = ConsoleColor.DarkGreen;
35 
39  if ((args.Length != 4) || (args[0] != "-i" && args[0] != "-o") || ((args[0] == "-i" && args[2] != "-o") && (args[0] == "-o" && args[2] != "-i")))
40  {
41  Console.ForegroundColor = ConsoleColor.Red;
42  Console.WriteLine("[Invalid command line input]");
43  Console.WriteLine("CCSPortWizard -i inputfile.c -o outputfile.cs");
44  Console.ForegroundColor = ConsoleColor.White;
45  return;
46  }
47  Console.WriteLine("[INPUT COMMAND VALID...]");
48 
52  if (args[2] == "-o") { DestinationIndex = 3; SourceIndex = 1; Console.WriteLine("[OUTPUT COMMAND VALID...]"); }
53  else { DestinationIndex = 1; SourceIndex = 3; }
54 
58  SyntaxMatch = Regex.Match(args[DestinationIndex], @"(\w+).cs");
59  if (SyntaxMatch.Success) { CSNamespace = SyntaxMatch.Groups[1].Value; Console.WriteLine("[OUTPUT FILE VALID...]"); }
60  else { Console.WriteLine(@"Specific destination filename is not a valid "".cs"" file"); }
61 
65  try
66  {
67  SourceFile = new StreamReader(args[SourceIndex]);
68  DestinationFile = new StreamWriter(args[DestinationIndex]);
69 
70  Transposer Transpose = new Transposer(CSNamespace);
71 
72  bool SyntaxMainScan = false;
73 
74  InputLines = String.Empty;
75 
79  while ((InputLines = SourceFile.ReadLine()) != null)
80  {
81  InputLines.TrimEnd();
82 
86  if (Transpose.SyntaxScan(ref InputLines))
87  {
88  DestinationFile.WriteLine(InputLines);
89  SyntaxMainScan = true;
90  }
91  else
92  {
96  if (SyntaxMainScan) { DestinationFile.WriteLine("\t\t" + InputLines); }
97  else { DestinationFile.WriteLine(InputLines); }
98  }
99  InputLines = String.Empty;
100  }
101 
105  if (SyntaxMainScan)
106  {
107  DestinationFile.WriteLine("\t}");
108  DestinationFile.WriteLine("}");
109  }
110 
114  SourceFile.Close();
115  DestinationFile.Close();
116  Console.WriteLine("[TRANSPOSE COMPLETE...]");
117  }
118  catch (Exception ex)
119  {
120  Console.ForegroundColor = ConsoleColor.Red;
121  Console.WriteLine("[TRANSPOSE ERROR!]");
122  Console.WriteLine(ex.Message);
123  }
124  Console.ForegroundColor = ConsoleColor.White;
125  return;
126  }
127  }
128 }
bool SyntaxScan(ref string codeLine)
This method scan each line of object c code and transpose it to c-sharp
Definition: Transposer.cs:507
static void Main(string[] args)
Definition: Program.cs:20