private void rewritePsfOCycleDriverSource(string driverSourceCodePath, PsfPsyQAddresses addresses, PsfStubMakerStruct stubMakerParameters)
        {
            int    lineNumber;
            string inputLine;
            string tempFilePath = Path.GetTempFileName();

            string       lineItem;
            string       lineFormat;
            string       lineValue;
            PropertyInfo psyQValue;

            Dictionary <int, string>    psyQSourceCodeLineNumber = XsfUtil.getPsyQSourceCodeLineNumberList();
            Dictionary <string, string> psyQSourceCode           = XsfUtil.getPsyQSourceCodeList();

            // open reader
            using (StreamReader reader =
                       new StreamReader(File.Open(driverSourceCodePath, FileMode.Open, FileAccess.Read)))
            {
                // open writer for temp file
                using (StreamWriter writer =
                           new StreamWriter(File.Open(tempFilePath, FileMode.Create, FileAccess.Write)))
                {
                    lineNumber = 1;

                    while ((inputLine = reader.ReadLine()) != null)
                    {
                        if (psyQSourceCodeLineNumber.ContainsKey(lineNumber))
                        {
                            if (stubMakerParameters.OverrideDriverLoadAddress &&
                                lineNumber == PsfDrvLoadLineNo)
                            {
                                writer.WriteLine(String.Format("#define PSFDRV_LOAD       ({0})", stubMakerParameters.PsfDrvLoad));
                            }
                            else
                            {
                                lineItem   = psyQSourceCodeLineNumber[lineNumber];
                                lineFormat = psyQSourceCode[lineItem];
                                psyQValue  = addresses.GetType().GetProperty(lineItem);
                                lineValue  = (string)psyQValue.GetValue(addresses, null);

                                if (!String.IsNullOrEmpty(lineValue))
                                {
                                    writer.WriteLine(String.Format(lineFormat, lineValue));
                                }
                                else
                                {
                                    // comment out this line
                                    writer.WriteLine(String.Format("//{0}", inputLine));
                                }
                            }
                        }
                        else
                        {
                            switch (lineNumber)
                            {
                            case DoSeqDefineLineNo:
                                if (!stubMakerParameters.UseSeqFunctions)
                                {
                                    writer.WriteLine("#undef DO_SEQ");
                                }
                                else
                                {
                                    writer.WriteLine(inputLine);
                                }
                                break;

                            case COMMENT_REVERB_OPEN:
                                if (!stubMakerParameters.IncludeReverb)
                                {
                                    writer.WriteLine("/*");
                                }
                                else
                                {
                                    writer.WriteLine(inputLine);
                                }
                                break;

                            case COMMENT_REVERB_CLOSE:
                                if (!stubMakerParameters.IncludeReverb)
                                {
                                    writer.WriteLine("*/");
                                }
                                else
                                {
                                    writer.WriteLine(inputLine);
                                }
                                break;

                            case PsfDrvSizeLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define PSFDRV_SIZE       ({0})", stubMakerParameters.PsfDrvSize, inputLine);
                                break;

                            case PsfDrvParamLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define PSFDRV_PARAM      ({0})", stubMakerParameters.PsfDrvParam, inputLine);
                                break;

                            case PsfDrvParamSizeLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define PSFDRV_PARAM_SIZE ({0})", stubMakerParameters.PsfDrvParamSize, inputLine);
                                break;

                            case MySeqLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_SEQ      ({0})", stubMakerParameters.MySeq, inputLine);
                                break;

                            case MySeqSizeLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_SEQ_SIZE ({0})", stubMakerParameters.MySeqSize, inputLine);
                                break;

                            case MyVhLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_VH ({0})", stubMakerParameters.MyVh, inputLine);
                                break;

                            case MyVhSizeLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_VH_SIZE ({0})", stubMakerParameters.MyVhSize, inputLine);
                                break;

                            case MyVbLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_VB ({0})", stubMakerParameters.MyVb, inputLine);
                                break;

                            case MyVbSizeLineNo:
                                this.rewriteOptionalLine(writer, stubMakerParameters.OverrideDriverLoadAddress,
                                                         "#define MY_VB_SIZE ({0})", stubMakerParameters.MyVbSize, inputLine);
                                break;

                            default:
                                writer.WriteLine(inputLine);
                                break;
                            }
                        }

                        lineNumber++;
                    }
                } // using (StreamWriter writer...
            }     // using (StreamReader reader...

            // overwrite original
            File.Copy(tempFilePath, driverSourceCodePath, true);
        }