static void writerootdir(void) { struct sfs_inode sfi; bzero((void *)&sfi, sizeof(sfi)); sfi.sfi_size = SWAPL(0); sfi.sfi_type = SWAPS(SFS_TYPE_DIR); sfi.sfi_linkcount = SWAPS(1); diskwrite(&sfi, SFS_ROOT_LOCATION); }
static void swapinode(struct sfs_inode *sfi) { int i; sfi->sfi_size = SWAPL(sfi->sfi_size); sfi->sfi_type = SWAPS(sfi->sfi_type); sfi->sfi_linkcount = SWAPS(sfi->sfi_linkcount); for (i=0; i<SFS_NDIRECT; i++) { sfi->sfi_direct[i] = SWAPL(sfi->sfi_direct[i]); } #ifdef SFS_NIDIRECT for (i=0; i<SFS_NIDIRECT; i++) { sfi->sfi_indirect[i] = SWAPL(sfi->sfi_indirect[i]); } #else sfi->sfi_indirect = SWAPL(sfi->sfi_indirect); #endif #ifdef SFS_NDIDIRECT for (i=0; i<SFS_NDIDIRECT; i++) { sfi->sfi_dindirect[i] = SWAPL(sfi->sfi_dindirect[i]); } #else #ifdef HAS_DIDIRECT sfi->sfi_dindirect = SWAPL(sfi->sfi_dindirect); #endif #endif #ifdef SFS_NTIDIRECT for (i=0; i<SFS_NTIDIRECT; i++) { sfi->sfi_tindirect[i] = SWAPL(sfi->sfi_tindirect[i]); } #else #ifdef HAS_TIDIRECT sfi->sfi_tindirect = SWAPL(sfi->sfi_tindirect); #endif #endif }
static int pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user) { struct pcap_win *pw = p->priv; PACKET Packet; u_char *dp = NULL; int packet_len = 0, caplen = 0; struct pcap_pkthdr pcap_header; u_char *endofbuf; int n = 0; dag_record_t *header; unsigned erf_record_len; ULONGLONG ts; int cc; unsigned swt; unsigned dfp = pw->adapter->DagFastProcess; cc = p->cc; if (cc == 0) /* Get new packets only if we have processed all the ones of the previous read */ { /* * Get new packets from the network. * * The PACKET structure had a bunch of extra stuff for * Windows 9x/Me, but the only interesting data in it * in the versions of Windows that we support is just * a copy of p->buffer, a copy of p->buflen, and the * actual number of bytes read returned from * PacketReceivePacket(), none of which has to be * retained from call to call, so we just keep one on * the stack. */ PacketInitPacket(&Packet, (BYTE *)p->buffer, p->bufsize); if (!PacketReceivePacket(pw->adapter, &Packet, TRUE)) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed"); return (-1); } cc = Packet.ulBytesReceived; if(cc == 0) /* The timeout has expired but we no packets arrived */ return (0); header = (dag_record_t*)pw->adapter->DagBuffer; } else header = (dag_record_t*)p->bp; endofbuf = (char*)header + cc; /* * Cycle through the packets */ do { erf_record_len = SWAPS(header->rlen); if((char*)header + erf_record_len > endofbuf) break; /* Increase the number of captured packets */ p->stat.ps_recv++; /* Find the beginning of the packet */ dp = ((u_char *)header) + dag_record_size; /* Determine actual packet len */ switch(header->type) { case TYPE_ATM: packet_len = ATM_SNAPLEN; caplen = ATM_SNAPLEN; dp += 4; break; case TYPE_ETH: swt = SWAPS(header->wlen); packet_len = swt - (pw->dag_fcs_bits); caplen = erf_record_len - dag_record_size - 2; if (caplen > packet_len) { caplen = packet_len; } dp += 2; break; case TYPE_HDLC_POS: swt = SWAPS(header->wlen); packet_len = swt - (pw->dag_fcs_bits); caplen = erf_record_len - dag_record_size; if (caplen > packet_len) { caplen = packet_len; } break; } if(caplen > p->snapshot) caplen = p->snapshot; /* * Has "pcap_breakloop()" been called? * If so, return immediately - if we haven't read any * packets, clear the flag and return -2 to indicate * that we were told to break out of the loop, otherwise * leave the flag set, so that the *next* call will break * out of the loop without having read any packets, and * return the number of packets we've processed so far. */ if (p->break_loop) { if (n == 0) { p->break_loop = 0; return (-2); } else { p->bp = (char*)header; p->cc = endofbuf - (char*)header; return (n); } } if(!dfp) { /* convert between timestamp formats */ ts = header->ts; pcap_header.ts.tv_sec = (int)(ts >> 32); ts = (ts & 0xffffffffi64) * 1000000; ts += 0x80000000; /* rounding */ pcap_header.ts.tv_usec = (int)(ts >> 32); if (pcap_header.ts.tv_usec >= 1000000) { pcap_header.ts.tv_usec -= 1000000; pcap_header.ts.tv_sec++; } } /* No underlaying filtering system. We need to filter on our own */ if (p->fcode.bf_insns) { if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0) { /* Move to next packet */ header = (dag_record_t*)((char*)header + erf_record_len); continue; } } /* Fill the header for the user suppplied callback function */ pcap_header.caplen = caplen; pcap_header.len = packet_len; /* Call the callback function */ (*callback)(user, &pcap_header, dp); /* Move to next packet */ header = (dag_record_t*)((char*)header + erf_record_len); /* Stop if the number of packets requested by user has been reached*/ if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) { p->bp = (char*)header; p->cc = endofbuf - (char*)header; return (n); } }
TexFont * txfLoadFont(const char *filename) { TexFont *txf; FILE *file; GLfloat w, h, xstep, ystep; char fileid[4], tmp; unsigned char *texbitmap; int min_glyph, max_glyph; int endianness, swap, format, stride, width, height; int i, j; size_t got; txf = NULL; file = fopen(filename, "rb"); if (file == NULL) { lastError = "file open failed."; goto error; } txf = (TexFont *) malloc(sizeof(TexFont)); if (txf == NULL) { lastError = "out of memory."; goto error; } /* For easy cleanup in error case. */ txf->texobj = 0; txf->tgi = NULL; txf->tgvi = NULL; txf->lut = NULL; txf->teximage = NULL; got = fread(fileid, 1, 4, file); if (got != 4 || strncmp(fileid, "\377txf", 4)) { lastError = "not a texture font file."; goto error; } /*CONSTANTCONDITION*/ assert(sizeof(int) == 4); /* Ensure external file format size. */ got = fread(&endianness, sizeof(int), 1, file); if (got == 1 && endianness == 0x12345678) { swap = 0; } else if (got == 1 && endianness == 0x78563412) { swap = 1; } else { lastError = "not a texture font file."; goto error; } #define EXPECT(n) if (got != (unsigned long) n) { lastError = "premature end of file."; goto error; } got = fread(&format, sizeof(int), 1, file); EXPECT(1); got = fread(&txf->tex_width, sizeof(int), 1, file); EXPECT(1); got = fread(&txf->tex_height, sizeof(int), 1, file); EXPECT(1); got = fread(&txf->max_ascent, sizeof(int), 1, file); EXPECT(1); got = fread(&txf->max_descent, sizeof(int), 1, file); EXPECT(1); got = fread(&txf->num_glyphs, sizeof(int), 1, file); EXPECT(1); if (swap) { SWAPL(&format, tmp); SWAPL(&txf->tex_width, tmp); SWAPL(&txf->tex_height, tmp); SWAPL(&txf->max_ascent, tmp); SWAPL(&txf->max_descent, tmp); SWAPL(&txf->num_glyphs, tmp); } txf->tgi = (TexGlyphInfo *) malloc(txf->num_glyphs * sizeof(TexGlyphInfo)); if (txf->tgi == NULL) { lastError = "out of memory."; goto error; } /*CONSTANTCONDITION*/ assert(sizeof(TexGlyphInfo) == 12); /* Ensure external file format size. */ got = fread(txf->tgi, sizeof(TexGlyphInfo), txf->num_glyphs, file); EXPECT(txf->num_glyphs); if (swap) { for (i = 0; i < txf->num_glyphs; i++) { SWAPS(&txf->tgi[i].c, tmp); SWAPS(&txf->tgi[i].x, tmp); SWAPS(&txf->tgi[i].y, tmp); } } txf->tgvi = (TexGlyphVertexInfo *) malloc(txf->num_glyphs * sizeof(TexGlyphVertexInfo)); if (txf->tgvi == NULL) { lastError = "out of memory."; goto error; } w = txf->tex_width; h = txf->tex_height; xstep = 0.5 / w; ystep = 0.5 / h; for (i = 0; i < txf->num_glyphs; i++) { TexGlyphInfo *tgi; tgi = &txf->tgi[i]; txf->tgvi[i].t0[0] = tgi->x / w + xstep; txf->tgvi[i].t0[1] = tgi->y / h + ystep; txf->tgvi[i].v0[0] = tgi->xoffset; txf->tgvi[i].v0[1] = tgi->yoffset; txf->tgvi[i].t1[0] = (tgi->x + tgi->width) / w + xstep; txf->tgvi[i].t1[1] = tgi->y / h + ystep; txf->tgvi[i].v1[0] = tgi->xoffset + tgi->width; txf->tgvi[i].v1[1] = tgi->yoffset; txf->tgvi[i].t2[0] = (tgi->x + tgi->width) / w + xstep; txf->tgvi[i].t2[1] = (tgi->y + tgi->height) / h + ystep; txf->tgvi[i].v2[0] = tgi->xoffset + tgi->width; txf->tgvi[i].v2[1] = tgi->yoffset + tgi->height; txf->tgvi[i].t3[0] = tgi->x / w + xstep; txf->tgvi[i].t3[1] = (tgi->y + tgi->height) / h + ystep; txf->tgvi[i].v3[0] = tgi->xoffset; txf->tgvi[i].v3[1] = tgi->yoffset + tgi->height; txf->tgvi[i].advance = tgi->advance; } min_glyph = txf->tgi[0].c; max_glyph = txf->tgi[0].c; for (i = 1; i < txf->num_glyphs; i++) { if (txf->tgi[i].c < min_glyph) { min_glyph = txf->tgi[i].c; } if (txf->tgi[i].c > max_glyph) { max_glyph = txf->tgi[i].c; } } txf->min_glyph = min_glyph; txf->range = max_glyph - min_glyph + 1; txf->lut = (TexGlyphVertexInfo **) calloc(txf->range, sizeof(TexGlyphVertexInfo *)); if (txf->lut == NULL) { lastError = "out of memory."; goto error; } for (i = 0; i < txf->num_glyphs; i++) { txf->lut[txf->tgi[i].c - txf->min_glyph] = &txf->tgvi[i]; } switch (format) { case TXF_FORMAT_BYTE: if (useLuminanceAlpha) { unsigned char *orig; orig = (unsigned char *) malloc(txf->tex_width * txf->tex_height); if (orig == NULL) { lastError = "out of memory."; goto error; } got = fread(orig, 1, txf->tex_width * txf->tex_height, file); EXPECT(txf->tex_width * txf->tex_height); txf->teximage = (unsigned char *) malloc(2 * txf->tex_width * txf->tex_height); if (txf->teximage == NULL) { lastError = "out of memory."; goto error; } for (i = 0; i < txf->tex_width * txf->tex_height; i++) { txf->teximage[i * 2] = orig[i]; txf->teximage[i * 2 + 1] = orig[i]; } free(orig); } else { txf->teximage = (unsigned char *) malloc(txf->tex_width * txf->tex_height); if (txf->teximage == NULL) { lastError = "out of memory."; goto error; } got = fread(txf->teximage, 1, txf->tex_width * txf->tex_height, file); EXPECT(txf->tex_width * txf->tex_height); } break; case TXF_FORMAT_BITMAP: width = txf->tex_width; height = txf->tex_height; stride = (width + 7) >> 3; texbitmap = (unsigned char *) malloc(stride * height); if (texbitmap == NULL) { lastError = "out of memory."; goto error; } got = fread(texbitmap, 1, stride * height, file); EXPECT(stride * height); if (useLuminanceAlpha) { txf->teximage = (unsigned char *) calloc(width * height * 2, 1); if (txf->teximage == NULL) { lastError = "out of memory."; goto error; } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (texbitmap[i * stride + (j >> 3)] & (1 << (j & 7))) { txf->teximage[(i * width + j) * 2] = 255; txf->teximage[(i * width + j) * 2 + 1] = 255; } } } } else { txf->teximage = (unsigned char *) calloc(width * height, 1); if (txf->teximage == NULL) { lastError = "out of memory."; goto error; } for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (texbitmap[i * stride + (j >> 3)] & (1 << (j & 7))) { txf->teximage[i * width + j] = 255; } } } } free(texbitmap); break; }
void nemo_main() { stream instr, outstr; int nx, ny, nz; /* size of scratch map */ int ix, iy, flip; imageptr iptr=NULL; /* pointer to image */ real tmp, zzz; string flipmode; flipmode = getparam("flip"); if (streq(flipmode,"x")) flip = X; else if (streq(flipmode,"y")) flip = Y; else if (streq(flipmode,"xy")) flip = XY; else error("Illegal flip axis"); instr = stropen(getparam("in"), "r"); outstr = stropen(getparam("out"), "w"); read_image( instr, &iptr); nx = Nx(iptr); ny = Ny(iptr); nz = Nz(iptr); if(flip==X) { for (iy=0; iy<ny; iy++) { /* flip in x */ for (ix=0; ix<nx/2; ix++) { tmp = MapValue(iptr,ix,iy); zzz = MapValue(iptr,nx-ix-1,iy); dprintf(1,"%d %d: %f %f\n",ix,iy,tmp,zzz); MapValue(iptr,ix,iy) = MapValue(iptr,nx-ix-1,iy); MapValue(iptr,nx-ix-1,iy) = tmp; } } } else if (flip==Y) { for (iy=0; iy<ny; iy++) { /* flip in y */ for (ix=0; ix<nx/2; ix++) { tmp = MapValue(iptr,iy,ix); zzz = MapValue(iptr,iy,nx-ix-1); dprintf(1,"%d %d: %f %f\n",ix,iy,tmp,zzz); MapValue(iptr,iy,ix) = MapValue(iptr,iy,nx-ix-1); MapValue(iptr,iy,nx-ix-1) = tmp; } } } else if (flip==XY) { for (iy=0; iy<ny; iy++) { /* swap the x and y axes */ for (ix=iy+1; ix<nx; ix++) { tmp = MapValue(iptr,ix,iy); dprintf(1,"%d %d: %f \n",ix,iy,tmp); MapValue(iptr,ix,iy) = MapValue(iptr,iy,ix); MapValue(iptr,iy,ix) = tmp; } } SWAPR(Xmin(iptr), Ymin(iptr)); SWAPR(Dx(iptr), Dy(iptr)); SWAPS(Namex(iptr), Namey(iptr)); } write_image(outstr, iptr); }
texfnt * readtexfont(char *name) { texfnt *tfnt; unsigned *image; unsigned char *cptr; unsigned short *sbuf, *sptr; short advancecell, xadvance; short llx, lly, urx, ury, ox, oy; int i, y, extralines; texchardesc *cd; int xsize, ysize, components; int swap = doSwap(); int tmp; tfnt = (texfnt *) malloc(sizeof(texfnt)); image = read_texture(name, &xsize, &ysize, &components); if (!image) { fprintf(stderr, "textmap: can't open font image %s\n", name); return 0; } extralines = ysize - xsize; if (extralines < 1) { fprintf(stderr, "textmap: bad input font!!\n"); return 0; } fb = (unsigned char *) malloc(xsize * extralines); sbuf = (unsigned short *) malloc(xsize * sizeof(short)); cptr = fb; for (y = xsize; y < ysize; y++) { int x; for (x = 0; x < xsize; x++) cptr[x] = image[y * xsize + x] >> 16; cptr += xsize; } initget(); tfnt->rasxsize = xsize; tfnt->rasysize = xsize; getbytes(&tfnt->charmin, sizeof(short)); getbytes(&tfnt->charmax, sizeof(short)); getbytes(&tfnt->pixhigh, sizeof(float)); getbytes(&advancecell, sizeof(short)); if (swap) { SWAPS(&tfnt->charmin, tmp); SWAPS(&tfnt->charmax, tmp); SWAPL(&tfnt->pixhigh, tmp); SWAPS(&advancecell, tmp); } tfnt->nchars = tfnt->charmax - tfnt->charmin + 1; tfnt->chars = (texchardesc *) malloc(tfnt->nchars * sizeof(texchardesc)); tfnt->rasdata = (unsigned short *) malloc(tfnt->rasxsize * tfnt->rasysize * sizeof(long)); sptr = tfnt->rasdata; for (y = 0; y < tfnt->rasysize; y++) { int x; for (x = 0; x < xsize; x++) sptr[x] = image[y * xsize + x] >> 16; fixrow(sptr, tfnt->rasxsize); sptr += tfnt->rasxsize; } cd = tfnt->chars; for (i = 0; i < tfnt->nchars; i++) { getbytes(&xadvance, sizeof(short)); getbytes(&llx, sizeof(short)); getbytes(&lly, sizeof(short)); getbytes(&urx, sizeof(short)); getbytes(&ury, sizeof(short)); getbytes(&ox, sizeof(short)); getbytes(&oy, sizeof(short)); if (swap) { SWAPS(&xadvance, tmp); SWAPS(&llx, tmp); SWAPS(&lly, tmp); SWAPS(&urx, tmp); SWAPS(&ury, tmp); SWAPS(&ox, tmp); SWAPS(&oy, tmp); } cd->movex = xadvance / (float) advancecell; if (llx >= 0) { cd->haveimage = 1; cd->llx = (llx - ox) / tfnt->pixhigh; cd->lly = (lly - oy) / tfnt->pixhigh; cd->urx = (urx - ox + 1) / tfnt->pixhigh; cd->ury = (ury - oy + 1) / tfnt->pixhigh; cd->tllx = llx / (float) tfnt->rasxsize; cd->tlly = lly / (float) tfnt->rasysize; cd->turx = (urx + 1) / (float) tfnt->rasxsize; cd->tury = (ury + 1) / (float) tfnt->rasysize; cd->data[0] = cd->tllx; cd->data[1] = cd->tlly; cd->data[2] = cd->llx; cd->data[3] = cd->lly; cd->data[4] = cd->turx; cd->data[5] = cd->tlly; cd->data[6] = cd->urx; cd->data[7] = cd->lly; cd->data[8] = cd->turx; cd->data[9] = cd->tury; cd->data[10] = cd->urx; cd->data[11] = cd->ury; cd->data[12] = cd->tllx; cd->data[13] = cd->tury; cd->data[14] = cd->llx; cd->data[15] = cd->ury; cd->data[16] = cd->llx; cd->data[17] = cd->lly; cd->data[18] = cd->urx; cd->data[19] = cd->lly; cd->data[20] = cd->urx; cd->data[21] = cd->ury; cd->data[22] = cd->llx; cd->data[23] = cd->ury; } else { cd->haveimage = 0; } cd++; } free(fb); free(sbuf); free(image); return tfnt; }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // Routine Name: NetFlexCommand // // Description: // This routine looks at the current SSB struct // and places the corresponding request on the // Request Confirm Queue. If the command that // has completed is an open, a receive and // transmit command are issued. // // Input: // acb - Our Driver Context for this adapter or head. // // Output: // None // // Called By: // NetFlexHandleInterrupt // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ VOID NetFlexCommand( PACB acb ) { PSCBREQ scbreq; PMACREQ macreq; PTR_OBJS trobjs; PETH_OBJS ethobjs; SHORT value,i; PUSHORT tempptr; NDIS_STATUS Status; #if (DBG || DBGPRINT) // // I wanted to know if I'm getting bad commands // if (acb->acb_ssb_virtptr->SSB_Cmd == TMS_CMDREJECT) { DebugPrint(0,("NF(%d): Command rejected\n",acb->anum)); DebugPrint(0,("NF(%d): SSB Status %x\n",acb->anum,SWAPS(acb->acb_ssb_virtptr->SSB_Status))); DebugPrint(0,("NF(%d): SSB Ptr %x\n",acb->anum,SWAPL(acb->acb_ssb_virtptr->SSB_Ptr))); } else if (acb->acb_ssb_virtptr->SSB_Status != SSB_GOOD) { DebugPrint(0,("NF(%d): Bad status %x\n",acb->anum,acb->acb_ssb_virtptr->SSB_Status)); DebugPrint(0,("NF(%d): cmd is %x\n",acb->anum,acb->acb_ssb_virtptr->SSB_Cmd)); } #endif // // Get the scb request associated with the completed request. // Status = NetFlexDequeue_TwoPtrQ_Head( (PVOID *)&(acb->acb_scbreq_head), (PVOID *)&(acb->acb_scbreq_tail), (PVOID *)&scbreq ); if (Status != NDIS_STATUS_SUCCESS) { DebugPrint(0,("NF(%d) NetFlexCommand - dequeue scbreq failed!\n",acb->anum)); return; } // // If we have a Macreq to place on the confirm q. Do this now. // macreq = scbreq->req_macreq; if (macreq) { // // If the command had a problem, save the failure reason and // exit out of the routine. Otherwise, save the success code // and see if the completed command is an open or a read error log. // if (acb->acb_ssb_virtptr->SSB_Cmd == TMS_CMDREJECT) { DebugPrint(0,("NF(%d): Command rejected\n",acb->anum)); DebugPrint(0,("NF(%d): SSB Status %x\n",acb->anum,SWAPS(acb->acb_ssb_virtptr->SSB_Status))); DebugPrint(0,("NF(%d): SSB Ptr %x\n",acb->anum,SWAPL(acb->acb_ssb_virtptr->SSB_Ptr))); macreq->req_status = NDIS_STATUS_FAILURE; } else if (acb->acb_ssb_virtptr->SSB_Status != SSB_GOOD) { DebugPrint(0,("NF(%d): Bad status %x\n",acb->anum,acb->acb_ssb_virtptr->SSB_Status)); DebugPrint(0,("NF(%d): cmd is %x\n",acb->anum,acb->acb_ssb_virtptr->SSB_Cmd)); if ((acb->acb_ssb_virtptr->SSB_Cmd == TMS_OPEN) && (acb->acb_ssb_virtptr->SSB_Status & SSB_OPENERR) ) { macreq->req_status = NDIS_STATUS_TOKEN_RING_OPEN_ERROR; macreq->req_info = (PVOID)(acb->acb_ssb_virtptr->SSB_Status >> 8); } else {