/* a simpler printk * refer to unix v6 * */ void printk(char *fmt, ...){ char c, *s; int n; int *adx = (uint*)(void*)&fmt + 1; _loop: while((c = *fmt++) != '%'){ if (c == '\0') return; putch(c); } c = *fmt++; if (c == 'd' || c == 'l'){ n = *adx; if (n<0){ putch('-'); printn(-n, 10); } else printn(n, 10); } if (c == 'o' || c == 'x'){ printn(*adx, c=='o'? 8:16 ); } if (c == 'c') { putch(*adx); } if (c == 's'){ puts(*adx); } adx++; goto _loop; }
/*********************************************************************************************** 功能:UART 格式化输出 形参:fmt 输入字符串指针 返回:0 详解:类似于C标准库中的printf 但是只支持 %d %l %o %x %s ************************************************************************************************/ void UART_printf(char *fmt, ...) { char c; unsigned int *adx = (unsigned int*)(void*)&fmt + 1; _loop: while((c = *fmt++) != '%') { if (c == '\0') return; UART_SendData(UART_DebugPort,c); } c = *fmt++; if (c == 'd' || c == 'l') { printn(*adx, 10); } if (c == 'o' || c == 'x') { printn(*adx, c=='o'? 8:16 ); } if (c == 's') { UART_puts((char*)*adx); } adx++; goto _loop; }
int UART_printf(const char *fmt, ...) { char c; unsigned int *adx = (unsigned int*)(void*)&fmt + 1; _loop: while((c = *fmt++) != '%') { if (c == '\0') return 0; UART_WriteByte(UART_DebugInstance, c); } c = *fmt++; if (c == 'd' || c == 'l') { printn(*adx, 10); } if (c == 'o' || c == 'x') { printn(*adx, c=='o'? 8:16 ); } if (c == 's') { UART_putstr(UART_DebugInstance, (char*)*adx); } adx++; goto _loop; return 0; }
void printn(node *b) { if(b) { printn(b->lchild); printf("%c", b->ch); printn(b->rchild); } }
//Hmm... let's try to build a really decent... //.... in-memory multipilication table! int main() { int mtable[10][10][10]; int a; int b; int c; int result; for(a = 0;a < 10; a = a + 1) { for(b = 0;b < 10; b = b + 1) { for(c = 0;c < 10; c = c + 1) { mtable[a][b][c] = a*b*c; } } } //now let's try some math! result = mtable[2][5][6]; //expect 60 printi(result); printn(); result = mtable[5][6][2]; //expect 60 printi(result); printn(); result = mtable[4][3][5]; //expect 60 printi(result); printn(); result = mtable[2][5][6] * mtable[5][6][2]; //expect 3600 printi(result); printn(); result = mtable[1][1][7]; //expect 60 printi(result); printn(); }
void test_print::test_printn() { printn(N(abcde)); printn(N(abBde)); printn(N(1q1q1qAA)); printn(N()); printn(N(AAAAAA)); printn(N(abcdefghijk)); printn(N(abcdefghijkl)); printn(N(abcdefghijkl1)); printn(N(abcdefghijkl12)); printn(N(abcdefghijkl123)); }
static void test(int n) { systime_t time = chTimeNow(); printn(n); print("\r\n"); printn(biessess); print("\r\n"); print(datastr); print("\r\n"); print("\r\n"); (void)datavec; }
describe_location() { char new_control[8]; char *comma_pos; int print_room_desc, print_room_desc_alt; char *item; /* check which room description should be printed */ if ((comma_pos = strchr(ROOM_DESC_CONTROL(room), ',')) != NULL) if (strchr(ROOM_DESC_CONTROL(room), '+') != NULL) strcpy(new_control, comma_pos + 1); else { strncpy(new_control, ROOM_DESC_CONTROL(room), comma_pos - ROOM_DESC_CONTROL(room)); *(new_control + (comma_pos - ROOM_DESC_CONTROL(room))) = '\0'; } else strcpy(new_control, "RC"); if ((strchr(new_control, 'R') != NULL) && (*ROOM_DESC(room) != '-')) print_room_desc = 1; else print_room_desc = 0; if ((strchr(new_control, 'C') != NULL) && (*ROOM_DESC_ALT(room) != '\0')) print_room_desc_alt = 1; else print_room_desc_alt = 0; if (print_room_desc || print_room_desc_alt || (*CONTENTS(room) != '\0')) print("\n"); if (print_room_desc) printn(ROOM_DESC(room)); if (print_room_desc_alt) printn(ROOM_DESC_ALT(room)); if (*CONTENTS(room) != '\0') { item = strtok(CONTENTS(room), ","); do { print("There is "); a_or_an(item); print(item); print(" here.\n"); } while ((item = nexttok(",")) != NULL); } }
printn(n,b) { extern putchar; auto a; if(a=n/b) /* assignment, not test for equality */ printn(a, b); /* recursive */ putchar(n%b + '0'); }
// print an unsigned integer in base b void printn(uint n, uint b){ static char *ntab = "0123456789ABCDEF"; uint a, m; if (a = n / b){ printn(a, b); } m = n % b; putch( ntab[m] ); }
void printn(int number, int radix,FILE *file) { int i; if (number < 0 && radix == 10){ fputc('-', file); number = -number; } if ((i = number / radix) != 0) printn(i, radix, file); fputc(dig[number % radix], file); }
//内部函数为实现UART_printf static void printn(unsigned int n, unsigned int b) { static char *ntab = "0123456789ABCDEF"; unsigned int a, m; if (n / b) { a = n / b; printn(a, b); } m = n % b; UART_SendData(UART_DebugPort,ntab[m]); }
static void printn(unsigned int n, unsigned int b) { static char *ntab = "0123456789ABCDEF"; unsigned int a, m; if (n / b) { a = n / b; printn(a, b); } m = n % b; UART_WriteByte(UART_DebugInstance, ntab[m]); }
void infon( const char *msg, ... ) { va_list va; if (!(DFlags & QUIET)) { va_start( va, msg ); printn( msg, va ); va_end( va ); need_nl = 1; } }
void printn(int n) { int a; if (n < 0) { putchar('-'); n = -n; } a = n / 10; if (a != 0) { printn(a); } putchar(n % 10 + '0'); }
void printn(long n) { long a; if (n < 0) { putchar('-'); n = -n; } a = n / 10; if (a != 0) { printn(a); } putchar(n % 10 + '0'); }
/* * Output a number in base 10. */ static void printn(long n) { long a; if (n < 0) { charOut('-'); n = -n; } a = n / 10; if (a != 0) { printn(a); } charOut(n % 10 + '0'); }
/* * Formatted output with a variable argument list. */ static void vprintf(char *fmt, va_list ap) { char c; int n; long ln; unsigned int u; unsigned long lu; char *s; Bool negFlag; char filler; int width, count; while (1) { while ((c = *fmt++) != '%') { if (c == '\0') { return; } charOut(c); } c = *fmt++; if (c == '-') { negFlag = TRUE; c = *fmt++; } else { negFlag = FALSE; } if (c == '0') { filler = '0'; c = *fmt++; } else { filler = ' '; } width = 0; while (c >= '0' && c <= '9') { width *= 10; width += c - '0'; c = *fmt++; } if (c == 'd') { n = va_arg(ap, int); count = countPrintn(n); if (width > 0 && !negFlag) { fill(width - count, filler); } printn(n); if (width > 0 && negFlag) { fill(width - count, filler); } } else if (c == 'u' || c == 'o' || c == 'x' || c == 'X') {
int main ( ) { char* text = "DDDDDDDOOOOOOOHHHHHHH"; checkRegisters1(); // Debugging: Save callee-saved registers to memory. All red LEDs should turn on. printn ( text, 10, 11, 12, 13, 14, 15, 16, 10, 11, 12, 13, 14, 15, 16, 10, 11, 12, 13, 14, 15, 16 ); checkRegisters2(); // Debugging: Check that callee-saved registers did not change. Red LEDs turn on if mismatch. return 0; }
void drawCmdLineWithPath() { register ushort o, l, old; // Выводим только последние 30 символов пути print(1, ROWS_CNT+6, "/"); l = strlen(panelA.path1); if(l>=30) o=l-30, l=30; else o=0; printn(2, ROWS_CNT+6, l, panelA.path1+o); print(l+2, ROWS_CNT+6, ">"); // Сохраняем значение для drawCmdLine panelA.cmdLineOff = l+3; // Выводим ком строку drawCmdLine(); }
// params: int pid void proc_info(int argc, char *argv[]) { int pid, err, i; pcbinfo res; pid = stoi(get_arg(argv, 1)); err = get_proc_info(pid, &res); if (err == 0) { print("Information about process pid = "); printi(pid); print("\n\tname:\t\t\t"); print(res.name); print("\n\tpriority:\t\t"); printi(res.pri); print("\n\tsupervised processes:\t"); for (i = 0; i < MAXPCB; i++) { if (res.supervised[i] != -1) { printi(res.supervised[i]); print(" "); } } print("\n\tsupervisor process:\t"); printi(res.supervisor); print("\n\tprocess state:\t\t"); printi(res.state); print("\n\ttime to sleep:\t\t"); printi(res.sleep); print("\n\twaiting for process:\t"); printi(res.waitfor); //print("\n\tlast error:\t\t"); //printi(res.error); printn(); } else { print("An error occured! (code:"); printi(err); print(")\n"); } exit(0); }
int main() { int t; scanf("%d", &t); node *bt; while(t--) { scanf("%s", str); l = strlen(str); l--; bt = new node(); bt = create(bt); printn(bt); printf("\n"); } }
int main(void) { char str[MAXCHAR]; int n, i, j; while (scanf("%d %s", &n, str) && n != 0) { for (i = 0; i < 2 * n + 3; i++) { /* line */ for (j = 0; str[j] != '\0'; j++) { /* number */ if (j > 0) putchar(' '); printn(str[j], i, n); } putchar('\n'); } putchar('\n'); } return 0; }
void drawPanelTitle(uchar active) { char* p; ushort l; uchar x; // Восстанавливаем памку memset((char*)charAddr(activePanel + 2, 0), 0x1C, 29); // Выводим путь по центру p = panelA.path1; if(p[0]==0) p = "/"; l = strlen(p); if(l>=27) p=p+(l-27), l=27; x = 2 + (30 - l) / 2 + activePanel; printn(x, 0, l, p); if(!active) return; print(x-1, 0, "["); print(x+l, 0, "]"); }
void printf(char *fmt, ...) { va_list ap; char c; int n; unsigned int u; char *s; char filler; int width, count, i; va_start(ap, fmt); while (1) { while ((c = *fmt++) != '%') { if (c == '\0') { va_end(ap); return; } putchar(c); } c = *fmt++; if (c == '0') { filler = '0'; c = *fmt++; } else { filler = ' '; } width = 0; if (c >= '0' && c <= '9') { width = c - '0'; c = *fmt++; } if (c == 'd') { n = va_arg(ap, int); if (width > 0) { count = countPrintn(n); for (i = 0; i < width - count; i++) { putchar(filler); } } printn(n); } else if (c == 's') {
void coquille(void) { int nb_arg, pid, status, cexit = 0; char prompt_line[255]; char buffer[255]; // char ibuf[3]; strcpy("coquille> ", prompt_line); print(prompt_line); while (!cexit) { // waiting for the user to enter a command gets(buffer, 255); printn(); // split the string nb_arg = split_args(buffer, command_arg); if (nb_arg != -1) { // if the command is exit, exit the shell if (strcmp("exit", command_arg[0]) == 0) cexit = 1; // otherwise create the desirated process else { pid = fourchette(command_arg[0], BAS_PRI, nb_arg, (char **) command_arg); if (pid > 0) wait(pid, &status); else perror("Error"); } } if (!cexit) print("coquille> "); } exit(0); }
main() { FILE *fp; char line[81]; int i; /* Do yourself a favour and change the filename to something else! */ fp=fopen("filetest.c","r"); if ((fp == NULL)) { fputs("\nCan't open file, sorry",stdout); exit(0); } printn(fp,10,stdout); for (i=0; i!=5; i++) { fgets(line,80,fp); fputs(line,stdout); } fclose(fp); }
static void dump_obj(struct ar_hdr* header) { char* name; size_t name_len; int is_bsd_name = arobj_name(header, &name, &name_len); printf("ar_name: "); printn(name, name_len); if (is_bsd_name) { printf(" (extended BSD name)"); } printf("\n"); mprintn("ar_date: ", header->ar_date, sizeof(header->ar_date)); mprintn("ar_uid: ", header->ar_uid, sizeof(header->ar_uid)); mprintn("ar_gid: ", header->ar_gid, sizeof(header->ar_gid)); mprintn("ar_mode: ", header->ar_mode, sizeof(header->ar_mode)); mprintn("ar_size: ", header->ar_size, sizeof(header->ar_size)); mprintn("ar_fmag: ", header->ar_fmag, sizeof(header->ar_fmag)); if (strncmp(header->ar_fmag, ARFMAG, sizeof(ARFMAG) - 1)) fatal("unexpected ar_fmag\n"); }
void printf(char *fmt, ...) { va_list ap; char c; int n; unsigned int u; char *s; va_start(ap, fmt); while (1) { while ((c = *fmt++) != '%') { if (c == '\0') { va_end(ap); return; } putchar(c); } c = *fmt++; if (c == 'd') { n = va_arg(ap, int); printn(n); } else if (c == 'u' || c == 'o' || c == 'x') {
int main(){ struct dlist *l = dd_new(); if (l == NULL){ printf("malloc err\n"); return -1; } dd_insert(l, "Gislene", 1); dd_insert(l, "Antonio", 3); dd_insert(l, "Emma", 5); dd_insertn(l, "Filip", 2, -2); print(l); putchar('\n'); printn(l); dd_free(l); return 0; }