diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 98611cb16..d8037ca8f 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -2,8 +2,8 @@ tuxpaint.c Tux Paint - A simple drawing program for children. - - Copyright (c) 2002-2014 by Bill Kendrick and others; see AUTHORS.txt + + Copyright (c) 2002-2017 by Bill Kendrick and others; see AUTHORS.txt bill@newbreedsoftware.com http://www.tuxpaint.org/ @@ -21,8 +21,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - - June 14, 2002 - April 16, 2014 + + June 14, 2002 - October 15, 2017 */ @@ -181,7 +181,7 @@ static scaleparams scaletable[] = { #include #include #include -#include //EP added this include for basename() +#include /* EP added this include for basename() */ /* On Linux, we can use 'wordexp()' to expand env. vars. in settings pulled from config. files */ @@ -256,7 +256,7 @@ char *strcasestr(const char *haystack, const char *needle) #endif #ifdef DEBUG -#undef gettext //EP to avoid warning on following line +#undef gettext /* EP to avoid warning on following line */ #define gettext(String) debug_gettext(String) #endif @@ -276,7 +276,7 @@ char *strcasestr(const char *haystack, const char *needle) #include #include -#if defined __BEOS__ //|| defined __HAIKU__ +#if defined __BEOS__ /* BeOS */ @@ -396,7 +396,7 @@ static void mtw(wchar_t * wtok, char *tok) /* The following section renames global variables defined in SDL_Pango.h to avoid errors during linking. It is okay to rename these variables because they are constants. - SDL_Pango.h is included by tuxpaint.c. + SDL_Pango.h is included by tuxpaint.c. */ #define _MATRIX_WHITE_BACK _MATRIX_WHITE_BACK0 #define MATRIX_WHITE_BACK MATRIX_WHITE_BACK0 @@ -467,7 +467,7 @@ static void mtw(wchar_t * wtok, char *tok) #endif -#include //EP added for PNG upgrade from 1.2 to 1.5 +#include /* EP added for PNG upgrade from 1.2 to 1.5 */ #define PNG_INTERNAL #include #define FNAME_EXTENSION ".png" @@ -512,7 +512,7 @@ static void mtw(wchar_t * wtok, char *tok) #include "compiler.h" -//EP added #ifndef __APPLE__ because macros are buggy (shifted by 1 byte), plus the function exists in SDL +/* EP added #ifndef __APPLE__ because macros are buggy (shifted by 1 byte), plus the function exists in SDL */ #ifndef __APPLE__ #if VIDEO_BPP==32 #ifdef __GNUC__ @@ -549,9 +549,9 @@ static void mtw(wchar_t * wtok, char *tok) #endif #endif -//#define fmemopen_alternative */ /* Uncomment this to test the fmemopen alternative in systems were fmemopen exists */ +/* #define fmemopen_alternative */ /* Uncomment this to test the fmemopen alternative in systems were fmemopen exists */ -#if defined (WIN32) || defined (__APPLE__) || defined(__NetBSD__) || defined(__sun) // MINGW/MSYS, NetBSD, and MacOSX need it, at least for now +#if defined (WIN32) || defined (__APPLE__) || defined(__NetBSD__) || defined(__sun) /* MINGW/MSYS, NetBSD, and MacOSX need it, at least for now */ #define fmemopen_alternative #endif @@ -623,8 +623,8 @@ enum { LABEL_OFF, LABEL_LABEL, - LABEL_SELECT //, -// LABEL_ROTATE + LABEL_SELECT + /* , LABEL_ROTATE */ }; @@ -715,7 +715,7 @@ static grid_dims gd_colors; /* was 17x1 */ static int WINDOW_WIDTH = 800; static int WINDOW_HEIGHT = 480; #elif defined(OLPC_XO) -// ideally we'd support rotation and 2x scaling +/* ideally we'd support rotation and 2x scaling */ static int WINDOW_WIDTH = 1200; static int WINDOW_HEIGHT = 900; #else @@ -996,12 +996,7 @@ static void update_canvas_ex_r(int x1, int y1, int x2, int y2, int screen_too) SDL_BlitSurface(img_starter, &dest, canvas, &dest); } - // printf("%d\n", canvas ); - //printf("%d, %d, %d, %d\n", dest.x, dest.y, dest.w, dest.h); - //printf("%d\n", screen); - //printf("%d, %d, %d, %d\n\n\n", r_canvas.x, r_canvas.y, r_canvas.w, r_canvas.w); - // src.x = x1 + 96; dest.x = x1 + 96; SDL_BlitSurface(canvas, &src, screen, &dest); @@ -1443,7 +1438,7 @@ static Uint16 *wcstou16(const wchar_t * str) will cause a change from one utf16 character into two.... (though at least UTF-8 suffers from this problem) */ - // FIXME: mangles non-BMP characters rather than using UTF-16 surrogates! + /* FIXME: mangles non-BMP characters rather than using UTF-16 surrogates! */ res[i] = (Uint16) str[i]; } @@ -2239,7 +2234,7 @@ static void mainloop(void) mod = event.key.keysym.mod; #ifdef DEBUG -// FIXME: debug junk +/* FIXME: debug junk */ fprintf(stderr, "key 0x%04x mod 0x%04x character 0x%04x %d <%c> is %sprintable, key_down 0x%x\n", (unsigned)key, @@ -2662,7 +2657,7 @@ static void mainloop(void) add_label_node(0, 0, 0, 0, NULL); derender_node(&label_node_to_edit); label_node_to_edit = NULL; -// playsound(screen, 0, SND_DELETE_LABEL, 0, SNDPOS_CENTER); // FIXME lack of specific sound + /* playsound(screen, 0, SND_DELETE_LABEL, 0, SNDPOS_CENTER); */ /* FIXME lack of specific sound */ if (been_saved) { @@ -2704,7 +2699,6 @@ static void mainloop(void) cur_font = select_cur_font; text_state = select_text_state; text_size = select_text_size; - // int j; for (j = 0; j < num_font_families; j++) { if (user_font_families[j] && user_font_families[j]->handle) @@ -2777,7 +2771,7 @@ static void mainloop(void) add_label_node(0, 0, 0, 0, NULL); derender_node(&label_node_to_edit); label_node_to_edit = NULL; -// playsound(screen, 0, SND_DELETE_LABEL, 0, SNDPOS_CENTER); // FIXME lack of specific sound + /* playsound(screen, 0, SND_DELETE_LABEL, 0, SNDPOS_CENTER); */ /* FIXME lack of specific sound */ if (been_saved) { @@ -3331,8 +3325,6 @@ static void mainloop(void) WARNING: this must be kept in sync with the mouse-move code (for cursor changes) and mouse-scroll code. */ - // magic_switchout(canvas); - if (cur_tool == TOOL_BRUSH || cur_tool == TOOL_STAMP || cur_tool == TOOL_SHAPES || cur_tool == TOOL_LINES || cur_tool == TOOL_MAGIC || cur_tool == TOOL_TEXT || @@ -3911,17 +3903,18 @@ static void mainloop(void) } else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL) { - /* FIXME *//* char font_tux_text[512]; */ + /* FIXME */ + /* char font_tux_text[512]; */ cur_font = cur_thing; -/* FIXME */ -/* - snprintf(font_tux_text, sizeof font_tux_text, "%s (%s).", - TTF_FontFaceFamilyName(getfonthandle(cur_font)), - TTF_FontFaceStyleName(getfonthandle(cur_font))); - draw_tux_text(TUX_GREAT, font_tux_text, 1); -*/ + /* FIXME */ + /* + snprintf(font_tux_text, sizeof font_tux_text, "%s (%s).", + TTF_FontFaceFamilyName(getfonthandle(cur_font)), + TTF_FontFaceStyleName(getfonthandle(cur_font))); + draw_tux_text(TUX_GREAT, font_tux_text, 1); + */ if (do_draw) draw_fonts(); @@ -6434,23 +6427,24 @@ static void loadbrush_callback(SDL_Surface * screen, { do { - fgets(buf, sizeof(buf), fi); - - if (strstr(buf, "frames=") != NULL) + if (fgets(buf, sizeof(buf), fi)) { - brushes_frames[num_brushes] = atoi(strstr(buf, "frames=") + 7); - } - else if (strstr(buf, "spacing=") != NULL) - { - brushes_spacing[num_brushes] = atoi(strstr(buf, "spacing=") + 8); - } - else if (strstr(buf, "directional") != NULL) - { - brushes_directional[num_brushes] = 1; - } - else if (strstr(buf, "random") != NULL) - { - want_rand = 1; + if (strstr(buf, "frames=") != NULL) + { + brushes_frames[num_brushes] = atoi(strstr(buf, "frames=") + 7); + } + else if (strstr(buf, "spacing=") != NULL) + { + brushes_spacing[num_brushes] = atoi(strstr(buf, "spacing=") + 8); + } + else if (strstr(buf, "directional") != NULL) + { + brushes_directional[num_brushes] = 1; + } + else if (strstr(buf, "random") != NULL) + { + want_rand = 1; + } } } while (!feof(fi)); @@ -7365,7 +7359,7 @@ static void loadstamp_callback(SDL_Surface * screen, show_progress_bar(screen); if (dotext > files[i].str && !strcasecmp(dotext, ext) - && (dotext - files[i].str + 1 + dirlen < sizeof fname) + && (dotext - files[i].str + 1 + dirlen < (int) (sizeof fname)) && !strcasestr(files[i].str, mirror_ext) && !strcasestr(files[i].str, flip_ext) && !strcasestr(files[i].str, mirrorflip_ext)) { @@ -7533,8 +7527,8 @@ static int generate_fontconfig_cache(void *vp) #endif #define hex2dec(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \ - ((c) >= 'A' && (c) <= 'F') ? ((c) - 'A' + 10) : \ - ((c) >= 'a' && (c) <= 'f') ? ((c) - 'a' + 10) : 0) + ((c) >= 'A' && (c) <= 'F') ? ((c) - 'A' + 10) : \ + ((c) >= 'a' && (c) <= 'f') ? ((c) - 'a' + 10) : 0) #ifndef WIN32 static void signal_handler(int sig) @@ -10628,49 +10622,48 @@ static char *loaddesc(const char *const fname, Uint8 * locale_text) do { - fgets(buf, sizeof(buf), fi); - - if (!feof(fi)) + if (fgets(buf, sizeof(buf), fi)) { - strip_trailing_whitespace(buf); - - if (!got_first) + if (!feof(fi)) { - /* First one is the default: */ + strip_trailing_whitespace(buf); - strcpy(def_buf, buf); - got_first = 1; - } - - - debug(buf); - - - // lang_prefix = lang_prefixes[langint]; - /* See if it's the one for this locale... */ - - if ((char *)strcasestr(buf, wished_langs[i].lang_prefix) == buf) - { - - debug(buf + strlen(wished_langs[i].lang_prefix)); - if ((char *)strcasestr(buf + strlen(wished_langs[i].lang_prefix), ".utf8=") == - buf + strlen(wished_langs[i].lang_prefix)) + if (!got_first) { - lang_prefix = wished_langs[i].lang_prefix; - short_lang_prefix = strdup(lang_prefix); - /* When in doubt, cut off country code */ - if (strchr(short_lang_prefix, '_')) - *strchr(short_lang_prefix, '_') = '\0'; + /* First one is the default: */ - need_own_font = wished_langs[i].need_own_font; - need_right_to_left = wished_langs[i].need_right_to_left; - need_right_to_left_word = wished_langs[i].need_right_to_left_word; + strcpy(def_buf, buf); + got_first = 1; + } + debug(buf); - found = 1; - debug("...FOUND!"); + // lang_prefix = lang_prefixes[langint]; + /* See if it's the one for this locale... */ + + if ((char *)strcasestr(buf, wished_langs[i].lang_prefix) == buf) + { + + debug(buf + strlen(wished_langs[i].lang_prefix)); + if ((char *)strcasestr(buf + strlen(wished_langs[i].lang_prefix), ".utf8=") == + buf + strlen(wished_langs[i].lang_prefix)) + { + lang_prefix = wished_langs[i].lang_prefix; + short_lang_prefix = strdup(lang_prefix); + /* When in doubt, cut off country code */ + if (strchr(short_lang_prefix, '_')) + *strchr(short_lang_prefix, '_') = '\0'; + + need_own_font = wished_langs[i].need_own_font; + need_right_to_left = wished_langs[i].need_right_to_left; + need_right_to_left_word = wished_langs[i].need_right_to_left_word; + + found = 1; + + debug("...FOUND!"); + } } } } @@ -10723,89 +10716,90 @@ static double loadinfo(const char *const fname, stamp_type * inf) do { - fgets(buf, sizeof buf, fi); - - if (!feof(fi)) + if (fgets(buf, sizeof buf, fi)) { - strip_trailing_whitespace(buf); - - if (strcmp(buf, "colorable") == 0) - inf->colorable = 1; - else if (strcmp(buf, "tintable") == 0) - inf->tintable = 1; - else if (!memcmp(buf, "scale", 5) && (isspace(buf[5]) || buf[5] == '=')) + if (!feof(fi)) { - double tmp, tmp2; - char *cp = buf + 6; + strip_trailing_whitespace(buf); - while (isspace(*cp) || *cp == '=') - cp++; - if (strchr(cp, '%')) + if (strcmp(buf, "colorable") == 0) + inf->colorable = 1; + else if (strcmp(buf, "tintable") == 0) + inf->tintable = 1; + else if (!memcmp(buf, "scale", 5) && (isspace(buf[5]) || buf[5] == '=')) { - tmp = strtod(cp, NULL) / 100.0; - if (tmp > 0.0001 && tmp < 10000.0) - ratio = tmp; - } - else if (strchr(cp, '/')) - { - tmp = strtod(cp, &cp); - while (*cp && !isdigit(*cp)) + double tmp, tmp2; + char *cp = buf + 6; + + while (isspace(*cp) || *cp == '=') cp++; - tmp2 = strtod(cp, NULL); - if (tmp > 0.0001 && tmp < 10000.0 && tmp2 > 0.0001 && tmp2 < 10000.0 - && tmp / tmp2 > 0.0001 && tmp / tmp2 < 10000.0) - ratio = tmp / tmp2; + if (strchr(cp, '%')) + { + tmp = strtod(cp, NULL) / 100.0; + if (tmp > 0.0001 && tmp < 10000.0) + ratio = tmp; + } + else if (strchr(cp, '/')) + { + tmp = strtod(cp, &cp); + while (*cp && !isdigit(*cp)) + cp++; + tmp2 = strtod(cp, NULL); + if (tmp > 0.0001 && tmp < 10000.0 && tmp2 > 0.0001 && tmp2 < 10000.0 + && tmp / tmp2 > 0.0001 && tmp / tmp2 < 10000.0) + ratio = tmp / tmp2; + } + else if (strchr(cp, ':')) + { + tmp = strtod(cp, &cp); + while (*cp && !isdigit(*cp)) + cp++; + tmp2 = strtod(cp, NULL); + if (tmp > 0.0001 && tmp < 10000.0 && + tmp2 > 0.0001 && tmp2 < 10000.0 && tmp2 / tmp > 0.0001 && tmp2 / tmp < 10000.0) + ratio = tmp2 / tmp; + } + else + { + tmp = strtod(cp, NULL); + if (tmp > 0.0001 && tmp < 10000.0) + ratio = 1.0 / tmp; + } } - else if (strchr(cp, ':')) + else if (!memcmp(buf, "tinter", 6) && (isspace(buf[6]) || buf[6] == '=')) { - tmp = strtod(cp, &cp); - while (*cp && !isdigit(*cp)) + char *cp = buf + 7; + + while (isspace(*cp) || *cp == '=') cp++; - tmp2 = strtod(cp, NULL); - if (tmp > 0.0001 && tmp < 10000.0 && - tmp2 > 0.0001 && tmp2 < 10000.0 && tmp2 / tmp > 0.0001 && tmp2 / tmp < 10000.0) - ratio = tmp2 / tmp; - } - else - { - tmp = strtod(cp, NULL); - if (tmp > 0.0001 && tmp < 10000.0) - ratio = 1.0 / tmp; - } - } - else if (!memcmp(buf, "tinter", 6) && (isspace(buf[6]) || buf[6] == '=')) - { - char *cp = buf + 7; + if (!strcmp(cp, "anyhue")) + { + inf->tinter = TINTER_ANYHUE; + } + else if (!strcmp(cp, "narrow")) + { + inf->tinter = TINTER_NARROW; + } + else if (!strcmp(cp, "normal")) + { + inf->tinter = TINTER_NORMAL; + } + else if (!strcmp(cp, "vector")) + { + inf->tinter = TINTER_VECTOR; + } + else + { + debug(cp); + } - while (isspace(*cp) || *cp == '=') - cp++; - if (!strcmp(cp, "anyhue")) - { - inf->tinter = TINTER_ANYHUE; + /* printf("tinter=%d\n", inf->tinter); */ } - else if (!strcmp(cp, "narrow")) - { - inf->tinter = TINTER_NARROW; - } - else if (!strcmp(cp, "normal")) - { - inf->tinter = TINTER_NORMAL; - } - else if (!strcmp(cp, "vector")) - { - inf->tinter = TINTER_VECTOR; - } - else - { - debug(cp); - } - - /* printf("tinter=%d\n", inf->tinter); */ + else if (strcmp(buf, "nomirror") == 0) + inf->mirrorable = 0; + else if (strcmp(buf, "noflip") == 0) + inf->flipable = 0; } - else if (strcmp(buf, "nomirror") == 0) - inf->mirrorable = 0; - else if (strcmp(buf, "noflip") == 0) - inf->flipable = 0; } } while (!feof(fi)); @@ -10961,7 +10955,7 @@ static void load_starter_id(char *saved_id, FILE * fil) char fname[FILENAME_MAX]; FILE *fi; char color_tag; - int r, g, b; + int r, g, b, tmp; rname = NULL; @@ -10980,55 +10974,56 @@ static void load_starter_id(char *saved_id, FILE * fil) if (fi != NULL) { - fgets(starter_id, sizeof(starter_id), fi); - starter_id[strlen(starter_id) - 1] = '\0'; - - fscanf(fi, "%d", &starter_mirrored); - fscanf(fi, "%d", &starter_flipped); - fscanf(fi, "%d", &starter_personal); - - do + if (fgets(starter_id, sizeof(starter_id), fi)) { - color_tag = fgetc(fi); - } - while ((color_tag == '\n' || color_tag == '\r') && !feof(fi)); + starter_id[strlen(starter_id) - 1] = '\0'; - if (!feof(fi) && color_tag == 'c') - { - fscanf(fi, "%d", &r); - fscanf(fi, "%d", &g); - fscanf(fi, "%d", &b); + tmp = fscanf(fi, "%d", &starter_mirrored); + tmp = fscanf(fi, "%d", &starter_flipped); + tmp = fscanf(fi, "%d", &starter_personal); - canvas_color_r = (Uint8) r; - canvas_color_g = (Uint8) g; - canvas_color_b = (Uint8) b; - } - else - { - canvas_color_r = 255; - canvas_color_g = 255; - canvas_color_b = 255; - } + do + { + color_tag = fgetc(fi); + } + while ((color_tag == '\n' || color_tag == '\r') && !feof(fi)); - do - { - color_tag = fgetc(fi); - } - while ((color_tag == '\n' || color_tag == '\r') && !feof(fi)); - { - if (!feof(fi) && color_tag == 'T') - { - fgets(template_id, sizeof(template_id), fi); - template_id[strlen(template_id) - 1] = '\0'; - fscanf(fi, "%d", &template_personal); - printf("template = %s\n (Personal=%d)", template_id, template_personal); - } - if (!feof(fi) && color_tag == 'M') - { - starter_modified = fgetc(fi); - } - } + if (!feof(fi) && color_tag == 'c') + { + tmp = fscanf(fi, "%d", &r); + tmp = fscanf(fi, "%d", &g); + tmp = fscanf(fi, "%d", &b); + canvas_color_r = (Uint8) r; + canvas_color_g = (Uint8) g; + canvas_color_b = (Uint8) b; + } + else + { + canvas_color_r = 255; + canvas_color_g = 255; + canvas_color_b = 255; + } + + do + { + color_tag = fgetc(fi); + } + while ((color_tag == '\n' || color_tag == '\r') && !feof(fi)); + + if (!feof(fi) && color_tag == 'T') + { + tmp = fgets(template_id, sizeof(template_id), fi); + template_id[strlen(template_id) - 1] = '\0'; + tmp = fscanf(fi, "%d", &template_personal); + /* FIXME: Debug only? */ + printf("template = %s\n (Personal=%d)", template_id, template_personal); + } + if (!feof(fi) && color_tag == 'M') + { + starter_modified = fgetc(fi); + } + } fclose(fi); } else @@ -12284,37 +12279,6 @@ static void free_surface_array(SDL_Surface * surface_array[], int count) } -/* Update screen where shape is/was: */ - -/* FIXME: unused */ -/* -static void update_shape(int cx, int ox1, int ox2, int cy, int oy1, int oy2, int fix) -{ - int rx, ry; - - rx = abs(ox1 - cx); - if (abs(ox2 - cx) > rx) - rx = abs(ox2 - cx); - - ry = abs(oy1 - cy); - if (abs(oy2 - cy) > ry) - ry = abs(oy2 - cy); - - if (fix) - { - if (ry > rx) - rx = ry; - else - ry = rx; - } - - SDL_UpdateRect(screen, max((cx - rx), 0) + 96, max(cy - ry, 0), - min((cx + rx) + 96, screen->w), - min(cy + ry, screen->h)); -} -*/ - - /* Draw a shape! */ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush) @@ -15012,7 +14976,7 @@ static int do_slideshow(void) update_list = 0; } - /* Was a call to SDL_WaitEvent(&event); before, + /* Was a call to SDL_WaitEvent(&event); before, changed to this while loop in order to get joystick working */ while (SDL_PollEvent(&event)) { @@ -16813,19 +16777,19 @@ static char *replace_tilde(const char* const path) int newlen; int len = strlen(path); - + if (!len) return strdup(""); - + if (path[0] == '~') { newlen = strlen(getenv("HOME")) + len; newpath = malloc(sizeof(char)*newlen); - sprintf(newpath, "%s%s", getenv("HOME"), path+1); + sprintf(newpath, "%s%s", getenv("HOME"), path+1); } else newpath = strdup(path); - + return newpath; } */ @@ -18752,7 +18716,7 @@ static int do_new_dialog(void) update_list = 0; } - /* Was a call to SDL_WaitEvent(&event); before, + /* Was a call to SDL_WaitEvent(&event); before, changed to this while loop in order to get joystick working */ while (SDL_PollEvent(&event)) { @@ -19332,7 +19296,7 @@ static int do_color_sel(void) val_x = val_y = motioner = 0; valhat_x = valhat_y = hatmotioner = 0; - /* FIXME this is the first step to make animated popups optional, + /* FIXME this is the first step to make animated popups optional, to be removed from here when implemented in a more general way */ int want_animated_popups = 1; @@ -20616,7 +20580,7 @@ static void delete_label_list(struct label_node **ref_head) *ref_head = NULL; } -/* A custom bliter that allows to put two transparent layers toghether without having to deal with colorkeys or SDL_SRCALPHA +/* A custom bliter that allows to put two transparent layers toghether without having to deal with colorkeys or SDL_SRCALPHA I am always reinventing the wheel. Hope this one is not squared. Pere */ static void myblit(SDL_Surface * src_surf, SDL_Rect * src_rect, SDL_Surface * dest_surf, SDL_Rect * dest_rect) { @@ -20864,7 +20828,7 @@ static void set_label_fonts() { Uint32 c; - /* FIXME: 2009/09/13 TTF_FontFaceFamilyName() appends random "\n" at the end + /* FIXME: 2009/09/13 TTF_FontFaceFamilyName() appends random "\n" at the end of the returned string. Should investigate why, and when corrected, remove the code that deals whith the ending "\n"s in ttffont */ ttffont = TTF_FontFaceFamilyName(getfonthandle(i)->ttf_font); @@ -21275,6 +21239,7 @@ void load_embedded_data(char *fname, SDL_Surface * org_surf) { FILE *fi, *fp; char *control; + char *CHAR_PTR_TMP; Bytef *unc_buff; int unc_size; @@ -21345,9 +21310,12 @@ void load_embedded_data(char *fname, SDL_Surface * org_surf) have_label_delta = have_label_data = have_background = have_foreground = FALSE; ldelta = ldata = fgnd = bgnd = FALSE; -/* Need to get things in order, as we can't enforce any order in custom chunks, we need to go around them 3 times */ + /* Need to get things in order, as we can't enforce any order in custom chunks, + we need to go around them 3 times */ -/* First we search for the things that usually were in the .dat file, so if a starter or a template is found and if it is not modified, we can load it clean (i.e. not rebluring a blured when scaled one)*/ + /* First we search for the things that usually were in the .dat file, so if a starter or a + template is found and if it is not modified, we can load it clean (i.e. not rebluring a + blured when scaled one)*/ for (u = 0; u < num_unknowns; u++) { printf("%s, %d\n", unknowns[u].name, unknowns[u].size); @@ -21367,15 +21335,16 @@ void load_embedded_data(char *fname, SDL_Surface * org_surf) return; /* Refusing to go further with the other chunks */ } -/* Put fi position at the right place after the chunk headers */ + /* Put fi position at the right place after the chunk headers */ control = malloc(50); - fgets(control, 49, fi); - fgets(control, 49, fi); - fgets(control, 49, fi); - fgets(control, 49, fi); + CHAR_PTR_TMP = fgets(control, 49, fi); + CHAR_PTR_TMP = fgets(control, 49, fi); + CHAR_PTR_TMP = fgets(control, 49, fi); + CHAR_PTR_TMP = fgets(control, 49, fi); free(control); - load_starter_id(NULL, fi); // fi will be closed in load_starter_id() + /* fi will be closed in load_starter_id() */ + load_starter_id(NULL, fi); if (!starter_modified) { /* Code adapted from load_current() */ @@ -21615,7 +21584,7 @@ void load_embedded_data(char *fname, SDL_Surface * org_surf) } -///////////////////////////////////////////////////////////////////////////// +/* ================================================================================== */ #if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__) && !defined(__HAIKU__) static void show_available_papersizes(int exitcode) @@ -21650,7 +21619,7 @@ static void show_available_papersizes(int exitcode) } #endif -///////////////////////////////////////////////////////////////////////////// +/* ================================================================================== */ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *filename) { @@ -21679,10 +21648,10 @@ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *file wordfree(&result); #endif - // FIXME: leaking mem here, but the trouble is that these - // strings get mixed in with ones from .data and .rodata - // and free() isn't smart about the situation -- also some - // of the strings end up being kept around + /* FIXME: leaking mem here, but the trouble is that these + strings get mixed in with ones from .data and .rodata + and free() isn't smart about the situation -- also some + of the strings end up being kept around */ parse_one_option(tmpcfg, str, strdup(arg), filename); #ifdef __linux__ free(arg); @@ -21690,7 +21659,7 @@ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *file } fclose(fi); - // These interact in horrid ways. + /* These interact in horrid ways. */ if (tmpcfg->parsertmp_lang && tmpcfg->parsertmp_locale) fprintf(stderr, "Warning: option 'lang=%s' overrides option 'locale=%s' in '%s'\n", @@ -21761,7 +21730,7 @@ static void parse_argv_options(struct cfginfo *restrict tmpcfg, char *argv[]) exit(1); } - // These interact in horrid ways. + /* These interact in horrid ways. */ if (tmpcfg->parsertmp_lang && tmpcfg->parsertmp_locale) { fprintf(stderr, @@ -21775,7 +21744,7 @@ static void parse_argv_options(struct cfginfo *restrict tmpcfg, char *argv[]) tmpcfg->parsertmp_lang = PARSE_CLOBBER; } -// merge two configs, with the winner taking priority +/* merge two configs, with the winner taking priority */ static void tmpcfg_merge(struct cfginfo *loser, const struct cfginfo *winner) { int i = CFGINFO_MAXOFFSET / sizeof(char *); @@ -21809,7 +21778,9 @@ static void setup_config(char *argv[]) parse_argv_options(&tmpcfg_cmd, argv); -#if defined(__APPLE__) //EP added this conditional section for Mac to allow for a config in the current directory, that supersedes sys and user configs +#if defined(__APPLE__) + /* EP added this conditional section for Mac to allow for a config in + the current directory, that supersedes sys and user configs */ /* Mac OS X: Use a "tuxpaint.cfg" file in the current folder */ struct cfginfo tmpcfg_curdir; @@ -21866,14 +21837,15 @@ static void setup_config(char *argv[]) #else /* Linux and other Unixes: Use 'rc' style (~/.tuxpaintrc) */ - // it should it be "~/.tuxpaint/tuxpaintrc" instead, but too late now + /* it should it be "~/.tuxpaint/tuxpaintrc" instead, but too late now */ snprintf(str, sizeof(str), "%s/.tuxpaintrc", home); #endif parse_file_options(&tmpcfg_usr, str); -#if defined(__APPLE__) //EP added this conditional section for Mac +#if defined(__APPLE__) + /* EP added this conditional section for Mac */ tmpcfg_merge(&tmpcfg_usr, &tmpcfg_curdir); #else tmpcfg_merge(&tmpcfg_usr, &tmpcfg_cmd); @@ -21885,14 +21857,17 @@ static void setup_config(char *argv[]) memset(&tmpcfg_sys, '\0', sizeof tmpcfg_sys); #ifdef _WIN32 - // global config file in the application directory + /* global config file in the application directory */ parse_file_options(&tmpcfg_sys, "tuxpaint.cfg"); -#elif defined(__APPLE__) //EP added this conditional section for Mac to fix folder&extension inconsistency with Tux Paint Config application) - /* Mac OS X: Use a "tuxpaint.cfg" file in the *global* Tux Paint application support folder */ +#elif defined(__APPLE__) + /* EP added this conditional section for Mac to fix + folder & extension inconsistency with Tux Paint Config application) */ + /* Mac OS X: Use a "tuxpaint.cfg" file in the *global* Tux Paint +application support folder */ snprintf(str, sizeof(str), "%s/tuxpaint.cfg", macosx.globalPreferencesPath); parse_file_options(&tmpcfg_sys, str); #else - // normally /etc/tuxpaint/tuxpaint.conf + /* normally /etc/tuxpaint/tuxpaint.conf */ parse_file_options(&tmpcfg_sys, CONFDIR "tuxpaint.conf"); #endif tmpcfg_merge(&tmpcfg, &tmpcfg_sys); @@ -21914,7 +21889,7 @@ static void setup_config(char *argv[]) button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale); - // FIXME: most of this is not required before starting the font scanner + /* FIXME: most of this is not required before starting the font scanner */ #ifdef PAPER_H if (tmpcfg_cmd.papersize && !strcmp(tmpcfg_cmd.papersize, "help")) @@ -21980,7 +21955,7 @@ static void setup_config(char *argv[]) } if (tmpcfg.parsertmp_fullscreen_native) { - // should conflict with other fullscreen/native_screensize setting? + /* should conflict with other fullscreen/native_screensize setting? */ if (!strcmp(tmpcfg.parsertmp_fullscreen_native, "native")) native_screensize = 1; fullscreen = strcmp(tmpcfg.parsertmp_fullscreen_native, "no"); @@ -21991,17 +21966,17 @@ static void setup_config(char *argv[]) stamp_size_override = -1; else { - // FIXME: needs to be a scaling factor + /* FIXME: needs to be a scaling factor */ stamp_size_override = atoi(tmpcfg.stamp_size_override); if (stamp_size_override > 10) stamp_size_override = 10; } } - // FIXME: make this dynamic (accelerometer or OLPC XO-1 rotation button) + /* FIXME: make this dynamic (accelerometer or OLPC XO-1 rotation button) */ if (tmpcfg.rotate_orientation) - rotate_orientation = !strcmp(tmpcfg.rotate_orientation, "portrait"); // alternative is "landscape" + rotate_orientation = !strcmp(tmpcfg.rotate_orientation, "portrait"); /* alternative is "landscape" */ if (tmpcfg.colorfile) - strcpy(colorfile, tmpcfg.colorfile); // FIXME can overflow + strcpy(colorfile, tmpcfg.colorfile); /* FIXME can overflow */ if (tmpcfg.print_delay) { print_delay = atoi(tmpcfg.print_delay); @@ -22015,13 +21990,13 @@ static void setup_config(char *argv[]) #endif if (tmpcfg.alt_print_command_default) { - // FIXME: probably need extra variables + /* FIXME: probably need extra variables */ if (!strcmp(tmpcfg.alt_print_command_default, "always")) alt_print_command_default = ALTPRINT_ALWAYS; else if (!strcmp(tmpcfg.alt_print_command_default, "never")) alt_print_command_default = ALTPRINT_NEVER; else - alt_print_command_default = ALTPRINT_MOD; // default ("mod") + alt_print_command_default = ALTPRINT_MOD; /* default ("mod") */ } #ifdef PAPER_H if (tmpcfg.papersize) @@ -22324,14 +22299,15 @@ static void setup_config(char *argv[]) static void chdir_to_binary(char *argv0) { - char curdir[256]; //EP added this block to print out of current directory + char curdir[256]; + /* EP added this block to print out of current directory */ getcwd(curdir, sizeof(curdir)); #ifdef DEBUG printf("Binary Path: %s\nCurrent directory at launchtime: %s\n", argv0, curdir); #endif -#if defined(__BEOS__) || defined(WIN32) || defined(__APPLE__) //EP added __APPLE__ +#if defined(__BEOS__) || defined(WIN32) || defined(__APPLE__) /* if run from gui, like OpenTracker in BeOS or Explorer in Windows, find path from which binary was run and change dir to it so all files will be local :) */ @@ -22346,14 +22322,16 @@ static void chdir_to_binary(char *argv0) char *app_path = strdup(argv0); char *slash = strrchr(app_path, '/'); -#if defined(__APPLE__) //EP added to fix 10.9 issue of current directory set by Finder to something else than folder where app bundle resides - // typical path of app's binary on Mac OS : /Applications/Tux Paint.app/Contents/MacOS/Tux Paint - int levels = 3; // we need to back up 3 levels +#if defined(__APPLE__) + /* EP added to fix 10.9 issue of current directory set by Finder + to something else than folder where app bundle resides */ + /* typical path of app's binary on Mac OS : /Applications/Tux Paint.app/Contents/MacOS/Tux Paint */ + int levels = 3; /* we need to back up 3 levels */ while ((levels-- > 0) && (slash)) { - *slash = '\0'; // this overwrites the \0 at end of string - slash = strrchr(app_path, '/'); // so we can carry on our back-pedaling... + *slash = '\0'; /* this overwrites the \0 at end of string */ + slash = strrchr(app_path, '/'); /* so we can carry on our back-pedaling... */ } #endif @@ -22375,7 +22353,7 @@ static void chdir_to_binary(char *argv0) #endif } -///////////////////////////////////////////////////////////////////// +/* ================================================================================== */ static void setup_colors(void) { @@ -22403,64 +22381,65 @@ static void setup_colors(void) do { - fgets(str, sizeof(str), fi); - - if (!feof(fi)) + if (fgets(str, sizeof(str), fi)) { - if (NUM_COLORS + 1 > max) + if (!feof(fi)) { - color_hexes = realloc(color_hexes, sizeof(Uint8 *) * (max + per)); - color_names = realloc(color_names, sizeof(char *) * (max + per)); - - for (i = max; i < max + per; i++) - color_hexes[i] = malloc(sizeof(Uint8) * 3); - - max = max + per; - } - - while (str[strlen(str) - 1] == '\n' || str[strlen(str) - 1] == '\r') - str[strlen(str) - 1] = '\0'; - - if (str[0] == '#') - { - /* Hex form */ - - sscanf(str + 1, "%s %n", tmp_str, &count); - - if (strlen(tmp_str) == 6) + if (NUM_COLORS + 1 > max) { - /* Byte (#rrggbb) form */ + color_hexes = realloc(color_hexes, sizeof(Uint8 *) * (max + per)); + color_names = realloc(color_names, sizeof(char *) * (max + per)); - color_hexes[NUM_COLORS][0] = (hex2dec(tmp_str[0]) << 4) + hex2dec(tmp_str[1]); - color_hexes[NUM_COLORS][1] = (hex2dec(tmp_str[2]) << 4) + hex2dec(tmp_str[3]); - color_hexes[NUM_COLORS][2] = (hex2dec(tmp_str[4]) << 4) + hex2dec(tmp_str[5]); + for (i = max; i < max + per; i++) + color_hexes[i] = malloc(sizeof(Uint8) * 3); - color_names[NUM_COLORS] = strdup(str + count); - NUM_COLORS++; + max = max + per; } - else if (strlen(tmp_str) == 3) + + while (str[strlen(str) - 1] == '\n' || str[strlen(str) - 1] == '\r') + str[strlen(str) - 1] = '\0'; + + if (str[0] == '#') { - /* Nybble (#rgb) form */ + /* Hex form */ - color_hexes[NUM_COLORS][0] = (hex2dec(tmp_str[0]) << 4) + hex2dec(tmp_str[0]); - color_hexes[NUM_COLORS][1] = (hex2dec(tmp_str[1]) << 4) + hex2dec(tmp_str[1]); - color_hexes[NUM_COLORS][2] = (hex2dec(tmp_str[2]) << 4) + hex2dec(tmp_str[2]); + sscanf(str + 1, "%s %n", tmp_str, &count); - color_names[NUM_COLORS] = strdup(str + count); - NUM_COLORS++; + if (strlen(tmp_str) == 6) + { + /* Byte (#rrggbb) form */ + + color_hexes[NUM_COLORS][0] = (hex2dec(tmp_str[0]) << 4) + hex2dec(tmp_str[1]); + color_hexes[NUM_COLORS][1] = (hex2dec(tmp_str[2]) << 4) + hex2dec(tmp_str[3]); + color_hexes[NUM_COLORS][2] = (hex2dec(tmp_str[4]) << 4) + hex2dec(tmp_str[5]); + + color_names[NUM_COLORS] = strdup(str + count); + NUM_COLORS++; + } + else if (strlen(tmp_str) == 3) + { + /* Nybble (#rgb) form */ + + color_hexes[NUM_COLORS][0] = (hex2dec(tmp_str[0]) << 4) + hex2dec(tmp_str[0]); + color_hexes[NUM_COLORS][1] = (hex2dec(tmp_str[1]) << 4) + hex2dec(tmp_str[1]); + color_hexes[NUM_COLORS][2] = (hex2dec(tmp_str[2]) << 4) + hex2dec(tmp_str[2]); + + color_names[NUM_COLORS] = strdup(str + count); + NUM_COLORS++; + } } - } - else - { - /* Assume int form */ - - if (sscanf(str, "%hu %hu %hu %n", - (short unsigned int *)&(color_hexes[NUM_COLORS][0]), - (short unsigned int *)&(color_hexes[NUM_COLORS][1]), - (short unsigned int *)&(color_hexes[NUM_COLORS][2]), &count) >= 3) + else { - color_names[NUM_COLORS] = strdup(str + count); - NUM_COLORS++; + /* Assume int form */ + + if (sscanf(str, "%hu %hu %hu %n", + (short unsigned int *)&(color_hexes[NUM_COLORS][0]), + (short unsigned int *)&(color_hexes[NUM_COLORS][1]), + (short unsigned int *)&(color_hexes[NUM_COLORS][2]), &count) >= 3) + { + color_names[NUM_COLORS] = strdup(str + count); + NUM_COLORS++; + } } } } @@ -22534,7 +22513,7 @@ static void setup_colors(void) } -////////////////////////////////////////////////////////////////// +/* ================================================================================== */ static void do_lock_file(void) { @@ -22634,7 +22613,8 @@ int TP_EventFilter(const SDL_Event * event) return 0; } -///////////////////////////////////////////////////////////////////////////// +/* ================================================================================== */ + static void setup(void) { int i; @@ -23587,22 +23567,9 @@ static void setup(void) signal(SIGPIPE, signal_handler); #endif - - /* Call this once */ -//EP now deprecated -/* -#if !defined(NOSVG) && !defined(OLD_SVG) -#ifdef DEBUG - printf("rsvg_init()\n"); fflush(stdout); -#endif - rsvg_init(); -#endif -*/ } - -///////////////////////////////////////////////////////////////////////////// - +/* ================================================================================== */ static void claim_to_be_ready(void) { @@ -23704,7 +23671,7 @@ static void claim_to_be_ready(void) draw_tux_text(tool_tux[cur_tool], tool_tips[cur_tool], 1); } -//////////////////////////////////////////////////////////////////////////// +/* ================================================================================== */ int main(int argc, char *argv[]) { @@ -23717,14 +23684,15 @@ int main(int argc, char *argv[]) CLOCK_ASM(time1); - // do not add code (slowness) here unless required for scanning fonts + /* do not add code (slowness) here unless required for scanning fonts */ progname = argv[0]; -#if defined(DEBUG) && defined(__APPLE__) //EP added block to log messages - freopen("/tmp/tuxpaint.log", "w", stdout); // redirect stdout to a file - dup2(fileno(stdout), fileno(stderr)); // redirect stderr to stdout - setvbuf(stdout, NULL, _IONBF, 0); // we don't want buffering to avoid de-sync'ing stdout and stderr - setvbuf(stderr, NULL, _IONBF, 0); // we don't want buffering to avoid de-sync'ing stdout and stderr +#if defined(DEBUG) && defined(__APPLE__) + /* EP added block to log messages */ + freopen("/tmp/tuxpaint.log", "w", stdout); /* redirect stdout to a file */ + dup2(fileno(stdout), fileno(stderr)); /* redirect stderr to stdout */ + setvbuf(stdout, NULL, _IONBF, 0); /* we don't want buffering to avoid de-sync'ing stdout and stderr */ + setvbuf(stderr, NULL, _IONBF, 0); /* we don't want buffering to avoid de-sync'ing stdout and stderr */ char logTime[100]; time_t t = time(NULL); @@ -23737,7 +23705,7 @@ int main(int argc, char *argv[]) CLOCK_ASM(time2); #ifdef FORKED_FONTS - // must start ASAP, but depends on locale which in turn needs the config + /* must start ASAP, but depends on locale which in turn needs the config */ #ifdef NO_SDLPANGO /* Only fork it now if we're not planning on creating a thread to handle fontconfig stuff -bjk 2010.04.27 */ #ifdef DEBUG @@ -23805,7 +23773,7 @@ static int trash(char *path) char deldate[32]; struct tm tim; time_t now; - int cnt; + int cnt, tmp; FILE *fi, *fo; unsigned char buf[1024]; size_t len; @@ -23821,7 +23789,7 @@ static int trash(char *path) return (unlink(path)); } - printf("trash: basename=%s", basename(path)); //EP + printf("trash: basename=%s", basename(path)); /* EP */ strcpy(fname, basename(path)); if (!file_exists(path)) @@ -23945,7 +23913,7 @@ static int trash(char *path) -bjk 2011.04.18 */ /* FIXME: Is this sufficient to find 'dbus-send' (rely on system to use $PATH?) -bjk 2011.04.18 */ - system("dbus-send / org.kde.KDirNotify.FilesAdded string:trash:/"); + tmp = system("dbus-send / org.kde.KDirNotify.FilesAdded string:trash:/"); /* Note: GNOME figures out when things change because it asks the Kernel @@ -24008,7 +23976,6 @@ static void handle_joyaxismotion(SDL_Event event, int *motioner, int *val_x, int else *val_y = 0; - // printf("i %d valx %d j %d val_y %d\n", i, val_x, j, val_y); if (*val_x || *val_y) { *motioner = TRUE; @@ -24073,7 +24040,7 @@ static void handle_joyballmotion(SDL_Event event, int oldpos_x, int oldpos_y) { int val_x, val_y; - /* FIXME: NOT TESTED Should this act like handle_joyaxismotion? + /* FIXME: NOT TESTED Should this act like handle_joyaxismotion? in the sense of setting the values for the moving but don't move the mouse here? */ /* printf("\n ball movement \n"); */ val_x = event.jball.xrel;