static void fill_words (struct state *st) { char *p = st->words + strlen(st->words); char *c; int lines = 0; int max = MAXLINES; for (c = st->words; c < p; c++) if (*c == '\n') lines++; while (p < st->words + sizeof(st->words) - 1 && lines < max) { int c = textclient_getc (st->tc); if (c == '\n') lines++; if (c > 0) *p++ = (char) c; else break; } *p = 0; st->lines = lines; }
static void fill_words (struct state *st) { char *p = st->words + strlen(st->words); while (p < st->words + sizeof(st->words) - 1 && st->lines < MAXLINES) { int c = textclient_getc (st->tc); if (c == '\n') st->lines++; if (c > 0) *p++ = (char) c; else break; } *p = 0; }
/* Reads and returns a single Unicode character from the text client. */ static unsigned long read_unicode (ModeInfo *mi) { splitflap_configuration *bp = &bps[MI_SCREEN(mi)]; const unsigned char *end = bp->text + sizeof(bp->text) - 1; /* 4 bytes */ unsigned long uc = 0; long L; int i; if (bp->clock_p || !bp->tc) abort(); /* Fill the buffer with available input. */ i = strlen ((char *) bp->text); while (i < (end - bp->text)) { int c = textclient_getc (bp->tc); if (c <= 0) break; bp->text[i++] = (char) c; bp->text[i] = 0; } /* Pop 1-4 bytes from the front of the buffer and extract a UTF8 character. */ L = utf8_decode (bp->text, i, &uc); if (L) { int j = end - bp->text - L; memmove (bp->text, bp->text + L, j); bp->text[j] = 0; } else uc = 0; return uc; }
/* Populates the sc->lines list with as many lines as possible. */ static void get_more_lines (sws_configuration *sc) { /* wrap anyway, if it's absurdly long. */ int wrap_pix = (wrap_p ? sc->line_pixel_width : 10000); int col = 0; int col_pix = 0; char *s = sc->buf; int target = sc->buf_size - sc->buf_tail - 2; /* Fill as much as we can into sc->buf. */ while (target > 0) { char c = textclient_getc (sc->tc); if (c <= 0) break; sc->buf[sc->buf_tail++] = c; sc->buf[sc->buf_tail] = 0; target--; } while (sc->total_lines < max_lines) { int cw; if (s >= sc->buf + sc->buf_tail) /* Reached end of buffer before end of line. Bail. */ return; cw = char_width (sc, *s); if (*s == '\r' || *s == '\n' || col_pix + cw >= wrap_pix) { int L = s - sc->buf; if (*s == '\r' || *s == '\n') { if (*s == '\r' && s[1] == '\n') /* swallow CRLF too */ *s++ = 0; *s++ = 0; } else { /* We wrapped -- try to back up to the previous word boundary. */ char *s2 = s; int n = 0; while (s2 > sc->buf && *s2 != ' ' && *s2 != '\t') s2--, n++; if (s2 > sc->buf) { s = s2; *s++ = 0; L = s - sc->buf; } } sc->lines[sc->total_lines] = (char *) malloc (L+1); memcpy (sc->lines[sc->total_lines], sc->buf, L); sc->lines[sc->total_lines][L] = 0; if (!textures_p) latin1_to_ascii (sc->lines[sc->total_lines]); { char *t = sc->lines[sc->total_lines]; char *ut = untabify (t); strip (ut, (alignment == 0), 1); /* if centering, strip leading whitespace too */ sc->lines[sc->total_lines] = ut; free (t); } sc->total_lines++; if (sc->buf_tail > (s - sc->buf)) { int i = sc->buf_tail - (s - sc->buf); memmove (sc->buf, s, i); sc->buf_tail = i; sc->buf[sc->buf_tail] = 0; } else { sc->buf_tail = 0; } sc->buf[sc->buf_tail] = 0; s = sc->buf; col = 0; col_pix = 0; } else { col++; col_pix += cw; if (*s == '\t') { int tab_pix = TAB_WIDTH * sc->char_width; col = TAB_WIDTH * ((col / TAB_WIDTH) + 1); col_pix = tab_pix * ((col / tab_pix) + 1); } s++; } } }
/* Returns a single line of text from the output buffer of the subprocess, taking into account wrapping, centering, etc. Returns 0 if no complete line is currently available. */ static char * get_one_line (fliptext_configuration *sc) { char *result = 0; int wrap_pix = sc->font_wrap_pixels; int col = 0; int col_pix = 0; char *s = sc->buf; int target = sc->buf_size - sc->buf_tail - 2; /* Fill as much as we can into sc->buf, but stop at newline. */ while (target > 0) { int c = textclient_getc (sc->tc); if (c <= 0) break; sc->buf[sc->buf_tail++] = (char) c; sc->buf[sc->buf_tail] = 0; target--; if (c == '\r' || c == '\n') break; } while (!result) { int cw; if (s >= sc->buf + sc->buf_tail) /* Reached end of buffer before end of line. Bail. */ return 0; cw = char_width (sc, *s); if (*s == '\r' || *s == '\n' || col_pix + cw >= wrap_pix) { int L = s - sc->buf; if (*s == '\r' || *s == '\n') { if (*s == '\r' && s[1] == '\n') /* swallow CRLF too */ *s++ = 0; *s++ = 0; } else { /* We wrapped -- try to back up to the previous word boundary. */ char *s2 = s; int n = 0; while (s2 > sc->buf && *s2 != ' ' && *s2 != '\t') s2--, n++; if (s2 > sc->buf) { s = s2; *s++ = 0; L = s - sc->buf; } } if (result) abort(); result = (char *) malloc (L+1); memcpy (result, sc->buf, L); result[L] = 0; { char *t = result; char *ut = untabify (t); strip (ut, (sc->alignment == 0), 1); /* if centering, strip leading whitespace too */ result = ut; free (t); } if (sc->buf_tail > (s - sc->buf)) { int i = sc->buf_tail - (s - sc->buf); memmove (sc->buf, s, i); sc->buf_tail = i; sc->buf[sc->buf_tail] = 0; } else { sc->buf_tail = 0; } sc->buf[sc->buf_tail] = 0; s = sc->buf; col = 0; col_pix = 0; } else { col++; col_pix += cw; if (*s == '\t') { int tab_pix = TAB_WIDTH * sc->char_width; col = TAB_WIDTH * ((col / TAB_WIDTH) + 1); col_pix = tab_pix * ((col / tab_pix) + 1); } s++; } } return result; }