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

Commit

Permalink
Initial commit of project sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed May 15, 2012
0 parents commit 3b0d693
Show file tree
Hide file tree
Showing 88 changed files with 7,265 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/src/dshell/obj
/src/dshell/bin
/src/_ReSharper.dshell.vs2010
/src/packages
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deveel Shell Application (dshell)
=================================

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.
3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

*.user
*.suo
20 changes: 20 additions & 0 deletions src/dshell.vs2010.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dshell.vs2010", "dshell\dshell.vs2010.csproj", "{5E849796-A39E-4AF8-A516-D2837C3CCE6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E849796-A39E-4AF8-A516-D2837C3CCE6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/dshell/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.user
108 changes: 108 additions & 0 deletions src/dshell/Deveel.Collections/SortedMatchEnumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace Deveel.Collections {
/// <summary>
/// An <see cref="IEnumerator">enumerator</see> returning end-truncated
/// matching values from a sorted list.
/// </summary>
/// <remarks>
/// This IEnumerator is initialized with a sorted ISet, sorted
/// IDictionary or another IEnumerator that must be placed at the
/// beginning of the matching area of a sorted set.
/// <para>
/// This IEnumerator is commonly used for TAB-completion.
/// </para>
/// </remarks>
public class SortedMatchEnumerator : IEnumerator<string> {
#region ctor
public SortedMatchEnumerator(string partialMatch, IEnumerator<String> en) {
this.partialMatch = partialMatch;
this.en = en;
}

public SortedMatchEnumerator(string partialMatch, ICollection<string> c, IComparer<string> comparer)
: this(partialMatch, SubsetCollection<string>.Tail(c, comparer, partialMatch).GetEnumerator()) {
}

public SortedMatchEnumerator(string partialMatch, SortedList<string, string> list)
: this(partialMatch, SubsetCollection<string>.Tail(list, partialMatch).GetEnumerator()) {
}

public SortedMatchEnumerator(string partialMatch, SortedDictionary<string, string> dictionary)
: this(partialMatch, SubsetDictionary<string, string>.Tail(dictionary, partialMatch).Keys.GetEnumerator()) {
}
#endregion

#region Fields
private readonly IEnumerator<string> en;
private readonly string partialMatch;

private string prefix;
private string suffix;

// the current match
private string current;
#endregion

#region Properties
public string Prefix {
get { return prefix; }
set { prefix = value; }
}

public string Suffix {
get { return suffix; }
set { suffix = value; }
}

public string Current {
get {
string result = current;
if (prefix != null)
result = prefix + result;
if (suffix != null)
result = result + suffix;
return result;
}
}

object IEnumerator.Current {
get { return Current; }
}

#endregion

#region Protected Methods
protected virtual bool Exclude(string current) {
return false;
}
#endregion

#region Public Methods
public bool MoveNext() {
while (en.MoveNext()) {
current = (string)en.Current;
if (current.Length == 0)
continue;
if (!current.StartsWith(partialMatch))
return false;
if (Exclude(current))
continue;
return true;
}
return false;
}

public void Reset() {
current = null;
en.Reset();
}

public void Dispose() {
}

#endregion
}
}
103 changes: 103 additions & 0 deletions src/dshell/Deveel.Collections/SubsetDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;

namespace Deveel.Collections {
public sealed class SubsetDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
private SortedDictionary<TKey, TValue> subset;

private static TKey NullKey = default(TKey);

public SubsetDictionary(SortedDictionary<TKey, TValue> dictionary, TKey startKey, TKey endKey) {
subset = new SortedDictionary<TKey, TValue>(dictionary.Comparer);
foreach(KeyValuePair<TKey, TValue> pair in dictionary) {
int c1 = 0;
if (!ReferenceEquals(startKey, NullKey))
c1 = dictionary.Comparer.Compare(pair.Key, startKey);
int c2 = 0;
if (!ReferenceEquals(endKey, NullKey))
c2 = dictionary.Comparer.Compare(pair.Key, endKey);
if (c1 >= 0 && c2 <= 0)
subset.Add(pair.Key, pair.Value);
}
}

public TValue this[TKey key] {
get { return subset[key]; }
}

TValue IDictionary<TKey, TValue>.this[TKey key] {
get { return this[key]; }
set { throw new NotSupportedException(); }
}

public ICollection<TKey> Keys {
get { return subset.Keys; }
}

public ICollection<TValue> Values {
get { return subset.Values; }
}

public int Count {
get { return subset.Count; }
}

public bool IsReadOnly {
get { return true;}
}

public bool ContainsKey(TKey key) {
return subset.ContainsKey(key);
}

void IDictionary<TKey, TValue>.Add(TKey key, TValue value) {
throw new NotSupportedException();
}

bool IDictionary<TKey, TValue>.Remove(TKey key) {
throw new NotSupportedException();
}

public bool TryGetValue(TKey key, out TValue value)
{
return subset.TryGetValue(key, out value);
}

void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) {
throw new NotSupportedException();
}

void ICollection<KeyValuePair<TKey, TValue>>.Clear() {
throw new NotSupportedException();
}

public bool Contains(KeyValuePair<TKey, TValue> item) {
return ((ICollection<KeyValuePair<TKey, TValue>>) subset).Contains(item);
}

public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
subset.CopyTo(array, arrayIndex);
}

bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) {
throw new NotSupportedException();
}

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return subset.GetEnumerator();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return GetEnumerator();
}

public static SubsetDictionary<TKey, TValue> Tail(SortedDictionary<TKey, TValue> dictionary, TKey startKey) {
return new SubsetDictionary<TKey, TValue>(dictionary, startKey, NullKey);
}

public static SubsetDictionary<TKey, TValue> Head(SortedDictionary<TKey, TValue> dictionary, TKey endKey) {
return new SubsetDictionary<TKey, TValue>(dictionary, NullKey, endKey);
}
}
}
85 changes: 85 additions & 0 deletions src/dshell/Deveel.Collections/SubsetList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace Deveel.Collections {
public sealed class SubsetCollection<T> : ICollection<T> {
private readonly SortedList<T, T> subset;


public int Count {
get { return subset.Count; }
}

public bool IsReadOnly {
get { return true; }
}

void ICollection<T>.Add(T item) {
throw new NotSupportedException();
}

void ICollection<T>.Clear() {
throw new NotSupportedException();
}

public bool Contains(T item) {
return subset.ContainsKey(item);
}

public void CopyTo(T[] array, int arrayIndex) {
subset.Keys.CopyTo(array, arrayIndex);
}

bool ICollection<T>.Remove(T item) {
throw new NotSupportedException();
}

public IEnumerator<T> GetEnumerator() {
return subset.Keys.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public static readonly T NullKey = default(T);

public SubsetCollection(SortedList<T, T> list, T startKey, T endKey) {
subset = new SortedList<T, T>();
foreach(KeyValuePair<T, T> pair in list) {
int c1 = 0;
if (!ReferenceEquals(startKey, NullKey))
c1 = list.Comparer.Compare(pair.Key, startKey);
int c2 = 0;
if (!ReferenceEquals(endKey, NullKey))
c2 = list.Comparer.Compare(pair.Key, endKey);
if (c1 >= 0 && c2 <= 0)
subset.Add(pair.Key, pair.Key);
}

}

public SubsetCollection(ICollection<T> list, IComparer<T> comparer, T startKey, T endKey) {
subset = new SortedList<T, T>();
foreach(T value in list) {
int c1 = 0;
if (!ReferenceEquals(startKey, NullKey))
c1 = comparer.Compare(value, startKey);
int c2 = 0;
if (!ReferenceEquals(endKey, NullKey))
c2 = comparer.Compare(value, endKey);
if (c1 >= 0 && c2 <= 0)
subset.Add(value, value);
}

}

public static SubsetCollection<T> Tail(SortedList<T, T> list, T startKey) {
return new SubsetCollection<T>(list, startKey, NullKey);
}

public static SubsetCollection<T> Tail(ICollection<T> c, IComparer<T> comparer, T startKey) {
return new SubsetCollection<T>(c, comparer, startKey, NullKey);
}
}
}
Loading

0 comments on commit 3b0d693

Please sign in to comment.