ESH

Executive Shell
git clone http://git.omkov.net/ESH
Log | Tree | Refs | README | Download

AuthorJamozed <[email protected]>
Date2021-11-12 04:35:15
Commit1c707b2204375e3ef880317170ec9ba3a46ee9d9
Parent18443a4aaf76b7d9deb66008bbe9b2b6bc74d53c

Fix fallthrough with extended escape sequences

Diffstat

M CHANGELOG | 2 ++
M src/lineread.c | 62 ++++++++++++++++++++++++++++++++------------------------------
M src/main.c | 4 ----

3 files changed, 34 insertions, 34 deletions

diff --git a/CHANGELOG b/CHANGELOG
index 8412762..1fc0871 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
 0.5.1,
 * Implement pipe handling
 * Implement redirect handling
+* Remove repeated warning when eshrc is absent
+* Fix unintended fallthrough when handling extended escape sequences
 
 0.5.0, 2021-09-11
 * Rename OSH to ESH
diff --git a/src/lineread.c b/src/lineread.c
index 022c21b..c1440d3 100644
--- a/src/lineread.c
+++ b/src/lineread.c
@@ -123,6 +123,7 @@ ret:;
 }
 
 #define l h.a[h.ap]
+
 /* Dynamically read a line from stdin */
 static char *lineedit(void) {
 	register char *r;
@@ -146,31 +147,31 @@ static char *lineedit(void) {
 		// printf("%02X\n", c); continue;
 
 		switch (c) {
-		case '\x01': { line_move_home(&l);       } continue; // CTRL + A
-		case '\x02': { line_move_left(&l);       } continue; // CTRL + B
-		case '\x03': { line_reset(&l);          } continue; // CTRL + C
-		case '\x04': { r = NULL;               } goto ret; // CTRL + D
-		case '\x05': { line_move_end(&l);        } continue; // CTRL + E
-		case '\x06': { line_move_right(&l);      } continue; // CTRL + F
-		case '\x07': {} continue;                   // IGNORE CTRL + G
-		case '\x08': { line_backspace(&l);      } continue; // CTRL + H
-		case '\x09': {} continue;                   // IGNORE CTRL + I
-		case '\x0A': {} goto end;                          // CTRL + J
-		case '\x0B': { line_delete_end(&l);      } continue; // CTRL + K
-		case '\x0C': { clearscreen(&l);        } continue; // CTRL + L
-		case '\x0D': {} goto end;                 // ENTER or CTRL + M
-		case '\x0E': { /* Next history */      } continue; // CTRL + N
-		case '\x0F': {} goto end;                          // CTRL + O
-		case '\x10': { /* Prior history */     } continue; // CTRL + P
-		case '\x11': { /* Start output */      } continue; // CTRL + Q
-		case '\x12': {} continue;                   // IGNORE CTRL + R
-		case '\x13': { /* Stop output */       } continue; // CTRL + S
-		case '\x14': { /* Swap with prior */   } continue; // CTRL + T
-		case '\x15': { line_delete_home(&l);     } continue; // CTRL + U
-		case '\x16': { /* Insert char code */  } continue; // CTRL + V
+		case '\x01': { line_move_home(&l);        } continue; // CTRL + A
+		case '\x02': { line_move_left(&l);        } continue; // CTRL + B
+		case '\x03': { line_reset(&l);            } continue; // CTRL + C
+		case '\x04': { r = NULL;                  } goto ret; // CTRL + D
+		case '\x05': { line_move_end(&l);         } continue; // CTRL + E
+		case '\x06': { line_move_right(&l);       } continue; // CTRL + F
+		case '\x07': {} continue;                      // IGNORE CTRL + G
+		case '\x08': { line_backspace(&l);        } continue; // CTRL + H
+		case '\x09': {} continue;                      // IGNORE CTRL + I
+		case '\x0A': {} goto end;                             // CTRL + J
+		case '\x0B': { line_delete_end(&l);       } continue; // CTRL + K
+		case '\x0C': { clearscreen(&l);           } continue; // CTRL + L
+		case '\x0D': {} goto end;                    // ENTER or CTRL + M
+		case '\x0E': { /* Next history */         } continue; // CTRL + N
+		case '\x0F': {} goto end;                             // CTRL + O
+		case '\x10': { /* Prior history */        } continue; // CTRL + P
+		case '\x11': { /* Start output */         } continue; // CTRL + Q
+		case '\x12': {} continue;                      // IGNORE CTRL + R
+		case '\x13': { /* Stop output */          } continue; // CTRL + S
+		case '\x14': { /* Swap with prior */      } continue; // CTRL + T
+		case '\x15': { line_delete_home(&l);      } continue; // CTRL + U
+		case '\x16': { /* Insert char code */     } continue; // CTRL + V
 		case '\x17': { line_delete_word_home(&l); } continue; // CTRL + W
-		case '\x18': {} continue;                   // IGNORE CTRL + X
-		case '\x19': { /* Paste deleted */     } continue; // CTRL + Y
+		case '\x18': {} continue;                      // IGNORE CTRL + X
+		case '\x19': { /* Paste deleted */        } continue; // CTRL + Y
 		case '\x1B': switch ((c = fgetc(stdin))) {
 			case 'b': { line_move_word_home(&l);  } continue; // ALT + B
 			case 'd': { line_delete_word_end(&l); } continue; // ALT + D
@@ -188,8 +189,8 @@ static char *lineedit(void) {
 			}
 			default:  {} continue;
 		}
-		case '\x7F': { line_backspace(&l);      } continue; // BACKSPACE
-		default:     { line_insert(&l, c);      } continue;
+		case '\x7F': { line_backspace(&l);        } continue; // BACKSPACE
+		default:     { line_insert(&l, c);        } continue;
 		}
 	}
 
@@ -198,22 +199,23 @@ end:;
 ret:;
 	tcrestore(); fputc('\n', stdout); return r;
 }
+
 #undef l // h.a[h.ap]
 
 /* Handle an extended ^[ sequence */
 static void line_esc(struct line *l, register int c) {
 	switch (c) {
 	case '2': switch ((c = fgetc(stdin))) {
-		case '~': { /* Insert char code */ break; } // INSERT
+		case '~': { /* Insert char code */ } return; // INSERT
 	}
 	case '3': switch ((c = fgetc(stdin))) {
-		case '~': { line_delete(l); break; } // DELETE
+		case '~': { line_delete(l); } return; // DELETE
 	}
 	case '5': switch ((c = fgetc(stdin))) {
-		case '~': { hist_move_home(&h); break; } // PAGE UP
+		case '~': { hist_move_home(&h); } return; // PAGE UP
 	}
 	case '6': switch ((c = fgetc(stdin))) {
-		case '~': { hist_move_end(&h); break; } // PAGE DOWN
+		case '~': { hist_move_end(&h); } return; // PAGE DOWN
 	}
 	}
 }
diff --git a/src/main.c b/src/main.c
index f536fd9..a59beed 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,10 +30,6 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
-/*
-	FIXME: Every second press of the delete key prints garbage to the terminal.
-*/
-
 #include "conf.h"
 #include "esh.h"
 #include "lineread.h"