bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Working with the selection buffer


From: Sadrul H Chowdhury
Subject: Working with the selection buffer
Date: Sat, 14 Oct 2006 22:44:17 -0400

Hi.

I am trying to work with the selection buffer of the terminal from my ncurses application. I want to be able to copy some text into the buffer. From what I've been able to find, it looks like I need to use 'ioctl'. So that's what I do (code to follow), and it looks like it does work in TTYs, at least to some extent. However, it does not work in any of the X terminals (mrxvt, urxvt, xterm etc.). Can anyone please tell me what I am missing?

/* START CODE */

#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>

int main()
{
  /* Copied from gpm.c */
  unsigned char buf[6 * sizeof(short)];
  unsigned short *arg = (unsigned short *)buf + 1;

  buf[sizeof(short)-1] = 2;

  arg[0]=(unsigned short)1;
  arg[1]=(unsigned short)2;
  arg[2]=(unsigned short)3;
  arg[3]=(unsigned short)4;
  arg[4]=(unsigned short)1;

  int fd = 1;
    /* XXX: Perhaps I need to open(terminal, O_WRONLY)?
     *      In which case, what's "terminal"? */
  if (ioctl(fd, TIOCLINUX, buf+sizeof(short)-1) < 0) {
    printf("can't ioctl\n");
    switch (errno) {
      case EBADF:
        printf("invalid file desc\n");
        break;
      case EFAULT:
        printf("argp\n");
        break;
      case EINVAL:
        printf("invalid argp\n");
        break;
      case ENOTTY:
        printf("invalid tty\n");
        break;
      default:
        printf("unknown: %d\n", errno);
        break;
    }
  }
  close(fd);

  return 0;
}

/* END CODE */

The error I get from X terminals is "invalid argp".

I am using 1 as the file-descriptor argument to ioctl. Should I use something else? Is there any way I can find out the file descriptor for the current terminal from my application?

Or better yet, is there a better way of doing what I want to do?

Thanks.
Sadrul

reply via email to

[Prev in Thread] Current Thread [Next in Thread]