Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!eecae!tank!nucsrl!accuvax.nwu.edu!jln From: jln@accuvax.nwu.edu (John Norstad) Newsgroups: comp.sys.mac.programmer Subject: Re: How to use ParamText's Message-ID: <10050090@accuvax.nwu.edu> Date: 14 Mar 89 21:23:11 GMT References: <8079@csli.STANFORD.EDU> Organization: Northwestern U, Evanston IL, USA Lines: 78 Try the following (MPW C 3.0). It's cryptic (in the most hallowed C tradition), and it's not incredibly effecient, but it works. /*______________________________________________________________________ PlugParams - Plug parameters into message. Entry: line1 = input line. p0, p1, p2, p3 = parameters. Exit: line2 = output line. This routine works just like the toolbox routine ParamText. The input line may contain place-holders ^0, ^1, ^2, and ^3, which are replaced by the parameters p0-p3. The input line must not contain any other ^ characters. The input and output lines may not be the same string. Pass nil for parameters which don't occur in line1. If the output line exceeds 255 characters it's truncated. _____________________________________________________________________*/ void PlugParams (Str255 line1, Str255 line2, Str255 p0, Str255 p1, Str255 p2, Str255 p3) { char *in; /* pointer to cur pos in input line */ char *out; /* pointer to cur pos in output line */ char *inEnd; /* pointer to end of input line */ char *outEnd; /* pointer to end of output line */ char *param; /* pointer to param to be plugged */ short len; /* length of param */ in = line1+1; out = line2+1; inEnd = line1 + 1 + *line1; outEnd = line2 + 256; while (in < inEnd ) { if (*in == '^') { in++; if (in >= inEnd) break; switch (*in++) { case '0': param = p0; break; case '1': param = p1; break; case '2': param = p2; break; case '3': param = p3; break; default: continue; }; if (!param) continue; len = *param; if (out + len > outEnd) len = outEnd - out; memcpy(out, param+1, len); out += len; } else { if (out >= outEnd) break; *out++ = *in++; }; }; *line2 = out - (line2+1); }; John Norstad Academic Computing and Network Services Northwestern University Bitnet: jln@nuacc Internet: jln@acns.nwu.edu Applelink: a0173