From 07f3df45beb9faf8acbdf7a32100bc31ed651208 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 12 Apr 2011 14:12:09 +0200 Subject: [PATCH] Converted scope-local variables into function-local variables. The 6502-specific LC implementation doesn't allow for scope-local vaiables between PT_BEGIN/PROCESS_BEGIN/PSOCK_BEGIN and PT_BEGIN/PROCESS_END/PSOCK_END. --- apps/rest-http/http-server.c | 23 ++++++++++++++++------- apps/shell/shell-base64.c | 8 ++++---- apps/shell/shell-file.c | 13 ++++++------- apps/shell/shell-ping.c | 6 ++---- apps/shell/shell-rsh.c | 5 +++-- apps/shell/shell-sendtest.c | 2 +- apps/shell/shell-text.c | 15 +++++++-------- apps/shell/shell-time.c | 8 ++++---- apps/shell/shell-vars.c | 4 ++-- apps/shell/shell.c | 6 +++--- core/net/dhcpc.c | 4 ++-- 11 files changed, 50 insertions(+), 44 deletions(-) diff --git a/apps/rest-http/http-server.c b/apps/rest-http/http-server.c index 6a361b182..34aa0b59f 100644 --- a/apps/rest-http/http-server.c +++ b/apps/rest-http/http-server.c @@ -392,10 +392,12 @@ content_type_t http_get_header_content_type(http_request_t* request) static PT_THREAD(handle_request(connection_state_t* conn_state)) { + static int error; + const char* content_len; + PSOCK_BEGIN(&(conn_state->sin)); - static int error; - const char* content_len = NULL; + content_len = NULL; error = HTTP_NO_ERROR; /*always reinit static variables due to protothreads*/ @@ -512,14 +514,19 @@ PT_THREAD(handle_request(connection_state_t* conn_state)) static PT_THREAD(send_data(connection_state_t* conn_state)) { + uint16_t index; + http_response_t* response; + http_header_t* header; + uint8_t* buffer; + PSOCK_BEGIN(&(conn_state->sout)); PRINTF("send_data -> \n"); - uint16_t index = 0; - http_response_t* response = &conn_state->response; - http_header_t* header = response->headers; - uint8_t* buffer = allocate_buffer(200); + index = 0; + response = &conn_state->response; + header = response->headers; + buffer = allocate_buffer(200); /*FIXME: what is the best solution here to send the data. Right now, if buffer is not allocated, no data is sent!*/ if (buffer) { @@ -583,6 +590,8 @@ PROCESS(http_server, "Httpd Process"); PROCESS_THREAD(http_server, ev, data) { + connection_state_t *conn_state; + PROCESS_BEGIN(); /* if static routes are used rather than RPL */ @@ -603,7 +612,7 @@ PROCESS_THREAD(http_server, ev, data) while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); - connection_state_t *conn_state = (connection_state_t *)data; + conn_state = (connection_state_t *)data; if(uip_connected()) { PRINTF("##Connected##\n"); diff --git a/apps/shell/shell-base64.c b/apps/shell/shell-base64.c index 39298f041..91d280161 100644 --- a/apps/shell/shell-base64.c +++ b/apps/shell/shell-base64.c @@ -117,13 +117,13 @@ base64_add_char(struct base64_decoder_state *s, char c) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_dec64_process, ev, data) { + struct shell_input *input; + struct base64_decoder_state s; + int i; + PROCESS_BEGIN(); while(1) { - struct shell_input *input; - struct base64_decoder_state s; - int i; - PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); input = data; diff --git a/apps/shell/shell-file.c b/apps/shell/shell-file.c index 2371b3fe9..d9e746c93 100644 --- a/apps/shell/shell-file.c +++ b/apps/shell/shell-file.c @@ -103,6 +103,7 @@ PROCESS_THREAD(shell_ls_process, ev, data) PROCESS_THREAD(shell_append_process, ev, data) { static int fd = 0; + struct shell_input *input; PROCESS_EXITHANDLER(cfs_close(fd)); @@ -115,7 +116,6 @@ PROCESS_THREAD(shell_append_process, ev, data) "append: could not open file for writing: ", data); } else { while(1) { - struct shell_input *input; PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); input = data; /* printf("cat input %d %d\n", input->len1, input->len2);*/ @@ -139,6 +139,7 @@ PROCESS_THREAD(shell_append_process, ev, data) PROCESS_THREAD(shell_write_process, ev, data) { static int fd = 0; + struct shell_input *input; int r; PROCESS_EXITHANDLER(cfs_close(fd)); @@ -152,7 +153,6 @@ PROCESS_THREAD(shell_write_process, ev, data) "write: could not open file for writing: ", data); } else { while(1) { - struct shell_input *input; PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); input = data; /* printf("cat input %d %d\n", input->len1, input->len2);*/ @@ -187,11 +187,14 @@ PROCESS_THREAD(shell_write_process, ev, data) PROCESS_THREAD(shell_read_process, ev, data) { static int fd = 0; + static int block_size = MAX_BLOCKSIZE; char *next; char filename[MAX_FILENAME_LEN]; int len; int offset = 0; - static int block_size = MAX_BLOCKSIZE; + char buf[MAX_BLOCKSIZE]; + struct shell_input *input; + PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_BEGIN(); @@ -236,10 +239,6 @@ PROCESS_THREAD(shell_read_process, ev, data) } else { while(1) { - char buf[MAX_BLOCKSIZE]; - int len; - struct shell_input *input; - len = cfs_read(fd, buf, block_size); if(len <= 0) { cfs_close(fd); diff --git a/apps/shell/shell-ping.c b/apps/shell/shell-ping.c index 5f8de1b80..4957a4fa7 100644 --- a/apps/shell/shell-ping.c +++ b/apps/shell/shell-ping.c @@ -133,8 +133,9 @@ send_ping(uip_ipaddr_t *dest_addr) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_ping_process, ev, data) { + static struct etimer e; struct shell_input *input; - + PROCESS_BEGIN(); if(data == NULL) { @@ -149,9 +150,6 @@ PROCESS_THREAD(shell_ping_process, ev, data) running = 1; while(running) { - static struct etimer e; - - etimer_set(&e, CLOCK_SECOND * 10); PROCESS_WAIT_EVENT(); diff --git a/apps/shell/shell-rsh.c b/apps/shell/shell-rsh.c index 946ec4145..95a13b83e 100644 --- a/apps/shell/shell-rsh.c +++ b/apps/shell/shell-rsh.c @@ -67,6 +67,7 @@ PROCESS(shell_rsh_server_process, "rsh server"); PROCESS_THREAD(shell_rsh_process, ev, data) { static rimeaddr_t receiver; + struct shell_input *input; const char *nextptr; char buf[40]; @@ -88,7 +89,6 @@ PROCESS_THREAD(shell_rsh_process, ev, data) meshconn_connect(&meshconn, &receiver); while(1) { - struct shell_input *input; PROCESS_WAIT_EVENT(); if(ev == shell_event_input) { input = data; @@ -114,6 +114,8 @@ PROCESS_THREAD(shell_rsh_process, ev, data) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_rsh_server_process, ev, data) { + struct shell_input *input; + PROCESS_BEGIN(); while(1) { @@ -123,7 +125,6 @@ PROCESS_THREAD(shell_rsh_server_process, ev, data) if(ev == PROCESS_EVENT_EXITED) { front_process = NULL; } else if(ev == shell_event_input) { - struct shell_input *input; input = data; packetbuf_clear(); memcpy(packetbuf_dataptr(), input->data1, input->len1); diff --git a/apps/shell/shell-sendtest.c b/apps/shell/shell-sendtest.c index ba83d71ec..2fa7213a0 100644 --- a/apps/shell/shell-sendtest.c +++ b/apps/shell/shell-sendtest.c @@ -117,10 +117,10 @@ print_usage(void) PROCESS_THREAD(shell_sendtest_process, ev, data) { static rimeaddr_t receiver; + static unsigned long cpu, lpm, rx, tx; const char *nextptr; const char *args; char buf[40]; - static unsigned long cpu, lpm, rx, tx; unsigned long cpu2, lpm2, rx2, tx2; PROCESS_BEGIN(); diff --git a/apps/shell/shell-text.c b/apps/shell/shell-text.c index 5bcd840b5..d80d3cb4e 100644 --- a/apps/shell/shell-text.c +++ b/apps/shell/shell-text.c @@ -131,6 +131,7 @@ PROCESS_THREAD(shell_binprint_process, ev, data) uint16_t *ptr; int i; char buf[2*64], *bufptr; + uint16_t val; PROCESS_BEGIN(); @@ -145,9 +146,8 @@ PROCESS_THREAD(shell_binprint_process, ev, data) bufptr = buf; ptr = (uint16_t *)input->data1; for(i = 0; i < input->len1 && i < input->len1 - 1; i += 2) { - uint16_t data; - memcpy(&data, ptr, sizeof(data)); - bufptr += sprintf(bufptr, "%u ", data); + memcpy(&val, ptr, sizeof(val)); + bufptr += sprintf(bufptr, "%u ", val); if(bufptr - buf >= sizeof(buf) - 6) { shell_output_str(&binprint_command, buf, ""); bufptr = buf; @@ -160,9 +160,8 @@ PROCESS_THREAD(shell_binprint_process, ev, data) ptr = (uint16_t *)input->data2; for(i = 0; i < input->len2 && i < input->len2 - 1; i += 2) { - uint16_t data; - memcpy(&data, ptr, sizeof(data)); - bufptr += sprintf(bufptr, "%u ", data); + memcpy(&val, ptr, sizeof(val)); + bufptr += sprintf(bufptr, "%u ", val); if(bufptr - buf >= sizeof(buf) - 6) { shell_output_str(&binprint_command, buf, ""); bufptr = buf; @@ -180,8 +179,9 @@ PROCESS_THREAD(shell_binprint_process, ev, data) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_size_process, ev, data) { - struct shell_input *input; static unsigned long size; + struct shell_input *input; + char buf[10]; PROCESS_BEGIN(); size = 0; @@ -193,7 +193,6 @@ PROCESS_THREAD(shell_size_process, ev, data) size += input->len1 + input->len2; if(input->len1 + input->len2 == 0) { - char buf[10]; snprintf(buf, sizeof(buf), "%lu", size); shell_output_str(&size_command, buf, ""); PROCESS_EXIT(); diff --git a/apps/shell/shell-time.c b/apps/shell/shell-time.c index 2e7ffad88..4999354cd 100644 --- a/apps/shell/shell-time.c +++ b/apps/shell/shell-time.c @@ -91,11 +91,11 @@ PROCESS_THREAD(shell_time_process, ev, data) uint16_t time[2]; } msg; unsigned long newtime; + const char *nextptr; PROCESS_BEGIN(); if(data != NULL) { - const char *nextptr; newtime = shell_strtolong(data, &nextptr); if(data != nextptr) { shell_set_time(newtime); @@ -122,6 +122,7 @@ PROCESS_THREAD(shell_time_process, ev, data) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_timestamp_process, ev, data) { + struct shell_input *input; struct msg { uint16_t len; uint16_t time[2]; @@ -132,7 +133,6 @@ PROCESS_THREAD(shell_timestamp_process, ev, data) PROCESS_BEGIN(); while(1) { - struct shell_input *input; PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); input = data; if(input->len1 + input->len2 == 0) { @@ -161,7 +161,9 @@ PROCESS_THREAD(shell_timestamp_process, ev, data) PROCESS_THREAD(shell_repeat_server_process, ev, data) { static char *command; + static struct process *started_process; char command_copy[MAX_COMMANDLENGTH]; + int ret; if(ev == shell_event_input) { goto exit; @@ -174,8 +176,6 @@ PROCESS_THREAD(shell_repeat_server_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE && data == &shell_repeat_process); { - int ret; - static struct process *started_process; strncpy(command_copy, command, MAX_COMMANDLENGTH); ret = shell_start_command(command_copy, (int)strlen(command_copy), &repeat_command, &started_process); diff --git a/apps/shell/shell-vars.c b/apps/shell/shell-vars.c index dd1982b67..1957ffc51 100644 --- a/apps/shell/shell-vars.c +++ b/apps/shell/shell-vars.c @@ -90,6 +90,8 @@ PROCESS_THREAD(shell_vars_process, ev, data) PROCESS_THREAD(shell_var_process, ev, data) { int i; + int j; + char numbuf[32]; PROCESS_BEGIN(); @@ -99,8 +101,6 @@ PROCESS_THREAD(shell_var_process, ev, data) for(i = 0; i < symbols_nelts; ++i) { if(symbols[i].name != NULL && strncmp(symbols[i].name, data, strlen(symbols[i].name)) == 0) { - char numbuf[32]; - int j; sprintf(numbuf, " %d", *((int *)symbols[i].value)); shell_output_str(&var_command, (char *)symbols[i].name, numbuf); diff --git a/apps/shell/shell.c b/apps/shell/shell.c index 5a9c01ad3..3302fa2d8 100644 --- a/apps/shell/shell.c +++ b/apps/shell/shell.c @@ -410,6 +410,8 @@ shell_register_command(struct shell_command *c) PROCESS_THREAD(shell_process, ev, data) { static struct process *started_process; + struct shell_input *input; + int ret; PROCESS_BEGIN(); /* Let the system start up before showing the prompt. */ @@ -420,9 +422,7 @@ PROCESS_THREAD(shell_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); { - struct shell_input *input = data; - int ret; - + input = data; ret = shell_start_command(input->data1, input->len1, NULL, &started_process); diff --git a/core/net/dhcpc.c b/core/net/dhcpc.c index a7213a51a..241f5d3e4 100644 --- a/core/net/dhcpc.c +++ b/core/net/dhcpc.c @@ -271,6 +271,8 @@ msg_for_me(void) static PT_THREAD(handle_dhcp(process_event_t ev, void *data)) { + clock_time_t ticks; + PT_BEGIN(&s.pt); init: @@ -350,7 +352,6 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) } while(s.ticks > 0) { - clock_time_t ticks; ticks = IMIN(s.ticks, MAX_TICKS); s.ticks -= ticks; etimer_set(&s.etimer, ticks); @@ -368,7 +369,6 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data)) /* renewing: */ xid++; do { - clock_time_t ticks; while(ev != tcpip_event) { tcpip_poll_udp(s.conn); PT_YIELD(&s.pt);