+ /* "executing" func () { list } */
+ struct function *funcp;
+ struct function **funcpp = &G.top_func;
+
+ while ((funcp = *funcpp) != NULL) {
+ if (strcmp(funcp->name, command->argv[0]) == 0) {
+ debug_printf_exec("replacing function '%s'", funcp->name);
+ free(funcp->name);
+ free_pipe_list(funcp->body, /* indent: */ 0);
+ goto skip;
+ }
+ funcpp = &funcp->next;
+ }
+ debug_printf_exec("remembering new function '%s'", funcp->name);
+ funcp = *funcpp = xzalloc(sizeof(*funcp));
+ /*funcp->next = NULL;*/
+ skip:
+ funcp->name = command->argv[0];
+ funcp->body = command->group;
+ command->group = NULL;
+ command->argv[0] = NULL;
+ free_strings(command->argv);
+ command->argv = NULL;
+ /* note: if we are in a loop, future "executions"
+ * of func def will see it as null command since
+ * command->group == NULL and command->argv == NULL */
+//this isn't exactly right: while...do f1() {a;}; f1; f1 {b;}; done
+//second loop will execute b!
+