static inline void do_in_t(double *dashs, double *slashs, int strpno, int tile_t) { double *l1 = alloc_line(T_WIDTH_DBL + 2); double *l2 = alloc_line(T_WIDTH_DBL + 2); uint8_t t, i; #ifdef DEBUG if (tile_t == ((DEBUG_SIZE / T_WIDTH_DBL))) { printf("Final task %i %i\n", tile_t, strpno - tile_t); } else { printf("Do do_in_t %i %i\n", tile_t, strpno - tile_t); } #endif for (t = 0; t < T_ITERS * 2; t += 2) { /* Load slash part */ l1[0] = slashs[tile_t * 2 * T_ITERS + t]; l1[1] = slashs[tile_t * 2 * T_ITERS + t + 1]; int r = (2 + t / 2); l1[r] = 0.0; for (i = 2; i <= r; i++) { l2[i] = ((l1[i - 2] + l1[i - 1] + l1[i]) / 3.0); } swap(&l1, &l2); } /* Write dash */ for (i = 2; i < T_WIDTH_DBL; i++) { dashs[strpno * T_WIDTH_DBL + i - 2] = l1[i]; } free(l1); free(l2); }
static inline void do_i0_t(double *dashs, double *slashs, int strpno, int tile_t) { double *l1 = alloc_line(T_WIDTH_DBL + 1); double *l2 = alloc_line(T_WIDTH_DBL + 1); uint8_t t, i; #ifdef DEBUG printf("Do do_i0_t %i %i\n", tile_t, strpno - tile_t); #endif for (i = 1; i < T_WIDTH_DBL + 1; i++) { l1[i] = dashs[strpno * T_WIDTH_DBL + i - 1]; } for (t = 0; t < 2 * T_ITERS; t += 2) { l1[0] = 0.0; int right = max(T_WIDTH_DBL - t / 2, 0); memcpy(l2, l1, (T_WIDTH_DBL + 1) * sizeof(*l1)); for (i = 1; i < right; i++) { l2[i] = ((l1[i - 1] + l1[i] + l1[i + 1]) / 3.0); } slashs[tile_t * 2 * T_ITERS + t] = l1[right - 1]; slashs[tile_t * 2 * T_ITERS + t + 1] = l1[right]; swap(&l1, &l2); } free(l1); free(l2); }
static inline void do_i_t(double *dashs, double *slashs, int strpno, int tile_t) { double *l1 = alloc_line(T_WIDTH_DBL + 2); double *l2 = alloc_line(T_WIDTH_DBL + 2); uint8_t t, i; #ifdef DEBUG if (tile_t == ((DEBUG_ITER / T_ITERS))) { printf("Final line, task %i %i\n", tile_t, strpno - tile_t); } #endif /* Load dash */ for (i = 2; i < T_WIDTH_DBL + 2; i++) { l1[i] = dashs[strpno * T_WIDTH_DBL + i - 2]; } for (t = 0; t < T_ITERS * 2; t += 2) { /* Load slash part */ l1[0] = slashs[tile_t * 2 * T_ITERS + t]; l1[1] = slashs[tile_t * 2 * T_ITERS + t + 1]; memcpy(l2, l1, (T_WIDTH_DBL + 2) * sizeof(*l1)); for (i = 2; i < T_WIDTH_DBL + 2; i++) { l2[i] = ((l1[i - 2] + l1[i - 1] + l1[i]) / 3.0); } /* Write slash */ slashs[tile_t * 2 * T_ITERS + t] = l1[T_WIDTH_DBL]; slashs[tile_t * 2 * T_ITERS + t + 1] = l1[T_WIDTH_DBL + 1]; swap(&l1, &l2); } /* Write dash */ for (i = 2; i < T_WIDTH_DBL; i++) { dashs[strpno * T_WIDTH_DBL + i - 2] = l2[i]; } free(l1); free(l2); }
/*---------------------------------------------------------------------------*/ void shell_prompt(char *str) { char *line; line = alloc_line(); if(line != NULL) { strncpy(line, str, TELNETD_CONF_LINELEN); /* petsciiconv_toascii(line, TELNETD_CONF_LINELEN);*/ sendline(line); } }
static CONT_LEVEL * alloc_level(PLFLT level) { CONT_LEVEL *node; node = (CONT_LEVEL *) malloc(sizeof(CONT_LEVEL)); node->level = level; node->next = NULL; node->line = alloc_line(node); return node; }
/*---------------------------------------------------------------------------*/ static void sendopt(u8_t option, u8_t value) { char *line; line = alloc_line(); if(line != NULL) { line[0] = TELNET_IAC; line[1] = option; line[2] = value; line[3] = 0; sendline(line); } }
static inline void do_i0_t0(double *dashs, double *slashs, int tile_t, int tile_i) { double *l1 = alloc_line(T_WIDTH_DBL + 1); double *l2 = alloc_line(T_WIDTH_DBL + 1); uint8_t t, i; #ifdef DEBUG printf("First task T I, %i %i\n", tile_t, tile_i); #endif for (i = 1; i < T_WIDTH_DBL + 1; i++) { l1[i] = dashs[i - 1]; } for (t = 0; t < T_ITERS * 2; t += 2) { l1[0] = 0.0; int right = max(T_WIDTH_DBL - t / 2, 1); memcpy(l2, l1, (T_WIDTH_DBL + 1) * sizeof(*l1)); for (i = 1; i < right; i++) { l2[i] = (l1[i - 1] + l1[i] + l1[i + 1]) / 3.0; } slashs[t] = l1[right - 1]; slashs[t + 1] = l1[right]; swap(&l1, &l2); } #ifdef DEBUG for (i = 0; i < DISPLAY_SIZE; i++) printf("%10.3f", dashs[i]); printf("\n"); #endif free(l1); free(l2); }
static void cont_mv_store(PLFLT xx, PLFLT yy) { if (cont3d) { if (currline->npts != 0) { /* not an empty list, allocate new */ currline->next = alloc_line(currlev); currline = currline->next; } /* and fill first element */ currline->x[0] = xx; currline->y[0] = yy; currline->npts = 1; } else plP_movwor(xx, yy); }
static void vedit_init() { register struct textline *p; if (currline) return; p = alloc_line(); firstline = p; lastline = p; currline = p; currpnt = 0; top_of_win = p; curr_window_line = 0; redraw_everything = FALSE; total_num_of_line = 0; shift = 0; /* lthuang: 99/07 */ }
/* * split splits 'line' right before the character pos */ static void split(register struct textline *line, register int pos) { register struct textline *p; if (pos > line->len) return; p = alloc_line(); p->len = line->len - pos; line->len = pos; strcpy(p->data, (line->data + pos)); *(line->data + pos) = '\0'; append(p, line); if (line == currline && pos <= currpnt) /* ? */ { currline = p; currpnt -= pos; curr_window_line++; } redraw_everything = TRUE; }
void shell_output_P(PGM_P str1, PGM_P str2) { static unsigned len; char *line; line = alloc_line(); if (line != NULL) { len = strlen_P(str1); strncpy_P(line, str1, TELNETD_CONF_LINELEN); if (len < TELNETD_CONF_LINELEN) strncpy_P(line + len, str2, TELNETD_CONF_LINELEN - len); len = strlen(line); if (len < TELNETD_CONF_LINELEN - 2) { line[len] = ISO_cr; line[len + 1] = ISO_nl; line[len + 2] = 0; } /* petsciiconv_toascii(line, TELNETD_CONF_LINELEN);*/ sendline(line); } }
int main(int argc, char **argv) { wint_t ch; CHAR *c; CSET cur_set; /* current character set */ LINE *l; /* current line */ int extra_lines; /* # of lines above first line */ int cur_col; /* current column */ int cur_line; /* line number of current position */ int max_line; /* max value of cur_line */ int this_line; /* line l points to */ int nflushd_lines; /* number of lines that were flushed */ int adjust, opt, warned, width; (void)setlocale(LC_CTYPE, ""); max_bufd_lines = 128; compress_spaces = 1; /* compress spaces into tabs */ while ((opt = getopt(argc, argv, "bfhl:px")) != -1) switch (opt) { case 'b': /* do not output backspaces */ no_backspaces = 1; break; case 'f': /* allow half forward line feeds */ fine = 1; break; case 'h': /* compress spaces into tabs */ compress_spaces = 1; break; case 'l': /* buffered line count */ if ((max_bufd_lines = atoi(optarg)) <= 0) errx(1, "bad -l argument %s", optarg); break; case 'p': /* pass unknown control sequences */ pass_unknown_seqs = 1; break; case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; case '?': default: usage(); } if (optind != argc) usage(); /* this value is in half lines */ max_bufd_lines *= 2; adjust = cur_col = extra_lines = warned = 0; cur_line = max_line = nflushd_lines = this_line = 0; cur_set = last_set = CS_NORMAL; lines = l = alloc_line(); while ((ch = getwchar()) != WEOF) { if (!iswgraph(ch)) { switch (ch) { case BS: /* can't go back further */ if (cur_col == 0) continue; --cur_col; continue; case CR: cur_col = 0; continue; case ESC: /* just ignore EOF */ switch(getwchar()) { case RLF: cur_line -= 2; break; case RHLF: cur_line--; break; case FHLF: cur_line++; if (cur_line > max_line) max_line = cur_line; } continue; case NL: cur_line += 2; if (cur_line > max_line) max_line = cur_line; cur_col = 0; continue; case SPACE: ++cur_col; continue; case SI: cur_set = CS_NORMAL; continue; case SO: cur_set = CS_ALTERNATE; continue; case TAB: /* adjust column */ cur_col |= 7; ++cur_col; continue; case VT: cur_line -= 2; continue; } if (iswspace(ch)) { if ((width = wcwidth(ch)) > 0) cur_col += width; continue; } if (!pass_unknown_seqs) continue; } /* Must stuff ch in a line - are we at the right one? */ if (cur_line != this_line - adjust) { LINE *lnew; int nmove; adjust = 0; nmove = cur_line - this_line; if (!fine) { /* round up to next line */ if (cur_line & 1) { adjust = 1; nmove++; } } if (nmove < 0) { for (; nmove < 0 && l->l_prev; nmove++) l = l->l_prev; if (nmove) { if (nflushd_lines == 0) { /* * Allow backup past first * line if nothing has been * flushed yet. */ for (; nmove < 0; nmove++) { lnew = alloc_line(); l->l_prev = lnew; lnew->l_next = l; l = lines = lnew; extra_lines++; } } else { if (!warned++) dowarn(cur_line); cur_line -= nmove; } } } else { /* may need to allocate here */ for (; nmove > 0 && l->l_next; nmove--) l = l->l_next; for (; nmove > 0; nmove--) { lnew = alloc_line(); lnew->l_prev = l; l->l_next = lnew; l = lnew; } } this_line = cur_line + adjust; nmove = this_line - nflushd_lines; if (nmove >= max_bufd_lines + BUFFER_MARGIN) { nflushd_lines += nmove - max_bufd_lines; flush_lines(nmove - max_bufd_lines); } } /* grow line's buffer? */ if (l->l_line_len + 1 >= l->l_lsize) { int need; need = l->l_lsize ? l->l_lsize * 2 : 90; if ((l->l_line = realloc(l->l_line, (unsigned)need * sizeof(CHAR))) == NULL) err(1, (char *)NULL); l->l_lsize = need; } c = &l->l_line[l->l_line_len++]; c->c_char = ch; c->c_set = cur_set; c->c_column = cur_col; c->c_width = wcwidth(ch); /* * If things are put in out of order, they will need sorting * when it is flushed. */ if (cur_col < l->l_max_col) l->l_needs_sort = 1; else l->l_max_col = cur_col; if (c->c_width > 0) cur_col += c->c_width; } if (ferror(stdin)) err(1, NULL); if (max_line == 0) exit(0); /* no lines, so just exit */ /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) this_line++; flush_lines(this_line - nflushd_lines + extra_lines + 1); /* make sure we leave things in a sane state */ if (last_set != CS_NORMAL) PUTC('\017'); /* flush out the last few blank lines */ nblank_lines = max_line - this_line; if (max_line & 1) nblank_lines++; else if (!nblank_lines) /* missing a \n on the last line? */ nblank_lines = 2; flush_blanks(); exit(0); }