Add more const in <object.h>.

This commit is contained in:
George Koehler 2017-11-11 13:08:13 -05:00
parent d347207e60
commit 805c916ab0
5 changed files with 48 additions and 64 deletions

View file

@ -13,22 +13,22 @@ struct outrelo;
struct outsect; struct outsect;
struct ranlib; struct ranlib;
int wr_open(char *f); int wr_open(const char *f);
void wr_close(void); void wr_close(void);
void wr_ohead(struct outhead *h); void wr_ohead(const struct outhead *h);
void wr_sect(struct outsect *s, unsigned int c); void wr_sect(const struct outsect *s, unsigned int c);
void wr_outsect(int sectno); void wr_outsect(int sectno);
void wr_emit(char *b, long c); void wr_emit(const char *b, long c);
void wr_putc(int c); void wr_putc(int c);
void wr_relo(struct outrelo *r, unsigned int c); void wr_relo(const struct outrelo *r, unsigned int c);
void wr_name(struct outname *n, unsigned int c); void wr_name(const struct outname *n, unsigned int c);
void wr_string(char *s, long c); void wr_string(const char *s, long c);
void wr_arhdr(int fd, struct ar_hdr *a); void wr_arhdr(int fd, struct ar_hdr *a);
void wr_ranlib(int fd, struct ranlib *r, long cnt); void wr_ranlib(int fd, struct ranlib *r, long cnt);
void wr_int2(int fd, int i); void wr_int2(int fd, int i);
void wr_long(int fd, long l); void wr_long(int fd, long l);
void wr_bytes(int fd, char *buf, long l); void wr_bytes(int fd, const char *buf, long l);
int rd_open(char *f); int rd_open(const char *f);
int rd_fdopen(int f); int rd_fdopen(int f);
void rd_close(void); void rd_close(void);
void rd_ohead(struct outhead *h); void rd_ohead(struct outhead *h);

View file

@ -3,6 +3,7 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include <fcntl.h>
#include "obj.h" #include "obj.h"
/* /*
@ -57,7 +58,7 @@ OUTREAD(int p, char* b, long n)
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
*/ */
int int
rd_open(char* f) rd_open(const char* f)
{ {
if ((outfile = open(f, 0)) < 0) if ((outfile = open(f, 0)) < 0)

View file

@ -11,6 +11,7 @@
* part. In this case #define OUTSEEK. * part. In this case #define OUTSEEK.
*/ */
#include <fcntl.h>
#include "obj.h" #include "obj.h"
/* /*
@ -28,8 +29,7 @@ int __sectionnr;
static int offcnt; static int offcnt;
void void
__wr_flush(ptr) __wr_flush(struct fil *ptr)
register struct fil *ptr;
{ {
#ifdef OUTSEEK #ifdef OUTSEEK
/* seek to correct position even if we aren't going to write now */ /* seek to correct position even if we aren't going to write now */
@ -53,14 +53,12 @@ __wr_flush(ptr)
} }
static void static void
OUTWRITE(p, b, n) OUTWRITE(int p, const char *b, long n)
int p; /* part number */ /* p = part number, b = buffer pointer, n = write count */
register char *b; /* buffer pointer */
long n; /* write count */
{ {
register struct fil *ptr = &__parts[p]; struct fil *ptr = &__parts[p];
register char *pn = ptr->pnow; char *pn = ptr->pnow;
register int i; int i;
long m; long m;
i = ptr->cnt; i = ptr->cnt;
@ -119,11 +117,10 @@ OUTWRITE(p, b, n)
} }
static void static void
BEGINSEEK(p, o) BEGINSEEK(int p, long o)
int p; /* part number */ /* p = part number, o = offset in file */
long o; /* offset in file */
{ {
register struct fil *ptr = &__parts[p]; struct fil *ptr = &__parts[p];
#ifdef OUTSEEK #ifdef OUTSEEK
ptr->fd = outfile; ptr->fd = outfile;
@ -143,10 +140,9 @@ BEGINSEEK(p, o)
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
*/ */
int int
wr_open(f) wr_open(const char *f)
char *f;
{ {
register struct fil *fdp; struct fil *fdp;
close(creat(f, 0666)); close(creat(f, 0666));
#ifdef OUTSEEK #ifdef OUTSEEK
@ -165,7 +161,7 @@ wr_open(f)
void void
wr_close() wr_close()
{ {
register struct fil *ptr; struct fil *ptr;
for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) { for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) {
__wr_flush(ptr); __wr_flush(ptr);
@ -181,11 +177,10 @@ wr_close()
} }
void void
wr_ohead(head) wr_ohead(const struct outhead *head)
register struct outhead *head;
{ {
{ {
register long off = OFF_RELO(*head); long off = OFF_RELO(*head);
BEGINSEEK(PARTEMIT, 0L); BEGINSEEK(PARTEMIT, 0L);
BEGINSEEK(PARTRELO, off); BEGINSEEK(PARTRELO, off);
@ -202,7 +197,7 @@ wr_ohead(head)
{ {
char buf[SZ_HEAD]; char buf[SZ_HEAD];
register char *c = &buf[0]; char *c = &buf[0];
put2(head->oh_magic, c); c += 2; put2(head->oh_magic, c); c += 2;
put2(head->oh_stamp, c); c += 2; put2(head->oh_stamp, c); c += 2;
@ -217,11 +212,9 @@ wr_ohead(head)
} }
void void
wr_sect(sect, cnt) wr_sect(const struct outsect *sect, unsigned int cnt)
register struct outsect *sect;
register unsigned int cnt;
{ {
{ register unsigned int i = cnt; { unsigned int i = cnt;
while (i--) { while (i--) {
if (offcnt >= 1 && offcnt < SECTCNT) { if (offcnt >= 1 && offcnt < SECTCNT) {
@ -234,8 +227,8 @@ wr_sect(sect, cnt)
} }
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTEMIT].cnt/SZ_SECT; i = __parts[PARTEMIT].cnt/SZ_SECT;
c = __parts[PARTEMIT].pnow; c = __parts[PARTEMIT].pnow;
@ -258,10 +251,10 @@ wr_sect(sect, cnt)
} }
void void
wr_outsect(s) wr_outsect(int s)
int s; /* section number */ /* s = section number */
{ {
register struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)]; struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
#ifdef OUTSEEK #ifdef OUTSEEK
@ -291,23 +284,19 @@ wr_outsect(s)
* We don't have to worry about byte order here. * We don't have to worry about byte order here.
*/ */
void void
wr_emit(emit, cnt) wr_emit(const char *emit, long cnt)
char *emit;
long cnt;
{ {
OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt); OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt);
} }
void void
wr_relo(relo, cnt) wr_relo(const struct outrelo *relo, unsigned int cnt)
register struct outrelo *relo;
unsigned int cnt;
{ {
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTRELO].cnt/SZ_RELO; i = __parts[PARTRELO].cnt/SZ_RELO;
c = __parts[PARTRELO].pnow; c = __parts[PARTRELO].pnow;
@ -329,14 +318,12 @@ wr_relo(relo, cnt)
} }
void void
wr_name(name, cnt) wr_name(const struct outname *name, unsigned int cnt)
register struct outname *name;
unsigned int cnt;
{ {
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTNAME].cnt/SZ_NAME; i = __parts[PARTNAME].cnt/SZ_NAME;
c = __parts[PARTNAME].pnow; c = __parts[PARTNAME].pnow;
@ -356,11 +343,8 @@ wr_name(name, cnt)
} }
void void
wr_string(addr, len) wr_string(const char *addr, long len)
char *addr;
long len;
{ {
OUTWRITE(PARTCHAR, addr, len); OUTWRITE(PARTCHAR, addr, len);
} }

View file

@ -12,19 +12,17 @@
You have to put it in an int! You have to put it in an int!
*/ */
static int maxchunk = MAXCHUNK; static const int maxchunk = MAXCHUNK;
/* /*
* Just write "cnt" bytes to file-descriptor "fd". * Just write "cnt" bytes to file-descriptor "fd".
*/ */
void void
wr_bytes(fd, string, cnt) wr_bytes(int fd, const char *string, long cnt)
register char *string;
register long cnt;
{ {
while (cnt) { while (cnt) {
register int n = cnt >= maxchunk ? maxchunk : cnt; int n = cnt >= maxchunk ? maxchunk : cnt;
if (write(fd, string, n) != n) if (write(fd, string, n) != n)
wr_fatal(); wr_fatal();

View file

@ -6,11 +6,12 @@
#include "obj.h" #include "obj.h"
extern int __sectionnr; extern int __sectionnr;
void __wr_flush(struct fil *);
void void
wr_putc(ch) wr_putc(int ch)
{ {
register struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)]; struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
if (ptr->cnt == 0) __wr_flush(ptr); if (ptr->cnt == 0) __wr_flush(ptr);
ptr->cnt--; *ptr->pnow++ = ch; ptr->cnt--; *ptr->pnow++ = ch;