1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

Merge pull request #241 from mehlis/shell

shell: don't use malloc on each line
This commit is contained in:
Oleg Hahm 2013-11-14 05:44:43 -08:00
commit 2532dda859
2 changed files with 8 additions and 12 deletions

View File

@ -2,7 +2,7 @@
* Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved.
*
* These sources were developed at the Freie Universitaet Berlin, Computer Systems
and Telematics group (http://cst.mi.fu-berlin.de).
* and Telematics group (http://cst.mi.fu-berlin.de).
* ----------------------------------------------------------------------------
* This file is part of RIOT.
*
@ -20,8 +20,6 @@ and Telematics group (http://cst.mi.fu-berlin.de).
* @ingroup feuerware
*/
//#include "hashtable.h"
typedef struct shell_command_t {
char *name;
char *desc;
@ -34,6 +32,8 @@ typedef struct shell_t {
void (*put_char)(int);
} shell_t;
#define SHELL_BUFFER_SIZE (127)
/**
* @brief Initialize a shell object
* @param shell Pointer to preallocated shell object

View File

@ -26,7 +26,6 @@
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
//#include <sys/unistd.h>
#include <string.h>
#include <stdio.h>
#include <shell.h>
@ -92,9 +91,10 @@ static void print_help(const shell_command_t *command_list)
static void handle_input_line(shell_t *shell, char *line)
{
char line_copy[SHELL_BUFFER_SIZE];
char *saveptr;
char *linedup = strdup(line);
char *command = strtok_r(linedup, " ", &saveptr);
strncpy(line_copy, line, sizeof(line_copy));
char *command = strtok_r(line_copy, " ", &saveptr);
void (*handler)(char *) = NULL;
@ -113,8 +113,6 @@ static void handle_input_line(shell_t *shell, char *line)
}
}
}
free(linedup);
}
static int readline(shell_t *shell, char *buf, size_t size)
@ -155,7 +153,7 @@ static inline void print_prompt(shell_t *shell)
void shell_run(shell_t *shell)
{
char line_buf[255];
char line_buf[SHELL_BUFFER_SIZE];
print_prompt(shell);
@ -163,9 +161,7 @@ void shell_run(shell_t *shell)
int res = readline(shell, line_buf, sizeof(line_buf));
if (!res) {
char *line_copy = strdup(line_buf);
handle_input_line(shell, line_copy);
free(line_copy);
handle_input_line(shell, line_buf);
}
print_prompt(shell);