From 9e409e363306ad24b1897a06ac5a499901d87c4b Mon Sep 17 00:00:00 2001 From: ElectricAlchemist Date: Tue, 29 Oct 2019 21:45:56 +0100 Subject: [PATCH] cleanup, added cur.xx and cur.yy, bug fixes --- ste | Bin 22168 -> 22168 bytes ste.c | 96 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/ste b/ste index 11f48d24ce9781e9c6af50990af137969f161b51..6f516f9b57ff5d661c971c41a178a01e695c9c91 100755 GIT binary patch delta 3859 zcmY*c4{%h)8Gn0s4=*9f3n53N6%*>ElV}1t z4P5NI)U2Bq(3>gP)+u({PHWXhg9xo+5}JfW3nWa%`Vaqs?}AByY7&L;`rCJj+Bb8% z-~avg+wc2!Z`TWC*9)Z8OEO;fNzV6rat4`~IqphhP4S#I2TtP*-`wq%I#U&7@O!MEIEX%7}ctsYl9?f4QjOgY){u151!(Svw zLQql)8^oluVV!+W*`W3Ni?&U9y}u~gmRIUJIwSdE-lJq@@|Kx%GEapiDbm=kv}7j} zGlTIrfwFOG2J0@z8fN%6z)KHNzS66%*3IHOfU2t~pULDc00ZsH47nPBRe8a-)%EMC zIr~YV6h2ibg^MN1!!rcC3~Zi#6+j-;#3=t5W9Y2XywHmU`^-m3={eFFik~%awAr{4 z>15dxi@=d>j1lhfb6*BDG@d;Of*LxiH1}Tuob{Lw*b#FTQCYsf^teWjsG&2eqJ2XS zG5Huo=`Lz!HBjzm;Z~sJI1BF+WYcq~aX@MDVR_1_H!wg=mC!ipKAo==YLaAh63RMg zsJr%ZYP6GvP)6MstbeTE_}Fc(%}n#o)P2T$F=35|%P<8-xvv?s^*d}=kVf8XHl~8%b4c)H)@YJiPsT@@vFd_)dZX#zUCI z%EOMFJHFD)-%De`Cc!m5M?;%)mF6|JI6O10uuM$u%>@Yg)zwATPUxlPLtx_$SStmS z2bYV{*N9O!%Qs+B-T8jYOnWj7xbPeWU_JK@l7`nvQKQRa{=&X^@nU>zV9wFv27I-j zvrZnK4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Ah(bDi*qFNF<}ruoNbl5@ z;+BbeYFg_`9K4};CHyGYbjqx#gylRtrBz?B2G>=LH^|au@`Lg+`62n?^jo-3R~Vbw z!gtjDo0-kHOT6}eNU_estX4@UOMHFCwU!8Ch#)jXnyX=ElxyW>bChqG1|LSh=R*r3 zfWTz>&i`>lB_GRS@vs|yozWgp-9xA>*9igU? zBqkOp^qO1aYUfG8evLUE^S^)v*=pk1AtvHujN2-FS+@dxcFnQVtb+~VU6s9wNy>f@ zq)bb!>2{Z~N5-721p1d)nE_|@DP)G-z#eE~Y4WbpqSCwY&rDvdk;8JmM!u2jWOAim zwJIt>UZj^_MOk_5MeS=#7w5iQxr6^_@-LNB{R_~GUPa2k!d!w|Z2@X}WinlP?D0ns zw{7@6a?Wx7z>1>Am%qss^%b`XHNFzdUE?d;D9XOd7sn~SDs#NzTj2UQ*H@+ZDrH|8 zIBI;wkf`x_=3S?N4$l9f*IdV;vvK**y)8Lq=8Qb{;8lUWam;bHB$v$$1a|PkPTseR z*L)rP1DIvs4rU4a6#RY#chars; // reallocate mem and inc size @@ -400,15 +402,15 @@ void rowAddChar (row *rw, char c) // WIP rw->size++; // copy bf cursor - for (i = 0; i < cur; i++) { + for (i = 0; i < t.cur.xx; i++) { rw->chars[i] = s[i]; } // add at cursor - rw->chars[cur++] = c; + rw->chars[t.cur.xx++] = c; //copy after cursor - for (i = cur; i < rw->size + 1; i++) { + for (i = t.cur.xx; i < rw->size + 1; i++) { rw->chars[i] = s[i - 1]; } @@ -420,33 +422,32 @@ void rowAddChar (row *rw, char c) // WIP void rowDeleteChar (row *rw, int m) // WIP { - int cur = t.cur.x + t.cur.off_x; char *s = rw->chars; //Do not delete NULL char - if (s[cur - 1] == '\0' && cur) return; - if (!cur && !m) return; - if (s[cur] == '\0' && m) return; + if (s[t.cur.xx - 1] == '\0' && t.cur.xx) return; + if (!t.cur.xx && !m) return; + if (s[t.cur.xx] == '\0' && m) return; rw->chars = malloc(rw->size); rw->size--; // Backspace if (!m) { - for (int i = 0; i < cur - 1; i++) + for (int i = 0; i < t.cur.xx - 1; i++) rw->chars[i] = s[i]; - for (int i = cur; i < rw->size + 1; i++) + for (int i = t.cur.xx; i < rw->size + 1; i++) rw->chars[i - 1] = s[i]; t.cur.x--; // Delete } else { - if(cur) { - for (int i = 0; i < cur; i++) + if(t.cur.xx) { + for (int i = 0; i < t.cur.xx; i++) rw->chars[i] = s[i]; } - for (int i = cur; i < rw->size + 1; i++) + for (int i = t.cur.xx; i < rw->size + 1; i++) rw->chars[i] = s[i + 1]; } @@ -464,40 +465,46 @@ void cursorMove (int a) if (t.cur.x <= 0 && !t.cur.off_x) { if (t.cur.y) { t.cur.y--; - t.cur.x = rows.rw[t.cur.y + t.cur.off_y].size; + t.cur.yy--; + t.cur.x = rows.rw[t.cur.yy].size; } } else t.cur.x--; break; case (KEY_RIGHT): - if (t.cur.x + t.cur.off_x >= rows.rw[t.cur.y + t.cur.off_y].size) { - if (t.cur.y + t.cur.off_y < rows.rownum - 1) { + if (t.cur.xx >= rows.rw[t.cur.yy].size) { + if (t.cur.yy < rows.rownum - 1) { t.cur.y++; + t.cur.yy++; if (t.cur.off_x) t.cur.off_x = 0; - t.cur.x = rows.rw[t.cur.y + t.cur.off_y].size; + t.cur.x = rows.rw[t.cur.yy].size; } } else t.cur.x++; break; case (KEY_UP): - if (t.cur.y + t.cur.off_y > 0) { - if (t.cur.y) t.cur.y--; - if (t.cur.x + t.cur.off_x > rows.rw[t.cur.y + t.cur.off_y].size) { + if (t.cur.yy > 0) { + if (t.cur.y) { + t.cur.y--; + t.cur.yy--; + if (t.cur.xx > rows.rw[t.cur.yy].size) { if (t.cur.off_x) t.cur.off_x = 0; - t.cur.x = rows.rw[t.cur.y + t.cur.off_y].size; + t.cur.x = rows.rw[t.cur.yy].size; } } break; case (KEY_DOWN): - if (t.cur.y + t.cur.off_y < rows.rownum - 1) { + if (t.cur.yy < rows.rownum - 1) { t.cur.y++; - if (t.cur.x + t.cur.off_x > rows.rw[t.cur.y + t.cur.off_y].size) { + t.cur.yy++; + if (t.cur.xx > rows.rw[t.cur.yy].size) { if (t.cur.off_x) t.cur.off_x = 0; - t.cur.x = rows.rw[t.cur.y + t.cur.off_y].size; + t.cur.x = rows.rw[t.cur.yy].size; } } break; + } } } @@ -527,16 +534,16 @@ void updateScroll (void) t.cur.x = 0; } /* convert the cursor from real to render */ - int ln = t.cur.y + t.cur.off_y; - t.cur.r_x = curRealToRender(&rows.rw[ln], t.cur.x); + t.cur.yy = t.cur.y + t.cur.off_y; + t.cur.xx = t.cur.x + t.cur.off_x; + t.cur.r_x = curRealToRender(&rows.rw[t.cur.yy], t.cur.x); } /*---------------------------------- scroll ------------------------------------*/ /* See whats under the cursor (memory) */ int whatsThat (void) { - int ln = t.cur.y + t.cur.off_y; - int c = rows.rw[ln].chars[t.cur.x + t.cur.off_x]; + int c = rows.rw[t.cur.yy].chars[t.cur.xx]; switch (c) { case ('\t'): return '^'; @@ -556,7 +563,6 @@ int whatsThat (void) { void rowAddRow (int pos) // WIP; TO DOCUMENT { - int cur_x = t.cur.x + t.cur.off_x; char *s = NULL; // Move away other lines //copy old last line to new space @@ -566,26 +572,20 @@ void rowAddRow (int pos) // WIP; TO DOCUMENT rowCpy(&rows.rw[last], &rows.rw[last - 1]); } - //if (!cur_x) cur_x = rows.rw[pos].size; - //if (rows.rw[pos].chars[cur_x] == '\0') { - // cur_x = 0; - // t.cur.x = 0; - //} - //copy previous row - int l = rows.rw[pos].size - cur_x; + int l = rows.rw[pos].size - t.cur.xx; s = malloc(l + 1); - memcpy(s, &rows.rw[pos].chars[cur_x], l); + memcpy(s, &rows.rw[pos].chars[t.cur.xx], l); s[l] = '\0'; // Delete prev row until cursor - char *p = malloc(cur_x + 1); - memcpy(p, rows.rw[pos].chars, cur_x); - p[cur_x] = '\0'; + char *p = malloc(t.cur.xx + 1); + memcpy(p, rows.rw[pos].chars, t.cur.xx); + p[t.cur.xx] = '\0'; rowFree(&rows.rw[pos]); - rows.rw[pos].chars = malloc(cur_x + 1); - memcpy(rows.rw[pos].chars, p, cur_x + 1); + rows.rw[pos].chars = malloc(t.cur.xx + 1); + memcpy(rows.rw[pos].chars, p, t.cur.xx + 1); free(p); - rows.rw[pos].size = cur_x; + rows.rw[pos].size = t.cur.xx; updateRender(&rows.rw[pos]); if (pos != rows.rownum - 1) {