Patch #:	none yet
Type:		operational change
Priority:	none
Modification:	add support for .IDeskTop color icon familes
Submitted:	  David Hornsby <djh@munnari.OZ.AU>
IMPORTANT:
IMPORTANT:	This patch assumes CAP at patch level 198.
IMPORTANT:	This is an interim patch only. You will need to keep this
IMPORTANT:	patch file in order to reverse the code changes before patch
IMPORTANT:	199 can be applied without error.
IMPORTANT:
File:		cap60/contrib/DeskTop/builddt.c
File:		cap60/contrib/DeskTop/dt.h
File:		cap60/contrib/DeskTop/dtmisc.c
File:		cap60/contrib/DeskTop/dumpdt.c
File:		cap60/contrib/DeskTop/Makefile
File:		cap60/contrib/DeskTop/README


*** contrib/DeskTop/builddt.c.orig	Mon Aug 11 00:02:19 1997
--- contrib/DeskTop/builddt.c		Sun Aug 10 22:16:52 1997
***************
*** 30,37 ****
  int totfiles = 0;
  int idesk = 0, adesk = 0;
  long iconlen, bndllen, freflen;
! short iconnum, bndlnum, frefnum;
! long iconoffset, bndloffset, frefoffset;
  long listoffset;
  u_char icon[1024];
  
--- 30,37 ----
  int totfiles = 0;
  int idesk = 0, adesk = 0;
  long iconlen, bndllen, freflen;
! short bndlnum, frefnum;
! long bndloffset, frefoffset;
  long listoffset;
  u_char icon[1024];
  
***************
*** 47,52 ****
--- 47,63 ----
  struct bids bids;
  struct fdata fdata;
  
+ struct icn icn[8] = {
+   "", 0, 0,
+   "ICN#", 0, 0,
+   "icl4", 0, 0,
+   "icl8", 0, 0,
+   "ics#", 0, 0,
+   "ics4", 0, 0,
+   "ics8", 0, 0,
+   "", 0, 0
+ };
+ 
  main(argc, argv)
  int argc;
  char *argv[];
***************
*** 225,230 ****
--- 236,242 ----
  makeEntry(path, file, resource, finderinfo)
  char *path, *file, *resource, *finderinfo;
  {
+ 	int h;
  	int i;
  	int j;
  	int k;
***************
*** 234,240 ****
  	short ilen;
  	long offset;
  	short numres;
! 	char *ic, *findICN();
  	struct fdata *ff, *findFREF();
  
  	totfiles++;
--- 246,252 ----
  	short ilen;
  	long offset;
  	short numres;
! 	char *ic, *findIcon();
  	struct fdata *ff, *findFREF();
  
  	totfiles++;
***************
*** 345,351 ****
  	  return;
  	}
  
! 	bndlnum = iconnum = frefnum = 0;
  
  	for (j = 0; j < numres; j++) {
  	  /* read resource type list */
--- 357,365 ----
  	  return;
  	}
  
! 	bndlnum = frefnum = 0;
! 	for (j = 0; j < 8; j++)
! 	  icn[j].iconnum = icn[j].iconoffset = 0;
  
  	for (j = 0; j < numres; j++) {
  	  /* read resource type list */
***************
*** 366,374 ****
  	    bndlnum = ntohs(tlist.rnum)+1;
  	    bndloffset = ntohs(tlist.roff);
  	  }
! 	  if (bcmp(tlist.rtype, "ICN#", 4) == 0) {
! 	    iconnum = ntohs(tlist.rnum)+1;
! 	    iconoffset = ntohs(tlist.roff);
  	  }
  	  if (bcmp(tlist.rtype, "FREF", 4) == 0) {
  	    frefnum = ntohs(tlist.rnum)+1;
--- 380,391 ----
  	    bndlnum = ntohs(tlist.rnum)+1;
  	    bndloffset = ntohs(tlist.roff);
  	  }
! 	  /* check for icon family */
! 	  for (h = 1; h < 7; h++) {
! 	    if (bcmp(tlist.rtype, icn[h].ityp, 4) == 0) {
! 	      icn[h].iconnum = ntohs(tlist.rnum)+1;
! 	      icn[h].iconoffset = ntohs(tlist.roff);
! 	    }
  	  }
  	  if (bcmp(tlist.rtype, "FREF", 4) == 0) {
  	    frefnum = ntohs(tlist.rnum)+1;
***************
*** 377,383 ****
  	}
  
  	/* check for BNDL/ICN#/FREF resources */
! 	if (bndlnum == 0 || iconnum == 0 || frefnum == 0) {
  	  if (debug) printf("no BNDL/ICN#/FREF resources\n");
  	  close(fd);
  	  return;
--- 394,400 ----
  	}
  
  	/* check for BNDL/ICN#/FREF resources */
! 	if (bndlnum == 0 || icn[1].iconnum == 0 || frefnum == 0) {
  	  if (debug) printf("no BNDL/ICN#/FREF resources\n");
  	  close(fd);
  	  return;
***************
*** 461,494 ****
  		printf("local ID %d, actual ID %d\n",
  		  (short)ntohs(bids.localID), (short)ntohs(bids.actualID));
  
! 	      if (bcmp(bdata.btype, "ICN#", 4) == 0) {
! 	        if ((ic = findICN(fd, ntohs(bids.actualID), &ilen)) != NULL) {
! 		  if ((ff = findFREF(fd, ntohs(bids.localID))) != NULL) {
! 	            idt.magic = htonl(MAGIC);
! 	            idt.isize = htonl(ilen);
! 		    bcopy(bhdr.creat, idt.creat, 4);
! 		    bcopy(ff->ftype, idt.ftype, 4);
! 		    idt.itype = 1; /* ICN# */
! 	            idt.pad1 = 0;
! 		    bzero(idt.userb, 4);
! 	            idt.pad2[0] = 0;
! 	            idt.pad2[1] = 0;
! 
! 		    if (debug) {
! 		      printf("creator");
! 		      printsig(idt.creat);
! 		      printf("type");
! 		      printsig(idt.ftype);
! 		      printf("found ICN# of length %d\n", ilen);
! 		      printicn(ic, ilen);
  		    }
! 
! 		    if (writing) {
! 		      write(fdi, &idt, sizeof(idt));
! 		      write(fdi, ic, ilen);
! 		      idesk++;
! 		    }
! 		  }
  	        }
  	      }
  	    }
--- 478,514 ----
  		printf("local ID %d, actual ID %d\n",
  		  (short)ntohs(bids.localID), (short)ntohs(bids.actualID));
  
! 	      if ((ff = findFREF(fd, ntohs(bids.localID))) != NULL) {
! 	        if (bcmp(bdata.btype, "ICN#", 4) == 0) {
! 	          /* check icon family */
! 	          for (h = 1; h < 7; h++) {
! 	            if ((ic=findIcon(fd,h,ntohs(bids.actualID),&ilen))!=NULL){
! 	              idt.magic = htonl(MAGIC);
! 	              idt.isize = htonl(ilen);
! 		      bcopy(bhdr.creat, idt.creat, 4);
! 		      bcopy(ff->ftype, idt.ftype, 4);
! 		      idt.itype = h;
! 	              idt.pad1 = 0;
! 		      bzero(idt.userb, 4);
! 	              idt.pad2[0] = 0;
! 	              idt.pad2[1] = 0;
! 
! 		      if (debug) {
! 		        printf("creator");
! 		        printsig(idt.creat);
! 		        printf("type");
! 		        printsig(idt.ftype);
! 		        printf("found '%s' of length %d\n", icn[h].ityp, ilen);
! 		        printicn(ic, h, ilen);
! 		      }
! 
! 		      if (writing) {
! 		        write(fdi, &idt, sizeof(idt));
! 		        write(fdi, ic, ilen);
! 		        idesk++;
! 		      }
  		    }
! 	          }
  	        }
  	      }
  	    }
***************
*** 501,514 ****
  }
  
  /*
!  * find the ICN# with the specified resource number,
!  * return a pointer to the ICN# data and it's length
   *
   */
  
  char *
! findICN(fd, rsrcID, len)
  int fd;
  short rsrcID;
  short *len;
  {
--- 521,536 ----
  }
  
  /*
!  * find the icon with the specified resource number
!  * and type (ICN#, icl4, icl8, ics#, ics4, ics8),
!  * return a pointer to the icon data and it's length
   *
   */
  
  char *
! findIcon(fd, typ, rsrcID, len)
  int fd;
+ int typ;
  short rsrcID;
  short *len;
  {
***************
*** 521,547 ****
  
  	/* keep current file pointer position */
  	if ((curpos = lseek(fd, 0, SEEK_CUR)) >= 0) {
! 	  /* move to start of ICN# resource reference list */
! 	  if (lseek(fd, listoffset+iconoffset, SEEK_SET) >= 0) {
! 	    for (i = 0; i < iconnum; i++) {
! 	      /* get resource reference list for each ICN# */
  	      if (read(fd, &rlist, sizeof(rlist)) == sizeof(rlist)) {
! 	        if (debug) {
! 	          printf("found ICN# rsrc ID %d ", (short)ntohs(rlist.rsrcID));
! 	          printf("offset %d\n", (long)ntohl(rlist.attrOff) & 0xffffff);
! 	        }
  	        if ((short)ntohs(rlist.rsrcID) == rsrcID)
  	          break;
  	      }
  	    }
! 	    if (i < iconnum) {
  	      offset = ntohl(rhdr.rdataOffset)+(ntohl(rlist.attrOff)&0xffffff);
! 	      /* move to beginning of ICN# resource data */
  	      if (lseek(fd, offset, SEEK_SET) >= 0) {
! 	        /* get ICN# resource length */
  	        if (read(fd, &iconlen, 4) == 4) {
  	          if ((iconlen = ntohl(iconlen)) <= sizeof(icon)) {
! 		    /* read ICN# data */
  	            if (read(fd, icon, iconlen) == iconlen) {
  		      /* restore original pointer */
  	              lseek(fd, curpos, SEEK_SET);
--- 543,569 ----
  
  	/* keep current file pointer position */
  	if ((curpos = lseek(fd, 0, SEEK_CUR)) >= 0) {
! 	  /* move to start of icon resource reference list */
! 	  if (lseek(fd, listoffset+icn[typ].iconoffset, SEEK_SET) >= 0) {
! 	    for (i = 0; i < icn[typ].iconnum; i++) {
! 	      /* get resource reference list for each icon */
  	      if (read(fd, &rlist, sizeof(rlist)) == sizeof(rlist)) {
! 	        if (debug)
! 	          printf("found '%s' rsrc ID %d offset %d\n",
! 		    icn[typ].ityp, (short)ntohs(rlist.rsrcID),
! 	            (long)ntohl(rlist.attrOff) & 0xffffff);
  	        if ((short)ntohs(rlist.rsrcID) == rsrcID)
  	          break;
  	      }
  	    }
! 	    if (i < icn[typ].iconnum) {
  	      offset = ntohl(rhdr.rdataOffset)+(ntohl(rlist.attrOff)&0xffffff);
! 	      /* move to beginning of icon resource data */
  	      if (lseek(fd, offset, SEEK_SET) >= 0) {
! 	        /* get icon resource length */
  	        if (read(fd, &iconlen, 4) == 4) {
  	          if ((iconlen = ntohl(iconlen)) <= sizeof(icon)) {
! 		    /* read icon data */
  	            if (read(fd, icon, iconlen) == iconlen) {
  		      /* restore original pointer */
  	              lseek(fd, curpos, SEEK_SET);
*** contrib/DeskTop/dt.h.orig		Mon Aug 11 00:04:07 1997
--- contrib/DeskTop/dt.h		Sun Aug 10 23:00:33 1997
***************
*** 1,7 ****
  /*
   * (re)build/dump CAP desktop files .IDeskTop and .ADeskTop
   *
!  * Copyright (c) 1993, The University of Melbourne.
   * All Rights Reserved. Permission to publicly redistribute this
   * package (other than as a component of CAP) or to use any part
   * of this software for any purpose, other than that intended by
--- 1,7 ----
  /*
   * (re)build/dump CAP desktop files .IDeskTop and .ADeskTop
   *
!  * Copyright (c) 1993-1997, The University of Melbourne.
   * All Rights Reserved. Permission to publicly redistribute this
   * package (other than as a component of CAP) or to use any part
   * of this software for any purpose, other than that intended by
***************
*** 11,16 ****
--- 11,17 ----
   * djh@munnari.OZ.AU
   * 15 February 1993
   * 30 November 1993
+  * 10 August   1997
   *
   * Refer: "Inside Macintosh", Volume 1, page I-128 "Format of a Resource File"
   *
***************
*** 50,60 ****
   */
  
  struct adt {
!   long magic;
    u_char creat[4];
    u_char userb[4];
!   long dlen;
!   long flen;
    /* names follow */
  };
  
--- 51,61 ----
   */
  
  struct adt {
!   int magic;
    u_char creat[4];
    u_char userb[4];
!   int dlen;
!   int flen;
    /* names follow */
  };
  
***************
*** 64,71 ****
   */
  
  struct idt {
!   long magic;
!   long isize;
    u_char creat[4];
    u_char ftype[4];
    u_char itype;
--- 65,72 ----
   */
  
  struct idt {
!   int magic;
!   int isize;
    u_char creat[4];
    u_char ftype[4];
    u_char itype;
***************
*** 89,95 ****
    u_short iconID;
    u_short pad[4];
    u_short commID;
!   u_long dirID;
  };
  
  struct finfo {
--- 90,96 ----
    u_short iconID;
    u_short pad[4];
    u_short commID;
!   u_int dirID;
  };
  
  struct finfo {
***************
*** 112,121 ****
  
  /* resource hdr */
  struct rhdr {
!   long rdataOffset;
!   long rmapOffset;
!   long rdataLength;
!   long rmapLength;
    u_char filler[240];
  };
  
--- 113,122 ----
  
  /* resource hdr */
  struct rhdr {
!   int rdataOffset;
!   int rmapOffset;
!   int rdataLength;
!   int rmapLength;
    u_char filler[240];
  };
  
***************
*** 137,144 ****
  struct rlist {
    short rsrcID;
    short nameOffset;
!   u_long attrOff;
!   u_long handle;
  };
  
  /* bundle header */
--- 138,145 ----
  struct rlist {
    short rsrcID;
    short nameOffset;
!   u_int attrOff;
!   u_int handle;
  };
  
  /* bundle header */
***************
*** 165,170 ****
--- 166,178 ----
    u_char ftype[4];
    short localID;
    /* ignore filename */
+ };
+ 
+ /* icon family */
+ struct icn {
+   char ityp[6];
+   short iconnum;
+   int iconoffset;
  };
  
  /* defines */
*** contrib/DeskTop/dtmisc.c.orig	Mon Aug 11 00:03:36 1997
--- contrib/DeskTop/dtmisc.c		Sun Aug 10 21:39:07 1997
***************
*** 46,60 ****
   */
  
  int
! printicn(icn, len)
  u_char *icn;
  short len;
  {
  	u_char *p;
  	int i, j, k;
  	u_long data1, data2, mask;
  
! 	if (len != 256)
  	  return;
  
  	for (i = 0, p = icn; i < 32; i += 2, p += 8) {
--- 46,61 ----
   */
  
  int
! printicn(icn, typ, len)
  u_char *icn;
+ int typ;
  short len;
  {
  	u_char *p;
  	int i, j, k;
  	u_long data1, data2, mask;
  
! 	if (typ != 1)
  	  return;
  
  	for (i = 0, p = icn; i < 32; i += 2, p += 8) {
*** contrib/DeskTop/dumpdt.c.orig	Mon Aug 11 00:02:59 1997
--- contrib/DeskTop/dumpdt.c		Sun Aug 10 23:29:57 1997
***************
*** 1,7 ****
  /*
   * dump CAP desktop files .IDeskTop and .ADeskTop
   *
!  * Copyright (c) 1993, The University of Melbourne.
   * All Rights Reserved. Permission to publicly redistribute this
   * package (other than as a component of CAP) or to use any part
   * of this software for any purpose, other than that intended by
--- 1,7 ----
  /*
   * dump CAP desktop files .IDeskTop and .ADeskTop
   *
!  * Copyright (c) 1993-1997, The University of Melbourne.
   * All Rights Reserved. Permission to publicly redistribute this
   * package (other than as a component of CAP) or to use any part
   * of this software for any purpose, other than that intended by
***************
*** 10,15 ****
--- 10,16 ----
   *
   * djh@munnari.OZ.AU
   * 15 February 1993
+  * 10 August   1997
   *
   * Refer: "Inside Macintosh", Volume 1, page I-128 "Format of a Resource File"
   *
***************
*** 23,28 ****
--- 24,32 ----
  struct adt adt;
  struct idt idt;
  
+ u_char last_creat[4] = { 0, 0, 0, 0 };
+ u_char last_ftype[4] = { 0, 0, 0, 0 };
+ 
  main(argc, argv)
  int argc;
  char *argv[];
***************
*** 95,101 ****
  	  exit(1);
  	}
  
! 	printf("\nICN# Mappings from %s/%s\n\n", argv[1], IFILE);
  
  	for ( ; ; ) {
  	  if (read(fd, &idt, sizeof(idt)) < sizeof(idt))
--- 99,105 ----
  	  exit(1);
  	}
  
! 	printf("\nIcon Family Mappings from %s/%s\n\n", argv[1], IFILE);
  
  	for ( ; ; ) {
  	  if (read(fd, &idt, sizeof(idt)) < sizeof(idt))
***************
*** 106,111 ****
--- 110,123 ----
  	    break;
  	  }
  
+ 	  if (last_creat[0] != '\0'
+ 	   && (bcmp(last_creat, idt.creat, 4) != 0
+ 	    || bcmp(last_ftype, idt.ftype, 4) != 0))
+ 	    printf("\n\n");
+ 
+ 	  bcopy(idt.creat, last_creat, 4);
+ 	  bcopy(idt.ftype, last_ftype, 4);
+ 
  	  printf("creat");
  	  printsig(idt.creat);
  	  printf("ftype");
***************
*** 116,130 ****
  	    printsig(idt.userb);
  	  }
  	  printf("\n");
- 
  	  if ((len = read(fd, icon, ntohl(idt.isize))) != ntohl(idt.isize)) {
  	    fprintf(stderr, "bad icon length %d\n", ntohl(idt.isize));
  	    break;
  	  }
! 
! 	  printf("\n");
! 	  printicn(icon, len);
! 	  printf("\n");
  	}
  
  	close(fd);
--- 128,138 ----
  	    printsig(idt.userb);
  	  }
  	  printf("\n");
  	  if ((len = read(fd, icon, ntohl(idt.isize))) != ntohl(idt.isize)) {
  	    fprintf(stderr, "bad icon length %d\n", ntohl(idt.isize));
  	    break;
  	  }
! 	  printicn(icon, idt.itype, len);
  	}
  
  	close(fd);
*** contrib/DeskTop/Makefile.orig	Wed Sep 25 00:08:49 1996
--- contrib/DeskTop/Makefile		Tue Aug 12 00:50:35 1997
***************
*** 1,5 ****
--- 1,7 ----
  all: builddt dumpdt
  
+ CFLAGS=-I../..
+ 
  builddt: builddt.o dtmisc.o
  	${CC} -o builddt builddt.o dtmisc.o
  
*** contrib/DeskTop/README.orig		Mon Aug 11 00:13:36 1997
--- contrib/DeskTop/README		Mon Aug 11 00:13:01 1997
***************
*** 3,14 ****
  
                        The University of Melbourne
                            djh@munnari.OZ.AU
!                            February, 1993
!                             version 1.0.2
  
  
  'dumpdt' dumps the content of the .IDeskTop and .ADeskTop files in the
! specified volume. usage:
  
  	dumpdt volumename
  
--- 3,14 ----
  
                        The University of Melbourne
                            djh@munnari.OZ.AU
!                             August, 1997
!                             version 1.0.3
  
  
  'dumpdt' dumps the content of the .IDeskTop and .ADeskTop files in the
! specified CAP AUFS volume. usage:
  
  	dumpdt volumename
  
***************
*** 41,47 ****
  for sensible data first. Always keep copies of existing .?DeskTop files.
  
  
! Copyright (c) 1993, The University of Melbourne.
  All Rights Reserved.  Permission to publicly redistribute this
  package (other than as part of CAP) or use any part of this software
  for any purpose other than as part of the original distribution must
--- 41,47 ----
  for sensible data first. Always keep copies of existing .?DeskTop files.
  
  
! Copyright (c) 1993-1997, The University of Melbourne.
  All Rights Reserved.  Permission to publicly redistribute this
  package (other than as part of CAP) or use any part of this software
  for any purpose other than as part of the original distribution must
