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; }
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; }