Make "put_string_list()" truly take a GList of strings as arguments;

generate such a list from the list of column format information and hand
the resulting list to "put_string_list()" when writing out the preference.

svn path=/trunk/; revision=3779
This commit is contained in:
Guy Harris 2001-07-23 00:12:47 +00:00
parent 91fe015bca
commit d7149c990b
1 changed files with 57 additions and 55 deletions

58
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.58 2001/07/22 22:41:37 guy Exp $
* $Id: prefs.c,v 1.59 2001/07/23 00:12:47 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -63,7 +63,6 @@
static int set_pref(gchar*, gchar*);
static GList *get_string_list(gchar *);
static gchar *put_string_list(GList *);
static void put_string_from_list(gchar *, int *, int *, gchar *);
static void clear_string_list(GList *);
static void free_col_info(e_prefs *);
@ -468,35 +467,16 @@ put_string_list(GList *sl)
{
static gchar pref_str[MAX_FMT_PREF_LEN] = "";
GList *clp = g_list_first(sl);
fmt_data *cfmt;
gchar *str;
int cur_pos = 0, cur_len = 0;
while (clp) {
cfmt = (fmt_data *) clp->data;
put_string_from_list(pref_str, &cur_pos, &cur_len, cfmt->title);
put_string_from_list(pref_str, &cur_pos, &cur_len, cfmt->fmt);
clp = clp->next;
}
/* If the string is at least two characters long, the last two characters
are ", ", and should be discarded, as there are no more items in the
string. */
if (cur_len >= 2)
pref_str[cur_len - 2] = '\0';
return(pref_str);
}
static void
put_string_from_list(gchar *pref_str, int *cur_posp, int *cur_lenp, gchar *str)
{
int cur_pos = *cur_posp;
int cur_len = *cur_lenp;
gchar *quoted_str;
int str_len;
gchar *strp, *quoted_strp, c;
int fmt_len;
while (clp) {
str = clp->data;
/* Allocate a buffer big enough to hold the entire string, with each
character quoted (that's the worst case). */
str_len = strlen(str);
@ -528,8 +508,16 @@ put_string_from_list(gchar *pref_str, int *cur_posp, int *cur_lenp, gchar *str)
cur_len += fmt_len;
}
g_free(quoted_str);
*cur_posp = cur_pos;
*cur_lenp = cur_len;
clp = clp->next;
}
/* If the string is at least two characters long, the last two characters
are ", ", and should be discarded, as there are no more items in the
string. */
if (cur_len >= 2)
pref_str[cur_len - 2] = '\0';
return(pref_str);
}
static void
@ -1446,6 +1434,8 @@ write_prefs(char **pf_path_return)
{
FILE *pf;
struct stat s_buf;
GList *clp, *col_l;
fmt_data *cfmt;
/* To do:
* - Split output lines longer than MAX_VAL_LEN
@ -1494,9 +1484,21 @@ write_prefs(char **pf_path_return)
"is set to \"command\"\n"
"%s: %s\n\n", PRS_PRINT_CMD, prefs.pr_cmd);
clp = prefs.col_list;
col_l = NULL;
while (clp) {
cfmt = (fmt_data *) clp->data;
col_l = g_list_append(col_l, cfmt->title);
col_l = g_list_append(col_l, cfmt->fmt);
clp = clp->next;
}
fprintf (pf, "# Packet list column format. Each pair of strings consists "
"of a column title \n# and its format.\n"
"%s: %s\n\n", PRS_COL_FMT, put_string_list(prefs.col_list));
"%s: %s\n\n", PRS_COL_FMT, put_string_list(col_l));
/* This frees the list of strings, but not the strings to which it
refers; that's what we want, as we haven't copied those strings,
we just referred to them. */
g_list_free(col_l);
fprintf (pf, "# TCP stream window color preferences. Each value is a six "
"digit hexadecimal value in the form rrggbb.\n");