Cleanup code of rgbfix, rgbgfx and external libs

Follow Linux kernel coding style.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
Antonio Niño Díaz
2018-01-01 16:52:43 +01:00
parent f41c532400
commit 2ffaf72e39
17 changed files with 289 additions and 289 deletions

View File

@@ -19,10 +19,10 @@
#include <unistd.h>
#include "extern/version.h"
#include "gfx/main.h"
static void
usage(void)
static void print_usage(void)
{
printf(
"usage: rgbgfx [-DFfhPTuVv] [-d #] [-o outfile] [-p palfile] [-t mapfile]\n"
@@ -30,8 +30,7 @@ usage(void)
exit(1);
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int ch, size;
struct Options opts = {0};
@@ -41,9 +40,8 @@ main(int argc, char *argv[])
char *ext;
const char *errmsg = "Warning: The PNG's %s setting is not the same as the setting defined on the command line.";
if (argc == 1) {
usage();
}
if (argc == 1)
print_usage();
opts.mapfile = "";
opts.palfile = "";
@@ -51,8 +49,8 @@ main(int argc, char *argv[])
depth = 2;
while((ch = getopt(argc, argv, "Dd:Ffho:Tt:uPp:Vvx:")) != -1) {
switch(ch) {
while ((ch = getopt(argc, argv, "Dd:Ffho:Tt:uPp:Vvx:")) != -1) {
switch (ch) {
case 'D':
opts.debug = true;
break;
@@ -95,22 +93,21 @@ main(int argc, char *argv[])
opts.trim = strtoul(optarg, NULL, 0);
break;
default:
usage();
print_usage();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
if (argc == 0) {
usage();
}
if (argc == 0)
print_usage();
opts.infile = argv[argc - 1];
if (depth != 1 && depth != 2) {
if (depth != 1 && depth != 2)
errx(1, "Depth option must be either 1 or 2.");
}
colors = 1 << depth;
input_png_file(opts, &png);
@@ -121,82 +118,77 @@ main(int argc, char *argv[])
get_text(&png);
if (png.horizontal != opts.horizontal) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "horizontal");
}
if (opts.hardfix) {
if (opts.hardfix)
png.horizontal = opts.horizontal;
}
}
if (png.horizontal) {
opts.horizontal = png.horizontal;
}
if (png.horizontal)
opts.horizontal = png.horizontal;
if (png.trim != opts.trim) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "trim");
}
if (opts.hardfix) {
if (opts.hardfix)
png.trim = opts.trim;
}
}
if (png.trim) {
if (png.trim)
opts.trim = png.trim;
}
if (opts.trim > png.width / 8 - 1) {
errx(1, "Trim (%i) for input png file '%s' too large (max: %i)", opts.trim, opts.infile, png.width / 8 - 1);
errx(1, "Trim (%i) for input png file '%s' too large (max: %i)",
opts.trim, opts.infile, png.width / 8 - 1);
}
if (strcmp(png.mapfile, opts.mapfile) != 0) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "tilemap file");
}
if (opts.hardfix) {
if (opts.hardfix)
png.mapfile = opts.mapfile;
}
}
if (!*opts.mapfile) {
if (!*opts.mapfile)
opts.mapfile = png.mapfile;
}
if (png.mapout != opts.mapout) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "tilemap file");
}
if (opts.hardfix) {
if (opts.hardfix)
png.mapout = opts.mapout;
}
}
if (png.mapout) {
if (png.mapout)
opts.mapout = png.mapout;
}
if (strcmp(png.palfile, opts.palfile) != 0) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "palette file");
}
if (opts.hardfix) {
if (opts.hardfix)
png.palfile = opts.palfile;
}
}
if (!*opts.palfile) {
if (!*opts.palfile)
opts.palfile = png.palfile;
}
if (png.palout != opts.palout) {
if (opts.verbose) {
if (opts.verbose)
warnx(errmsg, "palette file");
}
if (opts.hardfix) {
if (opts.hardfix)
png.palout = opts.palout;
}
}
if (png.palout) {
opts.palout = png.palout;
}
if (png.palout)
opts.palout = png.palout;
if (!*opts.mapfile && opts.mapout) {
if ((ext = strrchr(opts.infile, '.')) != NULL) {
ext = strrchr(opts.infile, '.');
if (ext != NULL) {
size = ext - opts.infile + 9;
opts.mapfile = malloc(size);
strncpy(opts.mapfile, opts.infile, size);
@@ -210,7 +202,9 @@ main(int argc, char *argv[])
}
if (!*opts.palfile && opts.palout) {
if ((ext = strrchr(opts.infile, '.')) != NULL) {
ext = strrchr(opts.infile, '.');
if (ext != NULL) {
size = ext - opts.infile + 5;
opts.palfile = malloc(size);
strncpy(opts.palfile, opts.infile, size);
@@ -233,17 +227,14 @@ main(int argc, char *argv[])
create_tilemap(opts, &gb, &tilemap);
}
if (*opts.outfile) {
if (*opts.outfile)
output_file(opts, gb);
}
if (*opts.mapfile) {
if (*opts.mapfile)
output_tilemap_file(opts, tilemap);
}
if (*opts.palfile) {
if (*opts.palfile)
output_palette_file(opts, png);
}
if (opts.fix || opts.debug) {
set_text(&png);