// We get here when we get affirmations from muds we are sending // mail packets to. void incoming_request( mapping info ) { int flag; flag = 0; if( !info["NAME"] || !info["PORTUDP"] ) return; if( info["ENDMSG"] ) { // We've received an acknowledgement of an ENDMSG..meaning, they // affirm that they got the last part of a message we sent them. // We pop it off the stack. if( !NETMAIL_D -> pop_mud( info["NAME"] ) ) { // Hmm..there apparently was nothing on the stack, yet we got // affirmation of an ENDMSG...log this. log_file( "mail_a", "unexpected mail_a from " + info["NAME"] + "\n" ); return; } TELL( "MAILA: Popped " + info["NAME"] + "." ); flag = 2; } else { if( info["RESEND"] ) { // They want us to resend the current message, because either // too much time has passed since the last received packet, or // some fields got messed up along the way. TELL( "MAILA: Got RESEND." ); flag = 1; } } // Let mail_q know that we are ready to either send a new message, // or resend the current one. MAIL_Q -> check_for_mail( info["NAME"], flag ); }
TraceContainerReader::TraceContainerReader(std::string filename) throw (TraceException) { ifs = fopen(filename.c_str(), "rb"); if (!ifs) { throw (TraceException("Unable to open trace for reading")); } /* Verify the magic number. */ uint64_t magic_number_read; READ(magic_number_read); if (magic_number_read != magic_number) { throw (TraceException("Magic number not found in trace")); } READ(trace_version); if (trace_version > highest_supported_version || trace_version < lowest_supported_version) { throw (TraceException("Unsupported trace version")); } uint64_t archt; READ(archt); arch = (bfd_architecture) archt; READ(mach); /* Read number of trace frames. */ READ(num_frames); /* Find offset of toc. */ uint64_t toc_offset; READ(toc_offset); /* Find the toc. */ SEEK(ifs, toc_offset); /* Read number of frames per toc entry. */ READ(frames_per_toc_entry); /* Read each toc entry. */ for (int i = 0; i < ((num_frames - 1) / frames_per_toc_entry); i++) { uint64_t offset; READ(offset); toc.push_back(offset); } /* We should be at the end of the file now. */ traceoff_t us = TELL(ifs); traceoff_t end = SEEKNAME(ifs, 0, SEEK_END); if (us != TELL(ifs) || end != 0) { throw(TraceException("The table of contents is malformed.")); } /* Seek to the first frame. */ seek(0); }
std::auto_ptr<frame> TraceContainerReader::get_frame(void) throw (TraceException) { /* Make sure we are in bounds. */ check_end_of_trace("get_frame() on non-existant frame"); uint64_t frame_len; READ(frame_len); if (frame_len == 0) { throw (TraceException("Read zero-length frame at offset " + TELL(ifs))); } /* We really just want a variable sized array, but MS VC++ doesn't support C99 yet. * * http://stackoverflow.com/questions/5246900/enabling-vlasvariable-length-arrays-in-ms-visual-c */ auto_vec<char> buf ( new char[frame_len] ); /* Read the frame into buf. */ if (fread(buf.get(), 1, frame_len, ifs) != frame_len) { throw (TraceException("Unable to read frame from trace")); } std::string sbuf(buf.get(), frame_len); std::auto_ptr<frame> f(new frame); if (!(f->ParseFromString(sbuf))) { throw (TraceException("Unable to parse from string")); } current_frame++; return f; }
void move_em( string f, string dir ) { string x, y; x = MESGDIR + dir + "/" + f ; y = mail_mesg_file( f ) + __SAVE_EXTENSION__; TELL( "Moving: " + x + " to " + y ); rename( x, y ); }
void TraceContainerWriter::finish(void) throw (TraceException) { if (is_finished) { throw (TraceException("finish called twice")); } /* Save the offset where we will write the toc. */ uint64_t toc_offset = TELL(ofs); if (toc_offset == -1) { throw (TraceException("Unable to determine the current offset in the trace")); } /* Make sure the toc is the right size. */ assert ((num_frames == 0) || ((num_frames - 1) / frames_per_toc_entry) == toc.size()); /* Write frames per toc entry. */ WRITE(frames_per_toc_entry); /* Write each offset to the file. */ for (std::vector<uint64_t>::size_type i = 0; i < toc.size(); i++) { WRITE(toc[i]); } /* Now we need to write the magic number, number of trace frames and the offset of field m at the start of the trace. */ /* Magic number. */ SEEK(ofs, magic_number_offset); WRITE(magic_number); /* Trace version. */ SEEK(ofs, trace_version_offset); WRITE(out_trace_version); /* CPU architecture. */ SEEK(ofs, bfd_arch_offset); uint64_t archt = (uint64_t) arch; WRITE(archt); /* Machine type. */ SEEK(ofs, bfd_machine_offset); WRITE(mach); /* Numer of trace frames */ SEEK(ofs, num_trace_frames_offset); WRITE(num_frames); /* Offset of toc. */ SEEK(ofs, toc_offset_offset); WRITE(toc_offset); /* Finally, close the file and mark us as finished. */ if (fclose(ofs)) { throw (TraceException("Unable to close trace file")); } is_finished = true; }
int pop_mud( string mudname ) { init_queue(); if( !file_exists( SAVE_FILE( mudname ) + SAVE_EXTENSION ) ) return 0; if( !restore_object( SAVE_FILE( mudname ) ) ) { rm( SAVE_FILE( mudname ) + SAVE_EXTENSION ); return 0; } if( !out_queue ) init_queue(); TELL( sizeof(out_queue) ); out_queue = out_queue[1..<1]; TELL(sizeof(out_queue ) ); if( !sizeof( out_queue ) ) rm( SAVE_FILE( mudname ) + SAVE_EXTENSION ); else save_object( SAVE_FILE( mudname ) ); return 1; }
void TraceContainerWriter::add(frame &f) throw (TraceException) { /* Is is time for a toc entry? */ if (num_frames > 0 && (num_frames % frames_per_toc_entry) == 0) { /* Yes. Add the file offset where we will insert this frame to toc. */ toc.push_back(TELL(ofs)); } num_frames++; /* Serialize to string so we can get the length. */ std::string s; if (!(f.SerializeToString(&s))) { throw (TraceException("Unable to serialize frame to ostream")); } /* Write the length before the frame. */ uint64_t len = s.length(); if (len == 0) { throw (TraceException("Attempt to add zero-length frame to trace")); } WRITE(len); /* Write the frame. */ traceoff_t old_offset = TELL(ofs); if (old_offset == -1) { throw (TraceException("Unable to determine the current offset in the trace")); } if (fwrite(s.c_str(), 1, len, ofs) != len) { throw (TraceException("Unable to write frame to trace file")); } /* Double-check our size. */ assert ((uint64_t)old_offset + len == (uint64_t)TELL(ofs)); }
/* * See if the specified file exists. If so, verify that it is indeed a file. */ static time_t is_a_file(char *name, mode_t * mode_) { Stat_t sb; if (stat(name, &sb) >= 0) { if ((sb.st_mode & S_IFMT) == S_IFREG) { if (mode_) /* save executable-status */ *mode_ = sb.st_mode & 0555; return (sb.st_mtime); } else { TELL("?? \"%s\" is not a file\n", name); (void) exit(FAIL); /*NOTREACHED */ } } return (0); }
void MMFXRead(LongN start, Card32 length) { IntX i; Card32 lenstr; if (loaded) return; MMFX = (MMFXTbl *)memNew(sizeof(MMFXTbl)); SEEK_ABS(start); IN1(MMFX->version); IN1(MMFX->nMetrics); IN1(MMFX->offSize); MMFX->offset = memNew(sizeof(Int32) * (MMFX->nMetrics + 1)); for (i = 0; i < MMFX->nMetrics; i++) { if (MMFX->offSize == 2) { Int16 tmp; IN1(tmp); MMFX->offset[i] = tmp; } else { IN1(MMFX->offset[i]); } if (MMFX->offset[i] < (Int32)minoffset) minoffset = MMFX->offset[i]; if (MMFX->offset[i] > (Int32)maxoffset) maxoffset = MMFX->offset[i]; } lenstr = (start + length) - TELL(); MMFX->offset[MMFX->nMetrics] = lenstr + 1; MMFX->cstrs = memNew(sizeof(Card8) * (lenstr + 1)); SEEK_ABS(start + minoffset); IN_BYTES(lenstr, MMFX->cstrs); loaded = 1; }
void TraceContainerReader::seek(uint64_t frame_number) throw (TraceException) { /* First, make sure the frame is in range. */ check_end_of_trace_num(frame_number, "seek() to non-existant frame"); /* Find the closest toc entry, if any. */ uint64_t toc_number = frame_number / frames_per_toc_entry; if (toc_number == 0) { current_frame = 0; SEEK(ifs, first_frame_offset); } else { current_frame = toc_number * frames_per_toc_entry; /* Use toc_number - 1 because there is no toc for frames [0,m). */ SEEK(ifs, toc[toc_number - 1]); } while (current_frame != frame_number) { /* Read frame length and skip that far ahead. */ uint64_t frame_len; READ(frame_len); SEEK(ifs, (uint64_t)TELL(ifs) + frame_len); current_frame++; } }
/* Read Type 13 charstring. Initial seek to offset performed if offset != -1 */ static void t13Read(cffCtx h, Offset offset, int init, int csLen) { unsigned length; switch (init) { case cstr_GLYPH: /* Initialize glyph charstring */ h->stack.cnt = 0; h->path.nStems = 0; h->path.flags = GET_WIDTH|FIRST_MOVE|FIRST_MASK; break; case cstr_DICT: /* Initialize DICT charstring */ h->path.flags = DICT_CSTR; break; case cstr_METRIC: /* Initialize metric charstring */ h->stack.cnt = 0; h->path.flags = 0; break; } if (offset != -1) /* Seek to position of charstring if not already positioned */ seekbyte(h, offset); for (;;) { int j; Fixed a; Fixed b; int byte0 = GETBYTE(h); switch (byte0) { case t13_endchar: if (!(h->path.flags & DICT_CSTR)) { if (h->path.flags & FIRST_MOVE) { /* Non-marking glyph; set bounds */ h->path.left = h->path.right = 0; h->path.bottom = h->path.top = 0; } if ((h->path.flags & GET_WIDTH) && setAdvance(h)) return; /* Stop after getting width */ if (h->stack.cnt > 1) { /* Process seac components */ int base; int accent; j = (h->stack.cnt == 4)? 0: 1; a = indexFix(h, j++); b = indexFix(h, j++); base = indexInt(h, j++); accent = indexInt(h, j); setComponentBounds(h, 0, base, 0, 0); setComponentBounds(h, 1, accent, a, b); } } PATH_FUNC_CALL(endchar,(h->cb.ctx)); h->path.flags |= SEEN_END; return; case t13_reserved0: case t13_reserved236: case t13_reserved237: case t13_reserved244: case t13_reserved255: fatal(h, "reserved charstring op"); case t13_rlineto: for (j = 0; j < h->stack.cnt; j += 2) addLine(h, indexFix(h, j + 0), indexFix(h, j + 1)); h->stack.cnt = 0; break; case t13_hlineto: case t13_vlineto: { int horz = byte0 == t13_hlineto; for (j = 0; j < h->stack.cnt; j++) if (horz++ & 1) addLine(h, indexFix(h, j), 0); else addLine(h, 0, indexFix(h, j)); } h->stack.cnt = 0; break; case t13_rrcurveto: for (j = 0; j < h->stack.cnt; j += 6) addCurve(h, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), indexFix(h, j + 4), indexFix(h, j + 5)); h->stack.cnt = 0; break; case t13_callsubr: { Offset save = TELL(h); Offset localOffset = INDEXGet(h, &h->index.Subrs, popInt(h) + h->index.Subrs.bias, &length); t13Read(h, localOffset, cstr_NONE, length); if (h->path.flags & SEEN_END) return; /* endchar operator terminated subr */ seekbyte(h, save); } break; case t13_return: return; case t13_rcurveline: for (j = 0; j < h->stack.cnt - 2; j += 6) addCurve(h, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), indexFix(h, j + 4), indexFix(h, j + 5)); addLine(h, indexFix(h, j + 0), indexFix(h, j + 1)); h->stack.cnt = 0; break; case t13_rlinecurve: for (j = 0; j < h->stack.cnt - 6; j += 2) addLine(h, indexFix(h, j + 0), indexFix(h, j + 1)); addCurve(h, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), indexFix(h, j + 4), indexFix(h, j + 5)); h->stack.cnt = 0; break; case t13_vvcurveto: if (h->stack.cnt & 1) { /* Add initial curve */ addCurve(h, 0, indexFix(h, 0), indexFix(h, 1), indexFix(h, 2), indexFix(h, 3), 0, indexFix(h, 4)); j = 5; } else j = 0; /* Add remaining curve(s) */ for (; j < h->stack.cnt; j += 4) addCurve(h, 0, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), 0, indexFix(h, j + 3)); h->stack.cnt = 0; break; case t13_hhcurveto: if (h->stack.cnt & 1) { /* Add initial curve */ addCurve(h, 0, indexFix(h, 1), indexFix(h, 0), indexFix(h, 2), indexFix(h, 3), indexFix(h, 4), 0); j = 5; } else j = 0; /* Add remaining curve(s) */ for (; j < h->stack.cnt; j += 4) addCurve(h, 0, indexFix(h, j + 0), 0, indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), 0); h->stack.cnt = 0; break; case t13_callgsubr: { Offset save = TELL(h); Offset localOffset = INDEXGet(h, &h->index.global, popInt(h) + h->index.global.bias, &length); t13Read(h, localOffset, cstr_NONE, length); if (h->path.flags & SEEN_END) return; /* endchar operator terminated subr */ seekbyte(h, save); } break; case t13_vhcurveto: case t13_hvcurveto: { int adjust = (h->stack.cnt & 1)? 5: 0; int horz = byte0 == t13_hvcurveto; /* Add initial curve(s) */ for (j = 0; j < h->stack.cnt - adjust; j += 4) if (horz++ & 1) addCurve(h, 0, indexFix(h, j + 0), 0, indexFix(h, j + 1), indexFix(h, j + 2), 0, indexFix(h, j + 3)); else addCurve(h, 0, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), 0); if (j < h->stack.cnt) { /* Add last curve */ if (horz & 1) addCurve(h, 0, indexFix(h, j + 0), 0, indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 4), indexFix(h, j + 3)); else addCurve(h, 0, 0, indexFix(h, j + 0), indexFix(h, j + 1), indexFix(h, j + 2), indexFix(h, j + 3), indexFix(h, j + 4)); } h->stack.cnt = 0; } break; case t13_rmoveto: b = popFix(h); a = popFix(h); if (addMove(h, a, b)) return; /* Stop after getting width */ h->stack.cnt = 0; break; case t13_hmoveto: if (addMove(h, popFix(h), 0)) return; /* Stop after getting width */ h->stack.cnt = 0; break; case t13_vmoveto: if (addMove(h, 0, popFix(h))) return; /* Stop after getting width */ h->stack.cnt = 0; break; case t13_hstem: case t13_vstem: case t13_hstemhm: case t13_vstemhm: if ((h->path.flags & GET_WIDTH) && setAdvance(h)) return; /* Stop after getting width */ h->path.nStems += h->stack.cnt / 2; if (PATH_FUNC_DEFINED(hintstem)) { int vert = byte0 == tx_vstem || byte0 == t2_vstemhm; b = vert? h->path.vstem: h->path.hstem; for (j = h->stack.cnt & 1; j < h->stack.cnt; j += 2) { a = b + indexFix(h, j); b = a + indexFix(h, j + 1); h->path.cb->hintstem(h->cb.ctx, vert, a, b); } if (vert) h->path.vstem = b; else h->path.hstem = b; } h->stack.cnt = 0; break; case t13_hintmask: case t13_cntrmask: { int cnt; if (h->path.flags & FIRST_MASK) { /* The vstem(hm) op may be omitted if stem list is followed by a mask op. In this case count the additional stems */ if (PATH_FUNC_DEFINED(hintstem)) { b = h->path.vstem; for (j = h->stack.cnt & 1; j < h->stack.cnt; j += 2) { a = b + indexFix(h, j); b = a + indexFix(h, j + 1); h->path.cb->hintstem(h->cb.ctx, 1, a, b); } } h->path.nStems += h->stack.cnt / 2; h->stack.cnt = 0; h->path.flags &= ~FIRST_MASK; } cnt = (h->path.nStems + 7) / 8; if (PATH_FUNC_DEFINED(hintmask)) { char mask[CFF_MAX_MASK_BYTES]; for (j = 0; j < cnt; j++) mask[j] = GETBYTE(h); h->path.cb->hintmask(h->cb.ctx, byte0 == t2_cntrmask, cnt, mask); } else while (cnt--) (void)GETBYTE(h); /* Discard mask bytes */ } break; case t13_escape: { double x; double y; switch (t13_ESC(GETBYTE(h))) { case t13_dotsection: break; default: case t13_reservedESC255: case t13_cntron: fatal(h, "reserved charstring op"); case t13_and: b = popFix(h); a = popFix(h); pushInt(h, a && b); break; case t13_or: b = popFix(h); a = popFix(h); pushInt(h, a || b); break; case t13_not: a = popFix(h); pushInt(h, !a); break; case t13_store: { int count = popInt(h); int i = popInt(h); int j = popInt(h); int iReg = popInt(h); int regSize; Fixed *reg = selRegItem(h, iReg, ®Size); if (i < 0 || i + count - 1 >= h->BCA.size || j < 0 || j + count - 1 >= regSize) fatal(h, "bounds check (store)\n"); memcpy(®[j], &h->BCA.array[i], sizeof(Fixed) * count); } break; case t13_abs: a = popFix(h); pushFix(h, (a < 0)? -a: a); break; case t13_add: b = popFix(h); a = popFix(h); pushFix(h, a + b); break; case t13_sub: b = popFix(h); a = popFix(h); pushFix(h, a - b); break; case t13_div: y = popDbl(h); x = popDbl(h); if (y == 0.0) fatal(h, "divide by zero (div)"); pushFix(h, DBL2FIX(x / y)); break; case t13_load: { int regSize; int count = popInt(h); int i = popInt(h); int iReg = popInt(h); Fixed *reg = selRegItem(h, iReg, ®Size); if (i < 0 || i + count - 1 >= h->BCA.size || count > regSize) fatal(h, "bounds check (load)\n"); memcpy(&h->BCA.array[i], reg, sizeof(Fixed) * count); } break; case t13_neg: a = popFix(h); pushFix(h, -a); break; case t13_eq: b = popFix(h); a = popFix(h); pushInt(h, a == b); break; case t13_drop: (void)popFix(h); break; case t13_put: { int i = popInt(h); if (i < 0 || i >= h->BCA.size) fatal(h, "bounds check (put)\n"); h->BCA.array[i] = popFix(h); } break; case t13_get: { int i = popInt(h); if (i < 0 || i >= h->BCA.size) fatal(h, "bounds check (get)\n"); pushFix(h, h->BCA.array[i]); } break; case t13_ifelse: { Fixed v2 = popFix(h); Fixed v1 = popFix(h); Fixed s2 = popFix(h); Fixed s1 = popFix(h); pushFix(h, (v1 > v2)? s2: s1); } break; case t13_random: pushFix(h, PMRand()); break; case t13_mul: y = popDbl(h); x = popDbl(h); pushFix(h, DBL2FIX(x * y)); break; case t13_sqrt: pushFix(h, FixedSqrt(popFix(h))); break; case t13_dup: pushFix(h, h->stack.array[h->stack.cnt - 1].f); break; case t13_exch: b = popFix(h); a = popFix(h); pushFix(h, b); pushFix(h, a); break; case t13_index: { int i = popInt(h); if (i < 0) i = 0; /* Duplicate top element */ if (i >= h->stack.cnt) fatal(h, "limit check (index)"); pushFix(h, h->stack.array[h->stack.cnt - 1 - i].f); } break; case t13_roll: { int j = popInt(h); int n = popInt(h); int iTop = h->stack.cnt - 1; int iBottom = h->stack.cnt - n; if (n < 0 || iBottom < 0) fatal(h, "limit check (roll)"); /* Constrain j to [0,n) */ if (j < 0) j = n - (-j % n); j %= n; reverse(h, iTop - j + 1, iTop); reverse(h, iBottom, iTop - j); reverse(h, iBottom, iTop); } break; case t13_hflex: addCurve(h, 1, indexFix(h, 0), 0, indexFix(h, 1), indexFix(h, 2), indexFix(h, 3), 0); addCurve(h, 1, indexFix(h, 4), 0, indexFix(h, 5), 0, indexFix(h, 6), -indexFix(h, 2)); h->stack.cnt = 0; break; case t13_flex: addCurve(h, 1, indexFix(h, 0), indexFix(h, 1), indexFix(h, 2), indexFix(h, 3), indexFix(h, 4), indexFix(h, 5)); addCurve(h, 1, indexFix(h, 6), indexFix(h, 7), indexFix(h, 8), indexFix(h, 9), indexFix(h, 10), indexFix(h, 11)); h->stack.cnt = 0; break; case t13_hflex1: { Fixed dy1 = indexFix(h, 1); Fixed dy2 = indexFix(h, 3); Fixed dy5 = indexFix(h, 7); addCurve(h, 1, indexFix(h, 0), dy1, indexFix(h, 2), dy2, indexFix(h, 4), 0); addCurve(h, 1, indexFix(h, 5), 0, indexFix(h, 6), dy5, indexFix(h, 8), -(dy1 + dy2 + dy5)); } h->stack.cnt = 0; break; case t13_flex1: { Fixed dx1 = indexFix(h, 0); Fixed dy1 = indexFix(h, 1); Fixed dx2 = indexFix(h, 2); Fixed dy2 = indexFix(h, 3); Fixed dx3 = indexFix(h, 4); Fixed dy3 = indexFix(h, 5); Fixed dx4 = indexFix(h, 6); Fixed dy4 = indexFix(h, 7); Fixed dx5 = indexFix(h, 8); Fixed dy5 = indexFix(h, 9); Fixed dx = dx1 + dx2 + dx3 + dx4 + dx5; Fixed dy = dy1 + dy2 + dy3 + dy4 + dy5; if (ABS(dx) > ABS(dy)) { dx = indexFix(h, 10); dy = -dy; } else { dx = -dx; dy = indexFix(h, 10); } addCurve(h, 1, dx1, dy1, dx2, dy2, dx3, dy3); addCurve(h, 1, dx4, dy4, dx5, dy5, dx, dy); } h->stack.cnt = 0; break; } } break; case t13_blend: blendValues(h); break; default: /* Matches 1..215, result -107..107 */ pushInt(h, 108 - byte0); break; case 241: /* 108..363 */ pushInt(h, 363 - GETBYTE(h)); break; case 239: /* 364..619 */ pushInt(h, 619 - GETBYTE(h)); break; case 246: /* 620..875 */ pushInt(h, GETBYTE(h) + 620); break; case 235: /* 876..1131 */ pushInt(h, 1131 - GETBYTE(h)); break; case 232: /* -108..-363 */ pushInt(h, GETBYTE(h) - 363); break; case 228: /* -364..-619 */ pushInt(h, GETBYTE(h) - 619); break; case 224: /* -620..-875 */ pushInt(h, GETBYTE(h) - 875); break; case 220: /* -876..-1131 */ pushInt(h, GETBYTE(h) - 1131); break; case t13_shortint: { /* 2 byte number */ long byte1 = GETBYTE(h); pushInt(h, byte1<<8 | GETBYTE(h)); } break; case t13_shftshort: { long byte1 = GETBYTE(h); pushFix(h, byte1<<23 | GETBYTE(h)<<15); } break; case 254: { /* 5 byte number */ long byte1 = GETBYTE(h); long byte2 = GETBYTE(h); long byte3 = GETBYTE(h); pushFix(h, byte1<<24 | byte2<<16 | byte3<<8 | GETBYTE(h)); } break; } } }