Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3376 → Rev 3377

/trunk/uspace/app/bdsh/scli.c
56,38 → 56,6
static int cli_init(cliuser_t *usr);
static void cli_finit(cliuser_t *usr);
 
/* (re)allocates memory to store the current working directory, gets
* and updates the current working directory, formats the prompt
* string */
unsigned int cli_set_prompt(cliuser_t *usr)
{
usr->prompt = (char *) realloc(usr->prompt, PATH_MAX);
if (NULL == usr->prompt) {
cli_error(CL_ENOMEM, "Can not allocate prompt");
return 1;
}
memset(usr->prompt, 0, sizeof(usr->prompt));
 
usr->cwd = (char *) realloc(usr->cwd, PATH_MAX);
if (NULL == usr->cwd) {
cli_error(CL_ENOMEM, "Can not allocate cwd");
return 1;
}
memset(usr->cwd, 0, sizeof(usr->cwd));
 
usr->cwd = getcwd(usr->cwd, PATH_MAX - 1);
 
if (NULL == usr->cwd)
snprintf(usr->cwd, PATH_MAX, "(unknown)");
 
if (1 < cli_psprintf(&usr->prompt, "%s # ", usr->cwd)) {
cli_error(cli_errno, "Failed to set prompt");
return 1;
}
 
return 0;
}
 
/* Constructor */
static int cli_init(cliuser_t *usr)
{
124,7 → 92,6
progname, PACKAGE_STRING);
 
while (!cli_quit) {
cli_set_prompt(&usr);
get_input(&usr);
if (NULL != usr.line) {
ret = tok_input(&usr);