void kmain(void){ vga_init(); heap_init(); unreal_init(); // DETECT MEMORY puts("Detecting memory... "); memdetect(); uint16_t count = *((uint16_t *) 0x7E00); if(!count){ puts("error - something is wrong with INT15/EAX=E820"); while(1); } uint16_t i; uint32_t amount = 0; for(i = 0;i < count;i++){ amount += *((uint32_t *) 0x7008 + i * 4); } uint32_t mb = amount / 1048576; amount %= 1048576; uint8_t point = amount / 131072; if(amount % 131072 > 65536) point++; putd(mb); putc('.'); putd(point); puts(" MB\n"); unreal_disk(); read_unbuffered(0, 0x30000, 1); puts("Done!"); while(1); }
int main(void) { const int max = 3; fori(max) { forj(max) { printf("(%d, %d) ", i, j); } printf("\n"); } printf("\n"); some_func(max); printf("\n"); const int i = 10; const float f = 1.0f; putl(i); putd(f); putl(10); // still works, sort of... putx(i); putx(f); print_vec2(vec(1.0, 2.0)); print_vec3(vec(1.0, 2.0, 3.0)); struct player p1 = player("Mario"); struct player p2 = player("Luigi", .lives = 2); // -Winitializer-overrides warning print_player(p1); print_player(p2); }
void exfile(void) { close(io); io = -1; if (vflag) { putd(); putchr('\n'); } }
main() { int i; sort(nn, (sizeof nn)/(sizeof nn[0])); for (i = 0; i < (sizeof nn)/(sizeof nn[0]); i++) { putd(nn[i]); putchar('\n'); } return 0; }
/* putd - output decimal number */ void putd(int n) { if (n < 0) { putchar('-'); n = -n; } if (n/10) putd(n/10); putchar(n%10 + '0'); }
void putd(void) { int r; r = count%10; count /= 10; if (count) putd(); putchr(r + '0'); }
//-------------------------------------------------------------------- void putdown(apvector<int> &hand,apvector<int> &tabe,const apvector<apstring> &deck) { int e; while(e!=-1) { e=putd(hand,tabe); if(e!=-1) drawht(hand,tabe,deck); } }
void exfile(int om) { if(om == OWRITE) if(Bflush(&iobuf) < 0) error(Q); close(io); io = -1; if(vflag) { putd(); putchr('\n'); } }
void print(void) { unsigned int *a1; nonzero(); a1 = addr1; do { if (listn) { count = a1-zero; putd(); putchr('\t'); } puts(getline(*a1++)); } while (a1 <= addr2); dot = addr2; listf = 0; listn = 0; pflag = 0; }
void commands(void) { int *a1, c, temp; char lastsep; Dir *d; for(;;) { if(pflag) { pflag = 0; addr1 = addr2 = dot; printcom(); } c = '\n'; for(addr1 = 0;;) { lastsep = c; a1 = address(); c = getchr(); if(c != ',' && c != ';') break; if(lastsep == ',') error(Q); if(a1 == 0) { a1 = zero+1; if(a1 > dol) a1--; } addr1 = a1; if(c == ';') dot = a1; } if(lastsep != '\n' && a1 == 0) a1 = dol; if((addr2=a1) == 0) { given = 0; addr2 = dot; } else given = 1; if(addr1 == 0) addr1 = addr2; switch(c) { case 'a': add(0); continue; case 'b': nonzero(); browse(); continue; case 'c': nonzero(); newline(); rdelete(addr1, addr2); append(gettty, addr1-1); continue; case 'd': nonzero(); newline(); rdelete(addr1, addr2); continue; case 'E': fchange = 0; c = 'e'; case 'e': setnoaddr(); if(vflag && fchange) { fchange = 0; error(Q); } filename(c); init(); addr2 = zero; goto caseread; case 'f': setnoaddr(); filename(c); putst(savedfile); continue; case 'g': global(1); continue; case 'i': add(-1); continue; case 'j': if(!given) addr2++; newline(); join(); continue; case 'k': nonzero(); c = getchr(); if(c < 'a' || c > 'z') error(Q); newline(); names[c-'a'] = *addr2 & ~01; anymarks |= 01; continue; case 'm': move(0); continue; case 'n': listn++; newline(); printcom(); continue; case '\n': if(a1==0) { a1 = dot+1; addr2 = a1; addr1 = a1; } if(lastsep==';') addr1 = a1; printcom(); continue; case 'l': listf++; case 'p': case 'P': newline(); printcom(); continue; case 'Q': fchange = 0; case 'q': setnoaddr(); newline(); quit(); case 'r': filename(c); caseread: if((io=open(file, OREAD)) < 0) { lastc = '\n'; error(file); } if((d = dirfstat(io)) != nil){ if(d->mode & DMAPPEND) print("warning: %s is append only\n", file); free(d); } Binit(&iobuf, io, OREAD); setwide(); squeeze(0); c = zero != dol; append(getfile, addr2); exfile(OREAD); fchange = c; continue; case 's': nonzero(); substitute(globp != 0); continue; case 't': move(1); continue; case 'u': nonzero(); newline(); if((*addr2&~01) != subnewa) error(Q); *addr2 = subolda; dot = addr2; continue; case 'v': global(0); continue; case 'W': wrapp++; case 'w': setwide(); squeeze(dol>zero); temp = getchr(); if(temp != 'q' && temp != 'Q') { peekc = temp; temp = 0; } filename(c); if(!wrapp || ((io = open(file, OWRITE)) == -1) || ((seek(io, 0L, 2)) == -1)) if((io = create(file, OWRITE, 0666)) < 0) error(file); Binit(&iobuf, io, OWRITE); wrapp = 0; if(dol > zero) putfile(); exfile(OWRITE); if(addr1<=zero+1 && addr2==dol) fchange = 0; if(temp == 'Q') fchange = 0; if(temp) quit(); continue; case '=': setwide(); squeeze(0); newline(); count = addr2 - zero; putd(); putchr('\n'); continue; case '!': callunix(); continue; case EOF: return; } error(Q); } }
int nvprintf(size_t size, const char *fmt, va_list ap) { u32 i; return_val_if_fail(fmt != NULL, -1); for (i = 0; i < size; i++) { if (fmt[i] == '%') { if ((i + 1) < size && fmt[i+1] != '%') { char conv = fmt[i+1]; switch (conv) { case 'c': { char c = va_arg(ap, char); putchar(c); i++; break; } case 'u': { unsigned int u = va_arg(ap, unsigned int); putu(u); i++; break; } case 'x': case 'X': { unsigned int x = va_arg(ap, unsigned int); putx(x); i++; break; } case 'd': case 'i': { int d = va_arg(ap, int); putd(d); i++; break; } case 'p': { void *p = va_arg(ap, void *); putp(p); i++; break; } case 's': { const char *s = va_arg(ap, char *); puts(s); i++; break; } } } } else {