char *Controller::readSource(const char *fileName) { char *buffer = NULL; bool networkFile = strstr(fileName, "://"); const char *delim = strchr(fileName, '?'); int len = strlen(fileName); int endIndex = delim ? (delim - fileName) : len; if (delim && !networkFile) { strcpy(opt_command, delim + 1); } _mainBas = false; trace("readSource %s %d %s", fileName, endIndex, opt_command); if (networkFile) { buffer = readConnection(fileName); } else if (strncasecmp("main.bas", fileName, endIndex) == 0) { // load as resource int len = maGetDataSize(MAIN_BAS); buffer = (char *)tmp_alloc(len + 1); maReadData(MAIN_BAS, buffer, 0, len); buffer[len] = '\0'; _mainBas = true; } else { // load from file system MAHandle handle = maFileOpen(fileName, MA_ACCESS_READ); if (maFileExists(handle)) { int len = maFileSize(handle); buffer = (char *)tmp_alloc(len + 1); maFileRead(handle, buffer, len); buffer[len] = '\0'; } maFileClose(handle); } if (buffer == NULL) { buffer = (char *)tmp_alloc(strlen(ERROR_BAS) + 1); strcpy(buffer, ERROR_BAS); } delete [] _programSrc; len = strlen(buffer); _programSrc = new char[len + 1]; strncpy(_programSrc, buffer, len); _programSrc[len] = 0; logPrint("Opened: %s %d bytes\n", fileName, len); return buffer; }
CLCServer::CLCServer(QObject * parent): QTcpServer(parent), m_parser(), m_help(QStringList() << "h" << "help", tr("Show help")), m_tab(QStringList() << "t" << "tab", tr("Path to the tab with format window%tab"), tr("tab path")), m_geom(QStringList() << "g" << "geometry", tr("set the geometry of the window (synthax : WidthxHeight+OffX+OffY"), tr("geometry")), m_del(QStringList() << "d" << "delete", tr("Flag to delete the tab")), m_list(QStringList() << "l" << "ls" << "list", tr("List the tabs")), m_exit(QStringList() << "x" << "exit", tr("Exit CLCBrowser")) { m_parser.addPositionalArgument(tr("url"), tr("url to open"), tr("[url]")); m_parser.addOption(m_help); m_parser.addOption(m_tab); m_parser.addOption(m_geom); m_parser.addOption(m_del); m_parser.addOption(m_list); m_parser.addOption(m_exit); connect(this, SIGNAL(newConnection()), this, SLOT(readConnection())); }