void RearrangeLineWhenInsSB (CONINFO* con) { u_int addr; int i; int prev = CODEIS_S; u_char ch, ch1; addr = text_offset (con, con->x, con->y) + 1; for (i = 0; i < con->xmax - con->x - 1; i++) { ch = con->textBuff [addr + i]; ch1 = con->textBuff [addr + i + 1]; if (iskanji (con, ch, ch1)) { switch (prev) { case CODEIS_S: case CODEIS_2: con->flagBuff [addr + i] = con->db | LATCH_1; prev = CODEIS_1; break; case CODEIS_1: con->flagBuff [addr + i] = con->db | LATCH_2; prev = CODEIS_1; break; } } else if (ch) { con->flagBuff [addr + i] = con->sb | LATCH_S; prev = CODEIS_S; } else prev = CODEIS_S; } }
char *get_chars_rowcol(Text *text, int row, int col, int length, int forwards) { int r = 0, c = 0; size_t i, bytes; char *ret; for (i = 0; i < text->size; ++i) { if (i == text->gap_start) { i += GAPSIZE(text) - 1; continue; } if (r >= row && c == col) break; if (text->buf[i] == '\n') { if (r == row && c == col - 1) break; ++r; c = 0; } else if (text->buf[i] == '\t') { c += 8;// - (c % 8); } else { // Handle unicode bytes = more_bytes_utf8[(unsigned int)(unsigned char)text->buf[i]]; i += bytes; ++c; } } // TODO handle unicode ret = calloc(1, length + 1); if (forwards) text_memcpy_from(ret, 0, text, i, length); else text_memcpy_from(ret, 0, text, text_offset(text, i, -length), length); return ret; }
int FirstOrSecondByte (CONINFO* con, u_char ch) { u_int prev_addr = -1; if (con->x == 0) { if (con->y > con->ymin) { prev_addr = text_offset (con, con->xmax, con->y - 1); } } else prev_addr = text_offset (con, con->x - 1, con->y); if (prev_addr != -1) { if (con->flagBuff [prev_addr] & CODEIS_1) return CODEIS_2; else return CODEIS_1; } return CODEIS_1; }