char* decode(char* in, char* out, long int offset) { char *err, **bitmap; FILE *fin, *fout; FontType font; unsigned short int loctable[257], col, col2; FontCharInfoType glyph[256]; short i, j,chars; long int mark; /* Prepare for input */ if(!(fin=fopen(in, "rb"))) return "Could not open input file."; /* Seek to specified location */ fseek(fin, offset, SEEK_SET); /* Load the font header */ fread(&font, sizeof(FontType), 1, fin); /* Get this placeholder for calculating owTLoc */ mark=ftell(fin) - 10; /* Convert header to local machine byte order */ font.fontType = ptoh(font.fontType); font.firstChar = ptoh(font.firstChar); font.lastChar = ptoh(font.lastChar); font.maxWidth = ptoh(font.maxWidth); font.kernMax = ptoh(font.kernMax); font.nDescent = ptoh(font.nDescent); font.fRectWidth = ptoh(font.fRectWidth); font.fRectHeight = ptoh(font.fRectHeight); font.owTLoc = ptoh(font.owTLoc); font.ascent = ptoh(font.ascent); font.descent = ptoh(font.descent); font.leading = ptoh(font.leading); font.rowWords = ptoh(font.rowWords); /* How many characters */ chars = font.lastChar - font.firstChar + 1; /* Load the bitmap image */ bitmap=(void*)malloc(font.fRectHeight*sizeof(void*)); for(i=0;i<font.fRectHeight;i++) { bitmap[i]=(void*)malloc(font.rowWords*2); fread(bitmap[i], font.rowWords*2, 1, fin); } /* Load the column table */ fread(&loctable[font.firstChar], sizeof(unsigned short int) * (chars+1), 1 ,fin); /* Seek to owTLoc */ fseek(fin, mark + font.owTLoc * 2, SEEK_SET); /* Load the offset/width table */ fread(&glyph[font.firstChar], sizeof(FontCharInfoType) * chars, 1, fin); /* Finished loading */ fclose(fin); /* Prepare for output */ if(!(fout=fopen(out, "w"))) return "Could not open output file."; /* Output the header */ fprintf(fout, "fontType %hu\n"\ "maxWidth %hd\n"\ "kernMax %hd\n"\ "nDescent %hd\n"\ "fRectWidth %hd\n"\ "fRectHeight %hd\n"\ "ascent %hd\n"\ "descent %hd\n"\ "leading %hd\n\n", font.fontType, font.maxWidth, font.kernMax, font.nDescent, font.fRectWidth, font.fRectHeight, font.ascent, font.descent, font.leading); /* Output the glyphs */ i=font.firstChar; while(i<=font.lastChar) { col=ptoh(loctable[i]); col2=ptoh(loctable[i+1]); if(col<col2) { if(i>32 && i!=39 && i!=92 && i<127) fprintf(fout, "GLYPH '%c'\n",i); else fprintf(fout, "GLYPH %d\n", i); if(glyph[i].width != col2-col) fprintf(fout, "WIDTH %d\n", glyph[i].width); if(glyph[i].offset) fprintf(fout, "OFFSET %d\n", glyph[i].offset); for(j=0;j<font.fRectHeight;j++) { for(col=ptoh(loctable[i]);col<col2;col++) { if(bitmap[j][col>>3] & bit[col&0x7]) fputc('#', fout); else fputc('-', fout); } fprintf(fout, "\n"); } fprintf(fout, "\n"); } i++; }
int clnt_rdma_kcreate(char *proto, void *handle, struct netbuf *raddr, int family, rpcprog_t pgm, rpcvers_t vers, struct cred *cred, CLIENT **cl) { CLIENT *h; struct cku_private *p; struct rpc_msg call_msg; rdma_registry_t *rp; ASSERT(INGLOBALZONE(curproc)); if (cl == NULL) return (EINVAL); *cl = NULL; p = kmem_zalloc(sizeof (*p), KM_SLEEP); /* * Find underlying RDMATF plugin */ rw_enter(&rdma_lock, RW_READER); rp = rdma_mod_head; while (rp != NULL) { if (strcmp(rp->r_mod->rdma_api, proto)) rp = rp->r_next; else { p->cku_rd_mod = rp->r_mod; p->cku_rd_handle = handle; break; } } rw_exit(&rdma_lock); if (p->cku_rd_mod == NULL) { /* * Should not happen. * No matching RDMATF plugin. */ kmem_free(p, sizeof (struct cku_private)); return (EINVAL); } h = ptoh(p); h->cl_ops = &rdma_clnt_ops; h->cl_private = (caddr_t)p; h->cl_auth = authkern_create(); /* call message, just used to pre-serialize below */ call_msg.rm_xid = 0; call_msg.rm_direction = CALL; call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; call_msg.rm_call.cb_prog = pgm; call_msg.rm_call.cb_vers = vers; xdrmem_create(&p->cku_outxdr, p->cku_rpchdr, CKU_HDRSIZE, XDR_ENCODE); /* pre-serialize call message header */ if (!xdr_callhdr(&p->cku_outxdr, &call_msg)) { XDR_DESTROY(&p->cku_outxdr); auth_destroy(h->cl_auth); kmem_free(p, sizeof (struct cku_private)); return (EINVAL); } /* * Set up the rpc information */ p->cku_cred = cred; p->cku_srcaddr.buf = kmem_zalloc(raddr->maxlen, KM_SLEEP); p->cku_srcaddr.maxlen = raddr->maxlen; p->cku_srcaddr.len = 0; p->cku_addr.buf = kmem_zalloc(raddr->maxlen, KM_SLEEP); p->cku_addr.maxlen = raddr->maxlen; p->cku_addr.len = raddr->len; bcopy(raddr->buf, p->cku_addr.buf, raddr->len); p->cku_addrfmly = family; *cl = h; return (0); }