mirror of https://github.com/sheumann/hush.git
Changes to handle the use of \r as newline on the IIgs.
This commit is contained in:
parent
c8de71ae9d
commit
b3a419646b
|
@ -162,7 +162,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nflag) {
|
if (nflag) {
|
||||||
*out++ = '\n';
|
*out++ = NEWLINE_CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_write:
|
do_write:
|
||||||
|
@ -321,7 +321,7 @@ int echo_main(int argc, char **argv)
|
||||||
|
|
||||||
newline_ret:
|
newline_ret:
|
||||||
if (nflag) {
|
if (nflag) {
|
||||||
cur_io->iov_base = (char*)"\n";
|
cur_io->iov_base = (char*)NEWLINE_STR;
|
||||||
cur_io->iov_len = 1;
|
cur_io->iov_len = 1;
|
||||||
cur_io++;
|
cur_io++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,4 +510,14 @@ pid_t wait_emul (int *stat_loc);
|
||||||
# define waitpid(pid, stat_loc, options) waitpid_emul((pid), (stat_loc), (options))
|
# define waitpid(pid, stat_loc, options) waitpid_emul((pid), (stat_loc), (options))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNO__
|
||||||
|
# define NEWLINE_CHAR '\r'
|
||||||
|
# define NEWLINE_STR "\r"
|
||||||
|
# define IS_NEWLINE(ch) ((ch) == '\r' || (ch) == '\n')
|
||||||
|
#else
|
||||||
|
# define NEWLINE_CHAR '\n'
|
||||||
|
# define NEWLINE_STR "\n"
|
||||||
|
# define IS_NEWLINE(ch) ((ch) == '\n')
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,7 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, int *end)
|
||||||
linebuf[idx++] = (char) ch;
|
linebuf[idx++] = (char) ch;
|
||||||
if (ch == '\0')
|
if (ch == '\0')
|
||||||
break;
|
break;
|
||||||
if (end && ch == '\n')
|
if (end && IS_NEWLINE(ch))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (end)
|
if (end)
|
||||||
|
@ -55,7 +55,7 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file)
|
||||||
int i;
|
int i;
|
||||||
char *c = bb_get_chunk_from_file(file, &i);
|
char *c = bb_get_chunk_from_file(file, &i);
|
||||||
|
|
||||||
if (i && c[--i] == '\n')
|
if (i-- && IS_NEWLINE(c[i]))
|
||||||
c[i] = '\0';
|
c[i] = '\0';
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
@ -138,7 +138,7 @@ static char* xmalloc_fgets_internal(FILE *file, int *sizep)
|
||||||
/* stupid. fgets knows the len, it should report it somehow */
|
/* stupid. fgets knows the len, it should report it somehow */
|
||||||
len = strlen(&linebuf[idx]);
|
len = strlen(&linebuf[idx]);
|
||||||
idx += len;
|
idx += len;
|
||||||
if (len != 0xff || linebuf[idx - 1] == '\n')
|
if (len != 0xff || IS_NEWLINE(linebuf[idx - 1]))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*sizep = idx;
|
*sizep = idx;
|
||||||
|
@ -155,7 +155,7 @@ char* FAST_FUNC xmalloc_fgetline_fast(FILE *file)
|
||||||
{
|
{
|
||||||
int sz;
|
int sz;
|
||||||
char *r = xmalloc_fgets_internal(file, &sz);
|
char *r = xmalloc_fgets_internal(file, &sz);
|
||||||
if (r && r[sz - 1] == '\n')
|
if (r && IS_NEWLINE(r[sz - 1]))
|
||||||
r[--sz] = '\0';
|
r[--sz] = '\0';
|
||||||
return r; /* not xrealloc(r, sz + 1)! */
|
return r; /* not xrealloc(r, sz + 1)! */
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file)
|
||||||
char *r = xmalloc_fgets_internal(file, &sz);
|
char *r = xmalloc_fgets_internal(file, &sz);
|
||||||
if (!r)
|
if (!r)
|
||||||
return r;
|
return r;
|
||||||
if (r[sz - 1] == '\n')
|
if (IS_NEWLINE(r[sz - 1]))
|
||||||
r[--sz] = '\0';
|
r[--sz] = '\0';
|
||||||
return xrealloc(r, sz + 1);
|
return xrealloc(r, sz + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
smallint syslog_level = LOG_ERR;
|
smallint syslog_level = LOG_ERR;
|
||||||
#endif
|
#endif
|
||||||
smallint logmode = LOGMODE_STDIO;
|
smallint logmode = LOGMODE_STDIO;
|
||||||
const char *msg_eol = "\n";
|
const char *msg_eol = NEWLINE_STR;
|
||||||
|
|
||||||
extern const char *applet_name;
|
extern const char *applet_name;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
|
||||||
/* +3 is for ": " before strerr and for terminating NUL */
|
/* +3 is for ": " before strerr and for terminating NUL */
|
||||||
msg1 = realloc(msg, applet_len + used + strerr_len + msgeol_len + 3);
|
msg1 = realloc(msg, applet_len + used + strerr_len + msgeol_len + 3);
|
||||||
if (!msg1) {
|
if (!msg1) {
|
||||||
msg[used++] = '\n'; /* overwrites NUL */
|
msg[used++] = NEWLINE_CHAR; /* overwrites NUL */
|
||||||
applet_len = 0;
|
applet_len = 0;
|
||||||
} else {
|
} else {
|
||||||
msg = msg1;
|
msg = msg1;
|
||||||
|
|
|
@ -228,6 +228,10 @@ off_t FAST_FUNC fdlength(int fd)
|
||||||
|
|
||||||
int FAST_FUNC bb_putchar_stderr(char ch)
|
int FAST_FUNC bb_putchar_stderr(char ch)
|
||||||
{
|
{
|
||||||
|
#ifdef __GNO__
|
||||||
|
if (ch == '\n')
|
||||||
|
ch = '\r';
|
||||||
|
#endif
|
||||||
return write(STDERR_FILENO, &ch, 1);
|
return write(STDERR_FILENO, &ch, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
shell/hush.c
28
shell/hush.c
|
@ -2196,7 +2196,7 @@ static void get_user_input(struct in_str *i)
|
||||||
# else
|
# else
|
||||||
do {
|
do {
|
||||||
G.flag_SIGINT = 0;
|
G.flag_SIGINT = 0;
|
||||||
if (i->last_char == '\0' || i->last_char == '\n') {
|
if (i->last_char == '\0' || IS_NEWLINE(i->last_char)) {
|
||||||
/* Why check_and_run_traps here? Try this interactively:
|
/* Why check_and_run_traps here? Try this interactively:
|
||||||
* $ trap 'echo INT' INT; (sleep 2; kill -INT $$) &
|
* $ trap 'echo INT' INT; (sleep 2; kill -INT $$) &
|
||||||
* $ <[enter], repeatedly...>
|
* $ <[enter], repeatedly...>
|
||||||
|
@ -3618,7 +3618,7 @@ static char *fetch_till_str(o_string *as_string,
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
if (ch != EOF)
|
if (ch != EOF)
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
if ((ch == '\n' || ch == EOF)
|
if ((IS_NEWLINE(ch) || ch == EOF)
|
||||||
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
|
||||||
) {
|
) {
|
||||||
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
if (strcmp(heredoc.data + past_EOL, word) == 0) {
|
||||||
|
@ -3626,7 +3626,7 @@ static char *fetch_till_str(o_string *as_string,
|
||||||
debug_printf_parse(("parsed heredoc '%s'\n", heredoc.data));
|
debug_printf_parse(("parsed heredoc '%s'\n", heredoc.data));
|
||||||
return heredoc.data;
|
return heredoc.data;
|
||||||
}
|
}
|
||||||
while (ch == '\n') {
|
while (IS_NEWLINE(ch)) {
|
||||||
o_addchr(&heredoc, ch);
|
o_addchr(&heredoc, ch);
|
||||||
prev = ch;
|
prev = ch;
|
||||||
jump_in:
|
jump_in:
|
||||||
|
@ -3749,7 +3749,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
|
||||||
nommu_addchr(&ctx->as_string, ch);
|
nommu_addchr(&ctx->as_string, ch);
|
||||||
do
|
do
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
while (ch == ' ' || ch == '\t' || ch == '\n');
|
while (ch == ' ' || ch == '\t' || IS_NEWLINE(ch));
|
||||||
if (ch != '{') {
|
if (ch != '{') {
|
||||||
syntax_error_unexpected_ch(ch);
|
syntax_error_unexpected_ch(ch);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -3782,7 +3782,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
|
||||||
} else {
|
} else {
|
||||||
/* bash does not allow "{echo...", requires whitespace */
|
/* bash does not allow "{echo...", requires whitespace */
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
if (ch != ' ' && ch != '\t' && ch != '\n') {
|
if (ch != ' ' && ch != '\t' && !IS_NEWLINE(ch)) {
|
||||||
syntax_error_unexpected_ch(ch);
|
syntax_error_unexpected_ch(ch);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -4245,7 +4245,7 @@ static int encode_string(o_string *as_string,
|
||||||
return 0; /* error */
|
return 0; /* error */
|
||||||
}
|
}
|
||||||
next = '\0';
|
next = '\0';
|
||||||
if (ch != '\n') {
|
if (!IS_NEWLINE(ch)) {
|
||||||
next = i_peek(input);
|
next = i_peek(input);
|
||||||
}
|
}
|
||||||
debug_printf_parse(("\" ch=%c (%d) escape=%d\n",
|
debug_printf_parse(("\" ch=%c (%d) escape=%d\n",
|
||||||
|
@ -4263,9 +4263,9 @@ static int encode_string(o_string *as_string,
|
||||||
* NB: in (unquoted) heredoc, above does not apply to ",
|
* NB: in (unquoted) heredoc, above does not apply to ",
|
||||||
* therefore we check for it by "next == dquote_end" cond.
|
* therefore we check for it by "next == dquote_end" cond.
|
||||||
*/
|
*/
|
||||||
if (next == dquote_end || strchr("$`\\\n", next)) {
|
if (next == dquote_end || strchr("$`\\\n" NEWLINE_STR, next)) {
|
||||||
ch = i_getch(input); /* eat next */
|
ch = i_getch(input); /* eat next */
|
||||||
if (ch == '\n')
|
if (IS_NEWLINE(ch))
|
||||||
goto again; /* skip \<newline> */
|
goto again; /* skip \<newline> */
|
||||||
} /* else: ch remains == '\\', and we double it below: */
|
} /* else: ch remains == '\\', and we double it below: */
|
||||||
o_addqchr(dest, ch); /* \c if c is a glob char, else just c */
|
o_addqchr(dest, ch); /* \c if c is a glob char, else just c */
|
||||||
|
@ -4388,7 +4388,7 @@ static struct pipe *parse_stream(char **pstring,
|
||||||
nommu_addchr(&ctx.as_string, ch);
|
nommu_addchr(&ctx.as_string, ch);
|
||||||
|
|
||||||
next = '\0';
|
next = '\0';
|
||||||
if (ch != '\n')
|
if (!IS_NEWLINE(ch))
|
||||||
next = i_peek(input);
|
next = i_peek(input);
|
||||||
|
|
||||||
is_special = "{}<>;&|()#'" /* special outside of "str" */
|
is_special = "{}<>;&|()#'" /* special outside of "str" */
|
||||||
|
@ -4428,7 +4428,7 @@ static struct pipe *parse_stream(char **pstring,
|
||||||
if (done_word(&dest, &ctx)) {
|
if (done_word(&dest, &ctx)) {
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
}
|
}
|
||||||
if (ch == '\n') {
|
if (IS_NEWLINE(ch)) {
|
||||||
/* Is this a case when newline is simply ignored?
|
/* Is this a case when newline is simply ignored?
|
||||||
* Some examples:
|
* Some examples:
|
||||||
* "cmd | <newline> cmd ..."
|
* "cmd | <newline> cmd ..."
|
||||||
|
@ -4597,7 +4597,7 @@ static struct pipe *parse_stream(char **pstring,
|
||||||
/* skip "#comment" */
|
/* skip "#comment" */
|
||||||
while (1) {
|
while (1) {
|
||||||
ch = i_peek(input);
|
ch = i_peek(input);
|
||||||
if (ch == EOF || ch == '\n')
|
if (ch == EOF || IS_NEWLINE(ch))
|
||||||
break;
|
break;
|
||||||
i_getch(input);
|
i_getch(input);
|
||||||
/* note: we do not add it to &ctx.as_string */
|
/* note: we do not add it to &ctx.as_string */
|
||||||
|
@ -4607,7 +4607,7 @@ static struct pipe *parse_stream(char **pstring,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
if (next == '\n') {
|
if (IS_NEWLINE(next)) {
|
||||||
/* It's "\<newline>" */
|
/* It's "\<newline>" */
|
||||||
#if !BB_MMU
|
#if !BB_MMU
|
||||||
/* Remove trailing '\' from ctx.as_string */
|
/* Remove trailing '\' from ctx.as_string */
|
||||||
|
@ -5918,7 +5918,7 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
|
||||||
if (pipe_list == ERR_PTR && end_trigger == ';') {
|
if (pipe_list == ERR_PTR && end_trigger == ';') {
|
||||||
/* Discard cached input (rest of line) */
|
/* Discard cached input (rest of line) */
|
||||||
int ch = inp->last_char;
|
int ch = inp->last_char;
|
||||||
while (ch != EOF && ch != '\n') {
|
while (ch != EOF && !IS_NEWLINE(ch)) {
|
||||||
//bb_error_msg("Discarded:'%c'", ch);
|
//bb_error_msg("Discarded:'%c'", ch);
|
||||||
ch = i_getch(inp);
|
ch = i_getch(inp);
|
||||||
}
|
}
|
||||||
|
@ -6107,7 +6107,7 @@ static int process_command_subs(o_string *dest, const char *s)
|
||||||
setup_file_in_str(&pipe_str, fp);
|
setup_file_in_str(&pipe_str, fp);
|
||||||
eol_cnt = 0;
|
eol_cnt = 0;
|
||||||
while ((ch = i_getch(&pipe_str)) != EOF) {
|
while ((ch = i_getch(&pipe_str)) != EOF) {
|
||||||
if (ch == '\n') {
|
if (IS_NEWLINE(ch)) {
|
||||||
eol_cnt++;
|
eol_cnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
|
||||||
continue;
|
continue;
|
||||||
if (backslash) {
|
if (backslash) {
|
||||||
backslash = 0;
|
backslash = 0;
|
||||||
if (c != '\n')
|
if (!IS_NEWLINE(c))
|
||||||
goto put;
|
goto put;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
|
||||||
backslash = 1;
|
backslash = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '\n')
|
if (IS_NEWLINE(c))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* $IFS splitting. NOT done if we run "read"
|
/* $IFS splitting. NOT done if we run "read"
|
||||||
|
|
Loading…
Reference in New Issue