NeoMutt  2024-10-02-7-gd3e66a
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
complete.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include "mutt/lib.h"
34#include "lib.h"
35#include "adata.h"
36#include "mdata.h"
37
46int nntp_complete(struct Buffer *buf)
47{
49 size_t n = 0;
50 struct Buffer *filepart = buf_new(buf_string(buf));
51 bool init = false;
52
53 /* special case to handle when there is no filepart yet
54 * find the first subscribed newsgroup */
55 int len = buf_len(filepart);
56 if (len == 0)
57 {
58 for (; n < adata->groups_num; n++)
59 {
60 struct NntpMboxData *mdata = adata->groups_list[n];
61
62 if (mdata && mdata->subscribed)
63 {
64 buf_strcpy(filepart, mdata->group);
65 init = true;
66 n++;
67 break;
68 }
69 }
70 }
71
72 for (; n < adata->groups_num; n++)
73 {
74 struct NntpMboxData *mdata = adata->groups_list[n];
75
76 if (mdata && mdata->subscribed &&
77 mutt_strn_equal(mdata->group, buf_string(filepart), len))
78 {
79 if (init)
80 {
81 char *str = filepart->data;
82 size_t i;
83 for (i = 0; (str[i] != '\0') && mdata->group[i]; i++)
84 {
85 if (str[i] != mdata->group[i])
86 break;
87 }
88 str[i] = '\0';
89 buf_fix_dptr(filepart);
90 }
91 else
92 {
93 buf_strcpy(filepart, mdata->group);
94 init = true;
95 }
96 }
97 }
98
99 buf_copy(buf, filepart);
100 buf_free(&filepart);
101 return init ? 0 : -1;
102}
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
Convenience wrapper for the library headers.
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:425
int nntp_complete(struct Buffer *buf)
Auto-complete NNTP newsgroups.
Definition: complete.c:46
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
Notmuch-specific Mailbox data.
Pop-specific Account data.
Key value store.
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:132
NNTP-specific Account data -.
Definition: adata.h:36
unsigned int groups_num
Definition: adata.h:58
void ** groups_list
Definition: adata.h:60
NNTP-specific Mailbox data -.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:48