📄 stio.c
字号:
ilineMax = ppd[ipd1].iline; ln = ppd->lnLow; for (iline = ppd->iline; iline < ilineMax;) { count = *pline & 0x0f; clinedelta = *pline++ >> 4; if (clinedelta == -8) { linedelta = (*pline << 8) | (pline[1] & 0xff); pline += 2; ln += linedelta; } else { ln += clinedelta; } /* if */ for (; count >= 0; count --) pcfd->pline[iline++] = ln; } /* for */ } /* for */ } /* for */ st_pchdr->flags |= flags; return (0);} /* st_readst */static st_read (fd, ordered, offset, ptr, size)FILE *fd;int offset;char *ptr;int size;int ordered;{ /* seek to correct location if need and read */ if (size == 0) return (0); if (!ordered) { if (lseek (fd, offset, 0) != offset) { st_warning ("st_read: error seeking\n"); return (-5); } /* if */ } /* if */ if (read (fd, (char *) ptr, size) != size) { st_warning ("st_read: error reading\n"); return (-6); } /* if */ return (0);} /* st_read */export void st_writebinary (filename, flags)int flags;char * filename; /* file to put it out to */{ int fn; fn = open (filename, O_CREAT|O_RDWR, 0666); if (fn < 0) { st_error ("cannot open symbol table file %s\n", filename); } /* if */ st_writest (fn, flags); close (fn);} /* writebinary *//* macro to write fields of the file descriptor table */#define ipdBase ipdFirst#define irfdMax crfd#define irfdBase rfdBasechar msg_werr[] = "cannot write pfield";#define WRITE(B,M,cf,pf) \ cbOffset += cbtotal, cbtotal=0; \ for (ifd =0; ifd<ifdmax; ifd++) { \ pcfd=st_pcfd_ifd(ifd); pfd = pcfd->pfd; pfd->B=fd.B+fd.cf;\ cbtotal += cb = pfd->cf*sizeof(*pcfd->pf); \ if (pfd->cf && fwrite((char *)(pcfd->pf),\ sizeof(*pcfd->pf),pfd->cf,file) != pfd->cf) st_error(msg_werr); \ fd.B=fd.B+fd.cf; hdr.M += fd.cf = pfd->cf; }#define ROUNDIT(table) \ if ((((unsigned)-cbtotal)&3) != 0) { \ if (fwrite(zero, 1, (((unsigned)-cbtotal)&3), file) != (((unsigned)-cbtotal)&3)) \ st_error("cannot write round bytes for table\n"); \ cbtotal = (cbtotal + 3) & ~3; \ } /* if */ char msg_err[] = "cannot write cur table\n";#define WRITEIT(M,Of,cu,pu) \ hdr.M=st_pchdr->cu; cbOffset += cbtotal; cbtotal=0; \ if (hdr.M) { \ cbtotal=st_pchdr->cu * sizeof(*st_pchdr->pu); hdr.Of=cbOffset; \ if(st_pchdr->cu && fwrite((char *)(st_pchdr->pu),sizeof(*st_pchdr->pu),st_pchdr->cu,file)!=st_pchdr->cu) \ st_error(msg_err); }export void st_writest (fn, flags)int flags;int fn;{ /* dump the symbol table in binary */ static char zero[4]; /* permanent zero buf for rounding */ pCFDR pcfd; FDR fd; pFDR pfd; HDRR hdr; int cb; /* count bytes for current file's table */ int cbtotal; /* count bytes for all file's table */ int cbOffset; /* current file offset */ int ifd; int ifdmax; int hdroffset; /* offset for hdr in file */ FILE *file; /* initialize stuff */ cbtotal = 0; bzero (&fd, cbFDR); bzero (&hdr, cbHDRR); ifdmax = st_ifdmax(); hdroffset = lseek (fn, 0, 1); cbOffset = lseek (fn, cbHDRR, 1); st_pchdr->cfd = ifdmax; file = fdopen (fn, "w"); if (file == NULL) st_error("st_writest: cannot write to file number %d\n", fn); if (flags & ST_PLINES) { int ipd; int ipd1; int ilineMax; pPDR ppd; cbtotal = 0; for (ifd = 0; ifd < ifdmax; ifd++) { cb = 0; /* count of bytes for the file */ pcfd = st_pcfd_ifd (ifd); pfd = pcfd->pfd; if (pfd->cline == 0 || pcfd->pline == 0) continue; hdr.ilineMax += pfd->cline; pfd->cbLineOffset = cbtotal; /* loop through each procedure, pack the info as speced in * the read routine. */ for (ipd = 0; ipd < pfd->cpd; ipd++) { short linedelta; /* current linedelta */ int sign; /* hold the sign bit */ short olinedelta = 0; /* last line delta */ char clinedelta; /* char version of olinedelta */ int ln; /* current line */ int count; /* count of same lines in a row */ pLINER pline; /* point to in memory line array */ char buf [128]; /* buffer to pack lines */ char *pbuf; /* traverse buf with this */ ppd = pcfd->ppd + ipd; if (ppd->iline == ilineNil || ppd->lnLow == -1 || ppd->lnHigh == -1) continue; ppd->cbLineOffset = cbtotal - pfd->cbLineOffset; /* get the iline from thext proc to bound the number of line * entries we deal with. */ ipd1 = 1;next: if (ipd + ipd1 >= pfd->cpd) ilineMax = pcfd->pfd->cline; else if (ppd[ipd1].iline == -1 || (ppd[ipd1].lnHigh == -1 && ppd[ipd1].lnLow != -1)) { ipd1++; goto next; } else ilineMax = ppd[ipd1].iline; if (ilineMax <= 0 || ppd->iline < 0) continue; pline = &pcfd->pline[ppd->iline]; ln = ppd->lnLow; count = -1; olinedelta = 0; for (pbuf = buf; pline <= pcfd->pline + ilineMax; pline++) { /* check if we have room in the buffer */ if (pline == pcfd->pline + ilineMax) /* last time through just to force out the last lines */ linedelta = 1; else linedelta = (*pline == 0 ? ppd->lnLow : *pline) - ln; if (linedelta != 0 || count == ST_LNCOUNTMAX) { sign = olinedelta >= 0 ? 0 : 1; if (count != -1 && olinedelta >= -7 && olinedelta < 8) { clinedelta = olinedelta; *pbuf++ = (clinedelta << 4) | count; } else if (count != -1) { *pbuf = count; *pbuf++ |= 0x80; *pbuf++ = olinedelta >> 8; *pbuf++ = olinedelta & 0xff; } /* if */ count = 0; olinedelta = linedelta; ln += linedelta; } else { count++; } /* if */ if (pbuf + 3 >= &buf[sizeof(buf)] || (pline == pcfd->pline + ilineMax && pbuf - buf > 0)) { fwrite (buf, pbuf - buf, sizeof(char), file); cbtotal += pbuf - buf; cb += pbuf - buf; pbuf = buf; } /* if */ } /* foreach line in a proc */ } /* for each proc */ pfd->cbLine = cb; } /* for each file */ if (hdr.ilineMax) { ROUNDIT(lines); hdr.cbLineOffset = cbOffset; hdr.cbLine = cbtotal; } /* if */ } /* if */ if (flags & ST_PPDS) { WRITE(ipdBase,ipdMax,cpd,ppd); if (hdr.ipdMax) hdr.cbPdOffset = cbOffset; } /* if */ if (flags & ST_PSYMS) { WRITE(isymBase,isymMax,csym,psym); if (hdr.isymMax) hdr.cbSymOffset = cbOffset; } /* if */ if (flags & ST_POPTS) { WRITE(ioptBase,ioptMax,copt,popt); if (hdr.ioptMax) hdr.cbOptOffset = cbOffset; } /* if */ if (flags & ST_PAUXS) { WRITE(iauxBase,iauxMax,caux,paux); if (hdr.iauxMax) hdr.cbAuxOffset = cbOffset; } /* if */ if (flags & ST_PSSS) { WRITE (issBase,issMax,cbSs,pss); /* round */ ROUNDIT(strings); hdr.issMax = cbtotal; if (hdr.issMax) hdr.cbSsOffset = cbOffset; } /* if */ if (flags & ST_PSSEXTS) { WRITEIT (issExtMax,cbSsExtOffset,cbssext,pssExt); /* round */ ROUNDIT(strings); hdr.issExtMax = cbtotal; } /* if */ if (flags & ST_PFDS) { WRITEIT (ifdMax,cbFdOffset,cfd,pfd); } /* if */ if (flags & ST_PRFDS) { WRITE(irfdBase,irfdMax,crfd,prfd); if (hdr.crfd) hdr.cbRfdOffset = cbOffset; } /* if */ /* write out externals */ if (flags & ST_PEXTS) { WRITEIT (iextMax,cbExtOffset,cext,pext); } /* if */ if ((flags & ST_PDNS) && st_pchdr->cdn != 0) { st_pchdr->pdn[0].rfd = 0; st_pchdr->pdn[0].index = 0; st_pchdr->pdn[1].rfd = 0; st_pchdr->pdn[1].index = 0; WRITEIT (idnMax,cbDnOffset,cdn,pdn); } /* if */ /* go back and write the header */ fflush (file); fseek (file, hdroffset, 0); hdr.vstamp = VALIDSTAMP; hdr.magic = magicSym; if (fwrite ((char *)&hdr, 1, cbHDRR, file) != cbHDRR) st_error ("cannot write symbol header\n"); fflush (file); /* NOW a KLUDGE, there is no libc call to free a stdio iop structure * so until, we get fdclose, here it is. */ memset(file, 0, sizeof(*file));} /* st_writebinary */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -