Skip to content

Commit

Permalink
feat(cli): make missing src error msgs consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Sep 29, 2023
1 parent ebf854b commit 1a77915
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ cp_image_t rgb_to_cp(const hicolor_metadata meta, const hicolor_rgb* rgb_img)
return img;
}

bool check_src_exists(
const char* src
) {
if (access(src, F_OK) != 0) {
fprintf(
stderr,
HICOLOR_CLI_ERROR "source image \"%s\" doesn't exist\n",
src
);
return false;
}

return true;
}

bool png_to_hicolor(
hicolor_version version,
bool dither,
Expand All @@ -76,12 +91,8 @@ bool png_to_hicolor(
{
hicolor_result res;

if (access(src, F_OK) != 0) {
fprintf(
stderr,
HICOLOR_CLI_ERROR "source image \"%s\" doesn't exist\n",
src
);
bool exists = check_src_exists(src);
if (!exists) {
return false;
}

Expand Down Expand Up @@ -159,12 +170,8 @@ bool png_quantize(
{
hicolor_result res;

if (access(src, F_OK) != 0) {
fprintf(
stderr,
HICOLOR_CLI_ERROR "source image \"%s\" doesn't exist\n",
src
);
bool exists = check_src_exists(src);
if (!exists) {
return false;
}

Expand Down Expand Up @@ -231,6 +238,11 @@ bool hicolor_to_png(
{
hicolor_result res;

bool exists = check_src_exists(src);
if (!exists) {
return false;
}

FILE* hi_file = fopen(src, "rb");
if (hi_file == NULL) {
fprintf(
Expand Down Expand Up @@ -284,6 +296,11 @@ bool hicolor_print_info(
{
hicolor_result res;

bool exists = check_src_exists(src);
if (!exists) {
return false;
}

FILE* hi_file = fopen(src, "rb");
if (hi_file == NULL) {
fprintf(
Expand Down

0 comments on commit 1a77915

Please sign in to comment.