~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to cmd/smyrna/main.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: main.c,v 1.12 2008/04/25 16:12:53 ellson Exp $ $Revision: 1.12 $ */
 
1
/* $Id: main.c,v 1.58 2009/12/09 23:45:26 erg Exp $Revision: */
2
2
/* vim:set shiftwidth=4 ts=8: */
3
3
 
4
4
/**********************************************************
22
22
#if defined(_WIN32) && !defined(__CYGWIN__)
23
23
#define WIN32_LEAN_AND_MEAN 1
24
24
#include <windows.h>
 
25
#include <windowsx.h>
25
26
#endif
26
27
#include <gtk/gtk.h>
27
28
#include <gtk/gtkgl.h>
28
29
#include <glade/glade.h>
29
30
#include "gui.h"
30
31
#include "viewport.h"
 
32
#include "support.h"
31
33
#include "menucallbacks.h"
32
34
#include "gltemplate.h"
33
35
#include "memory.h"
 
36
#include "gvprpipe.h"
 
37
#include "frmobjectui.h"
34
38
#ifdef ENABLE_NLS
35
39
#include "libintl.h"
36
40
#endif
 
41
#include <assert.h>
 
42
 
 
43
#ifdef HAVE_GETOPT_H
 
44
#include <getopt.h>
 
45
#else
 
46
#include "compat_getopt.h"
 
47
#endif
37
48
 
38
49
#ifdef G_OS_WIN32
39
50
gchar *package_prefix;
40
51
gchar *package_data_dir;
41
52
#endif
42
53
gchar *package_locale_dir;
43
 
static char* smyrnaDir;
44
 
char* smyrnaGlade;
45
 
 
46
 
char*
47
 
smyrnaPath (char* suffix)
 
54
static char *smyrnaDir;         /* path to directory containin smyrna data files */
 
55
char *smyrnaGlade;
 
56
unsigned char SmyrnaVerbose;
 
57
 
 
58
 
 
59
/* smyrnaPath:
 
60
 * Construct pathname for smyrna data file.
 
61
 * Base file name is given as suffix.
 
62
 * The function resolves the directory containing the data files,
 
63
 * and constructs a complete pathname.
 
64
 * The returned string is malloced, so the application should free
 
65
 * it later.
 
66
 * Returns NULL on error.
 
67
 */
 
68
char *smyrnaPath(char *suffix)
48
69
{
49
 
    char* buf;
50
 
    if (!smyrnaDir) return NULL;
51
 
    buf = N_NEW(strlen(smyrnaDir)+strlen(suffix)+2,char);
52
 
    sprintf (buf, "%s/%s", smyrnaDir, suffix);
 
70
    char *buf;
 
71
    static int baselen;
 
72
    int slen;
 
73
#ifdef WIN32
 
74
    char *pathSep = "\\";
 
75
#else
 
76
    char *pathSep = "/";
 
77
#endif
 
78
    assert(smyrnaDir);
 
79
 
 
80
    if (baselen == 0) {
 
81
        baselen = (int)strlen(smyrnaDir) + 2;
 
82
    }
 
83
    slen = (int)strlen(suffix);
 
84
    buf = N_NEW(baselen+slen, char);
 
85
    sprintf(buf, "%s%s%s", smyrnaDir, pathSep, suffix);
53
86
    return buf;
54
87
}
55
88
 
 
89
static char *useString = "Usage: smyrns [-v?] <file>\n\
 
90
  -v         - verbose\n\
 
91
  -?         - print usage\n";
 
92
 
 
93
static void usage(int v)
 
94
{
 
95
    printf(useString);
 
96
    exit(v);
 
97
}
 
98
 
 
99
 
 
100
static char *parseArgs(int argc, char *argv[], ViewInfo * view)
 
101
{
 
102
    unsigned int c;
 
103
 
 
104
    while ((c = getopt(argc, argv, ":K:txv?")) != -1) {
 
105
        switch (c) {
 
106
        case 'v':
 
107
            SmyrnaVerbose = 1;
 
108
            break;
 
109
#if 0
 
110
        case 't':
 
111
            view->dfltViewType = VT_TOPVIEW;
 
112
            break;
 
113
        case 'x':
 
114
            view->dfltViewType = VT_XDOT;
 
115
            break;
 
116
        case 'K':
 
117
            view->dfltEngine = s2layout(optarg);
 
118
            break;
 
119
#endif
 
120
        case '?':
 
121
            if (optopt == '?')
 
122
                usage(0);
 
123
            else
 
124
                fprintf(stderr,
 
125
                        "smyrna: option -%c unrecognized - ignored\n",
 
126
                        optopt);
 
127
            break;
 
128
        }
 
129
    }
 
130
 
 
131
    if (optind < argc)
 
132
        return argv[optind];
 
133
    else
 
134
        return NULL;
 
135
}
 
136
 
 
137
#ifdef UNUSED
 
138
static void close_cgraph(Agraph_t * g)
 
139
{
 
140
    Agnode_t *v;
 
141
    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
 
142
        agdelrec(v, "temp_node_record");
 
143
    }
 
144
    agclose(g);
 
145
}
 
146
 
 
147
#endif
 
148
 
56
149
int main(int argc, char *argv[])
57
150
{
58
151
    GdkGLConfig *glconfig;
59
 
 
60
 
    smyrnaDir = getenv ("SMYRNA_PATH");
61
 
#ifndef _WIN32
62
 
    if (!smyrnaDir)
 
152
    char *initFileName;
 
153
    /*combo box to show loaded graphs */
 
154
    GtkComboBox *graphComboBox;
 
155
 
 
156
 
 
157
 
 
158
    smyrnaDir = getenv("SMYRNA_PATH");
 
159
    if (!smyrnaDir) {
 
160
#ifdef _WIN32
 
161
        int sz =
 
162
            GetCurrentDirectory(0,
 
163
                                NULL) +
 
164
            strlen("\\share\\graphviz\\smyrna") + 1;
 
165
        smyrnaDir = N_NEW(sz, char);
 
166
        GetCurrentDirectory(sz, smyrnaDir);
 
167
        smyrnaDir[strlen(smyrnaDir) - 4] = (char) 0;
 
168
        strcat(smyrnaDir, "\\share\\graphviz\\smyrna");
 
169
#else
63
170
        smyrnaDir = SMYRNA_PATH;
64
171
#endif
65
 
 
 
172
    }
66
173
    load_attributes();
67
174
 
68
175
#ifdef G_OS_WIN32
72
179
    package_locale_dir =
73
180
        g_build_filename(package_prefix, "share", "locale", NULL);
74
181
#else
75
 
    if (smyrnaDir)
76
 
        package_locale_dir = g_build_filename(smyrnaDir, "locale", NULL);
77
 
    else
78
 
        package_locale_dir = g_build_filename(SMYRNA_PATH, "locale", NULL);
79
 
#endif  /* # */
 
182
    package_locale_dir = g_build_filename(smyrnaDir, "locale", NULL);
 
183
#endif                          /* # */
80
184
#ifdef ENABLE_NLS
81
185
    bindtextdomain(GETTEXT_PACKAGE, package_locale_dir);
82
186
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
83
187
    textdomain(GETTEXT_PACKAGE);
84
188
#endif
85
189
    view = NEW(ViewInfo);
 
190
 
86
191
    init_viewport(view);
87
 
 
88
192
    gtk_set_locale();
89
193
    gtk_init(&argc, &argv);
90
 
 
91
 
#ifdef _WIN32
92
 
#define GTKTOPVIEW_ICONSDIR "C:\\Projects\\ATT\\GTK\\GTKTest2\\GUI\\images\\"
93
 
#endif
94
 
    if (!(smyrnaGlade)) {
95
 
#ifdef _WIN32
96
 
        smyrnaGlade = SMYRNA_GLADE;
97
 
#else
98
 
        smyrnaGlade = smyrnaPath ("smyrna.glade");
99
 
#endif
100
 
    }
 
194
    initFileName = parseArgs(argc, argv, view);
 
195
    if (!(smyrnaGlade))
 
196
        smyrnaGlade = smyrnaPath("smyrna.glade");
101
197
    xml = glade_xml_new(smyrnaGlade, NULL, NULL);
 
198
 
102
199
    gladewidget = glade_xml_get_widget(xml, "frmMain");
103
200
    gtk_widget_show(gladewidget);
104
201
    g_signal_connect((gpointer) gladewidget, "destroy",
105
202
                     G_CALLBACK(mQuitSlot), NULL);
106
203
    glade_xml_signal_autoconnect(xml);
 
204
    if (initFileName) {
 
205
        view->initFile = 1;
 
206
        view->initFileName = strdup(initFileName);
 
207
    }
107
208
    gtk_gl_init(0, 0);
108
209
    /* Configure OpenGL framebuffer. */
109
210
    glconfig = configure_gl();
110
 
    gladewidget = glade_xml_get_widget(xml, "vbox2");
 
211
//      gladewidget = glade_xml_get_widget(xml, "vbox2");
 
212
    gladewidget = glade_xml_get_widget(xml, "hbox11");
 
213
 
 
214
    gtk_widget_hide(glade_xml_get_widget(xml, "vbox13"));
 
215
    gtk_window_set_deletable ((GtkWindow*)glade_xml_get_widget(xml, "dlgSettings"),0);
 
216
    gtk_window_set_deletable ((GtkWindow*)glade_xml_get_widget(xml, "dlgTVFilter"),0);
 
217
    gtk_window_set_deletable ((GtkWindow*)glade_xml_get_widget(xml, "frmTVNodes"),0);
 
218
 
 
219
 
111
220
    create_window(glconfig, gladewidget);
112
 
        /*first arg is used as file name */
113
 
    if (argc > 1)
114
 
        add_graph_to_viewport_from_file(argv[1]);
115
 
        gtk_main();
 
221
 
 
222
    change_cursor(GDK_TOP_LEFT_ARROW);
 
223
 
 
224
#ifndef WIN32
 
225
    glutInit(&argc, argv);
 
226
#endif
 
227
 
 
228
    gladewidget = glade_xml_get_widget(xml, "hbox13");
 
229
    graphComboBox = (GtkComboBox *) gtk_combo_box_new_text();
 
230
    gtk_box_pack_end((GtkBox*)gladewidget, (GtkWidget*)graphComboBox, 1, 1, 10);
 
231
    gtk_widget_show((GtkWidget*)graphComboBox);
 
232
    view->graphComboBox = graphComboBox;
 
233
    gtk_main();
 
234
 
116
235
 
117
236
 
118
237
#ifdef G_OS_WIN32
120
239
    g_free(package_data_dir);
121
240
#endif
122
241
    g_free(package_locale_dir);
123
 
    clear_viewport(view);
124
242
    return 0;
125
243
}