Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-06-09 16:20:26 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2011-09-24 15:08:09 (GMT)
commit27d65a891c010cc327ead7cddfac2a35519dd374 (patch)
tree82d84c15ed9f1f2296d2f619b3cbb85f5f95641e
parentc0ba905926cddff1ac3ec8b436dcf320b31324b2 (diff)
Make install data relocatable
-rw-r--r--Makefile8
-rw-r--r--src/fonts.c19
-rw-r--r--src/i18n.c2
-rw-r--r--src/im.c113
-rw-r--r--src/shapes.h32
-rw-r--r--src/sounds.h60
-rw-r--r--src/tip_tux.h12
-rw-r--r--src/tools.h32
-rw-r--r--src/tuxpaint.c263
-rw-r--r--src/tuxpaint.h29
10 files changed, 352 insertions, 218 deletions
diff --git a/Makefile b/Makefile
index 707cf67..1c891f6 100644
--- a/Makefile
+++ b/Makefile
@@ -221,12 +221,10 @@ CFLAGS:=$(CPPFLAGS) $(OPTFLAGS) -W -Wall -fno-common -ffloat-store \
$(shell src/test-option.sh -Wstrict-aliasing=2)
DEFS:=-DVER_DATE=\"$(VER_DATE)\" -DVER_VERSION=\"$(VER_VERSION)\" \
- -DDATA_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(DATA_PREFIX))/\" \
- -DDOC_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(DOC_PREFIX))/\" \
- -DLOCALEDIR=\"$(patsubst $(DESTDIR)%,%,$(LOCALE_PREFIX))/\" \
- -DIMDIR=\"$(patsubst $(DESTDIR)%,%,$(IM_PREFIX))/\" \
+ -DDEFAULT_DATA_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(DATA_PREFIX))/\" \
+ -DDEFAULT_LOCALEDIR=\"$(patsubst $(DESTDIR)%,%,$(LOCALE_PREFIX))/\" \
-DCONFDIR=\"$(patsubst $(DESTDIR)%,%,$(CONFDIR))/\" \
- -DMAGIC_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(MAGIC_PREFIX))/\" \
+ -DDEFAULT_MAGIC_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(MAGIC_PREFIX))/\" \
$(NOSOUNDFLAG) $(NOSVGFLAG) $(OLDSVGFLAG) $(NOPANGOFLAG) \
$(MAEMOFLAG)
diff --git a/src/fonts.c b/src/fonts.c
index 7671c08..3fe0574 100644
--- a/src/fonts.c
+++ b/src/fonts.c
@@ -123,6 +123,8 @@ SDL_Thread *font_thread;
#endif
+#include "tuxpaint.h"
+
#ifdef FORKED_FONTS
int no_system_fonts;
@@ -193,7 +195,7 @@ static TuxPaint_Font *try_alternate_font(int size)
if ((p = strrchr(prefix, '_')) != NULL)
{
*p = 0;
- snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, prefix);
+ snprintf(str, sizeof(str), "%s/fonts/locale/%s.ttf", DATA_PREFIX, prefix);
return TuxPaint_Font_OpenFont("", str, size);
}
@@ -213,14 +215,14 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
else
{
char str[128];
- snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
+ snprintf(str, sizeof(str), "%s/fonts/locale/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size);
#ifdef __APPLE__
if (!ret)
{
- snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix);
+ snprintf(str, sizeof(str), "%s/fonts/%s.ttf", DATA_PREFIX, lang_prefix);
ret = TuxPaint_Font_OpenFont("", str, size);
}
@@ -335,6 +337,13 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
}
#endif
+ char fname_buf[MAX_PATH];
+ if (ttffilename[0] != '/')
+ {
+ snprintf(fname_buf, sizeof(fname_buf), "%s/%s", DATA_PREFIX, ttffilename);
+ ttffilename = fname_buf;
+ }
+
tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font));
tpf->typ = FONT_TYPE_TTF;
tpf->ttf_font = TTF_OpenFont(ttffilename, size);
@@ -935,10 +944,12 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
/* static */ int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale)
{
char *homedirdir;
+ char str[MAX_PATH];
(void) vp; // junk passed by threading library
- loadfonts_locale_filter(screen, DATA_PREFIX "fonts", locale);
+ snprintf(str, sizeof(str), "%s/fonts", DATA_PREFIX);
+ loadfonts_locale_filter(screen, str, locale);
if (!no_system_fonts)
{
diff --git a/src/i18n.c b/src/i18n.c
index fd24fbc..ab2444d 100644
--- a/src/i18n.c
+++ b/src/i18n.c
@@ -64,6 +64,8 @@
#include <wctype.h>
#endif
+#include "tuxpaint.h"
+
/* Globals: */
diff --git a/src/im.c b/src/im.c
index cfbb746..4c869f9 100644
--- a/src/im.c
+++ b/src/im.c
@@ -43,6 +43,7 @@
#include <wchar.h>
#include "im.h"
+#include "tuxpaint.h"
@@ -830,7 +831,6 @@ static void im_fullreset(IM_DATA* im)
*/
static int im_event_zh_tw(IM_DATA* im, SDL_keysym ks)
{
- static const char* lang_file = IMDIR "zh_tw.im";
enum { SEC_ENGLISH, SEC_ZH_TW, SEC_TOTAL };
static CHARMAP cm;
@@ -860,20 +860,25 @@ static int im_event_zh_tw(IM_DATA* im, SDL_keysym ks)
break;
case IM_REQ_INIT: /* Initialization */
- charmap_init(&cm);
+ {
+ char lang_file[MAX_PATH];
+ snprintf(lang_file, sizeof(lang_file), "%s/im/zh_tw.im", DATA_PREFIX);
- if(charmap_load(&cm, lang_file)) {
- fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
- im->lang = LANG_DEFAULT;
- return im_event_c(im, ks);
- }
+ charmap_init(&cm);
- im_fullreset(im);
+ if(charmap_load(&cm, lang_file)) {
+ fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
+ im->lang = LANG_DEFAULT;
+ return im_event_c(im, ks);
+ }
- #ifdef DEBUG
- printf("IM: Loaded '%s'\n", lang_file);
- #endif
- break;
+ im_fullreset(im);
+
+ #ifdef DEBUG
+ printf("IM: Loaded '%s'\n", lang_file);
+ #endif
+ break;
+ }
}
if(im->request != IM_REQ_TRANSLATE) return 0;
@@ -1015,7 +1020,6 @@ static int im_event_zh_tw(IM_DATA* im, SDL_keysym ks)
*/
static int im_event_th(IM_DATA* im, SDL_keysym ks)
{
- static const char* lang_file = IMDIR "th.im";
enum { SEC_ENGLISH, SEC_THAI, SEC_TOTAL };
static CHARMAP cm;
@@ -1045,20 +1049,25 @@ static int im_event_th(IM_DATA* im, SDL_keysym ks)
break;
case IM_REQ_INIT: /* Initialization */
- charmap_init(&cm);
+ {
+ char lang_file[MAX_PATH];
+ snprintf(lang_file, sizeof(lang_file), "%s/im/th.im", DATA_PREFIX);
- if(charmap_load(&cm, lang_file)) {
- fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
- im->lang = LANG_DEFAULT;
- return im_event_c(im, ks);
- }
+ charmap_init(&cm);
- im_fullreset(im);
+ if(charmap_load(&cm, lang_file)) {
+ fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
+ im->lang = LANG_DEFAULT;
+ return im_event_c(im, ks);
+ }
- #ifdef DEBUG
- printf("IM: Loaded '%s'\n", lang_file);
- #endif
- break;
+ im_fullreset(im);
+
+ #ifdef DEBUG
+ printf("IM: Loaded '%s'\n", lang_file);
+ #endif
+ break;
+ }
}
if(im->request != IM_REQ_TRANSLATE) return 0;
@@ -1201,7 +1210,6 @@ static int im_event_th(IM_DATA* im, SDL_keysym ks)
*/
static int im_event_ja(IM_DATA* im, SDL_keysym ks)
{
- static const char* lang_file = IMDIR "ja.im";
enum { SEC_ENGLISH, SEC_HIRAGANA, SEC_KATAKANA, SEC_TOTAL };
static CHARMAP cm;
@@ -1231,20 +1239,25 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
break;
case IM_REQ_INIT: /* Initialization */
- charmap_init(&cm);
+ {
+ char lang_file[MAX_PATH];
+ snprintf(lang_file, sizeof(lang_file), "%s/im/ja.im", DATA_PREFIX);
- if(charmap_load(&cm, lang_file)) {
- fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
- im->lang = LANG_DEFAULT;
- return im_event_c(im, ks);
- }
+ charmap_init(&cm);
- im_fullreset(im);
+ if(charmap_load(&cm, lang_file)) {
+ fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
+ im->lang = LANG_DEFAULT;
+ return im_event_c(im, ks);
+ }
- #ifdef DEBUG
- printf("IM: Loaded '%s'\n", lang_file);
- #endif
- break;
+ im_fullreset(im);
+
+ #ifdef DEBUG
+ printf("IM: Loaded '%s'\n", lang_file);
+ #endif
+ break;
+ }
}
if(im->request != IM_REQ_TRANSLATE) return 0;
@@ -1412,7 +1425,6 @@ static int im_event_ko_isvowel(CHARMAP* cm, wchar_t c)
*/
static int im_event_ko(IM_DATA* im, SDL_keysym ks)
{
- static const char* lang_file = IMDIR "ko.im";
enum { SEC_ENGLISH, SEC_HANGUL, SEC_TOTAL };
static CHARMAP cm;
@@ -1442,20 +1454,25 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
break;
case IM_REQ_INIT: /* Initialization */
- charmap_init(&cm);
+ {
+ char lang_file[MAX_PATH];
+ snprintf(lang_file, sizeof(lang_file), "%s/im/ko.im", DATA_PREFIX);
- if(charmap_load(&cm, lang_file)) {
- fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
- im->lang = LANG_DEFAULT;
- return im_event_c(im, ks);
- }
+ charmap_init(&cm);
- im_fullreset(im);
+ if(charmap_load(&cm, lang_file)) {
+ fprintf(stderr, "Unable to load %s, defaulting to im_event_c\n", lang_file);
+ im->lang = LANG_DEFAULT;
+ return im_event_c(im, ks);
+ }
- #ifdef DEBUG
- printf("IM: Loaded '%s'\n", lang_file);
- #endif
- break;
+ im_fullreset(im);
+
+ #ifdef DEBUG
+ printf("IM: Loaded '%s'\n", lang_file);
+ #endif
+ break;
+ }
}
if(im->request != IM_REQ_TRANSLATE) return 0;
diff --git a/src/shapes.h b/src/shapes.h
index 456a0bc..5b08a83 100644
--- a/src/shapes.h
+++ b/src/shapes.h
@@ -247,20 +247,20 @@ const char *const shape_tips[NUM_SHAPES] = {
/* Shape icon filenames: */
const char *const shape_img_fnames[NUM_SHAPES] = {
- DATA_PREFIX "images/shapes/square.png",
- DATA_PREFIX "images/shapes/square_f.png",
- DATA_PREFIX "images/shapes/rectangle.png",
- DATA_PREFIX "images/shapes/rectangle_f.png",
- DATA_PREFIX "images/shapes/circle.png",
- DATA_PREFIX "images/shapes/circle_f.png",
- DATA_PREFIX "images/shapes/oval.png",
- DATA_PREFIX "images/shapes/oval_f.png",
- DATA_PREFIX "images/shapes/triangle.png",
- DATA_PREFIX "images/shapes/triangle_f.png",
- DATA_PREFIX "images/shapes/pentagon.png",
- DATA_PREFIX "images/shapes/pentagon_f.png",
- DATA_PREFIX "images/shapes/diamond.png",
- DATA_PREFIX "images/shapes/diamond_f.png",
- DATA_PREFIX "images/shapes/octagon.png",
- DATA_PREFIX "images/shapes/octagon_f.png"
+ "images/shapes/square.png",
+ "images/shapes/square_f.png",
+ "images/shapes/rectangle.png",
+ "images/shapes/rectangle_f.png",
+ "images/shapes/circle.png",
+ "images/shapes/circle_f.png",
+ "images/shapes/oval.png",
+ "images/shapes/oval_f.png",
+ "images/shapes/triangle.png",
+ "images/shapes/triangle_f.png",
+ "images/shapes/pentagon.png",
+ "images/shapes/pentagon_f.png",
+ "images/shapes/diamond.png",
+ "images/shapes/diamond_f.png",
+ "images/shapes/octagon.png",
+ "images/shapes/octagon_f.png"
};
diff --git a/src/sounds.h b/src/sounds.h
index b794729..828f1fa 100644
--- a/src/sounds.h
+++ b/src/sounds.h
@@ -78,36 +78,36 @@ enum
-bjk 2007.07.17 */
static const char *sound_fnames[NUM_SOUNDS] = {
- DATA_PREFIX "sounds/harp.wav",
- DATA_PREFIX "sounds/click.wav",
- DATA_PREFIX "sounds/bleep.wav",
- DATA_PREFIX "sounds/bubble.wav",
- DATA_PREFIX "sounds/stamp.wav",
- DATA_PREFIX "sounds/line_start.wav",
- DATA_PREFIX "sounds/line_end.wav",
- DATA_PREFIX "sounds/scroll.wav",
- DATA_PREFIX "sounds/paint1.wav",
- DATA_PREFIX "sounds/paint2.wav",
- DATA_PREFIX "sounds/paint3.wav",
- DATA_PREFIX "sounds/paint4.wav",
- DATA_PREFIX "sounds/eraser1.wav",
- DATA_PREFIX "sounds/eraser2.wav",
- DATA_PREFIX "sounds/save.wav",
- DATA_PREFIX "sounds/prompt.wav",
- DATA_PREFIX "sounds/flip.wav",
- DATA_PREFIX "sounds/mirror.wav",
- DATA_PREFIX "sounds/keyclick.wav",
- DATA_PREFIX "sounds/typewriterbell.wav",
- DATA_PREFIX "sounds/return.wav",
- DATA_PREFIX "sounds/shrink.wav",
- DATA_PREFIX "sounds/grow.wav",
- DATA_PREFIX "sounds/italic_on.wav",
- DATA_PREFIX "sounds/italic_off.wav",
- DATA_PREFIX "sounds/areyousure.wav",
- DATA_PREFIX "sounds/youcannot.wav",
- DATA_PREFIX "sounds/tuxok.wav",
- DATA_PREFIX "sounds/thick.wav",
- DATA_PREFIX "sounds/thin.wav"
+ "sounds/harp.wav",
+ "sounds/click.wav",
+ "sounds/bleep.wav",
+ "sounds/bubble.wav",
+ "sounds/stamp.wav",
+ "sounds/line_start.wav",
+ "sounds/line_end.wav",
+ "sounds/scroll.wav",
+ "sounds/paint1.wav",
+ "sounds/paint2.wav",
+ "sounds/paint3.wav",
+ "sounds/paint4.wav",
+ "sounds/eraser1.wav",
+ "sounds/eraser2.wav",
+ "sounds/save.wav",
+ "sounds/prompt.wav",
+ "sounds/flip.wav",
+ "sounds/mirror.wav",
+ "sounds/keyclick.wav",
+ "sounds/typewriterbell.wav",
+ "sounds/return.wav",
+ "sounds/shrink.wav",
+ "sounds/grow.wav",
+ "sounds/italic_on.wav",
+ "sounds/italic_off.wav",
+ "sounds/areyousure.wav",
+ "sounds/youcannot.wav",
+ "sounds/tuxok.wav",
+ "sounds/thick.wav",
+ "sounds/thin.wav"
};
#endif
diff --git a/src/tip_tux.h b/src/tip_tux.h
index 6f68b4c..346eba2 100644
--- a/src/tip_tux.h
+++ b/src/tip_tux.h
@@ -48,12 +48,12 @@ enum
/* Tux filenames: */
const char *const tux_img_fnames[NUM_TIP_TUX] = {
- DATA_PREFIX "images/tux/default.png",
- DATA_PREFIX "images/tux/kiss.png",
- DATA_PREFIX "images/tux/bored.png",
- DATA_PREFIX "images/tux/great.png",
- DATA_PREFIX "images/tux/oops.png",
- DATA_PREFIX "images/tux/wait.png"
+ "images/tux/default.png",
+ "images/tux/kiss.png",
+ "images/tux/bored.png",
+ "images/tux/great.png",
+ "images/tux/oops.png",
+ "images/tux/wait.png"
};
#endif /* TIP_TUX_H */
diff --git a/src/tools.h b/src/tools.h
index 9a29acb..d5e7bc8 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -176,22 +176,22 @@ const char *const tool_tips[NUM_TOOLS] = {
/* Tool icon filenames: */
const char *const tool_img_fnames[NUM_TOOLS] = {
- DATA_PREFIX "images/tools/brush.png",
- DATA_PREFIX "images/tools/stamp.png",
- DATA_PREFIX "images/tools/lines.png",
- DATA_PREFIX "images/tools/shapes.png",
- DATA_PREFIX "images/tools/text.png",
- DATA_PREFIX "images/tools/label.png",
- DATA_PREFIX "images/ui/dead40x40.png",
- DATA_PREFIX "images/tools/magic.png",
- DATA_PREFIX "images/tools/undo.png",
- DATA_PREFIX "images/tools/redo.png",
- DATA_PREFIX "images/tools/eraser.png",
- DATA_PREFIX "images/tools/new.png",
- DATA_PREFIX "images/tools/open.png",
- DATA_PREFIX "images/tools/save.png",
- DATA_PREFIX "images/tools/print.png",
- DATA_PREFIX "images/tools/quit.png"
+ "images/tools/brush.png",
+ "images/tools/stamp.png",
+ "images/tools/lines.png",
+ "images/tools/shapes.png",
+ "images/tools/text.png",
+ "images/tools/label.png",
+ "images/ui/dead40x40.png",
+ "images/tools/magic.png",
+ "images/tools/undo.png",
+ "images/tools/redo.png",
+ "images/tools/eraser.png",
+ "images/tools/new.png",
+ "images/tools/open.png",
+ "images/tools/save.png",
+ "images/tools/print.png",
+ "images/tools/quit.png"
};
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index b55ebde..d9f98d1 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -57,7 +57,6 @@
/*#define PRINTMETHOD_PNG_PNM_PS*/ /* Output PNG, assuming it gets printed */
-#define MAX_PATH 256
/* Compile-time options: */
@@ -464,6 +463,8 @@ extern WrapperData macosx;
#include "compiler.h"
+#include "tuxpaint.h"
+
#if VIDEO_BPP==32
#ifdef __GNUC__
@@ -584,6 +585,9 @@ static int NUM_COLORS;
static Uint8 * * color_hexes;
static char * * color_names;
+const char *DATA_PREFIX = DEFAULT_DATA_PREFIX;
+const char *MAGIC_PREFIX = DEFAULT_MAGIC_PREFIX;
+const char *LOCALEDIR = DEFAULT_LOCALEDIR;
/* Show debugging stuff: */
@@ -1623,7 +1627,7 @@ static SDL_Cursor *get_cursor(unsigned char *bits, unsigned char *mask_bits,
unsigned int x, unsigned int y);
static void seticon(void);
static SDL_Surface *loadimage(const char *const fname);
-static SDL_Surface *do_loadimage(const char *const fname, int abort_on_error);
+static SDL_Surface *do_loadimage(const char *fname, int abort_on_error);
static void draw_toolbar(void);
static void draw_magic(void);
static void draw_brushes(void);
@@ -1684,6 +1688,8 @@ static void playstampdesc(int chan);
#endif
static void do_wait(int counter);
static void load_current(void);
+static char * get_current_image_file(void);
+static void load_current_image(char * fname);
static void save_current(void);
static int do_prompt_image_flash(const char *const text,
const char *const btn_yes,
@@ -5678,9 +5684,7 @@ static void show_version(int details)
printf(" Data directory (DATA_PREFIX) = %s\n", DATA_PREFIX);
printf(" Plugin directory (MAGIC_PREFIX) = %s\n", MAGIC_PREFIX);
- printf(" Doc directory (DOC_PREFIX) = %s\n", DOC_PREFIX);
printf(" Locale directory (LOCALEDIR) = %s\n", LOCALEDIR);
- printf(" Input Method directory (IMDIR) = %s\n", IMDIR);
printf(" System config directory (CONFDIR) = %s\n", CONFDIR);
@@ -5905,9 +5909,20 @@ static void loadbrush_callback(SDL_Surface * screen,
static void load_brush_dir(SDL_Surface * screen, const char *restrict const dir)
{
char buf[TP_FTW_PATHSIZE];
- unsigned dirlen = strlen(dir);
+ unsigned dirlen;
+
+ if (dir[0] != '/')
+ {
+ snprintf(buf, sizeof(buf), "%s/%s", DATA_PREFIX, dir);
+ dirlen = strlen(buf);
+ }
+ else
+ {
+ dirlen = strlen(dir);
+ memcpy(buf, dir, dirlen);
+ buf[dirlen] = '\0';
+ }
- memcpy(buf, dir, dirlen);
tp_ftw(screen, buf, dirlen, 0, loadbrush_callback, NULL);
}
@@ -6776,8 +6791,20 @@ static void loadstamp_callback(SDL_Surface * screen,
static void load_stamp_dir(SDL_Surface * screen, const char *const dir)
{
char buf[TP_FTW_PATHSIZE];
- unsigned dirlen = strlen(dir);
- memcpy(buf, dir, dirlen);
+ unsigned dirlen;
+
+ if (dir[0] != '/')
+ {
+ snprintf(buf, sizeof(buf), "%s/%s", DATA_PREFIX, dir);
+ dirlen = strlen(buf);
+ }
+ else
+ {
+ dirlen = strlen(dir);
+ memcpy(buf, dir, dirlen);
+ buf[dirlen] = '\0';
+ }
+
load_stamp_basedir = dir;
tp_ftw(screen, buf, dirlen, 0, loadstamp_callback, NULL);
}
@@ -6790,7 +6817,7 @@ static void load_stamps(SDL_Surface * screen)
default_stamp_size = compute_default_scale_factor(1.0);
load_stamp_dir(screen, homedirdir);
- load_stamp_dir(screen, DATA_PREFIX "stamps");
+ load_stamp_dir(screen, "stamps");
#ifdef __APPLE__
load_stamp_dir(screen, "/Library/Application Support/TuxPaint/stamps");
#endif
@@ -6803,8 +6830,8 @@ static void load_stamps(SDL_Surface * screen)
if (num_stamps[0] == 0)
{
fprintf(stderr,
- "\nWarning: No stamps found in " DATA_PREFIX "stamps/\n"
- "or %s\n\n", homedirdir);
+ "\nWarning: No stamps found in %s/stamps/\n"
+ "or %s\n\n", DATA_PREFIX, homedirdir);
}
num_stamp_groups = stamp_group + 1;
@@ -6954,21 +6981,23 @@ static void seticon(void)
Uint8 *mask;
#endif
SDL_Surface *icon;
+ char fname_buf[MAX_PATH];
/* Load icon into a surface: */
#ifndef WIN32
- icon = IMG_Load(DATA_PREFIX "images/icon.png");
+ snprintf(fname_buf, sizeof(fname_buf), "%s/images/icon.png", DATA_PREFIX);
#else
- icon = IMG_Load(DATA_PREFIX "images/icon32x32.png");
+ snprintf(fname_buf, sizeof(fname_buf), "%s/images/icon32x32.png", DATA_PREFIX);
#endif
+ icon = IMG_Load(fname_buf);
if (icon == NULL)
{
fprintf(stderr,
"\nWarning: I could not load the icon image: %s\n"
"The Simple DirectMedia error that occurred was:\n"
- "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
+ "%s/images/icon.png", SDL_GetError(), DATA_PREFIX);
return;
}
@@ -7056,10 +7085,16 @@ static SDL_Surface *loadimage(const char *const fname)
/* Load an image: */
-static SDL_Surface *do_loadimage(const char *const fname, int abort_on_error)
+static SDL_Surface *do_loadimage(const char *fname, int abort_on_error)
{
SDL_Surface *s, *disp_fmt_s;
+ char fname_buf[MAX_PATH];
+ if (fname[0] != '/')
+ {
+ snprintf(fname_buf, sizeof(fname_buf), "%s/%s", DATA_PREFIX, fname);
+ fname = fname_buf;
+ }
/* Load the image file: */
@@ -9847,12 +9882,18 @@ static void playstampdesc(int chan)
#ifndef NOSOUND
-static Mix_Chunk *loadsound_extra(const char *const fname, const char *extra)
+static Mix_Chunk *loadsound_extra(const char *fname, const char *extra)
{
char *snd_fname;
char tmp_str[MAX_PATH], ext[5];
Mix_Chunk *tmp_snd;
+ char fname_buf[MAX_PATH];
+ if (fname[0] != '/')
+ {
+ snprintf(fname_buf, "%s/%s", DATA_PREFIX, fname);
+ fname = fname_buf;
+ }
if (strcasestr(fname, ".png") != NULL)
{
@@ -10412,13 +10453,16 @@ static void load_starter_id(char *saved_id, FILE *fil)
static void load_starter(char *img_id)
{
char *dirname;
- char fname[256];
+ char fname[MAX_PATH];
SDL_Surface *tmp_surf;
/* Determine path to starter files: */
if (starter_personal == 0)
- dirname = strdup(DATA_PREFIX "starters");
+ {
+ snprintf(fname, sizeof(fname), "%s/starters", DATA_PREFIX);
+ dirname = strdup(fname);
+ }
else
dirname = get_fname("starters", DIR_DATA);
@@ -10587,13 +10631,16 @@ static void load_starter(char *img_id)
static void load_template(char *img_id)
{
char *dirname;
- char fname[256];
+ char fname[MAX_PATH];
SDL_Surface *tmp_surf;
/* Determine path to starter files: */
if (template_personal == 0)
- dirname = strdup(DATA_PREFIX "templates");
+ {
+ snprintf(fname, sizeof(fname), "%s/templates", DATA_PREFIX);
+ dirname = strdup(fname);
+ }
else
dirname = get_fname("templates", DIR_DATA);
@@ -17191,8 +17238,8 @@ static int do_new_dialog(void)
{
/* Finally, check for system-wide coloring-book style
'starter' images: */
-
- dirname[places_to_look] = strdup(DATA_PREFIX "starters");
+ snprintf(fname, sizeof(fname), "%s/starters", DATA_PREFIX);
+ dirname[places_to_look] = strdup(fname);
}
else if (places_to_look == PLACE_PERSONAL_TEMPLATES_DIR)
{
@@ -17203,8 +17250,8 @@ static int do_new_dialog(void)
else if (places_to_look == PLACE_TEMPLATES_DIR)
{
/* Finally, check for system-wide 'template' images: */
-
- dirname[places_to_look] = strdup(DATA_PREFIX "templates");
+ snprintf(fname, sizeof(fname), "%s/templates", DATA_PREFIX);
+ dirname[places_to_look] = strdup(fname);
}
@@ -20899,7 +20946,17 @@ static void setup(void)
i = NUM_SOUNDS;
while (use_sound && i--)
{
- sounds[i] = Mix_LoadWAV(sound_fnames[i]);
+ if (sound_fnames[i][0] != '/')
+ {
+ char fname_buf[MAX_PATH];
+ snprintf(fname_buf, sizeof(fname_buf), "%s/%s", DATA_PREFIX,
+ sound_fnames[i]);
+ sounds[i] = Mix_LoadWAV(fname_buf);
+ }
+ else
+ {
+ sounds[i] = Mix_LoadWAV(sound_fnames[i]);
+ }
if (sounds[i] == NULL)
{
@@ -21043,9 +21100,9 @@ static void setup(void)
/* quickly: title image, version, progress bar, and watch cursor */
- img_title = loadimage(DATA_PREFIX "images/title.png");
- img_title_credits = loadimage(DATA_PREFIX "images/title-credits.png");
- img_progress = loadimage(DATA_PREFIX "images/ui/progress.png");
+ img_title = loadimage("images/title.png");
+ img_title_credits = loadimage("images/title-credits.png");
+ img_progress = loadimage("images/ui/progress.png");
if (screen->w - img_title->w >= 410 && screen->h - img_progress->h - img_title_credits->h - 40) /* FIXME: Font */
big_title = 1;
@@ -21054,9 +21111,9 @@ static void setup(void)
if (big_title)
- img_title_tuxpaint = loadimage(DATA_PREFIX "images/title-tuxpaint-2x.png");
+ img_title_tuxpaint = loadimage("images/title-tuxpaint-2x.png");
else
- img_title_tuxpaint = loadimage(DATA_PREFIX "images/title-tuxpaint.png");
+ img_title_tuxpaint = loadimage("images/title-tuxpaint.png");
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
@@ -21154,16 +21211,16 @@ static void setup(void)
#endif
medium_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
- DATA_PREFIX "fonts/default_font.ttf",
+ "fonts/default_font.ttf",
18 - (only_uppercase * 3));
if (medium_font == NULL)
{
fprintf(stderr,
"\nError: Can't load font file: "
- DATA_PREFIX "fonts/default_font.ttf\n"
+ "%s/fonts/default_font.ttf\n"
"The Simple DirectMedia Layer error that occurred was:\n"
- "%s\n\n", SDL_GetError());
+ "%s\n\n", DATA_PREFIX, SDL_GetError());
cleanup();
exit(1);
@@ -21334,20 +21391,20 @@ static void setup(void)
for (i = 0; i < NUM_TOOLS; i++)
img_tools[i] = loadimage(tool_img_fnames[i]);
- img_title_on = loadimage(DATA_PREFIX "images/ui/title.png");
- img_title_large_on = loadimage(DATA_PREFIX "images/ui/title_large.png");
- img_title_off = loadimage(DATA_PREFIX "images/ui/no_title.png");
- img_title_large_off = loadimage(DATA_PREFIX "images/ui/no_title_large.png");
+ img_title_on = loadimage("images/ui/title.png");
+ img_title_large_on = loadimage("images/ui/title_large.png");
+ img_title_off = loadimage("images/ui/no_title.png");
+ img_title_large_off = loadimage("images/ui/no_title_large.png");
- img_btn_up = loadimage(DATA_PREFIX "images/ui/btn_up.png");
- img_btn_down = loadimage(DATA_PREFIX "images/ui/btn_down.png");
- img_btn_off = loadimage(DATA_PREFIX "images/ui/btn_off.png");
+ img_btn_up = loadimage("images/ui/btn_up.png");
+ img_btn_down = loadimage("images/ui/btn_down.png");
+ img_btn_off = loadimage("images/ui/btn_off.png");
- img_btnsm_up = loadimage(DATA_PREFIX "images/ui/btnsm_up.png");
- img_btnsm_off = loadimage(DATA_PREFIX "images/ui/btnsm_off.png");
+ img_btnsm_up = loadimage("images/ui/btnsm_up.png");
+ img_btnsm_off = loadimage("images/ui/btnsm_off.png");
- img_sfx = loadimage(DATA_PREFIX "images/tools/sfx.png");
- img_speak = loadimage(DATA_PREFIX "images/tools/speak.png");
+ img_sfx = loadimage("images/tools/sfx.png");
+ img_speak = loadimage("images/tools/speak.png");
img_black = SDL_CreateRGBSurface(SDL_SRCALPHA | SDL_SWSURFACE,
img_btn_off->w, img_btn_off->h,
@@ -21370,54 +21427,54 @@ static void setup(void)
show_progress_bar(screen);
- img_yes = loadimage(DATA_PREFIX "images/ui/yes.png");
- img_no = loadimage(DATA_PREFIX "images/ui/no.png");
+ img_yes = loadimage("images/ui/yes.png");
+ img_no = loadimage("images/ui/no.png");
- img_prev = loadimage(DATA_PREFIX "images/ui/prev.png");
- img_next = loadimage(DATA_PREFIX "images/ui/next.png");
+ img_prev = loadimage("images/ui/prev.png");
+ img_next = loadimage("images/ui/next.png");
- img_mirror = loadimage(DATA_PREFIX "images/ui/mirror.png");
- img_flip = loadimage(DATA_PREFIX "images/ui/flip.png");
+ img_mirror = loadimage("images/ui/mirror.png");
+ img_flip = loadimage("images/ui/flip.png");
- img_open = loadimage(DATA_PREFIX "images/ui/open.png");
- img_erase = loadimage(DATA_PREFIX "images/ui/erase.png");
- img_back = loadimage(DATA_PREFIX "images/ui/back.png");
- img_trash = loadimage(DATA_PREFIX "images/ui/trash.png");
+ img_open = loadimage("images/ui/open.png");
+ img_erase = loadimage("images/ui/erase.png");
+ img_back = loadimage("images/ui/back.png");
+ img_trash = loadimage("images/ui/trash.png");
- img_slideshow = loadimage(DATA_PREFIX "images/ui/slideshow.png");
- img_play = loadimage(DATA_PREFIX "images/ui/play.png");
- img_select_digits = loadimage(DATA_PREFIX "images/ui/select_digits.png");
+ img_slideshow = loadimage("images/ui/slideshow.png");
+ img_play = loadimage("images/ui/play.png");
+ img_select_digits = loadimage("images/ui/select_digits.png");
- img_popup_arrow = loadimage(DATA_PREFIX "images/ui/popup_arrow.png");
+ img_popup_arrow = loadimage("images/ui/popup_arrow.png");
- img_dead40x40 = loadimage(DATA_PREFIX "images/ui/dead40x40.png");
+ img_dead40x40 = loadimage("images/ui/dead40x40.png");
- img_printer = loadimage(DATA_PREFIX "images/ui/printer.png");
- img_printer_wait = loadimage(DATA_PREFIX "images/ui/printer_wait.png");
+ img_printer = loadimage("images/ui/printer.png");
+ img_printer_wait = loadimage("images/ui/printer_wait.png");
- img_save_over = loadimage(DATA_PREFIX "images/ui/save_over.png");
+ img_save_over = loadimage("images/ui/save_over.png");
- img_grow = loadimage(DATA_PREFIX "images/ui/grow.png");
- img_shrink = loadimage(DATA_PREFIX "images/ui/shrink.png");
+ img_grow = loadimage("images/ui/grow.png");
+ img_shrink = loadimage("images/ui/shrink.png");
- img_magic_paint = loadimage(DATA_PREFIX "images/ui/magic_paint.png");
- img_magic_fullscreen = loadimage(DATA_PREFIX "images/ui/magic_fullscreen.png");
+ img_magic_paint = loadimage("images/ui/magic_paint.png");
+ img_magic_fullscreen = loadimage("images/ui/magic_fullscreen.png");
- img_bold = loadimage(DATA_PREFIX "images/ui/bold.png");
- img_italic = loadimage(DATA_PREFIX "images/ui/italic.png");
+ img_bold = loadimage("images/ui/bold.png");
+ img_italic = loadimage("images/ui/italic.png");
- img_label = loadimage(DATA_PREFIX "images/tools/label.png");
- img_label_select = loadimage(DATA_PREFIX "images/tools/label_select.png");
+ img_label = loadimage("images/tools/label.png");
+ img_label_select = loadimage("images/tools/label_select.png");
show_progress_bar(screen);
- tmp_imgcurup = loadimage(DATA_PREFIX "images/ui/cursor_up_large.png");
- tmp_imgcurdown = loadimage(DATA_PREFIX "images/ui/cursor_down_large.png");
+ tmp_imgcurup = loadimage("images/ui/cursor_up_large.png");
+ tmp_imgcurdown = loadimage("images/ui/cursor_down_large.png");
img_cursor_up = thumbnail(tmp_imgcurup, THUMB_W, THUMB_H, 0);
img_cursor_down = thumbnail(tmp_imgcurdown, THUMB_W, THUMB_H, 0);
- tmp_imgcurup = loadimage(DATA_PREFIX "images/ui/cursor_starter_up.png");
- tmp_imgcurdown = loadimage(DATA_PREFIX "images/ui/cursor_starter_down.png");
+ tmp_imgcurup = loadimage("images/ui/cursor_starter_up.png");
+ tmp_imgcurdown = loadimage("images/ui/cursor_starter_down.png");
img_cursor_starter_up = thumbnail(tmp_imgcurup, THUMB_W, THUMB_H, 0);
img_cursor_starter_down = thumbnail(tmp_imgcurdown, THUMB_W, THUMB_H, 0);
SDL_FreeSurface(tmp_imgcurup);
@@ -21425,22 +21482,22 @@ static void setup(void)
show_progress_bar(screen);
- img_scroll_up = loadimage(DATA_PREFIX "images/ui/scroll_up.png");
- img_scroll_down = loadimage(DATA_PREFIX "images/ui/scroll_down.png");
+ img_scroll_up = loadimage("images/ui/scroll_up.png");
+ img_scroll_down = loadimage("images/ui/scroll_down.png");
- img_scroll_up_off = loadimage(DATA_PREFIX "images/ui/scroll_up_off.png");
+ img_scroll_up_off = loadimage("images/ui/scroll_up_off.png");
img_scroll_down_off =
- loadimage(DATA_PREFIX "images/ui/scroll_down_off.png");
+ loadimage("images/ui/scroll_down_off.png");
#ifdef LOW_QUALITY_COLOR_SELECTOR
- img_paintcan = loadimage(DATA_PREFIX "images/ui/paintcan.png");
+ img_paintcan = loadimage("images/ui/paintcan.png");
#endif
show_progress_bar(screen);
/* Load brushes: */
- load_brush_dir(screen, DATA_PREFIX "brushes");
+ load_brush_dir(screen, "brushes");
homedirdir = get_fname("brushes", DIR_DATA);
load_brush_dir(screen, homedirdir);
#ifdef WIN32
@@ -21452,8 +21509,8 @@ static void setup(void)
if (num_brushes == 0)
{
fprintf(stderr,
- "\nError: No brushes found in " DATA_PREFIX "brushes/\n"
- "or %s\n\n", homedirdir);
+ "\nError: No brushes found in %s/brushes/\n"
+ "or %s\n\n", DATA_PREFIX, homedirdir);
cleanup();
exit(1);
}
@@ -21464,16 +21521,16 @@ static void setup(void)
/* Load system fonts: */
large_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
- DATA_PREFIX "fonts/default_font.ttf",
+ "fonts/default_font.ttf",
30 - (only_uppercase * 3));
if (large_font == NULL)
{
fprintf(stderr,
"\nError: Can't load font file: "
- DATA_PREFIX "fonts/default_font.ttf\n"
+ "%s/fonts/default_font.ttf\n"
"The Simple DirectMedia Layer error that occurred was:\n"
- "%s\n\n", SDL_GetError());
+ "%s\n\n", DATA_PREFIX, SDL_GetError());
cleanup();
exit(1);
@@ -21481,7 +21538,7 @@ static void setup(void)
small_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
- DATA_PREFIX "fonts/default_font.ttf",
+ "fonts/default_font.ttf",
#ifdef __APPLE__
12 - (only_uppercase * 2));
#else
@@ -21492,9 +21549,9 @@ static void setup(void)
{
fprintf(stderr,
"\nError: Can't load font file: "
- DATA_PREFIX "fonts/default_font.ttf\n"
+ "%s/fonts/default_font.ttf\n"
"The Simple DirectMedia Layer error that occurred was:\n"
- "%s\n\n", SDL_GetError());
+ "%s\n\n", DATA_PREFIX, SDL_GetError());
cleanup();
exit(1);
@@ -21536,12 +21593,12 @@ static void setup(void)
show_progress_bar(screen);
- img_mouse = loadimage(DATA_PREFIX "images/ui/mouse.png");
- img_mouse_click = loadimage(DATA_PREFIX "images/ui/mouse_click.png");
+ img_mouse = loadimage("images/ui/mouse.png");
+ img_mouse_click = loadimage("images/ui/mouse_click.png");
show_progress_bar(screen);
- img_color_picker = loadimage(DATA_PREFIX "images/ui/color_picker.png");
+ img_color_picker = loadimage("images/ui/color_picker.png");
/* Create toolbox and selector labels: */
@@ -21575,7 +21632,7 @@ static void setup(void)
#ifndef LOW_QUALITY_COLOR_SELECTOR
/* Create appropriately-shaped buttons: */
- img1 = loadimage(DATA_PREFIX "images/ui/paintwell.png");
+ img1 = loadimage("images/ui/paintwell.png");
img_paintwell = thumbnail(img1, color_button_w, color_button_h, 0);
tmp_btn_up = thumbnail(img_btn_up, color_button_w, color_button_h, 0);
tmp_btn_down = thumbnail(img_btn_down, color_button_w, color_button_h, 0);
@@ -21832,7 +21889,22 @@ int main(int argc, char *argv[])
CLOCK_TYPE time2;
CLOCK_TYPE time3;
- (void)argc;
+ char *data_prefix_realpath = NULL;
+ char *magic_prefix_realpath = NULL;
+ char *localedir_realpath = NULL;
+ const char *envdir = NULL;
+
+ envdir = getenv("TUXPAINT_DATA_PREFIX");
+ if (envdir)
+ DATA_PREFIX = data_prefix_realpath = realpath(envdir, NULL);
+
+ envdir = getenv("TUXPAINT_MAGIC_PREFIX");
+ if (envdir)
+ MAGIC_PREFIX = magic_prefix_realpath = realpath(envdir, NULL);
+
+ envdir = getenv("TUXPAINT_LOCALEDIR");
+ if (envdir)
+ LOCALEDIR = localedir_realpath = realpath(envdir, NULL);
CLOCK_ASM(time1);
@@ -21876,5 +21948,10 @@ int main(int argc, char *argv[])
save_current();
wait_for_sfx();
cleanup();
+
+ free(data_prefix_realpath);
+ free(magic_prefix_realpath);
+ free(localedir_realpath);
+
return 0;
}
diff --git a/src/tuxpaint.h b/src/tuxpaint.h
new file mode 100644
index 0000000..369b0f3
--- /dev/null
+++ b/src/tuxpaint.h
@@ -0,0 +1,29 @@
+/*
+ tuxpaint.h
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ 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)
+*/
+
+#ifndef TUXPAINT_H
+#define TUXPAINT_H
+
+#define MAX_PATH 256
+
+extern const char *DATA_PREFIX;
+extern const char *MAGIC_PREFIX;
+extern const char *LOCALEDIR;
+
+#endif