NeoMutt  2024-04-25-89-g194907
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 "lib.h"
#include "adata.h"
#include "mdata.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 46 of file complete.c.

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
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
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function: