2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "file_history.h"
28 typedef struct _AnFileHistory
34 static AnFileHistory
*s_history
= NULL
;
36 static void an_file_history_init()
38 s_history
= g_new(AnFileHistory
, 1);
39 s_history
->items
= NULL
;
40 s_history
->current
= NULL
;
43 AnHistFile
*an_hist_file_new(const char *name
, glong line
)
47 g_return_val_if_fail(name
, NULL
);
48 h_file
= g_new(AnHistFile
, 1);
49 h_file
->file
= g_strdup(name
);
54 void an_hist_file_free(AnHistFile
*h_file
)
56 g_return_if_fail(h_file
);
61 static void an_hist_items_free(GList
*items
)
65 g_return_if_fail(items
);
66 for (tmp
= items
; tmp
; tmp
= g_list_next(tmp
))
67 an_hist_file_free((AnHistFile
*) tmp
->data
);
71 void an_file_history_reset(void)
73 g_return_if_fail(s_history
&& s_history
->items
);
75 an_hist_items_free(s_history
->items
);
76 s_history
->items
= NULL
;
77 s_history
->current
= NULL
;
80 void an_file_history_push(const char *filename
, glong line
)
84 g_return_if_fail(filename
);
86 an_file_history_init();
87 if (s_history
->current
)
89 AnHistFile
*current
= (AnHistFile
*) s_history
->current
->data
;
90 if ((0 == strcmp(filename
, current
->file
)) &&
91 ((current
->line
< 1) || (line
== current
->line
)))
96 if (s_history
->current
!= s_history
->items
)
98 GList
*tmp
= s_history
->current
->prev
;
102 an_hist_items_free(s_history
->items
);
104 s_history
->items
= s_history
->current
;
105 s_history
->current
->prev
= NULL
;
107 if (g_list_length(s_history
->items
) > MAX_ENTRIES
)
109 GList
*tmp
= g_list_nth(s_history
->items
, OPT_ENTRIES
);
110 an_hist_items_free(tmp
->next
);
114 h_file
= an_hist_file_new(filename
, line
);
115 s_history
->items
= g_list_prepend(s_history
->items
, h_file
);
116 s_history
->current
= s_history
->items
;
119 void an_file_history_back(AnjutaDocman
*docman
)
123 if (!(s_history
&& s_history
->current
&& s_history
->current
->next
))
126 s_history
->current
= s_history
->current
->next
;
127 h_file
= (AnHistFile
*) s_history
->current
->data
;
128 anjuta_docman_goto_file_line_mark (docman
, h_file
->file
,
129 h_file
->line
, FALSE
);
132 void an_file_history_forward(AnjutaDocman
*docman
)
136 if (!(s_history
&& s_history
->current
&& s_history
->current
->prev
))
139 s_history
->current
= s_history
->current
->prev
;
140 h_file
= (AnHistFile
*) s_history
->current
->data
;
141 anjuta_docman_goto_file_line_mark(docman
, h_file
->file
,
142 h_file
->line
, FALSE
);
145 void an_file_history_dump(void)
150 g_return_if_fail(s_history
&& s_history
->items
);
151 fprintf(stderr
, "--------------------------\n");
152 for (tmp
= s_history
->items
; tmp
; tmp
= g_list_next(tmp
))
154 h_file
= (AnHistFile
*) tmp
->data
;
155 fprintf(stderr
, "%s:%ld", h_file
->file
, h_file
->line
);
156 if (tmp
== s_history
->current
)
157 fprintf(stderr
, " (*)");
158 fprintf(stderr
, "\n");
160 fprintf(stderr
, "--------------------------\n");
163 void an_file_history_free(void)
165 an_file_history_reset();