PHP is defunct on my Debian box due to glibc package problems, so I
wrote a C# version of convert.php. Here it is for anyone who might be
having the same problem. (Note, this sucked up close to 300M of RAM when
I ran it.) Also, the hrefs in the htm files refer to filenames of all
lower-case characters, while the actual filenames are not all
lower-case. I've attached a Perl script to convert all files in the
current directory to lower case.

Johannes, thanks for taking the time to figure all of this out. :-)

Nick

On Mon, 2002-08-12 at 12:46, Guenther Roith wrote:

> Hi!
> 
> 
> > Hello!
> >
> > > GETTING THE MS .NET DOC TO WORK ON LINUX
> > > ========================================
> >
> > Thanks for the precise instructions!  This is pretty good!
> >
> >
> > > 5. Change to it and type
> > >
> > > "C:\program files\Microsoft Help 2.0 SDK\hxcomp.exe" -u C:\program
> > > files\Microsoft.N
> > > ET\FrameworkSDK\Docs\1031\cpref.HxS
> > >
> > > at the command line. Your path may be a bit different.
> > >
> > > This can take some time.
> >
> >
> > Ok, I have arrived this far, but now I am running into trouble in the
> > next step:
> >
> > > 6. You will have some files in it and a sub-directory called "html" as
> well
> > > as "Scripts".
> > > Copy the file dtue.css in "Scripts" one dir level higher, that it is one
> dir
> > > above "html".
> >
> > I can not find a Scripts directory, or a dtue.css file.  In fact, I can
> > not find any .css files in there.
> 
> if the html dir is in lets say
> 
> c:\something\html
> 
> the Scripts dir is in
> c:\something\Scripts
> 
> then.
> 
> 
> If you really don't have it, I've attached the file.
> 
> copy it to c:\something\ if html would be c:\something\html
> 
> 
> >
> > Miguel
> >
> ----
> 

#!/usr/bin/perl

use File::Copy;

for (<*>)
{
   /^\.(|.)$/ and next;

   my $lc = $_;
   $lc =~ tr/A-Z/a-z/;
   
   move($_, $lc);
}
using System;
using System.IO;
using System.Text;

public class TagConverter {
        private static string OldString = "<SCRIPT 
SRC=\"ms-help:/../commoner/scripts/dtuelink.js\"></SCRIPT>";
        private static string NewString = "<link REL=STYLESHEET type=TEXT/CSS 
href=../style.css>";

        public static void Main(string[] args) {
                if (args.Length != 1) {
                        Console.WriteLine("Usage: convert.exe <directory>");
                        return;
                }
                else if (!Directory.Exists(args[0])) {
                        Console.WriteLine("Error: No such directory: {0}", args[0]);
                        return;
                }

                Convert(args[0]);
        }

        public static void Convert(string dir) {
                string[] filenames = Directory.GetFiles(dir);

                foreach (string filename in filenames) {
                        if (!filename.EndsWith(".htm"))
                                continue;

                        Console.WriteLine("Converting: " + filename);
                        string contents = ReadFile(filename);
                        contents = ReplaceTags(contents);
                        WriteFile(filename, contents);
                }
        }

        public static string ReadFile(string filename) {
                FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(file);
                StringBuilder builder = new StringBuilder();

                for (string line=reader.ReadLine(); line != null; 
line=reader.ReadLine()) {
                        builder.Append(line);
                        builder.Append("\n");
                }

                file.Close();
                return builder.ToString();
        }

        public static string ReplaceTags(string contents) {
                return contents.Replace(OldString, NewString);
        }

        public static void WriteFile(string filename, string contents) {
                FileStream file = File.Open(filename, FileMode.Truncate, 
FileAccess.ReadWrite);
                StreamWriter writer = new StreamWriter(file);
                writer.Write(contents);
                file.Close();
        }
}

Reply via email to