-/* $NetBSD: io.c,v 1.26 2011/10/03 12:32:28 roy Exp $ */
+/* $NetBSD: io.c,v 1.29 2021/05/02 12:50:45 rillig Exp $ */
/*
* io.c Larn is copyrighted 1986 by Noah Morgan.
- *
+ *
* Below are the functions in this file:
- *
+ *
* setupvt100() Subroutine to set up terminal in correct mode for game
* clearvt100() Subroutine to clean up terminal when the game is over
* ttgetch() Routine to read in one character from the terminal
* scbr() Function to set cbreak -echo for the terminal
* sncbr() Function to set -cbreak echo for the terminal
* newgame() Subroutine to save the initial time and seed rnd()
- *
+ *
* FILE OUTPUT ROUTINES
- *
+ *
* lprintf(format,args . . .) printf to the output buffer lprint(integer)
* end binary integer to output buffer lwrite(buf,len)
* rite a buffer to the output buffer lprcat(str)
* ent string to output buffer
- *
+ *
* FILE OUTPUT MACROS (in header.h)
- *
+ *
* lprc(character) put the character into the output
* buffer
- *
+ *
* FILE INPUT ROUTINES
- *
+ *
* long lgetc() read one character from input buffer
* long larn_lrint() read one integer from input buffer
* lrfill(address,number) put input bytes into a buffer char
* *lgetw() get a whitespace ended word from
* input char *lgetl() get a \n or EOF ended line
* from input
- *
+ *
* FILE OPEN / CLOSE ROUTINES
- *
+ *
* lcreat(filename) create a new file for write
* lopen(filename) open a file for read
* lappend(filename) open for append to an existing file
* lrclose() close the input file
* lwclose() close output file lflush()
* lush the output buffer
- *
+ *
* Other Routines
- *
+ *
* cursor(x,y) position cursor at [x,y]
* cursors() position cursor at [1,24]
* (saves memory) cl_line(x,y) Clear line at [1,y] and leave
* erminal initialization -- setup termcap info * char *tmcapcnv(sd,ss)
* outine to convert VT100 \33's to termcap format beep()
* e to emit a beep if enabled (see no-beep in .larnopts)
- *
+ *
* Note: ** entries are available only in termcap mode.
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: io.c,v 1.26 2011/10/03 12:32:28 roy Exp $");
+__RCSID("$NetBSD: io.c,v 1.29 2021/05/02 12:50:45 rillig Exp $");
#endif /* not lint */
#include "header.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include <term.h>
#include <fcntl.h>
#include <errno.h>
* Attributes off, clear screen, set scrolling region, set tty mode
*/
void
-setupvt100()
+setupvt100(void)
{
clear();
setscroll();
* Attributes off, clear screen, unset scrolling region, restore tty mode
*/
void
-clearvt100()
+clearvt100(void)
{
resetscroll();
clear();
* ttgetch() Routine to read in one character from the terminal
*/
int
-ttgetch()
+ttgetch(void)
{
char byt;
#ifdef EXTRA
* like: system("stty cbreak -echo")
*/
void
-scbr()
+scbr(void)
{
gtty(0, &ttx);
doraw(ttx);
* like: system("stty -cbreak echo")
*/
void
-sncbr()
+sncbr(void)
{
gtty(0, &ttx);
unraw(ttx);
* newgame() Subroutine to save the initial time and seed rnd()
*/
void
-newgame()
+newgame(void)
{
long *p, *pe;
for (p = c, pe = c + 100; p < pe; *p++ = 0);
* Returns nothing of value.
*/
void
-lprint(x)
- long x;
+lprint(long x)
{
if (lpnt >= lpend)
lflush();
* Returns nothing of value
*/
void
-lwrite(buf, len)
- char *buf;
- int len;
+lwrite(char *buf, int len)
{
char *s;
u_char *t;
*
* Returns 0 if EOF, otherwise the character
*/
-long
-lgetc()
+long
+lgetc(void)
{
int i;
if (ipoint != iepoint)
* The save order is low order first, to high order (4 bytes total)
* Returns the int read
*/
-long
-larn_lrint()
+long
+larn_lrint(void)
{
unsigned long i;
i = 255 & lgetc();
* Returns nothing of value
*/
void
-lrfill(adr, num)
- char *adr;
- int num;
+lrfill(char *adr, int num)
{
u_char *pnt;
int num2;
* Returns pointer to a buffer that contains word. If EOF, returns a NULL
*/
char *
-lgetw()
+lgetw(void)
{
char *lgp, cc;
int n = LINBUFSIZE, quote = 0;
* Returns pointer to a buffer that contains the line. If EOF, returns NULL
*/
char *
-lgetl()
+lgetl(void)
{
int i = LINBUFSIZE, ch;
char *str = lgetwbuf;
* Returns -1 if error, otherwise the file descriptor opened.
*/
int
-lcreat(str)
- char *str;
+lcreat(char *str)
{
lflush();
lpnt = lpbuf;
* Returns -1 if error, otherwise the file descriptor opened.
*/
int
-lopen(str)
- char *str;
+lopen(char *str)
{
ipoint = iepoint = MAXIBUF;
if (str == NULL)
* Returns -1 if error, otherwise the file descriptor opened.
*/
int
-lappend(str)
- char *str;
+lappend(char *str)
{
lpnt = lpbuf;
lpend = lpbuf + BUFBIG;
* Returns nothing of value.
*/
void
-lrclose()
+lrclose(void)
{
if (io_infd > 0) {
close(io_infd);
* Returns nothing of value.
*/
void
-lwclose()
+lwclose(void)
{
lflush();
if (io_outfd > 2) {
* cursor(x,y) Put cursor at specified coordinates staring at [1,1] (termcap)
*/
void
-cursor(x, y)
- int x, y;
+cursor(int x, int y)
{
if (lpnt >= lpend)
lflush();
* Routine to position cursor at beginning of 24th line
*/
void
-cursors()
+cursors(void)
{
cursor(1, 24);
}
* init_term() Terminal initialization -- setup termcap info
*/
void
-init_term()
+init_term(void)
{
setupterm(NULL, 0, NULL); /* will exit if invalid term */
if (!cursor_address) {
* cl_line(x,y) Clear the whole line indicated by 'y' and leave cursor at [x,y]
*/
void
-cl_line(x, y)
- int x, y;
+cl_line(int x, int y)
{
#ifdef VT100
cursor(x, y);
* cl_up(x,y) Clear screen from [x,1] to current position. Leave cursor at [x,y]
*/
void
-cl_up(x, y)
- int x, y;
+cl_up(int x, int y)
{
#ifdef VT100
cursor(x, y);
* cl_dn(x,y) Clear screen from [1,y] to end of display. Leave cursor at [x,y]
*/
void
-cl_dn(x, y)
- int x, y;
+cl_dn(int x, int y)
{
#ifdef VT100
cursor(x, y);
* set_score_output() Called when output should be literally printed.
*/
void
-set_score_output()
+set_score_output(void)
{
enable_scroll = -1;
}
static int scrline = 18; /* line # for wraparound instead of scrolling
* if no DL */
void
-lflush()
+lflush(void)
{
int lpoint;
u_char *str;
/*
* ttputch(ch) Print one character in decoded output buffer.
*/
-static int
+static int
ttputch(int ch)
{
outbuf[vindex++] = ch;
* flush_buf() Flush buffer with decoded output.
*/
static void
-flush_buf()
+flush_buf(void)
{
if (vindex)
write(io_outfd, outbuf, vindex);
* Processes only the \33[#m sequence (converts . files for termcap use
*/
char *
-tmcapcnv(sd, ss)
- char *sd, *ss;
+tmcapcnv(char *sd, char *ss)
{
int tmstate = 0; /* 0=normal, 1=\33 2=[ 3=# */
char tmdigit = 0; /* the # in \33[#m */
* beep() Routine to emit a beep if enabled (see no-beep in .larnopts)
*/
void
-beep()
+beep(void)
{
if (!nobeep)
*lpnt++ = '\7';