Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/datatoc
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/datatoc')
-rw-r--r--source/blender/datatoc/CMakeLists.txt52
-rw-r--r--source/blender/datatoc/datatoc.c141
-rw-r--r--source/blender/datatoc/datatoc_icon.c526
3 files changed, 355 insertions, 364 deletions
diff --git a/source/blender/datatoc/CMakeLists.txt b/source/blender/datatoc/CMakeLists.txt
index d2d91ae8664..734171afa07 100644
--- a/source/blender/datatoc/CMakeLists.txt
+++ b/source/blender/datatoc/CMakeLists.txt
@@ -19,7 +19,7 @@
# -----------------------------------------------------------------------------
# Build datatoc executable
set(SRC
- datatoc.c
+ datatoc.c
)
# SRC_DNA_INC is defined in the parent dir
@@ -31,35 +31,35 @@ add_executable(datatoc ${SRC})
if(NOT WITH_HEADLESS)
- set(SRC
- datatoc_icon.c
- )
- setup_platform_linker_flags()
- if(WIN32)
- include_directories(
- ../blenlib
- ../../../intern/utfconv
- )
+ set(SRC
+ datatoc_icon.c
+ )
+ setup_platform_linker_flags()
+ if(WIN32)
+ include_directories(
+ ../blenlib
+ ../../../intern/utfconv
+ )
- # for winstuff_dir.c
- add_definitions(-DUSE_STANDALONE)
+ # for winstuff_dir.c
+ add_definitions(-DUSE_STANDALONE)
- list(APPEND SRC
- ../blenlib/intern/winstuff_dir.c
- ../../../intern/utfconv/utfconv.c
- )
+ list(APPEND SRC
+ ../blenlib/intern/winstuff_dir.c
+ ../../../intern/utfconv/utfconv.c
+ )
- endif()
+ endif()
- include_directories(${PNG_INCLUDE_DIRS})
- link_directories(${PNG_LIBPATH} ${ZLIB_LIBPATH})
+ include_directories(${PNG_INCLUDE_DIRS})
+ link_directories(${PNG_LIBPATH} ${ZLIB_LIBPATH})
- add_executable(datatoc_icon ${SRC})
+ add_executable(datatoc_icon ${SRC})
- target_link_libraries(datatoc_icon ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
- # PNG library uses pow() and floow(), so seems -lm is required for proper
- # workign binary.
- if(UNIX AND NOT APPLE)
- target_link_libraries(datatoc_icon m)
- endif()
+ target_link_libraries(datatoc_icon ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
+ # PNG library uses pow() and floow(), so seems -lm is required for proper
+ # workign binary.
+ if(UNIX AND NOT APPLE)
+ target_link_libraries(datatoc_icon m)
+ endif()
endif()
diff --git a/source/blender/datatoc/datatoc.c b/source/blender/datatoc/datatoc.c
index d54fa898968..7a180b0912d 100644
--- a/source/blender/datatoc/datatoc.c
+++ b/source/blender/datatoc/datatoc.c
@@ -27,95 +27,96 @@
/* #define VERBOSE */
-#define MAX2(x, y) ( (x) > (y) ? (x) : (y) )
-#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z) )
+#define MAX2(x, y) ((x) > (y) ? (x) : (y))
+#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z))
static char *basename(char *string)
{
- char *lfslash, *lbslash;
-
- lfslash = strrchr(string, '/');
- lbslash = strrchr(string, '\\');
- if (lbslash) {
- lbslash++;
- }
- if (lfslash) {
- lfslash++;
- }
-
- return MAX3(string, lfslash, lbslash);
+ char *lfslash, *lbslash;
+
+ lfslash = strrchr(string, '/');
+ lbslash = strrchr(string, '\\');
+ if (lbslash) {
+ lbslash++;
+ }
+ if (lfslash) {
+ lfslash++;
+ }
+
+ return MAX3(string, lfslash, lbslash);
}
int main(int argc, char **argv)
{
- FILE *fpin, *fpout;
- long size;
- int i;
- int argv_len;
+ FILE *fpin, *fpout;
+ long size;
+ int i;
+ int argv_len;
- if (argc < 2) {
- printf("Usage: datatoc <data_file_from> <data_file_to>\n");
- exit(1);
- }
+ if (argc < 2) {
+ printf("Usage: datatoc <data_file_from> <data_file_to>\n");
+ exit(1);
+ }
- fpin = fopen(argv[1], "rb");
- if (!fpin) {
- printf("Unable to open input <%s>\n", argv[1]);
- exit(1);
- }
+ fpin = fopen(argv[1], "rb");
+ if (!fpin) {
+ printf("Unable to open input <%s>\n", argv[1]);
+ exit(1);
+ }
- argv[1] = basename(argv[1]);
+ argv[1] = basename(argv[1]);
- fseek(fpin, 0L, SEEK_END);
- size = ftell(fpin);
- fseek(fpin, 0L, SEEK_SET);
+ fseek(fpin, 0L, SEEK_END);
+ size = ftell(fpin);
+ fseek(fpin, 0L, SEEK_SET);
- if (argv[1][0] == '.') {
- argv[1]++;
- }
+ if (argv[1][0] == '.') {
+ argv[1]++;
+ }
#ifdef VERBOSE
- printf("Making C file <%s>\n", argv[2]);
+ printf("Making C file <%s>\n", argv[2]);
#endif
- argv_len = (int)strlen(argv[1]);
- for (i = 0; i < argv_len; i++) {
- if (argv[1][i] == '.') argv[1][i] = '_';
- }
-
- fpout = fopen(argv[2], "w");
- if (!fpout) {
- fprintf(stderr, "Unable to open output <%s>\n", argv[2]);
- exit(1);
- }
-
- fprintf(fpout, "/* DataToC output of file <%s> */\n\n", argv[1]);
-
- /* Quiet 'missing-variable-declarations' warning. */
- fprintf(fpout, "extern int datatoc_%s_size;\n", argv[1]);
- fprintf(fpout, "extern char datatoc_%s[];\n\n", argv[1]);
-
- fprintf(fpout, "int datatoc_%s_size = %d;\n", argv[1], (int)size);
- fprintf(fpout, "char datatoc_%s[] = {\n", argv[1]);
- while (size--) {
- /* if we want to open in an editor
- * this is nicer to avoid very long lines */
+ argv_len = (int)strlen(argv[1]);
+ for (i = 0; i < argv_len; i++) {
+ if (argv[1][i] == '.')
+ argv[1][i] = '_';
+ }
+
+ fpout = fopen(argv[2], "w");
+ if (!fpout) {
+ fprintf(stderr, "Unable to open output <%s>\n", argv[2]);
+ exit(1);
+ }
+
+ fprintf(fpout, "/* DataToC output of file <%s> */\n\n", argv[1]);
+
+ /* Quiet 'missing-variable-declarations' warning. */
+ fprintf(fpout, "extern int datatoc_%s_size;\n", argv[1]);
+ fprintf(fpout, "extern char datatoc_%s[];\n\n", argv[1]);
+
+ fprintf(fpout, "int datatoc_%s_size = %d;\n", argv[1], (int)size);
+ fprintf(fpout, "char datatoc_%s[] = {\n", argv[1]);
+ while (size--) {
+ /* if we want to open in an editor
+ * this is nicer to avoid very long lines */
#ifdef VERBOSE
- if (size % 32 == 31) {
- fprintf(fpout, "\n");
- }
+ if (size % 32 == 31) {
+ fprintf(fpout, "\n");
+ }
#endif
- /* fprintf (fpout, "\\x%02x", getc(fpin)); */
- fprintf(fpout, "%3d,", getc(fpin));
- }
+ /* fprintf (fpout, "\\x%02x", getc(fpin)); */
+ fprintf(fpout, "%3d,", getc(fpin));
+ }
- /* trailing NULL terminator, this isnt needed in some cases and
- * won't be taken into account by the size variable, but its useful when dealing with
- * NULL terminated string data */
- fprintf(fpout, "0\n};\n\n");
+ /* trailing NULL terminator, this isnt needed in some cases and
+ * won't be taken into account by the size variable, but its useful when dealing with
+ * NULL terminated string data */
+ fprintf(fpout, "0\n};\n\n");
- fclose(fpin);
- fclose(fpout);
- return 0;
+ fclose(fpin);
+ fclose(fpout);
+ return 0;
}
diff --git a/source/blender/datatoc/datatoc_icon.c b/source/blender/datatoc/datatoc_icon.c
index f63686d0136..82c5470943f 100644
--- a/source/blender/datatoc/datatoc_icon.c
+++ b/source/blender/datatoc/datatoc_icon.c
@@ -34,7 +34,6 @@
#include "png.h"
-
/* for Win32 DIR functions */
#ifdef WIN32
# include "../blenlib/BLI_winstuff.h"
@@ -51,342 +50,333 @@
static int path_ensure_slash(char *string)
{
- int len = strlen(string);
- if (len == 0 || string[len - 1] != SEP) {
- string[len] = SEP;
- string[len + 1] = '\0';
- return len + 1;
- }
- return len;
+ int len = strlen(string);
+ if (len == 0 || string[len - 1] != SEP) {
+ string[len] = SEP;
+ string[len + 1] = '\0';
+ return len + 1;
+ }
+ return len;
}
static bool path_test_extension(const char *str, const char *ext)
{
- const size_t a = strlen(str);
- const size_t b = strlen(ext);
- return !(a == 0 || b == 0 || b >= a) && (strcmp(ext, str + a - b) == 0);
+ const size_t a = strlen(str);
+ const size_t b = strlen(ext);
+ return !(a == 0 || b == 0 || b >= a) && (strcmp(ext, str + a - b) == 0);
}
static void endian_switch_uint32(unsigned int *val)
{
- unsigned int tval = *val;
- *val = ((tval >> 24)) |
- ((tval << 8) & 0x00ff0000) |
- ((tval >> 8) & 0x0000ff00) |
- ((tval << 24));
+ unsigned int tval = *val;
+ *val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
}
/* -------------------------------------------------------------------- */
/* Write a PNG from RGBA pixels */
-static bool write_png(const char *name, const unsigned int *pixels,
- const int width, const int height)
+static bool write_png(const char *name,
+ const unsigned int *pixels,
+ const int width,
+ const int height)
{
- png_structp png_ptr;
- png_infop info_ptr;
- png_bytepp row_pointers = NULL;
-
- FILE *fp;
-
- const int bytesperpixel = 4;
- const int compression = 9;
- int i;
-
- fp = fopen(name, "wb");
- if (fp == NULL) {
- printf("%s: Cannot open file for writing '%s'\n", __func__, name);
- return false;
- }
-
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL);
- if (png_ptr == NULL) {
- printf("%s: Cannot png_create_write_struct for file: '%s'\n", __func__, name);
- fclose(fp);
- return false;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL) {
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
- printf("%s: Cannot png_create_info_struct for file: '%s'\n", __func__, name);
- fclose(fp);
- return false;
- }
-
- if (setjmp(png_jmpbuf(png_ptr))) {
- png_destroy_write_struct(&png_ptr, &info_ptr);
- printf("%s: Cannot setjmp for file: '%s'\n", __func__, name);
- fclose(fp);
- return false;
- }
-
- /* write the file */
- png_init_io(png_ptr, fp);
-
- png_set_compression_level(png_ptr, compression);
-
- /* png image settings */
- png_set_IHDR(png_ptr,
- info_ptr,
- width,
- height,
- 8,
- PNG_COLOR_TYPE_RGBA,
- PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
-
- /* write the file header information */
- png_write_info(png_ptr, info_ptr);
+ png_structp png_ptr;
+ png_infop info_ptr;
+ png_bytepp row_pointers = NULL;
+
+ FILE *fp;
+
+ const int bytesperpixel = 4;
+ const int compression = 9;
+ int i;
+
+ fp = fopen(name, "wb");
+ if (fp == NULL) {
+ printf("%s: Cannot open file for writing '%s'\n", __func__, name);
+ return false;
+ }
+
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (png_ptr == NULL) {
+ printf("%s: Cannot png_create_write_struct for file: '%s'\n", __func__, name);
+ fclose(fp);
+ return false;
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ printf("%s: Cannot png_create_info_struct for file: '%s'\n", __func__, name);
+ fclose(fp);
+ return false;
+ }
+
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ printf("%s: Cannot setjmp for file: '%s'\n", __func__, name);
+ fclose(fp);
+ return false;
+ }
+
+ /* write the file */
+ png_init_io(png_ptr, fp);
+
+ png_set_compression_level(png_ptr, compression);
+
+ /* png image settings */
+ png_set_IHDR(png_ptr,
+ info_ptr,
+ width,
+ height,
+ 8,
+ PNG_COLOR_TYPE_RGBA,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+
+ /* write the file header information */
+ png_write_info(png_ptr, info_ptr);
#ifdef __LITTLE_ENDIAN__
- png_set_swap(png_ptr);
+ png_set_swap(png_ptr);
#endif
- /* allocate memory for an array of row-pointers */
- row_pointers = (png_bytepp) malloc(height * sizeof(png_bytep));
- if (row_pointers == NULL) {
- printf("%s: Cannot allocate row-pointers array for file '%s'\n", __func__, name);
- png_destroy_write_struct(&png_ptr, &info_ptr);
- if (fp) {
- fclose(fp);
- }
- return false;
- }
-
- /* set the individual row-pointers to point at the correct offsets */
- for (i = 0; i < height; i++) {
- row_pointers[height - 1 - i] = (png_bytep)
- (((const unsigned char *)pixels) +
- (i * width) * bytesperpixel * sizeof(unsigned char));
- }
-
- /* write out the entire image data in one call */
- png_write_image(png_ptr, row_pointers);
-
- /* write the additional chunks to the PNG file (not really needed) */
- png_write_end(png_ptr, info_ptr);
-
- /* clean up */
- free(row_pointers);
- png_destroy_write_struct(&png_ptr, &info_ptr);
-
- fflush(fp);
- fclose(fp);
-
- return true;
+ /* allocate memory for an array of row-pointers */
+ row_pointers = (png_bytepp)malloc(height * sizeof(png_bytep));
+ if (row_pointers == NULL) {
+ printf("%s: Cannot allocate row-pointers array for file '%s'\n", __func__, name);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ if (fp) {
+ fclose(fp);
+ }
+ return false;
+ }
+
+ /* set the individual row-pointers to point at the correct offsets */
+ for (i = 0; i < height; i++) {
+ row_pointers[height - 1 - i] = (png_bytep)(
+ ((const unsigned char *)pixels) + (i * width) * bytesperpixel * sizeof(unsigned char));
+ }
+
+ /* write out the entire image data in one call */
+ png_write_image(png_ptr, row_pointers);
+
+ /* write the additional chunks to the PNG file (not really needed) */
+ png_write_end(png_ptr, info_ptr);
+
+ /* clean up */
+ free(row_pointers);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ fflush(fp);
+ fclose(fp);
+
+ return true;
}
-
/* -------------------------------------------------------------------- */
/* Merge icon-data from files */
struct IconHead {
- unsigned int icon_w, icon_h;
- unsigned int orig_x, orig_y;
- unsigned int canvas_w, canvas_h;
+ unsigned int icon_w, icon_h;
+ unsigned int orig_x, orig_y;
+ unsigned int canvas_w, canvas_h;
};
-static bool icon_decode_head(FILE *f_src,
- struct IconHead *r_head)
+static bool icon_decode_head(FILE *f_src, struct IconHead *r_head)
{
- if (fread(r_head, 1, sizeof(*r_head), f_src) == sizeof(*r_head)) {
+ if (fread(r_head, 1, sizeof(*r_head), f_src) == sizeof(*r_head)) {
#ifndef __LITTLE_ENDIAN__
- endian_switch_uint32(&r_head->icon_w);
- endian_switch_uint32(&r_head->icon_h);
- endian_switch_uint32(&r_head->orig_x);
- endian_switch_uint32(&r_head->orig_y);
- endian_switch_uint32(&r_head->canvas_w);
- endian_switch_uint32(&r_head->canvas_h);
+ endian_switch_uint32(&r_head->icon_w);
+ endian_switch_uint32(&r_head->icon_h);
+ endian_switch_uint32(&r_head->orig_x);
+ endian_switch_uint32(&r_head->orig_y);
+ endian_switch_uint32(&r_head->canvas_w);
+ endian_switch_uint32(&r_head->canvas_h);
#endif
- return true;
- }
+ return true;
+ }
- /* quiet warning */
- (void)endian_switch_uint32;
+ /* quiet warning */
+ (void)endian_switch_uint32;
- return false;
+ return false;
}
-static bool icon_decode(FILE *f_src,
- struct IconHead *r_head, unsigned int **r_pixels)
+static bool icon_decode(FILE *f_src, struct IconHead *r_head, unsigned int **r_pixels)
{
- unsigned int *pixels;
- unsigned int pixels_size;
-
- if (!icon_decode_head(f_src, r_head)) {
- printf("%s: failed to read header\n", __func__);
- return false;
- }
-
- pixels_size = sizeof(char[4]) * r_head->icon_w * r_head->icon_h;
- pixels = malloc(pixels_size);
- if (pixels == NULL) {
- printf("%s: failed to allocate pixels\n", __func__);
- return false;
- }
-
- if (fread(pixels, 1, pixels_size, f_src) != pixels_size) {
- printf("%s: failed to read pixels\n", __func__);
- free(pixels);
- return false;
- }
-
- *r_pixels = pixels;
- return true;
+ unsigned int *pixels;
+ unsigned int pixels_size;
+
+ if (!icon_decode_head(f_src, r_head)) {
+ printf("%s: failed to read header\n", __func__);
+ return false;
+ }
+
+ pixels_size = sizeof(char[4]) * r_head->icon_w * r_head->icon_h;
+ pixels = malloc(pixels_size);
+ if (pixels == NULL) {
+ printf("%s: failed to allocate pixels\n", __func__);
+ return false;
+ }
+
+ if (fread(pixels, 1, pixels_size, f_src) != pixels_size) {
+ printf("%s: failed to read pixels\n", __func__);
+ free(pixels);
+ return false;
+ }
+
+ *r_pixels = pixels;
+ return true;
}
-static bool icon_read(const char *file_src,
- struct IconHead *r_head, unsigned int **r_pixels)
+static bool icon_read(const char *file_src, struct IconHead *r_head, unsigned int **r_pixels)
{
- FILE *f_src;
- bool success;
+ FILE *f_src;
+ bool success;
- f_src = fopen(file_src, "rb");
- if (f_src == NULL) {
- printf("%s: failed to open '%s'\n", __func__, file_src);
- return false;
- }
+ f_src = fopen(file_src, "rb");
+ if (f_src == NULL) {
+ printf("%s: failed to open '%s'\n", __func__, file_src);
+ return false;
+ }
- success = icon_decode(f_src, r_head, r_pixels);
+ success = icon_decode(f_src, r_head, r_pixels);
- fclose(f_src);
- return success;
+ fclose(f_src);
+ return success;
}
static bool icon_merge(const char *file_src,
unsigned int **r_pixels_canvas,
- unsigned int *r_canvas_w, unsigned int *r_canvas_h)
+ unsigned int *r_canvas_w,
+ unsigned int *r_canvas_h)
{
- struct IconHead head;
- unsigned int *pixels;
-
- unsigned int x, y;
+ struct IconHead head;
+ unsigned int *pixels;
- /* canvas */
- unsigned int *pixels_canvas;
- unsigned int canvas_w, canvas_h;
+ unsigned int x, y;
- if (!icon_read(file_src, &head, &pixels)) {
- return false;
- }
+ /* canvas */
+ unsigned int *pixels_canvas;
+ unsigned int canvas_w, canvas_h;
- if (*r_canvas_w == 0) {
- /* init once */
- *r_canvas_w = head.canvas_w;
- *r_canvas_h = head.canvas_h;
- *r_pixels_canvas = calloc(1, (head.canvas_w * head.canvas_h) * sizeof(unsigned char[4]));
- }
+ if (!icon_read(file_src, &head, &pixels)) {
+ return false;
+ }
- canvas_w = *r_canvas_w;
- canvas_h = *r_canvas_h;
- pixels_canvas = *r_pixels_canvas;
+ if (*r_canvas_w == 0) {
+ /* init once */
+ *r_canvas_w = head.canvas_w;
+ *r_canvas_h = head.canvas_h;
+ *r_pixels_canvas = calloc(1, (head.canvas_w * head.canvas_h) * sizeof(unsigned char[4]));
+ }
- assert(head.canvas_w == canvas_w);
- assert(head.canvas_h == canvas_h);
+ canvas_w = *r_canvas_w;
+ canvas_h = *r_canvas_h;
+ pixels_canvas = *r_pixels_canvas;
- for (x = 0; x < head.icon_w; x++) {
- for (y = 0; y < head.icon_h; y++) {
- unsigned int pixel;
- unsigned int dst_x, dst_y;
- unsigned int pixel_xy_dst;
+ assert(head.canvas_w == canvas_w);
+ assert(head.canvas_h == canvas_h);
+ for (x = 0; x < head.icon_w; x++) {
+ for (y = 0; y < head.icon_h; y++) {
+ unsigned int pixel;
+ unsigned int dst_x, dst_y;
+ unsigned int pixel_xy_dst;
- /* get pixel */
- pixel = pixels[(y * head.icon_w) + x];
+ /* get pixel */
+ pixel = pixels[(y * head.icon_w) + x];
- /* set pixel */
- dst_x = head.orig_x + x;
- dst_y = head.orig_y + y;
- pixel_xy_dst = (dst_y * canvas_w) + dst_x;
- assert(pixel_xy_dst < (canvas_w * canvas_h));
- pixels_canvas[pixel_xy_dst] = pixel;
- }
- }
+ /* set pixel */
+ dst_x = head.orig_x + x;
+ dst_y = head.orig_y + y;
+ pixel_xy_dst = (dst_y * canvas_w) + dst_x;
+ assert(pixel_xy_dst < (canvas_w * canvas_h));
+ pixels_canvas[pixel_xy_dst] = pixel;
+ }
+ }
- free(pixels);
+ free(pixels);
- /* only for bounds check */
- (void)canvas_h;
+ /* only for bounds check */
+ (void)canvas_h;
- return true;
+ return true;
}
static bool icondir_to_png(const char *path_src, const char *file_dst)
{
- /* Takes a path full of 'dat' files and writes out */
- DIR *dir;
- const struct dirent *fname;
- char filepath[1024];
- char *filename;
- int path_str_len;
- int found = 0, fail = 0;
-
- unsigned int *pixels_canvas = NULL;
- unsigned int canvas_w = 0, canvas_h = 0;
-
- errno = 0;
- dir = opendir(path_src);
- if (dir == NULL) {
- printf("%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) : "unknown");
- return false;
- }
-
- strcpy(filepath, path_src);
- path_str_len = path_ensure_slash(filepath);
- filename = &filepath[path_str_len];
-
-
- while ((fname = readdir(dir)) != NULL) {
- if (path_test_extension(fname->d_name, ".dat")) {
-
- strcpy(filename, fname->d_name);
-
- if (icon_merge(filepath, &pixels_canvas, &canvas_w, &canvas_h)) {
- found++;
- }
- else {
- fail++;
- }
- }
- }
-
- closedir(dir);
-
- if (found == 0) {
- printf("%s: dir '%s' has no icons\n", __func__, path_src);
- }
-
- if (fail != 0) {
- printf("%s: dir '%s' failed %d icons\n", __func__, path_src, fail);
- }
-
- /* write pixels */
- write_png(file_dst, pixels_canvas, canvas_w, canvas_h);
-
- free(pixels_canvas);
-
- return true;
+ /* Takes a path full of 'dat' files and writes out */
+ DIR *dir;
+ const struct dirent *fname;
+ char filepath[1024];
+ char *filename;
+ int path_str_len;
+ int found = 0, fail = 0;
+
+ unsigned int *pixels_canvas = NULL;
+ unsigned int canvas_w = 0, canvas_h = 0;
+
+ errno = 0;
+ dir = opendir(path_src);
+ if (dir == NULL) {
+ printf(
+ "%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) : "unknown");
+ return false;
+ }
+
+ strcpy(filepath, path_src);
+ path_str_len = path_ensure_slash(filepath);
+ filename = &filepath[path_str_len];
+
+ while ((fname = readdir(dir)) != NULL) {
+ if (path_test_extension(fname->d_name, ".dat")) {
+
+ strcpy(filename, fname->d_name);
+
+ if (icon_merge(filepath, &pixels_canvas, &canvas_w, &canvas_h)) {
+ found++;
+ }
+ else {
+ fail++;
+ }
+ }
+ }
+
+ closedir(dir);
+
+ if (found == 0) {
+ printf("%s: dir '%s' has no icons\n", __func__, path_src);
+ }
+
+ if (fail != 0) {
+ printf("%s: dir '%s' failed %d icons\n", __func__, path_src, fail);
+ }
+
+ /* write pixels */
+ write_png(file_dst, pixels_canvas, canvas_w, canvas_h);
+
+ free(pixels_canvas);
+
+ return true;
}
-
/* -------------------------------------------------------------------- */
/* Main and parse args */
int main(int argc, char **argv)
{
- const char *path_src;
- const char *file_dst;
-
+ const char *path_src;
+ const char *file_dst;
- if (argc < 3) {
- printf("Usage: datatoc_icon <dir_icons> <data_icon_to.png>\n");
- exit(1);
- }
+ if (argc < 3) {
+ printf("Usage: datatoc_icon <dir_icons> <data_icon_to.png>\n");
+ exit(1);
+ }
- path_src = argv[1];
- file_dst = argv[2];
+ path_src = argv[1];
+ file_dst = argv[2];
- return (icondir_to_png(path_src, file_dst) == true) ? 0 : 1;
+ return (icondir_to_png(path_src, file_dst) == true) ? 0 : 1;
}