* *** CHKTAGS_OVERVIEW TXT - 28 Jun 2025  12:46:03 - JGKNAUTH

Initialize variables.

Save current line and cursor numbers.

Turn on cursor insert mode for placement visibility.

Declare error if cursor is not on a data line.

(If an error is found during the following, prepare an EMSG.  However
don't issue it immediately since the message display can be wiped out by
subsequent processing.  Instead the done subroutine will issue the
delayed message as the very last thing it does before exiting.)

Prepare the C:\TMP\WORKBLOCK.HTM workfile environment.
   Find the drive containing Windows.
   Try to create the C:\TMP directory, if it doesn't already exist.
   Try to open the workfile.
   Ensure the user is not trying to use CHKTAGS on the workfile.
   Try to write to the workfile.
   FILE and then ERASE the workfile, so it is not in memory or on disk.
      (Otherwise there would be a PUT problem.)

Build the workfile.
   Isolate the code block to be checked for HTML problems.  [=> findblock]
   PUT a copy of the block at the top of the workfile.
   PUT spacer lines and hdr lines to set off the top and bottom sections.
   PUT a second copy of the block at the bottom of the workfile.

Invoke PCCON to format the top block into a one-line block.

Delete any <!--...--> comments from the one-line block.
   Report if there are only HTML comments in the block.

Optionally trim most non-tag text from the one-line block.  [=> trim]

Invoke CHKTAGSLINE to check for tag inconsistencies in the one-line block.
   exitcode  =  0:  All tags paired successfully
   exitcode  =  1:  Add tag to "end"; there is only one unpaired tag (a start tag)
   exitcode  =  2:  Add tag to "end"; multiple unpaired tags exist (all start tags)
   exitcode >= 10:  Errors

KEDIT and SAVE the resulting workfile.

For CHKTAGSLINE exitcode 0:
   KEDIT the workfile.
   QQUIT the workfile -- no longer needed.
   Go to done to finish up [=> done]

For CHKTAGSLINE exitcodes 1 and 2:
   Get the end tag saved by CHKTAGSLINETAG via EDITV.
   KEDIT the origin file.
   LOCATE the last line of the block being scanned for HTML tag problems.
   Append the end tag to that line.    ***
   Put the cursor on that tag and record the column in new_file_column.

In addition for exitcode 1:
   KEDIT the workfile.
   QQUIT the workfile -- no longer needed.
   Go to done to finish up [=> done]

(If reached here, exitcode must be 2 or greater)

KEDIT the workfile
call alert subroutine. [=> alert]

If user answered "NO" to the alert,
   (stay on workfile; don't switch to origin file)
   Call wrap [=> wrap]
   KEDIT the workfile.
   Place the cursor at (1,1).
   Exit 0.

If user answered "YES" to the alert,
   (switch to origin file, where end tag may have been appended above ***)
   Go to done to finish up. [=> done]

================================  wrap  ================================

If cursor is not on a data line, place it at (1,1).
Save current line and cursor numbers.
If length one-line block in workfile > margin, give user the option to flow the line.
   DIALOG with default width of 91.
   OK:  If input value is not a whole number > 0, EMSG and default to right margin.
        Place the cursor at (1,1).
        Invoke PCCON with the width as the margin (and INSET 0, HANGIND 0).
        SAVE the edited workfile.
        Put line 0 in the current line field.
        Try to place the cursor at (1,1).
        Return.

Restore the current line number at entry to wrap.
Try to restore the (not = -1) cursor numbers at entry to wrap.
Return.


================================  done  ================================

   KEDIT the origin file.
   Restore the entry current line.
   REFRESH   (needed to make CURSOR FILE work reliably to restore the cursor position)

   If an end tag append was done  (new_found_column not null),
      Do a 'LEFT 0'
      Try to put the cursor on the new tag.
      If that fails, just try to restore the entry cursor position.
   Restore the entry cursor position.

   If exitcode = 0 or exitcode = 1,
      Get the message saved by CHKTAGSLINETAG via EDITV.   (Must do at the end.)
      Display the message.

   If delayed_emsg Then display the delayed message.

   Exit exitcode.
