NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
complete.c File Reference

Auto-complete NNTP newsgroups. More...

#include "config.h"
#include <limits.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 (char *buf, size_t buflen)
 Auto-complete NNTP newsgroups. More...
 

Detailed Description

Auto-complete NNTP newsgroups.

Authors
  • Richard Russon

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 ( char *  buf,
size_t  buflen 
)

Auto-complete NNTP newsgroups.

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

XXX rules

Definition at line 47 of file complete.c.

48 {
50  size_t n = 0;
51  char filepart[PATH_MAX];
52  bool init = false;
53 
54  mutt_str_copy(filepart, buf, sizeof(filepart));
55 
56  /* special case to handle when there is no filepart yet
57  * find the first subscribed newsgroup */
58  int len = mutt_str_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  mutt_str_copy(filepart, mdata->group, sizeof(filepart));
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 && mutt_strn_equal(mdata->group, filepart, len))
80  {
81  if (init)
82  {
83  size_t i;
84  for (i = 0; filepart[i] && mdata->group[i]; i++)
85  {
86  if (filepart[i] != mdata->group[i])
87  break;
88  }
89  filepart[i] = '\0';
90  }
91  else
92  {
93  mutt_str_copy(filepart, mdata->group, sizeof(filepart));
94  init = true;
95  }
96  }
97  }
98 
99  mutt_str_copy(buf, filepart, buflen);
100  return init ? 0 : -1;
101 }
NNTP-specific Account data -.
Definition: adata.h:36
bool subscribed
Definition: mdata.h:41
char * group
Definition: mdata.h:34
void * mdata
Driver specific data.
Definition: mailbox.h:136
#define PATH_MAX
Definition: mutt.h:40
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
unsigned int groups_num
Definition: adata.h:59
NNTP-specific Mailbox data -.
Definition: mdata.h:32
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:749
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:593
void ** groups_list
Definition: adata.h:61
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function: