void output_with_escape(const char *str) { unsigned i; a_putchar('"'); if (str != NULL) { if (strchr(str, '"') || strchr(str, '\\')) { for (i = 0; i < strlen(str); i ++) { if (str[i] == '"') a_printf("\\\""); else if (str[i] == '\\') a_printf("\\\\"); else a_putchar(str[i]); } } else { a_printf("%s", str); } } a_putchar('"'); }
int show_candidate(candidate_info *cand) { int i; int page; int index; if (cand->num == 0) { a_printf("( e )"); return 0; } index = cand->index; if (cand->disp_limit) page = index / cand->disp_limit; else page = 0; a_printf("( c "); a_printf(" ( %d . %d ) ", cand->index + 1, cand->num); for (i = cand->disp_limit * page; i < (cand->disp_limit ? cand->disp_limit * (page + 1) : cand->num); i ++) { if (i >= cand->num) break; if (i == index) a_printf("( t "); else a_printf("( nil "); output_with_escape(cand->cand_array[i].label); a_putchar(' '); output_with_escape(cand->cand_array[i].str); a_printf(" ) "); } a_printf(") "); return 1; }
int show_preedit(preedit *pe) { preedit_buffer *p; p = pe->head; if (p == NULL || pe->length == 0) { a_printf(" ( e ) "); return 0; } a_printf("( p "); while (p) { a_printf(" ( "); if (p->attr & UPreeditAttr_Reverse) a_putchar('r'); if (p->attr & UPreeditAttr_UnderLine) a_putchar('u'); if (p->attr & UPreeditAttr_Cursor) a_putchar('c'); if (p->attr & UPreeditAttr_Separator) a_putchar('s'); a_putchar('t'); a_putchar(' '); output_with_escape(p->str); a_printf(" ) "); p = p->next; } a_printf(" ) "); return 1; }