.ad
.SH NAME
wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo,
-wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes, wr_fd,
+wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes,
rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect,
rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib,
rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd\ \-\ routines to read
.br
.B long l;
.PP
-.B int wr_fd()
-.PP
.B int rd_open(filename)
.br
.B char *filename;
to file descriptor
.IB fd .
.PP
-.I Wr_fd
-returns the current output file descriptor.
-.PP
Most of the
.I rd_
routines are the opposite of the
#define put4(l, c) (* ((long *) (c)) = (l))
#endif
+#define SECTCNT 3 /* number of sections with own output buffer */
#if BIGMACHINE
#define WBUFSIZ (8*BUFSIZ)
#else
extern struct fil __parts[];
-#define OUTBYTE(p, b) {if (__parts[p].cnt == 0) __wr_flush(&__parts[p]);\
- __parts[p].cnt--; *__parts[p].pnow++ = (b);}
-
#define PARTEMIT 0
-#define PARTRELO 1
-#define PARTNAME 2
-#define PARTCHAR 3
+#define PARTRELO (PARTEMIT+SECTCNT)
+#define PARTNAME (PARTRELO+1)
+#define PARTCHAR (PARTNAME+1)
#ifdef SYMDBUG
-#define PARTDBUG 4
+#define PARTDBUG (PARTCHAR+1)
#else
-#define PARTDBUG 3
+#define PARTDBUG (PARTCHAR+0)
#endif
#define NPARTS (PARTDBUG + 1)
+#define getsect(s) (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))
static int outfile;
static long currpos;
#endif
-static int sectionnr;
+int __sectionnr;
+#define sectionnr __sectionnr
static int offcnt;
__wr_flush(ptr)
#endif
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
ptr->currpos += ptr->pnow - ptr->pbegin;
- if (ptr == &__parts[PARTEMIT]) {
+ if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
n -= i;
b += i;
ptr->currpos += i;
- if (ptr == &__parts[PARTEMIT]) {
+ if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
b += m;
n &= WBUFSIZ - 1;
ptr->currpos += m;
- if (ptr == &__parts[PARTEMIT]) {
+ if (ptr < &__parts[PARTEMIT+SECTCNT]) {
offset[sectionnr] = ptr->currpos;
}
}
#else
ptr->currpos = lseek(ptr->fd, o, 0);
#endif
+ if (p >= PARTRELO) o = 0; /* no attempt to align writes
+ for the time being */
ptr->cnt = WBUFSIZ - ((int)o & (WBUFSIZ-1));
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
ptr->pnow = ptr->pbegin;
#endif /* OUTSEEK */
}
-wr_fd()
-{
-#ifdef OUTSEEK
- return outfile;
-#else
- return __parts[PARTEMIT].fd;
-#endif
-}
-
wr_ohead(head)
register struct outhead *head;
{
put4(sect->os_size, c); c += 4;
put4(sect->os_foff, c); c += 4;
}
+ if (offcnt >= 1 && offcnt < SECTCNT) {
+ BEGINSEEK(PARTEMIT+offcnt, sect->os_foff);
+ }
offset[offcnt++] = sect->os_foff;
#if ! (BYTES_REVERSED || WORDS_REVERSED)
if (sizeof(struct outsect) != SZ_SECT)
wr_outsect(s)
int s; /* section number */
{
- register struct fil *ptr = &__parts[PARTEMIT];
+ register struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
- if (s != sectionnr &&
- offset[s] != ptr->currpos + (ptr->pnow - ptr->pbegin)) {
+ if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
#ifdef OUTSEEK
if (currpos != ptr->currpos)
currpos = lseek(ptr->fd, ptr->currpos, 0);
#endif
ptr->currpos += ptr->pnow - ptr->pbegin;
offset[sectionnr] = ptr->currpos;
- ptr->currpos = lseek(ptr->fd, offset[s], 0);
+ if (offset[s] != ptr->currpos) {
+ ptr->currpos = lseek(ptr->fd, offset[s], 0);
+ }
ptr->cnt = WBUFSIZ - ((int)offset[s] & (WBUFSIZ-1));
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
ptr->pnow = ptr->pbegin;
char *emit;
long cnt;
{
- OUTWRITE(PARTEMIT, emit, cnt);
+ OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt);
}
wr_relo(relo, cnt)