| 1 | # define VAX 1 |
| 2 | struct {short hiword; short loword;}; /* stupid fp-11 */ |
| 3 | fixl(p) register long *p;{ |
| 4 | register short t; |
| 5 | t=p->hiword; p->hiword=p->loword; p->loword=t; |
| 6 | } |
| 7 | |
| 8 | main(argc,args) |
| 9 | int argc ; |
| 10 | char **args ; |
| 11 | { |
| 12 | int ifd , ofd , nbyt , ttt; |
| 13 | register char *infile , *oufile , *ap ; |
| 14 | char * fbuf, zero; |
| 15 | struct { |
| 16 | long magic; |
| 17 | long tlen,dlen; |
| 18 | long blen,slen,eadr,trl,drl; |
| 19 | } head; |
| 20 | |
| 21 | char buf[512] ; |
| 22 | |
| 23 | zero = '\0'; |
| 24 | if (argc != 3) { |
| 25 | usage : |
| 26 | printf("usage : rmhead input output\n") ; |
| 27 | exit(1) ; |
| 28 | } |
| 29 | |
| 30 | infile = args[1] ; |
| 31 | oufile = args[2] ; |
| 32 | |
| 33 | if ((ifd = open(infile,0)) < 0) { |
| 34 | ap = infile ; |
| 35 | oerr : |
| 36 | printf("%s : cannot open\n",ap) ; |
| 37 | exit(1) ; |
| 38 | } |
| 39 | |
| 40 | if ((ofd = creat(oufile,0777)) < 0) { |
| 41 | ap = oufile ; |
| 42 | goto oerr ; |
| 43 | } |
| 44 | |
| 45 | read(ifd,&head,sizeof head); |
| 46 | #ifndef VAX |
| 47 | fixl(&head.tlen); fixl(&head.dlen); |
| 48 | #endif |
| 49 | if (seek(ifd,sizeof head,0) < 0) { |
| 50 | printf("input seek error\n") ; |
| 51 | unlnk : |
| 52 | unlink(oufile) ; |
| 53 | exit(1) ; |
| 54 | } |
| 55 | |
| 56 | fbuf=sbrk(4096); |
| 57 | while (head.tlen>0) { |
| 58 | if (head.tlen>4096) nbyt=4096; else nbyt=head.tlen; |
| 59 | read(ifd,fbuf,nbyt); |
| 60 | write(ofd,fbuf,nbyt); |
| 61 | head.tlen -= nbyt; |
| 62 | } |
| 63 | while (nbyt&0777) {write(ofd,&zero,1); ++nbyt;} |
| 64 | while (head.dlen>0) { |
| 65 | if (head.dlen>4096) nbyt=4096; else nbyt=head.dlen; |
| 66 | read(ifd,fbuf,nbyt); |
| 67 | write(ofd,fbuf,nbyt); |
| 68 | head.dlen -= nbyt; |
| 69 | } |
| 70 | return(0); |
| 71 | } |