commit
f96b8abc49
22
src/child.c
22
src/child.c
@ -34,7 +34,8 @@ int child_writer_dead_handler(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void child_process_score_writer(int chfd, gchar *score_file) {
|
void child_process_score_writer(int chfd, gchar *score_file)
|
||||||
|
{
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
int i;
|
int i;
|
||||||
int fd=-1;
|
int fd=-1;
|
||||||
@ -44,10 +45,12 @@ void child_process_score_writer(int chfd, gchar *score_file) {
|
|||||||
struct flock lockinfo;
|
struct flock lockinfo;
|
||||||
gchar *score_file_full = g_strconcat(LOCALSTATEDIR, score_file, NULL);
|
gchar *score_file_full = g_strconcat(LOCALSTATEDIR, score_file, NULL);
|
||||||
|
|
||||||
while(1) {
|
while (1)
|
||||||
|
{
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(chfd, &rfds);
|
FD_SET(chfd, &rfds);
|
||||||
if(select(chfd + 1, &rfds, NULL, NULL, NULL) > 0) {
|
if (select(chfd + 1, &rfds, NULL, NULL, NULL) > 0)
|
||||||
|
{
|
||||||
if (read(chfd, &sz, sizeof(sz)) <= 0) {
|
if (read(chfd, &sz, sizeof(sz)) <= 0) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -68,7 +71,9 @@ void child_process_score_writer(int chfd, gchar *score_file) {
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
lockinfo.l_type=F_WRLCK;
|
lockinfo.l_type=F_WRLCK;
|
||||||
if(!fcntl(fd, F_SETLK, &lockinfo)) break;
|
if (!fcntl(fd, F_SETLK, &lockinfo)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (i >= 3) {
|
if (i >= 3) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
@ -89,15 +94,15 @@ void child_process_score_writer(int chfd, gchar *score_file) {
|
|||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
/* FIXME: here should be some sort of error
|
/* FIXME: here should be some sort of error reporting to parent */
|
||||||
reporting to parent */
|
|
||||||
}
|
}
|
||||||
sigprocmask(SIG_UNBLOCK, &sset, NULL);
|
sigprocmask(SIG_UNBLOCK, &sset, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigchld_handler(int param) {
|
static void sigchld_handler(int param)
|
||||||
|
{
|
||||||
pid_t ret = waitpid(0, NULL, WNOHANG);
|
pid_t ret = waitpid(0, NULL, WNOHANG);
|
||||||
|
|
||||||
if (ret > 0) { /* score writer process killed by bastards! */
|
if (ret > 0) { /* score writer process killed by bastards! */
|
||||||
@ -105,7 +110,8 @@ static void sigchld_handler(int param) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int child_setup(gchar *score_file) {
|
int child_setup(gchar *score_file)
|
||||||
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct sigaction sact;
|
struct sigaction sact;
|
||||||
int sfds[2];
|
int sfds[2];
|
||||||
|
117
src/game.c
117
src/game.c
@ -141,18 +141,21 @@ void rules_set(gint width, gint height, gint colors, gint next, gint destroy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean _rules_check_rules(GtkbGameRules r) {
|
gboolean _rules_check_rules(GtkbGameRules r) {
|
||||||
if((r.width < 4 || r.width > 99) ||
|
if ((r.width < 4 || r.width > 99)
|
||||||
(r.height < 4 || r.height > 99) ||
|
|| (r.height < 4 || r.height > 99)
|
||||||
(r.colors < 3 || r.colors > 99) ||
|
|| (r.colors < 3 || r.colors > 99)
|
||||||
(r.next < 2 || r.next > 99) ||
|
|| (r.next < 2 || r.next > 99)
|
||||||
(r.destroy < 3 || r.destroy > 99))
|
|| (r.destroy < 3 || r.destroy > 99))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *_rules_to_str(GtkbGameRules r) {
|
gchar *_rules_to_str(GtkbGameRules r) {
|
||||||
if(!_rules_check_rules(r))
|
if (!_rules_check_rules(r)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return g_strdup_printf(_save_fmt, r.width, r.height, r.colors, r.next, r.destroy);
|
return g_strdup_printf(_save_fmt, r.width, r.height, r.colors, r.next, r.destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,14 +181,16 @@ gboolean rules_check_str(gchar *rstr) {
|
|||||||
strstr(rstr, "\n") ||
|
strstr(rstr, "\n") ||
|
||||||
sscanf(rstr, _save_fmt, &r.width, &r.height, &r.colors, &r.next, &r.destroy) != 5 ||
|
sscanf(rstr, _save_fmt, &r.width, &r.height, &r.colors, &r.next, &r.destroy) != 5 ||
|
||||||
!_rules_check_rules(r))
|
!_rules_check_rules(r))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean rules_get_from_str(gchar *s, gint *width, gint *height, gint *colors, gint *next, gint *destroy) {
|
gboolean rules_get_from_str(gchar *s, gint *width, gint *height, gint *colors, gint *next, gint *destroy) {
|
||||||
if(!rules_check_str(s))
|
if (!rules_check_str(s)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
sscanf(s, _save_fmt, width, height, colors, next, destroy);
|
sscanf(s, _save_fmt, width, height, colors, next, destroy);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -193,9 +198,9 @@ gboolean rules_get_from_str(gchar *s, gint *width, gint *height, gint *colors, g
|
|||||||
gchar *rules_conv_3_0_to_str(gchar *w, gchar *h, gchar *c, gchar *n, gchar *d) {
|
gchar *rules_conv_3_0_to_str(gchar *w, gchar *h, gchar *c, gchar *n, gchar *d) {
|
||||||
GtkbGameRules r;
|
GtkbGameRules r;
|
||||||
|
|
||||||
if(!w[0] || !h[0] || !c[0] || !n[0] || !d[0])
|
if (!w[0] || !h[0] || !c[0] || !n[0] || !d[0]) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
r.width = strtol(w, NULL, 10);
|
r.width = strtol(w, NULL, 10);
|
||||||
r.height = strtol(h, NULL, 10);
|
r.height = strtol(h, NULL, 10);
|
||||||
r.colors = strtol(c, NULL, 10);
|
r.colors = strtol(c, NULL, 10);
|
||||||
@ -209,8 +214,9 @@ gboolean rules_is_current_str(gchar *r) {
|
|||||||
gboolean rval = 0;
|
gboolean rval = 0;
|
||||||
gchar *cur = _rules_to_str(_rules);
|
gchar *cur = _rules_to_str(_rules);
|
||||||
|
|
||||||
if(strcmp(r, cur) == 0)
|
if (strcmp(r, cur) == 0) {
|
||||||
rval = 1;
|
rval = 1;
|
||||||
|
}
|
||||||
g_free(cur);
|
g_free(cur);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
@ -240,26 +246,33 @@ void game_save_state_for_undo(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void game_restore_state_from_undo(void) {
|
void game_restore_state_from_undo(void) {
|
||||||
if(_score_undo == -1 || _hi_score_undo == -1)
|
if (_score_undo == -1 || _hi_score_undo == -1) {
|
||||||
/* cannot undo */
|
/* cannot undo */
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
memcpy(_board, _board_undo, sizeof(gint) * _rules.width * _rules.height);
|
memcpy(_board, _board_undo, sizeof(gint) * _rules.width * _rules.height);
|
||||||
memcpy(_next_colors, _next_colors_undo, sizeof(gint) * _rules.next);
|
memcpy(_next_colors, _next_colors_undo, sizeof(gint) * _rules.next);
|
||||||
_score = _score_undo;
|
_score = _score_undo;
|
||||||
_hi_score = _hi_score_undo;
|
_hi_score = _hi_score_undo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_init_game(gint *balls, gint *nextballs) {
|
void game_init_game(gint *balls, gint *nextballs)
|
||||||
if(_board)
|
{
|
||||||
|
if (_board) {
|
||||||
g_free(_board);
|
g_free(_board);
|
||||||
if(_board_undo)
|
}
|
||||||
|
if (_board_undo) {
|
||||||
g_free(_board_undo);
|
g_free(_board_undo);
|
||||||
if(_board_destroys)
|
}
|
||||||
|
if (_board_destroys) {
|
||||||
g_free(_board_destroys);
|
g_free(_board_destroys);
|
||||||
if(_next_colors)
|
}
|
||||||
|
if (_next_colors) {
|
||||||
g_free(_next_colors);
|
g_free(_next_colors);
|
||||||
if(_next_colors_undo)
|
}
|
||||||
|
if (_next_colors_undo) {
|
||||||
g_free(_next_colors_undo);
|
g_free(_next_colors_undo);
|
||||||
|
}
|
||||||
_board = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
|
_board = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
|
||||||
_board_destroys = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
|
_board_destroys = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
|
||||||
if (balls) {
|
if (balls) {
|
||||||
@ -280,10 +293,10 @@ gint game_count_free_cells(void) {
|
|||||||
gint i, counter = 0;
|
gint i, counter = 0;
|
||||||
gint *bp = _board;
|
gint *bp = _board;
|
||||||
|
|
||||||
for(i = 0; i < _rules.width * _rules.height; i++)
|
for (i = 0; i < _rules.width * _rules.height; i++) {
|
||||||
if (*bp++ == 0)
|
if (*bp++ == 0)
|
||||||
counter++;
|
counter++;
|
||||||
|
}
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,44 +317,51 @@ gint *game_get_next_as_int_arr(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gint board_get_at_node(gint node) {
|
gint board_get_at_node(gint node) {
|
||||||
if(node >= _rules.width * _rules.height)
|
if (node >= _rules.width * _rules.height) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return _board[node];
|
return _board[node];
|
||||||
}
|
}
|
||||||
|
|
||||||
gint board_get_at_xy(gint x, gint y) {
|
gint board_get_at_xy(gint x, gint y) {
|
||||||
if(x >= _rules.width || y > _rules.height)
|
if (x >= _rules.width || y > _rules.height) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return _board[y * _rules.width + x];
|
return _board[y * _rules.width + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
gint board_get_destroy_at_xy(gint x, gint y) {
|
gint board_get_destroy_at_xy(gint x, gint y) {
|
||||||
if(x >= _rules.width || y > _rules.height)
|
if (x >= _rules.width || y > _rules.height) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return _board_destroys[y * _rules.width + x];
|
return _board_destroys[y * _rules.width + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
void board_set_at_node(gint node, gint col) {
|
void board_set_at_node(gint node, gint col) {
|
||||||
if(node >= _rules.width * _rules.height)
|
if (node >= _rules.width * _rules.height) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
_board[node] = col;
|
_board[node] = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
void board_set_at_xy(gint x, gint y, gint col) {
|
void board_set_at_xy(gint x, gint y, gint col) {
|
||||||
if(x >= _rules.width || y > _rules.height)
|
if (x >= _rules.width || y > _rules.height) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
_board[y * _rules.width + x] = col;
|
_board[y * _rules.width + x] = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint next_get(gint num) {
|
gint next_get(gint num) {
|
||||||
if(num >= _rules.next)
|
if (num >= _rules.next) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return _next_colors[num];
|
return _next_colors[num];
|
||||||
}
|
}
|
||||||
|
|
||||||
void next_set(gint num, gint col) {
|
void next_set(gint num, gint col) {
|
||||||
if(num >= _rules.next)
|
if (num >= _rules.next) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
_next_colors[num] = col;
|
_next_colors[num] = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,16 +370,18 @@ void timer_start(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean timer_is_running(void) {
|
gboolean timer_is_running(void) {
|
||||||
if(_timer_start_time == -1 || _timer_limit <= 0)
|
if (_timer_start_time == -1 || _timer_limit <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean timer_is_expired(void) {
|
gboolean timer_is_expired(void) {
|
||||||
time_t nowt = time(NULL);
|
time_t nowt = time(NULL);
|
||||||
|
|
||||||
if(nowt - _timer_start_time >= _timer_limit)
|
if (nowt - _timer_start_time >= _timer_limit) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,13 +403,20 @@ struct gtkb_animarray {
|
|||||||
gint color, x, y, phase, time;
|
gint color, x, y, phase, time;
|
||||||
};
|
};
|
||||||
|
|
||||||
int animsort(const void *a, const void *b) {
|
int animsort(const void *a, const void *b)
|
||||||
if(((const struct gtkb_animarray *)a)->time == ((const struct gtkb_animarray *)b)->time) return 0;
|
{
|
||||||
if(((const struct gtkb_animarray *)a)->time > ((const struct gtkb_animarray *)b)->time) return 1;
|
if (((const struct gtkb_animarray *)a)->time == ((const struct gtkb_animarray *)b)->time) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (((const struct gtkb_animarray *)a)->time > ((const struct gtkb_animarray *)b)->time) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint game_destroy_lines(gboolean count_score) {
|
|
||||||
|
gint game_destroy_lines(gboolean count_score)
|
||||||
|
{
|
||||||
gint x, y, i, j;
|
gint x, y, i, j;
|
||||||
gint *del, have_del = 0;
|
gint *del, have_del = 0;
|
||||||
|
|
||||||
@ -398,8 +427,10 @@ gint game_destroy_lines(gboolean count_score) {
|
|||||||
|
|
||||||
del = g_malloc0(rules_get_width() * rules_get_height() * sizeof(gint));
|
del = g_malloc0(rules_get_width() * rules_get_height() * sizeof(gint));
|
||||||
|
|
||||||
for(y = 0; y < rules_get_height(); y++) {
|
for (y = 0; y < rules_get_height(); y++)
|
||||||
for(x = 0; x < rules_get_width(); x++) {
|
{
|
||||||
|
for (x = 0; x < rules_get_width(); x++)
|
||||||
|
{
|
||||||
if (board_get_at_xy(x, y) != 0) {
|
if (board_get_at_xy(x, y) != 0) {
|
||||||
/* horizontal */
|
/* horizontal */
|
||||||
if (rules_get_width() - x >= rules_get_destroy()) {
|
if (rules_get_width() - x >= rules_get_destroy()) {
|
||||||
@ -460,16 +491,21 @@ gint game_destroy_lines(gboolean count_score) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if(have_del) {
|
if (have_del)
|
||||||
if(pref_get_show_destroy()) {
|
{
|
||||||
|
if (pref_get_show_destroy())
|
||||||
|
{
|
||||||
gint animcadres = 0, animpos = 0, animtime;
|
gint animcadres = 0, animpos = 0, animtime;
|
||||||
struct gtkb_animarray *animarray;
|
struct gtkb_animarray *animarray;
|
||||||
struct timeval tvs, tve;
|
struct timeval tvs, tve;
|
||||||
|
|
||||||
animarray = g_new0(struct gtkb_animarray, rules_get_width() * rules_get_height() * gtkbTheme->maxdestphases);
|
animarray = g_new0(struct gtkb_animarray, rules_get_width() * rules_get_height() * gtkbTheme->maxdestphases);
|
||||||
for(y = 0; y < rules_get_height(); y++) {
|
for (y = 0; y < rules_get_height(); y++)
|
||||||
for(x = 0; x < rules_get_width(); x++) {
|
{
|
||||||
|
for (x = 0; x < rules_get_width(); x++)
|
||||||
|
{
|
||||||
if (del[y * rules_get_width() + x] == 1) {
|
if (del[y * rules_get_width() + x] == 1) {
|
||||||
gint color = board_get_at_xy(x, y);
|
gint color = board_get_at_xy(x, y);
|
||||||
|
|
||||||
@ -494,7 +530,8 @@ gint game_destroy_lines(gboolean count_score) {
|
|||||||
qsort(animarray, animcadres, sizeof(struct gtkb_animarray), animsort);
|
qsort(animarray, animcadres, sizeof(struct gtkb_animarray), animsort);
|
||||||
lock_actions(1);
|
lock_actions(1);
|
||||||
draw_board();
|
draw_board();
|
||||||
for(animtime = 0, i = 0; i < animcadres;) {
|
for (animtime = 0, i = 0; i < animcadres;)
|
||||||
|
{
|
||||||
gettimeofday(&tvs, NULL);
|
gettimeofday(&tvs, NULL);
|
||||||
gint isav = i;
|
gint isav = i;
|
||||||
for (; animtime == animarray[i].time && i < animcadres; i++) {
|
for (; animtime == animarray[i].time && i < animcadres; i++) {
|
||||||
|
57
src/gfx.c
57
src/gfx.c
@ -45,15 +45,18 @@ gint xy_to_cell_number(gint x, gint y) {
|
|||||||
return find_node_of_x_y(x, y, rules_get_width());
|
return find_node_of_x_y(x, y, rules_get_width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gint get_jump_phase(gint x, gint y) {
|
gint get_jump_phase(gint x, gint y) {
|
||||||
if(!_animation_in_progress || xy_to_cell_number(x, y) != _jumping_ball)
|
if (!_animation_in_progress || xy_to_cell_number(x, y) != _jumping_ball) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return _phase;
|
return _phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_jump_phase(gint p) {
|
void set_jump_phase(gint p) {
|
||||||
if(!_animation_in_progress)
|
if (!_animation_in_progress) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
_phase = p;
|
_phase = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +75,8 @@ void update_rectangle(gint x, gint y, gint w, gint h) {
|
|||||||
_pixmap, x, y, x, y, w, h);
|
_pixmap, x, y, x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_ball_no_update(gint ballcolor, gint x, gint y, gint jumpnum, gint destroynum) {
|
void draw_ball_no_update(gint ballcolor, gint x, gint y, gint jumpnum, gint destroynum)
|
||||||
|
{
|
||||||
GtkWidget *widget = mw_get_da();
|
GtkWidget *widget = mw_get_da();
|
||||||
GdkGC *gc = widget->style->fg_gc[gtk_widget_get_state(widget)];
|
GdkGC *gc = widget->style->fg_gc[gtk_widget_get_state(widget)];
|
||||||
gint cxs = gtkbTheme->emptycell.xsize;
|
gint cxs = gtkbTheme->emptycell.xsize;
|
||||||
@ -158,14 +162,16 @@ void draw_board(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gint inc_with_limit(gint val, gint lim) {
|
gint inc_with_limit(gint val, gint lim) {
|
||||||
if(val < lim)
|
if (val < lim) {
|
||||||
return val + 1;
|
return val + 1;
|
||||||
|
}
|
||||||
return lim;
|
return lim;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint dec_with_limit(gint val, gint lim) {
|
gint dec_with_limit(gint val, gint lim) {
|
||||||
if(val > lim)
|
if (val > lim) {
|
||||||
return val - 1;
|
return val - 1;
|
||||||
|
}
|
||||||
return lim;
|
return lim;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,15 +200,17 @@ void stop_jumping_animation(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_pointer_to(gint x, gint y) {
|
void move_pointer_to(gint x, gint y)
|
||||||
|
{
|
||||||
gint i, jp, dp, xc = _pointer_x, yc = _pointer_y;
|
gint i, jp, dp, xc = _pointer_x, yc = _pointer_y;
|
||||||
|
|
||||||
if(x >= rules_get_width() || y >= rules_get_height() || x < 0 || y < 0)
|
if (x >= rules_get_width() || y >= rules_get_height() || x < 0 || y < 0) {
|
||||||
/* "boundary check" */
|
/* "boundary check" */
|
||||||
return;
|
return;
|
||||||
if(_pointer_x == x && _pointer_y == y)
|
}
|
||||||
|
if (_pointer_x == x && _pointer_y == y) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
_pointer_x = x;
|
_pointer_x = x;
|
||||||
_pointer_y = y;
|
_pointer_y = y;
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
@ -219,17 +227,21 @@ void move_pointer_to(gint x, gint y) {
|
|||||||
void move_pointer(Direction dir) {
|
void move_pointer(Direction dir) {
|
||||||
gint xn = _pointer_x, yn = _pointer_y;
|
gint xn = _pointer_x, yn = _pointer_y;
|
||||||
|
|
||||||
if(dir == DIR_LEFT || dir == DIR_UP_LEFT || dir == DIR_DOWN_LEFT)
|
if (dir == DIR_LEFT || dir == DIR_UP_LEFT || dir == DIR_DOWN_LEFT) {
|
||||||
xn = dec_with_limit(_pointer_x, 0);
|
xn = dec_with_limit(_pointer_x, 0);
|
||||||
if(dir == DIR_RIGHT || dir == DIR_UP_RIGHT || dir == DIR_DOWN_RIGHT)
|
}
|
||||||
|
if (dir == DIR_RIGHT || dir == DIR_UP_RIGHT || dir == DIR_DOWN_RIGHT) {
|
||||||
xn = inc_with_limit(_pointer_x, rules_get_width() - 1);
|
xn = inc_with_limit(_pointer_x, rules_get_width() - 1);
|
||||||
if(dir == DIR_UP || dir == DIR_UP_LEFT || dir == DIR_UP_RIGHT)
|
}
|
||||||
|
if (dir == DIR_UP || dir == DIR_UP_LEFT || dir == DIR_UP_RIGHT) {
|
||||||
yn = dec_with_limit(_pointer_y, 0);
|
yn = dec_with_limit(_pointer_y, 0);
|
||||||
if(dir == DIR_DOWN || dir == DIR_DOWN_LEFT || dir == DIR_DOWN_RIGHT)
|
}
|
||||||
|
if (dir == DIR_DOWN || dir == DIR_DOWN_LEFT || dir == DIR_DOWN_RIGHT) {
|
||||||
yn = inc_with_limit(_pointer_y, rules_get_height() - 1);
|
yn = inc_with_limit(_pointer_y, rules_get_height() - 1);
|
||||||
|
}
|
||||||
if(xn == _pointer_x && yn == _pointer_y)
|
if (xn == _pointer_x && yn == _pointer_y) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
move_pointer_to(xn, yn);
|
move_pointer_to(xn, yn);
|
||||||
}
|
}
|
||||||
@ -308,7 +320,8 @@ void reinit_board(gint *newboard, gint *newnext, gint score, gint oldnext) {
|
|||||||
void remake_board(gint numoldchilds, gboolean isnextvalid) {
|
void remake_board(gint numoldchilds, gboolean isnextvalid) {
|
||||||
gint cxs, cys, i;
|
gint cxs, cys, i;
|
||||||
|
|
||||||
if(numoldchilds && numoldchilds != rules_get_next()) {
|
if (numoldchilds && numoldchilds != rules_get_next())
|
||||||
|
{
|
||||||
if (_small_balls) {
|
if (_small_balls) {
|
||||||
for (i = 0; i < numoldchilds; i++) {
|
for (i = 0; i < numoldchilds; i++) {
|
||||||
gtk_widget_destroy(_small_balls[i]);
|
gtk_widget_destroy(_small_balls[i]);
|
||||||
@ -364,7 +377,8 @@ gint expose_event(GtkWidget *widget, GdkEventExpose *event) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_pawnum_and_direction(gint pawx, gint pawy, gint x, gint y, gint *pawnum, gint *direction) {
|
void find_pawnum_and_direction(gint pawx, gint pawy, gint x, gint y, gint *pawnum, gint *direction)
|
||||||
|
{
|
||||||
if (pawy < y) {
|
if (pawy < y) {
|
||||||
*pawnum = 2;
|
*pawnum = 2;
|
||||||
if (*direction == 1) *pawnum = 6;
|
if (*direction == 1) *pawnum = 6;
|
||||||
@ -413,7 +427,8 @@ gboolean have_path(gint source_ball, gint target_ball) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_ball(gint source_ball, gint target_ball) {
|
void move_ball(gint source_ball, gint target_ball)
|
||||||
|
{
|
||||||
gint nodes[rules_get_width() * rules_get_height()];
|
gint nodes[rules_get_width() * rules_get_height()];
|
||||||
gint path[rules_get_width() * rules_get_height()];
|
gint path[rules_get_width() * rules_get_height()];
|
||||||
gint pawx = -1, pawy = -1;
|
gint pawx = -1, pawy = -1;
|
||||||
@ -439,9 +454,11 @@ void move_ball(gint source_ball, gint target_ball) {
|
|||||||
phase = 0;
|
phase = 0;
|
||||||
|
|
||||||
draw_ball(0, x, y, 0, 0);
|
draw_ball(0, x, y, 0, 0);
|
||||||
if(pref_get_show_path()) {
|
if (pref_get_show_path())
|
||||||
|
{
|
||||||
lock_actions(1);
|
lock_actions(1);
|
||||||
for(k = path[0] - 1; k; k--) {
|
for (k = path[0] - 1; k; k--)
|
||||||
|
{
|
||||||
gettimeofday(&tvs, NULL);
|
gettimeofday(&tvs, NULL);
|
||||||
find_x_y_of_the_node(&i, &j, path[k], rules_get_width(), rules_get_height());
|
find_x_y_of_the_node(&i, &j, path[k], rules_get_width(), rules_get_height());
|
||||||
if (k == path[0] - 1) {
|
if (k == path[0] - 1) {
|
||||||
|
@ -53,7 +53,8 @@ gint random_cell(void) {
|
|||||||
return (gint)(((gfloat)rules_get_width() * rules_get_height()) * rand() / (RAND_MAX + 1.0));
|
return (gint)(((gfloat)rules_get_width() * rules_get_height()) * rand() / (RAND_MAX + 1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void new_turn(gint number, gboolean first) {
|
void new_turn(gint number, gboolean first)
|
||||||
|
{
|
||||||
gint i, k = 0, free_cells_number, c;
|
gint i, k = 0, free_cells_number, c;
|
||||||
struct score_board scoreboard[10];
|
struct score_board scoreboard[10];
|
||||||
|
|
||||||
@ -101,7 +102,8 @@ void new_turn(gint number, gboolean first) {
|
|||||||
} while ((free_cells_number = game_count_free_cells()) == rules_get_width() * rules_get_height());
|
} while ((free_cells_number = game_count_free_cells()) == rules_get_width() * rules_get_height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void new_game(void){
|
void new_game(void)
|
||||||
|
{
|
||||||
stop_jumping_animation();
|
stop_jumping_animation();
|
||||||
game_init_game(NULL, NULL);
|
game_init_game(NULL, NULL);
|
||||||
menu_set_sensitive_undo(FALSE);
|
menu_set_sensitive_undo(FALSE);
|
||||||
@ -111,7 +113,9 @@ void new_game(void){
|
|||||||
draw_board();
|
draw_board();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
gint i;
|
gint i;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
@ -126,7 +130,8 @@ int main(int argc, char **argv) {
|
|||||||
#endif /* ENABLE_NLS */
|
#endif /* ENABLE_NLS */
|
||||||
|
|
||||||
/* drop privileges after spawning child with extra privs */
|
/* drop privileges after spawning child with extra privs */
|
||||||
if(score_setup() == -1) return 1;
|
if (score_setup() == -1)
|
||||||
|
return 1;
|
||||||
setregid(getgid(), getgid());
|
setregid(getgid(), getgid());
|
||||||
|
|
||||||
/* initialize random seed */
|
/* initialize random seed */
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
gboolean ut_key_pressed_cb(GtkWidget *widget, GdkEventKey *event) {
|
gboolean ut_key_pressed_cb(GtkWidget *widget, GdkEventKey *event)
|
||||||
|
{
|
||||||
if(widget && event && event->keyval == GDK_Escape) {
|
if(widget && event && event->keyval == GDK_Escape) {
|
||||||
gtk_widget_destroy(widget);
|
gtk_widget_destroy(widget);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -16,9 +17,11 @@ gboolean ut_key_pressed_cb(GtkWidget *widget, GdkEventKey *event) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *ut_window_new(gchar *title, gchar *wmname, gchar *wmclass,
|
GtkWidget *ut_window_new(gchar *title, gchar *wmname, gchar *wmclass,
|
||||||
gboolean escaable, gboolean modal, gboolean resizable,
|
gboolean escaable, gboolean modal, gboolean resizable,
|
||||||
gint border) {
|
gint border)
|
||||||
|
{
|
||||||
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
gtk_window_set_modal(GTK_WINDOW(window), modal);
|
gtk_window_set_modal(GTK_WINDOW(window), modal);
|
||||||
gtk_window_set_resizable(GTK_WINDOW(window), resizable);
|
gtk_window_set_resizable(GTK_WINDOW(window), resizable);
|
||||||
@ -31,7 +34,9 @@ GtkWidget *ut_window_new(gchar *title, gchar *wmname, gchar *wmclass,
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *ut_check_button_new(gchar *label, gboolean active, GtkWidget *parent) {
|
|
||||||
|
GtkWidget *ut_check_button_new(gchar *label, gboolean active, GtkWidget *parent)
|
||||||
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
button = gtk_check_button_new_with_label(label);
|
button = gtk_check_button_new_with_label(label);
|
||||||
@ -41,7 +46,9 @@ GtkWidget *ut_check_button_new(gchar *label, gboolean active, GtkWidget *parent)
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *ut_button_new(gchar *label, gpointer func, gpointer func_data, GtkWidget *parent) {
|
|
||||||
|
GtkWidget *ut_button_new(gchar *label, gpointer func, gpointer func_data, GtkWidget *parent)
|
||||||
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
button = gtk_button_new_with_label(label);
|
button = gtk_button_new_with_label(label);
|
||||||
@ -52,7 +59,9 @@ GtkWidget *ut_button_new(gchar *label, gpointer func, gpointer func_data, GtkWid
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *ut_button_new_stock(const gchar *stock_id, gpointer func, gpointer func_data, GtkWidget *parent) {
|
|
||||||
|
GtkWidget *ut_button_new_stock(const gchar *stock_id, gpointer func, gpointer func_data, GtkWidget *parent)
|
||||||
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
button = gtk_button_new_from_stock(stock_id);
|
button = gtk_button_new_from_stock(stock_id);
|
||||||
@ -63,7 +72,9 @@ GtkWidget *ut_button_new_stock(const gchar *stock_id, gpointer func, gpointer fu
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *ut_button_new_stock_swap(const gchar *stock_id, gpointer func, gpointer func_data, GtkWidget *parent) {
|
|
||||||
|
GtkWidget *ut_button_new_stock_swap(const gchar *stock_id, gpointer func, gpointer func_data, GtkWidget *parent)
|
||||||
|
{
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
button = gtk_button_new_from_stock(stock_id);
|
button = gtk_button_new_from_stock(stock_id);
|
||||||
@ -74,7 +85,9 @@ GtkWidget *ut_button_new_stock_swap(const gchar *stock_id, gpointer func, gpoint
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *ut_spin_button_new(gchar *label, gint min, gint max, gint val, GtkWidget *parent) {
|
|
||||||
|
GtkWidget *ut_spin_button_new(gchar *label, gint min, gint max, gint val, GtkWidget *parent)
|
||||||
|
{
|
||||||
GtkAdjustment *adj;
|
GtkAdjustment *adj;
|
||||||
GtkWidget *button, *hbox, *labelw;
|
GtkWidget *button, *hbox, *labelw;
|
||||||
|
|
||||||
@ -92,6 +105,7 @@ GtkWidget *ut_spin_button_new(gchar *label, gint min, gint max, gint val, GtkWid
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *ut_spin_button_start_new(gchar *label, gint min, gint max, gint val, GtkWidget *parent)
|
GtkWidget *ut_spin_button_start_new(gchar *label, gint min, gint max, gint val, GtkWidget *parent)
|
||||||
{
|
{
|
||||||
GtkAdjustment *adj;
|
GtkAdjustment *adj;
|
||||||
@ -111,13 +125,16 @@ GtkWidget *ut_spin_button_start_new(gchar *label, gint min, gint max, gint val,
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* shows simple message box */
|
/* shows simple message box */
|
||||||
void ut_simple_message_box(gchar *message) {
|
void ut_simple_message_box(gchar *message)
|
||||||
|
{
|
||||||
GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
|
GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
|
||||||
gtk_dialog_run(GTK_DIALOG(dialog));
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* shows simple message box */
|
/* shows simple message box */
|
||||||
void ut_simple_message_box_with_title(gchar *message, gchar *title) {
|
void ut_simple_message_box_with_title(gchar *message, gchar *title) {
|
||||||
GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
|
GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef __GTKUTILS_H
|
#ifndef __GTKUTILS_H
|
||||||
#define __GTKUTILS_H
|
#define __GTKUTILS_H
|
||||||
gboolean ut_key_pressed_cb (GtkWidget *widget,
|
gboolean ut_key_pressed_cb (GtkWidget *widget, GdkEventKey *event);
|
||||||
GdkEventKey *event);
|
|
||||||
|
|
||||||
GtkWidget *ut_window_new (gchar *title,
|
GtkWidget *ut_window_new (gchar *title,
|
||||||
gchar *wmname,
|
gchar *wmname,
|
||||||
@ -41,9 +40,9 @@ GtkWidget *ut_spin_button_start_new (gchar *label,
|
|||||||
gint max,
|
gint max,
|
||||||
gint val,
|
gint val,
|
||||||
GtkWidget *parent);
|
GtkWidget *parent);
|
||||||
|
|
||||||
void ut_simple_message_box (gchar *message);
|
void ut_simple_message_box (gchar *message);
|
||||||
|
|
||||||
void ut_simple_message_box_with_title (gchar *message,
|
void ut_simple_message_box_with_title (gchar *message, gchar *title);
|
||||||
gchar *title);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
#include "gtkutils.h"
|
#include "gtkutils.h"
|
||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
|
|
||||||
void show_hall_of_fame(GtkWidget *widget, gpointer data, struct score_board b[10]) {
|
void show_hall_of_fame (GtkWidget *widget, gpointer data, struct score_board b[10])
|
||||||
|
{
|
||||||
GtkWidget * hall_of_fame;
|
GtkWidget * hall_of_fame;
|
||||||
GtkWidget * frame, * sw, * tv;
|
GtkWidget * frame, * sw, * tv;
|
||||||
GtkWidget * vbox, * button_box;
|
GtkWidget * vbox, * button_box;
|
||||||
@ -48,7 +49,10 @@ void show_hall_of_fame(GtkWidget *widget, gpointer data, struct score_board b[10
|
|||||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN);
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN);
|
||||||
gtk_container_add(GTK_CONTAINER(frame), sw);
|
gtk_container_add(GTK_CONTAINER(frame), sw);
|
||||||
|
|
||||||
store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
|
store = gtk_list_store_new (3,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING);
|
||||||
for (i = 0; bs[i].score && i < 10; i++) {
|
for (i = 0; bs[i].score && i < 10; i++) {
|
||||||
gtk_list_store_append(store, &iter);
|
gtk_list_store_append(store, &iter);
|
||||||
str = g_strdup_printf("%d", bs[i].score);
|
str = g_strdup_printf("%d", bs[i].score);
|
||||||
@ -96,6 +100,8 @@ void show_hall_of_fame(GtkWidget *widget, gpointer data, struct score_board b[10
|
|||||||
gtk_widget_show_all (hall_of_fame);
|
gtk_widget_show_all (hall_of_fame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_hall_of_fame_cb(void) {
|
|
||||||
|
void show_hall_of_fame_cb(void)
|
||||||
|
{
|
||||||
show_hall_of_fame(NULL, NULL, NULL);
|
show_hall_of_fame(NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ static GtkWidget *_dialog = NULL;
|
|||||||
static gchar _last_player_name[15] = "";
|
static gchar _last_player_name[15] = "";
|
||||||
static gint _saved_score = 0;
|
static gint _saved_score = 0;
|
||||||
|
|
||||||
void read_entry(GtkWidget *widget, gpointer data) {
|
void read_entry(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
struct score_board current_entry;
|
struct score_board current_entry;
|
||||||
time_t current_time;
|
time_t current_time;
|
||||||
struct tm *timeptr;
|
struct tm *timeptr;
|
||||||
@ -37,6 +38,7 @@ void read_entry(GtkWidget *widget, gpointer data) {
|
|||||||
current_entry.score = _saved_score;
|
current_entry.score = _saved_score;
|
||||||
current_time = time(NULL);
|
current_time = time(NULL);
|
||||||
timeptr = localtime(¤t_time);
|
timeptr = localtime(¤t_time);
|
||||||
|
|
||||||
if (!timeptr) {
|
if (!timeptr) {
|
||||||
ut_simple_message_box(_("Unable to determine current date.\n"));
|
ut_simple_message_box(_("Unable to determine current date.\n"));
|
||||||
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
strncpy(current_entry.date, _("Unknown"), sizeof(current_entry.date));
|
||||||
@ -74,7 +76,9 @@ void read_entry(GtkWidget *widget, gpointer data) {
|
|||||||
/* show scores to let user see if (s)he's on top ;) */
|
/* show scores to let user see if (s)he's on top ;) */
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_name_dialog(void) {
|
|
||||||
|
void input_name_dialog(void)
|
||||||
|
{
|
||||||
GtkWidget * prompt_label, * vbox;
|
GtkWidget * prompt_label, * vbox;
|
||||||
GtkWidget * name;
|
GtkWidget * name;
|
||||||
GtkWidget * button;
|
GtkWidget * button;
|
||||||
|
@ -68,7 +68,8 @@ static gchar *_menu_translate(const gchar *path, gpointer data) {
|
|||||||
return gettext(path);
|
return gettext(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_get_main(GtkWidget *window, GtkWidget **menubar) {
|
void menu_get_main(GtkWidget *window, GtkWidget **menubar)
|
||||||
|
{
|
||||||
GtkAccelGroup *accel_group;
|
GtkAccelGroup *accel_group;
|
||||||
|
|
||||||
_action_group = gtk_action_group_new("MenuActions");
|
_action_group = gtk_action_group_new("MenuActions");
|
||||||
@ -83,14 +84,16 @@ void menu_get_main(GtkWidget *window, GtkWidget **menubar) {
|
|||||||
*menubar = gtk_ui_manager_get_widget(_ui_manager, "/MainMenu");
|
*menubar = gtk_ui_manager_get_widget(_ui_manager, "/MainMenu");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _menu_set_sensitive(const gchar *path, gboolean sensitive) {
|
void _menu_set_sensitive(const gchar *path, gboolean sensitive)
|
||||||
|
{
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
|
||||||
widget = gtk_ui_manager_get_widget(_ui_manager, path);
|
widget = gtk_ui_manager_get_widget(_ui_manager, path);
|
||||||
gtk_widget_set_sensitive(widget, sensitive);
|
gtk_widget_set_sensitive(widget, sensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_set_sensitive_undo(gboolean sensitive) {
|
void menu_set_sensitive_undo(gboolean sensitive)
|
||||||
|
{
|
||||||
_menu_set_sensitive("/MainMenu/EditMenu/Undo", sensitive);
|
_menu_set_sensitive("/MainMenu/EditMenu/Undo", sensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ void mw_set_user_score(gint score) {
|
|||||||
g_free(str);
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean _countdown_timer(gpointer data) {
|
gboolean _countdown_timer(gpointer data)
|
||||||
|
{
|
||||||
gchar *text;
|
gchar *text;
|
||||||
GtkLabel *label = data;
|
GtkLabel *label = data;
|
||||||
gint trem;
|
gint trem;
|
||||||
@ -94,7 +95,8 @@ gboolean _countdown_timer(gpointer data) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint _user_action_event(GtkWidget *w, GdkEvent *ev) {
|
gint _user_action_event(GtkWidget *w, GdkEvent *ev)
|
||||||
|
{
|
||||||
if (ev->type == GDK_MOTION_NOTIFY) {
|
if (ev->type == GDK_MOTION_NOTIFY) {
|
||||||
move_pointer_to(gtkb_theme_get_coord_at_x(ev->motion.x),
|
move_pointer_to(gtkb_theme_get_coord_at_x(ev->motion.x),
|
||||||
gtkb_theme_get_coord_at_y(ev->motion.y));
|
gtkb_theme_get_coord_at_y(ev->motion.y));
|
||||||
@ -137,13 +139,16 @@ gint _user_action_event(GtkWidget *w, GdkEvent *ev) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void main_window_destroy_cb (GtkWidget * w, gpointer user_data)
|
static void main_window_destroy_cb (GtkWidget * w, gpointer user_data)
|
||||||
{
|
{
|
||||||
gtkb_theme_free_handler (NULL, NULL);
|
gtkb_theme_free_handler (NULL, NULL);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mw_create(gint da_width, gint da_height) {
|
|
||||||
|
void mw_create(gint da_width, gint da_height)
|
||||||
|
{
|
||||||
GtkWidget * mainwin;
|
GtkWidget * mainwin;
|
||||||
GtkWidget * menubar;
|
GtkWidget * menubar;
|
||||||
GtkWidget * vbox, * hbox, * hbox1, * drawing_area_box;
|
GtkWidget * vbox, * hbox, * hbox1, * drawing_area_box;
|
||||||
|
19
src/path.c
19
src/path.c
@ -49,13 +49,15 @@ int find_node_by_coords(int x, int y, int number_of_x_cells, int number_of_y_cel
|
|||||||
number_of_cells: number of cells in the row
|
number_of_cells: number of cells in the row
|
||||||
returns number of marked nodes */
|
returns number of marked nodes */
|
||||||
int mark_neighbours_of_the_nodes (int *nodes, int *source_nodes, int *neighbours, int mark,
|
int mark_neighbours_of_the_nodes (int *nodes, int *source_nodes, int *neighbours, int mark,
|
||||||
int number_of_x_cells, int number_of_y_cells) {
|
int number_of_x_cells, int number_of_y_cells)
|
||||||
|
{
|
||||||
int i, j, neighbours_count = 0;
|
int i, j, neighbours_count = 0;
|
||||||
int x, y, node;
|
int x, y, node;
|
||||||
int xses[4] = { 0, 0, 1, -1};
|
int xses[4] = { 0, 0, 1, -1};
|
||||||
int yses[4] = {-1, 1, 0, 0};
|
int yses[4] = {-1, 1, 0, 0};
|
||||||
|
|
||||||
for(i = 1; i <= source_nodes[0]; i++) {
|
for (i = 1; i <= source_nodes[0]; i++)
|
||||||
|
{
|
||||||
find_x_y_of_the_node(&x, &y, source_nodes[i], number_of_x_cells, number_of_y_cells);
|
find_x_y_of_the_node(&x, &y, source_nodes[i], number_of_x_cells, number_of_y_cells);
|
||||||
if (x != -1 && y != -1) {
|
if (x != -1 && y != -1) {
|
||||||
for (j = 0; j < 4; j++) {
|
for (j = 0; j < 4; j++) {
|
||||||
@ -75,7 +77,8 @@ int mark_neighbours_of_the_nodes(int *nodes, int *source_nodes, int *neighbours,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if nodes are neighbours */
|
/* check if nodes are neighbours */
|
||||||
int is_neighbours(int node1, int node2, int xn, int yn) {
|
int is_neighbours(int node1, int node2, int xn, int yn)
|
||||||
|
{
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
|
|
||||||
find_x_y_of_the_node(&x1, &y1, node1, xn, yn);
|
find_x_y_of_the_node(&x1, &y1, node1, xn, yn);
|
||||||
@ -89,11 +92,13 @@ int is_neighbours(int node1, int node2, int xn, int yn) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* find the path between source_node and the target_node
|
/* find the path between source_node and the target_node
|
||||||
result stored in path
|
result stored in path
|
||||||
returns 0 on failure and 1 on success */
|
returns 0 on failure and 1 on success */
|
||||||
int find_path (int *nodes, int source_node, int target_node, int *path,
|
int find_path (int *nodes, int source_node, int target_node, int *path,
|
||||||
int number_of_x_cells, int number_of_y_cells) {
|
int number_of_x_cells, int number_of_y_cells)
|
||||||
|
{
|
||||||
int waves[number_of_x_cells * number_of_y_cells][number_of_x_cells * number_of_y_cells];
|
int waves[number_of_x_cells * number_of_y_cells][number_of_x_cells * number_of_y_cells];
|
||||||
int i, j, k = 1, finish = 0;
|
int i, j, k = 1, finish = 0;
|
||||||
|
|
||||||
@ -101,7 +106,8 @@ int find_path(int *nodes, int source_node, int target_node, int *path,
|
|||||||
waves[0][1] = source_node;
|
waves[0][1] = source_node;
|
||||||
|
|
||||||
nodes[source_node] = -1;
|
nodes[source_node] = -1;
|
||||||
while(!finish) {
|
while (!finish)
|
||||||
|
{
|
||||||
if (!mark_neighbours_of_the_nodes(nodes, waves[k - 1], waves[k], k,
|
if (!mark_neighbours_of_the_nodes(nodes, waves[k - 1], waves[k], k,
|
||||||
number_of_x_cells, number_of_y_cells)) {
|
number_of_x_cells, number_of_y_cells)) {
|
||||||
/* the destination can never be reached */
|
/* the destination can never be reached */
|
||||||
@ -118,7 +124,8 @@ int find_path(int *nodes, int source_node, int target_node, int *path,
|
|||||||
|
|
||||||
path[0] = k;
|
path[0] = k;
|
||||||
path[1] = waves[k - 1][i];
|
path[1] = waves[k - 1][i];
|
||||||
for(j = k - 2; j > 0; j--) {
|
for (j = k - 2; j > 0; j--)
|
||||||
|
{
|
||||||
finish = 0;
|
finish = 0;
|
||||||
for (i = 1; i <= waves[j][0]; i++) {
|
for (i = 1; i <= waves[j][0]; i++) {
|
||||||
if (is_neighbours(waves[j][i], path[k - j - 1],
|
if (is_neighbours(waves[j][i], path[k - j - 1],
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
int find_path (int *nodes, int source_node, int target_node, int *path,
|
int find_path (int *nodes, int source_node, int target_node, int *path,
|
||||||
int number_of_x_cells, int number_of_y_cells);
|
int number_of_x_cells, int number_of_y_cells);
|
||||||
|
|
||||||
void find_x_y_of_the_node (int *x, int *y,
|
void find_x_y_of_the_node (int *x, int *y,
|
||||||
int node, int number_of_x_cells, int number_of_y_cells);
|
int node, int number_of_x_cells, int number_of_y_cells);
|
||||||
|
|
||||||
int find_node_of_x_y (int x, int y, int number_of_x_cells);
|
int find_node_of_x_y (int x, int y, int number_of_x_cells);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "mainwin.h"
|
#include "mainwin.h"
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
PR_DIALOG,
|
PR_DIALOG,
|
||||||
PR_SHOW_NEXT,
|
PR_SHOW_NEXT,
|
||||||
PR_SHOW_PATH,
|
PR_SHOW_PATH,
|
||||||
@ -50,7 +51,9 @@ gboolean fix_draw_next_balls(gpointer data) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void preferences_apply(GtkWidget *widget, gpointer data) {
|
|
||||||
|
void preferences_apply(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
GtkWidget **buttons = data;
|
GtkWidget **buttons = data;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
@ -105,13 +108,17 @@ void preferences_apply(GtkWidget *widget, gpointer data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void preferences_ok(GtkWidget *widget, gpointer data) {
|
void preferences_ok(GtkWidget *widget, gpointer data) {
|
||||||
GtkWidget **buttons = data;
|
GtkWidget **buttons = data;
|
||||||
preferences_apply(widget, buttons);
|
preferences_apply(widget, buttons);
|
||||||
gtk_widget_destroy(buttons[PR_DIALOG]);
|
gtk_widget_destroy(buttons[PR_DIALOG]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void preferences_dialog(void) {
|
|
||||||
|
|
||||||
|
void preferences_dialog (void)
|
||||||
|
{
|
||||||
GtkWidget ** buttons;
|
GtkWidget ** buttons;
|
||||||
GtkWidget * frame;
|
GtkWidget * frame;
|
||||||
GtkWidget * big_vbox, * vbox, * buttons_box;
|
GtkWidget * big_vbox, * vbox, * buttons_box;
|
||||||
|
15
src/prefs.c
15
src/prefs.c
@ -142,7 +142,8 @@ gchar *pref_bool_to_str(gboolean val) {
|
|||||||
|
|
||||||
/* we use very lame preferences file format: ``property=value\n''.
|
/* we use very lame preferences file format: ``property=value\n''.
|
||||||
so - there must be no whitespaces on begin/end of line =) */
|
so - there must be no whitespaces on begin/end of line =) */
|
||||||
void load_preferences(void) {
|
void load_preferences(void)
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
gchar *rc_file;
|
gchar *rc_file;
|
||||||
gchar buffer[BUFFER_SIZE];
|
gchar buffer[BUFFER_SIZE];
|
||||||
@ -152,11 +153,14 @@ void load_preferences(void) {
|
|||||||
_theme_name = g_strdup(_default_theme_name);
|
_theme_name = g_strdup(_default_theme_name);
|
||||||
}
|
}
|
||||||
rc_file = find_rc_file();
|
rc_file = find_rc_file();
|
||||||
if((fp = fopen(rc_file, "r"))) {
|
if ((fp = fopen(rc_file, "r")))
|
||||||
while(fgets(buffer, BUFFER_SIZE, fp)) {
|
{
|
||||||
|
while(fgets(buffer, BUFFER_SIZE, fp))
|
||||||
|
{
|
||||||
g_strchomp(buffer);
|
g_strchomp(buffer);
|
||||||
prop_val = g_strsplit(buffer, "=", 2);
|
prop_val = g_strsplit(buffer, "=", 2);
|
||||||
if(prop_val[0] && prop_val[0][0] && prop_val[1] && prop_val[1][0]) {
|
if (prop_val[0] && prop_val[0][0] && prop_val[1] && prop_val[1][0])
|
||||||
|
{
|
||||||
if (!g_ascii_strcasecmp(prop_val[0], "show_hints")) {
|
if (!g_ascii_strcasecmp(prop_val[0], "show_hints")) {
|
||||||
_show_next_colors = pref_str_to_bool(prop_val[1]);
|
_show_next_colors = pref_str_to_bool(prop_val[1]);
|
||||||
} else if (!g_ascii_strcasecmp(prop_val[0], "show_path")) {
|
} else if (!g_ascii_strcasecmp(prop_val[0], "show_path")) {
|
||||||
@ -209,7 +213,8 @@ void write_pref_int(FILE *fp, gchar *property, gint value) {
|
|||||||
fprintf (fp, "%s=%d\n", property, value);
|
fprintf (fp, "%s=%d\n", property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *save_preferences(void) {
|
gchar *save_preferences (void)
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
gchar *rc_file/*, *err*/;
|
gchar *rc_file/*, *err*/;
|
||||||
gchar *ret = NULL;
|
gchar *ret = NULL;
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
#include "gtkutils.h"
|
#include "gtkutils.h"
|
||||||
|
|
||||||
/* Show dialog box with game rules*/
|
/* Show dialog box with game rules*/
|
||||||
void show_rules(GtkWidget *widget, gpointer data) {
|
void show_rules (GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
GtkWidget * window;
|
GtkWidget * window;
|
||||||
GtkWidget * vbox, * hbox, * button_box;
|
GtkWidget * vbox, * hbox, * button_box;
|
||||||
GtkWidget * label;
|
GtkWidget * label;
|
||||||
|
@ -20,7 +20,8 @@ struct _gtkb_rules_dialog {
|
|||||||
|
|
||||||
struct _gtkb_rules_dialog _rd;
|
struct _gtkb_rules_dialog _rd;
|
||||||
|
|
||||||
void rules_ok(GtkWidget *widget, gpointer data) {
|
void rules_ok(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
gint oldnext = rules_get_next();
|
gint oldnext = rules_get_next();
|
||||||
gchar *msg;
|
gchar *msg;
|
||||||
|
|
||||||
@ -42,7 +43,9 @@ void rules_ok(GtkWidget *widget, gpointer data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rules_classic(void) {
|
|
||||||
|
void rules_classic(void)
|
||||||
|
{
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.xrange), rules_get_classic_width());
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.xrange), rules_get_classic_width());
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.yrange), rules_get_classic_height());
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.yrange), rules_get_classic_height());
|
||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.crange), rules_get_classic_colors());
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.crange), rules_get_classic_colors());
|
||||||
@ -50,7 +53,9 @@ void rules_classic(void) {
|
|||||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.drange), rules_get_classic_destroy());
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(_rd.drange), rules_get_classic_destroy());
|
||||||
}
|
}
|
||||||
|
|
||||||
void rules_dialog(void) {
|
|
||||||
|
void rules_dialog (void)
|
||||||
|
{
|
||||||
GtkWidget * dialog;
|
GtkWidget * dialog;
|
||||||
GtkWidget * frame;
|
GtkWidget * frame;
|
||||||
GtkWidget * big_vbox, * vbox, * buttons_box;
|
GtkWidget * big_vbox, * vbox, * buttons_box;
|
||||||
|
@ -63,8 +63,8 @@ void do_delete_game(GtkWidget *widget, GtkWidget *treeview) {
|
|||||||
GtkTreeIter iter, nextiter;
|
GtkTreeIter iter, nextiter;
|
||||||
GValue value = {0, };
|
GValue value = {0, };
|
||||||
|
|
||||||
if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),&model, &iter))
|
||||||
&model, &iter)) {
|
{
|
||||||
gtk_tree_model_get_value(model, &iter, 1, &value);
|
gtk_tree_model_get_value(model, &iter, 1, &value);
|
||||||
if (g_value_get_string(&value)) {
|
if (g_value_get_string(&value)) {
|
||||||
unlink(g_value_get_string(&value));
|
unlink(g_value_get_string(&value));
|
||||||
@ -149,7 +149,9 @@ void free_gamelist(gchar **gamelist, gint num) {
|
|||||||
g_free(gamelist);
|
g_free(gamelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
gint game_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) {
|
|
||||||
|
gint game_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
|
||||||
|
{
|
||||||
GValue value_a = {0, };
|
GValue value_a = {0, };
|
||||||
GValue value_b = {0, };
|
GValue value_b = {0, };
|
||||||
gchar *str_a, *str_b;
|
gchar *str_a, *str_b;
|
||||||
@ -172,7 +174,10 @@ gint game_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpoi
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_load_game_dialog(gboolean is_save) {
|
|
||||||
|
|
||||||
|
void save_load_game_dialog(gboolean is_save)
|
||||||
|
{
|
||||||
GtkListStore * store;
|
GtkListStore * store;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkWidget * treeview;
|
GtkWidget * treeview;
|
||||||
@ -206,7 +211,10 @@ void save_load_game_dialog(gboolean is_save) {
|
|||||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(swindow), GTK_SHADOW_ETCHED_IN);
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(swindow), GTK_SHADOW_ETCHED_IN);
|
||||||
gtk_box_pack_start (GTK_BOX(vbox), swindow, TRUE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX(vbox), swindow, TRUE, TRUE, 0);
|
||||||
|
|
||||||
store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
|
store = gtk_list_store_new (3,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
gtk_list_store_append (store, &iter);
|
gtk_list_store_append (store, &iter);
|
||||||
memcpy (str1, gamelist[i * 2], 19 * sizeof(gchar));
|
memcpy (str1, gamelist[i * 2], 19 * sizeof(gchar));
|
||||||
|
@ -17,15 +17,15 @@
|
|||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
gint parse_save_game(gchar *sgame, gchar **rules, gint *score, gint **board, gint **next) {
|
gint parse_save_game(gchar *sgame, gchar **rules, gint *score, gint **board, gint **next)
|
||||||
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
gchar *sdata, *psdata, *srules;
|
gchar *sdata, *psdata, *srules;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
gint i, val;
|
gint i, val;
|
||||||
gint rw, rh, rc, rn, rd, rlen;
|
gint rw, rh, rc, rn, rd, rlen;
|
||||||
|
|
||||||
if(stat(sgame, &buf) != 0 || !S_ISREG(buf.st_mode) || buf.st_size < 20 ||
|
if (stat(sgame, &buf) != 0 || !S_ISREG(buf.st_mode) || buf.st_size < 20 || (f = fopen(sgame, "r")) == NULL) {
|
||||||
(f = fopen(sgame, "r")) == NULL) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,9 +84,11 @@ gint parse_save_game(gchar *sgame, gchar **rules, gint *score, gint **board, gin
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* check that save game name is in form YYYY-MM-DD-HHMMSS.sav and have correct content
|
/* check that save game name is in form YYYY-MM-DD-HHMMSS.sav and have correct content
|
||||||
return string "DD.MM.YYYY HH:MM:SS (score)" on success, NULL on failure */
|
return string "DD.MM.YYYY HH:MM:SS (score)" on success, NULL on failure */
|
||||||
gchar *is_valid_save_game(gchar *name, gchar *path) {
|
gchar *is_valid_save_game(gchar *name, gchar *path)
|
||||||
|
{
|
||||||
guint i, y, m, d, h, min, s;
|
guint i, y, m, d, h, min, s;
|
||||||
gint score, *board, *next;
|
gint score, *board, *next;
|
||||||
gchar *sgame;
|
gchar *sgame;
|
||||||
@ -118,7 +120,9 @@ gchar *is_valid_save_game(gchar *name, gchar *path) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
gint get_saved_games(gchar ***gamelist) {
|
|
||||||
|
gint get_saved_games(gchar ***gamelist)
|
||||||
|
{
|
||||||
gchar *datapath;
|
gchar *datapath;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
struct dirent *dir_entry;
|
struct dirent *dir_entry;
|
||||||
@ -136,7 +140,8 @@ gint get_saved_games(gchar ***gamelist) {
|
|||||||
g_free (datapath);
|
g_free (datapath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if((directory = opendir(datapath))) {
|
if ((directory = opendir(datapath)))
|
||||||
|
{
|
||||||
while ((dir_entry = readdir(directory))) {
|
while ((dir_entry = readdir(directory))) {
|
||||||
if ((game = is_valid_save_game(dir_entry->d_name, datapath)) != NULL) {
|
if ((game = is_valid_save_game(dir_entry->d_name, datapath)) != NULL) {
|
||||||
num++;
|
num++;
|
||||||
@ -152,7 +157,9 @@ gint get_saved_games(gchar ***gamelist) {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *save_game(gchar *rules, gint score, gint *board, gint *nextcolors) {
|
|
||||||
|
gchar *save_game(gchar *rules, gint score, gint *board, gint *nextcolors)
|
||||||
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
gchar *fname;
|
gchar *fname;
|
||||||
time_t nowtime;
|
time_t nowtime;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* scoreboard.c - save/load scores
|
/* scoreboard.c - save/load scores
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public
|
* modif (y it under the terms of the GNU General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 2 of the License, or (at your option) any later version.
|
* version 2 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
@ -23,12 +23,15 @@
|
|||||||
|
|
||||||
int _score_fd = -1;
|
int _score_fd = -1;
|
||||||
|
|
||||||
gint score_setup(void) {
|
gint score_setup(void)
|
||||||
|
{
|
||||||
_score_fd = child_setup(SCORE_FILE);
|
_score_fd = child_setup(SCORE_FILE);
|
||||||
return _score_fd;
|
return _score_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_score_board_full(struct score_board_full *bf, gint nbf) {
|
|
||||||
|
void free_score_board_full(struct score_board_full *bf, gint nbf)
|
||||||
|
{
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
for (i = 0; i < nbf; i++) {
|
for (i = 0; i < nbf; i++) {
|
||||||
@ -37,7 +40,9 @@ void free_score_board_full(struct score_board_full *bf, gint nbf) {
|
|||||||
g_free(bf);
|
g_free(bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf) {
|
|
||||||
|
gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf)
|
||||||
|
{
|
||||||
gint i;
|
gint i;
|
||||||
gchar *buf, *tname, *tdate, *rules;
|
gchar *buf, *tname, *tdate, *rules;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
@ -46,7 +51,8 @@ gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
if (strlen(b[i].name)) {
|
if (strlen(b[i].name)) {
|
||||||
tname = g_strdup(b[i].name);
|
tname = g_strdup(b[i].name);
|
||||||
if (!tname) {
|
if (!tname) {
|
||||||
@ -82,13 +88,17 @@ gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int score_sort(const void *a, const void *b) {
|
|
||||||
|
int score_sort(const void *a, const void *b)
|
||||||
|
{
|
||||||
if (((const struct score_board *)a)->score == ((const struct score_board *)b)->score) return 0;
|
if (((const struct score_board *)a)->score == ((const struct score_board *)b)->score) return 0;
|
||||||
if (((const struct score_board *)a)->score < ((const struct score_board *)b)->score) return 1;
|
if (((const struct score_board *)a)->score < ((const struct score_board *)b)->score) return 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint read_score(struct score_board *b, struct score_board_full **bf, gint *nbf) {
|
|
||||||
|
gint read_score(struct score_board *b, struct score_board_full **bf, gint *nbf)
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
gchar buffer[BUFFER_SIZE];
|
gchar buffer[BUFFER_SIZE];
|
||||||
gchar **str_val, *tstr, **tstr_val;
|
gchar **str_val, *tstr, **tstr_val;
|
||||||
@ -114,12 +124,14 @@ gint read_score(struct score_board *b, struct score_board_full **bf, gint *nbf)
|
|||||||
|
|
||||||
sc = 0;
|
sc = 0;
|
||||||
fsc = 0;
|
fsc = 0;
|
||||||
while(fgets(buffer, BUFFER_SIZE, fp)) {
|
while (fgets(buffer, BUFFER_SIZE, fp))
|
||||||
|
{
|
||||||
g_strchomp(buffer);
|
g_strchomp(buffer);
|
||||||
str_val = g_strsplit(buffer, "\t", 4);
|
str_val = g_strsplit(buffer, "\t", 4);
|
||||||
if (str_val[0] && str_val[0][0] &&
|
if (str_val[0] && str_val[0][0] &&
|
||||||
str_val[1] && str_val[1][0] &&
|
str_val[1] && str_val[1][0] &&
|
||||||
str_val[2] && str_val[2][0]) {
|
str_val[2] && str_val[2][0])
|
||||||
|
{
|
||||||
valid = 0;
|
valid = 0;
|
||||||
if (!str_val[3]) { /* < 2.2.0 file for mat */
|
if (!str_val[3]) { /* < 2.2.0 file for mat */
|
||||||
g_rules = rules_get_classic_as_str();
|
g_rules = rules_get_classic_as_str();
|
||||||
@ -197,7 +209,9 @@ gint read_score(struct score_board *b, struct score_board_full **bf, gint *nbf)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint insert_entry_in_score_board(struct score_board *board, struct score_board entry) {
|
|
||||||
|
gint insert_entry_in_score_board(struct score_board *board, struct score_board entry)
|
||||||
|
{
|
||||||
gint i=0,j;
|
gint i=0,j;
|
||||||
|
|
||||||
if (entry.score <= 0) {
|
if (entry.score <= 0) {
|
||||||
|
102
src/theme.c
102
src/theme.c
@ -1,7 +1,7 @@
|
|||||||
/* theme.c - functions related to theme handling
|
/* theme.c - functions related to theme handling
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public
|
* modif (y it under the terms of the GNU General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 2 of the License, or (at your option) any later version.
|
* version 2 of the License, or (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
@ -30,7 +30,9 @@ gchar *THEMEPREFIX="/.gtkballs/themes/";
|
|||||||
#define DELTA(d, h) \
|
#define DELTA(d, h) \
|
||||||
d = h < 0 ? (d > -h ? d + h : 0) : (d + h < 255 ? d + h : 255)
|
d = h < 0 ? (d > -h ? d + h : 0) : (d + h < 255 ? d + h : 255)
|
||||||
|
|
||||||
void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db) {
|
|
||||||
|
void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db)
|
||||||
|
{
|
||||||
/* pb created with 8b/rgb without alpha */
|
/* pb created with 8b/rgb without alpha */
|
||||||
gint i;
|
gint i;
|
||||||
gint nc = gdk_pixbuf_get_n_channels(pb);
|
gint nc = gdk_pixbuf_get_n_channels(pb);
|
||||||
@ -53,7 +55,9 @@ void hilight_pixbuff8(GdkPixbuf *pb, gint dr, gint dg, gint db) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *find_theme_path(gchar *themename) {
|
|
||||||
|
gchar *find_theme_path(gchar *themename)
|
||||||
|
{
|
||||||
gchar *homedir;
|
gchar *homedir;
|
||||||
gchar *themepath;
|
gchar *themepath;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
@ -74,7 +78,9 @@ gchar *find_theme_path(gchar *themename) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
|
|
||||||
|
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname)
|
||||||
|
{
|
||||||
gchar *fname;
|
gchar *fname;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gint rv = 1;
|
gint rv = 1;
|
||||||
@ -82,7 +88,9 @@ gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
|
|||||||
if (!(fname = g_strconcat(path, pixmapname, NULL))) {
|
if (!(fname = g_strconcat(path, pixmapname, NULL))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(pixmap->pixbuf) g_object_unref(pixmap->pixbuf);
|
if (pixmap->pixbuf) {
|
||||||
|
g_object_unref(pixmap->pixbuf);
|
||||||
|
}
|
||||||
pixmap->pixbuf = gdk_pixbuf_new_from_file(fname, &error);
|
pixmap->pixbuf = gdk_pixbuf_new_from_file(fname, &error);
|
||||||
if (!pixmap->pixbuf) {
|
if (!pixmap->pixbuf) {
|
||||||
ut_simple_message_box(error->message);
|
ut_simple_message_box(error->message);
|
||||||
@ -102,7 +110,9 @@ void gtkb_pixmap_free(GtkbPixmap pixmap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gtkb_theme_free(GtkbTheme *theme) {
|
|
||||||
|
void gtkb_theme_free(GtkbTheme *theme)
|
||||||
|
{
|
||||||
gint i, j;
|
gint i, j;
|
||||||
|
|
||||||
if (!theme) {
|
if (!theme) {
|
||||||
@ -141,14 +151,18 @@ void gtkb_theme_free(GtkbTheme *theme) {
|
|||||||
g_free (theme);
|
g_free (theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* warning! tmpname will be free()'d! */
|
/* warning! tmpname will be free()'d! */
|
||||||
gint gtkb_load_pixmap_from(gchar **trc, gchar *themepath, gchar *tmpname, GtkbPixmap *pixmap) {
|
gint gtkb_load_pixmap_from(gchar **trc, gchar *themepath, gchar *tmpname, GtkbPixmap *pixmap)
|
||||||
|
{
|
||||||
gchar *val;
|
gchar *val;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
val = trc_get_str(trc, tmpname);
|
val = trc_get_str(trc, tmpname);
|
||||||
g_free (tmpname);
|
g_free (tmpname);
|
||||||
if(val == NULL) return 0;
|
if (val == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
ret = gtkb_load_pixmap(pixmap, themepath, val);
|
ret = gtkb_load_pixmap(pixmap, themepath, val);
|
||||||
g_free (val);
|
g_free (val);
|
||||||
|
|
||||||
@ -172,7 +186,9 @@ void gtkb_make_hl_pixmap(GtkbTheme *theme) {
|
|||||||
hilight_pixbuff8(theme->hemptycell.pixbuf, prefs_get_hl_dr(), prefs_get_hl_dg(), prefs_get_hl_db());
|
hilight_pixbuff8(theme->hemptycell.pixbuf, prefs_get_hl_dr(), prefs_get_hl_dg(), prefs_get_hl_db());
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
|
||||||
|
GtkbTheme *gtkb_load_theme(gchar *themepath)
|
||||||
|
{
|
||||||
gchar **trc, *opt;
|
gchar **trc, *opt;
|
||||||
gchar *paws[] = {"down_up", "left_right", "up_down", "right_left",
|
gchar *paws[] = {"down_up", "left_right", "up_down", "right_left",
|
||||||
"down_right", "down_left", "up_right", "up_left", NULL};
|
"down_right", "down_left", "up_right", "up_left", NULL};
|
||||||
@ -205,38 +221,38 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
|||||||
/* find and load "footprints" pixmaps. */
|
/* find and load "footprints" pixmaps. */
|
||||||
for (i = 0; paws[i]; i++) {
|
for (i = 0; paws[i]; i++) {
|
||||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strconcat("paw.", paws[i], NULL),
|
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strconcat("paw.", paws[i], NULL),
|
||||||
&theme->paws[i]),
|
&theme->paws[i]), 0);
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* query number of available balls in theme */
|
/* query number of available balls in theme */
|
||||||
theme->numballs = trc_get_uint(trc, "ball.numbers");
|
theme->numballs = trc_get_uint(trc, "ball.numbers");
|
||||||
CHECKRET(theme->numballs, -1);
|
CHECKRET(theme->numballs, -1);
|
||||||
if(theme->numballs < rules_get_colors()) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
if (theme->numballs < rules_get_colors()) {
|
||||||
|
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||||
|
}
|
||||||
theme->balls = g_new0(GtkbBall, theme->numballs);
|
theme->balls = g_new0(GtkbBall, theme->numballs);
|
||||||
|
|
||||||
/* find and load all balls data. */
|
/* find and load all balls data. */
|
||||||
for (i = 0; i < theme->numballs; i++) {
|
for (i = 0; i < theme->numballs; i++) {
|
||||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.still", i + 1),
|
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.still", i + 1),
|
||||||
&theme->balls[i].ball),
|
&theme->balls[i].ball), 0);
|
||||||
0);
|
|
||||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.small", i + 1),
|
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.small", i + 1),
|
||||||
&theme->balls[i].small),
|
&theme->balls[i].small), 0);
|
||||||
0);
|
|
||||||
|
|
||||||
opt = g_strdup_printf("ball.%d.jump.numbers", i + 1);
|
opt = g_strdup_printf("ball.%d.jump.numbers", i + 1);
|
||||||
theme->balls[i].jumpphases = trc_get_uint(trc, opt);
|
theme->balls[i].jumpphases = trc_get_uint(trc, opt);
|
||||||
g_free (opt);
|
g_free (opt);
|
||||||
CHECKRET(theme->balls[i].jumpphases, -1);
|
CHECKRET(theme->balls[i].jumpphases, -1);
|
||||||
if(theme->balls[i].jumpphases < 2) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
if (theme->balls[i].jumpphases < 2) {
|
||||||
|
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||||
|
}
|
||||||
theme->balls[i].jump = g_new0(GtkbPixmap, theme->balls[i].jumpphases);
|
theme->balls[i].jump = g_new0(GtkbPixmap, theme->balls[i].jumpphases);
|
||||||
theme->balls[i].jumpdelays = g_new0(gint, theme->balls[i].jumpphases);
|
theme->balls[i].jumpdelays = g_new0(gint, theme->balls[i].jumpphases);
|
||||||
|
|
||||||
for (j = 0; j < theme->balls[i].jumpphases; j++) {
|
for (j = 0; j < theme->balls[i].jumpphases; j++) {
|
||||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
||||||
g_strdup_printf("ball.%d.jump.%d", i + 1, j + 1),
|
g_strdup_printf("ball.%d.jump.%d", i + 1, j + 1),
|
||||||
&theme->balls[i].jump[j]),
|
&theme->balls[i].jump[j]), 0);
|
||||||
0);
|
|
||||||
opt = g_strdup_printf("ball.%d.jump.%d.usec", i + 1, j + 1);
|
opt = g_strdup_printf("ball.%d.jump.%d.usec", i + 1, j + 1);
|
||||||
theme->balls[i].jumpdelays[j] = trc_get_uint(trc, opt);
|
theme->balls[i].jumpdelays[j] = trc_get_uint(trc, opt);
|
||||||
g_free (opt);
|
g_free (opt);
|
||||||
@ -247,18 +263,18 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
|||||||
theme->balls[i].destroyphases = trc_get_uint(trc, opt);
|
theme->balls[i].destroyphases = trc_get_uint(trc, opt);
|
||||||
g_free (opt);
|
g_free (opt);
|
||||||
CHECKRET(theme->balls[i].destroyphases, -1);
|
CHECKRET(theme->balls[i].destroyphases, -1);
|
||||||
if(theme->balls[i].destroyphases < 2) CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
if (theme->balls[i].destroyphases < 2) {
|
||||||
|
CHECKRET(0, 0); /* yes, i know. its ugly =) */
|
||||||
|
}
|
||||||
if (theme->balls[i].destroyphases > theme->maxdestphases) {
|
if (theme->balls[i].destroyphases > theme->maxdestphases) {
|
||||||
theme->maxdestphases = theme->balls[i].destroyphases;
|
theme->maxdestphases = theme->balls[i].destroyphases;
|
||||||
}
|
}
|
||||||
theme->balls[i].destroy = g_new0(GtkbPixmap, theme->balls[i].destroyphases);
|
theme->balls[i].destroy = g_new0(GtkbPixmap, theme->balls[i].destroyphases);
|
||||||
theme->balls[i].destroydelays = g_new0(gint, theme->balls[i].destroyphases);
|
theme->balls[i].destroydelays = g_new0(gint, theme->balls[i].destroyphases);
|
||||||
|
|
||||||
for (j = 0; j < theme->balls[i].destroyphases; j++) {
|
for (j = 0; j < theme->balls[i].destroyphases; j++) {
|
||||||
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
|
||||||
g_strdup_printf("ball.%d.destroy.%d", i + 1, j + 1),
|
g_strdup_printf("ball.%d.destroy.%d", i + 1, j + 1),
|
||||||
&theme->balls[i].destroy[j]),
|
&theme->balls[i].destroy[j]), 0);
|
||||||
0);
|
|
||||||
opt = g_strdup_printf("ball.%d.destroy.%d.usec", i + 1, j + 1);
|
opt = g_strdup_printf("ball.%d.destroy.%d.usec", i + 1, j + 1);
|
||||||
theme->balls[i].destroydelays[j] = trc_get_uint(trc, opt);
|
theme->balls[i].destroydelays[j] = trc_get_uint(trc, opt);
|
||||||
g_free (opt);
|
g_free (opt);
|
||||||
@ -270,16 +286,22 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
|
|||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint load_theme(gchar *themename) {
|
|
||||||
|
gint load_theme(gchar *themename)
|
||||||
|
{
|
||||||
gchar *themepath;
|
gchar *themepath;
|
||||||
GtkbTheme *theme;
|
GtkbTheme *theme;
|
||||||
|
|
||||||
if(!(themepath = find_theme_path(themename))) return 0;
|
if (!(themepath = find_theme_path(themename))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
theme = gtkb_load_theme(themepath);
|
theme = gtkb_load_theme(themepath);
|
||||||
g_free (themepath);
|
g_free (themepath);
|
||||||
|
|
||||||
if(!theme) return 0;
|
if (!theme) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
gtkb_theme_free(gtkbTheme);
|
gtkb_theme_free(gtkbTheme);
|
||||||
gtkbTheme = theme;
|
gtkbTheme = theme;
|
||||||
@ -287,25 +309,33 @@ gint load_theme(gchar *themename) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data) {
|
|
||||||
|
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data)
|
||||||
|
{
|
||||||
gtkb_theme_free(gtkbTheme);
|
gtkb_theme_free(gtkbTheme);
|
||||||
gtkbTheme = NULL;
|
gtkbTheme = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint gtkb_theme_get_balls_num(void) {
|
|
||||||
|
gint gtkb_theme_get_balls_num(void)
|
||||||
|
{
|
||||||
return gtkbTheme ? gtkbTheme->numballs : 0;
|
return gtkbTheme ? gtkbTheme->numballs : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* returns board coordinate of the pointer */
|
/* returns board coordinate of the pointer */
|
||||||
gint gtkb_theme_get_coord_at_x(gint x) {
|
gint gtkb_theme_get_coord_at_x(gint x)
|
||||||
|
{
|
||||||
if (gtkbTheme) {
|
if (gtkbTheme) {
|
||||||
return (x - 1) / gtkbTheme->emptycell.xsize;
|
return (x - 1) / gtkbTheme->emptycell.xsize;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint gtkb_theme_get_coord_at_y(gint y) {
|
|
||||||
|
gint gtkb_theme_get_coord_at_y(gint y)
|
||||||
|
{
|
||||||
if (gtkbTheme) {
|
if (gtkbTheme) {
|
||||||
return (y - 1) / gtkbTheme->emptycell.ysize;
|
return (y - 1) / gtkbTheme->emptycell.ysize;
|
||||||
}
|
}
|
||||||
@ -320,8 +350,10 @@ gint theme_get_height(void) {
|
|||||||
return gtkbTheme->emptycell.xsize;
|
return gtkbTheme->emptycell.xsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* find all available themes. */
|
/* find all available themes. */
|
||||||
gchar **get_available_themes(void) {
|
gchar **get_available_themes(void)
|
||||||
|
{
|
||||||
DIR *directory;
|
DIR *directory;
|
||||||
struct dirent *dir_entry;
|
struct dirent *dir_entry;
|
||||||
struct stat entry_stat;
|
struct stat entry_stat;
|
||||||
@ -334,11 +366,14 @@ gchar **get_available_themes(void) {
|
|||||||
} else {
|
} else {
|
||||||
hdir = g_strdup("./"); /* FIXME: does it work on non unix os? */
|
hdir = g_strdup("./"); /* FIXME: does it work on non unix os? */
|
||||||
}
|
}
|
||||||
for(j = 0, currdir = INSTALLPATH, num = 0; j < 2; j++, currdir = hdir) {
|
|
||||||
|
for (j = 0, currdir = INSTALLPATH, num = 0; j < 2; j++, currdir = hdir)
|
||||||
|
{
|
||||||
if (!(directory = opendir(currdir))) {
|
if (!(directory = opendir(currdir))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while((dir_entry = readdir(directory))) {
|
while((dir_entry = readdir(directory)))
|
||||||
|
{
|
||||||
if (!strncmp(dir_entry->d_name, ".", 2) ||
|
if (!strncmp(dir_entry->d_name, ".", 2) ||
|
||||||
!strncmp(dir_entry->d_name, "..", 3)) {
|
!strncmp(dir_entry->d_name, "..", 3)) {
|
||||||
continue;
|
continue;
|
||||||
@ -365,6 +400,7 @@ gchar **get_available_themes(void) {
|
|||||||
}
|
}
|
||||||
closedir(directory);
|
closedir(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (hdir);
|
g_free (hdir);
|
||||||
tlist = g_realloc(tlist, (num + 1) * sizeof(gchar *));
|
tlist = g_realloc(tlist, (num + 1) * sizeof(gchar *));
|
||||||
tlist[num] = NULL;
|
tlist[num] = NULL;
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* read contents of fname into gchar * */
|
/* read contents of fname into gchar * */
|
||||||
gchar **trc_open(gchar *fname) {
|
gchar **trc_open(gchar *fname)
|
||||||
|
{
|
||||||
gint fd;
|
gint fd;
|
||||||
struct stat fds;
|
struct stat fds;
|
||||||
ssize_t rb;
|
ssize_t rb;
|
||||||
@ -68,7 +69,8 @@ void trc_close(gchar **rcs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* return string value for given parameter. if not found retun NULL */
|
/* return string value for given parameter. if not found retun NULL */
|
||||||
gchar *trc_get_str(gchar **rcs, gchar *param) {
|
gchar *trc_get_str(gchar **rcs, gchar *param)
|
||||||
|
{
|
||||||
gint i;
|
gint i;
|
||||||
gchar **strval,*val;
|
gchar **strval,*val;
|
||||||
|
|
||||||
@ -98,7 +100,9 @@ gint trc_get_uint(gchar **rcs, gchar *param) {
|
|||||||
gchar *val;
|
gchar *val;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
if(!(val=trc_get_str(rcs, param))) return -1;
|
if (!(val=trc_get_str(rcs, param))) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
ret = atoi(val);
|
ret = atoi(val);
|
||||||
g_free (val);
|
g_free (val);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user