/* * return a raw character from the input stream */ static inline int inpch(void) { do { if (ifiles->curptr < ifiles->maxread) return *ifiles->curptr++; } while (inpbuf() > 0); return -1; }
void Processor<sint, sgf2n>::write_shares_to_file(const vector<int>& data_registers) { string filename; filename = "Persistence/Transactions-P" + to_string(P.my_num()) + ".data"; unsigned int size = data_registers.size(); vector< sint > inpbuf (size); for (unsigned int i = 0; i < size; i++) { inpbuf[i] = get_Sp_ref(data_registers[i]); } binary_file_io.write_to_file(filename, inpbuf); }
/* * get a string or character constant and save it as given by d. */ struct iobuf * faststr(int bc, struct iobuf *ob) { struct iobuf *ib = ifiles->ib; int ch; if (ob == NULL) ob = getobuf(BNORMAL); instr = 1; putob(ob, bc); for (;;) { if (ib->bsz == ib->cptr) ch = qcchar(); else if (ISCQ(ch = ib->buf[ib->cptr])) ch = qcchar(); else ib->cptr++; switch (ch) { case '\\': putob(ob, ch); if (ib->cptr == ib->bsz) inpbuf(0); incmnt = 1; putob(ob, qcchar()); incmnt = 0; continue; case '\n': warning("unterminated literal"); instr = 0; unch(ch); return ob; } putob(ob, ch); if (ch == bc) break; } putob(ob, 0); ob->cptr--; instr = 0; return ob; }
/* * Scan quickly the input file searching for: * - '#' directives * - keywords (if not flslvl) * - comments * * Handle strings, numbers and trigraphs with care. * Only data from pp files are scanned here, never any rescans. * This loop is always at trulvl. */ void fastscan(void) { struct iobuf *ob, rbs, *rb = &rbs; extern struct iobuf pb; struct iobuf *ib = ifiles->ib; struct symtab *nl; int ch, c2; usch *dp; #define IDSIZE 128 rb->buf = xmalloc(IDSIZE+1); rb->cptr = 0; rb->bsz = IDSIZE; goto run; for (;;) { /* tight loop to find special chars */ /* should use getchar/putchar here */ for (;;) { if (ib->cptr < ib->bsz) ch = ib->buf[ib->cptr++]; else ch = qcchar(); xloop: if (ch < 0) ch = 0; /* XXX */ if ((spechr[ch] & C_SPEC) != 0) break; putch(ch); } switch (ch) { case 0: free(rb->buf); return; case WARN: case CONC: error("bad char passed"); break; case '/': /* Comments */ incmnt++; ch = qcchar(); incmnt--; if (ch == '/' || ch == '*') { if (Cflag == 0) { int n = ifiles->lineno; fastcmnt2(ch); if (n == ifiles->lineno) putch(' '); /* 5.1.1.2 p3 */ } else Ccmnt2(&pb, ch); } else { putch('/'); goto xloop; } break; case '\n': /* newlines, for pp directives */ /* take care of leftover \n */ while (ifiles->escln > 0) { putch('\n'); ifiles->escln--; ifiles->lineno++; } putch('\n'); ifiles->lineno++; /* search for a # */ run: while ((ch = qcchar()) == '\t' || ch == ' ') putch(ch); if (ch == '%') { if ((c2 = qcchar()) != ':') unch(c2); else ch = '#'; } if (ch == '#') ppdir(); else goto xloop; break; case '?': if (ib->cptr+1 >= ib->bsz) inpbuf(2); if (ib->buf[ib->cptr] == '?') { ib->cptr++; if ((ch = chktg2(ib->buf[ib->cptr++]))) goto xloop; ib->cptr -= 2; } putch('?'); break; case '\'': /* character constant */ if (tflag) { putch(ch); break; /* character constants ignored */ } /* FALLTHROUGH */ case '\"': /* strings */ if (skpows) cntline(); faststr(ch, &pb); break; case '.': /* for pp-number */ if ((spechr[c2 = qcchar()] & C_DIGIT) == 0) { putch('.'); goto xloop; } unch(c2); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (skpows) cntline(); ch = fastnum(ch, &pb); goto xloop; case 'L': case 'U': case 'u': if (ib->cptr+2 >= ib->bsz) inpbuf(2); if ((c2 = ib->buf[ib->cptr]) == '\"' || c2 == '\'') { putch(ch); break; } else if (c2 == '8' && ch == 'u' && ib->buf[ib->cptr+1] == '\"') { ib->cptr++; putstr((usch *)"u8"); break; } /* FALLTHROUGH */ default: #ifdef PCC_DEBUG if ((spechr[ch] & C_ID) == 0) error("fastscan"); #endif if (flslvl) error("fastscan flslvl"); rb->cptr = 0; dp = bufid(ch, rb); if ((nl = lookup(dp, FIND)) != NULL) { if ((ob = kfind(nl)) != NULL) { if (*ob->buf == '-' || *ob->buf == '+') putch(' '); if (skpows) cntline(); buftobuf(ob, &pb); if (ob->cptr > 0 && (ob->buf[ob->cptr-1] == '-' || ob->buf[ob->cptr-1] == '+')) putch(' '); bufree(ob); } } else { putstr(dp); } break; case '\\': ib->buf[--ib->cptr] = '\\'; if ((ch = qcchar()) != '\\') goto xloop; putch('\\'); break; } } }
/* * Return a quick-cooked character. * If buffer empty; return 0. */ static int qcchar(void) { struct iobuf *ib = ifiles->ib; int ch; newone: do { if (ib->cptr < ib->bsz) { if (!ISCQ(ch = ib->buf[ib->cptr++])) return ch; break; } } while ((ch = inpbuf(0)) > 0); switch (ch) { case 0: return 0; /* end of file */ case '\r': goto newone; case '\\': if (ib->cptr == ib->bsz) inpbuf(0); switch (ch = ib->buf[ib->cptr]) { case 'u': case 'U': if (incmnt) return '\\'; ib->cptr++; ucn(ch == 'u' ? 4 : 8); break; case '\r': ib->cptr++; if (ib->cptr == ib->bsz) inpbuf(0); /* FALLTHROUGH */ case '\n': ib->cptr++; ifiles->escln++; break; default: return '\\'; } goto newone; case '?': inpbuf(2); if (ib->buf[ib->cptr] == '?') { if ((ch = chktg2(ib->buf[ib->cptr+1])) == 0) return '?'; ib->buf[++ib->cptr] = ch; goto newone; } return '?'; case '/': if (Cflag || incmnt || instr) return '/'; incmnt++; ch = qcchar(); incmnt--; if (ch == '/' || ch == '*') { int n = ifiles->lineno; fastcmnt2(ch); if (n == ifiles->lineno) return ' '; } else { ib->buf[--ib->cptr] = ch; return '/'; } goto newone; } error("ch error"); return 0; /* XXX */ }