simplify code to use existing $PWD
This commit is contained in:
parent
e3ed074981
commit
7d86eaba8c
35
main.c
35
main.c
@ -33,7 +33,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.185 2011/03/26 19:35:35 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.186 2011/03/26 19:43:47 tg Exp $");
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
@ -156,12 +156,12 @@ main(int argc, const char *argv[])
|
|||||||
Source *s = NULL;
|
Source *s = NULL;
|
||||||
struct block *l;
|
struct block *l;
|
||||||
unsigned char restricted, errexit, utf_flag;
|
unsigned char restricted, errexit, utf_flag;
|
||||||
|
char *cp;
|
||||||
const char *ccp, **wp;
|
const char *ccp, **wp;
|
||||||
struct tbl *vp;
|
struct tbl *vp;
|
||||||
struct stat s_stdin;
|
struct stat s_stdin;
|
||||||
#if !defined(_PATH_DEFPATH) && defined(_CS_PATH)
|
#if !defined(_PATH_DEFPATH) && defined(_CS_PATH)
|
||||||
ssize_t k;
|
ssize_t k;
|
||||||
char *cp;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* do things like getpgrp() et al. */
|
/* do things like getpgrp() et al. */
|
||||||
@ -306,26 +306,17 @@ main(int argc, const char *argv[])
|
|||||||
substitute(initsubs, 0);
|
substitute(initsubs, 0);
|
||||||
|
|
||||||
/* Figure out the current working directory and set $PWD */
|
/* Figure out the current working directory and set $PWD */
|
||||||
{
|
vp = global("PWD");
|
||||||
struct tbl *pwd_v = global("PWD");
|
cp = str_val(vp);
|
||||||
char *pwd = str_val(pwd_v);
|
/* Try to use existing $PWD if it is valid */
|
||||||
char *pwdx = pwd;
|
set_current_wd((cp[0] == '/' && test_eval(NULL, TO_FILEQ, cp, ".",
|
||||||
|
true)) ? cp : NULL);
|
||||||
/* Try to use existing $PWD if it is valid */
|
if (current_wd[0])
|
||||||
if (pwd[0] != '/' ||
|
simplify_path(current_wd);
|
||||||
!test_eval(NULL, TO_FILEQ, pwd, ".", true))
|
/* Only set pwd if we know where we are or if it had a bogus value */
|
||||||
pwdx = NULL;
|
if (current_wd[0] || *cp)
|
||||||
set_current_wd(pwdx);
|
/* setstr can't fail here */
|
||||||
if (current_wd[0])
|
setstr(vp, current_wd, KSH_RETURN_ERROR);
|
||||||
simplify_path(current_wd);
|
|
||||||
/*
|
|
||||||
* Only set pwd if we know where we are or if it had a
|
|
||||||
* bogus value
|
|
||||||
*/
|
|
||||||
if (current_wd[0] || pwd != null)
|
|
||||||
/* setstr can't fail here */
|
|
||||||
setstr(pwd_v, current_wd, KSH_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (wp = initcoms; *wp != NULL; wp++) {
|
for (wp = initcoms; *wp != NULL; wp++) {
|
||||||
shcomexec(wp);
|
shcomexec(wp);
|
||||||
|
4
misc.c
4
misc.c
@ -29,7 +29,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.160 2011/03/26 19:29:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.161 2011/03/26 19:43:48 tg Exp $");
|
||||||
|
|
||||||
/* type bits for unsigned char */
|
/* type bits for unsigned char */
|
||||||
unsigned char chtypes[UCHAR_MAX + 1];
|
unsigned char chtypes[UCHAR_MAX + 1];
|
||||||
@ -1586,7 +1586,7 @@ simplify_path(char *pathl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
set_current_wd(char *nwd)
|
set_current_wd(const char *nwd)
|
||||||
{
|
{
|
||||||
char *allocd = NULL;
|
char *allocd = NULL;
|
||||||
|
|
||||||
|
4
sh.h
4
sh.h
@ -154,7 +154,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.452 2011/03/24 19:05:49 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.453 2011/03/26 19:43:49 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R39 2011/03/23"
|
#define MKSH_VERSION "R39 2011/03/23"
|
||||||
|
|
||||||
@ -1705,7 +1705,7 @@ int reset_nonblock(int);
|
|||||||
char *ksh_get_wd(void);
|
char *ksh_get_wd(void);
|
||||||
char *do_realpath(const char *);
|
char *do_realpath(const char *);
|
||||||
void simplify_path(char *);
|
void simplify_path(char *);
|
||||||
void set_current_wd(char *);
|
void set_current_wd(const char *);
|
||||||
int c_cd(const char **);
|
int c_cd(const char **);
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
char *strdup_(const char *, Area *);
|
char *strdup_(const char *, Area *);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user