#! /bin/sed -nf 1i\ /** @page database Database Schema\ \ @dot\ digraph schema { # get everithing on one single line H;$!d;$x # remove all single-line comment lines s/\n--[^\n]*//g # encode html entities s/&/\&##SEMICOLON##/g s/\<##SEMICOLON##/g s/>/\>##SEMICOLON##/g # reduce spaces s,\t\| \+, ,g # remove multiline comments :f;s,\(.*\)/\*.*\*/[ \n]*;*,\1,g;tf # remove empty lines s,\n\+,\n,g # remove unknown commands s,\(;\|\n\) *\(INSERT\|DELIMITER\|USE\|DROP\|CREATE[ \n]\+DATABASE\)[ \n]\+[^;]*;\+,,ig # convert special characters within quotes :a;s/^\(\([^"]*"[^",]*"\)*[^"]*"[^"]*\),\([^"]*".*\)/\1\##COMMA##\3/g;ta :c;s/^\(\([^']*'[^',]*'\)*[^']*'[^']*\),\([^']*'.*\)/\1\##COMMA##\3/g;tc # backup everything to the buffer # then analyze only on one create table :i h s,.*\(create[ \n]\+table[^;]*;\).*,\1,ig # start html table node s|CREATE[ \n]\+TABLE[ \n]\+\(IF[ \n]\+NOT[ \n]\+EXISTS[ \n]\+\)\?`\?\(\w\+\)`\?| \2\n [shape=none, margin=0, label=<\n
\2 | |||
\1 | \2 | \4 | [^<]*\)COMMENT[ \n]\+["']\([^"']*\)["']\([^<]* | \)|\1\4 | \3 | |g # add line breaks for long lines s|\(]*>[^<]\{30,40\}\)[ \n]\+\([^<]\{20,\} | \)|\1
\1 | ]*>[^<]\{60,80\}\)[ \n]\+\([^<]\{30,\} | \)|\1