NeoMutt  2025-12-11-872-g385a04
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
complete.c File Reference

Auto-complete NNTP newsgroups. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "adata.h"
#include "mdata.h"
#include "module_data.h"
+ Include dependency graph for complete.c:

Go to the source code of this file.

Functions

int nntp_complete (struct Buffer *buf)
 Auto-complete NNTP newsgroups.
 

Detailed Description

Auto-complete NNTP newsgroups.

Authors
  • Richard Russon
  • Anna Figueiredo Gomes

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file complete.c.

Function Documentation

◆ nntp_complete()

int nntp_complete ( struct Buffer * buf)

Auto-complete NNTP newsgroups.

Parameters
bufBuffer containing pathname
Return values
0Match found
-1No matches

XXX rules

Definition at line 48 of file complete.c.

49{
51 struct NntpAccountData *adata = mod_data->current_news_srv;
52 size_t n = 0;
53 struct Buffer *filepart = buf_new(buf_string(buf));
54 bool init = false;
55
56 /* special case to handle when there is no filepart yet
57 * find the first subscribed newsgroup */
58 int len = buf_len(filepart);
59 if (len == 0)
60 {
61 for (; n < adata->groups_num; n++)
62 {
63 struct NntpMboxData *mdata = adata->groups_list[n];
64
65 if (mdata && mdata->subscribed)
66 {
67 buf_strcpy(filepart, mdata->group);
68 init = true;
69 n++;
70 break;
71 }
72 }
73 }
74
75 for (; n < adata->groups_num; n++)
76 {
77 struct NntpMboxData *mdata = adata->groups_list[n];
78
79 if (mdata && mdata->subscribed &&
80 mutt_strn_equal(mdata->group, buf_string(filepart), len))
81 {
82 if (init)
83 {
84 char *str = filepart->data;
85 size_t i;
86 for (i = 0; (str[i] != '\0') && mdata->group[i]; i++)
87 {
88 if (str[i] != mdata->group[i])
89 break;
90 }
91 str[i] = '\0';
92 buf_fix_dptr(filepart);
93 }
94 else
95 {
96 buf_strcpy(filepart, mdata->group);
97 init = true;
98 }
99 }
100 }
101
102 buf_copy(buf, filepart);
103 buf_free(&filepart);
104 return init ? 0 : -1;
105}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:182
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:319
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:304
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:601
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:81
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
char * data
Pointer to data.
Definition buffer.h:37
void * mdata
Driver specific data.
Definition mailbox.h:134
Container for Accounts, Notifications.
Definition neomutt.h:41
NNTP-specific Account data -.
Definition adata.h:36
struct NntpMboxData ** groups_list
List of newsgroups.
Definition adata.h:60
unsigned int groups_num
Number of newsgroups.
Definition adata.h:58
NNTP-specific Mailbox data -.
Definition mdata.h:34
struct NntpAccountData * adata
Account data.
Definition mdata.h:48
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function: