commit 2ed76fac28708faf5c0eb84b84a6f1507fe958dc
Author: Morel Bérenger <berengermorel76@gmail.com>
Date: Fri, 27 Nov 2020 01:45:52 +0100
initial commit
Diffstat:
A | LICENSE | | | 17 | +++++++++++++++++ |
A | README | | | 17 | +++++++++++++++++ |
A | example/uml.dt | | | 12 | ++++++++++++ |
A | uml | | | 112 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 158 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,17 @@
+Copyright (c) 2020 Morel Bérenger
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
diff --git a/README b/README
@@ -0,0 +1,17 @@
+This project aims at providing a set of scripts to generate
+graphviz code for various uses.
+
+List of uses:
+
+* UML-like class diagrams
+* TODO: physical/logical network diagrams
+* TODO: daemon dependencies diagrams
+
+Dependencies:
+
+* awk (tested with mawk 1.3.3 under Debian Buster)
+* dot
+
+Usage exemple:
+
+* uml-like: ./uml FILE | dot -Tpdf /tmp/FILE.pdf && mupdf /tmp/FILE.pdf
diff --git a/example/uml.dt b/example/uml.dt
@@ -0,0 +1,12 @@
+private
+class animal
+var int num_paw 4
+var bool have_tail
+virtual bool attack animal meh
+class dog
+class cat
+fun void climb coord:c
+inherit dog animal
+inherit cat animal
+associate cat dog fight
+aggreg cat dog fight
diff --git a/uml b/uml
@@ -0,0 +1,112 @@
+#!/usr/bin/awk -f
+
+function end_class() {
+ if( class != "" )
+ {
+ printf( "}\"\n]\n\n" );
+ }
+ class = "";
+ inside = "";
+}
+
+function fun( overload ) {
+ if( inside != "fun" )
+ {
+ printf( "|" );
+ inside = "fun";
+ }
+ printf( "%s %s(", scope, $3 )
+ for( i = 4; i <= NF; ++i )
+ {
+ gsub( ":", " ", $i );
+ printf( "%s%s", i == 4 ? "" : ", ", $i );
+ }
+ printf( "): %s %s\l", $2, overload );
+}
+
+function relation( from, to, tail, head, label ) {
+ printf( "%s -> %s [ arrowtail = \"%s\", arrowhead = \"%s\"", from, to, tail, head );
+ if( label != "" )
+ {
+ printf( ", label = \"%s\"", label );
+ }
+}
+
+BEGIN {
+ printf( "digraph %s\n{\n", FILENAME );
+ class = "";
+ scope = "";
+ inside = "";
+}
+
+$0 == "private" { scope = "[-]"; }
+$0 == "protected" { scope = "[#]"; }
+$0 == "public" { scope = "[+]"; }
+$0 == "package" { scope = "[~]"; }
+
+$1 == "class" {
+ end_class();
+ class = $2;
+ printf( "%s\n[\n\tshape=\"record\";\n\tlabel=\"{%s", class, class );
+}
+
+$1 == "fun" {
+ fun( "" );
+}
+
+$1 == "virtual" {
+ fun( "[[VIRT]]" );
+}
+
+$1 == "abstract" {
+ fun( "[[ABST]]" );
+}
+
+$1 == "var" {
+ if( inside != "var" )
+ {
+ printf( "|" );
+ inside = "var";
+ }
+ printf( "%s %s : %s", scope, $3, $2 );
+ if( NF == 4 )
+ {
+ printf( " = %s", $4 );
+ }
+ printf( "\l" );
+}
+
+$1 == "inherit" {
+ end_class();
+ relation( $2, $3, "none", "empty", "" );
+ printf( " ];\n" );
+}
+
+$1 == "associate" {
+ end_class();
+ relation( $2, $3, "empty", "vee", $4 );
+ printf( " ];\n" );
+}
+
+$1 == "aggreg" {
+ end_class();
+ relation( $2, $3, "odiamond", "vee", $4 );
+ printf( " ];\n" );
+}
+
+$1 == "compose" {
+ end_class();
+ relation( $2, $3, "diamond", "vee", $4 );
+ printf( " ];\n" );
+}
+
+$1 == "depends" {
+ end_class();
+ relation( $2, $3, "none", "vee", $4 );
+ printf( " style = \"dotted\" ];\n" );
+}
+
+END {
+ end_class();
+ printf( "}\n" );
+}