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-05-10 16:24:16 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-05-10 16:24:16 (GMT)
commit2ed7f9a8446d6c876743164dff86f68408bd932e (patch)
tree4719cf3807f61f5ffd859ffd86231ca14234c876
parent670a28e7ce5070fb8d4e7f72168892b7323456d2 (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/sugar.c8
-rw-r--r--src/sugar.h5
-rw-r--r--src/tip_tux.h12
-rw-r--r--src/tools.h32
-rw-r--r--src/tuxpaint.c261
-rw-r--r--src/tuxpaint.h29
12 files changed, 355 insertions, 226 deletions
diff --git a/Makefile b/Makefile
index 2aa0e31..389bba9 100644
--- a/Makefile
+++ b/Makefile
@@ -225,12 +225,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) $(if $(SUGAR), -DSUGAR)
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/sugar.c b/src/sugar.c
index 59fe343..7e5b727 100644
--- a/src/sugar.c
+++ b/src/sugar.c
@@ -19,9 +19,6 @@
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 - May 15, 2007
- $Id: cursor.c,v 1.5 2009/11/21 09:44:11 albert Exp $
*/
#include <SDL/SDL_syswm.h>
@@ -132,3 +129,8 @@ void sugar_save_jobject_file(char * path)
g_debug("Saved %s image to journal entry %s", path,
sugar_jobject_get_uid(jobject));
}
+
+char * sugar_get_savedir(void)
+{
+ return g_strdup_printf("%s/data", sugar_profile_get_activity_root());
+}
diff --git a/src/sugar.h b/src/sugar.h
index 70ba5d3..d0df18f 100644
--- a/src/sugar.h
+++ b/src/sugar.h
@@ -19,9 +19,6 @@
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 - May 15, 2007
- $Id: cursor.h,v 1.3 2007/05/16 01:11:34 wkendrick Exp $
*/
#ifndef SUGAR_H
@@ -34,6 +31,7 @@
int sugar_detected(void);
char * sugar_get_jobject_file(void);
void sugar_save_jobject_file(char * path);
+ char * sugar_get_savedir(void);
#else
void sugar_init(int * argc, char *** argv) { }
void sugar_cleanup(void) { }
@@ -41,6 +39,7 @@
int sugar_detected(void) { return 0; }
char * sugar_get_jobject_file(void) { return NULL; }
void sugar_save_jobject_file(char * path) { }
+ char * sugar_get_savedir(void) { return NULL; }
#endif
#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 74d991a..8ddcea3 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: */
@@ -103,6 +102,10 @@
#define TPAINT_AMASK 0x000000ff
#endif
+char *DATA_PREFIX;
+char *MAGIC_PREFIX;
+char *LOCALEDIR;
+
static unsigned draw_colors(unsigned action);
/* hide all scale-related values here */
@@ -465,6 +468,7 @@ extern WrapperData macosx;
#include "compiler.h"
#include "sugar.h"
+#include "tuxpaint.h"
#if VIDEO_BPP==32
@@ -1580,7 +1584,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);
@@ -5618,9 +5622,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);
@@ -5845,9 +5847,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);
}
@@ -6716,8 +6729,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);
}
@@ -6730,7 +6755,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
@@ -6743,8 +6768,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;
@@ -6894,21 +6919,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;
}
@@ -6996,10 +7023,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: */
@@ -9787,12 +9820,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)
{
@@ -10352,13 +10391,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/templates", DATA_PREFIX);
+ dirname = strdup(fname);
+ }
else
dirname = get_fname("starters", DIR_DATA);
@@ -10527,13 +10569,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);
@@ -11393,8 +11438,11 @@ static void cleanup(void)
#ifdef LOW_QUALITY_COLOR_SELECTOR
free_surface(&img_paintcan);
#else
- free_surface_array(img_color_btns, NUM_COLORS * 2);
- free(img_color_btns);
+ if (img_color_btns)
+ {
+ free_surface_array(img_color_btns, NUM_COLORS * 2);
+ free(img_color_btns);
+ }
#endif
free_surface(&screen);
@@ -17124,8 +17172,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)
{
@@ -17136,8 +17184,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);
}
@@ -20273,6 +20321,8 @@ static void setup_config(char *argv[])
if(tmpcfg_cmd.savedir)
savedir = strdup(tmpcfg_cmd.savedir);
+ else if (sugar_detected())
+ savedir = sugar_get_savedir();
else
{
#ifdef _WIN32
@@ -20836,7 +20886,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)
{
@@ -20980,9 +21040,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;
@@ -20991,9 +21051,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));
@@ -21091,16 +21151,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);
@@ -21271,20 +21331,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,
@@ -21307,54 +21367,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);
@@ -21362,22 +21422,21 @@ 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_down_off =
- loadimage(DATA_PREFIX "images/ui/scroll_down_off.png");
+ img_scroll_up_off = loadimage("images/ui/scroll_up_off.png");
+ img_scroll_down_off = 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
@@ -21389,8 +21448,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);
}
@@ -21401,16 +21460,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);
@@ -21418,7 +21477,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
@@ -21429,9 +21488,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);
@@ -21473,12 +21532,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: */
@@ -21512,7 +21571,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);
@@ -21774,6 +21833,18 @@ int main(int argc, char *argv[])
CLOCK_TYPE time2;
CLOCK_TYPE time3;
+ DATA_PREFIX = getenv("TUXPAINT_DATA_PREFIX");
+ if (DATA_PREFIX == NULL)
+ DATA_PREFIX = DEFAULT_DATA_PREFIX;
+
+ MAGIC_PREFIX = getenv("TUXPAINT_MAGIC_PREFIX");
+ if (MAGIC_PREFIX == NULL)
+ MAGIC_PREFIX = DEFAULT_MAGIC_PREFIX;
+
+ LOCALEDIR = getenv("TUXPAINT_LOCALEDIR");
+ if (LOCALEDIR == NULL)
+ LOCALEDIR = DEFAULT_LOCALEDIR;
+
sugar_init(&argc, &argv);
CLOCK_ASM(time1);
diff --git a/src/tuxpaint.h b/src/tuxpaint.h
new file mode 100644
index 0000000..356318f
--- /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 char *DATA_PREFIX;
+extern char *MAGIC_PREFIX;
+extern char *LOCALEDIR;
+
+#endif