#! /usr/bin/env bash # erd2map # # Create html map file from one of Marc's pretty ERDs # # Copyright (c) 2020 Marc Munro # Author: Marc Munro # License: GPL V3 # # Usage: # erd2map # # This requires the existence of files: # - .png (created from dia source by dia and pstoimg) # - .coords (created from dia source by xsltproc) # # The coords file (see stylesheet dia_to_map.xsl) consists of a bunch # of entity and point definitions in dia gird coordinates. # # scale_factors() # From our coords file and the size of the image work out scale # factors and offsets, printing output lines for for each to stdout. # Usage: scale_factors # scale_factors () { gawk -v SIZE=$1 'BEGIN { min_x = 100000 min_y = 100000 max_x = 0 max_y = 0 x_pixels = gensub(/x.*/, "", "g", SIZE) + 0 y_pixels = gensub(/.*x/, "", "g", SIZE) + 0 } /x=/ { x = gensub(/.*x=.([-0-9.]*).*/, "\\1", "g") + 0 y = gensub(/.*y=.([-0-9.]*).*/, "\\1", "g") + 0 if (x > max_x) max_x = x if (y > max_y) max_y = y if (x < min_x) min_x = x if (y < min_y) min_y = y } END { x_range = max_x - min_x y_range = max_y - min_y x_scale = x_pixels / x_range y_scale = y_pixels / y_range x_offset = -min_x * x_scale y_offset = -min_y * y_scale print "SCALE:", x_scale, y_scale print "OFFSET:", x_offset, y_offset } ' $2 } # Get html references for entities, printing the results to stdout. # Usage: cat entity_list | entity_refs # find_refs () { export ref_object=$2 ( cd $1 while read line; do if files=`grep -l "${ref_object}_${line}" *html` 2>/dev/null; then file=`echo "${files}" | head -1` echo "REFOBJECT $line ${file}#${ref_object}_${line}" fi done ) } # Create html area definitions for each entity based on scale factors # and the entities' html refs. # make_areas () { (cat - $1) | gawk -v BASENAME="$2" -v OBJTYPE="${objtype}" ' # Read coordinates attributes from a coords file line. function coords() { x = int(gensub(/.*x=\"([^\"]*).*/, "\\1", "g") * x_scale + x_offset) y = int(gensub(/.*y=\"([^\"]*).*/, "\\1", "g") * y_scale + y_offset) #print $0, x, y return x "," y } BEGIN { if (OBJTYPE == "view") { obj_tail = " view" } else { obj_tail = "s table" } printf("
\n", BASENAME) printf(" \n", BASENAME) } END { printf(" \n") printf(" \n", BASENAME, BASENAME) printf("
\n") } # Read x and y scale factors. /^SCALE: / { x_scale = $2 + 0 y_scale = $3 + 0 #print "SCALE:", x_scale, y_scale } # Read x and y pixel offsets /^OFFSET: / { x_offset = $2 + 0 y_offset = $3 + 0 #print "OFFSET:", x_offset, y_offset } # Create array (hash, really) of html_refs keyed by refobjects /^REFOBJECT/ { html_refs[$2] = gensub(/[^ ]* [^ ]* (.*)/, "\\1", "g") } # Read refobject name, and get html reference for it. /\n", href) } }' } # Get entities from coords file # Usage: entities # referenced_objects () { gawk '/