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

on fixCategoryNameDirectives (adrdata) {
		<<2/13/02; 12:20:58 PM by JES
			<<Loop over all the categories, and make sure that for each one, a #prefs.txt file exists, which contains a #categoryName directive, that specifies the category.
	if defined (adrdata^.stats.flCategoryPrefsFilesExist) {
		return (false)};
	local (adrcategories = @adrdata^.categories);
	local (adrcat);
	for adrcat in adrcategories {
		local (catname = nameOf (adrcat^));
		local (catfolder = radio.weblog.file.getCategoryFolder (catname));
		local (prefsfile = catfolder + "#prefs.txt");
		if file.exists (prefsfile) {
			local (s = file.readWholeFile (prefsfile));
			if string.lower (s) contains "#categoryname " {
			s = string.replaceAll (s, "\r\n", "\r");
			s = string.replaceAll (s, "\n", "\r");
			s = "#categoryName \"" + string.replaceAll (catname, "\"", "\\\"") + "\"\r" + s;
			file.writeTextFile (prefsfile, s)}
		else {
			if file.exists (catfolder + "#prefs.opml") {
				prefsfile = catfolder + "#prefs.opml";
				local (lo);
				op.xmlToOutline (file.readWholeFile (prefsfile), @lo);
				local (oldtarget = target.set (@lo));
				op.insert ("#categoryName \"" + string.replaceAll (catname, "\"", "\\\"") + "\"", up);
				try {target.set (oldtarget)};
				file.writeTextFile (prefsfile, op.outlineToXml (@lo))}
			else {
				local (s = "#categoryName \"" + string.replaceAll (catname, "\"", "\\\"") + "\"");
				file.sureFilePath (prefsfile);
				file.writeTextFile (prefsfile, s)}}};
	adrdata^.stats.flCategoryPrefsFilesExist = true}
<<bundle //testing
	<<fixcategoryNameDirectives (@weblogData)

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.