Exemplo n.º 1
0
/* LUA_NUMBER */
static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l);
  if (comma) save(LS, '.', l);
  while (isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == '.') {
    save_and_next(LS, l);
    if (LS->current == '.') {
      save_and_next(LS, l);
      save(LS, '\0', l);
      luaX_lexerror(LS,
                 "ambiguous syntax (decimal point x string concatenation)",
                 TK_NUMBER);
    }
  }
  while (isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == 'e' || LS->current == 'E') {
    save_and_next(LS, l);  /* read `E' */
    if (LS->current == '+' || LS->current == '-')
      save_and_next(LS, l);  /* optional exponent sign */
    while (isdigit(LS->current)) {
      checkbuffer(LS, l);
      save_and_next(LS, l);
    }
  }
  save(LS, '\0', l);
  if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
    luaX_lexerror(LS, "malformed number", TK_NUMBER);
}
Exemplo n.º 2
0
Arquivo: llex.c Projeto: jcubic/ToME
static void read_string (LexState *LS, int del, SemInfo *seminfo) {
  lua_State *L = LS->L;
  size_t l = 0;
  checkbuffer(L, 10, l);
  save_and_next(L, LS, l);
  while (LS->current != del) {
    checkbuffer(L, 10, l);
    switch (LS->current) {
      case EOZ:  case '\n':  case '\r':
        save(L, '\0', l);
        luaX_error(LS, "unfinished string", TK_STRING);
        break;  /* to avoid warnings */
      case '\\':
        next(LS);  /* do not save the '\' */
        switch (LS->current) {
          case 'a': save(L, '\a', l); next(LS); break;
          case 'b': save(L, '\b', l); next(LS); break;
          case 'f': save(L, '\f', l); next(LS); break;
          case 'n': save(L, '\n', l); next(LS); break;
          case 'r': save(L, '\r', l); next(LS); break;
          case 't': save(L, '\t', l); next(LS); break;
          case 'v': save(L, '\v', l); next(LS); break;
          case '\n':
            save(L, '\n', l);
            inclinenumber(LS);
            if (LS->current == '\r') next(LS);
            break;
          case '\r':
            save(L, '\n', l);
            inclinenumber(LS);
            if (LS->current == '\n') next(LS);
            break;
          case '0': case '1': case '2': case '3': case '4':
          case '5': case '6': case '7': case '8': case '9': {
            int c = 0;
            int i = 0;
            do {
              c = 10*c + (LS->current-'0');
              next(LS);
            } while (++i<3 && isdigit(LS->current));
            if (c != (unsigned char)c) {
              save(L, '\0', l);
              luaX_error(LS, "escape sequence too large", TK_STRING);
            }
            save(L, c, l);
            break;
          }
          default:  /* handles \\, \", \', and \? */
            save_and_next(L, LS, l);
        }
        break;
      default:
        save_and_next(L, LS, l);
    }
  }
  save_and_next(L, LS, l);  /* skip delimiter */
  save(L, '\0', l);
  seminfo->ts = luaS_newlstr(L, L->Mbuffer+1, l-3);
}
Exemplo n.º 3
0
static size_t readname (LexState *LS) {
  size_t l = 0;
  checkbuffer(LS, l);
  do {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  } while (isalnum(LS->current) || LS->current == '_');
  save(LS, '\0', l);
  return l-1;
}
Exemplo n.º 4
0
static void read_string (LexState *LS, int del, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l);
  save_and_next(LS, l);
  while (LS->current != del) {
    checkbuffer(LS, l);
    switch (LS->current) {
      case EOZ:
        save(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_EOS);
        break;  /* to avoid warnings */
      case '\n':
        save(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_STRING);
        break;  /* to avoid warnings */
      case '\\':
        next(LS);  /* do not save the `\' */
        switch (LS->current) {
          case 'a': save(LS, '\a', l); next(LS); break;
          case 'b': save(LS, '\b', l); next(LS); break;
          case 'f': save(LS, '\f', l); next(LS); break;
          case 'n': save(LS, '\n', l); next(LS); break;
          case 'r': save(LS, '\r', l); next(LS); break;
          case 't': save(LS, '\t', l); next(LS); break;
          case 'v': save(LS, '\v', l); next(LS); break;
          case '\n': save(LS, '\n', l); inclinenumber(LS); break;
          case EOZ: break;  /* will raise an error next loop */
          default: {
            if (!isdigit(LS->current))
              save_and_next(LS, l);  /* handles \\, \", \', and \? */
            else {  /* \xxx */
              int c = 0;
              int i = 0;
              do {
                c = 10*c + (LS->current-'0');
                next(LS);
              } while (++i<3 && isdigit(LS->current));
              if (c > UCHAR_MAX) {
                save(LS, '\0', l);
                luaX_lexerror(LS, "escape sequence too large", TK_STRING);
              }
              save(LS, c, l);
            }
          }
        }
        break;
      default:
        save_and_next(LS, l);
    }
  }
  save_and_next(LS, l);  /* skip delimiter */
  save(LS, '\0', l);
  seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 1, l - 3);
}
Exemplo n.º 5
0
static const char *readname (LexState *LS) {
  lua_State *L = LS->L;
  size_t l = 0;
  checkbuffer(L, 10, l);
  do {
    checkbuffer(L, 10, l);
    save_and_next(L, LS, l);
  } while (isalnum(LS->current) || LS->current == '_');
  save(L, '\0', l);
  return L->Mbuffer;
}
Exemplo n.º 6
0
Arquivo: llex.c Projeto: jcubic/ToME
static void read_long_string (LexState *LS, SemInfo *seminfo) {
  lua_State *L = LS->L;
  int cont = 0;
  size_t l = 0;
  checkbuffer(L, 10, l);
  save(L, '[', l);  /* save first '[' */
  save_and_next(L, LS, l);  /* pass the second '[' */
  for (;;) {
    checkbuffer(L, 10, l);
    switch (LS->current) {
      case EOZ:
        save(L, '\0', l);
        if (seminfo)
          luaX_error(LS, "unfinished long string", TK_STRING);
        else
          luaX_error(LS, "unfinished comment", TK_EOS);
        break;  /* to avoid warnings */
      case '[':
        save_and_next(L, LS, l);
        if (LS->current == '[') {
          cont++;
          save_and_next(L, LS, l);
        }
        continue;
      case ']':
        save_and_next(L, LS, l);
        if (LS->current == ']') {
          if (cont == 0) goto endloop;
          cont--;
          save_and_next(L, LS, l);
        }
        continue;
      case '\n':
        save(L, '\n', l);
        inclinenumber(LS);
        if (LS->current == '\r') next(LS);
        continue;
      case '\r':
        save(L, '\n', l);
        inclinenumber(LS);
        if (LS->current == '\n') next(LS);
        continue;
      default:
        if (seminfo)	/* no need to save complete comment */
          save(L, LS->current, l);
        next(LS);
    }
  } endloop:
  save_and_next(L, LS, l);  /* skip the second ']' */
  save(L, '\0', l);
  if (seminfo)
    seminfo->ts = luaS_newlstr(L, L->Mbuffer+2, l-5);
}
Exemplo n.º 7
0
static size_t readname (LexState *LS, char ch) {
  size_t l = 0;
  checkbuffer(LS, l);
  if (ch != 0)
  {
	  checkbuffer(LS, l);
	  save(LS, ch, l);
  }
  do {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  } while (lex_isalnum(LS->current) || LS->current == '_');
  save(LS, '\0', l);
  return l-1;
}
Exemplo n.º 8
0
static void read_long_string (LexState *LS, SemInfo *seminfo) {
  int cont = 0;
  size_t l = 0;
  checkbuffer(LS, l);
  save(LS, '[', l);  /* save first `[' */
  save_and_next(LS, l);  /* pass the second `[' */
  if (LS->current == '\n')  /* string starts with a newline? */
    inclinenumber(LS);  /* skip it */
  for (;;) {
    checkbuffer(LS, l);
    switch (LS->current) {
      case EOZ:
        save(LS, '\0', l);
        luaX_lexerror(LS, (seminfo) ? "unfinished long string" :
                                   "unfinished long comment", TK_EOS);
        break;  /* to avoid warnings */
      case '[':
        save_and_next(LS, l);
        if (LS->current == '[') {
          cont++;
          save_and_next(LS, l);
        }
        continue;
      case ']':
        save_and_next(LS, l);
        if (LS->current == ']') {
          if (cont == 0) goto endloop;
          cont--;
          save_and_next(LS, l);
        }
        continue;
      case '\n':
        save(LS, '\n', l);
        inclinenumber(LS);
        if (!seminfo) l = 0;  /* reset buffer to avoid wasting space */
        continue;
      default:
        save_and_next(LS, l);
    }
  } endloop:
  save_and_next(LS, l);  /* skip the second `]' */
  save(LS, '\0', l);
  if (seminfo)
    seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 2, l - 5);
}
Exemplo n.º 9
0
/* mainloop */
int mymain(int port, char *serialport, int baud, char *validip)
{
	/* check if port, serialport and baudrate are set, otherwise use defaults */
	if (port == -1) {
		msg_Info("No Port set - using 1337");
		port = 1337;
	}

	if (serialport == NULL) {
		msg_Info("No Serialport set - using /dev/ttyS0");
		serialport = "/dev/ttyS0";
	}

	if (baud == -1) {
		msg_Info("No Baudrate set - using 9600");
		baud = 9600;
	}

	int sock;
	struct sockaddr_in server;
	struct sockaddr_in client;

	unsigned char buffer[BUFFSIZE];

	unsigned int clientlen, serverlen;
	int received = 0;

	/* create the UDP socket */
	if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
		die("Failed to create socket\n");
	}

	/* construct the server sockaddr_in structure */
	memset(&server, 0, sizeof(server));			/* Clear struct */
	server.sin_family = AF_INET;				/* Internet/IP */
	server.sin_addr.s_addr = htonl(INADDR_ANY);	/* Any IP address */
	server.sin_port = htons(port);				/* server port */

	/* bind the socket */
	serverlen = sizeof(server);
	if (bind(sock, (struct sockaddr *) &server, serverlen) < 0) {
		die("Failed to bind server socket\n");
	}
	
	/* signal handler */
	signal(SIGTERM,sigfunc);
	signal(SIGINT,sigfunc);

	/* open serial port */
	global_serialport = open_port(serialport, baud);
	
	/* wait for UDP-packets */
	while (42) {
		/* Receive a message from the client */
		clientlen = sizeof(client);

		if ((received = recvfrom(sock, buffer, BUFFSIZE, 0,
								 (struct sockaddr *) &client,
								 &clientlen)) < 0) {
			die("Failed to receive message\n");
		}
		
		if(validip != NULL && client.sin_addr.s_addr != check_ip(validip)) {
			msg_Info("Wrong client tried to connect to server: %s", inet_ntoa(client.sin_addr));
		} else {
			msg_Info("Client connected: %s", inet_ntoa(client.sin_addr));
			
			if (checkbuffer(buffer) == 0) {
				msg_Dbg("buffer0-5: '%s'", buffer);
				
				/* RS-232 Code start */
				int n = write(global_serialport, buffer, BUFFSIZE);
				
				if (n < 0) {
					msg_Err("write() failed!");
				} else {
					msg_Dbg("Value(s) written to serial port");
				}
				/* RS-232 Code end */
			}
		}
	}
	
	/* close serial port */
	close(global_serialport);
    return 0;
}
Exemplo n.º 10
0
static void read_wstring (LexState *LS, int del, SemInfo *seminfo) {
  size_t l = 0;
  checkbuffer(LS, l * 2);
  wsave_and_next(LS, l);
  while (LS->current != del) {
    checkbuffer(LS, l * 2);
    switch (LS->current) {
      case EOZ:
        wsave(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_EOS);
        break;  /* to avoid warnings */
      case '\n':
        wsave(LS, '\0', l);
        luaX_lexerror(LS, "unfinished string", TK_STRING);
        break;  /* to avoid warnings */
      case '\\':
        next(LS);  /* do not save the `\' */
        switch (LS->current) {
          case 'a': wsave(LS, '\a', l); next(LS); break;
          case 'b': wsave(LS, '\b', l); next(LS); break;
          case 'f': wsave(LS, '\f', l); next(LS); break;
          case 'n': wsave(LS, '\n', l); next(LS); break;
          case 'r': wsave(LS, '\r', l); next(LS); break;
          case 't': wsave(LS, '\t', l); next(LS); break;
          case 'v': wsave(LS, '\v', l); next(LS); break;
          case '\n': wsave(LS, '\n', l); inclinenumber(LS); break;
          case EOZ: break;  /* will raise an error next loop */
          case 'x': {
			  int ch;
			  next(LS);
			  ch = tolower(LS->current);
              if (!lex_isdigit(ch) && !(ch >= 'a' && ch <= 'f') )
		          save(LS, 'x', l);  /* handles \\, \", \', and \? */
			  else {  /* \xxx */
				  int c = 0;
				  int i = 0;
				  int numDigits = 4;
				  do {
					  ch = tolower(LS->current);
					  if (lex_isdigit(ch))
					    c = 16*c + (ch-'0');
					  else if (ch >= 'a' && ch <= 'f')
						c = 16*c + (ch-'a') + 10;
					  next(LS);
					  ch = tolower(LS->current);
				  } while (++i<numDigits && (lex_isdigit(ch) || (ch >= 'a' && ch <= 'f')));
				  wsave(LS, c, l);
			  }
			  break;
          }
          default: {
            if (!lex_isdigit(LS->current))
              wsave_and_next(LS, l);  /* handles \\, \", \', and \? */
            else {  /* \xxx */
              int c = 0;
              int i = 0;
              do {
                c = 10*c + (LS->current-'0');
                next(LS);
              } while (++i<3 && lex_isdigit(LS->current));
              if (c > UCHAR_MAX) {
                wsave(LS, '\0', l);
                luaX_lexerror(LS, "escape sequence too large", TK_STRING);
              }
              wsave(LS, c, l);
            }
          }
        }
        break;
      default:
        wsave_and_next(LS, l);
    }
  }
  wsave_and_next(LS, l);  /* skip delimiter */
  wsave(LS, '\0', l);
  seminfo->ts = luaS_newlwstr(LS->L, (const lua_WChar*)(luaZ_buffer(LS->buff) + 1 * 2), (l - 3 * 2) / 2);
}
Exemplo n.º 11
0
/* LUA_NUMBER */
static int read_numeral (LexState *LS, int period, SemInfo *seminfo) {
  int isReal = 0;
  int startsWithZero = LS->current == '0';
  size_t l = 0;
  checkbuffer(LS, l);
  if (period) {
	save(LS, '.', l);
	isReal = 1;
  }
  if (startsWithZero) {
	next(LS);
	if (LS->current == 'x') {
	  /* Process a hex number */
	  int ch = 0;
      int c = 0;
      int i = 0;
      int numDigits = 8;
	  next(LS);
      do {
        ch = tolower(LS->current);
        if (lex_isdigit(ch))
          c = 16*c + (ch-'0');
        else if (ch >= 'a' && ch <= 'f')
          c = 16*c + (ch-'a') + 10;
        next(LS);
        ch = tolower(LS->current);
      } while (++i<numDigits && (lex_isdigit(ch) || (ch >= 'a' && ch <= 'f')));
	  seminfo->r = c;
	  return TK_NUMBER;
	} else {
      checkbuffer(LS, 1);
      save(LS, '0', l);
	}
  }
  while (lex_isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == '.') {
    isReal = 1;
    save_and_next(LS, l);
    if (LS->current == '.') {
      save_and_next(LS, l);
      save(LS, '\0', l);
      luaX_lexerror(LS,
                 "ambiguous syntax (decimal point x string concatenation)",
                 TK_NUMBER);
    }
  }
  while (lex_isdigit(LS->current)) {
    checkbuffer(LS, l);
    save_and_next(LS, l);
  }
  if (LS->current == 'e' || LS->current == 'E') {
    isReal = 1;
    save_and_next(LS, l);  /* read `E' */
    if (LS->current == '+' || LS->current == '-')
      save_and_next(LS, l);  /* optional exponent sign */
    while (lex_isdigit(LS->current)) {
      checkbuffer(LS, l);
      save_and_next(LS, l);
    }
  }
  save(LS, '\0', l);
  if (isReal) {
    if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
      luaX_lexerror(LS, "malformed number", TK_NUMBER);
	return TK_NUMBER;
  } else {
    if (!luaO_str2d(luaZ_buffer(LS->buff), &seminfo->r))
      luaX_lexerror(LS, "malformed integer", TK_NUMBER);
	return TK_NUMBER;
  }
}
Exemplo n.º 12
0
int main(void)
{
	unsigned k,i,j;
	e_dma_desc_t dma_desc[4];
	unsigned *dst, *src, *dst1, *src1, *dst2, *src2;
	unsigned tran;
	unsigned tran1;
	unsigned index[3];
	unsigned neighbour_core;
	unsigned *n_row, *n_col, *p;
	unsigned *mailbox, *mailbox1, *mailbox2, *mailbox3;
	n_row = (unsigned *)0x00006400;
	n_col = (unsigned *)0x00006404;
	tran = 128;
	p = 0x0000;
	
	// Get the core id of neighbour core
	e_neighbor_id(E_NEXT_CORE, E_ROW_WRAP, n_row, n_col);

	neighbour_core = (unsigned) e_get_global_address(*n_row, *n_col, p);

	// Define the mailbox
	mailbox = (unsigned *)0x6000;
	mailbox1 = (unsigned *)0x6100;
	mailbox2 = (unsigned *)0x6200;
	mailbox3 = (unsigned *)0x6300;

	// Initialize the buffer address for dma chain test
	src = (int *)0x2000;
	dst = (int *)(neighbour_core + (unsigned)0x2000);
	src1 = (int *)0x2300;
	dst1 = (int *)(neighbour_core + (unsigned)0x2500);
	src2 = (int *)0x2600;
	dst2 = (int *)(neighbour_core + (unsigned)0x2a00);

	// Test for word size
 	// Initialize the source and destination buffer
	for (i=0; i<tran; i++)
	{ 
		src[i]  = 0xaaaaaaaa;
		src1[i] = 0xbbbbbbbb;
		src2[i] = 0xcccccccc;
	}

	for (i=0; i<tran*6; i++)
	{
		dst[i] = 0x00000000;
	}
	

	// Prepare for the descriptor for 2d dma 
	
	e_dma_set_desc(E_DMA_0,(E_DMA_ENABLE|E_DMA_MASTER|E_DMA_WORD), 0x0000,
	0x0004, 0x0004,
	0x0080, 0x0003,
	0x0104 , 0x0304,
	(void *)src,(void *)dst, &dma_desc[0]);
	
	// Start transaction
	e_dma_start(&dma_desc[0], E_DMA_0);
	
	// Wait
	e_dma_wait(E_DMA_0);		
	
	// Check the destination buffer value
	index[0] = checkbuffer(dst,  (unsigned)0xaaaaaaaa, tran);
	index[1] = checkbuffer(dst1, (unsigned)0xbbbbbbbb, tran);
	index[2] = checkbuffer(dst2, (unsigned)0xcccccccc, tran);

	if((index[0]|index[1]|index[2]) == 0)
	{
		mailbox[0] = 0xffffffff;
	}else
	{
		mailbox[0] = 0x00000000;
	}

	// Test for doubleword size
 	// Initialize the source and destination buffer
	for (i=0; i<tran; i++)
	{ 
		src[i]  = 0xaaaaaaaa;
		src1[i] = 0xbbbbbbbb;
		src2[i] = 0xcccccccc;
	}

	for (i=0; i<tran*6; i++)
	{
		dst[i] = 0x00000000;
	}
	
	

	// Prepare for the descriptor for 2d dma 
	
	e_dma_set_desc(E_DMA_0,(E_DMA_ENABLE|E_DMA_MASTER|E_DMA_DWORD), 0x0000,
	0x0008, 0x0008,
	0x0040, 0x0003,
	0x0108 , 0x0308,
	(void *)src,(void *)dst, &dma_desc[0]);
	
	// Start transaction
	e_dma_start(&dma_desc[0], E_DMA_0);
	
	// Wait 
	e_dma_wait(E_DMA_0);	

	// Check the destination buffer value
	index[0] = checkbuffer(dst,  (unsigned)0xaaaaaaaa, tran);
	index[1] = checkbuffer(dst1, (unsigned)0xbbbbbbbb, tran);
	index[2] = checkbuffer(dst2, (unsigned)0xcccccccc, tran);

	if((index[0]|index[1]|index[2]) == 0)
	{
		mailbox1[0] = 0xffffffff;
	}else
	{
		mailbox1[0] = 0x00000000;
	}

	// Test for half size
 	// Initialize the source and destination buffer
	for (i=0; i<tran; i++)
	{ 
		src[i]  = 0xaaaaaaaa;
		src1[i] = 0xbbbbbbbb;
		src2[i] = 0xcccccccc;
	}

	for (i=0; i<tran*6; i++)
	{
		dst[i] = 0x00000000;
	}
	
	

	// Prepare for the descriptor for 2d dma 
	
	e_dma_set_desc(E_DMA_0,(E_DMA_ENABLE|E_DMA_MASTER|E_DMA_HWORD), 0x0000,
	0x0002, 0x0002,
	0x0100, 0x0003,
	0x0102 , 0x0302,
	(void *)src,(void *)dst, &dma_desc[0]);
	
	// Start transaction
	e_dma_start(&dma_desc[0], E_DMA_0);
	
	// Wait 
	e_dma_wait(E_DMA_0);		

	// Check the destination buffer value
	index[0] = checkbuffer(dst,  (unsigned)0xaaaaaaaa, tran);
	index[1] = checkbuffer(dst1, (unsigned)0xbbbbbbbb, tran);
	index[2] = checkbuffer(dst2, (unsigned)0xcccccccc, tran);

	if((index[0]|index[1]|index[2]) == 0)
	{
		mailbox2[0] = 0xffffffff;
	}else
	{
		mailbox2[0] = 0x00000000;
	}

	// Test for byte size
 	// Initialize the source and destination buffer
	for (i=0; i<tran; i++)
	{ 
		src[i]  = 0xaaaaaaaa;
		src1[i] = 0xbbbbbbbb;
		src2[i] = 0xcccccccc;
	}

	for (i=0; i<tran*6; i++)
	{
		dst[i] = 0x00000000;
	}
	

	// Prepare for the descriptor for 2d dma 
	
	e_dma_set_desc(E_DMA_0,(E_DMA_ENABLE|E_DMA_MASTER|E_DMA_BYTE), 0x0000,
	0x0001, 0x0001,
	0x0200, 0x0003,
	0x0101 , 0x0301,
	(void *)src,(void *)dst, &dma_desc[0]);
	
	// Start transaction
	e_dma_start(&dma_desc[0], E_DMA_0);
	
	// Wait 
	e_dma_wait(E_DMA_0);	
	
	// Check the destination buffer value
	index[0] = checkbuffer(dst,  (unsigned)0xaaaaaaaa, tran);
	index[1] = checkbuffer(dst1, (unsigned)0xbbbbbbbb, tran);
	index[2] = checkbuffer(dst2, (unsigned)0xcccccccc, tran);

	if((index[0]|index[1]|index[2]) == 0)
	{
		mailbox3[0] = 0xffffffff;
	}else
	{
		mailbox3[0] = 0x00000000;
	}
	return 0;
}