diff --git a/configure.in b/configure.in index 4a6eae9..5010c42 100644 --- a/configure.in +++ b/configure.in @@ -171,7 +171,7 @@ dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h sys/io.h errno.h) -AC_CHECK_HEADERS(limits.h kvm.h sys/param.h sys/dkstat.h) +AC_CHECK_HEADERS(limits.h kvm.h sys/param.h sys/dkstat.h stdbool.h) dnl check sys/sysctl.h seperately, as it requires other headers on at least OpenBSD AC_CHECK_HEADERS([sys/sysctl.h], [], [], diff --git a/server/client.c b/server/client.c index e468b3e..651adce 100644 --- a/server/client.c +++ b/server/client.c @@ -20,11 +20,11 @@ #endif #include "client.h" +#include "screen.h" #include "screenlist.h" #include "render.h" #include "input.h" #include "menuscreens.h" -#include "menuitem.h" #include "shared/report.h" #include "shared/LL.h" @@ -71,6 +71,7 @@ int client_destroy(Client *c) { Screen *s; + Menu *m; char *str; if (!c) @@ -99,12 +100,13 @@ client_destroy(Client *c) } LL_Destroy(c->screenlist); + m = (Menu *) c->menu; /* Destroy the client's menu, if it exists */ - if (c->menu) { - menuscreen_inform_item_destruction(c->menu); - menu_remove_item(c->menu->parent, c->menu); - menuscreen_inform_item_modified(c->menu->parent); - menuitem_destroy(c->menu); + if (m) { + menuscreen_inform_item_destruction(m); + menu_remove_item(m->parent, m); + menuscreen_inform_item_modified(m->parent); + menuitem_destroy(m); } /* Forget client's key reservations */ diff --git a/server/client.h b/server/client.h index 9d59d37..b605894 100644 --- a/server/client.h +++ b/server/client.h @@ -1,5 +1,15 @@ /** \file server/client.h * Defines all the client data and actions. + * + * \note If you only need 'struct Client' to work with you should use the + * following code (which does not create an indirect dependency on + * 'struct Screen'): + * + * \code + * #define INC_TYPES_ONLY 1 + * #include "client.h" + * #undef INC_TYPES_ONLY + * \endcode */ /* This file is part of LCDd, the lcdproc server. @@ -11,15 +21,10 @@ * 2002, Joris Robijn */ -#include "menu.h" -#include "menuitem.h" -/* These headers are placed here on purpose ! (circular references) */ - -#ifndef CLIENT_H -#define CLIENT_H +#ifndef CLIENT_H_TYPES +#define CLIENT_H_TYPES #include "shared/LL.h" -#include #define CLIENT_NAME_SIZE 256 @@ -42,11 +47,18 @@ typedef struct Client { LinkedList *messages; /**< Messages that the client sent. */ LinkedList *screenlist; /**< List of client's screens. */ - Menu *menu; /**< Menu hierarchy, if any */ + void* menu; /**< Menu hierarchy, if any */ } Client; +#endif +#ifndef INC_TYPES_ONLY +#ifndef CLIENT_H_FNCS +#define CLIENT_H_FNCS + +#define INC_TYPES_ONLY 1 #include "screen.h" +#undef INC_TYPES_ONLY /* When a new client connects, set up a new client data struct */ Client *client_create(int sock); @@ -73,4 +85,4 @@ int client_remove_screen(Client *c, Screen *s); int client_screen_count(Client *c); #endif - +#endif diff --git a/server/clients.c b/server/clients.c index fcca625..2aa6dba 100644 --- a/server/clients.c +++ b/server/clients.c @@ -19,9 +19,10 @@ #include #include +#include "shared/report.h" +#include "shared/LL.h" #include "client.h" #include "clients.h" -#include "shared/report.h" #include "render.h" LinkedList *clientlist = NULL; @@ -91,7 +92,7 @@ Client * clients_remove_client(Client *c, Direction whereto) { Client *client = LL_Remove(clientlist, c, whereto); - + return client; } diff --git a/server/clients.h b/server/clients.h index cf2733b..40f9d61 100644 --- a/server/clients.h +++ b/server/clients.h @@ -14,9 +14,6 @@ #define CLIENTS_H #include "client.h" -#include "shared/LL.h" - -/* extern LinkedList *clientlist; Not needed outside ? */ /* Initialize and kill client list...*/ int clients_init(void); diff --git a/server/commands/client_commands.c b/server/commands/client_commands.c index a9ab90b..39f4ac0 100644 --- a/server/commands/client_commands.c +++ b/server/commands/client_commands.c @@ -28,9 +28,10 @@ #include "shared/sockets.h" #include "drivers.h" -#include "render.h" #include "client.h" +#include "render.h" #include "input.h" +#include "client_commands.h" /** @@ -96,7 +97,7 @@ bye_func(Client *c, int argc, char **argv) c->state = GONE; //sock_send_error(c->sock, "\"bye\" is currently ignored\n"); - } + } return 0; } diff --git a/server/commands/command_list.c b/server/commands/command_list.c index d9a46a0..83bc608 100644 --- a/server/commands/command_list.c +++ b/server/commands/command_list.c @@ -14,6 +14,9 @@ * 2003, Joris Robijn */ +#include +#include + #include "command_list.h" #include "server_commands.h" #include "client_commands.h" @@ -21,9 +24,6 @@ #include "widget_commands.h" #include "menu_commands.h" -#include -#include - static client_function commands[] = { { "test_func", test_func_func }, { "hello", hello_func }, diff --git a/server/commands/command_list.h b/server/commands/command_list.h index 36119d7..6208470 100644 --- a/server/commands/command_list.h +++ b/server/commands/command_list.h @@ -13,7 +13,7 @@ #ifndef COMMANDS_COMMAND_LIST_H #define COMMANDS_COMMAND_LIST_H -#include "../client.h" +#include "client.h" /** * The function list for clients is stored in a table, and the items each diff --git a/server/commands/menu_commands.c b/server/commands/menu_commands.c index 4439e2f..dcf96ae 100644 --- a/server/commands/menu_commands.c +++ b/server/commands/menu_commands.c @@ -31,11 +31,11 @@ #include "shared/report.h" #include "shared/sockets.h" -#include "menu.h" +#include "client.h" #include "menuitem.h" +#include "menu.h" #include "menuscreens.h" #include "menu_commands.h" -#include "client.h" /* Local functions */ MenuEventFunc(menu_commands_handler); diff --git a/server/commands/screen_commands.c b/server/commands/screen_commands.c index 171d3fd..3218e49 100644 --- a/server/commands/screen_commands.c +++ b/server/commands/screen_commands.c @@ -30,6 +30,7 @@ #include "client.h" #include "screen.h" #include "render.h" +#include "screen_commands.h" /** * Tells the server the client has another screen to offer diff --git a/server/commands/server_commands.c b/server/commands/server_commands.c index b214036..cbc3100 100644 --- a/server/commands/server_commands.c +++ b/server/commands/server_commands.c @@ -29,6 +29,7 @@ #include "client.h" #include "render.h" +#include "server_commands.h" #define ALL_OUTPUTS_ON -1 #define ALL_OUTPUTS_OFF 0 diff --git a/server/commands/widget_commands.c b/server/commands/widget_commands.c index 17407c0..b687d20 100644 --- a/server/commands/widget_commands.c +++ b/server/commands/widget_commands.c @@ -30,8 +30,8 @@ #include "client.h" #include "screen.h" #include "widget.h" - #include "drivers.h" +#include "widget_commands.h" /** diff --git a/server/driver.h b/server/driver.h index c07ada2..85a8a9a 100644 --- a/server/driver.h +++ b/server/driver.h @@ -14,11 +14,13 @@ #include "drivers/lcd.h" -#ifndef bool -# define bool short -# define true 1 -# define false 0 +#ifdef HAVE_CONFIG_H +# include "config.h" #endif +#ifdef HAVE_STDBOOL_H +# include +#endif +#include "shared/defines.h" Driver * driver_load(const char *name, const char *filename); diff --git a/server/drivers.c b/server/drivers.c index cacbf81..6c5520c 100644 --- a/server/drivers.c +++ b/server/drivers.c @@ -24,11 +24,9 @@ #include "shared/report.h" #include "shared/configfile.h" -#include "drivers.h" #include "driver.h" -#include "drivers/lcd.h" +#include "drivers.h" #include "widget.h" -/* lcd.h is used for the driver API definition */ LinkedList *loaded_drivers = NULL; /**< list of loaded drivers */ diff --git a/server/drivers.h b/server/drivers.h index a1e047b..157904f 100644 --- a/server/drivers.h +++ b/server/drivers.h @@ -22,13 +22,6 @@ typedef struct DisplayProps { extern DisplayProps *display_props; -#ifndef bool -# define bool short -# define true 1 -# define false 0 -#endif - - int drivers_load_driver(const char *name); diff --git a/server/input.c b/server/input.c index 1e0663d..98bb051 100644 --- a/server/input.c +++ b/server/input.c @@ -11,8 +11,6 @@ * 2003, Joris Robijn */ - - #include #include #include @@ -20,13 +18,16 @@ #include "shared/sockets.h" #include "shared/report.h" #include "shared/configfile.h" +#include "shared/LL.h" #include "drivers.h" +#define INC_TYPES_ONLY 1 #include "client.h" +#include "screen.h" +#undef INC_TYPES_ONLY #include "screenlist.h" #include "menuscreens.h" - #include "input.h" #include "render.h" /* For server_msg* */ @@ -137,7 +138,7 @@ void input_send_to_client(Client *c, const char *key) snprintf(s, size, "key %s\n", key); sock_send_string(c->sock, s); free(s); - } + } else report(RPT_ERR, "%s: malloc failure", __FUNCTION__); } diff --git a/server/input.h b/server/input.h index de2bb89..8fa6714 100644 --- a/server/input.h +++ b/server/input.h @@ -13,17 +13,17 @@ #ifndef INPUT_H #define INPUT_H -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#ifdef HAVE_STDBOOL_H +# include +#endif +#include "shared/defines.h" /* Accepts and uses keypad input while displaying screens... */ int handle_input(void); -#ifndef bool -# define bool short -# define true 1 -# define false 0 -#endif - typedef struct KeyReservation { char *key; bool exclusive; diff --git a/server/main.c b/server/main.c index 9683db5..845ae99 100644 --- a/server/main.c +++ b/server/main.c @@ -57,8 +57,8 @@ #include "drivers.h" #include "sock.h" #include "clients.h" -#include "screenlist.h" #include "screen.h" +#include "screenlist.h" #include "parse.h" #include "render.h" #include "serverscreens.h" diff --git a/server/menu.c b/server/menu.c index 01776e1..68f56f2 100644 --- a/server/menu.c +++ b/server/menu.c @@ -32,14 +32,13 @@ # include "config.h" #endif +#include "widget.h" +#include "screen.h" #include "menuitem.h" #include "menu.h" #include "shared/report.h" #include "drivers.h" -#include "screen.h" -#include "widget.h" - extern Menu *custom_main_menu; @@ -209,7 +208,7 @@ menu_create(char *id, MenuEventFunc(*event_func), if (new_menu != NULL) { new_menu->data.menu.contents = LL_new(); new_menu->data.menu.association = NULL; - } + } return new_menu; } diff --git a/server/menu.h b/server/menu.h index 01a1eb3..047b598 100644 --- a/server/menu.h +++ b/server/menu.h @@ -12,27 +12,25 @@ * 2005, Peter Marschall - error checks, ... */ -#include "menuitem.h" -/* These headers are placed here on purpose ! (circular references) */ - #ifndef MENU_H #define MENU_H -#ifndef bool -# define bool short -# define true 1 -# define false 0 +#ifdef HAVE_CONFIG_H +# include "config.h" #endif +#ifdef HAVE_STDBOOL_H +# include +#endif +#include "shared/defines.h" #include "shared/LL.h" +#include "menuitem.h" /** A Menu is a MenuItem too. * This definition is only for better understanding of this code. */ typedef MenuItem Menu; -#include "screen.h" - /** Creates a new menu. */ Menu *menu_create(char *id, MenuEventFunc(*event_func), char *text, Client *client); @@ -43,8 +41,8 @@ Menu *menu_create(char *id, MenuEventFunc(*event_func), */ void menu_destroy(Menu *menu); -void menu_add_item(Menu *menu, MenuItem *item); /** Adds an item to the menu */ +void menu_add_item(Menu *menu, MenuItem *item); /** Removes an item from the menu (does not destroy it) */ void menu_remove_item(Menu *menu, MenuItem *item); diff --git a/server/menuitem.c b/server/menuitem.c index d9a303a..017463c 100644 --- a/server/menuitem.c +++ b/server/menuitem.c @@ -17,12 +17,14 @@ #include #include #include +#include #include "shared/report.h" #include "shared/defines.h" +#include "widget.h" +#include "screen.h" #include "menuitem.h" -#include "menuscreens.h" #include "menu.h" #include "drivers.h" @@ -134,7 +136,10 @@ MenuItem *menuitem_search(char *menu_id, Client *client) } /******** FUNCTION TABLES ********/ -/* Tables with functions to call for all different item types */ +/*- + * Tables with functions to call for all different item types. The order is: + * "menu", "action", "checkbox", "ring", "slider", "numeric", "alpha", "ip". + */ void (*destructor_table[NUM_ITEMTYPES]) (MenuItem *item) = { @@ -284,7 +289,7 @@ MenuItem *menuitem_create_checkbox(char *id, MenuEventFunc(*event_func), if (new_item != NULL) { new_item->data.checkbox.allow_gray = allow_gray; new_item->data.checkbox.value = value; - } + } return new_item; } @@ -301,7 +306,7 @@ MenuItem *menuitem_create_ring(char *id, MenuEventFunc(*event_func), if (new_item != NULL) { new_item->data.ring.strings = tablist2linkedlist(strings); new_item->data.ring.value = value; - } + } return new_item; } @@ -328,7 +333,7 @@ MenuItem *menuitem_create_slider(char *id, MenuEventFunc(*event_func), new_item->data.slider.maxvalue = maxvalue; new_item->data.slider.stepsize = stepsize; new_item->data.slider.value = value; - } + } return new_item; } @@ -351,7 +356,7 @@ MenuItem *menuitem_create_numeric(char *id, MenuEventFunc(*event_func), menuitem_destroy(new_item); return NULL; } - } + } return new_item; } @@ -445,7 +450,7 @@ MenuItem *menuitem_create_ip(char *id, MenuEventFunc(*event_func), __FUNCTION__, id, value); strncpy(new_item->data.ip.value, ipinfo->dummy, new_item->data.ip.maxlength); new_item->data.ip.value[new_item->data.ip.maxlength] = '\0'; - } + } } new_item->data.ip.edit_str = malloc(new_item->data.ip.maxlength + 1); @@ -476,7 +481,7 @@ void menuitem_destroy(MenuItem *item) /* And finally...*/ free(item); - } + } } void menuitem_destroy_ring(MenuItem *item) @@ -495,7 +500,7 @@ void menuitem_destroy_ring(MenuItem *item) } /* and the list */ LL_Destroy(item->data.ring.strings); - } + } } void menuitem_destroy_slider(MenuItem *item) @@ -507,7 +512,7 @@ void menuitem_destroy_slider(MenuItem *item) /* These strings should always be allocated */ free(item->data.slider.mintext); free(item->data.slider.maxtext); - } + } } void menuitem_destroy_numeric(MenuItem *item) @@ -518,7 +523,7 @@ void menuitem_destroy_numeric(MenuItem *item) if (item != NULL) { /* This string should always be allocated */ free(item->data.numeric.edit_str); - } + } } void menuitem_destroy_alpha(MenuItem *item) @@ -531,7 +536,7 @@ void menuitem_destroy_alpha(MenuItem *item) free(item->data.alpha.allowed_extra); free(item->data.alpha.value); free(item->data.alpha.edit_str); - } + } } void menuitem_destroy_ip(MenuItem *item) @@ -559,7 +564,7 @@ void menuitem_reset(MenuItem *item) func = reset_table[item->type]; if (func) func(item); - } + } } void menuitem_reset_numeric(MenuItem *item) @@ -577,7 +582,7 @@ void menuitem_reset_numeric(MenuItem *item) } else { snprintf(item->data.numeric.edit_str, MAX_NUMERIC_LEN, "%d", item->data.numeric.value); - } + } } } @@ -591,7 +596,7 @@ void menuitem_reset_alpha(MenuItem *item) item->data.alpha.edit_offs = 0; memset(item->data.alpha.edit_str, '\0', item->data.alpha.maxlength+1); strcpy(item->data.alpha.edit_str, item->data.alpha.value); - } + } } void menuitem_reset_ip(MenuItem *item) @@ -620,8 +625,8 @@ void menuitem_reset_ip(MenuItem *item) tmpstr[0] = ipinfo->sep; tmpstr[1] = '\0'; strcat(item->data.ip.edit_str, tmpstr); - } - } + } + } } @@ -664,8 +669,8 @@ void menuitem_rebuild_screen(MenuItem *item, Screen *s) /* Also always call update_screen */ menuitem_update_screen(item, s); - } - } + } + } } void menuitem_rebuild_screen_slider(MenuItem *item, Screen *s) @@ -1027,7 +1032,7 @@ MenuResult menuitem_process_input_slider(MenuItem *item, MenuToken token, const * Note: The max value is actually reached, * because of min(maxvalue, value + stepsize) below. * Wrapping then happens on the next key press. - */ + */ if ((!(keymask & (MENUTOKEN_LEFT | MENUTOKEN_DOWN))) && (item->data.slider.value == item->data.slider.maxvalue)) item->data.slider.value = item->data.slider.minvalue; @@ -1210,7 +1215,7 @@ MenuResult menuitem_process_input_numeric(MenuItem *item, MenuToken token, const default: return MENURESULT_NONE; } - } + } return MENURESULT_ERROR; } @@ -1339,7 +1344,7 @@ MenuResult menuitem_process_input_alpha(MenuItem *item, MenuToken token, const c item->data.alpha.edit_pos--; if (item->data.alpha.edit_offs > item->data.alpha.edit_pos) item->data.alpha.edit_offs = item->data.alpha.edit_pos; - } + } return MENURESULT_NONE; case MENUTOKEN_OTHER: if (pos >= item->data.alpha.maxlength) { @@ -1356,9 +1361,9 @@ MenuResult menuitem_process_input_alpha(MenuItem *item, MenuToken token, const c if (pos >= display_props->width - 2) item->data.alpha.edit_offs++; } - default: + default: return MENURESULT_NONE; - } + } } return MENURESULT_ERROR; } @@ -1489,7 +1494,7 @@ MenuResult menuitem_process_input_ip(MenuItem *item, MenuToken token, const char } } /* FALLTHROUGH */ - default: + default: return MENURESULT_NONE; } /* NOTREACHED */ diff --git a/server/menuitem.h b/server/menuitem.h index e974e5d..a83f210 100644 --- a/server/menuitem.h +++ b/server/menuitem.h @@ -11,7 +11,7 @@ * * The slider, numeric & string input and menu have their own screen, * that comes to front when the items are selected. - * One menuitem is in a different file: Menu data is in menu,h. + * One menuitem is in a different file: Menu data is in menu.h. */ /* This file is part of LCDd, the lcdproc server. @@ -27,13 +27,15 @@ #ifndef MENUITEM_H #define MENUITEM_H -#include "shared/LL.h" - -#ifndef bool -# define bool short -# define true 1 -# define false 0 +#ifdef HAVE_CONFIG_H +# include "config.h" #endif +#ifdef HAVE_STDBOOL_H +# include +#endif +#include "shared/defines.h" + +#include "shared/LL.h" /********************************************************************* * Data definitions of the menustuff @@ -191,8 +193,6 @@ typedef struct MenuItem { } MenuItem; -#include "screen.h" - /********************************************************************* * Functions to use the menustuff */ diff --git a/server/menuscreens.c b/server/menuscreens.c index 5d3c3e9..31d5910 100644 --- a/server/menuscreens.c +++ b/server/menuscreens.c @@ -1,7 +1,7 @@ /** \file server/menuscreens.c * Creates the server menu screen(s) and creates the menus that should be * displayed on this screen. - * It also handles its keypresses and converts them to menu tokens for + * It also handles its key presses and converts them to menu tokens for * easier processing. * * \note @@ -9,7 +9,8 @@ * a menu or on a separate SCREEN, for flexibility. */ -/* This file is part of LCDd, the lcdproc server. +/*- + * This file is part of LCDd, the lcdproc server. * * This file is released under the GNU General Public License. * Refer to the COPYING file distributed with this package. @@ -23,6 +24,7 @@ #include #include #include +#include #include "screen.h" #include "screenlist.h" @@ -53,7 +55,7 @@ Screen *menuscreen = NULL; MenuItem *active_menuitem = NULL; /** the "real" main_menu */ Menu *main_menu = NULL; -/** customizable entry point into the menu system (see menu_set_main()). */ +/** customizable entry point into the menu system (see menuscreen_set_main()). */ Menu *custom_main_menu = NULL; Menu *screens_menu = NULL; @@ -75,14 +77,17 @@ MenuEventFunc(titlespeed_handler); MenuEventFunc(contrast_handler); MenuEventFunc(brightness_handler); -int menuscreens_init(void) +int +menuscreens_init(void) { const char *tmp; debug(RPT_DEBUG, "%s()", __FUNCTION__); - /* Get keys from config file: MenuKey, EnterKey, UpKey, DownKey, LeftKey, RightKey. - * For a working menu at least 3 are necessary: MenuKey, EnterKey, UpKey/DownKey. + /* + * Get keys from config file: MenuKey, EnterKey, UpKey, DownKey, + * LeftKey, RightKey. For a working menu at least 3 are necessary: + * MenuKey, EnterKey, UpKey/DownKey. */ keymask = 0; menu_key = enter_key = NULL; @@ -150,7 +155,8 @@ int menuscreens_init(void) } -int menuscreens_shutdown(void) +int +menuscreens_shutdown(void) { debug(RPT_DEBUG, "%s()", __FUNCTION__); @@ -175,30 +181,31 @@ int menuscreens_shutdown(void) /* Forget menu's key reservations */ input_release_client_keys(NULL); - if (menu_key != NULL) + if (menu_key != NULL) free(menu_key); - if (enter_key != NULL) + if (enter_key != NULL) free(enter_key); - if (up_key != NULL) + if (up_key != NULL) free(up_key); - if (down_key != NULL) + if (down_key != NULL) free(down_key); if (left_key != NULL) - free(left_key); + free(left_key); if (right_key != NULL) - free(right_key); - keymask = 0; + free(right_key); + keymask = 0; return 0; } -void menuscreen_inform_item_destruction(MenuItem *item) +void +menuscreen_inform_item_destruction(MenuItem * item) { MenuItem *i; debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__, - ((item != NULL) ? item->id : "(null)")); + ((item != NULL) ? item->id : "(null)")); /* Are we currently in (a subitem of) the given item ? */ for (i = active_menuitem; i != NULL; i = i->parent) { @@ -208,10 +215,11 @@ void menuscreen_inform_item_destruction(MenuItem *item) } } -void menuscreen_inform_item_modified(MenuItem *item) +void +menuscreen_inform_item_modified(MenuItem * item) { debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__, - ((item != NULL) ? item->id : "(null)")); + ((item != NULL) ? item->id : "(null)")); if ((active_menuitem == NULL) || (item == NULL)) return; @@ -222,7 +230,8 @@ void menuscreen_inform_item_modified(MenuItem *item) } } -bool is_menu_key(const char *key) +bool +is_menu_key(const char *key) { if ((menu_key != NULL) && (key != NULL) && (strcmp(key, menu_key) == 0)) return true; @@ -230,12 +239,13 @@ bool is_menu_key(const char *key) return false; } -/** This function changes the menuitem to the given one, and does necesary +/** This function changes the menuitem to the given one, and does necessary * actions. * To leave the menu system, specify NULL for new_menuitem. * The item will not be reset when the new item is a child of the last one. */ -void menuscreen_switch_item(MenuItem *new_menuitem) +void +menuscreen_switch_item(MenuItem * new_menuitem) { MenuItem *old_menuitem = active_menuitem; @@ -249,16 +259,19 @@ void menuscreen_switch_item(MenuItem *new_menuitem) /* What was the state change ? */ if (!old_menuitem && !new_menuitem) { /* Nothing to be done */ - } else if (old_menuitem && !new_menuitem) { + } + else if (old_menuitem && !new_menuitem) { /* leave menu system */ menuscreen->priority = PRI_HIDDEN; - } else if (!old_menuitem && new_menuitem) { + } + else if (!old_menuitem && new_menuitem) { /* Menu is becoming active */ menuitem_reset(active_menuitem); menuitem_rebuild_screen(active_menuitem, menuscreen); menuscreen->priority = PRI_INPUT; - } else { + } + else { /* We're left with the usual case: a menu level switch */ if (old_menuitem->parent != new_menuitem) { menuitem_reset(new_menuitem); @@ -266,34 +279,36 @@ void menuscreen_switch_item(MenuItem *new_menuitem) menuitem_rebuild_screen(active_menuitem, menuscreen); } - if (old_menuitem && old_menuitem->event_func) - old_menuitem->event_func(old_menuitem, MENUEVENT_LEAVE); - if (new_menuitem && new_menuitem->event_func) - new_menuitem->event_func(new_menuitem, MENUEVENT_ENTER); + if (old_menuitem && old_menuitem->event_func) + old_menuitem->event_func(old_menuitem, MENUEVENT_LEAVE); + if (new_menuitem && new_menuitem->event_func) + new_menuitem->event_func(new_menuitem, MENUEVENT_ENTER); return; } -static void handle_quit(void) +static void +handle_quit(void) { debug(RPT_DEBUG, "%s: Closing menu screen", __FUNCTION__); menuscreen_switch_item(NULL); } -static void handle_close(void) +static void +handle_close(void) { debug(RPT_DEBUG, "%s: Closing item", __FUNCTION__); menuscreen_switch_item( - (active_menuitem == menuscreen_get_main()) - ? NULL - : active_menuitem->parent); + (active_menuitem == menuscreen_get_main()) + ? NULL + : active_menuitem->parent); } -static void handle_none(void) +static void +handle_none(void) { debug(RPT_DEBUG, "%s: Staying in item", __FUNCTION__); - if (active_menuitem) - { + if (active_menuitem) { menuitem_update_screen(active_menuitem, menuscreen); /* No rebuild needed, only value can be changed */ } @@ -305,45 +320,49 @@ static void handle_none(void) * own screen. The menuitem_process_input function should do * things like toggling checkboxes ! */ -static void handle_enter(void) +static void +handle_enter(void) { debug(RPT_DEBUG, "%s: Entering subitem", __FUNCTION__); menuscreen_switch_item(menu_get_current_item(active_menuitem)); } -static void handle_predecessor(void) +static void +handle_predecessor(void) { - MenuItem* predecessor; - MenuItem* item = (active_menuitem->type == MENUITEM_MENU) + MenuItem *predecessor; + MenuItem *item = (active_menuitem->type == MENUITEM_MENU) ? menu_get_item_for_predecessor_check(active_menuitem) : active_menuitem; assert(item != NULL); debug(RPT_DEBUG, "%s: Switching to registered predecessor '%s' of '%s'.", - __FUNCTION__, item->predecessor_id, item->id); + __FUNCTION__, item->predecessor_id, item->id); predecessor = menuitem_search(item->predecessor_id, (Client *) active_menuitem->client); if (predecessor == NULL) { - // note: if _quit_, _close_, _none_ get here this - // would be an implementation error - they should - // have been handled via different MENURESULT codes. + /* + * note: if _quit_, _close_, _none_ get here this would be an + * implementation error - they should have been handled via + * different MENURESULT codes. + */ report(RPT_ERR, "%s: cannot find predecessor '%s' of '%s'.", - __FUNCTION__, item->predecessor_id, item->id); + __FUNCTION__, item->predecessor_id, item->id); return; } switch (predecessor->type) { - case MENUITEM_ACTION: - case MENUITEM_CHECKBOX: - case MENUITEM_RING: + case MENUITEM_ACTION: + case MENUITEM_CHECKBOX: + case MENUITEM_RING: if (active_menuitem != predecessor->parent) menuscreen_switch_item(predecessor->parent); - // this won't work for hidden subitems + /* this won't work for hidden subitems */ menu_select_subitem(active_menuitem, item->predecessor_id); menuitem_update_screen(active_menuitem, menuscreen); break; - default: + default: if ((predecessor->parent != NULL) && (predecessor->parent->type == MENUITEM_MENU)) { - // update parent menu too + /* update parent menu too */ menu_select_subitem(predecessor->parent, predecessor->id); } menuscreen_switch_item(predecessor); @@ -351,39 +370,42 @@ static void handle_predecessor(void) } } -static void handle_successor(void) +static void +handle_successor(void) { MenuItem *successor; - MenuItem* item = (active_menuitem->type == MENUITEM_MENU) + MenuItem *item = (active_menuitem->type == MENUITEM_MENU) ? menu_get_item_for_successor_check(active_menuitem) : active_menuitem; assert(item != NULL); debug(RPT_DEBUG, "%s: Switching to registered successor '%s' of '%s'.", - __FUNCTION__, item->successor_id, item->id); + __FUNCTION__, item->successor_id, item->id); successor = menuitem_search(item->successor_id, (Client *) active_menuitem->client); if (successor == NULL) { - // note: if _quit_, _close_, _none_ get here this - // would be an implementation error - they should - // have been handled via different MENURESULT codes. + /* + * note: if _quit_, _close_, _none_ get here this would be an + * implementation error - they should have been handled via + * different MENURESULT codes. + */ report(RPT_ERR, "%s: cannot find successor '%s' of '%s'.", - __FUNCTION__, item->successor_id, item->id); + __FUNCTION__, item->successor_id, item->id); return; } switch (successor->type) { - case MENUITEM_ACTION: - case MENUITEM_CHECKBOX: - case MENUITEM_RING: + case MENUITEM_ACTION: + case MENUITEM_CHECKBOX: + case MENUITEM_RING: if (active_menuitem != successor->parent) menuscreen_switch_item(successor->parent); - // this won't work for hidden subitems + /* this won't work for hidden subitems */ menu_select_subitem(active_menuitem, item->successor_id); menuitem_update_screen(active_menuitem, menuscreen); break; - default: + default: if ((successor->parent != NULL) && (successor->parent->type == MENUITEM_MENU)) { - // update parent menu too + /* update parent menu too */ menu_select_subitem(successor->parent, successor->id); } menuscreen_switch_item(successor); @@ -391,7 +413,8 @@ static void handle_successor(void) } } -void menuscreen_key_handler(const char *key) +void +menuscreen_key_handler(const char *key) { MenuToken token = MENUTOKEN_NONE; MenuResult res; @@ -429,34 +452,35 @@ void menuscreen_key_handler(const char *key) res = menuitem_process_input(active_menuitem, token, key, keymask); switch (res) { - case MENURESULT_ERROR: + case MENURESULT_ERROR: report(RPT_ERR, "%s: Error from menuitem_process_input", __FUNCTION__); break; - case MENURESULT_NONE: + case MENURESULT_NONE: handle_none(); break; - case MENURESULT_ENTER: + case MENURESULT_ENTER: handle_enter(); break; - case MENURESULT_CLOSE: + case MENURESULT_CLOSE: handle_close(); break; - case MENURESULT_QUIT: + case MENURESULT_QUIT: handle_quit(); break; - case MENURESULT_PREDECESSOR: + case MENURESULT_PREDECESSOR: handle_predecessor(); break; - case MENURESULT_SUCCESSOR: + case MENURESULT_SUCCESSOR: handle_successor(); break; - default: + default: assert(!"unexpected menuresult"); break; } } -void menuscreen_create_menu(void) +void +menuscreen_create_menu(void) { Menu *options_menu; Menu *driver_menu; @@ -480,10 +504,10 @@ void menuscreen_create_menu(void) menu_add_item(main_menu, options_menu); #ifdef LCDPROC_TESTMENUS - /* TODO: - * Menu items in the screens menu currently have no functions assigned. - * Thefore only enable the menu for testing. If functions are available, - * this code should be outside the #ifdef. + /* + * TODO: Menu items in the screens menu currently have no functions + * assigned. Therefore only enable the menu for testing. If functions + * are available, this code should be outside the #ifdef. */ screens_menu = menu_create("screens", NULL, "Screens", NULL); if (screens_menu == NULL) { @@ -495,8 +519,10 @@ void menuscreen_create_menu(void) menuscreen_create_testmenu(); #endif - /* add option menu contents: - * menu's client is NULL since we're in the server */ + /* + * add option menu contents: menu's client is NULL since we're in the + * server + */ checkbox = menuitem_create_checkbox("heartbeat", heartbeat_handler, "Heartbeat", NULL, true, heartbeat); menu_add_item(options_menu, checkbox); @@ -507,8 +533,10 @@ void menuscreen_create_menu(void) "TitleSpeed", NULL, "0", "10", TITLESPEED_NO, TITLESPEED_MAX, 1, titlespeed); menu_add_item(options_menu, slider); - /* add driver specific option menus for each driver: - * menu's client is NULL since we're in the server */ + /* + * add driver specific option menus for each driver: menu's client is + * NULL since we're in the server + */ for (driver = drivers_getfirst(); driver; driver = drivers_getnext()) { int contrast_avail = (driver->get_contrast && driver->set_contrast) ? 1 : 0; int brightness_avail = (driver->get_brightness && driver->set_brightness) ? 1 : 0; @@ -518,7 +546,7 @@ void menuscreen_create_menu(void) driver_menu = menu_create(driver->name, NULL, driver->name, NULL); if (driver_menu == NULL) { report(RPT_ERR, "%s: Cannot create menu for driver %s", - __FUNCTION__, driver->name); + __FUNCTION__, driver->name); continue; } menu_set_association(driver_menu, driver); @@ -528,7 +556,7 @@ void menuscreen_create_menu(void) /* menu's client is NULL since we're in the server */ slider = menuitem_create_slider("contrast", contrast_handler, "Contrast", - NULL, "min", "max", 0, 1000, 25, contrast); + NULL, "min", "max", 0, 1000, 25, contrast); menu_add_item(driver_menu, slider); } if (brightness_avail) { @@ -536,11 +564,11 @@ void menuscreen_create_menu(void) int offbrightness = driver->get_brightness(driver, BACKLIGHT_OFF); slider = menuitem_create_slider("onbrightness", brightness_handler, "On Brightness", - NULL, "min", "max", 0, 1000, 25, onbrightness); + NULL, "min", "max", 0, 1000, 25, onbrightness); menu_add_item(driver_menu, slider); slider = menuitem_create_slider("offbrightness", brightness_handler, "Off Brightness", - NULL, "min", "max", 0, 1000, 25, offbrightness); + NULL, "min", "max", 0, 1000, 25, offbrightness); menu_add_item(driver_menu, slider); } } @@ -548,7 +576,9 @@ void menuscreen_create_menu(void) } #ifdef LCDPROC_TESTMENUS -void menuscreen_create_testmenu(void) { +void +menuscreen_create_testmenu(void) +{ MenuItem *test_item; Menu *test_menu; @@ -609,20 +639,20 @@ void menuscreen_create_testmenu(void) { test_item = menuitem_create_alpha("", NULL, "Alpha, caps only", NULL, 0, 3, 12, true, false, false, "-", "LCDPROC"); menu_add_item(test_menu, test_item); - test_item = menuitem_create_ip("", NULL, "IPv4", NULL, 0, "192.168.1.245"); + test_item = menuitem_create_ip("", NULL, "IPv4", NULL, false, "192.168.1.245"); menu_add_item(test_menu, test_item); - test_item = menuitem_create_ip("", NULL, "IPv6", NULL, 1, "1080:0:0:0:8:800:200C:417A"); + test_item = menuitem_create_ip("", NULL, "IPv6", NULL, true, "1080:0:0:0:8:800:200C:417A"); menu_add_item(test_menu, test_item); - + test_item = menuitem_create_ring("", NULL, "Charset", NULL, testiso, 0); menu_add_item(test_menu, test_item); } -#endif /*LCDPROC_TESTMENUS*/ +#endif /* LCDPROC_TESTMENUS */ -MenuEventFunc (heartbeat_handler) +MenuEventFunc(heartbeat_handler) { debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, - ((item != NULL) ? item->id : "(null)"), event); + ((item != NULL) ? item->id : "(null)"), event); if ((item != NULL) && (event == MENUEVENT_UPDATE)) { /* Set heartbeat setting */ @@ -632,10 +662,10 @@ MenuEventFunc (heartbeat_handler) return 0; } -MenuEventFunc (backlight_handler) +MenuEventFunc(backlight_handler) { debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, - ((item != NULL) ? item->id : "(null)"), event); + ((item != NULL) ? item->id : "(null)"), event); if ((item != NULL) && (event == MENUEVENT_UPDATE)) { /* Set backlight setting */ @@ -645,10 +675,10 @@ MenuEventFunc (backlight_handler) return 0; } -MenuEventFunc (titlespeed_handler) +MenuEventFunc(titlespeed_handler) { debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, - ((item != NULL) ? item->id : "(null)"), event); + ((item != NULL) ? item->id : "(null)"), event); if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { /* set titlespeed setting */ @@ -658,12 +688,15 @@ MenuEventFunc (titlespeed_handler) return 0; } -MenuEventFunc (contrast_handler) +MenuEventFunc(contrast_handler) { debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, - ((item != NULL) ? item->id : "(null)"), event); + ((item != NULL) ? item->id : "(null)"), event); - /* This function can be called by one of several drivers that support contrast */ + /* + * This function can be called by one of several drivers that support + * contrast + */ if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { /* Determine the driver by following the menu's association */ Driver *driver = item->parent->data.menu.association; @@ -671,18 +704,21 @@ MenuEventFunc (contrast_handler) if (driver != NULL) { driver->set_contrast(driver, item->data.slider.value); report(RPT_INFO, "Menu: set contrast of [%.40s] to %d", - driver->name, item->data.slider.value); + driver->name, item->data.slider.value); } } return 0; } -MenuEventFunc (brightness_handler) +MenuEventFunc(brightness_handler) { debug(RPT_DEBUG, "%s(item=[%s], event=%d)", __FUNCTION__, - ((item != NULL) ? item->id : "(null)"), event); + ((item != NULL) ? item->id : "(null)"), event); - /* This function can be called by one of several drivers that support brightness ! */ + /* + * This function can be called by one of several drivers that support + * brightness ! + */ if ((item != NULL) && ((event == MENUEVENT_MINUS) || (event == MENUEVENT_PLUS))) { /* Determine the driver by following the menu's association */ Driver *driver = item->parent->data.menu.association; @@ -706,7 +742,7 @@ menuscreen_add_screen(Screen *s) MenuItem *mi; debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__, - ((s != NULL) ? s->id : "(null)")); + ((s != NULL) ? s->id : "(null)")); /* screens have not been created or no screen given ... */ if ((screens_menu == NULL) || (s == NULL)) @@ -735,7 +771,7 @@ menuscreen_add_screen(Screen *s) menu_add_item(m, mi); mi = menuitem_create_ring("", NULL, "Priority", s->client, - "Hidden\tBackground\tForeground\tAlert\tInput", s->priority); + "Hidden\tBackground\tForeground\tAlert\tInput", s->priority); menu_add_item(m, mi); } @@ -744,7 +780,7 @@ void menuscreen_remove_screen(Screen *s) { debug(RPT_DEBUG, "%s(s=[%s])", __FUNCTION__, - (s != NULL) ? s->id : "(NULL)"); + (s != NULL) ? s->id : "(NULL)"); /* allow to remove the menuscreen itself */ if ((s == NULL) || (s == menuscreen)) @@ -759,22 +795,22 @@ menuscreen_remove_screen(Screen *s) } int -menuscreen_goto(Menu *menu) +menuscreen_goto(Menu * menu) { debug(RPT_DEBUG, "%s(m=[%s]): active_menuitem=[%s]", - __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)", - (active_menuitem != NULL) ? active_menuitem->id : "(NULL)"); - menuscreen_switch_item(menu); - return 0; + __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)", + (active_menuitem != NULL) ? active_menuitem->id : "(NULL)"); + menuscreen_switch_item(menu); + return 0; } /** sets custom main menu. Use NULL pointer to reset it to the "real" main * menu. */ int -menuscreen_set_main(Menu *menu) +menuscreen_set_main(Menu * menu) { debug(RPT_DEBUG, "%s(m=[%s])", - __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)"); + __FUNCTION__, (menu != NULL) ? menu->id : "(NULL)"); custom_main_menu = menu; return 0; } diff --git a/server/menuscreens.h b/server/menuscreens.h index 092576a..1984585 100644 --- a/server/menuscreens.h +++ b/server/menuscreens.h @@ -16,7 +16,6 @@ #define MENUSCREENS_H #include "menu.h" -#include "menuitem.h" #include "screen.h" extern Screen *menuscreen; diff --git a/server/render.h b/server/render.h index 3a3ae21..64b8072 100644 --- a/server/render.h +++ b/server/render.h @@ -12,8 +12,6 @@ #ifndef RENDER_H #define RENDER_H -#include "screen.h" - #define HEARTBEAT_OFF 0 #define HEARTBEAT_ON 1 #define HEARTBEAT_OPEN 2 @@ -31,7 +29,7 @@ #define CURSOR_UNDER 5 #define TITLESPEED_NO 0 /* needs to be (TITLESPEED_MIN - 1) */ -#define TITLESPEED_MIN 1 +#define TITLESPEED_MIN 1 #define TITLESPEED_MAX 10 extern int heartbeat; diff --git a/server/screen.c b/server/screen.c index 834143e..32b2009 100644 --- a/server/screen.c +++ b/server/screen.c @@ -25,7 +25,6 @@ #include "clients.h" #include "widget.h" #include "screenlist.h" -#include "screen.h" #include "menuscreens.h" #include "main.h" #include "render.h" diff --git a/server/screen.h b/server/screen.h index 7a5369a..b4aedf4 100644 --- a/server/screen.h +++ b/server/screen.h @@ -1,5 +1,15 @@ /** \file server/screen.h * Public interface to the screen management methods. + * + * \note If you only need 'struct Screen' to work with you should use the + * following code (which does not create an indirect dependency on + * 'struct Widget'): + * + * \code + * #define INC_TYPES_ONLY 1 + * #include "screen.h" + * #undef INC_TYPES_ONLY + * \endcode */ /* This file is part of LCDd, the lcdproc server. @@ -11,16 +21,18 @@ * 2003, Joris Robijn */ -#include "menu.h" -#include "menuitem.h" -#include "client.h" -/* These headers are placed here on purpose ! (circular references) */ - -#ifndef SCREEN_H -#define SCREEN_H +#ifndef SCREEN_H_TYPES +#define SCREEN_H_TYPES #include "shared/LL.h" -#include "client.h" + +#ifdef INC_TYPES_ONLY +# include "client.h" +#else +# define INC_TYPES_ONLY 1 +# include "client.h" +# undef INC_TYPES_ONLY +#endif typedef enum { PRI_HIDDEN, PRI_BACKGROUND, PRI_INFO, PRI_FOREGROUND, PRI_ALERT, PRI_INPUT @@ -43,13 +55,18 @@ typedef struct Screen { struct Client *client; } Screen; -#include "widget.h" - - extern int default_duration ; extern int default_priority ; -#include "client.h" +#endif + +#ifndef INC_TYPES_ONLY +#ifndef SCREEN_H_FNCS +#define SCREEN_H_FNCS + +#define INC_TYPES_ONLY 1 +#include "widget.h" +#undef INC_TYPES_ONLY /* Creates a new screen */ Screen *screen_create(char *id, Client *client); @@ -87,3 +104,4 @@ Priority screen_pri_name_to_pri(char *pri_name); char *screen_pri_to_pri_name(Priority pri); #endif +#endif diff --git a/server/screenlist.c b/server/screenlist.c index 9c5d6e9..e9d45d9 100644 --- a/server/screenlist.c +++ b/server/screenlist.c @@ -18,8 +18,10 @@ #include "shared/LL.h" #include "shared/sockets.h" #include "shared/report.h" -#include "screenlist.h" + +#include "client.h" #include "screen.h" +#include "screenlist.h" #include "main.h" /* for timer */ diff --git a/server/screenlist.h b/server/screenlist.h index c02965d..00dfee7 100644 --- a/server/screenlist.h +++ b/server/screenlist.h @@ -13,7 +13,13 @@ #ifndef SCREENLIST_H #define SCREENLIST_H -#include "screen.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#ifdef HAVE_STDBOOL_H +# include +#endif +#include "shared/defines.h" #define AUTOROTATE_OFF 0 #define AUTOROTATE_ON 1 diff --git a/server/sock.c b/server/sock.c index 6871c9b..590de75 100644 --- a/server/sock.c +++ b/server/sock.c @@ -37,15 +37,13 @@ #include #include -#include "sock.h" -#include "client.h" -#include "clients.h" -#include "screen.h" #include "shared/report.h" -#include "screenlist.h" #include "shared/sring.h" #include "shared/defines.h" +#include "clients.h" +#include "sock.h" + /****************************************************************************/ static fd_set active_fd_set, read_fd_set; diff --git a/server/sock.h b/server/sock.h index 5d8f993..1e2b740 100644 --- a/server/sock.h +++ b/server/sock.h @@ -16,8 +16,9 @@ #define SOCK_H #include "shared/sockets.h" - +#define INC_TYPES_ONLY 1 #include "client.h" +#undef INC_TYPES_ONLY /* Server functions...*/ int sock_init(char* bind_addr, int bind_port); diff --git a/server/widget.h b/server/widget.h index 7a0a9b8..df2c278 100644 --- a/server/widget.h +++ b/server/widget.h @@ -10,13 +10,12 @@ * Copyright (c) 1999, William Ferrell, Selene Scriven */ -#include "screen.h" -/* These headers are placed here on purpose ! (circular references) */ - #ifndef WIDGET_H #define WIDGET_H -struct Widget; +#define INC_TYPES_ONLY 1 +#include "screen.h" +#undef INC_TYPES_ONLY /* These correspond to the index into the "types" array...*/ typedef enum WidgetType { diff --git a/shared/defines.h b/shared/defines.h index c56af9e..cd64d2e 100644 --- a/shared/defines.h +++ b/shared/defines.h @@ -20,4 +20,11 @@ # define max(a,b) (((a) > (b)) ? (a) : (b)) #endif +/* Our own way of saying yes/no */ +#ifndef bool +# define bool short +# define true 1 +# define false 0 +#endif + #endif