Path: utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: STR# rsrc question Message-ID: <27490@ucbvax.BERKELEY.EDU> Date: 12 Jan 89 02:57:29 GMT References: <0Xmt9Fp48k-004N0lC@andrew.cmu.edu> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 79 Here is what I use to modify strings in a STR# (change them, add and delete strings: /* Note that these string list functions, unlike the systems, are zero based. */ /* GetStrPtr - returns a pointer to the data of list. since we do no functions, we know that our calling won't move data. */ StringPtr GetStrPtr(list, where)StrList list;Integer where;{ register Integer i; register char *p; for(i = 0, p = (Ptr) &(**list).strs;i < where;i++){ p += Length(p) + 1; } return (StringPtr) p; } /* GetStr - retrieve a copy of a string from the list */ GetStr(list, where, s)StrList list;Integer where;Str255 s;{ StringPtr p; p = GetStrPtr(list, where); HLock(list); StrMove(p, s); HUnlock(list); } /* SetStr - change the ith string in the list. (Note: the list may change length as a result of this operation.) */ SetStr(list, where, s)StrList list;Integer where;Str255 s;{ StringPtr p; p = GetStrPtr(list, where); if(p == NIL) return; if(p[0] == s[0]){ HLock(list); StrMove(s, p); HUnlock(list); }else{ Munger(list, StripAddress(p) - StripAddress(*list), NIL, Length(p) + 1, s, Length(s) + 1); } } /* InsertStr - insert s in the list as the new 'where'th item */ InsertStr(list, where, s)IntList list;Integer where;Str255 s;{ StringPtr p; p = GetStrPtr(list, where); Munger(list, StripAddress(p) - StripAddress(*list), NIL, 0, s, Length(s) + 1); (**list).cnt++; } /* DeleteStr - remove the whereth item */ DeleteStr(list, where)StrList list;Integer where;{ StringPtr p; p = GetStrPtr(list, where); Munger(list, StripAddress(p) - StripAddress(*list), NIL, Length(p) + 1, p, 0); (**list).cnt--; } --- David Phillip Oster --"When we replace the mouse with a pen, Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee