[comp.os.minix] Patches to ast.c & dd.c for ANSI_C

cagney@chook.ua.oz (Andrew Cagney - aka Noid) (11/11/89)

Below are patches to dd & ast so that they compile under AnsiC.

DD  had the problem of an incorrectly declared routine being passed
    as a parameter to signal. It was not declared void f().

AST (Not the person :-) Was opening the final image with mode append only
    It then proceeded to to a fseek to the start of the file and
    make a read. (This is considered an update). The change opens the
    file with correct mode. The open also explicitly states the
    type of the file (b binary) for the image.

    BTW is there any plan to support label's greater than 8 characters?

						Andrew Cagney

---------------------------------------------------------------- chomp
echo x - ast.c.cdif
sed '/^X/s///' > ast.c.cdif << '/'
X*** ast.c.orig	Sat Nov 11 22:17:01 1989
X--- ast.c	Sat Nov 11 22:18:59 1989
X***************
X*** 32,38 ****
X  
X  #define A_OUT		"a.out"
X  #define SYMBOL_FILE	"symbol.out"	/* contains symbol table */
X! #define LINE_LENGTH	24
X  
X  #define WORTH_LESS	1		/* lines contain no symbol */
X  #define LAST_LINE	2		/* end of file reached */
X--- 32,38 ----
X  
X  #define A_OUT		"a.out"
X  #define SYMBOL_FILE	"symbol.out"	/* contains symbol table */
X! #define LINE_LENGTH	80
X  
X  #define WORTH_LESS	1		/* lines contain no symbol */
X  #define LAST_LINE	2		/* end of file reached */
X***************
X*** 81,87 ****
X  		exit(-1);
X  	}
X  	if (o_file == NULL) o_file = A_OUT;
X! 	o_fd = fopen(o_file, "a");
X  	if (o_fd == NULL) {
X  		fprintf(stderr, "can't open %s\n", o_file);
X  		exit(-1);
X--- 81,87 ----
X  		exit(-1);
X  	}
X  	if (o_file == NULL) o_file = A_OUT;
X! 	o_fd = fopen(o_file, "r+b");
X  	if (o_fd == NULL) {
X  		fprintf(stderr, "can't open %s\n", o_file);
X  		exit(-1);
X***************
X*** 103,109 ****
X  	struct nlist symbol;
X  	int line_type;
X  
X! 	do_header();
X  	for(;;) {
X  		read_line(s_fd, buffer);
X  		line_type = transform_line(buffer, &symbol);
X--- 103,109 ----
X  	struct nlist symbol;
X  	int line_type;
X  
X! 	do_header(o_fd);
X  	for(;;) {
X  		read_line(s_fd, buffer);
X  		line_type = transform_line(buffer, &symbol);
X***************
X*** 248,259 ****
X  	}
X  }
X  
X! do_header()
X  {
X! 	int fd;
X! 
X! 	fd = open(o_file, 0);
X! 	if (read(fd, &header, sizeof(struct exec)) != sizeof(struct exec)) {
X  		fprintf(stderr, "%s: no executable file\n", o_file);
X  		exit(-1);
X  	}
X--- 248,258 ----
X  	}
X  }
X  
X! do_header(fd)
X! FILE *fd;
X  {
X! 	fseek(fd, 0L, 0); /* at start */
X! 	if (fread(&header, sizeof(struct exec), 1, fd) != 1) {
X  		fprintf(stderr, "%s: no executable file\n", o_file);
X  		exit(-1);
X  	}
X***************
X*** 267,279 ****
X  	}
X  	fseek(o_fd, A_SYMPOS(header), 0);
X  	nr_symbols = 0;
X- 	close(fd);
X  }
X  
X  redo_header(fd)
X  FILE *fd;
X  {
X! 	header.a_syms = (long) (nr_symbols * sizeof(struct nlist));
X  	fseek(fd, 0L, 0);
X  	if (fwrite(&header, sizeof(header), 1, fd) != 1) {
X  		fprintf(stderr, "%s: can't write\n", o_file);
X--- 266,277 ----
X  	}
X  	fseek(o_fd, A_SYMPOS(header), 0);
X  	nr_symbols = 0;
X  }
X  
X  redo_header(fd)
X  FILE *fd;
X  {
X! 	header.a_syms = ((long) nr_symbols) * sizeof(struct nlist);
X  	fseek(fd, 0L, 0);
X  	if (fwrite(&header, sizeof(header), 1, fd) != 1) {
X  		fprintf(stderr, "%s: can't write\n", o_file);
/
echo x - dd.c.cdif
sed '/^X/s///' > dd.c.cdif << '/'
X*** dd.c.orig	Sat Nov 11 22:17:10 1989
X--- dd.c	Sat Nov 11 22:20:58 1989
X***************
X*** 69,75 ****
X  
X  int convflag = 0;
X  int flag = 0;
X! int cnull(), ibm(), null(), over();
X  int ifd, ofd, ibc;
X  char *ibuf, *obuf, *op;
X  extern char *sbrk();
X--- 69,76 ----
X  
X  int convflag = 0;
X  int flag = 0;
X! int cnull(), ibm(), null();
X! void over();
X  int ifd, ofd, ibc;
X  char *ibuf, *obuf, *op;
X  extern char *sbrk();
X***************
X*** 102,108 ****
X  	fprintf(stderr, "%d truncated records\n", ntr);
X  }
X  
X! over()
X  {
X    statistics();
X    exit(0);
X--- 103,109 ----
X  	fprintf(stderr, "%d truncated records\n", ntr);
X  }
X  
X! void over()
X  {
X    statistics();
X    exit(0);
X***************
X*** 241,247 ****
X    ibc = obc = cbc = 0;
X    op = obuf;
X    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
X! 	signal(SIGINT, over);
X    for (; skip; skip--)
X  	read(ifd, ibuf, ibs);
X    for (; nseek; nseek--)
X--- 242,248 ----
X    ibc = obc = cbc = 0;
X    op = obuf;
X    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
X! 	(void) signal(SIGINT, over);
X    for (; skip; skip--)
X  	read(ifd, ibuf, ibs);
X    for (; nseek; nseek--)
/