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",

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

    "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")

