OSDN Git Service

8d2f956a21e3adf1ba9b77115ca1064aa8b4e0ed
[openpts/openpts.git] / src / uml2dot.c
1 /*
2  * This file is part of the OpenPTS project.
3  *
4  * The Initial Developer of the Original Code is International
5  * Business Machines Corporation. Portions created by IBM
6  * Corporation are Copyright (C) 2010 International Business
7  * Machines Corporation. All Rights Reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the Common Public License as published by
11  * IBM Corporation; either version 1 of the License, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * Common Public License for more details.
18  *
19  * You should have received a copy of the Common Public License
20  * along with this program; if not, a copy can be viewed at
21  * http://www.opensource.org/licenses/cpl1.0.php.
22  */
23
24 /**
25  * \file src/uml2dot.c
26  * \brief Utility, generate dot file from UML2 state siagram
27  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28  * @date 2010-04-01
29  *
30  *  UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc)
31  *
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <netdb.h>
38 #include <errno.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45
46 #include <openpts.h>
47 // #include <log.h>
48
49 /**
50  * usage
51  */
52 void usage(void) {
53     fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_UML2DOT_USAGE,
54             "usage: uml2dot [options] UMLfile \n"
55             "\t-o output\tset output file (default is stdout)\n"
56             "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n"
57             "\n"));
58 }
59
60 /**
61  * main
62  */
63 int main(int argc, char *argv[]) {
64     int rc = -1;
65     int c;
66     OPENPTS_FSM_CONTEXT *ctx;
67     char *input_filename = NULL;
68     char *output_filename = NULL;
69
70     initCatalog();
71
72     while ((c = getopt(argc, argv, "do:h")) != EOF) {
73         switch (c) {
74         case 'd':
75             setVerbosity(1);
76             break;
77         case 'o':
78             output_filename = optarg;
79             break;
80         case 'h':
81             /* fall through */
82         default:
83             usage();
84             return -1;
85         }
86     }
87     argc -= optind;
88     argv += optind;
89     input_filename = argv[0];
90
91     /* Read UML(XML) file */
92
93     if (input_filename == NULL) {
94         printf(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n"));
95         usage();
96         return -1;
97     }
98
99     /* read UML(XML) */
100     ctx = newFsmContext();
101     rc = readUmlModel(ctx, argv[0]);
102
103     if (rc != 0) {
104         ERROR("ERROR\n");
105         goto error;
106     }
107
108     /* Gen DOT file */
109     rc = writeDotModel(ctx, output_filename);
110
111     if (rc != 0) {
112         ERROR("ERROR\n");
113         goto error;
114     }
115
116   error:
117
118     freeFsmContext(ctx);
119
120     return rc;
121 }