home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d166
/
stevie.lha
/
Stevie
/
source
/
amiga.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-22
|
4KB
|
251 lines
/*
* Amiga system-dependent routines.
*/
#include "stevie.h"
long stdin_file_handle = 0;
int
GetCharacter()
{
char c;
Read(stdin_file_handle, &c, sizeof(c));
return ((int) c);
}
/*
* getCSIsequence - get a CSI sequence
* - either cursor keys, help, functionkeys, or some
* other sequence (if other, check window size)
*/
int
getCSIsequence()
{
int c;
int param1;
int param2;
c = GetCharacter();
if (isdigit(c)) {
param1 = 0;
while (isdigit(c)) {
param1 = param1 * 10 + c - '0';
c = GetCharacter();
}
if (c == '~') /* function key */
return ((char) (K_F1 + param1));
/* must be an event of some sort or a window bound report */
if (c == ';') {
param2 = 0;
c = GetCharacter();
while (isdigit(c)) {
param2 = param2 * 10 + c - '0';
c = GetCharacter();
}
if (c == ';') {
param1 = 0;
c = GetCharacter();
while (isdigit(c)) {
param1 = param1 * 10 + c - '0';
c = GetCharacter();
}
if (c == ';') {
param2 = 0;
c = GetCharacter();
while (isdigit(c)) {
param2 = param2 * 10 + c - '0';
c = GetCharacter();
}
if (c == ' ') {
c = GetCharacter();
if (c == 'r') {
if (param1 < 2)
param1 = 2;
if (param2 < 5)
param2 = 5;
if (Columns != param2 || Rows != param1) {
Columns = param2;
Rows = param1;
P(P_LI) = Rows;
return (-1);
} else
return 0;
}
}
}
}
}
while ((c != '|') && (c != '~'))
c = GetCharacter();
outstr("\033[0 q");
fflush(stdout); /* flush out the window size request */
return 0;
}
switch (c) {
case 'A': /* cursor up */
return K_UARROW;
case 'B': /* cursor down */
return K_DARROW;
case 'C': /* cursor right */
return K_RARROW;
case 'D': /* cursor left */
return K_LARROW;
case 'T': /* shift cursor up */
return K_SUARROW;
case 'S': /* shift cursor down */
return K_SDARROW;
case ' ': /* shift cursor left or right */
c = GetCharacter();
if (c == 'A') /* shift cursor left */
return K_SLARROW;
if (c == '@') /* shift cursor right */
return K_SRARROW;
break;
case '?': /* help */
c = GetCharacter();
if (c == '~')
return K_HELP;
break;
}
return 0; /* some other control code */
}
/*
* inchar() - get a character from the keyboard
*/
char
inchar()
{
int c;
fflush(stdout); /* flush any pending output */
for (;;) {
c = GetCharacter();
if (c != 0x9b)
break;
c = getCSIsequence();
if (c > 0)
break;
if (c == -1) {
screenalloc();
screenclear();
updateNextscreen();
updateRealscreen();
msg("");
cursupdate();
windgoto(Cursrow, Curscol);
fflush(stdout);
}
}
return (char) c;
}
void
outstr(s)
char *s;
{
while (*s)
outchar(*s++);
}
void
beep()
{
if (RedrawingDisabled)
return;
outchar('\007');
}
void
sleep(n)
int n;
{
void Delay();
if (n > 0)
Delay(50L * n);
}
void
delay()
{
void Delay();
Delay(25L);
}
void
windinit()
{
stdin_file_handle = Input();
if (!IsInteractive(stdin_file_handle)) {
fprintf(stderr, "stdin is not interactive ?!?!?!?");
exit(2);
}
Columns = 80;
P(P_LI) = Rows = 24;
if (raw(stdin) != 0)
perror("raw");
outstr("\033[12{"); /* window resize events activated */
outstr("\033[0 q"); /* get window size */
fflush(stdout);
for (;;) {
if (GetCharacter() == 0x9b)
if (getCSIsequence() == -1)
break;
}
}
void
windexit(r)
int r;
{
outstr("\033[12}"); /* window resize events de-activated */
fflush(stdout); /* flush any pending output */
if (cooked(stdin) != 0)
perror("cooked");
exit(r);
}
void
windgoto(r, c)
int c;
int r;
{
r++;
c++;
outstr("\033[");
if (r >= 10)
outchar((char) (r / 10 + '0'));
outchar((char) (r % 10 + '0'));
outchar(';');
if (c >= 10)
outchar((char) (c / 10 + '0'));
outchar((char) (c % 10 + '0'));
outchar('H');
}
FILE *
fopenb(fname, mode)
char *fname;
char *mode;
{
FILE *fopen();
char modestr[16];
sprintf(modestr, "%sb", mode);
return fopen(fname, modestr);
}