예제 #1
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setuint64(uint64_t i)
{
    sprintf(getbuffer(U8L), "%llu", i);
    svalue.set(buffer, strlen(buffer));
    nvalue = (real8)i;
    format = VF_BOTH;
}
예제 #2
0
/* Return a string describing the meaning of the signal number SIGNUM.  */
char *
strsignal (int signum)
{
  __libc_once_define (static, once);
  const char *desc;

  /* If we have not yet initialized the buffer do it now.  */
  __libc_once (once, init);

  if (
#ifdef SIGRTMIN
      (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
#endif
      signum < 0 || signum >= NSIG || (desc = _sys_siglist[signum]) == NULL)
    {
      char *buffer = getbuffer ();
      int len;
#ifdef SIGRTMIN
      if (signum >= SIGRTMIN && signum <= SIGRTMAX)
	len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"),
			  signum - SIGRTMIN);
      else
#endif
	len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"),
			  signum);
      if (len >= BUFFERSIZ)
	buffer = NULL;
      else
	buffer[len] = '\0';

      return buffer;
    }

  return (char *) _(desc);
}
예제 #3
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setint(int4 i)
{
	sprintf(getbuffer(U4L), "%d", i);
	svalue.set(buffer, strlen(buffer));
	nvalue = (real8)i;
	format = VF_BOTH;
}
예제 #4
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setr8(real8 n, uint2 fw, uint2 trailing, uint2 force)
{
	sprintf(getbuffer(R8L), "%0*.*f", fw, trailing, n);
	MCU_strip(buffer, trailing, force);
	svalue.set(buffer, strlen(buffer));
	nvalue = n;
	format = VF_BOTH;
}
예제 #5
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::grab(void)
{
	if (format == VF_ARRAY)
		grabarray();
	else if (format != VF_NUMBER && svalue . getstring() != buffer)
	{
		uint4 l = svalue.getlength();
		memmove(getbuffer(l), svalue.getstring(), l);
		svalue.set(buffer, l);
	}
}
예제 #6
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::grabsvalue()
{
	if (format == VF_NUMBER)
		tos();
	if (svalue.getstring() != buffer)
	{
		uint4 l = svalue.getlength();
		memmove(getbuffer(l), svalue.getstring(), l);
		svalue.set(buffer, l);
	}
}
예제 #7
0
static void 
_dxf_BUFFER_CONFIG (void *ctx, void *image, int llx, int lly, int urx, int ury,
		    int *CurrentDisplayMode, int *CurrentBufferMode,
		    tdmInteractorRedrawMode redrawMode) 
{ 
  /*
   *  Direct interactor echos use this and following routine to manage
   *  double buffering.
   */

  ENTRY(("_dxf_BUFFER_CONFIG (0x%x, 0x%x, %d, %d, %d, %d, 0x%x, 0x%x, %d)",
	 ctx, image, llx, lly, urx, ury,
	 CurrentDisplayMode, CurrentBufferMode, redrawMode));

  /* record current GL buffer mode */
  *CurrentBufferMode = getbuffer() ;
  
  if (redrawMode == tdmBothBufferDraw ||
      redrawMode == tdmFrontBufferDraw)
    {
      PRINT(("%s", redrawMode == tdmBothBufferDraw ?
	     "tdmBothBufferDraw" : "tdmFrontBufferDraw"));

      /*
       *  Interactor echos no longer double buffered, so don't bother
       *  keeping front and back buffer contents identical.
       */
      
      frontbuffer(TRUE) ;
      backbuffer(FALSE) ;
    }
  else if (redrawMode == tdmBackBufferDraw ||
	   redrawMode == tdmViewEchoMode)
    {
      PRINT(("%s", redrawMode == tdmViewEchoMode ?
	     "tdmViewEchoMode" : "tdmBackBufferDraw"));

      frontbuffer(FALSE) ;
      backbuffer(TRUE) ;
    }
  else
    PRINT(("ignoring redraw mode"));

  EXIT((""));
}
예제 #8
0
void gaudio_record_lld_start(void) {
	WAVEHDR		*pwh;

	if (!ah)
		return;

	while (nQueuedBuffers < MAX_WAVE_HEADERS) {
		// Find the empty one - there will always be at least one.
		for(pwh = WaveHdrs; pwh->lpData; pwh++);

		// Grab the next audio block from the free-list
		if (!getbuffer(pwh))
			break;
	}
	if (!isRunning) {
		isRunning = TRUE;
		waveInStart(ah);
	}
}
예제 #9
0
static DWORD WINAPI waveProc(LPVOID arg) {
	MSG			msg;
	WAVEHDR		*pwh;
	GDataBuffer	*paud;
	(void)		arg;

	while (GetMessage(&msg, 0, 0, 0)) {
		switch (msg.message) {
			case MM_WIM_DATA:
				pwh = (WAVEHDR *)msg.lParam;

				// Windows - Let go!
				waveInUnprepareHeader(ah, pwh, sizeof(WAVEHDR));

				// Save the buffer in the audio record list
				paud = (GDataBuffer *)pwh->dwUser;
				paud->len = pwh->dwBytesRecorded;
				gfxSystemLock();
				gaudioRecordSaveDataBlockI(paud);
				gfxSystemUnlock();
				pwh->lpData = 0;
				nQueuedBuffers--;

				// Are we stopping?
				if (!isRunning) {
					// Have we finished yet?
					if (!nQueuedBuffers) {
						gfxSystemLock();
						gaudioRecordDoneI();
						gfxSystemUnlock();
					}
	                break;
				}

				// Try and get a new block
				getbuffer(pwh);
                break;
		}
	}
	return 0;
}
예제 #10
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setstringf(const char *p_spec, ...)
{
	va_list t_args;
	int t_count;

#if defined(_HAS_VSCPRINTF)
	va_start(t_args, p_spec);
	t_count = _vscprintf(p_spec, t_args);
	va_end(t_args);
#elif defined(_HAS_VSNPRINTF)
	va_start(t_args, p_spec);
	t_count = vsnprintf(nil, 0, p_spec, t_args);
	va_end(t_args);
#else
#error MCExecPoint::setstringf not implemented
#endif

	va_start(t_args, p_spec);
	vsprintf(getbuffer(t_count + 1), p_spec, t_args);
	va_end(t_args);

	setstrlen();
}
예제 #11
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::upper()
{
	uint4 length = svalue.getlength();
	MCU_upper(getbuffer(length), svalue);
	svalue.set(buffer, length);
}
예제 #12
0
파일: copy.c 프로젝트: nathanmkaya/ksh-arch
void
fileout(register Archive_t* ap, register File_t* f)
{
	register size_t		m;
	register ssize_t	n;
	register off_t		c;
	int			err;
	Buffer_t*		bp;

	if (f->delta.op == DELTA_verify)
		ap->selected--;
	else if (putheader(ap, f))
	{
		if (!ap->format->putdata || !(*ap->format->putdata)(&state, ap, f, f->fd))
		{
			err = 0;
			c = f->st->st_size;
			while (c > 0)
			{
				n = m = c > state.buffersize ? state.buffersize : c;
				if (!err)
				{
					if (f->fd >= 0)
					{
						if ((n = read(f->fd, ap->io->next, m)) < 0 && errno == EIO)
						{
							static char*	buf;

							if (!buf)
							{
								n = 1024 * 8;
								error(1, "EIO read error -- falling back to aligned reads");
								if (!(buf = malloc(state.buffersize + n)))
									nospace();
								buf += n - (((ssize_t)buf) & (n - 1));
							}
							if ((n = read(f->fd, buf, m)) > 0)
								memcpy(ap->io->next, buf, n);
						}
					}
					else if (bp = getbuffer(f->fd))
					{
						memcpy(ap->io->next, bp->next, m);
						if (f->extended && ap->convert[SECTION_CONTROL].f2a)
							ccmapstr(ap->convert[SECTION_CONTROL].f2a, ap->io->next, m);
						bp->next += m;
					}
					else if (bread(f->ap, ap->io->next, (off_t)0, (off_t)n, 1) <= 0)
						n = -1;
				}
				if (n <= 0)
				{
					if (n)
						error(ERROR_SYSTEM|2, "%s: read error", f->path);
					else
						error(2, "%s: file size changed", f->path);
					memzero(ap->io->next, state.buffersize);
					err = 1;
				}
				else
				{
					c -= n;
					bput(ap, n);
				}
			}
		}
		puttrailer(ap, f);
	}
	if (f->fd >= 0)
		closein(ap, f, f->fd);
}
예제 #13
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setrectangle(int32_t p_left, int32_t p_top, int32_t p_right, int32_t p_bottom)
{
	sprintf(getbuffer(I4L * 4 + 4), "%d,%d,%d,%d", p_left, p_top, p_right, p_bottom);
	setstrlen();
}
예제 #14
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setrectangle(const MCRectangle32& p_rect)
{
	sprintf(getbuffer(I4L * 4 + 4), "%d,%d,%d,%d", p_rect . x, p_rect . y, p_rect . x + p_rect . width, p_rect . y + p_rect . height);
	setstrlen();
}
예제 #15
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::setpoint(int16_t x, int16_t y)
{
	sprintf(getbuffer(I2L * 2 + 2), "%d,%d", x, y);
	setstrlen();
}
예제 #16
0
std::shared_ptr<std::vector<unsigned char> > read_input_fd(int fd, bool &continue_flag) {
	std::shared_ptr<std::vector<unsigned char> > buffer = getbuffer();
	buffer->resize(4096);

	ssize_t bread = 0;
	while(!force_exit) {
		bread = read(fd, buffer->data(), buffer->size());
		if(bread < 0) {
			if(errno == EINTR) {
				bread = 0;
				continue;
			}
			fprintf(stderr, "Failed to read from STDIN: %m\n");
			cleanup();
			exit(1);
		}
		break;
	}

	if(bread == 0) {
		if(reopen_input && fd == input_fd) {
			close(fd);
			delpollfd(fd);
			open_named_input();
			setnonblock(input_fd, input_name);
			addpollfd(input_fd, POLLIN | POLLERR, FDTYPE::INPUT, input_name);
			continue_flag = false;
			return std::shared_ptr<std::vector<unsigned char> >();
		}
		else {
			cleanup();
			exit(0);
		}
	}
	else if(bread > 0) {
		std::vector<int> pending_close_fds;

		buffer->resize(bread);
		for(int fd = 0; fd < (int) fdinfos.size(); fd++) {
			if(fdinfos[fd].type == FDTYPE::CONN || fdinfos[fd].type == FDTYPE::FIFO) {
				if(fdinfos[fd].buffered_data < max_queue) {
					fdinfos[fd].out_buffers.push_back({ buffer, 0 });
					if(fdinfos[fd].out_buffers.size() >= buffer_count_shrink_threshold) {
						//Starting to accumulate a lot of buffers
						//Shrink to fit the older ones to avoid storing large numbers of potentially mostly empty buffers
						fdinfos[fd].out_buffers[fdinfos[fd].out_buffers.size() - buffer_count_shrink_threshold].buffer->shrink_to_fit();
					}
					fdinfos[fd].buffered_data += buffer->size();
					setpollfdevents(fd, POLLOUT | POLLERR);
				}
				else if(!fdinfos[fd].have_overflowed) {
					fdinfos[fd].have_overflowed = true;
					if(no_overflow) {
						// Don't close here as we are currently iterating over the list of fds
						pending_close_fds.push_back(fd);
						fprintf(stderr, "Queue overflow for output: %s, closing connection\n", fdinfos[fd].name.c_str());
					}
					else {
						fprintf(stderr, "Queue overflow for output: %s\n", fdinfos[fd].name.c_str());
					}
				}
			}
		}

		if(pending_close_fds.size()) {
			continue_flag = false;
			for(auto &fd : pending_close_fds) {
				close(fd);
				delpollfd(fd);
			}
		}
	}
	return std::move(buffer);
}
예제 #17
0
파일: execpt.cpp 프로젝트: bduck/livecode
void MCExecPoint::copysvalue(const char *s, uint4 l)
{
	memcpy(getbuffer(l), s, l);
	svalue.set(buffer, l);
	format = VF_STRING;
}
예제 #18
0
void echo(int sock) {
  int conn;
  int nfds = 1;
  struct pollfd *fd, *fds, *other_fds, *temp;
  struct BufferList *head = NULL;
  struct BufferNode *node = NULL;

  fds = calloc(ARRAY_SIZE, sizeof(struct pollfd));
  other_fds = calloc(ARRAY_SIZE, sizeof(struct pollfd));
  fds[0].fd = sock;
  fds[0].events = POLLIN;
  other_fds[0].fd = sock;
  other_fds[0].events = POLLIN;

  while (1) {
    ssize_t read_len = 0;
    int index = 1, other_index = 1;

    if ((poll(fds, nfds, -1)) < 0) {
      perror("poll:");
      continue;
    }

    for (; index < nfds; index++) {
      fd = &(fds[index]);
      if ((fd->revents & POLLHUP) || (fd->revents & POLLERR)) {
        delbuffer(&head, fd->fd);
        close(fd->fd);
        printf("Connection closed for fds[%d]: %d\n", index, fd->fd);
        continue;
      }

      node = getbuffer(&head, fd->fd);
      if (fd->revents & POLLIN) {
        int available_size = BUFF_SIZE - node->length;
        read_len = read(fd->fd, node->buffer+node->length, available_size);
        printf("Read length: %d from fds[%d]: %d\n", (int)read_len,
            index, fd->fd);
        if (read_len == 0) {
          if (node->length >0) {
            other_fds[other_index].fd = fds[index].fd;
            other_fds[other_index].events = POLLOUT;
            other_index++;
          } else {
            delbuffer(&head, fd->fd);
            close(fd->fd);
            printf("Connection closed for fds[%d]: fd %d\n", index, fd->fd);
          }
        } else if (read_len < 0) {
          perror("read:");
        } else {
          node->length += read_len;
          other_fds[other_index].fd = fds[index].fd;
          if (node->length == BUFF_SIZE) {
            other_fds[other_index].events = POLLOUT;
          } else {
            other_fds[other_index].events = POLLIN | POLLOUT;
          }
          other_index++;
        }
      } else if ((fd->revents & POLLOUT)) {
        ssize_t write_len = write(fd->fd, node->buffer, node->length);
        if (write_len < node->length) {
          if (write_len > 0) {
            memmove(node->buffer, node->buffer + write_len,
                    node->length - write_len);
            node->length -= write_len;
          }
          other_fds[other_index].fd = fds[index].fd;
          other_fds[other_index].events = POLLIN | POLLOUT;
          other_index++;
          printf("Failed to write all data to fds[%d]: %d\n", index, fd->fd);
        } else {
          node->length = 0;
        }
        if (node->length == 0) {
          other_fds[other_index].fd = fds[index].fd;
          other_fds[other_index].events = POLLIN;
          other_index++;
        }
      } else {
        other_fds[other_index] = fds[index];
        other_index++;
      }
    }

    if (fds[0].revents & POLLIN) {
      struct sockaddr_in peer;
      socklen_t size = sizeof(peer);

      if ((conn = accept(fds[0].fd, (struct sockaddr *)&peer, &size)) == -1) {
        perror("accept:");
      } else {
        printf("Connected from %s:%d - fds[%d]: %d\n",
            inet_ntoa(peer.sin_addr), ntohs(peer.sin_port), other_index, conn);
        other_fds[other_index].fd = conn;
        other_fds[other_index].events = POLLIN;
        other_index++;
      }
    }

    if ((fds[0].events == POLLIN) && (other_index  == ARRAY_SIZE)) {
      fds[0].events = 0;
    } else if ((fds[0].events == 0) &&
               (other_index <= (ARRAY_SIZE / 10 * 8))) {
      printf("other_index = %d", other_index);
      fds[0].events = POLLIN;
    }

    temp = fds;
    fds = other_fds;
    other_fds = temp;
    nfds = other_index;
  }
}