Exemple #1
0
static int search_col(FILE *ps,real r,real g,real b)
{
  int  i;
  
  for(i=0; (i<nrgb); i++)
    if ( (fabs(rgb[i].r-r) < GMX_REAL_EPS) &&
	 (fabs(rgb[i].g-g) < GMX_REAL_EPS) &&
	 (fabs(rgb[i].b-b) < GMX_REAL_EPS))
      return i;
  
  if (nrgb >= maxrgb) 
    {
      maxrgb+=100;
      srenew(rgb,maxrgb);
    }
  
  ps_defcolor(ps,r,g,b,i2a(nrgb));
  fprintf(ps,"/B%d {%s b} bind def\n",nrgb,i2a(nrgb));
  rgb[i].r=r;
  rgb[i].g=g;
  rgb[i].b=b;
  nrgb++;
  
  return nrgb-1;
}
Exemple #2
0
char *inet_ntoa_r(struct in_addr in,char* buf) {
  unsigned int len;
  unsigned char *ip=(unsigned char*)&in;
  len=i2a(buf,ip[0]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len;
  len+=i2a(buf+ len,ip[3]); buf[len]=0;
  return buf;
}
Exemple #3
0
char *itoa(int i, char *a, int r)
{
  if ((r < 2) || (r > 36)) r = 10;
  if (i<0) {
    *a = '-';
    *i2a(-(unsigned)i,a+1,r) = 0;
  } else *i2a(i,a,r) = 0;
  return a;
}
Exemple #4
0
/**
 Transforms integer i into an ascii string and stores the result in a;
 string is encoded in the base indicated by r.
 @param i Number to be converted
 @param a String result
 @param r Base of value; must be in the range 2 - 36
 @return Returns a
*/
static char *
_itoa(int i, char *a, int r) {
    r = ((r < 2) || (r > 36)) ? 10 : r;
    if(i < 0) {
        *a = '-';
        *i2a(-i, a+1, r) = 0;
    }
    else *i2a(i, a, r) = 0;
    return a;
}
bool TestDataStructuresParent::RecvTest6(
        const InfallibleTArray<IntDoubleArrays>& i1,
        InfallibleTArray<IntDoubleArrays>* o1)
{
    test_assert(3 == i1.Length(), "wrong length");

    IntDoubleArrays id1(i1[0]);
    test_assert(42 == id1.get_int(), "wrong value");

    InfallibleTArray<int> i2a(i1[1].get_ArrayOfint());
    test_assert(3 == i2a.Length(), "wrong length");
    test_assert(1 == i2a[0], "wrong value");
    test_assert(2 == i2a[1], "wrong value");
    test_assert(3 == i2a[2], "wrong value");

    InfallibleTArray<double> i3a(i1[2].get_ArrayOfdouble());
    test_assert(3 == i3a.Length(), "wrong length");
    test_assert(1.0 == i3a[0], "wrong value");
    test_assert(2.0 == i3a[1], "wrong value");
    test_assert(3.0 == i3a[2], "wrong value");

    o1->AppendElement(id1);
    o1->AppendElement(IntDoubleArrays(i2a));
    o1->AppendElement(IntDoubleArrays(i3a));

    return true;
}
Exemple #6
0
static char *i2a(unsigned i, char *a, unsigned r)
{
    if (i / r > 0)
        a = i2a(i / r, a, r);
    *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % r];
    return a + 1;
}
Exemple #7
0
t
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                              vsprintf.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                                    Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#include "type.h"
#include "const.h"
#include "protect.h"
#include "string.h"
#include "proc.h"
#include "tty.h"
#include "console.h"
#include "global.h"
#include "keyboard.h"
#include "proto.h"



/*======================================================================*
                                i2a
 *======================================================================*/
PRIVATE char* i2a(int val, int base, char ** ps)
{
	int m = val % base;
	int q = val / base;
	if (q) {
		i2a(q, base, ps);
	}
	*(*ps)++ = (m < 10) ? (m + '0') : (m - 10 + 'A');

	return *ps;
}
Exemple #8
0
void Wifly_Print_Last_Received_Message(void){

	if(response.type == PING){
		USART2_putstr("Type: PING\n\rID: \0");
		USART2_putstr(i2a(response.id));
	}
	else if(response.type == UPDATE){
		USART2_putstr("Type: UPDATE\n\r\ID: \0");
		USART2_putstr(i2a(update.id));
//		printHex(update.id);
		USART2_putstr("\n\rAVERAGE: \0");
		USART2_putstr(i2a(update.average));
//		printHex(update.average);

		//TODO: Print out the array
	}
Exemple #9
0
// ----------------------------------------------------------------------------
PRIVATE char *i2a(int val, int base, char **ps) {
    int m = val % base;
    int q = val / base;
    if (q) i2a(q, base, ps);
    *(*ps)++ = (m < 10) ? (m + '0') : (m - 10 + 'A');

    return *ps;
}
Exemple #10
0
/**
 * Gets the value at the given id
 * id - the id to set the servo location from
 */
void Wifly_Set_Servo_Location(uint32_t id) {

    uint32_t val = update.values[id];
    USART2_putstr("Setting servo location to: \0");
    USART2_putstr(i2a(val));
    USART2_putstr("\n\r\0");
    PWM_to_Deg(val);

}
Exemple #11
0
int main(int argc, char* argv[]) {
	char buff[5];
	
	char* p = i2a(buff, sizeof(buff), 123456789);
	
	puts(p);
	
	return 0;
}
Exemple #12
0
void _print_num ( const char __flash * s, UINT16 Num)
{
  char* pi2a;
  __no_init char i2a_locbuf[6];
  pi2a=&i2a_locbuf[0];
  i2a(pi2a, Num);
  while (*s) UART_TX (*s++);
//  UART_TX(':'); 
  while (*pi2a) UART_TX(*pi2a++);  
  UART_TX(',');
  UART_TX(' '); 
}
Exemple #13
0
char *Time_gmtstring(time_t time, char *result) {
        if (result) {
                char x[2];
                struct tm ts;
                /* This implementation needs to be fast and is around 50%
                 faster than strftime */
                gmtime_r(&time, &ts);
                memcpy(result, "aaa, xx aaa xxxx xx:xx:xx GMT\0", 30);
                /*              0    5  8   1214 17 20 23    29 */
                memcpy(result, days+3*ts.tm_wday, 3);
                i2a(ts.tm_mday);
                result[5] = x[0];
                result[6] = x[1];
                memcpy(result + 8, months+3*ts.tm_mon, 3);
                i2a((ts.tm_year+1900)/100);
                result[12] = x[0];
                result[13] = x[1];
                i2a((ts.tm_year+1900)%100);
                result[14] = x[0];
                result[15] = x[1];
                i2a(ts.tm_hour);
                result[17] = x[0];
                result[18] = x[1];
                i2a(ts.tm_min);
                result[20] = x[0];
                result[21] = x[1];
                i2a(ts.tm_sec);
                result[23] = x[0];
                result[24] = x[1];
        }
	return result;     
}
Exemple #14
0
char *Time_string(time_t time, char *result) {
#define i2a(i) (x[0]=(i/10)+'0', x[1]=(i%10)+'0')
        if (result) {
                char x[2];
                struct tm ts;
                /* This implementation needs to be fast and is around 50%
                   faster than strftime */
                localtime_r((const time_t *)&time, &ts);
                memcpy(result, "aaa, xx aaa xxxx xx:xx:xx\0", 26);
                /*              0    5  8   1214 17 20 2326 */
                memcpy(result, days+3*ts.tm_wday, 3);
                i2a(ts.tm_mday);
                result[5] = x[0];
                result[6] = x[1];
                memcpy(result + 8, months+3*ts.tm_mon, 3);
                i2a((ts.tm_year+1900)/100);
                result[12] = x[0];
                result[13] = x[1];
                i2a((ts.tm_year+1900)%100);
                result[14] = x[0];
                result[15] = x[1];
                i2a(ts.tm_hour);
                result[17] = x[0];
                result[18] = x[1];
                i2a(ts.tm_min);
                result[20] = x[0];
                result[21] = x[1];
                i2a(ts.tm_sec);
                result[23] = x[0];
                result[24] = x[1];
        }
	return result;     
}
Exemple #15
0
/**
 * Converts an array to a string representation
 * array- uint32_t pointer to head of array
 * size- size of array
 */
void print_array_to_string(uint32_t array[], uint32_t size){
	uint8_t a;
	uint8_t *str_ptr;
	uint32_t *array_ptr;
	uint32_t index = 0;

	str_ptr = &a;
	array_ptr = array;

	USART2_putstr("[\0");
	for(index = 0; index < size; index++){
		uint32_t val = array[index];
		USART2_putstr(i2a(val));
		USART2_putstr(", \0");
	}
	USART2_putstr("]\0");

}
Exemple #16
0
static int setup_index(
  const char *alpha					/* the alphabet */
)
{
  int i, a;

  /* flag unused letters */
  for (i=0; i<MAXASCII; i++) a2i(i) = -1;	/* illegal letters */

  /* set up the hashing and unhashing indices */
  for (i = 0; (a = alpha[i]); i++) {
    a = islower(a) ? toupper(a) : a;		/* convert to uppercase */
    a2i(a) = i;					/* position in alphabet */
    i2a(i) = a;
    if (isupper(a)) a2i(tolower(a)) = i;	/* set lowercase as well */
  }
  index_alen = i;				/* set global */

  return(i);
} /* setup_index */
Exemple #17
0
/**
 * Updates the server with the value read in from the potentiometer.
 * value - the value read in from the potentiometer.
 */
void Wifly_Send_Update(uint32_t value) {
    int i=0;

    Update_req_t msg;
    Update_req_t *pmsg;
    uint8_t *bytp;

    pmsg = &msg;
    bytp = (uint8_t *)pmsg;

    pmsg->type = UPDATE;
    pmsg->id = ID;
    pmsg->value = value;

    //Print out the sent value
    USART2_putstr("\n\rTRANSMITTED: \0");
    USART2_putstr(i2a(value));
    USART2_putstr("\n\r\0");

    //Zero the number of received bytes
    rcvd = 0;

    //Zero out the response object
    update.average = 0;
    update.id = 0;
    update.type = 0;
    response.type = 0;
    response.id = 0;


    for(i=0; i<sizeof(Update_req_t); i++,bytp++) {
        USART3_putchar(*bytp);
//		//Prints out the sent values in a user-readable format
//		USART2_putchar((*bytp)+48);

    }

//	USART2_putstr("\n\r\0");
//	USART2_putstr("Sent!\n\r\0");

}
Exemple #18
0
extern char *i2s(
  int index
)
{
  int i;
  int q, r, c;
  char *string = NULL;
  int l = 0;
  
  /* complete the computation */
  do {
    q = (index)/index_alen;
    r = (index) - q*index_alen;
    c = r;
    Resize(string, l + 1, char)
    string[l++] = i2a(c);
    index = q-1;
  } while (q > 0); 
  Resize(string, l + 1, char)
  string[l] = '\0';
  for (i=0; i<l/2; i++) SWAP(char, string[i], string[l-i-1]);

  return(string);
} /* i2s */
bool TestDataStructuresParent::RecvTest7(
        const Actors& i1,
        const Actors& i2,
        const Actors& i3,
        Actors* o1,
        Actors* o2,
        Actors* o3)
{
    test_assert(42 == i1.get_int(), "wrong value");

    InfallibleTArray<int> i2a(i2.get_ArrayOfint());
    test_assert(3 == i2a.Length(), "wrong length");
    test_assert(1 == i2a[0], "wrong value");
    test_assert(2 == i2a[1], "wrong value");
    test_assert(3 == i2a[2], "wrong value");

    assert_arrays_equal(mKids, i3.get_ArrayOfPTestDataStructuresSubParent());

    *o1 = 42;
    *o2 = i2a;
    *o3 = mKids;

    return true;
}
size_t  strftime ( char* dst, size_t max, const char* format, const struct tm* tm ) 
{
    char*         p = dst;
    const char*   src;
    unsigned int  no;
    char          buf [5];
  
  
    for ( ; *format != '\0'; format++ ) {
	if (*format == '%') {
	    if (*++format == '%') {
	        *p++ = '%';
	    }
	    else
again:
    	    switch (*format) {
//          case '%': *p++ = '%';  				 break;			// reduce size of jump table
            case 'n': *p++ = '\n'; 				 break;
            case 't': *p++ = '\t'; 				 break;
	    case 'O': case 'E': ++format; goto again;
            case 'c': src = "%b %a %d %k:%M:%S %Z %Y";        	 goto _strf;
            case 'r': src = "%I:%M:%S %p";                    	 goto _strf;
            case 'R': src = "%H:%M";      			 goto _strf;
            case 'x': src = "%b %a %d";   			 goto _strf;
            case 'X': src = "%k:%M:%S";   			 goto _strf;
            case 'D': src = "%m/%d/%y";   			 goto _strf;
            case 'T': src = "%H:%M:%S";
               _strf: p  += strftime (p, (size_t)(dst+max-p), src, tm); 	 break;
            case 'a': src = sweekdays [tm->tm_wday]; 		 goto _str;
            case 'A': src = weekdays  [tm->tm_wday]; 		 goto _str;
            case 'h':
            case 'b': src = smonths   [tm->tm_mon];  		 goto _str;
            case 'B': src = months    [tm->tm_mon];  		 goto _str;
            case 'p': src = ampm [tm->tm_hour > 12 ? 3 : 2]; goto _str;
            case 'P': src = ampm [tm->tm_hour > 12 ? 1 : 0]; goto _str;
            case 'C': no  = tm->tm_year/100 + 19; 		 goto _no;
            case 'd': no  = tm->tm_mday;          		 goto _no;
            case 'e': no  = tm->tm_mday;          		 goto _nos;
            case 'H': no  = tm->tm_hour;          		 goto _no;
            case 'I': no  = tm->tm_hour % 12;     		 goto _no;
            case 'j': no  = tm->tm_yday;          		 goto _no;
            case 'k': no  = tm->tm_hour;          		 goto _nos;
            case 'l': no  = tm->tm_hour % 12;     		 goto _nos;
            case 'm': no  = tm->tm_mon + 1;         		 goto _no;
            case 'M': no  = tm->tm_min;           		 goto _no;
            case 'S': no  = tm->tm_sec;           		 goto _no;
            case 'u': no  = tm->tm_wday ? tm->tm_wday : 7; 	 goto _no;
            case 'w': no  = tm->tm_wday;              		 goto _no;
	    case 'U': no  = (tm->tm_yday - tm->tm_wday + 7) / 7; goto _no;
	    case 'W': no  = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; goto _no;
	    case 'Z':
#ifdef WANT_TZFILE_PARSER
		      tzset(); src = tzname[0];
#else
		      src = "[unknown timezone]";
#endif
		      goto _str;
            case 'Y': i2a ( buf+0, (unsigned int)(tm->tm_year / 100 + 19) );
		      i2a ( buf+2, (unsigned int)(tm->tm_year % 100) );
		      src = buf;
		      goto _str;
            case 'y': no  = tm->tm_year % 100; 			 goto _no;
                 _no: i2a ( buf, no );				 /* append number 'no' */
                      src = buf;
            	      goto _str;
                _nos: i2a ( buf, no );				 /* the same, but '0'->' ' */
            	      if (buf[0] == '0')
		          buf[0] = ' ';
		      src = buf;
		_str: while (*src  &&  p < dst+max)		 /* append string */
      	                  *p++ = *src++;
      	              break;
      	    };
        } else {
            *p++ = *format;
        }
        
        if (p >= dst+max) 
            break;
    }
    
    *p = '\0'; 
    return p - dst;
}
Exemple #21
0
/*
 *  为更好地理解此函数的原理,可参考 printf 的注释部分。
 */
PUBLIC int vsprintf(char *buf, const char *fmt, va_list args)
{
	char*	p;

	va_list	p_next_arg = args;
	int	m;

	char	inner_buf[STR_DEFAULT_LEN];
	char	cs;
	int	align_nr;

	for (p=buf;*fmt;fmt++) {
		if (*fmt != '%') {
			*p++ = *fmt;
			continue;
		}
		else {		/* a format string begins */
			align_nr = 0;
		}

		fmt++;

		if (*fmt == '%') {
			*p++ = *fmt;
			continue;
		}
		else if (*fmt == '0') {
			cs = '0';
			fmt++;
		}
		else {
			cs = ' ';
		}
		while (((unsigned char)(*fmt) >= '0') && ((unsigned char)(*fmt) <= '9')) {
			align_nr *= 10;
			align_nr += *fmt - '0';
			fmt++;
		}

		char * q = inner_buf;
		memset(q, 0, sizeof(inner_buf));

		switch (*fmt) {
		case 'c':
			*q++ = *((char*)p_next_arg);
			p_next_arg += 4;
			break;
		case 'x':
			m = *((int*)p_next_arg);
			i2a(m, 16, &q);
			p_next_arg += 4;
			break;
		case 'd':
			m = *((int*)p_next_arg);
			if (m < 0) {
				m = m * (-1);
				*q++ = '-';
			}
			i2a(m, 10, &q);
			p_next_arg += 4;
			break;
		case 's':
			strcpy(q, (*((char**)p_next_arg)));
			q += strlen(*((char**)p_next_arg));
			p_next_arg += 4;
			break;
		default:
			break;
		}

		int k;
		for (k = 0; k < ((align_nr > strlen(inner_buf)) ? (align_nr - strlen(inner_buf)) : 0); k++) {
			*p++ = cs;
		}
		q = inner_buf;
		while (*q) {
			*p++ = *q++;
		}
	}

	*p = 0;

	return (p - buf);
}
Exemple #22
0
struct tm *Time_toDateTime(const char *s, struct tm *t) {
        assert(t);
        assert(s);
        struct tm tm = {.tm_isdst = -1}; 
        int has_date = false, has_time = false;
        const char *limit = s + strlen(s), *marker, *token, *cursor = s;
	while (true) {
		if (cursor >= limit) {
                        if (has_date || has_time) {
                                *(struct tm*)t = tm;
                                return t;
                        }
                        THROW(SQLException, "Invalid date or time");
                }
                token = cursor;
                
#line 185 "<stdout>"
{
	unsigned char yych;
	unsigned int yyaccept = 0;
	static const unsigned char yybm[] = {
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		128, 128, 128, 128, 128, 128, 128, 128, 
		128, 128,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
		  0,   0,   0,   0,   0,   0,   0,   0, 
	};

	yych = *cursor;
	if (yych <= ',') {
		if (yych == '+') goto yy4;
		goto yy5;
	} else {
		if (yych <= '-') goto yy4;
		if (yych <= '/') goto yy5;
		if (yych >= ':') goto yy5;
	}
	yyaccept = 0;
	yych = *(marker = ++cursor);
	if (yych <= '/') goto yy3;
	if (yych <= '9') goto yy15;
yy3:
#line 243 "src/system/Time.re"
	{
                        continue;
                 }
#line 242 "<stdout>"
yy4:
	yyaccept = 0;
	yych = *(marker = ++cursor);
	if (yych <= '/') goto yy3;
	if (yych <= '9') goto yy6;
	goto yy3;
yy5:
	yych = *++cursor;
	goto yy3;
yy6:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy8;
yy7:
	cursor = marker;
	if (yyaccept <= 1) {
		if (yyaccept <= 0) {
			goto yy3;
		} else {
			goto yy9;
		}
	} else {
		if (yyaccept <= 2) {
			goto yy23;
		} else {
			goto yy31;
		}
	}
yy8:
	yyaccept = 1;
	yych = *(marker = ++cursor);
	if (yych == '\n') goto yy9;
	if (yych <= '/') goto yy10;
	if (yych <= '9') goto yy11;
	goto yy10;
yy9:
#line 230 "src/system/Time.re"
	{ // Timezone: +-HH:MM, +-HH or +-HHMM is offset from UTC in seconds
                        if (has_time) { // Only set timezone if time has been seen
                                tm.TM_GMTOFF = a2i(token + 1, 2) * 3600;
                                if (token[3] >= '0' && token[3] <= '9')
                                        tm.TM_GMTOFF += a2i(token + 3, 2) * 60;
                                else if (token[4] >= '0' && token[4] <= '9')
                                        tm.TM_GMTOFF += a2i(token + 4, 2) * 60;
                                if (token[0] == '-')
                                        tm.TM_GMTOFF *= -1;
                        }
                        continue;
                 }
#line 292 "<stdout>"
yy10:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy14;
	goto yy7;
yy11:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy9;
	if (yych >= ':') goto yy9;
yy13:
	yych = *++cursor;
	goto yy9;
yy14:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy13;
	goto yy7;
yy15:
	yych = *++cursor;
	if (yych <= '/') goto yy17;
	if (yych >= ':') goto yy17;
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy27;
	goto yy7;
yy17:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy20;
	if (yych <= '9') goto yy7;
yy20:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yyaccept = 2;
	yych = *(marker = ++cursor);
	if (yych == '.') goto yy24;
yy23:
#line 214 "src/system/Time.re"
	{ // Time: HH:MM:SS
                        tm.tm_hour = a2i(token, 2);
                        tm.tm_min  = a2i(token + 3, 2);
                        tm.tm_sec  = a2i(token + 6, 2);
                        has_time = true;
                        continue;
                 }
#line 350 "<stdout>"
yy24:
	yych = *++cursor;
	if (yybm[0+yych] & 128) {
		goto yy25;
	}
	goto yy7;
yy25:
	++cursor;
	yych = *cursor;
	if (yybm[0+yych] & 128) {
		goto yy25;
	}
	goto yy23;
yy27:
	yych = *++cursor;
	if (yych <= '/') goto yy28;
	if (yych <= '9') goto yy29;
yy28:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy38;
	goto yy7;
yy29:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yyaccept = 3;
	yych = *(marker = ++cursor);
	if (yych == '.') goto yy33;
	if (yych <= '/') goto yy31;
	if (yych <= '9') goto yy32;
yy31:
#line 222 "src/system/Time.re"
	{ // Compressed Time: HHMMSS
                        tm.tm_hour = a2i(token, 2);
                        tm.tm_min  = a2i(token + 2, 2);
                        tm.tm_sec  = a2i(token + 4, 2);
                        has_time = true;
                        continue;
                 }
#line 391 "<stdout>"
yy32:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych <= '9') goto yy36;
	goto yy7;
yy33:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
yy34:
	++cursor;
	yych = *cursor;
	if (yych <= '/') goto yy31;
	if (yych <= '9') goto yy34;
	goto yy31;
yy36:
	++cursor;
#line 206 "src/system/Time.re"
	{ // Compressed Date: YYYYMMDD
                        tm.tm_year  = a2i(token, 4);
                        tm.tm_mon   = a2i(token + 4, 2) - 1;
                        tm.tm_mday  = a2i(token + 6, 2);
                        has_date = true;
                        continue;
                 }
#line 417 "<stdout>"
yy38:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy40;
	if (yych <= '9') goto yy7;
yy40:
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	yych = *++cursor;
	if (yych <= '/') goto yy7;
	if (yych >= ':') goto yy7;
	++cursor;
#line 198 "src/system/Time.re"
	{ // Date: YYYY-MM-DD
                        tm.tm_year  = a2i(token, 4);
                        tm.tm_mon   = a2i(token + 5, 2) - 1;
                        tm.tm_mday  = a2i(token + 8, 2);
                        has_date = true;
                        continue;
                 }
#line 441 "<stdout>"
}
#line 246 "src/system/Time.re"

        }
	return NULL;
}


char *Time_toString(time_t time, char result[20]) {
        assert(result);
        char x[2];
        struct tm ts = {.tm_isdst = -1};
        gmtime_r(&time, &ts);
        memcpy(result, "YYYY-MM-DD HH:MM:SS\0", 20);
        /*              0    5  8  11 14 17 */
        i2a((ts.tm_year+1900)/100);
        result[0] = x[0];
        result[1] = x[1];
        i2a((ts.tm_year+1900)%100);
        result[2] = x[0];
        result[3] = x[1];
        i2a(ts.tm_mon + 1); // Months in 01-12
        result[5] = x[0];
        result[6] = x[1];
        i2a(ts.tm_mday);
        result[8] = x[0];
        result[9] = x[1];
        i2a(ts.tm_hour);
        result[11] = x[0];
        result[12] = x[1];
        i2a(ts.tm_min);
        result[14] = x[0];
        result[15] = x[1];
        i2a(ts.tm_sec);
        result[17] = x[0];
        result[18] = x[1];
	return result;
}


time_t Time_now(void) {
	struct timeval t;
	if (gettimeofday(&t, NULL) != 0)
                THROW(AssertException, "%s", System_getLastError());
	return t.tv_sec;
}


long long Time_milli(void) {
	struct timeval t;
	if (gettimeofday(&t, NULL) != 0)
                THROW(AssertException, "%s", System_getLastError());
	return (long long)t.tv_sec * 1000  +  (long long)t.tv_usec / 1000;
}


int Time_usleep(long u) {
        struct timeval t;
        t.tv_sec = u / USEC_PER_SEC;
        t.tv_usec = (suseconds_t)(u % USEC_PER_SEC);
        select(0, 0, 0, 0, &t);
        return true;
}
Exemple #23
0
/**
 * Gets the buffer as a string
 */
uint8_t *USART2_get_buffer_as_string(){
	return i2a(USART2_get_buffer_as_number());
}
Exemple #24
0
void ps_color(FILE *ps,real r,real g,real b)
{
  ps_selcolor(ps,i2a(search_col(ps,r,g,b)));
}