Exemplo n.º 1
0
int
main (int argc, char *argv[]) {
  ProgramExitStatus exitStatus = PROG_EXIT_FATAL;

  {
    static const OptionsDescriptor descriptor = {
      OPTION_TABLE(programOptions),
      .applicationName = "brltty-trtxt",
      .argumentsSummary = "[{input-file | -} ...]"
    };

    PROCESS_OPTIONS(descriptor, argc, argv);
  }

  if (getTable(&inputTable, opt_inputTable)) {
    if (getTable(&outputTable, opt_outputTable)) {
      outputStream = stdout;
      outputName = standardOutputName;

      toDots = inputTable? toDots_mapped: toDots_unicode;
      toCharacter = outputTable? toCharacter_mapped: toCharacter_unicode;

      if (argc) {
        do {
          const char *file = argv[0];
          FILE *stream;

          if (strcmp(file, standardStreamArgument) == 0) {
            if (!processStream(stdin, standardInputName)) break;
          } else if ((stream = fopen(file, "r"))) {
            int ok = processStream(stream, file);
            fclose(stream);
            if (!ok) break;
          } else {
            logMessage(LOG_ERR, "cannot open file: %s: %s", file, strerror(errno));
            exitStatus = PROG_EXIT_SEMANTIC;
            break;
          }

          argv += 1, argc -= 1;
        } while (argc);

        if (!argc) exitStatus = PROG_EXIT_SUCCESS;
      } else if (processStream(stdin, standardInputName)) {
        exitStatus = PROG_EXIT_SUCCESS;
      }

      if (outputTable) destroyTextTable(outputTable);
    }

    if (inputTable) destroyTextTable(inputTable);
  }

  return exitStatus;
}
Exemplo n.º 2
0
void Connection::readyRead()
{
    while (m_socket && m_socket->bytesAvailable()) {
        long length;
        {
            QByteArray data;
            char c;
            while(m_socket->getChar(&c)) {
                if(c==0) break;
                data.append(c);
            }
            length = data.toLong();
        }
        QByteArray data;
        while (data.length() <= length) {
            if (!data.isEmpty() && !m_socket->waitForReadyRead()) {
                return;
            }
            data += m_socket->read(length - data.length() + 1);
        }
        //kDebug() << data;

        QDomDocument doc;
        doc.setContent(data);
        if (doc.documentElement().tagName() == "init") {
            processInit(doc);
        } else if (doc.documentElement().tagName() == "response") {
            processResponse(doc);
        } else if (doc.documentElement().tagName() == "stream") {
            processStream(doc);
        } else {
            //kWarning() << "unknown element" << xml->name();
        }
    }
}
Exemplo n.º 3
0
int
XML_ProcessFile(XML_Parser parser,
                const XML_Char *filename,
                unsigned flags)
{
  int result;

  if (!XML_SetBase(parser, filename)) {
    ftprintf(stderr, T("%s: out of memory"), filename);
    exit(1);
  }

  if (flags & XML_EXTERNAL_ENTITIES)
      XML_SetExternalEntityRefHandler(parser,
                                      (flags & XML_MAP_FILE)
                                      ? externalEntityRefFilemap
                                      : externalEntityRefStream);
  if (flags & XML_MAP_FILE) {
    PROCESS_ARGS args;
    args.retPtr = &result;
    args.parser = parser;
    if (!filemap(filename, processFile, &args))
      result = 0;
  }
  else
    result = processStream(filename, parser);
  return result;
}
Exemplo n.º 4
0
MD5::MD5 (const File& file)
{
    FileInputStream fin (file);

    if (fin.getStatus().wasOk())
        processStream (fin, -1);
    else
        zerostruct (result);
}
void RtspStreamWorker::processStreamLoop()
{
    bool abortFlag = false;
    while (!m_cancelFlag && !abortFlag)
    {
        if (m_threadPause.shouldPause())
            pause();
        abortFlag = !processStream();
    }
}
Exemplo n.º 6
0
bool ThreadedSocketConnection::read()
{
  struct timeval timeout = { 1, 0 };
  fd_set readset = m_fds;

  try
  {
    // Wait for input (1 second timeout)
    int result = select( 1 + m_socket, &readset, 0, 0, &timeout );

    if( result > 0 ) // Something to read
    {
      // We can read without blocking
      ssize_t size = socket_recv( m_socket, m_buffer, sizeof(m_buffer) );
      if ( size <= 0 ) { throw SocketRecvFailed( size ); }
      m_parser.addToStream( m_buffer, size );
    }
    else if( result == 0 && m_pSession ) // Timeout
    {
      m_pSession->next();
    }
    else if( result < 0 ) // Error
    {
      throw SocketRecvFailed( result );
    }

    processStream();
    return true;
  }
  catch ( SocketRecvFailed& e )
  {
    if( m_disconnect )
      return false;

    if( m_pSession )
    {
      m_pSession->getLog()->onEvent( e.what() );
      m_pSession->disconnect();
    }
    else
    {
      disconnect();
    }

    return false;
  }
}
Exemplo n.º 7
0
bool ThreadedSocketConnection::read()
{
  int timeout = 1000; // 1000ms = 1 second
  struct pollfd pfd = { m_socket, POLLIN | POLLPRI, 0 };

  try
  {
    // Wait for input (1 second timeout)
    int result = poll( &pfd, 1, timeout );

    if( result > 0 ) // Something to read
    {
      // We can read without blocking
      int size = recv( m_socket, m_buffer, sizeof(m_buffer), 0 );
      if ( size <= 0 ) { throw SocketRecvFailed( size ); }
      m_parser.addToStream( m_buffer, size );
    }
    else if( result == 0 && m_pSession ) // Timeout
    {
      m_pSession->next();
    }
    else if( result < 0 ) // Error
    {
      throw SocketRecvFailed( result );
    }

    processStream();
    return true;
  }
  catch ( SocketRecvFailed& e )
  {
    if( m_disconnect )
      return false;

    if( m_pSession )
    {
      m_pSession->getLog()->onEvent( e.what() );
      m_pSession->disconnect();
    }
    else
    {
      disconnect();
    }

    return false;
  }
}
Exemplo n.º 8
0
int
processHostCommandStreams (
  HostCommandStream *hcs,
  HostCommandStreamProcessor *processStream,
  void *data
) {
  while (hcs->streamVariable) {
    if (*hcs->streamVariable) {
      if (!processStream(hcs, data)) {
        return 0;
      }
    }

    hcs += 1;
  }

  return 1;
}
Exemplo n.º 9
0
static int
externalEntityRefStream(XML_Parser parser,
                        const XML_Char *context,
                        const XML_Char *base,
                        const XML_Char *systemId,
                        const XML_Char *publicId)
{
  XML_Char *s;
  const XML_Char *filename;
  int ret;
  XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0);
  filename = resolveSystemId(base, systemId, &s);
  XML_SetBase(entParser, filename);
  ret = processStream(filename, entParser);
  free(s);
  XML_ParserFree(entParser);
  return ret;
}
Exemplo n.º 10
0
void Facade::uploadCameraFromFile(StreamInfo streamInfo)
{
    try
    {
        processStream(&streamInfo);

        AddCamera addCamera(this->action, &streamInfo);
        addCamera.execute();

        DrawScene drawScene(this->action);
        drawScene.execute();

    }
    catch(BaseException& exc)
    {
        this->alertWindowService->showErrorMessage(exc.what());
    }
}
Exemplo n.º 11
0
MD5::MD5 (InputStream& input, int64 numBytesToRead)
{
    processStream (input, numBytesToRead);
}