34 |
/* |
/* |
35 |
* Recall history and copy into the appropriate GList. |
* Recall history and copy into the appropriate GList. |
36 |
*/ |
*/ |
37 |
void loadhistory(void) |
void |
38 |
|
loadhistory (void) |
39 |
{ |
{ |
40 |
gchar *historyfile, history[1024], **histsplit = NULL; |
gchar *historyfile, history[1024], **histsplit = NULL; |
41 |
FILE *fp; |
FILE *fp; |
42 |
|
|
43 |
historyfile = g_strconcat(xlogdir, G_DIR_SEPARATOR_S, "history", NULL); |
historyfile = g_strconcat (xlogdir, G_DIR_SEPARATOR_S, "history", NULL); |
44 |
fp = fopen(historyfile,"r"); |
fp = fopen (historyfile, "r"); |
45 |
if (fp != NULL) |
if (fp != NULL) |
46 |
|
{ |
47 |
|
while (!feof (fp)) |
48 |
{ |
{ |
49 |
while(!feof(fp)) |
if (fscanf (fp, "%s", history) == EOF) |
50 |
{ |
break; |
51 |
if (fscanf(fp,"%s", history) == EOF) break; |
histsplit = g_strsplit (history, ":", 1); |
52 |
histsplit = g_strsplit(history, ":", 1); |
if (!g_strcasecmp (histsplit[0], "se")) |
53 |
if (!g_strcasecmp(histsplit[0], "se")) |
{ |
54 |
{ |
g_strdelimit (histsplit[1], "_", ' '); |
55 |
g_strdelimit(histsplit[1], "_", ' '); |
searchhistory = |
56 |
searchhistory = g_list_append(searchhistory, g_strdup(histsplit[1])); |
g_list_append (searchhistory, g_strdup (histsplit[1])); |
57 |
} |
} |
58 |
g_strfreev(histsplit); |
g_strfreev (histsplit); |
|
} |
|
|
fclose(fp); |
|
59 |
} |
} |
60 |
g_free(historyfile); |
fclose (fp); |
61 |
|
} |
62 |
|
g_free (historyfile); |
63 |
} |
} |
64 |
|
|
65 |
/* |
/* |
66 |
* Save history to ~/.xlog/history |
* Save history to ~/.xlog/history |
67 |
*/ |
*/ |
68 |
void savehistory(void) |
void |
69 |
|
savehistory (void) |
70 |
{ |
{ |
71 |
gchar *historyfile; |
gchar *historyfile; |
72 |
FILE *fp; |
FILE *fp; |
73 |
guint i, n; |
guint i, n; |
74 |
gchar *search; |
gchar *search; |
75 |
|
|
76 |
historyfile = g_strconcat(xlogdir, G_DIR_SEPARATOR_S, "history", NULL); |
historyfile = g_strconcat (xlogdir, G_DIR_SEPARATOR_S, "history", NULL); |
77 |
if ((g_list_length(searchhistory) > 0)) |
if ((g_list_length (searchhistory) > 0)) |
78 |
|
{ |
79 |
|
fp = fopen (historyfile, "w"); |
80 |
|
if (fp != NULL) |
81 |
{ |
{ |
82 |
fp = fopen(historyfile, "w"); |
if ((n = g_list_length (searchhistory)) > 0) |
83 |
if (fp != NULL) |
{ |
84 |
|
for (i = 0; i < n; i++) |
85 |
{ |
{ |
86 |
if ((n = g_list_length(searchhistory)) > 0) |
search = g_list_nth_data (searchhistory, i); |
87 |
{ |
g_strdelimit (search, " ", '_'); |
88 |
for(i = 0; i < n; i++) |
fprintf (fp, "se:%s\n", search); |
89 |
{ |
g_free (search); |
|
search = g_list_nth_data(searchhistory, i); |
|
|
g_strdelimit(search, " ", '_'); |
|
|
fprintf(fp, "se:%s\n", search); |
|
|
g_free(search); |
|
|
} |
|
|
} |
|
|
fclose(fp); |
|
90 |
} |
} |
91 |
|
} |
92 |
|
fclose (fp); |
93 |
} |
} |
94 |
g_free(historyfile); |
} |
95 |
|
g_free (historyfile); |
96 |
} |
} |
|
|
|