mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
provide terminal emulation.
This commit is contained in:
parent
f0a1717ced
commit
0dbb04b425
7 changed files with 337 additions and 0 deletions
21
core/org.eclipse.cdt.core.solaris/library/PTY.h
Normal file
21
core/org.eclipse.cdt.core.solaris/library/PTY.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTY */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTY
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTY
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTY
|
||||
* Method: forkpty
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_pty_PTY_forkpty
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
32
core/org.eclipse.cdt.core.solaris/library/PTYInputStream.h
Normal file
32
core/org.eclipse.cdt.core.solaris/library/PTYInputStream.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTYInputStream */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE
|
||||
#define org_eclipse_cdt_utils_pty_PTYInputStream_SKIP_BUFFER_SIZE 2048L
|
||||
/* Inaccessible static: skipBuffer */
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: read0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
29
core/org.eclipse.cdt.core.solaris/library/PTYOutputStream.h
Normal file
29
core/org.eclipse.cdt.core.solaris/library/PTYOutputStream.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_eclipse_cdt_utils_pty_PTYOutputStream */
|
||||
|
||||
#ifndef _Included_org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
#define _Included_org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: write0
|
||||
* Signature: (I[BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0
|
||||
(JNIEnv *, jobject, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
107
core/org.eclipse.cdt.core.solaris/library/openpty.c
Normal file
107
core/org.eclipse.cdt.core.solaris/library/openpty.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stropts.h>
|
||||
|
||||
/**
|
||||
* This is taken from R. W. Stevens book.
|
||||
* Alain Magloire.
|
||||
*/
|
||||
|
||||
int ptym_open (char *pts_name);
|
||||
int ptys_open (int fdm, char * pts_name);
|
||||
|
||||
int
|
||||
openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp)
|
||||
{
|
||||
char line[20];
|
||||
line[0]=0;
|
||||
*amaster = ptym_open(line);
|
||||
if (*amaster < 0)
|
||||
return -1;
|
||||
*aslave = ptys_open(*amaster, line);
|
||||
if (*aslave < 0) {
|
||||
close(*amaster);
|
||||
return -1;
|
||||
}
|
||||
if (name)
|
||||
strcpy(name, line);
|
||||
#ifndef TCSAFLUSH
|
||||
#define TCSAFLUSH TCSETAF
|
||||
#endif
|
||||
if (termp)
|
||||
(void) tcsetattr(*aslave, TCSAFLUSH, termp);
|
||||
#ifdef TIOCSWINSZ
|
||||
if (winp)
|
||||
(void) ioctl(*aslave, TIOCSWINSZ, (char *)winp);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ptym_open(char * pts_name)
|
||||
{
|
||||
int fdm;
|
||||
char *ptr;
|
||||
|
||||
strcpy(pts_name, "/dev/ptmx");
|
||||
fdm = open(pts_name, O_RDWR);
|
||||
if (fdm < 0)
|
||||
return -1;
|
||||
if (fdm < 0)
|
||||
return -1;
|
||||
if (grantpt(fdm) < 0) { /* grant access to slave */
|
||||
close(fdm);
|
||||
return -2;
|
||||
}
|
||||
if (unlockpt(fdm) < 0) { /* clear slave's lock flag */
|
||||
close(fdm);
|
||||
return -3;
|
||||
}
|
||||
ptr = ptsname(fdm);
|
||||
if (ptr == NULL) { /* get slave's name */
|
||||
close (fdm);
|
||||
return -4;
|
||||
}
|
||||
strcpy(pts_name, ptr); /* return name of slave */
|
||||
return fdm; /* return fd of master */
|
||||
}
|
||||
|
||||
int
|
||||
ptys_open(int fdm, char * pts_name)
|
||||
{
|
||||
int fds;
|
||||
/* following should allocate controlling terminal */
|
||||
fds = open(pts_name, O_RDWR);
|
||||
if (fds < 0) {
|
||||
close(fdm);
|
||||
return -5;
|
||||
}
|
||||
if (ioctl(fds, I_PUSH, "ptem") < 0) {
|
||||
printf("pterm:%s\n", strerror(errno));
|
||||
close(fdm);
|
||||
close(fds);
|
||||
return -6;
|
||||
}
|
||||
if (ioctl(fds, I_PUSH, "ldterm") < 0) {
|
||||
printf("ldterm %s\n", strerror(errno));
|
||||
close(fdm);
|
||||
close(fds);
|
||||
return -7;
|
||||
}
|
||||
return fds;
|
||||
}
|
10
core/org.eclipse.cdt.core.solaris/library/openpty.h
Normal file
10
core/org.eclipse.cdt.core.solaris/library/openpty.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
#ifndef _OPENPTY_H
|
||||
#define _OPENPTY_H
|
||||
int ptym_open (char *pts_name);
|
||||
int ptys_open (int fdm, char * pts_name);
|
||||
#endif
|
35
core/org.eclipse.cdt.core.solaris/library/pty.c
Normal file
35
core/org.eclipse.cdt.core.solaris/library/pty.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "PTY.h"
|
||||
#include "openpty.h"
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTY
|
||||
* Method: forkpty
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTY_forkpty (JNIEnv *env, jobject jobj) {
|
||||
jfieldID fid; /* Store the field ID */
|
||||
jstring jstr = NULL;
|
||||
int master = -1;
|
||||
char line[1024]; /* FIXME: Should be enough */
|
||||
jclass cls;
|
||||
|
||||
line[0] = '\0';
|
||||
|
||||
master = ptym_open(line);
|
||||
if (master >= 0) {
|
||||
/* Get a reference to the obj's class */
|
||||
cls = (*env)->GetObjectClass(env, jobj);
|
||||
|
||||
/* Set the master fd. */
|
||||
fid = (*env)->GetFieldID(env, cls, "master", "I");
|
||||
if (fid == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(*env)->SetIntField(env, jobj, fid, (jint)master);
|
||||
|
||||
/* Create a new String for the slave. */
|
||||
jstr = (*env)->NewStringUTF(env, line);
|
||||
}
|
||||
return jstr;
|
||||
}
|
103
core/org.eclipse.cdt.core.solaris/library/ptyio.c
Normal file
103
core/org.eclipse.cdt.core.solaris/library/ptyio.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <PTYInputStream.h>
|
||||
#include <PTYOutputStream.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Header for class _org_eclipse_cdt_utils_pty_PTYInputStream */
|
||||
/* Header for class _org_eclipse_cdt_utils_pty_PTYOutputStream */
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: read0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYInputStream_read0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int fd;
|
||||
int status;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = read( fd, data, data_len );
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
if (status == 0) {
|
||||
/* EOF. */
|
||||
status = -1;
|
||||
} else if (status == -1) {
|
||||
/* Error, toss an exception */
|
||||
jclass exception = (*env)->FindClass(env, "java/io/IOException");
|
||||
if (exception == NULL) {
|
||||
/* Give up. */
|
||||
return -1;
|
||||
}
|
||||
(*env)->ThrowNew(env, exception, "read error");
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYInputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYInputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: write0
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYOutputStream_write0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint jfd,
|
||||
jbyteArray buf,
|
||||
jint buf_len)
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
jbyte *data;
|
||||
int data_len;
|
||||
|
||||
data = (*env)->GetByteArrayElements(env, buf, 0);
|
||||
data_len = buf_len;
|
||||
fd = jfd;
|
||||
|
||||
status = write(fd, data, data_len);
|
||||
(*env)->ReleaseByteArrayElements(env, buf, data, 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_eclipse_cdt_utils_pty_PTYOutputStream
|
||||
* Method: close0
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eclipse_cdt_utils_pty_PTYOutputStream_close0(JNIEnv * env,
|
||||
jobject jobj,
|
||||
jint fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
Loading…
Add table
Reference in a new issue