Browse Source

v.mapcalc: moved to Addons

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62549 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 10 years ago
parent
commit
b0e848d8cd

+ 0 - 14
vector/v.mapcalc/Makefile

@@ -1,14 +0,0 @@
-MODULE_TOPDIR = ../..
-
-PGM = v.mapcalc
-
-LIBES = $(GISLIB) $(DLLIB)
-DEPENDENCIES = $(GISDEP)
-
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-default: cmd
-
-yylex.c: v.mapcalc.tab.h
-
-.INTERMEDIATE: v.mapcalc.tab.c v.mapcalc.tab.h v.mapcalc.output

+ 0 - 254
vector/v.mapcalc/README

@@ -1,255 +0,0 @@
-The code was written by Christoph Simon <ciccio@kiosknet.com.br>.
-
-DESCRIPTION
-
-From ciccio@kiosknet.com.br Wed Aug  7 16:03:56 2002
-From: Christoph Simon <ciccio@kiosknet.com.br>
-To: grass5@grass.itc.it
-
-I've started to program a vector calculator program for Grass,
-inspired by r.mapcalc, wich is available at
-
-	http://freegis.org/cgi-bin/viewcvs.cgi/grass51/vector/v.mapcalc/
-
-Right now, I need to take a break working on it for professional
-reasons, as I am involved in a bigger project of which I do not know
-how long it will last.
-
-I'll try to summarize and comment here on what has been done, what it
-is useful for and what still needs to be done.
-
-It's much more complicated to deal with vector maps than with raster
-maps. Particularly, there are several levels on which we might want to
-deal with a vector map. For this reason the design of v.mapcalc is
-that of a skeleton with plugins: A parser will interpret statements
-and call the appropriate functions it finds in dynamically loaded
-plugins.
-
-The syntax should be able to deal with four different types:
-
-	- numbers
-	- points
-	- point lists
-	- maps
-
-Nummeric expressions should do what everybody would expect. There are
-some dozens of builtin functions from the math library. Points and
-point lists are meant in the mathematical sense: A point is a set of
-two or three numbers, representing the coordinate. All points have
-three components, but the third, if missing has the value of
-0.0/0.0 (NaN). An expression will yield a 3D result if all arguments a
-3D. There is a set of basic builtin operations like dot and cross
-product. Point lists are meant for polygons, lines, areas, etc. Points
-and point lists have no categories or attributes. And finally, of
-course, v.mapcalc deals with map expressions.
-
-For numbers, the infix operators do the obvious. For other types, the
-parser will translate them to function calls with predefined
-names. Some samples are set and can be replaced by something useful.
-
-The plugins are designed to be as simple as possible. There is one
-example which actually doesn't do anything but shows how it can be
-called. Such a plugin needs three global functions: One which can be
-called to find out the name the user must type to use the function,
-one which returns a string denoting the return type and the type and
-number of arguments, and finally the function itself.
-
-There are two more types which are somewhat special: One is type
-`argument' which can be any of the basic types. The parser will accept
-anything to be the argument to a function call, but the mechanism to
-actually call that function will check if the types match the
-prototype. The second special type `any' is sort of a backdoor: If
-something new comes up, it can be treated as type any, and it will be
-responsibility of the plugin to verify that it's the correct type. One
-case where the any-type can be useful is for SQL statement-pieces or
-other constructs when dealing with attributes, which can be literally
-of "any" type.
-
-There is one problem with this approach within v.mapcalc, which is
-calling a function with a variable list of arguments. This is a bit
-complicated, and before thinking of easy solutions, I need to
-recommend reading the code. Just before calling it, v.mapcalc has a
-pointer to that functions and a linked list of structures which hold
-the argument types and values. It would be nice to be able to
-construct such a call argument by argument, but there is no portable
-way to do so: First assembly would be needed, and second, the way a
-stack frame is built for a particular compiler/architecture can vary.
-The solution is to maintain a list of typedef'd prototypes and call
-them in a switch. This means, if someone needs a new function and
-writes a plugin, either he finds a typedef which matches this
-prototype, or he needs to add the typedef and a case in the switch.
-
-It makes only limited sense to mix arguments of different types: three
-at the power of map-A doesn't seem to be useful. So, the basic
-strategy is accept expressions only of the same type, while mixing
-types is always possible within the arguments to a function call.
-
-There is a file listing some example expressions. I hope that it is
-what one could expect. Adding a few plugins should allow for very
-complex expressions and operations.
-
-What still needs to be done:
-
-- The lexical scanner. At this point, there is a very simple and
-  limited scanner. My plan was to provide 4 methods of input:
-  + from the command line
-  + from stdin, interactively, using GNU readline and history
-  + from stdin by IO redirection like in "script | v.mapcalc"
-  + from a file, like in "v.mapcalc -i statementfile"
-  Of course, this should be done with Flex, with the input selection
-  as needed for all methods, as well as support for Bison to indicate
-  the position of a parse error.
-- There should be several builtin commands allowing to:
-  + include a file with statements
-  + document the meaning of a variable or function
-  + attaching documentaton to a variable or function
-  + saving certain things in a readible script like documentation or
-    constant values.
-  + a command to terminate the program (right now, only with Ctrl-D)
-- There is not yet any support for loops and conditionals. These do
-  not seem to be of much use with maps, but can prove powerful on
-  points and point lists.
-- There are certain operations which need to be performed always, like
-  opening a map. For now, they need to be done in the plugin, but
-  should definitively move to v.mapcalc.
-- Point lists are not working yet, though much of the basic
-  infrastructure is already done.
-- There seems to be a bug in memory management which can cause the
-  program to crash. Probably there are many more than that.
-
-I plan to continue work on v.mapcalc as soon as my time allows. In the
-meanwhile, I'd be happy if others advance on this (the core of
-v.mapcalc and/or plugins), and I'll do everything to answer questions
-someone might have trying to do so.
-
-Christoph Simon
-ciccio@kiosknet.com.br
-
----------------------------------------------------------------------------
-EXAMPLES:
-
-Some examples of what is working now:
-
-This is an empty statement, which is legal
-         ;
-
-Some builtin constants:
-         12;
-         e;
-         pi;
-         pnt_o;
-         pnt_i;
-         pnt_j;
-         pnt_k;
-         rivers;
-
-The last one isn't really a constant, as it depends on what if found
-at startup, but it behaves just the like.
-
-         a;
-This gives an error. "a", which is (not yet) defined, is handled as a
-string. There is no operation associated, so this gives a parse error.
-
-Next some simple assignments. Also here, the name of the variable is
-initially not more than a string, but after performing the assignment,
-they take the type of the expressionL:
-         num = 10.3;
-         pnt = (0,0);
-         map = rivers;
-         any = mkstring (hallo);
-The last is only a backdoor for cases when exceptional things are
-needed. The function mkstring is a sample implementation of type
-ANY. For now, only one word could be passed, but when flex is being
-used a quoted string might contain just anything.
-
-Next, I overwrite these variables. This is somewhat tricky. If you say
-"map = rivers", what should happen? In theory, we should actually
-duplicate this map, which could imply gigabytes on disk. This is not
-done, but if the map is changed, it must not change the former
-`value'. I hope it's doing now, what everybody would expect (including
-to free eventually the allocated memory).
-
-         num = 3.1;
-         pnt = (1,1);
-         map = cities;
-         any = mkstring (hello);
-
-The pure nummeric operations aren't new, beside that I'm trying to
-catch illegal operations:
-         sqrt(e);
-         num = cos (pi/4);
-         num = -num + 3 * num - sqrt (num^2);
-         3.3 + 4.4;
-         2.2 - 1.1;
-         5 * 7;
-         21 / 0;
-         21 / 2;
-         -21 / 7;
-         -6.6 ^ 1.2;
-         6.6 ^ 1.2;
-         12.5 % 3.6;
-         2 * (3.1 + 0.9);
-
-Next are points. Note that 2D and 3D are dealt with identically; in
-case of 2D, the z-value is 0.0/0.0 (NaN, "Not a Number"). This should
-be pretty portable. Generally, if at least one point is 2D, the result
-of a point operation will be 2D even if 3D points are involved too,
-ignoring the third dimension. I've defined some infix operations a bit
-arbitrarily. Of course, this could be changed. The double () in case
-of a single function argument are surely ugly, but not avoidable.
-
-         origin2d = (0,0);
-         p1 = (1,1);
-         p2 = p1;
-         p2 = v_copy (p1);
-         v_add ((1,0), (0,1));
-         (1,0) + (0,1);
-         v_sub ((1,1), (0,1));
-         (1,1) - (0,1);
-         v_abs ((-2, -1));
-         v_neg ((2, 1));
-         -(2,1);
-         v_mul ((2,4), 3.3);
-         (2,4) * 3.3;
-         3.3 * (2,4);
-         v_div ((6.6, 13.2), 3.3);
-         (6.6, 13.2) / 3.3;
-         v_unit ((12, 8));
-         v_cross ((1,2), (4,5));
-         v_cross ((1,2,3), (4,5,6));
-         (1,2,3) ^ (4,5,6);
-         v_val ((3,3));
-         v_dot ((1,2), (3,4));
-         (1,2) % (3,4);
-         v_dot ((1,2,3), (4,5,6));
-         (1,2,3) % (4,5,6);
-         v_area ((1,2,3), (4,5,6));
-         v_eq ((1,2), (1, 2));
-         v_eq ((1,2), (1.0001, 2.0001));
-         epsilon = (1e-3, 1e-3);
-         v_eq_epsilon ((1,2), (1.0001, 2.0001), epsilon);
-         v_isortho ((0,1), (1,0));
-         v_ispara ((0, 1), (0, -1));
-         v_isacute ((0, 1), (0, 0.5));
-         3 * (pnt + (2,2));
-
-This is planned, but doesn't work yet:
-
-         line = ((1,1), (2,1));
-         triangle = (line, (1.5, 2));
-
-And finally the map operations, which also aren't new, beside some
-internal details (freeing memory, not duplicating, etc.). I think that
-there is no map-operation which makes sense if it is not assigned to a
-variable. So all map expressions need to follow a variable and an
-equal sign. The very first expression, hence, will give an error:
-
-         rivers + cities;
-         map = rivers;
-         map;
-         map = rivers + cities;
-         map = testmap (rivers);
-         map = test2map (rivers, cities);
-         map = dltest (rivers, cities);
-

+ 0 - 142
vector/v.mapcalc/any.c

@@ -1,142 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "list.h"
-#include "mapcalc.h"
-#include "any.h"
-
-/*
- * This is a backdoor for strange types only. We only handle void pointer
- * references and make no kind of typecheck; lot's of errors can be made
- * by the user. But at least it's possible to deal with minor issues
- * without touching the parser.
- * Memory for "any" should be one single block.
- */
-
-typedef ANY *(*a_func) (void);
-typedef ANY *(*a_func_a) (void *a0);
-typedef ANY *(*a_func_aa) (void *a0, void *a1);
-
-typedef struct Anyfunc
-{
-    char *name;
-    void *func;
-    char *proto;
-} ANYFUNC;
-
-static ANY *mkstring(void *a);
-void setany(SYMBOL * var, SYMBOL * any);
-SYMBOL *mkanyvar(SYMBOL * var, SYMBOL * any);
-SYMBOL *anyfunc(SYMBOL * func, SYMBOL * arglist);
-
-static ANYFUNC af[] = {
-    {"mkstring", mkstring, "a"},
-    {NULL, NULL, NULL}
-};
-
-/***************************************************************************
- * Test function only
- */
-static ANY *mkstring(void *a)
-{
-    ANY *str;
-
-    str = (ANY *) listitem(sizeof(ANY));
-    str->type = st_str;
-    str->any = (char *)strdup(a);
-    str->refcnt = 1;
-    fprintf(stdout, "\t%s\n", (char *)a);
-
-    return str;
-}
-
-/*
- * End test function only
- ***************************************************************************/
-
-void init_any(void)
-{
-    SYMBOL *sym;
-    int i;
-
-    for (i = 0; af[i].name; i++) {
-	sym = putsym(af[i].name);
-	sym->type = sym->itype = st_afunc;
-	sym->v.p = af[i].func;
-	sym->proto = af[i].proto;
-	sym->rettype = st_any;
-    }
-}
-
-void setany(SYMBOL * var, SYMBOL * any)
-{
-    SYMBOL *sym;
-
-    if (var->name) {
-	sym = getsym(var->name);
-	if (sym) {
-	    if (--((ANY *) sym->v.p)->refcnt < 1)
-		G_free(sym->v.p);
-	    sym->v.p = any->v.p;
-	}
-    }
-
-    if (--((ANY *) var->v.p)->refcnt < 1)
-	G_free(var->v.p);
-    var->v.p = NULL;
-    freesym(var);
-
-    /* can't show an anyvar */
-    any->v.p = NULL;
-    freesym(any);
-}
-
-SYMBOL *mkanyvar(SYMBOL * var, SYMBOL * any)
-{
-    var->type = var->itype = st_any;
-    var->name = var->v.p;
-    var->v.p = any->v.p;
-    any->v.p = NULL;
-    symtab = (SYMBOL *) listadd((LIST *) symtab, (LIST *) var, cmpsymsym);
-
-    /* can't show any */
-
-    return var;
-}
-
-SYMBOL *anyfunc(SYMBOL * func, SYMBOL * arglist)
-{
-    SYMBOL *sym;
-    ANY *res = NULL;
-    int argc = -1;
-
-    if (!func || !func->v.p || func->type != st_afunc) {
-	parseerror = 1;
-	G_warning(_("Can't call bad any-function"));
-    }
-    else
-	argc = listcnt((LIST *) arglist);
-
-    if (argc == 0 && (!func->proto || !*func->proto))
-	res = (*(a_func) func->v.p) ();
-    else if (argc == 1 && !strcmp(func->proto, "a"))
-	res = (*(a_func_a) func->v.p) (arglist->v.p);
-    else if (argc == 2 && !strcmp(func->proto, "aa"))
-	res = (*(a_func_aa) func->v.p) (arglist->v.p, arglist->next->v.p);
-    else {
-	G_warning(_("Bad arguments to anyfunc %s (argc = %d)"), func->name,
-		  argc);
-	parseerror = 1;
-    }
-
-    listdelall((LIST *) func, freesym);
-    listdelall((LIST *) arglist, freesym);
-
-    sym = (SYMBOL *) listitem(sizeof(SYMBOL));
-    sym->type = st_any;
-    sym->v.p = res;
-
-    return sym;
-}

+ 0 - 17
vector/v.mapcalc/any.h

@@ -1,17 +0,0 @@
-#ifndef ANY_H
-#define ANY_H
-
-typedef struct Any
-{
-    struct Any *next;
-    STYP type;
-    void *any;
-    int refcnt;
-} ANY;
-
-extern void init_any(void);
-extern void setany(SYMBOL * var, SYMBOL * any);
-extern SYMBOL *mkanyvar(SYMBOL * var, SYMBOL * any);
-extern SYMBOL *anyfunc(SYMBOL * func, SYMBOL * arglist);
-
-#endif

+ 0 - 748
vector/v.mapcalc/list.c

@@ -1,748 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <time.h>
-#if 0
-#include <dmalloc.h>
-#endif
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "list.h"
-
-LIST *listitem(size_t size);
-LIST *listadd(LIST * head, LIST * elt, cmpfunc cmp);
-LIST *listaddnth(LIST * head, LIST * elt, int nth);
-LIST *listprep(LIST * head, LIST * elt);
-LIST *listapp(LIST * head, LIST * elt);
-LIST *listunlink(LIST * head, LIST * elt);
-LIST *listunlinknth(LIST * head, int nth);
-LIST *listdel(LIST * head, LIST * elt, freefunc func);
-LIST *listdelnth(LIST * head, int nth, freefunc func);
-int listcnt(LIST * head);
-LIST *listdup(LIST * head, cpyfunc cpy, size_t size);
-LIST *listsplit(LIST * head, LIST * elt);
-LIST *listsplitnth(LIST * head, int nth);
-LIST *listjoin(LIST * head, LIST * tail);
-LIST *listsort(LIST * head, cmpfunc cmp);
-LIST *listrev(LIST * head);
-LIST *listshuffle(LIST * head);
-LIST *listdelall(LIST * head, freefunc func);
-LIST **list2array(LIST * head);
-LIST *array2list(LIST ** array);
-void listforeach(LIST * head, actfunc action);
-int listidx(LIST * head, LIST * elt);
-LIST *listlast(LIST * head);
-LIST *listnth(LIST * head, int nth);
-LIST *listfind(LIST * head, LIST * elt, cmpfunc cmp);
-LIST *listfinddatum(LIST * head, void *datum, cmpfunc cmp);
-LIST *listbsearch(LIST * head, LIST * elt, cmpfunc cmp);
-LIST *listbsearchdatum(LIST * head, const void *data, cmpfunc cmp);
-
-static LIST *_listbsearch(LIST * min, int max, LIST * elt, cmpfunc cmp);
-static LIST *_listbsearchdatum(LIST * min, int max, const void *datum,
-			       cmpfunc cmp);
-
-/*
- * listitem()                   allocate memory for a list item
- */
-
-LIST *listitem(size_t size)
-{
-    LIST *item;
-
-    item = G_calloc(1, size);
-    if (!item) {
-	G_fatal_error(_("Out of memory"));
-	exit(1);
-    }
-
-    return item;
-}
-
-/*
- * listadd()                    insert item before first greater
- * (cmp == NULL) -> listapp()
- * This is VERY slow. Rather than a lineal search, we should
- * try to implement a listbapprox() function.
- */
-
-LIST *listadd(LIST * head, LIST * elt, cmpfunc cmp)
-{
-    LIST *item, *prev = NULL;
-
-    if (elt)
-	elt->next = NULL;
-
-    if (!elt)
-	return head;
-    if (!head)
-	return elt;
-    if (!cmp)
-	return listapp(head, elt);
-
-    for (item = head; item; item = item->next) {
-	/*
-	 * cmp (sample, each):
-	 * Answers if each is smaller/equal/greater than sample
-	 */
-	if ((*cmp) (elt, item) > 0)
-	    break;
-	prev = item;
-    }
-
-    if (!prev) {
-	elt->next = head;
-	head = elt;
-    }
-    else {
-	elt->next = prev->next;
-	prev->next = elt;
-    }
-
-    return head;
-}
-
-/*
- * listaddnth()                 make new item the nth of the list
- * (nth <= 0) -> listprep(), (nth > listcnt()) -> listapp()
- */
-
-LIST *listaddnth(LIST * head, LIST * elt, int nth)
-{
-    LIST *item, *prev = NULL;
-    int i;
-
-    if (elt)
-	elt->next = NULL;
-
-    if (!head)
-	return elt;
-    if (!elt)
-	return head;
-
-    if (nth < 1) {
-	elt->next = head;
-	return elt;
-    }
-
-    for (i = 0, item = head; item && i < nth; item = item->next, i++)
-	prev = item;
-
-    elt->next = prev->next;
-    prev->next = elt;
-
-    return head;
-}
-
-/*
- * listprep()                           prepend item on list
- */
-
-inline LIST *listprep(LIST * head, LIST * elt)
-{
-    if (elt && elt->next)
-	elt->next = NULL;
-
-    if (!head)
-	return elt;
-    if (!elt)
-	return head;
-
-    elt->next = head;
-
-    return elt;
-}
-
-/*
- * listapp()                            append item to list
- */
-
-LIST *listapp(LIST * head, LIST * elt)
-{
-    LIST *item;
-
-    if (elt)
-	elt->next = NULL;
-
-    if (!head)
-	return elt;
-    if (!elt)
-	return head;
-
-    for (item = head; item && item->next; item = item->next) ;
-
-    item->next = elt;
-
-    return head;
-}
-
-/*
- * listunlink()                         unlink item from list
- */
-
-LIST *listunlink(LIST * head, LIST * elt)
-{
-    LIST *item;
-
-    if (!head)
-	return NULL;
-    if (!elt)
-	return head;
-
-    if (head == elt) {
-	head = elt->next;
-	elt->next = NULL;
-	return head;
-    }
-
-    for (item = head; item && item->next != elt; item = item->next) ;
-    if (item->next == elt) {
-	item->next = elt->next;
-	elt->next = NULL;
-    }
-    return head;
-}
-
-/*
- * listunlinknth()                      unlink nth element from list
- * listunlinknth (head, 0) == (car (list))
- */
-
-LIST *listunlinknth(LIST * head, int nth)
-{
-    LIST *item, *elt;
-    int i;
-
-    if (!head)
-	return NULL;
-    if (nth < 0)
-	return head;
-
-    if (nth == 0) {
-	item = head->next;
-	head->next = NULL;
-	return item;
-    }
-
-    for (i = 0, item = head; item && item->next && i < nth - 1;
-	 item = item->next, i++) ;
-    if (item->next) {
-	elt = item->next;
-	item->next = elt->next;
-	elt->next = NULL;
-    }
-    return head;
-}
-
-/*
- * listdel()                            unlink and free element from list
- */
-
-LIST *listdel(LIST * head, LIST * elt, freefunc func)
-{
-    if (!elt)
-	return head;
-
-    if (head)
-	head = listunlink(head, elt);
-
-    if (func)
-	(*func) (elt);
-    G_free(elt);
-
-    return head;
-}
-
-/*
- * listdelnth()                         unlink and free nth element from list
- */
-
-LIST *listdelnth(LIST * head, int nth, freefunc func)
-{
-    LIST *item, *elt;
-    int i;
-
-    if (!head || nth < 0)
-	return NULL;
-
-    if (nth == 0) {
-	elt = head;
-	head = head->next;
-	listdel(NULL, elt, func);
-	return head;
-    }
-
-    for (i = 0, item = head; item && item->next && i < nth - 1;
-	 item = item->next, i++) ;
-
-    if (item && item->next) {
-	elt = item->next;
-	item->next = elt->next;
-	listdel(NULL, elt, func);
-    }
-
-    return head;
-}
-
-/*
- * listcnt()                            cound elements in list
- */
-
-inline int listcnt(LIST * head)
-{
-    LIST *item;
-    int n = 0;
-
-    for (item = head; item; item = item->next)
-	n++;
-
-    return n;
-}
-
-/*
- * listdup()                            duplicate list
- * if cpy is NULL, create same number of empty items
- */
-
-LIST *listdup(LIST * head, cpyfunc cpy, size_t size)
-{
-    LIST *newhead = NULL, *last = NULL, *item, *elt;
-
-    for (item = head; item; item = item->next) {
-	elt = listitem(size);
-	if (cpy)
-	    (*cpy) (elt, item);
-	if (!newhead)
-	    newhead = last = elt;
-	else {
-	    last->next = elt;
-	    last = elt;
-	}
-    }
-
-    return newhead;
-}
-
-/*
- * listsplit()                          make elt the head of a taillist
- */
-
-LIST *listsplit(LIST * head, LIST * elt)
-{
-    LIST *item;
-
-    if (!head || !elt)
-	return elt;
-
-    if (head == elt)
-	return NULL;
-
-    for (item = head; item && item->next != elt; item = item->next) ;
-    if (item->next == elt)
-	item->next = NULL;
-
-    return elt;
-}
-
-/*
- * listsplitnth()                       make nth element the head of a taillist
- */
-
-LIST *listsplitnth(LIST * head, int nth)
-{
-    LIST *item, *tail = NULL;
-    int i;
-
-    if (!head || nth < 1)
-	return NULL;
-
-    for (i = 0, item = head; item && i < nth - 1; item = item->next, i++) ;
-    if (item && item->next) {
-	tail = item->next;
-	item->next = NULL;
-    }
-
-    return tail;
-}
-
-/*
- * listjoin()                           joint two lists
- */
-
-LIST *listjoin(LIST * head, LIST * tail)
-{
-    LIST *item;
-
-    if (!head)
-	return tail;
-    if (!tail)
-	return head;
-
-    for (item = head; item && item->next; item = item->next) ;
-    if (item)
-	item->next = tail;
-
-    return head;
-}
-
-/*
- * listsort()                           Quick sort on list
- */
-
-LIST *listsort(LIST * head, cmpfunc cmp)
-{
-    LIST *high = NULL, *low = NULL, *item, *next;
-
-    if (!head || !head->next)
-	return head;
-
-    for (item = head; item;) {
-	next = item->next;
-	if ((*cmp) (item, head) < 0) {
-	    item->next = low;
-	    low = item;
-	}
-	else {
-	    item->next = high;
-	    high = item;
-	}
-	item = next;
-    }
-
-    high = listsort(high, cmp);
-    low = listsort(low, cmp);
-
-    head = listjoin(high, low);
-
-    return head;
-}
-
-/*
- * listrev()                            reverse order the list
- */
-
-LIST *listrev(LIST * head)
-{
-    LIST *newhead = NULL, *item, *next;
-
-    for (item = head; item;) {
-	next = item->next;
-	newhead = listprep(newhead, item);
-	item = next;
-    }
-
-    return newhead;
-}
-
-/*
- * listshuffle()
- */
-LIST *listshuffle(LIST * head)
-{
-    LIST **array, *newhead = NULL;
-    int n, i = 0, val;
-    struct timeval tv;
-
-    gettimeofday(&tv, NULL);
-    srandom(tv.tv_usec);
-
-    n = listcnt(head);
-    array = list2array(head);
-
-    while (i < n) {
-	val = random() % n;
-
-	if (array[val]) {
-	    newhead = listprep(newhead, array[val]);
-	    array[val] = NULL;
-	    i++;
-	}
-    }
-
-    G_free(array);
-
-    return newhead;
-}
-
-/*
- * listdelall()                         free the whole list
- */
-
-LIST *listdelall(LIST * head, freefunc func)
-{
-    LIST *item, *next;
-
-    for (item = head; item;) {
-	next = item->next;
-	if (func)
-	    (*func) (item);
-	G_free(item);
-	item = next;
-    }
-
-    return NULL;
-}
-
-/*
- * list2array()                         build an array with members of list
- * array is allocated and needs to be G_free ()ed, list not changed.
- */
-
-LIST **list2array(LIST * head)
-{
-    LIST **array, *item;
-    int n, i;
-
-    n = listcnt(head);
-    if (!n)
-	return NULL;
-
-    array = (LIST **) G_calloc(n + 1, sizeof(LIST *));
-    if (!array) {
-	G_fatal_error(_("Out of memory"));
-	exit(1);
-    }
-
-    for (i = 0, item = head; item; item = item->next, i++)
-	array[i] = item;
-
-    return array;
-}
-
-/*
- * array2list()                         link the elements of an array in order
- */
-
-LIST *array2list(LIST ** array)
-{
-    LIST *head = NULL, *item = NULL;
-    int i;
-
-    if (array)
-	head = item = array[0];
-
-    for (i = 1; array && array[i]; i++) {
-	item->next = array[i];
-	item = item->next;
-    }
-    item->next = NULL;
-
-    return head;
-}
-
-/*
- * listforeach()                        execute action on each item
- */
-
-inline void listforeach(LIST * head, actfunc action)
-{
-    LIST *item;
-
-    if (!head || !action)
-	return;
-
-    for (item = head; item; item = item->next)
-	(*action) (item);
-}
-
-/*
- * listidx()                            find offset of item from head
- * head is offset (index) zero.
- */
-
-int listidx(LIST * head, LIST * elt)
-{
-    LIST *item;
-    int i;
-
-    if (!elt)
-	return -1;
-
-    for (i = 0, item = head; item; item = item->next, i++)
-	if (item == elt)
-	    break;
-
-    if (!item)
-	return -1;
-
-    return i;
-}
-
-/*
- * listlast()                           find last item in list.
- */
-
-inline LIST *listlast(LIST * head)
-{
-    LIST *item;
-
-    for (item = head; item && item->next; item = item->next) ;
-
-    return item;
-}
-
-/*
- * listnth()                            find nth item in list.
- */
-
-LIST *listnth(LIST * head, int nth)
-{
-    LIST *item;
-    int i;
-
-    if (!head || nth < 0)
-	return NULL;
-
-    for (i = 0, item = head; item; item = item->next, i++)
-	if (i == nth)
-	    break;
-
-    return item;
-}
-
-/*
- * listfind()                   linear search giving structure as sample
- */
-
-LIST *listfind(LIST * head, LIST * elt, cmpfunc cmp)
-{
-    LIST *item;
-
-    for (item = head; item; item = item->next)
-	if (!(*cmp) (elt, item))
-	    break;
-
-    return item;
-}
-
-/*
- * listfinddatum()              linear search giving sample by pointer
- */
-
-LIST *listfinddatum(LIST * head, void *datum, cmpfunc cmp)
-{
-    LIST *item;
-
-    for (item = head; item; item = item->next)
-	if (!(*cmp) (datum, item))
-	    break;
-
-    return item;
-}
-
-static LIST *_listbsearch(LIST * min, int max, LIST * elt, cmpfunc cmp)
-{
-    LIST *item;
-    int i, n, result;
-
-    if (!min)
-	return NULL;
-
-    n = max / 2;
-
-    for (i = 0, item = min; item && i < n; item = item->next, i++) ;
-
-    result = (*cmp) (item, elt);
-    if (result == 0)
-	return item;
-    if (n == 0) {
-	if (max == 1 && item->next && !(*cmp) (item->next, elt))
-	    return item->next;
-	return NULL;
-    }
-
-    if (result < 0)
-	item = _listbsearch(min, n, elt, cmp);
-    else
-	item = _listbsearch(item->next, max - n - 1, elt, cmp);
-
-    return item;
-}
-
-/*
- * listbsearch()                        binary search with struct as sample
- */
-
-LIST *listbsearch(LIST * head, LIST * elt, cmpfunc cmp)
-{
-    LIST *item;
-    int n, max, result;
-
-    if (!head || !elt || !cmp)
-	return NULL;
-
-    max = listcnt(head);
-
-    n = max / 2;
-    item = listnth(head, n);
-    result = (*cmp) (item, elt);
-
-    if (result == 0)
-	return item;
-
-    if (result < 0)
-	item = _listbsearch(head, n, elt, cmp);
-    else
-	item = _listbsearch(item->next, max - n - 1, elt, cmp);
-
-    return item;
-}
-
-static LIST *_listbsearchdatum(LIST * min, int max, const void *datum,
-			       cmpfunc cmp)
-{
-    LIST *elt;
-    int i, n, result;
-
-    if (!min)
-	return NULL;
-
-    n = max / 2;
-
-    for (i = 0, elt = min; elt && i < n; elt = elt->next, i++) ;
-
-    result = (*cmp) (datum, elt);
-    if (result == 0)
-	return elt;
-    if (n == 0) {
-	if (max == 1 && elt->next && !(*cmp) (datum, elt->next))
-	    return elt->next;
-	return NULL;
-    }
-
-    if (result < 0)
-	elt = _listbsearchdatum(min, n, datum, cmp);
-    else
-	elt = _listbsearchdatum(elt->next, max - n - 1, datum, cmp);
-
-    return elt;
-}
-
-/*
- * listbsearchdatum()                           binary search for sample by ptr
- */
-
-LIST *listbsearchdatum(LIST * head, const void *datum, cmpfunc cmp)
-{
-    LIST *elt;
-    int n, max, result;
-
-    if (!head || !datum || !cmp)
-	return NULL;
-
-    max = listcnt(head);
-
-    n = max / 2;
-    elt = listnth(head, n);
-    result = (*cmp) (datum, elt);
-
-    if (result == 0)
-	return elt;
-
-    if (result < 0)
-	elt = _listbsearchdatum(head, n, datum, cmp);
-    else
-	elt = _listbsearchdatum(elt->next, max - n - 1, datum, cmp);
-
-    return elt;
-}

+ 0 - 54
vector/v.mapcalc/list.h

@@ -1,54 +0,0 @@
-#ifndef LIST_H
-#define LIST_H
-
-/*
- * Missing functions:
- * - version of listforeach() which allows passing arguments and
- *   which will return an argument
- */
-
-#ifndef LIST
-typedef struct List
-{
-    struct List *next;
-} LIST;
-#endif
-
-#ifndef LISTFUNC_DEFINED
-#define LISTFUNC_DEFINED
-typedef int (*cmpfunc) (const void *sample, const void *each);
-typedef void (*freefunc) (const void *elt);
-typedef void (*cpyfunc) (const void *dst, const void *src);
-typedef void (*actfunc) (const void *elt);
-#endif
-
-extern LIST *listitem(size_t size);
-extern LIST *listadd(LIST * head, LIST * elt, cmpfunc cmp);
-extern LIST *listaddnth(LIST * head, LIST * elt, int nth);
-extern LIST *listprep(LIST * head, LIST * elt);
-extern LIST *listapp(LIST * head, LIST * elt);
-extern LIST *listunlink(LIST * head, LIST * elt);
-extern LIST *listunlinknth(LIST * head, int nth);
-extern LIST *listdel(LIST * head, LIST * elt, freefunc func);
-extern LIST *listdelnth(LIST * head, int nth, freefunc func);
-extern int listcnt(LIST * head);
-extern LIST *listdup(LIST * head, cpyfunc cpy, size_t size);
-extern LIST *listsplit(LIST * head, LIST * elt);
-extern LIST *listsplitnth(LIST * head, int nth);
-extern LIST *listjoin(LIST * head, LIST * tail);
-extern LIST *listsort(LIST * head, cmpfunc cmp);
-extern LIST *listrev(LIST * head);
-extern LIST *listshuffle(LIST * head);
-extern LIST *listdelall(LIST * head, freefunc func);
-extern LIST **list2array(LIST * head);
-extern LIST *array2list(LIST ** array);
-extern void listforeach(LIST * head, actfunc action);
-extern int listidx(LIST * head, LIST * elt);
-extern LIST *listlast(LIST * head);
-extern LIST *listnth(LIST * head, int nth);
-extern LIST *listfind(LIST * head, LIST * elt, cmpfunc cmp);
-extern LIST *listfinddatum(LIST * head, void *datum, cmpfunc cmp);
-extern LIST *listbsearch(LIST * head, LIST * elt, cmpfunc cmp);
-extern LIST *listbsearchdatum(LIST * head, const void *data, cmpfunc cmp);
-
-#endif

+ 0 - 318
vector/v.mapcalc/map.c

@@ -1,318 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       v.mapcalc
- * AUTHOR(S):    Christoph Simon (original contributor)
- *               
- * PURPOSE:      
- * COPYRIGHT:    (C) 2002 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- *****************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "list.h"
-#include "mapcalc.h"
-#include "map.h"
-
-typedef MAP *(*m_func) (void);
-typedef MAP *(*m_func_m) (void *m0);
-typedef MAP *(*m_func_mm) (void *m0, void *m1);
-
-typedef struct Mapfunc
-{
-    char *name;
-    void *func;
-    char *proto;
-} MAPFUNC;
-
-static MAP *testmap(MAP * m);
-static MAP *test2map(MAP * m, MAP * n);
-static MAP *map_op_func_plus(MAP * m, MAP * n);
-static void find_maps(void);
-void init_map(void);
-void showmap(SYMBOL * map);
-void setmap(SYMBOL * var, SYMBOL * map);
-SYMBOL *mkmapvar(SYMBOL * var, SYMBOL * map);
-SYMBOL *mapfunc(SYMBOL * func, SYMBOL * arglist);
-SYMBOL *mapop(int op, SYMBOL * map1, SYMBOL * map2);
-
-static MAPFUNC mf[] = {
-    {"testmap", testmap, "m"},
-    {"test2map", test2map, "mm"},
-    {"map_op_func_+", map_op_func_plus, "mm"},
-    {NULL, NULL, NULL}
-};
-
-/*************************************************************************
- * This function represents a built-in map function.
- * Should probably go to another file
- */
-static MAP *testmap(MAP * m)
-{
-    char namebuf[128];
-
-    /*
-     * The map name always exists, as it represents data on disk, but
-     * might be a temporary name, when it should not be displayed
-     * (should it?).
-     */
-    G_message(_("Performing 1 arg map function on map %s"), m->name);
-    sprintf(namebuf, "t-%s", m->name);
-    m = (MAP *) listitem(sizeof(MAP));
-    m->name = strdup(namebuf);
-    return m;
-}
-
-static MAP *test2map(MAP * m, MAP * n)
-{
-    char namebuf[128];
-
-    G_message(_("Performing 2 arg map function on maps %s and %s"), m->name,
-	      n->name);
-    sprintf(namebuf, "%s.%s", m->name, n->name);
-    m = (MAP *) listitem(sizeof(MAP));
-    m->name = strdup(namebuf);
-    return m;
-}
-
-static MAP *map_op_func_plus(MAP * m, MAP * n)
-{
-    char namebuf[128];
-
-    G_message(_("Performing map %s + %s"), m->name, n->name);
-    sprintf(namebuf, "%s.%s", m->name, n->name);
-    m = (MAP *) listitem(sizeof(MAP));
-    m->name = strdup(namebuf);
-    return m;
-}
-
-/*
- * end of move to other file
- ***********************************************************************/
-
-static void find_maps(void)
-{
-    char *gisdbase, *location, *mapset;
-    char basepath[4096], subdirpath[4096], path[4096];
-    DIR *dir, *subdir;
-    struct dirent *ent, *subent;
-
-    gisdbase = getenv("GISDBASE");
-    if (!gisdbase)
-	gisdbase = ".";
-
-    location = getenv("LOCATION_NAME");
-    if (!location)
-	location = ".";
-
-    mapset = getenv("MAPSET");
-    if (!mapset)
-	mapset = ".";
-
-    /*
-     * Now, if I'm not in grass, I can simulate the existence of a vector
-     * map creating a directory vector with one subdirectory for each `map'
-     * having a file `head'
-     */
-
-    sprintf(basepath, "%s/%s/%s/vector", gisdbase, location, mapset);
-    dir = opendir(basepath);
-    if (!dir)
-	return;
-
-    while ((ent = readdir(dir)) != NULL) {
-	struct stat buf;
-
-	if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
-	    continue;
-
-	strcpy(path, basepath);
-	strcat(path, "/");
-	strcat(path, ent->d_name);
-
-	if (stat(path, &buf))
-	    continue;
-	if (S_ISDIR(buf.st_mode)) {
-	    strcpy(subdirpath, path);
-	    subdir = opendir(subdirpath);
-	    if (!subdir)
-		continue;
-	    while ((subent = readdir(subdir)) != NULL) {
-		if (!strcmp(subent->d_name, ".") ||
-		    !strcmp(subent->d_name, ".."))
-		    continue;
-		if (!strcmp(subent->d_name, "head")) {
-		    MAP *map;
-		    SYMBOL *sym;
-
-		    map = (MAP *) listitem(sizeof(MAP));
-		    map->name = strdup(ent->d_name);
-		    map->refcnt++;
-		    sym = putsym(map->name);
-		    sym->type = sym->itype = st_map;
-		    sym->v.p = map;
-		}
-	    }
-	    closedir(subdir);
-	}
-    }
-    closedir(dir);
-}
-
-void init_map(void)
-{
-    SYMBOL *sym;
-    int i;
-
-    for (i = 0; mf[i].name; i++) {
-	sym = putsym(mf[i].name);
-	sym->type = sym->itype = st_mfunc;
-	sym->v.p = mf[i].func;
-	sym->proto = mf[i].proto;
-	sym->rettype = st_map;
-    }
-
-    find_maps();
-}
-
-void printmap(SYMBOL * sym)
-{
-    MAP *map;
-
-    map = (MAP *) sym->v.p;
-    if (map->name)
-	fprintf(stdout, "\t%s\n", map->name);
-}
-
-void showmap(SYMBOL * sym)
-{
-    MAP *map;
-
-    map = (MAP *) sym->v.p;
-    printmap(sym);
-    if (--map->refcnt > 0)
-	sym->v.p = NULL;
-    freesym(sym);
-}
-
-MAP *freemap(MAP * map)
-{
-    if (map) {
-	if (map->refcnt > 0)
-	    return map;
-	if (map->name)
-	    G_free(map->name);
-	if (map->mapinfo)
-	    G_free(map->mapinfo);	/* call grass to handle map */
-	G_free(map);
-    }
-    return NULL;
-}
-
-void setmap(SYMBOL * var, SYMBOL * map)
-{
-    SYMBOL *sym;
-
-    if (var->name) {
-	sym = getsym(var->name);
-	if (sym) {
-	    sym->v.p = freemap(sym->v.p);
-	    sym->v.p = map->v.p;
-	}
-    }
-
-    freemap(var->v.p);
-    var->v.p = NULL;
-    freesym(var);
-
-    printmap(map);
-    map->v.p = NULL;
-    freesym(map);
-}
-
-SYMBOL *mkmapvar(SYMBOL * var, SYMBOL * map)
-{
-    var->type = var->itype = st_map;
-    var->name = var->v.p;
-    var->v.p = map->v.p;
-    map->v.p = NULL;
-    freesym(map);
-
-    symtab = (SYMBOL *) listadd((LIST *) symtab, (LIST *) var, cmpsymsym);
-
-    printmap(var);
-
-    return var;
-}
-
-SYMBOL *mapfunc(SYMBOL * func, SYMBOL * arglist)
-{
-    SYMBOL *sym;
-    MAP *res = NULL;
-    int argc = -1;
-
-    if (!func || !func->v.p || func->type != st_mfunc) {
-	parseerror = 1;
-	G_warning(_("Can't call bad map-function"));
-    }
-    else
-	argc = listcnt((LIST *) arglist);
-
-    if (argc == 0 && (!func->proto || !*func->proto))
-	res = (*(m_func) func->v.p) ();
-    else if (argc == 1 && !strcmp(func->proto, "m"))
-	res = (*(m_func_m) func->v.p) (arglist->v.p);
-    else if (argc == 2 && !strcmp(func->proto, "mm"))
-	res = (*(m_func_mm) func->v.p) (arglist->v.p, arglist->next->v.p);
-    else {
-	G_warning(_("Bad arguments to mapfunc %s (argc = %d)"), func->name,
-		  argc);
-	parseerror = 1;
-    }
-
-    listdelall((LIST *) func, freesym);
-    listdelall((LIST *) arglist, freesym);
-
-    sym = (SYMBOL *) listitem(sizeof(SYMBOL));
-    sym->type = st_map;
-    sym->v.p = res;
-
-    return sym;
-}
-
-SYMBOL *mapop(int op, SYMBOL * map1, SYMBOL * map2)
-{
-    SYMBOL *func, *arglist, *res = NULL;
-    char buf[32];
-
-    sprintf(buf, "map_op_func_%c", op);
-
-    func = getsym(buf);
-    if (!func) {
-	G_warning(_("No function defined to perform map %c map"), op);
-	parseerror = 1;
-    }
-    else {
-	res = (SYMBOL *) listitem(sizeof(SYMBOL));
-	symcpy(res, func);
-	res->next = NULL;
-	func = res;
-	arglist = (SYMBOL *) listapp(NULL, (LIST *) map1);
-	arglist = (SYMBOL *) listapp((LIST *) arglist, (LIST *) map2);
-
-	res = mapfunc(func, arglist);
-    }
-
-    /* free map1/map2 ?    only if they have no name? */
-
-    return res;
-}

+ 0 - 22
vector/v.mapcalc/map.h

@@ -1,22 +0,0 @@
-#ifndef MAP_H
-#define MAP_H
-
-typedef struct Map_info Map_info;
-
-
-typedef struct Map
-{
-    struct Map *next;
-    char *name;
-    Map_info *mapinfo;
-    int refcnt;
-} MAP;
-
-extern void init_map(void);
-extern void showmap(SYMBOL * map);
-extern void setmap(SYMBOL * var, SYMBOL * map);
-extern SYMBOL *mkmapvar(SYMBOL * var, SYMBOL * map);
-extern SYMBOL *mapfunc(SYMBOL * func, SYMBOL * arglist);
-extern SYMBOL *mapop(int op, SYMBOL * map1, SYMBOL * map2);
-
-#endif

+ 0 - 166
vector/v.mapcalc/mapcalc.c

@@ -1,166 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include "list.h"
-#include "mapcalc.h"
-#include "number.h"
-#include "map.h"
-#include "plugin.h"
-#include "vector.h"
-#include "any.h"
-
-extern int yyparse(void);	/* v.mapcalc.y */
-
-void freesym(const void *elt);
-SYMBOL *delsym(SYMBOL * head);
-int cmpsymname(const void *data, const void *elt);
-int cmpsymsym(const void *A, const void *B);
-void symcpy(const void *Dst, const void *Src);
-SYMBOL *getsym(const char *name);
-SYMBOL *putsym(const char *name);
-SYMBOL *argapp(SYMBOL * head, SYMBOL * arg);
-int main(int argc, char **argv);
-
-
-SYMBOL *symtab = NULL;
-int parseerror = 0;
-
-void freesym(const void *elt)
-{
-    SYMBOL *sym;
-
-    sym = (SYMBOL *) elt;
-
-    if (sym->name)
-	G_free(sym->name);
-    if (sym->proto)
-	G_free(sym->proto);
-
-    if (sym->itype == st_pnt) {
-	VECTOR *vec, *next;
-
-	for (vec = (VECTOR *) sym->v.p; vec;) {
-	    next = vec->next;
-	    if (--vec->refcnt < 1)
-		G_free(vec);
-	    vec = next;
-	}
-    }
-    else if (sym->itype == st_map) {
-	MAP *map, *next;
-
-	for (map = (MAP *) sym->v.p; map;) {
-	    next = map->next;
-	    if (--map->refcnt < 1)
-		G_free(map);	/* more needs to be done! */
-	    map = next;
-	}
-    }
-    else if (sym->itype == st_any) {
-	ANY *any, *next;
-
-	for (any = (ANY *) sym->v.p; any;) {
-	    next = any->next;
-	    if (--any->refcnt < 1)
-		G_free(any);
-	    any = next;
-	}
-    }
-    else if (sym->itype == st_str && sym->v.p)
-	G_free(sym->v.p);
-}
-
-SYMBOL *delsym(SYMBOL * head)
-{
-    return (SYMBOL *) listdelall((LIST *) head, freesym);
-}
-
-int cmpsymname(const void *data, const void *elt)
-{
-    SYMBOL *sym;
-    const char *name;
-
-    sym = (SYMBOL *) elt;
-    name = (const char *)data;
-
-    return strcmp(name, sym->name);
-}
-
-int cmpsymsym(const void *A, const void *B)
-{
-    SYMBOL *a, *b;
-
-    a = (SYMBOL *) A;
-    b = (SYMBOL *) B;
-
-    return strcmp(b->name, a->name);
-}
-
-void symcpy(const void *Dst, const void *Src)
-{
-    SYMBOL *dst, *src;
-
-    dst = (SYMBOL *) Dst;
-    src = (SYMBOL *) Src;
-
-    dst->type = src->type;
-    dst->itype = src->itype;
-    dst->rettype = src->rettype;
-    if (src->name)
-	dst->name = strdup(src->name);
-    if (src->proto)
-	dst->proto = strdup(src->proto);
-    if (src->itype == st_str && src->v.p)
-	dst->v.p = strdup(src->v.p);
-    else {
-	if (src->itype == st_pnt)
-	    ((VECTOR *) src->v.p)->refcnt++;
-	else if (src->itype == st_map)
-	    ((MAP *) src->v.p)->refcnt++;
-	else if (src->itype == st_any)
-	    ((ANY *) src->v.p)->refcnt++;
-	memcpy(&dst->v, &src->v, sizeof(src->v));
-    }
-}
-
-
-SYMBOL *getsym(const char *name)
-{
-    return (SYMBOL *) listbsearchdatum((LIST *) symtab, name, cmpsymname);
-}
-
-SYMBOL *putsym(const char *name)
-{
-    SYMBOL *sym;
-
-    sym = getsym(name);
-    if (sym) {
-	symtab = (SYMBOL *) listunlink((LIST *) symtab, (LIST *) sym);
-	freesym(sym);
-    }
-    else
-	sym = (SYMBOL *) listitem(sizeof(SYMBOL));
-
-    sym->name = strdup(name);
-    symtab = (SYMBOL *) listadd((LIST *) symtab, (LIST *) sym, cmpsymsym);
-
-    return sym;
-}
-
-SYMBOL *argapp(SYMBOL * head, SYMBOL * arg)
-{
-    return (SYMBOL *) listapp((LIST *) head, (LIST *) arg);
-}
-
-int main(int argc, char **argv)
-{
-    init_num();
-    init_map();
-    init_plug();
-    init_vec();
-    init_any();
-
-    yyparse();
-
-    exit(0);
-}

+ 0 - 46
vector/v.mapcalc/mapcalc.h

@@ -1,46 +0,0 @@
-#ifndef MAPCALC_H
-#define MAPCALC_H
-
-typedef enum Styp		/* Symbol Type */
-{
-    st_none = 0,
-    st_map,
-    st_any,
-    st_num,
-    st_str,
-    st_arg,
-    st_pnt,
-    st_nfunc,
-    st_mfunc,
-    st_pfunc,
-    st_afunc
-} STYP;
-
-typedef struct Symbol
-{
-    struct Symbol *next;
-    char *name;
-    STYP type;			/* type as seen by the parser */
-    STYP itype;			/* when type == st_any or st_arg */
-    union
-    {
-	double d;		/* nummeric value (always double) */
-	void *p;		/* pointer value */
-    } v;
-    char *proto;
-    STYP rettype;		/* if function, return type */
-} SYMBOL;
-
-extern int parseerror;
-extern SYMBOL *symtab;
-
-extern void freesym(const void *elt);
-extern SYMBOL *delsym(SYMBOL * head);
-extern int cmpsymsym(const void *A, const void *B);
-extern int cmpsymname(const void *data, const void *elt);
-extern void symcpy(const void *Dst, const void *Src);
-extern SYMBOL *getsym(const char *name);
-extern SYMBOL *putsym(const char *name);
-extern SYMBOL *argapp(SYMBOL * head, SYMBOL * arg);
-
-#endif

+ 0 - 245
vector/v.mapcalc/number.c

@@ -1,245 +0,0 @@
-#define _ISOC99_SOURCE		/* to get isfinite() */
-#define _BSD_SOURCE		/* to get __USE_MISC */
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "list.h"
-#include "mapcalc.h"
-
-typedef double (*d_func) (void);
-typedef double (*d_func_d) (double d);
-typedef double (*d_func_dd) (double d0, double d1);
-typedef double (*d_func_di) (double d, int i);
-typedef double (*d_func_dai) (double d, int *i);
-typedef double (*d_func_p) (void *p0);
-typedef double (*d_func_pp) (void *p0, void *p1);
-typedef double (*d_func_ppp) (void *p0, void *p1, void *p2);
-
-typedef struct Numfunc
-{
-    char *name;
-    void *func;
-    char *proto;
-} NUMFUNC;
-
-/*
- * Prototype Types:
- * - all return double or casted to double
- * "d"          (double d)
- * "dd"         (double d, double e)
- * "di"         (double d, int i)
- * "dai"        (double d, int *i)      [a == asterisk]
- *
- * For no argument say NULL or ""
- */
-
-static NUMFUNC nf[] = {
-    {"acos", acos, "d"},
-    {"asin", asin, "d"},
-    {"atan", atan, "d"},
-    {"atan2", atan2, "dd"},
-    {"cos", cos, "d"},
-    {"sin", sin, "d"},
-    {"tan", tan, "d"},
-    {"cosh", cosh, "d"},
-    {"sinh", sinh, "d"},
-    {"tanh", tanh, "d"},
-    {"acosh", acosh, "d"},
-    {"asinh", asinh, "d"},
-    {"atanh", atanh, "d"},
-    {"exp", exp, "d"},
-    {"frexp", frexp, "dai"},
-    {"ldexp", ldexp, "di"},
-    {"ln", log, "d"},
-    {"log10", log10, "d"},
-    {"modf", modf, "dai"},
-    {"pow", pow, "dd"},
-    {"sqrt", sqrt, "d"},
-    {"hypot", hypot, "dd"},
-    {"cbrt", cbrt, "d"},
-    {"ceil", ceil, "d"},
-    {"fabs", fabs, "d"},
-    {"floor", floor, "d"},
-    {"fmod", fmod, "dd"},
-    {"drem", drem, "dd"},
-    {"j0", j0, "d"},
-    {"j1", j1, "d"},
-    {"jn", jn, "dd"},
-    {"y0", y0, "d"},
-    {"y1", y1, "d"},
-    {"yn", yn, "dd"},
-    {"erf", erf, "d"},
-    {"erfc", erfc, "d"},
-    {"lgamma", lgamma, "d"},
-    {"rint", rint, "d"},
-    {NULL, NULL, NULL}
-};
-
-void init_num(void);
-void shownum(double d);
-void setnum(SYMBOL * var, double d);
-SYMBOL *mknumvar(SYMBOL * var, double d);
-double numfunc(SYMBOL * func, SYMBOL * arglist);
-double numop(int op, SYMBOL * opd1, SYMBOL * opd2);
-SYMBOL *mknum(double d);
-
-void init_num(void)
-{
-    SYMBOL *sym;
-    int i;
-
-    for (i = 0; nf[i].name; i++) {
-	sym = putsym(nf[i].name);
-	sym->type = sym->itype = st_nfunc;
-	sym->v.p = nf[i].func;
-	sym->proto = nf[i].proto;
-	sym->rettype = st_num;
-    }
-
-    /* add some handy constants */
-    sym = putsym("e");
-    sym->type = sym->itype = st_num;
-    sym->v.d = M_E;
-
-    sym = putsym("pi");
-    sym->type = sym->itype = st_num;
-    sym->v.d = M_PI;
-}
-
-void shownum(double d)
-{
-    if (!isfinite(d))
-	fprintf(stdout, "\t??.??\n");
-    else if (d == (int)d)
-	fprintf(stdout, "\t%d\n", (int)d);
-    else
-	fprintf(stdout, "\t%g\n", d);
-}
-
-void setnum(SYMBOL * var, double d)
-{
-    SYMBOL *sym;
-
-    var->v.d = d;
-    if (var->name) {
-	sym = getsym(var->name);
-	if (sym)
-	    sym->v.d = d;
-    }
-    shownum(d);
-    freesym(var);
-}
-
-SYMBOL *mknumvar(SYMBOL * var, double d)
-{
-    if (var) {
-	var->name = var->v.p;
-	var->type = var->itype = st_num;
-	var->v.d = d;
-	symtab = (SYMBOL *) listadd((LIST *) symtab, (LIST *) var, cmpsymsym);
-    }
-    else {
-	var = (SYMBOL *) listitem(sizeof(SYMBOL));
-	var->type = var->itype = st_num;
-	var->v.d = d;
-    }
-
-    shownum(d);
-
-    return var;
-}
-
-double numfunc(SYMBOL * func, SYMBOL * arglist)
-{
-    double res = 0.0;
-    int argc = -1;
-
-    if (!func || !func->v.p || func->type != st_nfunc) {
-	parseerror = 1;
-	G_warning(_("Can't call bad num-function"));
-    }
-    else
-	argc = listcnt((LIST *) arglist);
-
-    if (argc == 0 && (!func->proto || !*func->proto))
-	res = (*(d_func) func->v.p) ();
-    else if (argc == 1 && !strcmp(func->proto, "d"))
-	res = (*(d_func_d) func->v.p) (arglist->v.d);
-    else if (argc == 2 && !strcmp(func->proto, "dd"))
-	res = (*(d_func_dd) func->v.p) (arglist->v.d, arglist->next->v.d);
-    else if (argc == 2 && !strcmp(func->proto, "di"))
-	res = (*(d_func_di) func->v.p) (arglist->v.d,
-					(int)arglist->next->v.d);
-    else if (argc == 3 && !strcmp(func->proto, "dai")) {
-	int iptr;
-
-	iptr = (int)arglist->next->v.d;
-	res = (*(d_func_dai) func->v.p) (arglist->v.d, &iptr);
-	arglist->next->v.d = (double)iptr;
-    }
-    else if (argc == 1 && !strcmp(func->proto, "p"))
-	res = (*(d_func_p) func->v.p) (arglist->v.p);
-    else if (argc == 2 && !strcmp(func->proto, "pp"))
-	res = (*(d_func_pp) func->v.p) (arglist->v.p, arglist->next->v.p);
-    else if (argc == 3 && !strcmp(func->proto, "ppp"))
-	res = (*(d_func_ppp) func->v.p) (arglist->v.p,
-					 arglist->next->v.p,
-					 arglist->next->next->v.p);
-    else {
-	G_warning(_("Bad arguments to numfunc %s"), func->name);
-	parseerror = 1;
-    }
-
-    listdelall((LIST *) func, freesym);
-    listdelall((LIST *) arglist, freesym);
-
-    return res;
-}
-
-double numop(int op, SYMBOL * opd1, SYMBOL * opd2)
-{
-    SYMBOL *func, *arglist, *f;
-    char buf[32];
-    double res = 0.0;
-
-    if (opd1->itype == st_num)
-	sprintf(buf, "num_op_func_%c", op);
-    else if (opd1->itype == st_pnt)
-	sprintf(buf, "pnt_op_func_%c", op);
-
-    func = getsym(buf);
-    if (!func) {
-	if (opd1->itype == st_num)
-	    G_warning(_("No function defined to perform ``number %c number''"),
-		      op);
-	else if (opd1->itype == st_pnt)
-	    G_warning(_("No function defined to perform ``point %c point''"),
-		      op);
-	parseerror = 1;
-    }
-    else {
-	f = (SYMBOL *) listitem(sizeof(SYMBOL));
-	symcpy(f, func);
-	f->next = NULL;
-	func = f;
-	arglist = (SYMBOL *) listapp(NULL, (LIST *) opd1);
-	arglist = (SYMBOL *) listapp((LIST *) arglist, (LIST *) opd2);
-
-	res = numfunc(func, arglist);
-    }
-
-    return res;
-}
-
-SYMBOL *mknum(double d)
-{
-    SYMBOL *num;
-
-    num = (SYMBOL *) listitem(sizeof(SYMBOL));
-    num->type = num->itype = st_num;
-    num->v.d = d;
-
-    return num;
-}

+ 0 - 12
vector/v.mapcalc/number.h

@@ -1,12 +0,0 @@
-#ifndef NUMBER_H
-#define NUMBER_H
-
-extern void init_num(void);
-extern void shownum(double d);
-extern void setnum(SYMBOL * var, double d);
-extern SYMBOL *mknumvar(SYMBOL * var, double d);
-extern double numfunc(SYMBOL * func, SYMBOL * arglist);
-extern double numop(int op, SYMBOL * opd1, SYMBOL * opd2);
-extern SYMBOL *mknum(double d);
-
-#endif

+ 0 - 124
vector/v.mapcalc/plugin.c

@@ -1,124 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <dirent.h>
-#include <dlfcn.h>
-#include "list.h"
-#include "mapcalc.h"
-
-typedef char *(*func_t) (void);
-
-static int register_function(char *fname, void *func, char *proto);
-void init_plug(void);
-
-static int register_function(char *fname, void *func, char *proto)
-{
-    STYP type;
-    SYMBOL *sym;
-
-    sym = getsym(fname);
-    if (sym)
-	symtab = (SYMBOL *) listdel((LIST *) symtab, (LIST *) sym, freesym);
-
-    /*
-     * This is quite incomplete
-     */
-
-    switch (proto[0]) {
-    case 'd':
-	type = st_nfunc;
-	break;
-    case 'm':
-	type = st_mfunc;
-	break;
-    case 'p':
-	type = st_pfunc;
-	break;
-    default:
-	return 0;
-    }
-
-    sym = putsym(fname);
-    sym->v.p = func;
-    sym->type = sym->itype = sym->rettype = type;
-    sym->proto = strdup(proto + 2);	/* skip "m=" */
-
-    return 1;
-}
-
-void init_plug(void)
-{
-    SYMBOL *sym;
-    char path[4096], pathname[4096], *ptr, *fname, *proto;
-    struct dirent *ent;
-    void *handle, *func;
-    func_t fh, ph;
-    DIR *dir;
-
-    /*
-     * Search algorithm:
-     * 1. Find "pluginpath" in symbol table. If not found...
-     * 2. Find "$GISBASE/plugins". If not defined
-     * 3. Use "./plugins"
-     */
-
-    sym = getsym("pluginpath");
-    if (sym && sym->v.p)
-	strcpy(path, sym->v.p);
-    else {
-	ptr = getenv("GISBASE");
-	if (ptr)
-	    strcpy(path, ptr);
-	else
-	    strcpy(path, getcwd(path, 4096));
-	if (path[strlen(path) - 1] != '/')
-	    strcat(path, "/");
-	strcat(path, "plugins");
-    }
-
-    dir = opendir(path);
-    if (!dir)
-	return;
-
-    while ((ent = readdir(dir)) != NULL) {
-	if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
-	    continue;
-	strcpy(pathname, path);
-	strcat(pathname, "/");
-	strcat(pathname, ent->d_name);
-	if (access(pathname, R_OK | X_OK))
-	    continue;
-	handle = dlopen(pathname, RTLD_LAZY);
-	if (!handle)
-	    continue;
-	fh = dlsym(handle, "fname");
-	if (dlerror()) {
-	    dlclose(handle);
-	    continue;
-	}
-	fname = (*fh) ();
-	if (!fname) {
-	    dlclose(handle);
-	    continue;
-	}
-	ph = dlsym(handle, "proto");
-	if (dlerror()) {
-	    dlclose(handle);
-	    continue;
-	}
-	proto = (*ph) ();
-	if (!proto) {
-	    dlclose(handle);
-	    continue;
-	}
-	func = dlsym(handle, fname);
-	if (!func) {
-	    dlclose(handle);
-	    continue;
-	}
-	if (!register_function(fname, func, proto))
-	    dlclose(handle);
-    }
-    closedir(dir);
-}

+ 0 - 6
vector/v.mapcalc/plugin.h

@@ -1,6 +0,0 @@
-#ifndef MODULE_H
-#define MODULE_H
-
-extern void init_plug(void);
-
-#endif

+ 0 - 14
vector/v.mapcalc/plugins/Makefile

@@ -1,14 +0,0 @@
-CC = gcc
-CFLAGS = -g -Wall -Werror
-LDFLAGS = -shared
-
-all: testmod
-
-testmod: testmod.o
-	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
-
-testmod.o: testmod.c
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-clean:
-	rm -f *~ .*~ *.o testmod

+ 0 - 46
vector/v.mapcalc/plugins/testmod.c

@@ -1,46 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "../list.h"
-#include "../mapcalc.h"
-#include "../map.h"
-
-
-/*
- * Required function:
- * Return the name of the main function which is useable in v.mapcalc.
- */
-char *fname(void)
-{
-    return "dltest";
-}
-
-/*
- * Required function:
- * Return the prototype of the main function. Generally, it's the initial
- * letter of the C-type, plus "m" for (MAP *) and "p" for (POINT *).
- * Indirection doesn't fully work, but to return a pointer to one of the
- * above types, the letter "a" is used ("ai" means an integer pointer).
- *
- * Each prototype needs to be represented by one of the typedef and switch
- * cases in func.c of mapcalc.
- */
-char *proto(void)
-{
-    return "m=mm";
-}
-
-/*
- * This is the main function which needs to have the name and prototype
- * as returned above.
- */
-MAP *dltest(MAP * m, MAP * n)
-{
-    char namebuf[128];
-
-    printf("Performing 2 arg dynamically loaded map function on maps "
-	   "%s and %s\n", m->name, n->name);
-    sprintf(namebuf, "%s.%s", m->name, n->name);
-    m = (MAP *) listitem(sizeof(MAP));
-    m->name = strdup(namebuf);
-    return m;
-}

+ 0 - 268
vector/v.mapcalc/v.mapcalc.html

@@ -1,268 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.in.mapcalc</em> is a vector calculator program inspired by r.mapcalc.
-
-<h2>NOTES</h2>
-
-It's much more complicated to deal with vector maps than with raster
-maps. Particularly, there are several levels on which we might want to
-deal with a vector map. For this reason the design of v.mapcalc is
-that of a skeleton with plugins: A parser will interpret statements
-and call the appropriate functions it finds in dynamically loaded
-plugins.
-<p>
-The syntax should be able to deal with four different types:
-
-        - numbers
-        - points
-        - point lists
-        - maps
-<p>
-Numeric expressions should do what everybody would expect. There are
-some dozens of built in functions from the math library. Points and
-point lists are meant in the mathematical sense: A point is a set of
-two or three numbers, representing the coordinate. All points have
-three components, but the third, if missing has the value of
-0.0/0.0 (NaN). An expression will yield a 3D result if all arguments a
-3D. There is a set of basic built in operations like dot and cross
-product. Point lists are meant for polygons, lines, areas, etc. Points
-and point lists have no categories or attributes. And finally, of
-course, v.mapcalc deals with map expressions.
-<p>
-For numbers, the infix operators do the obvious. For other types, the
-parser will translate them to function calls with predefined
-names. Some samples are set and can be replaced by something useful.
-<p>
-The plugins are designed to be as simple as possible. There is one
-example which actually doesn't do anything but shows how it can be
-called. Such a plugin needs three global functions: One which can be
-called to find out the name the user must type to use the function,
-one which returns a string denoting the return type and the type and
-number of arguments, and finally the function itself.
-<p>
-There are two more types which are somewhat special: One is type
-`argument' which can be any of the basic types. The parser will accept
-anything to be the argument to a function call, but the mechanism to
-actually call that function will check if the types match the
-prototype. The second special type `any' is sort of a backdoor: If
-something new comes up, it can be treated as type any, and it will be
-responsibility of the plugin to verify that it's the correct type. One
-case where the any-type can be useful is for SQL statement-pieces or
-other constructs when dealing with attributes, which can be literally
-of "any" type.
-<p>
-There is one problem with this approach within v.mapcalc, which is
-calling a function with a variable list of arguments. This is a bit
-complicated, and before thinking of easy solutions, I need to
-recommend reading the code. Just before calling it, v.mapcalc has a
-pointer to that functions and a linked list of structures which hold
-the argument types and values. It would be nice to be able to
-construct such a call argument by argument, but there is no portable
-way to do so: First assembly would be needed, and second, the way a
-stack frame is built for a particular compiler/architecture can vary.
-The solution is to maintain a list of typedef'd prototypes and call
-them in a switch. This means, if someone needs a new function and
-writes a plugin, either he finds a typedef which matches this
-prototype, or he needs to add the typedef and a case in the switch.
-<p>
-It makes only limited sense to mix arguments of different types: three
-at the power of map-A doesn't seem to be useful. So, the basic
-strategy is accept expressions only of the same type, while mixing
-types is always possible within the arguments to a function call.
-<p>
-There is a file listing some example expressions. I hope that it is
-what one could expect. Adding a few plugins should allow for very
-complex expressions and operations.
-
-
-<h2>EXAMPLES</h2>
-
-This is an empty statement, which is legal
-<div class="code"><pre>
-         ;
-</pre></div>
-
-<p>
-Some built in constants:
-<div class="code"><pre>
-         12;
-         e;
-         pi;
-         pnt_o;
-         pnt_i;
-         pnt_j;
-         pnt_k;
-         rivers;
-</pre></div>
-
-<p>
-The last one isn't really a constant, as it depends on what if found
-at startup, but it behaves just the like.
-<div class="code"><pre>
-         a;
-</pre></div>
-
-<p>
-This gives an error. "a", which is (not yet) defined, is handled as a
-string. There is no operation associated, so this gives a parse error.
-<p>
-Next some simple assignments. Also here, the name of the variable is
-initially not more than a string, but after performing the assignment,
-they take the type of the expressionL:
-<div class="code"><pre>
-         num = 10.3;
-         pnt = (0,0);
-         map = rivers;
-         any = mkstring (hallo);
-</pre></div>
-
-<p>
-The last is only a backdoor for cases when exceptional things are
-needed. The function mkstring is a sample implementation of type
-ANY. For now, only one word could be passed, but when flex is being
-used a quoted string might contain just anything.
-<p>
-Next, I overwrite these variables. This is somewhat tricky. If you say
-"map = rivers", what should happen? In theory, we should actually
-duplicate this map, which could imply gigabytes on disk. This is not
-done, but if the map is changed, it must not change the former
-`value'. I hope it's doing now, what everybody would expect (including
-to free eventually the allocated memory).
-<div class="code"><pre>
-         num = 3.1;
-         pnt = (1,1);
-         map = cities;
-         any = mkstring (hello);
-</pre></div>
-
-<p>
-The pure numeric operations aren't new, beside that I'm trying to
-catch illegal operations:
-<div class="code"><pre>
-         sqrt(e);
-         num = cos (pi/4);
-         num = -num + 3 * num - sqrt (num^2);
-         3.3 + 4.4;
-         2.2 - 1.1;
-         5 * 7;
-         21 / 0;
-         21 / 2;
-         -21 / 7;
-         -6.6 ^ 1.2;
-         6.6 ^ 1.2;
-         12.5 % 3.6;
-         2 * (3.1 + 0.9);
-</pre></div>
-
-<p>
-Next are points. Note that 2D and 3D are dealt with identically; in
-case of 2D, the z-value is 0.0/0.0 (NaN, "Not a Number"). This should
-be pretty portable. Generally, if at least one point is 2D, the result
-of a point operation will be 2D even if 3D points are involved too,
-ignoring the third dimension. I've defined some infix operations a bit
-arbitrarily. Of course, this could be changed. The double () in case
-of a single function argument are surely ugly, but not avoidable.
-<div class="code"><pre>
-         origin2d = (0,0);
-         p1 = (1,1);
-         p2 = p1;
-         p2 = v_copy (p1);
-         v_add ((1,0), (0,1));
-         (1,0) + (0,1);
-         v_sub ((1,1), (0,1));
-         (1,1) - (0,1);
-         v_abs ((-2, -1));
-         v_neg ((2, 1));
-         -(2,1);
-         v_mul ((2,4), 3.3);
-         (2,4) * 3.3;
-         3.3 * (2,4);
-         v_div ((6.6, 13.2), 3.3);
-         (6.6, 13.2) / 3.3;
-         v_unit ((12, 8));
-         v_cross ((1,2), (4,5));
-         v_cross ((1,2,3), (4,5,6));
-         (1,2,3) ^ (4,5,6);
-         v_val ((3,3));
-         v_dot ((1,2), (3,4));
-         (1,2) % (3,4);
-         v_dot ((1,2,3), (4,5,6));
-         (1,2,3) % (4,5,6);
-         v_area ((1,2,3), (4,5,6));
-         v_eq ((1,2), (1, 2));
-         v_eq ((1,2), (1.0001, 2.0001));
-         epsilon = (1e-3, 1e-3);
-         v_eq_epsilon ((1,2), (1.0001, 2.0001), epsilon);
-         v_isortho ((0,1), (1,0));
-         v_ispara ((0, 1), (0, -1));
-         v_isacute ((0, 1), (0, 0.5));
-         3 * (pnt + (2,2));
-</pre></div>
-
-<p>
-This is planned, but doesn't work yet:
-<div class="code"><pre>
-         line = ((1,1), (2,1));
-         triangle = (line, (1.5, 2));
-</pre></div>
-
-<p>
-And finally the map operations, which also aren't new, beside some
-internal details (freeing memory, not duplicating, etc.). I think that
-there is no map-operation which makes sense if it is not assigned to a
-variable. So all map expressions need to follow a variable and an
-equal sign. The very first expression, hence, will give an error:
-<div class="code"><pre>
-         rivers + cities;
-         map = rivers;
-         map;
-         map = rivers + cities;
-         map = testmap (rivers);
-         map = test2map (rivers, cities);
-         map = dltest (rivers, cities);
-</pre></div>
-
-
-<h2>TODO</h2>
-
-- The lexical scanner. At this point, there is a very simple and
-  limited scanner. My plan was to provide 4 methods of input:
-  + from the command line
-  + from stdin, interactively, using GNU readline and history
-  + from stdin by IO redirection like in "script | v.mapcalc"
-  + from a file, like in "v.mapcalc -i statementfile"
-  Of course, this should be done with Flex, with the input selection
-  as needed for all methods, as well as support for Bison to indicate
-  the position of a parse error.
-- There should be several built in commands allowing to:
-  + include a file with statements
-  + document the meaning of a variable or function
-  + attaching documentation to a variable or function
-  + saving certain things in a readable script like documentation or
-    constant values.
-  + a command to terminate the program (right now, only with Ctrl-D)
-- There is not yet any support for loops and conditionals. These do
-  not seem to be of much use with maps, but can prove powerful on
-  points and point lists.
-- There are certain operations which need to be performed always, like
-  opening a map. For now, they need to be done in the plugin, but
-  should definitively move to v.mapcalc.
-- Point lists are not working yet, though much of the basic
-  infrastructure is already done.
-- There seems to be a bug in memory management which can cause the
-  program to crash. Probably there are many more than that.
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-  <a href="r.mapcalc.html">r.mapcalc</a>
-</em>
-
-
-<h2>AUTHOR</h2>
-
-Christoph Simon &lt;ciccio at kiosknet com.br&gt;
-
-<p>
-<i>Last changed: $Date$</i>

+ 0 - 136
vector/v.mapcalc/v.mapcalc.y

@@ -1,136 +0,0 @@
-%{
-#define _ISOC99_SOURCE			/* isfinite() */
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#if 0
-#include "list.h"
-#endif
-#include "mapcalc.h"
-#include "yylex.h"
-#include "number.h"
-#include "vector.h"
-#include "map.h"
-#include "any.h"
-
-/* should print message */
-#define ERR		if (parseerror) { yyerror ("\tfunction error\n"); YYERROR; }
-#define NOTZERO(a)	if (!isfinite(a) || a == 0.0) { printf ("\tdivision by zero\n"); YYERROR; }
-#define NOTFRAC(a,b)	if (a < 0.0 && b != (int)b) { printf ("\toperation doesn't yield real number\n"); YYERROR; }
-
-%}
-
-%union
-{
-  double dbl;
-  SYMBOL *ptr;
-}
-
-%token <dbl> NUM
-%token <ptr> STRING
-%token <ptr> NUMVAR PNTVAR MAPVAR ANYVAR
-%token <ptr> NUMFUNC PNTFUNC MAPFUNC ANYFUNC
-%type  <dbl> numexp
-%type  <ptr> pntexp mapexp anyexp
-%type  <ptr> point pntlst _pntlst
-%type  <ptr> arg arglst
-
-%right '='
-%left  '-' '+'
-%left  '*' '/' '%'
-%right '^'
-%left  NEG
-
-%%
-
-input:    /* empty */
-	| input stmt
-	;
-
-stmt:     ';'
-	| numexp ';'			{ shownum ($1); }
-	| pntexp ';'			{ showvec ($1); }
-	| MAPVAR ';'			{ showmap ($1); }
-	| NUMVAR '=' numexp ';'		{ setnum ($1, $3); }
-	| PNTVAR '=' pntexp ';'		{ setpnt ($1, $3); }
-	| MAPVAR '=' mapexp ';'		{ setmap ($1, $3); }
-	| ANYVAR '=' anyexp ';'		{ setany ($1, $3); }
-	| STRING '=' numexp ';'		{ mknumvar ($1, $3); }
-	| STRING '=' pntexp ';'		{ mkpntvar ($1, $3); }
-	| STRING '=' mapexp ';'		{ mkmapvar ($1, $3); }
-	| STRING '=' anyexp ';'		{ mkanyvar ($1, $3); }
-	| error ';'			{ parseerror = 0; }
-	;
-
-numexp:	  NUM				{ $$ = $1; }
-	| NUMVAR			{ $$ = $1->v.d; delsym ($1); }
-	| NUMFUNC '(' arglst ')'	{ $$ = numfunc ($1, $3); ERR; }
-	| numexp '+' numexp		{ $$ = $1 + $3; }
-	| numexp '-' numexp		{ $$ = $1 - $3; }
-	| numexp '*' numexp		{ $$ = $1 * $3; }
-	| numexp '/' numexp		{ NOTZERO ($3); $$ = $1 / $3; }
-	| '-' numexp %prec NEG		{ $$ = -$2; }
-	| numexp '^' numexp		{ NOTFRAC ($1, $3); $$ = pow ($1, $3); }
-	| numexp '%' numexp		{ NOTZERO ($3); $$ = fmod ($1, $3); }
-	| pntexp '%' pntexp		{ $$ = numop ('%', $1, $3); ERR; }
-	| '(' numexp ')'		{ $$ = $2; }
-	;
-
-pntexp:   PNTVAR			{ $$ = $1; }
-	| point				{ $$ = $1; }
-	| pntlst			{ $$ = $1; }
-	| PNTFUNC '(' arglst ')'	{ $$ = pntfunc ($1, $3); ERR; }
-	| pntexp '+' pntexp		{ $$ = pntop ('+', $1, $3); ERR; }
-	| pntexp '-' pntexp		{ $$ = pntop ('-', $1, $3); ERR; }
-	| pntexp '*' numexp		{ $$ = pntop ('*', $1, mknum($3)); ERR;}
-	| numexp '*' pntexp		{ $$ = pntop ('*', $3, mknum($1)); ERR;}
-	| pntexp '/' numexp		{ $$ = pntop ('/', $1, mknum($3)); ERR;}
-	| '-' pntexp %prec NEG		{ $$ = pntop ('_', $2, NULL); ERR; }
-	| pntexp '^' pntexp		{ $$ = pntop ('^', $1, $3); ERR; }
-	| '(' pntexp ')'		{ $$ = $2; }
-	;
-
-point:	  '(' numexp ',' numexp ')'	{ $$ = mkpnt ($2, $4, nanval); ERR; }
-	| '(' numexp ',' numexp ',' numexp ')' { $$ = mkpnt ($2, $4, $6); ERR; }
-	;
-
-pntlst:   '(' _pntlst ')'		{ $$ = $2; }
-	;
-
-_pntlst:  pntexp ',' pntexp		{ $$ = $1; }
-	| _pntlst ',' pntexp		{ $$ = pntapp ($1, $3); }
-	;
-
-mapexp:   MAPVAR			{ $$ = $1; }
-	| MAPFUNC '(' arglst ')'	{ $$ = mapfunc ($1, $3); ERR; }
-	| mapexp '+' mapexp		{ $$ = mapop ('+', $1, $3); ERR; }
-	| mapexp '-' mapexp		{ $$ = mapop ('-', $1, $3); ERR; }
-	| mapexp '*' mapexp		{ $$ = mapop ('*', $1, $3); ERR; }
-	| mapexp '/' mapexp		{ $$ = mapop ('/', $1, $3); ERR; }
-	| '-' mapexp %prec NEG		{ $$ = mapop ('_', $2, NULL); ERR; }
-	| mapexp '^' mapexp		{ $$ = mapop ('^', $1, $3); ERR; }
-	| mapexp '%' mapexp		{ $$ = mapop ('%', $1, $3); ERR; }
-	| '(' mapexp ')'		{ $$ = $2; }
-	;
-
-anyexp:   ANYVAR			{ $$ = $1; }
-	| ANYFUNC '(' arglst ')'	{ $$ = anyfunc ($1, $3); ERR; }
-	;
-
-arglst:  /* empty */			{ $$ = NULL; }
-	| arg				{ $$ = $1; }
-	| arglst ',' arg		{ $$ = argapp ($1, $3); }
-	;
-
-/*
- * The member itype continues the same. After using the argument list,
- * the function must either free the argument if it's not in symtab,
- * or reset type to what is in itype.
- */
-
-arg:	  STRING			{ $$ = $1; $$->type = st_arg; }
-	| numexp			{ $$ = mknum ($1); }
-	| pntexp			{ $$ = $1; $$->type = st_arg; }
-	| mapexp			{ $$ = $1; $$->type = st_arg; }
-	| anyexp			{ $$ = $1; $$->type = st_arg; }
-	;

+ 0 - 604
vector/v.mapcalc/vector.c

@@ -1,604 +0,0 @@
-#define _ISOC99_SOURCE		/* to get isfinite() */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "list.h"
-#include "mapcalc.h"
-#include "vector.h"
-
-typedef struct Vecfunc
-{
-    char *name;
-    void *func;
-    char *proto;
-} VECFUNC;
-
-static VECFUNC vf[] = {
-    {"v_copy", v_copy, "p=rp"},
-    {"v_add", v_add, "p=rpp"},
-    {"pnt_op_func_+", v_add, "p=rpp"},
-    {"v_sub", v_sub, "p=rpp"},
-    {"pnt_op_func_-", v_sub, "p=rpp"},
-    {"v_abs", v_abs, "p=rp"},
-    {"v_neg", v_neg, "p=rp"},
-    {"pnt_op_func__", v_neg, "p=rp"},
-    {"v_mul", v_mul, "p=rpd"},
-    {"pnt_op_func_*", v_mul, "p=rpd"},
-    {"v_div", v_div, "p=rpd"},
-    {"pnt_op_func_/", v_div, "p=rpd"},
-    {"v_unit", v_unit, "p=rp"},
-    {"v_cross", v_cross, "p=rpp"},
-    {"pnt_op_func_^", v_cross, "p=rpp"},
-    {"v_val", v_val, "d=p"},
-    {"v_dot", v_dot, "d=pp"},
-    {"pnt_op_func_%", v_dot, "d=pp"},
-    {"v_area", v_area, "d=pp"},
-    {"v_eq", v_eq, "d=pp"},
-    {"v_eq_epsilon", v_eq_epsilon, "d=ppp"},
-    {"v_isortho", v_isortho, "d=pp"},
-    {"v_ispara", v_ispara, "d=pp"},
-    {"v_isacute", v_isacute, "d=pp"},
-    {NULL, NULL, NULL}
-};
-
-typedef VECTOR *(*p_func) (void);
-typedef VECTOR *(*p_func_p) (void *p0);
-typedef VECTOR *(*p_func_pp) (void *p0, void *p1);
-typedef VECTOR *(*p_func_ppp) (void *p0, void *p1, void *p2);
-typedef VECTOR *(*p_func_ppd) (void *p0, void *p1, double d);
-
-double nanval;
-static VECTOR pnt_o = { NULL, 0, 0, 0, 1 };
-static VECTOR pnt_i = { NULL, 1, 0, 0, 1 };
-static VECTOR pnt_j = { NULL, 0, 1, 0, 1 };
-static VECTOR pnt_k = { NULL, 0, 0, 1, 1 };
-
-void init_vec(void);
-void printvec(SYMBOL * sym);
-void showvec(SYMBOL * sym);
-void setpnt(SYMBOL * var, SYMBOL * pnt);
-SYMBOL *mkpnt(double x, double y, double z);
-SYMBOL *mkpntvar(SYMBOL * var, SYMBOL * pnt);
-SYMBOL *pntfunc(SYMBOL * func, SYMBOL * arglist);
-SYMBOL *pntop(int op, SYMBOL * pnt1, SYMBOL * pnt2);
-SYMBOL *pntapp(SYMBOL * head, SYMBOL * elt);
-VECTOR *v_copy(VECTOR * p, VECTOR * p1);
-VECTOR *v_add(VECTOR * p, VECTOR * p1, VECTOR * p2);
-VECTOR *v_sub(VECTOR * p, VECTOR * p1, VECTOR * p2);
-VECTOR *v_abs(VECTOR * p, VECTOR * p1);
-VECTOR *v_neg(VECTOR * p, VECTOR * p1);
-static inline int _is_zero(double r);
-double v_eq(VECTOR * p1, VECTOR * p2);
-double v_eq_epsilon(VECTOR * p1, VECTOR * p2, VECTOR * e);
-VECTOR *v_mul(VECTOR * p, VECTOR * p1, double d);
-VECTOR *v_div(VECTOR * p, VECTOR * p1, double d);
-double v_val(VECTOR * p);
-VECTOR *v_unit(VECTOR * p, VECTOR * p1);
-double v_dot(VECTOR * p1, VECTOR * p2);
-VECTOR *v_cross(VECTOR * p, VECTOR * p1, VECTOR * p2);
-double v_isortho(VECTOR * p1, VECTOR * p2);
-double v_ispara(VECTOR * p1, VECTOR * p2);
-double v_isacute(VECTOR * p1, VECTOR * p2);
-double v_area(VECTOR * p1, VECTOR * p2);
-
-
-void init_vec(void)
-{
-    SYMBOL *sym;
-    int i;
-
-    for (i = 0; vf[i].name; i++) {
-	sym = putsym(vf[i].name);
-	switch (vf[i].proto[0]) {
-	case 'p':
-	    sym->type = st_pfunc;
-	    sym->rettype = st_pnt;
-	    break;
-	case 'd':
-	    sym->type = st_nfunc;
-	    sym->rettype = st_num;
-	    break;
-	}
-	sym->itype = sym->type;
-	sym->v.p = vf[i].func;
-	sym->proto = vf[i].proto + 2;
-    }
-
-    /* add some handy constants */
-    sym = putsym("pnt_o");
-    sym->type = sym->itype = st_pnt;
-    sym->v.p = &pnt_o;
-
-    sym = putsym("pnt_i");
-    sym->type = sym->itype = st_pnt;
-    sym->v.p = &pnt_i;
-
-    sym = putsym("pnt_j");
-    sym->type = sym->itype = st_pnt;
-    sym->v.p = &pnt_j;
-
-    sym = putsym("pnt_k");
-    sym->type = sym->itype = st_pnt;
-    sym->v.p = &pnt_k;
-
-    /* initialize NaN */
-    nanval = 0.0 / 0.0;
-}
-
-void printvec(SYMBOL * sym)
-{
-    VECTOR *v;
-
-    v = (VECTOR *) sym->v.p;
-
-    fprintf(stdout, "\t(");
-    if (!isfinite(v->x))
-	fprintf(stdout, "??.??");
-    else if (v->x == (int)v->x)
-	fprintf(stdout, "%d", (int)v->x);
-    else
-	fprintf(stdout, "%g", v->x);
-    fprintf(stdout, ", ");
-    if (!isfinite(v->y))
-	fprintf(stdout, "??.??");
-    else if (v->y == (int)v->y)
-	fprintf(stdout, "%d", (int)v->y);
-    else
-	fprintf(stdout, "%g", v->y);
-    if (isfinite(v->z)) {
-	fprintf(stdout, ", ");
-	if (v->z == (int)v->z)
-	    fprintf(stdout, "%d", (int)v->z);
-	else
-	    fprintf(stdout, "%g", v->z);
-    }
-    fprintf(stdout, ")\n");
-}
-
-void showvec(SYMBOL * sym)
-{
-
-    VECTOR *v;
-
-    v = (VECTOR *) sym->v.p;
-    printvec(sym);
-
-    if (v && --v->refcnt > 0)
-	sym->v.p = NULL;
-    freesym(sym);
-}
-
-void setpnt(SYMBOL * var, SYMBOL * pnt)
-{
-    SYMBOL *sym;
-
-    if (var->name) {
-	sym = getsym(var->name);
-	if (sym) {
-	    if (--((VECTOR *) sym->v.p)->refcnt < 1)
-		G_free(sym->v.p);
-	    /*
-	     * If refcnt(pnt) == 1, this was anonymous, else it's used
-	     * somewhere else. Must we dup then?
-	     */
-	    sym->v.p = pnt->v.p;
-	}
-    }
-
-    if (--((VECTOR *) var->v.p)->refcnt < 1)
-	G_free(var->v.p);
-    var->v.p = NULL;
-    freesym(var);
-
-    printvec(pnt);
-    pnt->v.p = NULL;
-    freesym(pnt);
-}
-
-SYMBOL *mkpnt(double x, double y, double z)
-{
-    SYMBOL *pnt;
-    VECTOR *vec;
-
-    vec = (VECTOR *) listitem(sizeof(VECTOR));
-    vec->x = x;
-    vec->y = y;
-    vec->z = z;
-    vec->refcnt = 1;
-
-    pnt = (SYMBOL *) listitem(sizeof(SYMBOL));
-    pnt->type = pnt->itype = st_pnt;
-    pnt->v.p = vec;
-
-    return pnt;
-}
-
-SYMBOL *mkpntvar(SYMBOL * var, SYMBOL * pnt)
-{
-    var->type = var->itype = st_pnt;
-    var->name = var->v.p;
-    var->v.p = pnt->v.p;
-    pnt->v.p = NULL;
-    freesym(pnt);
-
-    symtab = (SYMBOL *) listadd((LIST *) symtab, (LIST *) var, cmpsymsym);
-
-    printvec(var);
-
-    return var;
-}
-
-SYMBOL *pntfunc(SYMBOL * func, SYMBOL * arglist)
-{
-    SYMBOL *sym, *sptr;
-    VECTOR *res = NULL;
-    int argc = -1, i;
-
-    sym = (SYMBOL *) listitem(sizeof(SYMBOL));
-    sym->type = sym->itype = st_pnt;
-
-    if (!func || !func->v.p || func->type != st_pfunc) {
-	parseerror = 1;
-	G_warning(_("Can't call bad function"));
-    }
-    else
-	argc = listcnt((LIST *) arglist);
-
-    for (i = 0, sptr = arglist; sptr; sptr = sptr->next, i++) {
-	if (func->proto[i] == 'r')
-	    i++;
-	if (func->proto[i] == 'p') {
-	    if (sptr->itype != st_pnt || !sptr->v.p)
-		argc = -1;
-	}
-	else if (func->proto[i] == 'd' && sptr->itype != st_num)
-	    argc = -1;
-    }
-
-    res = (VECTOR *) listitem(sizeof(VECTOR));
-
-    if (argc == 0 && (!func->proto || !*func->proto))
-	res = (*(p_func) func->v.p) ();
-    else if (argc == 1 && !strcmp(func->proto, "p"))
-	res = (*(p_func_p) func->v.p) (arglist->v.p);
-    else if (argc == 1 && !strcmp(func->proto, "rp"))
-	res = (*(p_func_pp) func->v.p) (res, arglist->v.p);
-    else if (argc == 2 && !strcmp(func->proto, "rpd"))
-	res = (*(p_func_ppd) func->v.p) (res, arglist->v.p,
-					 arglist->next->v.d);
-    else if (argc == 2 && !strcmp(func->proto, "pp"))
-	res = (*(p_func_pp) func->v.p) (arglist->v.p, arglist->next->v.p);
-    else if (argc == 2 && !strcmp(func->proto, "rpp"))
-	res = (*(p_func_ppp) func->v.p) (res, arglist->v.p,
-					 arglist->next->v.p);
-    else if (argc == 3 && !strcmp(func->proto, "ppp"))
-	res = (*(p_func_ppp) func->v.p) (arglist->v.p,
-					 arglist->next->v.p,
-					 arglist->next->next->v.p);
-    else {
-	G_warning(_("Bad arguments to pointfunc %s"), func->name);
-	parseerror = 1;
-	sym = (SYMBOL *) listdelall((LIST *) sym, freesym);
-	if (res)
-	    G_free(res);
-	return NULL;
-    }
-    sym->v.p = res;
-
-    listdelall((LIST *) arglist, freesym);
-
-    return sym;
-}
-
-SYMBOL *pntop(int op, SYMBOL * pnt1, SYMBOL * pnt2)
-{
-    SYMBOL *func, *arglist, *res = NULL;
-    char buf[32];
-
-    sprintf(buf, "pnt_op_func_%c", op);
-
-    func = getsym(buf);
-    if (!func) {
-	G_warning(_("No function defined to perform ``point %c point''"), op);
-	parseerror = 1;
-    }
-    else if (func->rettype == st_pnt) {
-	res = (SYMBOL *) listitem(sizeof(SYMBOL));
-	symcpy(res, func);
-	res->next = NULL;
-	func = res;
-	arglist = (SYMBOL *) listapp(NULL, (LIST *) pnt1);
-	arglist = (SYMBOL *) listapp((LIST *) arglist, (LIST *) pnt2);
-
-	res = pntfunc(func, arglist);
-    }
-
-    return res;
-}
-
-SYMBOL *pntapp(SYMBOL * head, SYMBOL * elt)
-{
-    return (SYMBOL *) listapp((LIST *) head, (LIST *) elt);
-}
-
-/*
- * Utility function to copy a point: p = p1;
- * The dimension (2D/3D) depends on p1. Note, that copying a constant
- * will always yield 3D.
- */
-VECTOR *v_copy(VECTOR * p, VECTOR * p1)
-{
-    p->x = p1->x;
-    p->y = p1->y;
-    p->z = p1->z;
-
-    return p;
-}
-
-/*
- * Vector addition
- * Result is 2D if at least one of p1 or p2 is 2D.
- */
-VECTOR *v_add(VECTOR * p, VECTOR * p1, VECTOR * p2)
-{
-    p->x = p1->x + p2->x;
-    p->y = p1->y + p2->y;
-    /*
-     * resist the tentation setting p->z to nanval and then testing for
-     * dimension, as p might be the same as p1 or p2
-     */
-    if (!isnan(p1->z) && !isnan(p2->z))
-	p->z = p1->z + p2->z;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Vector substraction
- * Result is 2D if at least one of p1 or p2 is 2D.
- */
-VECTOR *v_sub(VECTOR * p, VECTOR * p1, VECTOR * p2)
-{
-    p->x = p1->x - p2->x;
-    p->y = p1->y - p2->y;
-    if (!isnan(p1->z) && !isnan(p2->z))
-	p->z = p1->z + p2->z;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Utility function to make all coordinates positive
- */
-VECTOR *v_abs(VECTOR * p, VECTOR * p1)
-{
-    p->x = fabs(p1->x);
-    p->y = fabs(p1->y);
-    if (!isnan(p1->z))
-	p->z = fabs(p1->z);
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Utility function to negate all coordinates
- */
-VECTOR *v_neg(VECTOR * p, VECTOR * p1)
-{
-    p->x = -p1->x;
-    p->y = -p1->y;
-    if (!isnan(p1->z))
-	p->z = -p1->z;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Utility function to compare two doubles for equality without epsilon
- * This is not really true, as we consider NaN to be zero.
- */
-static inline int _is_zero(double r)
-{
-    if ((isfinite(r) && r == 0.0) || isnan(r))
-	return 1;
-    return 0;
-}
-
-/*
- * Test for equality of two points. No epsion applied
- */
-double v_eq(VECTOR * p1, VECTOR * p2)
-{
-    VECTOR p;
-    int dim = 2;
-
-    if (!isnan(p1->z) && !isnan(p2->z))
-	dim = 3;
-
-    v_sub(&p, p1, p2);
-    v_abs(&p, &p);
-    if (_is_zero(p.x) && _is_zero(p.y) && (dim == 2 || _is_zero(p.z)))
-	return 1;
-    return 0;
-}
-
-/*
- * Test for equality of two points by a given epsilon
- * epsilon is supposed to have positive values only.
- */
-double v_eq_epsilon(VECTOR * p1, VECTOR * p2, VECTOR * e)
-{
-    VECTOR p;
-    int dim = 2;
-
-    if (!isnan(p1->z) && !isnan(p2->z))
-	dim = 3;
-
-    v_sub(&p, p1, p2);
-    v_abs(&p, &p);
-    if (p.x < e->x && p.y < e->y && (dim == 2 || (p.z < e->z)))
-	return 1;
-    return 0;
-}
-
-/*
- * Multiply a vector by a scalar
- */
-VECTOR *v_mul(VECTOR * p, VECTOR * p1, double d)
-{
-    p->x = d * p1->x;
-    p->y = d * p1->y;
-    if (!isnan(p1->z))
-	p->z = d * p1->z;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Divide a vector by a scalar
- */
-VECTOR *v_div(VECTOR * p, VECTOR * p1, double d)
-{
-    if (!isfinite(d) || d == 0.0) {
-	parseerror = 1;
-	return p;
-    }
-    p->x = p1->x / d;
-    p->y = p1->y / d;
-    if (!isnan(p1->z))
-	p->z = p1->z / d;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Compute the value of a vector
- */
-double v_val(VECTOR * p)
-{
-    return sqrt(p->x * p->x + p->y * p->y +
-		((isnan(p->z)) ? 0 : p->z * p->z));
-}
-
-/*
- * The only way to get a value of zero is that P1 is the origin.
- * The unit vector of the origin doesn't exist, but we return the
- * origin.
- */
-VECTOR *v_unit(VECTOR * p, VECTOR * p1)
-{
-    double val = v_val(p1);
-
-    if (_is_zero(val))
-	return v_copy(p, &pnt_o);
-
-    p->x = p1->x / val;
-    p->y = p1->y / val;
-    if (!isnan(p1->z))
-	p->z = p1->z / val;
-    else
-	p->z = nanval;
-
-    return p;
-}
-
-/*
- * Compute the dot product of P1 and P2
- */
-double v_dot(VECTOR * p1, VECTOR * p2)
-{
-    int dim = 2;
-
-    if (!isnan(p1->z) && !isnan(p2->z))
-	dim = 3;
-    return p1->x * p2->x + p1->y * p2->y + ((dim == 2) ? 0 : p1->z * p2->z);
-}
-
-/*
- * Compute the cross product of P1 and P2
- * Return (0,0) for 2D
- */
-
-VECTOR *v_cross(VECTOR * p, VECTOR * p1, VECTOR * p2)
-{
-    VECTOR p0;
-
-    if (!isnan(p1->z) && !isnan(p2->z)) {
-	p0.x = p1->y * p2->z + p1->z * p2->y;
-	p0.y = p1->z * p2->x + p1->x * p2->z;
-	p0.z = p1->x * p2->y + p1->y * p2->x;
-	v_copy(p, &p0);
-    }
-    else {
-	p->x = p->y = 0;
-	p->z = nanval;
-    }
-
-    return p;
-}
-
-/*
- * Decide if vector P1 is ortogonal to vector P2
- * Should test if either P1 or P2 are (0,0,0);
- */
-double v_isortho(VECTOR * p1, VECTOR * p2)
-{
-    return v_dot(p1, p2) == 0;
-}
-
-/*
- * Decide if P1 and P2 are parallel. If they are but have a diferent
- * direction, -1 is returned.
- */
-double v_ispara(VECTOR * p1, VECTOR * p2)
-{
-    double dot, val, dif;
-
-    dot = v_dot(p1, p2);
-    val = v_val(p1);
-    val *= v_val(p2);
-
-    dif = fabs(dot - val);
-    if (_is_zero(dif))
-	return 1;
-
-    dif = fabs(dot + val);
-    if (_is_zero(dif))
-	return -1;
-
-    return 0;
-}
-
-/*
- * Decide if P1 and P2 have and angle alpha which: 0 < alpha < 90.0
- */
-double v_isacute(VECTOR * p1, VECTOR * p2)
-{
-    return v_dot(p1, p2) > 0;
-}
-
-/*
- * Return the area spanned by the two vectors P1 and P2
- * Works only in 3D.
- */
-double v_area(VECTOR * p1, VECTOR * p2)
-{
-    VECTOR p;
-
-    return 0.5 * v_val(v_cross(&p, p1, p2));
-}

+ 0 - 41
vector/v.mapcalc/vector.h

@@ -1,41 +0,0 @@
-#ifndef VECTOR_H
-#define VECTOR_H
-
-typedef struct Vector
-{
-    struct Vector *next;
-    double x;
-    double y;
-    double z;
-    int refcnt;
-} VECTOR;
-
-extern double nanval;
-
-extern void init_vec(void);
-extern void showvec(SYMBOL * sym);
-extern void setpnt(SYMBOL * var, SYMBOL * pnt);
-extern SYMBOL *mkpnt(double x, double y, double z);
-extern SYMBOL *mkpntvar(SYMBOL * var, SYMBOL * pnt);
-extern SYMBOL *pntfunc(SYMBOL * func, SYMBOL * arglist);
-extern SYMBOL *pntop(int op, SYMBOL * pnt1, SYMBOL * pnt2);
-extern SYMBOL *pntapp(SYMBOL * head, SYMBOL * elt);
-extern VECTOR *v_copy(VECTOR * p, VECTOR * p1);
-extern VECTOR *v_add(VECTOR * p, VECTOR * p1, VECTOR * p2);
-extern VECTOR *v_sub(VECTOR * p, VECTOR * p1, VECTOR * p2);
-extern VECTOR *v_abs(VECTOR * p, VECTOR * p1);
-extern VECTOR *v_neg(VECTOR * p, VECTOR * p1);
-extern double v_eq(VECTOR * p1, VECTOR * p2);
-extern double v_eq_epsilon(VECTOR * p1, VECTOR * p2, VECTOR * e);
-extern VECTOR *v_mul(VECTOR * p, VECTOR * p1, double d);
-extern VECTOR *v_div(VECTOR * p, VECTOR * p1, double d);
-extern double v_val(VECTOR * p);
-extern VECTOR *v_unit(VECTOR * p, VECTOR * p1);
-extern double v_dot(VECTOR * p1, VECTOR * p2);
-extern VECTOR *v_cross(VECTOR * p, VECTOR * p1, VECTOR * p2);
-extern double v_isortho(VECTOR * p1, VECTOR * p2);
-extern double v_ispara(VECTOR * p1, VECTOR * p2);
-extern double v_isacute(VECTOR * p1, VECTOR * p2);
-extern double v_area(VECTOR * p1, VECTOR * p2);
-
-#endif

+ 0 - 109
vector/v.mapcalc/yylex.c

@@ -1,109 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <grass/gis.h>
-#include "list.h"
-#include "mapcalc.h"
-#include "yylex.h"
-#include "v.mapcalc.tab.h"
-
-/*
- * missing features (some might go to bison):
- * - quit/exit/bye
- * - load script
- * - set plugin path
- * - describe a function/variable
- * - get description for function/variable (help)
- * - save current state in a script to be reproducible (vars, descr...)
- */
-
-int yylex(void)
-{
-    int c;
-
-    while ((c = getchar()) == ' ' || c == '\t' || c == '\n') ;
-
-    if (c == EOF)
-	return 0;
-
-    if (c == '.' || isdigit(c)) {
-	ungetc(c, stdin);
-	scanf("%lf", &yylval.dbl);
-	return NUM;
-    }
-
-    if (isalpha(c) || c == '_') {
-	SYMBOL *s, *sym;
-	static char *symbuf = 0;
-	static int length = 0;
-	int i;
-
-	if (length == 0) {
-	    length = 40;
-	    symbuf = (char *)G_malloc(length + 1);
-	}
-
-	i = 0;
-	do {
-	    if (i == length) {
-		length *= 2;
-		symbuf = (char *)G_realloc(symbuf, length + 1);
-	    }
-	    symbuf[i++] = c;
-	    c = getchar();
-	} while (c != EOF && (isalnum(c) || c == '_'));
-
-	ungetc(c, stdin);
-	symbuf[i] = '\0';
-
-	/*
-	 * 1. Check, if it's a known symbol. If so, we know the type.
-	 * 2. Check, if it might be an external function. If so load
-	 * 3. Check, if there is a map with this name
-	 * 4. return as string.
-	 */
-	sym = (SYMBOL *) listitem(sizeof(SYMBOL));
-	s = getsym(symbuf);
-	if (!s) {
-	    sym->v.p = strdup(symbuf);
-	    sym->type = sym->itype = st_str;
-	    yylval.ptr = sym;
-	    return STRING;
-	}
-	else {
-	    symcpy(sym, s);
-	    s = sym;
-	}
-
-	yylval.ptr = s;
-	switch (s->type) {
-	case st_map:
-	    return MAPVAR;
-	case st_mfunc:
-	    return MAPFUNC;
-	case st_pnt:
-	    return PNTVAR;
-	case st_any:
-	    return ANYVAR;
-	case st_num:
-	    return NUMVAR;
-	case st_nfunc:
-	    return NUMFUNC;
-	case st_afunc:
-	    return ANYFUNC;
-	case st_pfunc:
-	    return PNTFUNC;
-	default:
-	    G_fatal_error("Insert more translations here (%d)", s->type);
-	}
-    }
-
-    return c;
-
-}
-
-void yyerror(const char *msg)
-{
-    fprintf(stdout, "%s\n", msg);
-}

+ 0 - 7
vector/v.mapcalc/yylex.h

@@ -1,7 +0,0 @@
-#ifndef YYLEX_H
-#define YYLEX_H
-
-extern int yylex(void);
-extern void yyerror(const char *msg);
-
-#endif