Set up current working directory on File->Open
[gscope.git] / mark.c
blob2a8461b1748bb6ee9e2de046fe968c0ade6d9797
1 /*
2 * (c) 2011 Cyrill Gorcunov, gorcunov@gmail.com
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "mark.h"
29 #include "backend-proto.h"
30 #include "view.h"
31 #include "list.h"
32 #include "util.h"
34 /* #define DBG(msg, ...) debug(msg, __VA_ARGS__) */
35 #define DBG(msg, ...)
37 /* indices on ring */
38 static unsigned long idx_last;
39 static unsigned long idx_current;
41 static struct mark_item marks[MARKS_LIMIT];
42 static int do_push = 1;
44 void mark_init(void)
46 idx_last = idx_current = 0;
47 memset(marks, 0, sizeof(marks));
50 void mark_fini(void)
52 unsigned long i;
54 for (i = 0; i < idx_last; i++)
55 free(marks[i].file_path);
57 idx_last = idx_current = 0;
60 void mark_push(struct backend_proto_item *item)
62 if (!do_push)
63 return;
65 idx_last++;
66 if (idx_last >= MARKS_LIMIT) {
67 idx_last = MARKS_LIMIT;
68 free(marks[idx_last - 1].file_path);
71 DBG("%s: %s:%lu", __func__, item->file, item->line);
73 idx_current = idx_last - 1;
75 marks[idx_last - 1].file_path = xstrdup(item->file);
76 marks[idx_last - 1].line = item->line;
79 static void mark_switch_to(struct gscope_info *info, unsigned long idx)
81 struct backend_proto_item item = { 0 };
83 item.file = marks[idx].file_path;
84 item.line = marks[idx].line;
86 do_push = 0;
87 query_switch_or_read_source_into_notebook(info, &item);
88 do_push = 1;
91 void mark_switch_to_next(struct gscope_info *info)
93 DBG("%s: %lu %lu", __func__, idx_last, idx_current);
95 if (idx_last && idx_current < idx_last - 1) {
96 idx_current++;
97 mark_switch_to(info, idx_current);
101 void mark_switch_to_prev(struct gscope_info *info)
103 DBG("%s: %lu %lu", __func__, idx_last, idx_current);
105 if (idx_current > 0) {
106 idx_current--;
107 mark_switch_to(info, idx_current);