void execute(expr_list * ee) { int verbose = isatty(2); expr_list *l; int count, n; setup_region(); exprs = ee; G_add_error_handler(error_handler, NULL); for (l = ee; l; l = l->next) { expression *e = l->exp; const char *var; if (e->type != expr_type_binding && e->type != expr_type_function) G_fatal_error("internal error: execute: invalid type: %d", e->type); if (e->type != expr_type_binding) continue; var = e->data.bind.var; if (!overwrite_flag && check_output_map(var)) G_fatal_error(_("output map <%s> exists. To overwrite, use the --overwrite flag"), var); } for (l = ee; l; l = l->next) { expression *e = l->exp; const char *var; expression *val; initialize(e); if (e->type != expr_type_binding) continue; var = e->data.bind.var; val = e->data.bind.val; e->data.bind.fd = open_output_map(var, val->res_type); } setup_maps(); count = rows * depths; n = 0; G_init_workers(); for (current_depth = 0; current_depth < depths; current_depth++) for (current_row = 0; current_row < rows; current_row++) { if (verbose) G_percent(n, count, 2); for (l = ee; l; l = l->next) { expression *e = l->exp; int fd; evaluate(e); if (e->type != expr_type_binding) continue; fd = e->data.bind.fd; put_map_row(fd, e->buf, e->res_type); } n++; } G_finish_workers(); if (verbose) G_percent(n, count, 2); for (l = ee; l; l = l->next) { expression *e = l->exp; const char *var; expression *val; int fd; if (e->type != expr_type_binding) continue; var = e->data.bind.var; val = e->data.bind.val; fd = e->data.bind.fd; close_output_map(fd); e->data.bind.fd = -1; if (val->type == expr_type_map) { if (val->data.map.mod == 'M') { copy_cats(var, val->data.map.idx); copy_colors(var, val->data.map.idx); } copy_history(var, val->data.map.idx); } else create_history(var, val); } G_unset_error_routine(); }
/* allocate a history buffer */ int sc_alloc_history_buffer(scr_stat *scp, int lines, int prev_ysize, int wait) { /* * syscons unconditionally allocates buffers up to * SC_HISTORY_SIZE lines or scp->ysize lines, whichever * is larger. A value greater than that is allowed, * subject to extra_history_size. */ sc_vtb_t *history; sc_vtb_t *prev_history; int cur_lines; /* current buffer size */ int min_lines; /* guaranteed buffer size */ int delta; /* lines to put back */ if (lines <= 0) lines = SC_HISTORY_SIZE; /* use the default value */ /* make it at least as large as the screen size */ lines = imax(lines, scp->ysize); /* remove the history buffer while we update it */ history = prev_history = scp->history; scp->history = NULL; /* calculate the amount of lines to put back to extra_history_size */ delta = 0; if (prev_history) { cur_lines = sc_vtb_rows(history); min_lines = imax(SC_HISTORY_SIZE, prev_ysize); if (cur_lines > min_lines) delta = cur_lines - min_lines; } /* lines up to min_lines are always allowed. */ min_lines = imax(SC_HISTORY_SIZE, scp->ysize); if (lines > min_lines) { if (lines - min_lines > extra_history_size + delta) { /* too many lines are requested */ scp->history = prev_history; return EINVAL; } } /* allocate a new buffer */ history = (sc_vtb_t *)malloc(sizeof(*history), M_DEVBUF, (wait) ? M_WAITOK : M_NOWAIT); if (history != NULL) { if (lines > min_lines) extra_history_size -= lines - min_lines; /* XXX error check? */ sc_vtb_init(history, VTB_RINGBUFFER, scp->xsize, lines, NULL, wait); /* FIXME: XXX no good? */ sc_vtb_clear(history, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8); if (prev_history != NULL) copy_history(prev_history, history); scp->history_pos = sc_vtb_tail(history); } else { scp->history_pos = 0; } /* destroy the previous buffer */ if (prev_history != NULL) { extra_history_size += delta; sc_vtb_destroy(prev_history); free(prev_history, M_DEVBUF); } scp->history = history; return 0; }