include("WBInclusions")
using WAV
include("w/DICT")

global JSEARCH = false

global STIME = time_ns()

APFS = "648" # WB:APFS
global versionNr = APFS
global NOVERSION = false
global FIRST = true
global MACROFILE = "MACRODICT"
global JULIA_VERSION = string(VERSION)

EMP("global dict = " * RRead("MACRODICT", "asis"))
global MACRODICT = dict[2]
global WithMacros = false

function MakeANoise()
    y, fs = wavread(raw"C:\Windows\Media\Ring01.wav")
    wavplay(y, fs)
end

#print("\n  WB v" * versionNr * "(" * TVersion * ") (j:" * JULIA_VERSION * ").   ")
if length(ARGS) == 0
    f = open("WB_Transforms", "r")

    vtn = replace(readline(f), r"[^\"]+\"([^\"]+).*" => s"\1")
    readline(f)  # throwaway for "=>" problem with {{TODAY}}

    print("\n  WB v" * versionNr * "(" * vtn * ") (j:" * JULIA_VERSION * 
            ").                 Ref.: \"" * hilite(HI_YELLOW, "..\\Template.txt") * "\"\n")

    ff = filter(x -> findfirst("=>", x) != nothing, readlines(f))
    close(f)
    f = []
    HI = HI_AQUA
    for itm in ff
        if itm[1:1] == "#" || findfirst("\".html\" => \"\"", itm) != nothing
            continue
        end
        comment = findfirst(r"##[^#]+", itm)
        comment = comment == nothing ? "" : itm[comment]
        itm = replace(replace(replace(replace(strip(itm), r"^ *r?\"" => "    "), r"\" +=>.*" => ""), 
                r"\\([{}|+.])" => s"\1"), r"[()]" => "")
        itm = replace(itm, r"{{([^|}]+)" => s"{{YYY\1")
        itm = replace(itm, "YYY" => HI_YELLOW)
        itm = replace(replace(replace(itm, "{{" => HI * "{{" * HI_END), r"}}$" => HI* "}}" * HI_END),
                "|" => HI * "|" * HI_END)

        itm = replace(itm, HI_AQUA * "|" * HI_END * "BI" * HI_AQUA => 
                HI_RED * "|" * HI_YELLOW * "BI" * HI_AQUA, count = 1)
        itm = replace(itm, "[\\-+]" => "[-+]")

        itm = replace(itm, "*}}?" => "*" * HI_AQUA * "}}i" * HI_END * "?")
        itm = replace(itm, HI_YELLOW * "[Pp]" => "[" * HI_YELLOW * "Pp" * HI_END * "]" * HI_YELLOW)
        itm = replace(itm, HI_YELLOW * "[Rr]" => "[" * HI_YELLOW * "Rr" * HI_END * "]" * HI_YELLOW) 

        itm = replace(itm, "}}\"i =>" => HI_AQUA * "}}" * HI_YELLOW * "i" * HI_END)
        itm = replace(itm, "^" * HI_AQUA * "|" * HI_END * "}]+" => "^|}]+")
        itm = replace(itm, HI_AQUA * "|" * HI_END * "]" => "|]")
        itm = replace(itm,"WDSG" * HI_AQUA * "|" * HI_END * "Buttocks" * HI_AQUA * "|" * HI_END * "K2" =>
                "WDSG" * HI_RED * "|" * HI_END * "Buttocks" * HI_RED * "|" * HI_END * "K2")
        itm = replace(itm,"NBB" * HI_AQUA * "|" * HI_END * "ENDNOTE" =>
                "NBB" * HI_RED * "|" * HI_YELLOW * "ENDNOTE" * HI_END)
        itmOut = itm * replace(comment, r"##( +)" => s"\1# ")
        if itmOut in f
            continue
        end 
        push!(f, itmOut)        
    end
    f = sort(f)
    println(" ")
    for itm in f
        println(itm)
    end
    exit(0)
end

global ThisFile = ARGS[1]
if !endswith(ThisFile, ".html")
    println("    Not an HTML file: \"", ThisFile, "\"")
    exit(16)
end
lx = length(ThisFile)
if !isfile(ThisFile)
    println("    Is not file: \"" * ThisFile * "\"!")
    exit(16)
end

include("WB_Transforms")
if FIRST
    print("\n  WB v" * versionNr * "(" * TVersion * ").  ")
    global FIRST = false
end

try 
    gbn = getBackupNumber()
    global BACKUPFILENAME = "/backups/" * ThisFile * ".qw" * gbn
    cp(ThisFile, BACKUPFILENAME)

    println(string(now())[12:19] * "  " * hilite(HI_YELLOW, replace(BACKUPFILENAME, "/" => "\\") *
                "  " * ThisFile) * "\n")
    global DATAIN = RRead(ThisFile, "raw")
    global FileContents = String(copy(DATAIN))
    global LENDIFF = length(DATAIN) - length(FileContents) 
    global OriginalFileContents = FileContents
catch ex
   local s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("Initialization failure: ", typeof(ex), ".\n", s);
    exit(16)
end

global Images = findall(r"<img [^>]+>", FileContents)
global iLen = length(Images)
for i = 1 : iLen
    img = Images[iLen + 1 - i]
    shit = FileContents[img]
    tgt = findfirst(r" src=\"{{[^}]+}}", shit)
    if tgt == nothing
        continue
    end
    imgName = shit[tgt]
    imgNameX = imgName[9 : length(imgName) - 2]
    dir = getD(imgNameX)
    if dir == MISSING
        println("==================> What the GKW1 is: \"" * imgNameX * "\"?\n")
        continue
    end
    global FileContents = replace(FileContents, imgName => 
                " src=\"w/images/" * dir[1] * "/" * dir[2] * "/" * imgNameX)
end

#  href="{{AztecFace.jpg}}"
searchString = r" href=\"{{([^}]+)}}"
global iLenX = length(findall(searchString, FileContents))
for i = 1 : iLenX
    local Images = findfirst(searchString, FileContents)
    if Images == nothing
        break
    end
    img = FileContents[Images]
    imgNameX = img[10:length(img) - 2]
    dir = getD(imgNameX)
    if dir == MISSING
        println("==================> What the GKW2 is: \"" * imgNameX * "\"?\n")
        continue
    end
    global FileContents = replace(FileContents, img => 
                " href=\"w/images/" * dir[1] * "/" * dir[2] * "/" * imgNameX, count = 1)
end

if ThisFile == "Zelensky5.html"
    incs = RRead("Z.txt", "asis")
    of = FileContents
    global FileContents = replace(FileContents, 
                r"<!\-\- BBStart \-\->.+?<!\-\- BBEnd \-\->"s => 
                            "<!-- BBStart -->" * incs * "<!-- BBEnd -->")
    if of == FileContents
        println("\n\n        " * hilite(HI_RED, "Zelensky5 no fix") * "\n\n")
        MakeANoise()
    end
elseif ThisFile == "JustSo.html"
    incl = RRead("w/txts/VirtualReality.txt", "asis")
    incs = replace(incl, r"\r?\n" => "<br>")
     if length(findall(r"<p id=\"BBStart\">.+?</p>"s, FileContents)) != 1
         println("\n\n        " * HI_RED * "JustSo no fix" * HI_END * "\n\n")
         MakeANoise()
     end
     global FileContents = replace(FileContents, 
             r"<p id=\"BBStart\">.+?</p>"s => "<p id=\"BBStart\">" * incs * "</p>")
end 

if findfirst("{{", FileContents) != nothing
    global WithMacros = true            
    for tr in Transforms
        if (nct = length(findall(tr.first, FileContents))) != 0            
            ky = string(tr.first)
            kz = get(MACRODICT, ky, -1)
            if kz == -1
                MACRODICT[ky] = nct
            else
                MACRODICT[ky] = min(kz + nct, 9999)
            end
            global FileContents = replace(FileContents, tr)
        end
    end
end

if ThisFile == "ChangeLog.html"   #     ["IndexOfSubjects.html", "ChangeLog.html"]
    nrFiles = string(length(findall(r"<li( class=\"li\"|>)", FileContents)))
    global FileContents = replace(FileContents, r">Total:</span> [0-9]{1,3}&#41;&nbsp;<" => 
            ">Total:</span> " * nrFiles * "&#41;&nbsp;<", count = 1)
elseif ThisFile == "IndexOfSubjects.html"
    global FileContents = replace(FileContents, r"&#10004;(\(\d+\) )?" => "")
    local longos = []
    local maxlen = 0
                       #  title="Zelensky0">Zelensky0</a>
    allAlong = findall(r"<li>[^<>]*<a href\=\"([^.]+)\.html\" title=\"\1\"[^>]*>\1</a>", FileContents)
    LallAlong = length(allAlong)
    allAlongQ = findall("<li>", FileContents)
    LallAlongQ = length(allAlongQ)
    SallAlong = "&Sigma; " * string(LallAlong) * "|" * string(LallAlongQ)
    global FileContents = replace(FileContents, r"&Sigma; \d{1,3}\|\d{1,3}" => SallAlong)
    for ix in allAlong
        itmqqq = FileContents[ix]
        itm = replace(FileContents[ix], r"^[^=]+=\"([^.]+).*" => s"\1") 
        litm = length(itm)
        if litm > maxlen
            longos = [itm]
            maxlen = litm
        elseif litm == maxlen
            push!(longos, itm)
        end
    end
    fc = FileContents
    for itm in longos
        global FileContents = replace(FileContents, 
                "<li><a href=\"" * itm => "<li>" * "&#10004;(" * string(length(itm)) * ") <a href=\"" * itm)
    end
    if fc == FileContents
        println("\nIndexOfSutjects fuckup\n")
    end            
elseif ThisFile == "Omnes.html"
    local s = length(findall(" class=\"ss\"", FileContents))
    global FileContents = replace(FileContents, 
            r":darkgreen;\">\(<span style=\"font-style:italic;\">Count:</span> [0-9]+\)\&nbsp;" =>
                ":darkgreen;\">(<span style=\"font-style:italic;\">Count:</span> " * string(s) * ")&nbsp;",
                    count = 1)
elseif ThisFile == "JSource.html"

    bkupFile = open("WBBKUP", "w")
    write(bkupFile,noww() * "\n\n")

    local len = 0
    local blankLines = 0
    local chars = 0
    for nm in TrackedScripts
        local b = RRead(nm, "asis")

        write(bkupFile, "*---- \"" * nm * "\"\n\n")
        write(bkupFile, b * "\n\n")
        chars += length(b)

        if findall(r"[^Rrv]read\(", b) != [] && nm != "WBInclusions"
            println("read: ", nm)
        end

        if JSEARCH
            z = "RRead(\"IndexOfSubjects"
            if (zz = length(findall(z, b))) > 0
                println("    \"", z , "\"  ", nm, "  ", zz)
            end
        end

        blankLines += length(findall(r"^[ \r\n]*$"m, b))
        l = length(split(b, "\n"))
        len += l
        if nm == "WBInclusions"
            global FileContents = replace(FileContents, r"Included data for other scripts \(\d+\)" =>
                    "Included data for other scripts (" * string(l) * ")")        
        end
    end

    close(bkupFile)

    global FileContents = replace(FileContents, r"Sigma; [^<]+" => 
            "Sigma; " * formatFixed(len - blankLines) * "(+" * 
                formatFixed(blankLines) * ") loc. " * formatFixed(chars) * " chars." , count = 1)
    global FileContents = replace(FileContents, r" id=\"TimeStamp\">[^<]+" =>
            " id=\"TimeStamp\">" * replace(noww()[1:16], "-" => ".") * " (-" * string(UTCoffset) * "h)")
    global FileContents = replace(FileContents, r"italic;\">J</span>.*?</span>" =>
            "italic;\">J</span> " * JULIA_VERSION * "]</span>")
elseif ThisFile == "Scripta.html"
    global FileContents = replace(FileContents, r"mini bees \+ Genie Bee \+ \d+ " => 
            "mini bees + Genie Bee + " * string(SpellingBees) * " ")  
elseif ThisFile in ["Zelensky1.html", "Zelensky3.html", "Zelensky4.html", "Zelensky5.html",
                "Zelensky6.html", "Zelensky7.html", "Zelensky8.html", "Zelensky9.html", 
                "Zelensky10.html", "Zelensky11.html", "Zelensky12.html", "Zelensky13.html"]
    if ThisFile == "Zelensky5.html"
        
        for i = 6 : 13
            EMP("readgkw" * string(i) * " = RRead(\"Zelensky" * string(i) * ".html\", \"clean\")")
        end

        details = length(findall("&#124", readgkw6)) - 1 +
                      length(findall("&#124", readgkw7)) - 1 +  
                      length(findall("&#124", readgkw8)) + 
                      length(findall("&#124", readgkw9)) +
                      length(findall("&#124", readgkw10)) - 1 +
                      length(findall("&#124", readgkw11)) +
                      length(findall("&#124", readgkw12)) +
                      length(findall("&#124", readgkw13)) + 
                      length(findall("&#124", FileContents))

        gkwctLavender = length(findall("lavender", readgkw6)) - 4 +  # Remember the asterisks!
                      length(findall("lavender", readgkw7)) +                      
                      length(findall("lavender", readgkw8)) - 2 + 
                      length(findall("lavender", readgkw9)) - 1 +
                      length(findall("lavender", readgkw10)) - 1 +
                      length(findall("lavender", readgkw11)) +
                      length(findall("lavender", readgkw12)) +
                      length(findall("lavender", readgkw13)) +
                      length(findall("lavender", FileContents)) - 1

        global NOACK = length(findall("&#x2612;", FileContents)) - 1
        global ACK = length(findall("&#x2611;", FileContents)) - 2

        y = string(details) * "r/" * string(gkwctLavender)
        global FileContents = 
                replace(FileContents, r"&nbsp;&nbsp;<span style=\"font-weight:bold;\">Recents: [^&]+<" => 
                    "&nbsp;&nbsp;<span style=\"font-weight:bold;\">Recents: " * wh(0) * "<")
        global FileContents = replace(FileContents, r"id=\"LAV\" style=\"font-weight:bold;\">[0-9/r]+" => 
                "id=\"LAV\" style=\"font-weight:bold;\">" * y) 
    end 
    Psum = formatFixed(length(findall("Mr. President", FileContents)))
    Ssum = formatFixed(length(findall(r"Sir[^a-z]", FileContents)))
    Rsum = formatFixed(length(findall("Putin", FileContents)))
    Zsum = formatFixed(length(findall(r"(pro\-| )Zelensky", FileContents)) - 2)
    global FileContents = 
        replace(FileContents, r"Mr\.&nbsp;President: \d+, Sir: \d+\.<br>Zelensky: \d+. Putin: \d+" =>
            "Mr.&nbsp;President: " * Psum * ", Sir: " * Ssum * ".<br>Zelensky: " * Zsum * ". Putin: " * Rsum,
                count = 1)
    if ThisFile == "Zelensky5.html" 
        global FileContents = replace(FileContents, "<!-- BBEnd -->" =>
                "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Acknowledged: " * 
                        string(ACK - NOACK) * " of " * string(ACK) * ".<!-- BBEnd -->")
    end
elseif ThisFile == "index1.html"

    IOS = RRead("IndexOfSubjects.html", "clean")
    IOSa = findall(r" title=\"([^\"]*)\"[^>]*>\1", IOS)
    IOSb = []
    for i in IOSa
        ii = IOS[i]
        ii = replace(ii, r" title=\"([^\"]*)\"[^>]*>\1" => s"\1")
        if ii in IOSb
            println("IOSb fuckup: \"", ii, "\"")
        else
            push!(IOSb, ii)
        end
    end
    #println(length(IOSb), "  ",IOSb)
    include("V1")
    VS = []
    for k in keys(V[2])
        kkk = string(k)
        kk = kkk[1: length(kkk) - 5]
        if kk in VS
            println("VS fuckup: \"", kk, "\"")
        else
            push!(VS, kk)
        end
    end
    #println("VS   ", VS)
    println("Len IOSb: ", length(IOSb), ". Len VS: ", length(VS), ".  ", "IndexOfSubjects" in IOSb, "|",
              "IndexOfSubjects" in VS, " - ", "index" in IOSb, "|", "index" in VS)
    local shit1 = 0
    for itm in IOSb
        shit1 += 1
        if !(itm in VS)
            println("Not in VS: \"", itm, "\"")
        end
    end
    local shit2 = 0
    for itm in VS
        shit2 += 1
        if !(itm in IOSb) && itm != "IndexOfSubjects"
            println("Not in IOSb: \"", itm, "\"")
        end
    end
    if shit1 + 1 == shit2
        println(" ")
    else
        println("shit1: ", shit1, "  shit2: ", shit2)
    end

    V1 = open("V1", "r")
    V1A = readline(V1)
    local a = findall(r"\d+", V1A)
    pages = V1A[a[1]]
    links = V1A[a[2]]
    if length(links) == 4                                # kludge
        links = links[1:1] * "," * links[2:4]
    else
        links = links[1:2] * "," * links[3:5]
    end 
    close(V1)
    V2 = open("V2", "r")
    readline(V2)
    V2A = readline(V2)
    a = findfirst(r"\d+", V2A)
    images = V2A[a]
    images = images[1:1] * "," * images[2:4] 
    close(V2)
    fcBefore = FileContents

    shit = findfirst(r"<span id=\"Stats\">[^<]+</span>", FileContents)
    println("--------   ", shit, " \"", FileContents[shit], "\"")

    global FileContents = replace(FileContents, r"<span id=\"Stats\">[^<]+</span>" =>
            "<span id=\"Stats\">" * pages * " pages, " * images * " different images and more than " *
                    links * " hyperlinks</span>", count = 1)

    shit = findfirst(r"<span id=\"Stats\">[^<]+</span>", FileContents)
    println("++++++++   ", shit, " \"", FileContents[shit], "\"")

    if fcBefore == FileContents
        println("    ", hilite(HI_RED, "index.html stats not changed"), "\n")
    end
    
    a = Duree(DateTime(2021,9,24,16,00), now())
    local b = formatDecimal(tryparse(Int32, a[findfirst(r"\d+", a)])/365.25, 2)
    global FileContents = replace(FileContents, r"<!-- AS -->[0-9.]+ years" => 
            "<!-- AS -->" * b * " years") 
   
elseif ThisFile == "Experiment.html"
    global FileContents = replace(FileContents, r"<!-- DTSTART -->[^<]+<!-- DTEND -->" =>
            "<!-- DTSTART -->" * noww() * "<!-- DTEND -->")
end
global FileContents = replace(FileContents, r"<img src=\"w/images/f/f5/JuliaLogo.jpg\" title=\"Julia[^>]+" =>
        "<img src=\"w/images/f/f5/JuliaLogo.jpg\" title=\"Julia (" * JULIA_VERSION * ")\"")

global gggg = replace(FileContents, r"<head>.*?</head>"s => "")
global ffff = findfirst(r"[{}]", gggg)
if ffff != nothing
    ffs = ffff.start
    ffe = ffff.stop
    ffs = max(0, ffs - 20)
    ffe = min(length(gggg) , ffe + 30)
    println("\n\n    " * HI_RED * "Stray \"{}\" char(s) in " * ThisFile * HI_END * 
                ": \"" * gggg[ffs:ffe] * "\"\n\n")
    MakeANoise()
end

# <a href="Date.html" style="text-decoration:none;">+2022.09.09 v007</a></span>
# <a href="Date.html" style="text-decoration:none"><span style="font-size:15px;color:blue">+2022.09.05 v164</span></a>
# ">+2022.09.10 v016<" " title="Last change: +2022.09.09 v007""

vStamp = findall(r">\+202[0-9]\.[0-1][0-9]\.[0-3][0-9] v[0-9]{3}<", FileContents)
VSHIT =  findall(r">\+202[0-9]\.[0-1][0-9]\.[0-3][0-9] v[0-9]{3}<!\-\- OFL \d{3} \-\->", FileContents)
VSHIT = length(VSHIT) > 0 ? FileContents[VSHIT[length(VSHIT)]][18:33] : ""

global wasModified = OriginalFileContents != FileContents

if length(vStamp) != 1
    println(HI_RED * "Versioning not available for this file: " , string(length(vStamp)) , HI_END * "\n")
    global NOVERSION = true
else
    if VSHIT != "" 
        println("                           " * HI_YELLOW * VSHIT * HI_END)
    end
    v = FileContents[vStamp[1]]
    w = tryparse(Int32, v[15:17])
    if w >= 979
        println("\n" * HI_RED * "**************** Version number overflow: ", w, 
                " ****************" * HI_END *"\n")
        MakeANoise()
    end
    w = "00000" * string(w + 1)
    wLen = length(w)
    w = w[wLen - 2 : wLen]
    y = string(Dates.now())
    z = ">+" * y[1:4] * "." * y[6:7] * "." * y[9:10] * " v" * w * "<"
    q = FileContents
    global FileContents = replace(FileContents, v => z, count = 1)
    if FileContents != q
        print("  Versionstamp updated to: " * HI_YELLOW * z[2:length(z) - 1] * HI_END * ".")
        needExtraLineEnd = true
        q = FileContents
        for tr in [
                r"[“”]" => "\"",
                r"[‘’]" => "'", 
                Char(0x2010) => "-",      # Hyphen
                Char(0x2011) => "-",      # Non-breaking hyphen
                Char(0x2026) => "...",    # Elipsis
                " " => " ",               # Preverted space
                r"[–—]" => "&ndash;",     # Perverted hyphen
                "→" => "&rarr;",
                # " " => " ",               # Wierd space in times n?n:***[AP]M
            ]
            global FileContents = replace(FileContents, tr)
        end

        if FileContents != q
            println(" Non-Ascii characters replaced.\n")
            needExtraLineEnd = false
        end
        q = FileContents
        global FileContents = 
            replace(FileContents, r"<title>(pax in terris|Dona nobis pacem) \| ([^<]+)</title>" => 
                s"<title>Nullius in verba | \2</title>", count = 1)
        if FileContents != q
            println(" Title updated.\n")
            needExtraLineEnd = false
        end
        q = FileContents
        global FileContents = replace(FileContents, "<p style=\"line-height:140%;font-size:95%;\">" => 
                "<p class=\"wph\">")
        if FileContents != q
            println(" ", Int32((length(q) - length(FileContents)) / 28), " Hdrs updated.\n")
            needExtraLineEnd = false
        end
        if needExtraLineEnd
            println("\n")
        end
        q = FileContents
        if findfirst("<meta name=\"author\"", FileContents) == nothing
            global FileContents = replace(FileContents, "<meta charset=\"UTF-8\">" => 
                    "<meta charset=\"UTF-8\">\n<meta name=\"author\" content=\"Bradford McCormick\">", 
                        count = 1)
        end
        if FileContents != q
            println(" Author added.\n")
        end
        q = FileContents
        replace(FileContents, "\r\n" => "\n")
        if FileContents != q
            println(" DOS linend(s) fixed.\n")
        end
        q = FileContents
        replace(FileContents, "\r" => "")
        if FileContents != q
            println(" Stubborn DOS linend(s) fixed.\n")
        end                
    else     
        println("  Version not updated!\n")
    end        
end

if ThisFile == "Quora13.html"

    Qfn = "Q.txt"
    if isfile(Qfn) 
        QBACKUPFILENAME = "/backups/" * Qfn * ".qw" * getBackupNumber()
        cp(Qfn, QBACKUPFILENAME)

        q = FileContents
        local newQtext = replace(replace(RRead(Qfn,"asis"), "\r\n" => "\n"), r"^[\n ]*" => "")
        newQtext = replace(newQtext, r" *\n+ *"m => "</p>\n\n<p>")
        newQtext = "<p class=\"q1\"><span class=\"q2\">&para;</span> " *
                "{{TODAY}}. " * newQtext 
        global FileContents = replace(FileContents, r"Begin entries \*\*\*\*\*\*\*\* --> *\n+"m =>
                "Begin entries ******** -->\n\n" * newQtext * "</p>\n\n")
        if FileContents == q
            println(ThisFile * "  add data failed")
        else
            while findfirst("<p></p>", newQtext) != nothing
                newQtext = replace(newQtext, r"[ \n]*<p></p>" => "")
            end
            println(ThisFile * " added data: ", length(q), " => ", length(FileContents))
            rm(Qfn)
        end    
    else
        println(ThisFile * " no \"" * Qfn * "\" file, No new data");
    end 

    q = FileContents
    global FileContents = replace(FileContents, r"Len</span>: [\d,]+&nbsp;&nbsp;\d+\." => 
            "Len</span>: " * formatFixed(length(FileContents)) * 
                "&nbsp;&nbsp;" * string(length(findall("&para;", FileContents))) * ".")
    if q == FileContents
        println(HI_YELLOW, ThisFile * " length not updated" , HI_END , "\n")
    end
elseif ThisFile == "TheSocietyOfTheUnheard.html"
    q = FileContents
    local TZM = RRead("TZMulti", "asis")       
    for itm in [["&", "&amp;"], ["<", "&lt;"], [">", "&gt;"]]
        TZM = replace(TZM, itm[1] => itm[2])
    end
    TZPLACEHOLDER = "{{TZMDATA}}"
    global FileContents = replace(FileContents, r"<!-- TZMSTART -->(.|\n)+?<!-- TZMEND -->" =>
            "<!-- TZMSTART -->\n" * TZPLACEHOLDER * "\n\n<!-- TZMEND -->")
    if FileContents == q
        println(HI_RED, " ---- TheSocietyOfThe Unheard update failed (1) ----", HI<END, "\n")
    else
        global FileContents = replace(FileContents, TZPLACEHOLDER => TZM)
        if FileContents == q
            println(" ++++ TheSocietyOfThe Unheard not updated ++++\n")
        elseif findfirst(TZPLACEHOLDER, FileContents) != nothing
            println(HI_RED, " ---- TheSocietyOfThe Unheard update failed (2) ----", HI<END, "\n")
        else 
            println(HI_YELLOW, " ++++ TheSocietyOfThe Unheard updated ++++", HI_END, "\n")
        end
    end
end
    
try
    local a = open(ThisFile, "w")
    write(a, FileContents)
    close(a)
    x = DATAIN == RRead(ThisFile, "raw")
    akk = replace(string(now()), r"T(\d{2}\:\d{2}\:\d{2}).*" => s" \1", count = 1)
    rslt = "  " * akk * ". Processed: " * HI_YELLOW * ThisFile * HI_END * ". " * 
            (wasModified ? HI_YELLOW * "*Txt-" * HI_END * "Modified" : "Txt-Unmodified") * ", " *
                (x ? HI_YELLOW * "*Dt-Un" * HI_END * "changed." : "Dt-Changed.") * 
                    "  (" * formatFixed(length(FileContents)) *
                    (LENDIFF == 0 ? "" : 
                        ", " * string(LENDIFF)) * ")  " * replace(string((time_ns() - STIME) / 1000000000),
                            r"\.(\d{4}).*" => s".\1")
    println(replace(rslt, "Txt-Unmodified, Dt-Changed" => HI_AQUA * "OK normal result" * HI_END, count = 1))

    FNX = "WBCTR"
    a = open(FNX, "r")
    b = readlines(a)[1]
    close(a)
    c = "00000000" *string(tryparse(Int32,b[1:7]) + 1)
    lenC = length(c)
    d = "00000000" *string(tryparse(Int32,b[9:14]) + NOVERSION)

    c = c[length(c) - 6 : length(c)] * " " * d[length(d) - 5 : length(d)]
    a = open(FNX, "w")
    write(a, c * " " * b[16:length(b)] * "\n")
    close(a)
    a = open("WBAuditTrail", "a")
    b = string(Dates.now())
    write(a, c * "  " * b[1:10] * " " * b[12:19] * "  " * ThisFile * "\n")
    close(a)            
catch ex
    local s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("\n  Vaidation failure]: ", typeof(ex), ".\n", s);
    exit(16)
end

#  println(replace(string(MACRODICT), r"(, |Int32}\()" => "\n"))

#  println(replace(replace(replace(replace(string(MACRODICT), r"(, |Int32}\()" => "\n"), r"(r\\|\\\")" => ""), "\\ =" => " ="),r" (\d+)\)" => s" \1"))

#  println(replace(replace(replace(replace(replace(c, "\\\\|" => "    | "), r"({{|}})" => s"  "), "=>" => ""), r"\| [^ ]+" => ""), r"  ([^ ]+) +(\d+)" => s"  \2   \1"))

# sort(split(replace(d * " ", "\n" => "  \n"), "\n"), rev = true)

d1 = dict[1][1] + 1
d2 = dict[1][2] + (length(ARGS) > 1 ? 1 : 0)
d3 = dict[1][3] + (WithMacros ? 1 : 0)
    
d0 = open(MACROFILE, "w")
write(d0, replace(replace(string([[d1, d2, d3], MACRODICT]), ", \"" => ",\n\""), "}(\"r" => "}(\n\"r"))
close(d0)