// call: interpret(telnetstate, readbytes) // return: boolean: again, string: towritebytes, string: command, [string: arg] static int l_interpret(lua_State *L) { TelnetState* ts = getts(L); size_t inputlen = 0; const char* inputbuffer = 0; if (lua_type(L, 2) == LUA_TSTRING) inputbuffer = luaL_checklstring(L, 2, &inputlen); ReadBuffer* in = &ts->in; if (in->len && inputbuffer) // make the two buffers (old + new data) only one { int len = in->len + inputlen; char* buf = MEM_ALLOC(len); memcpy(buf, in->p, in->len); memcpy(buf+in->len, inputbuffer, inputlen); MEM_FREE(in->buffer); in->p = in->mark = in->buffer = buf; in->len = len; } else if (inputbuffer) // we only have new data { in->buffer = 0; // this buffer is not allocated in->p = in->mark = (char*) inputbuffer; in->len = inputlen; } InterpretCommand cmd; if (ts->editmode == TELNET_EDIT_MODE) cmd = processeditmode(ts); else cmd = processlinemode(ts); if (cmd != IC_EOS) ReadMark(in); else cmd = IC_NOP; // EOS command is equivalent to a NOP for the caller // Again ? if (in->len) // Only need to be called again if we did not exhaust the input buffers lua_pushboolean(L, 1); else lua_pushboolean(L, 0); // Store the unprocessed bytes, if any and if they are not already stored if (in->mark < in->p && !in->buffer) { int len = in->p-in->mark+in->len; in->buffer = MEM_ALLOC(len); memcpy(in->buffer, in->mark, len); in->p = in->mark = in->buffer; in->len = len; } // free the input buffer if it was allocated and is empty else if (in->mark == in->p && !in->len && in->buffer) { MEM_FREE(in->buffer); in->buffer = in->p = in->mark = 0; in->len = 0; } // Byte to send if (ts->out.buffer) { lua_pushlstring(L, ts->out.buffer, ts->out.len); FreeBuffer(&ts->out); } else lua_pushnil(L); // Command assert(cmd < IC_NB_OF_CMD); lua_pushstring(L, ic_names[cmd]); // push command // Optional argument int opt = 0; if (cmd == IC_LINE) { opt++; if (ts->editmode == TELNET_EDIT_MODE) { char* line; int len; teel_getline(ts->teel, &line, &len, 1); lua_pushlstring(L, line, len); MEM_FREE(line); } else // TELNET_LINE_MODE { lua_pushlstring(L, ts->linemodebuffer.buffer, ts->linemodebuffer.len); FreeBuffer(&ts->linemodebuffer); } } return 3 + opt; }
Swall::Swall(QWidget *parent) : QWidget(parent) { //sndt_key = new QString(""); //sndf_key = new QString(""); // think I don't need playplay due to g_playmode // m_playplay = true; // this does not seem to have the right or any effect. why? /* QMap<QString, QString>::const_iterator ii = cfgmap.constBegin(); while (ii != cfgmap.constEnd()) { qDebug() << ii.key() << ": " << ii.value(); ++ii; } */ QGridLayout *grid = new QGridLayout(this); grid->setSpacing(2); QPushButton *quit = new QPushButton("Quit", this); grid->addWidget(quit, 11,0); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QPushButton *savecfg = new QPushButton("Save Config", this); grid->addWidget(savecfg, 11,2); connect(savecfg, SIGNAL(clicked()), this, SLOT(saveconfig())); QPushButton *loadcfg = new QPushButton("Load Config", this); grid->addWidget(loadcfg, 11,3); connect(loadcfg, SIGNAL(clicked()), this, SLOT(loadconfig())); QPushButton *playmode = new QPushButton("Play Mode", this); playmode->setCheckable(1); playmode->setChecked(1); grid->addWidget(playmode, 11,5); connect(playmode, SIGNAL(clicked()), this, SLOT(processplaymode())); QPushButton *editmode = new QPushButton("Edit Mode", this); editmode->setCheckable(1); grid->addWidget(editmode, 11,6); connect(editmode, SIGNAL(clicked()), this, SLOT(processeditmode())); QButtonGroup* buttonGroup = new QButtonGroup(this) ; buttonGroup->addButton(playmode); buttonGroup->addButton(editmode); QPushButton *help = new QPushButton("Help", this); grid->addWidget(help, 11,7); connect(help, SIGNAL(clicked()), this, SLOT(help())); QPushButton *about = new QPushButton("About", this); grid->addWidget(about, 11,8); connect(about, SIGNAL(clicked()), this, SLOT(about())); QPushButton *notes = new QPushButton("Notes", this); grid->addWidget(notes, 11,9); connect(notes, SIGNAL(clicked()), this, SLOT(notes())); QPalette pal; pal.setColor( QPalette::Active, QPalette::Button, "Blue" ); pal.setColor( QPalette::Active, QPalette::ButtonText, "Yellow" ); pal.setColor( QPalette::Inactive, QPalette::Button, "Cyan" ); pal.setColor( QPalette::Inactive, QPalette::ButtonText, "Green" ); // QButtonGroup* gridGroup = new QButtonGroup(this) ; // gridGroup->setExclusive(0); for (int row=0; row<10; row++) { for (int col=0; col<10; col++) { SPushButton *btn = new SPushButton("", this); // qDebug() << "Making SPushButtons for the grid."; btn->setFixedSize(115, 80); btn->setCheckable(1); // btn->setAutoDefault(false); btn->setPalette( pal ); QString sndt_key; QString some_sndt; QString some_butid; // sndt_key = new QString(""); some_sndt.append(QString("Cut::R")); some_sndt.append(QString("%1").arg(row)); some_sndt.append(QString(":C")); some_sndt.append(QString("%1").arg(col)); sndt_key.append(QString("sndt")); sndt_key.append(QString("%1").arg(row)); sndt_key.append(QString("%1").arg(col)); some_butid.append(QString("%1").arg(row)); some_butid.append(QString("%1").arg(col)); some_sndt = cfgmap[sndt_key]; QString sndf_key; QString some_sndf; // sndf_key = new QString(""); some_sndf.append(QString("cut_r")); some_sndf.append(QString("%1").arg(row)); some_sndf.append(QString("_c")); some_sndf.append(QString("%1").arg(col)); some_sndf.append(QString(".mp3")); sndf_key.append(QString("sndf")); sndf_key.append(QString("%1").arg(row)); sndf_key.append(QString("%1").arg(col)); some_sndf = cfgmap[sndf_key]; btn->setSndf(some_sndf); btn->setSndfKey(sndf_key); btn->setSndt(some_sndt); btn->setSndtKey(sndt_key); btn->setButId(some_butid); btn->setProcId("00"); btn->setText(btn->getSndt()); btn->setPlayb(false); btn->setSndLoop(false); connect(btn, SIGNAL(clicked()), btn, SLOT(processButton())); connect(this, SIGNAL(sbutconfig(QString, QString, QString)), btn, SLOT(updateButConfig(QString, QString, QString))); grid->addWidget(btn, row, col); } } setLayout(grid); }