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
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");

View file

@ -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;

View file

@ -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);

View file

@ -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();

View file

@ -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);

View file

@ -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();

View file

@ -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();

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);