unsigned long proc9p(unsigned char *msg, unsigned long size, Callbacks *cb) { Fcall ifcall; Fcall *ofcall = NULL; unsigned long slen; unsigned long index; unsigned char i; index = 4; ifcall.type = msg[index++]; get2(msg, index, ifcall.tag); if (size > MAX_MSG) { strcpy_P(pgmbuf, Etoobig); index = mkerr(msg, ifcall.tag, pgmbuf); goto END; } // if it isn't here, it isn't implemented switch(ifcall.type) { case TVersion: i = index; index = 7; get4(msg, i, ifcall.msize); get2(msg, i, slen); if (ifcall.msize > MAX_MSG) ifcall.msize = MAX_MSG; put4(msg, index, ifcall.msize); put2(msg, index, slen); index += slen; puthdr(msg, 0, RVersion, ifcall.tag, index); break; case TAttach: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.afid); get2(msg, index, slen); ifcall.uname = (char*)&msg[index]; index += slen; get2(msg, index, slen); msg[index-2] = '\0'; ifcall.aname = (char*)&msg[index]; index += slen; msg[index-2] = '\0'; ofcall = cb->attach(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = 7; msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); puthdr(msg, 0, RAttach, ifcall.tag, index); break; case TWalk: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.newfid); get2(msg, index, ifcall.nwname); if (ifcall.nwname > MAX_WELEM) ifcall.nwname = MAX_WELEM; for (i = 0; i < ifcall.nwname; i++) { get2(msg, index, slen); msg[index-2] = '\0'; ifcall.wname[i] = (char*)&msg[index]; index += slen; } msg[index] = '\0'; ofcall = cb->walk(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RWalk, ifcall.tag, 9 + ofcall->nwqid * 13); put2(msg, index, ofcall->nwqid); for (i = 0; i < ofcall->nwqid; i++) { msg[index++] = ofcall->wqid[i].type; put4(msg, index, ofcall->wqid[i].version); put8(msg, index, ofcall->wqid[i].path, 0); } break; case TStat: get4(msg, index, ifcall.fid); ofcall = cb->stat(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } slen = putstat(msg, 9, &(ofcall->stat)); index = puthdr(msg, 0, RStat, ifcall.tag, slen + 9); put2(msg, index, slen); // bleh? index += slen; break; case TClunk: get4(msg, index, ifcall.fid); ofcall = cb->clunk(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RClunk, ifcall.tag, 7); break; case TOpen: get4(msg, index, ifcall.fid); ifcall.mode = msg[index++]; ofcall = cb->open(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, ROpen, ifcall.tag, 24); msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); put4(msg, index, MAX_IO); break; case TRead: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.offset); index += 4; // :( get4(msg, index, ifcall.count); ofcall = cb->read(&ifcall, &msg[11]); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } // No response if (ofcall == NULL) { index = 0; goto END; } index = puthdr(msg, 0, RRead, ifcall.tag, 11 + ofcall->count); put4(msg, index, ofcall->count); index += ofcall->count; break; case TCreate: get4(msg, index, ifcall.fid); get2(msg, index, slen); ifcall.name = (char*)&msg[index]; index += slen; get4(msg, index, ifcall.perm); msg[index-4] = '\0'; ifcall.mode = msg[index++]; ofcall = cb->create(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RCreate, ifcall.tag, 24); msg[index++] = ofcall->qid.type; put4(msg, index, ofcall->qid.version); put8(msg, index, ofcall->qid.path, 0); put4(msg, index, MAX_IO); break; case TWrite: get4(msg, index, ifcall.fid); get4(msg, index, ifcall.offset); index += 4; // bleh... again get4(msg, index, ifcall.count); ofcall = cb->write(&ifcall, &msg[index]); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RWrite, ifcall.tag, 11); put4(msg, index, ofcall->count); break; case TRemove: get4(msg, index, ifcall.fid); ofcall = cb->remove(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RRemove, ifcall.tag, 7); break; case TFlush: get2(msg, index, ifcall.oldtag); ofcall = cb->flush(&ifcall); if (ofcall->type == RError) { index = mkerr(msg, ifcall.tag, ofcall->ename); goto END; } index = puthdr(msg, 0, RFlush, ifcall.tag, 7); break; default: strcpy_P(pgmbuf, Ebadtype); index = mkerr(msg, ifcall.tag, pgmbuf); break; } END: if (index > MAX_MSG) { strcpy_P(pgmbuf, Etoobig); index = mkerr(msg, ifcall.tag, pgmbuf); } return index; }
uint64_t get5(const uint8_t *p) { return get4(p) | (get1(p + 4) << 32); }
TPage loadSNX(QString fname, int cpage) { TPage page; QFile file(fname); if (!file.open(QFile::ReadOnly)) return page; TLine line; line.type = TL_TEXT; QTextCodec* codec = QTextCodec::codecForName("Shift-JIS"); int count = get4(file); int p1 = get4(file); int p2,p3; int len; long dataPos = count * 12 + 8; long curPos = 0; // long adr = 0; char buf[1024]; char cbuf[1024]; char* sptr; char* dptr; // if (dump) printf("; bytecode\n\n"); while (count > 0) { p1 = get4(file); p2 = get4(file); p3 = get4(file); if ((p1 == 0x11) && (p2 == 0x02)) { curPos = file.pos(); file.seek(dataPos + p3); len = get4(file); file.read(buf,len); file.seek(curPos); sptr = buf; dptr = buf; if (*sptr == 0x01) { sptr += 3; } while(1) { if ((*sptr > 0x00) && (*sptr < 0x04)) { sptr++; } else { *dptr = *sptr; if (*dptr == 0x00) break; dptr++; sptr++; } } } if (p1 == 0x0d) { if (p2 == 0x012) { sprintf(cbuf,"[ %s ]",buf); //fwrite(cbuf,strlen(cbuf),1,ofile); line.src.name.clear(); line.src.text = codec->toUnicode(cbuf); page.text.append(line); } else if (p2 == 0x2c) { sprintf(cbuf,"%s\n",buf); //fwrite(cbuf,strlen(cbuf),1,ofile); line.src.name.clear(); line.src.text = codec->toUnicode(buf); normLine(line); page.text.append(line); } } // if (dump) printf("\n"); count--; } return page; }