Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 5a853927 authored by rswindell's avatar rswindell

Implemented a multiple-choice version of uselect() called mselect().

parent f9526b55
......@@ -98,6 +98,52 @@ int sbbs_t::uselect(int add, uint n, const char *title, const char *item, const
return(uselect_num[i-1]);
}
unsigned count_set_bits(long val)
{
unsigned count = 0;
while(val) {
val &= val-1;
count++;
}
return count;
}
long sbbs_t::mselect(const char *hdr, str_list_t list, unsigned max_selections, const char* item_fmt
,const char* selected_str, const char* unselected_str, const char* prompt_fmt)
{
char prompt[128];
int i;
int max_item_len = 0;
long selected = 0;
for(i=0; list[i] != NULL; i++) {
int len = strlen(list[i]);
if(len > max_item_len)
max_item_len = len;
}
unsigned items = i;
if(max_selections > items)
max_selections = items;
while(online) {
bputs(hdr);
for(i=0; list[i] != NULL; i++)
bprintf(item_fmt, i+1, max_item_len, max_item_len, list[i]
, (selected & (1<<i)) ? selected_str : unselected_str);
SAFEPRINTF(prompt, prompt_fmt, max_selections);
mnemonics(prompt);
i=getnum(items);
if(i < 0)
return 0;
if(i == 0)
break;
if(i && i <= (int)items && (selected&(1<<(i-1)) || count_set_bits(selected) < max_selections))
selected ^= 1<<(i-1);
}
return selected;
}
/****************************************************************************/
/* Prompts user for System Password. Returns 1 if user entered correct PW */
/****************************************************************************/
......
......@@ -706,6 +706,8 @@ public:
int uselect(int add, uint n, const char *title, const char *item, const uchar *ar);
uint uselect_total, uselect_num[500];
long mselect(const char *title, str_list_t list, unsigned max_selections, const char* item_fmt, const char* selected_str, const char* unselected_str, const char* prompt_fmt);
void redrwstr(char *strin, int i, int l, long mode);
void attr(int atr); /* Change local and remote text attributes */
void ctrl_a(char x); /* Peforms the Ctrl-Ax attribute changes */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment