libConsole/cross_getch.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:51:15 +0200
changeset 83 220d76d0d672
parent 77 49e0babccb23
child 93 66b3596f71b6
permissions -rw-r--r--
Platform Independend Newlines Java uses %n for platform independend newlines \r\n on windows, \n on linux and so on... committer: Markus Bröker <mbroeker@largo.homelinux.org>
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
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
int cross_getch ()
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
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
int cross_getch ()
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
}