void tdraw(const char *s, size_t nmemb, int start, int stop) { twrite(s, start); tputs(T_ENTER_STANDOUT_MODE); twrite(s + start, stop - start + 1); tputs(T_EXIT_STANDOUT_MODE); twrite(s + stop + 1, nmemb - stop); }
void GlobalGrid::write( std::ofstream &ofs ) const{ // write the grid to a file ofs << "num_dimensions: " << num_dimensions << endl; ofs << "num_outputs: " << num_outputs << endl; ofs << "alpha: "; twrite( 1, &alpha, ofs ); ofs << "beta: "; twrite( 1, &beta, ofs ); ofs << "ruleType: "; if ( ruleType == rule_chebyshev ){ ofs << "lagrange-chebyshev"; }else if ( ruleType == rule_clenshawcurtis ){ ofs << "lagrange-clenshaw-curtis"; }else if ( ruleType == rule_gausslegendre ){ ofs << "lagrange-gauss-legendre"; }else if ( ruleType == rule_gausschebyshev1 ){ ofs << "lagrange-gauss-chebyshev1"; }else if ( ruleType == rule_gausschebyshev2 ){ ofs << "lagrange-gauss-chebyshev2"; }else if ( ruleType == rule_fejer2 ){ ofs << "lagrange-fejer2"; }else if ( ruleType == rule_gaussgegenbauer ){ ofs << "lagrange-gauss-gegenbauer"; }else if ( ruleType == rule_chebyshevN2P ){ ofs << "lagrange-chebyshev-nested-twopoint"; }else if ( ruleType == rule_gaussgegenbauer ){ ofs << "lagrange-gauss-gegenbauer"; }else if ( ruleType == rule_gaussjacobi ){ ofs << "lagrange-gauss-jacobi"; }else if ( ruleType == rule_gausslaguerre ){ ofs << "lagrange-gauss-laguerre"; }else if ( ruleType == rule_gausshermite ){ ofs << "lagrange-gauss-hermite"; }else if ( ruleType == rule_base ){ ofs << "empty-rule"; } ofs << endl; ofs << "Anisotropic: "; if ( anisotropic != 0 ){ ofs << "yes" << endl; twrite( num_dimensions+1, anisotropic, ofs ); }else{ ofs << "no" << endl; } ofs << "Tensors: "; if ( tensorList != 0 ){ ofs << "yes" << endl; tensorList->write( ofs ); }else{ ofs << "no" << endl; } ofs << "TensorWeights: "; if ( tensor_weights != 0 ){ ofs << "yes" << endl; twrite( tensorList->getNumIndexes(), tensor_weights, ofs ); }else{ ofs << "no" << endl; } ofs << "Points: "; if ( tensor_weights != 0 ){ ofs << "yes" << endl; points->write( ofs ); }else{ ofs << "no" << endl; } ofs << "NeededPoints: "; if ( needed_points == 0 ){ ofs << "no" << endl; }else{ ofs << "yes" << endl; needed_points->write( ofs ); } }
void mswait (void) { struct stat buf; static char *mbox = NULL; static int first = SE_YES; static unsigned long mtime = 0L; if (! Notify) return; if (first) { first = SE_NO; if ((mbox = getenv ("MAIL")) != NULL && access (mbox, 4) == 0) { if (stat (mbox, &buf) >= 0) { mtime = buf.st_mtime; if (buf.st_size > 0) remark ("You have mail"); } } } else if (mbox && stat (mbox, &buf) >= 0 && buf.st_mtime > mtime) { mtime = buf.st_mtime; remark ("You have new mail"); twrite (1, "\007", 1); /* Bell */ } }
void tputs(const char *s) { size_t n = strlen(s); twrite(s, n); }
rt_public int app_twrite(const void *buffer, size_t size) { /* Write 'size' bytes held in 'buffer' into the "pipe". Return the number * of bytes effectively written or -1 if an error occurred. */ return twrite(app_sp, buffer, size); }
/* read travel table */ static void rtrav(void) { int locc; struct travlist *t; char *s; char buf[12]; int len, m, n, entries; entries = 0; t = NULL; for (oldloc = -1;;) { /* get another line */ /* end of entry */ if ((locc = rnum()) != oldloc && oldloc >= 0) { t->next = 0; /* terminate the old entry */ #if DEBUG printf("%d:%d entries\n", oldloc, entries); twrite(oldloc); #endif } if (locc == -1) return; if (locc != oldloc) { /* getting a new entry */ t = travel[locc] = malloc(sizeof(*t)); if (t == NULL) errx(1, "Out of memory!"); /* printf("New travel list for %d\n", locc); */ entries = 0; oldloc = locc; } for (s = buf;; s++) /* get the newloc number /ASCII */ if ((*s = next()) == TAB || *s == LF) break; *s = 0; len = strlen(buf); /* quad long number handling */ /* printf("Newloc: %s (%d chars)\n", buf, len); */ if (len < 4) { /* no "m" conditions */ m = 0; n = atoi(buf); /* newloc mod 1000 = newloc */ } else { /* a long integer */ n = atoi(buf + len - 3); buf[len - 3] = 0; /* terminate newloc/1000 */ m = atoi(buf); } while (breakch != LF) { /* only do one line at a time */ if (entries++) { t = t->next = malloc(sizeof(*t)); if (t == NULL) errx(1, "Out of memory!"); } t->tverb = rnum(); /* get verb from the file */ t->tloc = n; /* table entry mod 1000 */ t->conditions = m; /* table entry / 1000 */ /* printf("entry %d for %d\n", entries, locc); */ } } }
void tprintf(const char *format, int x) { char s[32]; int n; n = snprintf(s, sizeof(s), format, x); twrite(s, n); }
void tmain(void) { size_t start, stop, t; char c; start = stop = 0; if (field(in.v, 1, &start, &stop)) tdraw(in.v, in.pmemb, start, stop); else twrite(in.v, in.pmemb); for (;;) { if (read(tty.in, &c, 1) < 0) perror("read"); switch (c) { case '\n': sel.nmemb = stop - start + 1; sel.v = in.v + start; /* FALLTHROUGH */ case CONTROL('C'): case CONTROL('D'): return; case CONTROL('A'): t = 0; /* FALLTHROUGH */ if (0) { case CONTROL('N'): t = stop + rune(in.v, stop, 1); } if (!field(in.v, 1, &t, &stop)) continue; start = t; break; case CONTROL('E'): t = in.pmemb - 1; /* FALLTHROUGH */ if (0) { case CONTROL('P'): t = start + rune(in.v, start, -1); } if (!field(in.v, -1, &t, &start)) continue; stop = t; break; default: continue; } if (in.nlines) tprintf(T_CURSOR_UP, in.nlines); tprintf(T_COLUMN_ADDRESS, 1); tdraw(in.v, in.pmemb, start, stop); } }
static void from_data_new(struct tor_conn *tc) { int from, to, amnt; char *buf; from = tc->from; to = tc->to; while (1) { int ret; cbuf_t cb; buf = cbuf_alloc(BUFF_SZ, &cb); assert(buf); amnt = from_tread(cos_spd_id(), from, cb, BUFF_SZ-1); if (0 == amnt) break; else if (-EPIPE == amnt) { goto close; } else if (amnt < 0) { printc("read from fd %d produced %d.\n", from, amnt); BUG(); } assert(amnt <= BUFF_SZ); if (amnt != (ret = twrite(cos_spd_id(), to, cb, amnt))) { printc("conn_mgr: write failed w/ %d on fd %d\n", ret, to); goto close; } cbuf_free(buf); } done: cbuf_free(buf); return; close: mapping_remove(from, to, tc->feid, tc->teid); from_trelease(cos_spd_id(), from); trelease(cos_spd_id(), to); assert(tc->feid && tc->teid); evt_put(tc->feid); evt_put(tc->teid); goto done; }
/* * Assumes pipe is buffered at least 257 characters, * so both sides can send and then receive. */ int banner(Replica *r, char *name) { int i; char c, *p; char buf[257]; dbg(DbgRpc, "sending tracmd\n"); qlock(&r->rlock); qlock(&r->wlock); /* both sides send tracmd */ if(twrite(r->wfd, tracmd, sizeof tracmd-1) < 0 || twflush(r->wfd) == -1){ werrstr("writing banner: %r"); err: qunlock(&r->wlock); qunlock(&r->rlock); return -1; } dbg(DbgRpc, "waiting for tracmd\n"); while((p = rdln(r->rfd)) != nil){ if(strcmp(tracmd, p) == 0) break; if(name) fprint(2, "%s# %s", name, p); } if(p == nil){ werrstr("did not receive initial banner"); goto err; } dbg(DbgRpc, "sending antissh\n"); /* both sides send \n~?\n~.\n */ if(twrite(r->wfd, antissh, sizeof antissh-1) < 0 || twflush(r->wfd) == -1){ werrstr("writing antissh: %r"); goto err; } dbg(DbgRpc, "waiting for antissh\n"); if(readln(r->rfd, "\n")<0 || readln(r->rfd, "~?\n")<0 || readln(r->rfd, "~.\n") < 0){ werrstr("corrupt anti-ssh banner"); goto err; } dbg(DbgRpc, "sending byte map\n"); /* both sides send 0x00, 0x01, ..., 0xFF, 0x00 */ /* the second 0x00 gives us a way to notice 0xFF being dropped */ for(i=0; i<257; i++) buf[i] = i; if(twrite(r->wfd, buf, sizeof buf) < 0 || twflush(r->wfd) == -1){ werrstr("short channel test write: %r"); goto err; } dbg(DbgRpc, "receiving byte map\n"); /* could be more efficient but doesn't matter */ for(i=0; i < sizeof buf; i++){ if(tread(r->rfd, &c, 1) != 1){ werrstr("8-bit test: expected 0x%x, got eof", buf[i]); goto err; } if(c != buf[i]){ werrstr("8-bit test: expected 0x%x, got 0x%x", buf[i], c); goto err; } } //fprint(2, "%s: pass\n", argv0); qunlock(&r->wlock); qunlock(&r->rlock); return 0; }
static const struct field * tmain(void) { size_t n; int c, i, j, k; i = j = 0; n = f.v[f.nmemb].lo; for (;;) { tputs(T_RESTORE_CURSOR); if (f.nmemb > 0) { twrite(in.v, f.v[i].so); tputs(T_ENTER_STANDOUT_MODE); twrite(in.v + f.v[i].so, f.v[i].eo - f.v[i].so + 1); tputs(T_EXIT_STANDOUT_MODE); twrite(in.v + f.v[i].eo + 1, n - f.v[i].eo); } else { twrite(in.v, n); } c = tgetc(); switch (c) { case KEY_ENTER: if (f.nmemb > 0) return &f.v[i]; break; case KEY_TERM: return NULL; case KEY_HOME: j = 0; break; case KEY_RIGHT: j = i + 1; break; case KEY_END: j = f.nmemb - 1; break; case KEY_LEFT: j = i - 1; break; case KEY_DOWN: j = i; while (j < (ssize_t)f.nmemb && f.v[i].lo == f.v[j].lo) j++; if (j == (ssize_t)f.nmemb) break; /* FALLTHROUGH */ if (0) { case KEY_UP: k = i; while (k && f.v[i].lo == f.v[k].lo) k--; j = k; while (j && f.v[j - 1].lo == f.v[k].lo) j--; } for (; fcmp(&f.v[i], &f.v[j]) < 0 && f.v[j].lo == f.v[j + 1].lo; j++) /* NOP */; break; } if (j >= 0 && j < (ssize_t)f.nmemb) i = j; } }