/* This write routine is based upon the assumption that storing an object * issues two writes: first one byte containing the storable type, then the * actual object contents. This routine buffers the first single-byte write * and sends it when the second write occurs. */ int net_char_write(char *pointer, int size) { GTCX static char buffered_type; static int buffered = 0; int count; if (buffered) { char* const buffer = net_buffer(1 + size); *buffer = buffered_type; buffered = 0; memcpy(buffer + 1, pointer, size); count = write2(socket_fides, buffer, 1 + size); if (count > 0) count -= 1; /* do not report buffered byte */ } else if (size == 1) { buffered_type = *pointer; buffered = 1; count = 1; /* pretend buffered bytes was written */ } else count = write2(socket_fides, pointer, size); return count; }
void PlayState::updateText() { // Black BG for the text to show more visibly char blackStrip[30]; for(int i = 0; i < 30; ++i) { blackStrip[i] = 127; } write2(blackStrip, Vec2(0, 0)); write2(blackStrip, Vec2(0, 19)); // Write lives char lifeCountToString[10]; gba_itoa(player.getLifeCount(), lifeCountToString); write(" :", Vec2(0,19)); write(lifeCountToString, Vec2(2, 19)); // Write bombs char bombCountToString[10]; gba_itoa(player.getBombCount(), bombCountToString); write(" :", Vec2(16, 19)); write(bombCountToString, Vec2(18, 19)); // Write Score char scoreToString[10]; gba_itoa(g_playerScore, scoreToString); write("Score: ", Vec2(0, 0)); write(scoreToString, Vec2(9, 0)); }
int main(int argc, char const ** argv) { if (argc != 2) { std::cerr << "USAGE: " << argv[0] << " IN.bam\n"; return 1; } // Open BGZF Stream for reading. seqan::Stream<seqan::Bgzf> inStream; if (!open(inStream, argv[1], "r")) { std::cerr << "ERROR: Could not open " << argv[1] << " for reading.\n"; return 1; } // Setup name store, cache, and BAM I/O context. typedef seqan::StringSet<seqan::CharString> TNameStore; typedef seqan::NameStoreCache<TNameStore> TNameStoreCache; typedef seqan::BamIOContext<TNameStore> TBamIOContext; TNameStore nameStore; TNameStoreCache nameStoreCache(nameStore); TBamIOContext context(nameStore, nameStoreCache); // Read header. seqan::BamHeader header; if (readRecord(header, context, inStream, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not read header from BAM file " << argv[1] << "\n"; return 1; } // Write out header again. if (write2(std::cout, header, context, seqan::Sam()) != 0) { std::cerr << "ERROR: Could not write header to stdout.\n"; return 1; } // Copy over the alignment records. seqan::BamAlignmentRecord record; while (!atEnd(inStream)) { if (readRecord(record, context, inStream, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not read record from BAM File " << argv[1] << "\n"; return 1; } if (write2(std::cout, record, context, seqan::Sam()) != 0) { std::cerr << "ERROR: Could not write record to stdout.\n"; return 1; } } return 0; }
void ViCustomMaskCreator::create() { qint64 totalSamples = qMin(mRead1.bufferSamples(), mRead2.bufferSamples()); qint64 currentSamples = 0; int i, end; qreal difference; while(mRead1.hasData() && mRead2.hasData()) { mRead1.read(); mRead2.read(); const ViSampleChunk &samples1 = mRead1.samples(); const ViSampleChunk &samples2 = mRead2.samples(); end = qMin(samples1.size(), samples2.size()); currentSamples += end; ViSampleChunk write1(end), write2(end); for(i = 0; i < end; ++i) { difference = qAbs(samples1[i] - samples2[i]); write1[i] = difference / 2; if(difference >= THRESHOLD) write2[i] = 1; else write2[i] = 0; } mWrite1.write(write1); mWrite2.write(write2); setProgress((currentSamples * 99.0) / totalSamples); } clear(); setProgress(100); emit finished(); }
/** Copia arquivo dentro do T2FS Os parametros são: primeiro parametro => arquivo origem segundo parametro => arquivo destino */ void cmdCp(void) { // Pega os nomes dos arquivos origem e destion char *src = strtok(NULL," \t"); char *dst = strtok(NULL," \t"); if (src==NULL || dst==NULL) { printf ("Missing parameter\n"); return; } // Abre o arquivo origem, que deve existir FILE2 hSrc = open2 (src); if (hSrc<0) { printf ("Open source file error: %d\n", hSrc); return; } // Cria o arquivo de destino, que será resetado se existir FILE2 hDst = create2 (dst); if (hDst<0) { close2(hSrc); printf ("Create destination file error: %d\n", hDst); return; } // Copia os dados de source para destination char buffer[2]; while( read2(hSrc, buffer, 1) == 1 ) { write2(hDst, buffer, 1); } // Fecha os arquicos close2(hSrc); close2(hDst); printf ("Files successfully copied\n"); }
void print1(CL_FORM *base) { LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(2)); /* T */ BIND_SPECIAL(SYMBOL(Slisp, 474), ARG(2)); /* *PRINT-ESCAPE* */ if(CL_TRUEP(ARG(1))) { if(CL_SYMBOLP(ARG(1)) && GET_SYMBOL(ARG(1)) == SYMBOL(Slisp, 48)) /* T */ { COPY(SYMVAL(Slisp, 59), ARG(1)); /* *TERMINAL-IO* */ } } else { COPY(SYMVAL(Slisp, 61), ARG(1)); /* *STANDARD-OUTPUT* */ } COPY(ARG(1), ARG(3)); terpri1(ARG(3)); COPY(ARG(0), ARG(3)); COPY(ARG(1), ARG(4)); write2(ARG(3)); LOAD_CHAR(ARG(3), ' ', ARG(3)); COPY(ARG(1), ARG(4)); write_char1(ARG(3)); mv_count = 1; RESTORE_SPECIAL; }
MessageOut::MessageOut(const message_type m_type) :myData(NULL), myDataSize(0), pos(0), myPacket(NULL) { write2(m_type); //Writes the message type in the first two bytes of the message. }
/* * Write a property ID */ void CTcDataStream::write_prop_id(uint prop_id) { /* if there's an object ID fixup list, add this reference */ if (G_keep_propfixups) CTcIdFixup::add_fixup(&G_propfixup, this, get_ofs(), prop_id); /* write the ID */ write2(prop_id); }
void main() { inti(); write1(0x80); for(num=0;num<11;num++) { write2(table[num]); delay(5); } write1(0x80+0x40); for(num=0;num<13;num++) { write2(table1[num]); delay(5); } while(1); }
/* * Write an offset value to the given label */ void CTcCodeStream::write_ofs(CTcCodeLabel *lbl, int bias, int is_long) { /* if the label is known, write it; otherwise, generate a fixup */ if (lbl->is_known) { long diff; /* * calculate the branch offset from the current position, * applying the bias to the current position */ diff = lbl->ofs - (ofs_ + bias); /* convert the offset to the correct format and write it out */ if (is_long) write4(diff); else write2(diff); } else { CTcLabelFixup *fixup; /* allocate a fixup */ fixup = alloc_fixup(); /* set up the fixup data */ fixup->ofs = ofs_; fixup->bias = bias; fixup->is_long = is_long; /* link the fixup into the label's fixup list */ fixup->nxt = lbl->fhead; lbl->fhead = fixup; /* write a placeholder to the code stream */ if (is_long) write4(0); else write2(0); } }
static int test_full (int opts) { enum { SZ = 2 }; u_rb_t *rb = NULL; con_err_if (u_rb_create(SZ, opts, &rb)); con_err_if (write1(rb)); con_err_if (write2(rb)); con_err_if (write3(rb) == 0); /* overflow, write3 must fail */ return 0; err: return 1; }
int main(int argc, char const ** argv) { if (argc != 3) { std::cerr << "USAGE: " << argv[0] << " IN.bam OUT.bam\n"; return 1; } // Open BGZF Stream for reading. seqan::Stream<seqan::Bgzf> inStream; if (!open(inStream, argv[1], "r")) { std::cerr << "ERROR: Could not open " << argv[1] << " for reading.\n"; return 1; } // Open BGZF Stream for writing. seqan::Stream<seqan::Bgzf> outStream; if (!open(outStream, argv[2], "w")) { std::cerr << "ERROR: Could not open " << argv[2] << " for writing.\n"; return 1; } // Setup name store, cache, and BAM I/O context. typedef seqan::StringSet<seqan::CharString> TNameStore; typedef seqan::NameStoreCache<TNameStore> TNameStoreCache; typedef seqan::BamIOContext<TNameStore> TBamIOContext; TNameStore nameStore; TNameStoreCache nameStoreCache(nameStore); TBamIOContext context(nameStore, nameStoreCache); // Read header. seqan::BamHeader header; if (readRecord(header, context, inStream, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not read header from BAM file " << argv[1] << "\n"; return 1; } // Write out header again. if (write2(outStream, header, context, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not write header to BAM file " << argv[2] << "\n"; return 1; } return 0; }
/* Write the specified buffer to the file desciptor, retrying until all * bytes are written or until an unrecoverable error occurs. */ rt_private int write2(int fd, char* pointer, int size) { int i; #ifdef EIF_VMS int sndbuf = get_socket_maxsend (socket_fides); int chunksize = size; if (chunksize > sndbuf) chunksize = sndbuf; #endif retry: #ifdef EIF_WINDOWS i = send(fd, pointer, size, 0); #elif defined EIF_VMS i = send(fd, pointer, chunksize, 0); #else i = write(fd, pointer, size); #endif if (i == SOCKET_ERROR && GET_SOCKET_ERROR == EWOULDBLOCK) { if (!net_socket_ready(0)) { /* The desired socket is not ready. Raise an exception. */ eraise(SOCKET_UNAVAILABLE_FOR_WRITING, EN_RETR); } else { /* Should not issue a recursive call here as this may potentially lead to an unbounded number of recursive calls, thus causing stack overflow should the socket issue this error many times in succession. */ goto retry; } } else if (i > 0 && i < size) { const int prev = i; /* A recursive call here is bounded because the remaining number of bytes is guaranteed to decrease each call. */ i = write2(fd, pointer + i, size - i); if (i > 0) i += prev; } return i; }
void MessageOut::writeString(const string &string, Sint16 length){ Uint16 stringLength = string.length(); if (length < 0) { // Write the length at the start if not fixed. write2(stringLength); length = stringLength; } else if (length < stringLength) { stringLength = length; // Make sure the length of the string is no longer than specified } expandData((this->pos) + length); memcpy((this->myData) + (this->pos), string.c_str(), stringLength); // Write the actual string. if (length > stringLength) // Pad remaining space with zeros. { memset((this->myData) + (this->pos) + stringLength, '\0', length - stringLength); } this->pos += length; }
int mesgsave(Message *m, char *s) { int ofd, n, k, ret; char *t, *raw, *unixheader, *all; t = estrstrdup(mbox.name, m->name); raw = readfile(t, "raw", &n); unixheader = readfile(t, "unixheader", &k); if(raw==nil || unixheader==nil){ fprint(2, "Mail: can't read %s: %r\n", t); free(t); return 0; } free(t); all = emalloc(n+2); memmove(all, raw, n); memmove(all+n, "\n", 1); n++; free(raw); ret = 1; s = estrdup(s); if(s[0] != '/') s = egrow(estrdup(mailboxdir), "/", s); ofd = open(s, OWRITE); if(ofd < 0){ fprint(2, "Mail: can't open %s: %r\n", s); ret = 0; }else if(seek(ofd, 0LL, 2) < 0 || write(ofd, unixheader, k) != k || write2(-1, ofd, all, n, 1) < n){ fprint(2, "Mail: save failed: can't write %s: %r\n", s); ret = 0; } free(unixheader); free(all); close(ofd); free(s); return ret; }
/** Copia arquivo de um sistema de arquivos para o outro Os parametros são: primeiro parametro => direção da copia -t copiar para o T2FS -f copiar para o FS do host segundo parametro => arquivo origem terceiro parametro => arquivo destino */ void cmdFscp(void) { // Pega a direção e os nomes dos arquivos origem e destion char *direcao = strtok(NULL, " \t"); char *src = strtok(NULL," \t"); char *dst = strtok(NULL," \t"); if (direcao==NULL || src==NULL || dst==NULL) { printf ("Missing parameter\n"); return; } // Valida direção if (strncmp(direcao, "-t", 2)==0) { // src == host // dst == T2FS // Abre o arquivo origem, que deve existir FILE *hSrc = fopen(src, "r+"); if (hSrc==NULL) { printf ("Open source file error\n"); return; } // Cria o arquivo de destino, que será resetado se existir FILE2 hDst = create2 (dst); if (hDst<0) { fclose(hSrc); printf ("Create destination file error: %d\n", hDst); return; } // Copia os dados de source para destination char buffer[2]; while( fread((void *)buffer, (size_t)1, (size_t)1, hSrc) == 1 ) { write2(hDst, buffer, 1); } // Fecha os arquicos fclose(hSrc); close2(hDst); } else if (strncmp(direcao, "-f", 2)==0) { // src == T2FS // dst == host // Abre o arquivo origem, que deve existir FILE2 hSrc = open2 (src); if (hSrc<0) { printf ("Open source file error: %d\n", hSrc); return; } // Cria o arquivo de destino, que será resetado se existir FILE *hDst = fopen(dst, "w+"); if (hDst==NULL) { printf ("Open destination file error\n"); return; } // Copia os dados de source para destination char buffer[2]; while ( read2(hSrc, buffer, 1) == 1 ) { fwrite((void *)buffer, (size_t)1, (size_t)1, hDst); } // Fecha os arquicos close2(hSrc); fclose(hDst); } else { printf ("Invalid copy direction\n"); return; } printf ("Files successfully copied\n"); }
static void BuildAVInfo(unsigned char *buf, const struct vobgroup *va) /* builds the part of the IFO structure from offset 0x100 (VMGM, VTSM) and 0x200 (VTS) onwards, containing the video, audio and subpicture stream attributes. Note these attributes don't include any stream IDs; those are specified per-PGC. */ { int i; static const int widescreen_bits[4] = { 0, /* VW_NONE */ 0x100, /* VW_NOLETTERBOX */ 0x200, /* VW_NOPANSCAN */ 2 /* VW_CROP */ }; write2 ( buf, (va->vd.vmpeg == 2 ? 0x4000 : 0) /* coding mode: MPEG-1 or MPEG-2 */ | widescreen_bits[va->vd.vwidescreen] /* whether to allow automatic pan-scan, automatic letterbox, do cropping */ | (va->vd.vformat == VF_PAL ? 0x1000 : 0) /* NTSC or PAL */ | (va->vd.vaspect == VA_16x9 ? 0xc00 : 0x300) // if 16:9, set aspect flag; if 4:3 set noletterbox/nopanscan | ((va->vd.vcaption & 1) ? 0x80 : 0) /* caption=field1 (line-21 closed-captioning, NTSC only) */ | ((va->vd.vcaption & 2) ? 0x40 : 0) /* caption=field2 (line-21 closed-captioning, NTSC only) */ | ((va->vd.vres - 1) << 3) /* resolution code */ ); /* bit rate always VBR, letterbox-cropped unset, PAL film flag unset for now */ buf[3] = va->numaudiotracks; /* nr audio streams, low byte */ for (i = 0; i < va->numaudiotracks; i++) { /* fill in menu/title audio attributes */ buf[4 + i * 8] = (va->ad[i].aformat - 1) << 6; /* audio coding mode */ if (va->ad[i].alangpresent == AL_LANG) /* for title audio, not menu audio */ { buf[4 + i * 8] |= 4; /* language type = as per language code */ memcpy(buf + 6 + i * 8, va->ad[i].lang, 2); /* language code */ } /*if*/ /* multichannel extension not supported for now */ if (va->ad[i].adolby == AD_SURROUND) /* for title audio, not menu audio */ { buf[4 + i * 8] |= 2; /* application mode = surround */ buf[11 + i * 8] = 8; /* suitable for Dolby surround decoding */ } /*if*/ /* karaoke options not supported for now */ buf[5 + i * 8] = ((va->ad[i].aquant - 1) << 6) /* quantization/DRC */ | ((va->ad[i].asample - 1) << 4) /* sample rate */ | (va->ad[i].achannels - 1); /* nr channels - 1 */ buf[9 + i * 8] = va->ad[i].acontent; /* audio code extension for title audio, not menu audio */ } /*for*/ buf[0x55] = va->numsubpicturetracks; /* nr subpicture streams, low byte */ for (i = 0; i < va->numsubpicturetracks; i++) { /* coding mode always RLE */ if (va->sp[i].slangpresent == AL_LANG) /* for title subpicture, not menu subpicture */ { buf[0x56 + i * 6] = 1; /* language type = as per language code */ memcpy(buf + 0x58 + i * 6, va->sp[i].lang, 2); /* language code */ } /*if*/ buf[0x56 + i * 6 + 5] = va->sp[i].scontent; /* title code extension (title subpicture only) */ } /*for*/ } /*BuildAVInfo*/
void TocGen(const struct workset *ws, const struct pgc *fpc, const char *fname) /* writes the IFO for a VMGM. */ { static unsigned char buf[2048]; int nextsector, offset, i, j, vtsstart; const bool forcemenus = needmenus(ws->menus); FILE *h; h = fopen(fname, "wb"); memset(buf, 0, 2048); memcpy(buf, "DVDVIDEO-VMG", 12); buf[0x21] = 0x11; /* version number */ buf[0x27] = 1; /* number of volumes */ buf[0x29] = 1; /* volume number */ buf[0x2a] = 1; /* side ID */ write2(buf + 0x3e, ws->titlesets->numvts); /* number of title sets */ strncpy((char *)(buf + 0x40), PACKAGE_STRING, 31); /* provider ID */ buf[0x86] = 4; /* start address of FP_PGC = 0x400 */ nextsector = 1; write4(buf + 0xc4, nextsector); /* sector pointer to TT_SRPT (table of titles) */ nextsector += Create_TT_SRPT(0, ws->titlesets, 0); /* just to figure out how many sectors will be needed */ if (jumppad || forcemenus) { write4(buf + 0xc8, nextsector); /* sector pointer to VMGM_PGCI_UT (menu PGC table) */ nextsector += CreatePGC(0, ws, VTYPE_VMGM); } /*if*/ write4(buf + 0xd0, nextsector); /* sector pointer to VMG_VTS_ATRT (copies of VTS audio/subpicture attrs) */ /* I will output it immediately following IFO header */ nextsector += (8 + ws->titlesets->numvts * 0x30c + 2047) / 2048; /* round up size of VMG_VTS_ATRT to whole sectors */ if (jumppad || forcemenus) { write4(buf + 0xd8, nextsector); /* sector pointer to VMGM_C_ADT (menu cell address table) */ /* I make it follow VMG_VTS_ATRT */ nextsector += CreateCellAddressTable(0, ws->menus->vg); /* how much room it will need */ write4(buf + 0xdc, nextsector); /* sector pointer to VMGM_VOBU_ADMAP (menu VOBU address map) */ nextsector += numsectVOBUAD(ws->menus->vg); } /*if*/ write4(buf + 0x1c, nextsector - 1); /* last sector of IFO */ vtsstart = nextsector * 2; /* size of two copies of everything above including BUP */ if (jumppad || forcemenus) { write4(buf + 0xc0, nextsector); /* start sector of menu VOB */ vtsstart += getvoblen(ws->menus->vg); } /*if*/ write4(buf + 0xc, vtsstart - 1); /* last sector of VMG set (last sector of BUP) */ if (forcemenus) BuildAVInfo(buf + 256, ws->menus->vg); /* create FPC at 0x400 as promised */ buf[0x407] = (getratedenom(ws->menus->vg) == 90090 ? 3 : 1) << 6; // only set frame rate XXX: should check titlesets if there is no VMGM menu buf[0x4e5] = 0xec; /* offset to command table, low byte */ offset = 0x4f4; /* commands start here, after 8-byte header of command table */ if (fpc) { unsigned char *pi; if (fpc->posti || fpc->numsources || fpc->numbuttons || fpc->entries) { fprintf(stderr,"ERR: FPC can ONLY contain prei commands, nothing else\n"); exit(1); } /*if*/ if (ws->menus && ws->menus->numgroups) pi = vm_compile(buf + offset, buf + offset, ws, ws->menus->groups[0].pg, 0, fpc->prei, 2); // XXX: just use the first pgcgroup as a reference else pi = vm_compile(buf + offset, buf + offset, ws, 0, 0, fpc->prei, 2); if (!pi) { fprintf(stderr,"ERR: in FPC\n"); exit(1); } /*if*/ offset = (pi - buf - offset) / 8; /* number of instructions */ assert(offset <= 128); buf[0x4ed] = offset; /* number of pre commands, low byte */ } else { /* generate default FPC */ if (forcemenus) { buf[offset + 0] = 0x30; // jump to VMGM 1 buf[offset + 1] = 0x06; buf[offset + 2] = 0x00; buf[offset + 3] = 0x00; buf[offset + 4] = 0x00; buf[offset + 5] = 0x42; buf[offset + 6] = 0x00; buf[offset + 7] = 0x00; } else if (ws->titlesets->numvts && ws->titlesets->vts[0].hasmenu) { buf[offset + 0] = 0x30; // jump to VTSM vts=1, ttn=1, menu=1 buf[offset + 1] = 0x06; buf[offset + 2] = 0x00; buf[offset + 3] = 0x01; buf[offset + 4] = 0x01; buf[offset + 5] = 0x83; buf[offset + 6] = 0x00; buf[offset + 7] = 0x00; } else { buf[offset + 0] = 0x30; // jump to title 1 buf[offset + 1] = 0x02; buf[offset + 2] = 0x00; buf[offset + 3] = 0x00; buf[offset + 4] = 0x00; buf[offset + 5] = 0x01; buf[offset + 6] = 0x00; buf[offset + 7] = 0x00; } /*if*/ buf[0x4ed] = 1; /* number of pre commands, low byte */ } /*if*/ write2(buf + 0x4f2, 7 + buf[0x4ed] * 8); /* end address relative to command table */ write2(buf + 0x82 /* end byte address, low word, of VMGI_MAT */, 0x4ec + read2(buf + 0x4f2)); nfwrite(buf, 2048, h); Create_TT_SRPT(h, ws->titlesets, vtsstart); /* generate it for real */ // PGC if (jumppad || forcemenus) CreatePGC(h, ws, VTYPE_VMGM); /* VMG_VTS_ATRT contains copies of menu and title attributes from all titlesets */ /* output immediately following IFO header, as promised above */ memset(buf, 0, 2048); j = 8 + ws->titlesets->numvts * 4; write2(buf, ws->titlesets->numvts); /* number of titlesets */ write4(buf + 4, ws->titlesets->numvts * 0x30c + 8 - 1); /* end address (last byte of last VTS_ATRT) */ for (i = 0; i < ws->titlesets->numvts; i++) write4(buf + 8 + i * 4, j + i * 0x308); /* offset to VTS_ATRT i */ nfwrite(buf, j, h); for (i = 0; i < ws->titlesets->numvts; i++) /* output each VTS_ATRT */ { write4(buf, 0x307); /* end address */ memcpy(buf + 4, ws->titlesets->vts[i].vtscat, 4); /* VTS_CAT (copy of bytes 0x22 .. 0x25 of VTS IFO) */ memcpy(buf + 8, ws->titlesets->vts[i].vtssummary, 0x300); /* copy of VTS attributes (bytes 0x100 onwards of VTS IFO) */ nfwrite(buf, 0x308, h); j += 0x308; } /*for*/ j = 2048 - (j & 2047); if (j < 2048) { /* pad to next whole sector */ memset(buf, 0, j); nfwrite(buf, j, h); } /*if*/ if (jumppad || forcemenus) { CreateCellAddressTable(h, ws->menus->vg); /* actually generate VMGM_C_ADT */ CreateVOBUAD(h, ws->menus->vg); /* generate VMGM_VOBU_ADMAP */ } /*if*/ fflush(h); if (errno != 0) { fprintf(stderr, "\nERR: Error %d -- %s -- flushing VMGM\n", errno, strerror(errno)); exit(1); } /*if*/ fclose(h); } /*TocGen*/
TVerdict CTestSyscalls::doTestStepL() { int err; if(TestStepName() == KCreat) { INFO_PRINTF1(_L("Creat():")); err = Creat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen1) { INFO_PRINTF1(_L("open1():")); err = open1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen2) { INFO_PRINTF1(_L("open2():")); err = open2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen3) { INFO_PRINTF1(_L("open3():")); err = open3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen4) { INFO_PRINTF1(_L("open4():")); err = open4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen5) { INFO_PRINTF1(_L("open5():")); err = open5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen6) { INFO_PRINTF1(_L("open6():")); err = open6(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate1) { INFO_PRINTF1(_L("OpenTruncate1:")); err = OpenTruncate1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenTruncate2) { INFO_PRINTF1(_L("OpenTruncate2:")); err = OpenTruncate2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen7) { INFO_PRINTF1(_L("open7():")); err = open7(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpenInAppendMode) { INFO_PRINTF1(_L("OpenInAppendMode():")); err = OpenInAppendMode(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite1) { INFO_PRINTF1(_L("write1():")); err = write1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite2) { INFO_PRINTF1(_L("write2():")); err = write2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite3) { INFO_PRINTF1(_L("write3():")); err = write3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kwrite5) { INFO_PRINTF1(_L("write5():")); err = write5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread1) { INFO_PRINTF1(_L("read1():")); err = read1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread2) { INFO_PRINTF1(_L("read2():")); err = read2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread3) { INFO_PRINTF1(_L("read3():")); err = read3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread4) { INFO_PRINTF1(_L("read4():")); err = read4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpendir) { INFO_PRINTF1(_L("Opendir():")); err = Opendir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClosedir) { INFO_PRINTF1(_L("Closedir():")); err = Closedir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReaddir) { INFO_PRINTF1(_L("Readdir():")); err = Readdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek) { INFO_PRINTF1(_L("Lseek():")); err = Lseek(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseek1) { INFO_PRINTF1(_L("Lseek1():")); err = Lseek1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess) { INFO_PRINTF1(_L("Access():")); err = Access(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KAccess1) { INFO_PRINTF1(_L("Access1():")); err = Access1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup) { INFO_PRINTF1(_L("Dup():")); err = Dup(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KDup2) { INFO_PRINTF1(_L("Dup2():")); err = Dup2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename) { INFO_PRINTF1(_L("Rename():")); err = Rename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename1) { INFO_PRINTF1(_L("Rename1():")); err = Rename1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod) { INFO_PRINTF1(_L("Chmod():")); err = Chmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod1) { INFO_PRINTF1(_L("Chmod1():")); err = Chmod1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_dir) { INFO_PRINTF1(_L("Chmod_dir():")); err = Chmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod) { INFO_PRINTF1(_L("FChmod():")); err = FChmod(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFChmod_dir) { INFO_PRINTF1(_L("FChmod_dir():")); err = FChmod_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KExit) { INFO_PRINTF1(_L("Exit():")); err = Exit(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClose) { INFO_PRINTF1(_L("Close():")); err = Close(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir) { INFO_PRINTF1(_L("Mkdir():")); err = Mkdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMk_dir) { INFO_PRINTF1(_L("Mk_dir():")); err = Mk_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir) { INFO_PRINTF1(_L("Rmdir():")); err = Rmdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRm_dir) { INFO_PRINTF1(_L("Rm_dir():")); err = Rm_dir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir1) { INFO_PRINTF1(_L("Rmdir1():")); err = Rmdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir_Chdir) { INFO_PRINTF1(_L("Rmdir_Chdir():")); err = Rmdir_Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFsync) { INFO_PRINTF1(_L("Fsync():")); err = Fsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes) { INFO_PRINTF1(_L("Utimes():")); err = Utimes(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtime) { INFO_PRINTF1(_L("Utime():")); err = Utime(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir) { INFO_PRINTF1(_L("Chdir():")); err = Chdir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFcntl) { INFO_PRINTF1(_L("Fcntl():")); err = Fcntl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KIoctl) { INFO_PRINTF1(_L("Ioctl():")); err = Ioctl(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat) { INFO_PRINTF1(_L("Fstat():")); err = Fstat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat) { INFO_PRINTF1(_L("Stat():")); err = Stat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat1) { INFO_PRINTF1(_L("Stat1():")); err = Stat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat2) { INFO_PRINTF1(_L("Stat2():")); err = Stat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat3) { INFO_PRINTF1(_L("Stat3():")); err = Stat3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KGetpid) { INFO_PRINTF1(_L("Getpid():")); err = Getpid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KClock) { INFO_PRINTF1(_L("Clock():")); err = Clock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTime) { INFO_PRINTF1(_L("Time():")); err = Time(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPid) { INFO_PRINTF1(_L("WaitPid():")); err = WaitPid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV) { INFO_PRINTF1(_L("ReadV():")); err = ReadV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWriteV) { INFO_PRINTF1(_L("WriteV():")); err = WriteV(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSleep) { INFO_PRINTF1(_L("Sleep():")); err = Sleep(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KSeekDir) { INFO_PRINTF1(_L("SeekDir():")); err = SeekDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRewindDir) { INFO_PRINTF1(_L("RewindDir():")); err = RewindDir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTelldir) { INFO_PRINTF1(_L("Telldir():")); err = Telldir(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestClock) { INFO_PRINTF1(_L("TestClock():")); err = TestClock(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat2) { INFO_PRINTF1(_L("Creat2():")); err = Creat2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopen8) { INFO_PRINTF1(_L("open8():")); err = open8(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KTestStat) { INFO_PRINTF1(_L("KTestStat():")); err = TestStat(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest1) { INFO_PRINTF1(_L("Lseekttytest1():")); err = Lseekttytest1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KLseekttytest2) { INFO_PRINTF1(_L("Lseekttytest2():")); err = Lseekttytest2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaitPidtest) { INFO_PRINTF1(_L("WaitPidtest():")); err = WaitPidtest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KWaittest) { INFO_PRINTF1(_L("Waittest():")); err = Waittest(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KOpen_FileDes_Test) { INFO_PRINTF1(_L("Open_FileDes_Test():")); err = Open_FileDes_Test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kopenuid) { INFO_PRINTF1(_L("openuid():")); err = openuid(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir1) { INFO_PRINTF1(_L("Mkdir1():")); err = Mkdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir2) { INFO_PRINTF1(_L("Mkdir2():")); err = Mkdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename2) { INFO_PRINTF1(_L("Rename2():")); err = Rename2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestfsync) { INFO_PRINTF1(_L("testfsync():")); err = testfsync(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestrename) { INFO_PRINTF1(_L("testrename():")); err = testrename(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ktestopenvalidate) { INFO_PRINTF1(_L("testopenvalidate():")); err = testopenvalidate(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Ksync_safe) { INFO_PRINTF1(_L("sync_safe():")); err = sync_safe(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KFstat1) { INFO_PRINTF1(_L("Fstat1():")); err = Fstat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes1) { INFO_PRINTF1(_L("Utimes1():")); err = Utimes1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test1) { INFO_PRINTF1(_L("Mkdir_test1():")); err = Mkdir_test1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod_test) { INFO_PRINTF1(_L("Chmod_test():")); err = Chmod_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir1) { INFO_PRINTF1(_L("Chdir1():")); err = Chdir1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir2) { INFO_PRINTF1(_L("Rmdir2():")); err = Rmdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename_test) { INFO_PRINTF1(_L("Rename_test():")); err = Rename_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename3) { INFO_PRINTF1(_L("Rename3():")); err = Rename3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KCreat1) { INFO_PRINTF1(_L("Creat1():")); err = Creat1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KReadV1) { INFO_PRINTF1(_L("ReadV1():")); err = ReadV1(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KUtimes2) { INFO_PRINTF1(_L("Utimes2():")); err = Utimes2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KStat_test) { INFO_PRINTF1(_L("Stat_test():")); err = Stat_test(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KMkdir_test2) { INFO_PRINTF1(_L("Mkdir_test2():")); err = Mkdir_test2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChmod2) { INFO_PRINTF1(_L("Chmod2():")); err = Chmod2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KChdir2) { INFO_PRINTF1(_L("Chdir2():")); err = Chdir2(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename4) { INFO_PRINTF1(_L("Rename4():")); err = Rename4(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRename5) { INFO_PRINTF1(_L("Rename5():")); err = Rename5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == KRmdir3) { INFO_PRINTF1(_L("Rmdir3():")); err = Rmdir3(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } else if(TestStepName() == Kread5) { INFO_PRINTF1(_L("read5():")); err = read5(); SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass); } return TestStepResult(); }
inline void writeUShort(unsigned short c) { write2((char*)&c); }
inline void writeShort(short c) { write2((char*)&c); }
int main(int argc, char const ** argv) { if (argc != 7) { std::cerr << "USAGE: " << argv[0] << " IN.bam IN.bam.bai REF BEGIN END COUNT\n"; return 1; } // Open BGZF Stream for reading. seqan::Stream<seqan::Bgzf> inStream; if (!open(inStream, argv[1], "r")) { std::cerr << "ERROR: Could not open " << argv[1] << " for reading.\n"; return 1; } // Read BAI index. seqan::BamIndex<seqan::Bai> baiIndex; if (read(baiIndex, argv[2]) != 0) { std::cerr << "ERROR: Could not read BAI index file " << argv[2] << "\n"; return 1; } // Setup name store, cache, and BAM I/O context. typedef seqan::StringSet<seqan::CharString> TNameStore; typedef seqan::NameStoreCache<TNameStore> TNameStoreCache; typedef seqan::BamIOContext<TNameStore> TBamIOContext; TNameStore nameStore; TNameStoreCache nameStoreCache(nameStore); TBamIOContext context(nameStore, nameStoreCache); // Read header. seqan::BamHeader header; if (readRecord(header, context, inStream, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not read header from BAM file " << argv[1] << "\n"; return 1; } // Translate from reference name to rId. int rId = 0; if (!getIdByName(nameStore, argv[3], rId, nameStoreCache)) { std::cerr << "ERROR: Reference sequence named " << argv[3] << " not known.\n"; return 1; } // Translate BEGIN and END arguments to number, 1-based to 0-based. int beginPos = 0, endPos = 0; if (!seqan::lexicalCast2(beginPos, argv[4]) || beginPos <= 0) { std::cerr << "ERROR: Begin position " << argv[4] << " is invalid.\n"; return 1; } beginPos -= 1; // 1-based to 0-based. if (!seqan::lexicalCast2(endPos, argv[5]) || endPos <= 0) { std::cerr << "ERROR: End position " << argv[5] << " is invalid.\n"; return 1; } endPos -= 1; // 1-based to 0-based. // Translate number of elements to print to number. int num = 0; if (!seqan::lexicalCast2(num, argv[6])) { std::cerr << "ERROR: Count " << argv[6] << " is invalid.\n"; return 1; } // Jump the BGZF stream to this position. bool hasAlignments = false; if (!jumpToRegion(inStream, hasAlignments, context, rId, beginPos, endPos, baiIndex)) { std::cerr << "ERROR: Could not jump to " << argv[3] << ":" << argv[4] << "\n"; return 1; } if (!hasAlignments) return 0; // No alignments here. // Seek linearly to the selected position. seqan::BamAlignmentRecord record; int numPrinted = 0; while (!atEnd(inStream) && numPrinted < num) { if (readRecord(record, context, inStream, seqan::Bam()) != 0) { std::cerr << "ERROR: Could not read record from BAM file.\n"; return 1; } // If we are on the next reference or at the end already then we stop. if (record.rId == -1 || record.rId > rId || record.pos >= endPos) break; // If we are left of the selected position then we skip this record. if (record.pos < beginPos) continue; // Otherwise, we print it to the user. numPrinted += 1; if (write2(std::cout, record, context, seqan::Sam()) != 0) { std::cerr << "ERROR: Could not write record to stdout.\n"; return 1; } } return 0; }
void write_to_string1(CL_FORM *base) { BIND_SPECIAL(SYMBOL(Slisp, 474), ARG(1)); /* *PRINT-ESCAPE* */ BIND_SPECIAL(SYMBOL(Slisp, 479), ARG(2)); /* *PRINT-RADIX* */ BIND_SPECIAL(SYMBOL(Slisp, 471), ARG(3)); /* *PRINT-BASE* */ BIND_SPECIAL(SYMBOL(Slisp, 473), ARG(4)); /* *PRINT-CIRCLE* */ BIND_SPECIAL(SYMBOL(Slisp, 478), ARG(5)); /* *PRINT-PRETTY* */ BIND_SPECIAL(SYMBOL(Slisp, 477), ARG(6)); /* *PRINT-LEVEL* */ BIND_SPECIAL(SYMBOL(Slisp, 476), ARG(7)); /* *PRINT-LENGTH* */ BIND_SPECIAL(SYMBOL(Slisp, 472), ARG(8)); /* *PRINT-CASE* */ BIND_SPECIAL(SYMBOL(Slisp, 475), ARG(9)); /* *PRINT-GENSYM* */ BIND_SPECIAL(SYMBOL(Slisp, 470), ARG(10)); /* *PRINT-ARRAY* */ LOAD_FIXNUM(ARG(11), 10, ARG(11)); LOAD_SYMBOL(SYMBOL(Slisp, 18), ARG(12)); /* CHARACTER */ LOAD_NIL(ARG(13)); LOAD_NIL(ARG(14)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(15)); /* T */ LOAD_FIXNUM(ARG(16), 0, ARG(16)); LOAD_NIL(ARG(17)); LOAD_FIXNUM(ARG(18), 0, ARG(18)); LOAD_NIL(ARG(19)); LOAD_NIL(ARG(20)); LOAD_NIL(ARG(21)); make_array1(ARG(11)); make_string_output_stream1(ARG(11)); COPY(ARG(0), ARG(12)); COPY(ARG(11), ARG(13)); write2(ARG(12)); COPY(ARG(11), ARG(12)); LOAD_SYMBOL(SYMBOL(Slisp, 64), ARG(13)); /* STREAM */ rt_struct_typep(ARG(12)); if(CL_TRUEP(ARG(12))) { COPY(OFFSET(AR_BASE(GET_FORM(ARG(11))), 0 + 1), ARG(12)); } else { COPY(SYMVAL(Slisp, 352), ARG(12)); /* NO_STRUCT */ COPY(ARG(11), ARG(13)); LOAD_SYMBOL(SYMBOL(Slisp, 64), ARG(14)); /* STREAM */ Ferror(ARG(12), 3); } if(CL_SYMBOLP(ARG(12)) && GET_SYMBOL(ARG(12)) == SYMBOL(Slisp, 102)) /* STRING-OUTPUT */ { } else { LOAD_SMSTR((CL_FORM *)&KClisp[268], ARG(12)); /* string-output-stream expected */ Ferror(ARG(12), 1); } COPY(ARG(11), ARG(12)); COPY(ARG(12), ARG(13)); COPY(ARG(13), ARG(14)); LOAD_SYMBOL(SYMBOL(Slisp, 64), ARG(15)); /* STREAM */ rt_struct_typep(ARG(14)); if(CL_TRUEP(ARG(14))) { COPY(OFFSET(AR_BASE(GET_FORM(ARG(13))), 1 + 1), ARG(12)); } else { COPY(SYMVAL(Slisp, 352), ARG(12)); /* NO_STRUCT */ LOAD_SYMBOL(SYMBOL(Slisp, 64), ARG(14)); /* STREAM */ Ferror(ARG(12), 3); } Ffuncall(ARG(12), 1); COPY(ARG(12), ARG(0)); RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; RESTORE_SPECIAL; }
void mesgsend(Message *m) { char *s, *body, *to; int i, j, h, n, natt, p[2]; struct Exec *e; Channel *sync; int first, nfld, delit, ofd; char *copy, *fld[100], *now; body = winreadbody(m->w, &n); /* assemble to: list from first line, to: line, and cc: line */ nto = 0; natt = 0; ncc = 0; nbcc = 0; first = 1; to = body; for(;;){ for(s=to; *s!='\n'; s++) if(*s == '\0'){ free(body); return; } if(s++ == to) /* blank line */ break; /* make copy of line to tokenize */ copy = emalloc(s-to); memmove(copy, to, s-to); copy[s-to-1] = '\0'; nfld = tokenizec(copy, fld, nelem(fld), ", \t"); if(nfld == 0){ free(copy); break; } n -= s-to; switch(h = whichheader(fld[0])){ case TO: case FROM: delit = 1; commas(to+strlen(fld[0]), s-1); for(i=1; i<nfld && nto<nelem(tolist); i++) if(!addressed(fld[i])) tolist[nto++] = estrdup(fld[i]); break; case BCC: delit = 1; commas(to+strlen(fld[0]), s-1); for(i=1; i<nfld && nbcc<nelem(bcclist); i++) if(!addressed(fld[i])) bcclist[nbcc++] = estrdup(fld[i]); break; case CC: delit = 1; commas(to+strlen(fld[0]), s-1); for(i=1; i<nfld && ncc<nelem(cclist); i++) if(!addressed(fld[i])) cclist[ncc++] = estrdup(fld[i]); break; case ATTACH: case INCLUDE: delit = 1; for(i=1; i<nfld && natt<nelem(attlist); i++){ attlist[natt] = estrdup(fld[i]); included[natt++] = (h == INCLUDE); } break; default: if(first){ delit = 1; for(i=0; i<nfld && nto<nelem(tolist); i++) tolist[nto++] = estrdup(fld[i]); }else /* ignore it */ delit = 0; break; } if(delit){ /* delete line from body */ memmove(to, s, n+1); }else to = s; free(copy); first = 0; } ofd = open(outgoing, OWRITE|OCEXEC); /* no error check necessary */ if(ofd > 0){ /* From dhog Fri Aug 24 22:13:00 EDT 2001 */ now = ctime(time(0)); seek(ofd, 0, 2); fprint(ofd, "From %s %s", user, now); fprint(ofd, "From: %s\n", user); fprint(ofd, "Date: %s", now); for(i=0; i<natt; i++) if(included[i]) fprint(ofd, "Include: %s\n", attlist[i]); else fprint(ofd, "Attach: %s\n", attlist[i]); /* needed because mail is by default Latin-1 */ fprint(ofd, "Content-Type: text/plain; charset=\"UTF-8\"\n"); fprint(ofd, "Content-Transfer-Encoding: 8bit\n"); } e = emalloc(sizeof(struct Exec)); if(pipe(p) < 0) error("can't create pipe: %r"); e->p[0] = p[0]; e->p[1] = p[1]; e->prog = unsharp("#9/bin/upas/marshal"); e->argv = emalloc((1+1+2+4*natt+1)*sizeof(char*)); e->argv[0] = estrdup("marshal"); e->argv[1] = estrdup("-8"); j = 2; if(m->replyname){ e->argv[j++] = estrdup("-R"); e->argv[j++] = estrstrdup(mbox.name, m->replyname); } for(i=0; i<natt; i++){ if(included[i]) e->argv[j++] = estrdup("-A"); else e->argv[j++] = estrdup("-a"); e->argv[j++] = estrdup(attlist[i]); } sync = chancreate(sizeof(int), 0); e->sync = sync; proccreate(execproc, e, EXECSTACK); recvul(sync); /* close(p[0]); */ /* using marshal -8, so generate rfc822 headers */ if(nto > 0){ print2(p[1], ofd, "To: "); for(i=0; i<nto-1; i++) print2(p[1], ofd, "%s, ", tolist[i]); print2(p[1], ofd, "%s\n", tolist[i]); } if(ncc > 0){ print2(p[1], ofd, "CC: "); for(i=0; i<ncc-1; i++) print2(p[1], ofd, "%s, ", cclist[i]); print2(p[1], ofd, "%s\n", cclist[i]); } if(nbcc > 0){ print2(p[1], ofd, "BCC: "); for(i=0; i<nbcc-1; i++) print2(p[1], ofd, "%s, ", bcclist[i]); print2(p[1], ofd, "%s\n", bcclist[i]); } i = strlen(body); if(i > 0) write2(p[1], ofd, body, i, 1); /* guarantee a blank line, to ensure attachments are separated from body */ if(i==0 || body[i-1]!='\n') write2(p[1], ofd, "\n\n", 2, 0); else if(i>1 && body[i-2]!='\n') write2(p[1], ofd, "\n", 1, 0); /* these look like pseudo-attachments in the "outgoing" box */ if(ofd>0 && natt>0){ for(i=0; i<natt; i++) if(included[i]) fprint(ofd, "=====> Include: %s\n", attlist[i]); else fprint(ofd, "=====> Attach: %s\n", attlist[i]); } if(ofd > 0) write(ofd, "\n", 1); for(i=0; i<natt; i++) free(attlist[i]); close(ofd); close(p[1]); free(body); if(m->replyname != nil) mesgmenumark(mbox.w, m->replyname, "\t[replied]"); if(m->name[0] == '/') s = estrdup(m->name); else s = estrstrdup(mbox.name, m->name); s = egrow(s, "-R", nil); winname(m->w, s); free(s); winclean(m->w); /* mark message unopened because it's no longer the original message */ m->opened = 0; }
static void CreateTMAPT(FILE *h, const struct pgcgroup *va) /* creates the VTS_TMAPTI structure which contains the time maps for each PGC. */ { int pgcindex, mapblock; unsigned char buf[8]; write2(buf, va->numpgcs); /* nr program chains, low word */ write2(buf + 2, 0); /* nr program chains, high word */ write4(buf + 4, sizeTMAPT(va) - 1); /* end address (last byte of last VTS_TMAP) */ nfwrite(buf, 8, h); mapblock = 8 + 4 * va->numpgcs; for (pgcindex = 0; pgcindex < va->numpgcs; pgcindex++) { write4(buf, mapblock); /* offset to VTS_TMAP[pgcindex + 1] */ nfwrite(buf, 4, h); mapblock += tmapt_block_size(va, pgcindex); } /*for*/ for (pgcindex = 0; pgcindex < va->numpgcs; pgcindex++) { /* fill in each VTS_TMAP */ int numtmapt = get_pgc_duration_seconds(va, pgcindex), ptsbase, j; const int units = secunit(numtmapt); const struct pgc * const thispgc = va->pgcs[pgcindex]; numtmapt /= units; buf[0] = units; /* time units, seconds */ buf[1] = 0; /* unused */ write2(buf + 2, numtmapt); /* nr entries in map, [0 .. 2048] */ nfwrite(buf, 4, h); /* write VTS_TMAP header */ if (numtmapt > 0) { /* write VTS_TMAP entries */ const struct vobuinfo *vobu1; // I don't know why I ever did this // ptsbase = -getframepts(va->vg); ptsbase = 0; // this matches Bullitt vobu1 = globalfindvobu(thispgc, ptsbase + pts_seconds_to_ticks(va->vg, units)); for (j = 0; j < numtmapt; j++) { const struct vobuinfo * const vobu2 = globalfindvobu ( thispgc, ptsbase + pts_seconds_to_ticks(va->vg, (j + 2) * units) ); write4(buf, vobu1->sector); if (!vobu2 || vobu1->vobcellid != vobu2->vobcellid) buf[0] |= 0x80; /* next time entry will be for a different cell */ nfwrite(buf, 4, h); vobu1 = vobu2; } /*for*/ } /*if*/ } /*for*/ pgcindex = (-sizeTMAPT(va)) & 2047; if (pgcindex) { /* clear out unused part of last sector */ memset(buf, 0, 8); while(pgcindex >= 8) { nfwrite(buf, 8, h); pgcindex -= 8; } /*while*/ if (pgcindex) /* shouldn't occur? */ nfwrite(buf, pgcindex, h); } /*if*/ }