move promptlen from edit.c into lex.c

This commit is contained in:
tg 2006-08-01 14:10:25 +00:00
parent c504a42ac1
commit ce18e01f2c
3 changed files with 43 additions and 43 deletions

42
edit.c
View File

@ -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 */

41
lex.c
View File

@ -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.
*/

3
sh.h
View File

@ -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 <sys/param.h>
@ -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 *);