#include <stdio.h>
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
abort();
}
\S{drawing-draw-text} \cw{draw_text()}
\c void draw_text(drawing *dr, int x, int y, int fonttype,
-\c int fontsize, int align, int colour, char *text);
+\c int fontsize, int align, int colour,
+\c const char *text);
Draws text in the puzzle window.
\S{drawing-status-bar} \cw{status_bar()}
-\c void status_bar(drawing *dr, char *text);
+\c void status_bar(drawing *dr, const char *text);
Sets the text in the game's status bar to \c{text}. The text is copied
from the supplied buffer, so the caller is free to deallocate or
\S{drawingapi-draw-text} \cw{draw_text()}
\c void (*draw_text)(void *handle, int x, int y, int fonttype,
-\c int fontsize, int align, int colour, char *text);
+\c int fontsize, int align, int colour,
+\c const char *text);
This function behaves exactly like the back end \cw{draw_text()}
function; see \k{drawing-draw-text}.
\S{drawingapi-status-bar} \cw{status_bar()}
-\c void (*status_bar)(void *handle, char *text);
+\c void (*status_bar)(void *handle, const char *text);
This function behaves exactly like the back end \cw{status_bar()}
function; see \k{drawing-status-bar}.
\H{midend-game-id} \cw{midend_game_id()}
-\c const char *midend_game_id(midend *me, char *id);
+\c const char *midend_game_id(midend *me, const char *id);
Passes the mid-end a string game ID (of any of the valid forms
\cq{params}, \cq{params:description} or \cq{params#seed}) which the
\H{frontend-fatal} \cw{fatal()}
-\c void fatal(char *fmt, ...);
+\c void fatal(const char *fmt, ...);
This is called by some utility functions if they encounter a
genuinely fatal error such as running out of memory. It is a
}
void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text)
+ int align, int colour, const char *text)
{
dr->api->draw_text(dr->handle, x, y, fonttype, fontsize, align,
colour, text);
return NULL; /* placate optimiser */
}
-void status_bar(drawing *dr, char *text)
+void status_bar(drawing *dr, const char *text)
{
char *rewritten;
* Fatal error, called in cases of complete despair such as when
* malloc() has returned NULL.
*/
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
char buf[512];
va_list ap;
js_error_box(buf);
}
-void debug_printf(char *fmt, ...)
+void debug_printf(const char *fmt, ...)
{
char buf[512];
va_list ap;
}
static void js_draw_text(void *handle, int x, int y, int fonttype,
- int fontsize, int align, int colour, char *text)
+ int fontsize, int align, int colour,
+ const char *text)
{
char fontstyle[80];
int halign;
js_canvas_end_draw();
}
-static void js_status_bar(void *handle, char *text)
+static void js_status_bar(void *handle, const char *text)
{
js_canvas_set_statusbar(text);
}
#ifdef DEBUGGING
static FILE *debug_fp = NULL;
-void dputs(char *buf)
+void dputs(const char *buf)
{
if (!debug_fp) {
debug_fp = fopen("debug.log", "w");
}
}
-void debug_printf(char *fmt, ...)
+void debug_printf(const char *fmt, ...)
{
char buf[4096];
va_list ap;
* Error reporting functions used elsewhere.
*/
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
va_list ap;
#endif
}
-void gtk_status_bar(void *handle, char *text)
+void gtk_status_bar(void *handle, const char *text)
{
frontend *fe = (frontend *)handle;
}
void gtk_draw_text(void *handle, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text)
+ int align, int colour, const char *text)
{
frontend *fe = (frontend *)handle;
int i;
me->game_id_change_notify_ctx = ctx;
}
-void midend_supersede_game_desc(midend *me, char *desc, char *privdesc)
+void midend_supersede_game_desc(midend *me, const char *desc,
+ const char *privdesc)
{
sfree(me->desc);
sfree(me->privdesc);
return NULL;
}
-static const char *midend_game_id_int(midend *me, char *id, int defmode)
+static const char *midend_game_id_int(midend *me, const char *id, int defmode)
{
const char *error;
- char *par, *desc, *seed;
+ char *par = NULL;
+ const char *desc, *seed;
game_params *newcurparams, *newparams, *oldparams1, *oldparams2;
int free_params;
* description. So `par' now points to the parameters
* string, and `desc' to the description string.
*/
- *desc++ = '\0';
- par = id;
+ par = snewn(desc-id + 1, char);
+ strncpy(par, id, desc-id);
+ par[desc-id] = '\0';
+ desc++;
seed = NULL;
} else if (seed && (!desc || seed < desc)) {
/*
* So `par' now points to the parameters string, and `seed'
* to the seed string.
*/
- *seed++ = '\0';
- par = id;
+ par = snewn(seed-id + 1, char);
+ strncpy(par, id, seed-id);
+ par[seed-id] = '\0';
+ seed++;
desc = NULL;
} else {
/*
*/
if (defmode == DEF_SEED) {
seed = id;
- par = desc = NULL;
+ par = NULL;
+ desc = NULL;
} else if (defmode == DEF_DESC) {
desc = id;
- par = seed = NULL;
+ par = NULL;
+ seed = NULL;
} else {
- par = id;
+ par = dupstr(id);
seed = desc = NULL;
}
}
me->genmode = GOT_SEED;
}
+ sfree(par);
+
return NULL;
}
-const char *midend_game_id(midend *me, char *id)
+const char *midend_game_id(midend *me, const char *id)
{
return midend_game_id_int(me, id, DEF_PARAMS);
}
return me->ourgame->status(me->states[me->statepos-1].state);
}
-char *midend_rewrite_statusbar(midend *me, char *text)
+char *midend_rewrite_statusbar(midend *me, const char *text)
{
/*
* An important special case is that we are occasionally called
void draw_text_outline(drawing *dr, int x, int y, int fonttype,
int fontsize, int align,
- int text_colour, int outline_colour, char *text)
+ int text_colour, int outline_colour, const char *text)
{
if (outline_colour > -1) {
draw_text(dr, x-1, y, fonttype, fontsize, align, outline_colour, text);
extern void _pause();
extern int _call_java(int cmd, int arg1, int arg2, int arg3);
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
va_list ap;
fprintf(stderr, "fatal error: ");
output[0] = output[1]= output[2] = 0.8f;
}
-void nestedvm_status_bar(void *handle, char *text)
+void nestedvm_status_bar(void *handle, const char *text)
{
_call_java(4,0,(int)text,0);
}
}
void nestedvm_draw_text(void *handle, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text)
+ int align, int colour, const char *text)
{
frontend *fe = (frontend *)handle;
_call_java(5, x + fe->ox, y + fe->oy,
void frontend_default_colour(frontend *fe, float *output) {}
void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text) {}
+ int align, int colour, const char *text) {}
void draw_rect(drawing *dr, int x, int y, int w, int h, int colour) {}
void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour) {}
void draw_thick_line(drawing *dr, float thickness,
{ return 0; }
void print_line_width(drawing *dr, int width) {}
void print_line_dotted(drawing *dr, int dotted) {}
-void midend_supersede_game_desc(midend *me, char *desc, char *privdesc) {}
-void status_bar(drawing *dr, char *text) {}
+void midend_supersede_game_desc(midend *me, const char *desc,
+ const char *privdesc) {}
+void status_bar(drawing *dr, const char *text) {}
struct preset_menu *preset_menu_new(void) {return NULL;}
struct preset_menu *preset_menu_add_submenu(struct preset_menu *parent,
char *title) {return NULL;}
void preset_menu_add_preset(struct preset_menu *parent,
char *title, game_params *params) {}
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
va_list ap;
}
#ifdef DEBUGGING
-void debug_printf(char *fmt, ...)
+void debug_printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
* clearly defined subsystem.
*/
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
va_list ap;
char errorbuf[2048];
return item;
}
-NSMenuItem *newitem(NSMenu *parent, char *title, char *key,
+NSMenuItem *newitem(NSMenu *parent, const char *title, const char *key,
id target, SEL action)
{
return initnewitem([NSMenuItem allocWithZone:[NSMenu menuZone]],
- (void)keyDown:(NSEvent *)ev;
- (void)activateTimer;
- (void)deactivateTimer;
-- (void)setStatusLine:(char *)text;
+- (void)setStatusLine:(const char *)text;
- (void)resizeForNewGameParams;
- (void)updateTypeMenuTick;
@end
last_time = now;
}
-- (void)showError:(char *)message
+- (void)showError:(const char *)message
{
NSAlert *alert;
if (update) {
int k;
config_item *i;
- char *error;
+ const char *error;
k = 0;
for (i = cfg; i->type != C_END; i++) {
[self sheetEndWithStatus:NO];
}
-- (void)setStatusLine:(char *)text
+- (void)setStatusLine:(const char *)text
{
[[status cell] setTitle:[NSString stringWithUTF8String:text]];
}
NSRectFill(r);
}
static void osx_draw_text(void *handle, int x, int y, int fonttype,
- int fontsize, int align, int colour, char *text)
+ int fontsize, int align, int colour,
+ const char *text)
{
frontend *fe = (frontend *)handle;
NSString *string = [NSString stringWithUTF8String:text];
frontend *fe = (frontend *)handle;
[fe->image unlockFocus];
}
-static void osx_status_bar(void *handle, char *text)
+static void osx_status_bar(void *handle, const char *text)
{
frontend *fe = (frontend *)handle;
[fe->window setStatusLine:text];
}
static void ps_draw_text(void *handle, int x, int y, int fonttype,
- int fontsize, int align, int colour, char *text)
+ int fontsize, int align, int colour,
+ const char *text)
{
psdata *ps = (psdata *)handle;
/* We can't use #ifdef DEBUG, because Cygwin defines it by default. */
#ifdef DEBUGGING
#define debug(x) (debug_printf x)
-void debug_printf(char *fmt, ...);
+void debug_printf(const char *fmt, ...);
#else
#define debug(x)
#endif
-void fatal(char *fmt, ...);
+void fatal(const char *fmt, ...);
void frontend_default_colour(frontend *fe, float *output);
void deactivate_timer(frontend *fe);
void activate_timer(frontend *fe);
drawing *drawing_new(const drawing_api *api, midend *me, void *handle);
void drawing_free(drawing *dr);
void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text);
+ int align, int colour, const char *text);
void draw_rect(drawing *dr, int x, int y, int w, int h, int colour);
void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour);
void draw_polygon(drawing *dr, int *coords, int npoints,
void draw_update(drawing *dr, int x, int y, int w, int h);
void end_draw(drawing *dr);
char *text_fallback(drawing *dr, const char *const *strings, int nstrings);
-void status_bar(drawing *dr, char *text);
+void status_bar(drawing *dr, const char *text);
blitter *blitter_new(drawing *dr, int w, int h);
void blitter_free(drawing *dr, blitter *bl);
/* save puts the portion of the current display with top-left corner
enum { CFG_SETTINGS, CFG_SEED, CFG_DESC, CFG_FRONTEND_SPECIFIC };
config_item *midend_get_config(midend *me, int which, char **wintitle);
const char *midend_set_config(midend *me, int which, config_item *cfg);
-const char *midend_game_id(midend *me, char *id);
+const char *midend_game_id(midend *me, const char *id);
char *midend_get_game_id(midend *me);
char *midend_get_random_seed(midend *me);
int midend_can_format_as_text_now(midend *me);
int midend_status(midend *me);
int midend_can_undo(midend *me);
int midend_can_redo(midend *me);
-void midend_supersede_game_desc(midend *me, char *desc, char *privdesc);
-char *midend_rewrite_statusbar(midend *me, char *text);
+void midend_supersede_game_desc(midend *me, const char *desc,
+ const char *privdesc);
+char *midend_rewrite_statusbar(midend *me, const char *text);
void midend_serialise(midend *me,
void (*write)(void *ctx, void *buf, int len),
void *wctx);
* by one pixel; useful for highlighting. Outline is omitted if -1. */
void draw_text_outline(drawing *dr, int x, int y, int fonttype,
int fontsize, int align,
- int text_colour, int outline_colour, char *text);
+ int text_colour, int outline_colour, const char *text);
/* Copies text left-justified with spaces. Length of string must be
* less than buffer size. */
*/
struct drawing_api {
void (*draw_text)(void *handle, int x, int y, int fonttype, int fontsize,
- int align, int colour, char *text);
+ int align, int colour, const char *text);
void (*draw_rect)(void *handle, int x, int y, int w, int h, int colour);
void (*draw_line)(void *handle, int x1, int y1, int x2, int y2,
int colour);
void (*unclip)(void *handle);
void (*start_draw)(void *handle);
void (*end_draw)(void *handle);
- void (*status_bar)(void *handle, char *text);
+ void (*status_bar)(void *handle, const char *text);
blitter *(*blitter_new)(void *handle, int w, int h);
void (*blitter_free)(void *handle, blitter *bl);
void (*blitter_save)(void *handle, blitter *bl, int x, int y);
#if 0 /* currently unused */
-static void debug_printf(char *fmt, ...)
+static void debug_printf(const char *fmt, ...)
{
char buf[4096];
va_list ap;
#ifdef TEST_GENERAL
#include <stdarg.h>
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
va_list ap;
*/
ret = NULL;
{
- char *sep;
+ const char *sep;
char buf[80];
int retlen;
edge *ea;
OutputDebugString(buf);
}
-void debug_printf(char *fmt, ...)
+void debug_printf(const char *fmt, ...)
{
char buf[4096];
va_list ap;
static void update_type_menu_tick(frontend *fe);
static void update_copy_menu_greying(frontend *fe);
-void fatal(char *fmt, ...)
+void fatal(const char *fmt, ...)
{
char buf[2048];
va_list ap;
*randseedsize = sizeof(SYSTEMTIME);
}
-static void win_status_bar(void *handle, char *text)
+static void win_status_bar(void *handle, const char *text)
{
#ifdef _WIN32_WCE
TCHAR wText[255];
}
static void win_draw_text(void *handle, int x, int y, int fonttype,
- int fontsize, int align, int colour, char *text)
+ int fontsize, int align, int colour,
+ const char *text)
{
frontend *fe = (frontend *)handle;
POINT xy;