Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace LightingSchemeAnalyzer
- {
- class Program
- {
- static void Main(string[] args)
- {
- var calls = new StringBuilder();
- var dic = new Dictionary<string, string>();
- var map = new Dictionary<string, string>();
- var inputList = new List<string>();
- string s = null;
- int stateBit = 0;
- while ((s = Console.ReadLine()) != null)
- {
- if (s.Contains("end")) break;
- if (s.Length < 1) continue;
- var cols = s.Split(new char[] {'\t'}, StringSplitOptions.RemoveEmptyEntries);
- if (cols.Length > 1)
- {
- inputList.Add(cols[0]);
- calls.AppendFormat("{0}(button := {1}, sceneCount := {2}, lightsOn => state.{3});\r\n", cols[0], NameToButtons(cols[0]), cols.Length - 1, stateBit);
- stateBit++;
- }
- for (int i = 1; i < cols.Length; i++)
- {
- var outputs = new Regex("[a-z][0-9]+").Matches(cols[i]);
- foreach (var match in outputs)
- {
- var cur = string.Empty;
- dic.TryGetValue(match.ToString(), out cur);
- if (cur == null || !cur.Contains(cols[0]))
- {
- dic[match.ToString()] = cur + " " + cols[0];
- }
- }
- foreach (var match in outputs)
- {
- var cur = string.Empty;
- map.TryGetValue(match.ToString(), out cur);
- map[match.ToString()] = cur + " (" + cols[0] + ".sceneIdx = " + (i - 1).ToString() + " AND " + cols[0] + ".lightsOn) OR";
- }
- }
- }
- foreach (var input in inputList)
- {
- Console.WriteLine(input + ",");
- }
- foreach (var entry in dic)
- {
- Console.WriteLine("{0}\t{1}", entry.Key, entry.Value);
- }
- Console.WriteLine(calls);
- foreach (var entry in map)
- {
- string line = (entry.Value + ";").Replace(" OR;", ";");
- string num = new Regex("[0-9]*").Match(entry.Key).NextMatch().Value;
- if (entry.Key[0] == 'p')
- {
- Console.WriteLine("{0} :={1}", "DO" + num, line);
- }
- else
- {
- Console.WriteLine("{0} :={1}", "MO[" + num + "]", line);
- }
- }
- }
- static string NameToButtons(string name)
- {
- return "DI" + new Regex("[0-9]+.*").Match(name).Value.Replace("_", " OR DI");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement