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

system.verbs.builtins.webserver.processMacros

on processMacros (text, adrVar = nil) {
	try {
		with webServer.standardMacros {
			local (tag = "<!--#");
			if defined (adrVar^) { << evaluate macro with optional table of params
				with adrVar^ { <<items in adrvar table override items in macros table
					if string.patternMatch (tag , text ) < 1 {
						return (text)}; <<no macros
					local (i, z, workCopy);
					workCopy = string.replaceAll (text, tag, ""); << change to one char for string.nthField
					for i = 2 to string.countFields (workCopy, "") {
						local (tempString = string.nthField (workCopy, "", i), macroString = "");
						tempString = string.replaceAll (tempString, "\\\"", ""); <<replace escaped quotes
						for z = 1 to string.countFields (tempString, "\"") { <<build macrostring, ignoring things between quotes
							local (testString = string.nthField (tempString, "\"", z));
							if (mod (z, 2)) > 0 { << test even/odd
								if string.patternMatch ("-->", testString) > 0 {
									testString = string.delete (testString, string.patternMatch ("-->", testString), sizeOf (testString));
									macroString = macroString + testString;
									break}; <<loop ends when we get to a > outside of quotes
								macroString = macroString + testString + "\""}
							else {
								macroString = macroString + testString + "\""}};
						macroString = string.replaceAll (macroString , "", "\\\""); <<put escaped quotes back
						if string.patternMatch ("(", macroString) < 1 { << no parentheses, not a script 
							if defined (macroString^) {
								case typeOf (macroString^) {
									stringType {
										text = string.replaceAll (text, tag + macroString + "-->", macroString^)};
									wpTextType {
										text = string.replaceAll (text, tag + macroString + "-->", string (macroString^))}}}
							else {
								text = string.replaceAll (text, tag + macroString + "-->", "")}}
						else { << it has parentheses and will be dealt with like a script
							try {
								local (evaluationString = string (evaluate (macroString)));
								text = string.replace (text, tag + macroString + "-->", evaluationString)}
							else {
								text = string.replaceAll (text, tag + macroString + "-->", "")}}}}}
			else { << same thing without optional table of params
				if string.patternMatch (tag , text ) < 1 {
					return (text)}; <<no macros
				local (i, z, workCopy);
				workCopy = string.replaceAll (text, tag, ""); << change to one char for string.nthField
				for i = 2 to string.countFields (workCopy, "") {
					local (tempString = string.nthField (workCopy, "", i), macroString = "");
					for z = 1 to string.countFields (tempString, "\"") { <<build macrostring, ignoring things between quotes
						local (testString = string.nthField (tempString, "\"", z));
						if (mod (z, 2)) > 0 { << test even/odd
							if string.patternMatch ("-->", testString) > 0 {
								testString = string.delete (testString, string.patternMatch ("-->", testString), sizeOf (testString));
								macroString = macroString + testString;
								break}; <<loop ends when we get to a > outside of quotes
							macroString = macroString + testString + "\""}
						else {
							macroString = macroString + testString + "\""}};
					if string.patternMatch ("(", macroString) < 1 { << no parentheses, not a script 
						if defined (macroString^) {
							case typeOf (macroString^) {
								stringType {
									text = string.replaceAll (text, tag + macroString + "-->", macroString^)};
								wpTextType {
									text = string.replaceAll (text, tag + macroString + "-->", string (macroString^))}}}
						else {
							text = string.replaceAll (text, tag + macroString + "-->", "")}}
					else { << it has parentheses and will be dealt with like a script
						try {
							local (transform = string (evaluate (macroString)));
							text = string.replace (text, tag + macroString + "-->", transform)}
						else {
							text = string.replaceAll (text, tag + macroString + "-->", "")}}}}};
		return (text)}
	else {
		return (webServer.errorMessage (tryError))}}



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.