Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tools.cs « HtmlAgilityPack « MainsoftWebTest « mainsoft « Test « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87209529d8f86f17e0f3cd4b18bea59f818545eb (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// HtmlAgilityPack V1.0 - Simon Mourier <simonm@microsoft.com>
using System;
using System.Diagnostics;
using System.IO;

namespace HtmlAgilityPack
{
	internal struct IOLibrary
	{
		internal static void MakeWritable(string path)
		{
			if (!File.Exists(path))
				return;
			File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.ReadOnly);
		}

		internal static void CopyAlways(string source, string target)
		{
			if (!File.Exists(source))
				return;
			Directory.CreateDirectory(Path.GetDirectoryName(target));
			MakeWritable(target);
			File.Copy(source, target, true);
		}
    }
#if !MONO
    internal struct HtmlLibrary
	{
		[Conditional("DEBUG")]
		internal static void GetVersion(out string version)
		{
			System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1, true);
			version = sf.GetMethod().DeclaringType.Assembly.GetName().Version.ToString();
		}

		[Conditional("DEBUG")]
		[Conditional("TRACE")]
		internal static void Trace(object Value)
		{
			// category is the method
			string name = null;
			GetCurrentMethodName(2, out name);
			System.Diagnostics.Trace.WriteLine(Value, name);
		}

		[Conditional("DEBUG")]
		[Conditional("TRACE")]
		internal static void TraceStackFrame(int steps)
		{
			string name = null;
			GetCurrentMethodName(2, out name);
			string trace = "";
			for(int i=1;i<steps;i++)
			{
				System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(i, true);
				trace += sf.ToString();
			}
			System.Diagnostics.Trace.WriteLine(trace, name);
			System.Diagnostics.Trace.WriteLine("");
		}

		[Conditional("DEBUG")]
		internal static void GetCurrentMethodName(out string name)
		{
			name = null;
			GetCurrentMethodName(2, out name);
		}

		[Conditional("DEBUG")]
		internal static void GetCurrentMethodName(int skipframe, out string name)
		{
			StackFrame sf = new StackFrame(skipframe, true);
			name = sf.GetMethod().DeclaringType.Name + "." + sf.GetMethod().Name;
		}

    }
#endif
    
    internal class HtmlCmdLine
	{
		static internal bool Help;

		static HtmlCmdLine()
		{
			Help = false;
			ParseArgs();
		}

		internal static string GetOption(string name, string def)
		{
			string p = def;
			string[] args = Environment.GetCommandLineArgs();
			for (int i=1;i<args.Length;i++)
			{
				GetStringArg(args[i], name, ref p);
			}
			return p;
		}

		internal static string GetOption(int index, string def)
		{
			string p = def;
			string[] args = Environment.GetCommandLineArgs();
			int j = 0;
			for (int i=1;i<args.Length;i++)
			{
				if (GetStringArg(args[i], ref p))
				{
					if (index==j)
						return p;
					else
						p = def;
					j++;
				}
			}
			return p;
		}

		internal static bool GetOption(string name, bool def)
		{
			bool p = def;
			string[] args = Environment.GetCommandLineArgs();
			for (int i=1;i<args.Length;i++)
			{
				GetBoolArg(args[i], name, ref p);
			}
			return p;
		}

		internal static int GetOption(string name, int def)
		{
			int p = def;
			string[] args = Environment.GetCommandLineArgs();
			for (int i=1;i<args.Length;i++)
			{
				GetIntArg(args[i], name, ref p);
			}
			return p;
		}

		private static void ParseArgs()
		{
			string[] args = Environment.GetCommandLineArgs();
			for (int i=1;i<args.Length;i++)
			{
				// help
				GetBoolArg(args[i], "?", ref Help);
				GetBoolArg(args[i], "h", ref Help);
				GetBoolArg(args[i], "help", ref Help);
			}
		}

		private static bool GetStringArg(string Arg, ref string ArgValue)
		{
			if (('/'==Arg[0]) || ('-'==Arg[0]))
				return false;
			ArgValue = Arg;
			return true;
		}

		private static void GetStringArg(string Arg, string Name, ref string ArgValue)
		{
			if (Arg.Length<(Name.Length+3)) // -name:x is 3 more than name
				return;
			if (('/'!=Arg[0]) && ('-'!=Arg[0]))	// not a param
				return;
			if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
				ArgValue = Arg.Substring(Name.Length+2, Arg.Length-Name.Length-2);
		}

		private static void GetBoolArg(string Arg, string Name, ref bool ArgValue)
		{
			if (Arg.Length<(Name.Length+1)) // -name is 1 more than name
				return;
			if (('/'!=Arg[0]) && ('-'!=Arg[0]))	// not a param
				return;
			if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
				ArgValue = true;
		}

		private static void GetIntArg(string Arg, string Name, ref int ArgValue)
		{
			if (Arg.Length<(Name.Length+3)) // -name:12 is 3 more than name
				return;
			if (('/'!=Arg[0]) && ('-'!=Arg[0]))	// not a param
				return;
			if (Arg.Substring(1, Name.Length).ToLower()==Name.ToLower())
			{
				try
				{
					ArgValue = Convert.ToInt32(Arg.Substring(Name.Length+2, Arg.Length-Name.Length-2));
				}
				catch
				{
				}
				
			}
		}
	}

	internal class HtmlConsoleListener: System.Diagnostics.TraceListener
	{
		public override void WriteLine(string Message)
		{
			Write(Message + "\n");
		}

		public override void Write(string Message)
		{
			Write(Message, "");
		}
	
		public override void Write(string Message, string Category)
		{
			Console.Write("T:" + Category + ": " + Message);
		}

		public override void WriteLine(string Message, string Category)
		{
			Write(Message + "\n", Category);
		}
	}

}