format chr2img.c, weirdly

This commit is contained in:
Sigrid Solveig Haflínudóttir 2021-06-23 17:33:14 +02:00
parent bdde0cc43e
commit 62d809147b
2 changed files with 54 additions and 41 deletions

View File

@ -12,6 +12,7 @@ clang-format -i src/devices/mpu.c
clang-format -i src/uxnasm.c clang-format -i src/uxnasm.c
clang-format -i src/uxnemu.c clang-format -i src/uxnemu.c
clang-format -i src/uxncli.c clang-format -i src/uxncli.c
clang-format -i src/chr2img.c
echo "Cleaning.." echo "Cleaning.."
rm -f ./bin/uxnasm rm -f ./bin/uxnasm

View File

@ -21,7 +21,11 @@ typedef struct {
static char *argv0; static char *argv0;
#define fprint(x, arg...) fprintf(stderr, arg) #define fprint(x, arg...) fprintf(stderr, arg)
#define exits(s) exit(s == NULL ? 0 : 1) #define exits(s) exit(s == NULL ? 0 : 1)
#define sysfatal(s) do{ fprintf(stderr, "error\n"); exit(1); }while(0) #define sysfatal(s) \
do { \
fprintf(stderr, "error\n"); \
exit(1); \
} while(0)
#define ARGBEGIN \ #define ARGBEGIN \
for(((argv0 = *argv)), argv++, argc--; \ for(((argv0 = *argv)), argv++, argc--; \
argv[0] && argv[0][0] == '-' && argv[0][1]; \ argv[0] && argv[0][0] == '-' && argv[0][1]; \
@ -29,15 +33,19 @@ static char *argv0;
char *_args, _argc, *_argt; \ char *_args, _argc, *_argt; \
_args = &argv[0][1]; \ _args = &argv[0][1]; \
if(_args[0] == '-' && _args[1] == 0) { \ if(_args[0] == '-' && _args[1] == 0) { \
argc--; argv++; break; \ argc--; \
argv++; \
break; \
} \ } \
_argc = 0; \ _argc = 0; \
while(*_args && (_argc = *_args++)) \ while(*_args && (_argc = *_args++)) \
switch(_argc) switch(_argc)
#define ARGEND }; #define ARGEND \
} \
;
#define EARGF(x) \ #define EARGF(x) \
(_argt=_args, _args="",\ (_argt = _args, _args = "", (*_argt ? _argt : argv[1] ? (argc--, *++argv) \
(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0))) : ((x), abort(), (char *)0)))
#endif #endif
static int hor = 44, ver = 26, bpp = 1; static int hor = 44, ver = 26, bpp = 1;
@ -84,6 +92,7 @@ getcoli(int x, int y, u8int *p)
static int static int
writebmp(int w, int h, u32int *p) writebmp(int w, int h, u32int *p)
{ {
/* clang-format off */
u8int hd[14+40+4*4] = { u8int hd[14+40+4*4] = {
'B', 'M', 'B', 'M',
0, 0, 0, 0, /* file size */ 0, 0, 0, 0, /* file size */
@ -107,6 +116,7 @@ writebmp(int w, int h, u32int *p)
0xff, 0, 0, 0, 0xff, 0, 0, 0,
}; };
int sz; int sz;
/* clang-format on */
sz = 14 + 40 + 4 * 4 + 4 * w * h; sz = 14 + 40 + 4 * 4 + 4 * w * h;
hd[2] = sz; hd[2] = sz;
@ -140,7 +150,8 @@ main(int argc, char **argv)
{0xffffff00, 0xffffffff, 0x72dec2ff, 0x666666ff}, {0xffffff00, 0xffffffff, 0x72dec2ff, 0x666666ff},
}; };
ARGBEGIN{ ARGBEGIN
{
case '1': case '1':
bpp = 1; bpp = 1;
break; break;
@ -152,7 +163,8 @@ main(int argc, char **argv)
break; break;
default: default:
usage(); usage();
}ARGEND }
ARGEND
if((p = readall(0, &sz)) == nil) if((p = readall(0, &sz)) == nil)
sysfatal("%r"); sysfatal("%r");