[Top][All Lists]

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

Re: libapl stdout

From: Chris Moller
Subject: Re: libapl stdout
Date: Fri, 27 Jan 2023 20:05:59 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

All of the code below is in the C++ language and std::string is a very basic bit of C++.  If you're not familiar with C++, the string class, stringstream, stringbuf, and so on, the first thing you need to do is get some experience in C++. 

There is no direct replacement for QString, but std::string is close.  See:

On 1/27/23 19:47, enztec@gmx.com wrote:
sorry that means nothing to me as to what to replace the qstring below with

On Fri, 27 Jan 2023 19:38:51 -0500
Chris Moller <moller@mollerware.com> wrote:

QString is mmore or less equivalent to the C++ std::string class.

On 1/27/23 18:00, enztec@gmx.com wrote:
what do i replace all the qstring with

/apl/libapl/c > grepi qstring

./aplexec.h:18:aplExec (apl_op_e apl_op, QString &cmd,
./aplexec.h:19:QString &outString, QString &errString);
./libaplc.c:12:AplExec::aplExec (apl_op_e apl_op, QString &cmd,
./libaplc.c:13:QString &outString, QString &errString)
./libaplc.c:29:outString = QString (outbuffer.str ().c_str ());
./libaplc.c:30:errString = QString (errbuffer.str ().c_str ());
./libaplc.c:40:outString = QString (res);
./libaplc.c:44:errString = QString (errbuffer.str ().c_str ());

On Fri, 27 Jan 2023 17:18:01 -0500
Chris Moller<moller@mollerware.com>  wrote:

Qt isn't necessary--that's just the environment I'm working in.  From my
example, get rid of the #include <QtWidgets>line.

Here's aplexec.h:

     #ifndef APLEXEC_H
     #define APLEXEC_H

     #include <QtWidgets>
     #include <apl/libapl.h>

     #define APL_VARIABLE "([⍙∆a-z][⍙∆_a-z0-9]*)"

     typedef enum {
     } apl_op_e;

     class AplExec
       static LIBAPL_error
       aplExec (apl_op_e apl_op, QString &cmd,
                QString &outString, QString &errString);
     #endif // APLEEXEC_H

Again, you don't need the Qt stuff.  Mostly, what you need is the

     #include <apl/libapl.h>

line.  And you probably don't need the #define APL_VARIABLE
"([⍙∆a-z][⍙∆_a-z0-9]*)" line

For this to work at all, you need to build Jürgen's APL twice, once as
usual to install apl itself, and a second time with

     ./configure --with-libapl
     make install

(with any other options you need on the configure)

What this does is put apl-related stuff in /usr/local/include and
/usr/local/lib.  (I think I manually copied Error.def from the apl
source tree into /usr/local/include--I don't think it gets copied with
the make install.)

On 1/27/23 16:28,enztec@gmx.com  wrote:

i don't have qt installed nor do i have your
#include "aplexec.h"

On Fri, 27 Jan 2023 11:23:08 -0500
Chris Moller<moller@mollerware.com>   wrote:

For what it's worth, in an ongoing project in use:

      #include <QtWidgets>

      #include <iostream>
      #include <sstream>

      #include <apl/libapl.h>

      #include "aplexec.h"

      AplExec::aplExec (apl_op_e apl_op, QString &cmd,
                 QString &outString, QString &errString)
        LIBAPL_error execerr = LAE_NO_ERROR;

        switch(apl_op) {
        case APL_OP_EXEC:
            std::stringstream outbuffer;
            std::streambuf *coutbuf = std::cout.rdbuf();
            std::stringstream errbuffer;
            std::streambuf *cerrbuf = std::cerr.rdbuf();
            execerr = apl_exec (cmd.toStdString ().c_str ());
            outString = QString (outbuffer.str ().c_str ());
            errString = QString (errbuffer.str ().c_str ());
        case APL_OP_COMMAND:
            std::stringstream errbuffer;
            std::streambuf *cerrbuf = std::cerr.rdbuf();
            const char *res = apl_command (cmd.toStdString ().c_str ());
            if (res) {
              outString = QString (res);
              free ((void *)res);
            errString = QString (errbuffer.str ().c_str ());

        return execerr;

I.e., I'm capturing stdout and stderr in strings.



Attachment: OpenPGP_0xDA6C01938888083E.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

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