include("WBInclusions")

APFS = "210" # WBSearch:APFS
version = APFS

global PRE = 20
global POST = 38

global FILTER = nothing
global FILTERED = false
global MATCHES = []
global PUTS = ""

global ARGZ = copy(ARGS)
global ARGZlen = length(ARGZ)
if ARGZlen > 0 && ARGZ[1][1:1] == "#"
    len = length(ARGZ[1])
    EMP("global FILTER = " * RRead(ARGZ[1][2:len], "asis"))
    global ARGZ = ARGZlen == 1 ? [] : ARGZ[2:ARGZlen]
    global FILTERED = true
    global ARGZlen -= 1
end
    
if ARGZlen == 0
    println("\n  WBSearch  [ \"%%x%\" for 1:'^', 2:'>', 3:'&', 4:'|', 5:'&#' ] v" * 
            APFS * "\n\n            RegEx_string  [before(", PRE, ") after(", POST, ")]  [case-sensitive?]")
    exit(0)
end

for itm in ["%%1%" => "^", 
            "%%2%" => ">", 
            "%%3%" => "&",
            "%%4%" => "&#", 
            "%%5%" => "|"
            ]
    ARGZ[1] = replace(ARGZ[1], itm)
end

if length(ARGZ) > 2
    global PRE = parse(Int32, ARGZ[2])
    global POST = parse(Int32, ARGZ[3])
end

global WC = Dict{String, Int32}()
global WCequals = Dict{String, Int32}()
global WCcount = 0
global WChcount = 0
global C9s = []
global C9imageDict = Dict{String, Any}()

global nowww = noww()

#     if (h >= "&#913;" && h <= "&#937;") || (h >= "&#945;" && h <= "&#969;")  # Don't trust Greeks!
 
global excludeds = ["&#913;", "&#914;", "&#915;", "&#916;", "&#917;", "&#918;", "&#919;", "&#920;", "&#921;", "&#922;", 
    "&#923;", "&#924;", "&#925;", "&#926;", "&#927;", "&#928;", "&#929;", "&#930;", "&#931;", "&#932;", "&#933;", 
    "&#934;", "&#935;", "&#936;", "&#937;",
 
    "&#945;", "&#946;", "&#947;", "&#948;", "&#949;", "&#950;", "&#951;", "&#952;", 
    "&#953;", "&#954;", "&#955;", "&#956;", "&#957;", "&#958;", "&#959;", "&#960;", "&#961;", "&#962;", "&#963;", 
    "&#964;", "&#965;", "&#966;", "&#967;", "&#968;", "&#969;",
      
    "&#32;", "&#33;", "&#34;", "&#35;", "&#39;", "&#40;", "&#41;", "&#42;", "&#45;", "&#47;",
    "&#58;", "&#60;", "&#61;", "&#62;", "&#89;", "&#91;", "&#93;", 
    "&#101;", "&#104;", "&#106;", "&#110;", "&#114;", "&#123;", "&#124;", "&#125;"]

global t = time();
global gotsomething = false
global SZ = Dict{String, String}()
global HSYMS = []
global HSYMCT = 0
global WorkString = ""
global CCT = 1
global MAXL = 0
global AgeDistribution = Dict{String, Int32}()
#global isWIN = Sys.iswindows()

#if isWIN
#    pwwd = pwd()
#    pwws = findlast("\\", pwwd)
#    global SOSOSO = pwwd[pwws.start + 1:length(pwwd)] * "\\"
#else 
    global SOSOSO = ""
#end

function et()
    return formatDecimal(time() - t, 3)
end

OUTPUTFILE = "JUNK.html"    #isWIN ? pwd() * "\\..\\JUNK.html" : "JUNK.html"
OUTPUTFILE2 = "JUNK2.html"  #isWIN ? pwd() * "\\..\\JUNK2.html" : "JUNK2.html"
OUTPUTFILE7 = "JUNK7.html"  #isWIN ? pwd() * "\\..\\JUNK7.html" : "JUNK7.html"

global searchString = ARGZ[1]
global ACCUMS = zeros(Int32, 1)    

global searchString = ARGZlen == 2 || ARGZlen == 4 ? Regex(searchString) : Regex(searchString, "i")
global strs = open("JUNK3.txt", "a")
write(strs, nowww * "  " * string(searchString) * "\n")
close(strs)

global errId = 0
global ctr = 0
global cctr = 0

global out = "\n<table\n    style=\"border-collapse:separate;white-space:nowrap;font-family:monospace;font-weight:bold;font-size:large;padding:0px 12px 10px 6px;\">"
try
    global errId = 1
    if FILTER == nothing
        global FILTER = readdir()
    end 
    global errId = 2
    for itm in FILTER
        itmLen = length(itm)
        if !isfile(itm) || itmLen < 6 || itm[itmLen - 4 : itmLen] != ".html" || 
                    itm in ["XXXRTree.html", "XXXXTree.html" , "XXXTree.html",
                        "JUNK.html", "JUNK2.html", "JUNK6.html", "JUNK7.html", "JUNK10.html"]
            continue
        end
        global item = itm
        global errId = 4
        res = RRead(item, "asis")
        
        lenRes = length(res)
        if lenRes > 49999
            lenRes = "            " * string(lenRes)
            lenLenRes = length(lenRes)
            chk = lenRes[lenLenRes - 10 : lenLenRes]
            if get(SZ, chk, "GKW") != "GKW"
                println("Error: " * chk * "  " * item) # Program breaks if 2 files same len
                exit(16)
            end          
            SZ[chk] = item
        end

        c9s = findall(r" href=\"c9/[^\"]+\"", res)
        for c9 in c9s
            push!(C9s, [res[c9], item])
        end

        c9s = findall(r" (src|href)=\"c9/[^\"]+\"", res)
        for c9 in c9s
            rr = res[c9]
            if !contains(rr, ".html")
                r = replace(replace(rr, r" (src|href)=\"c9/" => ""), "\"" => "")                          
                a = get(C9imageDict, r, "NUTHIN")
                if a == "NUTHIN"
                    C9imageDict[r] = Dict{String, Int32}(item => 1)
                else
                    aa = get(a, item, "NUTHIN")
                    if aa == "NUTHIN"                    
                        a[item] = 1
                    else
                        a[item] = a[item] + 1
                    end
                end
            end
        end            

        WC0 = findall(r"[ \n][a-zA-Z-]+", res)
        for wc in WC0
            s = lowercase(res[wc])
            sstop = wc.stop
            s = s[2 : length(s)]
            rs1 = res[sstop + 1: sstop + 1]
            if rs1 == "=" || (rs1 == ":" && s in ["background-color", "border", 
                                "border-collapse", "border-radius", "color", 
                                "direction", "font-family","font-size", "font-weight", "height", 
                                "line-height", "margin", "padding", "text-align", "text-decoration", 
                                "vertical-align", "white-space", "width"])
                global WChcount += 1
                s *= rs1
                a = get(WCequals, s, 0)
                WCequals[s] = a + 1
            else 
                global WCcount += 1
                a = get(WC, s, 0)
                WC[s] = a + 1
            end
        end

        global ctr += 1
        if ctr % 50 == 0
            ctrr = "   " * string(ctr)
            lenCtrr = length(ctrr)
            println(ctrr[lenCtrr - 4 : lenCtrr] , "  " , et())
        end        
        txt = res #   String(res)

        # global zzzzzz = txt # "  +2022.04.30 v002  "
        yyyyyy = findall(r">\+[0-9][0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9] v[0-9][0-9][0-9]", txt)
        if length(yyyyyy) != 1 && !(item == "Experiment.html" && length(yyyyyy) == 3)        # KLUDGE
            println("Versioning wrong in file:  " * item)
            exit(16)
        end

        age = txt[yyyyyy[1]][3:11]
        if age[9:9] == "3"         # Merge dom 30, 31 into 20's
            age = age[1:8] * "2"
        end
        if get(AgeDistribution, age, "NO") != "NO"
            AgeDistribution[age] += 1
        else
            AgeDistribution[age] = 1
        end

        x = findall(r"&#[^;]+;", txt)
        global HSYMCT += length(x)
        for y in x
            z = txt[y]
            if length(y) > 10
                println("  MESS in ", itm , ": ", hilite(HI_RED, "STARTMESS"), "\"", z , "\"", hilite(HI_RED, "ENDMESS"), "\n")
            end
            if z in HSYMS
                continue
            end
            push!(HSYMS, z)
        end

        global cctr += length(txt)

        quotes = ""
        ct = 1
        s = searchString
        qqk = findall(s, txt)
        qq = length(qqk)
        for itm in qqk
            alpha = itm.start - PRE
            omega = itm.stop + POST
            if alpha < 1
                 omega -= alpha - 1
                 alpha = 1
            end
            if omega > length(txt)
                omega = length(txt)
            end
            bailout = false
            global tq = txt[alpha:omega]
            for i = 1 : length(tq)
                global ii = Int32(Char(tq[i]))
                if ii > 127
                    println("Fuckup: " , item , " \"", tq, "\" " , ii, " \"" , tq[i] , "\"")
                    bailout = true
                    tq = "?" * replace(tq, r"[;&<>']" => "?") * "?"  
                    break
                end
            end
            if !bailout
                aaw = findfirst(s, tq)
                tq = tq[1 : aaw.start - 1] * "WQWQWQ" * tq[aaw.start : aaw.stop] * "XQXQXQ" *
                            tq[aaw.stop + 1: length(tq)]

                tq = replace(tq, ";" => "!!!!!!!!#59;")
                tq = replace(tq, "&" => "&amp;")
                tq = replace(tq, "!!!!!!!!" => "&")
                tq = replace(tq, "<" => "&lt;")   
                tq = replace(tq, ">" => "&gt;") 
                tq = replace(tq, "\"" => "&quot;")
                tq = replace(tq, "'" => "&apos;")
                tq = replace(tq, "/" => "&#47;")
                tq = replace(tq, "{" => "&#123;")
                tq = replace(tq, "}" => "&#125;")
                tq = replace(tq, " " => "&nbsp;")

                tq = replace(tq, "WQWQWQ" => "<span style=\"border-bottom:1px solid black;font-weight:normal;color:black;\">", count=1)    # Underscore the search text!
                tq = replace(tq, "XQXQXQ" => "</span>", count=1)                    
            end 
            inf = "<br>" * string(ct) * ". " * string(itm)
            global shitfuckshit = 22
            if length(inf) > 21
                println("\n        Inf problem in ", item, ": " * string(length(inf)) * " \"" * inf * "\"\n")
                global shitfuckshit = 24
            end
            quotes *= inf * ("&nbsp;" ^ (shitfuckshit - length(inf))) * "<span style=\"" * (bailout ? "" : "background-color:lightyellow;") * "padding:1px 6px 1px 5px;" * (bailout ? "" : "color:darkred;") * "\">" * tq * "</span>"
            ct += 1
        end

        global ACCUMS += [qq]
        if quotes != ""
            L = length(item) - 5
            if L > MAXL
                global MAXL = L
            end
            global WorkString *= (WorkString == "" ? "" : ", ") * item[1:L]
            push!(MATCHES, item)
            global PUTS *= "put " * item * "\n"
            global out *= "\n<tr><td style=\"vertical-align:top;line-height:135%;text-align:right;font-weight:normal;\"><span style=\"font-size:smaller;\">" * string(CCT) * ".</span>&nbsp;</td><!-- td style=\"vertical-align:top;line-height:135%;\"><a href=\"OSOSOS" * item * "\">==</a></td><td>&nbsp;</td --><td style=\"vertical-align:top;line-height:135%;\"><a href=\"OSOSOS" * item * "\" style=\"text-decoration:none;\">" * item[1:length(item) - 5] * "</a></td><td style=\"line-height:135%;vertical-align:top;\"><span style=\"font-weight:normal;color:gray;\">&nbsp;</span>&nbsp;" * quotes * "</td></tr>\n"
            global out = replace(out, "OSOSOS" => SOSOSO)
            global gotsomething = true
            global CCT += 1
        end
    end
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("\nDoing: " * item * " \"" * tq * "\"")
    println("      Failure[" * string(errId) * "]: ", typeof(ex), ".\n", s);
    exit(16)
end

hsyms = []
hsyms2 = []
global k = 1
global gotSomething = false
for i = 1 : length(HSYMS)
    h = HSYMS[i]
    if h in excludeds      # Don't trust Greeks! 
        continue
    end
    if k % 10 == 1
        if gotSomething
            kn1 = k - 1
            sp = "<span style=\"font-weight:normal;font-size:smaller;color:darkgreen;\">&#91;" * string(kn1) * "]</span>"
            push!(hsyms, sp)
            sp = "<span style=\"font-weight:normal;color:darkgreen;\">&#91;" * string(kn1) * "]</span>"
            push!(hsyms2, sp)
            gotSomething = false
        end
    end

    push!(hsyms, h)
    push!(hsyms2,h[3 : length(h) - 1])
    global k += 1
    global gotSomething = true
end
sct = formatFixed(HSYMCT)
global out *= (gotsomething ? "" : "\n<tr><td>[No matches]</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n") * 
            "<tr><td colspan=3><p style=\"font-size:80px;\">&nbsp;</p></td></tr>\n" *

            "<tr><td colspan=3><div style=\"width:600px;border-radius:6px;background-color:lightyellow;text-align:left;;border:2px solid black;padding:0px 8px 0px 10px;width:600px;font-family:sans-serif;font-weight:bold;\"><p style=\"white-space:normal;\"><span style=\"font-weight:normal;font-size: smaller;color:darkgreen;\">" * 
            string(k - 1) * ":</span>&nbsp;&nbsp;" * replace(join(hsyms, ", "), ", <span style=\"font-weight:normal;font-size:smaller;color:darkgreen;\">&#91;" => " <span style=\"font-weight:normal;font-size:smaller;color:darkgreen;\">&#91;")  * "</p><hr>" *
            "<p style=\"white-space:normal;font-size:smaller;\"><span style=\"font-weight:normal;color:darkgreen;\">" * 
            string(k - 1) * ":</span>&nbsp;&nbsp;" * replace(replace(join(hsyms2, ", "), ", <span style=\"font-weight:normal;color:darkgreen;\">&#91;" => " <span style=\"font-weight:normal;color:darkgreen;\">&#91;"), "x" => "<span style=\"color:darkred;\">x</span>") * "&nbsp;&nbsp;<span style=\"font-weight:normal;\">&#91;&Sigma;&nbsp;" * sct * "]</span></p></div></td></tr>\n" *

                "<tr><td colspan=3 style=\"text-align:right;padding-right:320px; padding-top:14px;\"><a style=\"text-decoration:none;font-weight:normal;\" href=\"JUNK2.html\">JUNK2.html</a>&nbsp; <a style=\"text-decoration:none;font-weight:normal;\" href=\"JUNK3.txt\">JUNK3.txt</a>&nbsp; <a style=\"text-decoration:none;font-weight:normal;\" href=\"JUNK7.html\">JUNK7.html</a></td></tr>" *
                "</table><!--p>&#91;&#8228;&nbsp;8228</p --><br><p style=\"padding:0px 24px 0px 16px;\"><a href=\"PUTS\" style=\"text-decoration:none;\">PUTS</a> | <a href=\"MATCHES\" style=\"text-decoration:none;\">MATCHES</a>&nbsp; (" *
                string(MAXL) * ") \"" * WorkString * "\"</p><br><br></div>\n<div style=\"width:100%;margin:60px 0px 20px 0px;text-align:right;\"><div class=\"floatright\"><a href=\"https://validator.w3.org/\" title=\"This page has been validated as HTML 5.\"><img alt=\"This page has been validated as HTML 5.\" src=\"w/images/c/ca/HTML5V.png\" style=\"width:80px;height:29px;padding-right:50px;\"></a></div></div></body></html>"

stotlen = string(cctr)
if cctr> 999
    stotlen = stotlen[1:length(stotlen) - 3] * "," *
            stotlen[length(stotlen) - 2 : length(stotlen)]
end
if cctr > 999999
    stotlen = stotlen[1:length(stotlen) - 7] * "," * 
            stotlen[length(stotlen) - 6 : length(stotlen)]
end 
pre = "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\"><head><title>Frustra</title><meta charset=\"UTF-8\"></head>\n<body><div style=\"margin:40px 0px 20px 32px;\"><p style=\"line-height:150%;font-family:sans-serif;font-weight:bold\">"

s = Array{Any}(undef, 1 * 2 + 1)
s[1] = "  "
global ix = 2
println("  searchString: ", hilite(HI_AQUA, "| "), searchString ,  hilite(HI_AQUA, " |"), ".")
ss = searchString
s[ix] = ss
global ix = ix + 1
s[ix] = "  "
global ix += 1  

s = replace(replace(string(s), "<" => "&lt;"), ">" => "&gt")
sp = "<span style=\"color:darkred;background-color:yellow;padding:4px 5px 2px 5px;\">"

s = replace(s, "Any[" => "Any[ ")
s = replace(s, "\"  \", " => "&nbsp;&nbsp;")
s = replace(s, ", \"  \"" => "&nbsp;&nbsp;&nbsp;")
s = replace(s, "Any[ &nbsp;&nbsp;r\"" => "Any[ &nbsp;&nbsp;r\"" * sp) 
s = replace(s,  "\"i, &nbsp;&nbsp;r\"" => "</span>\"i, &nbsp;&nbsp;r\"" * sp)
s = replace(s, r"\"(i?)&nbsp;&nbsp;&nbsp;" => s"</span>\"\1&nbsp;&nbsp;&nbsp;") 
pre *= "<span style=\"font-weight:normal;\">[ \"%%x%\" for 1:'^', 2:'>', 3:'&', 4:'&#', 5:'|' ]</span>&nbsp;&nbsp;" * s * ".&nbsp;&nbsp;" * OUTPUTFILE
pre *= "<br>Files: " * string(ctr) * ".&nbsp;&nbsp;Chars: " * stotlen * ".&nbsp; &Sigma;" *
                string(ACCUMS) * string(CCT - 1) * "&nbsp;&nbsp;Time: " *
                et() * ".&nbsp;&nbsp;v" *  version *
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" * replace(APtS_ET, r"d([^m]+)m" => s"<span style=\"font-weight:normal\">d\1s</span>") * (FILTERED ? "&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:red;font-size:larger;\">FILTERED!</span>" : "") * "</p>"

z = open(OUTPUTFILE, "w")
write(z, pre * out)
close(z)

kk = keys(SZ)
szfuxk = []
for k in kk
    push!(szfuxk, string(k))
end
global fu = ""
szfuxk = sort(szfuxk, rev = true)
global fx = "     3"
global FU66 = " "
for f in szfuxk
    if f[6:6] != FU66    #  fx[6:6] != " " && f[6:6] == " "
        global fu *= "\n"
        global fx = "     " * f[6:6]
        global FU66 = f[6:6]
    end
    global fu *= f * "   " * SZ[f] * "\n"
end
fuLen = length(szfuxk) 

kk = keys(AgeDistribution)
szfuxk = []
for k in kk
    push!(szfuxk, string(k))
end
szfuxk = sort(szfuxk, rev = true)
global pf1 = ""
global pf2 = ""
global you = ""
global totAges = 0
for f in szfuxk
    ct = "     " * string(AgeDistribution[f])
    global totAges += AgeDistribution[f]
    lenCt = length(ct)
    newf = "" 
    if f[1:4] == pf1
        newf = "    "
    else
        global pf1 = f[1:4]
        newf = pf1
    end
    newf *= "  "
    if f[6:7] == pf2
        newf *= "  "
    else
        global pf2 = f[6:7]
        newf *= pf2
    end
    newf *= " " * f[9:9]
    shitshit = ct[lenCt - 5 : lenCt]
    global you *= "\n      " * newf * shitshit
end
global totAgess = "      " * string(totAges)
global lenTA = length(totAgess)
global you *= "\n            ----------\n                " * totAgess[lenTA - 5 : lenTA]   

z = open(OUTPUTFILE2, "w")
write(z, "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"UTF-8\"><title>Frustra</title>\n")
write(z,"<style>\n  .s1 {\n    padding:0px 30px 0px 4px;\n    color:black;\n    text-decoration:none;\n  }\n  .s2 {\n    padding:0px 30px 0px 0px;\n    color:black;\n    text-decoration:none;\n  }\n</style>\n")

write(z,"</head>\n<body>\n<div style=\"margin:20px 0px 60px 32px;\">\n<p style=\"line-height:150%;font-family:sans-serif;font-weight:bold\">C:\\ROM\\JUNK2.html</p>\n<pre>\n")
zn = string(now())
zn = zn[1:10] * " " * zn[12 : length(zn)] 
write(z, "    WBSearch v" * version * "(j:" * string(VERSION) * ")   [ \"%%x%\" for 1:'^', 2:'>', 3:'&', 4:'&#', 5:'|' ]   " * APtS_ET * "\n")
fu2 = replace(fu, r" ([0-9]+)   ([^ .]+)\.html" =>
                  s" \1   <a href=\"OSOSOS\2.html\" style=\"text-decoration:none;\"><span style=\"color:darkred;font-weight:bold;\">\2.html</span></a>")

fu2 = replace(fu2, "OSOSOS" => SOSOSO)
write(z, "    " * zn * "  (" * string(fuLen) * "\n" * fu2)
write(z, you)
write(z, "</pre>\n</div>\n")

write(z, "<table\n    class=\"tbl\" style=\"font-size:16px;font-family:sans-serif; margin:0px 0px 0px 90px;line-height:21px;border-collapse:collapse;\">\n" )
global tr = ""
C9ss = sort(C9s, by = x -> lowercase(x[1] * x[2]))
FU = Dict()
for c9 in C9ss
    if get!(FU, c9, "SHIT") == "SHIT"
        FU[c9] = 1
    else
        FU[c9] += 1
    end
end

SHIT = []
for k in keys(FU)
    push!(SHIT, string(k))
end

ASSHOLE0 = []
for shit in keys(FU)
    push!(ASSHOLE0, [shit[2] * shit[1], [shit[1], shit[2], FU[shit]]])
end
ASSHOLE = sort(ASSHOLE0, by = x -> lowercase(x[1]))

global tr = "<td style=\"vertical-align:top;\"><a href=\"c9/\" style=\"padding:0; text-decoration:none;\">c9/</a></td>"
global ix = 0
for shit0 in ASSHOLE
    shit = shit0[2]
    write(z, "<tr style=\"background-color:" * (ix % 3 == 1 ? "yellow" : "white") * ";\"><td><a href=\"" * shit[2] * "\" class=\"s1\">" * shit[2] * "</a></td>" *
            tr * 
            "<td><a" * shit[1] * " class=\"s2\">" * shit[1][11 : length(shit[1]) - 1] * "</a></td><td style=\"padding-right:4px;\">" * string(shit[3]) *  "</td></tr>\n")
    global tr = "<td style=\"vertical-align:top;\">&nbsp;</td>"
    global ix += 1
end
write(z, "</table>\n")

write(z, "<div style=\"width:100%;margin:60px 0px 20px 0px;text-align:right;\"><div class=\"floatright\"><a href=\"https://validator.w3.org/\" title=\"This page has been validated as HTML 5.\"><img alt=\"This page has been validated as HTML 5.\" src=\"w/images/c/ca/HTML5V.png\" style=\"width:80px;height:29px;padding-right:50px;\"></a></div>\n</div></body>\n</html>")

close(z)

println("\nOutput saved to: " * OUTPUTFILE* ".  &Sigma;" * string(ACCUMS) * string(CCT - 1) * 
            "\nv" *  version * ".  Time: " * et())

function gsk(x)
    x2 = x[2]
    lenx2 = length(x2)

    if (lenx2 = length(x2)) > 3
        return x[1] * 276922881 +     # powers of 129
            Int32(x2[1]) * 2146689 + 
            Int32(x2[2]) * 16641 + 
            Int32(x2[3]) * 129 + 
            Int32(x2[4])
    end
    if lenx2 == 3
        return x[1] * 276922881 + 
            Int32(x2[1]) * 2146689 + 
            Int32(x2[2]) * 16641 + 
            Int32(x2[3]) * 129
    end
    if lenx2 == 2
        return x[1] * 276922881 + 
            Int32(x2[1]) * 2146689 + 
            Int32(x2[2]) * 16641
    end
    return x[1] * 276922881 + 
            Int32(x2[1]) * 2146689
end

function WCf(dict)
    WCS = []
    for k in keys(dict)
        v = dict[k] 
        push!(WCS, [v,string(k)])
    end
    return sort(WCS, by = x -> gsk(x), rev=true)               
end

global info = replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(string(WCf(WC)), r"Any\[(\d+). \"([^\"]+)\"\][,\]] ?" => s"\n\1  \2"),
            r"^Any\[" => ""), r"\n(\d{4}) " => s"\n \1 "), r"\n(\d{3}) " => s"\n  \1 "), r"\n(\d{2}) " => s"\n   \1 "), r"\n(\d) " => s"\n    \1 ", count = 1),

        r"\n (\d{4}) " => s"\n&nbsp;\n \1 ", count=1),
        r"\n  (\d{3}) " => s"\n<a id=\"X3\">&nbsp;</a>\n  \1 ", count=1),
        r"\n   (\d{2}) " => s"\n<a id=\"X2\">&nbsp;</a>\n   \1 ", count=1),
        r"\n    (\d) "    => s"\n<a id=\"X1\">&nbsp;</a>\n    \1 ", count=1),
        r"\n(\d) " => s"\n    \1 ")         # I do not understand why I need this translation

global info *= "</pre><h3 id=\"EC\" style=\"font-family:sans-serif;\">Equals and colons (" * formatFixed(length(WCequals)) * "):</h3>\n<pre style=\"font-size:18px;\">\n"

global brk = 77
global frst = true
WCSS = WCf(WCequals)
vlen = length(WCSS)
for i = 1 : vlen
    v = WCSS[i]
    v1 = string(v[1])
    lenv = length(v1)
    if lenv != brk
        if !frst
            global info *= "&nbsp;\n"
        end
        global frst = false
        global brk = lenv
    end
    global info *= " " ^ (5 - lenv) * v1 * "  " *  v[2]  * "\n"
end

z = open(OUTPUTFILE7, "w")
write(z, "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"UTF-8\"><title>Frustra</title></head>\n<body>\n<div style=\"margin:20px 0px 60px 50px;\">\n<h3 style=\"line-height:150%;font-family:sans-serif;font-weight:bold;padding-left:8px;font-size:18px;\">C:\\ROM\\JUNK7.html&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#X3\" style=\"font-weight:normal;color:darkred;\">X3</a>&nbsp;&nbsp;<a href=\"#X2\" style=\"font-weight:normal;color:darkred;\">X2</a>&nbsp;&nbsp;<a href=\"#X1\" style=\"font-weight:normal;color:darkred;\">X1</a>&nbsp;<a href=\"#EC\" style=\"font-weight:normal;color:darkred;padding-left:6px;\">EC<img src=\"w/images/5/5b/Next2a.gif\" alt=\"Next\" style=\"width:10px;height:12px;vertical-align:2px;padding-left:1px;\"></a></h3>\n<p style=\"font-size:18px;font-family:sans-serif;\">" *
noww() * "&nbsp;&nbsp;v" * APFS *    
    ".&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color:blue;\">Unique words: <span style=\"color:black;\">" * formatFixed(length(WC)) *
    "</span>.&nbsp;&nbsp;&nbsp;Total words:&nbsp;&nbsp;Text: <span style=\"color:black;\">" * formatFixed(WCcount) *
    "</span>,&nbsp;&nbsp;HTML: <span style=\"color:black;\">" * formatFixed(WChcount) *
    "</span></span></p>\n<pre style=\"font-size:18px;\">\n")
zn = string(now())
zn = zn[1:10] * " " * zn[12 : length(zn)] 
write(z, "WBSearch v" * version * "(j:" * string(VERSION) * ")   [ \"%%x%\" for 1:'^', 2:'>', 3:'&', 3:'&', 4:'&#', 5:'|' ]   " * APtS_ET * "\n")
fu2 = replace(fu, r" ([0-9]+)   ([^ .]+)\.html" =>
                  s" \1   <a href=\"OSOSOS\2.html\" style=\"text-decoration:none;\"><span style=\"color:darkred;font-weight:bold;\">\2.html</span></a>")
write(z, info)
write(z, "</pre>\n</div>\n<div style=\"width:100%;margin:60px 0px 20px 0px;text-align:right;\"><div class=\"floatright\"><a href=\"https://validator.w3.org/\" title=\"This page has been validated as HTML 5.\"><img alt=\"This page has been validated as HTML 5.\" src=\"w/images/c/ca/HTML5V.png\" style=\"width:80px;height:29px;padding-right:50px;\"></a></div>\n</div></body>\n</html>")
close(z)

a = open("C9IMAGDICT", "w")
write(a, string([noww() * "  v" * version, C9imageDict]))
close(a)
a = open("MATCHES", "w")
write(a, string(MATCHES))
close(a)
a = open("PUTS", "w")
write(a, PUTS)
close(a)

println("       Time: " * et())