From dd022e72aa85bd3b7f786a25653f42be5f8b8464 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 1 Oct 2015 19:25:49 +0100 Subject: [PATCH] termcap: paste in the escaped tgoto --- Library/libs/termcap.c | 60 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/Library/libs/termcap.c b/Library/libs/termcap.c index 9816eccf..a0182824 100644 --- a/Library/libs/termcap.c +++ b/Library/libs/termcap.c @@ -260,13 +260,71 @@ char *tgetstr(char *id, char **area) } /* end for(;;) */ } +/* + * tgoto - given the cursor motion string cm, make up the string + * for the cursor to go to (destcol, destline), and return the string. + * Returns "OOPS" if something's gone wrong, or the string otherwise. + */ + +char *tgoto(const char *cm, int destcol, int destline) +{ + static char ret[24]; + char *rp = ret; + int incr = 0; + int argno = 0; + int numval; + + for (; *cm; cm++) { + if (*cm == '%') { + switch (*++cm) { + case 'i': + incr = 1; + break; + case 'r': + argno = 1; + break; + case '+': + numval = (argno == 0 ? destline : destcol); + *rp++ = numval + incr + *++cm; + argno = 1 - argno; + break; + case '2': + numval = (argno == 0 ? destline : destcol); + numval = (numval + incr) % 100; + *rp++ = '0' + (numval / 10); + *rp++ = '0' + (numval % 10); + argno = 1 - argno; + break; + case 'd': + numval = (argno == 0 ? destline : destcol); + numval = (numval + incr) % 1000; + if (numval > 99) + *rp++ = '0' + (numval / 100); + if (numval > 9) + *rp++ = '0' + (numval / 10) % 10; + *rp++ = '0' + (numval % 10); + argno = 1 - argno; + break; + case '%': + *rp++ = '%'; + break; + default: + return("OOPS"); + } + } + else + *rp++ = *cm; + } + *rp = '\0'; + return ret; +} + /* * tputs - put the string cp out onto the terminal, using the function * outc. This should do padding for the terminal, but I can't find a * terminal that needs padding at the moment... */ - int tputs(const char *cp, int affcnt, int (*outc)(int ch)) { if (cp == (char *) NULL) -- 2.34.1