File: Program.cs

package info (click to toggle)
freeimage 3.18.0%2Bds2-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,824 kB
  • sloc: cpp: 42,339; cs: 36,178; pascal: 4,629; ansic: 1,294; makefile: 101; sh: 84
file content (122 lines) | stat: -rw-r--r-- 3,008 bytes parent folder | download | duplicates (8)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace FreeImageNET_SFM
{
	class Program
	{
		static private Regex searchPattern = new Regex("#include[ \\t]*\"(.*)\"", RegexOptions.Compiled);
		static private FileStream fStream = null;
		static private TextWriter textOut = null;
		private const string baseFolder = @"..\..\..\Library\";
		private const string templateName = @"FreeImage.cs.template";

		static int Main(string[] args)
		{
			try
			{
				if (!File.Exists(templateName))
				{
					Console.WriteLine(templateName + " not found."); return 1;
				}

				try
				{
					fStream = new FileStream(@"FreeImage.cs", FileMode.Create);
				}
				catch
				{
					Console.WriteLine("Unable to create output file."); return 2;
				}

				textOut = new StreamWriter(fStream);

				string[] content = File.ReadAllLines(templateName);

				for (int lineNumber = 0; lineNumber < content.Length; lineNumber++)
				{
					string line = content[lineNumber].Trim();
					Match match = searchPattern.Match(line);

					if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
					{
						if (!File.Exists(baseFolder + match.Groups[1].Value))
						{
							throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
						}

						ParseFile(baseFolder + match.Groups[1].Value);
					}
					else
					{
						textOut.WriteLine(content[lineNumber]);
					}
				}

				return 0;
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
				//Console.WriteLine("Error while parsing.");
				return 3;
			}
			finally
			{
				if (textOut != null)
				{
					textOut.Flush();
					textOut.Close();
				}
			}
		}

		private static void ParseFile(string fileName)
		{
			int lineNumber = 0;
			string line;
			Match match;
			string[] content = File.ReadAllLines(fileName);

            if (fileName.Contains("AssemblyInfo.cs"))
            {
				while (content[lineNumber].Trim().StartsWith("using") && lineNumber < content.Length)
				{
					lineNumber++;
				}
                lineNumber++;
            }
            else
            {
				while (!(content[lineNumber].Trim().StartsWith("namespace")) && lineNumber < content.Length)
				{
					lineNumber++;
				}
                //lineNumber += 2;
            }

			for (; lineNumber < content.Length; lineNumber++)
			{
				line = content[lineNumber].Trim();
				match = searchPattern.Match(line);

				if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
				{
					if (!File.Exists(baseFolder + match.Groups[1].Value))
					{
						throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
					}

					ParseFile(baseFolder + match.Groups[1].Value);
				}
				else
				{
					textOut.WriteLine(content[lineNumber]);
				}
			}
		}
	}
}