void win(struct point *ps) { struct point x; int j, k; int boxsize; /* actually diameter of box, not radius */ boxsize = (fast ? 10 : 4); x.col = ps->col; x.line = ps->line; for (j = 1; j < boxsize; j++) { for (k = 0; k < j; k++) { pchar(&x, '#'); x.line--; } for (k = 0; k < j; k++) { pchar(&x, '#'); x.col++; } j++; for (k = 0; k < j; k++) { pchar(&x, '#'); x.line++; } for (k = 0; k < j; k++) { pchar(&x, '#'); x.col--; } refresh(); delay(1); } }
void scans(int c, char* b) { unsigned char temp_char; int index = 0; for(index = 0 ; index < c-1 ; ) { temp_char = getch(); if(temp_char != 0) { b[index] = temp_char; pchar(b[index]); if(b[index] == '\n') { b[index] = 0; break; } index++; if(index == c-1) pchar('\n'); } } b[index+1] = 0; }
// blink a single character in Morse code void morse_character(char c) { unsigned char code, count; if (c == ' ') { print("Space\n"); _delay_ms(DIT * 7); return; } if (c < 'A' || c > 'Z') { print("Opps, unsupported character: "); pchar(c); print("\n"); return; } print("Char "); pchar(c); pchar(':'); code = pgm_read_byte(morse_code_table + (c - 'A')); for (count = code & 0x07; count > 0; count--) { LED_ON; if (code & 0x80) { print(" dah"); _delay_ms(DIT * 3); } else { print(" dit"); _delay_ms(DIT); } LED_OFF; _delay_ms(DIT); code = code << 1; } print("\n"); _delay_ms(DIT * 2); }
void scans(unsigned int length, char* outstr) { unsigned char temp_char = '\0'; int index = 0; for(index = 0 ; index < length-1 ; ) { temp_char = getch(); if(temp_char != 0) { outstr[index] = temp_char; pchar(outstr[index]); if(outstr[index] == '\n') { outstr[index] = 0; break; } index++; if(index == length-1) pchar('\n'); } } outstr[index+1] = 0; }
int pushsnake(void) { int i, bonus; int issame = 0; struct point tmp; /* * My manual says times doesn't return a value. Furthermore, the * snake should get his turn every time no matter if the user is * on a fast terminal with typematic keys or not. * So I have taken the call to times out. */ for (i = 4; i >= 0; i--) if (same(&snake[i], &snake[5])) issame++; if (!issame) pchar(&snake[5], ' '); /* Need the following to catch you if you step on the snake's tail */ tmp.col = snake[5].col; tmp.line = snake[5].line; for (i = 4; i >= 0; i--) snake[i + 1] = snake[i]; chase(&snake[0], &snake[1]); pchar(&snake[1], SNAKETAIL); pchar(&snake[0], SNAKEHEAD); for (i = 0; i < 6; i++) { if ((same(&snake[i], &you)) || (same(&tmp, &you))) { surround(&you); i = (cashvalue) % 10; bonus = arc4random_uniform(10); mvprintw(lcnt + 1, 0, "%d\n", bonus); refresh(); delay(30); if (bonus == i) { spacewarp(1); #ifdef LOGGING logit("bonus"); #endif flushinp(); return(1); } flushinp(); endwin(); if (loot >= penalty) { printf("\nYou and your $%d have been eaten\n", cashvalue); } else { printf("\nThe snake ate you. You owe $%d.\n", -cashvalue); } #ifdef LOGGING logit("eaten"); #endif length(moves); snscore(TOPN); close(rawscores); exit(0); } } return(0); }
void solve() { bool neg = false; if (sum < 0) { neg = true; sum = -sum; } int g = gcd(sum, n); int p = sum / g; int q = n / g; if (q == 1) { if (neg) printf("- "); printf("%d\n", p); return; } int a, b, c; if (p > q) { a = p/q; b = p%q; c = q; } else { a = 0; b = p; c = q; } int la = numlen(a); int lb = numlen(b); int lc = numlen(c); int ib = (neg ? 2 : 0) + la; int ic = (neg ? 2 : 0) + la; if (lc > lb) ib += lc - lb; // first line pchar(ib, ' '); printf("%d\n", b); // second line if (neg) printf("- "); if (a != 0) printf("%d", a); pchar(lc, '-'); putchar('\n'); // third line pchar(ic, ' '); printf("%d\n", c); }
/* * at - print current situation */ static void at(struct match *m, const char *title, const char *start, const char *stop, sopno startst, sopno stopst) { if (!(m->eflags®_TRACE)) return; (void) printf("%s %s-", title, pchar(*start)); (void) printf("%s ", pchar(*stop)); (void) printf("%ld-%ld\n", (long)startst, (long)stopst); }
static void phex(uint8_t c) { int hc = (((c) >> 4) & 0xf) + '0'; if (hc > '9') hc += 'a' - '9' - 1; pchar(hc); hc = ((c) & 0xf) + '0'; if (hc > '9') hc += 'a' - '9' - 1; pchar(hc); }
/* set up the board */ void setup(void) { int i; erase(); pchar(&you, ME); pchar(&finish, GOAL); pchar(&money, TREASURE); for (i = 1; i < 6; i++) { pchar(&snake[i], SNAKETAIL); } pchar(&snake[0], SNAKEHEAD); drawbox(); refresh(); }
/* * Test Userland Thread Scheduler (UTS) suite for KSE. */ int main(void) { int i; runq_init(&runq1); init_uts(&data1, &runq1); init_uts(&data2, &runq1); thread_start(&data1, aaaa, '+'); thread_start(&data1, aaaa, '-'); start_uts(&data1, 0); start_uts(&data2, 0); // start second ksegrp runq_init(&runq2); init_uts(&data3, &runq2); init_uts(&data4, &runq2); thread_start(&data3, newkse, 0); thread_start(&data3, aaaa, '*'); thread_start(&data3, aaaa, '.'); start_uts(&data3, 1); for (i = 0;1;i++) { // if (i < 1000) // thread_start(aaaa, 'a' + (i % 26)); pchar('A' + (i % 26)); nano(5); } pstr("\n** main() exiting **\n"); return (EX_OK); }
void snap(void) { /* I don't see the graphical purpose of the next block of code. * It just makes no sense. * * struct point p; * * if (you.line < 3) * pchar(point(&p, you.col, 0), '-'); * if (you.line > lcnt - 4) * pchar(point(&p, you.col, lcnt - 1), '_'); * if(you.col < 10) * pchar(point(&p, 0, you.line), '('); * if(you.col > ccnt-10) * pchar(point(&p, ccnt-1, you.line), ')'); */ if (!stretch(&money)) if (!stretch(&finish)) { pchar(&you, '?'); refresh(); delay(10); pchar(&you, ME); } /* Again, I don't see the point of the following either. * * if (you.line < 3) { * point(&p, you.col, 0); * chk(&p); * } * if (you.line > lcnt - 4) { * point(&p, you.col, lcnt - 1); * chk(&p); * } * if (you.col < 10) { * point(&p, 0, you.line); * chk(&p); * } * if (you.col > ccnt-10) { * point(&p, ccnt - 1, you.line); * chk(&p); * } */ refresh(); }
void pbinary(unsigned char c) { unsigned char i; for(i = 7; i < 8; i--) { pchar(c & (1 << i) ? '1' : '0'); } }
std::string param() { std::string s; while(rand(2)) s += pchar(); return s; }
void aaaa(int c) { for (;;) { pchar(c); nano(1); } }
int stretch(struct point *ps) { struct point p; p.col = you.col; p.line = you.line; if ((abs(ps->col - you.col) < (ccnt / 12)) && (you.line != ps->line)) { if (you.line < ps->line) { for (p.line = you.line + 1; p.line <= ps->line; p.line++) pchar(&p, 'v'); refresh(); delay(10); for (; p.line > you.line; p.line--) chk(&p); } else { for (p.line = you.line - 1; p.line >= ps->line; p.line--) pchar(&p, '^'); refresh(); delay(10); for (; p.line < you.line; p.line++) chk(&p); } return(1); } else if ((abs(ps->line - you.line) < (lcnt / 7)) && (you.col != ps->col)) { p.line = you.line; if (you.col < ps->col) { for (p.col = you.col + 1; p.col <= ps->col; p.col++) pchar(&p, '>'); refresh(); delay(10); for (; p.col > you.col; p.col--) chk(&p); } else { for (p.col = you.col - 1; p.col >= ps->col; p.col--) pchar(&p, '<'); refresh(); delay(10); for (; p.col < you.col; p.col++) chk(&p); } return(1); } return(0); }
void prints(char* s) { int index = 0; while(s[index] != 0) { pchar(s[index]); index++; } }
/* * Write formatted output to stdout, in a thread-safe manner. * * Recognises the following conversions: * %c -> char * %d -> signed int (base 10) * %s -> string * %u -> unsigned int (base 10) * %x -> unsigned int (base 16) */ static void pfmt(const char *fmt, ...) { static const char digits[16] = "0123456789abcdef"; va_list ap; char buf[10]; char *s; unsigned r, u; int c, d; va_start(ap, fmt); while ((c = *fmt++)) { if (c == '%') { c = *fmt++; switch (c) { case 'c': pchar(va_arg(ap, int)); continue; case 's': pstr(va_arg(ap, char *)); continue; case 'd': case 'u': case 'x': r = ((c == 'u') || (c == 'd')) ? 10 : 16; if (c == 'd') { d = va_arg(ap, unsigned); if (d < 0) { pchar('-'); u = (unsigned)(d * -1); } else u = (unsigned)d; } else u = va_arg(ap, unsigned); s = buf; do { *s++ = digits[u % r]; } while (u /= r); while (--s >= buf) pchar(*s); continue; }
void surround(struct point *ps) { int j; if (ps->col == 0) ps->col++; if (ps->line == 0) ps->line++; if (ps->line == LINES - 1) ps->line--; if (ps->col == COLS - 1) ps->col--; mvaddstr(ps->line, ps->col, "/*\\"); mvaddstr(ps->line + 1, ps->col, "* *"); mvaddstr(ps->line + 2, ps->col, "\\*/"); for (j = 0; j < 20; j++) { pchar(ps, '@'); refresh(); delay(1); pchar(ps, ' '); refresh(); delay(1); } if (post(cashvalue, 0)) { mvaddstr(ps->line, ps->col, " "); mvaddstr(ps->line + 1, ps->col, "o.o"); mvaddstr(ps->line + 2, ps->col, "\\_/"); refresh(); delay(6); mvaddstr(ps->line, ps->col, " "); mvaddstr(ps->line + 1, ps->col, "o.-"); mvaddstr(ps->line + 2, ps->col, "\\_/"); refresh(); delay(6); } mvaddstr(ps->line, ps->col, " "); mvaddstr(ps->line + 1, ps->col, "o.o"); mvaddstr(ps->line + 2, ps->col, "\\_/"); refresh(); delay(6); }
void inschar(char c) { register char *p; register char *pend; if (last_command == 'R' && (gchar(Curschar) != NUL)) { pchar(Curschar, c); } else { /* make room for the new char. */ if (!canincrease(1)) return; p = &Curschar->linep->s[strlen(Curschar->linep->s) + 1]; pend = &Curschar->linep->s[Curschar->index]; for (; p > pend; p--) *p = *(p - 1); *p = c; } if (RedrawingDisabled) { Curschar->index++; return; } /* * If we're in insert mode and showmatch mode is set, then check for * right parens and braces. If there isn't a match, then beep. If there * is a match AND it's on the screen, then flash to it briefly. If it * isn't on the screen, don't do anything. */ if (P(P_SM) && State == INSERT && (c == ')' || c == '}' || c == ']')) { LPtr *lpos, csave; if ((lpos = showmatch()) == NULL) /* no match, so beep */ beep(); else if (LINEOF(lpos) >= LINEOF(Topchar)) { /* show the new char first */ s_refresh(VALID_TO_CURSCHAR); csave = *Curschar; *Curschar = *lpos; /* move to matching char */ cursupdate(UPDATE_CURSOR); windgoto(Cursrow, Curscol); delay(); /* brief pause */ *Curschar = csave; /* restore cursor position */ cursupdate(UPDATE_ALL); } } inc(Curschar); CHANGED; }
void print_message1(message1_t message) { int i = 0; print("Message1 Received: "); print("\n\tProduct Key: "); for(i = 0; i < MESSAGE1_PRODUCT_KEY_LENGTH; ++i) { pchar(message.board_product_key[i]); } print("\n\tOutlet Number: "); for(i = 0; i < MESSAGE1_OUTLET_NUMBER_LENGTH; ++i) { pchar(message.board_outlet_number[i]); } print("\n\tState: "); for(i = 0; i < MESSAGE1_STATE_LENGTH; ++i) { pchar(message.state[i]); } print("\n\tOutlet Id: "); for(i = 0; i < MESSAGE1_OUTLET_ID_LENGTH; ++i) { pchar(message.outlet_id[i]); } print("\n\n"); }
main() { reset(); enable_interrupt(); while() { elegir_luz(); encender_luz(); } /***** rutina de interrupcion *****/ if (scan_inter () != 1) { if (shift_reg == FLAG) { switch (p_buffer) { case (0) : comienzo = 1; break; case (1) : if (comienzo==1) { p_buffer = 0; device = gchar(); if ( device == IDENTIFICATIVO) { acknowledge(); p_out = 0; wserial( gout () ); more = 1; } } break; default : if ( device == IDENTIFICATIVO ) { if (verificar() == NAK) no_acknowledge (); else { ack_nak = interpretar (); if ( ack_nak == ACK ) acknowledge (); else no_acknowledge (); } p_out = 0; wserial( gout () ); more = 1; } break; } p_buffer = 0; } else pchar(shift_reg); } else { if (more == 0) goto RTI; wserial( gout () ); if (shift_reg == 'f') { p_out = 1; more = 0; } } RTI (); }
/* * Write formatted output to stdout, in a thread-safe manner. * * Recognises the following conversions: * %c -> char * %d -> signed int (base 10) * %s -> string * %u -> unsigned int (base 10) * %x -> unsigned int (base 16) * %p -> unsigned int (base 16) */ void _thread_printf(int fd, const char *fmt, ...) { static const char digits[16] = "0123456789abcdef"; va_list ap; char buf[20]; char *s; unsigned long r, u; int c; long d; int islong; va_start(ap, fmt); while ((c = *fmt++)) { islong = 0; if (c == '%') { next: c = *fmt++; if (c == '\0') goto out; switch (c) { case 'c': pchar(fd, va_arg(ap, int)); continue; case 's': pstr(fd, va_arg(ap, char *)); continue; case 'l': islong = 1; goto next; case 'p': islong = 1; case 'd': case 'u': case 'x': r = ((c == 'u') || (c == 'd')) ? 10 : 16; if (c == 'd') { if (islong) d = va_arg(ap, unsigned long); else d = va_arg(ap, unsigned); if (d < 0) { pchar(fd, '-'); u = (unsigned long)(d * -1); } else u = (unsigned long)d; } else { if (islong) u = va_arg(ap, unsigned long); else u = va_arg(ap, unsigned); }
/* abs_path = "/" path_segments path_segments = segment *( "/" segment ) segment = *pchar *( ";" param ) param = *pchar pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | "," */ std::string abs_path() { std::string s = "/"; for(;;) { while(rand(2)) s += pchar(); while(rand(2)) s += ";" + param(); if(rand(2)) break; s.append("/"); } return s; }
/* * print - print a set of states */ static void print(struct match *m, const char *caption, states st, int ch, FILE *d) { struct re_guts *g = m->g; int i; int first = 1; if (!(m->eflags®_TRACE)) return; (void) fprintf(d, "%s", caption); if (ch != '\0') (void) fprintf(d, " %s", pchar(ch)); for (i = 0; i < g->nstates; i++) if (ISSET(st, i)) { (void) fprintf(d, "%s%d", (first) ? "\t" : ", ", i); first = 0; } (void) fprintf(d, "\n"); }
int chk(struct point *sp) { int j; if (same(sp, &money)) { pchar(sp, TREASURE); return(2); } if (same(sp, &finish)) { pchar(sp, GOAL); return(3); } if (same(sp, &snake[0])) { pchar(sp, SNAKEHEAD); return(4); } for (j = 1; j < 6; j++) { if (same(sp, &snake[j])) { pchar(sp, SNAKETAIL); return(4); } } if ((sp->col < 4) && (sp->line == 0)) { winnings(cashvalue); if ((you.line == 0) && (you.col < 4)) pchar(&you, ME); return(5); } if (same(sp, &you)) { pchar(sp, ME); return(1); } pchar(sp, ' '); return(0); }
void myprint(volatile char *str) { while(*str != '\0') { pchar(*str++); } }
//Key Execute function //Decodes a keycode, and executes depending on codetype void key_execute(keycode aKey, uint8_t down) { print("inside key_execute\n"); phex(aKey.type); print("<-Type:Code->"); phex(aKey.code); print("\n"); switch(aKey.type) { case TYPE_KEY: //Check for type, and call functions if(down) add_key(aKey.code); else del_key(aKey.code); break; case TYPE_MOD: //Check for type, and call functions if(down) add_mod(aKey.code); else del_mod(aKey.code); break; case TYPE_MEDIA: case TYPE_MOUSE: //Placeholder if mouse and media keys implemented break; case TYPE_MOMENTARY: //For mementary layer changes clear_keyboard(); //Clear all current plessed keys, because they may not exist in new layer if(down) set_current_layer(aKey.code); else set_current_layer(0); //Return to default layer break; case TYPE_TOGGLE: //For toggleing layer changes if(down && (aKey.code ^ get_current_layer()) ) { clear_keyboard(); set_current_layer(aKey.code); } break; case TYPE_MISC: //Miscelaneous functions need special treatment switch(aKey.code) { case CODE_JMP_BOOT: //Jump to boot loader if(down) //Only want to activate on key-down { jump_bootloader(); } break; case CODE_BR_UP: //Raise brightness of LEDS //In steps of 24 if(down) //Only want to activate on key-down { if(OCR4D < 0xF0) OCR4D += 0x20; } break; case CODE_BR_DOWN: //Lower brightness of LEDS //In steps of 24 if(down) //Only want to activate on key-down { if(OCR4D > 0x10) OCR4D -= 0x20; } break; } break; default: //Default case: Unknown Keytype //Print error and do nothing print("Unknown Key Type: "); phex(aKey.type); pchar('\n'); } }
main(int argc, char *argv[]) { char *p; int j; Tchar i; char buf[100]; buf[0] = '\0'; /* make sure it's empty (silly 3b2) */ progname = argv[0]; if ((p = strrchr(progname, '/')) == NULL) p = progname; else p++; DWBinit(progname, dwbpaths); if (strcmp(p, "nroff") == 0) TROFF = 0; #ifdef UNICODE alphabet = 128; /* unicode for plan 9 */ #endif /*UNICODE*/ mnspace(); nnspace(); mrehash(); nrehash(); numtabp[NL].val = -1; while (--argc > 0 && (++argv)[0][0] == '-') switch (argv[0][1]) { case 'N': /* ought to be used first... */ TROFF = 0; break; case 'd': fprintf(stderr, "troff/nroff version %s\n", Version); break; case 'F': /* switch font tables from default */ if (argv[0][2] != '\0') { strcpy(termtab, &argv[0][2]); strcpy(fontdir, &argv[0][2]); } else { argv++; argc--; strcpy(termtab, argv[0]); strcpy(fontdir, argv[0]); } break; case 0: goto start; case 'i': stdi++; break; case 'n': npn = atoi(&argv[0][2]); break; case 'u': /* set emboldening amount */ bdtab[3] = atoi(&argv[0][2]); if (bdtab[3] < 0 || bdtab[3] > 50) bdtab[3] = 0; break; case 's': if (!(stop = atoi(&argv[0][2]))) stop++; break; case 'r': sprintf(buf + strlen(buf), ".nr %c %s\n", argv[0][2], &argv[0][3]); /* not yet cpushback(buf);*/ /* dotnr(&argv[0][2], &argv[0][3]); */ break; case 'm': if (mflg++ >= NMF) { ERROR "Too many macro packages: %s", argv[0] WARN; break; } strcpy(mfiles[nmfi], nextf); strcat(mfiles[nmfi++], &argv[0][2]); break; case 'o': getpn(&argv[0][2]); break; case 'T': strcpy(devname, &argv[0][2]); dotT++; break; case 'a': ascii = 1; break; case 'h': hflg++; break; case 'e': eqflg++; break; case 'q': quiet++; save_tty(); break; case 'V': fprintf(stdout, "%croff: DWB %s\n", TROFF ? 't' : 'n', DWBVERSION); exit(0); case 't': if (argv[0][2] != '\0') trace = trace1 = argv[0][2]; break; /* for the sake of compatibility */ default: ERROR "unknown option %s", argv[0] WARN; done(02); } start: /* * cpushback maintains a LIFO, so push pack the -r arguments * in reverse order to maintain a FIFO in case someone did -rC1 -rC3 */ if (buf[0]) { char *p = buf; while(*p++) ; while(p > buf) { while(strncmp(p, ".nr", 3) != 0) p--; cpushback(p); *p-- = '\0'; } } argp = argv; rargc = argc; nmfi = 0; init2(); setjmp(sjbuf); loop: copyf = lgf = nb = nflush = nlflg = 0; if (ip && rbf0(ip) == 0 && ejf && frame->pframe <= ejl && dip == d) { nflush++; trap = 0; eject((Stack *)0); goto loop; } i = getch(); if (pendt) goto Lt; if ((j = cbits(i)) == XPAR) { copyf++; tflg++; while (cbits(i) != '\n') pchar(i = getch()); tflg = 0; copyf--; /* pointless */ goto loop; } if (j == cc || j == c2) { if (j == c2) nb++; copyf++; while ((j = cbits(i = getch())) == ' ' || j == '\t') ; ch = i; copyf--; control(getrq(), 1); flushi(); goto loop; } Lt: ch = i; text(); if (nlflg) numtabp[HP].val = 0; goto loop; }
void horiz(int i) { vflag = 0; if (i) pchar(makem(i)); }
void tbreak(void) { int pad, k; Tchar *i, j; int resol; int un0 = un; trap = 0; if (nb) return; if (dip == d && numtabp[NL].val == -1) { newline(1); return; } if (!nc) { setnel(); if (!wch) return; if (pendw) getword(1); movword(); } else if (pendw && !brflg) { getword(1); movword(); } *linep = dip->nls = 0; if (NROFF && dip == d) horiz(po); if (lnmod) donum(); lastl = ne; if (brflg != 1) { totout = 0; } else if (ad) { if ((lastl = ll - un) < ne) lastl = ne; } if (admod && ad && (brflg != 2)) { lastl = ne; adsp = adrem = 0; if (admod == 1) un += quant(nel / 2, HOR); else if (admod == 2) un += nel; } totout++; brflg = 0; if (lastl + un > dip->maxl) dip->maxl = lastl + un; horiz(un); if (NROFF) { if (adrem % t.Adj) resol = t.Hor; else resol = t.Adj; } else resol = HOR; lastl = ne + (nwd-1) * adsp + adrem; for (i = line; nc > 0; ) { if ((cbits(j = *i++)) == ' ') { pad = 0; do { pad += width(j); nc--; } while ((cbits(j = *i++)) == ' '); i--; pad += adsp; --nwd; if (adrem) { if (adrem < 0) { pad -= resol; adrem += resol; } else if ((totout & 01) || adrem / resol >= nwd) { pad += resol; adrem -= resol; } } pchar((Tchar) WORDSP); horiz(pad); } else { pchar(j); nc--; } } if (ic) { if ((k = ll - un0 - lastl + ics) > 0) horiz(k); pchar(ic); } if (icf) icf++; else ic = 0; ne = nwd = 0; un = in; setnel(); newline(0); if (dip != d) { if (dip->dnl > dip->hnl) dip->hnl = dip->dnl; } else { if (numtabp[NL].val > dip->hnl) dip->hnl = numtabp[NL].val; } for (k = ls - 1; k > 0 && !trap; k--) newline(0); spread = 0; }