From be839900419c7a74c4a46efd279d0ca16b35dc1f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 15 May 2008 23:28:07 +0000 Subject: Moved stuff into trunk. --- src/data/array.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 src/data/array.c (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c new file mode 100644 index 0000000..e893a6d --- /dev/null +++ b/src/data/array.c @@ -0,0 +1,266 @@ +/*:* + *: File: ./src/data/array.c + *: A simple interpreter + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.pblabs.net) + *: All rights reserved. + *: + *: Redistribution and use in source and binary forms, with or without modi- + *: fication, are permitted provided that the following conditions are met: + *: * Redistributions of source code must retain the above copyright + *: notice, this list of conditions and the following disclaimer. + *: * Redistributions in binary form must reproduce the above copyright + *: notice, this list of conditions and the following disclaimer in the + *: documentation and/or other materials provided with the distribution. + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software + *: without specific prior written permission. + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: POSSIBILITY OF SUCH DAMAGE. + *:*/ + +#include "array.h" + +Array* +array_new() { + Array *p_array = malloc(sizeof(Array)); + + p_array->i_size = 0; + p_array->pp_ae = NULL; + + return p_array; +} + + +void +array_delete(Array *p_array) { + if (!p_array) + return; + + if (p_array->i_size) + for (int i = p_array->i_size - 1; i >= 0; --i) + arrayelement_delete(p_array->pp_ae[i]); + + if (p_array->pp_ae) + free(p_array->pp_ae); + + free(p_array); +} + +void +array_set(Array *p_array, int i_index, void *p_val) { + if (p_array->i_size > i_index) { + p_array->pp_ae[i_index]->p_val = p_val; + + } else { + array_resize(p_array, i_index + 1); + p_array->pp_ae[i_index]->p_val = p_val; + } +} + +void +array_insert(Array *p_array, int i_index, void *p_val) { + if (p_array->i_size <= i_index) { + array_set(p_array, i_index, p_val); + + } else { + array_resize(p_array, p_array->i_size + 1); + + ArrayElement *p_ae = p_array->pp_ae[p_array->i_size-1]; + int i; + for (i = p_array->i_size - 1; i > i_index; --i) + p_array->pp_ae[i] = p_array->pp_ae[i-1]; + + p_array->pp_ae[i] = p_ae; + p_ae->p_val = p_val; + } +} + +void* +array_remove(Array *p_array, int i_index) { + if (p_array->i_size <= i_index) + return NULL; + + ArrayElement *p_ae = p_array->pp_ae[i_index]; + void *p_ret = p_ae->p_val; + int i; + + for (i = i_index+1; i < p_array->i_size; ++i) + p_array->pp_ae[i-1] = p_array->pp_ae[i]; + + p_array->pp_ae[i-1] = p_ae; + + array_resize(p_array, p_array->i_size - 1); + + return p_ret; +} + +void +array_print_int(Array *p_array) { + printf("Array:"); + for (int i = 0; i < p_array->i_size; ++i) + printf(" (%d,%d)", i, (int) array_get(p_array, i)); + printf("\n"); +} + +void +array_resize(Array *p_array, int i_size) { + if (i_size == p_array->i_size) + return; + + if (i_size < p_array->i_size) + for (int i = p_array->i_size - 1; i >= i_size; --i) + arrayelement_delete(p_array->pp_ae[i]); + + if (i_size == 0) { + free(p_array->pp_ae); + p_array->pp_ae = NULL; + + } else if (p_array->pp_ae != NULL) { + p_array->pp_ae = realloc(p_array->pp_ae, + sizeof(ArrayElement) * i_size); + + } else { + p_array->pp_ae = malloc(sizeof(ArrayElement) * i_size); + } + + if (i_size > p_array->i_size) + for (int i = p_array->i_size; i < i_size; ++i) + p_array->pp_ae[i] = arrayelement_new(NULL); + + p_array->i_size = i_size; +} + +void* +array_get(Array *p_array, int i_index) { + if (p_array->i_size > i_index) + return p_array->pp_ae[i_index]->p_val; + + return NULL; +} + +_Bool +array_defined(Array *p_array, int i_index) { + if (i_index >= p_array->i_size) + return false; + + return p_array->pp_ae[i_index]->p_val != NULL; +} + +void +array_splice(Array *p_array, int i_index, Array *p_array2) { + if (i_index >= array_get_size(p_array)) + return; + + array_remove(p_array, i_index); + + int i_size1= array_get_size(p_array); + int i_size2 = array_get_size(p_array2); + int i_size = i_size1 + i_size2; + + array_resize(p_array, i_size); + + for (int i = i_size1 - 1; i >= i_index; --i) + p_array->pp_ae[i+i_size2]->p_val = p_array->pp_ae[i]->p_val; + + for (int i = 0; i < i_size2; ++i) + p_array->pp_ae[i+i_index]->p_val = p_array2->pp_ae[i]->p_val; + +} + +void +array_unshift(Array *p_array, void *p_void) { + int i_size = array_get_size(p_array); + array_set(p_array, i_size, p_void); +} + +void +array_push(Array *p_array, void *p_void) { + int i_size = array_get_size(p_array); + array_resize(p_array, ++i_size); + + for (int i = i_size - 1; i > 0; --i) + p_array->pp_ae[i]->p_val = p_array->pp_ae[i-1]->p_val; + + array_set(p_array, 0, p_void); +} + +void +array_iterate(Array *p_array, void (*func)(void *)) { + if (!p_array) + return; + + for (int i = 0; i < array_get_size(p_array); ++i) + (*func) (array_get(p_array, i)); +} + +void +array_iterate2(Array *p_array, void (*func)(void *, void *), void *p_void) { + if (!p_array) + return; + + for (int i = 0; i < array_get_size(p_array); ++i) + (*func) (array_get(p_array, i), p_void); +} + +ArrayElement* +arrayelement_new(void *p_val) { + ArrayElement *p_ae = malloc(sizeof(ArrayElement)); + + p_ae->p_val = p_val; + + return p_ae; +} + +void +arrayelement_delete(ArrayElement *p_ae) { + if (!p_ae) + return; + + free(p_ae); +} + +ArrayIterator* +arrayiterator_new(Array *p_array) { + if (!p_array) + return NULL; + + ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator)); + p_arrayiterator->p_array = p_array; + p_arrayiterator->i_cur_pos = 0; + + return p_arrayiterator; +} + +void +arrayiterator_delete(ArrayIterator *p_arrayiterator) { + if (p_arrayiterator) + free(p_arrayiterator); +} + +_Bool +arrayiterator_has_next(ArrayIterator *p_arrayiterator) { + return p_arrayiterator->i_cur_pos < + array_get_size(p_arrayiterator->p_array); +} + +void* +arrayiterator_next(ArrayIterator *p_arrayiterator) { + if (!arrayiterator_has_next(p_arrayiterator)) + return NULL; + + return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++); +} -- cgit v1.2.3 From e4689bbb20dade47b98061d48ba73436c856f3ff Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 8 Aug 2008 09:31:58 +0000 Subject: changed header. --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index e893a6d..5afaf10 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.pblabs.net) + *: + *: Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.pb-labs.com) *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From da52f90a73abd653cfe9726bcf5c96338db0b7a2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 23 Aug 2008 01:46:47 +0000 Subject: some enhancements --- src/data/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 5afaf10..33afb39 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -5,7 +5,7 @@ *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org *: - *: Copyright (c) 2005 2006 2007 2008, Paul Buetow (http://www.pb-labs.com) + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow (http://www.pb-labs.com) *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- -- cgit v1.2.3 From e9a9ad33583c49df48ae99cab9ba0fd80f150a9e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 23 Aug 2008 02:03:40 +0000 Subject: changed headers --- src/data/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 33afb39..1fbf9d5 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -5,7 +5,7 @@ *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow (http://www.pb-labs.com) + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- -- cgit v1.2.3 From 7f3055c1f4429a81de3715d5d4173353382e2de2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 Aug 2008 19:30:11 +0000 Subject: some mods --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 1fbf9d5..2ae4ece 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From 71185ab0ab0b08b4d5bb2e750ff85e11f105a453 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 16 Sep 2008 17:05:51 +0000 Subject: array progress --- src/data/array.c | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 2ae4ece..da5bee8 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -41,7 +41,7 @@ array_new() { p_array->i_size = 0; p_array->pp_ae = NULL; - return p_array; + return (p_array); } @@ -92,7 +92,7 @@ array_insert(Array *p_array, int i_index, void *p_val) { void* array_remove(Array *p_array, int i_index) { if (p_array->i_size <= i_index) - return NULL; + return (NULL); ArrayElement *p_ae = p_array->pp_ae[i_index]; void *p_ret = p_ae->p_val; @@ -105,7 +105,7 @@ array_remove(Array *p_array, int i_index) { array_resize(p_array, p_array->i_size - 1); - return p_ret; + return (p_ret); } void @@ -147,17 +147,17 @@ array_resize(Array *p_array, int i_size) { void* array_get(Array *p_array, int i_index) { if (p_array->i_size > i_index) - return p_array->pp_ae[i_index]->p_val; + return (p_array->pp_ae[i_index]->p_val); - return NULL; + return (NULL); } _Bool array_defined(Array *p_array, int i_index) { if (i_index >= p_array->i_size) - return false; + return (false); - return p_array->pp_ae[i_index]->p_val != NULL; + return (p_array->pp_ae[i_index]->p_val != NULL); } void @@ -222,7 +222,7 @@ arrayelement_new(void *p_val) { p_ae->p_val = p_val; - return p_ae; + return (p_ae); } void @@ -235,14 +235,27 @@ arrayelement_delete(ArrayElement *p_ae) { ArrayIterator* arrayiterator_new(Array *p_array) { - if (!p_array) - return NULL; + if (p_array == NULL) + return (NULL); ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator)); p_arrayiterator->p_array = p_array; p_arrayiterator->i_cur_pos = 0; + p_arrayiterator->b_is_reverse = false; + + return (p_arrayiterator); +} + +ArrayIterator* +arrayiterator_new_reverse(Array *p_array) { + ArrayIterator *p_arrayiterator = arrayiterator_new(p_array); + if (p_arrayiterator == NULL) + return (NULL); + + p_arrayiterator->b_is_reverse = true; + p_arrayiterator->i_cur_pos = p_array->i_size; - return p_arrayiterator; + return (p_arrayiterator); } void @@ -253,14 +266,21 @@ arrayiterator_delete(ArrayIterator *p_arrayiterator) { _Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator) { - return p_arrayiterator->i_cur_pos < - array_get_size(p_arrayiterator->p_array); + if (p_arrayiterator->b_is_reverse) + return (p_arrayiterator->i_cur_pos >= 0); + + return (p_arrayiterator->i_cur_pos < + array_get_size(p_arrayiterator->p_array)); } void* arrayiterator_next(ArrayIterator *p_arrayiterator) { if (!arrayiterator_has_next(p_arrayiterator)) - return NULL; + return (NULL); + + if (p_arrayiterator->b_is_reverse) + return (array_get(p_arrayiterator->p_array, + p_arrayiterator->i_cur_pos--)); - return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++); + return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++)); } -- cgit v1.2.3 From cb1450b796eff3c8830616e2e9a3d83d4dfb4900 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 18 Oct 2008 22:47:31 +0000 Subject: backdowngrade --- src/data/array.c | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index da5bee8..2ae4ece 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -41,7 +41,7 @@ array_new() { p_array->i_size = 0; p_array->pp_ae = NULL; - return (p_array); + return p_array; } @@ -92,7 +92,7 @@ array_insert(Array *p_array, int i_index, void *p_val) { void* array_remove(Array *p_array, int i_index) { if (p_array->i_size <= i_index) - return (NULL); + return NULL; ArrayElement *p_ae = p_array->pp_ae[i_index]; void *p_ret = p_ae->p_val; @@ -105,7 +105,7 @@ array_remove(Array *p_array, int i_index) { array_resize(p_array, p_array->i_size - 1); - return (p_ret); + return p_ret; } void @@ -147,17 +147,17 @@ array_resize(Array *p_array, int i_size) { void* array_get(Array *p_array, int i_index) { if (p_array->i_size > i_index) - return (p_array->pp_ae[i_index]->p_val); + return p_array->pp_ae[i_index]->p_val; - return (NULL); + return NULL; } _Bool array_defined(Array *p_array, int i_index) { if (i_index >= p_array->i_size) - return (false); + return false; - return (p_array->pp_ae[i_index]->p_val != NULL); + return p_array->pp_ae[i_index]->p_val != NULL; } void @@ -222,7 +222,7 @@ arrayelement_new(void *p_val) { p_ae->p_val = p_val; - return (p_ae); + return p_ae; } void @@ -235,27 +235,14 @@ arrayelement_delete(ArrayElement *p_ae) { ArrayIterator* arrayiterator_new(Array *p_array) { - if (p_array == NULL) - return (NULL); + if (!p_array) + return NULL; ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator)); p_arrayiterator->p_array = p_array; p_arrayiterator->i_cur_pos = 0; - p_arrayiterator->b_is_reverse = false; - - return (p_arrayiterator); -} - -ArrayIterator* -arrayiterator_new_reverse(Array *p_array) { - ArrayIterator *p_arrayiterator = arrayiterator_new(p_array); - if (p_arrayiterator == NULL) - return (NULL); - - p_arrayiterator->b_is_reverse = true; - p_arrayiterator->i_cur_pos = p_array->i_size; - return (p_arrayiterator); + return p_arrayiterator; } void @@ -266,21 +253,14 @@ arrayiterator_delete(ArrayIterator *p_arrayiterator) { _Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator) { - if (p_arrayiterator->b_is_reverse) - return (p_arrayiterator->i_cur_pos >= 0); - - return (p_arrayiterator->i_cur_pos < - array_get_size(p_arrayiterator->p_array)); + return p_arrayiterator->i_cur_pos < + array_get_size(p_arrayiterator->p_array); } void* arrayiterator_next(ArrayIterator *p_arrayiterator) { if (!arrayiterator_has_next(p_arrayiterator)) - return (NULL); - - if (p_arrayiterator->b_is_reverse) - return (array_get(p_arrayiterator->p_array, - p_arrayiterator->i_cur_pos--)); + return NULL; - return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++)); + return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++); } -- cgit v1.2.3 From a5f564d59149de660c4832b8c6e8acd42770479c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 25 Oct 2008 00:12:08 +0000 Subject: make headers --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 2ae4ece..463297c 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From 1c6dd17947050d2f70dd8df6f4ad527180581c68 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 25 Oct 2008 00:23:48 +0000 Subject: astyle. more BSD style in return (FOO); --- src/data/array.c | 58 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 463297c..5ed61c3 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ @@ -41,7 +41,7 @@ array_new() { p_array->i_size = 0; p_array->pp_ae = NULL; - return p_array; + return (p_array); } @@ -92,7 +92,7 @@ array_insert(Array *p_array, int i_index, void *p_val) { void* array_remove(Array *p_array, int i_index) { if (p_array->i_size <= i_index) - return NULL; + return (NULL); ArrayElement *p_ae = p_array->pp_ae[i_index]; void *p_ret = p_ae->p_val; @@ -105,7 +105,7 @@ array_remove(Array *p_array, int i_index) { array_resize(p_array, p_array->i_size - 1); - return p_ret; + return (p_ret); } void @@ -147,17 +147,17 @@ array_resize(Array *p_array, int i_size) { void* array_get(Array *p_array, int i_index) { if (p_array->i_size > i_index) - return p_array->pp_ae[i_index]->p_val; + return (p_array->pp_ae[i_index]->p_val); - return NULL; + return (NULL); } _Bool array_defined(Array *p_array, int i_index) { if (i_index >= p_array->i_size) - return false; + return (false); - return p_array->pp_ae[i_index]->p_val != NULL; + return (p_array->pp_ae[i_index]->p_val != NULL); } void @@ -222,7 +222,7 @@ arrayelement_new(void *p_val) { p_ae->p_val = p_val; - return p_ae; + return (p_ae); } void @@ -236,13 +236,13 @@ arrayelement_delete(ArrayElement *p_ae) { ArrayIterator* arrayiterator_new(Array *p_array) { if (!p_array) - return NULL; + return (NULL); ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator)); p_arrayiterator->p_array = p_array; p_arrayiterator->i_cur_pos = 0; - return p_arrayiterator; + return (p_arrayiterator); } void @@ -253,14 +253,14 @@ arrayiterator_delete(ArrayIterator *p_arrayiterator) { _Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator) { - return p_arrayiterator->i_cur_pos < - array_get_size(p_arrayiterator->p_array); + return (p_arrayiterator->i_cur_pos < + array_get_size(p_arrayiterator->p_array)); } void* arrayiterator_next(ArrayIterator *p_arrayiterator) { if (!arrayiterator_has_next(p_arrayiterator)) - return NULL; + return (NULL); - return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++); + return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++)); } -- cgit v1.2.3 From 1c2c79c47719ca828ce0eb4365ea0327fe89f2d8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 28 Oct 2008 22:23:40 +0000 Subject: initial references support. run "make headers" --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 5ed61c3..93b3375 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From eb2a3bdc387eb76908dcd59b165738adccc28786 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 1 Nov 2008 18:57:20 +0000 Subject: modified headers --- src/data/array.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 93b3375..09022ff 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -19,10 +19,10 @@ *: be used to endorse or promote products derived from this software *: without specific prior written permission. *: - *: THIS SOFTWARE IS PROVIDED BY Paul Buetow AS IS'' AND ANY EXPRESS OR + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL Paul Buetow BE LIABLE FOR ANY DIRECT, + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -- cgit v1.2.3 From ff0828f06a1f317681c45402feda48bde592a076 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 4 Nov 2008 21:20:56 +0000 Subject: array_new_size array_new_copy implemented --- src/data/array.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 09022ff..6a2b1fa 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -44,6 +44,29 @@ array_new() { return (p_array); } +Array* +array_new_size(int i_size) { + Array *p_array = malloc(sizeof(Array)); + + p_array->i_size = 0; + p_array->pp_ae = NULL; + array_resize(p_array, i_size); + + return (p_array); +} + +void +_array_new_copy_cb(void *p_array, void *p_void) { + array_unshift(p_array, p_void); +} + +Array* +array_new_copy(Array *p_array) { + Array *p_array_cpy = array_new_size(array_get_size(p_array)); + array_iterate2(p_array, _array_new_copy_cb, p_array_cpy); + + return (p_array_cpy); +} void array_delete(Array *p_array) { -- cgit v1.2.3 From 37c687c229f89202e5625bc3d3f9b1c85cb94b51 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 4 Nov 2008 21:29:33 +0000 Subject: array_delete_iterate implemented.. --- src/data/array.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 6a2b1fa..553d6f5 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -83,6 +83,23 @@ array_delete(Array *p_array) { free(p_array); } +void +array_delete_iterate(Array *p_array, void (*func)(void *)) { + if (!p_array) + return; + + array_iterate(p_array, func); + + if (p_array->i_size) + for (int i = p_array->i_size - 1; i >= 0; --i) + arrayelement_delete(p_array->pp_ae[i]); + + if (p_array->pp_ae) + free(p_array->pp_ae); + + free(p_array); +} + void array_set(Array *p_array, int i_index, void *p_val) { if (p_array->i_size > i_index) { -- cgit v1.2.3 From 87de8060633801d3793246967f43c6159b0f5351 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 4 Nov 2008 22:55:22 +0000 Subject: astyle --- src/data/array.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 553d6f5..8e3419a 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,13 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +15,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ @@ -63,7 +63,7 @@ _array_new_copy_cb(void *p_array, void *p_void) { Array* array_new_copy(Array *p_array) { Array *p_array_cpy = array_new_size(array_get_size(p_array)); - array_iterate2(p_array, _array_new_copy_cb, p_array_cpy); + array_iterate2(p_array, _array_new_copy_cb, p_array_cpy); return (p_array_cpy); } -- cgit v1.2.3 From d2713783c48ca9fbdd6f4ea3aab03fe856fdd52a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 4 Nov 2008 23:24:42 +0000 Subject: big step forward for arrays in fype. --- src/data/array.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 8e3419a..9bd0101 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -56,14 +56,14 @@ array_new_size(int i_size) { } void -_array_new_copy_cb(void *p_array, void *p_void) { +_unshift_cb(void *p_array, void *p_void) { array_unshift(p_array, p_void); } Array* array_new_copy(Array *p_array) { Array *p_array_cpy = array_new_size(array_get_size(p_array)); - array_iterate2(p_array, _array_new_copy_cb, p_array_cpy); + array_iterate2(p_array, _unshift_cb, p_array_cpy); return (p_array_cpy); } @@ -238,6 +238,13 @@ array_push(Array *p_array, void *p_void) { array_set(p_array, 0, p_void); } +void +array_append(Array *p_array, Array *p_array_append) { + int i_size = array_get_size(p_array) + array_get_size(p_array_append); + array_resize(p_array, i_size); + array_iterate2(p_array_append, _unshift_cb, p_array); +} + void array_iterate(Array *p_array, void (*func)(void *)) { if (!p_array) -- cgit v1.2.3 From a46655f67043af257e70715903badf9d4321c4de Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 7 Nov 2008 22:11:06 +0000 Subject: one step further for arrays. --- src/data/array.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 9bd0101..ba9cf2a 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -40,16 +40,15 @@ array_new() { p_array->i_size = 0; p_array->pp_ae = NULL; + array_set_used(p_array, 0); return (p_array); } Array* array_new_size(int i_size) { - Array *p_array = malloc(sizeof(Array)); + Array *p_array = array_new(); - p_array->i_size = 0; - p_array->pp_ae = NULL; array_resize(p_array, i_size); return (p_array); @@ -109,8 +108,18 @@ array_set(Array *p_array, int i_index, void *p_val) { array_resize(p_array, i_index + 1); p_array->pp_ae[i_index]->p_val = p_val; } + + if (p_array->i_used < i_index) + array_set_used(p_array, i_index); } +void +array_set_used(Array *p_array, int i_used) { + //printf("foo %d",i_used); + p_array->i_used = i_used; +} + + void array_insert(Array *p_array, int i_index, void *p_val) { if (p_array->i_size <= i_index) { @@ -127,6 +136,9 @@ array_insert(Array *p_array, int i_index, void *p_val) { p_array->pp_ae[i] = p_ae; p_ae->p_val = p_val; } + + if (p_array->i_used < i_index) + array_set_used(p_array, i_index); } void* @@ -144,7 +156,6 @@ array_remove(Array *p_array, int i_index) { p_array->pp_ae[i-1] = p_ae; array_resize(p_array, p_array->i_size - 1); - return (p_ret); } @@ -182,6 +193,9 @@ array_resize(Array *p_array, int i_size) { p_array->pp_ae[i] = arrayelement_new(NULL); p_array->i_size = i_size; + //printf("[%d > %d]", p_array->i_used, i_size); + if (p_array->i_used > i_size) + array_set_used(p_array, i_size); } void* @@ -223,8 +237,9 @@ array_splice(Array *p_array, int i_index, Array *p_array2) { void array_unshift(Array *p_array, void *p_void) { - int i_size = array_get_size(p_array); - array_set(p_array, i_size, p_void); + int i_used = array_get_used(p_array); + array_set(p_array, i_used, p_void); + array_set_used(p_array, 1+i_used); } void @@ -250,7 +265,7 @@ array_iterate(Array *p_array, void (*func)(void *)) { if (!p_array) return; - for (int i = 0; i < array_get_size(p_array); ++i) + for (int i = 0; i < array_get_used(p_array); ++i) (*func) (array_get(p_array, i)); } @@ -259,7 +274,7 @@ array_iterate2(Array *p_array, void (*func)(void *, void *), void *p_void) { if (!p_array) return; - for (int i = 0; i < array_get_size(p_array); ++i) + for (int i = 0; i < array_get_used(p_array); ++i) (*func) (array_get(p_array, i), p_void); } @@ -300,8 +315,9 @@ arrayiterator_delete(ArrayIterator *p_arrayiterator) { _Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator) { + //printf("[%d]", p_arrayiterator->p_array->i_used); return (p_arrayiterator->i_cur_pos < - array_get_size(p_arrayiterator->p_array)); + array_get_used(p_arrayiterator->p_array)); } void* -- cgit v1.2.3 From 0c69b76e7d7cbc50d4f87e41766a2de1394a6cad Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 Nov 2008 11:28:26 +0000 Subject: len and ind implemented --- src/data/array.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index ba9cf2a..21e941d 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -115,7 +115,6 @@ array_set(Array *p_array, int i_index, void *p_val) { void array_set_used(Array *p_array, int i_used) { - //printf("foo %d",i_used); p_array->i_used = i_used; } @@ -193,7 +192,6 @@ array_resize(Array *p_array, int i_size) { p_array->pp_ae[i] = arrayelement_new(NULL); p_array->i_size = i_size; - //printf("[%d > %d]", p_array->i_used, i_size); if (p_array->i_used > i_size) array_set_used(p_array, i_size); } -- cgit v1.2.3 From 117201ad10df2859fb3510e8437d776f3a691f69 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 Nov 2008 13:23:58 +0000 Subject: changed the src headers. --- src/data/array.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 21e941d..bfe9a65 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,13 +1,14 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org - *: E-Mail : fype@dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: AUTHOR : http://paul.buetow.org + *: E-Mail : fype at dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -15,20 +16,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From 44c97ead68a274e462460eef33d67e7442c2fa47 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 15 Dec 2008 20:57:29 +0000 Subject: say foo[1] works --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index bfe9a65..5017e8c 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,14 +1,14 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: AUTHOR : http://paul.buetow.org *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: + *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -16,20 +16,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3 From 40ad7ffc7ebd91e90f0894badcc4132df9b3c45d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 15 Dec 2008 20:58:59 +0000 Subject: modified headers --- src/data/array.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/data/array.c') diff --git a/src/data/array.c b/src/data/array.c index 5017e8c..5543d41 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,14 +1,14 @@ /*:* *: File: ./src/data/array.c *: A simple interpreter - *: + *: *: WWW : http://fype.buetow.org *: AUTHOR : http://paul.buetow.org *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow + *: + *: Copyright (c) 2005 - 2008, Paul Buetow *: All rights reserved. - *: + *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: *: * Redistributions of source code must retain the above copyright @@ -16,20 +16,20 @@ *: * Redistributions in binary form must reproduce the above copyright *: notice, this list of conditions and the following disclaimer in the *: documentation and/or other materials provided with the distribution. - *: * Neither the name of P. B. Labs nor the names of its contributors may - *: be used to endorse or promote products derived from this software + *: * Neither the name of P. B. Labs nor the names of its contributors may + *: be used to endorse or promote products derived from this software *: without specific prior written permission. - *: - *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR - *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + *: + *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR + *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, - *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT, + *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *: POSSIBILITY OF SUCH DAMAGE. *:*/ -- cgit v1.2.3