Merge pull request #6 from wdlkmpx/patch1

consistent indentation
This commit is contained in:
Eugene Morozov 2021-01-16 15:20:57 +03:00 committed by GitHub
commit f96b8abc49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 2850 additions and 2655 deletions

View File

@ -34,7 +34,8 @@ int child_writer_dead_handler(void) {
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;
int i;
int fd=-1;
@ -44,10 +45,12 @@ void child_process_score_writer(int chfd, gchar *score_file) {
struct flock lockinfo;
gchar *score_file_full = g_strconcat(LOCALSTATEDIR, score_file, NULL);
while(1) {
while (1)
{
FD_ZERO(&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) {
exit(0);
}
@ -68,7 +71,9 @@ void child_process_score_writer(int chfd, gchar *score_file) {
i = 0;
while (1) {
lockinfo.l_type=F_WRLCK;
if(!fcntl(fd, F_SETLK, &lockinfo)) break;
if (!fcntl(fd, F_SETLK, &lockinfo)) {
break;
}
if (i >= 3) {
close(fd);
fd = -1;
@ -89,15 +94,15 @@ void child_process_score_writer(int chfd, gchar *score_file) {
if (fd != -1) {
close(fd);
} else {
/* FIXME: here should be some sort of error
reporting to parent */
/* FIXME: here should be some sort of error reporting to parent */
}
sigprocmask(SIG_UNBLOCK, &sset, NULL);
}
}
}
static void sigchld_handler(int param) {
static void sigchld_handler(int param)
{
pid_t ret = waitpid(0, NULL, WNOHANG);
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;
struct sigaction sact;
int sfds[2];

View File

@ -141,18 +141,21 @@ void rules_set(gint width, gint height, gint colors, gint next, gint destroy) {
}
gboolean _rules_check_rules(GtkbGameRules r) {
if((r.width < 4 || r.width > 99) ||
(r.height < 4 || r.height > 99) ||
(r.colors < 3 || r.colors > 99) ||
(r.next < 2 || r.next > 99) ||
(r.destroy < 3 || r.destroy > 99))
if ((r.width < 4 || r.width > 99)
|| (r.height < 4 || r.height > 99)
|| (r.colors < 3 || r.colors > 99)
|| (r.next < 2 || r.next > 99)
|| (r.destroy < 3 || r.destroy > 99))
{
return 0;
}
return 1;
}
gchar *_rules_to_str(GtkbGameRules r) {
if(!_rules_check_rules(r))
if (!_rules_check_rules(r)) {
return NULL;
}
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") ||
sscanf(rstr, _save_fmt, &r.width, &r.height, &r.colors, &r.next, &r.destroy) != 5 ||
!_rules_check_rules(r))
{
return 0;
}
return 1;
}
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;
}
sscanf(s, _save_fmt, width, height, colors, next, destroy);
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) {
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;
}
r.width = strtol(w, NULL, 10);
r.height = strtol(h, NULL, 10);
r.colors = strtol(c, NULL, 10);
@ -209,8 +214,9 @@ gboolean rules_is_current_str(gchar *r) {
gboolean rval = 0;
gchar *cur = _rules_to_str(_rules);
if(strcmp(r, cur) == 0)
if (strcmp(r, cur) == 0) {
rval = 1;
}
g_free(cur);
return rval;
@ -240,26 +246,33 @@ void game_save_state_for_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 */
return;
}
memcpy(_board, _board_undo, sizeof(gint) * _rules.width * _rules.height);
memcpy(_next_colors, _next_colors_undo, sizeof(gint) * _rules.next);
_score = _score_undo;
_hi_score = _hi_score_undo;
}
void game_init_game(gint *balls, gint *nextballs) {
if(_board)
void game_init_game(gint *balls, gint *nextballs)
{
if (_board) {
g_free(_board);
if(_board_undo)
}
if (_board_undo) {
g_free(_board_undo);
if(_board_destroys)
}
if (_board_destroys) {
g_free(_board_destroys);
if(_next_colors)
}
if (_next_colors) {
g_free(_next_colors);
if(_next_colors_undo)
}
if (_next_colors_undo) {
g_free(_next_colors_undo);
}
_board = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
_board_destroys = g_malloc0(sizeof(gint) * _rules.width * _rules.height);
if (balls) {
@ -280,10 +293,10 @@ gint game_count_free_cells(void) {
gint i, counter = 0;
gint *bp = _board;
for(i = 0; i < _rules.width * _rules.height; i++)
for (i = 0; i < _rules.width * _rules.height; i++) {
if (*bp++ == 0)
counter++;
}
return counter;
}
@ -304,44 +317,51 @@ gint *game_get_next_as_int_arr(void) {
}
gint board_get_at_node(gint node) {
if(node >= _rules.width * _rules.height)
if (node >= _rules.width * _rules.height) {
return 0;
}
return _board[node];
}
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 _board[y * _rules.width + x];
}
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 _board_destroys[y * _rules.width + x];
}
void board_set_at_node(gint node, gint col) {
if(node >= _rules.width * _rules.height)
if (node >= _rules.width * _rules.height) {
return;
}
_board[node] = 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;
}
_board[y * _rules.width + x] = col;
}
gint next_get(gint num) {
if(num >= _rules.next)
if (num >= _rules.next) {
return 0;
}
return _next_colors[num];
}
void next_set(gint num, gint col) {
if(num >= _rules.next)
if (num >= _rules.next) {
return;
}
_next_colors[num] = col;
}
@ -350,16 +370,18 @@ void timer_start(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 1;
}
gboolean timer_is_expired(void) {
time_t nowt = time(NULL);
if(nowt - _timer_start_time >= _timer_limit)
if (nowt - _timer_start_time >= _timer_limit) {
return 1;
}
return 0;
}
@ -381,13 +403,20 @@ struct gtkb_animarray {
gint color, x, y, phase, time;
};
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;
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;
}
return -1;
}
gint game_destroy_lines(gboolean count_score) {
gint game_destroy_lines(gboolean count_score)
{
gint x, y, i, j;
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));
for(y = 0; y < rules_get_height(); y++) {
for(x = 0; x < rules_get_width(); x++) {
for (y = 0; y < rules_get_height(); y++)
{
for (x = 0; x < rules_get_width(); x++)
{
if (board_get_at_xy(x, y) != 0) {
/* horizontal */
if (rules_get_width() - x >= rules_get_destroy()) {
@ -460,16 +491,21 @@ gint game_destroy_lines(gboolean count_score) {
}
}
}
i = 0;
if(have_del) {
if(pref_get_show_destroy()) {
if (have_del)
{
if (pref_get_show_destroy())
{
gint animcadres = 0, animpos = 0, animtime;
struct gtkb_animarray *animarray;
struct timeval tvs, tve;
animarray = g_new0(struct gtkb_animarray, rules_get_width() * rules_get_height() * gtkbTheme->maxdestphases);
for(y = 0; y < rules_get_height(); y++) {
for(x = 0; x < rules_get_width(); x++) {
for (y = 0; y < rules_get_height(); y++)
{
for (x = 0; x < rules_get_width(); x++)
{
if (del[y * rules_get_width() + x] == 1) {
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);
lock_actions(1);
draw_board();
for(animtime = 0, i = 0; i < animcadres;) {
for (animtime = 0, i = 0; i < animcadres;)
{
gettimeofday(&tvs, NULL);
gint isav = i;
for (; animtime == animarray[i].time && i < animcadres; i++) {

View File

@ -45,15 +45,18 @@ gint xy_to_cell_number(gint x, gint y) {
return find_node_of_x_y(x, y, rules_get_width());
}
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 _phase;
}
void set_jump_phase(gint p) {
if(!_animation_in_progress)
if (!_animation_in_progress) {
return;
}
_phase = p;
}
@ -72,7 +75,8 @@ void update_rectangle(gint x, gint y, gint w, gint 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();
GdkGC *gc = widget->style->fg_gc[gtk_widget_get_state(widget)];
gint cxs = gtkbTheme->emptycell.xsize;
@ -158,14 +162,16 @@ void draw_board(void) {
}
gint inc_with_limit(gint val, gint lim) {
if(val < lim)
if (val < lim) {
return val + 1;
}
return lim;
}
gint dec_with_limit(gint val, gint lim) {
if(val > lim)
if (val > lim) {
return val - 1;
}
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;
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" */
return;
if(_pointer_x == x && _pointer_y == y)
}
if (_pointer_x == x && _pointer_y == y) {
return;
}
_pointer_x = x;
_pointer_y = y;
for (i = 0; i < 2; i++) {
@ -219,17 +227,21 @@ void move_pointer_to(gint x, gint y) {
void move_pointer(Direction dir) {
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);
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);
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);
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);
if(xn == _pointer_x && yn == _pointer_y)
}
if (xn == _pointer_x && yn == _pointer_y) {
return;
}
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) {
gint cxs, cys, i;
if(numoldchilds && numoldchilds != rules_get_next()) {
if (numoldchilds && numoldchilds != rules_get_next())
{
if (_small_balls) {
for (i = 0; i < numoldchilds; i++) {
gtk_widget_destroy(_small_balls[i]);
@ -364,7 +377,8 @@ gint expose_event(GtkWidget *widget, GdkEventExpose *event) {
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) {
*pawnum = 2;
if (*direction == 1) *pawnum = 6;
@ -413,7 +427,8 @@ gboolean have_path(gint source_ball, gint target_ball) {
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 path[rules_get_width() * rules_get_height()];
gint pawx = -1, pawy = -1;
@ -439,9 +454,11 @@ void move_ball(gint source_ball, gint target_ball) {
phase = 0;
draw_ball(0, x, y, 0, 0);
if(pref_get_show_path()) {
if (pref_get_show_path())
{
lock_actions(1);
for(k = path[0] - 1; k; k--) {
for (k = path[0] - 1; k; k--)
{
gettimeofday(&tvs, NULL);
find_x_y_of_the_node(&i, &j, path[k], rules_get_width(), rules_get_height());
if (k == path[0] - 1) {

View File

@ -53,7 +53,8 @@ gint random_cell(void) {
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;
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());
}
void new_game(void){
void new_game(void)
{
stop_jumping_animation();
game_init_game(NULL, NULL);
menu_set_sensitive_undo(FALSE);
@ -111,7 +113,9 @@ void new_game(void){
draw_board();
}
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
gint i;
struct timeval tv;
struct timezone tz;
@ -126,7 +130,8 @@ int main(int argc, char **argv) {
#endif /* ENABLE_NLS */
/* drop privileges after spawning child with extra privs */
if(score_setup() == -1) return 1;
if (score_setup() == -1)
return 1;
setregid(getgid(), getgid());
/* initialize random seed */

View File

@ -8,7 +8,8 @@
#include <gtk/gtk.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) {
gtk_widget_destroy(widget);
return TRUE;
@ -16,9 +17,11 @@ gboolean ut_key_pressed_cb(GtkWidget *widget, GdkEventKey *event) {
return FALSE;
}
GtkWidget *ut_window_new(gchar *title, gchar *wmname, gchar *wmclass,
gboolean escaable, gboolean modal, gboolean resizable,
gint border) {
gint border)
{
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_modal(GTK_WINDOW(window), modal);
gtk_window_set_resizable(GTK_WINDOW(window), resizable);
@ -31,7 +34,9 @@ GtkWidget *ut_window_new(gchar *title, gchar *wmname, gchar *wmclass,
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;
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;
}
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;
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;
}
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;
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;
}
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;
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;
}
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;
GtkWidget *button, *hbox, *labelw;
@ -92,6 +105,7 @@ GtkWidget *ut_spin_button_new(gchar *label, gint min, gint max, gint val, GtkWid
return button;
}
GtkWidget *ut_spin_button_start_new(gchar *label, gint min, gint max, gint val, GtkWidget *parent)
{
GtkAdjustment *adj;
@ -111,13 +125,16 @@ GtkWidget *ut_spin_button_start_new(gchar *label, gint min, gint max, gint val,
return button;
}
/* 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);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
/* shows simple message box */
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);

View File

@ -1,7 +1,6 @@
#ifndef __GTKUTILS_H
#define __GTKUTILS_H
gboolean ut_key_pressed_cb (GtkWidget *widget,
GdkEventKey *event);
gboolean ut_key_pressed_cb (GtkWidget *widget, GdkEventKey *event);
GtkWidget *ut_window_new (gchar *title,
gchar *wmname,
@ -41,9 +40,9 @@ GtkWidget *ut_spin_button_start_new (gchar *label,
gint max,
gint val,
GtkWidget *parent);
void ut_simple_message_box (gchar *message);
void ut_simple_message_box_with_title (gchar *message,
gchar *title);
void ut_simple_message_box_with_title (gchar *message, gchar *title);
#endif

View File

@ -11,7 +11,8 @@
#include "gtkutils.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 * frame, * sw, * tv;
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_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++) {
gtk_list_store_append(store, &iter);
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);
}
void show_hall_of_fame_cb(void) {
void show_hall_of_fame_cb(void)
{
show_hall_of_fame(NULL, NULL, NULL);
}

View File

@ -21,7 +21,8 @@ static GtkWidget *_dialog = NULL;
static gchar _last_player_name[15] = "";
static gint _saved_score = 0;
void read_entry(GtkWidget *widget, gpointer data) {
void read_entry(GtkWidget *widget, gpointer data)
{
struct score_board current_entry;
time_t current_time;
struct tm *timeptr;
@ -37,6 +38,7 @@ void read_entry(GtkWidget *widget, gpointer data) {
current_entry.score = _saved_score;
current_time = time(NULL);
timeptr = localtime(&current_time);
if (!timeptr) {
ut_simple_message_box(_("Unable to determine current date.\n"));
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 ;) */
}
void input_name_dialog(void) {
void input_name_dialog(void)
{
GtkWidget * prompt_label, * vbox;
GtkWidget * name;
GtkWidget * button;

View File

@ -68,7 +68,8 @@ static gchar *_menu_translate(const gchar *path, gpointer data) {
return gettext(path);
}
void menu_get_main(GtkWidget *window, GtkWidget **menubar) {
void menu_get_main(GtkWidget *window, GtkWidget **menubar)
{
GtkAccelGroup *accel_group;
_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");
}
void _menu_set_sensitive(const gchar *path, gboolean sensitive) {
void _menu_set_sensitive(const gchar *path, gboolean sensitive)
{
GtkWidget *widget;
widget = gtk_ui_manager_get_widget(_ui_manager, path);
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);
}

View File

@ -68,7 +68,8 @@ void mw_set_user_score(gint score) {
g_free(str);
}
gboolean _countdown_timer(gpointer data) {
gboolean _countdown_timer(gpointer data)
{
gchar *text;
GtkLabel *label = data;
gint trem;
@ -94,7 +95,8 @@ gboolean _countdown_timer(gpointer data) {
return TRUE;
}
gint _user_action_event(GtkWidget *w, GdkEvent *ev) {
gint _user_action_event(GtkWidget *w, GdkEvent *ev)
{
if (ev->type == GDK_MOTION_NOTIFY) {
move_pointer_to(gtkb_theme_get_coord_at_x(ev->motion.x),
gtkb_theme_get_coord_at_y(ev->motion.y));
@ -137,13 +139,16 @@ gint _user_action_event(GtkWidget *w, GdkEvent *ev) {
return FALSE;
}
static void main_window_destroy_cb (GtkWidget * w, gpointer user_data)
{
gtkb_theme_free_handler (NULL, NULL);
gtk_main_quit ();
}
void mw_create(gint da_width, gint da_height) {
void mw_create(gint da_width, gint da_height)
{
GtkWidget * mainwin;
GtkWidget * menubar;
GtkWidget * vbox, * hbox, * hbox1, * drawing_area_box;

View File

@ -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
returns number of marked nodes */
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 x, y, node;
int xses[4] = { 0, 0, 1, -1};
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);
if (x != -1 && y != -1) {
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 */
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;
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;
}
/* find the path between source_node and the target_node
result stored in path
returns 0 on failure and 1 on success */
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 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;
nodes[source_node] = -1;
while(!finish) {
while (!finish)
{
if (!mark_neighbours_of_the_nodes(nodes, waves[k - 1], waves[k], k,
number_of_x_cells, number_of_y_cells)) {
/* 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[1] = waves[k - 1][i];
for(j = k - 2; j > 0; j--) {
for (j = k - 2; j > 0; j--)
{
finish = 0;
for (i = 1; i <= waves[j][0]; i++) {
if (is_neighbours(waves[j][i], path[k - j - 1],

View File

@ -3,8 +3,10 @@
int find_path (int *nodes, int source_node, int target_node, int *path,
int number_of_x_cells, int number_of_y_cells);
void find_x_y_of_the_node (int *x, int *y,
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);
#endif

View File

@ -16,7 +16,8 @@
#include "game.h"
#include "mainwin.h"
enum {
enum
{
PR_DIALOG,
PR_SHOW_NEXT,
PR_SHOW_PATH,
@ -50,7 +51,9 @@ gboolean fix_draw_next_balls(gpointer data) {
return FALSE;
}
void preferences_apply(GtkWidget *widget, gpointer data) {
void preferences_apply(GtkWidget *widget, gpointer data)
{
GtkWidget **buttons = data;
GtkTreeModel *model;
GtkTreeIter iter;
@ -105,13 +108,17 @@ void preferences_apply(GtkWidget *widget, gpointer data) {
}
}
void preferences_ok(GtkWidget *widget, gpointer data) {
GtkWidget **buttons = data;
preferences_apply(widget, buttons);
gtk_widget_destroy(buttons[PR_DIALOG]);
}
void preferences_dialog(void) {
void preferences_dialog (void)
{
GtkWidget ** buttons;
GtkWidget * frame;
GtkWidget * big_vbox, * vbox, * buttons_box;

View File

@ -142,7 +142,8 @@ gchar *pref_bool_to_str(gboolean val) {
/* we use very lame preferences file format: ``property=value\n''.
so - there must be no whitespaces on begin/end of line =) */
void load_preferences(void) {
void load_preferences(void)
{
FILE *fp;
gchar *rc_file;
gchar buffer[BUFFER_SIZE];
@ -152,11 +153,14 @@ void load_preferences(void) {
_theme_name = g_strdup(_default_theme_name);
}
rc_file = find_rc_file();
if((fp = fopen(rc_file, "r"))) {
while(fgets(buffer, BUFFER_SIZE, fp)) {
if ((fp = fopen(rc_file, "r")))
{
while(fgets(buffer, BUFFER_SIZE, fp))
{
g_strchomp(buffer);
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")) {
_show_next_colors = pref_str_to_bool(prop_val[1]);
} 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);
}
gchar *save_preferences(void) {
gchar *save_preferences (void)
{
FILE *fp;
gchar *rc_file/*, *err*/;
gchar *ret = NULL;

View File

@ -11,7 +11,8 @@
#include "gtkutils.h"
/* Show dialog box with game rules*/
void show_rules(GtkWidget *widget, gpointer data) {
void show_rules (GtkWidget *widget, gpointer data)
{
GtkWidget * window;
GtkWidget * vbox, * hbox, * button_box;
GtkWidget * label;

View File

@ -20,7 +20,8 @@ struct _gtkb_rules_dialog {
struct _gtkb_rules_dialog _rd;
void rules_ok(GtkWidget *widget, gpointer data) {
void rules_ok(GtkWidget *widget, gpointer data)
{
gint oldnext = rules_get_next();
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.yrange), rules_get_classic_height());
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());
}
void rules_dialog(void) {
void rules_dialog (void)
{
GtkWidget * dialog;
GtkWidget * frame;
GtkWidget * big_vbox, * vbox, * buttons_box;

View File

@ -63,8 +63,8 @@ void do_delete_game(GtkWidget *widget, GtkWidget *treeview) {
GtkTreeIter iter, nextiter;
GValue value = {0, };
if(gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),
&model, &iter)) {
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)),&model, &iter))
{
gtk_tree_model_get_value(model, &iter, 1, &value);
if (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);
}
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_b = {0, };
gchar *str_a, *str_b;
@ -172,7 +174,10 @@ gint game_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpoi
return r;
}
void save_load_game_dialog(gboolean is_save) {
void save_load_game_dialog(gboolean is_save)
{
GtkListStore * store;
GtkTreeIter iter;
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_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++) {
gtk_list_store_append (store, &iter);
memcpy (str1, gamelist[i * 2], 19 * sizeof(gchar));

View File

@ -17,15 +17,15 @@
#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;
gchar *sdata, *psdata, *srules;
FILE *f;
gint i, val;
gint rw, rh, rc, rn, rd, rlen;
if(stat(sgame, &buf) != 0 || !S_ISREG(buf.st_mode) || buf.st_size < 20 ||
(f = fopen(sgame, "r")) == NULL) {
if (stat(sgame, &buf) != 0 || !S_ISREG(buf.st_mode) || buf.st_size < 20 || (f = fopen(sgame, "r")) == NULL) {
return 0;
}
@ -84,9 +84,11 @@ gint parse_save_game(gchar *sgame, gchar **rules, gint *score, gint **board, gin
return 1;
}
/* 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 */
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;
gint score, *board, *next;
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;
struct stat buf;
struct dirent *dir_entry;
@ -136,7 +140,8 @@ gint get_saved_games(gchar ***gamelist) {
g_free (datapath);
return -1;
}
if((directory = opendir(datapath))) {
if ((directory = opendir(datapath)))
{
while ((dir_entry = readdir(directory))) {
if ((game = is_valid_save_game(dir_entry->d_name, datapath)) != NULL) {
num++;
@ -152,7 +157,9 @@ gint get_saved_games(gchar ***gamelist) {
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;
gchar *fname;
time_t nowtime;

View File

@ -1,7 +1,7 @@
/* scoreboard.c - save/load scores
*
* 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
* version 2 of the License, or (at your option) any later version.
*/
@ -23,12 +23,15 @@
int _score_fd = -1;
gint score_setup(void) {
gint score_setup(void)
{
_score_fd = child_setup(SCORE_FILE);
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;
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);
}
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;
gchar *buf, *tname, *tdate, *rules;
size_t sz;
@ -46,7 +51,8 @@ gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf) {
return FALSE;
}
for(i = 0; i < 10; i++) {
for (i = 0; i < 10; i++)
{
if (strlen(b[i].name)) {
tname = g_strdup(b[i].name);
if (!tname) {
@ -82,13 +88,17 @@ gint write_score(struct score_board *b, struct score_board_full *bf, gint nbf) {
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 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;
gchar buffer[BUFFER_SIZE];
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;
fsc = 0;
while(fgets(buffer, BUFFER_SIZE, fp)) {
while (fgets(buffer, BUFFER_SIZE, fp))
{
g_strchomp(buffer);
str_val = g_strsplit(buffer, "\t", 4);
if (str_val[0] && str_val[0][0] &&
str_val[1] && str_val[1][0] &&
str_val[2] && str_val[2][0]) {
str_val[2] && str_val[2][0])
{
valid = 0;
if (!str_val[3]) { /* < 2.2.0 file for mat */
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;
}
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;
if (entry.score <= 0) {

View File

@ -1,7 +1,7 @@
/* theme.c - functions related to theme handling
*
* 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
* version 2 of the License, or (at your option) any later version.
*/
@ -30,7 +30,9 @@ gchar *THEMEPREFIX="/.gtkballs/themes/";
#define DELTA(d, h) \
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 */
gint i;
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 *themepath;
struct stat buf;
@ -74,7 +78,9 @@ gchar *find_theme_path(gchar *themename) {
return NULL;
}
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname)
{
gchar *fname;
GError *error = NULL;
gint rv = 1;
@ -82,7 +88,9 @@ gint gtkb_load_pixmap(GtkbPixmap *pixmap, gchar *path, gchar *pixmapname) {
if (!(fname = g_strconcat(path, pixmapname, NULL))) {
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);
if (!pixmap->pixbuf) {
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;
if (!theme) {
@ -141,14 +151,18 @@ void gtkb_theme_free(GtkbTheme *theme) {
g_free (theme);
}
/* 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;
gint ret;
val = trc_get_str(trc, tmpname);
g_free (tmpname);
if(val == NULL) return 0;
if (val == NULL) {
return 0;
}
ret = gtkb_load_pixmap(pixmap, themepath, 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());
}
GtkbTheme *gtkb_load_theme(gchar *themepath) {
GtkbTheme *gtkb_load_theme(gchar *themepath)
{
gchar **trc, *opt;
gchar *paws[] = {"down_up", "left_right", "up_down", "right_left",
"down_right", "down_left", "up_right", "up_left", NULL};
@ -205,38 +221,38 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
/* find and load "footprints" pixmaps. */
for (i = 0; paws[i]; i++) {
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strconcat("paw.", paws[i], NULL),
&theme->paws[i]),
0);
&theme->paws[i]), 0);
}
/* query number of available balls in theme */
theme->numballs = trc_get_uint(trc, "ball.numbers");
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);
/* find and load all balls data. */
for (i = 0; i < theme->numballs; i++) {
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.still", i + 1),
&theme->balls[i].ball),
0);
&theme->balls[i].ball), 0);
CHECKRET(gtkb_load_pixmap_from(trc, themepath, g_strdup_printf("ball.%d.small", i + 1),
&theme->balls[i].small),
0);
&theme->balls[i].small), 0);
opt = g_strdup_printf("ball.%d.jump.numbers", i + 1);
theme->balls[i].jumpphases = trc_get_uint(trc, opt);
g_free (opt);
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].jumpdelays = g_new0(gint, theme->balls[i].jumpphases);
for (j = 0; j < theme->balls[i].jumpphases; j++) {
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
g_strdup_printf("ball.%d.jump.%d", i + 1, j + 1),
&theme->balls[i].jump[j]),
0);
&theme->balls[i].jump[j]), 0);
opt = g_strdup_printf("ball.%d.jump.%d.usec", i + 1, j + 1);
theme->balls[i].jumpdelays[j] = trc_get_uint(trc, opt);
g_free (opt);
@ -247,18 +263,18 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
theme->balls[i].destroyphases = trc_get_uint(trc, opt);
g_free (opt);
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) {
theme->maxdestphases = 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);
for (j = 0; j < theme->balls[i].destroyphases; j++) {
CHECKRET(gtkb_load_pixmap_from(trc, themepath,
g_strdup_printf("ball.%d.destroy.%d", i + 1, j + 1),
&theme->balls[i].destroy[j]),
0);
&theme->balls[i].destroy[j]), 0);
opt = g_strdup_printf("ball.%d.destroy.%d.usec", i + 1, j + 1);
theme->balls[i].destroydelays[j] = trc_get_uint(trc, opt);
g_free (opt);
@ -270,16 +286,22 @@ GtkbTheme *gtkb_load_theme(gchar *themepath) {
return theme;
}
gint load_theme(gchar *themename) {
gint load_theme(gchar *themename)
{
gchar *themepath;
GtkbTheme *theme;
if(!(themepath = find_theme_path(themename))) return 0;
if (!(themepath = find_theme_path(themename))) {
return 0;
}
theme = gtkb_load_theme(themepath);
g_free (themepath);
if(!theme) return 0;
if (!theme) {
return 0;
}
gtkb_theme_free(gtkbTheme);
gtkbTheme = theme;
@ -287,25 +309,33 @@ gint load_theme(gchar *themename) {
return 1;
}
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data) {
gint gtkb_theme_free_handler(GtkWidget *widget, gpointer data)
{
gtkb_theme_free(gtkbTheme);
gtkbTheme = NULL;
return 0;
}
gint gtkb_theme_get_balls_num(void) {
gint gtkb_theme_get_balls_num(void)
{
return gtkbTheme ? gtkbTheme->numballs : 0;
}
/* 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) {
return (x - 1) / gtkbTheme->emptycell.xsize;
}
return -1;
}
gint gtkb_theme_get_coord_at_y(gint y) {
gint gtkb_theme_get_coord_at_y(gint y)
{
if (gtkbTheme) {
return (y - 1) / gtkbTheme->emptycell.ysize;
}
@ -320,8 +350,10 @@ gint theme_get_height(void) {
return gtkbTheme->emptycell.xsize;
}
/* find all available themes. */
gchar **get_available_themes(void) {
gchar **get_available_themes(void)
{
DIR *directory;
struct dirent *dir_entry;
struct stat entry_stat;
@ -334,11 +366,14 @@ gchar **get_available_themes(void) {
} else {
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))) {
continue;
}
while((dir_entry = readdir(directory))) {
while((dir_entry = readdir(directory)))
{
if (!strncmp(dir_entry->d_name, ".", 2) ||
!strncmp(dir_entry->d_name, "..", 3)) {
continue;
@ -365,6 +400,7 @@ gchar **get_available_themes(void) {
}
closedir(directory);
}
g_free (hdir);
tlist = g_realloc(tlist, (num + 1) * sizeof(gchar *));
tlist[num] = NULL;

View File

@ -18,7 +18,8 @@
#include <errno.h>
/* read contents of fname into gchar * */
gchar **trc_open(gchar *fname) {
gchar **trc_open(gchar *fname)
{
gint fd;
struct stat fds;
ssize_t rb;
@ -68,7 +69,8 @@ void trc_close(gchar **rcs) {
}
/* 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;
gchar **strval,*val;
@ -98,7 +100,9 @@ gint trc_get_uint(gchar **rcs, gchar *param) {
gchar *val;
gint ret;
if(!(val=trc_get_str(rcs, param))) return -1;
if (!(val=trc_get_str(rcs, param))) {
return -1;
}
ret = atoi(val);
g_free (val);
return ret;