more internal buffering
This commit is contained in:
parent
99cae8d6df
commit
e9d477fd6e
|
@ -2,7 +2,7 @@
|
||||||
.ad
|
.ad
|
||||||
.SH NAME
|
.SH NAME
|
||||||
wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo,
|
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_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_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
|
rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd\ \-\ routines to read
|
||||||
|
@ -82,8 +82,6 @@ and write ACK-object files and libraries
|
||||||
.br
|
.br
|
||||||
.B long l;
|
.B long l;
|
||||||
.PP
|
.PP
|
||||||
.B int wr_fd()
|
|
||||||
.PP
|
|
||||||
.B int rd_open(filename)
|
.B int rd_open(filename)
|
||||||
.br
|
.br
|
||||||
.B char *filename;
|
.B char *filename;
|
||||||
|
@ -261,9 +259,6 @@ bytes from
|
||||||
to file descriptor
|
to file descriptor
|
||||||
.IB fd .
|
.IB fd .
|
||||||
.PP
|
.PP
|
||||||
.I Wr_fd
|
|
||||||
returns the current output file descriptor.
|
|
||||||
.PP
|
|
||||||
Most of the
|
Most of the
|
||||||
.I rd_
|
.I rd_
|
||||||
routines are the opposite of the
|
routines are the opposite of the
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#define put4(l, c) (* ((long *) (c)) = (l))
|
#define put4(l, c) (* ((long *) (c)) = (l))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SECTCNT 3 /* number of sections with own output buffer */
|
||||||
#if BIGMACHINE
|
#if BIGMACHINE
|
||||||
#define WBUFSIZ (8*BUFSIZ)
|
#define WBUFSIZ (8*BUFSIZ)
|
||||||
#else
|
#else
|
||||||
|
@ -55,17 +56,15 @@ struct fil {
|
||||||
|
|
||||||
extern struct fil __parts[];
|
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 PARTEMIT 0
|
||||||
#define PARTRELO 1
|
#define PARTRELO (PARTEMIT+SECTCNT)
|
||||||
#define PARTNAME 2
|
#define PARTNAME (PARTRELO+1)
|
||||||
#define PARTCHAR 3
|
#define PARTCHAR (PARTNAME+1)
|
||||||
#ifdef SYMDBUG
|
#ifdef SYMDBUG
|
||||||
#define PARTDBUG 4
|
#define PARTDBUG (PARTCHAR+1)
|
||||||
#else
|
#else
|
||||||
#define PARTDBUG 3
|
#define PARTDBUG (PARTCHAR+0)
|
||||||
#endif
|
#endif
|
||||||
#define NPARTS (PARTDBUG + 1)
|
#define NPARTS (PARTDBUG + 1)
|
||||||
|
|
||||||
|
#define getsect(s) (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))
|
||||||
|
|
|
@ -11,6 +11,13 @@ extern long lseek();
|
||||||
/*
|
/*
|
||||||
* Parts of the output file.
|
* Parts of the output file.
|
||||||
*/
|
*/
|
||||||
|
#undef PARTEMIT
|
||||||
|
#undef PARTRELO
|
||||||
|
#undef PARTNAME
|
||||||
|
#undef PARTCHAR
|
||||||
|
#undef PARTDBUG
|
||||||
|
#undef NPARTS
|
||||||
|
|
||||||
#define PARTEMIT 0
|
#define PARTEMIT 0
|
||||||
#define PARTRELO 1
|
#define PARTRELO 1
|
||||||
#define PARTNAME 2
|
#define PARTNAME 2
|
||||||
|
|
|
@ -26,7 +26,8 @@ struct fil __parts[NPARTS];
|
||||||
static int outfile;
|
static int outfile;
|
||||||
static long currpos;
|
static long currpos;
|
||||||
#endif
|
#endif
|
||||||
static int sectionnr;
|
int __sectionnr;
|
||||||
|
#define sectionnr __sectionnr
|
||||||
static int offcnt;
|
static int offcnt;
|
||||||
|
|
||||||
__wr_flush(ptr)
|
__wr_flush(ptr)
|
||||||
|
@ -40,7 +41,7 @@ __wr_flush(ptr)
|
||||||
#endif
|
#endif
|
||||||
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
|
wr_bytes(ptr->fd, ptr->pbegin, (long)(ptr->pnow - ptr->pbegin));
|
||||||
ptr->currpos += ptr->pnow - ptr->pbegin;
|
ptr->currpos += ptr->pnow - ptr->pbegin;
|
||||||
if (ptr == &__parts[PARTEMIT]) {
|
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
|
||||||
offset[sectionnr] = ptr->currpos;
|
offset[sectionnr] = ptr->currpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +71,7 @@ static OUTWRITE(p, b, n)
|
||||||
n -= i;
|
n -= i;
|
||||||
b += i;
|
b += i;
|
||||||
ptr->currpos += i;
|
ptr->currpos += i;
|
||||||
if (ptr == &__parts[PARTEMIT]) {
|
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
|
||||||
offset[sectionnr] = ptr->currpos;
|
offset[sectionnr] = ptr->currpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ static OUTWRITE(p, b, n)
|
||||||
b += m;
|
b += m;
|
||||||
n &= WBUFSIZ - 1;
|
n &= WBUFSIZ - 1;
|
||||||
ptr->currpos += m;
|
ptr->currpos += m;
|
||||||
if (ptr == &__parts[PARTEMIT]) {
|
if (ptr < &__parts[PARTEMIT+SECTCNT]) {
|
||||||
offset[sectionnr] = ptr->currpos;
|
offset[sectionnr] = ptr->currpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,6 +127,8 @@ static BEGINSEEK(p, o)
|
||||||
#else
|
#else
|
||||||
ptr->currpos = lseek(ptr->fd, o, 0);
|
ptr->currpos = lseek(ptr->fd, o, 0);
|
||||||
#endif
|
#endif
|
||||||
|
if (p >= PARTRELO) o = 0; /* no attempt to align writes
|
||||||
|
for the time being */
|
||||||
ptr->cnt = WBUFSIZ - ((int)o & (WBUFSIZ-1));
|
ptr->cnt = WBUFSIZ - ((int)o & (WBUFSIZ-1));
|
||||||
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
|
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
|
||||||
ptr->pnow = ptr->pbegin;
|
ptr->pnow = ptr->pbegin;
|
||||||
|
@ -172,15 +175,6 @@ wr_close()
|
||||||
#endif /* OUTSEEK */
|
#endif /* OUTSEEK */
|
||||||
}
|
}
|
||||||
|
|
||||||
wr_fd()
|
|
||||||
{
|
|
||||||
#ifdef OUTSEEK
|
|
||||||
return outfile;
|
|
||||||
#else
|
|
||||||
return __parts[PARTEMIT].fd;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
wr_ohead(head)
|
wr_ohead(head)
|
||||||
register struct outhead *head;
|
register struct outhead *head;
|
||||||
{
|
{
|
||||||
|
@ -239,6 +233,9 @@ wr_sect(sect, cnt1)
|
||||||
put4(sect->os_size, c); c += 4;
|
put4(sect->os_size, c); c += 4;
|
||||||
put4(sect->os_foff, 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;
|
offset[offcnt++] = sect->os_foff;
|
||||||
#if ! (BYTES_REVERSED || WORDS_REVERSED)
|
#if ! (BYTES_REVERSED || WORDS_REVERSED)
|
||||||
if (sizeof(struct outsect) != SZ_SECT)
|
if (sizeof(struct outsect) != SZ_SECT)
|
||||||
|
@ -262,10 +259,9 @@ wr_sect(sect, cnt1)
|
||||||
wr_outsect(s)
|
wr_outsect(s)
|
||||||
int s; /* section number */
|
int s; /* section number */
|
||||||
{
|
{
|
||||||
register struct fil *ptr = &__parts[PARTEMIT];
|
register struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
|
||||||
|
|
||||||
if (s != sectionnr &&
|
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
|
||||||
offset[s] != ptr->currpos + (ptr->pnow - ptr->pbegin)) {
|
|
||||||
#ifdef OUTSEEK
|
#ifdef OUTSEEK
|
||||||
if (currpos != ptr->currpos)
|
if (currpos != ptr->currpos)
|
||||||
currpos = lseek(ptr->fd, ptr->currpos, 0);
|
currpos = lseek(ptr->fd, ptr->currpos, 0);
|
||||||
|
@ -276,7 +272,9 @@ wr_outsect(s)
|
||||||
#endif
|
#endif
|
||||||
ptr->currpos += ptr->pnow - ptr->pbegin;
|
ptr->currpos += ptr->pnow - ptr->pbegin;
|
||||||
offset[sectionnr] = ptr->currpos;
|
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->cnt = WBUFSIZ - ((int)offset[s] & (WBUFSIZ-1));
|
||||||
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
|
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
|
||||||
ptr->pnow = ptr->pbegin;
|
ptr->pnow = ptr->pbegin;
|
||||||
|
@ -291,7 +289,7 @@ wr_emit(emit, cnt)
|
||||||
char *emit;
|
char *emit;
|
||||||
long cnt;
|
long cnt;
|
||||||
{
|
{
|
||||||
OUTWRITE(PARTEMIT, emit, cnt);
|
OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
wr_relo(relo, cnt)
|
wr_relo(relo, cnt)
|
||||||
|
|
|
@ -5,7 +5,12 @@
|
||||||
*/
|
*/
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
|
extern int __sectionnr;
|
||||||
|
|
||||||
wr_putc(ch)
|
wr_putc(ch)
|
||||||
{
|
{
|
||||||
OUTBYTE(PARTEMIT, ch);
|
register struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
|
||||||
|
|
||||||
|
if (ptr->cnt == 0) __wr_flush(ptr);
|
||||||
|
ptr->cnt--; *ptr->pnow++ = ch;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue