Beispiel #1
0
/*
 *	Parse expression and output appropriate tokens.
 *	Return token at end of expression.
 */
int
parse_expression(TOKEN *token)
{
    int		token_class;
    int		i, last_class, temp_class;
    DECL_MEMBER	*id_type;
    DECL_ID	*id_id;
    char	*new_id;
    char	string_const[MAX_TOKEN_LENGTH], octal_const[5];

    last_class = OPERATOR;

    token_class = get_token(token);

    while (1) {

        switch (token_class) {

        case LEFT_PAREN :
            if (last_class != OPERATOR) {
                parse_error("Missing operator");
                return ERROR;
            }

            /* Sub-expression */
            out_token(token);
            /* Parse to closing right paren */
            token_class = parse_expression(token);
            if (token_class != RIGHT_PAREN) {
                parse_error("Missing ')'");
                return ERROR;
            }

            out_token(token);
            break;

        case RIGHT_PAREN :
            return token_class;

        case OPERATOR :
            out_white_space(token);
            if (token->token_type == EQUAL)
                /* Make it a '==' */
                out_str("==");
            else

                /* Check for address operator '@' or '.' */
                if ((token->token_type == AT_OP) ||
                        (token->token_type == PERIOD)) {
                    token_class = get_token(token);
                    if (token_class == IDENTIFIER) {
                        /* Make it a '&' */
                        out_char('&');

                        /* See if it's a function reference */
                        if (find_symbol(token, &id_type, &id_id) &&
                                (id_type->type->token_type != PROCEDURE)) {
                            /* Variable - parse it */
                            temp_class = parse_member(token, id_type, id_id);
                        } else {

                            /* Function call - Check for */
                            /* a function conversion */
                            if (check_cvt_id(token, &cvt_functions[0], &new_id))
                                /* Convert to desired function */
                                out_str(new_id);
                            else
                                /* Function call - output name */
                                out_token_name(token);

                            temp_class = get_token(token);
                        }
                    } else

                        if (token_class == LEFT_PAREN) {
                            /* Constant list - convert to string */
                            out_char('"');
                            string_const[0] = '\0';

                            do {
                                token_class = get_token(token);
                                if (token_class == STRING)
                                    (void) strcat(string_const, token->token_name);
                                else if (token_class == NUMERIC) {
                                    cvt_octal(token, octal_const);
                                    (void) strcat(string_const, octal_const);
                                } else {
                                    parse_error("Illegal constant");
                                    return ERROR;
                                }

                                token_class = get_token(token);
                            } while (token_class == COMMA);

                            if (token_class != RIGHT_PAREN) {
                                parse_error("')' expected");
                                return ERROR;
                            }

                            i = strlen(string_const);
                            if ((i >= 4) &&
                                    (!strcmp(string_const + i - 4, "\\000")))
                                /* Discard trailing null */
                                string_const[i - 4] = '\0';
                            out_str(string_const);
                            out_char('"');
                        } else {
                            parse_error("Illegal operator");
                            return ERROR;
                        }
                } else

                    out_token_name(token);
            break;

        case IDENTIFIER :
            /* Check for identifier conversion */
            if (check_cvt_id(token, &cvt_identifiers[0], &new_id)) {
                out_white_space(token);
                out_str(new_id);
                temp_class = get_token(token);
            } else

                /* See if variable in context */
                if (find_symbol(token, &id_type, &id_id) &&
                        (id_type->type->token_type != PROCEDURE)) {
                    /* Variable - parse it */
                    temp_class = parse_member(token, id_type, id_id);
                } else

                    /* Function call - parse it */
                    temp_class = parse_function(token);
            break;

        case NUMERIC :
            out_token(token);
            break;

        case STRING :
            out_white_space(token);
            /* Convert to a numeric constant */
            if (token->token_length > 4) {
                parse_error("Illegal string constant");
                return ERROR;
            }

            if (token->token_length > 1)
                out_char('(');

            out_str_const(token->token_name, token->token_length);

            if (token->token_length > 1)
                out_char(')');
            break;

        default :
            /* Must not be part of an expression! */
            return token_class;
        }

        last_class = token_class;

        token_class = (last_class == IDENTIFIER) ?
                      temp_class : get_token(token);
    }
}
Beispiel #2
0
/*
 *	DO statement
 *	Handles DO;, DO CASE, DO WHILE, and iterative DO
 */
void
parse_do(TOKEN *first_token)
{
    TOKEN		token;
    int		token_class;
    int		case_line;
    char		case_statement[MAX_TOKEN_LENGTH];
    char		case_output[MAX_CASE_STATEMENT_SIZE];
    char		var_string[MAX_TOKEN_LENGTH];
    char		*temp_out_string, *temp_out_string1;
    DECL_MEMBER	*var_decl;
    DECL_ID		*var_decl_id;

    /* Create new context */
    new_context(DO, (TOKEN *) NULL);

    out_white_space(first_token);

    /* Determine what kind of DO statement */
    token_class = get_token(&token);

    switch (token_class) {

    case END_OF_LINE :
        /* DO; */
        out_white_space(&token);
        out_char('{');			/* } for dumb vi */
        parse_to_end();
        break;

    case IDENTIFIER :
        /* DO counter = start TO limit BY step */
        out_str("for");
        out_must_white(&token);
        out_char('(');

        /* Put full variable in var_string */
        var_string[0] = '\0';
        temp_out_string = out_string;
        out_string = var_string;
        token_class = parse_variable(&token, &var_decl, &var_decl_id);
        out_string = temp_out_string;

        /* Check for '=' */
        if ((token_class != OPERATOR) ||
                (token.token_type != EQUAL)) {
            parse_error("Missing '='");
            pop_context();
            return;
        }
        /* Send <ident> '=' <expr> */
        out_str(var_string);
        out_token(&token);
        token_class = parse_expression(&token);
        if ((token_class != RESERVED) ||
                (token.token_type != TO)) {
            parse_error("Missing TO");
            pop_context();
            return;
        }

        /* Send <ident> <= <limit> */
        out_str("; ");
        out_str(var_string);
        out_str(" <=");
        token_class = parse_expression(&token);
        out_str("; ");

        /* Parse increment */
        if ((token_class == RESERVED) &&
                (token.token_type == BY)) {

            /* Send <ident> += <step> */
            out_str(var_string);
            out_str(" +=");
            token_class = parse_expression(&token);
        } else {
            /* Send <ident>++ */
            out_str(var_string);
            out_str("++");
        }

        out_str(") {");		/* } for dumb vi */
        out_white_space(&token);

        if (token_class != END_OF_LINE) {
            parse_error("BY or ';' expected");
            pop_context();
            return;
        }

        parse_to_end();
        break;

    case RESERVED :
        switch (token.token_type) {

        case CASE :
            /* DO CASE <expr>; */
            out_str("switch (");
            if (parse_expression(&token) != END_OF_LINE) {
                parse_error("';' expected");
                pop_context();
                return;
            }
            out_white_space(&token);
            out_str(") {");		/* } for dumb vi */

            case_line = 0;
            while (1) {
                /* Place case statement in out_string */
                temp_out_string1 = out_string;
                case_output[0] = '\0';
                out_string = case_output;

                (void) snprintf(case_statement, sizeof(case_statement), "case %d :",
                                case_line++);
                token_class = parse_new_statement();
                if (token_class == END_OF_FILE) {
                    parse_error("Premature end-of-file");
                    exit(1);
                }
                if (token_class == END) {
                    out_string = temp_out_string1;
                    out_str(case_output);
                    break;
                }
                out_string = temp_out_string1;
                out_white_space(first_token);
                out_str(case_statement);
                out_str(case_output);
                out_white_space(first_token);
                out_str("break;\n");
            }
            break;

        case WHILE :
            /* DO WHILE <expr>; */
            out_str("while (");
            if (parse_expression(&token) != END_OF_LINE) {
                parse_error("';' expected");
                pop_context();
                return;
            }
            out_white_space(&token);
            out_str(") {");		/* } for dumb vi */

            parse_to_end();
            break;

        default:
            parse_error("Illegal DO clause");
            pop_context();
            return;
        }
        break;
    }

    /* End of context */
    pop_context();
}
Beispiel #3
0
void parse_atom_callback(int a, ___ b, ___ c) {
    if (a != 10 && a != 13) out_char(b, a);
}
Beispiel #4
0
/* Output a line. */
static void out_line (const char* line)
{
  for (; *line != '\0'; line++)
    out_char(*line);
  out_char('\n');
}
Beispiel #5
0
/* NB: this function is never called with "bad" chars
 * (control chars or chars >= 0x7f)
 */
static void out_string(const char *str)
{
	while (*str)
		out_char(*str++);
}
Beispiel #6
0
/*======================================================================*
                              sys_write
*======================================================================*/
PUBLIC int sys_printx(int _unused1, int _unused2, char* s, struct proc* p_proc)
{
	const char * p;
	char ch;

	char reenter_err[] = "? k_reenter is incorrect for unknown reason";
	reenter_err[0] = MAG_CH_PANIC;

	/**
	 * @note Code in both Ring 0 and Ring 1~3 may invoke printx().
	 * If this happens in Ring 0, no linear-physical address mapping
	 * is needed.
	 *
	 * @attention The value of `k_reenter' is tricky here. When
	 *   -# printx() is called in Ring 0
	 *      - k_reenter > 0. When code in Ring 0 calls printx(),
	 *        an `interrupt re-enter' will occur (printx() generates
	 *        a software interrupt). Thus `k_reenter' will be increased
	 *        by `kernel.asm::save' and be greater than 0.
	 *   -# printx() is called in Ring 1~3
	 *      - k_reenter == 0.
	 */
	if (k_reenter == 0)  /* printx() called in Ring<1~3> */
		p = va2la(proc2pid(p_proc), s);
	else if (k_reenter > 0) /* printx() called in Ring<0> */
		p = s;
	else	/* this should NOT happen */
		p = reenter_err;

	/**
	 * @note if assertion fails in any TASK, the system will be halted;
	 * if it fails in a USER PROC, it'll return like any normal syscall
	 * does.
	 */
	if ((*p == MAG_CH_PANIC) ||
	    (*p == MAG_CH_ASSERT && p_proc_ready < &proc_table[NR_TASKS])) {
		disable_int();
		char * v = (char*)V_MEM_BASE;
		const char * q = p + 1; /* +1: skip the magic char */

		while (v < (char*)(V_MEM_BASE + V_MEM_SIZE)) {
			*v++ = *q++;
			*v++ = RED_CHAR;
			if (!*q) {
				while (((int)v - V_MEM_BASE) % (SCR_WIDTH * 16)) {
					/* *v++ = ' '; */
					v++;
					*v++ = GRAY_CHAR;
				}
				q = p + 1;
			}
		}

		__asm__ __volatile__("hlt");
	}

	while ((ch = *p++) != 0) {
		if (ch == MAG_CH_PANIC || ch == MAG_CH_ASSERT)
			continue; /* skip the magic char */

		out_char(tty_table[p_proc->nr_tty].p_console, ch);
	}

	return 0;
}
Beispiel #7
0
/* We have to overcome some problems with this implementation.  On the
   one hand the strfmon() function is specified in XPG4 and of course
   it has to follow this.  But on the other hand POSIX.2 specifies
   some information in the LC_MONETARY category which should be used,
   too.  Some of the information contradicts the information which can
   be specified in format string.  */
ssize_t
__vstrfmon_l (char *s, size_t maxsize, __locale_t loc, const char *format,
	      va_list ap)
{
  struct __locale_data *current = loc->__locales[LC_MONETARY];
  _IO_strfile f;
  struct printf_info info;
  char *dest;			/* Pointer so copy the output.  */
  const char *fmt;		/* Pointer that walks through format.  */

  dest = s;
  fmt = format;

  /* Loop through the format-string.  */
  while (*fmt != '\0')
    {
      /* The floating-point value to output.  */
      union
      {
	double dbl;
	__long_double_t ldbl;
      }
      fpnum;
      int int_format;
      int print_curr_symbol;
      int left_prec;
      int left_pad;
      int right_prec;
      int group;
      char pad;
      int is_long_double;
      int p_sign_posn;
      int n_sign_posn;
      int sign_posn;
      int other_sign_posn;
      int left;
      int is_negative;
      int sep_by_space;
      int other_sep_by_space;
      int cs_precedes;
      int other_cs_precedes;
      const char *sign_string;
      const char *other_sign_string;
      int done;
      const char *currency_symbol;
      size_t currency_symbol_len;
      long int width;
      char *startp;
      const void *ptr;
      char space_char;

      /* Process all character which do not introduce a format
	 specification.  */
      if (*fmt != '%')
	{
	  out_char (*fmt++);
	  continue;
	}

      /* "%%" means a single '%' character.  */
      if (fmt[1] == '%')
	{
	  out_char (*++fmt);
	  ++fmt;
	  continue;
	}

      /* Defaults for formatting.  */
      int_format = 0;			/* Use international curr. symbol */
      print_curr_symbol = 1;		/* Print the currency symbol.  */
      left_prec = -1;			/* No left precision specified.  */
      right_prec = -1;			/* No right precision specified.  */
      group = 1;			/* Print digits grouped.  */
      pad = ' ';			/* Fill character is <SP>.  */
      is_long_double = 0;		/* Double argument by default.  */
      p_sign_posn = -2;			/* This indicates whether the */
      n_sign_posn = -2;			/* '(' flag is given.  */
      width = -1;			/* No width specified so far.  */
      left = 0;				/* Right justified by default.  */

      /* Parse group characters.  */
      while (1)
	{
	  switch (*++fmt)
	    {
	    case '=':			/* Set fill character.  */
	      pad = *++fmt;
	      if (pad == '\0')
		{
		  /* Premature EOS.  */
		  __set_errno (EINVAL);
		  return -1;
		}
	      continue;
	    case '^':			/* Don't group digits.  */
	      group = 0;
	      continue;
	    case '+':			/* Use +/- for sign of number.  */
	      if (n_sign_posn != -2)
		{
		  __set_errno (EINVAL);
		  return -1;
		}
	      p_sign_posn = *_NL_CURRENT (LC_MONETARY, P_SIGN_POSN);
	      n_sign_posn = *_NL_CURRENT (LC_MONETARY, N_SIGN_POSN);
	      continue;
	    case '(':			/* Use ( ) for negative sign.  */
	      if (n_sign_posn != -2)
		{
		  __set_errno (EINVAL);
		  return -1;
		}
	      p_sign_posn = 0;
	      n_sign_posn = 0;
	      continue;
	    case '!':			/* Don't print the currency symbol.  */
	      print_curr_symbol = 0;
	      continue;
	    case '-':			/* Print left justified.  */
	      left = 1;
	      continue;
	    default:
	      /* Will stop the loop.  */;
	    }
	  break;
	}

      if (isdigit (*fmt))
	{
	  /* Parse field width.  */
	  width = to_digit (*fmt);

	  while (isdigit (*++fmt))
	    {
	      int val = to_digit (*fmt);

	      if (width > LONG_MAX / 10
		  || (width == LONG_MAX && val > LONG_MAX % 10))
		{
		  __set_errno (E2BIG);
		  return -1;
		}

	      width = width * 10 + val;
	    }

	  /* If we don't have enough room for the demanded width we
	     can stop now and return an error.  */
	  if (width >= maxsize - (dest - s))
	    {
	      __set_errno (E2BIG);
	      return -1;
	    }
	}

      /* Recognize left precision.  */
      if (*fmt == '#')
	{
	  if (!isdigit (*++fmt))
	    {
	      __set_errno (EINVAL);
	      return -1;
	    }
	  left_prec = to_digit (*fmt);

	  while (isdigit (*++fmt))
	    {
	      left_prec *= 10;
	      left_prec += to_digit (*fmt);
	    }
	}

      /* Recognize right precision.  */
      if (*fmt == '.')
	{
	  if (!isdigit (*++fmt))
	    {
	      __set_errno (EINVAL);
	      return -1;
	    }
	  right_prec = to_digit (*fmt);

	  while (isdigit (*++fmt))
	    {
	      right_prec *= 10;
	      right_prec += to_digit (*fmt);
	    }
	}

      /* Handle modifier.  This is an extension.  */
      if (*fmt == 'L')
	{
	  ++fmt;
	  if (!__ldbl_is_dbl)
	    is_long_double = 1;
	}

      /* Handle format specifier.  */
      char int_symbol[4];
      switch (*fmt++)
	{
	case 'i': {		/* Use international currency symbol.  */
	  const char *int_curr_symbol;

	  int_curr_symbol = _NL_CURRENT (LC_MONETARY, INT_CURR_SYMBOL);
	  strncpy(int_symbol, int_curr_symbol, 3);
	  int_symbol[3] = '\0';

	  currency_symbol_len = 3;
	  currency_symbol = &int_symbol[0];
	  space_char = int_curr_symbol[3];
	  int_format = 1;
	  break;
	}
	case 'n':		/* Use national currency symbol.  */
	  currency_symbol = _NL_CURRENT (LC_MONETARY, CURRENCY_SYMBOL);
	  currency_symbol_len = strlen (currency_symbol);
	  space_char = ' ';
	  int_format = 0;
	  break;
	default:		/* Any unrecognized format is an error.  */
	  __set_errno (EINVAL);
	  return -1;
	}

      /* If not specified by the format string now find the values for
	 the format specification.  */
      if (p_sign_posn == -2)
	p_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_P_SIGN_POSN : P_SIGN_POSN);
      if (n_sign_posn == -2)
	n_sign_posn = *_NL_CURRENT (LC_MONETARY, int_format ? INT_N_SIGN_POSN : N_SIGN_POSN);

      if (right_prec == -1)
	{
	  right_prec = *_NL_CURRENT (LC_MONETARY, int_format ? INT_FRAC_DIGITS : FRAC_DIGITS);

	  if (right_prec == '\377')
	    right_prec = 2;
	}

      /* If we have to print the digits grouped determine how many
	 extra characters this means.  */
      if (group && left_prec != -1)
	left_prec += __guess_grouping (left_prec,
				       _NL_CURRENT (LC_MONETARY, MON_GROUPING),
				       *_NL_CURRENT (LC_MONETARY,
						     MON_THOUSANDS_SEP));

      /* Now it's time to get the value.  */
      if (is_long_double == 1)
	{
	  fpnum.ldbl = va_arg (ap, long double);
	  is_negative = fpnum.ldbl < 0;
	  if (is_negative)
	    fpnum.ldbl = -fpnum.ldbl;
	}
      else
	{
Beispiel #8
0
bool __stdcall outop( op_t &x )
{
    char buf[MAXSTR];
    switch( x.type )
    {
    case o_imm:
        {
            switch(cmd.insnpref)
            {
            case SWFACTION_GETURL2:
                {
                    switch(x.specflag1)
                    {
                    case 'M':
                        if (x.value == 2)
                            out_keyword("method:POST");
                        else
                            x.value?out_keyword("method:GET"):out_keyword("method:none");
                        break;
                    case 'T':
                        x.value?out_keyword("target:sprite"):out_keyword("target:browser");
                        break;
                    case 'V':
                        x.value?out_keyword("vars:load"):out_keyword("vars:no");
                    }
                }
                break;
            case SWFACTION_CONSTANTPOOL:
                OutValue( x, OOFW_IMM );   
                break;
            case SWFACTION_GOTOFRAME2:
                if (x.n == 0)
                {
                    x.value?out_keyword("play:yes"):out_keyword("play:no");
                }
                else
                {
                    OutValue( x, OOFW_IMM );
                }
                break;
            case SWFACTION_DEFINEFUNCTION2:
                if (x.n == 5)
                {
                    //output the parameters first
                    uint16 p = cmd.auxpref,
                        i = 0;
                    uint16 param_length = get_word(cmd.ea + 1) - p -2;

                    out_char('{', COLOR_SYMBOL);
                    while (i < param_length)
                    {
                        
                        uint8 reg = get_byte(cmd.ea + 3 + p + i);
                        char* reg_name = buf;
                        *reg_name = 0;
                        
                        while ((i++ < param_length) && ((*(reg_name++) = get_byte(cmd.ea + 3 + p + i))!= 0)) {;}
                        i++;

                        if (reg_name > buf && *(--reg_name) == 0)
                        {
                            char r[6];
                            out_char('{', COLOR_SYMBOL);
                            if (reg)
                            {
                                qsnprintf(r, 5, "r%u", reg);
                                out_register( r );
                            }
                            else
                            {
                                out_char('0', COLOR_NUMBER);
                            }                            
                            out_line(",\"", COLOR_SYMBOL);
                            out_line(buf, COLOR_CHAR);
                            out_line("\"}, ", COLOR_SYMBOL);
                        }//if
                    }//while

                    out_line("}, ", COLOR_SYMBOL);
                }
                OutValue( x, OOFW_IMM );
                break;
            default:
                OutValue( x, OOFW_IMM );
            }
        }
        break;
    case o_reg:
        qsnprintf(buf, MAXSTR, "r%u", x.reg);
        out_register( buf );
        break;
    case o_near:
        if( !out_name_expr(x, x.addr, x.addr) ) 
        { 
            // if we could not create and output a name expression from the address
            OutValue(x, OOF_ADDR | OOF_NUMBER | OOFW_32); // instead output a raw value
            QueueMark(Q_noName, cmd.ea); //and mark this as a problem
        }
        break;
    case o_null:
        out_keyword("null");
        break;
    case o_undefined:
        out_keyword("undefined");
        break;
    case o_bool:
        x.value?out_keyword("true"):out_keyword("false");
        break;
    case o_const:
        out_keyword("constant:");
        OutValue( x, OOFW_IMM );
        break;
    case o_string:
        {
            uint16 p = 0;            
            char c;

            out_char('"', COLOR_SYMBOL);

            while ((c = get_byte(x.addr+p)) != 0)
            {
                if (is_printable(c))
                {
                    out_char(c, COLOR_CHAR);
                }
                else
                {
                    qsnprintf(buf, MAXSTR, "\\x%02X", c);
                    out_line(buf, COLOR_STRING);                    
                }
                p++;
            }

            out_char('"', COLOR_SYMBOL);
        }
        break;
    case o_void:
        return 0;
    default:
        warning( "out: %lx: bad optype %d", cmd.ea, x.type );
    }

    return 1;
}
Beispiel #9
0
/*======================================================================*
               out_string
 *======================================================================*/
PUBLIC void out_string(CONSOLE* p_con, char* str, int color)
{
    for (char* p = str; p && *p != '\0'; p++) {
        out_char(p_con, *p, color);
    }
}
Beispiel #10
0
/**
 * Output a string.
 */
void
out_string(const char *value)
{
  for(; *value; value++)
    out_char(*value);
}
Beispiel #11
0
/**************************************************************
 *  Name                 : actionSelector
 *  Description          : determine the action from the main
 *                         character routine                                               
 *  Parameters           : none
 *  Return               : none
 *  Critical/explanation : no
 **************************************************************/
void actionSelector() {

	if (!rs_ctrlFlag.sbf) {
		switch (re_selStatus) {
		case SEL_OFF:
			LightsOff();
			break;
		case SEL_AUTO:
			break;
		case SEL_PL:
			HalfLight();
			break;
		case SEL_LON:
			LightsOn();
			break;
		default:
			break;
		}

		switch (re_sensorStatus) {
		case LS_INV:
			LightsOff();
			break;
		case LS_LOW:
			LightsOn();
			break;
		case LS_MED:
			HalfLight();
			break;
		case LS_HIGH:
			LightsOff();
			break;
		default:
			break;
		}

		switch (re_sbStatus) {
		case TxRx: //transmitter receiver
			rs_ctrlFlag.sbf = 0;
			break;
		case STOP:
			put("| ");
			out_char('1');
			out_char('0');
			put(" | ");
			out_char(rs_charVal.bit3 | 0x30);
			out_char(rs_charVal.bit2 | 0x30);
			put(" | ");
			out_char(rs_charVal.bit1 | 0x30);
			out_char(rs_charVal.bit0 | 0x30);
			put(" | ");
			out_char(rs_charVal.bit5 | 0x30);
			out_char(rs_charVal.bit4 | 0x30);
			put(" | \r\n");
			//put("TxRx: Disabled \r\n");
			UART0_C2 &= ~(UART0_C2_TE_MASK | UART0_C2_RE_MASK);
			rs_ctrlFlag.sbf = 1;
			break;
		default:
			break;
		}
	} else {
		//do nothing
	}
}
Beispiel #12
0
/*
	Procedure: trm_getc

	Purpose: process pending keyboard characters


	Parameters: 	none

	Return value: none

	Calls:	intdos(GET_CHAR)
		out_char
		IO_complete

	Globals: dcb_trm, regs
		pendc

	Errors:	none
*/
void trm_getc(void)
{
	char	nextch;
	int	err;
	int 	finish;


	/* process any pending characters until block finished */
	finish = FALSE;
	while ((pendc > 0) && !finish) {

     		/* get the processed character, if any */
		regs.h.ah = (byte) GET_CHAR;
		regs.h.dl = 0xFF;
		err = intdos(&regs, &regs);
		err = err;
		nextch = (char) regs.h.al;


		/* if no character present, ignore */
		if (regs.x.flags & 0x40){
		       /*pendc = 1;*/
		}


		/* if char = 0, get the function code & ignore */
		else if (nextch==NULCH) {
			regs.h.ah = (byte) GET_CHAR;
			regs.h.dl = 0xFF;
			err = intdos(&regs, &regs);
			err = err;
		}


		else {
			/* if CR, store newline & advance cursor */
			if (nextch==CR) {
				out_char(CR);
				out_char(LF);
				*dcb_trm.in_buf_p++ = '\n';
				dcb_trm.in_ctr++;
			}

			/* if backspace, delete prev. char, if any */
			else if (nextch==BS) {
				if (dcb_trm.in_ctr > 0) {
					out_char(BS);
					out_char(' ');
					out_char(BS);
					dcb_trm.in_ctr--;
					dcb_trm.in_buf_p--;
				}
			}

			/* otherwise, just store & echo */
			else {
				out_char(nextch);
				*dcb_trm.in_buf_p++ = nextch;
				dcb_trm.in_ctr++;
			}

			*dcb_trm.in_buf_p = NULCH;

			/* terminate on CR (ENTER) */
			if (nextch == CR)  {
				finish = TRUE;
			}

			/* otherwise, terminate if buffer full */
			else if (dcb_trm.in_ctr >= dcb_trm.in_max) {
				out_char(CR);
				out_char(LF);
				finish = TRUE;
			}
		}

	/* decrement character counter */
	pendc--;
	}

	/* cleanup if terminating */
	if (finish) {
		dcb_trm.status = DEV_IDLE;
		*dcb_trm.in_count_p = dcb_trm.in_ctr;
		*dcb_trm.eflag_p = SET;
	}

	return;
}
Beispiel #13
0
/* Output startup string. */
bool
send_init_strings(int fd GCC_UNUSED, TTY * old_settings)
{
    int i;
    bool need_flush = FALSE;

    (void) old_settings;
#ifdef TAB3
    if (old_settings != 0 &&
	old_settings->c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
	old_settings->c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
	SET_TTY(fd, old_settings);
    }
#endif
    if (use_reset || use_init) {
	if (VALID_STRING(init_prog)) {
	    IGNORE_RC(system(init_prog));
	}

	need_flush |= sent_string((use_reset && (reset_1string != 0))
				  ? reset_1string
				  : init_1string);

	need_flush |= sent_string((use_reset && (reset_2string != 0))
				  ? reset_2string
				  : init_2string);

#if defined(set_lr_margin)
	if (VALID_STRING(set_lr_margin)) {
	    need_flush |= sent_string(TPARM_2(set_lr_margin, 0,
					      columns - 1));
	} else
#endif
#if defined(set_left_margin_parm) && defined(set_right_margin_parm)
	    if (VALID_STRING(set_left_margin_parm)
		&& VALID_STRING(set_right_margin_parm)) {
	    need_flush |= sent_string(TPARM_1(set_left_margin_parm, 0));
	    need_flush |= sent_string(TPARM_1(set_right_margin_parm,
					      columns - 1));
	} else
#endif
	    if (VALID_STRING(clear_margins)
		&& VALID_STRING(set_left_margin)
		&& VALID_STRING(set_right_margin)) {
	    need_flush |= sent_string(clear_margins);
	    need_flush |= to_left_margin();
	    need_flush |= sent_string(set_left_margin);
	    if (VALID_STRING(parm_right_cursor)) {
		need_flush |= sent_string(TPARM_1(parm_right_cursor,
						  columns - 1));
	    } else {
		for (i = 0; i < columns - 1; i++) {
		    out_char(' ');
		    need_flush = TRUE;
		}
	    }
	    need_flush |= sent_string(set_right_margin);
	    need_flush |= to_left_margin();
	}

	need_flush |= reset_tabstops(columns);

	need_flush |= cat_file((use_reset && reset_file) ? reset_file : init_file);

	need_flush |= sent_string((use_reset && (reset_3string != 0))
				  ? reset_3string
				  : init_3string);
    }

    return need_flush;
}
void main (void)
{
	char ch;
        uint32 timeout;
                 SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;
  	printf("\nRunning FlexMem demo!!\n");

        /* Partition the memory to enable FlexMem mode */
        if ( partition_flash( EEPROM_16_16, DFLASH_SIZE_128) )
        {
            /* Device has been partitioned for the first time, so this
             * means the counters have not been initialized yet. We'll
             * zero them out now.
             */
            *((uint32 *)(LONGWORD_COUNTER_ADDR)) = 0x0;

            /* Wait for the command to complete */
            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

            *((uint16 *)(WORD_COUNTER_ADDR)) = 0x0;

            /* Wait for the command to complete */
            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

            *((uint8 *)(BYTE_COUNTER_ADDR)) = 0x0;

            /* Wait for the command to complete */
            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));
        }

        /* Display the initial counter values */
        printf("\nlongword counter = 0x%08X", *(uint32 *)(LONGWORD_COUNTER_ADDR));
        printf("\nword counter = 0x%04X", *(uint16 *)(WORD_COUNTER_ADDR));
        printf("\nbyte counter = 0x%02X", *(uint8 *)(BYTE_COUNTER_ADDR));


        /* Initialize the PIT timer to generate an interrupt every 15s */

        /* Enable the clock to the PIT module */
        SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

        /* Enable the PIT timer module */
        PIT_MCR &= ~PIT_MCR_MDIS_MASK;

        /* Calculate the timeout value to get a 15s interval */
        timeout = 15 * periph_clk_khz * 1000;
        PIT_LDVAL0 = timeout;

        /* Enable the timer and enable interrupts */
        PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK;

        /* Enable the PIT timer interrupt in the NVIC */
        enable_irq(68);


	while(1)
	{
		ch = in_char();
		out_char(ch);
	}
}
Beispiel #15
0
void pn(bc_num num)
{
    bc_struct::out_num(num, 10, out_char, 0);
    out_char ('\n');
}
Beispiel #16
0
void arabic_line(unsigned short *end, unsigned short *begin)
{
    unsigned short code, code_last;
    unsigned char join, join_last;
    unsigned char mode, mode_last;
    struct arabic_join *info;

    group_last = ARABIC_OTHER;
    code_last = 0;
    join_last = JOIN_NONE;
    mode_last = JOIN_NONE;
    while (end >= begin)
    {
  //  	mode_last = JOIN_NONE;
        info = seek_info(code = *end);
        join = info == NULL ? JOIN_NONE : info->join;

        if ((join_last & JOIN_RIGT) && (join & JOIN_LEFT))
        {
            mode_last |= JOIN_RIGT;
            mode = JOIN_LEFT;
        }
        else
        {
            mode = JOIN_NONE;
        }

        if (code_last)
        {
        	if (ara_per_switch == PERSIAN_CHAR)
        	{
			if ((code_last == 0x06cc) && (mode_last >1))
				out_char(code_last, 2+mode_last);
//			else
//			if ((code_last == 0x0622) && (mode_last == 1))
//				out_char(code_last, 0);
			else
				out_char(code_last, mode_last);
        	}else
        	{
            		out_char(code_last, mode_last);
        	}
        }

        mode_last = mode;
        code_last = code;
        join_last = join;

        end--;
    }
    if (code_last)
		if (ara_per_switch == PERSIAN_CHAR)
        	{
			if ((code_last == 0x06cc) && (mode_last >1))
				out_char(code_last, 2+mode_last);
//			else
//			if ((code_last == 0x0622) && (mode_last == 1))
//				out_char(code_last, 0);
			else
				out_char(code_last, mode_last);
        	}else
        	{
            		out_char(code_last, mode_last);
        	}
//        out_char(code_last, mode_last);
}
Beispiel #17
0
/*
 *	CALL statement
 *	Handles CALL <procedure name> [ ( <parameter list> ) ] ;
 */
void
parse_call(TOKEN *first_token)
{
    TOKEN		token;
    int		token_class;
    DECL_MEMBER	*id_type;
    DECL_ID		*id_id;
    char		*new_func, *tmp_out_string;
    char		func_name[MAX_TOKEN_LENGTH];

    /* Get procedure name */
    token_class = get_token(&token);
    if (token_class != IDENTIFIER) {
        parse_error("Illegal procedure name");
        return;
    }

    out_white_space(first_token);

    /* Check for function conversion */
    if (check_cvt_id(&token, &cvt_functions[0], &new_func)) {
        out_str(new_func);
        token_class = get_token(&token);
    } else

        if (find_symbol(&token, &id_type, &id_id) &&
                (id_type->type->token_type != PROCEDURE)) {

            /* Skip white space */
            token.white_space_start = token.white_space_end;

            /* Check for call to pointer */
            func_name[0] = '\0';
            tmp_out_string = out_string;
            out_string = func_name;
            token_class = parse_variable(&token, &id_type, &id_id);
            out_string = tmp_out_string;

            if ((id_type->type->token_type == POINTER) ||
#ifdef OFFSET
                    (id_type->type->token_type == OFFSET) ||
#endif
                    (id_type->type->token_type == WORD)) {
                /* Yes - use pointer reference */
                out_str("(*");
                out_str(func_name);
                out_char(')');
            } else {
                parse_error("Illegal procedure reference");
                return;
            }
        } else {
            out_token_name(&token);
            token_class = get_token(&token);
        }

    /* Get parameter list (if any) */
    if (token_class == LEFT_PAREN) {
        out_token(&token);

        do {
            token_class = parse_expression(&token);
            out_token(&token);
        } while (token_class == COMMA);

        if (token_class == RIGHT_PAREN)
            /* Get end of line */
            check_eol();
        else
            parse_error("Illegal parameter list seperator");
    } else

        if (token_class == END_OF_LINE) {
            /* No parameter list */
            out_str("()");
            out_token(&token);
        } else
            parse_error("';' expected");
}
Beispiel #18
0
void __stdcall out( void )
{
    char buf[MAXSTR];

    init_output_buffer(buf, sizeof(buf));
    OutMnem();

    if (cmd.Op1.type != o_void)
    {
        // output first operand
        out_one_operand( 0 );
    }

    if( cmd.Op2.type != o_void )
    {
        //pading
        out_symbol( ',' );
        OutChar( ' ' );
        // output second operand
        out_one_operand( 1 );
    }

    if( cmd.Op3.type != o_void )
    {
        //pading
        out_symbol( ',' );
        OutChar( ' ' );
        // output third operand
        out_one_operand( 2 );
    }

    if( cmd.Op4.type != o_void )
    {
        //pading
        out_symbol( ',' );
        OutChar( ' ' );
        // output fourth operand
        out_one_operand( 3 );
    }

    if( cmd.Op5.type != o_void )
    {
        //pading
        out_symbol( ',' );
        OutChar( ' ' );
        // output fifth operand
        out_one_operand( 4 );
    }

    if( cmd.Op6.type != o_void )
    {
        //pading
        out_symbol( ',' );
        OutChar( ' ' );
        // output sixth operand
        out_one_operand( 5 );
    }

    //more processing due to instructions
    //having more than 6 operands
    op_t op;
    op.flags = OF_SHOW;

    switch(cmd.insnpref)
    {
    case SWFACTION_PUSH:
        {
            uint16 length = get_word(cmd.ea + 1) + 3; 
            uint16 p = cmd.auxpref;
            uint8 error = 0;
            while((length - p) > 0 && error == 0)
            {
                switch(get_byte(cmd.ea + p++))
                {
                case 0: //string
                    op.type = o_string;
                    op.dtyp = dt_string;
                    op.addr = cmd.ea + p;
                    //increment the pointer past the string
                    while((length - p) > 0 && get_byte(cmd.ea + p)){ p++; }
                    if ((length - p) > 0)
                    {
                        p++; //adjust for the null caracter
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 1: //float
                    op.type = o_imm;
                    //op.dtyp = dt_float;
                    op.dtyp = dt_dword;
                    if ((length - p) >= 4)
                    {
                        op.value = get_long(cmd.ea + p);
                        p += 4;
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 2: //null
                    op.type = o_null;
                    op.dtyp = dt_void;
                    break;
                case 3: //undefined
                    op.type = o_undefined;
                    op.dtyp = dt_void;
                    break;
                case 4: //register
                    op.type = o_reg;
                    op.dtyp = dt_byte;
                    if ((length - p) >= 1)
                    {
                        op.reg = get_byte(cmd.ea + p++);
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 5: //bool
                    op.type = o_bool;
                    op.dtyp = dt_byte;
                    if ((length - p) >= 1)
                    {
                        op.value = get_byte(cmd.ea + p++);
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 6: //double
                    op.type = o_imm;
                    op.dtyp = dt_double;
                    if ((length - p) >= 8)
                    {
                        double d = (double)(get_qword(cmd.ea + p));
                        op.value = d;
                        p += 8;
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 7: //integer
                    op.type = o_imm;
                    op.dtyp = dt_dword;
                    if ((length - p) >= 4)
                    {
                        op.value = get_long(cmd.ea + p);
                        p += 4;
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 8: //constant 8
                    op.type = o_const;
                    op.dtyp = dt_byte;
                    if ((length - p) >= 1)
                    {
                        op.value = get_byte(cmd.ea + p++);
                    }
                    else
                    {
                        error = 1;
                    }
                    break;
                case 9: //constant 16
                    op.type = o_const;
                    op.dtyp = dt_word;
                    if ((length - p) >= 2)
                    {
                        op.value = get_word(cmd.ea + p);
                        p += 2;
                    }
                    else
                    {
                        error = 1;
                    }
                default: //unknown type, will not search for more items if this happens
                    error = 1;
                } //switch
                if (error == 0)
                {
                    //pading
                    out_symbol( ',' );
                    OutChar( ' ' );
                    // output extra operand
                    outop(op);
                }
            } //while
        } //case
        break;
        case SWFACTION_TRY:
            //ToDo    
            break;
        case SWFACTION_DEFINEFUNCTION:
            // Todo: highlight somehow the function body
            // this must be written some other place because
            // every time IDA rephreshes the view a duplicate line appears. :(
            //describe(cmd.ea + cmd.size, true, "%s {", cmd.segpref ? (char*)cmd.Op1.addr : "<anonymous>");
            //describe(cmd.ea + cmd.size + get_word(cmd.ea + cmd.size - 2), true, " }");
            break;
    default:;
    }

    term_output_buffer();
    // attach a possible user-defined comment to this instruction
    gl_comm = 1;
    MakeLine( buf );

    //multiline instruction printing
    switch (cmd.insnpref)
    {
    case SWFACTION_CONSTANTPOOL:
        {    
            uint16 length = get_word(cmd.ea + 1);
            uint8 c = 0,
                count = 0;


            if(cmd.Op1.value == 0) 
                break;  

            //limit printed lines to 499
            //IDA does not suport more than 500 per item
            if (cmd.Op1.value > 498)
            {
                cmd.Op1.value = 498;
                msg ("\nWarning: CONSTANTPOOL instruction ar %X has more that 498 declared constants!\n", cmd.ea);
            }

            char line[MAXSTR], buf[MAXSTR];
            init_output_buffer(line, sizeof(line));

            OutChar( '    ' );
            out_char('0', COLOR_NUMBER);
            out_line(": \"",COLOR_SYMBOL);

            for (uint16 i = 2; i < length; i++)
            {
                c = get_byte(cmd.ea + i + 3);
                if (c == 0)
                {
                    if (count++ < (cmd.Op1.value - 1))
                    {
                        out_line("\"", COLOR_SYMBOL);
                        //terminate buffer for current constant
                        //and print it
                        term_output_buffer(); MakeLine(line);

                        //initialize buffer for next constant                        
                        init_output_buffer(line, sizeof(line));
                        
                        OutChar( '    ' );
                        qsnprintf(buf, MAXSTR, "%d", count);
                        out_line(buf, COLOR_NUMBER);
                        out_line(": \"", COLOR_SYMBOL);
                    }
                    else
                        break;
                }
                else
                {
                    if (is_printable(c))
                        out_char(c, COLOR_CHAR);
                    else
                    {
                        qsnprintf(buf, MAXSTR, "\\x%02X", c);
                        out_line(buf, COLOR_STRING);
                    }
                }//else
            }//for

            out_char('"',COLOR_SYMBOL);

            //terminate buffer for last constant
            //and print it
            term_output_buffer(); MakeLine(line);
        }
        break;
    }
}
Beispiel #19
0
/*
 *	Parse statement starting with an identifier.
 *	Possibilities include:
 *		Assignment
 *		Procedure statement
 */
void
parse_identifier(TOKEN *first_token)
{
    TOKEN		token, next_token;
    TOKEN		param_token, attrib_token, type_token;
    int		token_class, next_token_class;
    DECL		*decl_list, *extra_decl_list;
    PARAM_LIST	*param_list, *param_ptr;
    DECL_MEMBER	*decl_ptr;
    DECL_ID		*decl_id;
    BOOLEAN		extern_proc, got_type, interrupt_proc;
    char		*tmp_text_ptr;

    /* Check for label or procedure */
    tmp_text_ptr = text_ptr;
    token_class = get_token(&token);

    if (token_class == LABEL) {
        /* Determine if label or procedure definition */
        next_token_class = get_token(&next_token);
        if ((next_token_class == RESERVED) &&
                (next_token.token_type == PROCEDURE)) {
            /*
             *	Procedure - Check for parameter list
             */
            param_list = NULL;
            token_class = get_token(&param_token);
            if (token_class == LEFT_PAREN) {
                /* Yes - get parameter list */
                get_param_list(&param_list);

                /* Get token after parameter list */
                token_class = get_token(&attrib_token);
            } else
                /* No param list - save as attribute */
                token_copy(&param_token, &attrib_token);

            out_white_space(first_token);
            extern_proc = FALSE;
            interrupt_proc = FALSE;

            got_type = (token_class == RESERVED) &&
                       (attrib_token.token_type >= BYTE) &&
                       (attrib_token.token_type <= SELECTOR);
            if (got_type) {
                /*
                 *	Process [ <type> ]
                 */
                token_copy(&attrib_token, &type_token);
                token_class = get_token(&attrib_token);
            }

            while (token_class == RESERVED) {
                if (attrib_token.token_type == INTERRUPT) {
                    /*
                     *	Process [ <interrupt> ]
                     */
                    interrupt_proc = TRUE;
                    token_class = get_token(&attrib_token);
                    if (token_class == NUMERIC)
                        /* Interrupt number */
                        token_class = get_token(&attrib_token);
                } else

                    /*
                     *	Process [ EXTERNAL |  { [ PUBLIC ] [ REENTRANT ] } ]
                     */
                    if (attrib_token.token_type == EXTERNAL) {
                        out_str("extern");
                        out_must_white(&attrib_token);
                        extern_proc = TRUE;

                        token_class = get_token(&attrib_token);
                    } else

                        if ((attrib_token.token_type == PUBLIC) ||
                                (attrib_token.token_type == REENTRANT)) {
                            do {
                                if (attrib_token.token_type == PUBLIC) {
                                    /* Ignore for now */
                                    token_class = get_token(&attrib_token);
                                } else

                                    if (attrib_token.token_type == REENTRANT) {
                                        /* Ignore for now */
                                        token_class = get_token(&attrib_token);
                                    } else
                                        break;
                            } while (token_class == RESERVED);
                        } else
                            break;
            }

            if (token_class != END_OF_LINE) {
                parse_error("';' expected");
                return;
            }

            if (interrupt_proc && !extern_proc)
                parse_warning("INTERRUPT procedure declared");

            /* Create declaration for procedure */
            get_element_ptr(&decl_ptr);
            get_var_ptr(&decl_ptr->name_list);
            /* Type = PROCEDURE */
            get_token_ptr(&decl_ptr->type);
            token_copy(&next_token, decl_ptr->type);
            /* Name = procedure name */
            get_token_ptr(&decl_ptr->name_list->name);
            token_copy(first_token, decl_ptr->name_list->name);
            /* Flag if parameter list */
            if (param_list)
                decl_ptr->initialization = DATA;
            /* Add it to context */
            add_to_context(decl_ptr);

            if (got_type) {
                /* Output procedure type */
                out_token_name(&type_token);
                out_must_white(&type_token);
            }

            /* Output procedure name */
            out_token_name(first_token);

            if (extern_proc) {
                out_str("()");

                if (param_list)
                    /* Parse parameter declarations */
                    parse_param_list(param_list, &decl_list,
                                     &extra_decl_list);

                out_char(';');
                /* Eat closing 'END [<proc name>];' */
                token_class = get_token(&token);
                if ((token_class != RESERVED) ||
                        (token.token_type != END)) {
                    parse_error("END expected");
                    return;
                }

                out_white_space(&token);
                token_class = get_token(&token);
                if (token_class == IDENTIFIER) {
                    token_class = get_token(&token);
                }

                if (token_class != END_OF_LINE) {
                    parse_error("';' expected");
                }

                return;
            } else

                if (param_list) {
                    out_token(&param_token);
                    /* Output parameter list */
                    param_ptr = param_list;
                    while (param_ptr) {
                        out_token(&param_ptr->param);
                        param_ptr = param_ptr->next_param;
                        if (param_ptr)
                            out_char(',');
                    }
                    out_char(')');

                    /* Parse parameter declarations */
                    parse_param_list(param_list, &decl_list,
                                     &extra_decl_list);

                    /* Output declarations */
                    if (decl_list) {
                        out_decl(decl_list);
                        /* Add declarations to context */
                        add_decl_to_context(decl_list);
                    }

                    out_str("\n{");		/* } for dumb vi */

                    if (extra_decl_list) {
                        out_decl(extra_decl_list);
                        /* Add declarations to context */
                        add_decl_to_context(extra_decl_list);
                    }

                    /* Discard declarations */
                    free_decl(decl_list);
                    free_decl(extra_decl_list);
                } else
                    /* No parameter list */
                    out_str("()\n{");	/* } for dumb vi */

            /* Create new context */
            new_context(PROCEDURE, first_token);
            /* Parse statements to END */
            parse_to_end();
            /* Pop procedure context */
            pop_context();
        } else {
            /*
             *	Label - add label name
             */
            out_token(first_token);
            /* Add colon */
            out_token(&token);

            /* Is this a defined label or a module? */
            if (find_symbol(first_token, &decl_ptr, &decl_id)) {
                if (decl_ptr->type->token_class == LABEL) {
                    /* Label - new context */
                    new_context(MODULE, first_token);
                    parse_statement(&next_token);
                    pop_context();
                } else {
                    parse_error("Illegal label name");
                    return;
                }
            } else
                parse_statement(&next_token);
        }
        return;
    }

    /* Assignment statement */
    text_ptr = tmp_text_ptr;
    token_copy(first_token, &token);
    token_class = parse_variable(&token, &decl_ptr, &decl_id);

    /* Check for multiple assignments */
    while (token_class == COMMA) {
        /* Print ' =' instead of ',' */
        out_str(" =");
        out_white_space(&token);
        /* Get identifier part of next assignment variable */
        token_class = get_token(&token);
        if (token_class != IDENTIFIER) {
            parse_error("Illegal assignment");
            return;
        }

        /* Parse remainder of variable (if any) */
        token_class = parse_variable(&token, &decl_ptr, &decl_id);
    }

    if (token_class == OPERATOR) {
        if (token.token_type != EQUAL) {
            parse_error("Illegal use of identifier");
            return;
        }

        out_token(&token);

        /* Check for POINTER assignment */
        if (decl_ptr->type->token_type == POINTER) {
            /* Yes - cast it */
            out_str(" (");
            out_str(TYPE_POINTER);
            out_str(" *) ");
        }

        if (parse_expression(&token) != END_OF_LINE)
            parse_error("';' expected");
        else
            out_token(&token);
        return;
    } else

        if (token_class != LABEL) {
            parse_error("Illegal use of identifier");
            return;
        }

}
Beispiel #20
0
void xprintf( char * ctrl, ...)
{
   int long_flag;
   int dot_flag;

   char  ch;
   va_list argp;
   va_start( argp, ctrl);

   for ( ; *ctrl; ctrl++) {
			RstWatchdog();
      if (*ctrl != '%') {
         out_char(*ctrl);
         continue;
         }

      /* initialize all the flags for this format.   */
      dot_flag   =
      long_flag  =
      left_flag  =
      do_padding = 0;
      pad_character = ' ';
      num2=32767; //0x7ffff

try_next:
      ch = *(++ctrl);

      if (isdigit(ch)) {
         if (dot_flag)
            num2 = getnum(&ctrl);
         else {
            if (ch == '0')
               pad_character = '0';

            num1 = getnum(&ctrl);
            do_padding = 1;
         }
         ctrl--;
         goto try_next;
      }

      switch (tolower(ch)) {
         case '%':
              out_char( '%');
              continue;

         case '-':
              left_flag = 1;
              break;

         case '.':
              dot_flag = 1;
              break;

         case 'l':
              long_flag = 1;
              break;

         case 'd':
              if (long_flag || ch == 'D') {
                 outnum( va_arg(argp, long), 10L);
                 continue;
                 }
              else {
                 outnum( va_arg(argp, int), 10L);
                 continue;
                 }
         case 'x':
              outnum( (U32)va_arg(argp, int), 16L);
              continue;

         case 's':
              outs( va_arg( argp, char *));
              continue;

         case 'c':
              out_char( va_arg( argp, int));
              continue;

         case '\\':
              switch (*ctrl) {
                 case 'a':
                      out_char( 0x07);
                      break;
                 case 'h':
                      out_char( 0x08);
                      break;
                 case 'r':
                      out_char( 0x0D);
                      break;
                 case 'n':
                      out_char( 0x0D);
                      out_char( 0x0A);
                      break;
                 default:
                      out_char( *ctrl);
                      break;
                 }
              ctrl++;
              break;

         default:
              continue;
         }
Beispiel #21
0
/*
 *	End of line (Null statement)
 */
void
parse_eol(TOKEN *first_token)
{
    out_white_space(first_token);
    out_char(';');
}
Beispiel #22
0
void parse_bracket_callback2(int a, ___ b, ___ c) {
    if (a[(char *)b]) out_char(c, a);
}
Beispiel #23
0
/*
 *	Parse function call
 */
int
parse_function(TOKEN *token)
{
    int		token_class;
    BOOLEAN		left_shift, right_shift;
    char		*new_func;
    DECL_MEMBER	*decl_ptr;
    DECL_ID		*decl_id;

    /* Function call - check for SHL or SHR */
    out_white_space(token);
    left_shift = !strcmp(token->token_name, "shl") ||
                 !strcmp(token->token_name, "SHL");
    right_shift = !strcmp(token->token_name, "shr") ||
                  !strcmp(token->token_name, "SHR");
    if (left_shift || right_shift) {
        /* SHL(expr, expr) or SHR(expr, expr) */
        /* Check for '(' */
        token_class = get_token(token);
        if (token_class != LEFT_PAREN) {
            parse_error("'(' expected");
            return ERROR;
        }
        out_token(token);

        /* Output first expression */
        out_char('(');
        token_class = parse_expression(token);
        if (token_class != COMMA) {
            parse_error("',' expected");
            return ERROR;
        }

        out_str(left_shift ? ") << (" : ") >> (");

        /* Output second expression */
        token_class = parse_expression(token);
        if (token_class != RIGHT_PAREN) {
            parse_error("Missing ')'");
            return ERROR;
        }
        out_char(')');
        out_token(token);
    } else {

        /* Check for a type cast function */
        if (check_cvt_id(token, &cast_functions[0], &new_func)) {
            /* Convert to a cast */
            out_char('(');
            out_str(new_func);
            out_str(") ");
        } else

            /* Check for a function conversion */
            if (check_cvt_id(token, &cvt_functions[0], &new_func)) {
                /* Convert to desired function */
                out_str(new_func);
            } else {

                /* Output function name */
                out_token_name(token);

                /* Check for parameter list */
                if (find_symbol(token, &decl_ptr, &decl_id)) {
                    if (decl_ptr->type->token_type != PROCEDURE) {
                        parse_error("Illegal function call");
                        return ERROR;
                    }
                    if (decl_ptr->initialization != DATA) {
                        /* No param list */
                        token_class = get_token(token);
                        return token_class;
                    }
                }
            }

        /* Check for parameter list */
        token_class = get_token(token);
        if (token_class != LEFT_PAREN) {
            parse_warning("Parameter list expected");
            return token_class;
        }
        out_token(token);

        /* Parse to closing right paren */
        do {
            token_class = parse_expression(token);
            out_token(token);
        } while (token_class == COMMA);

        if (token_class != RIGHT_PAREN) {
            parse_error("Missing ')'");
            return ERROR;
        }
    }
    /* Return token following function */
    token_class = get_token(token);
    return token_class;
}
Beispiel #24
0
void parse_branch_recurse(char *a, ___ b, int *c) {
    __ d=0, e=0, f=0;
    int g=0, h=0, i=0, j, k=0, l=0;
    char m[127];

    if (*a) {
        if (*a == '(') {
            if (1[a] == ')') {
                out_char(&d, 0);
                g = 2;
            } else {
                parse_re_recurse(a + 1, &d, &g);
                if (!g || *(a + g + 1) != ')') die();
                g += 2;
            }
        } else if (*a == '[') {
            if (a[g+1] == '^') { ++g; i = 1; }
            do127(0, (___)m, (___)i, parse_bracket_callback1);
            if (a[g+1] == ']') { ++g; ']'[m] = !i; }
            parse_bracket_recurse(a + 1, &g, m, i);
            do127(0, (___)m, &d, parse_bracket_callback2);
            if (!g || *(a + g + 1) != ']') die();
            g += 2;
        } else if (*a == '\\') {
            if (! 1[a]) die();
            out_char(&d, *(a+1));
            g = 2;
        } else if (*a == '.') {
            do127(1, &d, 0, parse_atom_callback);
            g = 1;
        } else if (*a != '.' && *a != '[' && *a != '(' && *a != ')'
             && *a != '|' && *a != '?' && *a != '{' && *a != '\\') {
            out_char(&d, *a);
            g = 1;
        }
    }
    a += g;

    if (*a) {
        if (*a == '?') {
            ++a;
            ++l;
            ++h;
        } else if (*a == '{') {
            ++a;
            ++h;

            j = scan_int(a, &k, 0);
            if (j) {
                if (k > 255) die();
                h += j;
                a += j;

                if (*a == ',') {
                    ++h;
                    ++a;
                    j = scan_int(a, &l, 0);
                    if (j) {
                        if (l > 255) die();
                        h += j;
                        a += j;
                        if (*a == '}') {
                            ++h;
                            ++a;
                            if (l < k) die();
                        } else die();
                    } else die();
                } else if (*a == '}') {
                    ++h;
                    ++a;
                    l = k;
                } else die();
            } else die();
        }

        if (h) {
            out_multiplex_recurse(k, l, &d, &f);
            walk(d, &d, 0, 0, out_destroy_callback);
            d = f;
        }
        g += h;
    }

    if (! g) return;

    e = malloc(sizeof(_));
    **e = d;
    1[*e] = 0;

    out_append(b, e);

    d = 0;
    *c += g;

    parse_branch_recurse(a, b, c);
}
Beispiel #25
0
void usbFunctionWriteOut( uchar *data, uchar len )
{

    /*  postpone receiving next data    */
    usbDisableAllRequests();

    /*    host -> device:  request   */
    do {
        char    c;

        //    delimiter?
        c    = *data++;
        if( c>0x20 ) {
            if( 'a'<=c && c<='z' )
                c    -= 0x20;        //    to upper case
            rbuf[rcnt++]    = c;
            rcnt    &= 7;
            continue;
        }
        if( rcnt==0 )
            continue;

        //    command
        if( rcnt==1 ) {
            char            *ptr;
            volatile uchar  *addr   = (uchar *)((unsigned int)tos);
            uchar           x;

            switch( rbuf[0] ) {
            case '@':   //    who
                        ptr = PSTR( CMD_WHO );
                        while( (c=pgm_read_byte(ptr++))!=0 ) {
                            out_char(c); 
                        }
                        break;
            case '?':   //    get
                        x    = *addr;
                        out_char( u2h(x>>4) ); 
                        out_char( u2h(x&0x0f) ); 
                        break;
            case '=':   //    set
                        cli();
                        *addr    = val;
                        sei();
                        break;
            case '$':   //    set twice
                        cli();
                        *addr    = val;
                        *addr    = val2;
                        sei();
                        break;
            case '&':   //    and & set
                        cli();
                        *addr    &= val;
                        sei();
                        break;
            case '|':   //    or & set
                        cli();
                        *addr    |= val;
                        sei();
                        break;
            case '^':   //    xor & set
                        cli();
                        *addr    ^= val;
                        sei();
                        break;
            default:    //    error
                        out_char( '!' ); 
            }
            out_char( '\r' ); 
            out_char( '\n' ); 
            rcnt    = 0;
            continue;
        }

        //    number
        if( rcnt==2 ) {
            val2    = val;
            val     = tos;
            tos     = (h2u(rbuf[0])<<4) | h2u(rbuf[1]);
            rcnt    = 0;
            continue;
        }

        //    sfr
        if( rcnt>=4 ) {
            val2    = val;
            val    = tos;
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || !defined PORTC
            tos    = 0x30 + ( 'D' - rbuf[--rcnt] ) * 3;
#else
            tos    = 0x20 + ( rbuf[--rcnt] - 'A' ) * 3;
#endif
            rbuf[rcnt]    = 0;
            if( !strcmp_P(rbuf,PSTR("PIN")) )
                tos    += 0;
            else if( !strcmp_P(rbuf,PSTR("DDR")) )
                tos    += 1;
            else if( !strcmp_P(rbuf,PSTR("PORT")) )
                tos    += 2;
            else
                tos    = 0x20;        //    error
            rcnt    = 0;
        }
    } while(--len);