1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* LEVEE, or Captain Video; A vi clone
*
* Copyright (c) 1982-2007 David L Parsons
* All rights reserved.
*
* Redistribution and use in source and binary forms, without or
* without modification, are permitted provided that the above
* copyright notice and this paragraph are duplicated in all such
* forms and that any documentation, advertising materials, and
* other materials related to such distribution and use acknowledge
* that the software was developed by David L Parsons (orc@pell.chi.il.us).
* My name may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/*
* Unix interface for levee
*/
#include "levee.h"
#ifdef OS_UNIX
#include "extern.h"
#include <termios.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ioctl.h>
#if USE_TERMCAP
#include <termcap.h>
#endif
int
min(a,b)
int a, b;
{
return (a>b) ? b : a;
}
int
max(a,b)
int a, b;
{
return (a<b) ? b : a;
}
void strput(s)
char *s;
{
#if USE_TERMCAP
if (s)
tputs(s, 1, putchar);
#else
if (s)
write(1, s, strlen(s));
#endif
}
#if !HAVE_BASENAME
char *
basename(s)
char *s;
{
char *rindex();
char *p;
if (p=strrchr(s,'/'))
return 1+p;
return s;
}
#endif
#if !HAVE_TCGETATTR
#define tcgetattr(fd,t) ioctl(fd, TCGETS, t)
#define tcsetattr(fd,n,t) ioctl(fd, n, t)
#define TCSANOW TCSETAF
#endif
static int ioset = 0;
static struct termios old;
void
initcon()
{
struct termios new;
if (!ioset) {
tcgetattr(0, &old); /* get editing keys */
Erasechar = old.c_cc[VERASE];
eraseline = old.c_cc[VKILL];
new = old;
new.c_iflag &= ~(IXON|IXOFF|IXANY|ICRNL|INLCR);
new.c_lflag &= ~(ICANON|ISIG|ECHO);
new.c_oflag = 0;
tcsetattr(0, TCSANOW, &new);
ioset=1;
}
}
void
fixcon()
{
if (ioset) {
tcsetattr(0, TCSANOW, &old);
ioset = 0;
}
}
int
getKey()
{
unsigned char c[1];
fd_set input;
fflush(stdout);
/* we're using Unix select() to wait for input, so lets hope that
* all the Unices out there support select(). If your Unix doesn't,
* you can make this work by replacing this select loop with:
*
* while (read(0,c,1) != 1)
* ;
* return c[1];
*
* ... and watch your load-average peg.
*/
while (1) {
FD_ZERO(&input);
FD_SET(0, &input);
select(1, &input, 0, 0, 0);
if( read(0,c,1) == 1)
return c[0];
};
}
#endif
|