Exemplo n.º 1
0
String::String(unsigned char value, unsigned char base)
{
	init();
	char buf[1 + 8 * sizeof(unsigned char)];
	utoa(value, buf, base);
	*this = buf;
}
Exemplo n.º 2
0
Arquivo: extra.cpp Projeto: b0nk/mbot
// !dccchat nick host port
static void
extra_cmd_dccchat (NetServer *s)
{
#ifdef WINDOZE
  SEND_TEXT (DEST, "Command not available on Windows.");
#else		// !WINDOZE
  strsplit (CMD[3], BUF, 4);
  if (BUF[3][0] == 0)
    {
      SEND_TEXT (DEST, "%s", HELP_DCCCHAT);
      return;
    }
  char addrbuf[12+1];
  struct in_addr ipe;
  struct hostent *addr = gethostbyname (BUF[2]);
  if (addr == NULL)
    {
      ipe.s_addr = inet_addr (BUF[2]);
      if (ipe.s_addr == (u_int)-1)
        {
          SEND_TEXT (DEST, "Cannot resolve host.");
          return;
        }
    }
  else
    memcpy (&ipe.s_addr, addr->h_addr_list[0], addr->h_length);
  utoa (ntohl (ipe.s_addr), addrbuf, 12);
  SEND_TEXT (BUF[1], "DCC CHAT chat %s %s", addrbuf, BUF[3]);
#endif		// !WINDOZE
}
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
{
	struct tm tm_time;
	struct tm *ptm = &tm_time; //localtime(&file_header->mtime);

#if ENABLE_FEATURE_TAR_UNAME_GNAME
	char uid[sizeof(int)*3 + 2];
	/*char gid[sizeof(int)*3 + 2];*/
	char *user;
	char *group;

	localtime_r(&file_header->mtime, ptm);

	user = file_header->tar__uname;
	if (user == NULL) {
		sprintf(uid, "%u", (unsigned)file_header->uid);
		user = uid;
	}
	group = file_header->tar__gname;
	if (group == NULL) {
		/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
		group = utoa(file_header->gid);
	}
	printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
		bb_mode_string(file_header->mode),
		user,
		group,
		file_header->size,
		1900 + ptm->tm_year,
		1 + ptm->tm_mon,
		ptm->tm_mday,
		ptm->tm_hour,
		ptm->tm_min,
		ptm->tm_sec,
		file_header->name);

#else /* !FEATURE_TAR_UNAME_GNAME */

	localtime_r(&file_header->mtime, ptm);

	printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
		bb_mode_string(file_header->mode),
		(unsigned)file_header->uid,
		(unsigned)file_header->gid,
		file_header->size,
		1900 + ptm->tm_year,
		1 + ptm->tm_mon,
		ptm->tm_mday,
		ptm->tm_hour,
		ptm->tm_min,
		ptm->tm_sec,
		file_header->name);

#endif /* FEATURE_TAR_UNAME_GNAME */

	if (file_header->link_target) {
		printf(" -> %s", file_header->link_target);
	}
	bb_putchar('\n');
}
Exemplo n.º 4
0
static int addgroup_wrapper(struct passwd *p, const char *group_name)
{
	char *argv[6];

	argv[0] = (char*)"addgroup";
	if (group_name) {
		/* Add user to existing group */
		argv[1] = (char*)"--";
		argv[2] = p->pw_name;
		argv[3] = (char*)group_name;
		argv[4] = NULL;
	} else {
		/* Add user to his own group with the first free gid
		 * found in passwd_study.
		 */
#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS || !ENABLE_ADDGROUP
		/* We try to use --gid, not -g, because "standard" addgroup
		 * has no short option -g, it has only long --gid.
		 */
		argv[1] = (char*)"--gid";
#else
		/* Breaks if system in fact does NOT use busybox addgroup */
		argv[1] = (char*)"-g";
#endif
		argv[2] = utoa(p->pw_gid);
		argv[3] = (char*)"--";
		argv[4] = p->pw_name;
		argv[5] = NULL;
	}

	return spawn_and_wait(argv);
}
Exemplo n.º 5
0
char* MyMessage::getString(char *buffer) const {
	uint8_t payloadType = miGetPayloadType();
	if (buffer != NULL) {
		if (payloadType == P_STRING) {
			strncpy(buffer, data, miGetLength());
			buffer[miGetLength()] = 0;
		} else if (payloadType == P_BYTE) {
			itoa(bValue, buffer, 10);
		} else if (payloadType == P_INT16) {
			itoa(iValue, buffer, 10);
		} else if (payloadType == P_UINT16) {
			utoa(uiValue, buffer, 10);
		} else if (payloadType == P_LONG32) {
			ltoa(lValue, buffer, 10);
		} else if (payloadType == P_ULONG32) {
			ultoa(ulValue, buffer, 10);
		} else if (payloadType == P_FLOAT32) {
			dtostrf(fValue,2,min(fPrecision, 8),buffer);
		} else if (payloadType == P_CUSTOM) {
			return getCustomString(buffer);
		}
		return buffer;
	} else {
		return NULL;
	}
}
Exemplo n.º 6
0
ICACHE_FLASH_ATTR String::String(unsigned int value, unsigned char base)
{
	init();
	char buf[1 + 8 * sizeof(unsigned int)];
	utoa(value, buf, base);
	*this = buf;
}
Exemplo n.º 7
0
void UART_WriteHexByte(uint8_t theByte, uint8_t prefix)
{
	char str[3];
	utoa(theByte, str, 16);
	if (prefix) UART_WriteString("0x");
	UART_WriteString(str);
}
String::String(unsigned int value, unsigned char base)
{
	init();
	char buf[17];
	utoa(value, buf, base);
	*this = buf;
}
Exemplo n.º 9
0
 char* Extsram::verify_sram_with_rand(char* str, uint8_t num_of_runs){
	//leds_control l;
	char status_ok[] PROGMEM = "sram verification succesfull";
	char status_nok[] PROGMEM = "rand sram verification failed at address:";
	char tmp_string[6];
	address_result result;
	uint16_t a;
	result.result = ok;
	result.addr = 0;
	uint8_t rand_d;
	for(uint16_t r=0; r <= num_of_runs; r++){
		//l.L1 = l.sw;
		for(a=0; a<EXTSRAM_SIZ; a++){
			rand_d = rand();
			write_single_byte(a, rand_d);
			if(read_single_byte(a) != rand_d){
				result.addr = a;
				result.result = nok;
				break;
			}
		}
	}
	if(not result.result){
		strcpy(str, status_nok);
		utoa(result.addr, tmp_string, 10);
		strcat(str, tmp_string);
	}
	else{
		strcpy(str, status_ok);
	}
	return str;
}
Exemplo n.º 10
0
int
printf_X(unsigned int i, FILE *f)
{
    char buf[32];
    utoa(i, buf, 16);
    return printf_s(buf, f);
}
Exemplo n.º 11
0
void drawRectAbs(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint32_t color)
{
  char cmd[32] = "draw ";

  if (x1 > x2) swap(&x1, &x2);
  if (y1 > y2) swap(&y1, &y2);
  utoa(x1, &cmd[strlen(cmd)], 10);
  strcat(cmd, ",");
  utoa(y1, &cmd[strlen(cmd)], 10);
  strcat(cmd, ",");
  utoa(x2-1, &cmd[strlen(cmd)], 10);
  strcat(cmd, ",");
  utoa(y2-1, &cmd[strlen(cmd)], 10);
  strcat(cmd, ",");
  utoa(color, &cmd[strlen(cmd)], 10);
  sendCommand(cmd);
}
Exemplo n.º 12
0
String::String(unsigned char value, unsigned char base)
{
	init();
	char buf[1 + 8 * sizeof(unsigned char)];
	//had to make this change where I recasted input args 1 and 3
	utoa((unsigned long)value, buf, (int)base); 
	*this = buf;
}
Exemplo n.º 13
0
std::auto_ptr<OsdElement> newStateSavedOsdElement(unsigned stateNo) {
	char txt[sizeof stateSavedTxt];
	
	std::memcpy(txt, stateSavedTxt, sizeof stateSavedTxt);
	utoa(stateNo, txt + 6);
	
	return std::auto_ptr<OsdElement>(new ShadedTextOsdElment(stateSavedTxtWidth, txt));
}
Exemplo n.º 14
0
void osDbgPrintf(const char * format, ...) {

	int i,p;

	va_list v1;
	va_start(v1, format);

	int tmpint;
	char *tmpcharp;
	char dest[500];


	for(i=0,p=0; format[i]; ++i){
		if(format[i]=='%'){
			switch(format[i+1]){
				case '%':
					dest[p++]='%'; break;
					break;
				case 'x':
				case 'X':
					tmpint = va_arg(v1, int);
					tmpcharp = utoa(format[i+1]=='x'?"0123456789abcdef":"0123456789ABCDEF",(unsigned)tmpint, 16);
					for(;*tmpcharp;++tmpcharp, ++p)
						dest[p]=*tmpcharp;
					break;
				case 'u':
				case 'd':
					tmpint = va_arg(v1, int);
					if (format[i+1]=='u')
						tmpcharp = utoa("0123456789",(unsigned)tmpint, 10);
					else
						tmpcharp = itoa("0123456789",(unsigned)tmpint, 10);
					for(;*tmpcharp;++tmpcharp, ++p)
						dest[p]=*tmpcharp;
					break;
				case 's':
					tmpcharp = va_arg(v1, char *);
					for(;*tmpcharp;++tmpcharp, ++p)
						dest[p]=*tmpcharp;
					break;
			}
			/* Skip the next character */
			++i;
		}else
			dest[p++]=format[i];
	}
Exemplo n.º 15
0
void print_bits(uint16_t* bits) {
  utoa(((*bits) & 0x3f) << 4, (char *)msg_buf, 2);
  uart_sendstr((char *)msg_buf);
  uart_sendchar(' ');
  utoa((*bits) >> 6, (char *)msg_buf, 2);
  uart_sendstr((char *)msg_buf);
  uart_newline();
}
Exemplo n.º 16
0
int
printf_x(unsigned int i, FILE *f)
{
    char buf[32];
    utoa(i, buf, 16);
    strtolower(buf);
    return printf_s(buf, f);
}
Exemplo n.º 17
0
 /// @brief Converts a pointer to a preallocated string.
 INLINE char *ptoa(const void *val, char* memory) {
   char* buf = utoa(reinterpret_cast<uint64_t>(val), memory + 32, 16);
   char* result = memory;  // 32
   strcpy(result + 2, buf);  // NOLINT(runtime/printf
   result[0] = '0';
   result[1] = 'x';
   return result;
 }
Exemplo n.º 18
0
/*
 * use putchar_func to print a string
 *   @putchar_func is a function pointer to print a character
 *   @format is the control format string (e.g. "%d + %d = %d")
 *   @data is the address of the first variable argument
 * please implement it.
 */
int
vfprintf(void (*putchar_func)(char), const char *format, void **data) {
	int  cnt=0;					//number of the printed char
	char ch;
	char *pbuf;
	while(1){
		while((ch=*format++)!='%'){
			if(ch=='\0'){
			      return cnt;
			}
			putchar_func(ch);
			cnt++;
		}
		switch ((ch=*format++)){
			case 'c':
				putchar_func(*(char *)data++);      	//Notice data=data+1, data proceeds 4 bytes,
				cnt++;			      		//beacause of 4 bytes of alignment.
				break;
			case 'd':
				pbuf=itoa(*(int *)data++,10);
				while((ch=*pbuf++)!=0){
					putchar_func(ch);
					cnt++;
				}
				break;
			case 'x':
				pbuf=utoa(*(unsigned int *)data++,16);
				while((ch=*pbuf++)!=0){
					putchar_func(ch);
					cnt++;
				}
				break;
			case 's':
				pbuf=*(char **)data++;
				while((ch=*pbuf++)!=0){
					putchar_func(ch);
					cnt++;
				}
				break;
			default :

			// If this foramt specifier is invalid, print it out
			// with '%' as const string. Specifically, if it's '\0' which 
			// ends the whole format string, the pointer format needs to
			// go back, thus, we can return to the while loop safely, or unexpected
			// behavior happens
			

				putchar_func('%');			
				cnt++;
				if(ch!='\0'){
			      	putchar_func(ch);	
				cnt++;
				}
				else  format--;
		}
	}
}
Exemplo n.º 19
0
bool tpRFID::CheckCard()
{
  //debugPrinter->println("Tock");
	if (rfid->isCard()) {
		debugPrinter->println("Card Present");
        if (!hold){
          if (rfid->readCardSerial()) {           
		            debugPrinter->print(rfid->serNum[0],HEX);
                debugPrinter->print("-");
		            debugPrinter->print(rfid->serNum[1],HEX);
                debugPrinter->print("-");
		            debugPrinter->print(rfid->serNum[2],HEX);
                debugPrinter->print("-");
		            debugPrinter->print(rfid->serNum[3],HEX);
                debugPrinter->print("-");
		            debugPrinter->print(rfid->serNum[4],HEX);
                debugPrinter->println(" ");

                utoa(rfid->serNum[0], &cardID[0], HEX);
                utoa(rfid->serNum[1], &cardID[2], HEX);
                utoa(rfid->serNum[2], &cardID[4], HEX);
                utoa(rfid->serNum[3], &cardID[6], HEX);
                utoa(rfid->serNum[4], &cardID[8], HEX);

                /*String code = String(rfid->serNum[0],HEX);
                code = String(code + String(rfid->serNum[1],HEX));
                code = String(code + String(rfid->serNum[2],HEX));
                code = String(code + String(rfid->serNum[3],HEX));
                code = String(code + String(rfid->serNum[4],HEX));

                cardID = new String(code);*/

                hold = true;

                return true;
            }

          }
    } else {
      hold = false;
    }
    
    rfid->halt();
    return false;
}
Exemplo n.º 20
0
void    show_include_stack( void )
{
    inputcb *   ip;
    char        linestr[MAX_L_AS_STR];
    char        linemac[MAX_L_AS_STR];


    if( input_cbs != NULL ) {
        if( input_cbs->fmflags & II_macro ) {
            utoa( input_cbs->s.m->lineno, linestr, 10 );
            utoa( input_cbs->s.m->mac->lineno, linemac, 10 );
            g_info( err_inf_mac_def, linestr, input_cbs->s.m->mac->name,
                    linemac, input_cbs->s.m->mac->mac_file_name);
//      } else {
//          utoa( input_cbs->s.f->lineno, linestr, 10 );
//          g_info( inf_file_line, linestr, input_cbs->s.f->filename );
        }
        ip = input_cbs->prev;
    } else {
        ip = NULL;
    }
    out_msg( "\n" );
    while( ip != NULL ) {
        switch( ip->fmflags & II_input ) {
        case    II_file:
            utoa( ip->s.f->lineno, linestr, 10 );
            g_info( err_inf_line_file, linestr, ip->s.f->filename );
            break;
        case    II_tag :
            g_info( err_inf_tag, ip->s.m->tag->name );
            // fallthrough
        case    II_macro :
            utoa( ip->s.m->lineno, linestr, 10 );
            utoa( ip->s.m->mac->lineno, linemac, 10 );
            g_info( err_inf_mac_def, linestr, ip->s.m->mac->name,
                    linemac, ip->s.m->mac->mac_file_name);
            break;
        default:
            g_info( err_inc_unknown );
            break;
        }
        ip = ip->prev;
    }
    return;
}
Exemplo n.º 21
0
static void printMangledId( IDMANGLE *id )
{
    auto char buff[32];

    prt_cpp_char( '_' );
    utoa( id->index, buff, 10 );
    PrtString( buff );
    prt_cpp_char( '_' );
}
Exemplo n.º 22
0
/***********************************************************
 * 
 * getActiveMessage
 *
 * get the current sensors LCD message to print during trap Active mode.
 * 
 ***********************************************************/
void BulbRamp::getActiveMessage(char buffer[])
{
	//buffer[0] = 0;
	
	//itoa (countDownInt(),buffer,10);
	utoa((unsigned int) shutterPulseTime_ ,buffer,10);
	
	
}
Exemplo n.º 23
0
void main()
  {
    int base;
    char buffer[18];

    for( base = 2; base <= 16; base = base + 2 )
      printf( "%2d %s\n", base,
              utoa( (unsigned) 12765, buffer, base ) );
  }
Exemplo n.º 24
0
int sprintf(char *str, const char *format, ...) {
	char *dst = str;
	char const *src = format;
	bool isfmt = false;
	void *args = (&format + 1);
	int argn = 0;
	do {
		if(!isfmt && *src != '%') {
			*dst++ = *src;
		} else if(isfmt) {
			switch(*src) {
				case 'c':
					*dst++ = ((char*)args)[argn++];
					break;
				case 's':
					strcpy(dst, ((char**)args)[argn]);
					dst += strlen(((char**)args)[argn]);
					break;
				case 'd':
					dst += strlen(itoa(((int*)args)[argn++], dst, 10));
					break;
				case 'u':
					dst += strlen(utoa(((uint*)args)[argn++], dst, 10));
					break;
				case 'o':
					dst += strlen(utoa(((uint*)args)[argn++], dst, 8));
					break;
				case 'x':
				case 'p':
					dst += strlen(utoa(((uint*)args)[argn++], dst, 16));
					break;
				case '%':
					*dst++ = '%';
					break;
				default:
					return -1;
			}
			isfmt = false;
		} else if(*src == '%') {
			isfmt = true;
		}
	} while(*src++);
	return (int)strlen(str);
}
Exemplo n.º 25
0
void serialWriteUint16_0(uint16_t val){
	//get the number of digits
	uint8_t numberOfDigits = digitCount(val);
	//create buffer for result
	char resultString[numberOfDigits];
	//convert to string
	utoa(val, resultString, 10);
	//write to serial
	serialWriteString_0(resultString);
}
Exemplo n.º 26
0
inline char* append_itoa(char *to, typename signed_for_int<Int>::signed_t n) {
  char buf[signed_for_int<Int>::toa_bufsize];
  char *end=buf+signed_for_int<Int>::toa_bufsize;
  char *p=utoa(end, n);
  int ns=end-p;
  std::memcpy(to, p, ns);
  to+=ns;
  *to=0;
  return to;
}
Exemplo n.º 27
0
void    file_mac_info( void )
{
    char        linestr[MAX_L_AS_STR];
    char        linemac[MAX_L_AS_STR];

    if( input_cbs != NULL ) {
        if( input_cbs->fmflags & II_macro ) {
            utoa( input_cbs->s.m->lineno, linestr, 10 );
            utoa( input_cbs->s.m->mac->lineno, linemac, 10 );
            g_info( err_inf_mac_def, linestr, input_cbs->s.m->mac->name,
                    linemac, input_cbs->s.m->mac->mac_file_name);
        } else {
            utoa( input_cbs->s.f->lineno, linestr, 10 );
            g_info( inf_file_line, linestr, input_cbs->s.f->filename );
        }
    }
    show_include_stack();
    return;
}
Exemplo n.º 28
0
static void run_login_script(struct passwd *pw, char *full_tty)
{
    char *t_argv[2];

    t_argv[0] = getenv("LOGIN_PRE_SUID_SCRIPT");
    if (t_argv[0]) {
        t_argv[1] = NULL;
        xsetenv("LOGIN_TTY", full_tty);
        xsetenv("LOGIN_USER", pw->pw_name);
        xsetenv("LOGIN_UID", utoa(pw->pw_uid));
        xsetenv("LOGIN_GID", utoa(pw->pw_gid));
        xsetenv("LOGIN_SHELL", pw->pw_shell);
        spawn_and_wait(t_argv);	/* NOMMU-friendly */
        unsetenv("LOGIN_TTY");
        unsetenv("LOGIN_USER");
        unsetenv("LOGIN_UID");
        unsetenv("LOGIN_GID");
        unsetenv("LOGIN_SHELL");
    }
}
Exemplo n.º 29
0
char *utoa(unsigned value, char *digits, int base)
{
    const char *s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    if (base == 0)
        base = 10;
    if (digits == nullptr || base < 2 || base > 36)
        return nullptr;
    if (value < (unsigned) base) {
        digits[0] = s[value];
        digits[1] = '\0';
    } else {
        char *p;
        for (p = utoa(value / ((unsigned)base), digits, base);
             *p;
             p++) {}
        utoa( value % ((unsigned)base), p, base);
    }
    return digits;
}
Exemplo n.º 30
0
char *display_voltage_info() {
  char accu_str[5];
  char x_str[5];
  char y_str[5];
  char z_str[5];
  utoa(g_adc_voltage[0],accu_str,10);
  utoa(g_adc_voltage[1],x_str,10);
  utoa(g_adc_voltage[2],y_str,10);
  utoa(g_adc_voltage[3],z_str,10);
  strcpy(uart_buf, "battery: ");
  strcat(uart_buf, accu_str);
  strcat(uart_buf, " x: ");
  strcat(uart_buf, x_str);
  strcat(uart_buf, " y: ");
  strcat(uart_buf, y_str);
  strcat(uart_buf, " z: ");
  strcat(uart_buf, z_str);
  strcat(uart_buf, "\x1B[1B\x1B[2K\x0D");
  return uart_buf;
}