explicitely declare void function argg and static functions

This commit is contained in:
marschap
2007-04-11 11:48:01 +00:00
parent 25c18aa3df
commit 23f9b667f7
6 changed files with 94 additions and 79 deletions
+58 -20
View File
@@ -13,7 +13,7 @@
#include "shared/str.h" #include "shared/str.h"
#include "shared/sockets.h" #include "shared/sockets.h"
char * address = UNSET_STR; char *address = UNSET_STR;
int port = UNSET_INT; int port = UNSET_INT;
short autoscroll = 1; short autoscroll = 1;
@@ -22,16 +22,18 @@ short listening = 0;
short scroll_x = 0, scroll_y = 0; short scroll_x = 0, scroll_y = 0;
short lcd_cursor_x, lcd_cursor_y; short lcd_cursor_x, lcd_cursor_y;
short lcd_width = 0, lcd_height = 0; short lcd_width = 0, lcd_height = 0;
char * lcd_buf = NULL; char *lcd_buf = NULL;
short last_vc_cursor_y = 0; short last_vc_cursor_y = 0;
short last_vc_cursor_x = 0; short last_vc_cursor_x = 0;
short last_lcd_cursor_x = 0; short last_lcd_cursor_x = 0;
short last_lcd_cursor_y = 0; short last_lcd_cursor_y = 0;
int read_connect_string(); static int read_connect_string(void);
static int split(char *str, char delim, char *parts[], int maxparts);
int connect_and_setup()
int connect_and_setup(void)
{ {
char buf[200]; char buf[200];
int i; int i;
@@ -80,12 +82,13 @@ int connect_and_setup()
return 0; return 0;
} }
int read_connect_string()
static int read_connect_string(void)
{ {
char buf[8192]; char buf[8192];
int len = 0; int len = 0;
int a; int a;
char * argv[20]; char *argv[20];
int argc; int argc;
short received = 0; short received = 0;
short timeout = 50; /* Give the server 5 secs to respond */ short timeout = 50; /* Give the server 5 secs to respond */
@@ -110,10 +113,10 @@ int read_connect_string()
argc = split(buf, ' ', argv, 20); argc = split(buf, ' ', argv, 20);
for (a = 1; a < argc; a++) { for (a = 1; a < argc; a++) {
if (0 == strcmp (argv[a], "wid")) if (0 == strcmp(argv[a], "wid"))
lcd_width = atoi (argv[++a]); lcd_width = atoi(argv[++a]);
else if (0 == strcmp (argv[a], "hgt")) else if (0 == strcmp(argv[a], "hgt"))
lcd_height = atoi (argv[++a]); lcd_height = atoi(argv[++a]);
} }
if (argc <= 0 || strcmp(argv[0], "connect") != 0 if (argc <= 0 || strcmp(argv[0], "connect") != 0
|| lcd_width == 0 || lcd_width == 0) { || lcd_width == 0 || lcd_width == 0) {
@@ -123,18 +126,51 @@ int read_connect_string()
return 0; return 0;
} }
int read_response(char * buf, int maxsize)
static int split(char *str, char delim, char *parts[], int maxparts)
/* Splits a string into parts, to which pointers will be returned in &parts.
* The return value is the number of parts.
* maxparts is the maximum number of parts returned. If more parts exist
* they are (unsplit) in the last part.
* The parts are split at the character delim.
* No new space will be allocated, the string str will be mutated !
*/
{
char *p1 = str;
char *p2;
int part_nr = 0;
/* Find the delim char to end the current part */
while (part_nr < maxparts - 1 && (p2 = strchr(p1, delim))) {
/* subsequent parts... */
*p2 = 0;
parts[part_nr] = p1;
p1 = p2 + 1; /* Just after the delim char */
part_nr ++;
}
/* and the last part... */
parts[part_nr] = p1;
part_nr ++;
return part_nr;
}
int read_response(char *buf, int maxsize)
{ {
return sock_recv_string(sock, buf, maxsize); return sock_recv_string(sock, buf, maxsize);
} }
int process_response(char * str)
int process_response(char *str)
{ {
char *argv[10]; char *argv[10];
int argc; int argc;
//int i; //int i;
//char * p; //char *p;
char * str2 = strdup(str); /* get_args modifies str2 */ char *str2 = strdup(str); /* get_args modifies str2 */
report(RPT_DEBUG, "Server said: \"%s\"", str); report(RPT_DEBUG, "Server said: \"%s\"", str);
@@ -205,13 +241,14 @@ int process_response(char * str)
} }
int update_display()
int update_display(void)
{ {
//int bytes_read; //int bytes_read;
short line; short line;
int e = 0; int e = 0;
char buf[80]; char buf[80];
char * str_buf; char *str_buf;
short num_lines; short num_lines;
num_lines = min(lcd_height, vc_height); num_lines = min(lcd_height, vc_height);
@@ -261,8 +298,8 @@ int update_display()
str_buf = malloc(80 + 2 * lcd_width); str_buf = malloc(80 + 2 * lcd_width);
for (line = 0; line < num_lines; line++) { for (line = 0; line < num_lines; line++) {
char * vc_p; char *vc_p;
char * lcd_p; char *lcd_p;
short line_width; short line_width;
line_width = min(lcd_width, vc_width); line_width = min(lcd_width, vc_width);
@@ -274,7 +311,7 @@ int update_display()
/* Has the line data changed ? */ /* Has the line data changed ? */
if (memcmp(vc_p, lcd_p, line_width) != 0) { if (memcmp(vc_p, lcd_p, line_width) != 0) {
/* Yes, so send it */ /* Yes, so send it */
char * a; char *a;
short pos; short pos;
/* Format/escape the data */ /* Format/escape the data */
@@ -311,7 +348,8 @@ int update_display()
return 0; return 0;
} }
int send_nop()
int send_nop(void)
{ {
return sock_send_string(sock, "\n"); return sock_send_string(sock, "\n");
} }
+6 -6
View File
@@ -1,13 +1,13 @@
#ifndef LCD_LINK_H #ifndef LCD_LINK_H
#define LCD_LINK_H #define LCD_LINK_H
extern char * address; extern char *address;
extern int port; extern int port;
int connect_and_setup(); int connect_and_setup(void);
int read_response( char * str, int maxsize ); int read_response(char *str, int maxsize);
int process_response( char * str ); int process_response(char *str);
int update_display(); int update_display(void);
int send_nop(); int send_nop(void);
#endif #endif
+11 -40
View File
@@ -34,7 +34,7 @@
#define DEFAULT_CONFIGFILE SYSCONFDIR "/lcdvc.conf" #define DEFAULT_CONFIGFILE SYSCONFDIR "/lcdvc.conf"
char * help_text = char *help_text =
"lcdvc - LCDproc virtual console\n" "lcdvc - LCDproc virtual console\n"
"\n" "\n"
"Copyright (c) 2002, Joris Robijn, 2006 Peter Marschall.\n" "Copyright (c) 2002, Joris Robijn, 2006 Peter Marschall.\n"
@@ -62,14 +62,12 @@ char *vcs_device = UNSET_STR;
char *keys[4]; char *keys[4];
/* Function prototypes */ /* Function prototypes */
int process_command_line(int argc, char ** argv); static int process_command_line(int argc, char **argv);
int process_configfile(char * configfile); static int process_configfile(char *configfile);
int connect_and_setup(); static int main_loop(void);
int update_display();
int process_response(char * str);
int main_loop();
int main( int argc, char ** argv )
int main(int argc, char **argv)
{ {
int e = 0; int e = 0;
@@ -99,7 +97,8 @@ int main( int argc, char ** argv )
return 0; return 0;
} }
int process_command_line( int argc, char ** argv )
static int process_command_line(int argc, char **argv)
{ {
int c; int c;
int error = 0; int error = 0;
@@ -166,7 +165,8 @@ int process_command_line( int argc, char ** argv )
return error; return error;
} }
int process_configfile( char * configfile )
static int process_configfile(char *configfile)
{ {
if (strcmp(configfile, UNSET_STR) == 0) { if (strcmp(configfile, UNSET_STR) == 0) {
configfile = DEFAULT_CONFIGFILE; configfile = DEFAULT_CONFIGFILE;
@@ -205,37 +205,8 @@ int process_configfile( char * configfile )
return 0; return 0;
} }
int split( char * str, char delim, char * parts[], int maxparts )
/* Splits a string into parts, to which pointers will be returned in &parts.
* The return value is the number of parts.
* maxparts is the maximum number of parts returned. If more parts exist
* they are (unsplit) in the last part.
* The parts are split at the character delim.
* No new space will be allocated, the string str will be mutated !
*/
{
char * p1 = str;
char * p2;
int part_nr = 0;
/* Find the delim char to end the current part */ static int main_loop(void)
while (part_nr < maxparts - 1 && (p2 = strchr(p1, delim))) {
/* subsequent parts... */
*p2 = 0;
parts[part_nr] = p1;
p1 = p2 + 1; /* Just after the delim char */
part_nr ++;
}
/* and the last part... */
parts[part_nr] = p1;
part_nr ++;
return part_nr;
}
int main_loop()
{ {
int num_bytes; int num_bytes;
char buf[80]; char buf[80];
-2
View File
@@ -23,6 +23,4 @@ extern char *keys[4];
extern char *progname; extern char *progname;
int split(char * str, char delim, char * parts[], int maxparts);
#endif #endif
+16 -8
View File
@@ -14,9 +14,10 @@
int vcs0, vcsa; int vcs0, vcsa;
unsigned short vc_width = 0, vc_height = 0; unsigned short vc_width = 0, vc_height = 0;
unsigned short vc_cursor_x = 0, vc_cursor_y = 0; unsigned short vc_cursor_x = 0, vc_cursor_y = 0;
char * vc_buf = NULL; char *vc_buf = NULL;
int open_vcs()
int open_vcs(void)
{ {
/* Open the /dev/vcsX and /dev/vcsaX devices */ /* Open the /dev/vcsX and /dev/vcsaX devices */
vcs0 = open(vcs_device, O_RDONLY); vcs0 = open(vcs_device, O_RDONLY);
@@ -32,7 +33,8 @@ int open_vcs()
return 0; return 0;
} }
int read_vcdata()
int read_vcdata(void)
{ {
unsigned short new_vc_height; unsigned short new_vc_height;
unsigned short new_vc_width; unsigned short new_vc_width;
@@ -53,13 +55,19 @@ int read_vcdata()
vc_cursor_y = buf[3]; vc_cursor_y = buf[3];
/* Screen resize or initial buffer allocation ? */ /* Screen resize or initial buffer allocation ? */
if (new_vc_width != vc_width || new_vc_height != vc_height) { if ((new_vc_width != vc_width) || (new_vc_height != vc_height)) {
vc_width = new_vc_width; vc_width = new_vc_width;
vc_height = new_vc_height; vc_height = new_vc_height;
if (vc_buf)
free(vc_buf); if (vc_width * vc_height > 0) {
vc_buf = malloc(vc_width * vc_height); vc_buf = realloc(vc_buf, vc_width * vc_height);
memset(vc_buf, ' ', vc_width * vc_height);
if (vc_buf == NULL) {
report(RPT_ERR, "malloc failure: %s", strerror(errno));
return -1;
}
memset(vc_buf, ' ', vc_width * vc_height);
}
} }
/* Read characters from /dev/cvs0 */ /* Read characters from /dev/cvs0 */
+3 -3
View File
@@ -3,9 +3,9 @@
extern unsigned short vc_width, vc_height; extern unsigned short vc_width, vc_height;
extern unsigned short vc_cursor_x, vc_cursor_y; extern unsigned short vc_cursor_x, vc_cursor_y;
extern char * vc_buf; extern char *vc_buf;
int open_vcs(); int open_vcs(void);
int read_vcdata(); int read_vcdata(void);
#endif #endif