options working fairly well

This commit is contained in:
Albert Cahalan 2009-11-23 07:45:24 +00:00
parent f3441070e8
commit e3a971194c
12 changed files with 152 additions and 95 deletions

View file

@ -1033,7 +1033,7 @@ PLUGIN_LIBS:=$($(OS)_PLUGIN_LIBS)
#MAGIC_CFLAGS:=-g3 -O2 -fvisibility=hidden -fno-common -W -Wstrict-prototypes -Wmissing-prototypes -Wall $(MAGIC_SDL_CPPFLAGS) -Isrc/
MAGIC_CFLAGS:=-g3 -O2 -fno-common -W -Wstrict-prototypes -Wmissing-prototypes -Wall $(MAGIC_SDL_CPPFLAGS) -Isrc/
SHARED_FLAGS:=-shared -fpic
SHARED_FLAGS:=-shared -fpic -Wl,--warn-shared-textrel
MAGIC_C:=$(wildcard magic/src/*.c)
MAGIC_SO:=$(patsubst magic/src/%.c,magic/%.$(SO_TYPE),$(MAGIC_C))

View file

@ -68,7 +68,7 @@
///////////////// directory walking callers and callbacks //////////////////
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, char * locale)
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale)
{
dirlen = dirlen;
@ -107,8 +107,8 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
char fname[512];
TuxPaint_Font *font;
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
/* printf("Loading font: %s (locale is: %s)\n", fname, (locale != NULL ? locale : "NULL")); */
if (locale != NULL && strstr(fname, "locale") != NULL && all_locale_fonts == 0)
/* printf("Loading font: %s (locale is: %s)\n", fname, (locale ? locale : "NULL")); */
if (locale && strstr(fname, "locale") && !all_locale_fonts)
{
char fname_check[512];
/* We're (probably) loading from our locale fonts folder; ONLY load our locale's font */
@ -261,8 +261,8 @@ void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count, char * locale),
char * locale)
unsigned count, const char *restrict const locale),
const char *restrict const locale)
{
DIR *d;
unsigned num_file_names = 0;

View file

@ -46,13 +46,13 @@ typedef struct tp_ftw_str
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files, unsigned i, char * locale);
unsigned dirlen, tp_ftw_str * files, unsigned i, const char *restrict const locale);
int compare_ftw_str(const void *v1, const void *v2);
void tp_ftw(SDL_Surface * screen, char *restrict const dir, unsigned dirlen,
int rsrc, void (*fn) (SDL_Surface * screen,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned count, char * locale),
char * locale);
unsigned count, const char *restrict const locale),
const char *restrict const locale);
#endif

View file

@ -920,7 +920,7 @@ static void groupfonts(void)
}
static void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, const char *restrict locale)
static void loadfonts_locale_filter(SDL_Surface * screen, const char *const dir, const char *restrict const locale)
{
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir);
@ -935,7 +935,7 @@ static void loadfonts(SDL_Surface * screen, const char *const dir)
}
static int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict locale)
static int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict const locale)
{
char *homedirdir;
@ -997,7 +997,7 @@ static int load_user_fonts(SDL_Surface * screen, void *vp, const char *restrict
void run_font_scanner(SDL_Surface * screen, const char *restrict locale)
void run_font_scanner(SDL_Surface * screen, const char *restrict const locale)
{
int sv[2];
int size, i;

View file

@ -106,7 +106,7 @@ int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
#ifdef FORKED_FONTS
void reliable_write(int fd, const void *buf, size_t count);
void run_font_scanner(SDL_Surface * screen, const char *restrict locale);
void run_font_scanner(SDL_Surface * screen, const char *restrict const locale);
void receive_some_font_info(SDL_Surface * screen);
#endif

View file

@ -28,18 +28,7 @@
#include "get_fname.h"
#include "debug.h"
char *savedir;
char *datadir;
/* The filename for the current image: */
char *get_fname(const char *const name, int kind)
{
char f[512];
char * dir;
#include "compiler.h"
/* DIR_SAVE: Where is the user's saved directory?
This is where their saved files are stored
@ -58,43 +47,23 @@ char *get_fname(const char *const name, int kind)
DIR_DATA: Where is the user's data directory?
This is where local fonts, brushes and stamps can be found. */
if (kind == DIR_SAVE)
dir = savedir;
else if (kind == DIR_DATA)
dir = datadir;
else
return NULL;
const char *savedir;
const char *datadir;
#ifdef WIN32
snprintf(f, sizeof(f), "%s/%s", dir, name);
#elif __BEOS__
if (*name == '\0')
strcpy(f, dir);
else
snprintf(f, sizeof(f), "%s/%s", dir, name);
#endif
// FIXME: We shouldn't be allocating memory all the time.
// There should be distinct functions for each directory.
// There should be distinct functions for each thread,
// for caller-provided space, and maybe callee strdup.
// That's at most 4 functions per Tux Paint thread.
char *get_fname(const char *const name, int kind)
{
char f[512];
const char *restrict const dir = (kind==DIR_SAVE) ? savedir : datadir;
/* Put together home directory path + settings directory + filename... */
if (dir == NULL)
{
fprintf(stderr, "Warning: get_fname() has a NULL dir...!?\n");
return strdup(name);;
}
if (*name != '\0')
{
/* (Some mkdir()'s don't like trailing slashes) */
snprintf(f, sizeof(f), "%s/%s", dir, name);
}
else
{
snprintf(f, sizeof(f), "%s", dir);
}
// Some mkdir()'s don't like trailing slashes
snprintf(f, sizeof(f), "%s%c%s", dir, (*name)?'/':'\0', name);
return strdup(f);
}

View file

@ -25,8 +25,8 @@
#ifndef GET_FNAME_H
#define GET_FNAME_H
extern char *savedir;
extern char *datadir;
extern const char *savedir;
extern const char *datadir;
enum {
DIR_SAVE,

View file

@ -14,7 +14,7 @@
#include <ctype.h>
#include <stdint.h>
static const char PARSE_YES[] = "yes";
const char PARSE_YES[] = "yes";
const char PARSE_NO[] = "no";
const char PARSE_CLOBBER[] = ":-("; // for painful lang/locale priority situation
@ -27,13 +27,13 @@ struct cfg
#define MULTIVAL 0x00000000
#define POS 0x00000001
#define NEG 0x00000002
#define BOOL (POS|NEG)
#define BOOLMASK (POS|NEG)
#define BITS 2 // if this grows past 2, must shift the offset
#define FLAGMASK ((1<<BITS)-1)
#define MULTI(x) (void*)(offsetof(struct cfginfo,x)|MULTIVAL)
#define POSBOOL(x) (void*)(offsetof(struct cfginfo,x)|POS|BOOL)
#define NEGBOOL(x) (void*)(offsetof(struct cfginfo,x)|NEG|BOOL)
#define POSBOOL(x) (void*)(offsetof(struct cfginfo,x)|POS)
#define NEGBOOL(x) (void*)(offsetof(struct cfginfo,x)|NEG)
#define IMM(x) imm_##x
static void imm_version(void)
@ -173,7 +173,7 @@ void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const ch
uintptr_t uintptr = cfg ? (uintptr_t)cfg->val : 0;
unsigned flags = (uintptr<CFGINFO_MAXOFFSET) ? (uintptr & FLAGMASK) : 0;
if(!cfg || (!(flags & BOOL) && noflag) )
if(!cfg || (!(flags & BOOLMASK) && noflag) )
{
if(src)
printf("Unknown option '%s' in config file '%s'\n",str,src);
@ -199,7 +199,7 @@ void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const ch
exit(0);
}
if(flags & BOOL)
if(flags & BOOLMASK)
{
int flip = !!noflag ^ !!(flags & NEG);
if(!opt)

View file

@ -1,7 +1,7 @@
#pragma once
#include "compiler.h"
//extern const char PARSE_YES[];
extern const char PARSE_YES[];
extern const char PARSE_NO[];
extern const char PARSE_CLOBBER[];

View file

@ -78,10 +78,9 @@ static int f2dec(float f)
/* Actually save the PostScript data to the file stream: */
int do_ps_save(FILE * fi,
// const char *restrict const fname,
const char * fname,
const char *restrict const fname,
SDL_Surface * surf,
char * pprsize,
const char *restrict pprsize,
int is_pipe)
{
const struct paper * ppr;
@ -113,13 +112,13 @@ int do_ps_save(FILE * fi,
in config file), ask the system. It will return either their
$PAPER env. var., the value from /etc/papersize, or NULL: */
pprsize = (char *) systempapername();
pprsize = systempapername();
if (pprsize == NULL)
{
/* No setting, env. var. or /etc/ file; use the default! */
pprsize = (char *) defaultpapername();
pprsize = defaultpapername();
#ifdef DEBUG
printf("Using default paper\n");

View file

@ -36,6 +36,7 @@
#include <stdio.h>
#include <sys/wait.h>
#include "SDL.h"
#include "compiler.h"
/* Method for printing images: */
@ -78,10 +79,9 @@
#ifdef PRINTMETHOD_PS
int do_ps_save(FILE * fi,
// const char *restrict const fname,
const char *fname,
const char *restrict const fname,
SDL_Surface * surf,
char * pprsize,
const char *restrict pprsize,
int is_pipe);
#endif

View file

@ -1107,7 +1107,7 @@ static magic_api *magic_api_struct; /* Pointer to our internal functions; passed
#endif
static const char *printcommand = PRINTCOMMAND;
static const char *altprintcommand = ALTPRINTCOMMAND;
char *papersize = NULL;
static const char *papersize;
#endif
@ -5657,7 +5657,7 @@ static unsigned compute_default_scale_factor(double ratio)
static void loadbrush_callback(SDL_Surface * screen,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned i, char * locale)
unsigned i, const char *restrict const locale)
{
FILE * fi;
char buf[64];
@ -5745,7 +5745,7 @@ static void loadbrush_callback(SDL_Surface * screen,
static void load_brush_dir(SDL_Surface * screen, const char *const dir)
static void load_brush_dir(SDL_Surface * screen, const char *restrict const dir)
{
char buf[TP_FTW_PATHSIZE];
unsigned dirlen = strlen(dir);
@ -6489,7 +6489,7 @@ static void get_stamp_thumb(stamp_type * sd)
static void loadstamp_callback(SDL_Surface * screen,
const char *restrict const dir,
unsigned dirlen, tp_ftw_str * files,
unsigned i, char * locale)
unsigned i, const char *restrict const locale)
{
(void)locale;
#ifdef DEBUG
@ -11307,8 +11307,8 @@ static void cleanup(void)
}
#if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__)
if (papersize != NULL)
free(papersize);
// if (papersize != NULL)
// free(papersize);
#endif
@ -14593,15 +14593,15 @@ void do_print(void)
SDL_BlitSurface(label, NULL, save_canvas, NULL);
#if !defined(WIN32) && !defined(__BEOS__) && !defined(__APPLE__)
char *pcmd;
const char *pcmd;
FILE *pi;
/* Linux, Unix, etc. */
if (want_alt_printcommand && !fullscreen)
pcmd = (char *) altprintcommand;
pcmd = altprintcommand;
else
pcmd = (char *) printcommand;
pcmd = printcommand;
pi = popen(pcmd, "w");
@ -18901,12 +18901,13 @@ static void undo_tmp_applied_text()
/////////////////////////////////////////////////////////////////////////////
#if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__)
static void show_available_papersizes(FILE * fi, const char * prg)
static void show_available_papersizes(int exitcode)
{
FILE *fi = exitcode ? stderr : stdout;
const struct paper * ppr;
int cnt;
fprintf(fi, "Usage: %s [--papersize PAPERSIZE]\n", prg);
fprintf(fi, "Usage: %s [--papersize PAPERSIZE]\n", progname);
fprintf(fi, "\n");
fprintf(fi, "PAPERSIZE may be one of:\n");
@ -19083,7 +19084,7 @@ static void setup_config(char *argv[])
#elif __APPLE__
savedir = strdup(macosx.preferencesPath);
#else
asprintf(&savedir, "%s/%s", home, ".tuxpaint");
asprintf((char**)&savedir, "%s/%s", home, ".tuxpaint");
#endif
}
@ -19127,7 +19128,7 @@ static void setup_config(char *argv[])
if(tmpcfg.savedir)
{
free(savedir);
free((char*)savedir);
savedir = tmpcfg.savedir;
}
@ -19139,19 +19140,107 @@ static void setup_config(char *argv[])
tmpcfg.parsertmp_locale = NULL;
button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale);
#if 0
all_locale_fonts
no_system_fonts
parsertmp_windowsize
parsertmp_fullscreen_native
// FIXME: most of this is not required before starting the font scanner
if(tmpcfg_cmd.papersize && !strcmp(tmpcfg_cmd.papersize, "help"))
show_available_papersizes(0);
#endif
#define SETBOOL(x) do{ if(tmpcfg.x) x = (tmpcfg.x==PARSE_YES); }while(0)
SETBOOL(all_locale_fonts);
SETBOOL(autosave_on_quit);
SETBOOL(disable_label);
SETBOOL(disable_magic_controls);
SETBOOL(disable_print);
SETBOOL(disable_quit);
SETBOOL(disable_save);
SETBOOL(disable_screensaver);
SETBOOL(disable_stamp_controls);
SETBOOL(dont_do_xor);
SETBOOL(dont_load_stamps);
SETBOOL(fullscreen);
SETBOOL(grab_input);
SETBOOL(hide_cursor);
SETBOOL(keymouse);
SETBOOL(mirrorstamps);
SETBOOL(native_screensize);
SETBOOL(no_button_distinction);
SETBOOL(no_fancy_cursors);
SETBOOL(no_system_fonts);
SETBOOL(noshortcuts);
SETBOOL(ok_to_use_lockfile);
SETBOOL(only_uppercase);
SETBOOL(simple_shapes);
SETBOOL(start_blank);
SETBOOL(use_print_config);
SETBOOL(use_sound);
SETBOOL(wheely);
#undef SETBOOL
if(tmpcfg.parsertmp_windowsize)
{
char *endp1;
char *endp2;
int w = strtoul(tmpcfg.parsertmp_windowsize, &endp1, 10);
int h = strtoul(endp1 + 1, &endp2, 10);
if (tmpcfg.parsertmp_windowsize==endp1 || endp1+1==endp2 || *endp1!='x' || *endp2)
{
fprintf(stderr,"Window size '%s' is not understood.\n",tmpcfg.parsertmp_windowsize);
exit(97);
}
if (w<500 || w>32000 || h<480 || h>32000 || h>w*3 || w>h*4)
{
fprintf(stderr,"Window size '%s' is not reasonable.\n",tmpcfg.parsertmp_windowsize);
exit(93);
}
WINDOW_WIDTH = w;
WINDOW_HEIGHT = h;
}
if(tmpcfg.parsertmp_fullscreen_native)
{
// 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");
}
if(tmpcfg.stamp_size_override)
{
if (!strcmp(tmpcfg.stamp_size_override, "default"))
stamp_size_override = -1;
else
{
// 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)
if(tmpcfg.rotate_orientation)
rotate_orientation = !strcmp(tmpcfg.rotate_orientation, "portrait"); // alternative is "landscape"
if(tmpcfg.colorfile)
strcpy(colorfile, tmpcfg.colorfile); // FIXME can overflow
if(tmpcfg.print_delay)
print_delay = atoi(tmpcfg.print_delay);
if(tmpcfg.printcommand)
printcommand = tmpcfg.printcommand;
if(tmpcfg.altprintcommand)
altprintcommand = tmpcfg.altprintcommand;
if(tmpcfg.alt_print_command_default)
{
// 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")
}
if(tmpcfg.papersize)
papersize = tmpcfg.papersize;
}
static void chdir_to_binary(char *argv0)
{
#if defined(__BEOS__) || defined(WIN32)