OSDN Git Service

fixed for Ubuntu 12.04
[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  * cleanup 2012-01-05 SM
30  *
31  *  UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc)
32  *
33  */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <netdb.h>
39 #include <errno.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <unistd.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46
47 #include <openpts.h>
48
49 /**
50  * usage
51  */
52 void usage(void) {
53     OUTPUT(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     /* logging/NLS */
71     initCatalog();
72
73     while ((c = getopt(argc, argv, "do:h")) != EOF) {
74         switch (c) {
75         case 'd':
76             setVerbosity(1);
77             break;
78         case 'o':
79             output_filename = optarg;
80             break;
81         case 'h':
82             /* fall through */
83         default:
84             usage();
85             return -1;
86         }
87     }
88     argc -= optind;
89     argv += optind;
90     input_filename = argv[0];
91
92     /* Read UML(XML) file */
93     if (input_filename == NULL) {
94         ERROR(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         LOG(LOG_ERR, "ERROR\n");
105         goto error;
106     }
107
108     /* Gen DOT file */
109     rc = writeDotModel(ctx, output_filename);
110
111     if (rc != 0) {
112         LOG(LOG_ERR, "ERROR\n");
113         goto error;
114     }
115
116   error:
117     freeFsmContext(ctx);
118
119     return rc;
120 }