int printf(char *format, ...) { char c; int i; long n; va_list a; va_start(a, format); while(c = *format++) { if(c == '%') { switch(c = *format++) { case 's': // String puts(va_arg(a, char*)); break; case 'c': // Char putc(va_arg(a, char)); break; case 'i': // 16 bit Integer case 'u': // 16 bit Unsigned i = va_arg(a, int); if(c == 'i' && i < 0) i = -i, putc('-'); xtoa((unsigned)i, dv + 5); break; case 'l': // 32 bit Long case 'd': case 'n': // 32 bit uNsigned loNg n = va_arg(a, long); if(c == 'l' && n < 0) n = -n, putc('-'); xtoa((unsigned long)n, dv); break; case 'X': // 16 bit heXadecimal i = va_arg(a, int); puth(i >> 12); puth(i >> 8); puth(i >> 4); puth(i); break; case 'x': // 8 bit heXadecimal i = va_arg(a, int); puth(i >> 4); puth(i); break; case 0: return inde; default: goto bad_fmt; } } else bad_fmt: putc(c); }
uint16_t s_printf(char *instr, const char *format, ...) { char c; int i; long n; sptr = instr; slen = 0; sptr[slen] = '\0'; va_list a; va_start(a, format); while( (c = *format++) ) { if(c == '%') { switch(c = *format++) { case 's': // String s_puts(va_arg(a, char*)); break; case 'c': // Char s_putc(va_arg(a, int)); // Char gets promoted to Int in args, so it's an int we're looking for (GCC warning) break; case 'i': // 16 bit Integer case 'd': // 16 bit Integer case 'u': // 16 bit Unsigned i = va_arg(a, int); if( (c == 'i' || c == 'd') && i < 0 ) i = -i, s_putc('-'); xtoa((unsigned)i, dv + 5); break; case 'l': // 32 bit Long case 'n': // 32 bit uNsigned loNg n = va_arg(a, long); if(c == 'l' && n < 0) n = -n, s_putc('-'); xtoa((unsigned long)n, dv); break; case 'x': // 16 bit heXadecimal i = va_arg(a, int); puth(i >> 12); puth(i >> 8); puth(i >> 4); puth(i); break; case 0: return slen; default: goto bad_fmt; } } else bad_fmt: s_putc(c); }
void tprintf(char *format, ...) { char c; int i; long n; va_list a; va_start(a, format); while((c = *format++)) { if(c == '%') { switch(c = *format++) { case 's': // String UART0_PrintString(va_arg(a, char*)); break; case 'c': // Char UART0_Sendchar((char) va_arg(a, int)); break; case 'i': // 16 bit Integer case 'u': // 16 bit Unsigned i = va_arg(a, int); if(c == 'i' && i < 0) i = -i, UART0_Sendchar('-'); xtoa((unsigned)i, dv + 5); break; case 'l': // 32 bit Long case 'n': // 32 bit uNsigned loNg n = va_arg(a, long); if(c == 'l' && n < 0) n = -n, UART0_Sendchar('-'); xtoa((unsigned long)n, dv); break; case 'x': // 16 bit heXadecimal i = va_arg(a, int); puth(i >> 12); puth(i >> 8); puth(i >> 4); puth(i); break; case 0: return; default: goto bad_fmt; } } else bad_fmt: UART0_Sendchar(c); }
void lddrvr(const char * fn) { char * buf = read_file(fn); if (buf == NULL) { puts("Could read file \'"); puts(fn); puts("\'.\n"); return; } if (drvr_exists( ((int*)buf)[5] )) { puts("Driver with id "); puth(((int*)buf)[5]); puts(" already exists.\n"); return; } puts("asf\n"); while (1) {} create_drvr(buf); free(buf); }
void OLED::write(char *format, ...) { char c; int i, val; int8_t padding_len; long n; va_list a; va_start(a, format); while (c = *format++) { if (c == '%') { c = *format++; // '1' is 49 '2' is 50 .. '9' is 57 // '1' - 48 = 0x01 which is real number, not ASCII number padding_len = c-48; // we found padding so now check format string type if ((uint8_t)padding_len >= 1 && (uint8_t)padding_len <= 9) { c = *format++; } switch (c) { case 's': // String puts(va_arg(a, char*)); break; case 'c': // Char putc(va_arg(a, char)); break; case 'i': // 16 bit Integer case 'd': // 16 bit Integer case 'u': // 16 bit Unsigned i = va_arg(a, int); if ((uint8_t)padding_len >= 1 && (uint8_t)padding_len <= 9) { val = i; while (val != 0) { val = val / 10; padding_len--; } if (padding_len > 0) { if (i <= 0) { padding_len--; // - sign already pads 1 place and 0 is special } for (int i = 0; i < (uint8_t)padding_len; ++i) { putc(' '); } } } if (c == 'i' && i < 0) { i = -i; putc('-'); } xtoa((unsigned)i, dv + 5); break; case 'l': // 32 bit Long case 'n': // 32 bit uNsigned loNg n = va_arg(a, long); if (c == 'l' && n < 0) n = -n, putc('-'); xtoa((unsigned long)n, dv); break; case 'x': // 16 bit heXadecimal i = va_arg(a, int); puth(i >> 12); puth(i >> 8); puth(i >> 4); puth(i); break; case 0: return; default: goto bad_fmt; } } else {