home *** CD-ROM | disk | FTP | other *** search
/ Neil's C++ Stuff / 2006-05-neilstuff_com.iso / nsup.js < prev   
Text File  |  2006-05-18  |  7KB  |  293 lines

  1. //*[nsup.js]******************************************************************
  2. //
  3. // NeilStuff.com Update Script
  4. //
  5. //-[History]------------------------------------------------------------------
  6. // 2006-05-18 by NeilO .... Created.
  7. //
  8. //****************************************************************************
  9.  
  10. var fso = new ActiveXObject("Scripting.FileSystemObject");
  11.  
  12. var folder = fso.GetFolder("E:\\Archive\\Neil's C++ Stuff\\2000-01-28 (v01.01f)\\Client");
  13.  
  14. var en = new Enumerator(folder.Files);
  15.  
  16. var fi = fso.GetFile("c:\\stuff\\neilstuff_com\\cpp\\a_arrays.htm");
  17. WScript.Echo(fi.Attributes);
  18.  
  19. for ( ; !en.atEnd(); en.moveNext() )
  20. {
  21.     WScript.Echo("  Processing \"" + en.item().Name + "\"");
  22.  
  23.     if (!en.item().Name.match(/\.htm$/))
  24.         continue;
  25.  
  26.     // ignore if Read-Only
  27.     if (1 == (en.item().Attributes & 1))
  28.         continue;
  29.     
  30.     var stream = en.item().OpenAsTextStream();
  31.     var sText = stream.ReadAll();
  32.     stream.Close();
  33.     
  34.     var bi = sText.indexOf("<SCRIPT LANGUAGE=\"JavaScript\"> <!--");
  35.     if (bi > 0)
  36.     {
  37.         var ei = sText.indexOf("</SCRIPT>", bi);
  38.         if (ei > 0)
  39.         {
  40.             sText = sText.substr(0, bi) +
  41.                 "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/global.js\"></SCRIPT>" +
  42.                 sText.substr(ei + 9);
  43.         }
  44.     }
  45.     
  46.     if (sText.indexOf("\"header.js\"") < 0)
  47.         sText = sText.replace(/(\<BODY[^>]+>)/, "$1\r\n<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/header.js\"></SCRIPT>\r\n");
  48.     
  49.     sText = sText.replace("<!-- contact form has been removed ... i placed the source for it in \"oldcform.stx\" -->",
  50.         "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/footer.js\"></SCRIPT>");
  51.  
  52.     var i = sText.indexOf("fastcounter");
  53.     if (i > 0)
  54.     {
  55.         bi = sText.lastIndexOf("<TD ALIGN=RIGHT>", i);
  56.         if (bi > 0)
  57.         {
  58.             var ei = sText.indexOf("1090661\"></A></TD>");
  59.             if (ei > 0)
  60.             {
  61.                 sText = sText.substr(0, bi) +
  62.                     "<TD ALIGN=RIGHT><SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/counter.js\"></SCRIPT></TD>" +
  63.                     sText.substr(ei + 18);
  64.             }
  65.         }
  66.     }
  67.     
  68.     sText = sText.replace("life-long beautiful lovin' (wife)", "lovin' wife");
  69.  
  70.     sText = sText.replace("<I>Download the site in ZIP format <A HREF=\"zip/cppstuff.zip\">here</A>.</I><BR>",
  71.         "<I>The site ZIP has been removed due to copy abuse.</I><BR>");
  72.  
  73.     try
  74.     {
  75.         stream = fso.CreateTextFile("cpp\\" + en.item().Name, true);
  76.         stream.Write(sText);
  77.         stream.Close();
  78.     }
  79.     catch (e)
  80.     {
  81.         WScript.Echo("  Failed to change " + en.item().Name);
  82.     }
  83. }
  84.  
  85. //
  86. // Process Neil's Guide to C++
  87. //
  88.  
  89. WScript.Echo("Processing Neil's Guide to C++");
  90.  
  91. var sitemap = [ ];
  92.  
  93. var folder = fso.GetFolder("guide_to_c++");
  94.  
  95. var en = new Enumerator(folder.Files);
  96.  
  97. for ( ; !en.atEnd(); en.moveNext() )
  98. {
  99.     if (!en.item().Name.match(/\.htm$/))
  100.         continue;
  101.     
  102.     if ("index.htm" == en.item().Name)
  103.         continue;
  104.  
  105.     var o = ProcessGuideItem(null, en.item());
  106.     
  107.     sitemap.push(o);
  108.  
  109. } // for ()
  110.  
  111. var fen = new Enumerator(folder.SubFolders);
  112. for ( ; !fen.atEnd(); fen.moveNext() )
  113. {
  114.     var Base = fen.item().Name;
  115.     
  116.     sitemap.push(null);
  117.     
  118.     var en = new Enumerator(fen.item().Files);
  119.  
  120.     for ( ; !en.atEnd(); en.moveNext() )
  121.     {
  122.         if (!en.item().Name.match(/\.htm$/))
  123.             continue;
  124.  
  125.         var o = ProcessGuideItem(Base, en.item());
  126.  
  127.         sitemap.push(o);
  128.  
  129.     }
  130. }
  131.  
  132. var stream = fso.OpenTextFile("guide_to_c++\\index.htm");
  133. var sMainPage = stream.ReadAll();
  134. stream.Close();
  135.  
  136. var bi = sMainPage.indexOf("<!--main1-->");
  137. if (bi >= 0)
  138. {
  139.     bi += 12;
  140.     ei = sMainPage.indexOf("<!--main2-->", bi);
  141.     if (ei >= 0)
  142.     {
  143.         sMainPage = sMainPage.slice(bi, ei);
  144.     }
  145. }
  146.  
  147. try
  148. {
  149.     var stream = fso.CreateTextFile("guide_to_c++\\index.htm", true);
  150.     stream.WriteLine("<HTML><HEAD><TITLE>");
  151.     stream.WriteLine("Neil's Guide to C++ (abandoned book)");
  152.     stream.WriteLine("</TITLE>");
  153.     stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/global.js\"></SCRIPT>");
  154.     stream.WriteLine("</HEAD><BODY>");
  155.     stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/header.js\"></SCRIPT>");
  156.     stream.WriteLine("<H1>Neil's Guide to C++</H2>");
  157.     stream.WriteLine("<H5>An abandoned C++ book written by Neil C. Obremski in 2001-2002</H5>");
  158.     stream.WriteLine("<HR/>");
  159.  
  160.     var Section = null;
  161.  
  162.     for (var i = 0; i < sitemap.length; i++)
  163.     {
  164.         var o = sitemap[i];
  165.         if (null == o)
  166.             stream.WriteLine("<BR/>");
  167.         else
  168.             stream.WriteLine("<A HREF=\"" + o.vfn + "\">" + o.title + "</A><BR/>");
  169.  
  170.     }
  171.     stream.WriteLine("<HR/>");
  172.  
  173.     stream.WriteLine("<!--main1-->" + sMainPage + "<!--main2-->");
  174.     
  175.     stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/counter.js\"></SCRIPT>");
  176.     stream.WriteLine("<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"../archjs/footer.js\"></SCRIPT>");
  177.     stream.WriteLine("</BODY></HTML>");
  178.  
  179.     stream.Close();
  180. }
  181. catch (e)
  182. {
  183.     WScript.Echo("  Could not write index file");
  184. }
  185.  
  186. for (var i = 0; i < sitemap.length; i++)
  187. {
  188.     if (null != sitemap[i])
  189.         UpdateGuideItem(sitemap[i]);
  190. }
  191.  
  192. function ProcessGuideItem(Base, item)
  193. {
  194.     var o =
  195.     {
  196.         fn : item.Name,
  197.         full : item.Path,
  198.         vfn : Base + "/" + item.Name
  199.     };
  200.  
  201.     if (null == Base)
  202.         o.vfn = item.Name;
  203.  
  204.     if ("notes" == Base)
  205.         Base = "Notes";
  206.     else if ("part1" == Base)
  207.         Base = "Part 1";
  208.     else if ("part2" == Base)
  209.         Base = "Part 2";
  210.     
  211.     var sDots = "..";
  212.     if (null != Base)
  213.         sDots += "/..";
  214.     
  215.     o.Dots = sDots;
  216.  
  217.     var stream = item.OpenAsTextStream();
  218.     var sText = stream.ReadAll();
  219.     stream.Close();
  220.  
  221.     var m = sText.match(/<title>([^<]+)<\/title>/i);
  222.  
  223.     //var m = o.fn.match(/^Chapter\s+([0-9]+): (.*) 
  224.     if (null != m)
  225.     {
  226.         if (null != Base)
  227.             o.title = Base + ": " + m[1];
  228.         else
  229.             o.title = m[1];
  230.     }
  231.     else
  232.     {
  233.         WScript.Echo("  No title: \"" + item.Name + "\"");
  234.     }
  235.  
  236.     // don't change it if its Read-Only
  237.     if (1 == (item.Attributes & 1))
  238.         o.readonly = true;
  239.  
  240.     o.Text = sText;
  241.     
  242.     return o;
  243. }
  244.  
  245. function UpdateGuideItem(o)
  246. {
  247.     if (o.readonly)
  248.         return false;
  249.  
  250.     WScript.Echo("  Updating \"" + o.title + "\"");
  251.  
  252.  
  253.     if (o.Text.indexOf("global.js\"") < 0)
  254.     {
  255.         var i = o.Text.indexOf("</head>");
  256.         
  257.         o.Text = o.Text.substr(0, i) +
  258.             "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
  259.             o.Dots + "/archjs/global.js\"></SCRIPT>\r\n" +
  260.             o.Text.substr(i);
  261.     }
  262.  
  263.     if (o.Text.indexOf("header.js\"") < 0)
  264.     {
  265.         var i = o.Text.indexOf("<body");
  266.         
  267.         i = o.Text.indexOf(">", i) + 1;
  268.         
  269.         o.Text = o.Text.substr(0, i) +
  270.             "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
  271.             o.Dots + "/archjs/header.js\"></SCRIPT>\r\n" +
  272.             o.Text.substr(i);
  273.     }
  274.  
  275.     if (o.Text.indexOf("footer.js\"") < 0)
  276.     {
  277.         var i = o.Text.indexOf("</body>");
  278.         
  279.         o.Text = o.Text.substr(0, i) +
  280.             "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
  281.             o.Dots + "/archjs/counter.js\"></SCRIPT>\r\n" +
  282.             "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
  283.             o.Dots + "/archjs/footer.js\"></SCRIPT>\r\n" +        
  284.             o.Text.substr(i);
  285.     }
  286.  
  287.     WScript.Echo("  * " + o.full);
  288.     var stream = fso.CreateTextFile(o.full, true);
  289.     stream.Write(o.Text);
  290.     stream.Close();
  291.  
  292.     return true;
  293. }