Blame


1 1fce2e75 2021-08-14 op /*
2 1fce2e75 2021-08-14 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 1fce2e75 2021-08-14 op *
4 1fce2e75 2021-08-14 op * Permission to use, copy, modify, and distribute this software for any
5 1fce2e75 2021-08-14 op * purpose with or without fee is hereby granted, provided that the above
6 1fce2e75 2021-08-14 op * copyright notice and this permission notice appear in all copies.
7 1fce2e75 2021-08-14 op *
8 1fce2e75 2021-08-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 1fce2e75 2021-08-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 1fce2e75 2021-08-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 1fce2e75 2021-08-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 1fce2e75 2021-08-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 1fce2e75 2021-08-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 1fce2e75 2021-08-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 1fce2e75 2021-08-14 op */
16 1fce2e75 2021-08-14 op
17 1fce2e75 2021-08-14 op #include "compat.h"
18 1fce2e75 2021-08-14 op
19 1fce2e75 2021-08-14 op #include <errno.h>
20 f63b8f73 2022-04-24 op #include <limits.h>
21 1fce2e75 2021-08-14 op #include <stdio.h>
22 1fce2e75 2021-08-14 op #include <stdlib.h>
23 1fce2e75 2021-08-14 op #include <string.h>
24 9e97090d 2022-02-26 op #include <time.h>
25 1fce2e75 2021-08-14 op #include <unistd.h>
26 1fce2e75 2021-08-14 op
27 1fce2e75 2021-08-14 op #include "defaults.h"
28 b9fcc0e9 2021-10-08 op #include "fs.h"
29 1fce2e75 2021-08-14 op #include "minibuffer.h"
30 1fce2e75 2021-08-14 op #include "session.h"
31 1fce2e75 2021-08-14 op #include "ui.h"
32 1fce2e75 2021-08-14 op
33 9e97090d 2022-02-26 op struct history history;
34 9e97090d 2022-02-26 op
35 1fce2e75 2021-08-14 op static struct event autosaveev;
36 1fce2e75 2021-08-14 op
37 1fce2e75 2021-08-14 op void
38 1fce2e75 2021-08-14 op switch_to_tab(struct tab *tab)
39 1fce2e75 2021-08-14 op {
40 1fce2e75 2021-08-14 op current_tab = tab;
41 1fce2e75 2021-08-14 op tab->flags &= ~TAB_URGENT;
42 1fce2e75 2021-08-14 op
43 fb8dcd1c 2022-01-18 op if (operating && tab->flags & TAB_LAZY)
44 ed21a9a1 2022-01-11 op load_url_in_tab(tab, tab->hist_cur->h, NULL, LU_MODE_NOHIST);
45 1fce2e75 2021-08-14 op }
46 1fce2e75 2021-08-14 op
47 1fce2e75 2021-08-14 op unsigned int
48 1fce2e75 2021-08-14 op tab_new_id(void)
49 1fce2e75 2021-08-14 op {
50 1fce2e75 2021-08-14 op static uint32_t tab_counter;
51 1fce2e75 2021-08-14 op
52 1fce2e75 2021-08-14 op return tab_counter++;
53 1fce2e75 2021-08-14 op }
54 1fce2e75 2021-08-14 op
55 1fce2e75 2021-08-14 op struct tab *
56 1fce2e75 2021-08-14 op new_tab(const char *url, const char *base, struct tab *after)
57 1fce2e75 2021-08-14 op {
58 1fce2e75 2021-08-14 op struct tab *tab;
59 1fce2e75 2021-08-14 op
60 87aeb47b 2021-08-18 op ui_schedule_redraw();
61 1fce2e75 2021-08-14 op autosave_hook();
62 1fce2e75 2021-08-14 op
63 1fce2e75 2021-08-14 op if ((tab = calloc(1, sizeof(*tab))) == NULL) {
64 1fce2e75 2021-08-14 op event_loopbreak();
65 1fce2e75 2021-08-14 op return NULL;
66 1fce2e75 2021-08-14 op }
67 1fce2e75 2021-08-14 op
68 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->hist.head);
69 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->buffer.head);
70 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->buffer.page.head);
71 3b30597e 2022-02-11 op evtimer_set(&tab->loadingev, NULL, NULL);
72 1fce2e75 2021-08-14 op
73 1fce2e75 2021-08-14 op tab->id = tab_new_id();
74 1fce2e75 2021-08-14 op
75 1fce2e75 2021-08-14 op if (after != NULL)
76 1fce2e75 2021-08-14 op TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs);
77 1fce2e75 2021-08-14 op else
78 1fce2e75 2021-08-14 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
79 1fce2e75 2021-08-14 op
80 ea639250 2021-01-02 op if (!operating)
81 ea639250 2021-01-02 op tab->flags |= TAB_LAZY;
82 1fce2e75 2021-08-14 op load_url_in_tab(tab, url, base, 0);
83 ea639250 2021-01-02 op switch_to_tab(tab);
84 1fce2e75 2021-08-14 op return tab;
85 1fce2e75 2021-08-14 op }
86 1fce2e75 2021-08-14 op
87 1fce2e75 2021-08-14 op /*
88 6c74799d 2022-01-05 op * Move a tab from the tablist to the killed tab list and erase its
89 05de8ac3 2022-01-06 op * contents. Append should always be 0 to prepend tabs so unkill_tab
90 05de8ac3 2022-01-06 op * can work correctly; appending is only useful during startup when
91 05de8ac3 2022-01-06 op * receiving the list of killed tabs to keep the correct order.
92 05de8ac3 2022-01-06 op * NB: doesn't update the current_tab.
93 1fce2e75 2021-08-14 op */
94 1fce2e75 2021-08-14 op void
95 05de8ac3 2022-01-06 op kill_tab(struct tab *tab, int append)
96 1fce2e75 2021-08-14 op {
97 6c74799d 2022-01-05 op int count;
98 6c74799d 2022-01-05 op
99 1fce2e75 2021-08-14 op stop_tab(tab);
100 6c74799d 2022-01-05 op erase_buffer(&tab->buffer);
101 6c74799d 2022-01-05 op TAILQ_REMOVE(&tabshead, tab, tabs);
102 87aeb47b 2021-08-18 op ui_schedule_redraw();
103 1fce2e75 2021-08-14 op autosave_hook();
104 1fce2e75 2021-08-14 op
105 1fce2e75 2021-08-14 op if (evtimer_pending(&tab->loadingev, NULL))
106 1fce2e75 2021-08-14 op evtimer_del(&tab->loadingev);
107 1fce2e75 2021-08-14 op
108 05de8ac3 2022-01-06 op if (append)
109 05de8ac3 2022-01-06 op TAILQ_INSERT_TAIL(&ktabshead, tab, tabs);
110 05de8ac3 2022-01-06 op else
111 05de8ac3 2022-01-06 op TAILQ_INSERT_HEAD(&ktabshead, tab, tabs);
112 6c74799d 2022-01-05 op
113 6c74799d 2022-01-05 op /* gc closed tabs */
114 6c74799d 2022-01-05 op count = 0;
115 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &ktabshead, tabs)
116 6c74799d 2022-01-05 op count++;
117 6c74799d 2022-01-05 op while (count > max_killed_tabs) {
118 6c74799d 2022-01-05 op count--;
119 6c74799d 2022-01-05 op free_tab(TAILQ_LAST(&ktabshead, tabshead));
120 6c74799d 2022-01-05 op }
121 6c74799d 2022-01-05 op }
122 6c74799d 2022-01-05 op
123 6c74799d 2022-01-05 op /*
124 265508d0 2022-01-05 op * Resurrects the lastest killed tab and returns it. The tab is already
125 6c74799d 2022-01-05 op * added to the tab list with the TAB_LAZY flag set. NB: this doesn't
126 6c74799d 2022-01-05 op * update current_tab.
127 6c74799d 2022-01-05 op */
128 6c74799d 2022-01-05 op struct tab *
129 6c74799d 2022-01-05 op unkill_tab(void)
130 6c74799d 2022-01-05 op {
131 6c74799d 2022-01-05 op struct tab *t;
132 6c74799d 2022-01-05 op
133 6c74799d 2022-01-05 op if (TAILQ_EMPTY(&ktabshead))
134 6c74799d 2022-01-05 op return NULL;
135 6c74799d 2022-01-05 op
136 b7286684 2022-01-13 op ui_schedule_redraw();
137 6c74799d 2022-01-05 op autosave_hook();
138 6c74799d 2022-01-05 op
139 6c74799d 2022-01-05 op t = TAILQ_FIRST(&ktabshead);
140 6c74799d 2022-01-05 op TAILQ_REMOVE(&ktabshead, t, tabs);
141 6c74799d 2022-01-05 op TAILQ_INSERT_TAIL(&tabshead, t, tabs);
142 6c74799d 2022-01-05 op t->flags |= TAB_LAZY;
143 6c74799d 2022-01-05 op return t;
144 6c74799d 2022-01-05 op }
145 6c74799d 2022-01-05 op
146 6c74799d 2022-01-05 op /*
147 1b45e5df 2022-01-05 op * Free every resource linked to the tab, including the tab itself, and
148 1b45e5df 2022-01-05 op * removes it from the *killed* tablist.
149 6c74799d 2022-01-05 op */
150 6c74799d 2022-01-05 op void
151 6c74799d 2022-01-05 op free_tab(struct tab *tab)
152 6c74799d 2022-01-05 op {
153 6c74799d 2022-01-05 op TAILQ_REMOVE(&ktabshead, tab, tabs);
154 bf935370 2022-01-05 op hist_clear(&tab->hist);
155 1fce2e75 2021-08-14 op free(tab);
156 1fce2e75 2021-08-14 op }
157 1fce2e75 2021-08-14 op
158 1fce2e75 2021-08-14 op void
159 1fce2e75 2021-08-14 op stop_tab(struct tab *tab)
160 1fce2e75 2021-08-14 op {
161 1fce2e75 2021-08-14 op ui_send_net(IMSG_STOP, tab->id, NULL, 0);
162 1fce2e75 2021-08-14 op }
163 1fce2e75 2021-08-14 op
164 6c74799d 2022-01-05 op static inline void
165 f63b8f73 2022-04-24 op savetab(FILE *fp, struct tab *tab, int killed)
166 1fce2e75 2021-08-14 op {
167 f63b8f73 2022-04-24 op struct hist *h;
168 f63b8f73 2022-04-24 op size_t top_line, current_line;
169 f63b8f73 2022-04-24 op int future;
170 1fce2e75 2021-08-14 op
171 f63b8f73 2022-04-24 op get_scroll_position(tab, &top_line, &current_line);
172 d0971653 2021-09-15 op
173 f63b8f73 2022-04-24 op fprintf(fp, "%s ", tab->hist_cur->h);
174 6c74799d 2022-01-05 op if (tab == current_tab)
175 f63b8f73 2022-04-24 op fprintf(fp, "current,");
176 6c74799d 2022-01-05 op if (killed)
177 f63b8f73 2022-04-24 op fprintf(fp, "killed,");
178 1fce2e75 2021-08-14 op
179 f63b8f73 2022-04-24 op fprintf(fp, "top=%zu,cur=%zu %s\n", top_line, current_line,
180 f63b8f73 2022-04-24 op tab->buffer.page.title);
181 e795e935 2022-01-18 op
182 6c74799d 2022-01-05 op future = 0;
183 6c74799d 2022-01-05 op TAILQ_FOREACH(h, &tab->hist.head, entries) {
184 6c74799d 2022-01-05 op if (h == tab->hist_cur) {
185 6c74799d 2022-01-05 op future = 1;
186 6c74799d 2022-01-05 op continue;
187 6c74799d 2022-01-05 op }
188 1fce2e75 2021-08-14 op
189 f63b8f73 2022-04-24 op fprintf(fp, "%s %s\n", future ? ">" : "<", h->h);
190 6c74799d 2022-01-05 op }
191 6c74799d 2022-01-05 op }
192 1040cc7f 2021-01-02 op
193 6c74799d 2022-01-05 op void
194 6c74799d 2022-01-05 op save_session(void)
195 6c74799d 2022-01-05 op {
196 de6a6a40 2022-04-24 op FILE *tmp;
197 de6a6a40 2022-04-24 op struct tab *tab;
198 de6a6a40 2022-04-24 op size_t i;
199 de6a6a40 2022-04-24 op int fd, err= 0;
200 de6a6a40 2022-04-24 op char sfn[PATH_MAX];
201 1fce2e75 2021-08-14 op
202 6c74799d 2022-01-05 op if (safe_mode)
203 6c74799d 2022-01-05 op return;
204 6c74799d 2022-01-05 op
205 de6a6a40 2022-04-24 op strlcpy(sfn, session_file_tmp, sizeof(sfn));
206 de6a6a40 2022-04-24 op if ((fd = mkstemp(sfn)) == -1 ||
207 de6a6a40 2022-04-24 op (tmp = fdopen(fd, "w")) == NULL) {
208 de6a6a40 2022-04-24 op if (fd != -1) {
209 de6a6a40 2022-04-24 op unlink(sfn);
210 de6a6a40 2022-04-24 op close(fd);
211 de6a6a40 2022-04-24 op }
212 f63b8f73 2022-04-24 op return;
213 de6a6a40 2022-04-24 op }
214 6c74799d 2022-01-05 op
215 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &tabshead, tabs)
216 de6a6a40 2022-04-24 op savetab(tmp, tab, 0);
217 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &ktabshead, tabs)
218 de6a6a40 2022-04-24 op savetab(tmp, tab, 1);
219 6c74799d 2022-01-05 op
220 de6a6a40 2022-04-24 op err = ferror(tmp);
221 de6a6a40 2022-04-24 op fclose(tmp);
222 9e97090d 2022-02-26 op
223 de6a6a40 2022-04-24 op if (err) {
224 de6a6a40 2022-04-24 op unlink(sfn);
225 f63b8f73 2022-04-24 op return;
226 de6a6a40 2022-04-24 op }
227 f63b8f73 2022-04-24 op
228 de6a6a40 2022-04-24 op if (rename(sfn, session_file))
229 de6a6a40 2022-04-24 op return;
230 de6a6a40 2022-04-24 op
231 de6a6a40 2022-04-24 op strlcpy(sfn, history_file_tmp, sizeof(sfn));
232 de6a6a40 2022-04-24 op if ((fd = mkstemp(sfn)) == -1 ||
233 de6a6a40 2022-04-24 op (tmp = fdopen(fd, "w")) == NULL) {
234 de6a6a40 2022-04-24 op if (fd != -1) {
235 de6a6a40 2022-04-24 op unlink(sfn);
236 de6a6a40 2022-04-24 op close(fd);
237 de6a6a40 2022-04-24 op }
238 de6a6a40 2022-04-24 op return;
239 de6a6a40 2022-04-24 op }
240 de6a6a40 2022-04-24 op
241 9e97090d 2022-02-26 op if (history.dirty) {
242 9e97090d 2022-02-26 op for (i = 0; i < history.len && history.dirty > 0; ++i) {
243 9e97090d 2022-02-26 op if (!history.items[i].dirty)
244 9e97090d 2022-02-26 op continue;
245 9e97090d 2022-02-26 op history.dirty--;
246 9e97090d 2022-02-26 op history.items[i].dirty = 0;
247 9e97090d 2022-02-26 op
248 de6a6a40 2022-04-24 op fprintf(tmp, "%lld %s\n",
249 f63b8f73 2022-04-24 op (long long)history.items[i].ts,
250 f63b8f73 2022-04-24 op history.items[i].uri);
251 9e97090d 2022-02-26 op }
252 9e97090d 2022-02-26 op history.dirty = 0;
253 9e97090d 2022-02-26 op }
254 f63b8f73 2022-04-24 op
255 de6a6a40 2022-04-24 op err = ferror(tmp);
256 de6a6a40 2022-04-24 op fclose(tmp);
257 de6a6a40 2022-04-24 op
258 de6a6a40 2022-04-24 op if (err) {
259 de6a6a40 2022-04-24 op unlink(sfn);
260 de6a6a40 2022-04-24 op return;
261 de6a6a40 2022-04-24 op }
262 de6a6a40 2022-04-24 op
263 de6a6a40 2022-04-24 op rename(sfn, history_file);
264 9e97090d 2022-02-26 op }
265 9e97090d 2022-02-26 op
266 9e97090d 2022-02-26 op void
267 9e97090d 2022-02-26 op history_push(struct histitem *hi)
268 9e97090d 2022-02-26 op {
269 9e97090d 2022-02-26 op size_t i, oldest = 0;
270 9e97090d 2022-02-26 op char *uri;
271 9e97090d 2022-02-26 op
272 9e97090d 2022-02-26 op for (i = 0; i < history.len; ++i) {
273 9e97090d 2022-02-26 op if (history.items[i].ts < history.items[oldest].ts)
274 9e97090d 2022-02-26 op oldest = i;
275 9e97090d 2022-02-26 op
276 9e97090d 2022-02-26 op /* remove duplicates */
277 9e97090d 2022-02-26 op if (!strcmp(history.items[i].uri, hi->uri))
278 9e97090d 2022-02-26 op return;
279 9e97090d 2022-02-26 op }
280 9e97090d 2022-02-26 op
281 9e97090d 2022-02-26 op if ((uri = strdup(hi->uri)) == NULL)
282 9e97090d 2022-02-26 op abort();
283 9e97090d 2022-02-26 op
284 9e97090d 2022-02-26 op /* don't grow too much; replace the oldest */
285 9e97090d 2022-02-26 op if (history.len == HISTORY_CAP) {
286 9e97090d 2022-02-26 op history.items[oldest].ts = hi->ts;
287 9e97090d 2022-02-26 op free(history.items[oldest].uri);
288 9e97090d 2022-02-26 op history.items[oldest].uri = uri;
289 9e97090d 2022-02-26 op return;
290 9e97090d 2022-02-26 op }
291 9e97090d 2022-02-26 op
292 9e97090d 2022-02-26 op history.items[history.len].ts = hi->ts;
293 9e97090d 2022-02-26 op history.items[history.len].uri = uri;
294 9e97090d 2022-02-26 op history.len++;
295 9e97090d 2022-02-26 op }
296 9e97090d 2022-02-26 op
297 9e97090d 2022-02-26 op static int
298 9e97090d 2022-02-26 op history_cmp(const void *a, const void *b)
299 9e97090d 2022-02-26 op {
300 9e97090d 2022-02-26 op const struct history_item *i = a, *j = b;
301 9e97090d 2022-02-26 op return strcmp(i->uri, j->uri);
302 9e97090d 2022-02-26 op }
303 9e97090d 2022-02-26 op
304 9e97090d 2022-02-26 op void
305 9e97090d 2022-02-26 op history_sort(void)
306 9e97090d 2022-02-26 op {
307 9e97090d 2022-02-26 op qsort(history.items, history.len, sizeof(history.items[0]),
308 9e97090d 2022-02-26 op history_cmp);
309 1fce2e75 2021-08-14 op }
310 1fce2e75 2021-08-14 op
311 1fce2e75 2021-08-14 op void
312 9e97090d 2022-02-26 op history_add(const char *uri)
313 9e97090d 2022-02-26 op {
314 9e97090d 2022-02-26 op size_t i, j, insert = 0, oldest = 0;
315 9e97090d 2022-02-26 op char *u;
316 9e97090d 2022-02-26 op int c;
317 9e97090d 2022-02-26 op
318 9e97090d 2022-02-26 op for (i = 0; i < history.len; ++i) {
319 9e97090d 2022-02-26 op if (history.items[i].ts < history.items[oldest].ts)
320 9e97090d 2022-02-26 op oldest = i;
321 9e97090d 2022-02-26 op
322 9e97090d 2022-02-26 op if (insert != 0 && insert < i)
323 9e97090d 2022-02-26 op continue;
324 9e97090d 2022-02-26 op
325 9e97090d 2022-02-26 op c = strcmp(uri, history.items[i].uri);
326 9e97090d 2022-02-26 op if (c == 0) {
327 9e97090d 2022-02-26 op history.items[i].ts = time(NULL);
328 9e97090d 2022-02-26 op history.items[i].dirty = 1;
329 9e97090d 2022-02-26 op history.dirty++;
330 9e97090d 2022-02-26 op autosave_hook();
331 9e97090d 2022-02-26 op return;
332 9e97090d 2022-02-26 op }
333 9e97090d 2022-02-26 op
334 9e97090d 2022-02-26 op if (c > 0)
335 9e97090d 2022-02-26 op insert = i;
336 9e97090d 2022-02-26 op }
337 9e97090d 2022-02-26 op
338 9e97090d 2022-02-26 op if ((u = strdup(uri)) == NULL)
339 9e97090d 2022-02-26 op return;
340 9e97090d 2022-02-26 op
341 9e97090d 2022-02-26 op /* if history is full, replace the oldest one */
342 9e97090d 2022-02-26 op if (history.len == HISTORY_CAP) {
343 9e97090d 2022-02-26 op free(history.items[oldest].uri);
344 9e97090d 2022-02-26 op history.items[oldest].uri = u;
345 9e97090d 2022-02-26 op history.items[oldest].ts = time(NULL);
346 9e97090d 2022-02-26 op history.items[oldest].dirty = 1;
347 9e97090d 2022-02-26 op history.dirty++;
348 9e97090d 2022-02-26 op history_sort();
349 9e97090d 2022-02-26 op autosave_hook();
350 9e97090d 2022-02-26 op return;
351 9e97090d 2022-02-26 op }
352 9e97090d 2022-02-26 op
353 9e97090d 2022-02-26 op /* otherwise just insert in the right spot */
354 9e97090d 2022-02-26 op
355 9e97090d 2022-02-26 op for (j = history.len; j > insert; --j)
356 9e97090d 2022-02-26 op memcpy(&history.items[j], &history.items[j-1],
357 9e97090d 2022-02-26 op sizeof(history.items[j]));
358 9e97090d 2022-02-26 op
359 9e97090d 2022-02-26 op history.items[insert].ts = time(NULL);
360 9e97090d 2022-02-26 op history.items[insert].uri = u;
361 9e97090d 2022-02-26 op history.items[insert].dirty = 1;
362 9e97090d 2022-02-26 op history.dirty++;
363 9e97090d 2022-02-26 op history.len++;
364 9e97090d 2022-02-26 op autosave_hook();
365 9e97090d 2022-02-26 op }
366 9e97090d 2022-02-26 op
367 9e97090d 2022-02-26 op void
368 1fce2e75 2021-08-14 op autosave_init(void)
369 1fce2e75 2021-08-14 op {
370 1fce2e75 2021-08-14 op evtimer_set(&autosaveev, autosave_timer, NULL);
371 1fce2e75 2021-08-14 op }
372 1fce2e75 2021-08-14 op
373 1fce2e75 2021-08-14 op void
374 1fce2e75 2021-08-14 op autosave_timer(int fd, short event, void *data)
375 1fce2e75 2021-08-14 op {
376 1fce2e75 2021-08-14 op save_session();
377 1fce2e75 2021-08-14 op }
378 1fce2e75 2021-08-14 op
379 1fce2e75 2021-08-14 op /*
380 1fce2e75 2021-08-14 op * Function to be called in "interesting" places where we may want to
381 1fce2e75 2021-08-14 op * schedule an autosave (like on new tab or before loading an url.)
382 1fce2e75 2021-08-14 op */
383 1fce2e75 2021-08-14 op void
384 1fce2e75 2021-08-14 op autosave_hook(void)
385 1fce2e75 2021-08-14 op {
386 1fce2e75 2021-08-14 op struct timeval tv;
387 1fce2e75 2021-08-14 op
388 1fce2e75 2021-08-14 op if (autosave <= 0)
389 1fce2e75 2021-08-14 op return;
390 1fce2e75 2021-08-14 op
391 1fce2e75 2021-08-14 op if (!evtimer_pending(&autosaveev, NULL)) {
392 1fce2e75 2021-08-14 op tv.tv_sec = autosave;
393 1fce2e75 2021-08-14 op tv.tv_usec = 0;
394 1fce2e75 2021-08-14 op
395 1fce2e75 2021-08-14 op evtimer_add(&autosaveev, &tv);
396 1fce2e75 2021-08-14 op }
397 1fce2e75 2021-08-14 op }