shithub: vexed

Download patch

ref: 5a2d78f14e4c179c9ec1e337e184def382259463
parent: 864748af0fa9ad18dd5b94fe36962d7706763d1b
author: phil9 <[email protected]>
date: Fri Sep 23 10:00:28 EDT 2022

add edition using binary input (thanks grimmware)

--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@
 `i` inserts a byte before the current selection.  
 `p` inserts a byte after the current selection.  
 `x` deletes the currently selected byte.  
+`.` edit selected byte in binary.  
 `u` undo last edit.  
 `r` redo last undo'ed edit.  
 `s` save file.  
--- a/vexed.c
+++ b/vexed.c
@@ -31,6 +31,7 @@
 	Msnarfhex,
 	Msnarfascii,
 	Mdecode,
+	Mbinary,
 	Minsert,
 	Mappend,
 	Mdelete,
@@ -44,6 +45,7 @@
 	"snarf hex",
 	"snarf ascii",
 	"decode",
+	"binary",
 	"insert",
 	"append",
 	"delete",
@@ -273,6 +275,28 @@
 }
 
 void
+xbinary(void)
+{
+	char tmp[9] = {0};
+	char msg[19] = "Binary (xxxxxxxx):";
+	char out = 0;
+	int n, i;
+
+	for(i = 0; i < 8; i++)
+		msg[15 - i] = (buf.data[sel] & 1 << i) ? '1' : '0';
+	n = enter(msg, tmp, sizeof tmp, mctl, kctl, nil);
+	if(n <= 0)
+		return;
+	for(i = 0; i < 8 && i < n; i++){
+		if(tmp[7-i] != '0')
+			out |= 1 << i;
+	}
+	buf.data[sel] = out;
+	modified = 1;
+	redraw();
+}
+
+void
 xlook(void)
 {
 	char tmp[255] = {0};
@@ -536,6 +560,9 @@
 	case Mappend:
 		xappend();
 		break;
+	case Mbinary:
+		xbinary();
+		break;
 	case Mlook:
 		xlook();
 		break;
@@ -712,6 +739,9 @@
 	case 'p':
 	case 'P':
 		xappend();
+		break;
+	case '.':
+		xbinary();
 		break;
 	case 'l':
 	case 'L':