Changes to handle the use of \r as newline on the IIgs.

This commit is contained in:
Stephen Heumann 2014-11-08 19:58:11 -06:00
parent c8de71ae9d
commit b3a419646b
7 changed files with 39 additions and 25 deletions

View File

@ -162,7 +162,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
}
if (nflag) {
*out++ = '\n';
*out++ = NEWLINE_CHAR;
}
do_write:
@ -321,7 +321,7 @@ int echo_main(int argc, char **argv)
newline_ret:
if (nflag) {
cur_io->iov_base = (char*)"\n";
cur_io->iov_base = (char*)NEWLINE_STR;
cur_io->iov_len = 1;
cur_io++;
}

View File

@ -510,4 +510,14 @@ pid_t wait_emul (int *stat_loc);
# define waitpid(pid, stat_loc, options) waitpid_emul((pid), (stat_loc), (options))
#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

View File

@ -24,7 +24,7 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, int *end)
linebuf[idx++] = (char) ch;
if (ch == '\0')
break;
if (end && ch == '\n')
if (end && IS_NEWLINE(ch))
break;
}
if (end)
@ -55,7 +55,7 @@ char* FAST_FUNC xmalloc_fgetline(FILE *file)
int i;
char *c = bb_get_chunk_from_file(file, &i);
if (i && c[--i] == '\n')
if (i-- && IS_NEWLINE(c[i]))
c[i] = '\0';
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 */
len = strlen(&linebuf[idx]);
idx += len;
if (len != 0xff || linebuf[idx - 1] == '\n')
if (len != 0xff || IS_NEWLINE(linebuf[idx - 1]))
break;
}
*sizep = idx;
@ -155,7 +155,7 @@ char* FAST_FUNC xmalloc_fgetline_fast(FILE *file)
{
int sz;
char *r = xmalloc_fgets_internal(file, &sz);
if (r && r[sz - 1] == '\n')
if (r && IS_NEWLINE(r[sz - 1]))
r[--sz] = '\0';
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);
if (!r)
return r;
if (r[sz - 1] == '\n')
if (IS_NEWLINE(r[sz - 1]))
r[--sz] = '\0';
return xrealloc(r, sz + 1);
}

View File

@ -15,7 +15,7 @@
smallint syslog_level = LOG_ERR;
#endif
smallint logmode = LOGMODE_STDIO;
const char *msg_eol = "\n";
const char *msg_eol = NEWLINE_STR;
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 */
msg1 = realloc(msg, applet_len + used + strerr_len + msgeol_len + 3);
if (!msg1) {
msg[used++] = '\n'; /* overwrites NUL */
msg[used++] = NEWLINE_CHAR; /* overwrites NUL */
applet_len = 0;
} else {
msg = msg1;

View File

@ -228,6 +228,10 @@ off_t FAST_FUNC fdlength(int fd)
int FAST_FUNC bb_putchar_stderr(char ch)
{
#ifdef __GNO__
if (ch == '\n')
ch = '\r';
#endif
return write(STDERR_FILENO, &ch, 1);
}

View File

@ -2196,7 +2196,7 @@ static void get_user_input(struct in_str *i)
# else
do {
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:
* $ trap 'echo INT' INT; (sleep 2; kill -INT $$) &
* $ <[enter], repeatedly...>
@ -3618,7 +3618,7 @@ static char *fetch_till_str(o_string *as_string,
ch = i_getch(input);
if (ch != EOF)
nommu_addchr(as_string, ch);
if ((ch == '\n' || ch == EOF)
if ((IS_NEWLINE(ch) || ch == EOF)
&& ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\')
) {
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));
return heredoc.data;
}
while (ch == '\n') {
while (IS_NEWLINE(ch)) {
o_addchr(&heredoc, ch);
prev = ch;
jump_in:
@ -3749,7 +3749,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
nommu_addchr(&ctx->as_string, ch);
do
ch = i_getch(input);
while (ch == ' ' || ch == '\t' || ch == '\n');
while (ch == ' ' || ch == '\t' || IS_NEWLINE(ch));
if (ch != '{') {
syntax_error_unexpected_ch(ch);
return 1;
@ -3782,7 +3782,7 @@ static int parse_group(o_string *dest, struct parse_context *ctx,
} else {
/* bash does not allow "{echo...", requires whitespace */
ch = i_getch(input);
if (ch != ' ' && ch != '\t' && ch != '\n') {
if (ch != ' ' && ch != '\t' && !IS_NEWLINE(ch)) {
syntax_error_unexpected_ch(ch);
return 1;
}
@ -4245,7 +4245,7 @@ static int encode_string(o_string *as_string,
return 0; /* error */
}
next = '\0';
if (ch != '\n') {
if (!IS_NEWLINE(ch)) {
next = i_peek(input);
}
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 ",
* 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 */
if (ch == '\n')
if (IS_NEWLINE(ch))
goto again; /* skip \<newline> */
} /* else: ch remains == '\\', and we double it below: */
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);
next = '\0';
if (ch != '\n')
if (!IS_NEWLINE(ch))
next = i_peek(input);
is_special = "{}<>;&|()#'" /* special outside of "str" */
@ -4428,7 +4428,7 @@ static struct pipe *parse_stream(char **pstring,
if (done_word(&dest, &ctx)) {
goto parse_error;
}
if (ch == '\n') {
if (IS_NEWLINE(ch)) {
/* Is this a case when newline is simply ignored?
* Some examples:
* "cmd | <newline> cmd ..."
@ -4597,7 +4597,7 @@ static struct pipe *parse_stream(char **pstring,
/* skip "#comment" */
while (1) {
ch = i_peek(input);
if (ch == EOF || ch == '\n')
if (ch == EOF || IS_NEWLINE(ch))
break;
i_getch(input);
/* note: we do not add it to &ctx.as_string */
@ -4607,7 +4607,7 @@ static struct pipe *parse_stream(char **pstring,
}
break;
case '\\':
if (next == '\n') {
if (IS_NEWLINE(next)) {
/* It's "\<newline>" */
#if !BB_MMU
/* 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 == ';') {
/* Discard cached input (rest of line) */
int ch = inp->last_char;
while (ch != EOF && ch != '\n') {
while (ch != EOF && !IS_NEWLINE(ch)) {
//bb_error_msg("Discarded:'%c'", ch);
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);
eol_cnt = 0;
while ((ch = i_getch(&pipe_str)) != EOF) {
if (ch == '\n') {
if (IS_NEWLINE(ch)) {
eol_cnt++;
continue;
}

View File

@ -227,7 +227,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
continue;
if (backslash) {
backslash = 0;
if (c != '\n')
if (!IS_NEWLINE(c))
goto put;
continue;
}
@ -235,7 +235,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
backslash = 1;
continue;
}
if (c == '\n')
if (IS_NEWLINE(c))
break;
/* $IFS splitting. NOT done if we run "read"