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.
This commit is contained in:
Oliver Schmidt 2011-04-12 14:12:09 +02:00
parent b19fb0ac9e
commit 07f3df45be
11 changed files with 50 additions and 44 deletions

View File

@ -392,10 +392,12 @@ content_type_t http_get_header_content_type(http_request_t* request)
static static
PT_THREAD(handle_request(connection_state_t* conn_state)) PT_THREAD(handle_request(connection_state_t* conn_state))
{ {
static int error;
const char* content_len;
PSOCK_BEGIN(&(conn_state->sin)); PSOCK_BEGIN(&(conn_state->sin));
static int error; content_len = NULL;
const char* content_len = NULL;
error = HTTP_NO_ERROR; /*always reinit static variables due to protothreads*/ 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 static
PT_THREAD(send_data(connection_state_t* conn_state)) 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)); PSOCK_BEGIN(&(conn_state->sout));
PRINTF("send_data -> \n"); PRINTF("send_data -> \n");
uint16_t index = 0; index = 0;
http_response_t* response = &conn_state->response; response = &conn_state->response;
http_header_t* header = response->headers; header = response->headers;
uint8_t* buffer = allocate_buffer(200); 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!*/ /*FIXME: what is the best solution here to send the data. Right now, if buffer is not allocated, no data is sent!*/
if (buffer) { if (buffer) {
@ -583,6 +590,8 @@ PROCESS(http_server, "Httpd Process");
PROCESS_THREAD(http_server, ev, data) PROCESS_THREAD(http_server, ev, data)
{ {
connection_state_t *conn_state;
PROCESS_BEGIN(); PROCESS_BEGIN();
/* if static routes are used rather than RPL */ /* if static routes are used rather than RPL */
@ -603,7 +612,7 @@ PROCESS_THREAD(http_server, ev, data)
while(1) { while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); 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()) { if(uip_connected()) {
PRINTF("##Connected##\n"); PRINTF("##Connected##\n");

View File

@ -117,13 +117,13 @@ base64_add_char(struct base64_decoder_state *s, char c)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_dec64_process, ev, data) PROCESS_THREAD(shell_dec64_process, ev, data)
{ {
struct shell_input *input;
struct base64_decoder_state s;
int i;
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1) { while(1) {
struct shell_input *input;
struct base64_decoder_state s;
int i;
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
input = data; input = data;

View File

@ -103,6 +103,7 @@ PROCESS_THREAD(shell_ls_process, ev, data)
PROCESS_THREAD(shell_append_process, ev, data) PROCESS_THREAD(shell_append_process, ev, data)
{ {
static int fd = 0; static int fd = 0;
struct shell_input *input;
PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_EXITHANDLER(cfs_close(fd));
@ -115,7 +116,6 @@ PROCESS_THREAD(shell_append_process, ev, data)
"append: could not open file for writing: ", data); "append: could not open file for writing: ", data);
} else { } else {
while(1) { while(1) {
struct shell_input *input;
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
input = data; input = data;
/* printf("cat input %d %d\n", input->len1, input->len2);*/ /* 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) PROCESS_THREAD(shell_write_process, ev, data)
{ {
static int fd = 0; static int fd = 0;
struct shell_input *input;
int r; int r;
PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_EXITHANDLER(cfs_close(fd));
@ -152,7 +153,6 @@ PROCESS_THREAD(shell_write_process, ev, data)
"write: could not open file for writing: ", data); "write: could not open file for writing: ", data);
} else { } else {
while(1) { while(1) {
struct shell_input *input;
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
input = data; input = data;
/* printf("cat input %d %d\n", input->len1, input->len2);*/ /* 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) PROCESS_THREAD(shell_read_process, ev, data)
{ {
static int fd = 0; static int fd = 0;
static int block_size = MAX_BLOCKSIZE;
char *next; char *next;
char filename[MAX_FILENAME_LEN]; char filename[MAX_FILENAME_LEN];
int len; int len;
int offset = 0; int offset = 0;
static int block_size = MAX_BLOCKSIZE; char buf[MAX_BLOCKSIZE];
struct shell_input *input;
PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_EXITHANDLER(cfs_close(fd));
PROCESS_BEGIN(); PROCESS_BEGIN();
@ -236,10 +239,6 @@ PROCESS_THREAD(shell_read_process, ev, data)
} else { } else {
while(1) { while(1) {
char buf[MAX_BLOCKSIZE];
int len;
struct shell_input *input;
len = cfs_read(fd, buf, block_size); len = cfs_read(fd, buf, block_size);
if(len <= 0) { if(len <= 0) {
cfs_close(fd); cfs_close(fd);

View File

@ -133,8 +133,9 @@ send_ping(uip_ipaddr_t *dest_addr)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ping_process, ev, data) PROCESS_THREAD(shell_ping_process, ev, data)
{ {
static struct etimer e;
struct shell_input *input; struct shell_input *input;
PROCESS_BEGIN(); PROCESS_BEGIN();
if(data == NULL) { if(data == NULL) {
@ -149,9 +150,6 @@ PROCESS_THREAD(shell_ping_process, ev, data)
running = 1; running = 1;
while(running) { while(running) {
static struct etimer e;
etimer_set(&e, CLOCK_SECOND * 10); etimer_set(&e, CLOCK_SECOND * 10);
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();

View File

@ -67,6 +67,7 @@ PROCESS(shell_rsh_server_process, "rsh server");
PROCESS_THREAD(shell_rsh_process, ev, data) PROCESS_THREAD(shell_rsh_process, ev, data)
{ {
static rimeaddr_t receiver; static rimeaddr_t receiver;
struct shell_input *input;
const char *nextptr; const char *nextptr;
char buf[40]; char buf[40];
@ -88,7 +89,6 @@ PROCESS_THREAD(shell_rsh_process, ev, data)
meshconn_connect(&meshconn, &receiver); meshconn_connect(&meshconn, &receiver);
while(1) { while(1) {
struct shell_input *input;
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
if(ev == shell_event_input) { if(ev == shell_event_input) {
input = data; input = data;
@ -114,6 +114,8 @@ PROCESS_THREAD(shell_rsh_process, ev, data)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rsh_server_process, ev, data) PROCESS_THREAD(shell_rsh_server_process, ev, data)
{ {
struct shell_input *input;
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1) { while(1) {
@ -123,7 +125,6 @@ PROCESS_THREAD(shell_rsh_server_process, ev, data)
if(ev == PROCESS_EVENT_EXITED) { if(ev == PROCESS_EVENT_EXITED) {
front_process = NULL; front_process = NULL;
} else if(ev == shell_event_input) { } else if(ev == shell_event_input) {
struct shell_input *input;
input = data; input = data;
packetbuf_clear(); packetbuf_clear();
memcpy(packetbuf_dataptr(), input->data1, input->len1); memcpy(packetbuf_dataptr(), input->data1, input->len1);

View File

@ -117,10 +117,10 @@ print_usage(void)
PROCESS_THREAD(shell_sendtest_process, ev, data) PROCESS_THREAD(shell_sendtest_process, ev, data)
{ {
static rimeaddr_t receiver; static rimeaddr_t receiver;
static unsigned long cpu, lpm, rx, tx;
const char *nextptr; const char *nextptr;
const char *args; const char *args;
char buf[40]; char buf[40];
static unsigned long cpu, lpm, rx, tx;
unsigned long cpu2, lpm2, rx2, tx2; unsigned long cpu2, lpm2, rx2, tx2;
PROCESS_BEGIN(); PROCESS_BEGIN();

View File

@ -131,6 +131,7 @@ PROCESS_THREAD(shell_binprint_process, ev, data)
uint16_t *ptr; uint16_t *ptr;
int i; int i;
char buf[2*64], *bufptr; char buf[2*64], *bufptr;
uint16_t val;
PROCESS_BEGIN(); PROCESS_BEGIN();
@ -145,9 +146,8 @@ PROCESS_THREAD(shell_binprint_process, ev, data)
bufptr = buf; bufptr = buf;
ptr = (uint16_t *)input->data1; ptr = (uint16_t *)input->data1;
for(i = 0; i < input->len1 && i < input->len1 - 1; i += 2) { for(i = 0; i < input->len1 && i < input->len1 - 1; i += 2) {
uint16_t data; memcpy(&val, ptr, sizeof(val));
memcpy(&data, ptr, sizeof(data)); bufptr += sprintf(bufptr, "%u ", val);
bufptr += sprintf(bufptr, "%u ", data);
if(bufptr - buf >= sizeof(buf) - 6) { if(bufptr - buf >= sizeof(buf) - 6) {
shell_output_str(&binprint_command, buf, ""); shell_output_str(&binprint_command, buf, "");
bufptr = buf; bufptr = buf;
@ -160,9 +160,8 @@ PROCESS_THREAD(shell_binprint_process, ev, data)
ptr = (uint16_t *)input->data2; ptr = (uint16_t *)input->data2;
for(i = 0; i < input->len2 && i < input->len2 - 1; i += 2) { for(i = 0; i < input->len2 && i < input->len2 - 1; i += 2) {
uint16_t data; memcpy(&val, ptr, sizeof(val));
memcpy(&data, ptr, sizeof(data)); bufptr += sprintf(bufptr, "%u ", val);
bufptr += sprintf(bufptr, "%u ", data);
if(bufptr - buf >= sizeof(buf) - 6) { if(bufptr - buf >= sizeof(buf) - 6) {
shell_output_str(&binprint_command, buf, ""); shell_output_str(&binprint_command, buf, "");
bufptr = buf; bufptr = buf;
@ -180,8 +179,9 @@ PROCESS_THREAD(shell_binprint_process, ev, data)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_size_process, ev, data) PROCESS_THREAD(shell_size_process, ev, data)
{ {
struct shell_input *input;
static unsigned long size; static unsigned long size;
struct shell_input *input;
char buf[10];
PROCESS_BEGIN(); PROCESS_BEGIN();
size = 0; size = 0;
@ -193,7 +193,6 @@ PROCESS_THREAD(shell_size_process, ev, data)
size += input->len1 + input->len2; size += input->len1 + input->len2;
if(input->len1 + input->len2 == 0) { if(input->len1 + input->len2 == 0) {
char buf[10];
snprintf(buf, sizeof(buf), "%lu", size); snprintf(buf, sizeof(buf), "%lu", size);
shell_output_str(&size_command, buf, ""); shell_output_str(&size_command, buf, "");
PROCESS_EXIT(); PROCESS_EXIT();

View File

@ -91,11 +91,11 @@ PROCESS_THREAD(shell_time_process, ev, data)
uint16_t time[2]; uint16_t time[2];
} msg; } msg;
unsigned long newtime; unsigned long newtime;
const char *nextptr;
PROCESS_BEGIN(); PROCESS_BEGIN();
if(data != NULL) { if(data != NULL) {
const char *nextptr;
newtime = shell_strtolong(data, &nextptr); newtime = shell_strtolong(data, &nextptr);
if(data != nextptr) { if(data != nextptr) {
shell_set_time(newtime); shell_set_time(newtime);
@ -122,6 +122,7 @@ PROCESS_THREAD(shell_time_process, ev, data)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_timestamp_process, ev, data) PROCESS_THREAD(shell_timestamp_process, ev, data)
{ {
struct shell_input *input;
struct msg { struct msg {
uint16_t len; uint16_t len;
uint16_t time[2]; uint16_t time[2];
@ -132,7 +133,6 @@ PROCESS_THREAD(shell_timestamp_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
while(1) { while(1) {
struct shell_input *input;
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input); PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
input = data; input = data;
if(input->len1 + input->len2 == 0) { 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) PROCESS_THREAD(shell_repeat_server_process, ev, data)
{ {
static char *command; static char *command;
static struct process *started_process;
char command_copy[MAX_COMMANDLENGTH]; char command_copy[MAX_COMMANDLENGTH];
int ret;
if(ev == shell_event_input) { if(ev == shell_event_input) {
goto exit; goto exit;
@ -174,8 +176,6 @@ PROCESS_THREAD(shell_repeat_server_process, ev, data)
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE && PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE &&
data == &shell_repeat_process); data == &shell_repeat_process);
{ {
int ret;
static struct process *started_process;
strncpy(command_copy, command, MAX_COMMANDLENGTH); strncpy(command_copy, command, MAX_COMMANDLENGTH);
ret = shell_start_command(command_copy, (int)strlen(command_copy), ret = shell_start_command(command_copy, (int)strlen(command_copy),
&repeat_command, &started_process); &repeat_command, &started_process);

View File

@ -90,6 +90,8 @@ PROCESS_THREAD(shell_vars_process, ev, data)
PROCESS_THREAD(shell_var_process, ev, data) PROCESS_THREAD(shell_var_process, ev, data)
{ {
int i; int i;
int j;
char numbuf[32];
PROCESS_BEGIN(); PROCESS_BEGIN();
@ -99,8 +101,6 @@ PROCESS_THREAD(shell_var_process, ev, data)
for(i = 0; i < symbols_nelts; ++i) { for(i = 0; i < symbols_nelts; ++i) {
if(symbols[i].name != NULL && if(symbols[i].name != NULL &&
strncmp(symbols[i].name, data, strlen(symbols[i].name)) == 0) { strncmp(symbols[i].name, data, strlen(symbols[i].name)) == 0) {
char numbuf[32];
int j;
sprintf(numbuf, " %d", *((int *)symbols[i].value)); sprintf(numbuf, " %d", *((int *)symbols[i].value));
shell_output_str(&var_command, (char *)symbols[i].name, numbuf); shell_output_str(&var_command, (char *)symbols[i].name, numbuf);

View File

@ -410,6 +410,8 @@ shell_register_command(struct shell_command *c)
PROCESS_THREAD(shell_process, ev, data) PROCESS_THREAD(shell_process, ev, data)
{ {
static struct process *started_process; static struct process *started_process;
struct shell_input *input;
int ret;
PROCESS_BEGIN(); PROCESS_BEGIN();
/* Let the system start up before showing the prompt. */ /* 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); PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
{ {
struct shell_input *input = data; input = data;
int ret;
ret = shell_start_command(input->data1, input->len1, NULL, ret = shell_start_command(input->data1, input->len1, NULL,
&started_process); &started_process);

View File

@ -271,6 +271,8 @@ msg_for_me(void)
static static
PT_THREAD(handle_dhcp(process_event_t ev, void *data)) PT_THREAD(handle_dhcp(process_event_t ev, void *data))
{ {
clock_time_t ticks;
PT_BEGIN(&s.pt); PT_BEGIN(&s.pt);
init: init:
@ -350,7 +352,6 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
} }
while(s.ticks > 0) { while(s.ticks > 0) {
clock_time_t ticks;
ticks = IMIN(s.ticks, MAX_TICKS); ticks = IMIN(s.ticks, MAX_TICKS);
s.ticks -= ticks; s.ticks -= ticks;
etimer_set(&s.etimer, ticks); etimer_set(&s.etimer, ticks);
@ -368,7 +369,6 @@ PT_THREAD(handle_dhcp(process_event_t ev, void *data))
/* renewing: */ /* renewing: */
xid++; xid++;
do { do {
clock_time_t ticks;
while(ev != tcpip_event) { while(ev != tcpip_event) {
tcpip_poll_udp(s.conn); tcpip_poll_udp(s.conn);
PT_YIELD(&s.pt); PT_YIELD(&s.pt);