Пример #1
0
//------------------------------------------------------------------------------
void ostream::putNum(uint32_t n, bool neg) {
  char buf[13];
  char* end = buf + sizeof(buf) - 1;
  char* num;
  char* str;
  uint8_t base = flagsToBase();
  *end = '\0';
  str = num = fmtNum(n, end, base);
  if (base == 10) {
    if (neg) {
      *--str = '-';
    } else if (flags() & showpos) {
      *--str = '+';
    }
  } else if (flags() & showbase) {
    if (flags() & hex) {
      *--str = flags() & uppercase ? 'X' : 'x';
    }
    *--str = '0';
  }
  uint8_t len = end - str;
  fmtflags adj = flags() & adjustfield;
  if (adj == internal) {
    while (str < num) putch(*str++);
  }
  if (adj != left) {
    do_fill(len);
  }
  putstr(str);
  do_fill(len);
}
Пример #2
0
//------------------------------------------------------------------------------
void ostream::putDouble(double n) {
  uint8_t nd = precision();
  double round = 0.5;
  char sign;
  char buf[13];  // room for sign, 10 digits, '.', and zero byte
  char *end = buf + sizeof(buf) - 1;
  char *str = end;
  // terminate string
  *end = '\0';

  // get sign and make nonnegative
  if (n < 0.0) {
    sign = '-';
    n = -n;
  } else {
    sign = flags() & showpos ? '+' : '\0';
  }
  // check for larger than uint32_t
  if (n > 4.0E9) {
    pgm err(PSTR("BIG FLT"));
    putPgm(err);
    return;
  }
  // round up and separate in and fraction parts
  for (uint8_t i = 0; i < nd; ++i) round *= 0.1;
  n += round;
  uint32_t intPart = n;
  double fractionPart = n - intPart;

  // format intPart and decimal point
  if (nd || (flags() & showpoint)) *--str = '.';
  str = fmtNum(intPart, str, 10);

  // calculate length for fill
  uint8_t len = sign ? 1 : 0;
  len += nd + end - str;

  // extract adjust field
  fmtflags adj = flags() & adjustfield;
  if (adj == internal) {
    if (sign) putch(sign);
    do_fill(len);
  } else {
    // do fill for internal or right
    fill_not_left(len);
    if (sign) *--str = sign;
  }
  putstr(str);
  // output fraction
  while (nd-- > 0) {
    fractionPart *= 10.0;
    int digit = static_cast<int>(fractionPart);
    putch(digit + '0');
    fractionPart -= digit;
  }
  // do fill if not done above
  do_fill(len);
}
Пример #3
0
/* Fill the current path using a specified rule. */
static int
fill_with_rule(gs_state * pgs, int rule)
{
    int code;

    /* If we're inside a charpath, just merge the current path */
    /* into the parent's path. */
    if (pgs->in_charpath)
        code = gx_path_add_char_path(pgs->show_gstate->path, pgs->path,
                                     pgs->in_charpath);
            /* If we're rendering a glyph cached, the show machinery decides
             * whether to actually image it on the output or not, but uncached
             * will render directly to the output, so for text rendering
             * mode 3, we have to short circuit it here, but keep the
             * current point
             */
    else if (gs_is_null_device(pgs->device)
            || (pgs->show_gstate && pgs->text_rendering_mode == 3
            && pgs->in_cachedevice == CACHE_DEVICE_NOT_CACHING)) {
        /* Handle separately to prevent gs_state_color_load - bug 688308. */
        gs_newpath(pgs);
        code = 0;
    } else {
        code = do_fill(pgs, rule);
        if (code >= 0)
            gs_newpath(pgs);
    }
    return code;
}
Пример #4
0
//------------------------------------------------------------------------------
void ostream::putPgm(const pgm &arg) {
  char *str = arg.ptr;
  int n = strlen_P(str);
  fill_not_left(n);
  for (uint8_t c; (c = pgm_read_byte(str)); str++) {
    putch(c);
  }
  do_fill(n);
}
Пример #5
0
//------------------------------------------------------------------------------
void ostream::putPgm(const char* str) {
  int n;
  for (n = 0; pgm_read_byte(&str[n]); n++) {}
  fill_not_left(n);
  for (uint8_t c; (c = pgm_read_byte(str)); str++) {
    putch(c);
  }
  do_fill(n);
}
Пример #6
0
int main(int argc, char *argv[])
{
    int listenfd, connfd, port, clientlen;
    int threads, buffers;
    struct sockaddr_in clientaddr;

    sched = (char*) malloc(5*sizeof(char));
    getargs(&port,&threads, &buffers,sched, argc, argv);
    //initialize global variables
    //  reqBuf = (reqBuf_t *)malloc(buffers*sizeof(reqBuf_t));
    // rioBuf = (rio_t *)malloc(buffers*sizeof(rio_t));
    fdInfoBuf = (fdInfo *)malloc(buffers*sizeof(fdInfo));
    bufferSize = buffers;
    numInBuf = 0;
    consumers = threads;

    //create threads
    pthread_t handlerC[consumers];
    int i;
    for(i=0; i<consumers; i++) {
        pthread_create(&handlerC[i], NULL, requestHandler, NULL);
    }

    printf("consumers join\n");

    listenfd = Open_listenfd(port);
    while (1) {
        pthread_mutex_lock(&m);
        printf("num in buffer:%d\n", numInBuf);
        while(numInBuf == bufferSize) {
            printf("producer waiting\n");
            pthread_cond_wait(&empty, &m);
        }
        clientlen = sizeof(clientaddr);
        pthread_mutex_unlock(&m);
        printf("listenning\n");
        //this operation should be unlock!!!!
        connfd = Accept(listenfd, (SA *)&clientaddr, (socklen_t *) &clientlen);
        pthread_mutex_lock(&m);
        do_fill(connfd);
        // printf("num after fill in buffer:%d\n", numInBuf);
        pthread_cond_signal(&fill);
        pthread_mutex_unlock(&m);
    }

}
Пример #7
0
/*
 *	The function "mon()" is the dialog user interface, called
 *	from the simulation just after program start.
 */
void mon(void)
{
	register int eoj = 1;
	static char cmd[LENCMD];

	tcgetattr(0, &old_term);

	if (x_flag) {
		if (do_getfile(xfn) == 0)
			do_go();
	}
	while (eoj) {
		next:
		printf(">>> ");
		fflush(stdout);
		if (fgets(cmd, LENCMD, stdin) == NULL) {
			putchar('\n');
			goto next;
		}
		switch (*cmd) {
		case '\n':
			do_step();
			break;
		case 't':
			do_trace(cmd + 1);
			break;
		case 'g':
			do_go();
			break;
		case 'd':
			do_dump(cmd + 1);
			break;
		case 'l':
			do_list(cmd + 1);
			break;
		case 'm':
			do_modify(cmd +	1);
			break;
		case 'f':
			do_fill(cmd + 1);
			break;
		case 'v':
			do_move(cmd + 1);
			break;
		case 'x':
			do_reg(cmd + 1);
			break;
		case 'p':
			do_port(cmd + 1);
			break;
		case 'b':
			do_break(cmd + 1);
			break;
		case 'h':
			do_hist(cmd + 1);
			break;
		case 'z':
			do_count(cmd + 1);
			break;
		case 'c':
			do_clock();
			break;
		case 's':
			do_show();
			break;
		case '?':
			do_help();
			break;
		case 'r':
			do_getfile(cmd + 1);
			break;
		case '!':
			do_unix(cmd + 1);
			break;
		case 'q':
			eoj = 0;
			break;
		default:
			puts("what??");
			break;
		}
	}
}
Пример #8
0
//------------------------------------------------------------------------------
void ostream::putChar(char c) {
  fill_not_left(1);
  putch(c);
  do_fill(1);
}
Пример #9
0
//------------------------------------------------------------------------------
void ostream::fill_not_left(unsigned len) {
  if ((flags() & adjustfield) != left) {
    do_fill(len);
  }
}
Пример #10
0
//------------------------------------------------------------------------------
void ostream::putStr(const char *str) {
  unsigned n = strlen(str);
  fill_not_left(n);
  putstr(str);
  do_fill(n);
}