Initial commit of gopohermap checker

This commit is contained in:
sloumdrone 2019-10-03 22:39:15 -07:00
commit a3b4a2d077
1 changed files with 94 additions and 0 deletions

94
mapcheck Executable file
View File

@ -0,0 +1,94 @@
#! /usr/bin/awk -f
#
# _ __ ___ __ _ _ __ ___| |__ ___ ___| | __
# | '_ ` _ \ / _` | '_ \ / __| '_ \ / _ \/ __| |/ /
# | | | | | | (_| | |_) | (__| | | | __/ (__| <
# |_| |_| |_|\__,_| .__/ \___|_| |_|\___|\___|_|\_\
# |_|
#
# mapcheck is a tool to validate gophermaps for the gopher
# internet protocol. It will validate a map in a few ways:
#
# 1. Check for link lines without all four required values
# 2. Warns of any non-standard link types
# 3. Warns if a line of text is longer than a value set by
# the variable "MAXLEN"
#
# This software is licensed under the GNU GPLv3 License
# For more details see:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
BEGIN {
FS="\t";
OFS=" ";
# Set variable
MAXLEN = 60;
ERR=0
WARN=0
FNAME=""
# Initialize types array with values
TYPES["h"] = 0
TYPES["i"] = 0
TYPES["0"] = 0
TYPES["1"] = 0
TYPES["2"] = 0
TYPES["3"] = 0
TYPES["4"] = 0
TYPES["5"] = 0
TYPES["6"] = 0
TYPES["7"] = 0
TYPES["8"] = 0
TYPES["9"] = 0
TYPES["+"] = 0
TYPES["g"] = 0
TYPES["I"] = 0
TYPES["T"] = 0
TYPES["s"] = 0
print "mapcheck v0.1";
}
{
if (FILENAME != FNAME) {
if (FNAME != "" && (ERR > 0 || VIOLATION > 0 || WARN > 0)) {
print "\n" ERR, "Errors, " VIOLATION, "Violations, and " WARN, "Warnings"
} else if (FNAME != "") {
print "No issues found."
}
if (FNAME != "") {
print ""
print "- - - - - - - \n"
}
ERR=0
WARN=0
FNAME=FILENAME
print "Reading", FILENAME "\n"
}
if ((NF == 1 && length($1) > MAXLEN) || (NF == 4 && length($1) - 1 > MAXLEN)) {
WARN++
print "WARNING: Line", NR ":", "Line length is", length($1) ". Max length is", MAXLEN
}
if (NF > 1 && NF < 4) {
ERR++
print "ERROR: Line", NR ":", "Link line with", NF, "columns. Expected 4."
}
if (NF == 4 && !(substr($1, 1, 1) in TYPES)) {
WARN++
print "WARNING: Line", NR ":", "Non-standard gophertype \"" substr($1, 1, 1) "\" may not be valid in all clients"
}
}
END {
if (ERR > 0 || VIOLATION > 0 || WARN > 0) {
print "\n" ERR, "Errors, " VIOLATION, "Violations, and " WARN, "Warnings"
} else {
print "No issues found."
}
}