mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-13 15:10:49 +02:00
commit bash-20090903 snapshot
This commit is contained in:
+4
-2
@@ -246,7 +246,8 @@ udequote_pathname (pathname)
|
||||
if (pathname[i - 1] == 0)
|
||||
break;
|
||||
}
|
||||
pathname[j] = '\0';
|
||||
if (pathname)
|
||||
pathname[j] = '\0';
|
||||
}
|
||||
|
||||
#if HANDLE_MULTIBYTE
|
||||
@@ -279,7 +280,8 @@ wdequote_pathname (pathname)
|
||||
if (wpathname[i - 1] == L'\0')
|
||||
break;
|
||||
}
|
||||
wpathname[j] = L'\0';
|
||||
if (wpathname)
|
||||
wpathname[j] = L'\0';
|
||||
|
||||
/* Convert the wide character string into unibyte character set. */
|
||||
memset (&ps, '\0', sizeof(mbstate_t));
|
||||
|
||||
+1
-1
@@ -637,7 +637,7 @@ glob_vector (pat, dir, flags)
|
||||
continue;
|
||||
}
|
||||
|
||||
convfn = fnxform (dp->d_name, D_NAMLEN (dp));
|
||||
convfn = fnx_fromfs (dp->d_name, D_NAMLEN (dp));
|
||||
if (strmatch (pat, convfn, mflags) != FNM_NOMATCH)
|
||||
{
|
||||
if (nalloca < ALLOCA_MAX)
|
||||
|
||||
@@ -1426,6 +1426,7 @@ static const struct {
|
||||
{ "completion-ignore-case", &_rl_completion_case_fold, 0 },
|
||||
{ "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 },
|
||||
{ "disable-completion", &rl_inhibit_completion, 0 },
|
||||
{ "echo-control-characters", &_rl_echo_control_chars, 0 },
|
||||
{ "enable-keypad", &_rl_enable_keypad, 0 },
|
||||
{ "expand-tilde", &rl_complete_with_tilde_expansion, 0 },
|
||||
{ "history-preserve-point", &_rl_history_preserve_point, 0 },
|
||||
|
||||
@@ -401,6 +401,11 @@ can be set to either
|
||||
or
|
||||
.BR vi .
|
||||
.TP
|
||||
.B echo\-control\-characters (On)
|
||||
When set to \fBOn\fP, on operating systems that indicate they support it,
|
||||
readline echoes a character corresponding to a signal generated from the
|
||||
keyboard.
|
||||
.TP
|
||||
.B enable\-keypad (Off)
|
||||
When set to \fBOn\fP, readline will try to enable the application
|
||||
keypad when it is called. Some systems need this to enable the
|
||||
|
||||
@@ -474,6 +474,11 @@ key bindings is used. By default, Readline starts up in Emacs editing
|
||||
mode, where the keystrokes are most similar to Emacs. This variable can be
|
||||
set to either @samp{emacs} or @samp{vi}.
|
||||
|
||||
@item echo-control-characters
|
||||
When set to @samp{on}, on operating systems that indicate they support it,
|
||||
readline echoes a character corresponding to a signal generated from the
|
||||
keyboard. The default is @samp{on}.
|
||||
|
||||
@item enable-keypad
|
||||
@vindex enable-keypad
|
||||
When set to @samp{on}, Readline will try to enable the application
|
||||
|
||||
@@ -4,7 +4,7 @@ Copyright (C) 1988-2009 Free Software Foundation, Inc.
|
||||
|
||||
@set EDITION 6.0
|
||||
@set VERSION 6.0
|
||||
@set UPDATED 22 August 2009
|
||||
@set UPDATED 31 August 2009
|
||||
@set UPDATED-MONTH August 2009
|
||||
|
||||
@set LASTCHANGE Sat Aug 22 12:02:34 EDT 2009
|
||||
@set LASTCHANGE Mon Aug 31 09:01:30 EDT 2009
|
||||
|
||||
+26
-16
@@ -305,16 +305,20 @@ get_history_event (string, caller_index, delimiting_quote)
|
||||
/* Extract the contents of STRING as if it is enclosed in single quotes.
|
||||
SINDEX, when passed in, is the offset of the character immediately
|
||||
following the opening single quote; on exit, SINDEX is left pointing
|
||||
to the closing single quote. */
|
||||
to the closing single quote. FLAGS currently used to allow backslash
|
||||
to escape a single quote (e.g., for bash $'...'). */
|
||||
static void
|
||||
hist_string_extract_single_quoted (string, sindex)
|
||||
hist_string_extract_single_quoted (string, sindex, flags)
|
||||
char *string;
|
||||
int *sindex;
|
||||
int *sindex, flags;
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = *sindex; string[i] && string[i] != '\''; i++)
|
||||
;
|
||||
{
|
||||
if ((flags & 1) && string[i] == '\\' && string[i+1])
|
||||
i++;
|
||||
}
|
||||
|
||||
*sindex = i;
|
||||
}
|
||||
@@ -924,7 +928,7 @@ history_expand (hstring, output)
|
||||
char **output;
|
||||
{
|
||||
register int j;
|
||||
int i, r, l, passc, cc, modified, eindex, only_printing, dquote;
|
||||
int i, r, l, passc, cc, modified, eindex, only_printing, dquote, flag;
|
||||
char *string;
|
||||
|
||||
/* The output string, and its length. */
|
||||
@@ -1044,8 +1048,9 @@ history_expand (hstring, output)
|
||||
else if (dquote == 0 && history_quotes_inhibit_expansion && string[i] == '\'')
|
||||
{
|
||||
/* If this is bash, single quotes inhibit history expansion. */
|
||||
flag = (i > 0 && string[i - 1] == '$');
|
||||
i++;
|
||||
hist_string_extract_single_quoted (string, &i);
|
||||
hist_string_extract_single_quoted (string, &i, flag);
|
||||
}
|
||||
else if (history_quotes_inhibit_expansion && string[i] == '\\')
|
||||
{
|
||||
@@ -1130,8 +1135,9 @@ history_expand (hstring, output)
|
||||
{
|
||||
int quote, slen;
|
||||
|
||||
flag = (i > 0 && string[i - 1] == '$');
|
||||
quote = i++;
|
||||
hist_string_extract_single_quoted (string, &i);
|
||||
hist_string_extract_single_quoted (string, &i, flag);
|
||||
|
||||
slen = i - quote + 2;
|
||||
temp = (char *)xmalloc (slen);
|
||||
@@ -1435,17 +1441,21 @@ history_tokenize_word (string, ind)
|
||||
i += 2;
|
||||
return i;
|
||||
}
|
||||
else
|
||||
else if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
|
||||
(peek == '>' && string[i] == '&') ||
|
||||
(peek == '(' && (string[i] == '>' || string[i] == '<')) || /* ) */
|
||||
(peek == '(' && string[i] == '$')) /* ) */
|
||||
{
|
||||
if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
|
||||
(peek == '>' && string[i] == '&') ||
|
||||
(peek == '(' && (string[i] == '>' || string[i] == '<')) || /* ) */
|
||||
(peek == '(' && string[i] == '$')) /* ) */
|
||||
{
|
||||
i += 2;
|
||||
return i;
|
||||
}
|
||||
i += 2;
|
||||
return i;
|
||||
}
|
||||
#if 0
|
||||
else if (peek == '\'' && string[i] == '$')
|
||||
{
|
||||
i += 2; /* XXX */
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (string[i] != '$')
|
||||
{
|
||||
|
||||
@@ -275,6 +275,10 @@ int _rl_bind_stty_chars = 1;
|
||||
its initial state. */
|
||||
int _rl_revert_all_at_newline = 0;
|
||||
|
||||
/* Non-zero means to honor the termios ECHOCTL bit and echo control
|
||||
characters corresponding to keyboard-generated signals. */
|
||||
int _rl_echo_control_chars = 1;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Top Level Functions */
|
||||
|
||||
@@ -421,6 +421,7 @@ extern int _rl_convert_meta_chars_to_ascii;
|
||||
extern int _rl_output_meta_chars;
|
||||
extern int _rl_bind_stty_chars;
|
||||
extern int _rl_revert_all_at_newline;
|
||||
extern int _rl_echo_control_chars;
|
||||
extern char *_rl_comment_begin;
|
||||
extern unsigned char _rl_parsing_conditionalized_out;
|
||||
extern Keymap _rl_keymap;
|
||||
|
||||
@@ -101,7 +101,8 @@ int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
|
||||
int _rl_interrupt_immediately = 0;
|
||||
int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */
|
||||
|
||||
/* If non-zero, print characters corresponding to received signals. */
|
||||
/* If non-zero, print characters corresponding to received signals as long as
|
||||
the user has indicated his desire to do so (_rl_echo_control_chars). */
|
||||
int _rl_echoctl = 0;
|
||||
|
||||
int _rl_intr_char = 0;
|
||||
@@ -637,7 +638,7 @@ rl_echo_signal_char (sig)
|
||||
char cstr[3];
|
||||
int cslen, c;
|
||||
|
||||
if (_rl_echoctl == 0)
|
||||
if (_rl_echoctl == 0 || _rl_echo_control_chars == 0)
|
||||
return;
|
||||
|
||||
switch (sig)
|
||||
|
||||
+1
-1
@@ -1151,7 +1151,7 @@ int
|
||||
rl_delete_horizontal_space (count, ignore)
|
||||
int count, ignore;
|
||||
{
|
||||
int start = rl_point;
|
||||
int start;
|
||||
|
||||
while (rl_point && whitespace (rl_line_buffer[rl_point - 1]))
|
||||
rl_point--;
|
||||
|
||||
@@ -189,10 +189,13 @@ _rl_replace_text (text, start, end)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
rl_begin_undo_group ();
|
||||
rl_delete_text (start, end + 1);
|
||||
if (start <= end)
|
||||
rl_delete_text (start, end + 1);
|
||||
rl_point = start;
|
||||
n = rl_insert_text (text);
|
||||
if (*text)
|
||||
n = rl_insert_text (text);
|
||||
rl_end_undo_group ();
|
||||
|
||||
return n;
|
||||
@@ -583,7 +586,7 @@ rl_skip_csi_sequence (count, key)
|
||||
RL_SETSTATE (RL_STATE_MOREINPUT);
|
||||
do
|
||||
ch = rl_read_key ();
|
||||
while (ch >= 0x20 && ch < 0x40)
|
||||
while (ch >= 0x20 && ch < 0x40);
|
||||
RL_UNSETSTATE (RL_STATE_MOREINPUT);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -139,6 +139,9 @@ _rl_copy_undo_list (head)
|
||||
{
|
||||
UNDO_LIST *list, *new, *roving, *c;
|
||||
|
||||
if (head == 0)
|
||||
return head;
|
||||
|
||||
list = head;
|
||||
new = 0;
|
||||
while (list)
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
/* readline.c -- a general facility for reading lines of input
|
||||
with emacs style editing and completion. */
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library
|
||||
for reading lines of text with interactive input and history editing.
|
||||
|
||||
Readline 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Readline is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Readline. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define READLINE_LIBRARY
|
||||
|
||||
#if defined (HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h> /* for _POSIX_VERSION */
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#if defined (HAVE_STDLIB_H)
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
# include "ansi_stdlib.h"
|
||||
#endif /* HAVE_STDLIB_H */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* System-specific feature definitions and include files. */
|
||||
#include "rldefs.h"
|
||||
|
||||
/* Some standard library routines. */
|
||||
#include "readline.h"
|
||||
#include "history.h"
|
||||
|
||||
#include "rlprivate.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
extern void replace_history_data PARAMS((int, histdata_t *, histdata_t *));
|
||||
|
||||
/* Non-zero tells rl_delete_text and rl_insert_text to not add to
|
||||
the undo list. */
|
||||
int _rl_doing_an_undo = 0;
|
||||
|
||||
/* How many unclosed undo groups we currently have. */
|
||||
int _rl_undo_group_level = 0;
|
||||
|
||||
/* The current undo list for THE_LINE. */
|
||||
UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL;
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
/* Undo, and Undoing */
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
static UNDO_LIST *
|
||||
alloc_undo_entry (what, start, end, text)
|
||||
enum undo_code what;
|
||||
int start, end;
|
||||
char *text;
|
||||
{
|
||||
UNDO_LIST *temp;
|
||||
|
||||
temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST));
|
||||
temp->what = what;
|
||||
temp->start = start;
|
||||
temp->end = end;
|
||||
temp->text = text;
|
||||
|
||||
temp->next = (UNDO_LIST *)NULL;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* Remember how to undo something. Concatenate some undos if that
|
||||
seems right. */
|
||||
void
|
||||
rl_add_undo (what, start, end, text)
|
||||
enum undo_code what;
|
||||
int start, end;
|
||||
char *text;
|
||||
{
|
||||
UNDO_LIST *temp;
|
||||
|
||||
temp = alloc_undo_entry (what, start, end, text);
|
||||
temp->next = rl_undo_list;
|
||||
rl_undo_list = temp;
|
||||
}
|
||||
|
||||
/* Free the existing undo list. */
|
||||
void
|
||||
rl_free_undo_list ()
|
||||
{
|
||||
UNDO_LIST *release, *orig_list;
|
||||
|
||||
orig_list = rl_undo_list;
|
||||
while (rl_undo_list)
|
||||
{
|
||||
release = rl_undo_list;
|
||||
rl_undo_list = rl_undo_list->next;
|
||||
|
||||
if (release->what == UNDO_DELETE)
|
||||
xfree (release->text);
|
||||
|
||||
xfree (release);
|
||||
}
|
||||
rl_undo_list = (UNDO_LIST *)NULL;
|
||||
replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL);
|
||||
}
|
||||
|
||||
UNDO_LIST *
|
||||
_rl_copy_undo_entry (entry)
|
||||
UNDO_LIST *entry;
|
||||
{
|
||||
UNDO_LIST *new;
|
||||
|
||||
new = alloc_undo_entry (entry->what, entry->start, entry->end, (char *)NULL);
|
||||
new->text = entry->text ? savestring (entry->text) : 0;
|
||||
return new;
|
||||
}
|
||||
|
||||
UNDO_LIST *
|
||||
_rl_copy_undo_list (head)
|
||||
UNDO_LIST *head;
|
||||
{
|
||||
UNDO_LIST *list, *new, *roving, *c;
|
||||
|
||||
list = head;
|
||||
new = 0;
|
||||
while (list)
|
||||
{
|
||||
c = _rl_copy_undo_entry (list);
|
||||
if (new == 0)
|
||||
roving = new = c;
|
||||
else
|
||||
{
|
||||
roving->next = c;
|
||||
roving = roving->next;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
roving->next = 0;
|
||||
return new;
|
||||
}
|
||||
|
||||
/* Undo the next thing in the list. Return 0 if there
|
||||
is nothing to undo, or non-zero if there was. */
|
||||
int
|
||||
rl_do_undo ()
|
||||
{
|
||||
UNDO_LIST *release;
|
||||
int waiting_for_begin, start, end;
|
||||
|
||||
#define TRANS(i) ((i) == -1 ? rl_point : ((i) == -2 ? rl_end : (i)))
|
||||
|
||||
start = end = waiting_for_begin = 0;
|
||||
do
|
||||
{
|
||||
if (rl_undo_list == 0)
|
||||
return (0);
|
||||
|
||||
_rl_doing_an_undo = 1;
|
||||
RL_SETSTATE(RL_STATE_UNDOING);
|
||||
|
||||
/* To better support vi-mode, a start or end value of -1 means
|
||||
rl_point, and a value of -2 means rl_end. */
|
||||
if (rl_undo_list->what == UNDO_DELETE || rl_undo_list->what == UNDO_INSERT)
|
||||
{
|
||||
start = TRANS (rl_undo_list->start);
|
||||
end = TRANS (rl_undo_list->end);
|
||||
}
|
||||
|
||||
switch (rl_undo_list->what)
|
||||
{
|
||||
/* Undoing deletes means inserting some text. */
|
||||
case UNDO_DELETE:
|
||||
rl_point = start;
|
||||
rl_insert_text (rl_undo_list->text);
|
||||
xfree (rl_undo_list->text);
|
||||
break;
|
||||
|
||||
/* Undoing inserts means deleting some text. */
|
||||
case UNDO_INSERT:
|
||||
rl_delete_text (start, end);
|
||||
rl_point = start;
|
||||
break;
|
||||
|
||||
/* Undoing an END means undoing everything 'til we get to a BEGIN. */
|
||||
case UNDO_END:
|
||||
waiting_for_begin++;
|
||||
break;
|
||||
|
||||
/* Undoing a BEGIN means that we are done with this group. */
|
||||
case UNDO_BEGIN:
|
||||
if (waiting_for_begin)
|
||||
waiting_for_begin--;
|
||||
else
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
|
||||
_rl_doing_an_undo = 0;
|
||||
RL_UNSETSTATE(RL_STATE_UNDOING);
|
||||
|
||||
release = rl_undo_list;
|
||||
rl_undo_list = rl_undo_list->next;
|
||||
replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list);
|
||||
|
||||
xfree (release);
|
||||
}
|
||||
while (waiting_for_begin);
|
||||
|
||||
return (1);
|
||||
}
|
||||
#undef TRANS
|
||||
|
||||
int
|
||||
_rl_fix_last_undo_of_type (type, start, end)
|
||||
int type, start, end;
|
||||
{
|
||||
UNDO_LIST *rl;
|
||||
|
||||
for (rl = rl_undo_list; rl; rl = rl->next)
|
||||
{
|
||||
if (rl->what == type)
|
||||
{
|
||||
rl->start = start;
|
||||
rl->end = end;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin a group. Subsequent undos are undone as an atomic operation. */
|
||||
int
|
||||
rl_begin_undo_group ()
|
||||
{
|
||||
rl_add_undo (UNDO_BEGIN, 0, 0, 0);
|
||||
_rl_undo_group_level++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* End an undo group started with rl_begin_undo_group (). */
|
||||
int
|
||||
rl_end_undo_group ()
|
||||
{
|
||||
rl_add_undo (UNDO_END, 0, 0, 0);
|
||||
_rl_undo_group_level--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Save an undo entry for the text from START to END. */
|
||||
int
|
||||
rl_modifying (start, end)
|
||||
int start, end;
|
||||
{
|
||||
if (start > end)
|
||||
{
|
||||
SWAP (start, end);
|
||||
}
|
||||
|
||||
if (start != end)
|
||||
{
|
||||
char *temp = rl_copy_text (start, end);
|
||||
rl_begin_undo_group ();
|
||||
rl_add_undo (UNDO_DELETE, start, end, temp);
|
||||
rl_add_undo (UNDO_INSERT, start, end, (char *)NULL);
|
||||
rl_end_undo_group ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Revert the current line to its previous state. */
|
||||
int
|
||||
rl_revert_line (count, key)
|
||||
int count, key;
|
||||
{
|
||||
if (rl_undo_list == 0)
|
||||
rl_ding ();
|
||||
else
|
||||
{
|
||||
while (rl_undo_list)
|
||||
rl_do_undo ();
|
||||
#if defined (VI_MODE)
|
||||
if (rl_editing_mode == vi_mode)
|
||||
rl_point = rl_mark = 0; /* rl_end should be set correctly */
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Do some undoing of things that were done. */
|
||||
int
|
||||
rl_undo_command (count, key)
|
||||
int count, key;
|
||||
{
|
||||
if (count < 0)
|
||||
return 0; /* Nothing to do. */
|
||||
|
||||
while (count)
|
||||
{
|
||||
if (rl_do_undo ())
|
||||
count--;
|
||||
else
|
||||
{
|
||||
rl_ding ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1
-1
@@ -92,7 +92,7 @@ uconvert(s, ip, up)
|
||||
ipart = (ipart * 10) + (*p - '0');
|
||||
}
|
||||
|
||||
if (*p == 0)
|
||||
if (p == 0 || *p == 0) /* callers ensure p can never be 0; this is to shut up clang */
|
||||
RETURN(1);
|
||||
|
||||
if (*p == DECIMAL)
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/* uconvert - convert string representations of decimal numbers into whole
|
||||
number/fractional value pairs. */
|
||||
|
||||
/* Copyright (C) 2008,2009 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "bashtypes.h"
|
||||
|
||||
#if defined (TIME_WITH_SYS_TIME)
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# if defined (HAVE_SYS_TIME_H)
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "chartypes.h"
|
||||
|
||||
#include "shell.h"
|
||||
#include "builtins.h"
|
||||
|
||||
#define DECIMAL '.' /* XXX - should use locale */
|
||||
|
||||
#define RETURN(x) \
|
||||
do { \
|
||||
if (ip) *ip = ipart * mult; \
|
||||
if (up) *up = upart; \
|
||||
return (x); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* An incredibly simplistic floating point converter.
|
||||
*/
|
||||
static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
|
||||
|
||||
/* Take a decimal number int-part[.[micro-part]] and convert it to the whole
|
||||
and fractional portions. The fractional portion is returned in
|
||||
millionths (micro); callers are responsible for multiplying appropriately.
|
||||
Return 1 if value converted; 0 if invalid integer for either whole or
|
||||
fractional parts. */
|
||||
int
|
||||
uconvert(s, ip, up)
|
||||
char *s;
|
||||
long *ip, *up;
|
||||
{
|
||||
int n, mult;
|
||||
long ipart, upart;
|
||||
char *p;
|
||||
|
||||
ipart = upart = 0;
|
||||
mult = 1;
|
||||
|
||||
if (s && (*s == '-' || *s == '+'))
|
||||
{
|
||||
mult = (*s == '-') ? -1 : 1;
|
||||
p = s + 1;
|
||||
}
|
||||
else
|
||||
p = s;
|
||||
|
||||
for ( ; p && *p; p++)
|
||||
{
|
||||
if (*p == DECIMAL) /* decimal point */
|
||||
break;
|
||||
if (DIGIT(*p) == 0)
|
||||
RETURN(0);
|
||||
ipart = (ipart * 10) + (*p - '0');
|
||||
}
|
||||
|
||||
if (*p == 0)
|
||||
RETURN(1);
|
||||
|
||||
if (*p == DECIMAL)
|
||||
p++;
|
||||
|
||||
/* Look for up to six digits past a decimal point. */
|
||||
for (n = 0; n < 6 && p[n]; n++)
|
||||
{
|
||||
if (DIGIT(p[n]) == 0)
|
||||
RETURN(0);
|
||||
upart = (upart * 10) + (p[n] - '0');
|
||||
}
|
||||
|
||||
/* Now convert to millionths */
|
||||
upart *= multiplier[n];
|
||||
|
||||
if (n == 6 && p[6] >= '5' && p[6] <= '9')
|
||||
upart++; /* round up 1 */
|
||||
|
||||
RETURN(1);
|
||||
}
|
||||
Reference in New Issue
Block a user