-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
1445 lines (1174 loc) · 39.7 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id: main.c,v 1.22 2003/03/25 00:30:47 d3august Exp $
*/
/* xtraceroute - graphically show traceroute information.
* Copyright (C) 1996-1998 Björn Augustsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "xt.h"
#include <GL/glx.h>
#include <GL/glu.h>
#include <gtkgl/gtkglarea.h>
#include <sys/stat.h>
#include <string.h>
#include <netdb.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h> // for sigaction
#include <sys/wait.h> // for waitpid
#include <unistd.h> // for close
#include <stdlib.h> // for atoi
#include "trackball.h"
GtkWidget *clist; /* The list of sites below the globe */
GdkPixbuf *earth_texture;
GdkPixbuf *night_texture;
GdkPixbuf *created_texture;
int xbegin, ybegin, zbegin;
int xbeginstrafe, ybeginstrafe;
GLfloat zoom = EARTH_SIZE;
float curquat[4];
GLint vp[4]; /* viewport */
int newModel = 1; /* Do we need to recalc the modelview matrix? */
site local; /* For resolving where localhost is (to rotate earth right) */
static const char* versionstring = N_("Xtraceroute version ");
/**
* Called to reset the sites.
*/
static void
clear_sites(void)
{
int i;
for(i=0;i<MAX_SITES;i++)
{
sites[i].draw = 0;
if(sites[i].extpipe_active == TRUE) /* Kill any lookups in progress */
{
if(sites[i].extpipe_pid != 0)
{
kill(sites[i].extpipe_pid, SIGTERM);
//printf("Killed %ld\n", sites[i].extpipe_pid);
}
}
}
// spinner_reset();
}
/**
* Recalculates the modelview matrix.
* Call this when a user has rotated the globe with the mouse or similar.
* If the world needs changing, call makeearth instead.
* (Zooming does this, the lines are constant size independent of zoom.)
*/
static void
recalcModelView(void)
{
GLfloat m[4][4];
glPopMatrix();
glPushMatrix();
build_rotmatrix(m, curquat);
glMultMatrixf(&m[0][0]);
glScalef(zoom,zoom,zoom);
}
/**
* Used as a callback for expose events.
*/
void
redraw(GtkWidget *wi, GdkEvent *gdk_event)
{
if (!gtk_gl_area_make_current(GTK_GL_AREA(wi)))
printf("make_current failed in redraw()\n");
if (newModel)
{
recalcModelView();
newModel = 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCallList(WORLD);
gtk_gl_area_swapbuffers(GTK_GL_AREA(wi));
}
/**
* Called when someone clicks on the globe. If he clicked on a site, it
* returns that site's number. Otherwise it returns -1.
*/
static int
which_site(GLint x, GLint y)
{
typedef struct {
GLuint num_names;
GLuint min_dist;
GLuint max_dist;
GLuint name;
} hit_record;
hit_record selectBuf[MAXSELECT/4];
GLint hits = 0;
GLdouble aspect;
if (!gtk_gl_area_make_current(GTK_GL_AREA(glarea)))
printf("make_current failed early in which_site()\n");
//printf("which_site?\n");
glSelectBuffer(MAXSELECT, (GLuint *) &selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(NOT_SELECTABLE);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x, glarea->allocation.height - y, 1, 1, vp);
// Note: This code is common to some in reshape. Maybe look into that.
aspect = (float)glarea->allocation.width / (float)glarea->allocation.height;
if(glarea->allocation.width > glarea->allocation.height)
{
/* It's wide. */
gluPerspective( 40.0, /* Field of view, in "y" direction. */
aspect, /* Aspect ratio */
1.0, /* Z near */
10.0); /* Z far */
}
else
{
/* It's high. */
gluPerspective( 40.0/aspect, /* Field of view, in "y" direction. */
aspect, /* Aspect ratio */
1.0, /* Z near */
10.0); /* Z far */
}
glMatrixMode(GL_MODELVIEW);
set_render_mode(SELECT_MODE);
makeearth();
set_render_mode(NORMAL_MODE);
glCallList(WORLD);
hits = glRenderMode(GL_RENDER);
/* Change back to projection here to pop my old matrix.
Otherwise we'll look at the world through the pickmatrix
in the future. */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
/* Process the hits, find the closest one */
{
GLuint closest_distance = ~0U; // A really big number
int retval = -1;
int i;
for(i=0 ; i<hits ; i++)
{
/* The hit records are potentially variable length, but I only
* use one name per object. */
if(selectBuf[i].num_names != 1)
{
printf("Ouch! More than one name in hit record!\n");
return -1;
}
if(selectBuf[i].name != NOT_SELECTABLE)
{
if(selectBuf[i].min_dist < closest_distance)
{
closest_distance = selectBuf[i].min_dist;
retval = selectBuf[i].name;
}
}
}
return retval;
}
}
/**
* reshape() : called whenever the window size changes.
*/
static void
reshape(GtkWidget *wi, gpointer data)
{
gint w, h;
GLdouble aspect;
if(!GTK_WIDGET_REALIZED (wi))
{
gtk_widget_queue_resize(wi);
return;
}
if (!gtk_gl_area_make_current(GTK_GL_AREA(wi)))
{
printf("make_current failed in reshape()\n");
return;
}
w = wi->allocation.width;
h = wi->allocation.height;
aspect = (float)w / (float)h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glLoadIdentity();
if(w > h)
{
/* It's wide. */
gluPerspective( 40.0, /* Field of view, in "y" direction. */
aspect, /* Aspect ratio */
1.0, /* Z near */
10.0); /* Z far */
}
else
{
/* It's high. */
gluPerspective( 40.0/aspect, /* Field of view, in "y" direction. */
aspect, /* Aspect ratio */
1.0, /* Z near */
10.0); /* Z far */
}
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glGetIntegerv(GL_VIEWPORT, vp);
gtk_gl_area_swapbuffers(GTK_GL_AREA(wi));
}
// have these un-globalized or put in a separate file later
gint rotation_track_tag = 0;
gint translation_track_tag = 0;
gint zoom_track_tag = 0;
/**
* mouse_motion(): Called when the mouse moves. (Callback.)
*/
static gint
mouse_motion(GtkWidget *wi, GdkEventMotion *ev)
{
gboolean any_change = FALSE;
gboolean zoom_change = FALSE;
float tempquat[4];
gint x, y, w, h;
gfloat strafex,strafey;
GdkModifierType mods;
gdk_window_get_pointer (wi->window, &x, &y, &mods);
w = glarea->allocation.width;
h = glarea->allocation.height;
// Begin zoom stuff, sort this out later.
// if (zoom_track_tag && (zbegin > -1) )
if (zoom_track_tag && (y != zbegin) )
{
double fakt;
fakt = (1.0 - (2*(y-zbegin) / (double)h));
// printf("fact: %f, zoom: %f\n", fakt, zoom);
zoom*=fakt;
if (zoom > Z_OF_EYE - EARTH_SIZE)
zoom=Z_OF_EYE - EARTH_SIZE; /* prevents going inside the object */
if (zoom <= EARTH_SIZE/4)
zoom = EARTH_SIZE/4; /* prevents going beyond "infinity" */
zbegin=y;
any_change = TRUE;
zoom_change = TRUE;
}
/* Rotation: */
/* This stuff doesn't really work well unless the
canvas is quadratic. */
if(rotation_track_tag && (x != xbegin || y != ybegin) )
{
trackball(tempquat,
(2.0*xbegin - w) / w,
(h - 2.0*ybegin) / h,
(2.0*x - w) / w,
(h - 2.0*y) / h);
add_quats(tempquat, curquat, curquat);
xbegin = x;
ybegin = y;
any_change = TRUE;
}
/* Translation: */
if(translation_track_tag && (x != xbeginstrafe || y != ybeginstrafe) )
{
/* Modify factor 4 to get a lower/higher sensitivity. */
strafex = (gfloat) -4*(xbeginstrafe-x)/w;
strafey = (gfloat) 4*(ybeginstrafe-y)/h;
set_view_motion(strafex,strafey);
xbeginstrafe = x;
ybeginstrafe = y;
any_change = TRUE;
}
if(zoom_change == TRUE)
{
/* We need to rebuild the earth in this case or the sites
and lines would not be in proportion to the earth any more. */
newModel = 1;
makeearth();
}
else if(any_change == TRUE)
{
newModel = 1;
redraw(glarea, NULL);
}
return TRUE;
}
/**
* Called whenever any mouse button is pressed on the glarea.
*/
static gint
mouse_button_down(GtkWidget *wi, GdkEventButton *ev)
{
int site;
int x = (int)ev->x;
int y = (int)ev->y;
switch(ev->button)
{
case 1: /* Left button, rotation or selection */
// printf("Mouse 1 down!\n");
/* In case the user is trying to select a site */
site = which_site(x, y);
if(site != -1)
{
gtk_clist_select_row(GTK_CLIST(clist), site, 1);
/* Scroll the list here to make sure the listitem
is visible in the window. */
gtk_clist_moveto(GTK_CLIST(clist),site, 1, 0.5, 0.5);
break;
}
/* He wasn't, he's trying to rotate the earth. */
//printf("no site!\n");
xbegin = x;
ybegin = y;
/*vafan ? FIXME*/ zbegin = -1;
if(rotation_track_tag == 0) /* To prevent duplicate callbacks. */
rotation_track_tag = gtk_idle_add((GtkFunction)mouse_motion, wi);
break;
case 2: /* Middle button, translation */
// printf("Mouse 2 down!\n");
xbeginstrafe = x;
ybeginstrafe = y;
if(translation_track_tag == 0) /* To prevent duplicate callbacks. */
translation_track_tag = gtk_idle_add((GtkFunction)mouse_motion, wi);
break;
case 3: /* Right button, zoom */
// printf("Mouse 3 down!\n");
zbegin = y;
if(zoom_track_tag == 0) /* To prevent duplicate callbacks. */
zoom_track_tag = gtk_idle_add((GtkFunction)mouse_motion, wi);
break;
}
return TRUE;
}
/*-------------------------------------------------------------------------*/
/* mouse_button_up(): Called when any mouse button gets released. */
/*-------------------------------------------------------------------------*/
static gint
mouse_button_up(GtkWidget *wi, GdkEventButton *ev)
{
if(ev->button == 1 && rotation_track_tag != 0)
{
gtk_idle_remove(rotation_track_tag);
rotation_track_tag = 0;
// printf("Mouse 1 up!\n");
}
if(ev->button == 2 && translation_track_tag != 0)
{
gtk_idle_remove(translation_track_tag);
translation_track_tag = 0;
// printf("Mouse 2 up!\n");
}
if(ev->button == 3 && zoom_track_tag != 0)
{
gtk_idle_remove(zoom_track_tag);
zoom_track_tag = 0;
// printf("Mouse 3 up!\n");
}
return TRUE;
}
/**
* Makes sure the binary we're going to use is really there.
*/
static void
lookfor(const char* const program)
{
struct stat statbuf;
if(stat(program, &statbuf) < 0) {
char tmp[501];
g_snprintf(tmp,500,_("Can't find a binary I need!\n"
"I'm looking for \"%s\"."),program);
perror(tmp);
exit(EXIT_FAILURE);
}
if(! (statbuf.st_mode & S_IFREG) ) {
printf(_("Problem looking for \"%s\"! It isn't a regular file!\n")
,program);
exit(EXIT_FAILURE);
}
if(! (statbuf.st_mode & S_IXUSR) ) {
printf(_("%s isn't executable!\n"),program);
exit(EXIT_FAILURE);
}
DPRINTF("%s\t is there and looks OK.\n", program);
}
/**
* exit_program(): Guess?
*/
static void
exit_program(GtkWidget *wi, gpointer *data)
{
extern traceroute_state_t traceroute_state; // From extprog.c
if (traceroute_state.fd[0] != -1)
close(traceroute_state.fd[0]);
gtk_main_quit();
}
/**
* about_program()
*/
void
about_program(GtkWidget *wi, gpointer *data)
{
char mess[501];
int n;
n = g_snprintf(mess, sizeof(mess), _("%s%s\nBy Bjorn Augustsson\n"), _(versionstring), VERSION);
#ifdef HAVE_GEOIP
n += g_snprintf(mess+n, sizeof(mess)-n, "Uses GeoIP data from MaxMind\n");
#endif
tell_user(mess);
}
/*-------------------------------------------------------------------------*/
/* clist_item_selected() */
/*-------------------------------------------------------------------------*/
static gint
clist_item_selected(GtkCList *parentlist, gint row, gint column,
GdkEventButton *event)
{
if (event && event->type == GDK_2BUTTON_PRESS)
{
info_window(row); /* Double click detected */
}
else
{
int i;
if(sites[row].selected == 0)
{
/* Clear all other sites (so two sites can't be selected) */
for(i=0;i<MAX_SITES;i++)
sites[i].selected = 0;
sites[row].selected = 1;
infowin_change_site(row);
makeearth();
}
}
return TRUE;
}
/**
* info_button_callback()
*/
static gint
info_button_callback(GtkWidget *wi, gpointer *data)
{
int i;
for(i=0;i<MAX_SITES;i++)
if(sites[i].selected)
{
info_window(i);
return TRUE;
}
printf("Huh, no site selected!?\n");
/* Get into info-about-next-item-mode */
return TRUE;
}
#if 0
/*-------------------------------------------------------------------------*/
/* set_texture_name() : used to select a different map if a Map menu was */
/* enabled. */
/*-------------------------------------------------------------------------*/
static void
set_texture_name(gint number)
{
char texname[200];
strcpy(texname, DATADIR);
strcat(texname,"/");
strcat(texname, texture_name[number]);
g_print("Trying to load map [%s] ... ",texname);
earth_texture = readTexture(texname);
g_print("done.\n");
}
#endif //0
/*-------------------------------------------------------------------------*/
/* choose_transparency() : wrapper for set_transparency */
/*-------------------------------------------------------------------------*/
void choose_transparency (gpointer data, guint action, GtkWidget *w) {
set_transparency(action);
redraw(GTK_WIDGET(glarea), NULL);
}
#if 0
/*-------------------------------------------------------------------------*/
/* choose_map() */
/*-------------------------------------------------------------------------*/
void choose_map (GtkWidget *w, gpointer data ) {
set_texture_name((gint) data);
/* re-afficher la terre avec texture */
map_texture();
redraw(GTK_WIDGET(glarea), NULL);
}
#endif //0
/*-------------------------------------------------------------------------*/
/* choose_zoom() */
/*-------------------------------------------------------------------------*/
void choose_zoom (gpointer data, guint action, GtkWidget *w) {
set_zoom(action); /* the type of zoom is passed to the gl impl. */
newModel = 1;
recalcModelView();
makeearth(); /* makeearth calls redraw() */
}
/* Sets the lighting mode in the user settings.
* Also updates the texture if neccessary.
*
* This is used as a callback.
*/
void set_lighting_mode(gpointer data, guint action, GtkWidget *w)
{
// This is neccessary because the callback gets called when I
// set the defaults.
if(! GTK_WIDGET_REALIZED(w))
{
return;
}
if(user_settings->lighting_mode == (lighting_t)action)
{
// It wasn't a change.
return;
}
user_settings->lighting_mode = (lighting_t)action;
if (user_settings->lighting_mode == DAY_AND_NIGHT)
{
composite_texture(night_texture, earth_texture, &created_texture);
map_texture(created_texture);
}
else
map_texture(earth_texture);
}
/*-------------------------------------------------------------------------*/
/* menu_items[] : The menu struct */
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* build_menu() */
/*-------------------------------------------------------------------------*/
static void
build_menu( GtkWidget *window, GtkWidget **menubar )
{
/* strings are marked with a preceding N_() for translation purpose
see gettext()
*/
static GtkItemFactoryEntry menu_items[] = {
{ N_("/_File"), NULL, NULL, 0, "<Branch>" },
// { N_("/File/_New..."), "<control>O", (GtkItemFactoryCallback)new_trace, 0, NULL },
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
{ N_("/File/_Quit"), "<control>Q", exit_program, 0, NULL },
{ N_("/_Preferences"), NULL, NULL, 0, "<Branch>" },
{ N_("/Preferences/_Lighting"), NULL, NULL, 0, "<Branch>" },
{ N_("/Preferences/Lighting/Day and _night"),NULL, set_lighting_mode, DAY_AND_NIGHT, "<RadioItem>" },
{ N_("/Preferences/Lighting/_Day only"), NULL, set_lighting_mode, DAY_ONLY, "/Preferences/Lighting/Day and night" },
{ N_("/_Database"), NULL, NULL, 0, "<Branch>" },
{ N_("/Database/Add host..."), NULL, addHost, 0, NULL },
{ N_("/Database/Add net..."), NULL, addNet, 0, NULL },
{ N_("/Database/Add keyword..."), NULL, addGen, 0, NULL },
/*
{ N_("/_Map"), NULL, NULL, 0, "<Branch>" },
{ N_("/Map/Map one"), NULL, choose_map, 0, NULL },
{ N_("/Map/Map two"), NULL, choose_map, 1, NULL },
{ N_("/Map/Map three"), NULL, choose_map, 2, NULL },
*/
{ N_("/_View"), NULL, NULL, 0, "<Branch>" },
{ N_("/View/Zoom _In"), "<control>i", choose_zoom, 0, NULL },
{ N_("/View/Zoom _Out"), "<control>o", choose_zoom, 1, NULL },
{ N_("/View/Zoom In x2"), NULL, choose_zoom, 2, NULL },
{ N_("/View/Zoom Out x2"), NULL, choose_zoom, 3, NULL },
{ N_("/View/Restore default"), NULL, choose_zoom, 4, NULL },
{ N_("/_Transparency"), NULL, NULL, 0, "<Branch>" },
{ N_("/Transparency/Off"), NULL, choose_transparency, 0, NULL },
{ N_("/Transparency/On"), NULL, choose_transparency, 1, NULL },
{ N_("/_Help"), NULL, NULL, 0, "<LastBranch>" },
{ N_("/_Help/About"), NULL, about_program, 0, NULL },
};
gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
GtkAccelGroup *accel_group = gtk_accel_group_new();
GtkItemFactory *item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR,
"<main>", accel_group);
gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
/* Set the preferences */
switch(user_settings->lighting_mode)
{
case DAY_AND_NIGHT:
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM (
gtk_item_factory_get_item (item_factory,
"/Preferences/Lighting/Day and night")),
TRUE);
break;
case DAY_ONLY:
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(
gtk_item_factory_get_item (item_factory,
"/Preferences/Lighting/Day only")),
TRUE);
break;
default:
printf("Funky lighting mode making menu: %d\n",
user_settings->lighting_mode);
exit(EXIT_FAILURE);
}
/* Attach the new accelerator group to the window. */
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
if (menubar)
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}
/**
* Usage...
*/
static void
usage(void)
{
g_print(_("%s%s\n\n"
"Usage: xtraceroute [--texture <(day) texture file>]\n"
" [--ntexture <night texture file>]\n"
" [--night | --nonight]\n"
" [--lod <level-of-detail>]\n"
" [--stdin | - | <site> ]\n"
" [--version]\n"
" [--help]\n")
,_(versionstring), VERSION);
}
/**
* Handler for SIGCHLD. We get these when the extprogs die.
*/
static void
childhandler(int sig, siginfo_t* sip, void* uap)
{
pid_t pid = sip->si_pid;
extern traceroute_state_t traceroute_state;
// DPRINTF("pid: %ld died\n", (long)pid);
if(traceroute_state.pid == pid)
{
traceroute_state.pid = 0;
spinner_unref("traceroute");
}
else // It was a host process that died.
{
int i;
for(i=0 ; i<MAX_SITES ; i++)
{
if(sites[i].extpipe_pid == pid)
{
spinner_unref("host");
sites[i].extpipe_active = FALSE;
sites[i].extpipe_pid = 0;
goto out;
}
}
/* Maybe it was the initial one for localhost. */
if(local.extpipe_pid == pid)
{
spinner_unref("localhost");
goto out;
}
DPRINTF("Huh? Who was pid %d?\n", (int)pid);
spinner_unref("Unknown!");
}
out:
waitpid(pid, NULL, 0);
}
/**
* Adds a hostname to the lookup history in the combo widget.
*
* Maintains a 10-entry history.
*/
static void
combo_add_to_history(const char* name, GtkCombo* combo)
{
static GList *items = NULL;
char *newloc;
if(!(newloc = (char*)malloc(100)))
{
printf("unable to allocate memory for newloc in history!\n");
exit_program(NULL, NULL);
}
strncpy(newloc, name, 100);
items = g_list_prepend(items, newloc);
if(g_list_length(items) > 10)
{
char* item_to_remove = g_list_nth_data(items, 10);
items = g_list_remove(items, item_to_remove);
free(item_to_remove);
}
gtk_combo_set_popdown_strings (GTK_COMBO(combo), items);
}
#if 0
/**
* Callback function for the combo widget in the top of the screen.
* When you click on an entry in the history there, this gets called.
* It starts a new trace and adds the name to the history (again).
*
* The "list" argument is the gtk_list part of the combo widget that
* caused the signal, and "member" is the entry in the list.
*
* The "combo" argument is the combo widget itself.
*
* See also combo_entry_callback().
*/
static gint
combo_list_callback(GtkWidget *list,
GtkWidget *member,
gpointer *combo)
{
char* data;
gtk_label_get(GTK_LABEL(GTK_BIN(member)->child), &data);
DPRINTF("combo_list_callback called. member: %s\n", data);
if(!strcmp(user_settings->current_target, data))
{
// combo_add_to_history(data, GTK_COMBO(combo));
}
return(TRUE);
}
static gint
change_callback(GtkWidget *list,
GtkWidget *member,
gpointer *combo)
{ printf("change\n"); return(TRUE);}
static gint
combochange_callback(GtkWidget *list,
GtkWidget *member,
gpointer *combo)
{ printf("combo change\n"); return(TRUE);}
static gint
hide_callback(GtkWidget *list,
GtkWidget *member,
gpointer *combo)
{ printf("hide\n"); return(TRUE);}
#endif //0
/**
* Callback function for the combo widget in the top of the screen.
* When you press enter there, this gets called. It starts a new
* trace and adds the name to the history.
*
* The "entry" argument is the gtk_entry part of the combo widget that
* caused the signal.
*
* The "combo" argument is the combo widget itself.
*
* See also combo_list_callback().
*/
static gint
combo_entry_callback(GtkWidget *entry, gpointer *combo)
{
int i;
extern traceroute_state_t traceroute_state; // From extprog.c
/* Might make sense to have a better test for hostname
validity here. Nasty things might happen if there's
an ampersand character in the string for example, since
it gets passed to the shell via popen().
God I'm happy this won't run SUID root... :) */
/* Maybe tell_user here or something? */
/*
if(strlen(user_settings->current_target) < 2)
{
new_trace(NULL, NULL);
return TRUE;
}
*/
combo_add_to_history(gtk_entry_get_text(GTK_ENTRY(entry)),
GTK_COMBO(combo));
strcpy(user_settings->current_target, gtk_entry_get_text(GTK_ENTRY(entry)));
if(traceroute_state.fd[0] != -1)
{
gdk_input_remove(traceroute_state.tag); // Should this be here? Think so.
close(traceroute_state.fd[0]);
traceroute_state.fd[0] = -1;
}
traceroute_state.buffer_counter = 0;
for(i=0;i<MAX_SITES;i++)
{
sites[i].draw = 0;
sites[i].selected = 0;
/* Kill all possible extprograms still running. */
if(sites[i].extpipe_tag != 0)
{
gdk_input_remove(sites[i].extpipe_tag);
sites[i].extpipe_tag = 0;
if(sites[i].extpipe[0] != -1)
{
close(sites[i].extpipe[0]);
sites[i].extpipe[0] = -1;
}
}
sites[i].extpipe_data_counter = 0;
}
/* Clear the whole list. */
gtk_clist_clear(GTK_CLIST(clist));
makeearth();
calltrace();
return TRUE;
}
/**
* parse commandline arguments, and set relevant fields in the
* user_settings struct.
*
* Might make sense to use getopt for this.
*/
static void
parse_commandline(int argc, char *argv[])
{
int has_target = FALSE;
int has_texture = FALSE;
int has_night_texture = FALSE;
int has_night = FALSE;
int has_nonight = FALSE;
unsigned int i;
for(i=1; i < argc; i++) {
if (!strcmp(argv[i],"--version")) {
g_print("%s%s\n", _(versionstring), VERSION);
exit(EXIT_SUCCESS);
} else if(!strcmp(argv[i],"--help") ||