first commit
This commit is contained in:
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# minihex
|
||||||
|
|
||||||
|
A minimalist, single-file hexadecimal editor written in C with no dependencies (except the standard library). The program tries to be as simple as possible. Many bugs exist.
|
||||||
43
hex.c
Normal file
43
hex.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// TODO: Error checking
|
||||||
|
|
||||||
|
#define BYTES 1024
|
||||||
|
#define BYTES_PER_LINE 10
|
||||||
|
|
||||||
|
void print_hex(unsigned char* buf, int byteno)
|
||||||
|
{
|
||||||
|
for (int i=0; i<byteno; i++)
|
||||||
|
{
|
||||||
|
if (i % BYTES_PER_LINE == 0)
|
||||||
|
{
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
printf("%.2X ", buf[i]);
|
||||||
|
}
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
FILE* f = fopen(argv[1], "r");
|
||||||
|
unsigned char buf[BYTES];
|
||||||
|
int byteno = fread(buf, 1, BYTES, f);
|
||||||
|
print_hex(buf, byteno);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
char cmd;
|
||||||
|
int loc;
|
||||||
|
scanf("%c%d", &cmd, &loc);
|
||||||
|
|
||||||
|
if (cmd == 'p') print_hex(buf + loc, BYTES_PER_LINE);
|
||||||
|
if (cmd == 'e') scanf("%x", buf + loc);
|
||||||
|
if (cmd == 's') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
f = fopen(argv[1], "w");
|
||||||
|
fwrite(buf, 1, BYTES, f);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
9
makefile
Normal file
9
makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CC=gcc
|
||||||
|
CFLAGS=-g -Wall -Wextra -o
|
||||||
|
CFILES=hex.c
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(CC) $(CFILES) $(CFLAGS) minihex
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm minihex
|
||||||
Reference in New Issue
Block a user