void UDPServer::handleDataRequest(QString data) { qDebug() << "UDPServer::handleDataRequest called with data:" << data; QString cmd = data.section(';',1,1).toLower(); switch (COMMANDS.indexOf(cmd.section(' ',0,0))) { case 0: // Help command (help) qDebug() << "help command called"; sendHelp(); break; case 1: // List devices command (lsdvs) qDebug() << "List devices command called"; sendDeviceList(); break; case 2: // Select device command (sldvc) qDebug() << "Select device command called"; selectDevice(cmd); break; case 3: // Deselect device command (dsdvc) qDebug() << "Deselect device command called"; deselectDevice(); break; case 4: // List buttons command (lsbts) qDebug() << "List buttons command called"; listButtons(); break; case 5: // Keymap command (kmap) qDebug() << "Keymap command called"; mapKey(cmd); break; case 6: // Undo keymap command (umap) qDebug() << "Undo keymap command called"; unmapKey(cmd); break; case 7: // Supported devices command (supdvs) qDebug() << "Supported devices command called"; supportedDevices(cmd); break; case 8: // Axis Format Map (afmap) qDebug() << "Axis Format Map command called"; axisFormatMap(cmd); break; case 9: // Axis Key Map (akmap) qDebug() << "Axis Key Map command called"; axisKeyMap(cmd); break; default: qDebug() << "Command not recognised"; QString reply = "10;"; reply += "\'" + cmd.section(' ',0,0) + "\'"; reply += " is not recognized as a command, use the \'help\' command for more information"; sendDatagram(reply.toLatin1()); break; } emit dataAvailable(data); }
/** Start editing from a command * @param ch Character to attach editor to * @param pd Descriptor to attach editor to * @param oldParser Parser to return control to when we are done * @param postcmd command to pass edited string back to when done * @param initial Initial editor state * @param sendinitial Do we send the help screen when we load */ Editor::Editor(Char *ch, ParseDescriptor *pd, Parser *oldParser, Command *postcmd, QString initial = "", bool sendinitial=true) : Parser(ch, pd), isOLC(false), _old(oldParser), _postcmd(postcmd), curstate(STATE_MENU) { QTextOStream elos(&el); elos << endl; lines = QStringList::split(el, initial, true); if (sendinitial) { sendHelp(); } }
/** Start editing from OLC * @param ch Character to attach editor to * @param pd Descriptor to attach editor to * @param activeolc OLC we were called from * @param initial Initial editor state * @param sendinitial Do we send the help screen when we load */ Editor::Editor(Char *ch, ParseDescriptor *pd, olc *activeolc, QString initial="", bool sendinitial=true) : Parser(ch, pd), isOLC(true), _old(activeolc), _postcmd(NULL), curstate(STATE_MENU) { QTextOStream elos(&el); elos << endl; lines = QStringList::split(el, initial, true); if (sendinitial) { sendHelp(); } }
void pluginFilter(void *handle, const char *from, const char *host, const char *command, const char *channel, const char *message) { char buff[520]; int i, j; double k; time_t t; if (strcmp(command, "PRIVMSG") != 0) return; channel = ircGetIntendedChannel(channel, from); if (strcmp(message, API_HELP_CMD) == 0) sendHelp(from); if (strstr(message, "<s ") == message) { t = time(NULL); i = j = 0; sscanf(message, "<s %i, %i", &i, &j); k = stirling(i, j, time(NULL)); if (time(NULL) - t >= 5) sprintf(buff, "S(%i, %i) took too long .-.", i, j); else sprintf(buff, "S(%i, %i) = %f", i, j, k); ircMessage(channel, buff); } else if (strstr(message, "<fibo") == message) { i = 0; sscanf(message, "<fibo %i", &i); k = fibonacci(i); if (k > 0) sprintf(buff, "Fibonacci number %i is %.0f", i, k); else sprintf(buff, "Fibonacci number %i is inf", i); ircMessage(channel, buff); } return; }
/** Parse a line of input * Since we only need to worry about state in this function, we define our * states as a local type. */ void Editor::parseLine(QString line) { QString cline = line.simplifyWhiteSpace(); QString out; QTextOStream os(&out); switch (curstate) { case STATE_MENU: if (QString("@append").startsWith(cline.lower())) { os << endl << "Appending to buffer. Enter . on separate line to return to menu." << endl; _desc->send(out); curstate = STATE_APPEND; break; } if (QString("@insert").startsWith(cline.section(" ",0,0).lower())) { insertpos = cline.section(" ", 1,1).toInt(); if (insertpos > 0) --insertpos; os << endl << "Inserting into buffer. Enter . on separate line to return to menu." << endl; _desc->send(out); curstate = STATE_INSERT; break; } if (QString("@delete").startsWith(cline.section(" ", 0, 0).lower())) { bool ok; int line1 = cline.section(" ", 1,1).toInt(&ok) - 1; if (!ok) { os << endl << "Need to specify a line or range to delete." << endl; _desc->send(out); break;; } int line2 = cline.section(" ", 2,2).toInt(&ok) - 1; if (ok) { lines.erase(lines.at(line1), lines.at(line2)); os << endl << line2 - line1 << " lines deleted. Type @list to see updated buffer." << endl; _desc->send(out); break; } else { os << endl << "1 line deleted. Type @list to see updated buffer." << endl; _desc->send(out); lines.erase(lines.at(line1)); break; } } if (QString("@help").startsWith(cline.lower())) { sendHelp(); break; } if (QString("@language").startsWith(cline.lower())) { QString lang = cline.section(" ", 1,1); lang = Language::getLangIDfromShort(lang); if (lang.length() != 5) { os << endl << "That language is unknown." << endl; _desc->send(out); break; } os << endl << "Starting soon, this will allow you to change the" << " language for a part of an editor string. This editor" << " feature is currently unimplemented." << endl; _desc->send(out); break; } if (QString("@list").startsWith(cline.lower())) { QStringList::iterator cur; os << endl; int count = 1; for (cur = lines.begin(); cur != lines.end(); ++cur) { os.width(3); os << count++; os.width(0); os << ". " << *cur << endl; } os << endl; _desc->send(out); break; } if (QString("@quit").startsWith(cline.lower())) { returnControl(); break; } if (QString("@abort").startsWith(cline.lower())) { returnControl(true); break; } sendHelp(); break; case STATE_APPEND: if (line.stripWhiteSpace() == ".") { curstate = STATE_MENU; break; } /* Append a line to the end of the edit buffer */ lines += line; break; case STATE_INSERT: if (line.stripWhiteSpace() == ".") { curstate = STATE_MENU; break; } /* Insert line before insertpos - increment insertpos */ lines.insert(lines.at(insertpos++), line); break; } }