* coding style harmonization in servers/

- explicitely declare void arguments
  - make a few string args const
* better support for shorter displays in server screen
* make target to create top level tag file
This commit is contained in:
marschap
2007-04-02 21:29:53 +00:00
parent a63ae89eb7
commit 6a1511bb72
100 changed files with 2180 additions and 2170 deletions
+142 -142
View File
@@ -41,202 +41,202 @@
typedef struct driver_symbols {
char *name;
const char *name;
short offset; /* offset in Driver structure */
short required;
} DriverSymbols;
DriverSymbols driver_symbols[] = {
{ "api_version", offsetof(Driver, api_version), 1 },
{ "api_version", offsetof(Driver, api_version), 1 },
{ "stay_in_foreground", offsetof(Driver, stay_in_foreground), 1 },
{ "supports_multiple", offsetof(Driver, supports_multiple), 1 },
{ "symbol_prefix", offsetof(Driver, symbol_prefix), 1 },
{ "init", offsetof(Driver, init), 1 },
{ "close", offsetof(Driver, close), 1 },
{ "width", offsetof(Driver, width), 0 },
{ "height", offsetof(Driver, height), 0 },
{ "clear", offsetof(Driver, clear), 0 },
{ "flush", offsetof(Driver, flush), 0 },
{ "string", offsetof(Driver, string), 0 },
{ "chr", offsetof(Driver, chr), 0 },
{ "vbar", offsetof(Driver, vbar), 0 },
{ "hbar", offsetof(Driver, hbar), 0 },
{ "num", offsetof(Driver, num), 0 },
{ "heartbeat", offsetof(Driver, heartbeat), 0 },
{ "icon", offsetof(Driver, icon), 0 },
{ "cursor", offsetof(Driver, cursor), 0 },
{ "set_char", offsetof(Driver, set_char), 0 },
{ "get_free_chars", offsetof(Driver, get_free_chars), 0 },
{ "cellwidth", offsetof(Driver, cellwidth), 0 },
{ "cellheight", offsetof(Driver, cellheight), 0 },
{ "get_contrast", offsetof(Driver, get_contrast), 0 },
{ "set_contrast", offsetof(Driver, set_contrast), 0 },
{ "get_brightness", offsetof(Driver, get_brightness), 0 },
{ "set_brightness", offsetof(Driver, set_brightness), 0 },
{ "backlight", offsetof(Driver, backlight), 0 },
{ "output", offsetof(Driver, output), 0 },
{ "get_key", offsetof(Driver, get_key), 0 },
{ "get_info", offsetof(Driver, get_info), 0 },
{ "supports_multiple", offsetof(Driver, supports_multiple), 1 },
{ "symbol_prefix", offsetof(Driver, symbol_prefix), 1 },
{ "init", offsetof(Driver, init), 1 },
{ "close", offsetof(Driver, close), 1 },
{ "width", offsetof(Driver, width), 0 },
{ "height", offsetof(Driver, height), 0 },
{ "clear", offsetof(Driver, clear), 0 },
{ "flush", offsetof(Driver, flush), 0 },
{ "string", offsetof(Driver, string), 0 },
{ "chr", offsetof(Driver, chr), 0 },
{ "vbar", offsetof(Driver, vbar), 0 },
{ "hbar", offsetof(Driver, hbar), 0 },
{ "num", offsetof(Driver, num), 0 },
{ "heartbeat", offsetof(Driver, heartbeat), 0 },
{ "icon", offsetof(Driver, icon), 0 },
{ "cursor", offsetof(Driver, cursor), 0 },
{ "set_char", offsetof(Driver, set_char), 0 },
{ "get_free_chars", offsetof(Driver, get_free_chars), 0 },
{ "cellwidth", offsetof(Driver, cellwidth), 0 },
{ "cellheight", offsetof(Driver, cellheight), 0 },
{ "get_contrast", offsetof(Driver, get_contrast), 0 },
{ "set_contrast", offsetof(Driver, set_contrast), 0 },
{ "get_brightness", offsetof(Driver, get_brightness), 0 },
{ "set_brightness", offsetof(Driver, set_brightness), 0 },
{ "backlight", offsetof(Driver, backlight), 0 },
{ "output", offsetof(Driver, output), 0 },
{ "get_key", offsetof(Driver, get_key), 0 },
{ "get_info", offsetof(Driver, get_info), 0 },
{ NULL, 0, 0 }
};
/* Functions for the driver */
static int request_display_width();
static int request_display_height();
static int driver_store_private_ptr(Driver * driver, void * private_data);
static int request_display_width(void);
static int request_display_height(void);
static int driver_store_private_ptr(Driver *driver, void *private_data);
Driver *
driver_load( char * name, char * filename )
driver_load(const char *name, const char *filename)
{
Driver * driver = NULL;
Driver *driver = NULL;
int res;
report( RPT_DEBUG, "%s( name=\"%.40s\", filename=\"%.80s\")", __FUNCTION__, name, filename );
report(RPT_DEBUG, "%s(name=\"%.40s\", filename=\"%.80s\")", __FUNCTION__, name, filename);
/* Allocate memory for new driver struct */
driver = malloc( sizeof( Driver ));
memset( driver, 0, sizeof (Driver));
driver = malloc(sizeof(Driver));
memset(driver, 0, sizeof(Driver));
/* And store its name and filename */
driver->name = malloc( strlen( name ) + 1 );
strcpy( driver->name, name );
driver->filename = malloc( strlen( filename ) + 1 );
strcpy( driver->filename, filename );
driver->name = malloc(strlen(name) + 1);
strcpy(driver->name, name);
driver->filename = malloc(strlen(filename) + 1);
strcpy(driver->filename, filename);
/* Load and bind the driver module and locate the symbols */
if( driver_bind_module( driver ) < 0 ) {
report( RPT_ERR, "Driver [%.40s] binding failed", name );
free( driver->name );
free( driver->filename );
free( driver );
if (driver_bind_module(driver) < 0) {
report(RPT_ERR, "Driver [%.40s] binding failed", name);
free(driver->name);
free(driver->filename);
free(driver);
return NULL;
}
/* Check module version */
if( strcmp( *(driver->api_version), API_VERSION ) != 0 ) {
report( RPT_ERR, "Driver [%.40s] is of an incompatible version", name );
driver_unbind_module( driver );
free( driver->name );
free( driver->filename );
free( driver );
if (strcmp(*(driver->api_version), API_VERSION) != 0) {
report(RPT_ERR, "Driver [%.40s] is of an incompatible version", name);
driver_unbind_module(driver);
free(driver->name);
free(driver->filename);
free(driver);
return NULL;
}
/* Call the init function */
debug( RPT_DEBUG, "%s: Calling driver [%.40s] init function", __FUNCTION__, driver->name );
res = driver->init( driver );
if( res < 0 ) {
report( RPT_ERR, "Driver [%.40s] init failed, return code < 0", driver->name );
debug(RPT_DEBUG, "%s: Calling driver [%.40s] init function", __FUNCTION__, driver->name);
res = driver->init(driver);
if (res < 0) {
report(RPT_ERR, "Driver [%.40s] init failed, return code < 0", driver->name);
/* Driver load failed, driver should not be added to list
* Free driver structure again
*/
driver_unbind_module( driver );
free( driver->name );
free( driver->filename );
free( driver );
driver_unbind_module(driver);
free(driver->name);
free(driver->filename);
free(driver);
return NULL;
}
debug( RPT_NOTICE, "Driver [%.40s] loaded", driver->name );
debug(RPT_NOTICE, "Driver [%.40s] loaded", driver->name);
return driver;
}
int
driver_unload( Driver * driver )
driver_unload(Driver *driver)
{
debug( RPT_NOTICE, "Closing driver [%.40s]", driver->name );
if( driver->close )
driver->close (driver);
debug(RPT_NOTICE, "Closing driver [%.40s]", driver->name);
if (driver->close)
driver->close(driver);
/* Unlaod the module */
driver_unbind_module( driver );
driver_unbind_module(driver);
/* Free its data */
free( driver->filename );
free( driver->name );
free( driver );
debug( RPT_DEBUG, "%s: Driver unloaded", __FUNCTION__ );
free(driver->filename);
free(driver->name);
free(driver);
debug(RPT_DEBUG, "%s: Driver unloaded", __FUNCTION__);
return 0;
}
int
driver_bind_module( Driver * driver )
driver_bind_module(Driver *driver)
{
int i;
int missing_symbols = 0;
debug( RPT_DEBUG, "%s( driver=[%.40s] )", __FUNCTION__, driver->name );
debug(RPT_DEBUG, "%s(driver=[%.40s])", __FUNCTION__, driver->name);
/* Load the module */
#ifndef WIN32
driver->module_handle = dlopen( driver->filename, RTLD_NOW );
driver->module_handle = dlopen(driver->filename, RTLD_NOW);
#else
driver->module_handle = LoadLibraryEx( (driver->filename), NULL, 0 );
driver->module_handle = LoadLibraryEx((driver->filename), NULL, 0);
#endif
if( driver->module_handle == NULL ) {
if (driver->module_handle == NULL) {
#ifndef WIN32
report( RPT_ERR, "Could not open driver module %.40s: %s", driver->filename, dlerror() );
report(RPT_ERR, "Could not open driver module %.40s: %s", driver->filename, dlerror());
#else
/* REVISIT: replace dlerror() */
report( RPT_ERR, "Could not open driver module %.40s.", driver->filename );
report(RPT_ERR, "Could not open driver module %.40s.", driver->filename);
#endif
return -1;
}
/* And locate the symbols */
for( i=0; driver_symbols[i].name; i++ ) {
for (i = 0; driver_symbols[i].name; i++) {
void (**p)();
p = (void(**)() ) ((size_t)driver + (driver_symbols[i].offset));
p = (void(**)()) ((size_t)driver + (driver_symbols[i].offset));
*p = NULL;
/* Add the symbol_prefix */
if( driver->symbol_prefix ) {
char *s = malloc( strlen( *(driver->symbol_prefix) ) + strlen( driver_symbols[i].name ) + 1 );
strcpy( s, *(driver->symbol_prefix) ) ;
strcat( s, driver_symbols[i].name );
debug( RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, s );
if (driver->symbol_prefix) {
char *s = malloc(strlen(*(driver->symbol_prefix)) + strlen(driver_symbols[i].name) + 1);
strcpy(s, *(driver->symbol_prefix));
strcat(s, driver_symbols[i].name);
debug(RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, s);
#ifndef WIN32
*p = dlsym( driver->module_handle, s );
*p = dlsym(driver->module_handle, s);
#else
*p = (void(*)()) (GetProcAddress( driver->module_handle, s ));
*p = (void(*)()) (GetProcAddress(driver->module_handle, s));
#endif
free( s );
free(s);
}
/* Retrieve the symbol */
if( !*p ) {
debug( RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, driver_symbols[i].name );
if (!*p) {
debug(RPT_DEBUG, "%s: finding symbol: %s", __FUNCTION__, driver_symbols[i].name);
#ifndef WIN32
*p = dlsym( driver->module_handle, driver_symbols[i].name );
*p = dlsym(driver->module_handle, driver_symbols[i].name);
#else
*p = (void(*)()) (GetProcAddress( driver->module_handle, driver_symbols[i].name ));
*p = (void(*)()) (GetProcAddress(driver->module_handle, driver_symbols[i].name));
#endif
}
if( *p ) {
debug( RPT_DEBUG, "%s: found symbol at: %p", __FUNCTION__, *p );
if (*p) {
debug(RPT_DEBUG, "%s: found symbol at: %p", __FUNCTION__, *p);
}
/* Was the symbol required but not found ? */
if( !*p && driver_symbols[i].required ) {
report( RPT_ERR, "Driver [%.40s] does not have required symbol: %s", driver->name, driver_symbols[i].name );
if (!*p && driver_symbols[i].required) {
report(RPT_ERR, "Driver [%.40s] does not have required symbol: %s", driver->name, driver_symbols[i].name);
missing_symbols = 1;
}
}
/* If errors, leave now while we can :) */
if( missing_symbols ) {
report( RPT_ERR, "Driver [%.40s] does not have all obligatory symbols", driver->name );
if (missing_symbols) {
report(RPT_ERR, "Driver [%.40s] does not have all obligatory symbols", driver->name);
#ifndef WIN32
dlclose( driver->module_handle );
dlclose(driver->module_handle);
#else
FreeLibrary( driver->module_handle );
FreeLibrary(driver->module_handle);
#endif
return -1;
}
@@ -267,14 +267,14 @@ driver_bind_module( Driver * driver )
int
driver_unbind_module( Driver * driver )
driver_unbind_module(Driver *driver)
{
debug( RPT_DEBUG, "%s( driver=[%.40s] )", __FUNCTION__, driver->name );
debug(RPT_DEBUG, "%s(driver=[%.40s])", __FUNCTION__, driver->name);
#ifndef WIN32
dlclose( driver->module_handle );
dlclose(driver->module_handle);
#else
FreeLibrary( driver->module_handle );
FreeLibrary(driver->module_handle);
#endif
return 0;
@@ -282,7 +282,7 @@ driver_unbind_module( Driver * driver )
bool
driver_does_output( Driver * driver )
driver_does_output(Driver *driver)
{
return (driver->width != NULL
|| driver->height != NULL
@@ -293,30 +293,30 @@ driver_does_output( Driver * driver )
bool
driver_does_input( Driver * driver )
driver_does_input(Driver *driver)
{
return (driver->get_key != NULL) ? 1 : 0;
}
bool
driver_stay_in_foreground( Driver * driver )
driver_stay_in_foreground(Driver *driver)
{
return *driver->stay_in_foreground;
}
bool
driver_supports_multiple( Driver * driver )
driver_supports_multiple(Driver *driver)
{
return *driver->supports_multiple;
}
static int
driver_store_private_ptr(Driver * driver, void * private_data)
driver_store_private_ptr(Driver *driver, void *private_data)
{
debug( RPT_DEBUG, "%s( driver=[%.40s], ptr=%p )", __FUNCTION__, driver->name, private_data );
debug(RPT_DEBUG, "%s(driver=[%.40s], ptr=%p)", __FUNCTION__, driver->name, private_data);
driver->private_data = private_data;
return 0;
@@ -324,33 +324,33 @@ driver_store_private_ptr(Driver * driver, void * private_data)
static int
request_display_width()
request_display_width(void)
{
if( !display_props )
if (!display_props)
return 0;
return display_props->width;
}
static int
request_display_height()
request_display_height(void)
{
if( !display_props )
if (!display_props)
return 0;
return display_props->height;
}
void
driver_alt_vbar( Driver * drv, int x, int y, int len, int promille, int pattern )
driver_alt_vbar(Driver *drv, int x, int y, int len, int promille, int pattern)
{
int pos;
debug (RPT_DEBUG, "%s( drv=[%.40s], x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, drv->name, x, y, len, promille, pattern);
debug(RPT_DEBUG, "%s(drv=[%.40s], x=%d, y=%d, len=%d, promille=%d, pattern=%d)", __FUNCTION__, drv->name, x, y, len, promille, pattern);
if (!drv->chr)
return;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
drv->chr (drv, x, y-pos, '|');
for (pos = 0; pos < len; pos++) {
if (2 * pos < ((long) promille * len / 500 + 1)) {
drv->chr(drv, x, y-pos, '|');
} else {
; /* print nothing */
}
@@ -358,18 +358,18 @@ driver_alt_vbar( Driver * drv, int x, int y, int len, int promille, int pattern
}
void
driver_alt_hbar( Driver * drv, int x, int y, int len, int promille, int pattern )
driver_alt_hbar(Driver *drv, int x, int y, int len, int promille, int pattern)
{
int pos;
debug (RPT_DEBUG, "%s( drv=[%.40s], x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, drv->name, x, y, len, promille, pattern);
debug(RPT_DEBUG, "%s(drv=[%.40s], x=%d, y=%d, len=%d, promille=%d, pattern=%d)", __FUNCTION__, drv->name, x, y, len, promille, pattern);
if (!drv->chr)
return;
for ( pos=0; pos<len; pos++ ) {
if( 2 * pos < ((long) promille * len / 500 + 1) ) {
drv->chr (drv, x+pos, y, '-');
for (pos = 0; pos < len; pos++) {
if (2 * pos < ((long) promille * len / 500 + 1)) {
drv->chr(drv, x+pos, y, '-');
} else {
; /* print nothing */
}
@@ -377,7 +377,7 @@ driver_alt_hbar( Driver * drv, int x, int y, int len, int promille, int pattern
}
void
driver_alt_num( Driver * drv, int x, int num )
driver_alt_num(Driver *drv, int x, int num)
{
/* Ugly code extracted by David GLAUDE from lcdm001.c ;)*/
/* Moved to driver.c by Joris Robijn */
@@ -443,7 +443,7 @@ driver_alt_num( Driver * drv, int x, int num )
int y, dx;
debug (RPT_DEBUG, "%s( drv=[%.40s], x=%d, num=%d )", __FUNCTION__, drv->name, x, num);
debug(RPT_DEBUG, "%s(drv=[%.40s], x=%d, num=%d)", __FUNCTION__, drv->name, x, num);
if ((num < 0) || (num > 10))
return;
@@ -452,15 +452,15 @@ driver_alt_num( Driver * drv, int x, int num )
for (y = 0; y < 4; y++)
for (dx = 0; num_map[num][y][dx] != '\0'; dx++)
drv->chr (drv, x + dx, y+1, num_map[num][y][dx]);
drv->chr(drv, x + dx, y+1, num_map[num][y][dx]);
}
void
driver_alt_heartbeat( Driver * drv, int state )
driver_alt_heartbeat(Driver *drv, int state)
{
int icon;
debug (RPT_DEBUG, "%s( drv=[%.40s], state=%d )", __FUNCTION__, drv->name, state);
debug(RPT_DEBUG, "%s(drv=[%.40s], state=%d)", __FUNCTION__, drv->name, state);
if (state == HEARTBEAT_OFF)
return;
@@ -475,18 +475,18 @@ driver_alt_heartbeat( Driver * drv, int state )
icon = (timer & 5) ? ICON_HEART_FILLED : ICON_HEART_OPEN;
if (drv->icon)
drv->icon( drv, drv->width(drv), 1, icon);
drv->icon(drv, drv->width(drv), 1, icon);
else
driver_alt_icon( drv, drv->width(drv), 1, icon);
driver_alt_icon(drv, drv->width(drv), 1, icon);
}
void
driver_alt_icon( Driver * drv, int x, int y, int icon )
driver_alt_icon(Driver *drv, int x, int y, int icon)
{
char ch1 = '?';
char ch2 = 0;
char ch2 = '\0';
debug (RPT_DEBUG, "%s( drv=[%.40s], x=%d, y=%d, icon=ICON_%s )", __FUNCTION__, drv->name, x, y, widget_icon_to_iconname (icon) );
debug(RPT_DEBUG, "%s(drv=[%.40s], x=%d, y=%d, icon=ICON_%s)", __FUNCTION__, drv->name, x, y, widget_icon_to_iconname(icon));
if (!drv->chr)
return;
@@ -515,31 +515,31 @@ driver_alt_icon( Driver * drv, int x, int y, int icon )
case ICON_PREV: ch1 = '|'; ch2 = '<'; break;
case ICON_REC: ch1 = '('; ch2 = ')'; break;
}
drv->chr( drv, x, y, ch1);
drv->chr(drv, x, y, ch1);
if (ch2)
drv->chr( drv, x+1, y, ch2);
drv->chr(drv, x+1, y, ch2);
}
void driver_alt_cursor( Driver * drv, int x, int y, int state )
void driver_alt_cursor(Driver *drv, int x, int y, int state)
{
/* Same question about timer in this function... */
debug (RPT_DEBUG, "%s( drv=[%.40s], x=%d, y=%d, state=%d )", __FUNCTION__, drv->name, x, y, state);
debug(RPT_DEBUG, "%s(drv=[%.40s], x=%d, y=%d, state=%d)", __FUNCTION__, drv->name, x, y, state);
switch( state ) {
switch (state) {
case CURSOR_BLOCK:
case CURSOR_DEFAULT_ON:
if (timer & 2 && drv->chr) {
if (drv->icon) {
drv->icon( drv, x, y, ICON_BLOCK_FILLED);
drv->icon(drv, x, y, ICON_BLOCK_FILLED);
} else {
driver_alt_icon( drv, x, y, ICON_BLOCK_FILLED );
driver_alt_icon(drv, x, y, ICON_BLOCK_FILLED);
}
}
break;
case CURSOR_UNDER:
if (timer & 2 && drv->chr) {
drv->chr( drv, x, y, '_');
drv->chr(drv, x, y, '_');
}
break;
}