Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
$PRODUCES pushd.c
#include <tilde/tilde.h>
#include "../shell.h"
-#include "../maxpath.h"
+#include "maxpath.h"
#include "common.h"
#include "builtext.h"
/* Offset to the end of the list. */
static int directory_list_offset;
-static void pushd_error ();
-static void clear_directory_stack ();
-static int cd_to_string ();
-static int change_to_temp ();
-static int get_dirstack_index ();
-static void add_dirstack_element ();
+static void pushd_error __P((int, char *));
+static void clear_directory_stack __P((void));
+static int cd_to_string __P((char *));
+static int change_to_temp __P((char *));
+static void add_dirstack_element __P((char *));
+static int get_dirstack_index __P((long, int, int *));
#define NOCD 0x01
#define ROTATE 0x02
flags |= NOCD;
}
else if (ISOPTION (list->word->word, '-'))
- {
- list = list->next;
- break;
- }
+ {
+ list = list->next;
+ break;
+ }
else if (list->word->word[0] == '-' && list->word->word[1] == '\0')
/* Let `pushd -' work like it used to. */
break;
char *which_word;
which_word = (char *)NULL;
- for (flags = 0, which = 0L, direction = '+'; list; list = list->next)
+ for (flags = 0, which = 0, direction = '+'; list; list = list->next)
{
if (ISOPTION (list->word->word, 'n'))
- {
- flags |= NOCD;
- }
+ {
+ flags |= NOCD;
+ }
else if (ISOPTION (list->word->word, '-'))
- {
- list = list->next;
- break;
- }
+ {
+ list = list->next;
+ break;
+ }
else if (((direction = list->word->word[0]) == '+') || direction == '-')
{
if (legal_number (list->word->word + 1, &which) == 0)
(direction == '-' && which == directory_list_offset))
{
i = ((flags & NOCD) == 0) ? cd_to_string (pushd_directory_list[directory_list_offset - 1])
- : EXECUTION_SUCCESS;
+ : EXECUTION_SUCCESS;
if (i != EXECUTION_SUCCESS)
return (i);
free (pushd_directory_list[--directory_list_offset]);
vflag |= 1;
}
else if (ISOPTION (list->word->word, '-'))
- {
- list = list->next;
- break;
- }
+ {
+ list = list->next;
+ break;
+ }
else if (*list->word->word == '+' || *list->word->word == '-')
- {
- int sign;
- if (legal_number (w = list->word->word + 1, &i) == 0)
+ {
+ int sign;
+ if (legal_number (w = list->word->word + 1, &i) == 0)
{
builtin_error (m_badarg, list->word->word);
builtin_usage ();
static int
get_dirstack_index (ind, sign, indexp)
- int ind, sign, *indexp;
+ long ind;
+ int sign, *indexp;
{
if (indexp)
*indexp = sign > 0 ? 1 : 2;
*indexp = sign > 0 ? 2 : 1;
return 0;
}
- else
+ else if (ind >= 0 && ind <= directory_list_offset)
return (sign > 0 ? directory_list_offset - ind : ind);
+ else
+ return -1;
}
/* Used by the tilde expansion code. */
#ifdef INCLUDE_UNUSED
char *
get_dirstack_element (ind, sign)
- int ind, sign;
+ long ind;
+ int sign;
{
int i;
void
set_dirstack_element (ind, sign, value)
- int ind, sign;
+ long ind;
+ int sign;
char *value;
{
int i;