Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Move to old-code
Browse files Browse the repository at this point in the history
svn path=/trunk/old-code/; revision=156205
  • Loading branch information
migueldeicaza committed Apr 27, 2010
1 parent fd3a432 commit 8352f77
Show file tree
Hide file tree
Showing 12 changed files with 986 additions and 0 deletions.
74 changes: 74 additions & 0 deletions wahid/Cell.cs
@@ -0,0 +1,74 @@
//
// Cell.cs
//
// Authors:
// Miguel de Icaza (miguel@novell.com)
//
// Copyright 2008 Novell, Inc (http://www.novell.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;

namespace Wahid {

public class Cell {
public static Value DefaultValue = new StringValue ("");
public Sheet Sheet { get; private set; }

public int Col { get; set; }
public int Row { get; set; }

Value val;

/// <summary>
/// Internal constructor, must only be called by Sheet.CreateCell
/// </summary>
public Cell (Sheet sheet, int col, int row)
{
Sheet = sheet;
Col = col;
Row = row;
val = DefaultValue;
}

public Value Value {
get {
return val;
}

set {
val = value;
}
}

Formula formula;

public Formula Formula {
get {
return formula;
}

set {
formula = value;
}
}
}
}
45 changes: 45 additions & 0 deletions wahid/DirAccess.cs
@@ -0,0 +1,45 @@
//
// DirAccess.cs: primitive access to zip files, it must be unpacked.
//
// Authors:
// Miguel de Icaza (miguel@novell.com)
//
// Copyright 2008 Novell, Inc (http://www.novell.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using System;

namespace Wahid {
public class DirAccess : ZipAccess {
string loc;

public DirAccess (string loc)
{
this.loc = loc;
}

public override Stream Get (string resource)
{
return File.OpenRead (Path.Combine (loc, resource));
}
}
}
180 changes: 180 additions & 0 deletions wahid/Formula.cs
@@ -0,0 +1,180 @@
//
// Formula.cs
//
// Authors:
// Miguel de Icaza (miguel@novell.com)
//
// Copyright 2008 Novell, Inc (http://www.novell.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Text;

namespace Wahid {

public class Formula {

class Tokenizer {
StringBuilder sb = new StringBuilder ();
int len;
int pos;
string s;
object putback;

public Tokenizer (string s)
{
this.s = s.Trim ();
len = s.Length;
}

double GetFraction (StringBuilder sb)
{
sb.Append (s[pos++]);
if (pos < len && Char.IsDigit (s [pos])){
while (pos < len && Char.IsDigit (s [pos]))
sb.Append (s [pos++]);
}
if (pos < len && s [pos] == 'e' || s [pos] == 'E'){
sb.Append (s [pos++]);
if (pos < len && s [pos] == '+' || s [pos] == '-')
sb.Append (s [pos++]);
if (pos < len && Char.IsDigit (s [pos]))
while (pos < len && Char.IsDigit (s [pos]))
sb.Append (s [pos++]);
}
return double.Parse (sb.ToString ());
}

double GetNumber ()
{
sb.Length = 0;

while (pos < len && Char.IsDigit (s [pos]))
sb.Append (s [pos++]);
if (pos < len && s [pos] == '.')
return GetFraction (sb);

return double.Parse (sb.ToString ());
}

ErrorValue TryError (string error, ErrorValue ret)
{
if (error == null)
throw new Exception ("Invalid error");

string sub = s.Substring (pos);

if (s.StartsWith (error)){
pos += error.Length;
return ret;
}
return null;
}

object GetToken ()
{
if (putback != null){
object p = putback;
putback = null;
return p;
}

while (pos < len){
char c = s [pos];

if (c >= '0' && c <= '9')
return GetNumber ();

if (c == '.'){
sb.Length = 0;
return GetFraction (sb);
}

if (c == '#'){
return TryError ("#DIV/0!", ErrorValue.DivisionByZero) ??
TryError ("#N/A!", ErrorValue.NA) ??
TryError ("#NAME?", ErrorValue.Name) ??
TryError ("#NULL?", ErrorValue.Null) ??
TryError ("#NUM!", ErrorValue.Num) ??
TryError ("#REF!", ErrorValue.Ref) ??
TryError (null, null);
}
if (c == '"'){
int start = ++pos;
while (pos < len && s [pos] != '"')
pos++;
if (pos < len)
return new StringValue (s.Substring (start, pos-start));
throw new Exception ("Unfinished quote");
}

if (c == ':' || c == ',' || c == ' ' || c == '^' || c == '*' || c == '/' || c == '+' ||
c == '-' || c == '&' || c == '=' || c == '%' || c == '[' || c == ']' || c == '!'){
pos++;
return c;
}

if (c == '>'){
if (pos + 1 < len && s [pos+1] == '='){
pos += 2;
return ">=";
}
pos++;
return '>';
}

if (c == '<'){
if (pos + 1 < len && s [pos+1] == '='){
pos += 2;
return "<=";
}

if (pos + 1 < len && s [pos+1] == '>'){
pos += 2;
return "<>";
}
pos++;
return '<';
}

if (c == '[' || c == ']'){
return c;
}


}
return null;
}

void PutBack (object a)
{
putback = a;
}
}


public Formula (string s)
{
// Parse the beast.
}
}
}
13 changes: 13 additions & 0 deletions wahid/Locale.cs
@@ -0,0 +1,13 @@
namespace Wahid {

static class Helper {

/// <summary>
/// Allows C-like _("string") localization
/// </summary>
public static string _ (this object s)
{
return s.ToString ();
}
}
}
9 changes: 9 additions & 0 deletions wahid/Makefile
@@ -0,0 +1,9 @@
SOURCES = Cell.cs Formula.cs Locale.cs Sheet.cs Workbook.cs ZipAccess.cs Value.cs xlsx.cs

DESKTOP_SOURCES = DirAccess.cs

wahid.exe: main.cs $(SOURCES) $(DESKTOP_SOURCES) Makefile
gmcs -debug -out:wahid.exe main.cs $(SOURCES) $(DESKTOP_SOURCES) -r:System.Xml.Linq -r:System.Core

run: wahid.exe
mono --debug wahid.exe
44 changes: 44 additions & 0 deletions wahid/README
@@ -0,0 +1,44 @@
Wahid - A Spreadsheet engine
----------------------------

This is spreadsheet engine, initially without a GUI.

Ideally a number of user interfaces can be built on top of the
spreadsheet engine:

* Silverlight (like Google's spreadsheets)

* gui.cs (the most powerful and awesome RIA in the world)

* command-line, to compute, and convert data.

* Gnome (worth doing?)

OOXML
-----

Am drawing inspiration form the OOXML specification on how to
structure the internals of this engine, but the idea is to
have multiple importers and expoters.

Currently the code does not even unzip archives, it expects a
directory called "test" to contain an unzipped OOXML file (I
used the gnumeric test files for this).

The Zip support is split from the loader as in Silverlight we
would want to use the Downloader class to unzip the files for
us, while on the desktop we can use SharpZipLib.

Models and Views
----------------

The engine will communicate with the views through events that
the views connect to.

In addition to the usual support for views for multiple
spreadsheets, this will be useful to have views and
controllers that can be connected on the backend to a server.
This would allow multiple users to edit the spreadsheet
simultaneously.


0 comments on commit 8352f77

Please sign in to comment.