File: Options.cs

package info (click to toggle)
xsddiagram 1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 2,184 kB
  • ctags: 1,092
  • sloc: cs: 9,274; sh: 42; makefile: 26; xml: 3
file content (163 lines) | stat: -rw-r--r-- 5,797 bytes parent folder | download | duplicates (2)
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
//    XSDDiagram - A XML Schema Definition file viewer
//    Copyright (C) 2006-2011  Regis COSNIER
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Collections.Generic;

namespace XSDDiagram
{
    public class Options
    {
		public static string[] Arguments { get; private set; }
		public static string InputFile { get; private set; }
		public static string OutputFile { get; private set; }
        public static bool OutputOnStdOut { get; private set; }
        public static string OutputOnStdOutExtension { get; private set; }
		public static IList<string> RootElements { get; private set; }
		public static int ExpandLevel { get; private set; }
        public static bool ShowDocumentation { get; private set; }
        public static float Zoom { get; private set; }
		public static bool ForceHugeImageGeneration { get; private set; }
		public static bool RequestHelp { get; private set; }
		public static bool IsRunningOnMono { get; private set; }
        public static string Username { get; private set; }
        public static string Password { get; private set; }
        public static IList<string> TextOutputFields { get; private set; }

		static Options()
		{
			InputFile = null;
			OutputFile = null;
			OutputOnStdOut = false;
			OutputOnStdOutExtension = "png";
			RootElements = new List<string>();
			ExpandLevel = 0;
            ShowDocumentation = false;
            Zoom = 100.0f;
			ForceHugeImageGeneration = false;
			RequestHelp = false;
            TextOutputFields = new List<string>();

            IsRunningOnMono = Type.GetType("Mono.Runtime") != null;

			string[] args = Environment.GetCommandLineArgs();
			List<string> arguments = new List<string>();
			// Convert "--option:params" or "/option params" to "-option params"
			foreach (var argument in args)
			{
				string command = null;
				if (/*argument.StartsWith("/") ||*/ argument.StartsWith("-"))
					command = argument.Substring(1);
				else if (argument.StartsWith("--"))
					command = argument.Substring(2);
				if (!string.IsNullOrEmpty(command))
				{
					int indexOfColon = command.IndexOf(':');
					if (indexOfColon > 0)
					{
						string parameter = command.Substring(indexOfColon + 1);
						command = command.Substring(0, indexOfColon);
						arguments.Add("-" + command);
						arguments.Add(parameter);
					}
					else
						arguments.Add("-" + command);
				}
				else
					arguments.Add(argument);
			}
			Arguments = arguments.ToArray();

			int currentArgument = 1;
			while (currentArgument < arguments.Count)
			{
				string argument = arguments[currentArgument++];
				if (string.Compare("-h", argument, true) == 0)
				{
					RequestHelp = true;
				}
				else if (string.Compare("-o", argument, true) == 0)
				{
					if (currentArgument < arguments.Count)
						OutputFile = args[currentArgument++];
				}
				else if (string.Compare("-os", argument, true) == 0)
				{
					OutputOnStdOut = true;
					if (currentArgument < arguments.Count)
						OutputOnStdOutExtension = args[currentArgument++];
				}
				else if (string.Compare("-r", argument, true) == 0)
				{
					if (currentArgument < arguments.Count)
						RootElements.Add(args[currentArgument++]);
				}
                else if (string.Compare("-e", argument, true) == 0)
                {
                    if (currentArgument < arguments.Count)
                    {
                        try
                        {
                            ExpandLevel = int.Parse(args[currentArgument++]);
                        }
                        catch { }
                    }
                }
                else if(string.Compare("-d", argument, true) == 0)
                {
                    ShowDocumentation = true;
                }
				else if (string.Compare("-z", argument, true) == 0)
				{
					if (currentArgument < arguments.Count)
					{
						try
						{
							Zoom = (float)int.Parse(args[currentArgument++]);
						}
						catch { }
					}
				}
				else if (string.Compare("-y", argument, true) == 0)
				{
					ForceHugeImageGeneration = true;
				}
                else if (string.Compare("-u", argument, true) == 0)
				{
					if (currentArgument < arguments.Count)
						Username = args[currentArgument++];
				}
                else if (string.Compare("-p", argument, true) == 0)
				{
					if (currentArgument < arguments.Count)
						Password = args[currentArgument++];
				}
                else if (string.Compare("-f", argument, true) == 0)
                {
                    if (currentArgument < arguments.Count)
                    {
                        string textOutputFields = args[currentArgument++];
                        foreach (string field in textOutputFields.Split(new char[] { ',' }))
                            TextOutputFields.Add(field.Trim());
                    }
                }
                else
					InputFile = argument;
			}
		}
    }
}