summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-10-08 21:07:04 +0000
committerRoy Marples <roy@marples.name>2008-10-08 21:07:04 +0000
commitc4e673edbc2b2a804e3d8374e3f87a30f87041b8 (patch)
tree2a9f301023693dbf2663d75fae20e184c6609cf1 /src
parenta872fe5590e8f49695d7ce5a6449af4200c953f9 (diff)
downloadopenrc-c4e673edbc2b2a804e3d8374e3f87a30f87041b8.tar.gz
openrc-c4e673edbc2b2a804e3d8374e3f87a30f87041b8.tar.bz2
openrc-c4e673edbc2b2a804e3d8374e3f87a30f87041b8.tar.xz
Add a better, but incomplete tgoto implementation to make gcc happy.
Diffstat (limited to 'src')
-rw-r--r--src/libeinfo/libeinfo.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/libeinfo/libeinfo.c b/src/libeinfo/libeinfo.c
index 66b6dbc..12ca368 100644
--- a/src/libeinfo/libeinfo.c
+++ b/src/libeinfo/libeinfo.c
@@ -306,11 +306,65 @@ is_verbose(void)
/* Fake tgoto call - very crapy, but works for our needs */
#ifndef HAVE_TERMCAP
static char *
-tgoto(const char *cap, int a, int b)
+tgoto(const char *cap, int col, int line)
{
static char buf[20];
+ char *p, *e, c, dbuf[6];
+ int oncol = 0, which = line, i;
+
+ p = buf;
+ e = p + sizeof(buf);
+ while ((c = *cap++)) {
+ if (c != '%' || ((c = *cap++) == '%')) {
+ *p++ = c;
+ if (p >= e) {
+ errno = E2BIG;
+ return NULL;
+ }
+ continue;
+ }
+ switch (c) {
+ case '3':
+ case '2':
+ case 'd':
+ i = 0;
+ do
+ dbuf[i++] = which % 10 | '0';
+ while ((which /= 10));
+ if (c != 'd') {
+ c -= '0';
+ if (i > c) {
+ errno = EINVAL;
+ return NULL;
+ }
+ while (i < c)
+ dbuf[i++] = '0';
+ }
+ if (p + i >= e) {
+ errno = E2BIG;
+ return NULL;
+ }
+ do
+ *p++ = dbuf[--i];
+ while (i);
+ break;
+ case 'r':
+ oncol = 0;
+ break;
+ case 'i':
+ col++;
+ line++;
+ which++;
+ continue;
+ default:
+ errno = EINVAL;
+ return NULL;
+ }
- snprintf(buf, sizeof(buf), cap, b, a);
+ oncol = 1 - oncol;
+ which = oncol ? col : line;
+ }
+ *p = '\0';
return buf;
}
#endif