first commit

This commit is contained in:
xamidev
2024-06-02 09:48:26 +02:00
commit 7d971f6f37
4 changed files with 55 additions and 0 deletions

3
README.md Normal file
View 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
View 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
View File

@@ -0,0 +1,9 @@
CC=gcc
CFLAGS=-g -Wall -Wextra -o
CFILES=hex.c
all:
$(CC) $(CFILES) $(CFLAGS) minihex
clean:
rm minihex

BIN
minihex Executable file

Binary file not shown.