/* * rList 1.1 * lists the type & id of resources (IIgs + Macintosh) * (C)opyright 1997 by Kelvin Sherlock. All rights reserved. * * This program and accompanying source code may be freely * distributed. * * Questions, comments, and the like should be directed to me, * Kelvin Sherlock * */ /* * v 1.0 - initial version * v 1.0.1 - minor bug fix * v 1.1 - added macintosh support * */ /* * Conditional compilation options: * * #define CHECK_STACK * causes stack usage info to be issued * */ #include #include /* for structures ONLY */ #include #include #include #include #include #include /* for kernStatus */ #ifdef CHECK_STACK #include #endif #include "macresource.h" /* #ifndef udispatch #define udispatch 0xE10008 #endif extern pascal int kernStatus (void) inline (0x0603, udispatch); */ extern GSString255Ptr __C2GSMALLOC (char *); /* * routines to byteswap for endian compatability */ extern void swapint (void *); extern void swaplong (void *); extern long swap3 (void *); extern long swaplong2 (void *); int GoToWork(int, char *); void usage(void); int McList(Handle, unsigned long); int GSList(Handle, unsigned long); static char Author[]={"Kelvin Sherlock "}; static int ORCA; void main(int argc, char **argv){ static char* Errs[]={ "", /* Dummy - No error */ ": No such file\r", ": File has no resource fork\r", ": Can't open file\r", ": Can't Allocate Memory\r", ": Can't read file\r", ": Incompatible/corrupted resource\r", }; #ifdef CHECK_STACK static char stacksize[]={"\rxxxxx bytes of stack used\r"}; #endif int MyID; int i; int err; #ifdef CHECK_STACK begin_stack_check(); #endif kernStatus(); ORCA=(_toolErr); MyID=MMStartUp(); if (argc==1) usage(); else{ for (i=1;iresType){ /* Sanity check */ if ( ( (long) ResInfo - (long) Mich) > l ) return (6); Int2Hex(ResInfo->resType,&strl[1],4); Long2Hex(ResInfo->resID,&strl[7],8); Int2Hex(ResInfo->resAttr,&strl[17],4); Long2Hex(ResInfo->resSize,&strl[23],8); if (ORCA) WriteCString(strl); else WriteGS(&WriteDCB); ResInfo++; } return (0); } //#pragma debug -1 int McList (Handle h, unsigned long l) { static MacResourceHeader McHeader; static MacResourceMap McMap; static MacResourceTypeList McType; static MacReferenceList McRef; static char bstr[] = {" "}; static char strl[] = {"xxxx\t$xxxx\t$xx \t$xxxxxxxx\t--------------------\r"}; static IORecGS WriteDCB = {5, 2, strl, 48, 0, 0}; Pointer Mich; Pointer rdata; Pointer rtype; Pointer rref; Pointer rtype2; Pointer rname; int i; int j; int k; Mich = *h; memcpy (&McHeader,Mich, sizeof (MacResourceHeader) ); swaplong (&McHeader.offset_rdata); swaplong (&McHeader.offset_rmap); swaplong (&McHeader.length_rdata); swaplong (&McHeader.length_rmap); /* sanity check */ if (McHeader.offset_rdata + McHeader.length_rdata > l) return 6; if (McHeader.offset_rmap + McHeader.length_rmap > l) return 6; WriteCString ("Type\tID \tAttr \tSize \tName\r" "----\t-----\t---- \t---------\t----\r"); rdata = Mich + McHeader.offset_rdata; Mich += McHeader.offset_rmap; memcpy (&McMap, Mich, sizeof (MacResourceMap) ); swapint (&McMap.attr); swapint (&McMap.offset_typelist); swapint (&McMap.offset_namelist); swapint (&McMap.count); rname = Mich + McMap.offset_namelist; rtype2 = rtype = Mich + McMap.offset_typelist; for (i=McMap.count+1; i; i--) { memcpy( &McType, rtype+2, // Apple's doc's wrong?.... sizeof (MacResourceTypeList)); swapint (&McType.count); swapint (&McType.offset); for (k=0; k<4; k++) strl[k] = (isprint (McType.ResourceType[k]) ? McType.ResourceType[k] : ' '); rref = rtype2 + McType.offset; for (j=McType.count+1; j; j--) { memcpy ( &McRef, rref, sizeof (MacReferenceList) ); swapint (&McRef.ResourceID); swapint (&McRef.offset_namelist); Int2Hex (McRef.ResourceID, &strl[6], 4); Int2Hex (McRef.attr, &strl[12], 2); Mich = rdata + swap3 (&McRef.offset_data); Long2Hex (swaplong2 (Mich), &strl[18], 8); memcpy (&strl[27], bstr, 20); /* replace old name */ if (McRef.offset_namelist != 0xffff ) { Mich = McRef.offset_namelist + rname; memcpy (&strl[27], Mich + 1, (*Mich < 20) ? *Mich : 20); } rref += sizeof (MacReferenceList); if (ORCA) WriteCString(strl); else WriteGS(&WriteDCB); } rtype += sizeof (MacResourceTypeList); } return 0; }