Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include "compat.h"
19 #include <limits.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "compl.h"
24 #include "defaults.h"
25 #include "mcache.h"
26 #include "minibuffer.h"
27 #include "session.h"
28 #include "telescope.h"
29 #include "ui.h"
30 #include "utf8.h"
32 #define GUARD_RECURSIVE_MINIBUFFER() \
33 do { \
34 if (in_minibuffer) { \
35 message("enable-recursive-minibuffers " \
36 "is not yet available."); \
37 return; \
38 } \
39 } while(0)
41 #define GUARD_READ_ONLY() \
42 do { \
43 if (!in_minibuffer) { \
44 message("text is read-only"); \
45 return; \
46 } \
47 } while(0)
49 /* return 1 if moved, 0 otherwise */
50 static inline int
51 forward_line(struct buffer *buffer, int n)
52 {
53 struct vline *vl;
54 int did;
56 if (buffer->current_line == NULL)
57 return 0;
58 vl = buffer->current_line;
60 did = 0;
61 while (n != 0) {
62 if (n > 0) {
63 vl = TAILQ_NEXT(vl, vlines);
64 if (vl == NULL)
65 return did;
66 if (vl->parent->flags & L_HIDDEN)
67 continue;
68 buffer->current_line = vl;
69 n--;
70 } else {
71 vl = TAILQ_PREV(vl, vhead, vlines);
72 if (vl == NULL)
73 return did;
74 if (vl->parent->flags & L_HIDDEN)
75 continue;
76 if (buffer->current_line == buffer->top_line) {
77 buffer->line_off--;
78 buffer->top_line = vl;
79 }
80 buffer->current_line = vl;
81 n++;
82 }
84 did = 1;
85 }
87 return did;
88 }
90 void
91 cmd_previous_line(struct buffer *buffer)
92 {
93 forward_line(buffer, -1);
94 }
96 void
97 cmd_next_line(struct buffer *buffer)
98 {
99 forward_line(buffer, +1);
102 void
103 cmd_backward_char(struct buffer *buffer)
105 if (buffer->cpoff != 0)
106 buffer->cpoff--;
109 void
110 cmd_forward_char(struct buffer *buffer)
112 size_t len = 0;
114 if (buffer->current_line == NULL)
115 return;
117 if (buffer->current_line->line != NULL)
118 len = utf8_cplen(buffer->current_line->line);
119 if (++buffer->cpoff > len)
120 buffer->cpoff = len;
123 void
124 cmd_backward_paragraph(struct buffer *buffer)
126 do {
127 if (!forward_line(buffer, -1)) {
128 message("No previous paragraph");
129 return;
131 } while (buffer->current_line->line != NULL ||
132 buffer->current_line->parent->type != LINE_TEXT);
135 void
136 cmd_forward_paragraph(struct buffer *buffer)
138 do {
139 if (!forward_line(buffer, +1)) {
140 message("No next paragraph");
141 return;
143 } while (buffer->current_line->line != NULL ||
144 buffer->current_line->parent->type != LINE_TEXT);
147 void
148 cmd_move_beginning_of_line(struct buffer *buffer)
150 buffer->cpoff = 0;
153 void
154 cmd_move_end_of_line(struct buffer *buffer)
156 struct vline *vl;
158 vl = buffer->current_line;
159 if (vl == NULL || vl->line == NULL)
160 return;
161 buffer->cpoff = utf8_cplen(vl->line);
164 void
165 cmd_redraw(struct buffer *buffer)
167 ui_schedule_redraw();
170 void
171 cmd_scroll_line_up(struct buffer *buffer)
173 struct vline *vl;
175 for (;;) {
176 if (buffer->top_line == NULL)
177 return;
179 if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
180 == NULL)
181 return;
183 buffer->top_line = vl;
185 if (vl->parent->flags & L_HIDDEN)
186 continue;
188 break;
191 buffer->line_off--;
193 forward_line(buffer, -1);
196 void
197 cmd_scroll_line_down(struct buffer *buffer)
199 if (!forward_line(buffer, +1))
200 return;
202 for (;;) {
203 if (buffer->top_line == NULL)
204 return;
206 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
207 if (buffer->top_line->parent->flags & L_HIDDEN)
208 continue;
209 break;
212 buffer->line_off++;
215 void
216 cmd_scroll_up(struct buffer *buffer)
218 struct vline *vl;
219 int i;
221 if (buffer->top_line == NULL)
222 return;
224 for (i = 0; i < body_lines; ++i) {
225 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
226 if (vl == NULL)
227 break;
228 buffer->line_off--;
229 buffer->top_line = vl;
230 forward_line(buffer, -1);
234 void
235 cmd_scroll_down(struct buffer *buffer)
237 int i;
239 if (buffer->top_line == NULL)
240 return;
242 for (i = 0; i < body_lines; ++i) {
243 if (!forward_line(buffer, +1))
244 break;
246 buffer->top_line = TAILQ_NEXT(buffer->top_line,
247 vlines);
248 buffer->line_off++;
252 void
253 cmd_beginning_of_buffer(struct buffer *buffer)
255 buffer->current_line = TAILQ_FIRST(&buffer->head);
256 buffer->cpoff = 0;
257 buffer->top_line = buffer->current_line;
258 buffer->line_off = 0;
261 void
262 cmd_end_of_buffer(struct buffer *buffer)
264 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
266 if (buffer->current_line == NULL)
267 return;
269 /* deal with invisible lines */
270 if (buffer->current_line->parent->flags & L_HIDDEN)
271 forward_line(buffer, -1);
273 cmd_move_end_of_line(buffer);
276 static void
277 kill_telescope_cb(int r, struct tab *tab)
279 if (r) {
280 save_session();
281 event_loopbreak();
285 void
286 cmd_kill_telescope(struct buffer *buffer)
288 yornp("really quit?", kill_telescope_cb, NULL);
291 void
292 cmd_push_button(struct buffer *buffer)
294 struct vline *vl;
295 struct line *l;
297 vl = buffer->current_line;
299 if (vl == NULL)
300 return;
302 switch (vl->parent->type) {
303 case LINE_LINK:
304 load_url_in_tab(current_tab, vl->parent->alt, NULL,
305 LU_MODE_NOCACHE);
306 break;
307 case LINE_PRE_START:
308 l = TAILQ_NEXT(vl->parent, lines);
309 for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
310 if (l->type == LINE_PRE_END)
311 break;
312 l->flags ^= L_HIDDEN;
313 if (l->flags & L_HIDDEN)
314 buffer->line_max--;
315 else
316 buffer->line_max++;
318 break;
319 default:
320 break;
324 void
325 cmd_push_button_new_tab(struct buffer *buffer)
327 struct vline *vl;
329 vl = buffer->current_line;
330 if (vl == NULL || vl->parent->type != LINE_LINK)
331 return;
333 new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
336 void
337 cmd_previous_button(struct buffer *buffer)
339 struct excursion place;
341 save_excursion(&place, buffer);
343 do {
344 if (!forward_line(buffer, -1)) {
345 restore_excursion(&place, buffer);
346 message("No previous link");
347 return;
349 } while (buffer->current_line->parent->type != LINE_LINK);
352 void
353 cmd_next_button(struct buffer *buffer)
355 struct excursion place;
357 save_excursion(&place, buffer);
359 do {
360 if (!forward_line(buffer, +1)){
361 restore_excursion(&place, buffer);
362 message("No next link");
363 return;
365 } while (buffer->current_line->parent->type != LINE_LINK);
368 static inline int
369 is_heading(const struct line *l)
371 return l->type == LINE_TITLE_1 ||
372 l->type == LINE_TITLE_2 ||
373 l->type == LINE_TITLE_3;
376 void
377 cmd_previous_heading(struct buffer *buffer)
379 struct excursion place;
381 save_excursion(&place, buffer);
383 do {
384 if (!forward_line(buffer, -1)) {
385 restore_excursion(&place, buffer);
386 message("No previous heading");
387 return;
389 } while (!is_heading(buffer->current_line->parent));
392 void
393 cmd_next_heading(struct buffer *buffer)
395 struct excursion place;
397 save_excursion(&place, buffer);
399 do {
400 if (!forward_line(buffer, +1)) {
401 restore_excursion(&place, buffer);
402 message("No next heading");
403 return;
405 } while (!is_heading(buffer->current_line->parent));
408 void
409 cmd_previous_page(struct buffer *buffer)
411 if (!load_previous_page(current_tab))
412 message("No previous page");
415 void
416 cmd_next_page(struct buffer *buffer)
418 if (!load_next_page(current_tab))
419 message("No next page");
422 void
423 cmd_clear_minibuf(struct buffer *buffer)
425 message(NULL);
428 void
429 cmd_execute_extended_command(struct buffer *buffer)
431 size_t len;
433 GUARD_RECURSIVE_MINIBUFFER();
435 enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
436 &eecmd_history, compl_eecmd, NULL);
438 len = sizeof(ministate.prompt);
439 strlcpy(ministate.prompt, "", len);
441 if (thiskey.meta)
442 strlcat(ministate.prompt, "M-", len);
444 strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
446 if (thiskey.meta)
447 strlcat(ministate.prompt, " ", len);
450 void
451 cmd_tab_close(struct buffer *buffer)
453 struct tab *tab, *t;
455 tab = current_tab;
457 if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
458 (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
459 switch_to_tab(t);
460 kill_tab(tab, 0);
461 } else
462 message("Can't close the only tab.");
466 void
467 cmd_tab_close_other(struct buffer *buffer)
469 struct tab *t, *i;
471 TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
472 if (t == current_tab)
473 continue;
475 kill_tab(t, 0);
479 void
480 cmd_tab_undo_close(struct buffer *buffer)
482 struct tab *t;
484 if ((t = unkill_tab()) == NULL) {
485 message("No recently-closed tabs");
486 return;
489 switch_to_tab(t);
492 void
493 cmd_tab_new(struct buffer *buffer)
495 const char *url;
497 if ((url = new_tab_url) == NULL)
498 url = NEW_TAB_URL;
500 new_tab(url, NULL, NULL);
503 void
504 cmd_tab_next(struct buffer *buffer)
506 struct tab *t;
508 if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
509 t = TAILQ_FIRST(&tabshead);
510 switch_to_tab(t);
513 void
514 cmd_tab_previous(struct buffer *buffer)
516 struct tab *t;
518 if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
519 t = TAILQ_LAST(&tabshead, tabshead);
520 switch_to_tab(t);
523 void
524 cmd_tab_move(struct buffer *buffer)
526 struct tab *t;
528 t = TAILQ_NEXT(current_tab, tabs);
529 TAILQ_REMOVE(&tabshead, current_tab, tabs);
531 if (t == NULL)
532 TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
533 else
534 TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
537 void
538 cmd_tab_move_to(struct buffer *buffer)
540 struct tab *t;
542 t = TAILQ_PREV(current_tab, tabshead, tabs);
543 TAILQ_REMOVE(&tabshead, current_tab, tabs);
545 if (t == NULL)
546 TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
547 else
548 TAILQ_INSERT_BEFORE(t, current_tab, tabs);
551 void
552 cmd_tab_select(struct buffer *buffer)
554 GUARD_RECURSIVE_MINIBUFFER();
556 enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
557 NULL, compl_ts, NULL);
558 strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
561 void
562 cmd_load_url(struct buffer *buffer)
564 GUARD_RECURSIVE_MINIBUFFER();
566 enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
567 &lu_history, NULL, NULL);
568 strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
571 void
572 cmd_load_current_url(struct buffer *buffer)
574 GUARD_RECURSIVE_MINIBUFFER();
576 enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
577 &lu_history, NULL, NULL);
578 strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
579 strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
580 ministate.buffer.cpoff = utf8_cplen(ministate.buf);
583 void
584 cmd_reload_page(struct buffer *buffer)
586 load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL,
587 LU_MODE_NOHIST|LU_MODE_NOCACHE);
590 void
591 cmd_bookmark_page(struct buffer *buffer)
593 GUARD_RECURSIVE_MINIBUFFER();
595 enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
596 NULL, NULL);
597 strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
598 strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
599 ministate.buffer.cpoff = utf8_cplen(ministate.buf);
602 void
603 cmd_list_bookmarks(struct buffer *buffer)
605 load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
608 void
609 cmd_toggle_help(struct buffer *buffer)
611 ui_toggle_side_window(SIDE_WINDOW_LEFT);
614 void
615 cmd_link_select(struct buffer *buffer)
617 struct line *l;
619 GUARD_RECURSIVE_MINIBUFFER();
621 l = TAILQ_FIRST(&buffer->page.head);
622 while (l != NULL && l->type != LINE_LINK)
623 l = TAILQ_NEXT(l, lines);
625 if (l == NULL) {
626 message("No links found");
627 return;
630 enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
631 NULL, compl_ls, l);
632 strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
635 void
636 cmd_swiper(struct buffer *buffer)
638 GUARD_RECURSIVE_MINIBUFFER();
640 enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
641 NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
642 strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
645 void
646 cmd_toc(struct buffer *buffer)
648 struct line *l;
650 GUARD_RECURSIVE_MINIBUFFER();
652 l = TAILQ_FIRST(&buffer->page.head);
653 while (l != NULL &&
654 l->type != LINE_TITLE_1 &&
655 l->type != LINE_TITLE_2 &&
656 l->type != LINE_TITLE_3)
657 l = TAILQ_NEXT(l, lines);
659 if (l == NULL) {
660 message("No headings found");
661 return;
664 enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
665 NULL, compl_toc, l);
666 strlcpy(ministate.prompt, "Select heading: ",
667 sizeof(ministate.prompt));
670 void
671 cmd_inc_fill_column(struct buffer *buffer)
673 if (fill_column == INT_MAX)
674 return;
676 fill_column += 2;
677 message("fill-column: %d", fill_column);
679 ui_schedule_redraw();
682 void
683 cmd_dec_fill_column(struct buffer *buffer)
685 if (fill_column == INT_MAX || fill_column < 8)
686 return;
688 fill_column -= 2;
689 message("fill-column: %d", fill_column);
691 ui_schedule_redraw();
694 void
695 cmd_olivetti_mode(struct buffer *buffer)
697 olivetti_mode = !olivetti_mode;
698 if (olivetti_mode)
699 message("olivetti-mode enabled");
700 else
701 message("olivetti-mode disabled");
703 ui_schedule_redraw();
706 void
707 cmd_mini_delete_char(struct buffer *buffer)
709 char *c, *n;
711 GUARD_READ_ONLY();
713 minibuffer_taint_hist();
715 c = utf8_nth(buffer->current_line->line, buffer->cpoff);
716 if (*c == '\0')
717 return;
718 n = utf8_next_cp(c);
720 memmove(c, n, strlen(n)+1);
722 recompute_completions(0);
725 void
726 cmd_mini_delete_backward_char(struct buffer *buffer)
728 char *c, *p, *start;
730 GUARD_READ_ONLY();
732 minibuffer_taint_hist();
734 c = utf8_nth(buffer->current_line->line, buffer->cpoff);
735 start = buffer->current_line->line;
736 if (c == start)
737 return;
738 p = utf8_prev_cp(c-1, start);
740 memmove(p, c, strlen(c)+1);
741 buffer->cpoff--;
743 recompute_completions(0);
746 void
747 cmd_mini_kill_line(struct buffer *buffer)
749 char *c;
751 GUARD_READ_ONLY();
753 minibuffer_taint_hist();
754 c = utf8_nth(buffer->current_line->line, buffer->cpoff);
755 *c = '\0';
757 recompute_completions(0);
760 void
761 cmd_mini_abort(struct buffer *buffer)
763 if (!in_minibuffer)
764 return;
766 ministate.abortfn();
769 void
770 cmd_mini_complete_and_exit(struct buffer *buffer)
772 if (!in_minibuffer)
773 return;
775 minibuffer_taint_hist();
776 ministate.donefn();
779 void
780 cmd_mini_previous_history_element(struct buffer *buffer)
782 if (ministate.history == NULL) {
783 message("No history");
784 return;
787 if (ministate.hist_cur == NULL ||
788 (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
789 ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
790 ministate.hist_off = ministate.history->len - 1;
791 if (ministate.hist_cur == NULL)
792 message("No prev history item");
793 } else {
794 ministate.hist_off--;
797 if (ministate.hist_cur != NULL)
798 buffer->current_line->line = ministate.hist_cur->h;
801 void
802 cmd_mini_next_history_element(struct buffer *buffer)
804 if (ministate.history == NULL) {
805 message("No history");
806 return;
809 if (ministate.hist_cur == NULL ||
810 (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
811 ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
812 ministate.hist_off = 0;
813 if (ministate.hist_cur == NULL)
814 message("No next history item");
815 } else {
816 ministate.hist_off++;
819 if (ministate.hist_cur != NULL)
820 buffer->current_line->line = ministate.hist_cur->h;
823 void
824 cmd_previous_completion(struct buffer *buffer)
826 if (in_minibuffer != MB_COMPREAD)
827 return;
829 buffer = &ministate.compl.buffer;
831 if (buffer->current_line != NULL)
832 buffer->current_line->parent->type = LINE_COMPL;
834 forward_line(buffer, -1);
836 if (buffer->current_line != NULL)
837 buffer->current_line->parent->type = LINE_COMPL_CURRENT;
840 void
841 cmd_next_completion(struct buffer *buffer)
843 if (in_minibuffer != MB_COMPREAD)
844 return;
846 buffer = &ministate.compl.buffer;
848 if (buffer->current_line != NULL)
849 buffer->current_line->parent->type = LINE_COMPL;
851 forward_line(buffer, +1);
853 if (buffer->current_line != NULL)
854 buffer->current_line->parent->type = LINE_COMPL_CURRENT;
857 void
858 cmd_insert_current_candidate(struct buffer *buffer)
860 if (in_minibuffer != MB_COMPREAD)
861 return;
863 minibuffer_insert_current_candidate();
866 void
867 cmd_suspend_telescope(struct buffer *buffer)
869 message("Zzz...");
870 ui_suspend();
873 void
874 cmd_toggle_pre_wrap(struct buffer *buffer)
876 dont_wrap_pre = !dont_wrap_pre;
878 if (dont_wrap_pre)
879 message("Don't wrap preformatted blocks");
880 else
881 message("Wrap preformatted blocks");
883 ui_schedule_redraw();
886 void
887 cmd_mini_goto_beginning(struct buffer *buffer)
889 struct vline *vl;
891 if (!in_minibuffer)
892 return;
894 buffer = &ministate.compl.buffer;
896 if ((vl = buffer->current_line) != NULL)
897 vl->parent->type = LINE_COMPL;
899 vl = TAILQ_FIRST(&buffer->head);
900 while (vl != NULL && vl->parent->flags & L_HIDDEN)
901 vl = TAILQ_NEXT(vl, vlines);
903 if (vl == NULL)
904 return;
906 vl->parent->type = LINE_COMPL_CURRENT;
907 buffer->top_line = vl;
908 buffer->current_line = vl;
911 void
912 cmd_mini_goto_end(struct buffer *buffer)
914 struct vline *vl;
916 if (!in_minibuffer)
917 return;
919 buffer = &ministate.compl.buffer;
921 if ((vl = buffer->current_line) != NULL)
922 vl->parent->type = LINE_COMPL;
924 vl = TAILQ_LAST(&buffer->head, vhead);
925 while (vl != NULL && vl->parent->flags & L_HIDDEN)
926 vl = TAILQ_PREV(vl, vhead, vlines);
928 if (vl == NULL)
929 return;
931 vl->parent->type = LINE_COMPL_CURRENT;
932 buffer->current_line = vl;
935 void
936 cmd_other_window(struct buffer *buffer)
938 ui_other_window();
941 void
942 cmd_mini_scroll_up(struct buffer *buffer)
944 if (!in_minibuffer)
945 return;
947 buffer = &ministate.compl.buffer;
948 if (buffer->current_line == NULL)
949 return;
951 buffer->current_line->parent->type = LINE_COMPL;
952 cmd_scroll_up(buffer);
953 buffer->current_line->parent->type = LINE_COMPL_CURRENT;
956 void
957 cmd_mini_scroll_down(struct buffer *buffer)
959 if (!in_minibuffer)
960 return;
962 buffer = &ministate.compl.buffer;
963 if (buffer->current_line == NULL)
964 return;
966 buffer->current_line->parent->type = LINE_COMPL;
967 cmd_scroll_down(buffer);
968 buffer->current_line->parent->type = LINE_COMPL_CURRENT;
971 void
972 cmd_toggle_downloads(struct buffer *buffer)
974 ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
977 void
978 cmd_cache_info(struct buffer *buffer)
980 size_t npages, tot;
981 char fmt[FMT_SCALED_STRSIZE];
983 mcache_info(&npages, &tot);
985 if (fmt_scaled(tot, fmt) == 0)
986 message("pages: %zu, total: %s", npages, fmt);
987 else
988 message("pages: %zu, total: %zu", npages, tot);