Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!ernie!shebanow From: shebanow@ernie.BERKELEY.EDU (Mike Shebanow) Newsgroups: net.sources.mac Subject: IMLib Source (Part 2 of 4) Message-ID: <11106@ucbvax.BERKELEY.EDU> Date: Thu, 28-Nov-85 01:53:57 EST Article-I.D.: ucbvax.11106 Posted: Thu Nov 28 01:53:57 1985 Date-Received: Fri, 29-Nov-85 00:16:49 EST Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: shebanow@ernie.BERKELEY.EDU (Mike Shebanow) Organization: University of California, Berkeley Lines: 819 (beware the line eater) =========================Packages.Asm============================== ; ; Packages.ASM Andrew G. Shebanow 8/31/85 ; ; Portions of this code Copyright 1984,1985 Consulair Corp. ; ; This file contains routines to emulate the high level calls ; for all of the Macintosh packages (with the exception of the SANE ; related ones). These interface routines have the same names ; and calling conventions as the routines in Inside Mac. The routines ; are intended for use with Consulair's MacC compiler, but could ; be converted to any other compiler as well. ; ; The Standard File package routines are based on code written ; by Bill Duvall of Consulair Corp. ; ; Copyright 1985 HyperSoft All Rights Reserved ; ; Modifications: ; 10/18/85 Fixed StringToNum routine selector (AGS) ; INCLUDE MacTraps.D INCLUDE ToolEqu.D INCLUDE SysEqu.D ; International Utilities XDEF IUDateString XDEF IUDatePString XDEF IUTimeString XDEF IUTimePString XDEF IUMetric XDEF IUGetIntl XDEF IUSetIntl XDEF IUCompString XDEF IUMagString XDEF IUEqualString XDEF IUMagIDString ; Binary Decimal Conversion XDEF NumToString XDEF StringToNum ; Standard File XDEF SFPutFile XDEF SFPPutFile XDEF SFGetFile XDEF SFPGetFile ; Disk Initialization XDEF DILoad XDEF DIUnload XDEF DIBadMount XDEF DIFormat XDEF DIVerify XDEF DIZero Module 'IntlTime' ; IUDateString(dateTime,form,theString) ; long dateTime; (D0) ; DateForm form; (D1) ; Str255 *theString; (D2) IUDateString MOVE.L D0,-(SP) ; dateTime MOVE.W D1,-(SP) ; form MOVE.L D2,-(SP) ; theString MOVE #0,-(SP) ; routine selector _Pack6 RTS ; IUDatePString(dateTime,form,theString,intlParam) ; long dateTime; (D0) ; DateForm form; (D1) ; Str255 *theString; (D2) ; Handle intlParam; (D3) IUDatePString MOVE.L D0,-(SP) ; dateTime MOVE.W D1,-(SP) ; form MOVE.L D2,-(SP) ; theString MOVE.L D3,-(SP) ; intlParam MOVE #14,-(SP) ; routine selector _Pack6 RTS ; IUTimeString(dateTime,wantSeconds,theString) ; long dateTime; (D0) ; short wantSeconds; (D1) (actually boolean) ; Str255 *theString (D2) IUTimeString MOVE.L D0,-(SP) ; dateTime MOVE.B D1,-(SP) ; wantSeconds (BOOLEAN) MOVE.L D2,-(SP) ; theString MOVE #2,-(SP) ; routine selector _Pack6 RTS ; IUTimePString(dateTime,wantSeconds,theString,intlParam) ; long dateTime; (D0) ; short wantSeconds; (D1) (actually boolean) ; Str255 *theString (D2) ; Handle intlParam; (D3) IUTimePString MOVE.L D0,-(SP) ; dateTime MOVE.B D1,-(SP) ; wantSeconds MOVE.L D2,-(SP) ; theString MOVE.L D3,-(SP) ; intlParam MOVE #16,-(SP) ; routine selector _Pack6 RTS Module 'IntlMisc' ; char IUMetric() (actually boolean) IUMetric MOVE.B #0,-(SP) ; save space for result MOVE #4,-(SP) ; routine selector _Pack6 MOVE.B (SP)+,D0 ; get result RTS ; result in D0??? ; Handle IUGetIntl(theID) ; short theID; (D0) IUGetIntl MOVE.L #0,-(SP) ; save space for result MOVE.W D0,-(SP) ; theID MOVE #6,-(SP) ; routine selector _Pack6 MOVE.L (SP)+,A0 ; save result in A0 RTS ; IUSetIntl(refNum,theID,intlParam) ; short refNum; (D0) ; short theID; (D1) ; Handle intlParam; (D2) IUSetIntl MOVE.W D0,-(SP) ; refnum MOVE.W D1,-(SP) ; theID MOVE.L D2,-(SP) ; intlParam MOVE #8,-(SP) ; routine selector _Pack6 RTS Module 'IntlString' ; short IUCompString(aStr,bStr) ; Str255 *aStr; (D0) ; Str255 *bStr; (D1) IUCompString MOVE.L D0,A0 ; get pointer to string MOVE.B (A0)+,D2 ; D2 = aLen MOVE.L A0,D0 ; D0 = first char of aStr MOVE.L D1,A0 MOVE.B (A0)+,D3 ; D3 = bLen MOVE.L A0,D1 ; D1 = first char of bStr BSR IUMagString RTS ; result in D0 ; short IUMagString(aStr,bStr,aLen,bLen) ; char *aStr; (D0) ; char *bStr; (D1) ; short aLen; (D2) ; short bLen; (D3) IUMagString MOVE.W #0,-(SP) ; save space for result MOVE.L D0,-(SP) ; aStr MOVE.L D1,-(SP) ; bStr MOVE.W D2,-(SP) ; aLen MOVE.W D3,-(SP) ; bLen MOVE #10,-(SP) ; routine selector _Pack6 MOVE.W (SP)+,D0 RTS ; result in D0 ; short IUEqualString(aStr,bStr) ; Str255 *aStr; (D0) ; Str255 *bStr; (D1) IUEqualString MOVE.L D0,A0 ; get pointer to string MOVE.B (A0)+,D2 ; D2 = aLen AND.L #$0FF,D2 MOVE.L A0,D0 ; D0 = first char of aStr MOVE.L D1,A0 MOVE.B (A0)+,D3 ; D3 = bLen AND.L #$0FF,D3 MOVE.L A0,D1 ; D1 = first char of bStr BSR IUMagIDString RTS ; result in D0 ; short IUMagIDString(aStr,bStr,aLen,bLen) ; char *aStr; (D0) ; char *bStr; (D1) ; short aLen; (D2) ; short bLen; (D3) IUMagIDString MOVE.W #0,-(SP) ; save space for result MOVE.L D0,-(SP) ; aStr MOVE.L D1,-(SP) ; bStr MOVE.W D2,-(SP) ; aLen MOVE.W D3,-(SP) ; bLen MOVE #12,-(SP) ; routine selector _Pack6 MOVE.W (SP)+,D0 RTS ; result in D0 Module 'Binary2Decimal' ; NumToString(theNum,theString) ; long theNum; (D0) ; Str255 *theString (D1) NumToString MOVE.L A0,-(SP) ; save A0 MOVE.L D1,A0 ; theString MOVE #0,-(SP) ; routine selector _Pack7 MOVE.L (SP)+,A0 ; restore A0 RTS ; StringToNum(theString,theNum) ; Str255 *theString; (D0) ; long *theNum; (D1) StringToNum MOVE.L D1,-(SP) ; save D1 MOVE.L D0,A0 ; A0 -> theString MOVE #1,-(SP) ; routine selector _Pack7 MOVE.L (SP)+,A0 ; move old D1 into A0 MOVE.L D0,(A0) ; save result RTS Module 'StdPutFile' ; SFPutFile(where, prompt, origName, dlgHook, reply) ; Point *where; (D0) ; struct PStr *prompt; (D1) ; struct PStr *origName; (D2) ; int (*dlgHook)(); (D3) ; SFReply *reply; (D4) SFPutFile MOVE.L D0,A0 MOVE.L (A0),-(SP) ; WHERE MOVE.L D1,-(SP) ; PROMPT MOVE.L D2,-(SP) ; origName MOVE.L D3,-(SP) ; dlgHook MOVE.L D4,-(SP) ; reply MOVE #1,-(SP) ; routine selector _Pack3 RTS ; SFPPutFile(where,prompt,origName,dlgHook,reply,dlgID,filterProc) ; Point *where; (D0) ; struct PStr *prompt; (D1) ; struct PStr *origName; (D2) ; int (*dlgHook)(); (D3) ; SFReply *reply; (D4) ; short dlgID; (D5) ; int (*dlgHook)() (D6) SFPPutFile MOVE.L D0,A0 MOVE.L (A0),-(SP) ; WHERE MOVE.L D1,-(SP) ; PROMPT MOVE.L D2,-(SP) ; origName MOVE.L D3,-(SP) ; dlgHook MOVE.L D4,-(SP) ; reply MOVE.W D5,-(SP) ; dlgID MOVE.L D6,-(SP) ; dlgHook MOVE #3,-(SP) ; routine selector _Pack3 RTS Module 'StdGetFile' ; SFGetFile(where, prompt, fileFilter, numTypes, typeList, dlgHook, reply) ; Point *where; (D0) ; struct PStr *prompt; (D1) ; int (*fileFilter)(); (D2) ; short numTypes; (D3) ; SFTypeList *typeList; (D4) ; int (*dlgHook)(); (D5) ; SFReply *reply; (D6) SFGetFile MOVE.L D0,A0 MOVE.L (A0),-(SP) ; WHERE MOVE.L D1,-(SP) ; PROMPT MOVE.L D2,-(SP) ; FILTER PROC MOVE.W D3,-(SP) ; numTypes MOVE.L D4,-(SP) ; typeList MOVE.L D5,-(SP) ; dlgHook MOVE.L D6,-(SP) ; reply MOVE #2,-(SP) ; routine selector _Pack3 RTS ; SFPGetFile(where, prompt, fileFilter, numTypes, typeList, ; dlgHook, reply, dlgID, filterProc) ; Point *where; (D0) ; struct PStr *prompt; (D1) ; int (*fileFilter)(); (D2) ; short numTypes; (D3) ; SFTypeList *typeList; (D4) ; int (*dlgHook)(); (D5) ; SFReply *reply; (D6) ; short dlgID; 8(A6) ; int (*filterProc)() 12(A6) SFPGetFile LINK A6,#0 MOVE.L D0,A0 MOVE.L (A0),-(SP) ; WHERE MOVE.L D1,-(SP) ; PROMPT MOVE.L D2,-(SP) ; FILTER PROC MOVE.W D3,-(SP) ; numTypes MOVE.L D4,-(SP) ; typeList MOVE.L D5,-(SP) ; dlgHook MOVE.L D6,-(SP) ; reply MOVE.W 10(A6),-(SP) ; dlgID MOVE.L 12(A6),-(SP) ; filterProc MOVE #4,-(SP) ; routine selector _Pack3 UNLK A6 RTS Module 'DiskInit' ; DILoad() DILoad MOVE #2,-(SP) ; routine selector _Pack2 RTS ; DIUnload() DIUnload MOVE #4,-(SP) ; routine selector _Pack2 RTS ; short DIBadMount(where,evtMessage) ; Point *where; (D0) ; long evtMessage; (D1) DIBadMount MOVE.W #0,-(SP) ; save space for result MOVE.L D0,A0 ; convert point to long MOVE.L (A0),-(SP) ; where MOVE.L D1,-(SP) ; evtMessage MOVE #0,-(SP) ; routine selector _Pack2 MOVE.W (SP)+,D0 RTS ; D0 contains error ; short DIFormat(drvNum) ; short drvNum; (D0) DIFormat MOVE.W #0,-(SP) ; save space for result MOVE.W D0,-(SP) ; drvNum MOVE #6,-(SP) ; routine selector _Pack2 MOVE.W (SP)+,D0 RTS ; D0 contains error ; short DIVerify(drvNum) ; short drvNum; (D0) DIVerify MOVE.W #0,-(SP) ; save space for result MOVE.W D0,-(SP) ; drvNum MOVE #8,-(SP) ; routine selector _Pack2 MOVE.W (SP)+,D0 RTS ; D0 contains error ; short DIZero(drvNum,volName) ; short drvNum; (D0) ; Str255 *volName; (D1) DIZero MOVE.W #0,-(SP) ; save space for result MOVE.W D0,-(SP) ; drvNum MOVE.L D1,-(SP) ; volName MOVE #10,-(SP) ; routine selector _Pack2 MOVE.W (SP)+,D0 RTS ; D0 contains error END =========================StringLib.c============================== /* * StringLib.C Andrew G. Shebanow 8/2/85 * * Routines for doing operations on Pascal strings in Mac C. * * Copyright 1985 HyperSoft All Rights Reserved */ #include #include /* this is a library of routines */ #Options M /* some handy definitions */ /* miscellaneous definitions */ #define VOID void #define BYTE char #define WORD short #define LONG int #define UBYTE unsigned char #define UWORD unsigned short #define ULONG unsigned int #define REG register #define LOCAL static #define GLOBAL /* */ #define EXTERN extern #define TYPEDEF typedef #define STRUCT struct #define UNION union /* pascal boolean definitions */ #define TRUE 1 #define FALSE 0 #define NULL 0 /* * StrUpper: * * Converts a strings contents to uppercase. No checking for * international characters is done. */ GLOBAL VOID StrUpper(str) StringPtr str; { UBYTE cntr, lim; UBYTE ch; lim = str->count; for (cntr = 0; cntr < lim; cntr++) { ch = str->s[cntr]; if ((ch >= 'a') && (ch <= 'z')) str->s[cntr] = (ch - 'a' + 'A'); } } /* * AppendStr: * * Append str2 to str1. It is assumed that str1 has all 255 bytes * of data allocated to it. */ GLOBAL VOID AppendStr(str1,str2) StringPtr str1; StringPtr str2; { UBYTE cntr; UBYTE lim; UBYTE offst; if ((str2 == NULL) || (str2->count == 0)) return; if ((str1->count + str2->count) > 255) lim = 255 - str1->count; else lim = str2->count; offst = str1->count; for (cntr = 0; cntr < lim; cntr++) str1->s[offst + cntr] = str2->s[cntr]; str1->count += lim; } /* * CopyStr: * * copies source string to destination string. */ GLOBAL VOID CopyStr(srcStr,dstStr) REG StringPtr srcStr; REG StringPtr dstStr; { REG UBYTE cntr; REG UBYTE lim; lim = srcStr->count; dstStr->count = lim; for (cntr = 0; cntr < lim; cntr++) dstStr->s[cntr] = srcStr->s[cntr]; } /* * GetSuffix: * * searches a filename for a suffix (eg, ".c"), and copies the suffix * into another string. Note that it searches BACKWARDS into the string, so * the file 'Crazy Name.file.c' has a suffix string of '.c'! */ GLOBAL LONG GetSuffix(fileName,suffix) StringPtr fileName; StringPtr suffix; { WORD cntr; WORD lim; WORD found = FALSE; UBYTE dcntr = 0; lim = (WORD) (fileName->count & 0x0ff); suffix->count = 0; if (lim == 0) return(FALSE); for (cntr = lim - 1; cntr >= 0; cntr--) if (fileName->s[cntr] == '.') { found = TRUE; break; } if (found == FALSE) return(FALSE); while (cntr < lim) { suffix->s[dcntr++] = fileName->s[cntr++]; suffix->count += 1; } return(TRUE); } /* * ChangeSuffix: * * searches a string for a suffix (eg, ".c"), and copies the string * to a destintaion string, using the new suffix passed to it. */ GLOBAL VOID ChangeSuffix(srcStr,dstStr,suffix) StringPtr srcStr; StringPtr dstStr; StringPtr suffix; { UBYTE cntr, lim; WORD found = FALSE; UBYTE dcntr = 0; lim = srcStr->count; dstStr->count = 0; if (lim == 0) { /* copy suffix string to dest string */ CopyStr(suffix,dstStr); return; } /* copy entire string */ CopyStr(srcStr,dstStr); /* search for start of suffix, moving backwards */ for (cntr = lim - 1; cntr >= 0; cntr--) if (dstStr->s[cntr] == '.') { found = TRUE; break; } if (found == TRUE) dstStr->count = cntr; /* truncate the string */ /* append new suffix */ AppendStr(dstStr,suffix); return; } /**************************** end of StringLib.C *********************/ =========================TECalls.c============================== /* * TECalls.c Dave Burnard 7/6/85 * * TEScrap ToolBox Extension Routines. Desribed in the TextEdit section * of Inside Mac. * * Copyright 1985 Dave Burnard * * Modifications: * * 10/18/85 Cosmetic modifications to match rest of library (AGS) */ #Options +Z #include "MacDefs.h" #include "Memory.h" #define OSErr short /* ToolBox Global access */ #define TEScrpLength *((short *)0x0AB0) #define TEScrpHandle *((Handle *)0x0AB4) /* * TEScrapHandle: * * returns a handle to the text edit scrap. */ Handle TEScrapHandle() { return(TEScrpHandle); } /* * TEGetScrapLen: * * returns the length of the TextEdit scrap. */ long TEGetScrapLen() { return(TEScrpLength); } /* * TESetScrapLen: * * sets the length of the text edit scrap. Presumably called after * you put something in the scrap. */ void TESetScrapLen(length) long length; { TEScrpLength = (short) length; } /* * TEFromScrap: * * Sets the TE scrap to have a copy of the real scrap data. * Note that the function actually returns the scrap length, not the * OSErr as it should. Maybe a call to MemError() would result in * the desired result? */ OSErr TEFromScrap() { long offset,length; length = GetScrap(TEScrapHandle(), 'TEXT', &offset); if (length > 0) { TESetScrapLen(length); } return((OSErr) length); } /* * TEToScrap: * * copy TE scrap to real scrap. MUST be preceded by a call to ZeroScrap! * Note that the function actually returns the scrap length, not the * OSErr as it should. Maybe a call to MemError() would result in * the desired result? */ OSErr TEToScrap() { Ptr *TEScrapH; long length; HLock(TEScrapH = TEScrapHandle()); length = PutScrap(TEGetScrapLen(), 'TEXT', *TEScrapH); HUnlock(TEScrapH); /* if length is <0, it is an error code */ if (length >= 0) { length = 0; } return((OSErr) length); } /****************************** end of TECalls.c *************************/ =========================ToolUtils.c============================== /* * ToolUtils.c Andrew G. Shebanow 9/3/85 * * Implementation of ToolBox utility routines for MacC. These * routines emulate the [ No Trap Macro ] routines documented in the * ToolBox Utilities section of Inside Mac. */ #include #include #include /* pascal boolean definitions */ #define TRUE 1 #define FALSE 0 #define NULL 0 /* this is a library of routines */ #Options M /* * GetIndString: * * This function attempts to read a 'STR#' resource into memory * and extract an individual string from that resource. */ GetIndString(theString,strListID,index) StringPtr theString; /* set to the string */ unsigned short strListID; /* the id of the STR# resource */ unsigned short index; /* index (range 1-n) of desired Str255 */ { StringHandle strHandle; register unsigned char *strPtr; register unsigned char idx; unsigned char lcntr, total; unsigned short *cntPtr, cnt; strHandle = (StringHandle) GetResource('STR#',strListID); if (strHandle == NULL) { theString->count = 0; return; } HLock(strHandle); cntPtr = (unsigned short *) *strHandle; cnt = *cntPtr; if (index > cnt) { theString->count = 0; return; } strPtr = (unsigned char *) ++cntPtr; index -= 1; for (idx = 0; idx < index; idx++) { /* get the strings before the desired string */ total = *strPtr; strPtr += (total + 1); } theString->count = *strPtr; strPtr++; total = theString->count; for (lcntr = 0; lcntr < total; lcntr++) { theString->s[lcntr] = *strPtr; strPtr++; } HUnlock(strHandle); } typedef struct { short count; Pattern thePats[100]; } PatList; GetIndPattern(thePattern,patListID,index) Pattern *thePattern; short patListID; short index; { PatList **patHandle; PatList *patPtr; patHandle = (PatList **) GetResource('PAT#',patListID); if (patHandle == NULL) return; HLock(patHandle); patPtr = *patHandle; if (index > patPtr->count) { HUnlock(patHandle); return; } BlockMove(&(patPtr->thePats[index]),thePattern,8); HUnlock(patHandle); } void ScreenRes(scrVRes,scrHRes) short *scrVRes; /* D0.L */ short *scrHRes; /* D1.L */ { #asm ; These constants are defined in ; Macintosh Technical Note 16: MacWorks XL Owners Manual ScrVRes EQU $102 ScrHres EQU $104 MOVEM.L A0-A1,-(SP) ; save registers MOVE.L D0,A0 ; put variables in address registers MOVE.L D1,A1 MOVE.W ScrVRes,(A0) ; store into variable MOVE.W ScrHRes,(A1) ; ditto MOVEM.L (SP)+,A0-A1 ; restore registers #endasm } /**************************** end of ToolUtils.c *********************/