[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Savannah-hackers] Re: submission of precis.org.za - savannah.gnu.org
From: |
Evan Summers |
Subject: |
[Savannah-hackers] Re: submission of precis.org.za - savannah.gnu.org |
Date: |
Wed, 21 Aug 2002 14:42:32 +0200 (SAST) |
> In order to release your project under the GPL you
> should write copyright notice and copying conditions
i have done this eg. see below :)
but still need to upload to precis.org.za
but my account on the webserver is not functional
since it crashed last week...
> Could you resubmit once it's done?
> You can resubmit your project with ease by copying
sjoe, but this would be the third time!?
--
kind regards
evan
......................................................................
precis.org.za // java-inspiration for the c programming language
"The best way to ensure there will not be an OS community is to lock
an entire country or province into a proprietary licensing scheme."
-- Bas Kotterink, opensource advocate in education
/* precis.org.za ............................................................
This is part of precis.org.za programming tool
copyright 2002 evan summers
precis.org.za 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.
precis.org.za 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., 675 Mass Ave, Cambridge, MA 02139, USA
*/
#include "precisLang.h"
/** Map .....................................................................
*
*/
Map Map_new(int capacity) {
Map this = Map_newInstance();
if (capacity == nullint) capacity = Map_Capacity;
this->capacity = capacity;
this->rowCapacity = 1;
this->length = 0;
this->index = 0;
this->ref = System_createClearMemory(this->capacity*sizeof(objectref));
this->keys = System_createClearMemory(this->capacity*sizeof(objectref));
this->rowCount = 0;
this->rowIndex = 0;
this->rowIterator = 0;
return this;
}
Map Map_newTable(int capacity, int rowCapacity) {
Map this = Map_newInstance();
if (capacity == nullint) capacity = Map_Capacity;
this->ref = System_createClearMemory(capacity*rowCapacity*sizeof(objectref));
this->keys = System_createClearMemory(capacity*sizeof(objectref));
this->capacity = capacity;
this->rowIndex = 0;
this->rowIterator = 0;
this->rowCapacity = rowCapacity;
this->length = 0;
return this;
}
Map Map_newLines(Array array) {
int it;
Map this;
if (array == null) return null;
if (Array_length(array) <= 0) return null;
this = Map_new(Array_length(array));
for (it = 0; it < Array_length(array); it++) {
String line = Array_get(array, it);
String key = String_parseWord(line, 0);
String value = String_parseString(line, nullint);
Map_put(this, key, value);
}
return this;
}
Array Map_toLines(Map this) {
int it;
Array array;
if (this == null) return null;
if (this->length <= 0) return null;
array = Array_new(this->length);
for (it = 0; it < this->length; it++) {
String key = Map_getKeyAt(this, it);
String value = Map_getAt(this, it);
String line = String_newBuffer(nullint);
if (value == null) continue;
String_add(line, key);
String_addSpace(line);
String_add(line, value);
Array_add(array, line);
}
return array;
}
Object Map_putRowElement(Map this, int index, int rowIndex, Object value) {
int elementIndex;
if (this == null) return null;
if (index < 0) return null;
if (rowIndex < 0) return null;
if (index >= this->capacity) return null;
if (rowIndex >= this->rowCapacity) return null;
elementIndex = rowIndex*this->capacity+index;
if (this->ref[elementIndex] != null) Object_deref(this->ref[elementIndex]);
this->ref[elementIndex] = Object_ref(value);
if (index >= this->length) this->length = index+1;
if (rowIndex >= this->rowCount) this->rowCount = rowIndex+1;
return value;
}
Object Map_putKey(Map this, int index, Object key) {
if (this == null) return null;
if (index < 0) return null;
if (index >= this->capacity) return null;
if (this->keys[index] != null) Object_deref(key);
this->keys[index] = Object_ref(key);
if (index >= this->length) this->length = index+1;
return key;
}
Object Map_getKeyAt(Map this, int index) {
if (this == null) return null;
if (index < 0) return null;
if (index >= this->length) return null;
return this->keys[index];
}
Object Map_putElement(Map this, int index, Object value) {
return Map_putRowElement(this, index, this->rowIndex, value);
}
Object Map_getRowElement(Map this, int index, int rowIndex) {
if (this == null) return null;
if (index < 0 || index >= this->length) return null;
if (rowIndex < 0 || rowIndex >= this->rowCount) return null;
return this->ref[rowIndex*this->capacity+index];
}
int Map_getRowCount(Map this) {
if (this == null) return nullint;
return this->rowCount;
}
Object Map_getElement(Map this, int index) {
if (this == null) return null;
return Map_getRowElement(this, index, this->rowIndex);
}
Object Map_put(Map this, Object key, Object value) {
if (this == null) return null;
if (key == null) return null;
if (!Map_instanceof(this)) {
System_panicprintf("Map_put inconsistent\n");
return null;
}
Map_ensureCapacity(this, this->length+1);
if (Map_containsKey(this, key) == false) {
this->index = this->length;
Map_putElement(this, this->index, value);
Map_putKey(this, this->index, key);
} else {
Map_putElement(this, this->index, value);
}
return value;
}
Object Map_reput(Map this, Object key, Object value) {
if (this == null) return null;
if (Map_containsKey(this, key)) {
Object object = Map_getElement(this, this->index);
Map_putElement(this, this->index, value);
Object_deref(object);
} else {
Map_put(this, key, value);
}
return value;
}
Object Map_putInt(Map this, Object key, int value) {
Object integer = Integer_new(value);
if (this == null) return null;
Map_put(this, key, integer);
return integer;
}
Map Map_translate(Map this, Map map) {
int it, itInner;
for (it = 0; it < this->length; it++) {
for (itInner = 0; itInner < map->length; itInner++) {
if (String_equals(this->keys[it], map->keys[itInner])) {
Map_putKey(this, it, Map_getElement(map, itInner));
}
}
}
return this;
}
Integer Map_parseInteger(Map this, Object key, int coalesceValue) {
Object object = Map_get(this, key);
Integer value = Integer_new(coalesceValue);
int index;
if (this == null) return null;
index = this->index;
if (object == null) {
Map_put(this, key, value);
return value;
}
if (!String_instanceof(object) || !String_isNumeric((String)object)) return
null;
value = Integer_newParse((String)object);
if (object == null) return null;
Map_putElement(this, index, Object_reref(object, value));
return value;
}
Decimal Map_parseDecimal(Map this, Object key, int scale, Decimal
coalesceValue) {
Object object = Map_get(this, key);
Decimal value = coalesceValue;
int index;
if (this == null) return null;
index = this->index;
if (object == null) {
Map_put(this, key, value);
return value;
}
if (!String_instanceof(object)) return null;
value = Decimal_newParse((String)object, scale);
if (value == null) return null;
Map_putElement(this, index, Object_reref(object, value));
return value;
}
Date Map_parseDate(Map this, Object key, Date coalesceValue) {
Object object = Map_get(this, key);
Date value = coalesceValue;
int index;
if (this == null) return null;
index = this->index;
if (object == null) {
Map_put(this, key, value);
return value;
}
if (!String_instanceof(object)) return null;
value = Date_newParse((String)object);
if (value == null) return null;
Map_putElement(this, index, Object_reref(object, value));
return value;
}
Object Map_get(Map this, Object key) {
int it;
if (this == null) return null;
if (!Map_instanceof(this)) {
System_panicprintf("Map_get inconsistent\n");
return null;
}
for (it = 0; it < this->length; it++) {
if (Object_equals(this->keys[it], key)) {
this->index = it;
return Map_getElement(this, it);
}
}
return null;
}
Object Map_getAt(Map this, int index) {
if (this == null) return null;
if (index < 0 || index >= this->length) return null;
return Map_getElement(this, index);
}
Object Map_getIntern(Map this, stringref key) {
int it;
if (this == null) return null;
for (it = 0; it < this->length; it++) {
String string = (String)this->keys[it];
if (String_instanceof(string) && stringref_equals(string->ref, key)) {
this->index = it;
return Map_getElement(this, it);
}
}
return null;
}
Array Map_getKeys(Map this) {
Array array;
int it;
if (this == null) return null;
array = Array_new(this->length);
for (it = 0; it < this->length; it++) Array_add(array, this->keys[it]);
return array;
}
Array Map_getElements(Map this) {
Array array;
int it;
if (this == null) return null;
array = Array_new(this->length);
for (it = 0; it < this->length; it++) Array_add(array, Map_getElement(this,
it));
return array;
}
Object Map_getKey(Map this, Object value) {
int it;
if (this == null) return null;
for (it = 0; it < this->length; it++) {
if (Object_equals(Map_getElement(this, it), value)) {
this->index = it;
return this->keys[it];
}
}
return null;
}
stringref Map_getStringIntern(Map this, Object key) {
Object object = Map_get(this, key);
if (object == null) return null;
if (!String_instanceof(object)) return null;
return String_intern((String)object);
}
String Map_getString(Map this, Object key) {
Object object = Map_get(this, key);
if (object == null) return null;
if (!String_instanceof(object)) return null;
return (String)object;
}
Date Map_getDate(Map this, Object key) {
Object object = Map_get(this, key);
if (object == null) return null;
if (String_instanceof(object)) return Date_newParse(object);
if (!Date_instanceof(object)) return null;
return (Date)object;
}
Integer Map_getInteger(Map this, Object key) {
Object object = Map_get(this, key);
if (object == null) return null;
if (String_instanceof(object)) return Integer_newParse(object);
if (!Integer_instanceof(object)) return null;
return (Integer)object;
}
int Map_getInt(Map this, Object key) {
Object object = Map_getInteger(this, key);
if (object == null) return nullint;
if (String_instanceof(object)) object = Integer_newParse(object);
if (!Integer_instanceof(object)) return nullint;
return Integer_intValue(object);
}
int Map_getIntIntern(Map this, stringref key) {
Object object = Map_getIntern(this, key);
if (object == null) return nullint;
if (String_instanceof(object)) object = Integer_newParse(object);
if (!Integer_instanceof(object)) return nullint;
return Integer_intValue(object);
}
Long Map_getLong(Map this, Object key) {
Object object = Map_get(this, key);
if (object == null) return null;
if (String_instanceof(object)) return Long_newParse(object);
if (!Long_instanceof(object)) return null;
return (Long)object;
}
Decimal Map_getDecimalImplied(Map this, Object key, int scale) {
Object object = Map_get(this, key);
if (object == null) return null;
if (String_instanceof(object)) return
Decimal_new(int_parseIntern(String_intern(object)), scale);
if (!Decimal_instanceof(object)) return null;
return (Decimal)object;
}
Decimal Map_getDecimal(Map this, Object key, int scale) {
Object object = Map_get(this, key);
if (object == null) return null;
if (String_instanceof(object)) return Decimal_newParse(object, scale);
if (!Decimal_instanceof(object)) return null;
return (Decimal)object;
}
boolean Map_containsKey(Map this, Object key) {
int it;
if (this == null) return false;
for (it = 0; it < this->length; it++) {
if (Object_equals(this->keys[it], key)) {
this->index = it;
return true;
}
}
return false;
}
boolean Map_contains(Map this, Object value) {
int it;
if (this == null) return false;
for (it = 0; it < this->length; it++) {
if (Object_equals(Map_getElement(this, it), value)) {
this->index = it;
return true;
}
}
return false;
}
String Map_toAttributeString(Map this) {
int it;
String string;
if (this == null) return null;
string = String_newBuffer(nullint);
for (it = 0; it < this->length; it++) {
Object key = Map_getKeyAt(this, it);
Object value = Map_getAt(this, it);
if (it > 0) String_addChar(string, ' ');
String_add(string, key);
String_addChar(string, '=');
String_add(string, value);
}
return string;
}
String Map_toString(Map this) {
if (this == null) return null;
return String_newprintf("Map length %d rowCount %d", this->length,
this->rowCount);
}
boolean Map_finalize(Map this) {
if (this == null) return false;
System_destroyMemory(this->keys);
System_destroyMemory(this->ref);
return true;
}
int Map_length(Map this) {
if (this == null) return nullint;
if (!Map_instanceof(this)) {
System_panicprintf("Map_length inconsistent\n");
return nullint;
}
return this->length;
}
int Map_capacity(Map this) {
if (this == null) return nullint;
if (!Map_instanceof(this)) {
System_panicprintf("Map_capacity inconsistent\n");
return nullint;
}
return this->capacity;
}
Map Map_resize(Map this, int capacity, int rowCapacity) {
int it, rowIt;
objectarray ref;
objectarray keys;
if (this == null) return null;
if (capacity == nullint) capacity = this->length;
if (rowCapacity == nullint) rowCapacity = this->rowCount;
keys = System_createClearMemory(capacity*sizeof(objectref)); if (keys ==
null) return null;
ref = System_createClearMemory(capacity*rowCapacity*sizeof(objectref));
if (ref == null) return null;
this->capacity = capacity;
this->length = int_min(this->length, this->capacity);
this->rowCapacity = rowCapacity;
this->rowCount = int_min(this->rowCount, this->rowCapacity);
System_copyMemory(keys, this->keys, this->length*sizeof(objectref));
System_copyMemory(ref, this->ref,
this->rowCount*this->capacity*sizeof(objectref));
this->keys = keys;
this->ref = ref;
System_destroyMemory(this->ref);
System_destroyMemory(this->keys);
return this;
}
Map Map_ensureCapacity(Map this, int capacity) {
if (this == null) return null;
if (this->capacity >= capacity) return this;
capacity = int_max(this->capacity*3/2, capacity);
return Map_resize(this, capacity, this->rowCapacity);
}
Map Map_trimCapacity(Map this) {
return Map_resize(this, nullint, nullint);
}
Map Map_ensureRowCapacity(Map this, int rowCapacity) {
int it, rowIt;
objectarray ref;
if (this == null) return null;
if (this->rowCapacity >= rowCapacity) return this;
rowCapacity = int_max(this->rowCapacity*3/2, rowCapacity);
return Map_resize(this, this->capacity, rowCapacity);
}
Map Map_ensureNew(Map this, Object key) {
int it;
if (this == null) return null;
if (key == null) return null;
if (!Map_containsKey(this, key)) return this;
if (Map_getElement(this, this->index) != null) {
this = Map_ensureRowCapacity(this, this->rowCount+1);
if (this == null) return null;
this->rowIndex = this->rowCount;
this->rowCount++;
}
return this;
}
boolean Map_hasNext(Map this) {
if (this == null) return false;
if (this->rowIterator >= this->rowCount) {
this->rowIterator = 0;
return false;
}
this->rowIndex = this->rowIterator;
this->rowIterator++;
return true;
}
Map Map_next(Map this) {
if (this == null) return null;
if (Map_hasNext(this) == false) return null;
return this;
}
Map Map_setRowIndex(Map this, int rowIndex) {
if (this == null) return false;
this->rowIndex = rowIndex;
return this;
}
/** IntMap ............................................................
*
*/
IntMap IntMap_new(int capacity) {
IntMap this = IntMap_newInstance();
if (capacity == nullint) capacity = IntMap_Capacity;
this->capacity = capacity;
this->length = 0;
this->lengthSorted = 0;
this->index = 0;
this->ref = System_createClearMemory(this->capacity*sizeof(int));
this->key = System_createClearMemory(this->capacity*sizeof(int));
return this;
}
IntMap IntMap_putKey(IntMap this, int index, int key) {
if (this == null) return null;
if (index < 0) return null;
if (index >= this->capacity) return null;
this->key[index] = key;
if (index >= this->length) this->length = index+1;
return this;
}
int IntMap_getKeyAt(IntMap this, int index) {
if (this == null) return nullint;
if (index < 0) return nullint;
if (index >= this->length) return nullint;
return this->key[index];
}
IntMap IntMap_putAt(IntMap this, int index, int value) {
if (this == null) return null;
if (index < 0) return null;
if (index >= this->capacity) return null;
this->ref[index] = value;
if (index >= this->length) this->length = index+1;
return this;
}
int IntMap_getAt(IntMap this, int index) {
if (this == null) return nullint;
if (index < 0 || index >= this->length) return nullint;
return this->ref[index];
}
IntMap IntMap_add(IntMap this, int key, int value) {
if (this == null) return null;
if (key == nullint) return null;
if (!IntMap_instanceof(this)) {
System_panicprintf("IntMap_put inconsistent\n");
return null;
}
IntMap_ensureCapacity(this, this->length+1);
if (IntMap_containsKey(this, key) == false) {
this->index = this->length;
IntMap_putAt(this, this->index, value);
IntMap_putKey(this, this->index, key);
} else {
IntMap_putAt(this, this->index, value);
}
return this;
}
int IntMap_getInt(IntMap this, int key) {
int it;
if (this == null) return nullint;
if (!IntMap_instanceof(this)) {
System_panicprintf("IntMap_get inconsistent\n");
return nullint;
}
for (it = 0; it < this->length; it++) {
if (this->key[it] == key) {
this->index = it;
return IntMap_getAt(this, it);
}
}
return nullint;
}
IntArray IntMap_getKeys(IntMap this) {
IntArray array;
int it;
if (this == null) return null;
array = IntArray_new(this->length);
for (it = 0; it < this->length; it++) IntArray_addInt(array, this->key[it]);
return array;
}
IntArray IntMap_getElements(IntMap this) {
IntArray array;
int it;
if (this == null) return null;
array = IntArray_new(this->length);
for (it = 0; it < this->length; it++) IntArray_addInt(array,
IntMap_getAt(this, it));
return array;
}
int IntMap_getKey(IntMap this, int value) {
int it;
if (this == null) return nullint;
for (it = 0; it < this->length; it++) {
if (IntMap_getAt(this, it) == value) {
this->index = it;
return this->key[it];
}
}
return nullint;
}
Integer IntMap_getInteger(IntMap this, int key) {
int value = IntMap_getInt(this, key);
if (value == nullint) return null;
return Integer_new(value);
}
boolean IntMap_containsKey(IntMap this, int key) {
int it;
if (this == null) return false;
for (it = 0; it < this->length; it++) {
if (this->key[it] == key) {
this->index = it;
return true;
}
}
return false;
}
boolean IntMap_contains(IntMap this, int value) {
int it;
if (this == null) return false;
for (it = 0; it < this->length; it++) {
if (IntMap_getAt(this, it) == value) {
this->index = it;
return true;
}
}
return false;
}
String IntMap_toString(IntMap this) {
if (this == null) return null;
return String_newprintf("IntMap length %d", this->length);
}
boolean IntMap_finalize(IntMap this) {
if (this == null) return false;
System_destroyMemory(this->key);
System_destroyMemory(this->ref);
return true;
}
int IntMap_length(IntMap this) {
if (this == null) return nullint;
if (!IntMap_instanceof(this)) {
System_panicprintf("IntMap_length inconsistent\n");
return nullint;
}
return this->length;
}
int IntMap_capacity(IntMap this) {
if (this == null) return nullint;
if (!IntMap_instanceof(this)) {
System_panicprintf("IntMap_capacity inconsistent\n");
return nullint;
}
return this->capacity;
}
IntMap IntMap_resize(IntMap this, int capacity) {
int it, rowIt;
intarray ref;
intarray key;
if (this == null) return null;
if (capacity == nullint) capacity = this->length;
key = System_createClearMemory(capacity*sizeof(int)); if (key == null) return
null;
ref = System_createClearMemory(capacity*sizeof(int));
if (ref == null) return null;
this->capacity = capacity;
this->length = int_min(this->length, this->capacity);
System_copyMemory(key, this->key, this->length*sizeof(int));
System_copyMemory(ref, this->ref, this->length*sizeof(int));
this->key = key;
this->ref = ref;
System_destroyMemory(this->ref);
System_destroyMemory(this->key);
return this;
}
IntMap IntMap_ensureCapacity(IntMap this, int capacity) {
if (this == null) return null;
if (this->capacity >= capacity) return this;
capacity = int_max(this->capacity*3/2, capacity);
return IntMap_resize(this, capacity);
}
IntMap IntMap_trimCapacity(IntMap this) {
return IntMap_resize(this, nullint);
}
/** Checksum ................................................................
*
*/
Checksum Checksum_new() {
Checksum this = Checksum_newInstance();
md5_init(&this->md5);
return this;
}
Checksum Checksum_addIntern(Checksum this, stringref string) {
if (this == null) return null;
if (string == null) return this;
md5_process(&this->md5, string, strlen(string));
return this;
}
Checksum Checksum_add(Checksum this, Object object) {
if (this == null) return null;
if (object == null) return this;
return Checksum_addIntern(this, Object_toStringIntern(object));
}
Checksum Checksum_addInt(Checksum this, int value) {
return Checksum_addIntern(this, int_toStringIntern(value));
}
stringref Checksum_getPrivate(Checksum this) {
int it;
if (this == null) return null;
if (this->string[0] != 0) return this->string;
md5_finish(&this->md5, this->array);
for (it = 0; it < Checksum_Length; it++) {
sprintf(this->string+it*2, "%02x", this->array[it]);
}
this->string[it*2] = 0;
this->value = 0;
for (it = 0; it < Checksum_Length-1; it++) {
this->value |= this->array[it]<<(it*4);
}
return this->string;
}
longintern Checksum_toLong(Checksum this) {
Checksum_getPrivate(this);
return this->value;
}
stringref Checksum_toStringIntern(Checksum this) {
return Checksum_getPrivate(this);
}
String Checksum_toString(Checksum this) {
return String_newIntern(Checksum_toStringIntern(this));
}
boolean Checksum_equals(Checksum this, Checksum another) {
Checksum_getPrivate(this);
Checksum_getPrivate(another);
return stringref_equals(Checksum_toStringIntern(this),
Checksum_toStringIntern(another));
}
boolean Checksum_finalize(Checksum this) {
if (this == null) return false;
return true;
}