Lines 3511-3516
Link Here
|
3511 |
} |
3511 |
} |
3512 |
} |
3512 |
} |
|
|
3513 |
#define IN_TRIG "/.getin" |
3514 |
#define OUT_TRIG "/.getout" |
3515 |
|
3516 |
#define ADD_TRIGGER(buf, path, name) \ |
3517 |
strcpy ((buf), "( builtin cd \""); \ |
3518 |
strcat ((buf), (path)); \ |
3519 |
strcat ((buf), "\" ; ."); \ |
3520 |
strcat ((buf), (name)); \ |
3521 |
strcat ((buf), " )"); |
3522 |
|
3523 |
static char * |
3524 |
build_trigger_list (old, olde, new, newe) |
3525 |
char *old, *olde, *new, *newe; |
3526 |
{ |
3527 |
char *buf, *pos, *pos1; |
3528 |
|
3529 |
buf = (char *)xmalloc (strlen (olde) + sizeof IN_TRIG + |
3530 |
strlen (newe) + sizeof OUT_TRIG + 49); |
3531 |
|
3532 |
strcpy (buf, "( "); |
3533 |
pos1 = pos = buf + 2; |
3534 |
|
3535 |
strcpy (pos, old); |
3536 |
strcat (pos, OUT_TRIG); |
3537 |
|
3538 |
if (executable_file (pos)) |
3539 |
{ |
3540 |
ADD_TRIGGER(pos, olde, OUT_TRIG); |
3541 |
pos1 = pos + strlen (pos); |
3542 |
|
3543 |
strcat (pos, " && "); |
3544 |
pos = pos1 + 4; |
3545 |
} |
3546 |
|
3547 |
strcpy (pos, new); |
3548 |
strcat (pos, IN_TRIG); |
3549 |
|
3550 |
if (executable_file (pos)) |
3551 |
{ |
3552 |
ADD_TRIGGER(pos, newe, IN_TRIG); |
3553 |
pos1 = pos + strlen (pos); |
3554 |
} |
3555 |
|
3556 |
strcpy (pos1, " )"); |
3557 |
|
3558 |
if (strlen (buf) == 4) |
3559 |
{ |
3560 |
xfree (buf); |
3561 |
buf = NULL; |
3562 |
} |
3563 |
|
3564 |
xfree(olde); |
3565 |
xfree(newe); |
3566 |
|
3567 |
return buf; |
3568 |
} |
3569 |
|
3570 |
static char * |
3571 |
escape_string (string) |
3572 |
char *string; |
3573 |
{ |
3574 |
char *result; |
3575 |
int i, j; |
3576 |
|
3577 |
for (j = i = 0; string[i]; i++) |
3578 |
switch (string[i]) |
3579 |
{ |
3580 |
case '$': |
3581 |
case '`': |
3582 |
case '"': |
3583 |
case '\\': |
3584 |
j++; |
3585 |
} |
3586 |
|
3587 |
result = (char *)xmalloc (i + j + 1); |
3588 |
|
3589 |
for (j = i = 0; string[i]; j++, i++) |
3590 |
switch (string[i]) |
3591 |
{ |
3592 |
case '$': |
3593 |
case '`': |
3594 |
case '"': |
3595 |
case '\\': |
3596 |
result[j++] = '\\'; |
3597 |
default: |
3598 |
result[j] = string[i]; |
3599 |
} |
3600 |
|
3601 |
result[j] = string[i]; |
3602 |
|
3603 |
return result; |
3604 |
} |
3605 |
|
3513 |
/* Execute a simple command that is hopefully defined in a disk file |
3606 |
/* Execute a simple command that is hopefully defined in a disk file |
3514 |
somewhere. |
3607 |
somewhere. |
Lines 3539-3546
Link Here
|
3539 |
struct fd_bitmap *fds_to_close; |
3632 |
struct fd_bitmap *fds_to_close; |
3540 |
int cmdflags; |
3633 |
int cmdflags; |
3541 |
{ |
3634 |
{ |
3542 |
char *pathname, *command, **args; |
3635 |
char *lazycd_name, *pathname, *command, **args; |
3543 |
int nofork; |
3636 |
int nofork, lazycd_result = 0, lazycd = 0; |
3544 |
pid_t pid; |
3637 |
pid_t pid; |
3545 |
nofork = (cmdflags & CMD_NO_FORK); /* Don't fork, just exec, if no pipes */ |
3638 |
nofork = (cmdflags & CMD_NO_FORK); /* Don't fork, just exec, if no pipes */ |
Lines 3569-3574
Link Here
|
3569 |
{ |
3662 |
{ |
3570 |
maybe_make_export_env (); |
3663 |
maybe_make_export_env (); |
3571 |
put_command_name_into_env (command); |
3664 |
put_command_name_into_env (command); |
|
|
3665 |
lazycd_name = command; |
3666 |
} |
3667 |
else |
3668 |
lazycd_name = pathname; |
3669 |
|
3670 |
if (!find_variable ("LAZY_DISABLE") && is_directory (lazycd_name)) |
3671 |
{ |
3672 |
sh_builtin_func_t *builtin; |
3673 |
char *oldpwd; |
3674 |
|
3675 |
/* lazycd patch by Alessandro Di Marco <dmr@c0nc3pt.com> |
3676 |
* for Amiga (and some Mac) nostalgics only! ;) |
3677 |
*/ |
3678 |
|
3679 |
lazycd = 1; |
3680 |
oldpwd = getcwd (0,0); |
3681 |
|
3682 |
builtin = find_shell_builtin ("cd"); |
3683 |
words = make_word_list (make_bare_word ("cd"), |
3684 |
make_word_list (make_bare_word (lazycd_name), |
3685 |
NULL)); |
3686 |
|
3687 |
lazycd_result = execute_builtin (builtin, words, 0, 0); |
3688 |
dispose_words (words); |
3689 |
|
3690 |
if (!lazycd_result) |
3691 |
{ |
3692 |
char *newpwd = getcwd (0,0); |
3693 |
|
3694 |
if (!oldpwd || !newpwd) |
3695 |
lazycd_result = 1; |
3696 |
else |
3697 |
{ |
3698 |
char *cmd = build_trigger_list (oldpwd, |
3699 |
escape_string(oldpwd), |
3700 |
newpwd, |
3701 |
escape_string(newpwd)); |
3702 |
if (cmd) |
3703 |
{ |
3704 |
words = make_word_list (make_bare_word ("sh"), |
3705 |
make_word_list (make_bare_word ("-c"), |
3706 |
make_word_list (make_bare_word (cmd), |
3707 |
NULL))); |
3708 |
xfree (cmd); |
3709 |
} |
3710 |
else /* trig nothing */ |
3711 |
lazycd = 2; |
3712 |
} |
3713 |
|
3714 |
xfree (newpwd); |
3715 |
} |
3716 |
|
3717 |
xfree (oldpwd); |
3572 |
} |
3718 |
} |
3573 |
/* We have to make the child before we check for the non-existence |
3719 |
/* We have to make the child before we check for the non-existence |
Lines 3636-3641
Link Here
|
3636 |
if (async) |
3782 |
if (async) |
3637 |
interactive = old_interactive; |
3783 |
interactive = old_interactive; |
|
|
3784 |
if (lazycd) |
3785 |
{ |
3786 |
if (lazycd_result || lazycd == 2) |
3787 |
exit (lazycd_result); |
3788 |
|
3789 |
command = "/bin/sh"; |
3790 |
} |
3791 |
|
3638 |
if (command == 0) |
3792 |
if (command == 0) |
3639 |
{ |
3793 |
{ |
3640 |
internal_error (_("%s: command not found"), pathname); |
3794 |
internal_error (_("%s: command not found"), pathname); |
Lines 3651-3656
Link Here
|
3651 |
else |
3805 |
else |
3652 |
{ |
3806 |
{ |
3653 |
parent_return: |
3807 |
parent_return: |
|
|
3808 |
|
3809 |
if (lazycd == 1 && !lazycd_result) |
3810 |
dispose_words (words); |
3811 |
|
3654 |
/* Make sure that the pipes are closed in the parent. */ |
3812 |
/* Make sure that the pipes are closed in the parent. */ |
3655 |
close_pipes (pipe_in, pipe_out); |
3813 |
close_pipes (pipe_in, pipe_out); |
3656 |
#if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD) |
3814 |
#if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD) |