Changeset 0c4f46a in mainline


Ignore:
Timestamp:
2008-08-30T15:05:54Z (16 years ago)
Author:
Tim Post <echo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42a0607
Parents:
43e02a6
Message:

Let 'cd' invoke cli_set_prompt(), no need to do it in every iteration of the main loop.

Location:
uspace/app/bdsh
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    r43e02a6 r0c4f46a  
    8787
    8888        if (rc == 0) {
     89                cli_set_prompt(usr);
    8990                return CMD_SUCCESS;
    9091        } else {
  • uspace/app/bdsh/scli.c

    r43e02a6 r0c4f46a  
    5757static void cli_finit(cliuser_t *usr);
    5858
    59 /* (re)allocates memory to store the current working directory, gets
    60  * and updates the current working directory, formats the prompt
    61  * string */
    62 unsigned int cli_set_prompt(cliuser_t *usr)
    63 {
    64         usr->prompt = (char *) realloc(usr->prompt, PATH_MAX);
    65         if (NULL == usr->prompt) {
    66                 cli_error(CL_ENOMEM, "Can not allocate prompt");
    67                 return 1;
    68         }
    69         memset(usr->prompt, 0, sizeof(usr->prompt));
    70 
    71         usr->cwd = (char *) realloc(usr->cwd, PATH_MAX);
    72         if (NULL == usr->cwd) {
    73                 cli_error(CL_ENOMEM, "Can not allocate cwd");
    74                 return 1;
    75         }
    76         memset(usr->cwd, 0, sizeof(usr->cwd));
    77 
    78         usr->cwd = getcwd(usr->cwd, PATH_MAX - 1);
    79 
    80         if (NULL == usr->cwd)
    81                 snprintf(usr->cwd, PATH_MAX, "(unknown)");
    82 
    83         if (1 < cli_psprintf(&usr->prompt, "%s # ", usr->cwd)) {
    84                 cli_error(cli_errno, "Failed to set prompt");
    85                 return 1;
    86         }
    87 
    88         return 0;
    89 }
    90 
    9159/* Constructor */
    9260static int cli_init(cliuser_t *usr)
     
    12593
    12694        while (!cli_quit) {
    127                 cli_set_prompt(&usr);
    12895                get_input(&usr);
    12996                if (NULL != usr.line) {
  • uspace/app/bdsh/scli.h

    r43e02a6 r0c4f46a  
    1414} cliuser_t;
    1515
    16 extern unsigned int cli_set_prompt(cliuser_t *usr);
    17 
    1816#endif
  • uspace/app/bdsh/util.c

    r43e02a6 r0c4f46a  
    248248}
    249249
     250/* (re)allocates memory to store the current working directory, gets
     251 * and updates the current working directory, formats the prompt
     252 * string */
     253unsigned int cli_set_prompt(cliuser_t *usr)
     254{
     255        usr->prompt = (char *) realloc(usr->prompt, PATH_MAX);
     256        if (NULL == usr->prompt) {
     257                cli_error(CL_ENOMEM, "Can not allocate prompt");
     258                cli_errno = CL_ENOMEM;
     259                return 1;
     260        }
     261        memset(usr->prompt, 0, sizeof(usr->prompt));
     262
     263        usr->cwd = (char *) realloc(usr->cwd, PATH_MAX);
     264        if (NULL == usr->cwd) {
     265                cli_error(CL_ENOMEM, "Can not allocate cwd");
     266                cli_errno = CL_ENOMEM;
     267                return 1;
     268        }
     269        memset(usr->cwd, 0, sizeof(usr->cwd));
     270
     271        usr->cwd = getcwd(usr->cwd, PATH_MAX - 1);
     272
     273        if (NULL == usr->cwd)
     274                snprintf(usr->cwd, PATH_MAX, "(unknown)");
     275
     276        if (1 < cli_psprintf(&usr->prompt, "%s # ", usr->cwd)) {
     277                cli_error(cli_errno, "Failed to set prompt");
     278                return 1;
     279        }
     280
     281        return 0;
     282}
     283
     284
  • uspace/app/bdsh/util.h

    r43e02a6 r0c4f46a  
    11#ifndef UTIL_H
    22#define UTIL_H
     3
     4#include "scli.h"
    35
    46/* Internal string handlers */
     
    810extern char * cli_strtok_r(char *, const char *, char **);
    911extern char * cli_strtok(char *, const char *);
     12
     13/* Utility functions */
    1014extern unsigned int cli_count_args(char **);
     15extern unsigned int cli_set_prompt(cliuser_t *usr);
    1116
    1217#endif
Note: See TracChangeset for help on using the changeset viewer.