static inline void put_paragraph (WEdit * edit, unsigned char *t, off_t p, long indent, off_t size) { off_t cursor; off_t i; int c = '\0'; cursor = edit->buffer.curs1; if (indent != 0) while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; for (i = 0; i < size; i++, p++) { if (i != 0 && indent != 0) { if (t[i - 1] == '\n' && c == '\n') { while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) p++; } else if (t[i - 1] == '\n') { off_t curs; edit_cursor_move (edit, p - edit->buffer.curs1); curs = edit->buffer.curs1; edit_insert_indent (edit, indent); if (cursor >= curs) cursor += edit->buffer.curs1 - p; p = edit->buffer.curs1; } else if (c == '\n') { edit_cursor_move (edit, p - edit->buffer.curs1); while (strchr ("\t ", edit_buffer_get_byte (&edit->buffer, p)) != NULL) { edit_delete (edit, TRUE); if (cursor > edit->buffer.curs1) cursor--; } p = edit->buffer.curs1; } } c = edit_buffer_get_byte (&edit->buffer, p); if (c != t[i]) replace_at (edit, p, t[i]); } edit_cursor_move (edit, cursor - edit->buffer.curs1); /* restore cursor position */ }
/** * Tworzy wszytskie możliwe modyfikacje słowa 'word' według zasad * ustalonych dla dictionary_hints. * @param[in] dict Słownik. * @param[in] word Słowo. * @param[in,out] hints_size Ilość podpowiedzi. * @param[in,out] output Wskaźnik na tablicę podpowiedzi. */ static void possible_hints(const struct dictionary *dict, const wchar_t *word, int **hints_size, wchar_t ***output) { const wchar_t * alphabet = create_alphabet(dict); wchar_t *hints[HINTS_SIZE]; int size = 0; for (size_t i = 0; i < (wcslen(word) + 1); i++) { wchar_t *h1 = malloc(wcslen(word) * sizeof(wchar_t *)); wcscpy(h1, word); delete_at(h1, i, wcslen(word)); hints[size] = h1; size++; } for (size_t i = 0; i < wcslen(word); i++) for (int j = 0; alphabet[j]; j++) { wchar_t *h2 = malloc((wcslen(word) + 1) * sizeof(wchar_t *)); wcscpy(h2, word); replace_at(h2, alphabet[j], i, wcslen(word)); hints[size] = h2; size++; } for (size_t i = 0; i <= wcslen(word); i++) for (int j = 0; alphabet[j]; j++) { wchar_t *h3 = malloc((wcslen(word) + 2) * sizeof(wchar_t *)); h3[0] = L'\0'; wchar_t c[2]; c[0] = alphabet[j]; c[1] = L'\0'; insert_at(word, c, i, wcslen(word), &h3); hints[size] = h3; size++; } *hints_size = &size; qsort(hints, size, sizeof(wchar_t *), compare); *output = hints; }
/* replaces a block of text */ static void put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size) { long cursor; int i, c = 0; cursor = edit->curs1; if (indent) while (strchr ("\t ", edit_get_byte (edit, p))) p++; for (i = 0; i < size; i++, p++) { if (i && indent) { if (t[i - 1] == '\n' && c == '\n') { while (strchr ("\t ", edit_get_byte (edit, p))) p++; } else if (t[i - 1] == '\n') { long curs; edit_cursor_move (edit, p - edit->curs1); curs = edit->curs1; edit_insert_indent (edit, indent); if (cursor >= curs) cursor += edit->curs1 - p; p = edit->curs1; } else if (c == '\n') { edit_cursor_move (edit, p - edit->curs1); while (strchr ("\t ", edit_get_byte (edit, p))) { edit_delete (edit, 1); if (cursor > edit->curs1) cursor--; } p = edit->curs1; } } c = edit_get_byte (edit, p); if (c != t[i]) replace_at (edit, p, t[i]); } edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */ }