Improve linetrack interface
* include/mailutils/locus.h (mu_linetrack_rebase): New proto. * libmailutils/locus/linetrack.c (mu_linetrack_rebase): New function. * libmailutils/diag/diag.c (mu_diag_at_locus_range): New function.
Showing
3 changed files
with
66 additions
and
13 deletions
... | @@ -65,6 +65,7 @@ void mu_lrange_debug (struct mu_locus_range const *loc, | ... | @@ -65,6 +65,7 @@ void mu_lrange_debug (struct mu_locus_range const *loc, |
65 | 65 | ||
66 | int mu_linetrack_create (mu_linetrack_t *ret, | 66 | int mu_linetrack_create (mu_linetrack_t *ret, |
67 | char const *file_name, size_t max_lines); | 67 | char const *file_name, size_t max_lines); |
68 | int mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt); | ||
68 | void mu_linetrack_free (mu_linetrack_t trk); | 69 | void mu_linetrack_free (mu_linetrack_t trk); |
69 | void mu_linetrack_destroy (mu_linetrack_t *trk); | 70 | void mu_linetrack_destroy (mu_linetrack_t *trk); |
70 | void mu_linetrack_advance (mu_linetrack_t trk, | 71 | void mu_linetrack_advance (mu_linetrack_t trk, | ... | ... |
... | @@ -29,6 +29,7 @@ | ... | @@ -29,6 +29,7 @@ |
29 | #include <mailutils/errno.h> | 29 | #include <mailutils/errno.h> |
30 | #include <mailutils/stdstream.h> | 30 | #include <mailutils/stdstream.h> |
31 | #include <mailutils/stream.h> | 31 | #include <mailutils/stream.h> |
32 | #include <mailutils/locus.h> | ||
32 | 33 | ||
33 | void | 34 | void |
34 | mu_diag_init () | 35 | mu_diag_init () |
... | @@ -71,6 +72,37 @@ mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...) | ... | @@ -71,6 +72,37 @@ mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...) |
71 | } | 72 | } |
72 | 73 | ||
73 | void | 74 | void |
75 | mu_diag_at_locus_range (int level, struct mu_locus_range const *loc, | ||
76 | const char *fmt, ...) | ||
77 | { | ||
78 | va_list ap; | ||
79 | struct mu_locus_range old = MU_LOCUS_RANGE_INITIALIZER; | ||
80 | int restore = 0; | ||
81 | |||
82 | if (loc) | ||
83 | { | ||
84 | if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
85 | MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &old) == 0) | ||
86 | { | ||
87 | mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
88 | MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, (void*) loc); | ||
89 | restore = 1; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | va_start (ap, fmt); | ||
94 | mu_diag_voutput (level, fmt, ap); | ||
95 | va_end (ap); | ||
96 | |||
97 | if (restore) | ||
98 | { | ||
99 | mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, | ||
100 | MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &old); | ||
101 | mu_locus_range_deinit (&old); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void | ||
74 | mu_diag_vprintf (int level, const char *fmt, va_list ap) | 106 | mu_diag_vprintf (int level, const char *fmt, va_list ap) |
75 | { | 107 | { |
76 | mu_diag_init (); | 108 | mu_diag_init (); | ... | ... |
... | @@ -28,9 +28,27 @@ struct mu_linetrack | ... | @@ -28,9 +28,27 @@ struct mu_linetrack |
28 | cols[head + n] (0 <= n <= tos). */ | 28 | cols[head + n] (0 <= n <= tos). */ |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static inline unsigned * | ||
32 | cols_ptr (mu_linetrack_t trk, size_t n) | ||
33 | { | ||
34 | return &trk->cols[(trk->head + n) % trk->max_lines]; | ||
35 | } | ||
36 | |||
37 | static inline unsigned * | ||
38 | cols_tos_ptr (mu_linetrack_t trk) | ||
39 | { | ||
40 | return cols_ptr (trk, trk->tos); | ||
41 | } | ||
42 | |||
43 | static inline unsigned | ||
44 | cols_peek (mu_linetrack_t trk, size_t n) | ||
45 | { | ||
46 | return *cols_ptr (trk, n); | ||
47 | } | ||
48 | |||
31 | int | 49 | int |
32 | mu_linetrack_create (mu_linetrack_t *ret, | 50 | mu_linetrack_create (mu_linetrack_t *ret, |
33 | char const *file_name, size_t max_lines) | 51 | char const *file_name, size_t max_lines) |
34 | { | 52 | { |
35 | int rc; | 53 | int rc; |
36 | struct mu_linetrack *trk; | 54 | struct mu_linetrack *trk; |
... | @@ -65,6 +83,20 @@ mu_linetrack_create (mu_linetrack_t *ret, | ... | @@ -65,6 +83,20 @@ mu_linetrack_create (mu_linetrack_t *ret, |
65 | return 0; | 83 | return 0; |
66 | } | 84 | } |
67 | 85 | ||
86 | int | ||
87 | mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt) | ||
88 | { | ||
89 | char const *file_name; | ||
90 | int rc = mu_ident_ref (pt->mu_file, &file_name); | ||
91 | if (rc) | ||
92 | return rc; | ||
93 | mu_ident_deref (trk->file_name); | ||
94 | trk->file_name = file_name; | ||
95 | trk->hline = pt->mu_line; | ||
96 | *cols_ptr (trk, 0) = pt->mu_col; | ||
97 | return 0; | ||
98 | } | ||
99 | |||
68 | void | 100 | void |
69 | mu_linetrack_free (mu_linetrack_t trk) | 101 | mu_linetrack_free (mu_linetrack_t trk) |
70 | { | 102 | { |
... | @@ -87,18 +119,6 @@ mu_linetrack_destroy (mu_linetrack_t *trk) | ... | @@ -87,18 +119,6 @@ mu_linetrack_destroy (mu_linetrack_t *trk) |
87 | } | 119 | } |
88 | 120 | ||
89 | static inline unsigned * | 121 | static inline unsigned * |
90 | cols_tos_ptr (mu_linetrack_t trk) | ||
91 | { | ||
92 | return &trk->cols[(trk->head + trk->tos) % trk->max_lines]; | ||
93 | } | ||
94 | |||
95 | static inline unsigned | ||
96 | cols_peek (mu_linetrack_t trk, size_t n) | ||
97 | { | ||
98 | return trk->cols[(trk->head + n) % trk->max_lines]; | ||
99 | } | ||
100 | |||
101 | static inline unsigned * | ||
102 | push (mu_linetrack_t trk) | 122 | push (mu_linetrack_t trk) |
103 | { | 123 | { |
104 | unsigned *ptr; | 124 | unsigned *ptr; | ... | ... |
-
Please register or sign in to post a comment