[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Perl Help, Shuck, AppleScript



johnb@tempest.net.hk writes:
>But I've found that the above script only works when an entry for the
>function 'foo' appears as a single word item in the pod file, i.e. it's a
>function which can take no parameters. E.g. looking up "time", "split" and
>"tell" works but "gmtime", "join" and "telldir" doesn't.
>
>So does anyone know the correct way to get Shuck to look up functions via
>AppleScript/AppleEvents ? I hope it's possible as MacPerl manages it somehow.

What Perl does is looking up the search key in the dbm file "MacPerl Help",
which results in an URL that MacPerl sends off via Internet Config.

>And would it be possbile to generalise this to look up anything anywhere,
>i.e. not just functions in perlfunc.pod ?

This is done the same way.

I could & should make this method available, probably by adding a "HELP"
AppleEvent to MacPerl and/or Shuck, which should be a matter of a few
minutes.

For your curiosity, I've appended the source code currently built into Perl &
Shuck below.

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
  "Then anyone who leaves behind him a written manual, and likewise
   anyone who receives it, in the belief that such writing will be
   clear and certain, must be exceedingly simple-minded..."
                                                -- Plato, _Phaedrus_

void Lookup(char * start, int len)
{
	datum		key;
	datum		data;

	key.dptr		= start;
	key.dsize	= len;
	data = dbm_fetch(gIndex, key);

	if (!data.dptr) {
		SysBeep(1);
	} else {
		LaunchIndexURL(data.dptr, data.dsize);
	}
}

char * gHex = "0123456789ABCDEF";

void LaunchIndexURL(char * urlPtr, int urlLen)
{
	int		len;
	char		urlBuf[300];
	char *	url = urlBuf+8;
	char *	end;

	strcpy(urlBuf+1, "Helper ");
	if (*urlPtr == '!')
		return;		/* False positive */
	if ((!strncmp(urlPtr, "file:", 5) && urlPtr[5] != '/')
	 || (!strncmp(urlPtr, "pod:", 4) && urlPtr[4] != '/')
	) {
		char *	path;
		char *	urlPath;
		FSSpec	here;

		here.vRefNum	= gIndexVol;
		here.parID		= gIndexDir;

		FSpUp(&here);
		*strchr(urlPtr, ':') = 0;
		strcpy(url, urlPtr);
		strcat(url, ":///");
		urlLen -= strlen(urlPtr)+1;
		urlPtr += strlen(urlPtr)+1;
		urlPtr[-1] = ':';
		urlPath	= url+strlen(url);
		for (path = FSp2FullPath(&here); *path; path++)
			switch (*path) {
			case ':':	/* Translate directory separators */
				*urlPath++ = '/';
				break;
			case '<':	/* Encode dangerous characters */
			case '>':
			case '+':
			case '\"':
			case '*':
			case '%':
			case '&':
			case '/':
			case '(':
			case ')':
			case '=':
			case '?':
			case '\'':
			case '`':
			case '^':
			case '$':
			case '#':
			case ' ':
				*urlPath++ = '%';
				*urlPath++ = gHex[(*path >> 4) & 15];
				*urlPath++ = gHex[*path & 15];
				break;
			default:
				*urlPath++ = *path;
				break;
			}
		if (urlPath[-1] != '/')
			*urlPath++ = '/';
		memcpy(urlPath, urlPtr, urlLen);
		len = urlPath - url + urlLen;
	} else {
		memcpy(url, urlPtr, urlLen);
		len = urlLen;
	}

	if (end = (char *) memchr(url, ':', len)) {
		urlBuf[0] = end-urlBuf-1;
	}

	if (gICInstance) {
		long		selStart	= 0;
		long		selEnd	= len;

		if (!ICLaunchURL(gICInstance, "\p", url, len, &selStart,
&selEnd))
			return;
		else {
			ICAttr	attr;
			long		size			=	0;

			if (end) {

				if(ICGetPref(gICInstance, (StringPtr) urlBuf,
&attr, nil, &size) == icPrefNotFoundErr) {
					SetCursor(&qd.arrow);
					url[-1] = urlBuf[0]-7;
					ParamText((StringPtr)(url-1),
(StringPtr)"\p", (StringPtr)"\p", (StringPtr)"\p");
					if (Alert(kHelperAlert, nil) == 1) {
						url[-1] = ' ';
						ICEditPreferences(gICInstance,
(StringPtr) urlBuf);
					}
					return;
				}
			}
		}
	}
	MetaHelp("\pFailed to launch help viewer. "
				"Please make sure that you have Internet Config
1.2 or later "
				"installed set up valid helpers for http,,
file  and/or pod"",
				(StringPtr) "\p", (StringPtr) "\p", (StringPtr)
"\p");
}