** END HEADER -- do not remove this line
//
// Generated on 01/14/00
//
parameter bModal
local f
f = new webutilForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class webutilForm of FORM
   with (this)
      scaleFontBold = false
      metric = 6	// Pixels
      height = 269
      left = 96
      top = 51
      width = 416
      text = "HTML To PRG Converter"
      icon = "filename webwizard.ico"
   endwith


   this.RECTANGLE1 = new RECTANGLE(this)
   with (this.RECTANGLE1)
      left = 12
      top = 10
      width = 390
      height = 212
      text = ""
   endwith


   this.TEXT1 = new TEXT(this)
   with (this.TEXT1)
      height = 19
      left = 41
      top = 100
      width = 124
      fontSize = 9
      text = "Source HTML File"
   endwith


   this.EFSOURCEFILE = new ENTRYFIELD(this)
   with (this.EFSOURCEFILE)
      height = 19
      left = 41
      top = 116
      width = 311
      colorHighLight = "N/0x80ffff"
      fontSize = 9
      value = ""
      maxLength = 250
   endwith


   this.PBSOURCEFILE = new PUSHBUTTON(this)
   with (this.PBSOURCEFILE)
      onClick = class::PBSOURCEFILE_ONCLICK
      height = 19
      left = 356
      top = 117
      width = 27
      text = ""
      upBitmap = "RESOURCE #148"
   endwith


   this.TEXT2 = new TEXT(this)
   with (this.TEXT2)
      height = 19
      left = 41
      top = 161
      width = 142
      fontSize = 9
      text = "Destination .PRG file"
   endwith


   this.EFOUTPUTFILE = new ENTRYFIELD(this)
   with (this.EFOUTPUTFILE)
      height = 19
      left = 41
      top = 178
      width = 311
      colorHighLight = "N/0x80ffff"
      fontSize = 9
      value = ""
      maxLength = 250
   endwith


   this.PBOUTPUTFILE = new PUSHBUTTON(this)
   with (this.PBOUTPUTFILE)
      onClick = class::PBOUTPUTFILE_ONCLICK
      height = 19
      left = 356
      top = 179
      width = 27
      text = ""
      upBitmap = "RESOURCE #148"
   endwith


   this.PBACTION = new PUSHBUTTON(this)
   with (this.PBACTION)
      onClick = class::PBACTION_ONCLICK
      height = 21
      left = 316
      top = 230
      width = 87
      text = "&FInish"
      fontSize = 9
   endwith


   this.CANCELBUTTON = new PUSHBUTTON(this)
   with (this.CANCELBUTTON)
      onClick = class::CANCELBUTTON_ONCLICK
      height = 21
      left = 221
      top = 230
      width = 87
      text = "&Close"
      default = true
      fontSize = 9
   endwith


   this.TEXT3 = new TEXT(this)
   with (this.TEXT3)
      height = 60
      left = 37
      top = 32
      width = 340
      fontSize = 9
      l0 = "<p>This Wizard will extract the <BODY> from an HTML document, convert it to dBASE source code and insert it at the end of the indicated PRG file for use with the dBASE Web Classes.</p><p><i>It will not destroy any code that already exists in your .PRG file"
      l0 += ".</i></p>"
      text = l0
   endwith


   function PBSOURCEFILE_onClick
      cSourceFile = getFile("*.htm*", "Select Source File")
      if not empty(cSourceFile)
         form.efSourceFile.value := lower(cSourceFile)
      endif

   function PBOUTPUTFILE_onClick
      cOutputFile = putFile("Specify Output File", "", "prg")
      if not empty(cOutputFile)
         form.efOutputFile.value := lower(cOutputFile)
      endif

   function CANCELBUTTON_onClick
      form.close()
      return

   function PBACTION_onClick
      if empty(form.efSourceFile.value)
         msgbox("Please select the source file.", "Invalid Entry")
         form.efSourceFile.setFocus()
         return
      endif
      if empty(form.efOutputFile.value)
         msgbox("Please specify the output file.", "Invalid Entry")
         form.efOutputFile.setFocus()
         return
      endif
      if not file(trim(form.efSourceFile.value))
         msgbox("The specified source file does not exist.", "File Not Found")
         form.efSourceFile.setFocus()
         return
      endif
      cOutputFile = trim(form.efOutputFile.value)

      if file(cOutputFile)
         oFNSplit = new FNSplit(cOutputFile)
         set safety off
         copy file (cOutputFile) to (oFNSplit.Drive + oFNSplit.Dir + "\Backup of " + oFNSplit.Name + oFNSplit.Ext)
         set safety on
      endif

      cDelim = "'"
      

      oFSource = new file()
      fOutPut = new file()
      oFSource.open(trim(form.efSourceFile.value), "R")
      if not file(cOutPutFile)
         fOutPut.create(cOutputFile,"RA")
      else
         fOutPut.open(cOutputFile,"RA")
      endif

      bBodyStarted = false

      do while not oFSource.eof()
         cSourceLine = oFSource.getS()

         
         if at('<BODY',upper(cSourceLine)) >0 // if finds start body tag
            bBodyStarted = true
            fOutput.puts(chr(13)+'with (this.fOut)')
            fOutput.puts('')
         endif

         if bBodyStarted
            if not "'" $ cSourceLine
               cLDelim = "'"
               cRDelim = "'"
            elseif not '"' $ cSourceLine
               cLDelim = '"'
               cRDelim = '"'
            else
               cLDelim = '['
               cRDelim = ']'
            endif
            fOutPut.puts("   puts(" + cLDelim + cSourceLine + cRDelim + ")")
         endif

         if at('</BODY',upper(cSourceLine)) >0 // if finds end body tag

            exit
         endif

      enddo

      if bBodyStarted
        fOutput.puts('')
        fOutput.puts('endwith')
      endif

      oFSource.close()
      fOutPut.close()
      msgbox("Conversion Completed.", "Done")
      return
endclass
class FNSplit(cFullPath)
/*======================================================================

Example of use:

   cFullPath = getFile()
   if not isblank(cFullPath)
      oFNSplit = new FNSplit(cFullPath)
      ? "The drive name is " + oFNSplit.Drive
      ? "The directory name is " + oFNSplit.Dir
      ? "The file name is " + oFNSplit.Name
      ? "The file extension is " + oFNSplit.Ext
      ? "The full path with the file extension stripped is " + ;
        oFNSplit.DriveDirName
   endif

======================================================================*/

   if pcount() > 0
      this.FullPath = cFullPath
   else
      this.FullPath = ""
   endif
   if not isblank(this.FullPath)
      class::SplitFileName()
   else
      store "" to this.Drive,;
                  this.Dir,;
                  this.Name,;
                  this.Ext,;
                  this.DriveDirName
   endif

   function SplitFileName
      local nPos, cPath, cTemp
      cTemp = this.FullPath

      // parse drive letter
      nPos  = at(":", this.FullPath)
      if nPos > 0  && we have a drive letter
         this.Drive = left(this.FullPath, nPos)
         cTemp = right(this.FullPath, len(this.FullPath) - nPos)
      else
         this.Drive = ""
      endif

      // parse directory
      nPos  = rat("\", cTemp)
      if nPos = 0  && no backslash, no directory
         this.Dir = ""
      elseif nPos = 1  && root directory
         this.Dir = "\"
      else
         this.Dir = left(cTemp, nPos - 1)
      endif

      // parse name and extension
      cTemp = right(cTemp, len(cTemp) - nPos)
      nPos = at(".", cTemp)
      if nPos > 0  && we have a name *and* extension
         this.Name = left(cTemp, nPos - 1)
         this.Ext = right(cTemp, len(cTemp) - nPos + 1)
      else
         this.Name = cTemp
         this.Ext = ""
      endif

      this.DriveDir = this.Drive + this.Dir
      if not isblank(this.Dir)
         this.DriveDirName = this.Drive + this.Dir + "\" + this.Name
      else
         this.DriveDirName = this.Drive + this.Name
      endif

endclass
