Skip to content

Commit

Permalink
2.1.1
Browse files Browse the repository at this point in the history
Added on-the-fly ASCII/UTF-8 switching; define is now used as a default
  • Loading branch information
PQCraft authored Jan 26, 2022
1 parent cf3dcbb commit b8f5ae6
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions qhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
/* */
/* ---------------------------------------------------------------- */

const char* VER = "2.1";
const char* VER = "2.1.1";

#ifndef QHD_ASCII
#define QHD_ASCII 0 // Enable/disable 7-bit ASCII mode
#define QHD_ASCII 0 // Enable/disable 7-bit ASCII mode by default
#endif

#include <stdio.h>
Expand All @@ -34,6 +34,7 @@ bool opt_showhex = true;
bool opt_showchr = true;
bool opt_onlyfile = false;
bool opt_color = false;
bool opt_ascii = QHD_ASCII;

void aperror(char* str) {
fprintf(stderr, "%s: ", argv[0]);
Expand Down Expand Up @@ -83,11 +84,11 @@ void setcolor(int code) {

void putdiv() {
setcolor(COLOR_DIV);
#if defined(QHD_ASCII) && QHD_ASCII
if (opt_ascii) {
putchar('|');
#else
} else {
printf("│");
#endif
}
}

void parsecolors(char* instr) {
Expand Down Expand Up @@ -135,18 +136,20 @@ void parsecolors(char* instr) {
}

void puthelp() {
printf("Quick HexDump version %s\n\n", VER);
printf("USAGE: %s [OPTION]... FILE\n\n", argv[0]);
puts("OPTIONS:");
printf("Quick HexDump version %s\n", VER);
printf("\nUSAGE: %s [OPTION]... FILE\n", argv[0]);
puts("\nOPTIONS:");
puts(" --help Display help text and exit");
puts(" --version Display version info and exit");
puts(" -b, --bar Display a column bar");
puts(" -e, --emptyline Display an empty line if the file size is zero");
puts(" -p, --hide-pos Hide the position column");
puts(" -h, --hide-hex Hide the hexadecimal column");
puts(" -c, --hide-chr Hide the character column");
puts(" -C, --color Enable color escape codes\n");
puts("ENVIRONMENT:");
puts(" -C, --color Enable color escape codes");
puts(" -a, --ascii Use only 7-bit ASCII characters");
puts(" -A, --ext-char Use UTF-8 characters");
puts("\nENVIRONMENT:");
puts(" QHD_COLORS: Sets the pallette to use when color escape codes are enabled");
puts(" Format is key=value separated by colons");
puts(" Values are the middle parts of a color escape code (put between \"\\e[\" and \"m\")");
Expand Down Expand Up @@ -194,6 +197,10 @@ bool readopt() {
opt_showchr = false;
} else if (!strcmp(opt, "color")) {
opt_color = true;
} else if (!strcmp(opt, "ascii")) {
opt_ascii = true;
} else if (!strcmp(opt, "ext-char")) {
opt_ascii = false;
} else {
errno = EINVAL;
aperror(argv[i]);
Expand All @@ -214,6 +221,10 @@ bool readopt() {
opt_showchr = false;
} else if (opt == 'C') {
opt_color = true;
} else if (opt == 'a') {
opt_ascii = true;
} else if (opt == 'A') {
opt_ascii = false;
} else {
char tmp[3] = {'-', 0, 0};
tmp[1] = opt;
Expand Down Expand Up @@ -331,11 +342,11 @@ int main(int _argc, char** _argv) {
} else {
setcolor(COLOR_CHRN);
if (i < bread) {
#if defined(QHD_ASCII) && QHD_ASCII
if (opt_ascii) {
putchar('.');
#else
} else {
printf("·");
#endif
}
} else {
putchar(' ');
}
Expand Down

0 comments on commit b8f5ae6

Please sign in to comment.