libConsole/cross_getch.c
author Markus Bröker<broeker.markus@googlemail.com>
Sat, 21 Oct 2017 13:45:05 +0200
changeset 171 c6e0af68825a
parent 134 8325a0fc22cd
permissions -rw-r--r--
Entrypoint and RET fixed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 69
diff changeset
     1
/**
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 69
diff changeset
     2
 * libConsole/cross_getch.c
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 69
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 69
diff changeset
     4
 */
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 69
diff changeset
     5
53
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <jni.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <Console.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#ifdef WIN32
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
#include <conio.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
134
8325a0fc22cd simple corrections
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 93
diff changeset
    13
static int cross_getch ()
53
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
    int ch = -1;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
69
b5912e5f899f Useless cross_getch hack removed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 53
diff changeset
    17
    ch = getch ();
53
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
    return ch;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
}
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
#else
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
#include <termios.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
93
66b3596f71b6 make cross_getch invisible
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
    25
static int cross_getch ()
53
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
    int ch = -1, fd = 0;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
    struct termios neu, alt;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    fd = fileno (stdin);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    tcgetattr (fd, &alt);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    neu = alt;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
    neu.c_lflag &= ~(ICANON | ECHO);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    tcsetattr (fd, TCSANOW, &neu);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
    ch = getchar ();
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
    tcsetattr (fd, TCSANOW, &alt);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
    return ch;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
}
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
#endif
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass)
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
    return cross_getch ();
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
}