* Added preference file saves and reads.
svn path=/trunk/; revision=75
This commit is contained in:
parent
3b9dda5d6b
commit
06e5aae0e3
|
@ -1,7 +1,7 @@
|
|||
/* capture.c
|
||||
* Routines for packet capture windows
|
||||
*
|
||||
* $Id: capture.c,v 1.7 1998/10/13 07:03:31 guy Exp $
|
||||
* $Id: capture.c,v 1.8 1998/10/28 21:38:06 gerald Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -281,7 +281,7 @@ capture_prep_cb(GtkWidget *w, gpointer d) {
|
|||
cancel_bt = gtk_button_new_with_label ("Cancel");
|
||||
gtk_signal_connect_object(GTK_OBJECT(cancel_bt), "clicked",
|
||||
GTK_SIGNAL_FUNC(capture_prep_close_cb), GTK_OBJECT(cap_open_w));
|
||||
GTK_WIDGET_SET_FLAGS(ok_bt, GTK_CAN_DEFAULT);
|
||||
GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
|
||||
gtk_box_pack_start (GTK_BOX (bbox), cancel_bt, TRUE, TRUE, 0);
|
||||
gtk_widget_show(cancel_bt);
|
||||
|
||||
|
|
15
ethereal.c
15
ethereal.c
|
@ -1,6 +1,6 @@
|
|||
/* ethereal.c
|
||||
*
|
||||
* $Id: ethereal.c,v 1.8 1998/10/16 06:44:32 guy Exp $
|
||||
* $Id: ethereal.c,v 1.9 1998/10/28 21:38:07 gerald Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -60,11 +60,11 @@
|
|||
#include "file.h"
|
||||
#include "menu.h"
|
||||
#include "etypes.h"
|
||||
#include "prefs.h"
|
||||
#include "print.h"
|
||||
#include "resolv.h"
|
||||
#include "follow.h"
|
||||
#include "util.h"
|
||||
#include "prefs.h"
|
||||
|
||||
FILE *data_out_file = NULL;
|
||||
packet_info pi;
|
||||
|
@ -76,8 +76,6 @@ guint main_ctx, file_ctx;
|
|||
frame_data *fd;
|
||||
gint start_capture = 0;
|
||||
|
||||
extern pr_opts printer_opts;
|
||||
|
||||
ts_type timestamp_type = RELATIVE;
|
||||
|
||||
#define E_DFILTER_TE_KEY "display_filter_te"
|
||||
|
@ -387,6 +385,8 @@ main(int argc, char *argv[])
|
|||
cf.save_file = NULL;
|
||||
cf.snap = 68;
|
||||
cf.count = 0;
|
||||
|
||||
read_prefs();
|
||||
|
||||
/* Let GTK get its args */
|
||||
gtk_init (&argc, &argv);
|
||||
|
@ -465,13 +465,6 @@ main(int argc, char *argv[])
|
|||
sprintf(rc_file, "%s/%s", getenv("HOME"), RC_FILE);
|
||||
gtk_rc_parse(rc_file);
|
||||
|
||||
/* initialize printer options. temporary! we should only initialize
|
||||
* if the options are not set in some ethereal initialization file */
|
||||
printer_opts.output_format = 0;
|
||||
printer_opts.output_dest = 0;
|
||||
printer_opts.file = g_strdup("ethereal.out");
|
||||
printer_opts.cmd = g_strdup("lpr");
|
||||
|
||||
if ((m_r_font = gdk_font_load(medium_font)) == NULL) {
|
||||
fprintf(stderr, "Error font %s not found (use -m option)\n", medium_font);
|
||||
exit(1);
|
||||
|
|
4
menu.c
4
menu.c
|
@ -1,7 +1,7 @@
|
|||
/* menu.c
|
||||
* Menu routines
|
||||
*
|
||||
* $Id: menu.c,v 1.8 1998/10/16 01:18:29 gerald Exp $
|
||||
* $Id: menu.c,v 1.9 1998/10/28 21:38:08 gerald Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -38,9 +38,9 @@
|
|||
#include "ethereal.h"
|
||||
#include "capture.h"
|
||||
#include "packet.h"
|
||||
#include "prefs.h"
|
||||
#include "print.h"
|
||||
#include "follow.h"
|
||||
#include "prefs.h"
|
||||
|
||||
/* Much of this was take from the GTK+ tuturial at http://www.gtk.org */
|
||||
|
||||
|
|
219
prefs.c
219
prefs.c
|
@ -1,7 +1,7 @@
|
|||
/* prefs.c
|
||||
* Routines for handling preferences
|
||||
*
|
||||
* $Id: prefs.c,v 1.7 1998/10/16 01:18:33 gerald Exp $
|
||||
* $Id: prefs.c,v 1.8 1998/10/28 21:38:09 gerald Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -36,11 +36,24 @@
|
|||
#include "ethereal.h"
|
||||
#include "packet.h"
|
||||
#include "file.h"
|
||||
#include "prefs.h"
|
||||
#include "print.h"
|
||||
#include "filter.h"
|
||||
#include "prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
extern capture_file cf;
|
||||
/* Internal functions */
|
||||
static int set_prefs(gchar*, gchar*);
|
||||
static void write_prefs();
|
||||
static void prefs_main_ok_cb(GtkWidget *, gpointer);
|
||||
static void prefs_main_save_cb(GtkWidget *, gpointer);
|
||||
static void prefs_main_cancel_cb(GtkWidget *, gpointer);
|
||||
|
||||
e_prefs prefs;
|
||||
static int init_prefs = 1;
|
||||
|
||||
#define PF_NAME ".ethereal/preferences"
|
||||
|
||||
static gchar *pf_path = NULL;
|
||||
|
||||
void
|
||||
prefs_cb(GtkWidget *w, gpointer sp) {
|
||||
|
@ -137,7 +150,9 @@ prefs_main_ok_cb(GtkWidget *w, gpointer win) {
|
|||
|
||||
void
|
||||
prefs_main_save_cb(GtkWidget *w, gpointer win) {
|
||||
printer_prefs_save(gtk_object_get_data(GTK_OBJECT(win), E_PRINT_PAGE_KEY));
|
||||
filter_prefs_save(gtk_object_get_data(GTK_OBJECT(win), E_FILTER_PAGE_KEY));
|
||||
write_prefs();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -148,3 +163,201 @@ prefs_main_cancel_cb(GtkWidget *w, gpointer win) {
|
|||
gtk_widget_destroy(GTK_WIDGET(win));
|
||||
}
|
||||
|
||||
/* Preferences file format:
|
||||
* - Configuration directives start at the beginning of the line, and
|
||||
* are terminated with a colon.
|
||||
* - Directives can be continued on the next line by preceding them with
|
||||
* whitespace.
|
||||
*
|
||||
* Example:
|
||||
|
||||
# This is a comment line
|
||||
print.command: lpr
|
||||
print.file: /a/very/long/path/
|
||||
to/ethereal-out.ps
|
||||
*
|
||||
*/
|
||||
|
||||
#define MAX_VAR_LEN 32
|
||||
#define MAX_VAL_LEN 256
|
||||
void
|
||||
read_prefs() {
|
||||
enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
|
||||
FILE *pf;
|
||||
gchar cur_var[MAX_VAR_LEN], cur_val[MAX_VAL_LEN];
|
||||
int got_c, state = START;
|
||||
gint var_len = 0, val_len = 0, fline = 1, pline = 1;
|
||||
|
||||
/* Initialize preferences. With any luck, these values will be
|
||||
overwritten below. */
|
||||
if (init_prefs) {
|
||||
init_prefs = 0;
|
||||
prefs.pr_format = PR_FMT_TEXT;
|
||||
prefs.pr_dest = PR_DEST_CMD;
|
||||
prefs.pr_file = g_strdup("ethereal.out");
|
||||
prefs.pr_cmd = g_strdup("lpr");
|
||||
}
|
||||
|
||||
if (! pf_path) {
|
||||
pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_NAME) + 4);
|
||||
sprintf(pf_path, "%s/%s", getenv("HOME"), PF_NAME);
|
||||
}
|
||||
|
||||
if ((pf = fopen(pf_path, "r")) == NULL) {
|
||||
simple_dialog(ESD_TYPE_WARN, NULL,
|
||||
"Can't open preferences file\n\"%s\".");
|
||||
return;
|
||||
}
|
||||
|
||||
while ((got_c = getc(pf)) != EOF) {
|
||||
if (got_c == '\n') {
|
||||
state = START;
|
||||
fline++;
|
||||
continue;
|
||||
}
|
||||
if (var_len >= MAX_VAR_LEN) {
|
||||
g_warning ("%s line %d: Variable too long", pf_path, fline);
|
||||
state = IN_SKIP;
|
||||
var_len = 0;
|
||||
continue;
|
||||
}
|
||||
if (val_len >= MAX_VAL_LEN) {
|
||||
g_warning ("%s line %d: Value too long", pf_path, fline);
|
||||
state = IN_SKIP;
|
||||
var_len = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case START:
|
||||
if (isalnum(got_c)) {
|
||||
state = IN_VAR;
|
||||
if (var_len > 0) {
|
||||
cur_var[var_len] = '\0';
|
||||
cur_val[val_len] = '\0';
|
||||
if (! set_pref(cur_var, cur_val))
|
||||
g_warning ("%s line %d: Bogus preference", pf_path, pline);
|
||||
}
|
||||
cur_var[0] = got_c;
|
||||
var_len = 1;
|
||||
pline = fline;
|
||||
} else if (isspace(got_c) && var_len > 0) {
|
||||
state = PRE_VAL;
|
||||
} else if (got_c == '#') {
|
||||
state = IN_SKIP;
|
||||
} else {
|
||||
g_warning ("%s line %d: Malformed line", pf_path, fline);
|
||||
}
|
||||
break;
|
||||
case IN_VAR:
|
||||
if (got_c != ':') {
|
||||
cur_var[var_len] = got_c;
|
||||
var_len++;
|
||||
} else {
|
||||
state = PRE_VAL;
|
||||
val_len = 0;
|
||||
}
|
||||
break;
|
||||
case PRE_VAL:
|
||||
if (!isspace(got_c)) {
|
||||
state = IN_VAL;
|
||||
cur_val[val_len] = got_c;
|
||||
val_len++;
|
||||
}
|
||||
break;
|
||||
case IN_VAL:
|
||||
cur_val[val_len] = got_c;
|
||||
val_len++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (var_len > 0) {
|
||||
cur_var[var_len] = '\0';
|
||||
cur_val[val_len] = '\0';
|
||||
if (! set_pref(cur_var, cur_val))
|
||||
g_warning ("%s line %d: Bogus preference", pf_path, pline);
|
||||
}
|
||||
fclose(pf);
|
||||
}
|
||||
|
||||
#define PRS_PRINT_FMT "print.format"
|
||||
#define PRS_PRINT_DEST "print.destination"
|
||||
#define PRS_PRINT_FILE "print.file"
|
||||
#define PRS_PRINT_CMD "print.command"
|
||||
|
||||
static gchar *pr_formats[] = { "text", "postscript" };
|
||||
static gchar *pr_dests[] = { "command", "file" };
|
||||
|
||||
int
|
||||
set_pref(gchar *pref, gchar *value) {
|
||||
|
||||
if (strcmp(pref, PRS_PRINT_FMT) == 0) {
|
||||
if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) {
|
||||
prefs.pr_format = PR_FMT_TEXT;
|
||||
} else if (strcmp(value, pr_formats[PR_FMT_PS]) == 0) {
|
||||
prefs.pr_format = PR_FMT_PS;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else if (strcmp(pref, PRS_PRINT_DEST) == 0) {
|
||||
if (strcmp(value, pr_dests[PR_DEST_CMD]) == 0) {
|
||||
prefs.pr_dest = PR_DEST_CMD;
|
||||
} else if (strcmp(value, pr_dests[PR_DEST_FILE]) == 0) {
|
||||
prefs.pr_dest = PR_DEST_FILE;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else if (strcmp(pref, PRS_PRINT_FILE) == 0) {
|
||||
if (prefs.pr_file) g_free(prefs.pr_file);
|
||||
prefs.pr_file = g_strdup(value);
|
||||
} else if (strcmp(pref, PRS_PRINT_CMD) == 0) {
|
||||
if (prefs.pr_cmd) g_free(prefs.pr_cmd);
|
||||
prefs.pr_cmd = g_strdup(value);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
write_prefs() {
|
||||
FILE *pf;
|
||||
|
||||
/* To do: Split output lines longer than MAX_VAL_LEN */
|
||||
|
||||
if (! pf_path) {
|
||||
pf_path = (gchar *) g_malloc(strlen(getenv("HOME")) + strlen(PF_NAME) + 4);
|
||||
sprintf(pf_path, "%s/%s", getenv("HOME"), PF_NAME);
|
||||
}
|
||||
|
||||
if ((pf = fopen(pf_path, "w")) == NULL) {
|
||||
simple_dialog(ESD_TYPE_WARN, NULL,
|
||||
"Can't open preferences file\n\"%s\".");
|
||||
return;
|
||||
}
|
||||
|
||||
fputs("# Configuration file for Ethereal " VERSION ".\n"
|
||||
"#\n"
|
||||
"# This file is regenerated each time preferences are saved within\n"
|
||||
"# Ethereal. Making manual changes should be safe, however.\n"
|
||||
"\n"
|
||||
"######## Printing ########\n"
|
||||
"\n", pf);
|
||||
|
||||
fprintf (pf, "# Can be one of \"text\" or \"postscript\".\n"
|
||||
"print.format: %s\n\n", pr_formats[prefs.pr_format]);
|
||||
|
||||
fprintf (pf, "# Can be one of \"command\" or \"file\".\n"
|
||||
"print.destination: %s\n\n", pr_dests[prefs.pr_dest]);
|
||||
|
||||
fprintf (pf, "# This is the file that gets written to when the "
|
||||
"destination is set to \"file\"\n"
|
||||
"%s: %s\n\n", PRS_PRINT_FILE, prefs.pr_file);
|
||||
|
||||
fprintf (pf, "# Output gets piped to this command when the destination "
|
||||
"is set to \"command\"\n"
|
||||
"%s: %s\n", PRS_PRINT_CMD, prefs.pr_cmd);
|
||||
|
||||
fclose(pf);
|
||||
}
|
||||
|
|
19
prefs.h
19
prefs.h
|
@ -1,7 +1,7 @@
|
|||
/* prefs.h
|
||||
* Definitions for preference handling routines
|
||||
*
|
||||
* $Id: prefs.h,v 1.3 1998/10/12 01:40:55 gerald Exp $
|
||||
* $Id: prefs.h,v 1.4 1998/10/28 21:38:10 gerald Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@zing.org>
|
||||
|
@ -26,6 +26,19 @@
|
|||
#ifndef __PREFS_H__
|
||||
#define __PREFS_H__
|
||||
|
||||
#define PR_FMT_TEXT 0
|
||||
#define PR_FMT_PS 1
|
||||
|
||||
#define PR_DEST_CMD 0
|
||||
#define PR_DEST_FILE 1
|
||||
|
||||
typedef struct _e_prefs {
|
||||
gint pr_format;
|
||||
gint pr_dest;
|
||||
gchar *pr_file;
|
||||
gchar *pr_cmd;
|
||||
} e_prefs;
|
||||
|
||||
#define E_PR_PG_NONE -1
|
||||
#define E_PR_PG_PRINTING 0
|
||||
#define E_PR_PG_FILTER 1
|
||||
|
@ -36,8 +49,6 @@
|
|||
#define E_FILT_TE_PTR_KEY "filter_te_ptr"
|
||||
|
||||
void prefs_cb(GtkWidget *, gpointer);
|
||||
void prefs_main_ok_cb(GtkWidget *, gpointer);
|
||||
void prefs_main_save_cb(GtkWidget *, gpointer);
|
||||
void prefs_main_cancel_cb(GtkWidget *, gpointer);
|
||||
void read_prefs();
|
||||
|
||||
#endif /* prefs.h */
|
||||
|
|
181
print.c
181
print.c
|
@ -1,7 +1,7 @@
|
|||
/* print.c
|
||||
* Routines for printing packet analysis trees.
|
||||
*
|
||||
* $Id: print.c,v 1.7 1998/10/22 19:10:17 gram Exp $
|
||||
* $Id: print.c,v 1.8 1998/10/28 21:38:11 gerald Exp $
|
||||
*
|
||||
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
|
||||
*
|
||||
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "ethereal.h"
|
||||
#include "packet.h"
|
||||
#include "prefs.h"
|
||||
#include "print.h"
|
||||
#include "ps.h"
|
||||
|
||||
|
@ -52,200 +53,188 @@ static void dumpit_ps (FILE *fh, register const u_char *cp, register u_int lengt
|
|||
static void ps_clean_string(unsigned char *out, const unsigned char *in,
|
||||
int outbuf_size);
|
||||
|
||||
extern e_prefs prefs;
|
||||
|
||||
/* #include "ps.c" */
|
||||
|
||||
pr_opts printer_opts;
|
||||
|
||||
/* Key for gtk_object_set_data */
|
||||
const gchar *print_prefs_key = "printer_prefs_data";
|
||||
#define PRINT_CMD_TE_KEY "printer_command_entry"
|
||||
#define PRINT_FILE_TE_KEY "printer_file_entry"
|
||||
|
||||
GtkWidget * printer_prefs_show()
|
||||
{
|
||||
GtkWidget *main_vb, *button;
|
||||
GtkWidget *main_vb, *main_tb, *button;
|
||||
GtkWidget *format_hb, *format_lb;
|
||||
GtkWidget *dest_hb, *dest_lb;
|
||||
GtkWidget *cmd_hb, *cmd_lb, *cmd_te;
|
||||
GtkWidget *file_hb, *file_bt, *file_te;
|
||||
GtkWidget *cmd_lb, *cmd_te;
|
||||
GtkWidget *file_bt_hb, *file_bt, *file_te;
|
||||
GSList *format_grp, *dest_grp;
|
||||
pr_opts *temp_pr_opts = g_malloc(sizeof(pr_opts));
|
||||
|
||||
/* Make a working copy of the printer data */
|
||||
memcpy(temp_pr_opts, &printer_opts, sizeof(pr_opts));
|
||||
/* temp_pr_opts->cmd = g_strdup(printer_opts->cmd);
|
||||
temp_pr_opts->file = g_strdup(printer_opts->file);*/
|
||||
/* Enclosing containers for each row of widgets */
|
||||
main_vb = gtk_vbox_new(FALSE, 5);
|
||||
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
||||
|
||||
/* Container for each row of widgets */
|
||||
main_vb = gtk_vbox_new(FALSE, 3);
|
||||
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
|
||||
gtk_widget_show(main_vb);
|
||||
gtk_object_set_data(GTK_OBJECT(main_vb), print_prefs_key,
|
||||
temp_pr_opts);
|
||||
main_tb = gtk_table_new(4, 2, FALSE);
|
||||
gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
|
||||
gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
|
||||
gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
|
||||
gtk_widget_show(main_tb);
|
||||
|
||||
/* Output format */
|
||||
format_hb = gtk_hbox_new(FALSE, 1);
|
||||
gtk_container_add(GTK_CONTAINER(main_vb), format_hb);
|
||||
gtk_widget_show(format_hb);
|
||||
|
||||
format_lb = gtk_label_new("Format:");
|
||||
gtk_box_pack_start(GTK_BOX(format_hb), format_lb, FALSE, FALSE, 3);
|
||||
gtk_misc_set_alignment(GTK_MISC(format_lb), 1.0, 0.5);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), format_lb, 0, 1, 0, 1);
|
||||
gtk_widget_show(format_lb);
|
||||
|
||||
format_hb = gtk_hbox_new(FALSE, 0);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), format_hb, 1, 2, 0, 1);
|
||||
gtk_widget_show(format_hb);
|
||||
|
||||
button = gtk_radio_button_new_with_label(NULL, "Plain Text");
|
||||
if (printer_opts.output_format == 0) {
|
||||
if (prefs.pr_format == PR_FMT_TEXT) {
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
}
|
||||
format_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
|
||||
gtk_box_pack_start(GTK_BOX(format_hb), button, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
|
||||
gtk_widget_show(button);
|
||||
|
||||
button = gtk_radio_button_new_with_label(format_grp, "PostScript");
|
||||
if (printer_opts.output_format == 1) {
|
||||
if (prefs.pr_format == PR_FMT_PS) {
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
}
|
||||
gtk_signal_connect(GTK_OBJECT(button), "toggled",
|
||||
GTK_SIGNAL_FUNC(printer_opts_toggle_format),
|
||||
(gpointer)temp_pr_opts);
|
||||
gtk_box_pack_start(GTK_BOX(format_hb), button, TRUE, TRUE, 0);
|
||||
GTK_SIGNAL_FUNC(printer_opts_toggle_format), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(format_hb), button, FALSE, FALSE, 10);
|
||||
gtk_widget_show(button);
|
||||
|
||||
/* Output destination */
|
||||
dest_hb = gtk_hbox_new(FALSE, 1);
|
||||
gtk_container_add(GTK_CONTAINER(main_vb), dest_hb);
|
||||
gtk_widget_show(dest_hb);
|
||||
|
||||
dest_lb = gtk_label_new("Print to:");
|
||||
gtk_box_pack_start(GTK_BOX(dest_hb), dest_lb, FALSE, FALSE, 3);
|
||||
gtk_misc_set_alignment(GTK_MISC(dest_lb), 1.0, 0.5);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_lb, 0, 1, 1, 2);
|
||||
gtk_widget_show(dest_lb);
|
||||
|
||||
dest_hb = gtk_hbox_new(FALSE, 0);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), dest_hb, 1, 2, 1, 2);
|
||||
gtk_widget_show(dest_hb);
|
||||
|
||||
button = gtk_radio_button_new_with_label(NULL, "Command");
|
||||
if (printer_opts.output_dest == 0) {
|
||||
if (prefs.pr_dest == PR_DEST_CMD) {
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
}
|
||||
dest_grp = gtk_radio_button_group(GTK_RADIO_BUTTON(button));
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
gtk_box_pack_start(GTK_BOX(dest_hb), button, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
|
||||
gtk_widget_show(button);
|
||||
|
||||
button = gtk_radio_button_new_with_label(dest_grp, "File");
|
||||
if (printer_opts.output_dest == 1) {
|
||||
if (prefs.pr_dest == PR_DEST_FILE) {
|
||||
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), TRUE);
|
||||
}
|
||||
gtk_signal_connect(GTK_OBJECT(button), "toggled",
|
||||
GTK_SIGNAL_FUNC(printer_opts_toggle_dest),
|
||||
(gpointer)temp_pr_opts);
|
||||
gtk_box_pack_start(GTK_BOX(dest_hb), button, TRUE, TRUE, 0);
|
||||
GTK_SIGNAL_FUNC(printer_opts_toggle_dest), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(dest_hb), button, FALSE, FALSE, 10);
|
||||
gtk_widget_show(button);
|
||||
|
||||
/* Command text entry */
|
||||
cmd_hb = gtk_hbox_new(FALSE, 1);
|
||||
gtk_container_add(GTK_CONTAINER(main_vb), cmd_hb);
|
||||
gtk_widget_show(cmd_hb);
|
||||
|
||||
cmd_lb = gtk_label_new("Command:");
|
||||
gtk_box_pack_start(GTK_BOX(cmd_hb), cmd_lb, FALSE, FALSE, 3);
|
||||
gtk_misc_set_alignment(GTK_MISC(cmd_lb), 1.0, 0.5);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_lb, 0, 1, 2, 3);
|
||||
gtk_widget_show(cmd_lb);
|
||||
|
||||
cmd_te = gtk_entry_new();
|
||||
temp_pr_opts->cmd_te = cmd_te;
|
||||
gtk_entry_set_text(GTK_ENTRY(cmd_te), printer_opts.cmd);
|
||||
gtk_box_pack_start(GTK_BOX(cmd_hb), cmd_te, TRUE, TRUE, 3);
|
||||
gtk_object_set_data(GTK_OBJECT(main_vb), PRINT_CMD_TE_KEY, cmd_te);
|
||||
if (prefs.pr_cmd) gtk_entry_set_text(GTK_ENTRY(cmd_te), prefs.pr_cmd);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), cmd_te, 1, 2, 2, 3);
|
||||
gtk_widget_show(cmd_te);
|
||||
|
||||
/* File button and text entry */
|
||||
file_hb = gtk_hbox_new(FALSE, 1);
|
||||
gtk_container_add(GTK_CONTAINER(main_vb), file_hb);
|
||||
gtk_widget_show(file_hb);
|
||||
file_bt_hb = gtk_hbox_new(FALSE, 0);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), file_bt_hb, 0, 1, 3, 4);
|
||||
gtk_widget_show(file_bt_hb);
|
||||
|
||||
file_bt = gtk_button_new_with_label("File:");
|
||||
gtk_box_pack_start(GTK_BOX(file_hb), file_bt, FALSE, FALSE, 3);
|
||||
gtk_box_pack_end(GTK_BOX(file_bt_hb), file_bt, FALSE, FALSE, 0);
|
||||
gtk_widget_show(file_bt);
|
||||
|
||||
file_te = gtk_entry_new();
|
||||
temp_pr_opts->file_te = file_te;
|
||||
gtk_entry_set_text(GTK_ENTRY(file_te), printer_opts.file);
|
||||
gtk_box_pack_start(GTK_BOX(file_hb), file_te, TRUE, TRUE, 3);
|
||||
gtk_object_set_data(GTK_OBJECT(main_vb), PRINT_FILE_TE_KEY, file_te);
|
||||
if (prefs.pr_file) gtk_entry_set_text(GTK_ENTRY(file_te), prefs.pr_file);
|
||||
gtk_table_attach_defaults(GTK_TABLE(main_tb), file_te, 1, 2, 3, 4);
|
||||
gtk_widget_show(file_te);
|
||||
|
||||
gtk_signal_connect_object(GTK_OBJECT(file_bt), "clicked",
|
||||
GTK_SIGNAL_FUNC(printer_opts_file_cb), GTK_OBJECT(file_te));
|
||||
|
||||
|
||||
gtk_widget_show(main_vb);
|
||||
return(main_vb);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
printer_opts_file_cb(GtkWidget *w, gpointer te) {
|
||||
GtkWidget *fs, **w_list;
|
||||
GtkWidget *fs;
|
||||
|
||||
w_list = g_malloc(2 * sizeof(GtkWidget *));
|
||||
|
||||
fs = gtk_file_selection_new ("Ethereal: Print to a File");
|
||||
w_list[0] = fs;
|
||||
w_list[1] = (GtkWidget *) te;
|
||||
gtk_object_set_data(GTK_OBJECT(fs), PRINT_FILE_TE_KEY, te);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
|
||||
"clicked", (GtkSignalFunc) printer_opts_fs_ok_cb, w_list);
|
||||
"clicked", (GtkSignalFunc) printer_opts_fs_ok_cb, fs);
|
||||
|
||||
/* Connect the cancel_button to destroy the widget */
|
||||
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->cancel_button),
|
||||
"clicked", (GtkSignalFunc) printer_opts_fs_cancel_cb, w_list);
|
||||
"clicked", (GtkSignalFunc) printer_opts_fs_cancel_cb, fs);
|
||||
|
||||
gtk_widget_show(fs);
|
||||
}
|
||||
|
||||
static void
|
||||
printer_opts_fs_ok_cb(GtkWidget *w, gpointer data) {
|
||||
GtkWidget **w_list = (GtkWidget **) data;
|
||||
|
||||
gtk_entry_set_text(GTK_ENTRY(w_list[1]),
|
||||
gtk_file_selection_get_filename (GTK_FILE_SELECTION(w_list[0])));
|
||||
gtk_entry_set_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(data),
|
||||
PRINT_FILE_TE_KEY)),
|
||||
gtk_file_selection_get_filename (GTK_FILE_SELECTION(data)));
|
||||
printer_opts_fs_cancel_cb(w, data);
|
||||
}
|
||||
|
||||
static void
|
||||
printer_opts_fs_cancel_cb(GtkWidget *w, gpointer data) {
|
||||
GtkWidget **w_list = (GtkWidget **) data;
|
||||
|
||||
gtk_widget_destroy(w_list[0]);
|
||||
g_free(data);
|
||||
gtk_widget_destroy(GTK_WIDGET(data));
|
||||
}
|
||||
|
||||
void
|
||||
printer_prefs_ok(GtkWidget *w)
|
||||
{
|
||||
pr_opts *data = gtk_object_get_data(GTK_OBJECT(w), print_prefs_key);
|
||||
|
||||
printer_opts.output_format = ((pr_opts*)data)->output_format;
|
||||
printer_opts.output_dest = ((pr_opts*)data)->output_dest;
|
||||
if(prefs.pr_cmd) g_free(prefs.pr_cmd);
|
||||
prefs.pr_cmd =
|
||||
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
|
||||
PRINT_CMD_TE_KEY))));
|
||||
|
||||
free(printer_opts.cmd);
|
||||
printer_opts.cmd =
|
||||
g_strdup(gtk_entry_get_text(GTK_ENTRY(((pr_opts*)data)->cmd_te)));
|
||||
if(prefs.pr_file) g_free(prefs.pr_file);
|
||||
prefs.pr_file =
|
||||
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(w),
|
||||
PRINT_FILE_TE_KEY))));
|
||||
}
|
||||
|
||||
free(printer_opts.file);
|
||||
printer_opts.file =
|
||||
g_strdup(gtk_entry_get_text(GTK_ENTRY(((pr_opts*)data)->file_te)));
|
||||
|
||||
g_free(data);
|
||||
void
|
||||
printer_prefs_save(GtkWidget *w)
|
||||
{
|
||||
printer_prefs_ok(w);
|
||||
}
|
||||
|
||||
void
|
||||
printer_prefs_cancel(GtkWidget *w)
|
||||
{
|
||||
pr_opts *data = gtk_object_get_data(GTK_OBJECT(w), print_prefs_key);
|
||||
|
||||
g_free(data);
|
||||
}
|
||||
|
||||
static void
|
||||
printer_opts_toggle_format(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
if (GTK_TOGGLE_BUTTON (widget)->active) {
|
||||
((pr_opts*)data)->output_format = 1;
|
||||
prefs.pr_format = PR_FMT_PS;
|
||||
/* toggle file/cmd */
|
||||
}
|
||||
else {
|
||||
((pr_opts*)data)->output_format = 0;
|
||||
prefs.pr_format = PR_FMT_TEXT;
|
||||
/* toggle file/cmd */
|
||||
}
|
||||
}
|
||||
|
@ -254,10 +243,10 @@ static void
|
|||
printer_opts_toggle_dest(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
if (GTK_TOGGLE_BUTTON (widget)->active) {
|
||||
((pr_opts*)data)->output_dest = 1;
|
||||
prefs.pr_dest = PR_DEST_FILE;
|
||||
}
|
||||
else {
|
||||
((pr_opts*)data)->output_dest = 0;
|
||||
prefs.pr_dest = PR_DEST_CMD;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,13 +257,13 @@ void print_tree(const u_char *pd, frame_data *fd, GtkTree *tree)
|
|||
char *out;
|
||||
|
||||
/* Open the file or command for output */
|
||||
if (printer_opts.output_dest == 0) {
|
||||
out = printer_opts.cmd;
|
||||
fh = popen(printer_opts.cmd, "w");
|
||||
if (prefs.pr_dest == PR_DEST_CMD) {
|
||||
out = prefs.pr_cmd;
|
||||
fh = popen(prefs.pr_cmd, "w");
|
||||
}
|
||||
else {
|
||||
out = printer_opts.file;
|
||||
fh = fopen(printer_opts.file, "w");
|
||||
out = prefs.pr_file;
|
||||
fh = fopen(prefs.pr_file, "w");
|
||||
}
|
||||
|
||||
if (!fh) {
|
||||
|
@ -283,7 +272,7 @@ void print_tree(const u_char *pd, frame_data *fd, GtkTree *tree)
|
|||
}
|
||||
|
||||
/* Create the output */
|
||||
if (printer_opts.output_format == 0) {
|
||||
if (prefs.pr_format == PR_FMT_TEXT) {
|
||||
print_tree_text(fh, pd, fd, tree);
|
||||
}
|
||||
else {
|
||||
|
@ -293,7 +282,7 @@ void print_tree(const u_char *pd, frame_data *fd, GtkTree *tree)
|
|||
}
|
||||
|
||||
/* Close the file or command */
|
||||
if (printer_opts.output_dest == 0) {
|
||||
if (prefs.pr_dest == PR_DEST_CMD) {
|
||||
pclose(fh);
|
||||
}
|
||||
else {
|
||||
|
|
14
print.h
14
print.h
|
@ -1,7 +1,7 @@
|
|||
/* print.h
|
||||
* Definitions for printing packet analysis trees.
|
||||
*
|
||||
* $Id: print.h,v 1.5 1998/10/10 03:32:20 gerald Exp $
|
||||
* $Id: print.h,v 1.6 1998/10/28 21:38:11 gerald Exp $
|
||||
*
|
||||
* Gilbert Ramirez <gram@verdict.uthscsa.edu>
|
||||
*
|
||||
|
@ -28,21 +28,11 @@
|
|||
#ifndef __PRINT_H__
|
||||
#define __PRINT_H__
|
||||
|
||||
typedef struct pr_opts {
|
||||
int output_format; /* 0=text, 1=postscript */
|
||||
int output_dest; /* 0=cmd, 1=file */
|
||||
char *file;
|
||||
char *cmd;
|
||||
|
||||
/* for the dialogue box */
|
||||
GtkWidget *cmd_te;
|
||||
GtkWidget *file_te;
|
||||
} pr_opts;
|
||||
|
||||
/* Functions in print.h */
|
||||
|
||||
GtkWidget *printer_prefs_show();
|
||||
void printer_prefs_ok(GtkWidget *w);
|
||||
void printer_prefs_save(GtkWidget *w);
|
||||
void printer_prefs_cancel(GtkWidget *w);
|
||||
void print_tree(const u_char *pd, frame_data *fd, GtkTree *tree);
|
||||
void print_tree_text(FILE *fh, const u_char *pd, frame_data *fd, GtkTree *tree);
|
||||
|
|
Loading…
Reference in New Issue