Пример #1
0
static Token *op(int ch) {
    Token *t = &tok;
    int ch2;

    switch (ch) {
       case '/':
          outch(ch);
          ch2 = nextch();
          if (ch2 == '*' || ch2 == '/') {
             return cmt(ch2);
          }
          backch(ch2);
          break;
       case '+':
       case '-':
       case '*':
       case '%':
       case '=':
          outch(ch);
          break;
       default: 
          t->sym == ERROR;
          t->ival = 0;
          return t;
    }

    t->sym = OP;
    t->ival = ch;
    outch(0);
    return t;
}
Пример #2
0
static Token *cmt(int ch) {
    Token *t = &tok;
    clear_lexeme();

    switch (ch) {
      case '/':
        while (true) {
          ch = nextch();
          if (ch == '\n' || ch == '\r') break;
          outch(ch);
        }
        break;

      case '*':
        while (true) {
          ch = nextch();
          if (ch == '/' && prevch() == '*')
               { delete_prev(); break;} /* erase '*' */
          outch(ch);
        }
        break;

      default:
        break;
    }

    t->sym = CMT;
    outch(0);
    return t;
}
Пример #3
0
/*
** handle_hsc_skip
**
** copy text until '|>' occures;
** no syntax check or whatsoever is performed
**
*/
BOOL handle_hsc_onlycopy( INFILE *inpf, HSCTAG *tag )
{
    int  ch      = EOF;                /* current char */
    int  prev_ch = EOF;                /* prev char read */
    BOOL abort   = FALSE;

    do {

        ch = infgetc( inpf );

        if ( (prev_ch=='|') && (ch=='>') ) {

            abort = TRUE;

        } else if ( (prev_ch=='|') && (ch!='|') ) {

            outch( prev_ch );
            outch( ch );

        } else if ( ch != '|' )
            outch( ch );

        abort |= infeof(inpf);
        prev_ch = ch;

    } while ( !abort );

    if ( prev_ch == EOF )
        err_eof(inpf, "skipping source");

    return (TRUE);
}
Пример #4
0
//------------------------------------------------------
// int getCadTeclado(char* cadena)
//
// Descripción:
//   Lee una cadena del teclado matricial, caracter a
//   caracter y la devuelve para que la use el
//   programa principal.
//
// Parámetros:
//   char* cadena
//     puntero al búfer donde almacena la cadena leída.
//------------------------------------------------------
int getCadTeclado(char* cadena) {
	int i = 0;													// Lleva la cuenta de la posición en el array
	char w;														// Variable donde se almacena cada caracter leído del teclado
	int num = 0;													// Número que devuelve la función
	int cifras = 0;	
	output("			");												// Número de cifras del número
	do {														// Se ejecuta:
		w = teclado();												//	Lee el teclado matricial y almacena la tecla pulsada en w
		if (w <= '9' && w >= '0') {										//	Si la tecla pulsada es un número
			if (i == 0 && w == '0') {									//		Si para la primera cifra intentamos poner un 0
				i--;											//			Se ignora la tecla pulsada
			} else {											//		Si para la primera cifra no intentamos poner un 0
				cifras++;										//			Aumenta el número de cifras del número
				cadena[i] = w;										// 			Almacena el caracter leído en el array cadena
				outch(cadena[i]);									// 			Imprime en el terminal el caracter leído
			}
		} else if (w != 'D' && w != 'E') {									//	Si la tecla pulsada no es un número ni la tecla de borrar o de enter 
			i--;												//		Se ignora la tecla pulsada
		}
		if (w == 'D') { 											//	Si la tecla pulsada es la de borrar
			if (i > 0) {											//		Si no estamos en la primera posición del array
				cifras--;										//			Disminuye el número de cifras del número
				outch('\b');										//			Se borra el último número imprimido en el terminal
				i -= 2;											//			Retrocede una posición en el array
			} else {											// 		Si estamos en la primera posición
				i--;											//			Se ignora la tecla pulsada
			}
		}
	} while ((w != 'E') && (++i < 4));										// Mientras no se pulse la tecla de enter y el número tenga 4 cifras o menos

	output("\r\n");													// Se guardan e imprimen los caracteres de:
	cadena[i++] = '\r';												// - Retorno de carro
	cadena[i++] = '\n';												// - Cambio de línea
	cadena[i]   = '\0';												// - Fin de cadena
	
	if (cifras == 4) {												// Devuelve el número si tiene 4 cifras
		num = 1000*(cadena[0] - 48) + 100*(cadena[1] - 48) + 10*(cadena[2] - 48) + (cadena[3] - 48);
		return num;
	}
	else if (cifras == 3) {												// Devuelve el número si tiene 3 cifras
		num = 100*(cadena[0] - 48) + 10*(cadena[1] - 48) + (cadena[2] - 48);
		return num;
	}
	else if (cifras == 2) {												// Devuelve el número si tiene 2 cifras
		num = 10*(cadena[0] - 48) + (cadena[1] - 48);
		return num;
	}
	else if (cifras == 1) {												// Devuelve el número si tiene 1 cifra
		num = (cadena[0] - 48);
		return num;
	}
	else if (cifras == 0) {												// Devuelve un 1 si no introducimos nada
		return 1;
	}
	return 1;
}
Пример #5
0
/*
 * showexpl:
 *	Show the explosions as they currently are
 */
void
showexpl(int y, int x, char type)
{
	PLAYER *pp;
	EXPL *ep;

	if (y < 0 || y >= HEIGHT)
		return;
	if (x < 0 || x >= WIDTH)
		return;
	ep = malloc(sizeof(*ep));
	ep->e_y = y;
	ep->e_x = x;
	ep->e_char = type;
	ep->e_next = NULL;
	if (Last_expl == NULL)
		Expl[0] = ep;
	else
		Last_expl->e_next = ep;
	Last_expl = ep;
	for (pp = Player; pp < End_player; pp++) {
		if (pp->p_maze[y][x] == type)
			continue;
		pp->p_maze[y][x] = type;
		cgoto(pp, y, x);
		outch(pp, type);
	}
#ifdef MONITOR
	for (pp = Monitor; pp < End_monitor; pp++) {
		if (pp->p_maze[y][x] == type)
			continue;
		pp->p_maze[y][x] = type;
		cgoto(pp, y, x);
		outch(pp, type);
	}
#endif
	switch (Maze[y][x]) {
	  case WALL1:
	  case WALL2:
	  case WALL3:
#ifdef RANDOM
	  case DOOR:
#endif
#ifdef REFLECT
	  case WALL4:
	  case WALL5:
#endif
		if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
			remove_wall(y, x);
		break;
	}
}
Пример #6
0
/*
 * showexpl:
 *	Show the explosions as they currently are
 */
void
showexpl(int y, int x, char type)
{
	PLAYER	*pp;
	EXPL	*ep;

	if (y < 0 || y >= HEIGHT)
		return;
	if (x < 0 || x >= WIDTH)
		return;
	ep = (EXPL *) malloc(sizeof (EXPL));	/* NOSTRICT */
	if (ep == NULL) {
		logit(LOG_ERR, "malloc");
		return;
	}
	ep->e_y = y;
	ep->e_x = x;
	ep->e_char = type;
	ep->e_next = NULL;
	if (Last_expl == NULL)
		Expl[0] = ep;
	else
		Last_expl->e_next = ep;
	Last_expl = ep;
	for (pp = Player; pp < End_player; pp++) {
		if (pp->p_maze[y][x] == type)
			continue;
		pp->p_maze[y][x] = type;
		cgoto(pp, y, x);
		outch(pp, type);
	}
	for (pp = Monitor; pp < End_monitor; pp++) {
		if (pp->p_maze[y][x] == type)
			continue;
		pp->p_maze[y][x] = type;
		cgoto(pp, y, x);
		outch(pp, type);
	}
	switch (Maze[y][x]) {
	  case WALL1:
	  case WALL2:
	  case WALL3:
	  case DOOR:
	  case WALL4:
	  case WALL5:
		if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
			remove_wall(y, x);
		break;
	}
}
Пример #7
0
static void draw_line(size_t line, size_t startcol, Window *wp, Line *lp,
		      size_t lineno, Region *r, int highlight)
{
  size_t x, i;

  term_move(line, 0);
  for (x = 0, i = startcol; i < astr_len(lp->item) && x < wp->ewidth; i++) {
    if (highlight && in_region(lineno, i, r))
      outch(*astr_char(lp->item, (ptrdiff_t)i), FONT_REVERSE, &x);
    else
      outch(*astr_char(lp->item, (ptrdiff_t)i), FONT_NORMAL, &x);
  }

  draw_end_of_line(line, wp, lineno, r, highlight, x, i);
}
Пример #8
0
/*
 * rollexpl:
 *	Roll the explosions over, so the next one in the list is at the
 *	top
 */
void
rollexpl(void)
{
	EXPL *ep;
	PLAYER *pp;
	int y, x;
	char c;
	EXPL *nextep;

	for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
		nextep = ep->e_next;
		y = ep->e_y;
		x = ep->e_x;
		if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
			c = Maze[y][x];
		else
			c = SPACE;
		for (pp = Player; pp < End_player; pp++)
			if (pp->p_maze[y][x] == ep->e_char) {
				pp->p_maze[y][x] = c;
				cgoto(pp, y, x);
				outch(pp, c);
			}
#ifdef MONITOR
		for (pp = Monitor; pp < End_monitor; pp++)
			check(pp, y, x);
#endif
		free(ep);
	}
	for (x = EXPLEN - 1; x > 0; x--)
		Expl[x] = Expl[x - 1];
	Last_expl = Expl[0] = NULL;
}
Пример #9
0
void goto_line(editor_t *ed)
  {
  int lineno, l, pos;

  ed->anchor = -1;
  if (prompt(ed, "Goto line: ", 1))
    {
    lineno = atoi(ed->linebuf);
    if (lineno > 0)
      {
      pos = 0;
      for (l = 0; l < lineno - 1; l++)
        {
        pos = next_line(ed, pos);
        if (pos < 0) break;
        }
      }
    else
      {
      pos = -1;
      }

    if (pos >= 0)
      {
      moveto(ed, pos, 1);
      }
    else
      {
      outch(ed, '\007');
      }
    }
  ed->refresh = 1;
  }
Пример #10
0
static long
lptwrite(Chan *c, void *a, long n, vlong)
{
	char str[16], *p;
	long base, k;

	if(n <= 0)
		return 0;
	if(c->qid.path != Qdata){
		if(n > sizeof str-1)
			n = sizeof str-1;
		memmove(str, a, n);
		str[n] = 0;
		outb(c->qid.path, strtoul(str, 0, 0));
		return n;
	}
	p = a;
	k = n;
	base = lptbase[c->dev];
	if(waserror()){
		outb(base+Qpcr, Finitbar);
		nexterror();
	}
	while(--k >= 0)
		outch(base, *p++);
	poperror();
	return n;
}
Пример #11
0
/*
 * rollexpl:
 *	Roll the explosions over, so the next one in the list is at the
 *	top
 */
void
rollexpl(void)
{
	EXPL	*ep;
	PLAYER	*pp;
	int	y, x;
	char	c;
	EXPL	*nextep;

	for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
		nextep = ep->e_next;
		y = ep->e_y;
		x = ep->e_x;
		if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
			c = Maze[y][x];
		else
			c = SPACE;
		for (pp = Player; pp < End_player; pp++)
			if (pp->p_maze[y][x] == ep->e_char) {
				pp->p_maze[y][x] = c;
				cgoto(pp, y, x);
				outch(pp, c);
			}
		for (pp = Monitor; pp < End_monitor; pp++)
			check(pp, y, x);
		free((char *) ep);
	}
	memmove(&Expl[1], &Expl[0], (EXPLEN - 1) * sizeof Expl[0]);
	/* for (x = EXPLEN - 1; x > 0; x--)
		Expl[x] = Expl[x - 1]; */
	Last_expl = Expl[0] = NULL;
}
Пример #12
0
static Token *lit(int ch) {
    Token *t = &tok;
    int d = 0;
    int v = 0;
    int b = 10;

    outch(ch);
    v = hexval(ch);

    if (ch == '0') {
        b = 8;
        ch = nextch();
        if (ch == 'x') {
            b = 16; 
	    outch(ch);
        } else 
            backch(ch);
    }

    while (true) {
       ch = nextch();
       d  = hexval(ch);
       switch (codeof(ch)) {
          case '0': case '9':
             if (d < b) {
                 outch(ch);
                 v = v * b + d;
                 continue;
             }
          case 'Z':
             if (b == 16 && d < b) {
                 outch(ch);
                 v = v * b + d;
                 continue;
             }
          default: break;
       }
       backch(ch); 
       break;
    }

    t->sym = LIT;
    t->ival = v;
    outch(0);
    return t;
}
Пример #13
0
/*
** parse_amp
**
** parse ampersand ("&")
*/
BOOL parse_amp( INFILE *inpf )
{
    if ( !fatal_error ) {
        char *nxtwd;
        char nxtch;
        DLNODE *nd;

        /* write blank if necessary */
        outstr( infgetcws( inpf ) );

        /* get entity id */
        nxtwd = infgetw( inpf );

        /* search for entity in list */
        nd = find_dlnode( defent->first, (APTR) nxtwd, cmp_strent );
        if ( nd == NULL ) {

            message( WARN_UNKN_ENTITY, inpf );
            errstr( "Unknown entity " );
            errqstr( nxtwd );
            errlf();

        }

        /* check for closing ';' */
        nxtch = infgetc( inpf );
        if ( nxtch != ';' ) {

            message( WARN_EXPT_SEMIK, inpf );
            errqstr( ";" );
            errstr( " expected (found: " );
            errqstr( ch2str( nxtch ) );
            errstr( ")\n" );

        }

        /* output whole entity */
        outch( '&' );
        outstr( nxtwd );
        outch( nxtch );
    }

    return (BOOL)( !fatal_error );
}
Пример #14
0
static Token *id(int ch) {
    Token *t = &tok;

    outch(ch);
    while (true) {
       ch = nextch();
       switch (codeof(ch)) {
          case 'Z': case '0': case '9':
	     outch(ch);
             continue;
          default: break;
       }
       backch(ch); 
       break;
    }
    t->sym = ID;
    outch(0);
    return t;
}
Пример #15
0
static void draw_end_of_line(size_t line, Window *wp, size_t lineno, Region *r,
                             int highlight, size_t x, size_t i)
{
  if (x >= term_width()) {
    term_move(line, term_width() - 1);
    term_addch('$');
  } else if (highlight) {
    for (; x < wp->ewidth; ++i) {
      if (in_region(lineno, i, r))
        outch(' ', FONT_REVERSE, &x);
      else
        x++;
    }
  }
}
Пример #16
0
static int
vvprintf(const char *format, va_list arg, FILE *fq, char *s, size_t blength)
{
    int vint;
    double vdbl;
    unsigned int uvint;
    const char *vcptr;
    int chcount = 0;
    size_t len;
    char numbuf[50];
    char *nptr;
    int *viptr;

    while (*format)
    {
        if (*format == '%')
        {
            format++;
            if (*format == 'd')
            {
                vint = va_arg(arg, int);
                if (vint < 0)
                {
                    uvint = -vint;
                }
                else
                {
                    uvint = vint;
                }
                nptr = numbuf;
                do
                {
                    *nptr++ = (char)('0' + uvint % 10);
                    uvint /= 10;
                } while (uvint > 0);
                if (vint < 0)
                {
                    *nptr++ = '-';
                }
                do
                {
                    nptr--;
                    outch(*nptr);
                    chcount++;
                } while (nptr != numbuf);
            }
            else if (strchr("eEgGfF", *format) != NULL && *format != 0)
Пример #17
0
int prompt(editor_t *ed, char *msg, int selection)
  {
  int maxlen, len, ch;
  char *buf = ed->linebuf;

  gotoxy(ed, 0, ed->lines);
  outstr(ed, STATUS_COLOR);
  outstr(ed, msg);
  outstr(ed, CLREOL);

  len = 0;
  maxlen = ed->cols - strlen(msg) - 1;
  if (selection)
    {
    len = get_selected_text(ed, buf, maxlen);
    outbuf(ed, buf, len);
    }

  for (;;)
    {
    ch = getkey(ed);
    if (ch == KEY_ESC)
      {
      return 0;
      }
    else if (ch == KEY_ENTER)
      {
      buf[len] = 0;
      return len > 0;
      }
    else if (ch == KEY_BACKSPACE)
      {
      if (len > 0)
        {
        outstr(ed, "\b \b");
        len--;
        }
      }
    else if (ch >= ' ' && ch < 0x100 && len < maxlen)
      {
      outch(ed, ch);
      buf[len++] = ch;
      }
    }
  }
Пример #18
0
void find_text(editor_t *ed, int next)
  {
  int slen;

  if (!next)
    {
    if (!prompt(ed, "Find: ", 1))
      {
      ed->refresh = 1;
      return;
      }
    if (ed->search)
      neutron_free(ed->search);
    ed->search = neutron_strdup(ed->linebuf);
    }

  if (!ed->search) return;
  slen = strlen(ed->search);
  if (slen > 0)
    {
    char *match;

    close_gap(ed);
    match = strstr(ed->start + ed->linepos + ed->col, ed->search);
    if (match != 0)
      {
      int pos = match - ed->start;
      ed->anchor = pos;
      moveto(ed, pos + slen, 1);
      }
    else
      {
      outch(ed, '\007');
      }
    }
  ed->refresh = 1;
  }
Пример #19
0
/*
 * Receive and process server output from @sock.
 * Return number of characters received on success, -1 on error.
 */
static int
recv_output(int sock)
{
    /*
     * Read a chunk of server output and feed its characters into a
     * simple state machine.
     * Initial state is SCANNING_ID.
     * In state SCANNING_ID, buffer the character.  If it's a space,
     * decode the id that has been buffered, and enter state BUFFERING
     * or COPYING depending on its value.
     * In state BUFFERING, buffer the character.  If it's newline,
     * pass id and buffered text to servercmd(), then enter state
     * SCANNING_ID.
     * In state COPYING, pass the character to outch().  If it's
     * newline, enter state SCANNING_ID.
     */
    static enum {
	SCANNING_ID, BUFFERING, COPYING
    } state = SCANNING_ID;
    static int id;
    static struct lbuf lbuf;
    char buf[4096];
    ssize_t n;
    int i, ch, len;
    char *line;

    n = read(sock, buf, sizeof(buf));
    if (n < 0)
	return -1;

    for (i = 0; i < n; i++) {
	ch = buf[i];
	switch (state) {
	case SCANNING_ID:
	    if (ch == '\n') {
		/* FIXME gripe unexpected! */
		lbuf_init(&lbuf);
		break;
	    }
	    lbuf_putc(&lbuf, ch);
	    if (ch != ' ')
		break;
	    line = lbuf_line(&lbuf);
	    id = parseid(line);
	    lbuf_init(&lbuf);

	    switch (id) {
	    case C_PROMPT:
	    case C_FLUSH:
	    case C_EXECUTE:
	    case C_EXIT:
	    case C_FLASH:
	    case C_INFORM:
	    case C_PIPE:
	    case C_REDIR:
		state = BUFFERING;
		break;
	    default:
		/* unknown or unexpected id, treat like C_DATA */
	    case C_DATA:
		state = COPYING;
		break;
	    }
	    break;

	case BUFFERING:
	    len = lbuf_putc(&lbuf, ch);
	    if (len) {
		line = lbuf_line(&lbuf);
		servercmd(id, line, len);
		lbuf_init(&lbuf);
		state = SCANNING_ID;
	    }
	    break;

	case COPYING:
	    outch(ch);
	    if (ch == '\n')
		state = SCANNING_ID;
	}
    }

    return n;
}
Пример #20
0
void stdcalc()
{
    double  u=0,v=0;          /* u:输入的第1个数, v:输入的第2个数  */
    int     flag=0;        /* 输入数据是否有小数点标志:0-无 1-有 */
    int     sign=0;           /* 是否单击了运算符:0-无 其他-运算符字符 */
    int     x,y;  /* (x,y)鼠标当前位置 (xx,yy)鼠标前一位置 */
    char   s[9];              /* 存储输入的数字符号(含小数点) */
    int     fget=4;          /* 前一次单击的按钮标签 */
    int     d,dn;                /* 当前单击的按钮标签 */
	int     pn=0;                 /* 当前键盘输入的标签 */
    int     i=0,j; 
    standard();
     save_as_old_mouse(0,0);
         	        outtextxy(OUTX-15,OUTY,"0");
    	        outtextxy(OUTX,OUTY,".");
    while(1)    /* 单击右键则退出简单计算器 */
    {     
          if (kbhit()!=0)
            pn=bioskey(0);
			
		  if (rightpress()==1||pn==0x11b)
		    {mode=-1;break;}
		 
    	if(leftpress()!=1 && pn==0)    /* 鼠标左键未单击的处理 */
    	{
           move_mouse();
    	}
    	else if(MouseLeftFlag==1||pn!=0)  /* 鼠标左键单击的处理 */
    	{
    	    if(MouseLeftFlag==1){
			 MouseLeftFlag=0;   /* 置标志为0,防止单击1次左键而多次进入 */ 
             get_mouse_position(&x,&y);
             d=returnstdkey(x,y); /* 得到单击按钮的标签 */
			}
			else {
			 d=stdgetKey(pn);
			 pn=0;
			 }
			
			if(d==-1) continue;
			if(d==20||d==21||d==22||d==23) 
			{if(d==20) mode=1;if(d==21) mode=2;if(d==22) mode=3;if(d==23) mode=4;
			break;}
    	    show(std[d][0],std[d][2],std[d][1],std[d][3]);

    	    if(d==4)         /* 单击C开始使用 */
    	    {
    	        clearscreen();
    	        outtextxy(OUTX-15,OUTY,"0");
    	        outtextxy(OUTX,OUTY,".");
    	        v=u=0;
    	        sign=0;
    	        flag=0;
    	        i=0;
    	    }
    	    else if((dn=checknum(d,0))!=-1)  /* 单击'0'-'9'数字键的处理 */
    	    {
      	      if(dn==0&&u==0&&flag==0) /* 开始时始终单击'0',就显示0 */
    	      {
    	          i=0;
    	          s[i++]=itoc(dn);
    	          s[i++]='.';
    	          s[i]='\0';
    	          u=atof(s);
    	    	    outch(u);
    	      }
    	      else
    	      { 
    	       if(fget==4||fget==19||fget==3||fget==9)
    	    	  {
    	    		   clearscreen();
    	    		   i=0;
    	    		   s[i++]=itoc(dn);
    	    		   s[i++]='.';
    	    		   s[i]='\0';
    	    		   u=atof(s);
    	    		   outch(u);
    	    	  }
    	    	  if(checknum(fget,0)!=-1)
    	    	  {
    	    	     if(sign==0) /* 未单击运算符,处理第1个数u */
    	    	     {
    	    		     if(flag==0) /* 输入数据无小数点 */
    	    		     {
    	    		        clearscreen();
    	    		        u=u*10+d-'0';
    	    		        if((u>0&&u<1e8)||(u<0&&u>-1e8))
    	    		        {
    	    		           s[--i]=itoc(dn);
    	    		           s[++i]='.';
    	    		           s[++i]='\0';
    	    		           u=atof(s);
    	    		           outch(u);
    	    		        }
    	    		        else
    	    		           outch(u);
    	    		     }
    	    		     if(flag==1) /* 输入数据有小数点 */
    	    		     {
    	    		        if(i<=8)
    	    		        {
    	    		           clearscreen();
    	    		           s[i]=itoc(dn);
    	    		           s[++i]='\0';
    	    		           u=atof(s);
			                   outch(u);
    	    		        }
    	    		     }
    	    	     }
    	    	     if(sign!=0) /* 单击了运算符,处理第2个数v */
    	    	     {
    	    		    if(flag==0)
    	    		    {
    	    		       clearscreen();
    	    		       v=v*10+d-'0';
    	    		       if((v>0&&v<1e8)||(v<0&&v>-1e8))
    	    		       {
    	    		          s[--i]=itoc(dn);
    	    		          s[++i]='.';
    	    		          s[++i]='\0';
    	    		          v=atof(s);
    	    		          outch(v);
    	    		       }
    	    		       else
    	    		          outch(v);
    	    		    }
    	    		    if(flag==1)
    	    		    {
    	    		       if(i<=8)
    	    		       {
    	    		          clearscreen();
    	    		          s[i++]=itoc(dn);
    	    		          s[i]='\0';
    	    		          v=atof(s);
			                  outch(v);
    	    		       }
    	    		    }
    	    	     }
    	    	   }
    	    	   if(fget==8||fget==13||fget==14||fget==18)
    	    	   {
    	    		    clearscreen();
    	    		    i=0;
    	    		    s[i++]=itoc(dn);
    	    		    s[i++]='.';
    	    		    s[i]='\0';
    	    		    v=atof(s);
    	    		    outch(v);
    	    	   }
    	    	   if(fget==17) /* 前一次单击的是小数点按钮 */
    	    	   {
    	    		   clearscreen();
    	    		   s[i]=itoc(dn);
    	    		   s[++i]='\0';
    	    		   if(sign==0)
    	    		   {
			             u=atof(s);
			             outch(u);
    	    		   }
    	    		   if(sign!=0)
    	    		   {
			             v=atof(s);
			             outch(v);
    	    		   }
    	    	   }
    	       }
    	     
    	   }
    	   else if(d==8||d==13||d==14||d==18)  
{  /* 单击加,减,乘,除按钮的处理 */
    	      if(sign!=0)
    	      {
    	      	if(fget==8||fget==13||fget==14||fget==18);
    	      	else
    	      	{
    	      	   if(sign==14&&v==0)
    	      	   {
    	      	   	clearscreen();
    	      	   	outtextxy(OUTX-15,OUTY,"Err");
    	      	   }
    	      	   else{
    	      	   	u=calculate(u,v,sign);
    	      	   	outch(u);
    	      	   }
    	      	}
    	      }
    	      sign=d;
    	      flag=0;
    	      i=0;
    	   }
    	   else if(d==19)   /* 单击等号按钮的处理 */ 
    	   {
    	      if(sign!=0)
    	      {
    	      	if(sign=='/'&&fabs(v)<1e-6)
    	      	{
    	      	   clearscreen();
    	      	   outtextxy(OUTX-15,OUTY,"Err");
    	      	}
    	      	else
    	      	{
    	      	   u=calculate(u,v,sign);
    	      	   outch(u);
    	      	}
    	      }
    	      flag=0;
    	      sign=0;
    	      i=0;
    	   }
    	   else if(d==17)   /* 单击小数点按钮的处理 */ 
    	   {
    	     if(flag==0)
    	     	 flag=1;
    	   }
    	   else if(d==3)  /* 单击1/x按钮的处理 */ 
    	   {
    	      if(sign==0)   /* 如果是第1个数,输出u的百分数 */
    	      	{if(fabs(u)>1e-6) {u=1/u; outch(u);} else  {clearscreen();  outtextxy(OUTX-15,OUTY,"Err");}}
    	      if(sign!=0)   /* 是第2个数(单击过运算符),输出v的百分数 */
    	      	{if(fabs(v)>1e-6) {v=1/v; outch(v);} else  {clearscreen();  outtextxy(OUTX-15,OUTY,"Err");}}

    	      i=0;
    	   }
    	   else if(d==9)  /* 单击求平方根按钮的处理 */
         {
    	     if(sign==0)    /*对输入的第1个数求平方根 */
    	     {
    	     	  if(u<0)
    	     	  {
    	     	     clearscreen();
    	     	     outtextxy(OUTX-15,OUTY,"Err");
    	     	  }
    	     	  else{
    	     	     u=sqrt(u);
    	     	     outch(u);
    	     	  }
    	     }
    	     if(sign!=0) /*对输入的第2个数求平方根 */
    	     {
    	     	  if(v<0)
    	     	  {
    	     	     clearscreen();
    	     	     outtextxy(OUTX-15,OUTY,"Er");
    	     	  }
    	     	  else{
    	     	     v=sqrt(v);
    	     	     outch(v);
    	     	  }
    	     }
    	     i=0;
    	   }
    	   else if(d==16)   /* 单击+/-按钮的处理 */
    	   {
    	         if(sign==0)
    	         {
    	         	u=-u;
    	         	outch(u);
    	         }
    	         else
    	         {
    	         	v=-v;
    	         	outch(v);
    	         }
    	   }
    	   else
    	      continue;

	       fget=d;   /* 保存上次单击按钮的标签 */
       } /* End of else if(MouseLeftFlag==1) */
     }   /* End of while(rightpress()!=2) */

}
Пример #21
0
int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
{
   char ch;
   int64_t value;
   char *strvalue;
   wchar_t *wstrvalue;
   int min;
   int max;
   int state;
   int flags;
   int cflags;
   int32_t currlen;
   int base;
#ifdef FP_OUTPUT
   LDOUBLE fvalue;
#endif

   state = DP_S_DEFAULT;
   currlen = flags = cflags = min = 0;
   max = -1;
   ch = *format++;
   *buffer = 0;

   while (state != DP_S_DONE) {
      if ((ch == '\0') || (currlen >= maxlen)) {
         state = DP_S_DONE;
      }
      switch (state) {
      case DP_S_DEFAULT:
         if (ch == '%') {
            state = DP_S_FLAGS;
         } else {
            outch(ch);
         }
         ch = *format++;
         break;
      case DP_S_FLAGS:
         switch (ch) {
         case '-':
            flags |= DP_F_MINUS;
            ch = *format++;
            break;
         case '+':
            flags |= DP_F_PLUS;
            ch = *format++;
            break;
         case ' ':
            flags |= DP_F_SPACE;
            ch = *format++;
            break;
         case '#':
            flags |= DP_F_NUM;
            ch = *format++;
            break;
         case '0':
            flags |= DP_F_ZERO;
            ch = *format++;
            break;
         default:
            state = DP_S_MIN;
            break;
         }
         break;
      case DP_S_MIN:
         if (isdigit((unsigned char)ch)) {
            min = 10 * min + char_to_int(ch);
            ch = *format++;
         } else if (ch == '*') {
            min = va_arg(args, int);
            ch = *format++;
            state = DP_S_DOT;
         } else
            state = DP_S_DOT;
         break;
      case DP_S_DOT:
         if (ch == '.') {
            state = DP_S_MAX;
            flags |= DP_F_DOT;
            ch = *format++;
         } else
            state = DP_S_MOD;
         break;
      case DP_S_MAX:
         if (isdigit((unsigned char)ch)) {
            if (max < 0)
               max = 0;
            max = 10 * max + char_to_int(ch);
            ch = *format++;
         } else if (ch == '*') {
            max = va_arg(args, int);
            ch = *format++;
            state = DP_S_MOD;
         } else