ref: 56c707043ba4521ca83525ec85d58eaa432ab743
parent: b1c218a33551408c615b22aa42a1327b1d8cc14a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jan 25 09:36:39 EST 2023
reformat
--- a/hx.c
+++ b/hx.c
@@ -12,7 +12,7 @@
#include <unistd.h>
#define OREAD O_RDONLY
#define nil NULL
-#define exits(s) do { return (s) != nil; } while (0)
+#define exits(s) do{ return (s) != nil; }while(0)
typedef size_t u64int;
#else
#include <u.h>
@@ -56,16 +56,16 @@
off = 0;
eof = 0;
sz = 0;
- for (addr = 0; eof == 0;) {
- if ((sz = read(fd, buf, Bufsz)) < 1) {
+ for(addr = 0; eof == 0;){
+ if((sz = read(fd, buf, Bufsz)) < 1){
section = 0;
break;
}
- if (pipeit > 0)
+ if(pipeit > 0)
write(pipeit, buf, sz);
- for (i = 0; i < sz; ) {
- if (lineoff == 0) {
+ for(i = 0; i < sz; ){
+ if(lineoff == 0){
s[off++] = b2h[((addr>>55) & 0x1fe)];
s[off++] = b2h[((addr>>55) & 0x1fe)+1];
s[off++] = b2h[((addr>>47) & 0x1fe)];
@@ -86,23 +86,23 @@
s[off++] = ' ';
}
- for (; i < sz && lineoff < 16; i++, addr++) {
- if (lineoff < 16)
+ for(; i < sz && lineoff < 16; i++, addr++){
+ if(lineoff < 16)
line[lineoff++] = buf[i];
s[off++] = b2h[(int)buf[i]*2+0];
s[off++] = b2h[(int)buf[i]*2+1];
s[off++] = ' ';
- if (lineoff == 8)
+ if(lineoff == 8)
s[off++] = ' ';
}
- if (lineoff == 16) {
+ if(lineoff == 16){
ascii:
s[off++] = ' ';
s[off++] = '|';
- for (lineoff = 0; lineoff < 16; lineoff++) {
+ for(lineoff = 0; lineoff < 16; lineoff++){
c = line[lineoff];
- if (c < 0x20 || c > 0x7e)
+ if(c < 0x20 || c > 0x7e)
c = '.';
s[off++] = c;
}
@@ -111,10 +111,10 @@
lineoff = 0;
}
- if (off >= (int)sizeof(s)-Linesz) {
+ if(off >= (int)sizeof(s)-Linesz){
writes:
- for (wroff = 0; wroff < off; wroff += r) {
- if ((r = write(pipeit+1, s+wroff, off-wroff)) < 0) {
+ for(wroff = 0; wroff < off; wroff += r){
+ if((r = write(pipeit+1, s+wroff, off-wroff)) < 0){
sz = -1;
break;
}
@@ -122,9 +122,9 @@
off = 0;
}
}
- if (section)
+ if(section)
break;
- if (sz == 0)
+ if(sz == 0)
continue;
#ifdef __linux__
@@ -134,27 +134,27 @@
goto writes;
}
- if (sz >= 0) {
- if (eof == 0 && lineoff > 0 && lineoff < 16) {
+ if(sz >= 0){
+ if(eof == 0 && lineoff > 0 && lineoff < 16){
eof = 1;
- if (lineoff == 8) {
+ if(lineoff == 8){
off--;
- if (off < 0)
+ if(off < 0)
off = 0;
}
- for (; lineoff < 16; lineoff++) {
+ for(; lineoff < 16; lineoff++){
line[lineoff] = 0;
s[off++] = ' ';
s[off++] = ' ';
s[off++] = ' ';
- if (lineoff == 8)
+ if(lineoff == 8)
s[off++] = ' ';
}
i = sz = 0;
goto ascii;
}
- for (wroff = 0; wroff < off; wroff += r) {
- if ((r = write(pipeit+1, s+wroff, off-wroff)) < 0) {
+ for(wroff = 0; wroff < off; wroff += r){
+ if((r = write(pipeit+1, s+wroff, off-wroff)) < 0){
sz = -1;
break;
}
@@ -161,7 +161,7 @@
}
}
- if (section) {
+ if(section){
write(pipeit+1, "\n", 1);
goto again;
}
@@ -178,7 +178,7 @@
{
int i, fd, res, opts;
- if ((buf = malloc(Bufsz)) == nil) {
+ if((buf = malloc(Bufsz)) == nil){
perror("buf");
exits("buf");
}
@@ -185,9 +185,9 @@
res = 0;
opts = 0;
- for (i = 1; i < argc && res == 0; i++) {
- if (argv[i][0] == '-' && argv[i][2] == 0) {
- switch (argv[i][1]) {
+ for(i = 1; i < argc && res == 0; i++){
+ if(argv[i][0] == '-' && argv[i][2] == 0){
+ switch(argv[i][1]){
case 's':
section = 1;
opts++;
@@ -202,23 +202,23 @@
write(2, "\n", 1);
exits("usage");
}
- if (opts == argc-1) {
+ if(opts == argc-1){
fd = 0;
goto dump;
}
continue;
}
- if ((fd = open(argv[i], OREAD)) < 0) {
+ if((fd = open(argv[i], OREAD)) < 0){
perror(argv[i]);
res = 1;
- } else {
- if (argc > 2+opts) {
+ }else {
+ if(argc > 2+opts){
write(pipeit+1, "hx ", 3);
write(pipeit+1, argv[i], strlen(argv[i]));
write(pipeit+1, "\n", 1);
}
dump:
- if ((res = hx(fd)) != 0)
+ if((res = hx(fd)) != 0)
perror(argv[1]);
close(fd);
}