From 9fab7fe63d89f489dfc0ec72c3559fdca26e185b Mon Sep 17 00:00:00 2001 From: gunboy001 Date: Thu, 28 Nov 2019 09:43:51 +0100 Subject: [PATCH] clarified constants --- .sconsign.dblite | Bin 3124 -> 3124 bytes src/ste.c | 43 ++++++++++++++++++++++++++++++------------- src/ste.o | Bin 12952 -> 13200 bytes 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.sconsign.dblite b/.sconsign.dblite index 5c29a0d6e5450cfab05389c405d9b4569af38b6c..ac2f1376f14b30d9dd3d0bfa894c91fbd93817e5 100644 GIT binary patch delta 375 zcmajby-EW?5C?FLIYlplAQB=r@dHUf!tGu5i z4%R|a`4D1j<*T>^BzBfN>~CiNGpS4}Z?E~FHT;gjY3IO=sw6a;=%z_TK#kFqF(MP? z^F(mXDZ9ffD0W6c_LYC}5B@kANUe;=IH6JsA}nT7`^FDK88D@=XWex+avG%>gK2U6 z;p{Gm-zB2F>fiTpGpaJhLn)fn4(6PAGz>%A&`^;io~IbWEpR(9-dnEE&mvg&Zv9UTku6(<6v*s2MXj2#!J) ze}S{mPW}jY7ypI3mx9#I@f^+r?|VkoQT6S$M0c*gBv|bt*g-845pjh_6`_p#iff{U zc14T3VaSRyOBc7+Z%M%mC7Y@gDusgls)?A}7sbJi{ z6gT8xOdjVY?0$i3hMKu>(sIyWX7gi)5 q!K%dLG)kku8r #include #include @@ -10,10 +13,18 @@ /* defines */ #define CTRL(k) ((k) & 0x1f) // Control mask modifier #define STAT_SIZE 128 -#define _XOPEN_SOURCE_EXTENDED -#define _GNU_SOURCE #define SBUF_SIZE 2048 +#define MODE_MASK 0x1 +#define COMMAND_MASK 0x06 + +#define NORMAL_M 0x0 +#define COMMAND_M 0x1 + +#define FIND_C 0x1 + +#define MODIFIED 0x80 + // Search buffer typedef struct sbuf { char c[SBUF_SIZE]; @@ -84,6 +95,7 @@ static void updateInfo (void); static int whatsThat (void); static void insert (sbuf *buf, int c); static inline void flush (sbuf *buf); +static void pop (sbuf *buf); /* --------------------------------- main ------------------------------------ */ int main (int argc, char *argv[]) @@ -125,24 +137,24 @@ int main (int argc, char *argv[]) break; case (KEY_BACKSPACE): - handleDel(0); - break; - case (KEY_DC): - handleDel(1); + if ((t.mode_b & MODE_MASK) == NORMAL_M) + handleDel(c); + else + pop(&t.search_buffer); break; case (KEY_ENTER): case (10): case ('\r'): - if ((t.mode_b & 0x1) == 0x0) { + if ((t.mode_b & MODE_MASK) == NORMAL_M) { rowAddRow(&rows, t.cur.y, t.cur.x); t.cur.y++; t.cur.x = 0; } else { editorFind(t.search_buffer.c, &t.cur.y, &t.cur.x); // Toggle mode - t.mode_b ^= 0x1; + t.mode_b ^= MODE_MASK; flush (&t.search_buffer); } break; @@ -157,13 +169,14 @@ int main (int argc, char *argv[]) case (CTRL('f')): // Toggle mode - t.mode_b ^= 0x1; + t.mode_b ^= MODE_MASK; flush (&t.search_buffer); break; default: - if ((t.mode_b & 0x1) == 0x0) { + if ((t.mode_b & MODE_MASK) == NORMAL_M) { + t.mode_b |= MODIFIED; if (c == KEY_STAB) c = '\t'; rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); t.cur.x++; @@ -259,7 +272,7 @@ void drawScreen () drawLines(); /* draw the bar */ drawBar( - ((t.mode_b & 0x1) == 0) ? t.statusbar : + ((t.mode_b & MODE_MASK) == NORMAL_M) ? t.statusbar : t.search_buffer.c ); /* move back to the cursor position */ @@ -512,7 +525,7 @@ int whatsThat (void) { void handleDel (int select) { - if (!select) { + if (select == KEY_BACKSPACE) { if (t.cur.x <= 0 && t.cur.y > 0) { t.cur.x = rows.rw[t.cur.y - 1].size; rowAppendString(&rows.rw[t.cur.y - 1], rows.rw[t.cur.y].chars, rows.rw[t.cur.y].size); @@ -528,7 +541,7 @@ void handleDel (int select) if (rowDeleteChar(&rows.rw[t.cur.y], 0, t.cur.x)) t.cur.x--; } - } else { + } else if (select == KEY_DC) { if (t.cur.x >= rows.rw[t.cur.y].size) { rowAppendString(&rows.rw[t.cur.y], rows.rw[t.cur.y + 1].chars, rows.rw[t.cur.y + 1].size); rowDeleteRow(&rows, t.cur.y + 1); @@ -596,4 +609,8 @@ void flush (sbuf *buf) buf->num = 0; } +void pop (sbuf *buf) +{ + if (buf->num) buf->c[--(buf->num)] = '\0'; +} /*--------------------------------- testing ------------------------------------*/ diff --git a/src/ste.o b/src/ste.o index f9c714b404e26f253ca10697ebb629fc5a44d15b..07b146c9a7a62408a2d3ce1fbd309e0e778a9099 100644 GIT binary patch delta 3695 zcmZ`*3v8R!6~5Pb+0Nt7qseb4X_G*lrfFUdq^(Pw;Noh(A*B!6tuQ*s(xe1}v~(_8 zH;p87T-7ozsgA^om_#x*_D1b2^(Cz&84zeeOTs3x7h5_CbqXj}X>dD+ch0r{_1033 zbkDu_JMVkX|2Wn&x^J}Bu&wDt-9vovs);dA@M)tKYGp{5iD`k?HUES%axn+j)9z{u zft{iL>dMa0-f9a$l>}*_l{ED#6(cmWvu0#kAkrE5v@`Hg($$pai^aWmE$Br{|HNSa zl`>sl^DUHeZ?1CET@r6Id!uc+-cPi^KZW6yFcce}F}z}emkhJq2nW(u=e(W8nCmph zAibk-JZ;2e%w)_lqlD7InQk*=Wx?L`ZyPpeg#VIW%ngT);l+%Q!IpsrgIk;&C*|3L z2F84`TxH}udU^UgzF2|cUx^r8&aU3t+o)&eyqB~`PGz9d*PUO(jrRx6#|ZNu#+dG) z4b7P=l%VgEs30ErIj5#yW{y^Wf&?lRumq;0^C>5BN zS@C}Zb==BHC&`22MqEqNT=84rRrA`d7p@CUXO_q$2lnQpC1HW=qIay4BmZmVRGL*wN&3C5v#c=U!V`*go zvv$&*C?gwanI@Lq$Q`rFk%kytGFDo$QQH;BjHKagpNKq&uI+P?2V-zLr@`_gbgp$@ z&?e_IJZW37;oiAop(BPba~?08M`2)AbIcsLboWTyn;FP}@8zz1wD@y$=z9yt`FP~3 zOYykYJ>?3n(&b|d6Ife(|3g-FW zQjQ$s(4SXd7(j__0uyi!AyfPZm*7`<73no}1_4u*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