myadm

Simple MySQL client for the terminal
git clone git://git.bitsmanent.org/myadm
Log | Files | Refs | README | LICENSE

commit fc530ad6f4fac6688c8ebbaab00a918b74526080
parent 92eb94c16445553b9ee58b1ad7121389449527fc
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed,  2 Mar 2016 17:32:10 +0100

Quote item fields.

Diffstat:
Mcore.c | 24+++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/core.c b/core.c @@ -13,6 +13,7 @@ #include <locale.h> #define LENGTH(X) (sizeof X / sizeof X[0]) +#define QUOTE(S) (stfl_ipool_fromwc(ipool, stfl_quote(stfl_ipool_towc(ipool, S)))) typedef union { int i; @@ -282,21 +283,23 @@ mysql_items(MYSQL_RES *res, Item **items) { /* XXX this function is a disaster */ void stfl_putitem(Item *item) { - char t[32]; /* XXX */ - char txt[256]; /* XXX */ + char t[32]; + char txt[256]; + char itm[128]; - if(item->nfields == 1) - snprintf(txt, sizeof txt, "listitem text:\"%s\"", item->fields[0]); + if(item->nfields == 1) { + snprintf(txt, sizeof txt, "listitem text:\"%s\"", QUOTE(item->fields[0])); + } else { - strncpy(txt, "listitem text:\"", sizeof txt); + itm[0] = '\0'; for(int i = 0; i < item->nfields; ++i) { snprintf(t, sizeof t, "%-8.16s", item->fields[i]); if(i) - strncat(txt, " | ", sizeof txt); - /* XXX What if strlen(all_fields) > sizeof txt? */ - strncat(txt, t, sizeof txt); + strncat(itm, " | ", sizeof itm); + strncat(itm, t, sizeof itm); } - strncat(txt, "\"", sizeof txt); + + snprintf(txt, sizeof txt, "listitem text:%s", QUOTE(itm)); } stfl_modify(selview->form, L"items", L"append", stfl_ipool_towc(ipool, txt)); } @@ -314,6 +317,9 @@ mysql_listview(MYSQL_RES *res) { stfl_modify(selview->form, L"items", L"replace_inner", L"vbox"); /* clear */ /* XXX actually in reverse order */ + if(selview->items) + selview->form = stfl_create(L"<items.stfl>"); + for(item = selview->items; item; item = item->next) stfl_putitem(item); }