[comp.os.minix] Wanted, a copy of "io.h"

nhc@cbnewsj.att.com (n.h.chandler) (11/21/90)

Would someone please e-mail me a copy of io.h,
or indicate an ftp site and path where it is archived?
Thank you.

Neville Chandler
nhc@cbnewsj.att.com

nhc@cbnewsj.att.com (n.h.chandler) (11/23/90)

Help! I need a copy of "io.h" or a binary of
dos2out.  Can someone in "Minix-land" help me?
Thanks.

N. Chandler
nhc@cbnewsj.att.com

hall@pnet01.cts.com (Robert R. Hall) (11/24/90)

Ok here is my copy of dos2out.c.  I have patched it so it will
convert large programs like elvis and kermit correctly without
printing error messages.

I could find any file labled "io.h". What does it go with?

echo x - dos2out.c
sed '/^X/s///' > dos2out.c << '/'
X/*	dos2out  -  convert ms-dos exe-format to a.out format
X *		    december '85
X *
X *
X *
X *
X *
X
XDescription of file-structures:
X
X	 a.out					 .exe
X-------------------------		-------------------------
X|	 header		|		|	 header		|
X|	 		|		|	   +		|
X+-----------------------+		|      relocation	|
X|	 text		|		|	  info		|
X|	   +		|		+-----------------------+
X|	 data		|		|			|
X+-----------------------+		|			|
X|   relocation info	|		|	 text		|
X+-----------------------+		|	   +		|
X|    symbol table	|		|	 data		|
X+-----------------------+		|			|
X|    string table	|		|			|
X+-----------------------+		+-----------------------+
X
X
X
XFor more information see MS-DOS programmers reference manual
X
X*/
X
X
X
X/* define the a.out header format (short form) */
X
X
X/* define the formatted part of the header of an MS-DOS exe-file */
X
X
X#define	D_FMT_SIZE	 28		/* size of formatted header part */	
X#define IS_EXE	     0x5A4D		/* valid linker signature; note that
X					   in a dump it shows as 4D 5A */
X
X
Xtypedef struct d_reloctab {		/* DOS relocation table entry */
X	unsigned int	r_offset;	/* offset to symbol in load-module */
X	unsigned int	r_segment;	/* segment relative to zero;
X					   real segment must now be added */
X};
X
X/* dos formatted part of the header */
Xtypedef struct d_fmt_hdr {
X	unsigned int 	ldsign;		/* linker signature, 5A4Dh */
X	unsigned int	last_page_size; /* size of last page */
X	unsigned int	nr_of_pages;	/* a page is 512 b */
X	unsigned int	nr_of_relocs;	/* nr of relocation items */
X	unsigned int	hdr_size;	/* header-size in *16b */
X	unsigned int	min_free;	/* min free mem required after prog */
X	unsigned int	max_free;	/* max free mem ever needed (FFFFh) */
X	unsigned int	ss_seg;		/* stack-segment; must be relocated */
X	unsigned int	sp_reg;		/* sp value to be loaded */
X	unsigned int	chksum;		/* neg. sum of all words in file */
X	unsigned int	ip_reg;		/* ip value (program entry-point) */
X	unsigned int	cs_seg;		/* offset of code-seg in load-module */
X	unsigned int	reloc_table;	/* start of reloc-table in hdr, 1Bh */
X	unsigned int	overlay_num;	/* overlay number - not used */
X};
X
X#define MAGIC0	       0x01		/* magic number, byte 1 */
X#define MAGIC1	       0x03		/* and second byte */
X#define A_SEP	       0x20		/* seperate I&D flag */
X#define A_EXEC	       0x10		/* executable */
X#define A_I8086	       0x04		/* Intel 8088/86 cpu */
X#define A_HDR_LEN	 32		/* short form of header */
X#define DOS	     0xFFFF		/* version for a.out is -1 */
X
X
Xtypedef struct a_out_hdr {
X	unsigned char	a_magic[2];	/* magic number */
X	unsigned char	a_flags;	/* flags for sep I&D etc */
X	unsigned char   a_cpu;		/* cpu-type */
X	unsigned char	a_hdrlen;	/* length of header */
X	unsigned char	a_unused;	/* sic */
X	unsigned short	a_version;	/* version stamp */
X	long		a_text;		/* size of text segment in bytes */
X	long		a_data;		/* size of data-segment in bytes */
X	long		a_bss;		/* size of bss (stack) segment   */
X	long		a_entry;	/* program entry-point */
X	long		a_totb;		/* other, eg initial stack-ptr */
X	long		a_syms;		/* symbol-table size */
X	/* END OF SHORT FORM */
X};
X
X/* bytes & words left to right? */
X#define A_BLR(cputype)	((cputype&0x01)!=0)  /* TRUE if bytes left-to-right */
X#define A_WLR(cputype)	((cputype&0x02)!=0)  /* TRUE if words left-to-right */
X
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <sys\types.h>
X#include <sys\stat.h>
X
X
X#define PH_SECTSIZE	512		/* size of a disk-block */
X#define NOT_A_HDR_LEN	(PH_SECTSIZE-A_HDR_LEN)	/* complement */
X#define FNAME		 32		/* length of filename/path +1 */
X
X
Xunsigned char inbuf[PH_SECTSIZE];
Xunsigned char inbuf2[PH_SECTSIZE];
Xunsigned char outbuf[PH_SECTSIZE];
X
Xstruct a_out_hdr *a_ptr= (struct a_out_hdr *)outbuf;
Xstruct d_fmt_hdr *d_ptr= (struct d_fmt_hdr *)inbuf;
X
X
Xmain (argc,argv)
Xint argc;
Xchar *argv[];
X{
X  char *dptr,			/* pointer to DOS-header */
X       *sptr,			/* pointer to OUT-header */
X       in_name[FNAME],		/* input filename */
X       out_name[FNAME];		/* output filename */
X  register int i;
X  int	in_cnt, 		/* # bytes read from input */
X	out_cnt,		/* # bytes written to output */
X	block_cnt,		/* # nr of bloks of load-module */
X	lastp_cnt,		/* # bytes in last block */
X	inf, outf,		/* filedescriptors */
X	print=0,		/* switch: print information */
X	delete=0,		/* delete exe file after processing */
X	sym,			/* data-relocation symbol offset */
X	sym_blk, sym_off;	/* load-module block & offset in blk */
X  long	d_size,			/* size of data-segment */
X	t_size,			/* size of text-segment */
X	load_size;		/* size of load-module in bytes */
X
X
X/*================================================================
X *			process parameters
X *===============================================================*/
X
X
X  if (argc<2 || argc>3) {
X     printf ("usage:  dos2out [-pd] fname[.ext]\n");
X     exit (2);
X  }
X
X  while (--argc)
X    switch (argv[argc][0]) {
X      case '-': while (*++argv[argc])
X		  switch (*argv[argc] | 32) {
X		    case 'p' : print=1; break;
X		    case 'd' : delete =1; break;
X		  default :
X		  printf ("Bad switch %c, ignored\n",*argv[argc]);
X		  }
X		break;
X
X      default :	/* make filenames */
X	dptr=in_name; sptr=out_name;
X	while (*argv[argc] && *argv[argc]!='.') {
X	   *dptr++ = *argv[argc]; 
X	   *sptr++ = *argv[argc]++;
X	}
X	/* is there an extension to the filename? */
X	if (*argv[argc]=='.') {
X	   while (*argv[argc]) *dptr++ = *argv[argc]++;
X	   *dptr=0;
X	}
X	else  {
X	   *dptr=0;
X	   strcat(dptr,".exe");
X	}
X	*sptr=0;
X	strcat(sptr,".out");
X    } /* end switch */
X
X    /* open & create files */
X    if ((inf=open(in_name,O_RDONLY|O_BINARY)) <0) {
X       printf ("input file %s not found\n",in_name);
X       exit(2);
X    }
X
X
X    /* get first block and check conditions for conversion */
X    if ((in_cnt=read(inf,inbuf,PH_SECTSIZE))!=PH_SECTSIZE) {
X	printf ("read %d bytes, should be %d - abort\n",in_cnt,PH_SECTSIZE);
X	exit(2);
X    }
X    if (d_ptr->ldsign!=IS_EXE) {
X	printf ("not a valid .exe file - stop\n");
X	exit(2);
X    }
X    if (d_ptr->nr_of_relocs>1) {
X	printf ("Too many relocations - stop\n");
X	exit(2);
X    }
X    /* see documentation for explanation of this condition */
X    if (d_ptr->nr_of_relocs<1) {
X	printf ("Exactly one relocation item required - can't process\n");
X	exit(2);
X    }
X    if (d_ptr->ip_reg) {
X	printf ("Warning - program entry point not at zero\n");
X	printf ("re-link using 'CRTSO' as first element\n");
X	exit(2);
X    }
X
X
X    /* input file is ok, open output (possibly destroy existing file) */
X    if ((outf=open(out_name,O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,S_IWRITE)) <0) {
X	printf ("cannot open output %s\n",out_name);
X	exit(2);
X    }
X
X
X/*========================= PROCESS FILE =============================*/
X
X    /* get reloc symbol's position in load-module */
X    sym  = (int) inbuf[d_ptr->reloc_table+1] << 8;
X    sym += (int) inbuf[d_ptr->reloc_table];
X    sym_blk = sym / PH_SECTSIZE;
X    sym_off = sym % PH_SECTSIZE;
X
X    /* get block with relocation symbol */
X    while (sym_blk>=0) {
X	read(inf,inbuf2,PH_SECTSIZE);
X	sym_blk--;
X    }
X
X    /* get symbol and calculate sizes */
X    t_size = inbuf2[sym_off+1] << 8;
X    t_size+= inbuf2[sym_off];
X    t_size <<= 4;
X    load_size  = (long)(d_ptr->nr_of_pages-2) * PH_SECTSIZE +
X	          (long)d_ptr->last_page_size;
X    d_size = load_size - t_size;
X
X    /* reposition file */
X    close (inf);
X    inf=open(in_name,O_RDONLY|O_BINARY);
X    in_cnt=read(inf,inbuf2,PH_SECTSIZE);
X
X    /* make a.out header */
X    a_ptr->a_magic[0] = MAGIC0;
X    a_ptr->a_magic[1] = MAGIC1;
X    a_ptr->a_flags    = A_SEP;
X    a_ptr->a_cpu      = A_I8086;
X    a_ptr->a_hdrlen   = A_HDR_LEN;
X    a_ptr->a_syms     = 0;
X    a_ptr->a_unused   = 0;
X    a_ptr->a_version  = DOS;
X    a_ptr->a_data     = d_size;
X    a_ptr->a_text     = t_size;
X    a_ptr->a_bss      = (d_ptr->min_free<<4) - d_ptr->sp_reg;
X    a_ptr->a_entry    = d_ptr->ip_reg;
X    a_ptr->a_totb     = a_ptr->a_text + a_ptr->a_bss + 
X			a_ptr->a_data + d_ptr->sp_reg;
X
X    if (print) printinfo();
X
X    /* void remainder of first block; it holds nothing */
X    /* determine nr of blocks to copy and copy them */
X    block_cnt = d_ptr->nr_of_pages-1;		/* exclude header-block */
X    lastp_cnt = d_ptr->last_page_size;
X    while (block_cnt--) {
X
X	if ((in_cnt=read(inf,inbuf,PH_SECTSIZE))!=PH_SECTSIZE)
X	   if (block_cnt || (!block_cnt && in_cnt<lastp_cnt)) {
X		printf ("read %d bytes, should be %d - abort\n",
X			in_cnt,(block_cnt ? PH_SECTSIZE : lastp_cnt));
X		exit(2);
X	};	
X	i = (!block_cnt && lastp_cnt<NOT_A_HDR_LEN ?
X	     lastp_cnt : NOT_A_HDR_LEN);
X	dptr = &outbuf[A_HDR_LEN];
X	sptr = inbuf;
X	while (i--) *dptr++ = *sptr++;
X
X	i = (!block_cnt && lastp_cnt<NOT_A_HDR_LEN ?
X	     lastp_cnt+A_HDR_LEN : PH_SECTSIZE);
X	if ((out_cnt=write(outf,outbuf,i)) != i) {
X		printf ("wrote %d bytes, should be %d - abort\n",out_cnt,i);
X		perror("Output file ERROR: ");
X		exit(2);
X	}
X
X	i = (i<PH_SECTSIZE ? 0 :
X	    (!block_cnt ? lastp_cnt-NOT_A_HDR_LEN : A_HDR_LEN));
X	dptr = outbuf;
X	while (i--) *dptr++ = *sptr++;
X    }
X
X    /* write last block */
X    if (out_cnt==PH_SECTSIZE) {
X	i = lastp_cnt-NOT_A_HDR_LEN;
X	if ((out_cnt=write(outf,outbuf,i)) != i) {
X	  printf("write error last block: %d, should be %d\n",out_cnt,i);
X	  exit(2);
X	}
X    }
X    close (outf);
X    close (inf);
X    if (delete) unlink (in_name);
X    printf("   -done-\n");
X    exit(0);
X}
X
X
X
Xprintinfo ()
X{
X  printf ("\n\nDOS-header:\n");
X  printf ("          nr of pages:  %4xh    (%4d dec)\n",
X	d_ptr->nr_of_pages, d_ptr->nr_of_pages);
X  printf ("   bytes in last page:  %4xh    (%4d dec)\n",
X	d_ptr->last_page_size, d_ptr->last_page_size);
X  printf ("    min. free mem *16:  %4xh    (%4d dec)\n",
X	d_ptr->min_free, d_ptr->min_free);
X  printf ("           stack-size:  %4xh    (%4d dec)\n",
X	d_ptr->ss_seg, d_ptr->ss_seg);
X  printf ("    stack-pointer val:  %4xh    (%4d dec)\n",
X	d_ptr->sp_reg, d_ptr->sp_reg);
X  printf ("  program entry-point:  %4xh    (%4d dec)\n",
X	d_ptr->ip_reg, d_ptr->ip_reg);
X  printf ("     code-segment val:  %4xh    (%4d dec)\n",
X	d_ptr->cs_seg, d_ptr->cs_seg);
X
X  printf ("\n\nOUT-header:\n");
X  printf ("            text-size: %6lxh   (%6ld dec)\n",
X	a_ptr->a_text, a_ptr->a_text);
X  printf ("            data-size: %6lxh   (%6ld dec)\n",
X	a_ptr->a_data, a_ptr->a_data);
X  printf ("             bss-size: %6lxh   (%6ld dec)\n",
X	a_ptr->a_bss, a_ptr->a_bss);
X  printf ("          entry-point: %6lxh   (%6ld dec)\n",
X	a_ptr->a_entry, a_ptr->a_entry);
X  printf ("           totalbytes: %6lxh   (%6ld dec)\n\n",
X	a_ptr->a_totb, a_ptr->a_totb);
X}
/

UUCP: {hplabs!hp-sdd ucsd nosc}!crash!pnet01!hall
ARPA: crash!pnet01!hall@nosc.mil
INET: hall@pnet01.cts.com