/src/neomutt/nntp/complete.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file |
3 | | * Auto-complete NNTP newsgroups |
4 | | * |
5 | | * @authors |
6 | | * Copyright (C) 2018 Richard Russon <rich@flatcap.org> |
7 | | * |
8 | | * @copyright |
9 | | * This program is free software: you can redistribute it and/or modify it under |
10 | | * the terms of the GNU General Public License as published by the Free Software |
11 | | * Foundation, either version 2 of the License, or (at your option) any later |
12 | | * version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
17 | | * details. |
18 | | * |
19 | | * You should have received a copy of the GNU General Public License along with |
20 | | * this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @page nntp_complete Auto-complete NNTP newsgroups |
25 | | * |
26 | | * Auto-complete NNTP newsgroups |
27 | | */ |
28 | | |
29 | | #include "config.h" |
30 | | #include <stdbool.h> |
31 | | #include <stdio.h> |
32 | | #include "mutt/lib.h" |
33 | | #include "lib.h" |
34 | | #include "adata.h" |
35 | | #include "mdata.h" |
36 | | |
37 | | /** |
38 | | * nntp_complete - Auto-complete NNTP newsgroups |
39 | | * @param buf Buffer containing pathname |
40 | | * @retval 0 Match found |
41 | | * @retval -1 No matches |
42 | | * |
43 | | * XXX rules |
44 | | */ |
45 | | int nntp_complete(struct Buffer *buf) |
46 | 0 | { |
47 | 0 | struct NntpAccountData *adata = CurrentNewsSrv; |
48 | 0 | size_t n = 0; |
49 | 0 | struct Buffer *filepart = buf_new(buf_string(buf)); |
50 | 0 | bool init = false; |
51 | | |
52 | | /* special case to handle when there is no filepart yet |
53 | | * find the first subscribed newsgroup */ |
54 | 0 | int len = buf_len(filepart); |
55 | 0 | if (len == 0) |
56 | 0 | { |
57 | 0 | for (; n < adata->groups_num; n++) |
58 | 0 | { |
59 | 0 | struct NntpMboxData *mdata = adata->groups_list[n]; |
60 | |
|
61 | 0 | if (mdata && mdata->subscribed) |
62 | 0 | { |
63 | 0 | buf_strcpy(filepart, mdata->group); |
64 | 0 | init = true; |
65 | 0 | n++; |
66 | 0 | break; |
67 | 0 | } |
68 | 0 | } |
69 | 0 | } |
70 | |
|
71 | 0 | for (; n < adata->groups_num; n++) |
72 | 0 | { |
73 | 0 | struct NntpMboxData *mdata = adata->groups_list[n]; |
74 | |
|
75 | 0 | if (mdata && mdata->subscribed && |
76 | 0 | mutt_strn_equal(mdata->group, buf_string(filepart), len)) |
77 | 0 | { |
78 | 0 | if (init) |
79 | 0 | { |
80 | 0 | char *str = filepart->data; |
81 | 0 | size_t i; |
82 | 0 | for (i = 0; (str[i] != '\0') && mdata->group[i]; i++) |
83 | 0 | { |
84 | 0 | if (str[i] != mdata->group[i]) |
85 | 0 | break; |
86 | 0 | } |
87 | 0 | str[i] = '\0'; |
88 | 0 | buf_fix_dptr(filepart); |
89 | 0 | } |
90 | 0 | else |
91 | 0 | { |
92 | 0 | buf_strcpy(filepart, mdata->group); |
93 | 0 | init = true; |
94 | 0 | } |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | 0 | buf_copy(buf, filepart); |
99 | 0 | buf_free(&filepart); |
100 | 0 | return init ? 0 : -1; |
101 | 0 | } |