From ce18e01f2c7cbaee283c7f05fe1296d39e9f6746 Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 1 Aug 2006 14:10:25 +0000 Subject: [PATCH] move promptlen from edit.c into lex.c --- edit.c | 42 +----------------------------------------- lex.c | 41 ++++++++++++++++++++++++++++++++++++++++- sh.h | 3 ++- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/edit.c b/edit.c index 60b5169..7ca7fb2 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.25 2006/08/01 14:09:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.26 2006/08/01 14:10:24 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -30,7 +30,6 @@ void x_flush(void); void x_putc(int); void x_puts(const u_char *); bool x_mode(bool); -int promptlen(const char *, const char **); int x_do_comment(char *, int, int *); void x_print_expansions(int, char *const *, int); int x_cf_glob(int, const char *, int, int, int *, int *, char ***, int *); @@ -225,45 +224,6 @@ x_mode(bool onoff) return prev; } -int -promptlen(const char *cp, const char **spp) -{ - int count = 0; - const char *sp = cp; - char delimiter = 0; - int indelimit = 0; - - /* Undocumented AT&T ksh feature: - * If the second char in the prompt string is \r then the first char - * is taken to be a non-printing delimiter and any chars between two - * instances of the delimiter are not considered to be part of the - * prompt length - */ - if (*cp && cp[1] == '\r') { - delimiter = *cp; - cp += 2; - } - for (; *cp; cp++) { - if (indelimit && *cp != delimiter) - ; - else if (*cp == '\n' || *cp == '\r') { - count = 0; - sp = cp + 1; - } else if (*cp == '\t') { - count = (count | 7) + 1; - } else if (*cp == '\b') { - if (count > 0) - count--; - } else if (*cp == delimiter) - indelimit = !indelimit; - else - count++; - } - if (spp) - *spp = sp; - return count; -} - /* ------------------------------------------------------------------------- */ /* Misc common code for vi/emacs */ diff --git a/lex.c b/lex.c index b2a7a62..32621b1 100644 --- a/lex.c +++ b/lex.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.15 2006/08/01 14:09:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.16 2006/08/01 14:10:25 tg Exp $"); /* Structure to keep track of the lexing state and the various pieces of info * needed for each particular state. */ @@ -1093,6 +1093,45 @@ pprompt(const char *cp, int ntruncate) shf_flush(shl_out); } +int +promptlen(const char *cp, const char **spp) +{ + int count = 0; + const char *sp = cp; + char delimiter = 0; + int indelimit = 0; + + /* Undocumented AT&T ksh feature: + * If the second char in the prompt string is \r then the first char + * is taken to be a non-printing delimiter and any chars between two + * instances of the delimiter are not considered to be part of the + * prompt length + */ + if (*cp && cp[1] == '\r') { + delimiter = *cp; + cp += 2; + } + for (; *cp; cp++) { + if (indelimit && *cp != delimiter) + ; + else if (*cp == '\n' || *cp == '\r') { + count = 0; + sp = cp + 1; + } else if (*cp == '\t') { + count = (count | 7) + 1; + } else if (*cp == '\b') { + if (count > 0) + count--; + } else if (*cp == delimiter) + indelimit = !indelimit; + else + count++; + } + if (spp) + *spp = sp; + return count; +} + /* Read the variable part of a ${...} expression (ie, up to but not including * the :[-+?=#%] or close-brace. */ diff --git a/sh.h b/sh.h index 7670ff5..1eab8b5 100644 --- a/sh.h +++ b/sh.h @@ -8,7 +8,7 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.29 2006/08/01 14:09:20 tg Exp $" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.30 2006/08/01 14:10:25 tg Exp $" #include @@ -1081,6 +1081,7 @@ void yyerror(const char *, ...) Source * pushs(int, Area *); void set_prompt(int, Source *); void pprompt(const char *, int); +int promptlen(const char *, const char **); /* main.c */ int include(const char *, int, char **, int); int command(const char *);