static RESULT_NODE * next_operand (RESULT_NODE *r, int *indent) { RESULT_NODE *p; p = r-> parent; if (!p) return NULL; while (p-> parent && ((! p-> script_node) || ( p-> script_node-> type == GG_OPERATOR && p-> script_node-> operator == OP_UNDEFINED)) && r == p-> op2) { r = p; p = r-> parent; } if (((! p-> script_node) || ( p-> script_node-> type == GG_OPERATOR && p-> script_node-> operator == OP_UNDEFINED)) && r != p-> op2) return first_operand (p-> op2, indent); else return NULL; }
//one arg: ops static cellpoint list_of_values(void) { args_push(args_ref(1)); reg = no_operands(); if (is_true(reg)){ reg = NIL; }else { //get the first operand args_push(args_ref(1)); reg = first_operand(); //eval the first operand with tail_context is a_false args_push(a_false); args_push(reg); reg = eval(); stack_push(&vars_stack, reg); //eval the rest operands args_push(args_ref(1)); reg = rest_operands(); args_push(reg); reg = list_of_values(); reg = cons(stack_pop(&vars_stack), reg); } args_pop(1); return reg; }
static pSlipObject list_of_values(pSlip gd, pSlipObject exps, pSlipEnvironment env) { if (is_no_operands(gd, exps) == S_TRUE) { return gd->singleton_EmptyList; } else { pSlipObject x; x = slip_eval(gd, first_operand(exps), env); if (x == NULL) x = gd->singleton_Nil; return cons(gd, x, list_of_values(gd, rest_operands(exps), env)); } }
object *list_of_values(object *exps, object *env) { return is_no_operands(exps) ? empty_list() : cons(eval(first_operand(exps), env), list_of_values(rest_operands(exps), env)); }
char * concatenate_results (RESULT_NODE *r, int shuffle, Bool convert_indent, char **error_text) { RESULT_NODE *op; int indent = 0, shuffle_cnt, oplines, totlines, linewidth, opwidth, totwidth, totlinelength, runlength, line; char **blk, *txt, *line_end, *last_line, *rc; if (error_text) *error_text = NULL; /* No errors yet */ totlines = 0; totwidth = 0; totlinelength = 0; shuffle_cnt = 0; op = first_operand (r, & indent); if (convert_indent) r-> indent = 0; /* Coz indent has been migrated. */ else indent = 0; /* Forget about initial indentation */ while (op) { op-> indent = indent; /* Copy indent value to operand. */ /* Perform shuffle */ if (shuffle > 0 && op-> indent >= shuffle) { if (op-> indent - shuffle_cnt >= shuffle) op-> indent -= shuffle_cnt; else op-> indent = shuffle; } /* Calculate length & width of operand for shuffle. */ if (op-> value. type == TYPE_BLOCK) { /* Catch undefined operand. */ if (! op-> value. b) return NULL; oplines = 0; opwidth = 0; blk = op-> value. b; while (*blk) { oplines++; linewidth = strlen (*blk); if (linewidth > opwidth) opwidth = linewidth; blk++; } opwidth += op-> indent; totwidth += opwidth; totlinelength += opwidth; } else { if (op-> value. type != TYPE_UNDEFINED) string_value (& op-> value); /* Catch undefined operand. */ if (op-> value. type == TYPE_UNDEFINED || (! op-> value. s)) { /* Pass node result coz that's where culprit is stored */ result_node_error ("Undefined expression", r, error_text); return NULL; } string_value (& op-> value); oplines = 1; opwidth = op-> indent + strllen (op-> value. s); if (strchr (op-> value. s, '\n')) totwidth = opwidth; else totwidth += opwidth; totlinelength += op-> indent + strlen (op-> value. s); } if (oplines > totlines) totlines = oplines; if (op-> value. s && strchr (op-> value. s, '\n')) shuffle_cnt = 0; else if (op-> script_node-> extend) shuffle_cnt = totwidth; else shuffle_cnt += opwidth - (op-> script_node-> width + indent); op = next_operand (op, & indent); } /* Now build the result */ rc = mem_alloc (totlines * totlinelength + 1); memset (rc, ' ', totlines * totlinelength + 1); op = first_operand (r, NULL); runlength = 0; while (op) { line = 0; if (op-> value. type == TYPE_BLOCK) { opwidth = 0; blk = op-> value. b; while (*blk) { linewidth = strlen (*blk); if (linewidth > opwidth) opwidth = linewidth; txt = rc + line * totlinelength + runlength + op-> indent; memcpy (txt, *blk, strlen (*blk)); blk++; line++; } opwidth += op-> indent; runlength += opwidth; } else { for (line = 0; line < totlines; line++) { txt = rc + line * totlinelength + runlength + op-> indent; memcpy (txt, op-> value. s, strlen (op-> value. s)); } runlength += op-> indent + strlen (op-> value. s); } op = next_operand (op, NULL); } rc [totlines * totlinelength] = 0; /* Trim whitespace from all lines */ txt = rc; while (txt) { line_end = strchr(txt, '\n'); if (!line_end) break; if (*(line_end - 1) == '\r') line_end = line_end - 1; last_line = line_end; while (last_line > txt) { if (!isspace (*(last_line - 1))) break; last_line--; } memmove(last_line, line_end, strlen(line_end) + 1); txt = last_line + (*last_line == '\r' ? 2 : 1); } /* JS Blunder check */ ASSERT (runlength == totlinelength); return rc; }