# HG changeset patch # User Jacob Dawid # Date 1302333773 -7200 # Node ID 9d5e5da5a2979feb6d14a26a1f2b0a46e91aa5fd # Parent 7519e2efaf31021cd0a4efc071b94aa9c4b76efe Everything compiles again. diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//Quint.pro --- a/gui//Quint.pro Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//Quint.pro Sat Apr 09 09:22:53 2011 +0200 @@ -81,6 +81,6 @@ LFLAGS = $$system(mkoctfile -p LFLAGS) \ $$system(mkoctfile -p OCTAVE_LIBS) \ $$system(mkoctfile -p LIBS) -LIBS += $$LFLAGS -loctave -loctinterp -lreadline +LIBS += $$LFLAGS -loctave -loctinterp -lreadline -lutil QMAKE_CXXFLAGS += $$INCFLAGS diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/Pty.cpp --- a/gui//src/Pty.cpp Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/Pty.cpp Sat Apr 09 09:22:53 2011 +0200 @@ -19,7 +19,7 @@ */ // Own -#include "kprocess.h" +#include "kprocess_p.h" #include "kptyprocess.h" #include "Pty.h" diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kprocess.h --- a/gui//src/kprocess.h Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kprocess.h Sat Apr 09 09:22:53 2011 +0200 @@ -25,8 +25,9 @@ #include "kdecore_export.h" #include +class KProcess; +class KProcessPrivate; -class KProcessPrivate; /** * \class KProcess kprocess.h @@ -337,5 +338,7 @@ Q_PRIVATE_SLOT(d_func(), void _k_forwardStderr()) }; +#include "kprocess_p.h" + #endif diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kprocess_p.h --- a/gui//src/kprocess_p.h Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kprocess_p.h Sat Apr 09 09:22:53 2011 +0200 @@ -21,9 +21,10 @@ #ifndef KPROCESS_P_H #define KPROCESS_P_H +class KProcess; +class KProcessPrivate; #include "kprocess.h" - class KProcessPrivate { Q_DECLARE_PUBLIC(KProcess) protected: diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kptydevice.cpp --- a/gui//src/kptydevice.cpp Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kptydevice.cpp Sat Apr 09 09:22:53 2011 +0200 @@ -57,177 +57,6 @@ # define PTY_BYTES_AVAILABLE FIONREAD #endif -#define KMAXINT ((int)(~0U >> 1)) - -///////////////////////////////////////////////////// -// Helper. Remove when QRingBuffer becomes public. // -///////////////////////////////////////////////////// - -#include -#include - -#define CHUNKSIZE 4096 - -class KRingBuffer -{ -public: - KRingBuffer() - { - clear(); - } - - void clear() - { - buffers.clear(); - QByteArray tmp; - tmp.resize(CHUNKSIZE); - buffers << tmp; - head = tail = 0; - totalSize = 0; - } - - inline bool isEmpty() const - { - return buffers.count() == 1 && !tail; - } - - inline int size() const - { - return totalSize; - } - - inline int readSize() const - { - return (buffers.count() == 1 ? tail : buffers.first().size()) - head; - } - - inline const char *readPointer() const - { - Q_ASSERT(totalSize > 0); - return buffers.first().constData() + head; - } - - void free(int bytes) - { - totalSize -= bytes; - Q_ASSERT(totalSize >= 0); - - forever { - int nbs = readSize(); - - if (bytes < nbs) { - head += bytes; - if (head == tail && buffers.count() == 1) { - buffers.first().resize(CHUNKSIZE); - head = tail = 0; - } - break; - } - - bytes -= nbs; - if (buffers.count() == 1) { - buffers.first().resize(CHUNKSIZE); - head = tail = 0; - break; - } - - buffers.removeFirst(); - head = 0; - } - } - - char *reserve(int bytes) - { - totalSize += bytes; - - char *ptr; - if (tail + bytes <= buffers.last().size()) { - ptr = buffers.last().data() + tail; - tail += bytes; - } else { - buffers.last().resize(tail); - QByteArray tmp; - tmp.resize(qMax(CHUNKSIZE, bytes)); - ptr = tmp.data(); - buffers << tmp; - tail = bytes; - } - return ptr; - } - - // release a trailing part of the last reservation - inline void unreserve(int bytes) - { - totalSize -= bytes; - tail -= bytes; - } - - inline void write(const char *data, int len) - { - memcpy(reserve(len), data, len); - } - - // Find the first occurrence of c and return the index after it. - // If c is not found until maxLength, maxLength is returned, provided - // it is smaller than the buffer size. Otherwise -1 is returned. - int indexAfter(char c, int maxLength = KMAXINT) const - { - int index = 0; - int start = head; - QLinkedList::ConstIterator it = buffers.begin(); - forever { - if (!maxLength) - return index; - if (index == size()) - return -1; - const QByteArray &buf = *it; - ++it; - int len = qMin((it == buffers.end() ? tail : buf.size()) - start, - maxLength); - const char *ptr = buf.data() + start; - if (const char *rptr = (const char *)memchr(ptr, c, len)) - return index + (rptr - ptr) + 1; - index += len; - maxLength -= len; - start = 0; - } - } - - inline int lineSize(int maxLength = KMAXINT) const - { - return indexAfter('\n', maxLength); - } - - inline bool canReadLine() const - { - return lineSize() != -1; - } - - int read(char *data, int maxLength) - { - int bytesToRead = qMin(size(), maxLength); - int readSoFar = 0; - while (readSoFar < bytesToRead) { - const char *ptr = readPointer(); - int bs = qMin(bytesToRead - readSoFar, readSize()); - memcpy(data + readSoFar, ptr, bs); - readSoFar += bs; - free(bs); - } - return readSoFar; - } - - int readLine(char *data, int maxLength) - { - return read(data, lineSize(qMin(maxLength, size()))); - } - -private: - QLinkedList buffers; - int head, tail; - int totalSize; -}; - ////////////////// // private data // ////////////////// @@ -247,30 +76,6 @@ #define NO_INTR(ret,func) do { ret = func; } while (ret < 0 && errno == EINTR) -struct KPtyDevicePrivate : public KPtyPrivate { - Q_DECLARE_PUBLIC(KPtyDevice) - - KPtyDevicePrivate(KPty* parent) : - KPtyPrivate(parent), - emittedReadyRead(false), emittedBytesWritten(false), - readNotifier(0), writeNotifier(0) - { - } - - bool _k_canRead(); - bool _k_canWrite(); - - bool doWait(int msecs, bool reading); - void finishOpen(QIODevice::OpenMode mode); - - bool emittedReadyRead; - bool emittedBytesWritten; - QSocketNotifier *readNotifier; - QSocketNotifier *writeNotifier; - KRingBuffer readBuffer; - KRingBuffer writeBuffer; -}; - bool KPtyDevicePrivate::_k_canRead() { Q_Q(KPtyDevice); diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kptydevice.h --- a/gui//src/kptydevice.h Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kptydevice.h Sat Apr 09 09:22:53 2011 +0200 @@ -21,11 +21,13 @@ #ifndef kptydev_h #define kptydev_h +struct KPtyPrivate; +struct KPtyDevicePrivate; + #include "kpty.h" - +#include "kpty_p.h" #include - -struct KPtyDevicePrivate; +#include #define Q_DECLARE_PRIVATE_MI(Class, SuperClass) \ inline Class##Private* d_func() { return reinterpret_cast(SuperClass::d_ptr); } \ @@ -152,5 +154,200 @@ Q_PRIVATE_SLOT(d_func(), bool _k_canWrite()) }; +#define KMAXINT ((int)(~0U >> 1)) + +///////////////////////////////////////////////////// +// Helper. Remove when QRingBuffer becomes public. // +///////////////////////////////////////////////////// + +#include +#include + +#define CHUNKSIZE 4096 + +class KRingBuffer +{ +public: + KRingBuffer() + { + clear(); + } + + void clear() + { + buffers.clear(); + QByteArray tmp; + tmp.resize(CHUNKSIZE); + buffers << tmp; + head = tail = 0; + totalSize = 0; + } + + inline bool isEmpty() const + { + return buffers.count() == 1 && !tail; + } + + inline int size() const + { + return totalSize; + } + + inline int readSize() const + { + return (buffers.count() == 1 ? tail : buffers.first().size()) - head; + } + + inline const char *readPointer() const + { + Q_ASSERT(totalSize > 0); + return buffers.first().constData() + head; + } + + void free(int bytes) + { + totalSize -= bytes; + Q_ASSERT(totalSize >= 0); + + forever { + int nbs = readSize(); + + if (bytes < nbs) { + head += bytes; + if (head == tail && buffers.count() == 1) { + buffers.first().resize(CHUNKSIZE); + head = tail = 0; + } + break; + } + + bytes -= nbs; + if (buffers.count() == 1) { + buffers.first().resize(CHUNKSIZE); + head = tail = 0; + break; + } + + buffers.removeFirst(); + head = 0; + } + } + + char *reserve(int bytes) + { + totalSize += bytes; + + char *ptr; + if (tail + bytes <= buffers.last().size()) { + ptr = buffers.last().data() + tail; + tail += bytes; + } else { + buffers.last().resize(tail); + QByteArray tmp; + tmp.resize(qMax(CHUNKSIZE, bytes)); + ptr = tmp.data(); + buffers << tmp; + tail = bytes; + } + return ptr; + } + + // release a trailing part of the last reservation + inline void unreserve(int bytes) + { + totalSize -= bytes; + tail -= bytes; + } + + inline void write(const char *data, int len) + { + memcpy(reserve(len), data, len); + } + + // Find the first occurrence of c and return the index after it. + // If c is not found until maxLength, maxLength is returned, provided + // it is smaller than the buffer size. Otherwise -1 is returned. + int indexAfter(char c, int maxLength = KMAXINT) const + { + int index = 0; + int start = head; + QLinkedList::ConstIterator it = buffers.begin(); + forever { + if (!maxLength) + return index; + if (index == size()) + return -1; + const QByteArray &buf = *it; + ++it; + int len = qMin((it == buffers.end() ? tail : buf.size()) - start, + maxLength); + const char *ptr = buf.data() + start; + if (const char *rptr = (const char *)memchr(ptr, c, len)) + return index + (rptr - ptr) + 1; + index += len; + maxLength -= len; + start = 0; + } + } + + inline int lineSize(int maxLength = KMAXINT) const + { + return indexAfter('\n', maxLength); + } + + inline bool canReadLine() const + { + return lineSize() != -1; + } + + int read(char *data, int maxLength) + { + int bytesToRead = qMin(size(), maxLength); + int readSoFar = 0; + while (readSoFar < bytesToRead) { + const char *ptr = readPointer(); + int bs = qMin(bytesToRead - readSoFar, readSize()); + memcpy(data + readSoFar, ptr, bs); + readSoFar += bs; + free(bs); + } + return readSoFar; + } + + int readLine(char *data, int maxLength) + { + return read(data, lineSize(qMin(maxLength, size()))); + } + +private: + QLinkedList buffers; + int head, tail; + int totalSize; +}; + +struct KPtyDevicePrivate : public KPtyPrivate { + Q_DECLARE_PUBLIC(KPtyDevice) + + KPtyDevicePrivate(KPty* parent) : + KPtyPrivate(parent), + emittedReadyRead(false), emittedBytesWritten(false), + readNotifier(0), writeNotifier(0) + { + } + + bool _k_canRead(); + bool _k_canWrite(); + + bool doWait(int msecs, bool reading); + void finishOpen(QIODevice::OpenMode mode); + + bool emittedReadyRead; + bool emittedBytesWritten; + QSocketNotifier *readNotifier; + QSocketNotifier *writeNotifier; + KRingBuffer readBuffer; + KRingBuffer writeBuffer; +}; + #endif diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kptyprocess.cpp --- a/gui//src/kptyprocess.cpp Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kptyprocess.cpp Sat Apr 09 09:22:53 2011 +0200 @@ -20,7 +20,7 @@ Boston, MA 02110-1301, USA. */ #include "kptyprocess.h" -#include "kprocess_p.h" +#include "kprocess.h" //#include #include "kptydevice.h" @@ -32,23 +32,7 @@ // private data // ////////////////// -struct KPtyProcessPrivate : KProcessPrivate { - KPtyProcessPrivate() : - ptyChannels(KPtyProcess::NoChannels), - addUtmp(false) - { - } - void _k_onStateChanged(QProcess::ProcessState newState) - { - if (newState == QProcess::NotRunning && addUtmp) - pty->logout(); - } - - KPtyDevice *pty; - KPtyProcess::PtyChannels ptyChannels; - bool addUtmp : 1; -}; KPtyProcess::KPtyProcess(QObject *parent) : KProcess(new KPtyProcessPrivate, parent) diff -r 7519e2efaf31 -r 9d5e5da5a297 gui//src/kptyprocess.h --- a/gui//src/kptyprocess.h Sat Apr 09 00:23:46 2011 +0200 +++ b/gui//src/kptyprocess.h Sat Apr 09 09:22:53 2011 +0200 @@ -23,12 +23,14 @@ #define KPTYPROCESS_H #include "kprocess.h" - +#include "kprocess_p.h" +#include "kptydevice.h" #include "kpty_export.h" class KPtyDevice; +class KPtyProcess; +struct KPtyProcessPrivate; -struct KPtyProcessPrivate; /** * This class extends KProcess by support for PTYs (pseudo TTYs). * @@ -133,6 +135,24 @@ Q_PRIVATE_SLOT(d_func(), void _k_onStateChanged(QProcess::ProcessState)) }; +struct KPtyProcessPrivate : KProcessPrivate { + KPtyProcessPrivate() : + ptyChannels(KPtyProcess::NoChannels), + addUtmp(false) + { + } + + void _k_onStateChanged(QProcess::ProcessState newState) + { + if (newState == QProcess::NotRunning && addUtmp) + pty->logout(); + } + + KPtyDevice *pty; + KPtyProcess::PtyChannels ptyChannels; + bool addUtmp : 1; +}; + Q_DECLARE_OPERATORS_FOR_FLAGS(KPtyProcess::PtyChannels) #endif