2024-04-03 08:28:56

*---- "Ascii"

include("WBInclusions")

APFS = "014" # Ascii:APFS
global versionNr = APFS[2:3]

# I (BMcC) was thoroughly enraged in trying to fix up this script.

global nr = 1
global clr = 30
global defaultClr = Sys.iswindows() ? "33" : "31"
if length(ARGS) == 2
    colr = tryparse(Int64, ARGS[2])
    if colr == nothing
        println("\n   Color not numeric: ", ARGS)
        exit(16)   
    end
    defaultClr = string(colr)
end
global lenArgs = length(ARGS)
global FUCKEDUP = lenArgs > 0 ? lowercase(ARGS[1]) : ""
if FUCKEDUP == "ext"
    global FUCKEDUP = "extended"
end

if !(lenArgs == 0 || FUCKEDUP in ["extended", "plain"])
    println("\n   Parameters fucked up: ", ARGS)
    exit(16)
end
rng = FUCKEDUP == "extended" ? [160 : 175] : [32 : 47]
println(lenArgs > 1 ? "\n       \033[28;1m28 \033[29;1m29 \033[30;1m30 \033[31;1m31 \033[32;1m32 \033[32;1m32 " *
            "\033[33;1m33 \033[34;1m34 \033[35;1m35 \033[36;1m36 \033[37;1m37 \033[38;1m38\033[0m  " * "(v" * APFS * ")\n" : "\n") 

hexes = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]

if length(ARGS) == 0
    println(LO_GRAY * "         2         3         4         5         6         7" * HI_END)
end

for i =  rng[1] 
    for j = 0 : 5
        k = i + j * 16
        print("     ", 
                k == 127 ? "[" : HI_COLOR(defaultClr) * Char(k) * HI_END, 
                k < 100 ? "  " : k == 127 ? HI_YELLOW * "v" * HI_END : " " , 
                k == 127 ? HI_YELLOW * versionNr * HI_END * "]" : string(k))         # for 127 show version number!
    end

    print("  " * LO_GRAY * hexes[1 + mod(i, 16)] * HI_END * "\n")
    if clr == 37
         global clr = 90
    else
         global clr += 1
    end
    global nr += 1
end


*---- "Hexprint"

include("WBInclusions")

APFS = "021" # Hexprint:APFS
version = "v" * APFS * " +2023.07.21"
# Adding the kludge speeded up a search of 600K file from 175 sec to > 1 sec

global MYARGS = ARGS
global DOSSY = false

t = time() 

function myPrint(fn, offshit::Int64=0, maxShit::Int64=9999999)  
    offset = Int(floor(offshit / 16)) * 16
    maxLen = Int(floor((maxShit + 15) / 16)) * 16
    if (length(fn)) < 1
        return("\n         NO ARGUMENT\n\n")
    end
    notGood = false
    hexChars = "0123456789ABCDEF"
    everything = ""
    everyin = ""
    p4 = 0
    
    try
        t = RRead(fn, "raw")
        if length(MYARGS) > 3
            if MYARGS[4] == "="
                MYARGS[4] = MYARGS[2]
            end
            p4 = tryparse(Int64, MYARGS[4])   
            p4 = Int(floor(p4 / 16)) * 16 + 1
            t = t[p4:length(t)]
            p4 -= 1
        end 
        rlim = lent = length(t)
        if offset < 0
            offset = Int(floor((rlim + offset) / 16)) * 16
        end
        taboo = offset + maxLen
        if rlim > taboo
            rlim = taboo
        end
        for i = 1:rlim                                     # length(t)
            r = hexChars[1 + (Int(floor(t[i] % 16)))]    
            q = hexChars[1 + (Int(floor(t[i] / 16)))]    
            everything *= string(q,r, " ")
            if t[i] < 32 || t[i] > 127
                if t[i] == 13 || t[i] == 9
                    global DOSSY = true
                end 
                everyin *= "." 
            else
                everyin *= string(Char(t[i])) 
            end
        end
        hx = string(offset, base = 16)
        println("\n         HexPrint " * version * "\n         " * fn *
                " (" * string(lent) * ": " * string(offset) * " ~ " * string(rlim) * ", 0x" * hx * 
                (p4 == 0 ? "" : "  \033[31;1mKLUDGE!\033[0m") * ")\n")

        shit = Int(floor(length(everyin) % 16))
        if shit > 0
            shit = 16 - shit 
            everyin *= "                                               "[1:shit]
            everything *= "                                               "[1:( 3 * shit)]
        end

#    30   2F 54 65 78 74 42 75 62 62 6C 65 2E 6A 70 67 22   | /TextBubble.jpg" |   48

        rl = offset    #    tryparse(Int64,offset) 
        while rl < rlim 
            stain = "        " * string(string(rl + p4, base = 16))
            stain = stain[(length(stain) - 5):length(stain)]
            omg = everything[(3 * rl + 1):(3 * rl + 23)] * " " * everything[(3 * rl + 24):(3 * rl + 48)]
            stain2 = stain * "   " * 
                replace(omg, r"([89ABCDEF][0123456789ABCDEF]|0[0123456789BCDEF])" => s"\e[31;1m\1\e[0m") * 
                        HI_YELLOW * "  |" * HI_END * " " * 
                        everyin[(rl + 1):(rl + 16)]  * " " * HI_YELLOW * "|" * HI_END * "   " * 
                        string(rl + p4)
            println(stain2)
            rl += 16
        end
    catch ex
        println("Exception: ", ex)
        notGood = true
    finally
        if notGood == false
            print("\n         CLOSED: ")
        else
            print("\n         NOTGOOD: ")
        end
        println(fn) #  * "\n")
    end
end

p1 = ""
p2 = 0
p3 = 99999999
if length(MYARGS) > 2  #  3
    p1 = MYARGS[1]                    # filename
    p2 = length(MYARGS) > 3 ? 0 : tryparse(Int64, MYARGS[2])   # offset
    p3 = tryparse(Int64, MYARGS[3])   # length
elseif length(MYARGS) == 2
    p1 = MYARGS[1]
    p2 = tryparse(Int64, MYARGS[2])
elseif length(MYARGS) == 1
    p1 = MYARGS[1]
else
    println("\n    Hexprint  Filename  [start  [ length  [ kludge ] ] ]")
    exit(16)
end
myPrint(p1,p2,p3)
println("         E/t: " , formatDecimal(time() - t, 3), 
            DOSSY ? "   " * HI_RED * "DOS lineend(s) or tab(s) detected" * HI_END : "")


*---- "Sc9"

include("WBInclusions")

if length(ARGS) < 1
    println("  Need a string to search for")
    exit(16)
end
global str = Regex(replace(replace(ARGS[1], "%%1%" => "^"), "%%2%" => ">") , "i")

global VERSION = "015"
global BASE = "/ROM/BO/c9/" 
global DIRS = 0
global DISCARDS = 0
global PROCESSED = 0
global HITS = []
global SIZE = 0
global HREFS = 0
global SRCS = 0

function RD(dir)
    global DIRS += 1
    # println("          dir: \"",dir, "\"")
    files = readdir(dir)
    for f in files
        if isdir(dir * f)
            RD(dir * f * "/")
            continue
        end
        if !endswith(f, ".html")
            global DISCARDS += 1
            continue
        end
        ff = dir * f
        b = RRead(ff, "asis")
        c = findall(str, b)
        if length(c) > 0
            fff = replace(ff[length(BASE) + 1 : length(ff)], "/" => "\\")
            push!(HITS, [ff, length(c)])
            #println("  ", fff)
        end
        global HREFS += length(findall(" href=\"", b))
        global SRCS += length(findall(" src=\"", b))
        global PROCESSED += 1
        global SIZE += length(b)
   end
end
println("")
RD(BASE)
println("  PROCESSED: ", PROCESSED, ".  DIRS: ", DIRS,
        ".  DISCARDS: " , DISCARDS, ".  > JUNK6.html.   (", formatFixed(SIZE) , "  ",
                formatFixed(HREFS), "  ", formatFixed(SRCS) * ")")

a = open("JUNK6.html", "w")
write(a, "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"UTF-8\">\n<title>Frustra</title>\n<style>\ntd {\n  padding:4px 20px 4px 8px;\n  vertical-align:top;\n}\na {\n  text-decoration:none;\n}\n</style>\n</head>\n<body>\n<div style=\"margin:40px 0px 80px 80px;font-family:sans-serif;font-size:19px;\">\n<table style=\"border-collapse:collapse;\">\n<tr><td colspan=2><span style=\"font-size:24px;\">" * string(str) * "</span></td></tr>\n")
global SHIT = Dict{String, Any}()
for i = 1 : length(HITS)
    hit = HITS[i]
    h = hit[1]
    pfx = length(findall("/", h)) > 4 ? "0" : "1"
    SHIT[pfx * lowercase(h)] = hit
end
global kk = []
for k in keys(SHIT)
    push!(kk, string(k))
end
kkk = sort(kk)
global PREVX = "X"
for kkkk in kkk
    shit = SHIT[kkkk]
    h = shit[1]
    hlen = shit[2]
    kkkk1 = kkkk[1:1]
    sz = kkkk1 != PREVX ? 12 : 0
    write(a, "<tr><td style=\"padding-top:" * string(sz) * "px;\"><a href=\"" * h * "\">" * h[12 : length(h)] * "</a></td><td style=\"text-align:right;padding-top:" * string(sz) * "px;\">" * string(hlen) * "</td></tr>\n")
    global PREVX = kkkk1
end
write(a,"</table></div>\n</body></html>\n")
close(a)
    

*---- "TzMulti"

using Random
include("WBInclusions")

Version = "026"
if length(ARGS) == 0
    println("\nTzMulti v" * Version * ". Input:  [seedNumber | \"x\"] [text | *filename]\n\n" *
        "    * Take a newspaper.\n    * Take some scissors.\n    * Choose from this paper an article the length you want to make your poem.\n" *
        "    * Cut out the article.\n    * Next carefully cut out each of the words that make up this article and\n              put them all in a bag.\n" *
        "    * Shake gently.\n    * Next take out each cutting one after the other.\n    * Copy conscientiously in the order in which they left the bag.\n" *
        "    * The poem will resemble you.\n    * And there you are--an infinitely original author of charming sensibility,\n" *
        "              even though unappreciated by the vulgar herd.\n    * (Tristan Tzara)")
    exit(16)
end

global ARGS2 = ARGS[2]

if ARGS2[1:1] == "*"
    global ARGS2 = RRead(ARGS2[2 : length(ARGS2)], "asis")
end
    
global Data0 = split(replace(replace(replace(replace(replace(strip(ARGS2),
 
        r"[\r\n]" => " "),
        r"\-\-+" => ""),
        r"[^a-zA-Z0-9'\- ]" => ""),
        r"  +" => " "),
        r" (Mr|Mrs|Mx|Dr|Prof|Messrs) " => s" \1. "),
      # r" ( '|' )" => " "),

" ")

global CHARS = 0
for itm in Data0
    global CHARS += length(itm)
end

global Data = copy(Data0)
global DataJoin = join(Data0, " ")

if (global Seed = tryparse(Int32, ARGS[1])) == nothing
    global Seed = 0
    for chr in DataJoin
        global Seed += Int32(chr)
    end
end

global Fortuna = rand(MersenneTwister(Seed), UInt64, length(Data))

global Out = ""

for ix = 1 : 999999
    len = length(Data)
    if len == 1
        break
    end
    thisIndex = (Fortuna[ix] % len) + 1
    global Out *= Data[thisIndex] * " "
    deleteat!(Data, thisIndex)
end
global Out *= Data[1]

println("\n  TzMulti v" * Version * " Seed: " * string(Seed) * "  (" * string(CHARS) * ":" * string(length(Data0)) * 
            ")\n\n  " * HI_YELLOW * DataJoin * HI_END)

println("\n  " * HI_RED * Out *HI_END)

*---- "BP"

include("WBInclusions")     # Not using noww() function here

global version = "029"

global fn = "w\\txts\\BP"
global displayCt = 16

global ARGZ = copy(ARGS)
global lenARGZ = length(ARGZ)

# Cheat against myself. NumberS are seeming to be too low.

if lenARGZ == 6
    global ARGZ = [string(max(parse(Int32, ARGZ[1]), parse(Int32, ARGZ[4]))), 
                   string(max(parse(Int32, ARGZ[2]), parse(Int32, ARGZ[5]))), 
                   string(max(parse(Int32, ARGZ[3]), parse(Int32, ARGZ[6])))]
    global lenARGZ = length(ARGZ)
end

global MAAAS = 0
global MAAAD = 0
global MINMINS = 99999
global MINMIND = 99999

struct ITEM
    s
    d
end

function pushDown(itm, arry)
    return append!([itm],arry[1:length(arry) - 1])
end       

global ThisDayTotS = 0
global ThisDayTotD = 0
global LenThisDay = 0
global IgnoredLines = 0
global EODs = Dict{String,Array{ITEM}}()

if lenARGZ == 0
    # Go to display current file contents
elseif lenARGZ == 1
    global displayCt = tryparse(Int32, ARGZ[1])
elseif lenARGZ != 3
    println("Wrong number arguments")
    exit(16)
else
    if !isfile(fn)
        close(open(fn, "w"))
    end 

    global nowwRaw = now()
    global nowww = string(nowwRaw)
    global nowww_HM = nowww[12:16]

    prev = split(RRead(fn, "asis"), "\n")
    lenPrev = length(prev)
    global lds = lenPrev
    if lenPrev > 0
        while true
            if prev[lds][3:12] != "          "
                break
            end
            global lds = lds - 1
        end
    end
    if length(ARGZ[1]) != 3 || length(ARGZ[2]) != 2 || !(length(ARGZ[3]) in [2,3]) 
        println("\nAsshole parameter length: ", ARGZ)
        exit(16)
    end

    global Join_ARGZ_Original = ARGZ[1] * " " * ARGZ[2] *        (length(ARGZ[3]) == 2 ? "  " : " ") * ARGZ[3] 
    global Join_ARGZ =          ARGZ[1] * " " * ARGZ[2] * "  " * (length(ARGZ[3]) == 2 ? ARGZ[3] : "99")

    if findfirst(r"^[12]\d{2} [56789]\d  [456789]\d$", Join_ARGZ) == nothing
        println("\nInput bad: ", ARGZ)
        exit(16)
    end

    cur = replace(nowww, r"T(.{5}).*" => s" \1") * "  " * Join_ARGZ_Original

    global doy = "000" * string(dayofyear(nowwRaw) + (cur[1:4] == "2024" ? 365 : 0))
    lenDoy = length(doy)
    global doy = "   " * doy[lenDoy - 3: lenDoy]

    if lenPrev == 0
        b = open(fn, "w")
        write(b, "  " * cur * doy)
    else
        b = open(fn, "a")
        if cur[1:10] == prev[lds][3:12] 
            write(b, "\n            " * cur[11:length(cur)] * doy)
        else
            write(b, "\n  " * cur * doy)
        end
    end
    close(b)
end

global all = []

linesIn = split(RRead(fn, "asis"), "\n")
for itm in linesIn
    if length(itm) < 1 || itm[1:1] == "#"
        global IgnoredLines += 1
        continue
    end
    push!(all, itm)            # push! inserts at the end not the beginning of the list
end 

global hiD = 0
global hiS = 0
global loD = 999
global loS = 999
global MaxMaxS = 0
global MaxMaxD = 0
global MinMinS = 999
global MinMinD = 999

global SQ32 = zeros(Int32,32)
global DQ32 = zeros(Int32,32)
global Qct = 0

lenAll = length(all)
global readings = ""
global lineNr = 1

global prevDoy = ""
function Doy(doy)
    if doy == prevDoy
        return "   "
    end
    global prevDoy = doy
    return doy
end
global TodOy = ""

for i = 0 : lenAll - 1
    nxt = all[lenAll - i]
    s = tryparse(Int32, nxt[21:23])
    d = tryparse(Int32, nxt[25:26])
    ThisDoy = nxt[34:37]
    if get(EODs,ThisDoy, ITEM("X", "X")) == ITEM("X", "X")
        EODs[ThisDoy] = [ITEM(s,d)]
    else 
        push!(EODs[ThisDoy], ITEM(s,d))
    end 
    Doy_OUT = Doy(ThisDoy)

#   +  2022-12-29 07:32  160 60 74  0363=

    if i < displayCt
        RT = ""
        RTX = ""
        if lineNr == 1
            RT = "LINE1"
            global Todoy = Doy_OUT
        elseif lineNr == 2 
            if Doy_OUT != "   " 
                RTX = "                          LINE2"
            else
                RT = "LINE2"
            end
        end
        global lineNr = lineNr + 1
        global readings *= RTX * (Doy_OUT == "   " ? "" : "\n") * "    " * nxt[21:32] * " " * nxt[14:18] * 
                    " " * (Doy_OUT == "   " ? "   " : LO_GRAY * Doy_OUT * HI_END) * RT * "\n"
        if s > hiS
            global hiS = s
        end
        if s < loS
            global loS = s
        end

        if d > hiD
            global hiD = d
        end
        if d < loD
            global loD = d
        end
    end


    if Qct < 32
        global SQ32 = pushDown(s,SQ32)
        global DQ32 = pushDown(d,DQ32)
        global Qct += 1
    end

    if Todoy == ThisDoy
        global ThisDayTotS += s
        global ThisDayTotD += d
        global LenThisDay += 1
    end
end

function hilite(nbr, clr)
    nbrS = string(nbr)
    return replace(readings, "X" * nbrS => "X" * clr * nbrS * HI_END)
end

global readings = replace(readings, r"\n    ([0-9]{3}) " => s"\nX\1X")

function fmtItm(num)
    a = "        " * string(round(num, digits = 1))
    lena = length(a)
    return a[lena - 4: lena]
end

HI_ = HI_RED
LO_ = HI_AQUA

global readings = hilite(hiS, HI_)
global readings = hilite(hiD, HI_)

global readings = hilite(loS, LO_)
global readings = hilite(loD, LO_)

avgS = formatDecimal(sum(SQ32) / Qct, 2)
avgD = formatDecimal(sum(DQ32) / Qct, 2)

dd = fmtItm(ThisDayTotS / LenThisDay) * fmtItm(ThisDayTotD / LenThisDay)

readings = replace(readings, "LINE1" => "   "  * dd * "    d: " * HI_ * "MAAAS" * " "  * "MAAAD" * HI_END * "  %%S%%   i: " *  avgS )
readings = replace(readings, "LINE2" => "                     " * LO_ * "MINMINS" * " "  * "MINMIND" * HI_END * "   %%D%%       " *  avgD *  
            "   ( " * formatFixed(string(length(all))) * LO_GRAY *  " #:" * string(IgnoredLines) * ".  " *
                    formatFixed(stat("w/txts/BP").size) * " v" * version * HI_END * " )")

# This was just too goddamned much no-fucking work!
shit = Regex("(\\d{4})" * "(\\033\\[0m\\n)" )
readings = replace(readings, shit => s"\1Y\2")
x = findall(r"\d{4}Y", readings)
global fux = Dict()
for itm in x
    ri = readings[itm]
    rim = EODs[ri[1:4]]
    s = 0
    d = 0
    for itm2 in rim
        s += itm2.s
        d += itm2.d
    end
    lenRI = length(rim)
    aaa = string(round(s/lenRI, digits = 1)) * " " * string(round(d/lenRI, digits = 1 ))
    global fux[ri] = ri[1:4] * "   " * aaa
end
for f in keys(fux)  
    global readings = replace(readings,f => fux[f], count = 1)
end

#println("\n    " * HI_ * string(MaxMaxS) * " "  * string(MaxMaxD) * HI_END)
#println("    " * LO_ * string(MinMinS) * " "  * string(MinMinD) * HI_END * 
#            "      (" * string(length(all)) * LO_GRAY *  " #" * string(IgnoredLines) * HI_END * ")")

EODkeys = []
global data = ""
k = []
for kk in keys(EODs)
    push!(EODkeys, String(kk))
end
global prevDT = ""
X = sort(EODkeys, rev=true)

global Rct = 0
global SR32 = zeros(Float64,32)
global DR32 = zeros(Float64,32)

#print(replace(readings, r"X([^X]+)X" => s"    \1 "))

for itm in X
    s = 0.0
    d = 0.0
    for itm2 in EODs[itm]
        s += itm2.s
        d += itm2.d
    end
    len = length(EODs[itm])
    dt = replace(string(Day(tryparse(Int32, itm) - 1) + Date("2023")), "-" => ".")
    if dt[1:5] == prevDT
        dt = "     " * dt[6:length(dt)]
    else
        global prevDT = dt[1:5]
    end

    if Rct <32


        for itm2 in EODs[itm]
            if itm2.s > MAAAS 
                global MAAAS = itm2.s
            end
            if itm2.s < MINMINS 
                global MINMINS = itm2.s
            end
            if itm2.d > MAAAD 
                global MAAAD = itm2.d
            end
            if itm2.d < MINMIND 
                global MINMIND = itm2.d
            end
        end

        global SR32 = pushDown(s/len,SR32)
        global DR32 = pushDown(d/len,DR32)
        global Rct += 1
    end

    global data *= "    " * dt *
                 "   " * string(round(s/ len, digits = 1)) * "  " * string(round(d / len, digits = 1)) * "\n"
end

#println("S: ", SR32, "\nD: ", DR32, "\nct: ", Rct)

S = formatDecimal(sum(SR32)/ Rct, 2)
D = formatDecimal(sum(DR32)/ Rct, 2)

for itm in ("MAAAS", "MAAAD" , "MINMINS", "MINMIND")
    EMP("global readings = replace(readings, \"" * itm * "\" => string(" * itm * "))")
end    

a = open("BP.txt", "w")
write(a, data)
close(a)

#println("   avgS: " , avgS, ".  avgD: ", avgD, "'")

global readings = replace(readings, "%%S%%" => S)
global readings = replace(readings, "%%D%%" => D)

print(replace(readings, r"X([^X]+)X" => s"    \1 "))



*---- "NUBP"

include("WBInclusions")

a = open("\\t\\bp", "r")
b = readlines(a)
close(a)

D = Dict()

lenB = length(b)
for i = 1 : lenB
    itm = b[lenB + 1 - i]
    if itm[1:1] == "#"
        continue
    end
    item = split(itm[21:length(itm)], r" +")
    sp = parse(Int32, item[1])
    dp = parse(Int32, item[2])
    date = parse(Int32, item[4])
    x = get!(D, date, [0, 0, 0])
    D[date] = [x[1]+ sp, x[2] + dp, x[3] + 1]
end
ks = []
for k in keys(D)
    push!(ks, Int32(k))
end
ks = sort(ks)

global days = 0
global items = 0
global SumByItemsSP = 0
global SumByItemsDP = 0
global SumByDaysSP = 0
global SumByDaysDP = 0

function h(t)
    return HI_AQUA * string(t) * HI_END
end

function hf(t, n)
    return HI_YELLOW * formatDecimal(t, n) * HI_END
end

lenKS = length(ks)
range = (length(ARGS) > 0 ? parse(Int32, ARGS[1]) : 30)
start = ks[lenKS + 1 - range]

println("\n    NUBP v002.  ksLen: ", h(lenKS), ".  ksMax: ", h(ks[lenKS]), ".  start: ", h(start), " (", h(range), ")\n")

for k in ks
    if k < start
        continue
    end
    dk = D[k]
    global days += 1
    global items += dk[3]
    global SumByItemsSP += dk[1]
    global SumByItemsDP += dk[2]
    global SumByDaysSP += dk[1] / dk[3]
    global SumByDaysDP += dk[2] / dk[3]
end

println("    By item:  ", hf(SumByItemsSP / items, 3), "  ",
              hf(SumByItemsDP / items, 3), "\n    By day:   ",
              hf(SumByDaysSP / days, 3), "  ",
              hf(SumByDaysDP / days, 3))

*---- "del"

include("WBInclusions")

println(" ")
for itm in ARGS
    try
        x = findlast("\\", itm)
        ditm = itm
        if x != nothing
            ditm = itm[x.start + 1 : length(itm)]
        end
        ditm = "\\deleted\\" * ditm
        ditmDot = ditm * "."
        bkupix= 0
        while isfile(ditm)
            ditm = ditmDot * string(bkupix)
            bkupix += 1
        end
        print("    " * HI_YELLOW * itm * HI_END * " ")
        cp(itm, ditm)
        rm(itm)
        println("deleted." * " Copied to: " * ditm)
    catch ex
        s = string(ex)  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        println("Initialization failure: ", typeof(ex), ".\n", s);
        exit(16)
    end
end


*---- "WBInclusions"

APFSJ = "165" # WBInclusions:APFS

# SubstitutionString("s" * "\\1" * t*)

using Dates

global HI_COLOR_PFX = "\033["
function HI_COLOR(clr)
    return HI_COLOR_PFX * string(clr) * ";1m"
end

global LO_GRAY     = HI_COLOR(30)
global HI_RED      = HI_COLOR(31)
global HI_GREEN    = HI_COLOR(32)
global HI_YELLOW   = HI_COLOR(33)
global HI_BLUE     = HI_COLOR(34)
global HI_MAGENTA  = HI_COLOR(35)
global HI_AQUA     = HI_COLOR(36)
global HI_WHITE    = HI_COLOR(37)
global HI_END      = HI_COLOR_PFX * "0m"

function hilite(clr, txt)
    return clr * string(txt) * HI_END
end

global UCK = 0
while UCK < 10
    try 
        global UTCoffset = Int32(round((Dates.value(now(UTC)) - Dates.value(now())) / (60 * 60 * 1000)))
        global UCK = 9999
    catch ex
        global UCK += 1
        s = string(ex)  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        println("\n      " * hilite(HI_RED * "UTC Failure: " * string(typeof(ex)) * ".") * "\n");
    end
end

global SpellingBees = 102

global HILITE_TOHEX = Dict(
    0 => hilite(HI_AQUA, "."), 1 => "1", 2 => "2", 3 => "3", 4 => "4", 5 => "5", 6 => "6", 7 => "7", 8 => "8", 
    9 => "9", 10 => hilite(HI_AQUA, "A"), 11 => hilite(HI_AQUA, "B"), 12 => hilite(HI_AQUA, "C"), 
    13 => hilite(HI_AQUA, "D"), 14 => hilite(HI_AQUA, "E"), 15 => hilite(HI_AQUA, "F")
)

global TrackedScripts = ["Ascii", "Hexprint", "Sc9", "TzMulti", "BP", "NUBP", "del", "WBInclusions",
                         "WB", "WBafter", "WBupdate", "WBTree", "w/WBCount", "WBSearch",
                         "WBMap", "w/WBcompare", "WBheads", "WBW", "WBX", "WBY",
                         "WBZ", "WB_Transforms", "WBdiff", "ZZ", "WBM", "Quora", "C9images"]

function Duree(start, finish, x)    #  Duree(a, now()) = "0d 00h 35m 56s"
  a = div(tryparse(Int64,replace(string(finish - start), " milliseconds" => "")), 1000)
  days = div(a, 86400)
  rmdr = a - days * 86400
  hours = div(rmdr, 3600)
  mins = div(rmdr - hours * 3600, 60)
  secs = "00" * string(rmdr - mins * 60)
  mins = "00" * string(mins)
  hours = "00" * string(hours)
  return string(days) * "d " * 
         hours[length(hours) - 1 : length(hours)] * "h " * 
         mins[length(mins) - 1 : length(mins)] * "m " *
         secs[length(secs) - 1 : length(secs)] * "s"  
end
function Duree(start, finish)
  return replace(Duree(start, finish, "X"), r"m.*$" => "m")
end

global APtS_End = DateTime(2022,9,11,15,45)
global APtS_ET = "APtS(843) " * Duree(APtS_End, now())

function noww()
    dt = string(Dates.now())
    dtx = findfirst('T', dt)
    if dtx == nothing || length(dt) < 20 || dt[20] != '.'
        println("\n**** Date fuckup noww(): \"" * dt * "\" ****\n")
        exit(16)
    end
    return dt[1: dtx - 1] * " " * dt[dtx + 1: 19]
end

function RRead(nm, options)
    a = open(nm, "r")
    b = read(a)
    close(a)
    lco = lowercase(options)
    if lco == "raw"
        return b
    end
    tot127 = 0
    first127 = -1
    gotDOS = false
    lowBAD = -1
    firstLowBAD = -1
    ix = 0
    for c in b
        if c > 127
            if first127 == -1
                first127 = ix
            end 
            tot127 += 1
        elseif c < 32
            if c == 13   #  \x0d
                gotDOS = true
            elseif c != 10    # not \x0a below \x20 (space char) 
                if firstLowBAD == -1
                    firstLowBAD = ix
                end
                lowBAD += 1
            end    
        end
        ix += 1         
    end
    pfx = prefix = "\n\n"
    if tot127 > 0
        println(prefix, hilite(HI_RED, "    *** " * string(tot127) * " charcters > 127 found in " * nm * 
                " (" * string(first127) * ") ***"))
        prefix = "\n"
    end
    if lowBAD != -1
        println(prefix, hilite(HI_RED, "    *** " * string(lowBAD) * " BAD charcters < 32 found in " * nm * 
                " (" * string(firstLowBAD) * ") ***"))
        prefix = "\n"
    end
    if gotDOS
        println(prefix, hilite(HI_RED, "    *** DOS lineend(s) found in: " * nm * " ***"))
        prefix = "\n"
    end
    if pfx != prefix
        println("\n")
    end
    b = String(b)
    if lco == "asis" 
        return b
    end
    if lco == "clean"
        b = replace(b, "-->" => "``>")
        return replace(b, r"<!--[^`]+``>" => "<!-- COMMENT -->")
    end
    println("       RRead invalid options: \"", options, "\"")
    exit(16)
end

function formatDecimal(flt, dgts)
    a = string(round(flt, digits = dgts))
    b = findfirst(r"\.\d+", a)
    if b == nothing
        println("\n", hilite(HI_RED, "formatDecimal no period: \"" * string(flt) * "\"."))
        exit(16)
    end
    c = dgts - (b.stop - b.start)
    if c > 0
        a *= "0" ^ c
    end
    return a
end

function formatFixed(fixd)
    fx = string(fixd)
    a = ""
    punctuation = ""
    while (lenfx = length(fx)) > 3
        a = fx[lenfx - 2: lenfx] * punctuation * a
        punctuation = ","
        fx = fx[1:lenfx - 3]
    end
    if lenfx == 0
        return a
    end
    return fx * punctuation * a
end 

function getBackupNumber()
    bkupfn = "/ROM/BO/WBBKUPID"
    bkupid = open(bkupfn, "r")
    bkupnr = string(tryparse(Int64, readline(bkupid)) + 1)
    close(bkupid)
    bkupid = open(bkupfn, "w")
    write(bkupid, bkupnr * "\n")
    close(bkupid)
    verifi = RRead(bkupfn,"asis")
    if verifi != bkupnr * "\n"
        println("\n    " * hilite(HI_RED * bkupfn * " update catastrophic failure!") * "\n") 
        exit(16)
    end
    return bkupnr
end

#   length(findall(\"<span style=\\\"color:black;\\\">info@servantofthepeople.com</span>\", ax)


function wh(x)

#   "X \e[30;1m Y \e[0m Z" = "X " * LO_GRAY * " Y " * HI_END * " Z" 

    return replace(wh(), r"\e\[30;1m([wz])\e\[0m" =>
            s"<span style=\"font-weight:normal;\">\1</span>")
end

function wh()
    a1 = RRead("Z.txt", "asis")
    a1 = a1[findfirst("`",a1).start : length(a1)]
    global confirmeds = length(findall("| ", a1))
    global sents = length(findall("|+", a1))
    global zelenskys = 0
    
    for itm in ["9", "10", "11", "12"] 
        EMP("ax = RRead(\"Zelensky" * itm * ".html\", \"asis\");" * 
            "ax = ax[findfirst(r\"`[^`]+`\", ax)];" * 
            "global confirmeds += length(findall(\"&#62;\", ax));" * 
            "global sents += length(findall(\"THANK YOU FOR YOUR SUBMISSION!\", ax));" *
            "global zelenskys += length(findall(\"<span style=\\\"color:black;\\\">info@servantofthepeople.com</span>\", ax))")
    end

    return hilite(LO_GRAY, "w") * string(confirmeds) * "/" * string(sents)   * hilite(LO_GRAY, "z") * string(zelenskys)
end

# Equivalent of APL eval()
function EMP(txt)
    #println("EMP: [", txt, "]")
    if typeof(txt) != String
        println("EMP parameter not String: [", txt, "]")
        return nothing
    end
    return(eval(Meta.parse(txt)))::Any
end

*---- "WB"

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

global JSEARCH = false

global STIME = time_ns()

APFS = "647" # 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 == "Quora12.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)

*---- "WBafter"

#using Pkg; Pkg.add("HTTP")

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

APFS = "120" # WBafter:APFS

# Get images!
global k = keys(D)
global IMGarry = []

for ky in k
    x = D[ky]
    y = "w/images/" * x[1] * "/" * x[2] * "/" * ky
    z = string(Dates.unix2datetime(mtime(y)))
    push!(IMGarry, z[1:10] * " " * z[12:16] * "            " * hilite(LO_GRAY, "w/images/") * x[1] * "/" * x[2] * "/" * ky)
end


global incoming = Dict{String, Array{String}}()

nowww = noww()

global arry = []
global ctr = 24
global ctrTrick = ""
if length(ARGS) > 0
    x = tryparse(Int32, ARGS[1])
    if x != nothing && x > 0
        global ctr = x
    else
        global ctrTrick = "!"
    end
end

global xtras = [
    "w/WBKountout.html",
    "z.txt",
    "w/css/WBmiracle.css",
    # "V2",
    # "V1",
]
global xtras = vcat(xtras, TrackedScripts)

global xcludeds = [
    "JUNK.html",
    "JUNK2.html",
    "JUNK6.html",
    "JUNK7.html",
    "JUNK10.html",
    "XXXTree.html",
    "XXXXTree.html",
    "XXXRTree.html"
]
    
try
    global errId = 1
    a = readdir()
    for itm in a
        if findfirst(".html", itm) == nothing || itm in xcludeds
            continue
        end 
        t0 = string(Dates.unix2datetime(mtime(itm)))
        push!(arry, t0[1:10] * " " * t0[12:16] * "    " * itm)
    end
    for itm in xtras
        tx = string(Dates.unix2datetime(mtime(itm)))
        push!(arry, tx[1:10] * " " * tx[12:16] * "        " * itm)
    end
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("\n      Failure[" * string(errId) * "]: ", typeof(ex), ".\n", s);
    exit(16)
end

yxxx = tryparse(Int32, nowww[12:13]) + UTCoffset
fudge = yxxx > 23 ? " **" : ""
xxx = "00" * string(yxxx)
xxx = xxx[length(xxx) - 1: length(xxx)]

pct = formatDecimal(Dates.value(now() - APtS_End) / (86400 * 10 * 843), 2) * "%"

println("\n  WBafter v" * APFS * "     " * hilite(HI_YELLOW, 
           nowww[1:10] * " " * xxx * nowww[14:16] * " UTC" * fudge) * "(" * 
               string(UTCoffset) * "h)" * ctrTrick * " " *
               hilite(LO_GRAY, string(ctr)) * "    " * replace(replace(APtS_ET, 
                       r"d(.*)" => s"dZZZ\1"), "ZZZ" => LO_GRAY) * HI_END * " (" * pct * ")")

# On +2024.01.23 I was so discouraged/depressed that I gave up on this but next morning
# I saw how to do it and going carefully step by step, did it. Easily. No screaming.

n = string(now())
savemeDir = "/SAVEME"
Files = readdir(savemeDir)
times = []
for itm in Files
    if !startswith(itm, r"BO|ROM|bradstuff")
        continue
    end
    push!(times,mtime(savemeDir * "/" * itm))
end
sortedTimes = sort(times)
sLen = length(sortedTimes)
howLongAgo = Duree(Dates.unix2datetime(sortedTimes[sLen]), Dates.now(UTC))

println("                   " * n[1:10] * " " * n[12:16] * "               Bkup: " * 
               hilite(HI_YELLOW, "-" * howLongAgo) * "   Z: " * 
               hilite(HI_YELLOW, string(Date(now())-Date(2022,2,23))[1:3]) * " days.  " * wh())

# Check backup files for scripts
global wbFirst = true
for d in ["./", "./w/"]
    cd(d)
    a = readdir("./")
    for itm in a
        if !endswith(itm, "1") || !isfile(itm) || itm in ["DICT1", "V1", "V2", "SZ1"]
            continue
        end
        if RRead(itm, "raw") == RRead(itm[1:length(itm) - 1], "raw")
            continue
        end
        println((wbFirst ? "\n" : "") * "             WB not match: \"" * itm * "\"")
        global wbFirst = false
    end
end
cd("../")

#if RRead("WBBKUP", "raw") != RRead("WBBKUP1", "raw")
#    println((wbFirst ? "\n" : "") * "             WB not match: \"WBBKUP\"")
#    global wbFirst = false
#end    

println(" ")

global ydm = "xxxxxxxxxx"

b = open("WBLOG-TS", "r")
c = readline(b)
close(b)
push!(arry,c[1:16] * "    " * hilite(HI_AQUA, "~-------"))

println("  " * hilite(LO_GRAY, formatFixed(length(arry)) * " " * formatFixed(length(IMGarry))) *
            hilite(HI_YELLOW, "           V1, V2" * " " ^ 22) *
            hilite(LO_GRAY, "j:" * string(VERSION)))

z = sort(vcat(arry, IMGarry), rev=true)
 
for i = 1 : min(ctr,length(z))
    zi = z[i] 
    if zi[1:10] == ydm
        println("            " * zi[11:length(zi)])
        continue
    end
    global ydm = zi[1:10]
    println("  " *zi)
end
#close(y)

  

*---- "WBupdate"

include("WBInclusions")

APFS = "012" # WBupdate:APFS
global version = APFS
nowww = noww()
inf = "\n" * "WBupdate(" * version *").   " * HI_AQUA * nowww * HI_END * "  (local time)    " * APtS_ET * "\n"
w = open("WBLOG-TS", "w")

yxxx = tryparse(Int32, nowww[12:13]) + UTCoffset
xxx = "00" * string(yxxx)
xxx = xxx[length(xxx) - 1: length(xxx)] 

write(w, nowww[1:10] *  " "  * xxx * nowww[14:16] * "\n")
close(w)
#close(write(open("WBLOG-TS", "w"), nowww[1:10] * " "  * nowww[12:16])) # Does not work
print(inf)


nowww = string(Dates.now())
nowww = nowww[1:10] * " " * nowww[12:16]
yyxxx = tryparse(Int32, nowww[12:13]) + UTCoffset
fudge = yyxxx > 23 ? " **" : ""
xxx = "00" * string(yyxxx)
xxx = xxx[length(xxx) - 1: length(xxx)]

println("                 " * nowww[1:10] * " " * xxx * nowww[14:16] * "  UTC")

if yxxx > 23
    run(`"\windows\System32\notepad.exe" WBLOG-TS`)
end

*---- "WBTree"

include("WBInclusions")

global SHOWUNUSEDS = false

APFS = "258" # WBTree:APFS
version = APFS

mutable struct R
    ct::Int32
    nm::String
end

global V1ID = getBackupNumber()

global SOUGHT = 0
global QUORAS = 0

global nowww = noww()
global DATEPROBLEMS = []
global Validated = -1
global SZ = 0
global EXTERNAL_LINKS = 0
global TOTAL_LINKS = 0
global IMAGE_LINKS = 0
global EMPTIES = 0
global totAUI = 0

global YAHOOS = 0
global ZAHOOS = 0

global szDict = Dict{String,Array{String}}()
global oflDict = Dict{String, Int32}()

global ILUsage = Dict{String, Int32}()
global ILUct = 0
global ILUIgnoreds = Dict{String, Array{String}}(
    "_LynxBlk" => [],
    "_Footnotes" => [],
    "_BRM5V" => []
)

global NUTHIN = ["NUTHIN"]
function ILU(itm)
    a = get!(ILUsage, itm, -1)
    if a == -1
        if itm == "IndexOfSubjects#X" && findfirst(" id=\"X\"", RRead("IndexOfSubjects.html", "clean")) != nothing
            return
        end    
        println(hilite(HI_YELLOW, "    Not found: \"" * itm * "\""))
        return
    end
    ILUsage[itm] = a + 1
    poundStart = findfirst("#", itm).start
    id = itm[poundStart + 1: length(itm)]
    f = itm[1:poundStart - 1]
    if haskey(ILUIgnoreds,id)
        aa = ILUIgnoreds[id]
        if !(f in aa)
             push!(aa, f)
        end
     end
end

global IDS = Dict{String,Array{String}}()
global LWIDS = Dict()
global MAPS = 0
global L2C1FirstPadding = true
global noTOCs = []
global FootnoteBlocks = 0

global HRlen = 24
global HighRevisions = []
for i = 1 : HRlen
    push!(HighRevisions, R(-1 * i, ""))
end

global SumRevisions = 0
global NYTComments = 1  # Add one for th comment I had to take direcly from the NYT website +2023.06.01
global Bingers = 0
global Googlers = 0
global Qsum = 0
global Q = ""
global AllFilesInCurrentDirectory = []

function qwrite(txt)
    global Qsum += length(txt)
    global Q *= txt
end

function ErrorQuit(txt)
    println(hilite(HI_RED, "\n--------\n    " * txt * "\n--------") * "\n")
    exit(16)
end

HSYMS = []

global fdict = Dict{String, String}()
global ildict = Dict{String, Int64}()
global linkCt = 0
global ilinkCt = 0
global pageCt = 0
global incoming = Dict{String, Array{String}}()
global externalLinks = Dict{String, Array{String}}()

global excludeds = ["IndexOfSubjects.html"]
global ignoreds = [
    "JUNK.html",
    "JUNK2.html",
    "JUNK6.html",
    "JUNK7.html",
    "JUNK10.html"
]

pre = "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"w/css/WBmiracle.css\">\n<title>Link inventory</title>\n<meta charset=\"UTF-8\">\n<style>\n    tr td span a {text-decoration:none;}\n    .bY {\n        background-color:yellow;\n        padding:2px 5px;\n    }\n    .bY a {\n        font-family:sans-serif;\n    }\n    .bG {\n        font-weight:normal;\n        color:gray;\n    }\n    .bib {\n        font-weight:bold;\n        color:blue;\n    }\n    .px2 {\n        padding:2px;\n    }\n    .px2 a {\n        font-family:sans-serif;\n    }\n</style>\n</head>\n<body style=\"background-color:white;\"><div style=\"padding:2px 0px 0px 6px;\"><a href=\"welcome.html\" style=\"text-decoration:none;\" class=\"rWel\"><img src=\"w/images/1/12/Prev2a.gif\" alt=\"Previous\" style=\"padding-left:3px;padding-right:1px;width:10px; height:12px;\">Welcome</a></div>\n<div class=\"read600\">\n" *
            "<p style=\"font-family:sans-serif;white-space:nowrap;\">WBTree v" * version * ".&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"IndexOfSubjects.html\">Index</a>&nbsp;&nbsp;&nbsp;<a href=\"w/WBKountOut.html\">Images</a>&nbsp;&nbsp;&nbsp;<a href=\"Dashboard.html\">Dashboard</a><span style=\"vertical-align:1px;padding-left:2px;\"><a href=\"Dashboard.html\" ><img src=\"w/images/5/5b/Next2a.gif\" alt=\"Next2a.gif\" style=\"width:10px;height:12px;\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" * APtS_ET * "</span><br>\n"
 
pres = Dict(
    "Tree" => "Go: <a href=\"XXXRTree.html\">RTree</a><span style=\"vertical-align:1px;padding-left:2px;\"><a href=\"XXXRTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a><a href=\"XXXXTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a></span>",
    "RTree" => "Go: <a href=\"XXXXTree.html\">XTree</a><span style=\"vertical-align:1px;padding-left:2px;\"><a href=\"XXXXTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a><a href=\"XXXTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a></span>",
    "XTree" => "Go: <a href=\"XXXTree.html\">Tree</a><span style=\"vertical-align:1px;padding-left:2px;\"><a href=\"XXXTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a><a href=\"XXXRTree.html\" ><img alt=\"Next2a.gif\" src=\"w/images/5/5b/Next2a.gif\" style=\"width:10px;height:12px;\"></a></span>"
)

pre2 = "</p>\n"

post = "</table>\n<p style=\"margin-top:32px;width:600px;text-align:right;\">[ <a href=\"https://validator.w3.org/\"><span style=\"font-size:larger;vertical-align:-1px;\">&Omega;</span>&nbsp;W3C&nbsp;HTML&nbsp;validator</a>&nbsp;&nbsp;~--S,Z-- ]</p></div>\n</body></html>"

println("\nWBTree v", version, " (./V1).  ", nowww, "    " * APtS_ET , 
        ".  V1ID: " * hilite(HI_YELLOW,  string(V1ID)) * "\n")

rm("XXXTree.html", force=true)
rm("XXXRTree.html", force=true)
rm("XXXXTree.html", force=true)

function saveTable(fn, fv)
    global Q = ""
    global Qsum = 0
    qwrite(pre)
    qwrite(pres[fn])
    qwrite(pre2)
    qwrite(replace(fv, r"TheActiFist</a></span><span class=\"bG\">&nbsp;(&lt;=|=&gt;)" =>
            s"TheActiFist</a></span><span class=\"bG\">&nbsp;\1&nbsp;&nbsp;<span style=\"color:darkred;\">Damn him (her, other)!</span>"))
    qwrite(post)
    # sQsum = string(Qsum)
    sQsum = formatFixed(Qsum)    # sQsum[1:3] * "," * sQsum[4:6]
    ilc = ""
    if fn == "Tree"
        ilc = "&nbsp;&nbsp;" * formatFixed(length(findall(" href=\"#",Q)))
    end
    global Q = replace(Q, "--S,Z--" => sQsum * ilc, count = 1) 
    global q = open("XXX" * fn * ".html", "w")
    write(q, Q)
    close(q)
end    

function makeTable(DICT, ptr)
    global L2C1FirstPadding = true
    if ptr == "=&gt;"
        istr = string(ilinkCt)
        if ilinkCt > 999
            listr = length(istr)
            istr = istr[1: listr - 3] * "," * istr[listr - 2: listr]
        end
        global out = "<table style=\"border-collapse:collapse;font-family:sans-serif;font-weight:bold;background-color:lightyellow;padding:10px;\"><tr><td colspan=2 style=\"padding:2px 0px 12px 2px;color:gray;font-weight:normal;\"><span style=\"border:2px solid darkred;padding:2px 3px 1px 2px;background-color:yellow;\"><a href=\"XXXRTree.html\" style=\"text-decoration:none;\">T</a></span> Pages: " * string(pageCt) * ". Interpage links &gt; <span style=\"font-weight:bold;\">" * lc * "</span>. Imaps: " * string(MAPS) * ". NYTs: <span style=\"font-weight:bold;\">" * string(NYTComments) * "</span>. B/G: <span style=\"font-weight:bold;\">" * string(Bingers) * "</span>/<span style=\"font-weight:bold;\">" * string(Googlers) * "</span><br><span style=\"white-space:nowrap;\"><span style=\"color:blue;padding-top:4px;\">" * nowww * "</span>.  Intrapage ('#') links > " * istr * ".  Img links: " * formatFixed(IMAGE_LINKS) * ".  Footnotes: " * string(FootnoteBlocks) * ".</span></td></tr>\n"
        global ILINKS = istr
        global RLINKS = lc
    elseif ptr == "&lt;=" 
        global out = "<table style=\"border-collapse:collapse;font-family:sans-serif;font-weight:bold;background-color:lightyellow;padding:10px;\"><tr><td colspan=2 style=\"padding:2px 0px 12px 2px;color:gray;font-weight:normal;\"><span style=\"border:2px solid darkred;padding:2px 3px 1px 2px;background-color:yellow;\"><a href=\"XXXXTree.html\" style=\"text-decoration:none;\">R</a></span> Reverse table of incoming internal interpage links:<br><span style=\"color:blue;\">" * nowww * "</span></td></tr>\n"
    else
        global out = "<table style=\"border-collapse:collapse;font-family:sans-serif;font-weight:bold;background-color:lightyellow;padding:10px;\"><tr><td colspan=2 style=\"padding:2px 0px 12px 2px;color:gray;font-weight:normal;\"><span style=\"border:2px solid darkred;padding:2px 3px 1px 2px;background-color:yellow;\"><a href=\"XXXTree.html\" style=\"text-decoration:none;\">X</a></span> !QWERTY! outgoing external links (several uninteresting items excluded):<br><span style=\"color:blue;\">" * nowww * "</span>&nbsp;&nbsp;(Validator: !VICTORY!)</td></tr>\n"
    end
    global shit = []
    global shit = collect(keys(DICT))
global shoot = copy(shit)
    ghosts = []
    crt = 0
    shitx = sort(shit, by=lowercase)
    for s in shitx
        s2 = s[1:(length(s) - 5)]
        if length(DICT[s]) == 0
            push!(ghosts, (s2 == "IntoTheLight" ? "<a href=\"https://www.bmccedd.org/IntoTheLight.html\">IntoTheLight</a>" : "<a href=\"" * s2 * ".html\">" * s2 * "</a>"))
        end
        ilss = "" 
        ils = get(ildict, s, 0)
        if ils > 0
            ilss = "(DDD" * string(ils) * ")"
        end
        if ptr != "&lt;&lt;="
            if s2 == "welcome"
                s2a = ""
            else
                s2a = "|" * s2
            end
            ohmygod = "<a style=\"\" href=\"" * s2 * ".html\">" * s2 * "</a>"
            if s2 == "IntoTheLight"
                ohmygod = "<a style=\"\" href=\"https://www.bmccedd.org/IntoTheLight.html\">IntotheLight</a>"
            end
            global out *= "<tr><td colspan=2 class=\"px2\"><span class=\"bY\" id=\"" * Translates[s2] * "\">" * ohmygod * "</span><span class=\"bG\">&nbsp;" * ptr * "</span></td></tr>"
        else
            if s2 == "https://validator.w3"
                global Validated = length(findall(",", DICT[s])) + 1
                DICT[s] = "[ <span style=\"font-style:italic;\">TMTC:</span> " * string(Validated) * " ]"
            end
            crtx = string(crt += 1)

            sFixed = replace(s, "&amp;" => "!!!")
            sFixed = replace(sFixed, r"(!!!|&)" => "&amp;")
            if s != sFixed
                println("\n    \"", s, "\"\n    \"", sFixed, "\"\n")
            end

            crtx = ("&nbsp;" ^ (4 - length(crtx))) * crtx
            global out *= "<tr" * (s == "https://www.bmccedd.org/IntoTheLight.html" ? " id=\"IntoTheLight\"" : "") * "><td colspan=2 class=\"px2\"><span style=\"font-weight:normal;\">" * crtx * ".</span>&nbsp;<span style=\"background-color:yellow;padding:2px 5px;overflow-wrap:anywhere;\"><a href=\"" * sFixed * "\">" * sFixed * "</a></span><span class=\"bG\">" * ilss * " " * ptr * "</span></td></tr>"
        end
        if s2 in ["OnCitation", "Date", "BRADFORD", "EndOfEarth"] && ptr == "&lt;="
            global out *= "<tr><td> </td><td>&#91; <span style=\"font-style:italic;\">TMTC:</span> " * string(1 + length(findall(",", DICT[s]))) * " ]</td></tr>"
        
            if s2 == "Date" 
                #ds = replace(DICT[s], r"<a href=\"#([^\"]+)\">\1</a>" => s"\1.html")
                ds = replace(DICT[s], r"<a href=\"#[a-zA-Z]{1,2}\">([^\"]+)</a>" => s"\1.html")
                global DS = split(ds, ", ")
                global DICK = Dict()
                for shooter in shoot
                    DICK[shooter] = 0
                end
                for ddss in DS
                    DICK[ddss] = 1
                end  
                k = keys(DICK)
                for kk in k
                    if DICK[kk] == 0
                         push!(DATEPROBLEMS, kk[1:length(kk) - 5])
                    end
                 end
                 global DATEPROBLEMS = sort(DATEPROBLEMS)
            end

        elseif s2 != "welcome" || ptr != "&lt;="
            global out *= "<tr><td style=\"padding:2px" * (L2C1FirstPadding ? " 2px 2px 40px" : "") * ";\"> </td><td class=\"px2\">" *
               (ptr == "&lt;=" && s2 == "IntoTheLight" ? "&#91; <a href=\"XXXXTree.html#IntoTheLight\">All incoming links remote</a> <span style=\"font-weight:normal;\">==&gt;</span> ]" : (length(DICT[s]) > 0 ? DICT[s] : "&nbsp;")) *
               "</td></tr>\n"
        else
            losers = ""
            snoTOCs = sort(noTOCs)
            for item in snoTOCs
                loser = item[1:length(item) - 5]
                if loser == "welcome"
                    continue
                end
                losers *= "<a href=\"" * loser * ".html\">" * loser * "</a>, "
            end
            global out *= "<tr><td style=\"padding:2px" * (L2C1FirstPadding ? " 2px 2px 40px" : "") * ";\"> </td><td class=\"px2\">!TOC&#91;" *
               losers[1 : length(losers) - 2] * "]</td></tr>\n"
        end
        global L2C1FirstPadding = false
    end
    gh = replace(replace(replace(string(ghosts), "\\\"" => "SHIT"), "\"" => "\""), "SHIT" => "\"")   
    out *= (length(ghosts) == 0 ? "" : "<tr><td colspan=2 style=\"padding:20px 0px 2px 2px;color:gray;font-weight:normal;\">Ghosts: " * gh * "</td></tr>")
    out = replace(out, "!QWERTY!" => string(crt), count=1)
    return(out)
end

# Shrink code by translating all internal links into 2 character codenames, so "#BRADFORD" might become "#bO"
# This will break at 2705 files
Alphas = [  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
            "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
            "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
global Translates = Dict{String,String}()
global trix = 0

function setID(fn)
    if length(fn) == 1
        Translates[fn] = fn
        return
    end
    ch1 = div(trix,52)
    ch2 = trix - ch1 * 52
    Translates[fn] = Alphas[ch1 + 1] * Alphas[ch2 + 1]
    global trix += 1
end
 
try
    global errId = 1
    THEGODDAMNEDDIR = readdir()
    for itm in THEGODDAMNEDDIR
        if findfirst(".html", itm) == nothing || itm in ignoreds
            continue
        end
        incoming[itm] = []
        itmX = itm[1 : length(itm) - 5]
        setID(itmX)
        push!(AllFilesInCurrentDirectory, itmX)
    end

    zz = replace(RRead("IndexOfSubjects.html", "clean"), r"&#10004;(\(\d+\) )?" => "") 
    z = findall(r"<li><a href=\"([^.]+).html\" title=\"([^\"]+)\"[ >]", zz)
    global FilesInIndexOfSubjects = []
    for itm in z
        shitstain = replace(zz[itm], r"<li><a href=\"([^.]+)\.html\" title=\"([^\"]+)\"[ >]" => s"\1,\2")
        shitstain = replace(shitstain, " " => "_")
        shitcomma = findfirst(",", shitstain).start
        firstshit = shitstain[1:shitcomma - 1]
        lastshit =  shitstain[shitcomma + 1 : length(shitstain)]
        if firstshit != lastshit
            println("\n", hilite(HI_RED, "    Mismatched entry in IndexOfSubjects \"" * firstshit * "\" \"" * lastshit * "\""), "\n")
            exit(16)
        end
        if firstshit in FilesInIndexOfSubjects
            println("Duplicate in IndexOfSubjects: \"", shitstain, "\"")
            exit(16)
        end        
        push!(FilesInIndexOfSubjects,firstshit)
    end
    for itm in AllFilesInCurrentDirectory
        if !(itm in FilesInIndexOfSubjects)
            println("** In AllFilesInCurrentDirectory but not in FilesInIndexOfSubjects: " , itm)
        end
    end
    for itm in FilesInIndexOfSubjects
        if !(itm in AllFilesInCurrentDirectory)
            println("** In FilesInIndexOfSubjects but not in In AllFilesInCurrentDirectory: " , itm)
        end
    end

    global ALLUNUSEDIDS = Dict{String,Array{String}}()
    global ORIGINALUNUSEDIDS = Dict{String,Array{String}}()
    rr = 0
    for f in FilesInIndexOfSubjects
        ftext = RRead(f * ".html", "clean")

        if length(findall(r"[{}]", replace(ftext, r"<head>.*?</head>"s => ""))) != 0
            println("\n\n        " * hilite(HI_RED, "Stray \"{}\" characters in " * f * ".html.") * "\n\n")
        end

        ff = findall(r" id=\"[^\"]+", ftext) 
        rr += length(ff)
        for fff in ff
            t = ftext[fff.start+5:fff.stop]

            ILUsage[f * "#" * t] = 0

            abitch = get!(ALLUNUSEDIDS, f, ["MISSING"])
            bbitch = get!(ORIGINALUNUSEDIDS, f, ["MISSING"])
            if abitch != bbitch
                println("ADDSADSADSADSADSADA")
                exit(16)
            end
            if abitch == ["MISSING"]
                ALLUNUSEDIDS[f] = [t]
                ORIGINALUNUSEDIDS[f] = [t]
                continue
            end
            push!(abitch, t)
            push!(bbitch, t)
        end
    end

    global errId = 2
    vTable = []
    for itm in keys(incoming)
        global pageCt += 1        
        item = itm
        global errId = 4
        sres = RRead(item, "clean")
        global errId = 5
        global SZ += length(sres)
        x = findfirst("href=\"welcome.html#TOC\"", sres)
        if x == nothing
            push!(noTOCs,item)
        end
        ofl = findfirst(r"<!-- OFL \d{3} -->", sres)
        if ofl != nothing
            oflDict[item] = tryparse(Int32, sres[ofl][10:12])            
        end

        global EXTERNAL_LINKS += length(findall(r"<a(rea)? href=\"https?://", sres))
        global TOTAL_LINKS += length(findall(r"<a(rea)? href=\"", sres))
        
        global IMAGE_LINKS += length(findall(r" href=\"w/images[^.<]+\.(jpg|gif|png)\" ", sres))
        global EMPTIES += length(findall(r"<(span|div)>", sres))

        fns = length(findall(r"Footnotes</a>(</span>)+</h3>", sres))
        if fns > 0
            if fns > 1
                println("\n", hilite(HI_RED, "Footnote problem in " * item), "\n")
                exit(16)
            end
            global FootnoteBlocks += 1
        end

        global NYTComments += length(findall("Your comment has been approved!", sres))
        global Bingers += length(findall("This page indexed on Bing", sres))
        global Googlers += length(findall("This page indexed on Google", sres)) 
        
        if startswith(itm, "Quora")
           aa = r"\d{3}&nbsp;&nbsp;([\d,]+)\.</td>"    
           global QUORAS += tryparse(Int32, replace(sres[findfirst(aa,sres)],aa => s"\1"))
        end 

        # "  +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]", sres)
        yLen = length(yyyyyy)
        if yLen != 1 && !(item == "Experiment.html" && yLen == 3)        # KLUDGE
            ErrorQuit("Versioning wrong in file:  " * item)
        end

        # Police department
        if length(findall(r"({{|}})", sres)) != 0
            ErrorQuit("Loose bracket(s):  " * item)
        end
        if length(findall("size:larger;\"> </span", sres)) != 0
            ErrorQuit("Weird \"size:larger;\":  " * item)
        end

        rv = parse(Int32, sres[yyyyyy[yLen]][15:17])
        global SumRevisions += rv
        rva = "0000" * string(rv)
        #write(vFile, rva[length(rva) - 3: length(rva)] * " " * item * "\n")
        push!(vTable, item * " " * rva[length(rva) - 3: length(rva)])

        for i = 1 : HRlen
            if rv >= HighRevisions[i].ct
                if i == HRlen
                    HighRevisions[HRlen] = R(rv,item)
                    break
                end
                nh = []
                if i > 1
                    nh = HighRevisions[1:i - 1]
                end
                global HighRevisions = append!(nh, [R(rv,item)], HighRevisions[i:HRlen - 1])
                break
            end
        end        
            
        x = findall(r"href=\"[a-zA-Z0-9-_!]+\.html#[^\"]+", sres)
        y = []
        for z in x
            w = sres[z]
            v = findfirst("#", w)
            push!(y, [w[7 : v.start - 6], w[v.start + 1 : length(w)]])
            global ILUct += 1
            ilu = w[7 : v.start - 6] * "#" *  w[v.start + 1 : length(w)]
            ILU(ilu)
            goddamnedfilename = w[7 : v.start - 6]
            if goddamnedfilename == "IndexOfSubjects"
                continue
            end
            goddamnedlink = w[v.start + 1 : length(w)]
            ids = ALLUNUSEDIDS[goddamnedfilename]
            if goddamnedlink in ids
                kky = findall(x->x == goddamnedlink, ids)
                if length(kky) > 1
                    println("\n", hilite(HI_RED, "    Duplicate \"id\" name? \"" * item * "\"  \"" * goddamnedfilename *
                         "\"\n        " * sring(kky) * "  \"" * goddamnedlink, "\""), "\n")
                    exit(16)
                end
                if length(kky) == 1
                     deleteat!(ids, kky)
                end 
            end    
        end

        yahoo = []
        xhoo = findall(r" href=\"#[^\"]+", sres)
        global YAHOOS += length(xhoo)
        for zhoo in xhoo
            w = sres[zhoo]
            ww = w[9 : length(w)]
            global ILUct += 1
            ilu = item[1:length(item) - 5] * "#" *  ww
            ILU(ilu)


            ids = ALLUNUSEDIDS[item[1: length(item) - 5]]
            if ww in ids
                kky = findall(x->x == ww, ids)
                if length(kky) > 1
                    println("Duplicate item in ALLUNUSEDIDS: " * item * " \"" * ww * "\"")
                    exit(16)
                end
                if length(kky) == 1
                     deleteat!(ids, kky)
                     if length(findall(x->x == ww, ids)) != 0
                         println("Deleteat failed for: " * item * " \"" * ww * "\"")
                         exit(16)
                     end
                end 
            end



            push!(yahoo, ww)
        end

        zahoo = []
        xhoo = findall(r" id=\"[^\"]+", sres)
        global ZAHOOS += length(xhoo)
        for zhoo in xhoo
            w = sres[zhoo]
            push!(zahoo, w[6 : length(w)])
        end

        for src in yahoo
            if !(src in zahoo)
                println("        " * item * " internal link src missing target: \"" * src * "\"")
            end
        end

        ittm = itm[1 : length(itm) - 5]
        LWIDS[ittm] = y
        x = findall(r" id=\"[^\"]+", sres)
        y = []
        for z in x
            push!(y, sres[z.start + 5 : z.stop])
        end
        IDS[ittm] = y

        x = findall(r"&#[^;]+;", sres)
        for y in x
            z = sres[y]
            if z in HSYMS
                continue
            end
            push!(HSYMS, z)
        end 
                  
        if itm in excludeds
            global fdict[itm] = "&#91; <span style=\"font-style:italic;\">Everything</span> ]"
            continue
        end

        if findfirst(r"aplacetostudy"i,  sres) != nothing
            println((item in ["Dashboard.html", "JSource.html"] ? "" : "** ") * "\"Aplacetostudy\": " * item)
        end

        global MAPS += length(findall("<map name=\"", sres))

        refs = findall(r"href=\"[a-zA-Z0-9-_!]+\.", sres)

        global linkCt += length(findall(r"href=\"w/txts/(VirtualReality|WhitePrivilege)\.txt\"", sres))

        srefs = []
        for r in refs
            ss = sres[r]
            ss = ss[7: (length(ss) - 1)]
            if !(ss in srefs)
                push!(srefs, ss)
            end
            if !(ss * ".html" in THEGODDAMNEDDIR) && !(ss in ["XXXTree",  "XXXRTree", "XXXXTree"])
println("                           ----\"", ss, "\"    ", ss * ".html" in THEGODDAMNEDDIR)
                ErrorQuit("Bad link in " * itm * ": \"" * ss * ".html\".")
            end
            if !(itm in incoming[ss * ".html"])
                push!(incoming[ss * ".html"], itm)
            end
            global linkCt += 1 
        end
        str = ""
        for x in sort(srefs, by=lowercase)
            str *= (str != "" ? ", " : "") * "<a href=\"#" * Translates[x] * "\">" * x * "</a>"
        end
        global fdict[itm] = str
        global ildict[itm] = iq = length(findall(r"<a (style=\"text-decoration:none\" )?href=\"#", sres))
        if !(itm in ["XXXRTree", "XXXTree", "XXXXTree"])
            global ilinkCt += iq
        end

        xls = findall(r"( href=\"|\|link=)http.*?[\" ]", sres)
        for xl in xls
            t = sres[xl]
            t = replace(t, r"( href=\"|\|link=)" => "", count=1)
            t = t[1:length(t) - 1]
            if get(externalLinks, t, "!") == "!"
                externalLinks[t] = [itm]
            else
                if !(itm in externalLinks[t])
                    push!(externalLinks[t], itm)
                end
            end
        end
    end
    vTable = sort(vTable)
    global vDict = "global V = [\"" * replace(string(Dates.now()), r"T(.{8}).*" => s" \1") * "  " * V1ID *
                "\", Dict{String,String}(\n"
    for item in vTable
        a = findfirst(" ", item)
        #vText *= item[a.start + 1:length(item)] * " " * item[1 : a.start - 1] * "\n"
        dictName = item[1 : a.start - 1]
        dictValue = item[a.start + 1:length(item)] 
        global vDict *= "  \"" * dictName * "\" => \"" * dictValue * "\",\n"
        ofl = get!(oflDict, dictName, 0)
        dictValue = "0000000" * string(tryparse(Int32,dictValue) + 1000 * ofl)
        dictValue = dictValue[length(dictValue) - 4:length(dictValue)]
        dv = get!(szDict, dictValue, ["NOTHING"])
        if dv == ["NOTHING"]
            szDict[dictValue] = [dictName]
        else 
            szDict[dictValue] = append!(szDict[dictValue], [dictName])
        end        
    end
    shitshit = sort(collect(keys(szDict)), rev=true)
    hiVersions = ""
    for i = 1 : 12
        s = shitshit[i]
        hiVersions *= "   " * s * "   " * replace(string(szDict[s]), r"([\[\]\"]|\.html)" => "") * "\n"
    end
    szFile = open("HIversions.txt", "w")
    write(szFile, hiVersions)
    close(szFile)
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    ErrorQuit("\n      Failure[" * string(errId) * "]: " * string(typeof(ex)) * ".\n" * s);
end

lc = string(linkCt)
if linkCt > 999
    lenlc = length(lc)
    lc = lc[1:lenlc - 3] * "," * lc[lenlc - 2:lenlc]
end

global incoming2 = Dict{String, String}()
for k in keys(incoming)
    ary = incoming[k]
    str = ""
    for x in sort(ary, by=lowercase)
        stp = x[1:length(x)-5]
        str *= (str != "" ? ", " : "") * "<a href=\"#" * Translates[stp] * "\">" * stp * "</a>"
    end
    global incoming2[k] = str
end

T = makeTable(fdict, "=&gt;")

RT = makeTable(incoming2, "&lt;=")

global incoming2 = Dict{String, String}()
for k in keys(externalLinks)
    if findfirst("https://faculty.washington.edu/walter/Killing%20Cats3.html#_edn", k) != nothing
        continue
    end
    ary = externalLinks[k]
    str = ""
    for x in sort(ary, by=lowercase)
        stp = x[1:length(x)-5]
        stp2 = ""
        if stp != "welcome"
            stp2 = "|" * stp
        end 
        str *= (str != "" ? ", " : "") * "<a href=\"" * stp * ".html\">" * stp * "</a>"    # ZZZZZ
    end
    global incoming2[k] = str
end

XT = makeTable(incoming2, "&lt;&lt;=")
XT = replace(XT, "!VICTORY!" => string(Validated), count=1) 

saveTable("Tree", T)
saveTable("RTree", RT)
saveTable("XTree", XT)

println("\n--------\n")

global ct = 0
global chksL = 0
global chksR = 0
shitx = sort(collect(keys(LWIDS)))

for k in shitx
    for kk in LWIDS[k]
        if kk[1]== ""                # local links in same file
            global chksL += 1
            if kk[2] in IDS[k]
                continue
            end
            spacer = ""
            if length(k) < 12
                spacer = " " ^ (12 - length(k))
            end
            println(k, spacer, " ? \"#" * kk[2] * "\"")
            global ct += 1
            continue
        end
        global chksR += 1       
        if kk[2] in IDS[kk[1]]
            continue
        end
        spacer = ""
        if length(k) < 12
            spacer = " " ^ (12 - length(k))
        end
        println(k, spacer, " ? \"" * kk[1] * "#" * kk[2] * "\"")
        global ct += 1
    end
end

global tks = 0
global uks = 0
global uksTotal = 0

global kyy = []
for ky in keys(ALLUNUSEDIDS)
    push!(kyy, string(ky))
end
for ky in sort(kyy)   #   keys(ALLUNUSEDIDS)
    global tks += length(ORIGINALUNUSEDIDS[ky])
    global uks += length(ALLUNUSEDIDS[ky])
    global uksTotal += length(ALLUNUSEDIDS[ky])
    for ignore in keys(ILUIgnoreds) 
        if ignore in ALLUNUSEDIDS[ky]
            global uks -= 1
        end
    end

        aui = []
        for itm in ALLUNUSEDIDS[ky]
            if !(startswith(itm, "cite") || itm in keys(ILUIgnoreds))
                push!(aui, itm)
            end
        end
        
        lenaui = length(aui)
        if lenaui > 0
            global totAUI += lenaui

#----------------
            if SHOWUNUSEDS
                println("** " , length(aui), "   ", ky, "  ", sort(aui))
            end
#----------------

        end

end

global usedMulti = 0
global usedOnce = 0

global multis = 0
global keyCount = 0
global kk = 0
#global kkk = []
global II = 0
for k in keys(ILUsage)
    global keyCount += 1
    ii = ILUsage[k]
    if ii == 0

        kkkk = findfirst("#", k)
        kkkk = k[kkkk.start+1: length(k)]
        if kkkk in keys(ILUIgnoreds)
            global II += 1
        end
    elseif ii == 1
        global usedOnce += 1;
    else
        global usedMulti += 1
        global multis += ii - 1
        global kk += 1
        iii = " " ^ (6 - length(string(ii))) * string(ii)
        #push!(kkk, iii * "  " * string(k))
    end
end

#kkk = sort(kkk, rev=true)
#for j in kkk
#    println(j)
#end

function X(position, data)
    x = data - tryparse(Int32,xdata[position])
    if x != 0 
        XS[position] = "[" * string(x) * "]"
        global xdata[position] = string(data)
        global changed = true
    end
end    

global xdata = split(RRead("TreeData", "asis"), "\n")
global XS = []
for i = 1 : length(xdata)
    push!(XS, "")
end
global changed = false;

X(1,TOTAL_LINKS - EXTERNAL_LINKS)
X(2,EXTERNAL_LINKS)

X(3, NYTComments)
if changed
    xfile = open("TreeData", "w")
    write(xfile, xdata[1] * "\n" * xdata[2] * "\n" * xdata[3])
    close(xfile)
end

iDups = (tks - uksTotal) - ilinkCt

q1 = Duree(DateTime(2023,8,1,16,00), now())
q2 = formatDecimal(QUORAS / (tryparse(Int32, q1[findfirst(r"\d+", q1)]) + 1), 4) * "0000"
q3 = hilite(HI_YELLOW, replace(q2, r"^(\d+\.\d).*" => s"\1")) * replace(q2, r"^\d+\.\d(\d).*" => s"\1") 

println("\n  Links: ",   
        hilite(HI_YELLOW, formatFixed(TOTAL_LINKS - EXTERNAL_LINKS)), XS[1], "i + ", 
        hilite( HI_YELLOW, formatFixed(EXTERNAL_LINKS)), XS[2], "r.  ", formatFixed(SZ),
        ".  Empties: ", hilite(HI_YELLOW, formatFixed(EMPTIES)), ".  Quoras: ", formatFixed(QUORAS), 
                " (" * q3 * ").  Orphan IDs: ", formatFixed(totAUI))
global HR1s = []
global a = open("JUNK5.txt", "w")
write(a, "  " * "+" * replace(replace(noww(), "-" => "."), " " => "+")[1:16] * ". WBTree\n\n")
for i = 1 : HRlen
    i1 = HighRevisions[i].ct
    if i < 7
        push!(HR1s,i1)
    end
    i1 = string(i1)
    pfx = " " ^ (8 - length(i1)) 
    write(a, pfx * i1 * "  " * HighRevisions[i].nm * "\n")
end
close(a)
hrs = string(HR1s)
println("\n  Errs:", (ct == 1 ? "" : HI_YELLOW), ct, (ct == 1 ? "" : HI_END), 
          ".  NYTs: ", hilite(HI_YELLOW, NYTComments), XS[3], ".  B/G: ", 
          hilite(HI_YELLOW, Bingers), "/", hilite(HI_YELLOW, Googlers), 
          ".  Revs: " * hilite(HI_GREEN, replace(hrs[5:length(hrs) - 1], "," => "")) *
          "  (" * hilite(HI_GREEN, formatFixed(string(SumRevisions))) * ")   " * hilite(HI_AQUA,
                  " ** Good to go! **"))

sdp = string(DATEPROBLEMS)
sdp = sdp[4 : length(sdp)]

println("\n",length(DICK), "-", length(DS), "=", 
        length(DATEPROBLEMS), ".  DateProblems ", # .  ?: ",length(shoot), "  ", 
        sdp)    #string(DATEPROBLEMS)

#println("\n    YAHOOS: " , YAHOOS, ". ZAHOOS: " , ZAHOOS, ".")

vFile = open("V1", "w")
write(vFile, "# " * string(pageCt - 1) * " " *           # Don't count IndexOfSubjects
          string(linkCt + EXTERNAL_LINKS + IMAGE_LINKS) * 
          "  sum(map((x) -> tryparse(Int32,string(x)), values(V[2])))\n" * vDict * ")]\n")
close(vFile)

#println("\nSOUGHT: " , SOUGHT)


*---- "w/WBCount"

include("../WBInclusions")

APFS = "186" # WBCount:APFS
version = APFS

global D = "D = Dict{String, Array{Any}}( # God damn strong typing! [string, string, int?]\n"

pre = "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"css/WBmiracle.css\">\n<title>Image inventory</title>\n<meta charset=\"UTF-8\">\n<style>\n    .tar {\n        text-align:right;\n    }\n    .bib {\n        font-weight:bold;\n        color:blue;\n    }\n</style>\n</head>\n<body style=\"background-color:gainsboro;\"><div style=\"padding:2px 0px 0px 6px;\"><a href=\"../welcome.html\" style=\"text-decoration:none;\" class=\"rWel\"><img src=\"images/1/12/Prev2a.gif\" alt=\"Previous\" style=\"padding-left:3px;padding-right:1px;width:10px; height:12px;\">Welcome</a></div>\n<div class=\"read600\">\n"

post = "\n<p style=\"margin-bottom:20px;font-family:monospace;font-size:17px;padding-left:4px;white-space:nowrap;\">XXXX</p>\n<p style=\"margin-bottom:20px;font-family:monospace;font-size:16px;line-height:120%\">XYXY</p>\n<p style=\"margin-top:32px;width:600px;text-align:right;\">[ <a href=\"https://validator.w3.org/\"><span style=\"font-size:larger;vertical-align:-1px;\">&Omega;</span>&nbsp;W3C&nbsp;HTML&nbsp;validator</a> ]</p></div>\n</body></html>"

global unhex = Dict{String,Int32}(
    "0" => 0, "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6, "7" => 7,
    "8" => 8, "9" => 9, "a" => 10, "b" => 11, "c" => 12, "d" => 13, "e" => 14, "f" => 15
)

global uppers = Dict{String,Int32}(
    "0" => 0, "1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0, "6" => 0, "7" => 0,
    "8" => 0, "9" => 0, "a" => 0, "b" => 0, "c" => 0, "d" => 0, "e" => 0, "f" => 0
)

global lowers = Dict{String,Int32}(
    "0" => 0, "1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0, "6" => 0, "7" => 0,
    "8" => 0, "9" => 0, "a" => 0, "b" => 0, "c" => 0, "d" => 0, "e" => 0, "f" => 0
)



global ignoreds = [ 
    "JUNK.html",
    "JUNK2.html"
]

global DISTR = Dict(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0,
    8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0
)
global D10Plus = 0

global distr = []
for i = 1:256
    push!(distr,0)
end

global tbl = Dict()
global maxLen = -1
global ct = 0
global rejects = []
global dshit = []
global FirstImage = true
global REPO = length(ARGS) > 0 && lowercase(ARGS[1]) == "repo"
global TrivialImages = ["Next2a.gif", "Prev2a.gif", "Spacer.gif", "WikiMedia.png"]
global trivials = 0
global Qsum = 0
global Q = ""
global Biggies = []
global TOTSZ = Int64(0)
function qwrite(txt)
    global Qsum += length(txt)
    #write(q, txt)
    global Q *= txt
end

for (root, dirs, files) in walkdir(".")
    #println("Directories in $root")
    #for dir in dirs
    #    println(joinpath(root, dir)) # path to directories
    #end
    #println("Files in $root")
    for file in files
        x = joinpath(root, file) # path to files
        #if !contains(x, "images")
        if findfirst(r"^\.\\images\\([0-9a-f])\\\1[0-9a-f][\\]", x) == nothing
            if findfirst(r"^\.\\(css\\|txts\\|pdfs\\)", x) == nothing
                push!(rejects, x)
            end
            continue
        end
        # Create a directory with copies of all the image files
        if REPO
            tgt = "\\REPO\\" * x[15 : length(x)]
            try                
                rs = open(tgt, "w")
                write(rs, RRead(x, "raw"))
                close(rs)
            catch ex
                s = string(ex)  
                if length(s) > 200
                    s = s[1:200] * "..."
                end
                println("\n      REPO: ", tgt , ": ", typeof(ex), ".\n", s);
            end
        end
        y = length(x)
        z = x[15:y]
        zLen = length(z)
        if zLen > maxLen
            global maxLen = zLen
        end
        global tbl[z] = replace(x[1:14], r"[\\]" => "/")
        global ct += 1
        if !(tbl[z] in dshit)
            push!(dshit, tbl[z])
        end
    end
end
dt = string(Dates.now())
dtx = findfirst('T', dt)
dtx = replace(dt[1: dtx - 1] * " " * dt[dtx + 1: length(dt)], r"\.[0-9]+" => "", count=1)
global stuff = "<p style=\"font-family: sans-serif;color:black;margin-top:24px;margin-bottom:32px;\">&#91;WBCount v" * version * "]&nbsp;&nbsp;" * pwd() * "&nbsp;&nbsp;&nbsp;(--IMAGES--)&nbsp;&nbsp;--S,Z--.<br>maxLen: " * string(maxLen) * ",  count: " *
           string(ct) * ".&nbsp;&nbsp;<span style=\"color:mediumblue;font-weight:bold;background-color:lightyellow;padding:2px 3px 1px 2px;\">" * dtx * "</span>.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"../XXXTree.html\">Links</a>&nbsp;&nbsp;&nbsp;<a href=\"../Dashboard.html\">Dashboard</a><span style=\"vertical-align:1px;padding-left:2px;\"><a href=\"../Dashboard.html\" ><img alt=\"Next2a.gif\" src=\"images/5/5b/Next2a.gif\" width=\"10\" height=\"12\"></a></span><br>"

global stuff *= "<span style=\"font-size:17px;color:darkslategray;\">&#34;Hey,<span style=\"vertical-align:12px;\">&nbsp;</span>don't it always seem to go, that you don't know what you've got 'till it's gone....&#34; (Joni Mitchell; <i>how many pictures I have lost by failing to capture them when I saw them!</i>)</span></p>"

fuck = sort(collect(keys(tbl)), by=lowercase)
global stuff *= "\n<div style=\"height:570px;width:550px; overflow:auto; border: 1px solid black;border-radius:6px;margin:16px 0px 0px 6px;padding:2px 0px 2px 36px;background-color:lightyellow;\"><table style=\"font-family:sans-serif;border-collapse:separate;margin:8px 0px 16px 8px;\">" *
            "<tr><td colspan=3 class=\"tar\">" *
        "<span style=\"border:1px solid black;padding:1px 6px 1px 4px;background-color:white;\">" * 
        "QQsbsQQ" * "</span></td></tr>"
for ks in fuck

    ww = tbl[ks]
    uppers[ww[12:12]] += 1
    lowers[ww[13:13]] += 1
    w = unhex[ww[12:12]] * 16 + unhex[ww[13:13]] + 1
    distr[w] += 1

    # <!-- td><span style=\"padding-left:16px;\">[[File:Next2a.gif|link=Media:" * ks * "|Go to Wiki record for image!]]</span></td -->

#                                                                                       <a href=\"images/" * tbl[ks][10:13] * "/" * ks * "\"</a>                                                                                         
    global stuff *= "<tr><td" * (FirstImage ? " style=\"padding-right:38px;\"" : "") * "><a href=\"images/" * tbl[ks][10:13] * "/" * ks * "\">" * tbl[ks][10:13] * "</a></td><td class=\"bib\">" * ks * 
            "</td><td class=\"tar\">--" * ks * "--</td></tr>\n"
    global FirstImage = false
    # println(tbl[ks], " ",ks)
    global D *= "    \"" * ks * "\" => [\"" * tbl[ks][10:10] * "\", \"" * tbl[ks][12:13] * "\"],\n"
end

for r in rejects
    if r in [".\\WBCount", ".\\WBCount1", ".\\WBKountOut.html", ".\\WBcompare", ".\\WBcompare1"]
        continue
    end
    println("  ", r)
end

println("\n-------")

global ImageCache = Dict{String, Int32}()
global ict = 0
global failures = []
cd("../")                # This shit makes no sense to me, so I cheated. GODDAMNED RIGHT!

try
    for (root, dirs, files) in walkdir("./w/")
        for file in files
            x = joinpath(root, file) # path to files
            if !contains(x, "images")
                continue
            end
            z = replace(x, "\\" => "/")
            global ImageCache[z[3 : length(z)]] = 0
            sz = "       " * string(stat("/ROM/BO/" * z).size)
            sizesz = length(sz)
            push!(Biggies, sz[sizesz - 7:sizesz] * "  " *  z[17:length(z)])
            global ict += 1
        end
    end
    global errId = 1
    a = readdir()
    global errId = 2
    for itm in a
        if findfirst(".html", itm) == nothing || itm in ignoreds
            continue
        end
        global item = itm
        global errId = 4
        txt = RRead(item, "clean")

        txt = replace(txt, r"url\('?([^')]+)'?\)" => s" src=\"\1\" ")  # kludge up backgraound images

        images = findall(r" (src|href)=\"[^\"]+", txt)
        for i = 1 : length(images)
            str0 = txt[images[i]]
            if !contains(str0, "/w/images/")
                if length(str0) >= 10 && str0[1:10] == " href=\"w/i"
                    str0 = replace(str0, " href=\"" => " href=\"./", count = 1)
                elseif length(str0) >= 9 && str0[1:9] == " src=\"w/i"
                    str0 = replace(str0, " src=\"" => " src=\"./", count = 1)
                else
                    continue
                end                
            end
            str1 = replace(str0, "%27" => "'")
            off = findfirst("\"", str0)
            str = str1[(off[1] + 3):length(str1)]

            if haskey(ImageCache, str)
                global ImageCache[str] += 1
            elseif !isfile(str)
                strd = "./" * str[1:13]
                if !isdir(strd)
                    mkdir(strd)
                    println("  ", strd)
                end
                println("?MISSING: ", str)
            else
                println("?GODKNOWSWHAT: ", str)               
            end
        end
    end
    
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("\n      Failure: ", typeof(ex), ".\n", s);
    #exit(16)
    push!(failures, item)
    return 0
end

global unused = ""
global unusedPfx = ""
global Uct = 0
ks = keys(ImageCache)
global ReverseImages = Dict{Int32, Array{String}}()
global bigsum = 0
global ones = 0
for k in ks
    global TOTSZ += stat(k).size 
    if ImageCache[k] == 0
        global unused *= unusedPfx * "\"" * k * "\""
        global unusedPfx = ", "
        global Uct += 1
    else
        kn = ImageCache[k]
        kkX = k[15:length(k)]

        if k[15:length(k)] in TrivialImages
            global trivials += ImageCache[k]
        end
        global stuff = replace(stuff, "--" * kkX * "--" => string(kn), count=1)
        global bigsum += kn
        if kn == 1
            global ones += 1
        end
        if !(kkX in ["Prev2a.gif", "Next2a.gif", "Spacer.gif", "HTML5V.png", 
                    "GarbageCan.gif", "K2.gif", "Buttocks.jpg", "United_states.gif", "WDSG.gif"]) 
            if haskey(ReverseImages, kn)
                push!(ReverseImages[kn], kkX)  #    ReverseImages[kn] *= ", " * "\"" * kkX * "\""
            else
                global ReverseImages[kn] = [kkX]    #   "\"" * kkX * "\""
            end
        end
    end
end

global tot = 0
print("\nuppers: ")
for z in ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
    global tot += uppers[z]
    print(" " * string(uppers[z]))
    if z in ["7", "f"]
        print(" " * HI_YELLOW * string(tot) * HI_END * " ")
        global tot = 0
    end
end
println("\n")
global tot = 0 
print("lowers: ")
for z in ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
    global tot += lowers[z]
    print(" " * string(lowers[z]))
    if z in ["7", "f"]
        print(" " * HI_YELLOW * string(tot) * HI_END * " ")
        global tot = 0
    end
end
println("\n")


print("Going to save ./WBKountOut.html : (" * pwd() * ")\n")
#global q = open("w/WBKountOut.html", "w") #
qwrite(pre)
sbs = formatFixed(bigsum)

consequentials = formatFixed(bigsum - trivials)
stuff = replace(stuff, "--IMAGES--" => "Celibates: " * string(ones))
stuff = replace(stuff, r"<td class=\"tar\">--[^>]+</td>" => "<td class=\"tar\"><span style=\"font-weight:bold;color:crimson;font-size:x-large;font-family:sans-serif;\">**</span></td>")
qt = stuff * "<tr><td colspan=3 class=\"tar\">" *
        "<span style=\"border:1px solid black;padding:1px 6px 1px 4px;background-color:white;\">" * formatFixed(length(ImageCache)) * " &nbsp;<span style=\"font-weight:bold;\">&Sigma;</span><sup><span style=\"padding-left:1px;\">+</span></sup> " * 
        sbs * "</span></td></tr></table></div>"
fuckedup = replace(qt, "QQsbsQQ" => formatFixed(length(ImageCache) - length(TrivialImages)) * " &nbsp;<span style=\"font-weight:bold;\">&Sigma;</span><sup><span style=\"padding-left:1px;\">-</span></sup> " * consequentials, count = 1)
qwrite(fuckedup)

shitx = sort(collect(keys(ReverseImages)), rev=true)
global nuthin = "[nuthin]"
println(" ")
for i = 1 : length(shitx)
    sq = shitx[i]
    if sq < 12             # min usage count for celebities list
        continue
    end
    z = ""
    zzz = sort(ReverseImages[sq])
    for zz in zzz    #   ReverseImages[sq]
        if length(z) > 0
            z *= ", "
        end
        z *= "\"" * zz * "\""      
    end

    s = string(sq)
    u = "(" * string(length(ReverseImages[sq])) * ")      "    
    println(" " ^ (6 - length(s)) * s, " ", u[1:6], z)
    global nuthin = ""
end

if length(unused) > 0
    print("\n    Unused: " * unused * "  (" * string(Uct) * ")\n\n")
    qwrite("<p style=\"margin-top:24px;\">" * replace(replace(unused, "w/images/" => ""), " " => "&nbsp; ") * "</p>")
end

qwrite(post)
#global q = open("w/WBKountOut.html", "w")

Q = replace(Q, "NancyTheBitch.jpg</span></td>" => 
            "NancyTheBitch.jpg</span> (<span style=\"font-style:italic;color:black;vertical-align:-1px;\">~Melva</span>)</td>", count=1)
Q = replace(Q, "FirstSteps.jpg</span></td>" => 
            "FirstSteps.jpg</span> (<span style=\"font-style:italic;color:black;vertical-align:-1px;\">Modified</span>)</td>", count=1)
Q = replace(Q, "Giphy.gif</span></td>" => 
            "Giphy.gif</span> (<span style=\"font-style:italic;color:black;vertical-align:-1px;\">Animated</span>)</td>", count=1)


sQsum = formatFixed(Qsum)
STOTSZ = formatFixed(TOTSZ)

#write(q, replace(Q, "--S,Z--" => "<span style=\"color:gray;\">DDD" * sQsum * "   " * STOTSZ * "</span>", count = 1))
#close(q)
println("\n./WBKountOut.html saved: " * sQsum * "    " * APtS_ET)

if nuthin != ""
    println("    " * nuthin)
end

global shi = []
for s = 1:20
    append!(shi,0)
end

global crap = ""
global crap_HTML = ""
for i = 1 : length(distr)
    if i % 32 == 1
        global crap *= " "
        global crap_HTML *= "&nbsp;"
        if i % 64 == 1
            global crap *= "\n   "
            global crap_HTML *= "<br>"
        end
    end
    distri = distr[i]
    global shi[distri + 1] += 1 
    global crap *= HILITE_TOHEX[distri]
    if distri > 9
        global D10Plus += 1
    end
    DISTR[distri] += 1
    if distri == 0
        global crap_HTML *= "<span style=\"font-weight:bold;color:mediumblue;background-color:ghostwhite;padding:1px 0px 1px 0px;\">.</span>"
    elseif distri < 10
        global crap_HTML *= string(distri)
    else
        global crap_HTML *= "<span style=\"font-weight:bold;color:mediumblue;background-color:ghostwhite;padding:1px 0px 1px 0px;\">" * "ABCDEF"[distri-9:distri-9] * "</span>"
    end
end

global crap_HTML *= "&nbsp;&nbsp;" * string(D10Plus)
 
global mulch = 0
for i = 1: length(shi)
    global mulch += (i - 1) * shi[i]
    if shi[i] != 0
        global shi[i] = [i - 1, shi[i], mulch]
    end
end
for i = 1 : length(shi)
    if shi[length(shi)] != 0
        break
    end
    global shi = copy(shi)[1:length(shi) - 1]
end 

global shidt = 0
global shid = []

for i = 2 : length(shi)
    if shi[i] == 0
        append!(shid, 0)
        continue
    end
    sh = shi[i][2]    #  * (i - 1)
    append!(shid, sh) #  - shi[i - 1][3])
    global shidt += sh
end
tots = []
for itm in shi
    push!(tots, itm[3])
end

#SHID = open("w/SHID", "w")
#write(SHID, "global SHID = " * string(tots))
#close(SHID)
global shidd = []
global dnom = shi[length(shi)][3]
for i = 1 : length(shi)
    push!(shidd, replace(string((shi[i][3]/dnom) * 100 + 0.005) * "0000", r"\.([0-9]{2})[0-9]+" => s".\1") * "%")
end
println(crap * "  " * string(D10Plus) , "\n\n", shi, " ", shidt, "\n\n", replace(string(shidd), "\"" => ""), " " * string(length(shidd) - 1))

global distrBars = ""
for i = 0 : 12
    si = "   " * string(i)
    lensi = length(si)
    si = replace(si[lensi - 2 : lensi], " " => "&nbsp;")
    global distrBars *= si * "   " * ("*" ^ DISTR[i]) * "<br>"
end


Q = replace(Q, "XXXX" => crap_HTML)
Q = replace(Q, "XYXY" => distrBars)

q = open("w/WBKountOut.html", "w")
write(q, replace(Q, "--S,Z--" => "<span style=\"color:gray;\">" * sQsum * "&nbsp; " * STOTSZ * "</span>", count = 1))
close(q)

global D *= ")\n\nglobal DICT_VERSION = \"WBCount v" * version * " (D:001).\"\n\n"
global D *= "global MISSING = [\"MISSING_1\", \"MISSING_2\"]\n\n"
global D *= "function pushD(ky, itm)\n"
global D *= "    r = get!(D, ky, MISSING)\n"
global D *= "    if r == MISSING\n"
global D *= "        return(r)\n"
global D *= "    end\n"                
global D *= "    return(push!(r, itm))\n"
global D *= "end\n\n"
global D *= "function appendD(ky, itm...)\n"
global D *= "    r = get!(D, ky, MISSING)\n"
global D *= "    if r == MISSING\n"
global D *= "        return(r)\n"
global D *= "    end\n"                
global D *= "    return(append!(r, itm...))\n"
global D *= "end\n\n"
global D *= "function getD(ky, ksub)\n"
global D *= "    a = get!(D, ky, MISSING)\n"
global D *= "    if a == MISSING\n"
global D *= "        return(MISSING)\n"
global D *= "    end\n"
global D *= "    if ksub > length(a) || ksub < 1\n"
global D *= "        return(MISSING)\n"
global D *= "    end\n"
global D *= "    return a[ksub]\n"
global D *= "end\n\n"
global D *= "function getD(ky)\n"
global D *= "    return(get!(D, ky, MISSING))\n"
global D *= "end\n\n"
global D *= "global DCOLOR1 = HI_RED * \"****** \"\n"
global D *= "global DCOLOR2 = HI_END\n"
global D *= "function addD(ky, val)\n"
global D *= "    if typeof(val) != Vector{String} || length(val) != 2 || typeof(val[1]) != String ||\n"
global D *= "                typeof(val[2]) != String\n"
global D *= "        throw(ArgumentError(DCOLOR1 * \"Bad argument: \" * string(val) * DCOLOR2))\n"
global D *= "    end\n"
global D *= "    if typeof(ky) != String\n"
global D *= "        throw(ArgumentError(DCOLOR1 * \"Bad key: \" * string(ky) * DCOLOR2))\n"
global D *= "    end\n"
global D *= "    if getD(ky) != MISSING\n"
global D *= "        throw(ArgumentError(DCOLOR1 * \"Exists: \" * string(ky) * DCOLOR2))\n"
global D *= "    end\n"
global D *= "    D[ky] = val\n"
global D *= "    return(D[ky])\n"
global D *= "end\n"

d = pwd() * "\\w\\DICT"
a = open(d, "w")
write(a, D)
close(a)

a = open("w/BIG", "w")
b = sort(Biggies, rev=true)[1:24]
for c in b
    write(a, c * "\n")
end
close(a)


*---- "WBSearch"

include("WBInclusions")

APFS = "209" # 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:'|' ] v" * 
            APFS * "\n\n            RegEx_string  [before(", PRE, ") after(", POST, ")]  [case-sensitive?]")
    exit(0)
end

for itm in ["%%1%" => "^", 
            "%%2%" => ">", 
            "%%3%" => "&", 
            "%%4%" => "|"]
    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:'|' ]</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:'|' ]   " * 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:'&' ]   " * 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())

*---- "WBMap"

APFS = "030" # WBMap:APFS
global version = APFS

include("WBInclusions")

mutable struct Foo
   links::Array{String}
   count::Int32
end
global NONEXISTENT = Foo(["NONEXISTENT"],0)

global allFiles = Dict{String, Foo}()

global excludeds = ["XXXTree.html", "XXXRTree.html", 
            "XXXXTree.html", "IndexOfSubjects.html", "Images.html"]   # "NYNYT.html"] 
global lim = 0
global totLinks = 0
global totExtLinks = 0
global totFiles = 1
global bottomLevel = []
global atLevels = [[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],
            [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],
            [0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
global totItems = 1
global ignoreds = [
    "JUNK.html",
    "JUNK2.html",
    "JUNK6.html",
    "JUNK7.html",
    "JUNK10.html"
]

try
    global errId = 1
    a = readdir()
    global errId = 2
    for itm in a
        if findfirst(".html", itm) == nothing || itm in ignoreds   #     || itm == "JSource.html"
            continue
        end
        global totFiles += 1
        global errId = 3
        sres = RRead(itm, "clean")       
        x = findall(r" href=\"[a-zA-Z0-9\-_]+!?\.html", sres)

        global totLinks += length(x)
        global totExtLinks += length(findall(r" href=\"https?://", sres))

        if itm in excludeds
            continue
        end

        y = []
        for z in x
            w = sres[z]
            w = w[8:length(w)]
            if w in y || w == itm
                 continue
            end
            push!(y, w)
        end
        allFiles[itm] = Foo(sort(y), 0)
    end
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    println("\n      Failure[" * string(errId) * "]: ", typeof(ex), ".\n", s);
    exit(16)
end
println("allFiles: " , length(allFiles))
SEEDFILE = length(ARGS) > 0 ? ARGS[1] : "index"

allKeys = sort(collect(keys(allFiles)))
if !(SEEDFILE * ".html" in allKeys)
    println("\n Root file does not exist: \"" * SEEDFILE * "\".")
    exit(16)
end

allFiles[SEEDFILE * ".html"].count = 1

global iterations = 0
while iterations < 20
    local allFiles_NEW = Dict{String, Foo}()
    for Key in allKeys
        allFiles_NEW[Key] = Foo(copy(allFiles[Key].links),allFiles[Key].count )
    end
    global iterations += 1
    if iterations > 18
        println("Overflow!")
        exit(16)
    end
    local thisLevel = []
    local nextLevel = []
    local addedInNextLevel = []        
    for Key in allKeys
        if allFiles[Key].count == 1
            push!(thisLevel, Key)
            push!(nextLevel, Key)
            for itm in allFiles[Key].links
                if itm in excludeds
                    continue
                end
                if get!(allFiles,itm,NONEXISTENT) == NONEXISTENT
                    println("Key error: \"" * Key * "\" > \"" * itm * "\"")
                    exit(16)
                end

                if allFiles_NEW[itm].count == 0
                    allFiles_NEW[itm].count = 1
                    push!(addedInNextLevel, itm)
                    push!(nextLevel, itm)
                    atLevels[iterations + 1][1] += 1
                    global totItems += 1
                    atLevels[iterations + 1][2] = totItems
                    
                end
            end
        end 
    end
    if length(thisLevel) == length(nextLevel)
        break
    end
    global bottomLevel = addedInNextLevel
    global allFiles = allFiles_NEW
end

println("\n  WBMap v" * version * "\n  totFiles: " * string(totFiles) * "           iterations: " * string(iterations) *  
                ".\n  totLinks: " * string(totLinks) * ":" * string(totExtLinks) *
                "    Root: \"" * SEEDFILE * "\"\n")

global THEREST = ""
global disconnecteds = 0
for Key in allKeys
    itm = allFiles[Key]
    if itm.count == 0 && !(Key in ["WWWTree.html","WWWRTree.html","WWWXTree.html"])
        global THEREST *= "\n " * Key
        global disconnecteds += 1
    end
end

global atLevels2 = []
for i in 1 : 100
    if atLevels[i] == [0,0]
        break
    end
    x = [i, atLevels[i][1], atLevels[i][2]]
    push!(atLevels2, x) 
end
tt = atLevels2[length(atLevels2)][3]
ttt = []
for i in 1 : length(atLevels2)
    alti = atLevels2[i]
    #altk = string((alti[3]/tt) * 100 + 0.005) * "0000"
    altj = replace(string((alti[3]/tt) * 100 + 0.005) * "0000", r"\.([0-9]{2})[0-9]+" => s".\1%")
    push!(ttt, [alti[1], alti[2], alti[3], altj])
end
shit = ttt[length(ttt)][3]
ttt = replace(string(ttt), "\"" => "")
ttt = ttt[5:length(ttt) - 1]
ttt = replace(ttt, r"Any\[([0-9]+)," => s"[\1:")
ttt = replace(ttt, r"\[([0-9]+)\: ([0-9]+), ([0-9]+)," => s"\1: [\2, \3.")
ttt = replace(ttt, ".00" => "")
ttt = replace(ttt, r", (5|9|13|17|21|25|29):" => s",\n    \1:")
ttt = replace(ttt, r"(\d+\.?\d*%)" => SubstitutionString(HI_YELLOW * "\\1" * HI_END))
println(" ", iterations, "  " , ttt, "  ", atLevels2[length(atLevels2)][2] + 
            length(excludeds) + disconnecteds, " " , shit, "\n " , THEREST * "\n\n", bottomLevel)

*---- "w/WBcompare"

include("../WBInclusions")
using HTTP
include("DICT")

#pushD("Oh My God", ['G', "G2"])

APFS = "032" # WBcompare:APFS
version = APFS

global CLEANUPLOCALONLY = length(ARGS) == 2 || ARGS[2] == "CLEANUP"
global ANALYZEALL = length(ARGS) == 2 || ARGS[2] == "MICE"
if !CLEANUPLOCALONLY && !ANALYZEALL
    println("No operation specified. No work done. Exiting...."
    exit(16)
end

global big = 150000
global BIGS = []
global t = time();
global PrevTime = 0.0

global URLroot = "https://www.bmccedd.org/w/images/"

println("\n  Remote: " * URLroot * "\n      (Bad: remote -> local len)\n")

global tbl = Array{String}(undef, 2100)
global sz = 0
global totlen = 0

function myPrintln(txt...)
    for t in txt
        write(LOG, string(t))
    end
    write(LOG, "\n")
    println(txt...)
end

function getImage(img)
    global errId = 0
    try
        global errId = 1
        a = HTTP.get(URLroot * img)
        global errId = 2
        ab = a.body
        global errId = 3
        global errId = 4
        fb = RRead("./images/" * img, "raw")
        global errId = 6
        return([ab, fb])
    catch ex
        s = string(ex)  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        myPrintln("\n      Failure[" * string(errId) * "]: ", typeof(ex), ".\n", s);
        #exit(16)
        return nothing
    end
end

global LOG = open("WBC.log", "w")

global others = []

for (root, dirs, files) in walkdir(".")
    for file in files
        x = joinpath(root, file) # path to files
        if !contains(x, "images")
            push!(others,x)
            continue
        end
        global sz += 1
        tbl[sz] = replace(x[10:length(x)], "\\" => "/")
        q = getD(tbl[sz][6:length(tbl[sz])])
# println("----             \"", q, "\"  ", typeof(q))  # God damn strong typing! [string, string, int?] 
        if q == MISSING
            myPrintln("============> Missing from DICT: \"" * tbl[sz] * "\"")
            if CLEANUPLOCALONLY
                rm("images/" * tbl[sz])
            end
            push!(q, 1)
            continue
        end
        push!(q, 0)
    end
end
for itm in keys(D)
    if length(D[itm]) < 3
        myPrintln("============> Missing from local: \"" * itm * "\" \"" * string(D[itm]) * "\"")
    end
end

# Kludge to get rid of dead files in a remote setup

if !ANALYZEALL
    exit(0)
end       

for i = 1 : sz
    tbli = tbl[i]
    sleep(1)
    if i % 50 == 0
        ii = "    " * string(i)
        lenii = length(ii)
        ii = ii[lenii - 4 : lenii]
        NewTime = round(time() - t, digits=4)
        #dt = string(Dates.now())
        #dtx = findfirst('T', dt)
        #noww = dt[1: dtx - 1] * " " * dt[dtx + 1: 19]
        tdiff = replace(string(NewTime - PrevTime), r"\.\d+" => "")
        myPrintln("---- Processed " * ii * " files. " * noww() * " ---- ",
                        NewTime, " (", tdiff, ")")
        global PrevTime = NewTime
    end
    x = getImage(tbli)
    if x == nothing
        continue
    end
    lenx1 = length(x[1])
    lenx2 = length(x[2])
    global totlen += lenx1
    if lenx1 != lenx2 || x[1] != x[2]
        myPrintln("    Bad: " * 
            string(i) * ". " * tbli[1:5] * " " * tbli[6:length(tbli)] * " " * 
                    string(lenx1) * " " * string(lenx2) )
    end
    bigger = max(lenx1, lenx2)
    if bigger >= big
        push!(BIGS, string(bigger) * ":" * tbli)
    end
end

a = join(sort(BIGS, rev=true),"\n")
b = replace(a, ":" => "  ")
b = replace(b, r"( [0-9a-f]/[0-9a-f]{2})/" => s"  \1    ")
z = open("WBIG", "w")
write(z, b * "\n\n" * join(sort(others),"\n"))
close(z)

stotlen = formatFixed(totlen) 

tmt = time() - t
myPrintln("\n" * string(sz) * " files in directories. " * 
            stotlen * " total length. v" * version * "  ",
            string(round(tmt, digits=4)) * " (" * string(round(tmt / 60, digits=3)) * ")\n")

write(LOG, "\n")
close(LOG)

*---- "WBheads"

include("WBInclusions")
using HTTP

APFS = "010" # WBheads:APFS
global versionNr = APFS

global failures = []
global attns = []

txt = RRead("XXXXTree.html", "asis")
urls = findall(r"href=\"[^\"]+", txt)
global ctr = 0;
for urlx in urls
    global item = txt[urlx]
    if !contains(item, "http")
        continue
    end
    global ctr += 1
    global item = item[7 : length(item)]
    try
        print("    ", ctr, ". ", item)
        heads = HTTP.head(item, readtimeout=15)
        sx = string(heads.status)
        sxx = ""
        if sx != "200"
            sxx = "ATTN: "
            push!(attns, item)
        end
        println(" ", sxx, sx)
    catch ex
        s = string(ex)
        println(" **Failed**")  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        push!(failures, (item * " =>\n" * s))
    end
end
println("\nWBheads v", versionNr, ". Count: " , ctr , ".")
println("\n", attns)
println("--------")
global ctr = 0
for f in failures
    global ctr += 1
    println("\n", ctr, " (" ,formatDigits((failures/ctr) * 100, 2) "%)", f)
end
    

*---- "WBW"

include("WBInclusions")
using HTTP
    
global HICOLOR = HI_AQUA
global version = "052"

global downLoadCount = 0
global downLoadLength = 0

if length(ARGS) == 0 || beginswith(ARGS[1], r"[wWpPtT]")

    # Read file "V1" and execute it. This sets variable "V", from which we set V_2
    
    EMP(replace(String(HTTP.get("https://www.bmccedd.org/V1").body), "\n *" => ""))
    global V_2 = V[2]
    
    global doStart = true
    global didSomething = false
    global progressCTR = 0
    
    global findTS = r">\+\d{4}\.\d{2}\.\d{2} v\d{3}"
    
    function doOne(fname, txt, oldRVA)
        cc = "https://www.bmccedd.org/" * fname
        f = open(fname, "w")
        newBody0 = HTTP.get(cc).body
        write(f, newBody0)
        close(f)
        newBody = String(newBody0)
        global downLoadLength += length(newBody)
        global downLoadCount += 1
        allVStamps = findall(findTS, newBody)
        lenAV = length(allVStamps)
        if lenAV != 1 && !(fname == "Experiment.html" && lenAV == 3)        # KLUDGE
            println(hilite(HICOLOR, "Versioning doOne wrong in file:  " * fname))
            exit(16)
        end
        rv = parse(Int32, newBody[allVStamps[lenAV]][15:17])
        newRVA = "0000" * string(rv)
        newRVA = newRVA[length(newRVA) - 3: length(newRVA)]
        v = get(V_2, fname, "----")
        if v == "----"
            println(hilite(HICOLOR, "  doOne In target but not in source: " * fname))
        elseif v != newRVA
            println(hilite(HICOLOR, "  ====> doOne remote not match V_2 for " * fname * ": (" * oldRVA * ") " * newRVA * " ? " * v)) 
        end
        println(txt)

        global didSomething = true
    end
    
    #2022-10-13 16:12    ChangeLog.html
    
    println("\nWBW  v" * version * ". lenV: " * string(length(V_2)) * ".    T/stmp: " * V[1] * "\n")
    
    try
        aLocal = readdir()
        for itm in aLocal
            if findfirst(".html", itm) == nothing || 
                    startswith(itm, r"XXX|JUNK")
                continue
            end
            FileContents = RRead(itm, "asis")
            allVStamps = findall(findTS, FileContents)
            lenAV = length(allVStamps)
            if lenAV != 1 && !(itm == "Experiment.html" && lenAV == 3)        # KLUDGE
                println(hilite(HICOLOR, "Versioning local wrong in file:  " * string(lenAV) * "  " * itm))
                exit(16)
            end
            rv = parse(Int32, FileContents[allVStamps[lenAV]][15:17])
            currentRVA = "0000" * string(rv)
            lenCRVA = length(currentRVA)
            currentRVA = currentRVA[lenCRVA - 3: lenCRVA]
            v = get(V_2, itm, "----")
            if v == "----"
                println(hilite(HICOLOR, "    In target but not in source: " * itm))
            elseif v != currentRVA
                if v > currentRVA
                    doOne(itm, "  Updated  " * currentRVA * " > " * v * "   " * itm, currentRVA)
                else 
                    println(hilite(HICOLOR, "        <<<< \"" * itm * "\" " * v * " < " * currentRVA * " <<<<"))
                end
            end
            delete!(V_2, itm)
        end
        for k in keys(V_2)
            doOne(k, "  Added                  " * k, "n/a")
        end         
    catch ex
        s = string(ex)  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        println(hilite(HICOLOR, "\n      Failure: " * string(typeof(ex)) * ".\n" * s))
        return 16
    end
    if didSomething
        println(" \n     Downloaded: " * formatFixed(downLoadLength) * "  " *
                formatFixed(downLoadCount) * "\n")
    end
end

if length(ARGS) > 0 && !beginswith(ARGS[1], r"[iI]")
    println(hilite(HICOLOR, "Invalid ARGS[1]: \"" * ARGS[1] * "\""))
    exit(16)
end

global doEnd = false
global doStart = true

#   2022-10-02 15:12     w/images/c/cc   SmilingLady.jpg 123

b = split(String(HTTP.get("https://www.bmccedd.org/V2").body), "\n")

println("WBYY  v" * version)
for itm in b
    if length(itm) < 42 || itm[24:32] != "w/images/"
        continue
    end
    try
        d = findlast(" ", itm).start
        c = itm[24:36] * "/" * itm[40:d - 1]
        len = itm[d + 1: length(itm)]
        doit = true
        what = "new " * len
        if isfile(c)
            sz = string(stat(c).size)
            what = (doit = (sz = string(stat(c).size)) != len) == true ? sz * ":" * len : len
        end
        if doit
            c113 = c[1:13]
            if !isdir(c113) && isdir(c[1:10])
                mkdir(c113)
                print(" [ New directory: " * c113 * " ] ")
            end
            cc = "https://www.bmccedd.org/" * c
            if doStart
                println(" ")
                global doStart = false
            end
            print("    " * cc)
            #res = HTTP.get(cc)
            f = open(c, "w")
            write(f, HTTP.get(cc).body)
            close(f)
            println(" Done.  " * what)
            global doEnd = true
        end
    catch ex
        s = string(ex)  
        if length(s) > 200
            s = s[1:200] * "..."
        end
        println(hilite(HICOLOR, "\n      Failure: " * string(typeof(ex)) * ".\n" * s))
        #return 0
    end
end
if doEnd
    println(" ")
end

*---- "WBX"

include("WbInclusions")

global errid = 0
global ct = 0
global totct = 0
if length(ARGS) != 2 || ARGS[2] != "MICE"
    println("ARGS wrong")
    exit(16)
end

global XPUTS = ""

function myPrintln(x)
    write(LOG, x * "\n")
    println(x)
end
global LOG = open("WBXLOG", "w")

global workToDo = [

#    r" ((George( W\.? | Walker )?)?Bush)(, |'s, |'s | )" => 
#    s" <a href=\"../MissonAccomplished.jpg\" style=\"text-decoration:none;\">\1</a>\4",

    "<span class=\"reference-text\"" =>
    "<span"

]

try
    for f in readdir(".")
        lenf = length(f)

# startswith(f, "Quor")  || startswith(f, "Zel") ||

        if !isfile(f) || lenf < 6 || f[lenf - 4 : lenf] != ".html" || 
 
                f in ["XXXTree.html", "XXXRTree.html", "XXXXTree.html", "JUNK.html", "JUNK2.html"]

            #myPrintln("====> Rejected: \"" * f * "\".")
            continue
        end
        fn = f
        global errid = 3
        c = RRead(fn, "asis")
        global errid = 4
        d = c
#--- Change function(s) go after here

        for i = 1 : length(workToDo)
            d = replace(d, workToDo[i])
        end

#--- Change function(s) go before here       
        global totct += 1  
        if c == d
            myPrintln("--Done: " * f * ". Not fixed!")
            continue
        end

        vStamp = findall(r">\+202[0-9]\.[0-1][0-9]\.[0-3][0-9] v[0-9]{3}<", d)
        if length(vStamp) != 1
            myPrintln("*** Versioning not avaliable for this file: " * string(length(vStamp)) * ": " * f * " ***\n")
        else 
            v = d[vStamp[1]]            
            w = tryparse(Int32, v[15:17])
            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 = d
            global d = replace(d, v => z, count = 1)
            if d == q
                myPrintln("God knows qhat fucked up: " * f)
            end
        end
        global ct += 1        
        global errid = 5
        b = open(fn, "w")
        global errid = 6
        write(b, d)
        global errid = 7
        close(b)
        myPrintln("++Done: " * f * " Fixed.")
        global XPUTS *= "put " * f * "\n"
    end
    global errid = 8
catch ex
    s = string(ex)  
    if length(s) > 200
        s = s[1:200] * "..."
    end
    myPrintln("\n  Failure[" * string(errid) * "]: " * string(typeof(ex)) * ".\n" * s)
    exit(16)
end
close(LOG)

# Write file of a "put " statement for each changed file
a = open("XPUTS", "w")
write(a, XPUTS)
close(a)

tct = "\n+" * replace(replace(noww(), "-" => "."), " " => "+")[1:16] * ". WBX Total: " * string(ct) * "/" * string(totct)
println(tct, "\n")

global strs = open("JUNK4.txt", "a")
write(strs, "\n" * tct * "\n") 
for i = 1 : length(workToDo)
    write(strs, string(workToDo[i]) * "\n")
end
close(strs)


*---- "WBY"

DIR = "/ROM/BO/"

include(DIR * "WBInclusions")
include(DIR * "w/DICT")

if length(ARGS) > 0
    global lim = tryparse(Int32,ARGS[1])
else
    global lim = 20
end

global OUTPUTFILE = DIR * "V2"

global FILE = open(OUTPUTFILE, "w")
function myPrintln(x)
    println(x)
    write(FILE, x * "\n")
end 

global k = keys(D)
global arry = []
global prv = "xxxxxxxxxxxxxx"

for ky in k
    if findfirst(" ", ky) != nothing || findfirst(r"\.(jpg|gif|png)$", ky) == nothing 
        println("\nDICT ERROR! \"" * ky * "\"")
        exit(16)
    end
    x = D[ky]
    y = DIR * "w/images/" * x[1] * "/" * x[2] * "/" * ky
    z = string(Dates.unix2datetime(mtime(y)))
    push!(arry, "  " * z[1:10] * " " * z[12:16] * "     w/images/" * x[1] * "/" * x[2] * "   " * ky)
end
myPrintln("\n" * string(length(D)) * "  WBY: ." * OUTPUTFILE * "      " * APtS_ET * "\n")
arry2 = sort(arry, rev=true)
for i = 1 : min(length(arry2),lim)
    ii = arry2[i]
    gkw = DIR * ii[24:36] * "/" * ii[40:length(arry2[i])]
    lenk = string(stat(gkw).size)
    if ii[1:7] == prv[1:7]
        if ii[1:10] == prv[1:10]
            if ii[1:13] == prv[1:13]
                myPrintln( "             " * ii[14:length(arry2[i])] * " " * lenk)
                continue
            end
            myPrintln( "          " * ii[11:length(arry2[i])] * " " * lenk)
            global prv = ii[1:13]
            continue
        end
        global prv = ii[1:13]
        myPrintln( "       " * ii[8:length(arry2[i])] * " " * lenk)
        continue
    end
    global prv = ii[1:13]
    myPrintln(arry2[i] * " " * lenk)   
end
close(FILE)

*---- "WBZ"

include("WBInclusions")
include("w/DICT")
#using WAV
#y, fs = wavread(raw"C:\Windows\Media\Ring01.wav")
#wavplay(y, fs)


APFS = "0168" # WBZ:APFS
global versionNr = APFS

include("WBInclusions")

global hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']

global xx = []
global usedDirectories = fill!(Array{Bool}(undef,256),false)
global assholes = 0
println("\n WBZ v" * versionNr * ".  ARGS ", ARGS, "    ", APtS_ET)
if length(ARGS) == 0       
    txt = RRead("w/WBKountOut.html", "asis")
    sall = findall(r"href=\"images[^\"]+\"", txt)
    for i = 1 : length(sall)
        sa = sall[i]
        push!(xx,txt[sa.start + 18 : sa.stop - 1])
    end
elseif length(ARGS) == 1 
    global xx = split(replace(ARGS[1]," " => ""), ',')
elseif length(ARGS) > 0
    global xx = ARGS
end
shit = []
for s = 1:256
    append!(shit,0)
end
global first = "" # "\n"
for x in xx
    #y = collect(x)
    #leny = length(y)
    #Ltot = 0         # leny
    #for i = 1 : leny
    #    Ltot += Int32(y[i])
    #end
    Ltot = sum(map(Int32, collect(x)))    # Fun!
    ttt = Ltot % 256
    shit[ttt + 1] += 1
    v = Int32(ttt % 16)
    w = Int32((ttt - v) / 16)
    if usedDirectories[ttt + 1] == false
        global assholes += 1;
        usedDirectories[ttt + 1] = true
    end

    if length(ARGS) > 0
        wplus1 = w + 1
        lenD = length(readdir("w/images/" * hex[wplus1] * "/" * hex[wplus1] * hex[v + 1] * "/"))
        println("\n", first * "    " * hex[wplus1] * "/" * hex[wplus1] * hex[v + 1] * "    " * x *
                        " (" , lenD, ")  " , 
                        (getD(x) == MISSING ? "" : HI_RED * "   Already used!" * HI_END))
        global first = ""
    end
end

global shi = []
global shid = []
for s = 1:20
    append!(shi,0)
end


global crap = ""
for i = 1 : length(shit)
    if i % 32 == 1
        global crap *= " "
        if i % 64 == 1
            global crap *= "\n   "
        end
    end
    shi[shit[i] + 1] += 1
    global crap *= HILITE_TOHEX[shit[i]]
end

shiORIG = copy(shi)
global mulch = 0
for i = 1: length(shi)
    global mulch += (i - 1) * shi[i]
    if shi[i] != 0
        global shi[i] = [i - 1, shi[i], mulch]
    end
end    
for i = 1 : length(shi)
    if shi[length(shi)] != 0
        break
    end
    global shi = copy(shi)[1:length(shi) - 1]
end
global shidt = 0
for i = 2 : length(shi)
    if shi[i] == 0
        append!(shid, 0)
        continue
    end
    sh = shi[i][2] # (i - 1)
    append!(shid, sh) #  - shi[i - 1][3])
    global shidt += sh
end
xxx = shi
qqqqq = shi[length(shi)][3]

#println("\n\n", shi, "\n")
ss1 = SubstitutionString("[\\1, " * HI_YELLOW * "\\2" * HI_END)   #       s" * "\\1" * t*)
ss2 = SubstitutionString(" " * HI_RED * "\\1" * HI_END * "]]")

println(crap * 
    "  " * string(sum(shiORIG[11 : length(shiORIG)])) * "\n\n" * 
    replace(replace(replace(replace(replace(replace(replace(string(shi), r"\[(\d), (\d+)" => ss1), r"1([01234]), (\d+), " => s"1\1, YY1\2YY2, "), r" (\d+)]]" => ss2), "YY1" => HI_AQUA), "YY2" => HI_END), "], [7," => "],\n    [7,"), "], [12," => "],\n    [12,") *
     "]\n\n    " *  
    replace(replace(replace(string(map(x -> x < 10 ? string(shid[x]) : ("X" * string(shid[x]) * "Y"), Array(1:length(shid)))), "\"" => ""), "X" => HI_AQUA), "Y" => HI_END) *
     " " * 
     string(shidt) * 
     " " * 
     string(assholes)
)

if length(ARGS) != 0
    return(0)
end

for i = 1:length(xxx)
    if typeof(xxx[i]) == Vector{Int64}
        xxx[i] = (i - 1) * xxx[i][2]
    end
end
println(" ",xxx, "  ", formatDecimal(qqqqq /  assholes, 3))


*---- "WB_Transforms"

global TVersion = "122"    # ******** It is IMPERATIVE to use "\|" not "|" in the search strings! ********
global WB_TODAY = replace(noww()[1:10], "-" => ".")    # Throwaway like for WB info display to work right

global Transforms = [

    "{{APtS_ET}}" =>
             APtS_ET,

    "{{TOP}}" =>
                "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n" *
                "<link rel=\"stylesheet\" type=\"text/css\" href=\"w/css/WBmiracle.css\">\n" *
                "<meta charset=\"UTF-8\">\n<title>Dona nobis pacem | " * 
                        replace(ThisFile, ".html" => "") *     # This line has to be filtered out in "j WB"
                "</title>\n</head>\n" *
                "<body style=\"background-color:white;\">\n" *
                "<div style=\"padding:2px 0px 0px 6px;\"><a href=\"welcome.html\" style=\"text-decoration:none;\" class=\"rWel\"><img src=\"w/images/1/12/Prev2a.gif\" alt=\"Previous\" class=\"wRel2\">Welcome</a></div>\n" *
                "<div class=\"read600\">",

    r"{{FOOTER\|Buttocks\|(\d+)}}" =>
                s"{{FOOTER|Buttocks|\1|210}}",

    r"{{FOOTER\|WDSG\|(\d+)}}" =>
                s"{{FOOTER|WDSG|\1|140}}",

    r"{{FOOTER\|K2\|(\d+)}}" =>
                s"{{FOOTER|K2|\1|90}}",

    r"{{FOOTER\|(WDSG|Buttocks|K2)\|(\d+)\|(\d+)}}" =>
                s"<table\n    class=\"tbl600\" style=\"margin-top:\2px;\">\n<tr>\n<td style=\"vertical-align:top;\">{{\1|0|0}}</td>\n<td style=\"width:100%;\">&nbsp;</td>\n<td style=\"vertical-align:top;text-align:right;padding-top:\3px;\"><table class=\"tbl\" style=\"margin:0;\"><tr><td style=\"vertical-align:top;padding:7px 0px 0px 0px;\"><a href=\"https://validator.w3.org/\" title=\"This page validated as HTML 5\"><img src=\"w/images/c/ca/HTML5V.png\" alt=\"This page has been validated as HTML 5.\" style=\"width:80px;height:29px;padding:0;\"></a></td><td><a href=\"https://html.com/html5/\"><img src=\"w/images/d/dd/HTML5.png\" title=\"HTML5. I (BMcC) have cleaned this page of at least most MediaWiki residue.\" style=\"height:50px;width:50px;padding:0px 0px 0px 7px;\"></a></td></tr></table></td>\n</tr></table>",

    "{{BOTTOM}}" =>
                "<div class=\"read600\"><p style=\"clear:both;font-size:16px;\" title=\"bradmcc@bmccedd.org | https://www.bmccedd.org | " * ThisFile * "\">&nbsp;</p></div></body></html>",

    r"{{WDSG\|([0-9]+)\|([0-9]+)}}" =>
                s"<div style=\"width:275px;margin:\1px 0px \2px 0px;\"><a href=\"EndOfEarth.html\" title=\"Where deleted stuff goes....\"><img src=\"w/images/0/04/WDSG.gif\" alt=\"Where deleted stuff goes....\" style=\"width:275px;height:166px;\"></a></div>",

    r"{{Buttocks\|([0-9]+)\|([0-9]+)}}" =>
                s"<div class=\"thumb tleft\"><div class=\"thumbinner\" style=\"width:248px;margin:\1px 0px \2px 0px;\"><a href=\"EndOfEarth.html\" title=\"EndOfEarth\"><img src=\"w/images/0/08/Buttocks.jpg\" alt=\"\" style=\"width:246px;height:162px;\" class=\"thumbimage\"></a>  <div class=\"thumbcaption\" style=\"font-size:18px;line-height:22px;padding-bottom:1px;\">Unfortunate for themself, the person who lacks one; unfortunate for others, the person that <a href=\"Petty.html\" title=\"Asshole!\">is</a> one. <span style=\"color:darkred;font-weight:bold;\">Don't be an a**hole!</span></div></div></div>",

    r"{{K2\|([0-9]+)\|([0-9]+)}}" =>
                s"<div style=\"width:124px;text-align:center;padding:0px;\"><div style=\"display:inline-block;width:124px;height:86px;\"><a href=\"BRADFORD.html\" title=\"BMcC signature seal stamp. Modelled on 18th century messenger&#39;s letter box in collection of Suntory Museum, Tokyo. Japanese write poems and prayers on slips of paper which they tie into knots like this shape although with longer legs. Prayers are often tied to branches of trees which can look like they are covered with snow. &quot;Symbol of a symbol, image of an image, emerging from the destiny that is sinking into darkness....&quot; (H. Broch, &quot;The Sleepwalkers&quot;, p.648) Always remember. Add value. (This image created not later than 21 May 2003)\"><img src=\"w/images/1/1f/K2.gif\" alt=\"BMcC signature seal stamp. Modelled on 18th century messenger&#39;s letter box in collection of Suntory Museum, Tokyo. Japanese write poems and prayers on slips of paper which they tie into knots like this shape although with longer legs. Prayers are often tied to branches of trees which can look like they are covered with snow. &quot;Symbol of a symbol, image of an image, emerging from the destiny that is sinking into darkness....&quot; (H. Broch, &quot;The Sleepwalkers&quot;, p.648) Always remember. Add value. (This image created not later than 21 May 2003)\" style=\"width:124px;height:86px;margin-bottom:-5px;\"></a></div><div style=\"color:lightslategray;font-style:italic;font-size:12px;font-family:serif;display:inline-block;padding-top:0px;\">Invenit et fecit</div></div>",

    r"{{NBB\|([^}]+)}}" =>
                s"<!-- NBB: {{TODAY|0}}. \1 -->",

    "{{TODAY}}" => 
                "<span style=\"font-weight:bold;font-style:italic;color:blue;\">{{TODAY|0}}</span>",

# The "=>" in the following line was causing WB info display to fuck up when two lines 
    r"{{TODAY\|[^}]+}}" => 
                "+" * WB_TODAY,

    r"{{DATE\|([\-+])(\d{4})[|.](\d{2})[|.](\d{2})}}" =>     ##   (Parentheses not included)#
                s"<a href=\"Date.html\" style=\"text-decoration:none;\" title=\"Date\"><span style=\"font-style:italic;color:blue;font-weight:bold;\">\1\2.\3.\4</span></a>",

    r"{{TSV\|([0-9.]+)\|([0-9]+)\|([0-9]+)\|([0-9]+)}}" =>     ##   TimeStamp + Version#
                 s"<div style=\"margin-top:\3px;margin-bottom:\4px;font-size:smaller;text-align: right; direction: ltr; margin-left: 1em;\"><span style=\"color:darkslategray;\" title=\"Last change date\"><a href=\"Date.html\" style=\"text-decoration:none;\">+\1 v\2</a></span><br>\n<span style=\"white-space:nowrap;\"><span style=\"font-size:21px;color:white;\">&nbsp;</span><span style=\"vertical-align:0px;\"><a href=\"welcome.html#TOC\" title=\"welcome#TOC\"><img src=\"w/images/1/12/Prev2a.gif\" alt=\"Previous\" style=\"width:10px; height:12px\"></a></span><a href=\"welcome.html#TOC\" title=\"welcome\" class=\"rW\">Return to Table of contents<span style=\"padding-left:1px;\">&#9496;</span></a></span></div>",

    "{{ORELSE}}" =>
            "<span style=\"font-family:sans-serif;border:3px solid darkred;font-weight:bold;padding:1px 2px 0px 2px;color:darkred;background-color:yellow;\"><a style=\"text-decoration:none;\" href=\"Petty.html\" title=\"Petty\"><span style=\"font-weight:bold;font-family:sans-serif;\"><span style=\"vertical-align:-1px;font-size:larger;\">O</span>r&nbsp;else!</span></a></span>",

    "{{FITB}}" =>
            "&#91;<a href=\"Glossary.html#FITB\" title=\"Glossary\" style=\"text-decoration:none;\"><span title=\"This space reserved for describing one or more human beings or other noemata &#91;objects of consciousness&#93; so bad that there either are no words that can describe them, or else only words not fit to print. These referent(s) should never have existed, but having had that misfortune, either shape up or else go back swiftly whence they came.\">fill in the blank</span></a>]",

    "{{RIP}}" =>
             "<a href=\"Scheissestuckwelt.html\" style=\"font-family:sans-serif;font-weight:bold;font-size:larger;vertical-align:2px;padding-left:3px;\" title=\"RIP: Rot in place\">&#9980;</a>",

    r"{{I\|([^{}]+)}}" =>
             s"<span style=\"font-style:italic;\">\1</span>",

    r"{{B\|([^{}]+)}}" =>
             s"<span style=\"font-weight:bold;\">\1</span>",

    r"{{(IB|BI)\|([^{}]+)}}" =>          ##                       (IB|BI)#
             s"<span style=\"font-style:italic;font-weight:bold;\">\2</span>",

    "{{AKA}}" =>          ##                                (Includes terminating colon (':'))#
             "<span style=\"font-style:italic;\">aka</span>:",

    r"{{([Ii])([Ee])}}" =>    ##                           (Includes terminating colon (':'))#
             s"<span style=\"font-style:italic;\">\1.\2.</span>:",

    r"{{([Ee])([Gg])}}" =>    ##                           (Includes terminating colon (':'))#
             s"<span style=\"font-style:italic;\">\1.\2.</span>:",

    r"{{([Rr])ef}}" =>
             s"<span style=\"font-style:italic;\">\1ef.</span>:",

#    r"{{P\|(.)}}" =>
#            s"<p><span style=\"font-size:larger;\">\1</span>",

#    r"{{PX\|(.)}}" =>
#            s"<p><span style=\"font-size:x-large;font-weight:bold;\">\1</span>",

    r"{{NBSP\|([-]?\d\d?)}}" =>
            s"<span style=\"vertical-align:\1px;\">&nbsp;</span>",

# Watch out! 
#   "{{HOTLINK|{{imagename}}|text}}" works, but it has to pass thru WB twice. the 1st pass resolves to:
#   "<span class="aSharp"><a href="{{imagename}}" style="text-decoration:none;">text</a></span>"
#   The 2nd pass resolves the image URL. Jesus Christ, but it does work. 

    r"{{HOTLINK\|([^|]+)\|([^}]+)}}" =>##                This tag may need to pass thru WB twice#
            s"<span class=\"aSharp\"><a href=\"\1\" style=\"text-decoration:none;\">\2</a></span>",

    r"{{CROSSLINK\|([^|]+)\|([^}]+)}}" =>
            s"<a href=\"\1\" style=\"text-decoration:none;font-family:sans-serif;font-weight:bold;color:darkred;padding:0px 2px 0px 2px;vertical-align:-3px;font-size:larger;\" title=\"\2\"><span style=\"font-size:larger;\">*</span></a>", 

    "{{DOTS}}" => 
             "<p style=\"text-align:center;\">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*</p>",

    r"{{TC\|([^\|}]+)\|([^}]+)}}" =>     ##                    Text blurb with hyperlink#
            s"<a href=\"\2\" style=\"text-decoration:none;\">{{TC|\1}}</a>",

    r"{{TC\|([^}]+)}}" =>
            s"<img src=\"w/images/6/60/TextBubble.jpg\" alt=\"&#91; \1 &#93;\" title=\"&#91; \1 &#93;\" style=\"vertical-align:-1px;padding:0px 1px 0px 1px;\">",

    r"{{HTML5V\|([0-9]+)\|([0-9]+)}}" =>
                s"<div id=\"_BRM5V\" style=\"width:600px;margin:\1px 0px 0px \2px;text-align:right;\"><div class=\"floatright\"><a href=\"https://validator.w3.org/\" title=\"This page validated as HTML 5\" rel=\"nofollow\"><img src=\"w/images/c/ca/HTML5V.png\" alt=\"This page is validated HTML 5\" style=\"width:80px;height:29px;\"></a></div></div>",

    r"{{HTML5\|(\d+)}}" =>
                s"<table style=\"margin:\1px 0px 0px 0px;text-align:right;\" class=\"tbl\"><tr><td style=\"width:100%\">&nbsp;</td><td style=\"vertical-align:top;padding-top:7px;\"><a href=\"https://validator.w3.org/\" title=\"This page has been validated as HTML 5.\"><img src=\"w/images/c/ca/HTML5V.png\" alt=\"This page has been validated as HTML 5.\" style=\"width:80px;height:29px;\"></a></td><td><a href=\"https://html.com/html5/\"><img src=\"w/images/d/dd/HTML5.png\" title=\"HTML5. I (BMcC) have cleaned this page of at least most MediaWiki residue.\" style=\"height:50px;width:50px;padding:0px 0px 0px 7px;\"></a></td></tr></table>",

    "{{IBM}}" =>
            "<a href=\"IBM.html\" title=\"IBM\" style=\"text-decoration:none;\"><span title=\"THINK\" style=\"font-weight:bold;color:blue;\">IBM</span></a>",

    "{{StP}}" =>
            "St. Paul's Illiberal Day Carcel for pubsecent male virgins <a href=\"w/images/1/1d/WhatJocksGet2.gif\" title=\"Athletes get don't-ask-don't-tell sex.\" style=\"text-decoration:none\"><span style=\"font-style:italic;\">except-for-omerta-sanitary-services-for-jocks</span></a>",

    "{{THINK}}" =>
            "<a href=\"IBM.html\" style=\"text-decoration:none;\"><span style=\"background-color:#E0E0E0;padding:1px 4px 0px 3px;font-weight:bold;border:1px solid #585858;border-radius:3px;\" title=\"THINK\">THINK</span></a>",

    "{{IRC}}" =>  ##                                Int'l Rescue Commitee#
            "<a href=\"https://help.rescue.org\" title=\"Help the refugees Mr. Zelensky&#39;s war is producing!\"><img src=\"w/images/e/eb/Irc-logo.png\" alt=\"Help the refugees Mr. Zelensky&#39;s war is producing!\" style=\"width:112px;height:149px;\"></a>",

    r"{{BMcC}}" =>
                "<span style=\"font-style:normal;\">&#40;</span>{{BMcC|}}<span style=\"font-style:normal;\">&#41;</span>",

    r"{{BMcC\|[^}]*}}" =>  ##                         (Any parameter value for no perentheses)#
                "<span\n\nstyle=\"white-space:nowrap;\"><a href=\"BRADFORD.html\" title=\"BRADFORD\"><span title=\"&quot;I am who am&quot; (Exodus 3:14). Are you, too, my reader?\">BMcC</span></a><span style=\"font-weight:normal;\"><span style=\"font-style:normal;\">&#91;</span><a href=\"BRADFORD.html\" title=\"BRADFORD\" style=\"text-decoration:none;\"><span style=\"font-weight:normal;font-size:smaller;\" title=\"&quot;I am who am&quot; (Exodus 3:14). Are you, too, my reader?\">18-11-46-503</span></a><span style=\"font-style:normal;\">&#93;</span></span></span>",

    "{{EMAIL}}" =>
             "<span style=\"background-color:lightyellow;color:green;padding:0px 1px 1px 1px;\" title=\"Email me if you, my reader, have thoughts (not pre-judices!) about what I think / feel!\"><a href=\"InFesta.html\" title=\"Email me!\" style=\"text-decoration:none;font-weight:normal;\"><span style=\"color:darkgreen;\">bradmcc@bmccedd.org</span></a></span>",

    "{{BO}}" =>    ##                                 Help protect The American Dream from body odor!#
            "{{BO|Americanism.html}}",

    r"{{BO\|([^}]+)}}" =>
            s"<div class=\"BO\" style=\"border:4px solid darkred;padding:2px 5px 1px 5px;background-color:yellow;color:darkred;\"><a href=\"\1\" title=\"You must say the words: &#34;BODY ODOR!&#34; as an expulsive expletive as if you were suddenly overcome by an enormous involuntary explosive disgusting bowel movement which soiled you and your clothes all over: &#34;BODY ODOR!&#34; Always remember: If a man (woman or other) can't have the right stuff, they can still use the right deodorant!\" style=\"text-decoration:none;font-family:sans-serif;text-align:left;color:darkred;line-height:140%;font-size:17px;\"><span style=\"font-weight:bold;\">BODY&nbsp;ODOR<br>FREE&nbsp;ZONE!</span></a></div>",

    r"{{([Pp])eople}}" =>
             s"<a href=\"Glossary.html#People\">\1eople</a>",

    r"{{([Tt])he([my])}}" =>
             s"<a href=\"Glossary.html#theThem\">\1he\2</a>",

    r"{{([lr])AQUO}}" =>
            s"<span class=\"\1aquo\">&\1aquo;</span>",

    "{{CLEAR}}" =>
            "<br style=\"clear:both;\"><!-- kludge for vertical margin spacing mystery -->",

    r"{{BIDEN\|([^}|)]+)}}" =>
            s"{{BIDEN|\1|<span class=\"blb\">&#x2612;</span>}}",

    r"{{BIDEN\|([^|)]+)\|([^}]*)}}" =>    ##                  User must code 1 space after 2nd "|" before 2nd date#
            s"<span class=\"nd\"><span class=\"blb\">&#91;</span>\1 <span class=\"blb\">&#x2611;</span>\2<span class=\"blb\">]</span></span>",

    r"{{BQ\|([^|{}\"]+)\|([^|{}\"]*)}}" =>   ##             Quotes ('"') are killers!#
            s"<div class=\"bq1\">\n<span class=\"bqq\">\"</span><span class=\"bq2\">\1</span><span class=\"bqq\">\"</span>\2\n</div>",
   
]


*---- "WBdiff"

include("WBInclusions")

global Version = "005"

if length(ARGS) < 1 || !(endswith(ARGS[1], ".html"))
    println("\nIncorrect paramater shit")
    exit(16)
end
global ARGS1 = ARGS[1]
global ARGS1_NAKED = ARGS1[1:length(ARGS1) - 5]

global a = readdir("/backups")
global x = ""
global xshit = ""
global xshitb = ""
for item in a
    if !(startswith(item, ARGS1))
        continue
    end
    ix = length(ARGS1)
    seq = item[ix + 4 : length(item)]
    shit = " " ^ (6 - length(seq))
    seq = shit * seq
    itemx = ARGS1 * ".qw" * seq
    if itemx > x
        global x = itemx
        global xshit = xshitb
        global xshitb = item
    end
end

xshitfull = "/backups/" * xshit
old = RRead(xshitfull, "asis")    

new = RRead(ARGS1, "asis")

REGEX = Regex("<title>[a-zA-Z_ ]+\\| (" * ARGS1_NAKED * "|F\\*ckedUp)</title>")

DIMGRAY = r" title=\"Last change date\"><a href=\"Date.html\" style=\"text-decoration:none;color:dimgray;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a></span>"

QQQQQ = r" title=\"Last change date\"><a href=\"Date.html\" style=\"text-decoration:none;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}(<!-- OFL \d{3} -->)?</a>"

global QDict = Dict(   # Omit the goddamned ".html" in the keys!

    "welcome" => r" title=\"Last change date\"><span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}(<!-- OFL \d{3} -->)?</span></a>", 

    "WhomIWouldLikeToBe" => r" title=\"Last change date\"><span style=\"font-size:15px;font-weight:normal;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span></a>",

    "index" => r"color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a></span>",

    "index1" => r" title=\"Last change date\"><span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Biden1" =>
               r"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span></a></span>&nbsp;<a href=\"Biden.html",

    "Cat" =>
               r"<a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span></a>",

    "Churchill" =>
               r"color:darkslategray;\" title=\"Last change date\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a>",

    "Maybe" =>
               r"title=\"Last change date\"><span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Puns" =>  r"<a href=\"Date.html\" style=\"text-decoration:none;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a> <span style=\"font-style:italic;\">Ha! Ha!</span>",

    "Security" =>
               r"title=\"Last change date\"><a href=\"Date.html\" style=\"text-decoration:none;color:dimgray;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a>",

    "Seiho" => r"<a href=\"Date.html\" style=\"text-decoration:none;color:blue;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a></span>",

    "ShortStory0" => r"<a href=\"Date.html\" style=\"text-decoration:none\" title=\"Last change date\"><span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "StP" => r";color:blue;\"><a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "StP2" => r";color:blue;\"><a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Suburbia3" => r"<span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span></a></span>",

    "Thanks" => r"<a href=\"Date.html\" style=\"text-decoration:none;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a>\. <span",

    "Waldo1" => r"<span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Waldo2" => r"<span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Zelensky0" => r"color:blue;\"><a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Zelensky2" => r"<a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Petty0" => r";color:blue;\"><a href=\"Date.html\" style=\"text-decoration:none\"><span style=\"font-size:15px;color:blue\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</span>",

    "Date" => r"none;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a> <span style=\"font-style:italic;\">Nunc",

    "MrSAthertonMiddleton" => r"<a href=\"Date.html\" style=\"text-decoration:none;color:ghostwhite;padding-right:10px;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a></span>",

    "EndOfEarth" => r"color:darkslategray;\" title=\"Last change\"><a href=\"Date.html\" style=\"text-decoration:none;\">\+\d{4}\.\d{2}\.\d{2} v\d{3}</a>\. <span style=\"font-style:italic;\">So what",

    "BodyOdorDarkness" => DIMGRAY,

    "ZelenskyDarkness" => DIMGRAY,

    "155mm" => DIMGRAY,

    "BlackHole" => DIMGRAY,
)

QQQQQN = "DONTCARE1DONTCARE1"
RRRRR = "<meta name=\"author\" content=\"Bradford McCormick\">\n"
RRRRRN = "DONTCARE2DONTCARE2"

function repl(in, from, to, id)
    orig = in
    out = replace(in, from => to, count = 1)
    if orig == out
        println("\n" * HI_RED * "******** COULD NOT COMPARE FILES: " * string(id) * ": \"" *
                    xshit * "\" ********" * HI_END)
        exit(16)
    end 
    return out
end

global PERVERT = haskey(QDict, ARGS1_NAKED)
global oldx = repl(old,  get!(QDict, ARGS1_NAKED, QQQQQ), QQQQQN, 1)
global oldx = repl(oldx, REGEX, RRRRRN, 2)
global oldx = repl(oldx, RRRRR, "", 3)

global newx = repl(new,  get!(QDict, ARGS1_NAKED, QQQQQ), QQQQQN, 4)
global newx = repl(newx, REGEX, RRRRRN, 5)
global newx = repl(newx, RRRRR, "", 6)

println("\n" * LO_GRAY * "WBdiff v" * Version * "." * HI_END * " " * xshit *
         " (" * formatFixed(length(new)) * ")" * (PERVERT ? "***" : "") * "   "  * (newx == oldx ? HI_YELLOW* "No changes" : HI_AQUA * "Changed!") * HI_END * "\n")



*---- "ZZ"

# Today is or will shortly become Saturday, April 01, 2023, day 402 of this mad

include("WBInclusions")
global outputFile = "kx.txt"

version = "012"

if isfile(outputFile)
    s = RRead(outputFile, "asis")
    if findfirst(r"[ \r\n]+[*]{3}", s) != nothing
        println(HI_RED * "\n******** Output file: " * outputFile * " exists!" * HI_END)
        exit(16)
    end
end

dt = DateTime(now()) + Hour(length(ARGS) == 0 ? 24 : (tryparse(Int64, ARGS[1]) * 24))
z0 = DateTime(dt) - DateTime("2022-02-23T00:00")
z = replace(string(div(z0, 86400000)), " milliseconds" => "")

DayOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
        "Saturday", "Sunday"][Dates.dayofweek(dt)]

Month = ["January", "February", "March", "April", "May", "June", "July",
        "August", "September", "October", "November", 
        "December"][tryparse(Int32,replace(string(Dates.Month(dt)), r" months?" => ""))]

Day = replace(string(Dates.Day(dt)), r" days?" => "")

if length(Day) == 1
    Day = "0" * Day
end

DATE = DayOfWeek * ", " * Month * " " * Day * ", " * string(Dates.Year(dt))[1:4] * ", day " * z

println("\n  ZZ v" * version * " (\"" * outputFile * "\")   \"" * HI_YELLOW * DATE * HI_END * "\"")

global txt = RRead("w/txts/k1.txt", "asis")

global txt = replace(txt, "***" => "")

if length(ARGS) > 0
    global txt = replace(txt,  "or will shortly become " => "")
end

global txt = replace(txt, "Saturday, April 01, 2023, day 402" => DATE)

a = open(outputFile, "w")
write(a, txt)
close(a)

run(`"\windows\System32\notepad.exe" $outputFile`)
   

*---- "WBM"

include("WBInclusions")

global ThisFile = "Filler.html"
include("WB_Transforms")
global MDN = "MACRODICT"

# EMP("global MACRODICT = " * RRead("MACRODICT", "asis"))

# I make mountains out of molehills: 
#     global DICT = EMP(EMP("global " * MDN * " = RRead(\"" * MDN * "\", \"asis\")"))

global dict = EMP(RRead(MDN, "asis"))
global DICT = dict[2]

global KWHO = Dict{String,Int32}()

for itm in Transforms
    temp = string(itm.first)
    KWHO[temp] = get!(DICT, temp, 0)          # This adds elements to MACRODICT, too!
end

a1 = replace(string(KWHO), "}}\\\"i\"" => "}}")    # God nows what mess for key that ends with '}}"i' 

a = replace(replace(replace(replace(string(a1), r"(, |Int32}\()" => "\n"), r"(r\\|\\\")" => ""),
         "\\ =" => " ="),r" (\d+)\)" => s" \1")

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

b = replace(b, r"  (\d)   "    => s"    \1   ")
b = replace(b, r"  (\d{2})   " => s"   \1   ")
b = replace(b, r"  (\d{3})   " => s"  \1   ")
b = replace(b, r"  (\d{4})   " => s" \1   ")
b = replace(b, r"  (\d{5})   " => s"\1   ")

c = split(b, "\n")

x = []

for i = 1 : length(c)    
    push!(x, (findfirst("BIDEN", c[i]) == nothing ? "a" : " ") * c[i])  # BIDEN is worthless
end

y = sort(x, rev=true)
println("")
global firstbreak = true
global HILITE_COLOR = HI_YELLOW
global pct = (dict[1][3] / dict[1][2]) * 100

# WB counters added +2023.11.08

global ver = "             v023 (" * string(length(KWHO) - 1) * ")  " * hilite(HI_YELLOW, MDN) * "  " *
                           string(dict[1][1]) * "  " * string(dict[1][2]) * " " * string(dict[1][3]) *
                           " (" * formatDecimal(pct,2) * "%)"
for i = 2 : length(y)
    yi = replace(y[i], r"^a" => " ")
    breaker = ""
    if findfirst(" 0 ", yi) != nothing
        if firstbreak
            breaker = "\n"
            global HILITE_COLOR = ""
            global firstbreak = false
        end
    end    
    
    biden = findfirst("BIDEN", yi) != nothing    
    println(breaker * "  " * hilite(biden ? LO_GRAY : HILITE_COLOR, yi), ver)
    global ver = ""
end

*---- "Quora"

include("WBInclusions")        # Quora [1|9] Quora[nn]
global version = "v006"

global QuoraFile = "Quora11.html"

if length(ARGS) != 2 || (ARGS[2] * ".html" != QuoraFile)
    println("Wrong!")
    exit(16)
end

if "1" == ARGS[1]

    global a = RRead(QuoraFile, "asis")
    b = findall(">&para;<", a)
    lenb = length(b)

    println(version, "  1: ", lenb)
    for i = 1 : lenb
        ii = lenb + 1 - i
        aii = b[ii]
        global a = a[1:aii.start - 1] * " id=\"z" * string(ii) * "\">&para;<" * a[aii.stop + 1:length(a)]
    end
    z = open("QT1", "w")
    write(z, a)
    close(z)
    exit(0)
end

if "9" != ARGS[1]
    return(0)
end

global a = RRead(QuoraFile, "asis")
global toc = ""

global b = findall(r"<p class=\"q1.+?</p>", a)
global bshit = findall(r"<p class=\"q1.+?(</p>|\n)", a)

for i = 1 : min(length(b), length(bshit))
    if b[i] != bshit[i]
        println("\n **", a[b[i]], "**\n\n **", a[bshit[i]], "**\n")
        exit(16)
    end
end

global lenb = length(b)
println(version, "  9: ", lenb)

for i = 1 : lenb
    c = a[b[i]]
    d = replace(c, "<span class=\"q2" => 
                "<a class=\"q2")
    d= replace(d," id=\"z" => " href=\"#z", count = 1)
    d = replace(d, "&para;</span>" => "&para;</a>")
    d = replace(d, "<p" => "<span")
    d = replace(d, "</p>" => "</span><br>\n")
    global toc *= d
end

z = open("QT9", "w")
write(z, toc)
close(z)



*---- "C9images"

include("WBInclusions")

global VERSION = "008"
global BASE = "/ROM/BO/c9/" 
global OKs = Dict()
AGOs = []
USERS = Dict{String, Int32}()

EMP("global C9IMAGDICT = " * RRead("C9IMAGDICT", "asis"))

global ix = 1
function RD(dir)
    # println("          dir: \"",dir, "\"")
    files = readdir(dir)
    for f in files
        if isdir(dir * f)
            RD(dir * f * "/")
            continue
        end
        if !(endswith(f, ".jpg") || endswith(f, ".gif") || endswith(f, ".png"))
            continue
        end
        global ok = false
        global notok = 0
        global q = ""
        global force = false
        while !ok
            try
                if isfile("\\Oldimages\\" * f * q)
                    xx = get(OKs, lowercase(f), "SSSSS")
                    mismatch = ""
                    if (xx != "SSSSS") && (RRead(dir * f, "raw") != RRead(xx, "raw")) 
                        mismatch = " " * HI_RED * "MISMATCH!" * HI_END
                    end
                    println("\\Oldimages\\" * f * q * " ?? " * dir * f  * " ?? " * get(OKs, lowercase(f), HI_AQUA * xx * HI_END) * mismatch) 
                    ok = true
                    
                    continue
                end
                cp(dir * f, "\\Oldimages\\" * f * q)
                mt = stat(dir * f)
#println("    " * dir * f * "     " , string(stat(dir *  f).mtime))
                #println("OK    ", dir * f , "   ",  "\\Oldimages\\" * f * q)
                OKs[f] = lowercase(dir * f)
                push!(AGOs,[stat(dir * f).mtime, dir*f])
                ok = true
            catch ex
                local s = string(ex)  
                if length(s) > 200
                    s = s[1:200] * "..."
                end
                println("Failure: ", dir * f * "  " * typeof(ex), ".\n", s);
                ok = true 
            end
        end
        global ix += 1
   end
end

foreach(rm, filter(contains("."), readdir("/OLDIMAGES",join=true))) # What a shit!


RD(BASE)

LIST1 = []
LIST2 = []
global USED = 0


AGOss = sort(AGOs,by = x -> x[1], rev = true)
for item in AGOss
    xxx = item[2][12:length(item[2])]
    xxxx = ""
    xxxxx = ""
    if (a = get(C9IMAGDICT[2], xxx, "NUTHIN"))  != "NUTHIN"
        xxxx = " <span class=\"bZ\">" * replace(replace(replace(string(a), r"Dict{String, (Int32|Any)}" => ""), r"[()]" => ""), r"\" => (\d+)," => s"\"&nbsp;=>&nbsp;\1,") * "</span>"
        xxxxx = " <span class=\"bZ\">USED</span>"
        global USED += 1        
        for u in keys(a)
            if u in keys(USERS)
                USERS[u] += 1
            else
                USERS[u] = 1
            end
        end 
    end
                                                                                            #   s" \1:\2")
    push!(LIST2, replace(replace(string(Dates.unix2datetime(item[1])), r"T(\d{2}):(\d{2}).*" => " "), "-" => ".") * 
            "</td><td>&nbsp;</td><td style=\"vertical-align:top;\">" * xxxxx * "<a href=\"" * item[2] * "\" class=\"bY\">"  * xxx * "</a></td><td>&nbsp;</td><td style=\"vertical-align:top;\">" * xxxx)
end

AGOst = sort(AGOs, by = x -> lowercase(x[2]))
for item in AGOst
    xxx = item[2][12:length(item[2])]
    xxxx = ""
    xxxxx = ""
    if (a = get(C9IMAGDICT[2], xxx, "NUTHIN"))  != "NUTHIN"
        xxxx = " <span class=\"bZ\">" * replace(replace(replace(string(a), r"Dict{String, (Int32|Any)}" => ""), r"[()]" => ""), r"\" => (\d+)," => s"\"&nbsp;=>&nbsp;\1,") * "</span>"
        xxxxx = " <span class=\"bZ\">USED</span>"
    end
    push!(LIST1, replace(replace(string(Dates.unix2datetime(item[1])), r"T(\d{2}):(\d{2}).*" => " "), "-" => ".") * 
            "</td><td>&nbsp;</td><td style=\"vertical-align:top;\">" * xxxxx * "<a href=\"" * item[2] * "\" class=\"bY\">"  * xxx * "</a></td><td>&nbsp;</td><td>" * xxxx)
end
#println("\n\n")

global junk10 = open("JUNK10.html", "w")
write(junk10, "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"w/css/WBmiracle.css\">\n<title>Link inventory</title>\n<meta charset=\"UTF-8\">\n<style>\n     .bZ {\n        color:darkred;\n        font-weight:bold;\n        padding:2px 0px 0px 0px;\n        font-family:sans-serif;\n    }\n    .bY {\n        text-decoration:none;\n        white-space:nowrap;\n        color:black;\n        font-family:sans-serif;\n        font-weight:bold;\n        padding:2px 0px 0px 9px;\n        font-size:18px;\n    }\n    .bX {\n        white-space:nowrap;\n        padding:2px 0px 0px 12px;\n        color:blue;\n        font-family:sans-serif;\n        font-style:italic;\n        font-weight:bold;\n        font-size:16px;\n    }\n    .px2 a {\n        font-family:sans-serif;\n    }\n</style>\n</head>\n<body style=\"background-color:white;\"><div style=\"padding:2px 0px 0px 6px;\"><a href=\"welcome.html\" style=\"text-decoration:none;\" class=\"rWel\"><img src=\"w/images/1/12/Prev2a.gif\" alt=\"Previous\" style=\"padding-left:3px;padding-right:1px;width:10px; height:12px;\">Welcome</a></div>\n<div class=\"read600\">\n")

write(junk10, "<p id=\"Top\" style=\"font-size:20px;font-family:sans-serif;color:black;font-weight:bold;\">c9images v" * VERSION * "&nbsp; [" * C9IMAGDICT[1] * "]<br>USED: " * string(USED) * ". &nbsp;Total: " * formatFixed(length(LIST1)) * ". &nbsp;&nbsp;<a href=\"#Chrono\" style=\"font-weight:bold;font-family:sans-serif;\">Chronological order</a></p>\n" * 
        "<table\n    class=\"tbl\" style=\"margin:20px 0px 20px 20px;\">\n")    

for i = 1 : length(LIST1)
    write(junk10, "<tr><td class=\"bX\" style=\"vertical-align:top;\">" * LIST1[i] * "</td></tr>\n")
end
write(junk10, "<tr id=\"Chrono\"><td colspan=5 style=\"padding:22px 0px 24px 0px;\"><span style=\"font-size:24px;font-weight:bold;\">&mdash;&mdash; Chronological order (<a href=\"#Top\" style=\"font-style:italic;font-weight:normal;\">Top</a>) &mdash;&mdash;</span></td></tr>\n")

for i = 1 : length(LIST1)
    write(junk10, "<tr><td class=\"bX\" style=\"vertical-align:top;\">" * LIST2[i] * "</td></tr>\n")
end

global U = ""
Uc = ""
println(USERS)
sds = []
for k in keys(USERS)
    push!(sds, string(k))
end


for u in sort(sds, by = x -> lowercase(x))
    global U *= Uc * "<a href=\"" * u * "\" style=\"text-decoration:none;font-family:sans-serif;font-weight:bold;\">" * u * "</a>(" * string(USERS[u]) * ")"
    global Uc = ", "
end

write(junk10,"</table>\n<p style=\"font-family:sans-serif;font-weight:bold;font-size:20px;\">Users(# files ref'd):&nbsp; " * U * ".</p>")

write(junk10, "\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(junk10)

println("ix: ", ix - 1)



