/*
 * compile command: g++ -I/usr/include/qt -L/usr/X11R6/lib read2clip.cpp -lqt -lX11
 */

#include <qapp.h>
#include <qclipboard.h>
#include <string>
#include <strstream>
#include <iostream>

class MyApp : public QApplication
{
  Q_OBJECT;

public:
  MyApp(int &argc, char **argv);
 public slots:
   void clipChanged();
};

MyApp::MyApp(int &argc, char **argv)
  : QApplication(argc, argv)
{
}

void MyApp::clipChanged()
{
  quit();
}

#include "meta-code.cpp"

int main( int argc, char **argv )
{
    MyApp a( argc, argv );

    QObject::connect( (const QObject *) a.clipboard(), SIGNAL(dataChanged()), (const QObject *) &a, SLOT(clipChanged()) );


    strstreambuf s;
    while (cin) {
      cin >> &s;
      if (!cin.fail())
	break;
    }
    s.sputc('\0');
    s.freeze();

    a.clipboard()->setText(s.str());
    return a.exec();
}
