Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!nike!cit-vax!amdahl!amdcad!jimb From: jimb@amdcad.UUCP (Jim Budler) Newsgroups: net.sources.mac Subject: xbin->MacBinary converter (macbin.c) Message-ID: <13400@amdcad.UUCP> Date: Thu, 16-Oct-86 20:02:34 EDT Article-I.D.: amdcad.13400 Posted: Thu Oct 16 20:02:34 1986 Date-Received: Fri, 17-Oct-86 03:37:23 EDT Reply-To: jimb@amdcad.UUCP (Jim Budler) Distribution: world Organization: Advanced Micro Devices, Sunnyvale, California Lines: 249 Keywords: xbin macput macget macbinary unix macintosh mac #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # README # makefile # macbin.c # This archive created: Thu Oct 16 16:57:13 1986 export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'README' then echo shar: "will not over-write existing file 'README'" else sed 's/^X//' << \SHAR_EOF > 'README' XA new version of Unix macbin. X XChanges: X X '% macbin *' will convert all *.{info,data,rsrc} trios in the X current directory to basename.bin. X X '% macbin foo fee fum' will attempt to convert foo.{data,rsrc,info}, X fee.{data,rsrc,info}, and fum.{data,info,rsrc}. X X '% macbin -v ' will be a little noisier about it. SHAR_EOF if test 322 -ne "`wc -c < 'README'`" then echo shar: "error transmitting 'README'" '(should have been 322 characters)' fi fi if test -f 'makefile' then echo shar: "will not over-write existing file 'makefile'" else sed 's/^X//' << \SHAR_EOF > 'makefile' X# CFLAGS=-O -Drindex=strrchr -DBZERO # for sysV I think XCFLAGS=-O X Xmacbin: macbin.c makefile X cc $(CFLAGS) -s -o macbin macbin.c X SHAR_EOF if test 132 -ne "`wc -c < 'makefile'`" then echo shar: "error transmitting 'makefile'" '(should have been 132 characters)' fi fi if test -f 'macbin.c' then echo shar: "will not over-write existing file 'macbin.c'" else sed 's/^X//' << \SHAR_EOF > 'macbin.c' X/*--------------------------------------------------------------------* X | Version : 2.0 | X | Author : Jim Budler | X | Copyright Oct 13, 1986 | X | Placed in public domain Oct 14, 1986 | X | Enjoy | X *--------------------------------------------------------------------*/ X X#include X#include X Xextern int errno; X Xmain(argc,argv) Xint argc; Xchar **argv; X{ X/* structure of the info file - from MacBin.C X char zero1; X char nlen; X char name[63]; X char type[4]; 65 0101 X char creator[4]; 69 X char flags; 73 X char zero2; 74 0112 X char location[6]; 80 X char protected; 81 0121 X char zero3; 82 0122 X char dflen[4]; X char rflen[4]; X char cdate[4]; X char mdate[4]; X*/ X FILE *fd, *ofd; X char bname[128]; X char iname[128]; X char dname[128]; X char rname[128]; X char oname[128]; X char buf[128]; X char * charp, * cmd; X char * rindex(); X int verbose = 0; X if ((cmd = rindex(argv[0], '/')) != NULL) X ++cmd; X else X cmd = argv[0]; X if (argc > 1) X if (!strcmp(argv[1], "-v")) { X verbose = 1; X --argc; X ++argv; X } X if (argc < 2) { X fprintf(stderr,"Usage:\n\t%s [-v] filename(s)\n",cmd); X exit(EINVAL); X } X while ( argc > 1 ) { X (void) bzero(buf,128); X if (( charp = rindex (argv[1], '.')) == NULL) X strcpy(bname, argv[1]); X else { X *charp = '\0'; X if ( strcmp(++charp,"data") && strcmp (charp, "info") X && strcmp (charp, "rsrc")) { X *(--charp) = '.'; /* put it back */ X strcpy(bname, argv[1]); X } else { X strcpy(bname,argv[1]); X --argc; X ++argv; X } X } X strcpy(oname,bname); X strcat(oname,".bin"); X strcpy(iname,bname); X strcat(iname,".info"); X strcpy(dname,bname); X strcat(dname,".data"); X strcpy(rname,bname); X strcat(rname,".rsrc"); X if (verbose) X fprintf (stderr, "Converting %s\n", bname); X while ( argc > 1 && (!strcmp(argv[1], iname) || X !strcmp(argv[1], dname) || !strcmp(argv[1], rname))) { X --argc; X ++argv; X } X if ((ofd = fopen( oname, "w")) == NULL){ X perror(oname); X --argc; X ++argv; X continue; X } X if ((fd = fopen(iname,"r")) == NULL){ X if ( verbose ) X fprintf ( stderr, "No %s\n", iname); X fclose(ofd); X unlink(oname); X --argc; X ++argv; X continue; X } X if (fread(buf, sizeof(*buf), 128, fd) > 0){ X if (buf[74] & 0x40) buf[81] = '\1'; /* protected */ X buf[74] = '\0'; /* clear zero2 */ X fwrite(buf, sizeof(*buf),128, ofd); X (void) bzero(buf,128); X } X fclose(fd); X if ((fd = fopen(dname,"r")) == NULL){ X if ( verbose ) X fprintf ( stderr, "No %s\n", dname); X fclose(ofd); X unlink(oname); X --argc; X ++argv; X continue; X } X while (fread(buf, sizeof(*buf),128, fd) > 0){ X fwrite(buf, sizeof(*buf),128, ofd); X (void) bzero(buf,128); X } X fclose(fd); X if ((fd = fopen(rname,"r")) == NULL){ X if ( verbose ) X fprintf ( stderr, "No %s\n", rname); X fclose(ofd); X unlink(oname); X --argc; X ++argv; X continue; X } X while (fread(buf, sizeof(*buf),128, fd) > 0){ X fwrite(buf, sizeof(*buf),128, ofd); X (void) bzero(buf,128); X } X fclose(fd); X fclose(ofd); X } X} X X#ifdef BZERO X/* File : bzero.c X Author : Richard A. O'Keefe. X Updated: 23 April 1984 X Defines: bzero() X X bzero(dst, len) moves "len" 0 bytes to "dst". X Thus to clear a disc buffer to 0s do bzero(buffer, BUFSIZ). X X Note: the "b" routines are there to exploit certain VAX order codes, X but the MOVC5 instruction will only move 65535 characters. The asm X code is presented for your interest and amusement. X*/ X X#include "strings.h" X X#if VaxAsm X Xvoid bzero(dst, len) X char *dst; X int len; X { X asm("movc5 $0,*4(ap),$0,8(ap),*4(ap)"); X } X X#else ~VaxAsm X Xvoid bzero(dst, len) X register char *dst; X register int len; X { X while (--len >= 0) *dst++ = 0; X } X X#endif VaxAsm X X#endif /* BZERO */ SHAR_EOF if test 3976 -ne "`wc -c < 'macbin.c'`" then echo shar: "error transmitting 'macbin.c'" '(should have been 3976 characters)' fi fi exit 0 # End of shell archive -- Jim Budler Advanced Micro Devices, Inc. (408) 749-5806 Usenet: {ucbvax,decwrl,ihnp4}!amdcad!jimb Compuserve: 72415,1200