示例#1
0
文件: braille.c 项目: junwuwei/brltty
static char *
readCommandLine (void) {
  if (fillInputBuffer()) {
    if (inputStart < inputLength) {
      const char *newline = memchr(&inputBuffer[inputStart], '\n', inputLength-inputStart);

      if (newline) {
        char *string;
        int stringLength = newline - inputBuffer;
        inputCarriageReturn = 0;

        if ((newline != inputBuffer) && (*(newline-1) == '\r')) {
          inputCarriageReturn = 1;
          stringLength -= 1;
        }

        string = makeString(inputBuffer, stringLength);
        inputLength -= ++newline - inputBuffer;
        memmove(inputBuffer, newline, inputLength);
        inputStart = 0;
        return string;
      } else {
        inputStart = inputLength;
      }
    } else if (inputEnd) {
      char *string;

      if (inputLength) {
        string = makeString(inputBuffer, inputLength);
        inputLength = 0;
        inputStart = 0;
      } else {
        string = copyString("quit");
      }

      return string;
    }
  }

  return NULL;
}
示例#2
0
   static void	skipInputData(j_decompress_ptr cinfo, long num_bytes)
      // Called by client when it wants to advance past some
      // uninteresting data.
   {
      StreamedJPEGReader*	src = (StreamedJPEGReader*) cinfo->client_data;
      AssertISV(src, "StreamedJPEGReader::skipInputData - 'this' is missing!");

      // According to jpeg docs, large skips are
      // infrequent.  So let's just do it the simple
      // way.
      if (num_bytes > 0) 
      {
         while (num_bytes > (long) src->mSource.bytes_in_buffer) 
         {
            num_bytes -= (long) src->mSource.bytes_in_buffer;
            fillInputBuffer(cinfo);
         }

         // Handle remainder.
         src->mSource.next_input_byte += (size_t) num_bytes;
         src->mSource.bytes_in_buffer -= (size_t) num_bytes;
      }
   }
示例#3
0
size_t libmaus2::lz::XzDecoder::read(
	uint8_t *
		#if defined(LIBMAUS2_HAVE_LZMA)
		A
		#endif
		,
	size_t
		#if defined(LIBMAUS2_HAVE_LZMA)
		s
		#endif
)
{
	size_t r = 0;

	#if defined(LIBMAUS2_HAVE_LZMA)
	while ( s )
	{
		// if output data buffer is empty
		if ( pc == pe )
		{
			// try to fill the input buffer
			if ( ! lstr.avail_in )
			{
				lstr.avail_in = fillInputBuffer();
				lstr.next_in = Ainbuf.begin();
			}

			// still no data, end of the file
			if ( ! lstr.avail_in )
			{
				s = 0;

				if ( lastret != LZMA_STREAM_END )
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "XzDecoder::read(): file is truncated" << std::endl;
					lme.finish();
					throw lme;
				}
			}
			// we have data, try to decompress it
			else
			{
				lstr.next_out = Aoutbuf.begin();
				lstr.avail_out = Aoutbuf.size();

				// call decompression
				lzma_ret const ret = lzma_code(&lstr,LZMA_RUN);
				lastret = ret;

				pa = Aoutbuf.begin();
				pc = Aoutbuf.begin();
				pe = Aoutbuf.begin() + Aoutbuf.size() - lstr.avail_out;

				switch ( ret )
				{
					/*
					 * nothing special
					 */
					case LZMA_OK:
					{
						break;
					}
					/*
					 * end of compressed stream. set up new decoder in case another compressed stream follows this one
					 */
					case LZMA_STREAM_END:
					{
						// move rest of input data to front of buffer
						memmove(Ainbuf.begin(),lstr.next_in,lstr.avail_in);
						size_t const g = lstr.avail_in;
						lzma_end(&lstr);

						initDecoder();

						lstr.next_in = Ainbuf.begin();
						lstr.avail_in = g;

						break;
					}
					/*
					 * an actual error
					 */
					default:
					{
						libmaus2::exception::LibMausException lme;
						lme.getStream() << "XzDecoder::read(): liblzma error " << ret << std::endl;
						lme.finish();
						throw lme;
						break;
					}
				}
			}
		}

		size_t const tocopy = std::min(s,static_cast<size_t>(pe-pc));
		std::copy(pc,pc+tocopy,A);
		A += tocopy;
		s -= tocopy;
		pc += tocopy;
		r += tocopy;
	}
	#endif

	return r;
}