rename rd_long/wr_long to rd_int4/wr_int4 for consistency. Align declaration and definition name of parameters and adapt man page accordingly.

This commit is contained in:
carl 2019-05-11 01:03:36 +08:00
parent bb6540c5f4
commit ccfd8a3e18
9 changed files with 87 additions and 95 deletions

View file

@ -5,7 +5,7 @@ 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,
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
rd_int2, rd_unsigned2, rd_int4, rd_bytes, rd_fd\ \-\ routines to read
and write ACK-object files and libraries
.SH SYNOPSIS
.B #include <out.h>
@ -16,25 +16,25 @@ and write ACK-object files and libraries
.br
.B #include <object.h>
.PP
.B FILE* wr_open(const char *filename)
.B int wr_open(const char *filename)
.PP
.B void wr_close()
.B void wr_close(void)
.PP
.B void wr_ohead(struct outhead *head)
.B void wr_ohead(const struct outhead *head)
.PP
.B void wr_sect(struct outsect *sect, unsigned int cnt)
.B void wr_sect(const struct outsect *sect, unsigned int cnt)
.PP
.B void wr_outsect(int sectionnr)
.B void wr_outsect(int sectno)
.PP
.B void wr_emit(const char *emit, long cnt)
.PP
.B void wr_putc(int ch)
.B void wr_putc(int c)
.PP
.B void wr_relo(const struct outrelo *relo, unsigned int cnt)
.PP
.B void wr_name(struct outname *name, unsigned int cnt)
.B void wr_name(const struct outname *name, unsigned int cnt)
.PP
.B void wr_string(const char *stringaddr, long cnt)
.B void wr_string(const char *addr, long len)
.PP
.B void wr_arhdr(FILE* fd, struct ar_hdr *arhdr)
.PP
@ -44,25 +44,25 @@ and write ACK-object files and libraries
.PP
.B void wr_long(FILE* fd, long l)
.PP
.B void wr_bytes(FILE* fd, const char* buf, long l)
.B void wr_bytes(FILE* fd, const char* buf, long cnt)
.PP
.B int rd_open(const char *filename)
.PP
.B int rd_fdopen(FILE* fd)
.PP
.B void rd_close()
.B void rd_close(void)
.PP
.B void rd_ohead(struct outhead *head)
.PP
.B void rd_sect(struct outsect *sect, unsigned int cnt)
.PP
.B void rd_outsect(int sectionnr)
.B void rd_outsect(int sectno)
.PP
.B void rd_emit(char *emit, long cnt)
.PP
.B void rd_relo(struct outrelo *relo, unsigned int cnt)
.PP
.B void rd_rew_relo(struct outhead *head)
.B void rd_rew_relos(struct outhead *head)
.PP
.B void rd_name(struct outname *name, unsigned int cnt)
.PP
@ -76,86 +76,86 @@ and write ACK-object files and libraries
.PP
.B unsigned int rd_unsigned2(FILE* fd)
.PP
.B long rd_long(FILE* fd)
.B long rd_int4FILE* fd)
.PP
.B void rd_bytes(FILE* fd, char *buf, long l)
.PP
.B FILE* rd_fd()
.B FILE* rd_fd(void)
.SH DESCRIPTION
These routines come in handy when reading or writing ACK-object files
or libraries. No checking is performed.
.PP
.I Wr_open
.I wr_open
opens the file
.I filename
for writing and initializes some of this modules local variables.
It must be called before writing parts of the object file.
It returns 1 if it succeeds, 0 if it fails.
.PP
.I Wr_close
.I wr_close
closes the object file. Don't forget to call it, because it might
flush internal buffers.
.PP
.I Wr_ohead
.I wr_ohead
writes the
.I head
header structure.
This routine must be called before the routines to write the other
parts.
.PP
.I Wr_sect
.I wr_sect
writes
.I cnt
section headers, starting at
.IB sect .
Before writing a section, its section header must be written.
.PP
.I Wr_outsect
.I wr_outsect
indicates that the next section to be written is
.IB sectionnr .
.IB secno .
This routine can be used to switch between sections.
.PP
.I Wr_emit
.I wr_emit
writes
.I cnt
bytes, starting at
.IB emit ,
of the current section.
.PP
.I Wr_putc
adds character
.I wr_putc
adds byte
.I ch
to the current section.
.PP
.I Wr_relo
.I wr_relo
writes
.I cnt
outrelo structures, indicated by
.IB relo ,
in the relocation information part of the object file.
.PP
.I Wr_name
.I wr_name
writes
.I cnt
outname structures, indicated by
.IB name ,
in the name-table part of the object file.
.PP
.I Wr_string
.I wr_string
writes
.I cnt
bytes, indicated by
.IB stringaddr ,
.IB addr,
in the string table part of the object file.
.PP
The next few routines can be used independantly:
.I Wr_arhdr
.I wr_arhdr
writes the archive member header
.I arhdr
to file descriptor
.IB fd .
.PP
.I Wr_ranlib
.I wr_ranlib
writes
.I cnt
ranlib structures, indicated by
@ -163,23 +163,23 @@ ranlib structures, indicated by
to file descriptor
.IB fd.
.PP
.I Wr_int2
.I wr_int2
writes a 2-byte integer
.I i
to file descriptor
.IB fd ,
low order byte first.
.PP
.I Wr_long
.I wr_long
writes a 4-byte integer
.I l
to file descriptor
.IB fd ,
low order word first, low order byte first.
.PP
.I Wr_bytes
.I wr_bytes
writes
.I l
.I cnt
bytes from
.I buf
to file descriptor
@ -191,7 +191,7 @@ routines are the opposite of the
.I wr_
routines. However, a few of them deserve special mentioning:
.PP
.I Rd_fdopen
.I rd_fdopen
initialises for reading an "object file" from file descriptor
.IB fd ,
at its current position.
@ -201,16 +201,16 @@ When using this entry point for reading,
.I rd_close
does not have to be called.
.PP
.I Rd_rew_relo
.I rd_rew_relos
rewinds the relocation part, so that it can be read again.
\fILed\fR(6) sometimes needs this.
.PP
.I Rd_unsigned2
.I rd_unsigned2
reads two bytes from file descriptor
.I fd
and interpretes them as an unsigned integer.
and interprets them as an unsigned integer.
.PP
.I Rd_arhdr
.I rd_arhdr
returns 1 if a header was read, and 0 on end-of-file.
.PP
When using any of the reading routines, a routine

View file

@ -17,49 +17,40 @@ struct outsect;
struct ranlib;
struct outname;
int wr_open(const char *f);
int wr_open(const char *filename);
void wr_close(void);
void wr_ohead(const struct outhead *h);
void wr_sect(const struct outsect *s, unsigned int c);
void wr_ohead(const struct outhead *head);
void wr_sect(const struct outsect *sect, unsigned int cnt);
void wr_outsect(int sectno);
void wr_emit(const char *b, long c);
void wr_emit(const char *emit, long cnt);
void wr_putc(int c);
void wr_relo(const struct outrelo *r, unsigned int c);
void wr_name(const struct outname *n, unsigned int c);
void wr_string(const char *s, long c);
void wr_relo(const struct outrelo *relo, unsigned int cnt);
void wr_name(const struct outname *name, unsigned int cnt);
void wr_string(const char *addr, long len);
void wr_arhdr(FILE* fd, struct ar_hdr *a);
void wr_ranlib(FILE* fd, struct ranlib *r, long cnt);
void wr_arhdr(FILE* fd, struct ar_hdr *arhdr);
void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt);
void wr_int2(FILE* fd, int i);
void wr_long(FILE* fd, long l);
void wr_bytes(FILE* fd, const char *buf, long l);
void wr_int4(FILE* fd, long l);
void wr_bytes(FILE* fd, const char *buf, long cnt);
int rd_open(const char *f);
int rd_open(const char *filename);
int rd_fdopen(FILE* fd);
void rd_close(void);
void rd_ohead(struct outhead *h);
void rd_sect(struct outsect *s, unsigned int c);
void rd_ohead(struct outhead* head);
void rd_sect(struct outsect* sect, unsigned int cnt);
void rd_outsect(int sectno);
void rd_emit(char *b, long c);
void rd_relo(struct outrelo *r, unsigned int c);
void rd_emit(char* emit, long cnt);
void rd_relo(struct outrelo* relo, unsigned int cnt);
void rd_rew_relos(struct outhead *head);
void rd_name(struct outname *n, unsigned int c);
void rd_string(char *s, long c);
void rd_name(struct outname* name, unsigned int cnt);
void rd_string(char* addr, long len);
/** Reads an archive header and returns the filled
* up archive header structure. Returns 0 if failure
* otherwise returns 1.
*
* @param[in] fd Opened file descriptor to read from.
* @param[out] a Archive header structure.
*
*/
int rd_arhdr(FILE* fd, struct ar_hdr *a);
void rd_ranlib(FILE* fd, struct ranlib *r, long cnt);
int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr);
void rd_ranlib(FILE* fd, register struct ranlib *ran, register long cnt);
int rd_int2(FILE* fd);
long rd_long(FILE* fd);
long rd_int4(FILE* fd);
unsigned int rd_unsigned2(FILE* fd);
void rd_bytes(FILE* fd, char *buf, long l);
FILE* rd_fd(void);

View file

@ -61,10 +61,10 @@ OUTREAD(int p, char* b, long n)
/*
* Open the output file according to the chosen strategy.
*/
int rd_open(const char* f)
int rd_open(const char* filename)
{
if ((outfile = fopen(f, "rb")) == NULL)
if ((outfile = fopen(filename, "rb")) == NULL)
return 0;
return rd_fdopen(outfile);
}
@ -160,10 +160,10 @@ rd_sect(struct outsect* sect, unsigned int cnt)
}
void
rd_outsect(int s)
rd_outsect(int sectno)
{
OUTSECT(s);
sectionnr = s;
OUTSECT(sectno);
sectionnr = sectno;
}
/*

View file

@ -13,6 +13,7 @@
extern void rd_fatal(void);
int rd_arhdr(FILE* fd, register struct ar_hdr *arhdr)
{
char buf[AR_TOTAL];

View file

@ -11,7 +11,7 @@
#include "obj.h"
long rd_long(FILE* fd)
long rd_int4(FILE* fd)
{
char buf[4];

View file

@ -144,18 +144,18 @@ static void BEGINSEEK(int p, long o)
/*
* Open the output file according to the chosen strategy.
*/
int wr_open(const char *f)
int wr_open(const char *filename)
{
struct fil *fdp;
fclose(fopen(f,"wb"));
fclose(fopen(filename,"wb"));
#ifdef OUTSEEK
if ((outfile = fopen(f, "ab+")) == NULL)
if ((outfile = fopen(filename, "ab+")) == NULL)
return 0;
currpos = 0;
#else /* not OUTSEEK */
for (fdp = &__parts[PARTEMIT]; fdp < &__parts[NPARTS]; fdp++)
if ((fdp->fd = fopen(f, "wb+")) == NULL)
if ((fdp->fd = fopen(filename, "wb+")) == NULL)
return 0;
#endif /* not OUTSEEK */
offcnt = 0;
@ -254,12 +254,12 @@ wr_sect(const struct outsect *sect, unsigned int cnt)
}
void
wr_outsect(int s)
wr_outsect(int sectno)
/* s = section number */
{
struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
if (sectno != sectionnr && sectno >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
#ifdef OUTSEEK
if (currpos != ptr->currpos)
{
@ -273,18 +273,18 @@ wr_outsect(int s)
currpos = ptr->currpos;
#endif
offset[sectionnr] = ptr->currpos;
if (offset[s] != ptr->currpos) {
fseek(ptr->fd, offset[s], SEEK_SET);
ptr->currpos = offset[s];
if (offset[sectno] != ptr->currpos) {
fseek(ptr->fd, offset[sectno], SEEK_SET);
ptr->currpos = offset[sectno];
#ifdef OUTSEEK
currpos = ptr->currpos;
#endif
}
ptr->cnt = WBUFSIZ - ((int)offset[s] & (WBUFSIZ-1));
ptr->cnt = WBUFSIZ - ((int)offset[sectno] & (WBUFSIZ-1));
ptr->pbegin = ptr->pbuf + (WBUFSIZ - ptr->cnt);
ptr->pnow = ptr->pbegin;
}
sectionnr = s;
sectionnr = sectno;
}
/*

View file

@ -22,7 +22,7 @@ extern void wr_fatal(void);
/*
* Just write "cnt" bytes to file-descriptor "fd".
*/
void wr_bytes(FILE* fd, const char *string, long cnt)
void wr_bytes(FILE* fd, const char *buf, long cnt)
{
size_t written_bytes;
@ -30,12 +30,12 @@ void wr_bytes(FILE* fd, const char *string, long cnt)
{
int n = cnt >= maxchunk ? maxchunk : cnt;
written_bytes = fwrite(string, 1, n, fd);
written_bytes = fwrite(buf, 1, n, fd);
if (written_bytes != (size_t)n)
{
wr_fatal();
}
string += n;
buf += n;
cnt -= n;
}
}

View file

@ -10,7 +10,7 @@
#include "object.h"
#include "obj.h"
void wr_long(FILE* fd, long l)
void wr_int4(FILE* fd, long l)
{
char buf[4];

View file

@ -12,10 +12,10 @@
#include "obj.h"
#include "ranlib.h"
void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1)
void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt)
{
struct ranlib *r;
long cnt, val;
long cnt2, val;
char *c;
/*
@ -30,11 +30,11 @@ void wr_ranlib(FILE* fd, struct ranlib *ran, long cnt1)
*/
r = ran;
c = (char *)r;
cnt = cnt1;
while (cnt--) {
cnt2 = cnt;
while (cnt2--) {
val = r->ran_off; put4(val, c); c += 4;
val = r->ran_pos; put4(val, c); c += 4;
r++;
}
wr_bytes(fd, (char *) ran, cnt1 * SZ_RAN);
wr_bytes(fd, (char *) ran, cnt * SZ_RAN);
}