예제 #1
0
mcxstatus mcxIOexpectNum
(  mcxIO*        xf
,  long*         lngp
,  mcxOnFail     ON_FAIL
)
   {  int   n_read   =  0
   ;  int   n_conv   =  0
   ;  mcxstatus status = STATUS_OK

   ;  if (inbuffer(xf))
      buffer_spout(xf, "mcxIOexpectNum")

   ;  mcxIOskipSpace(xf)      /* keeps accounting correct */

   ;  errno = 0
   ;  n_conv   =  fscanf(xf->fp, "%ld%n", lngp, &n_read)

   ;  xf->bc += n_read  /* fixme do fscanf error handling */
   ;  xf->lo += n_read

   ;  if (1 != n_conv)
         mcxErr("mcxIOexpectNum", "parse error: expected to find integer")
      ,  status = STATUS_FAIL
   ;  else if (errno == ERANGE)
         mcxErr("mcxIOexpectNum", "range error: not in allowable range")
      ,  status = STATUS_FAIL

   ;  if (status)
      {  mcxIOpos(xf, stderr)
      ;  if (ON_FAIL == EXIT_ON_FAIL)
         mcxExit(1)
   ;  }

      return status
;  }
예제 #2
0
int mcxIOstepback
(  int c
,  mcxIO*    xf
)
   {  if (c == EOF)
      return EOF
   ;  else
      {  if (inbuffer(xf) && xf->buffer_consumed > 0)
         c = xf->buffer->str[--xf->buffer_consumed]
   /* insert a new branch for zlib aware reading here; splice into buffer */
      ;  else if (ungetc(c, xf->fp) == EOF)
         {  mcxErr
            (  "mcxIOstepback"
            ,  "failed to push back <%d> on stream <%s>\n"
            ,  c
            ,  xf->fn->str
            )
         ;  return EOF
      ;  }

         xf->bc--
      ;  if (c == '\n')
            xf->lc--
         ,  xf->lo = xf->lo_
         ,  xf->lo_ = 0
      ;  else
         xf->lo--
   ;  }
      return c
;  }
예제 #3
0
mcxstatus mcxIOexpectReal
(  mcxIO*        xf
,  double*       dblp
,  mcxOnFail     ON_FAIL
)
   {  int   n_read   =  0
   ;  int   n_conv   =  0

   ;  if (inbuffer(xf))
      buffer_spout(xf, "mcxIOexpectReal")

   ;  mcxIOskipSpace(xf)      /* keeps accounting correct */

   ;  n_conv   =  fscanf(xf->fp, " %lf%n", dblp, &n_read)

   ;  xf->bc += n_read  /* fixme do fscanf error handling */
   ;  xf->lo += n_read

   ;  if (1 != n_conv)
      {  if (ON_FAIL == EXIT_ON_FAIL)
         {  mcxIOpos(xf, stderr)
         ;  mcxErr("parseReal", "parse error: expected to find real")
         ;  mcxExit(1)
      ;  }
         return STATUS_FAIL
   ;  }
      return STATUS_OK
;  }
예제 #4
0
dim mcxIOdiscard
(  mcxIO*      xf
,  dim         amount
)
   {  dim bsz        =  xf->buffer->mxl
   ;  char* buf      =  xf->buffer->str
   ;  dim  n_read    =  0
   ;  dim  n_chunk   =  amount / bsz
   ;  dim  rem       =  amount - bsz * n_chunk
   ;  dim  i, n

   ;  if (inbuffer(xf))
      buffer_spout(xf, "mcxIOdiscard")

   ;  for (i=0;i<n_chunk;i++)
      {  n = fread(buf, 1, bsz, xf->fp)
      ;  n_read += n
      ;  xf->bc += n  
      ;  if (n != bsz)
         break
   ;  }

      if (i < n_chunk)
      return n_read

   ;  if (rem)
         n = fread(buf, 1, rem, xf->fp)
      ,  n_read += n
      ,  xf->bc += n  

   ;  return n_read
;  }
예제 #5
0
파일: Volume.cpp 프로젝트: herbsolo/DynamO
  void 
  RVolume::loadRawFile(std::string filename, size_t width, size_t height, size_t depth,
		       size_t bytes)
  {
    std::ifstream file(filename.c_str(), std::ifstream::binary);
    std::vector<GLubyte> inbuffer(width * height * depth);
    
    switch (bytes)
      {
      case 1:
	{
	  file.read(reinterpret_cast<char*>(&inbuffer[0]), inbuffer.size());
	  if (file.fail()) M_throw() << "Failed to load the texture from the file";
	}
	break;
      case 2:
	{
	  std::vector<uint16_t> tempBuffer(width * height * depth);
	  file.read(reinterpret_cast<char*>(&tempBuffer[0]), 2 * tempBuffer.size());
	  if (file.fail()) M_throw() << "Failed to load the texture from the file";
	  for (size_t i(0); i < tempBuffer.size(); ++i)
	    inbuffer[i] = uint8_t(tempBuffer[i] >> 8);
	}
	break;
      default:
	M_throw() << "Cannot load at that bit depth yet";
      }

    loadData(inbuffer, width, height, depth);
  }
예제 #6
0
int mcxIOstep
(  mcxIO*    xf
)
   {  int c

#if 0
;if (xf->buffer)
fprintf(stderr, "buffer [%s]\n", xf->buffer->str)
;else
fprintf(stderr, "nobuffer\n")
#endif


   ;  if (xf->ateof)
      c = EOF
   ;  else if (inbuffer(xf))
      {  c = xf->buffer->str[xf->buffer_consumed++]
      ;  if (!inbuffer(xf))
         buffer_empty(xf)
   ;  }
      else
      c = fgetc(xf->fp)

   ;  switch(c)
      {
      case '\n'
      :  xf->lc++
      ;  xf->bc++
      ;  xf->lo_  =  xf->lo
      ;  xf->lo   =  0
      ;  break
      ;

      case EOF
      :  xf->ateof =  1
      ;  break
      ;

      default
      :  xf->bc++
      ;  xf->lo++
      ;  break
   ;  }
      return c
;  }
예제 #7
0
void GfxPicture::drawSci11Vga() {
	SciSpan<const byte> inbuffer(*_resource);
	int priorityBandsCount = inbuffer[3];
	int has_cel = inbuffer[4];
	int vector_dataPos = inbuffer.getUint32LEAt(16);
	int vector_size = _resource->size() - vector_dataPos;
	int palette_data_ptr = inbuffer.getUint32LEAt(28);
	int cel_headerPos = inbuffer.getUint32LEAt(32);
	int cel_RlePos = inbuffer.getUint32LEAt(cel_headerPos + 24);
	int cel_LiteralPos = inbuffer.getUint32LEAt(cel_headerPos + 28);
	Palette palette;

	// Header
	// [headerSize:WORD] [unknown:BYTE] [priorityBandCount:BYTE] [hasCel:BYTE] [unknown:BYTE]
	// [unknown:WORD] [unknown:WORD] [unknown:WORD] [unknown:WORD] [unknown:WORD]
	// Offset 16
	// [vectorDataOffset:DWORD] [unknown:DWORD] [unknown:DWORD] [paletteDataOffset:DWORD]
	// Offset 32
	// [celHeaderOffset:DWORD] [unknown:DWORD]
	// [priorityBandData:WORD] * priorityBandCount
	// [priority:BYTE] [unknown:BYTE]

	// priority bands are supposed to be 14 for sci1.1 pictures
	assert(priorityBandsCount == 14);

	if (_addToFlag) {
		_priority = inbuffer[40 + priorityBandsCount * 2] & 0xF;
	}

	// display Cel-data
	if (has_cel) {
		// Create palette and set it
		_palette->createFromData(inbuffer.subspan(palette_data_ptr), &palette);
		_palette->set(&palette, true);

		drawCelData(inbuffer, cel_headerPos, cel_RlePos, cel_LiteralPos, 0, 0, 0, 0, false);
	}

	// process vector data
	drawVectorData(inbuffer.subspan(vector_dataPos, vector_size));

	// Set priority band information
	_ports->priorityBandsInitSci11(inbuffer.subspan(40));
}
예제 #8
0
void MasterSlaveCommunicator::slave_obey_loop()
{
    QByteArray inbuffer(_bufsize, 0);
    while (true)
    {
        // receive the next message from the master
        int tag;
        ProcessManager::receiveByteBuffer(inbuffer, master(), tag);

        // if the message tag specifies a non-existing task, terminate the obey loop
        if (tag < 0 || tag >= _tasks.size()) break;

        // perform the requested task, deserializing and serializing QVariant from/to buffer
        QByteArray outbuffer = toByteArray(_bufsize, _tasks[tag]->perform(toVariant(inbuffer)));

        // send the result back to the master
        ProcessManager::sendByteBuffer(outbuffer, master(), tag);
    }
}
예제 #9
0
dim mcxIOdiscardLine
(  mcxIO       *xf
)
   {  int a
   ;  dim ct = 0

   ;  if (!xf->fp)
      {  mcxIOerr(xf, "mcxIOdiscardLine", "is not open")
      ;  return 0          /* fixme; set errno? */
   ;  }

      while(((a = mcxIOstep(xf)) != '\n') && a != EOF)
      ct++

   ;  if (inbuffer(xf))     /* fixme/design check buffer for line */
      buffer_spout(xf, "mcxIOdiscardLine")

   ;  return ct
;  }
예제 #10
0
파일: Volume.cpp 프로젝트: herbsolo/DynamO
  void
  RVolume::loadSphereTestPattern()
  {
    const size_t size(256);

    std::vector<GLubyte> inbuffer(size * size * size);

    //Sphere test pattern
    for (size_t z(0); z < size; ++z)
      for (size_t y(0); y < size; ++y)
        for (size_t x(0); x < size; ++x)
          inbuffer[x + size * (y + size * z)] 
	    = (std::sqrt(std::pow(x - size / 2.0, 2) 
			 + std::pow(y - size / 2.0, 2) 
			 + std::pow(z - size / 2.0, 2))
	       < 122.0) ? 255.0 : 0;
    
    loadData(inbuffer, size, size, size);
  }
예제 #11
0
mcxstatus  mcxIOreadFile
(  mcxIO    *xf
,  mcxTing   *filetxt
)
   {  struct stat mystat
   ;  size_t sz = 4096
   ;  ssize_t r
   ;  const char* me = "mcxIOreadFile"

   ;  mcxTingEmpty(filetxt, 0)

   ;  if (inbuffer(xf))
      buffer_spout(xf, me)

   ;  if (!xf->stdio)
      {  if (stat(xf->fn->str, &mystat))
         mcxIOerr(xf, me, "cannae stat file")
      ;  else
         sz = mystat.st_size
   ;  }

      if (!xf->fp && mcxIOopen(xf, RETURN_ON_FAIL))
      {  mcxIOerr(xf, me, "cannae open file")
      ;  return STATUS_FAIL
   ;  }

      if (xf->ateof)
      return STATUS_OK
                                          /* fixme; ting count overflow */
   ;  if (!(filetxt = mcxTingEmpty(filetxt, sz)))
      return STATUS_NOMEM

   ;  while ((r = mcxIOappendChunk(xf, filetxt, sz, 0)) > 0 && !xf->ateof)

   ;  if (r <0)
      return STATUS_FAIL                  /* fixme; look closer at error */

   ;  return STATUS_OK
;  }