Skip to content
This repository was archived by the owner on Jan 3, 2022. It is now read-only.

Commit 3b0d693

Browse files
committed
Initial commit of project sources
0 parents  commit 3b0d693

File tree

88 files changed

+7265
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7265
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/src/dshell/obj
3+
/src/dshell/bin
4+
/src/_ReSharper.dshell.vs2010
5+
/src/packages

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deveel Shell Application (dshell)
2+
=================================
3+
4+
This library provides an easy way to build .NET/Mono console-driven applications, handling complex inputs, defining custom commands, text auto-completion, user sessions, etc.

src/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
*.user
3+
*.suo

src/dshell.vs2010.sln

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dshell.vs2010", "dshell\dshell.vs2010.csproj", "{5E849796-A39E-4AF8-A516-D2837C3CCE6F}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

src/dshell/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.user
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace Deveel.Collections {
6+
/// <summary>
7+
/// An <see cref="IEnumerator">enumerator</see> returning end-truncated
8+
/// matching values from a sorted list.
9+
/// </summary>
10+
/// <remarks>
11+
/// This IEnumerator is initialized with a sorted ISet, sorted
12+
/// IDictionary or another IEnumerator that must be placed at the
13+
/// beginning of the matching area of a sorted set.
14+
/// <para>
15+
/// This IEnumerator is commonly used for TAB-completion.
16+
/// </para>
17+
/// </remarks>
18+
public class SortedMatchEnumerator : IEnumerator<string> {
19+
#region ctor
20+
public SortedMatchEnumerator(string partialMatch, IEnumerator<String> en) {
21+
this.partialMatch = partialMatch;
22+
this.en = en;
23+
}
24+
25+
public SortedMatchEnumerator(string partialMatch, ICollection<string> c, IComparer<string> comparer)
26+
: this(partialMatch, SubsetCollection<string>.Tail(c, comparer, partialMatch).GetEnumerator()) {
27+
}
28+
29+
public SortedMatchEnumerator(string partialMatch, SortedList<string, string> list)
30+
: this(partialMatch, SubsetCollection<string>.Tail(list, partialMatch).GetEnumerator()) {
31+
}
32+
33+
public SortedMatchEnumerator(string partialMatch, SortedDictionary<string, string> dictionary)
34+
: this(partialMatch, SubsetDictionary<string, string>.Tail(dictionary, partialMatch).Keys.GetEnumerator()) {
35+
}
36+
#endregion
37+
38+
#region Fields
39+
private readonly IEnumerator<string> en;
40+
private readonly string partialMatch;
41+
42+
private string prefix;
43+
private string suffix;
44+
45+
// the current match
46+
private string current;
47+
#endregion
48+
49+
#region Properties
50+
public string Prefix {
51+
get { return prefix; }
52+
set { prefix = value; }
53+
}
54+
55+
public string Suffix {
56+
get { return suffix; }
57+
set { suffix = value; }
58+
}
59+
60+
public string Current {
61+
get {
62+
string result = current;
63+
if (prefix != null)
64+
result = prefix + result;
65+
if (suffix != null)
66+
result = result + suffix;
67+
return result;
68+
}
69+
}
70+
71+
object IEnumerator.Current {
72+
get { return Current; }
73+
}
74+
75+
#endregion
76+
77+
#region Protected Methods
78+
protected virtual bool Exclude(string current) {
79+
return false;
80+
}
81+
#endregion
82+
83+
#region Public Methods
84+
public bool MoveNext() {
85+
while (en.MoveNext()) {
86+
current = (string)en.Current;
87+
if (current.Length == 0)
88+
continue;
89+
if (!current.StartsWith(partialMatch))
90+
return false;
91+
if (Exclude(current))
92+
continue;
93+
return true;
94+
}
95+
return false;
96+
}
97+
98+
public void Reset() {
99+
current = null;
100+
en.Reset();
101+
}
102+
103+
public void Dispose() {
104+
}
105+
106+
#endregion
107+
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Deveel.Collections {
5+
public sealed class SubsetDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
6+
private SortedDictionary<TKey, TValue> subset;
7+
8+
private static TKey NullKey = default(TKey);
9+
10+
public SubsetDictionary(SortedDictionary<TKey, TValue> dictionary, TKey startKey, TKey endKey) {
11+
subset = new SortedDictionary<TKey, TValue>(dictionary.Comparer);
12+
foreach(KeyValuePair<TKey, TValue> pair in dictionary) {
13+
int c1 = 0;
14+
if (!ReferenceEquals(startKey, NullKey))
15+
c1 = dictionary.Comparer.Compare(pair.Key, startKey);
16+
int c2 = 0;
17+
if (!ReferenceEquals(endKey, NullKey))
18+
c2 = dictionary.Comparer.Compare(pair.Key, endKey);
19+
if (c1 >= 0 && c2 <= 0)
20+
subset.Add(pair.Key, pair.Value);
21+
}
22+
}
23+
24+
public TValue this[TKey key] {
25+
get { return subset[key]; }
26+
}
27+
28+
TValue IDictionary<TKey, TValue>.this[TKey key] {
29+
get { return this[key]; }
30+
set { throw new NotSupportedException(); }
31+
}
32+
33+
public ICollection<TKey> Keys {
34+
get { return subset.Keys; }
35+
}
36+
37+
public ICollection<TValue> Values {
38+
get { return subset.Values; }
39+
}
40+
41+
public int Count {
42+
get { return subset.Count; }
43+
}
44+
45+
public bool IsReadOnly {
46+
get { return true;}
47+
}
48+
49+
public bool ContainsKey(TKey key) {
50+
return subset.ContainsKey(key);
51+
}
52+
53+
void IDictionary<TKey, TValue>.Add(TKey key, TValue value) {
54+
throw new NotSupportedException();
55+
}
56+
57+
bool IDictionary<TKey, TValue>.Remove(TKey key) {
58+
throw new NotSupportedException();
59+
}
60+
61+
public bool TryGetValue(TKey key, out TValue value)
62+
{
63+
return subset.TryGetValue(key, out value);
64+
}
65+
66+
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) {
67+
throw new NotSupportedException();
68+
}
69+
70+
void ICollection<KeyValuePair<TKey, TValue>>.Clear() {
71+
throw new NotSupportedException();
72+
}
73+
74+
public bool Contains(KeyValuePair<TKey, TValue> item) {
75+
return ((ICollection<KeyValuePair<TKey, TValue>>) subset).Contains(item);
76+
}
77+
78+
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
79+
subset.CopyTo(array, arrayIndex);
80+
}
81+
82+
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) {
83+
throw new NotSupportedException();
84+
}
85+
86+
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
87+
{
88+
return subset.GetEnumerator();
89+
}
90+
91+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
92+
return GetEnumerator();
93+
}
94+
95+
public static SubsetDictionary<TKey, TValue> Tail(SortedDictionary<TKey, TValue> dictionary, TKey startKey) {
96+
return new SubsetDictionary<TKey, TValue>(dictionary, startKey, NullKey);
97+
}
98+
99+
public static SubsetDictionary<TKey, TValue> Head(SortedDictionary<TKey, TValue> dictionary, TKey endKey) {
100+
return new SubsetDictionary<TKey, TValue>(dictionary, NullKey, endKey);
101+
}
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace Deveel.Collections {
6+
public sealed class SubsetCollection<T> : ICollection<T> {
7+
private readonly SortedList<T, T> subset;
8+
9+
10+
public int Count {
11+
get { return subset.Count; }
12+
}
13+
14+
public bool IsReadOnly {
15+
get { return true; }
16+
}
17+
18+
void ICollection<T>.Add(T item) {
19+
throw new NotSupportedException();
20+
}
21+
22+
void ICollection<T>.Clear() {
23+
throw new NotSupportedException();
24+
}
25+
26+
public bool Contains(T item) {
27+
return subset.ContainsKey(item);
28+
}
29+
30+
public void CopyTo(T[] array, int arrayIndex) {
31+
subset.Keys.CopyTo(array, arrayIndex);
32+
}
33+
34+
bool ICollection<T>.Remove(T item) {
35+
throw new NotSupportedException();
36+
}
37+
38+
public IEnumerator<T> GetEnumerator() {
39+
return subset.Keys.GetEnumerator();
40+
}
41+
42+
IEnumerator IEnumerable.GetEnumerator() {
43+
return GetEnumerator();
44+
}
45+
public static readonly T NullKey = default(T);
46+
47+
public SubsetCollection(SortedList<T, T> list, T startKey, T endKey) {
48+
subset = new SortedList<T, T>();
49+
foreach(KeyValuePair<T, T> pair in list) {
50+
int c1 = 0;
51+
if (!ReferenceEquals(startKey, NullKey))
52+
c1 = list.Comparer.Compare(pair.Key, startKey);
53+
int c2 = 0;
54+
if (!ReferenceEquals(endKey, NullKey))
55+
c2 = list.Comparer.Compare(pair.Key, endKey);
56+
if (c1 >= 0 && c2 <= 0)
57+
subset.Add(pair.Key, pair.Key);
58+
}
59+
60+
}
61+
62+
public SubsetCollection(ICollection<T> list, IComparer<T> comparer, T startKey, T endKey) {
63+
subset = new SortedList<T, T>();
64+
foreach(T value in list) {
65+
int c1 = 0;
66+
if (!ReferenceEquals(startKey, NullKey))
67+
c1 = comparer.Compare(value, startKey);
68+
int c2 = 0;
69+
if (!ReferenceEquals(endKey, NullKey))
70+
c2 = comparer.Compare(value, endKey);
71+
if (c1 >= 0 && c2 <= 0)
72+
subset.Add(value, value);
73+
}
74+
75+
}
76+
77+
public static SubsetCollection<T> Tail(SortedList<T, T> list, T startKey) {
78+
return new SubsetCollection<T>(list, startKey, NullKey);
79+
}
80+
81+
public static SubsetCollection<T> Tail(ICollection<T> c, IComparer<T> comparer, T startKey) {
82+
return new SubsetCollection<T>(c, comparer, startKey, NullKey);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)