Changeset 1859


Ignore:
Timestamp:
Sep 2, 2012, 5:37:36 PM (8 years ago)
Author:
sam
Message:

neercs: spawn a shell and read what it tries to print.

Location:
trunk/tools/neercs
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/neercs/Makefile.am

    r1856 r1859  
    99    $(old_sources) \
    1010    \
    11     term/term.cpp term/term.h \
    12     term/pty.cpp term/pty.h \
     11    term/term.h term/term.cpp term/ansi.cpp \
     12    term/pty.h term/pty.cpp \
    1313    \
    1414    video/render.cpp video/render.h \
  • trunk/tools/neercs/neercs.vcxproj

    r1857 r1859  
    7171    <ClCompile Include="old\widgets.c" />
    7272    <ClCompile Include="old\wm.cpp" />
     73    <ClInclude Include="term\ansi.cpp" />
    7374    <ClInclude Include="term\pty.cpp" />
    7475    <ClInclude Include="term\term.cpp" />
  • trunk/tools/neercs/neercs.vcxproj.filters

    r1857 r1859  
    7474    <ClCompile Include="old\python\py_module.c">
    7575      <Filter>old\python</Filter>
     76    </ClCompile>
     77    <ClCompile Include="term\ansi.cpp">
     78      <Filter>term</Filter>
    7679    </ClCompile>
    7780    <ClCompile Include="term\pty.cpp">
  • trunk/tools/neercs/term/pty.cpp

    r1856 r1859  
    4343
    4444Pty::Pty(ivec2 size)
    45   : m_size(size)
     45  : m_fd(-1),
     46    m_pid(-1),
     47    m_size(size)
    4648{
    4749    ;
     
    5052Pty::~Pty()
    5153{
    52 
     54    if (m_fd >= 0)
     55    {
     56        close((int)m_fd);
     57    }
    5358}
    5459
     
    5964    pid_t pid;
    6065
    61     m_pid = 0;
    62     m_fd = 0;
     66    m_pid = -1;
     67    m_fd = -1;
    6368
    6469    pid = forkpty(&fd, NULL, NULL, NULL);
     
    9398    m_fd = fd;
    9499#endif
     100}
     101
     102size_t Pty::ReadData(char *data, size_t maxlen)
     103{
     104    fd_set fdset;
     105    int maxfd = -1;
     106
     107    FD_ZERO(&fdset);
     108    if (m_fd >= 0)
     109    {
     110        FD_SET((int)m_fd, &fdset);
     111        maxfd = std::max(maxfd, (int)m_fd);
     112    }
     113
     114    if (maxfd >= 0)
     115    {
     116        struct timeval tv;
     117        tv.tv_sec = 0;
     118        tv.tv_usec = 50000;
     119        int ret = select(maxfd + 1, &fdset, NULL, NULL, &tv);
     120
     121        if (ret < 0)
     122        {
     123            Log::Error("cannot read from PTY\n");
     124            return 0;
     125        }
     126
     127        if (ret)
     128        {
     129            if (FD_ISSET((int)m_fd, &fdset))
     130            {
     131                ssize_t nr = read((int)m_fd, data, maxlen);
     132                if (nr >= 0)
     133                    return nr;
     134            }
     135        }
     136    }
     137
     138    return 0;
    95139}
    96140
  • trunk/tools/neercs/term/pty.h

    r1856 r1859  
    1313
    1414    void Run(char const *command);
     15    size_t ReadData(char *data, size_t maxlen);
    1516    void SetWindowSize(ivec2 size);
    1617
    1718private:
    18     uint64_t m_fd;
    19     uint64_t m_pid;
     19    int64_t m_fd;
     20    int64_t m_pid;
    2021    char const *m_argv[2];
    2122    ivec2 m_size;
  • trunk/tools/neercs/term/term.cpp

    r1858 r1859  
    88
    99#include "core.h"
    10 #include "lolgl.h"
    1110
    1211using namespace std;
     
    2019{
    2120    m_caca = caca_create_canvas(size.x, size.y);
     21
     22#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
     23    m_pty = new Pty(size);
     24    char const *shell = getenv("SHELL");
     25    if (!shell)
     26        shell = "/bin/sh";
     27    m_pty->Run(shell);
     28#endif
    2229}
    2330
     
    3037    /* XXX: for now we draw fancy shit */
    3138    m_time += seconds;
    32     DrawFancyShit();
     39
     40    for (;;)
     41    {
     42        char buf[BUFSIZ];
     43        size_t bytes = m_pty->ReadData(buf, BUFSIZ);
     44        if (bytes <= 0)
     45            break;
     46        ReadAnsi(buf, bytes);
     47    }
    3348#else
    3449    /* Unsupported platform - draw some fancy shit instead */
     
    4560Term::~Term()
    4661{
     62#if defined HAVE_PTY_H || defined HAVE_UTIL_H || defined HAVE_LIBUTIL_H
     63    delete m_pty;
     64#endif
     65    caca_free_canvas(m_caca);
    4766}
    4867
  • trunk/tools/neercs/term/term.h

    r1856 r1859  
    77
    88#include "term/pty.h"
     9
     10struct Iso2022Conversion
     11{
     12    Iso2022Conversion() { Reset(); }
     13    void Reset();
     14
     15    /* cs = coding system/coding method: */
     16    /* (with standard return) */
     17    /* '@' = ISO-2022, */
     18    /* 'G' = UTF-8 without implementation level, */
     19    /* '8' = UTF-8 (Linux console and imitators), */
     20    /* and many others that are rarely used; */
     21    /* (without standard return) */
     22    /* '/G' = UTF-8 Level 1, */
     23    /* '/H' = UTF-8 Level 2, */
     24    /* '/I' = UTF-8 Level 3, */
     25    /* and many others that are rarely used */
     26    uint32_t cs;
     27    /* ctrl8bit = allow 8-bit controls */
     28    uint8_t ctrl8bit;
     29    /* cn[0] = C0 control charset (0x00 ... 0x1f):
     30     * '@' = ISO 646,
     31     * '~' = empty,
     32     * and many others that are rarely used */
     33    /* cn[1] = C1 control charset (0x80 ... 0x9f):
     34     * 'C' = ISO 6429-1983,
     35     * '~' = empty,
     36     * and many others that are rarely used */
     37    uint32_t cn[2];
     38    /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
     39     *                              94x94-char. 0x21/0x21 ... 0x7e/0x7e),
     40     * and
     41     * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
     42     *                              96-char. 0xa0 ... 0xff,
     43     *                              94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
     44     *                              96x96-char. 0xa0/0xa0 ... 0xff/0xff):
     45     * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
     46    uint8_t glr[2];
     47    /* gn[i] = G0/G1/G2/G3 graphic charset state:
     48     * (94-char. sets)
     49     * '0' = DEC ACS (VT100 and imitators),
     50     * 'B' = US-ASCII,
     51     * and many others that are rarely used for e.g. various national ASCII variations;
     52     * (96-char. sets)
     53     * '.A' = ISO 8859-1 "Latin 1" GR,
     54     * '.~' = empty 96-char. set,
     55     * and many others that are rarely used for e.g. ISO 8859-n GR;
     56     * (double-byte 94x94-charsets)
     57     * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
     58     * '$A' = Chinese Character Set (GB 2312),
     59     * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
     60     * '$C' = Korean Graphic Character Set (KSC 5601:1987),
     61     * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
     62     * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
     63     * '$G' = CNS 11643 plane 1,
     64     * '$H' = CNS 11643 plane 2,
     65     * '$I' = CNS 11643 plane 3,
     66     * '$J' = CNS 11643 plane 4,
     67     * '$K' = CNS 11643 plane 5,
     68     * '$L' = CNS 11643 plane 6,
     69     * '$M' = CNS 11643 plane 7,
     70     * '$O' = JIS X 0213 plane 1,
     71     * '$P' = JIS X 0213 plane 2,
     72     * '$Q' = JIS X 0213-2004 Plane 1,
     73     * and many others that are rarely used for e.g. traditional
     74     * ideographic Vietnamese and BlissSymbolics;
     75     * (double-byte 96x96-charsets)
     76     * none standardized or in use on terminals AFAIK (Mule does use
     77     * some internally)
     78     */
     79    uint32_t gn[4];
     80    /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
     81    uint8_t ss;
     82};
    983
    1084class Term : public Entity
     
    2296
    2397private:
     98    /* Terminal emulation main entry point */
     99    size_t ReadAnsi(void const *data, size_t size);
     100    size_t SendAnsi(char const *str);
     101
     102    /* Utility functions for terminal emulation */
     103    void ReadGrcm(unsigned int argc, unsigned int const *argv);
     104    inline int ReadChar(unsigned char c, int *x, int *y);
     105    inline int ReadDuplet(unsigned char const *buffer, unsigned int *skip,
     106                          int top, int bottom, int width, int height);
     107
     108private:
    24109    Pty *m_pty;
    25110    caca_canvas_t *m_caca;
    26111    ivec2 m_size;
     112
     113    /* Terminal attributes */
     114    char *m_title;
     115
     116    int m_bell, m_init, m_report_mouse;
     117    int m_changed;                  /* content was updated */
     118    Iso2022Conversion m_conv_state; /* charset mess */
     119
     120    uint8_t m_fg, m_bg;   /* ANSI-context fg/bg */
     121    uint8_t m_dfg, m_dbg; /* Default fg/bg */
     122    uint8_t m_bold, m_blink, m_italics, m_negative, m_concealed, m_underline;
     123    uint8_t m_faint, m_strike, m_proportional; /* unsupported */
     124    uint32_t m_clearattr;
    27125
    28126    /* Mostly for fancy shit */
Note: See TracChangeset for help on using the changeset viewer.