Пример #1
0
Object *Builtin_subtract(ListObject *arg, ListObject *context)
{
	NumberObject *ret = NULL;

	int i = 0;
	while (i < arg->len)
	{
		Object *term = arg->arr[i];
		if (Object_istype(term, NUMBER_OBJECT))
		{
			if (i == 0)
			{
				double init = NUM(term)->value;
				if (arg->len == 1)
					init = -init;
				ret = new_NumberObject(init);
			}
			else
				NUM(ret)->value -= NUM(term)->value;
		}
		else
		{
			if (ret != NULL)
				del_Object(OBJ(ret));
			ret = NULL;
			break;
		}
		i++;
	}
	if (ret == NULL)
		cause_error(INCORRECT_ARGUMENT_ERROR, "(<number> <number> ...)", 23);

	return OBJ(ret);
}
Пример #2
0
Object *Builtin_set(ListObject *arg, ListObject *context)
{
	if (arg->len == 2 && arg->arr[0]->type == SYMBOL_OBJECT)
	{
		SymbolObject *symbol = SYM(arg->arr[0]);
		Object *value = arg->arr[1];
		Context_set(context, symbol, value);
		return value;
	}
	else
	{
		cause_error(INCORRECT_ARGUMENT_ERROR, "(set <symbol> <object>)", 23);
		return NULL;
	}
}
Пример #3
0
int
main (int argc, char *argv[])
{
  // Note that the default behavior is to log to STDERR...

  int counter = 1 ;

  if (argc > 1)
    {
      if (ACE_LOG_MSG->open (argv[0],
                             ACE_Log_Msg::OSTREAM) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();
      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));
    }
  else
    {
      if (ACE_LOG_MSG->open (argv[0]) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();

      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));

      // Exercise many different combinations of STDERR and OSTREAM.

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter++,
                  8,
                  "",
                  "hello",
                  10000));

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cout);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->msg_ostream (0);

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cerr);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

      // Print out the binary bytes of the array in hex form.
      ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                                (char *) array,
                                sizeof array);

      // Disable the LM_DEBUG and LM_INFO messages at the process level.
      u_long priority_mask =
        ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
      ACE_CLR_BITS (priority_mask,
                    LM_DEBUG | LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_SET_BITS (priority_mask,
                    LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_CLR_BITS (priority_mask, LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);
      
      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      char badname[] = "badname";

      char *l_argv[2];
      l_argv[0] = badname;
      l_argv[1] = 0;

      if (ACE_OS::execv (badname,
                         l_argv) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "%n: (%x), %p%r\n",
                      10000,
                      badname,
                      cleanup));
          ACE_OS::_exit ();
        }
    }
  return 0;
}
static void
test_log_msg_features (const ACE_TCHAR *program)
{
  // Note that the default behavior is to log to STDERR...

  int counter = 1 ;

  if (ACE_LOG_MSG->open (program) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("cannot open logger!!!\n")));

  cause_error ();

  // Check to see what happened.
  if (ACE_LOG_MSG->op_status () == -1
      && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("op_status and errnum work!\n")));
  else
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("op_status and errnum failed!\n")));

  const char *badname = "badname";

  // We use the DEBUG messages instead of error messages. This is to
  // help the scripts. If we print out error messages the scripts
  // start catching them as errors.
  if (ACE_OS::open (badname,
                    O_RDONLY) == ACE_INVALID_HANDLE)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("%n: (%x), can't open %s%r\n"),
                10000,
                badname,
                cleanup));

  // Try a log operation that would overflow the logging buffer if not
  // properly guarded.
  ACE_TCHAR big[ACE_Log_Record::MAXLOGMSGLEN + 1];
  size_t i = 0;
  const ACE_TCHAR alphabet[] = ACE_TEXT ("abcdefghijklmnopqrstuvwxyz");
  size_t j = ACE_OS::strlen (alphabet);
  while (i < ACE_Log_Record::MAXLOGMSGLEN)
    big[i++] = alphabet[i % j];
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big: %s\n"), big));

  // Exercise many different combinations of OSTREAM.

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter++,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("hello"),
              10000));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // The next two messages shouldn't print.
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

  // Print out the binary bytes of the array in hex form.
  ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                            (char *) array,
                            sizeof array);

  // Disable the LM_DEBUG and LM_INFO messages.
  u_long priority_mask =
    ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
                LM_DEBUG | LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_SET_BITS (priority_mask,
                LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_CLR_BITS (priority_mask, LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));
}
Пример #5
0
/*
Lexer_getnext
	returns the next Token in the source text
	can potentially return EOF or unknown token, and/or set_error
	uses lexical definition macros to generate appropriate tokens
*/
Token *Lexer_getnext(Lexer *self)
{
    char c;
    if (self->scanner->curr_index == -1)
        c = Scanner_getnext(self->scanner);
    else
        c = Scanner_getcurr(self->scanner);

    // ignore whitespace
    while (c && strchr(WHITESPACE_CHARS, c))
        c = Scanner_getnext(self->scanner);

    // begin creating a Token
    Token *token = new_Token(c, self->scanner->curr_index,
                             self->scanner->curr_line, self->scanner->curr_col);

    if (c == EOF_CHAR)
        token->type = EOF_TOKEN;

    else if (c == '.') // decimal numeric literal
    {
        token->type = UNKNOWN_TOKEN;
        c = Scanner_getnext(self->scanner);

        while (strchr(NUMERIC_CHARS, c))
        {
            if (token->type != NUMERIC_LITERAL_TOKEN)
                token->type = NUMERIC_LITERAL_TOKEN;

            Token_append(token, c);
            c = Scanner_getnext(self->scanner);
        }

        if (token->type == UNKNOWN_TOKEN)
            cause_error(UNEXPECTED_TOKEN_ERROR, token->buffer, token->len);
    }

    else if (strchr(SYMBOL_CHARS, c))
    {
        token->type = SYMBOL_TOKEN;
        c = Scanner_getnext(self->scanner);

        while (strchr(SYMBOL_CHARS, c))
        {
            Token_append(token, c);
            c = Scanner_getnext(self->scanner);
        }
    }

    else if (strchr(NUMERIC_CHARS, c))
    {
        token->type = NUMERIC_LITERAL_TOKEN;
        c = Scanner_getnext(self->scanner);

        int has_decimal = 0;
        while (strchr(NUMERIC_CHARS, c) || (!has_decimal && c == '.'))
        {
            if (c == '.') has_decimal = 1;
            Token_append(token, c);
            c = Scanner_getnext(self->scanner);
        }
    }

    else if (strchr(STRING_QUOTE_CHARS, c))
    {
        token->type = STRING_LITERAL_TOKEN;
        char end_quote = c;
        c = Scanner_getnext(self->scanner);

        while (c != end_quote)
        {
            if (c == EOF_CHAR) // EOF in string
            {
                token->type = EOF_TOKEN;
                cause_error(UNTERMINATED_STRING_ERROR, token->buffer, token->len);
                Scanner_getnext(self->scanner);
                return token;
            }

            Token_append(token, c);
            c = Scanner_getnext(self->scanner);
        }

        Token_append(token, c);
        Scanner_getnext(self->scanner);
    }

    else if (c == LIST_START_CHAR)
    {
        token->type = LIST_START_TOKEN;
        Scanner_getnext(self->scanner);
    }

    else if (c == LIST_END_CHAR)
    {
        token->type = LIST_END_TOKEN;
        Scanner_getnext(self->scanner);
    }

    else if (c == ESCAPE_CHAR)
    {
        token->type = ESCAPE_TOKEN;
        Scanner_getnext(self->scanner);
    }

    else if (c == EVALUATE_CHAR)
    {
        token->type = EVALUATE_TOKEN;
        Scanner_getnext(self->scanner);
    }

    else
    {
        token->type = UNKNOWN_TOKEN;
        cause_error(UNEXPECTED_TOKEN_ERROR, token->buffer, token->len);
        Scanner_getnext(self->scanner);
    }

    return token;
}
Пример #6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int counter = 1;

  if (argc > 1) // Just give a dummy command-line argument to trigger this path.
    {
      if (ACE_LOG_MSG->open (argv[0],
                             ACE_Log_Msg::OSTREAM) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();
      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));
    }
  else   // The default behavior is to log to STDERR...
    {
      if (ACE_LOG_MSG->open (argv[0]) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();

      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));

      // Exercise many different combinations of STDERR and OSTREAM.

      double f = 3.1416 * counter++;
      int i = 10000;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "hello",
                  i));

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cout);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      // This message will print twice - once for OSTREAM and once for
      // STDERR.

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->msg_ostream (0);

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cerr);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

#endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */

      static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

      // Print out the binary bytes of the array in hex form.
      ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                                (char *) array,
                                sizeof array);

      // Disable the LM_DEBUG and LM_INFO messages at the process level.
      u_long priority_mask =
        ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
      ACE_CLR_BITS (priority_mask,
                    LM_DEBUG | LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_SET_BITS (priority_mask,
                    LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_CLR_BITS (priority_mask, LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      char badname[] = "badname";

      char *l_argv[2];
      l_argv[0] = badname;
      l_argv[1] = 0;

      if (ACE_OS::execv (badname,
                         l_argv) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "%n: (%x), %p%r\n",
                      10000,
                      badname,
                      cleanup));
          ACE_OS::_exit ();
        }
    }
  return 0;
}