#include <termcap.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <string.h>
#include <curses.h>
#include "curspriv.h"
/* fatal - report error and die. Never returns */
void fatal(char *s)
{
- (void) fprintf(stderr, "curses: %s\n", s);
+ write(2, "curses: ", 8);
+ write(2, s, strlen(s));
+ write(2, "\n", 1);
exit(1);
}
/* Outc - call putchar, necessary because putchar is a macro. */
-void outc(int c)
+int outc(int c)
{
- putchar(c);
+ return putchar(c);
}
/* Move cursor to r,c */
'>', '<', 'v', '^', '#', ':', ' ', '#', '+', '\'', '#', '+', '+',
'+', '+', '+', '-', ' ', '-', ' ', '_', '+', '+', '+', '+', '|'
};
-char _cursident[28] = "+,.-0ahI`fgjklmnopqrstuvwx~";
+unsigned char _cursident[28] = "+,.-0ahI`fgjklmnopqrstuvwx~";
int setterm(char *type)
{
/* Time to optimize than to do things directly. */
/****************************************************************/
-_PROTOTYPE(static void gotoxy, (int row, int col ));
-_PROTOTYPE(static void newattr, (int ch ));
-_PROTOTYPE(static void Putchar, (int ch ));
-_PROTOTYPE(static void clrupdate, (WINDOW *scr ));
-_PROTOTYPE(static void transformline, (int lineno ));
+static void gotoxy(int row, int col );
+static void newattr(int ch );
+static void Putchar(int ch );
+static void clrupdate(WINDOW *scr );
+static void transformline(int lineno);
static void gotoxy(int row, int col)
{
/* Putchar() writes a character, with attributes, to the physical
screen, but avoids writing to the lower right screen position.
Should it care about am?
+
+ FIXME: try and move away from sucking in stdio in curses and in
+ termcap
*/
/* Output char with attribute */
/* Updates the screen to look like curscr. */
/****************************************************************/
-void doupdate()
+void doupdate(void)
{
int i;
#include "curspriv.h"
#include <termcap.h>
-int endwin()
+int endwin(void)
{
extern char *me;
#include <curses.h>
#include "curspriv.h"
-WINDOW *initscr()
+WINDOW *initscr(void)
{
char *term;
/* Actual lines themselves. */
/****************************************************************/
-_PROTOTYPE(static WINDOW *makenew, (int nlines, int ncols, int begy,int begx));
-
static WINDOW *makenew(int num_lines, int num_columns, int begy, int begx)
{
int i;
--- /dev/null
+#include <string.h>
+#include <curses.h>
+#include "curspriv.h"
+
+extern char __printscanbuf[513]; /* buffer used during I/O */
+
+/****************************************************************/
+/* Wprintw(win,fmt,args) does a printf() in window 'win'. */
+/****************************************************************/
+int wprintw(WINDOW *win, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(__printscanbuf, sizeof(__printscanbuf), fmt, args);
+ if (waddstr(win, __printscanbuf) == ERR) return(ERR);
+ return(strlen(__printscanbuf));
+}
+
+/****************************************************************/
+/* Printw(fmt,args) does a printf() in stdscr. */
+/****************************************************************/
+int printw(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(__printscanbuf, sizeof(__printscanbuf), fmt, args);
+ if (waddstr(stdscr, __printscanbuf) == ERR) return(ERR);
+ return(strlen(__printscanbuf));
+} /* printw */
+
+/****************************************************************/
+/* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */
+/* tion, then does a printf() in stdscr. */
+/****************************************************************/
+int mvprintw(int y, int x, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if (wmove(stdscr, y, x) == ERR) return(ERR);
+ vsnprintf(__printscanbuf, sizeof(__printscanbuf), fmt, args);
+ if (waddstr(stdscr, __printscanbuf) == ERR) return(ERR);
+ return(strlen(__printscanbuf));
+}
+
+/****************************************************************/
+/* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */
+/* A new position, then does a printf() in window 'win'. */
+/****************************************************************/
+int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if (wmove(win, y, x) == ERR) return(ERR);
+ vsnprintf(__printscanbuf, sizeof(__printscanbuf), fmt, args);
+ if (waddstr(win, __printscanbuf) == ERR) return(ERR);
+ return(strlen(__printscanbuf));
+} /* mvwprintw */
#include <curses.h>
#include "curspriv.h"
-static char printscanbuf[513]; /* buffer used during I/O */
+/* These functions are expensive so keep them in their own files and
+ don't suck them in for anything else.
+
+ Really we should probably use the internal snprintf helpers and
+ remove the length limit and buffer but that's a FIXME */
-/****************************************************************/
-/* Wprintw(win,fmt,args) does a printf() in window 'win'. */
-/****************************************************************/
-int wprintw(WINDOW *win, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- vsprintf(printscanbuf, fmt, args);
- if (waddstr(win, printscanbuf) == ERR) return(ERR);
- return(strlen(printscanbuf));
-}
-
-/****************************************************************/
-/* Printw(fmt,args) does a printf() in stdscr. */
-/****************************************************************/
-int printw(const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- vsprintf(printscanbuf, fmt, args);
- if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
- return(strlen(printscanbuf));
-} /* printw */
-
-/****************************************************************/
-/* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */
-/* tion, then does a printf() in stdscr. */
-/****************************************************************/
-int mvprintw(int y, int x, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- if (wmove(stdscr, y, x) == ERR) return(ERR);
- vsprintf(printscanbuf, fmt, args);
- if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
- return(strlen(printscanbuf));
-}
-
-/****************************************************************/
-/* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */
-/* A new position, then does a printf() in window 'win'. */
-/****************************************************************/
-int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- if (wmove(win, y, x) == ERR) return(ERR);
- vsprintf(printscanbuf, fmt, args);
- if (waddstr(win, printscanbuf) == ERR) return(ERR);
- return(strlen(printscanbuf));
-} /* mvwprintw */
-
-/****************************************************************/
-/* Wscanw(win,fmt,args) gets a string via window 'win', then */
-/* Scans the string using format 'fmt' to extract the values */
-/* And put them in the variables pointed to the arguments. */
-/****************************************************************/
-int wscanw(WINDOW *win, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- wrefresh(win); /* set cursor */
- if (wgetstr(win, printscanbuf) == ERR) /* get string */
- return(ERR);
- return(vsscanf(printscanbuf, fmt, args));
-} /* wscanw */
-
-/****************************************************************/
-/* Scanw(fmt,args) gets a string via stdscr, then scans the */
-/* String using format 'fmt' to extract the values and put them */
-/* In the variables pointed to the arguments. */
-/****************************************************************/
-int scanw(const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- wrefresh(stdscr); /* set cursor */
- if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
- return(ERR);
- return(vsscanf(printscanbuf, fmt, args));
-} /* scanw */
-
-/****************************************************************/
-/* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */
-/* Tion, then gets a string via stdscr and scans the string */
-/* Using format 'fmt' to extract the values and put them in the */
-/* Variables pointed to the arguments. */
-/****************************************************************/
-int mvscanw(int y, int x, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- if (wmove(stdscr, y, x) == ERR) return(ERR);
- wrefresh(stdscr); /* set cursor */
- if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
- return(ERR);
- return(vsscanf(printscanbuf, fmt, args));
-} /* mvscanw */
-
-/****************************************************************/
-/* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */
-/* New position, then gets a string via 'win' and scans the */
-/* String using format 'fmt' to extract the values and put them */
-/* In the variables pointed to the arguments. */
-/****************************************************************/
-int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- if (wmove(win, y, x) == ERR) return(ERR);
- wrefresh(win); /* set cursor */
- if (wgetstr(win, printscanbuf) == ERR) /* get string */
- return(ERR);
- return(vsscanf(printscanbuf, fmt, args));
-} /* mvwscanw */
+char __printscanbuf[513]; /* buffer used during I/O */
--- /dev/null
+#include <string.h>
+#include <curses.h>
+#include "curspriv.h"
+
+extern char __printscanbuf[513]; /* buffer used during I/O */
+
+/****************************************************************/
+/* Wscanw(win,fmt,args) gets a string via window 'win', then */
+/* Scans the string using format 'fmt' to extract the values */
+/* And put them in the variables pointed to the arguments. */
+/****************************************************************/
+int wscanw(WINDOW *win, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ wrefresh(win); /* set cursor */
+ if (wgetstr(win, __printscanbuf) == ERR) /* get string */
+ return(ERR);
+ return(vsscanf(__printscanbuf, fmt, args));
+} /* wscanw */
+
+/****************************************************************/
+/* Scanw(fmt,args) gets a string via stdscr, then scans the */
+/* String using format 'fmt' to extract the values and put them */
+/* In the variables pointed to the arguments. */
+/****************************************************************/
+int scanw(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ wrefresh(stdscr); /* set cursor */
+ if (wgetstr(stdscr, __printscanbuf) == ERR) /* get string */
+ return(ERR);
+ return(vsscanf(__printscanbuf, fmt, args));
+} /* scanw */
+
+/****************************************************************/
+/* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */
+/* Tion, then gets a string via stdscr and scans the string */
+/* Using format 'fmt' to extract the values and put them in the */
+/* Variables pointed to the arguments. */
+/****************************************************************/
+int mvscanw(int y, int x, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if (wmove(stdscr, y, x) == ERR) return(ERR);
+ wrefresh(stdscr); /* set cursor */
+ if (wgetstr(stdscr, __printscanbuf) == ERR) /* get string */
+ return(ERR);
+ return(vsscanf(__printscanbuf, fmt, args));
+} /* mvscanw */
+
+/****************************************************************/
+/* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */
+/* New position, then gets a string via 'win' and scans the */
+/* String using format 'fmt' to extract the values and put them */
+/* In the variables pointed to the arguments. */
+/****************************************************************/
+int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ if (wmove(win, y, x) == ERR) return(ERR);
+ wrefresh(win); /* set cursor */
+ if (wgetstr(win, __printscanbuf) == ERR) /* get string */
+ return(ERR);
+ return(vsscanf(__printscanbuf, fmt, args));
+} /* mvwscanw */
#include <curses.h>
#include "curspriv.h"
-_PROTOTYPE( static void ttysetflags, (void) );
-
-static void ttysetflags()
+static void ttysetflags(void)
{
_tty.c_iflag |= ICRNL | IXON;
_tty.c_oflag |= OPOST | ONLCR;
tcsetattr(0, TCSANOW, &_tty);
} /* ttysetflags */
-void raw()
+void raw(void)
{
_cursvar.rawmode = TRUE;
ttysetflags();
} /* raw */
-void noraw()
+void noraw(void)
{
_cursvar.rawmode = FALSE;
ttysetflags();
} /* noraw */
-void echo()
+void echo(void)
{
_cursvar.echoit = TRUE;
ttysetflags();
}
-void noecho()
+void noecho(void)
{
_cursvar.echoit = FALSE;
ttysetflags();
}
-void nl()
+void nl(void)
{
NONL = FALSE;
ttysetflags();
} /* nl */
-void nonl()
+void nonl(void)
{
NONL = TRUE;
ttysetflags();
} /* nonl */
-void cbreak()
+void cbreak(void)
{
_cursvar.cbrkmode = TRUE;
ttysetflags();
} /* cbreak */
-void nocbreak()
+void nocbreak(void)
{
_cursvar.cbrkmode = FALSE;
ttysetflags();
+++ /dev/null
-/* tparam.c
- * Merge parameters into a termcap entry string.
- * Copyright (C) 1985, 1987, 1993 Free Software Foundation, Inc.
- */
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <malloc.h>
-#include <termcap.h>
-
-static void memory_out __P((void));
-static char *xmalloc __P((unsigned size));
-static char *xrealloc __P((char *ptr, unsigned size));
-static char *tparam1 __P((char *string, char *outstring, int len, char *up, char *left, int *argp));
-
-static void memory_out() {
- write(2, "virtual memory exhausted\n", 25);
- exit(1);
-}
-
-static char *xmalloc(unsigned size)
-{
- register char *tem = malloc(size);
-
- if (!tem)
- memory_out();
- return tem;
-}
-
-static char *xrealloc(char *ptr, unsigned size)
-{
- register char *tem = realloc(ptr, size);
-
- if (!tem)
- memory_out();
- return tem;
-}
-
-/* Assuming STRING is the value of a termcap string entry
- containing `%' constructs to expand parameters,
- merge in parameter values and store result in block OUTSTRING points to.
- LEN is the length of OUTSTRING. If more space is needed,
- a block is allocated with `malloc'.
-
- The value returned is the address of the resulting string.
- This may be OUTSTRING or may be the address of a block got with `malloc'.
- In the latter case, the caller must free the block.
-
- The fourth and following args to tparam serve as the parameter values.
- */
-/* VARARGS 2 */
-char * tparam(char *string, char *outstring, int len, int arg0, int arg1, int arg2,int arg3)
-{
-#ifdef NO_ARG_ARRAY
- int arg[4];
- arg[0] = arg0;
- arg[1] = arg1;
- arg[2] = arg2;
- arg[3] = arg3;
- return tparam1(string, outstring, len, NULL, NULL, arg);
-#else
- (void)arg1; (void)arg2; (void)arg3;
- return tparam1(string, outstring, len, NULL, NULL, &arg0);
-#endif
-}
-
-char *BC;
-char *UP;
-
-static char tgoto_buf[50];
-
-char *tgoto(char *cm, int hpos, int vpos)
-{
- int args[2];
-
- if (!cm)
- return NULL;
- args[0] = vpos;
- args[1] = hpos;
- return tparam1(cm, tgoto_buf, 50, UP, BC, args);
-}
-
-static char *tparam1(char *string, char *outstring, int len, char *up, char *left, register int *argp)
-{
- register int c, tem;
- register char *p = string;
- register char *op = outstring;
- int *old_argp = argp;
- int outlen = 0;
- int doleft = 0;
- int doup = 0;
- char *outend = outstring + len;
-
- while (1) {
- /* If the buffer might be too short, make it bigger. */
- if (op + 5 >= outend) {
- register char *new;
- if (outlen == 0) {
- outlen = len + 40;
- new = (char *) xmalloc(outlen);
- outend += 40;
- memcpy(new, outstring, op - outstring);
- }
- else {
- outend += outlen;
- outlen *= 2;
- new = (char *) xrealloc(outstring, outlen);
- }
- op += new -outstring;
- outend += new -outstring;
- outstring = new;
- }
- c = *p++;
- if (!c)
- break;
- if (c == '%') {
- c = *p++;
- tem = *argp;
- switch (c) {
- case 'd': /* %d means output in decimal. */
- if (tem < 10)
- goto onedigit;
- if (tem < 100)
- goto twodigit;
- case '3': /* %3 means output in decimal, 3 digits. */
- if (tem > 999) {
- *op++ = tem / 1000 + '0';
- tem %= 1000;
- }
- *op++ = tem / 100 + '0';
- case '2': /* %2 means output in decimal, 2 digits. */
-twodigit:
- tem %= 100;
- *op++ = tem / 10 + '0';
-onedigit:
- *op++ = tem % 10 + '0';
- argp++;
- break;
-
- case 'C':
- /* For c-100: print quotient of value by 96, if
- * nonzero, then do like %+. */
- if (tem >= 96) {
- *op++ = tem / 96;
- tem %= 96;
- }
- case '+': /* %+x means add character code of char x. */
- tem += *p++;
- case '.': /* %. means output as character. */
- if (left) {
- /* If want to forbid output of 0 and \n and
- * \t, and this is one of them, increment
- * it. */
- while (tem == 0 || tem == '\n' || tem == '\t') {
- tem++;
- if (argp == old_argp)
- doup++, outend -= strlen(up);
- else
- doleft++, outend -= strlen(left);
- }
- }
- *op++ = tem ? tem : 0200;
- case 'f': /* %f means discard next arg. */
- argp++;
- break;
-
- case 'b': /* %b means back up one arg (and re-use
- * it). */
- argp--;
- break;
-
- case 'r': /* %r means interchange following two args. */
- argp[0] = argp[1];
- argp[1] = tem;
- old_argp++;
- break;
-
- case '>': /* %>xy means if arg is > char code of x, */
- if (argp[0] > *p++) /* then add char code of y
- * to the arg, */
- argp[0] += *p; /* and in any case don't
- * output. */
- p++; /* Leave the arg to be output later. */
- break;
-
- case 'a': /* %a means arithmetic. */
- /* Next character says what operation. Add or
- * subtract either a constant or some other arg. */
- /* First following character is + to add or - to
- * subtract or = to assign. */
- /* Next following char is 'p' and an arg spec (0100
- * plus position of that arg relative to this one)
- * or 'c' and a constant stored in a character. */
- tem = p[2] & 0177;
- if (p[1] == 'p')
- tem = argp[tem - 0100];
- if (p[0] == '-')
- argp[0] -= tem;
- else if (p[0] == '+')
- argp[0] += tem;
- else if (p[0] == '*')
- argp[0] *= tem;
- else if (p[0] == '/')
- argp[0] /= tem;
- else
- argp[0] = tem;
-
- p += 3;
- break;
-
- case 'i': /* %i means add one to arg, */
- argp[0]++; /* and leave it to be output later. */
- argp[1]++; /* Increment the following arg,
- * too! */
- break;
-
- case '%': /* %% means output %; no arg. */
- goto ordinary;
-
- case 'n': /* %n means xor each of next two args with
- * 140. */
- argp[0] ^= 0140;
- argp[1] ^= 0140;
- break;
-
- case 'm': /* %m means xor each of next two args with
- * 177. */
- argp[0] ^= 0177;
- argp[1] ^= 0177;
- break;
-
- case 'B': /* %B means express arg as BCD char code. */
- argp[0] += 6 * (tem / 10);
- break;
-
- case 'D': /* %D means weird Delta Data
- * transformation. */
- argp[0] -= 2 * (tem % 16);
- break;
- }
- }
- else
- /* Ordinary character in the argument string. */
-ordinary:
- *op++ = c;
- }
- *op = 0;
- while (doup-- > 0)
- strcat(op, up);
- while (doleft-- > 0)
- strcat(op, left);
- return outstring;
-}
-
-#ifdef TEST
-
-int main(int argc, char **argv)
-{
- char buf[50];
- int args[3];
-
- args[0] = atoi(argv[2]);
- args[1] = atoi(argv[3]);
- args[2] = atoi(argv[4]);
- tparam1(argv[1], buf, 50, "LEFT", "UP", args);
- printf("%s\n", buf);
- return 0;
-}
-#endif /* DEBUG */
-\1a
/* If error, return -1. */
/****************************************************************/
-_PROTOTYPE( static short newline, (WINDOW *win, int lin));
-
static short newline(WINDOW *win, int lin)
{
if (++lin > win->_regbottom) {