/**
 * print_binary - converts decimal to binary
 * @n: number to be converted
 * Return:
 */
void print_binary(unsigned long int n)
{
	int i;
	unsigned long int shifted;
	unsigned int flag;
	int byte_size = sizeof(unsigned long int) * 8 - 1;

	flag = 0;

	if (n == 0)
	{
		_putchar ('0');
	}

	for (i = byte_size; i >= 0; i--)
	{
		shifted = n >> i;
		if (shifted & 1)
		{
			_putchar('1');
			flag = 1;
		}
		else if (!(shifted & 1) && (flag == 1))
		{
			_putchar ('0');
		}
	}
}
예제 #2
0
파일: avr_main.c 프로젝트: Fadis/uARM
static int uart_putchar(char c, FILE *stream){

	if(c == '\n') _putchar('\r');
	_putchar(c);
	
	return 0;
}
예제 #3
0
static void
putchar(char c)
{
	_putchar(c);
	if (c == '\n') {
		_putchar('\r');
	}
}
예제 #4
0
파일: shell.c 프로젝트: JMR-b/RIOT
static inline void print_prompt(void)
{
    _putchar('>');
    _putchar(' ');

#ifdef MODULE_NEWLIB
    fflush(stdout);
#endif
}
예제 #5
0
/**
 * @fn void _puts(const char *tempStr)
 * @brief Prints a NULL-erminated string on UART 1
 *
 * @param s The string to output
 *
 */
int
_puts(const char *s)
{
  while( *s != '\0' )
    _putchar(*s++);
  
  _putchar('\n');

  return 0;
}
예제 #6
0
/**
 * @fn int _printf(const char *format, ...)
 * @brief Prints a formatted string on UART1
 *
 * @param format The string
 */
int _printf(const char *format, ...)
{
   int format_cntr=0;
   char temp_str[20];
   int return_flag=0,cntr_val;
   long double f1,f2;
   char *str_temp;
   int *cntr=&cntr_val;

   va_list ap;
   va_start(ap, format);
   *cntr=0;
   while(*format) {
     temp_str[format_cntr]='\0';
     if(*format=='%')
     {
       *format++;
       while(*format==' ')
       {
	 format++;
	 _putchar(' ');
       }
       while(condition)

       {
	 temp_str[format_cntr++]=*format++;
       }
       temp_str[format_cntr]='\0';
       if(*format=='%')
       {
	 _putchar('%');
	 (*cntr)++;
	 format_cntr=0;
	 format++;
	 continue;
       }

       /************** print unsigned ****************/
       else if(*format=='u')
       {
	 return_flag=format_val(temp_str,0,cntr,0);
	 if(return_flag!=-1)

	   print_hex_oct(va_arg(ap,unsigned int),10,0,return_flag,0,cntr);

	 else
	 {
	   _putchar(*format);
	   (*cntr)++;
	 }
	 format++;
	 format_cntr=0;
	 continue;
       }
/**
 * print_last_digit - checks for alpha
 * @i: the value to be checked
 * Return: last digit of i
 */
int print_last_digit(int i)
{
	if (i < 0)
	{
		_putchar(((i *= -1) % 10) + '0');

	}
	else
	{
		_putchar((i % 10) + '0');
	}
	return (i % 10);
}
예제 #8
0
static int format_val(char *temp,long float_flag,int *cntr_val,int flag)
{
left_val=0;
right_val=0;
	if(*temp=='\0'&&flag==1)
	{
		right_val=3;
		return 0;
	}
	while(*temp!='.'&&*temp!='\0')
	{
		if(*temp<'0'||*temp>'9')
		{
			while(*temp)
			{
				_putchar(*temp++);
				(*cntr_val)++;
			}
			return -1;
		}
		else
		left_val=left_val*10+*temp-'0';
    	 temp++;
	}
    if(*temp)
		temp++;
		else
		return left_val;
	while(*temp)
	{
	if(*temp<'0'||*temp>'9')
	{
	while(*temp)
		{
			_putchar(*temp++);
			(*cntr_val)++;
		}
	return -1;
	}
	else
	right_val=right_val*10+*temp-'0';
     temp++;
	}

return 0;
}
/**
 * _print_rev_recursion - prints a string in reverse
 * @s: the string
 * Return: the string
 */
void _print_rev_recursion(char *s)
{
	if (*s)
	{
	_print_rev_recursion(s + 1);
	_putchar(*s);
	}
}
예제 #10
0
static void float_print(long double f1,long double f2,int multi,int *cntr_val)
{
	int i=1,temp,cntr=0,i1,neg_flag=0;
	char s1[10];

	 if(f1<0)
	 {
		 f1=f1*-1;
		 neg_flag=1;
		 f2=f1;
	 }
	 temp=(int)f1;

	 f1=f1-temp;
     f1=f1*multi;

     temp=f1;

     if(temp==0)
    	s1[cntr++]='0';
     while(temp>0)
     {
         i1=temp%10;
         temp=temp/10;
         s1[cntr]=i1+0x30;
         cntr++;
     }

     while(right_val<9&&(right_val -cntr)>0)
	   s1[cntr++]='0';
	   s1[cntr]='.';
	   cntr++;

	   temp=(int)f2;
	 if(temp==0)
		s1[cntr++]='0';
	 while(temp>0)
	 {
	      i1=temp%10;
	      temp=temp/10;
	      s1[cntr]=i1+0x30;
	      cntr++;
	 }

	 while(left_val-- -cntr>0)
		{
			_putchar(' ');
			(*cntr_val)++;
		}
			if(neg_flag==1)
	    s1[cntr++]='-';
	    s1[cntr]='\0';
	    cntr--;
	 	strrev(s1);
    	_puts(s1);
		(*cntr_val)+=strlen(s1);
   		neg_flag=0;
}
예제 #11
0
파일: printf.c 프로젝트: ndreys/stfuboot
static void printchar(char **str, int c)
{
	extern int putchar(int c);

	if (str) {
		**str = c;
		++(*str);
	}
	else (void)_putchar(c);
}
예제 #12
0
파일: getpass.c 프로젝트: salextpuru/FUZIX
static char *_gets(char *buf, int len) {
    int ch, i = 0;

    while (i < len) {
        if ((ch = _getchar()) == EOF && i == 0)
            return NULL;
#if 0
        if (ch >= ' ')
            _putchar(ch);
        else {
            _putchar('^');
            _putchar(ch + '@');
        }
#endif
        if ((ch == 'C' & 037) || (ch == 'Z' & 037))
            return NULL;
        if (ch == '\n' || ch == '\r')
            break;
        buf[i++] = ch;
    }
    buf[i] = 0;
    return buf;
}
예제 #13
0
static void print_hex_oct( long int temp_var,int div,int corr_factor,int ret_val,int sign,int *cntr_val)
{
  unsigned long int i=1,i1,temp=temp_var;
  int cntr=0,neg_flag=0;
  char s1[40];

  if(sign==1&&temp_var<0)
  {
    temp=-temp_var;
    neg_flag=1;
  }
  if(temp==0)
    s1[cntr++]='0';
  while(temp>0)
  {
    i1=temp%div;
    temp=temp/div;
    if(i1<=9)
      s1[cntr]=i1+'0';
    else
      s1[cntr]=i1+corr_factor-9;
    cntr++;
  }

  while((left_val-(right_val>cntr?right_val:cntr+neg_flag))>0)
  {
    _putchar(' ');
    left_val--;
		(*cntr_val)++;
	}

	while(right_val-cntr>0)
	{
		s1[cntr++]='0';
	}

	if(neg_flag==1)
	s1[cntr++]='-';

	s1[cntr]='\0';
	strrev(s1);
	_puts(s1);
	(*cntr_val)+=strlen(s1);
}
예제 #14
0
파일: shell.c 프로젝트: JMR-b/RIOT
static int readline(char *buf, size_t size)
{
    char *line_buf_ptr = buf;

    while (1) {
        if ((line_buf_ptr - buf) >= ((int) size) - 1) {
            return -1;
        }

        int c = getchar();
        if (c < 0) {
            return 1;
        }

        /* We allow Unix linebreaks (\n), DOS linebreaks (\r\n), and Mac linebreaks (\r). */
        /* QEMU transmits only a single '\r' == 13 on hitting enter ("-serial stdio"). */
        /* DOS newlines are handled like hitting enter twice, but empty lines are ignored. */
        if (c == '\r' || c == '\n') {
            *line_buf_ptr = '\0';
            _putchar('\r');
            _putchar('\n');

            /* return 1 if line is empty, 0 otherwise */
            return line_buf_ptr == buf;
        }
        /* QEMU uses 0x7f (DEL) as backspace, while 0x08 (BS) is for most terminals */
        else if (c == 0x08 || c == 0x7f) {
            if (line_buf_ptr == buf) {
                /* The line is empty. */
                continue;
            }

            *--line_buf_ptr = '\0';
            /* white-tape the character */
            _putchar('\b');
            _putchar(' ');
            _putchar('\b');
        }
        else {
            *line_buf_ptr++ = c;
            _putchar(c);
        }
    }
}
예제 #15
0
파일: fputc.c 프로젝트: dannf/ti-cgt-c6x
_CODE_ACCESS int putchar(int _x) { return(_putchar(_x)); }
예제 #16
0
void zigbee_putchar(char ch)
{
    _putchar(&charZigbee, ch);
}
예제 #17
0
int console_putchar(char ch)
{
    _putchar(&charConsole, ch);
    return ch;
}
예제 #18
0
void loop() {

    static int8_t value=0;
    uint8_t n;

    // blink LED
    for(n=0; n<3; n++)
    {
        ledOn();
        delay(200);
        ledOff();
        delay(200);
    }
    uint8_t row,col;

    // display row an colun test
    initDisplay();
    for(row=0; row<5; row++)
    {
        for(col=0; col<7; col++)
        {

            setRow(row);
            setCol(col);
            delay(100);
        }
    }

    // show hello
    _putchar('H');
    showMatrix(200);
    _putchar('E');
    showMatrix(200);
    _putchar('L');
    showMatrix(400);
    _putchar('O');
    showMatrix(200);


    //**************** key display example ***************************
    do
    {
        n=_getchar();
        value=getKey();
        _putchar(n);
        showLeds(value);
    }
    while(n!='i');

    //**************** key sound display example ***************************
    tone(CH2_SPEAKERPIN, frequencyTable[0],50);
    do
    {
        n=_getchar();
        value=getKey();
        tone(CH2_SPEAKERPIN, frequencyTable[value],50);
        delay(50);
        _putchar(n);
        showLeds(value);
    }
    while(n!='i');

    // key code test
    do
    {
        n=scanKey();
        //initDisplay();
        //setCol(0);
        //setRowPattern(n);
        if(n<0x10)	hex1(n);
        else _putchar('n');
        showLeds(n);
        showMatrix(100);
        //delay(1000);
    } while(n!=HASHKEY);

}
예제 #19
0
파일: refresh.c 프로젝트: jamjr/Helios-NG
int wrefresh(reg WINDOW	* win )
{
	reg short	wy;
	reg int		retval;

	/*
	 * make sure were in visual state
	 */
	if (_endwin) {
		_puts(VS);
		_puts(TI);
		_endwin = FALSE;
	}

	/*
	 * initialize loop parameters
	 */

	ly = curscr->_cury;
	lx = curscr->_curx;
	wy = 0;
	_win = win;
	curwin = (win == curscr);

	if (win->_clear || curscr->_clear || curwin) {
		if ((win->_flags & _FULLWIN) || curscr->_clear) {
			_puts(CL);
			ly = 0;
			lx = 0;
			if (!curwin) {
				curscr->_clear = FALSE;
				curscr->_cury = 0;
				curscr->_curx = 0;
				werase(curscr);
			}
			touchwin(win);
		}
		win->_clear = FALSE;
	}
	if (!CA) {
		if (win->_curx != 0)
			_putchar('\n');
		if (!curwin)
			werase(curscr);
	}
# ifdef DEBUG
	fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin);
	fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n");
# endif
	for (wy = 0; wy < win->_maxy; wy++) {
# ifdef DEBUG
		fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy],
			win->_lastch[wy]);
# endif
		if (win->_firstch[wy] != _NOCHANGE)
		  {
			if (makech(win, wy) == ERR)
				return ERR;
			else {
				if (win->_firstch[wy] >= win->_ch_off)
					win->_firstch[wy] = win->_maxx +
							    win->_ch_off;
				if (win->_lastch[wy] < win->_maxx +
						       win->_ch_off)
					win->_lastch[wy] = win->_ch_off;
				if (win->_lastch[wy] < win->_firstch[wy])
					win->_firstch[wy] = _NOCHANGE;
			}
		      }
		
# ifdef DEBUG
		fprintf(outf, "\t%d\t%d\n", win->_firstch[wy],
			win->_lastch[wy]);
# endif
	}

	if (win == curscr)
		domvcur(ly, lx, win->_cury, win->_curx);
	else {
		if (win->_leave) {
			curscr->_cury = ly;
			curscr->_curx = lx;
			ly -= win->_begy;
			lx -= win->_begx;
			if (ly >= 0 && ly < win->_maxy && lx >= 0 &&
			    lx < win->_maxx) {
				win->_cury = ly;
				win->_curx = lx;
			}
			else
				win->_cury = win->_curx = 0;
		}
		else {
			domvcur(ly, lx, win->_cury + win->_begy,
				win->_curx + win->_begx);
			curscr->_cury = win->_cury + win->_begy;
			curscr->_curx = win->_curx + win->_begx;
		}
	}
	retval = OK;
	_win = NULL;
	fflush(stdout);
	return retval;
}
예제 #20
0
int putchar(int c)
{
    _putchar(c);
    return c;
}