Sint4 getinitial(Sint4 x,Sint4 y) { Sint4 i; gwrite(x,y,'_',3); do { #ifdef _WINDOWS do_windows_events(); #endif for (i=0;i<40;i++) { if (kbhit()) return getkey(); #ifdef _WINDOWS flashywait(5); #else flashywait(15); #endif } for (i=0;i<40;i++) { if (kbhit()) { gwrite(x,y,'_',3); return getkey(); } #ifdef _WINDOWS flashywait(5); #else flashywait(15); #endif } } while (1); }
void runtime·printcomplex_c(Complex128 v) { gwrite("(", 1); runtime·printfloat_c(v.real); runtime·printfloat_c(v.imag); gwrite("i)", 2); }
void runtime·printbool_c(bool v) { if(v) { gwrite((byte*)"true", 4); return; } gwrite((byte*)"false", 5); }
void runtime·printstring_c(String v) { if(v.len > runtime·maxstring) { gwrite("[string too long]", 17); return; } if(v.len > 0) gwrite(v.str, v.len); }
/* * dble() * Have the current player double and ask opponent to accept. */ void dble () { register int resp; /* response to y/n */ for (;;) { writel (" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ writel (" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else { /* computer accepts */ writel (" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; if (tflag) gwrite(); return; } } /* ask if player accepts */ writel (" Does "); writel (cturn == 1? color[2]: color[3]); writel (" accept?"); /* get response from yorn, * a "2" means he said "p" * for print board. */ if ((resp = yorn ('R')) == 2) { writel (" Reprint.\n"); buflush(); wrboard(); writel (*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } nexturn (); /* declined */ cturn *= -2; return; } }
static int process(Agraph_t * g, int gcnt) { Agnode_t *n; bcstate state; Agraph_t *blk; Agraph_t *tree; int bcnt; aginit(g, AGNODE, "info", sizeof(Agnodeinfo_t), TRUE); aginit(g, AGEDGE, "info", sizeof(Agedgeinfo_t), TRUE); aginit(g, AGRAPH, "info", sizeof(Agraphinfo_t), TRUE); state.count = 0; state.nComp = 0; state.stk = 0; state.blks = 0; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (N(n) == 0) dfs(g, n, &state, 0); } for (blk = state.blks; blk; blk = NEXTBLK(blk)) { nodeInduce(blk, g); } if (external) { bcnt = 0; for (blk = state.blks; blk; blk = NEXTBLK(blk)) { gwrite(blk, gcnt, bcnt++); } } else gwrite(g, gcnt, 0); if (doTree) { tree = agopen("blkcut_tree", Agstrictundirected, 0); for (blk = state.blks; blk; blk = NEXTBLK(blk)) addCutPts(tree, blk); gwrite(tree, gcnt, -1); agclose(tree); } if (verbose) { int cuts = 0; bcnt = 0; for (blk = state.blks; blk; blk = NEXTBLK(blk)) bcnt++; for (n = agfstnode(g); n; n = agnxtnode(g, n)) if (Cut(n)) cuts++; fprintf(stderr, "%s: %d blocks %d cutpoints\n", agnameof(g), bcnt, cuts); } if (state.blks && NEXTBLK(state.blks)) return 1; /* >= 2 blocks */ else return 0; }
void getinitials(void) { Sint4 k,i; newframe(); outtext("ENTER YOUR",100,70,3); outtext(" INITIALS",100,90,3); outtext("_ _ _",128,130,3); strcpy(scoreinit[0],"..."); killsound(); for (i=0;i<3;i++) { k=0; while (k==0) { k=getinitial(i*24+128,130); if (k==8 || k==127) { if (i>0) i--; k=0; } } if (k!=0) { gwrite(i*24+128,130,k,3); scoreinit[0][i]=k; } } for (i=0;i<20;i++) flashywait(15); setupsound(); gclear(); gpal(0); ginten(0); setretr(true); recputinit(scoreinit[0]); }
static int dbWriteKeyValue(int fd, char_t *key, char_t *value) { int rc; int len; char_t *pLineOut; a_assert(key && *key); a_assert(value); fmtAlloc(&pLineOut, BUF_MAX, T("%s=%s\n"), key, value); if (pLineOut) { len = gstrlen(pLineOut); #ifdef CE rc = writeUniToAsc(fd, pLineOut, len); #else rc = gwrite(fd, pLineOut, len); #endif bfree(B_L, pLineOut); } else { rc = -1; } return rc; }
/*------------------------------------------------------------------- write_header() - writes a HDR_SIZE byte block that contains a header. -------------------------------------------------------------------*/ int write_header( int fd, /*file descriptor*/ unsigned char *hdr, /*header location*/ enum header_types hdr_type /*header type flag*/ ){ if( gwrite(fd,hdr,UCH,UCH,HDR_SIZ,NO) < 0 ) return -1; else return 0; }
void dble() { int resp; /* response to y/n */ for (;;) { addstr(" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ addstr(" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else {/* computer accepts */ addstr(" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; gwrite(); return; } } /* ask if player accepts */ printw(" Does %s accept?", cturn == 1 ? color[2] : color[3]); /* get response from yorn; a "2" means he said "p" to print board. */ if ((resp = yorn ('r')) == 2) { addstr(" Reprint.\n"); moveplayers(); wrboard(); addstr(*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; gwrite(); return; } nexturn(); /* declined */ cturn *= -2; return; } }
void outtext(char *p,int16_t x,int16_t y,int16_t c) { int16_t i; for (i=0;p[i];i++) { gwrite(x,y,isalnum(p[i]) ? p[i] : ' ',c); x+=12; } }
void runtime·printint_c(int64 v) { if(v < 0) { gwrite("-", 1); v = -v; } runtime·printuint_c(v); }
Sint4 getinitial(Sint4 x,Sint4 y) { Sint4 i; gwrite(x,y,'_',3); do { for (i=0;i<40;i++) { if (kbhit()) return getkey(); flashywait(15); } for (i=0;i<40;i++) { if (kbhit()) { gwrite(x,y,'_',3); return getkey(); } flashywait(15); } } while (1); }
static void runtime_printbyte(int8 c) { Slice sl; sl.__values = &c; sl.__count = 1; sl.__capacity = 1; gwrite(sl); }
static void runtime_prints(const char *s) { Slice sl; // Use memcpy to avoid const-cast warning. memcpy(&sl.__values, &s, sizeof(char*)); sl.__count = runtime_findnull((const byte*)s); sl.__capacity = sl.__count; gwrite(sl); }
void writenum(Sint5 n,Sint4 x,Sint4 y,Sint4 w,Sint4 c) { Sint4 d,xp=(w-1)*12+x; while (w>0) { d=(Sint4)(n%10); if (w>1 || d>0) gwrite(xp,y,d+'0',c); n/=10; w--; xp-=12; } }
void runtime·printuint_c(uint64 v) { byte buf[100]; int32 i; for(i=nelem(buf)-1; i>0; i--) { buf[i] = v%10 + '0'; if(v < 10) break; v = v/10; } gwrite(buf+i, nelem(buf)-i); }
/* main (int argc, char *argv[]) { */ void gread_gwrite_test () { FILE *fp; char program[] = "gread_ewrite_test", filespc[] = "/data/petsun23/testx"; int i, n = N; float *x, *y; printf ("CPU_is_bigendian=%d\n", CPU_is_bigendian ()); if (!(x = (float *) malloc (n * sizeof (float)))) errm (program); if (!(y = (float *) malloc (n * sizeof (float)))) errm (program); for (i = 0; i < n; i++) { x[i] = -1. + 2.0*rand ()/(float) RAND_MAX; if (i < 20) printf ("%10d%10.4f\n", i, x[i]); } printf ("Writing: %s\n", filespc); fflush (stdout); if (!(fp = fopen (filespc, "wb"))) errw (program, filespc); if (gwrite ((char *) x, sizeof (float), n, fp, 'b') || fclose (fp)) errw (program, filespc); printf ("Reading: %s\n", filespc); fflush (stdout); if (!(fp = fopen (filespc, "rb"))) errr (program, filespc); if (gread ((char *) y, sizeof (float), n, fp, 1) || fclose (fp)) errr (program, filespc); if (0) for (i = 0; i < n; i++) printf ("%10f%10f\n", x[i], y[i]); for (i = 0; i < n; i++) assert (y[i] == x[i]); printf ("Writing: %s\n", filespc); fflush (stdout); if (!(fp = fopen (filespc, "wb"))) errw (program, filespc); if (gwrite ((char *) x, sizeof (float), n, fp, 'l') || fclose (fp)) errw (program, filespc); printf ("Reading: %s\n", filespc); fflush (stdout); if (!(fp = fopen (filespc, "rb"))) errr (program, filespc); if (gread ((char *) y, sizeof (float), n, fp, 0) || fclose (fp)) errr (program, filespc); if (0) for (i = 0; i < n; i++) printf ("%10f%10f\n", x[i], y[i]); for (i = 0; i < n; i++) assert (y[i] == x[i]); printf ("Done\n"); fflush (stdout); free (x); free (y); }
void runtime·printhex_c(uint64 v) { static int8 *dig = "0123456789abcdef"; byte buf[100]; int32 i; i=nelem(buf); for(; v>0; v/=16) buf[--i] = dig[v%16]; if(i == nelem(buf)) buf[--i] = '0'; buf[--i] = 'x'; buf[--i] = '0'; gwrite(buf+i, nelem(buf)-i); }
void getinitials(void) { Sint4 k,i; #ifdef _WINDOWS pause_windows_sound_playback(); #endif newframe(); outtext("ENTER YOUR",100,70,3); outtext(" INITIALS",100,90,3); outtext("_ _ _",128,130,3); strcpy(scoreinit[0],"..."); killsound(); for (i=0;i<3;i++) { k=0; while (k==0) { k=getinitial(i*24+128,130); if (k==8 || k==127) { if (i>0) i--; k=0; } } if (k!=0) { gwrite(i*24+128,130,k,3); scoreinit[0][i]=k; } } for (i=0;i<20;i++) #ifdef _WINDOWS flashywait(2); #else flashywait(15); #endif setupsound(); gclear(); gpal(0); ginten(0); setretr(TRUE); recputinit(scoreinit[0]); #ifdef _WINDOWS resume_windows_sound_playback(); #endif }
void runtime·prints(int8 *s) { gwrite(s, runtime·findnull((byte*)s)); }
// Very simple printf. Only for debugging prints. // Do not add to this without checking with Rob. static void go_vprintf(const char *s, va_list va) { const char *p, *lp; Slice sl; runtime_printlock(); lp = p = s; for(; *p; p++) { if(*p != '%') continue; if(p > lp) { // Use memcpy to avoid const-cast warning. memcpy(&sl.__values, &lp, sizeof(char*)); sl.__count = p - lp; sl.__capacity = p - lp; gwrite(sl); } p++; switch(*p) { case 'a': runtime_printslice(va_arg(va, Slice)); break; case 'c': runtime_printbyte(va_arg(va, int32)); break; case 'd': runtime_printint(va_arg(va, int32)); break; case 'D': runtime_printint(va_arg(va, int64)); break; case 'e': runtime_printeface(va_arg(va, Eface)); break; case 'f': runtime_printfloat(va_arg(va, float64)); break; case 'C': runtime_printcomplex(va_arg(va, complex double)); break; case 'i': runtime_printiface(va_arg(va, Iface)); break; case 'p': runtime_printpointer(va_arg(va, void*)); break; case 's': runtime_prints(va_arg(va, char*)); break; case 'S': runtime_printstring(va_arg(va, String)); break; case 't': runtime_printbool(va_arg(va, int)); break; case 'U': runtime_printuint(va_arg(va, uint64)); break; case 'x': runtime_printhex(va_arg(va, uint32)); break; case 'X': runtime_printhex(va_arg(va, uint64)); break; } lp = p+1; } if(p > lp) { // Use memcpy to avoid const-cast warning. memcpy(&sl.__values, &lp, sizeof(char*)); sl.__count = p - lp; sl.__capacity = p - lp; gwrite(sl); } runtime_printunlock(); }
void runtime·printnl(void) { gwrite("\n", 1); }
// Very simple printf. Only for debugging prints. // Do not add to this without checking with Rob. static void go_vprintf(const char *s, va_list va) { const char *p, *lp; //runtime_lock(&debuglock); lp = p = s; for(; *p; p++) { if(*p != '%') continue; if(p > lp) gwrite(lp, p-lp); p++; switch(*p) { case 'a': runtime_printslice(va_arg(va, Slice)); break; case 'c': runtime_printbyte(va_arg(va, int32)); break; case 'd': runtime_printint(va_arg(va, int32)); break; case 'D': runtime_printint(va_arg(va, int64)); break; case 'e': runtime_printeface(va_arg(va, Eface)); break; case 'f': runtime_printfloat(va_arg(va, float64)); break; case 'C': runtime_printcomplex(va_arg(va, complex double)); break; case 'i': runtime_printiface(va_arg(va, Iface)); break; case 'p': runtime_printpointer(va_arg(va, void*)); break; case 's': runtime_prints(va_arg(va, char*)); break; case 'S': runtime_printstring(va_arg(va, String)); break; case 't': runtime_printbool(va_arg(va, int)); break; case 'U': runtime_printuint(va_arg(va, uint64)); break; case 'x': runtime_printhex(va_arg(va, uint32)); break; case 'X': runtime_printhex(va_arg(va, uint64)); break; } lp = p+1; } if(p > lp) gwrite(lp, p-lp); //runtime_unlock(&debuglock); }
void runtime_prints(const char *s) { gwrite(s, runtime_findnull((const byte*)s)); }
void wrboard(void) { int l; static const char bl[] = "| | | |\n"; static const char sv[] = "| | | | \n"; fixtty(&noech); clear(); if (tflag) { fboard(); goto lastline; } writel("_____________________________________________________\n"); writel(bl); strcpy(ln, bl); for (j = 1; j < 50; j += 4) { k = j / 4 + (j > 24 ? 12 : 13); ln[j + 1] = k % 10 + '0'; ln[j] = k / 10 + '0'; if (j == 21) j += 4; } writel(ln); for (i = 0; i < 5; i++) { strcpy(ln, sv); for (j = 1; j < 50; j += 4) { k = j / 4 + (j > 24 ? 12 : 13); wrbsub(); if (j == 21) j += 4; } if (-board[25] > i) ln[26] = 'w'; if (-board[25] > i + 5) ln[25] = 'w'; if (-board[25] > i + 10) ln[27] = 'w'; l = 53; if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) { ln[54] = 'r'; l = 55; } if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) { ln[55] = 'r'; l = 56; } if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) { ln[56] = 'r'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; writel(ln); } strcpy(ln, bl); ln[25] = 'B'; ln[26] = 'A'; ln[27] = 'R'; writel(ln); strcpy(ln, sv); for (i = 4; i > -1; i--) { for (j = 1; j < 50; j += 4) { k = ((j > 24 ? 53 : 49) - j) / 4; wrbsub(); if (j == 21) j += 4; } if (board[0] > i) ln[26] = 'r'; if (board[0] > i + 5) ln[25] = 'r'; if (board[0] > i + 10) ln[27] = 'r'; l = 53; if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) { ln[54] = 'w'; l = 55; } if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) { ln[55] = 'w'; l = 56; } if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) { ln[56] = 'w'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; writel(ln); } strcpy(ln, bl); for (j = 1; j < 50; j += 4) { k = ((j > 24 ? 53 : 49) - j) / 4; ln[j + 1] = k % 10 + '0'; if (k > 9) ln[j] = k / 10 + '0'; if (j == 21) j += 4; } writel(ln); writel("|_______________________|___|_______________________|\n"); lastline: gwrite(); if (tflag) curmove(18, 0); else { writec('\n'); writec('\n'); } fixtty(&bg_raw); }
void runtime·printbyte_c(int8 c) { gwrite(&c, 1); }
void runtime·printfloat_c(float64 v) { byte buf[20]; int32 e, s, i, n; float64 h; if(ISNAN(v)) { gwrite("NaN", 3); return; } if(v == runtime·posinf) { gwrite("+Inf", 4); return; } if(v == runtime·neginf) { gwrite("-Inf", 4); return; } n = 7; // digits printed e = 0; // exp s = 0; // sign if(v == 0) { if(1/v == runtime·neginf) s = 1; } else { // sign if(v < 0) { v = -v; s = 1; } // normalize while(v >= 10) { e++; v /= 10; } while(v < 1) { e--; v *= 10; } // round h = 5; for(i=0; i<n; i++) h /= 10; v += h; if(v >= 10) { e++; v /= 10; } } // format +d.dddd+edd buf[0] = '+'; if(s) buf[0] = '-'; for(i=0; i<n; i++) { s = v; buf[i+2] = s+'0'; v -= s; v *= 10.; } buf[1] = buf[2]; buf[2] = '.'; buf[n+2] = 'e'; buf[n+3] = '+'; if(e < 0) { e = -e; buf[n+3] = '-'; } buf[n+4] = (e/100) + '0'; buf[n+5] = (e/10)%10 + '0'; buf[n+6] = (e%10) + '0'; gwrite(buf, n+7); }
void wrboard() { int l; static const char bl[] = "| | | |\n"; static const char sv[] = "| | | | \n"; clear(); fboard(); goto lastline; addstr("_____________________________________________________\n"); addstr(bl); strlcpy(ln, bl, sizeof ln); for (j = 1; j < 50; j += 4) { k = j / 4 + (j > 24 ? 12 : 13); ln[j + 1] = k % 10 + '0'; ln[j] = k / 10 + '0'; if (j == 21) j += 4; } addstr(ln); for (i = 0; i < 5; i++) { strlcpy(ln, sv, sizeof ln); for (j = 1; j < 50; j += 4) { k = j / 4 + (j > 24 ? 12 : 13); wrbsub(); if (j == 21) j += 4; } if (-board[25] > i) ln[26] = 'w'; if (-board[25] > i + 5) ln[25] = 'w'; if (-board[25] > i + 10) ln[27] = 'w'; l = 53; if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) { ln[54] = 'r'; l = 55; } if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) { ln[55] = 'r'; l = 56; } if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) { ln[56] = 'r'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; addstr(ln); } strlcpy(ln, bl, sizeof ln); ln[25] = 'B'; ln[26] = 'A'; ln[27] = 'R'; addstr(ln); strlcpy(ln, sv, sizeof ln); for (i = 4; i > -1; i--) { for (j = 1; j < 50; j += 4) { k = ((j > 24 ? 53 : 49) - j) / 4; wrbsub(); if (j == 21) j += 4; } if (board[0] > i) ln[26] = 'r'; if (board[0] > i + 5) ln[25] = 'r'; if (board[0] > i + 10) ln[27] = 'r'; l = 53; if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) { ln[54] = 'w'; l = 55; } if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) { ln[55] = 'w'; l = 56; } if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) { ln[56] = 'w'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; addstr(ln); } strlcpy(ln, bl, sizeof ln); for (j = 1; j < 50; j += 4) { k = ((j > 24 ? 53 : 49) - j) / 4; ln[j + 1] = k % 10 + '0'; if (k > 9) ln[j] = k / 10 + '0'; if (j == 21) j += 4; } addstr(ln); addstr("|_______________________|___|_______________________|\n"); lastline: gwrite(); move(18, 0); }
// Very simple printf. Only for debugging prints. // Do not add to this without checking with Rob. static void vprintf(int8 *s, byte *base) { int8 *p, *lp; uintptr arg, siz; byte *v; //runtime·lock(&debuglock); lp = p = s; arg = (uintptr)base; for(; *p; p++) { if(*p != '%') continue; if(p > lp) gwrite(lp, p-lp); p++; siz = 0; switch(*p) { case 't': case 'c': siz = 1; break; case 'd': // 32-bit case 'x': arg = ROUND(arg, 4); siz = 4; break; case 'D': // 64-bit case 'U': case 'X': case 'f': arg = ROUND(arg, sizeof(uintreg)); siz = 8; break; case 'C': arg = ROUND(arg, sizeof(uintreg)); siz = 16; break; case 'p': // pointer-sized case 's': arg = ROUND(arg, sizeof(uintptr)); siz = sizeof(uintptr); break; case 'S': // pointer-aligned but bigger arg = ROUND(arg, sizeof(uintptr)); siz = sizeof(String); break; case 'a': // pointer-aligned but bigger arg = ROUND(arg, sizeof(uintptr)); siz = sizeof(Slice); break; case 'i': // pointer-aligned but bigger case 'e': arg = ROUND(arg, sizeof(uintptr)); siz = sizeof(Eface); break; } v = (byte*)arg; switch(*p) { case 'a': runtime·printslice_c(*(Slice*)v); break; case 'c': runtime·printbyte_c(*(int8*)v); break; case 'd': runtime·printint_c(*(int32*)v); break; case 'D': runtime·printint_c(*(int64*)v); break; case 'e': runtime·printeface_c(*(Eface*)v); break; case 'f': runtime·printfloat_c(*(float64*)v); break; case 'C': runtime·printcomplex_c(*(Complex128*)v); break; case 'i': runtime·printiface_c(*(Iface*)v); break; case 'p': runtime·printpointer_c(*(void**)v); break; case 's': runtime·prints(*(int8**)v); break; case 'S': runtime·printstring_c(*(String*)v); break; case 't': runtime·printbool_c(*(bool*)v); break; case 'U': runtime·printuint_c(*(uint64*)v); break; case 'x': runtime·printhex_c(*(uint32*)v); break; case 'X': runtime·printhex_c(*(uint64*)v); break; } arg += siz; lp = p+1; } if(p > lp) gwrite(lp, p-lp); //runtime·unlock(&debuglock); }