~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Wrapper/FreeImage.NET/cs/SourceFileMerger/Program.cs

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Text;
 
4
using System.IO;
 
5
using System.Text.RegularExpressions;
 
6
 
 
7
namespace FreeImageNET_SFM
 
8
{
 
9
        class Program
 
10
        {
 
11
                static private Regex searchPattern = new Regex("#include[ \\t]*\"(.*)\"", RegexOptions.Compiled);
 
12
                static private FileStream fStream = null;
 
13
                static private TextWriter textOut = null;
 
14
                private const string baseFolder = @"..\..\..\Library\";
 
15
                private const string templateName = @"FreeImage.cs.template";
 
16
 
 
17
                static int Main(string[] args)
 
18
                {
 
19
                        try
 
20
                        {
 
21
                                if (!File.Exists(templateName))
 
22
                                {
 
23
                                        Console.WriteLine(templateName + " not found."); return 1;
 
24
                                }
 
25
 
 
26
                                try
 
27
                                {
 
28
                                        fStream = new FileStream(@"FreeImage.cs", FileMode.Create);
 
29
                                }
 
30
                                catch
 
31
                                {
 
32
                                        Console.WriteLine("Unable to create output file."); return 2;
 
33
                                }
 
34
 
 
35
                                textOut = new StreamWriter(fStream);
 
36
 
 
37
                                string[] content = File.ReadAllLines(templateName);
 
38
 
 
39
                                for (int lineNumber = 0; lineNumber < content.Length; lineNumber++)
 
40
                                {
 
41
                                        string line = content[lineNumber].Trim();
 
42
                                        Match match = searchPattern.Match(line);
 
43
 
 
44
                                        if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
 
45
                                        {
 
46
                                                if (!File.Exists(baseFolder + match.Groups[1].Value))
 
47
                                                {
 
48
                                                        throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
 
49
                                                }
 
50
 
 
51
                                                ParseFile(baseFolder + match.Groups[1].Value);
 
52
                                        }
 
53
                                        else
 
54
                                        {
 
55
                                                textOut.WriteLine(content[lineNumber]);
 
56
                                        }
 
57
                                }
 
58
 
 
59
                                return 0;
 
60
                        }
 
61
                        catch (Exception ex)
 
62
                        {
 
63
                                Console.WriteLine(ex.ToString());
 
64
                                //Console.WriteLine("Error while parsing.");
 
65
                                return 3;
 
66
                        }
 
67
                        finally
 
68
                        {
 
69
                                if (textOut != null)
 
70
                                {
 
71
                                        textOut.Flush();
 
72
                                        textOut.Close();
 
73
                                }
 
74
                        }
 
75
                }
 
76
 
 
77
                private static void ParseFile(string fileName)
 
78
                {
 
79
                        int lineNumber = 0;
 
80
                        string line;
 
81
                        Match match;
 
82
                        string[] content = File.ReadAllLines(fileName);
 
83
 
 
84
            if (fileName.Contains("AssemblyInfo.cs"))
 
85
            {
 
86
                                while (content[lineNumber].Trim().StartsWith("using") && lineNumber < content.Length)
 
87
                                {
 
88
                                        lineNumber++;
 
89
                                }
 
90
                lineNumber++;
 
91
            }
 
92
            else
 
93
            {
 
94
                                while (!(content[lineNumber].Trim().StartsWith("namespace")) && lineNumber < content.Length)
 
95
                                {
 
96
                                        lineNumber++;
 
97
                                }
 
98
                //lineNumber += 2;
 
99
            }
 
100
 
 
101
                        for (; lineNumber < content.Length; lineNumber++)
 
102
                        {
 
103
                                line = content[lineNumber].Trim();
 
104
                                match = searchPattern.Match(line);
 
105
 
 
106
                                if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
 
107
                                {
 
108
                                        if (!File.Exists(baseFolder + match.Groups[1].Value))
 
109
                                        {
 
110
                                                throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
 
111
                                        }
 
112
 
 
113
                                        ParseFile(baseFolder + match.Groups[1].Value);
 
114
                                }
 
115
                                else
 
116
                                {
 
117
                                        textOut.WriteLine(content[lineNumber]);
 
118
                                }
 
119
                        }
 
120
                }
 
121
        }
 
122
}
 
 
b'\\ No newline at end of file'