home *** CD-ROM | disk | FTP | other *** search
- //*[nsup.js]******************************************************************
- //
- // NeilStuff.com Update Script
- //
- //-[History]------------------------------------------------------------------
- // 2006-05-18 by NeilO .... Created.
- //
- //****************************************************************************
-
- var fso = new ActiveXObject("Scripting.FileSystemObject");
-
- var folder = fso.GetFolder("E:\\Archive\\Neil's C++ Stuff\\2000-01-28 (v01.01f)\\Client");
-
- var en = new Enumerator(folder.Files);
-
- var fi = fso.GetFile("c:\\stuff\\neilstuff_com\\cpp\\a_arrays.htm");
- WScript.Echo(fi.Attributes);
-
- for ( ; !en.atEnd(); en.moveNext() )
- {
- WScript.Echo(" Processing \"" + en.item().Name + "\"");
-
- if (!en.item().Name.match(/\.htm$/))
- continue;
-
- // ignore if Read-Only
- if (1 == (en.item().Attributes & 1))
- continue;
-
- var stream = en.item().OpenAsTextStream();
- var sText = stream.ReadAll();
- stream.Close();
-
- var bi = sText.indexOf("<SCRIPT LANGUAGE=\"JavaScript\"> <!--");
- if (bi > 0)
- {
- var ei = sText.indexOf("</SCRIPT>", bi);
- if (ei > 0)
- {
- sText = sText.substr(0, bi) +
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/global.js\"></SCRIPT>" +
- sText.substr(ei + 9);
- }
- }
-
- if (sText.indexOf("\"header.js\"") < 0)
- sText = sText.replace(/(\<BODY[^>]+>)/, "$1\r\n<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/header.js\"></SCRIPT>\r\n");
-
- sText = sText.replace("<!-- contact form has been removed ... i placed the source for it in \"oldcform.stx\" -->",
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/footer.js\"></SCRIPT>");
-
- var i = sText.indexOf("fastcounter");
- if (i > 0)
- {
- bi = sText.lastIndexOf("<TD ALIGN=RIGHT>", i);
- if (bi > 0)
- {
- var ei = sText.indexOf("1090661\"></A></TD>");
- if (ei > 0)
- {
- sText = sText.substr(0, bi) +
- "<TD ALIGN=RIGHT><SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/counter.js\"></SCRIPT></TD>" +
- sText.substr(ei + 18);
- }
- }
- }
-
- sText = sText.replace("life-long beautiful lovin' (wife)", "lovin' wife");
-
- sText = sText.replace("<I>Download the site in ZIP format <A HREF=\"zip/cppstuff.zip\">here</A>.</I><BR>",
- "<I>The site ZIP has been removed due to copy abuse.</I><BR>");
-
- try
- {
- stream = fso.CreateTextFile("cpp\\" + en.item().Name, true);
- stream.Write(sText);
- stream.Close();
- }
- catch (e)
- {
- WScript.Echo(" Failed to change " + en.item().Name);
- }
- }
-
- //
- // Process Neil's Guide to C++
- //
-
- WScript.Echo("Processing Neil's Guide to C++");
-
- var sitemap = [ ];
-
- var folder = fso.GetFolder("guide_to_c++");
-
- var en = new Enumerator(folder.Files);
-
- for ( ; !en.atEnd(); en.moveNext() )
- {
- if (!en.item().Name.match(/\.htm$/))
- continue;
-
- if ("index.htm" == en.item().Name)
- continue;
-
- var o = ProcessGuideItem(null, en.item());
-
- sitemap.push(o);
-
- } // for ()
-
- var fen = new Enumerator(folder.SubFolders);
- for ( ; !fen.atEnd(); fen.moveNext() )
- {
- var Base = fen.item().Name;
-
- sitemap.push(null);
-
- var en = new Enumerator(fen.item().Files);
-
- for ( ; !en.atEnd(); en.moveNext() )
- {
- if (!en.item().Name.match(/\.htm$/))
- continue;
-
- var o = ProcessGuideItem(Base, en.item());
-
- sitemap.push(o);
-
- }
- }
-
- var stream = fso.OpenTextFile("guide_to_c++\\index.htm");
- var sMainPage = stream.ReadAll();
- stream.Close();
-
- var bi = sMainPage.indexOf("<!--main1-->");
- if (bi >= 0)
- {
- bi += 12;
- ei = sMainPage.indexOf("<!--main2-->", bi);
- if (ei >= 0)
- {
- sMainPage = sMainPage.slice(bi, ei);
- }
- }
-
- try
- {
- var stream = fso.CreateTextFile("guide_to_c++\\index.htm", true);
- stream.WriteLine("<HTML><HEAD><TITLE>");
- stream.WriteLine("Neil's Guide to C++ (abandoned book)");
- stream.WriteLine("</TITLE>");
- stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/global.js\"></SCRIPT>");
- stream.WriteLine("</HEAD><BODY>");
- stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/header.js\"></SCRIPT>");
- stream.WriteLine("<H1>Neil's Guide to C++</H2>");
- stream.WriteLine("<H5>An abandoned C++ book written by Neil C. Obremski in 2001-2002</H5>");
- stream.WriteLine("<HR/>");
-
- var Section = null;
-
- for (var i = 0; i < sitemap.length; i++)
- {
- var o = sitemap[i];
- if (null == o)
- stream.WriteLine("<BR/>");
- else
- stream.WriteLine("<A HREF=\"" + o.vfn + "\">" + o.title + "</A><BR/>");
-
- }
- stream.WriteLine("<HR/>");
-
- stream.WriteLine("<!--main1-->" + sMainPage + "<!--main2-->");
-
- stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/counter.js\"></SCRIPT>");
- stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/footer.js\"></SCRIPT>");
- stream.WriteLine("</BODY></HTML>");
-
- stream.Close();
- }
- catch (e)
- {
- WScript.Echo(" Could not write index file");
- }
-
- for (var i = 0; i < sitemap.length; i++)
- {
- if (null != sitemap[i])
- UpdateGuideItem(sitemap[i]);
- }
-
- function ProcessGuideItem(Base, item)
- {
- var o =
- {
- fn : item.Name,
- full : item.Path,
- vfn : Base + "/" + item.Name
- };
-
- if (null == Base)
- o.vfn = item.Name;
-
- if ("notes" == Base)
- Base = "Notes";
- else if ("part1" == Base)
- Base = "Part 1";
- else if ("part2" == Base)
- Base = "Part 2";
-
- var sDots = "..";
- if (null != Base)
- sDots += "/..";
-
- o.Dots = sDots;
-
- var stream = item.OpenAsTextStream();
- var sText = stream.ReadAll();
- stream.Close();
-
- var m = sText.match(/<title>([^<]+)<\/title>/i);
-
- //var m = o.fn.match(/^Chapter\s+([0-9]+): (.*)
- if (null != m)
- {
- if (null != Base)
- o.title = Base + ": " + m[1];
- else
- o.title = m[1];
- }
- else
- {
- WScript.Echo(" No title: \"" + item.Name + "\"");
- }
-
- // don't change it if its Read-Only
- if (1 == (item.Attributes & 1))
- o.readonly = true;
-
- o.Text = sText;
-
- return o;
- }
-
- function UpdateGuideItem(o)
- {
- if (o.readonly)
- return false;
-
- WScript.Echo(" Updating \"" + o.title + "\"");
-
-
- if (o.Text.indexOf("global.js\"") < 0)
- {
- var i = o.Text.indexOf("</head>");
-
- o.Text = o.Text.substr(0, i) +
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
- o.Dots + "/archjs/global.js\"></SCRIPT>\r\n" +
- o.Text.substr(i);
- }
-
- if (o.Text.indexOf("header.js\"") < 0)
- {
- var i = o.Text.indexOf("<body");
-
- i = o.Text.indexOf(">", i) + 1;
-
- o.Text = o.Text.substr(0, i) +
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
- o.Dots + "/archjs/header.js\"></SCRIPT>\r\n" +
- o.Text.substr(i);
- }
-
- if (o.Text.indexOf("footer.js\"") < 0)
- {
- var i = o.Text.indexOf("</body>");
-
- o.Text = o.Text.substr(0, i) +
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
- o.Dots + "/archjs/counter.js\"></SCRIPT>\r\n" +
- "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
- o.Dots + "/archjs/footer.js\"></SCRIPT>\r\n" +
- o.Text.substr(i);
- }
-
- WScript.Echo(" * " + o.full);
- var stream = fso.CreateTextFile(o.full, true);
- stream.Write(o.Text);
- stream.Close();
-
- return true;
- }