Monday, November 08, 2010 at 12:02 AM.


<<this script is embedded in the MacBird program
	<<it's in 'scpt' resource 128
	<<it's called in iowafrontier.c

<<card-runtime support scripts
on init (tablename, packedtable, fsapp, filelist) { <<start a card
	<<create a table for the card, run the startCard script
		<<we unpack the table as a sub-table in
			<<or create an empty one if packedtable is empty
		<<dmb 9/30/96: we don't call startcard anymore
			<<it's too soon. the runtime will call it directly after 
			<<doing all of its default setup.
			<<also, startcard needs to run in the card context, which 
			<<none of these event handlers require.
		<<dmb 9/13/96: we no longer support cards as apps:
			<<set up two items in the table: files and path
				<<files is a list, containing the files dropped onto the app
				<<you can refer to these as files [1], files [2], etc.
				<<path is a file spec for the application that opened the card
		<<if there's a startup script in the table, we run it
		<<returns the name of the table we created for the card
	<<make sure the base table exists
	local (adrBaseTable =;
	if not defined (adrBaseTable^) {
		new (tableType, adrBaseTable)};
	if sizeOf (tablename) == 0 { <<Iowa Runtime doesn't have a name, make one up
		tablename = nameOf (table.uniqueName ("card", adrBaseTable)^)};
	<<unpack the card's table, or create an empty one if it doesn't have one
	local (adrTable = @adrBaseTable^.[tablename]);
	if sizeOf (packedtable) > 0 {
		unpack (@packedtable, adrTable)}
	else {
		new (tableType, adrTable)};
	<<initialize the contents of the table
	if defined (adrTable^.path) { <<get rid of old field
		delete (@adrTable^.path)};
	if defined (adrTable^.files) { <<transition from a table to a list
		delete (@adrTable^.files)};
	<<adrTable^.path = fsapp <<it's still called a path, just like desktop scripts & droplets
	<<if filelist == nil
		<<adrTable^.files = {}
		<<adrTable^.files = filelist
	<<patch Frontier's paths table, switch in this card's menu bar if it has one
	card.setGlobalTable (adrTable, true);
	<<if defined (adrTable^.startCard)
		<<if runmode
			<<adrTable^.startCard ()
				<<adrTable^.startCard ()
				<<adrTable^.startCardError = tryError
	return (tablename)};
on clos (tablename) { <<close a card
	local (adrTable =;
	if defined (adrTable^) {
		local (adrTable = @adrTable^.[tablename]);
		if defined (adrTable^) {
			if defined (adrTable^.parentPath) {
				card.bringCardToFront (file.fileFromPath (adrTable^.parentPath))};
			delete (adrTable)};
		return (true)}};
on edtb (tablename, windowtitle) { <<edit the table embedded in the card 
	local (adrTable =[tablename]);
	target.set (adrTable);
	window.setTitle (adrTable, windowtitle);
	edit (adrTable);
	Frontier.bringToFront ();
	return (true)};
on gett (tablename) { <<return the packed table
	local (data);
	pack ([tablename], @data);
	return (data)};
on sett (tablename, majorswitch) { <<the table becomes the current table
	<<dmb 9/6/96: after making sure the table exists, let card.setGlobalTable do the work
		<<also, handle empty string for when a card is switching out
	local (adrTable);
	if tablename == "" {
		adrTable = nil}
	else {
		adrTable =[tablename];
		if not defined (adrTable^) {
			new (tableType, adrTable)}};
	return (card.setGlobalTable (adrTable, majorswitch))};

<<clay basket macro language support scripts
on dosc (s) { <<runs a macro, for Clay Basket
	try { = s;
		with {
			return (string (evaluate (s)))}}
	else {
		scriptError (toys.cleanForExport (tryError))}};
on addg (name, value, type) { <<add a name/value to the glossary
	local (adrsubtable = [name]);
	if defined (adrsubtable^) {
		if not dialog.confirm ("OK to replace existing glossary entry named \"" + name + "\"?") {
			return (false)}}
	else {
		new (tabletype, adrsubtable)};
	adrsubtable^.v = value;
	adrsubtable^.t = type; ();
	return (true)};
on refg (name) { <<turn a glossary entry name into a string for insertion into HTML text
	local (adrsubtable = [name]);
	if not defined (adrsubtable^) {
		scriptError ("There is no glossary entry named \"" + name + "\"")};
	with adrsubtable^ {
		case t {
			0 {
				return (v)};
			1 {
				return ("<a href=\""+ v + "\">" + name + "</a>")};
			2 {
				return ("<a href=\"mailto:"+ v + "\">" + name + "</a>")}}
		else {
			scriptError ("Unsupported glossary type, number = " + t)}}};
on edtg () { <<bring Frontier to the front and edit the glossary table
	frontier.bringtofront ();
	edit (;
	return (true)}

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.