ajout switch pour les option et verif option valide

This commit is contained in:
PrStein 2023-02-15 23:00:31 +01:00
parent 6aed25817b
commit 9584a8a3dc

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* mode.cpp :+: :+: :+: */ /* mode.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/11 19:19:30 by apommier #+# #+# */ /* Created: 2023/02/11 19:19:30 by apommier #+# #+# */
/* Updated: 2023/02/15 17:02:12 by apommier ### ########.fr */ /* Updated: 2023/02/15 22:57:31 by sadjigui ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,12 +27,85 @@ int search_and_erase(std::string &str, std::string toFind)
return 1; return 1;
} }
void do_chan_option(fdList &allFds, int userNbr, std::string opt /*, channel (string or direct reference or pointer but no copy)*/) // void exec_chan_opt(fdList &allFds, char opt, bool sign)
// {
// (void)allFds;
// char opts[11] = {'o','p','s','i','t','n','m','l','b','v','k'};
// int j = 0;
// for (; opts[j] && opts[j] != opt; j++){}
// switch (j)
// {
// case 0: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 1: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 2: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 3: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 4: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 5: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 6: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 7: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 8: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 9: std::cout << "launching option: " << opt << std::endl;
// break ;
// case 10: std::cout << "launching option: " << opt << std::endl;
// break ;
// default : std::cout << "Not launching option" << std::endl;
// break ;
// }
// }
void do_chan_opt(fdList &allFds, int userNbr, std::string opt /*, channel (string or direct reference or pointer but no copy)*/)
{ {
(void)allFds; (void)allFds;
(void)userNbr; (void)userNbr;
char opts[11] = {'o','p','s','i','t','n','m','l','b','v','k'};
bool sign = true;
if (opt[0] == '-')
sign = false;
for (int i = 0; opt[i]; i++) for (int i = 0; opt[i]; i++)
{ {
// exec_chan_opt(allFds, opt[i], sign);
int j = 0;
for (; opts[j] && opts[j] != opt[i]; j++){}
switch (j)
{
case 0: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 1: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 2: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 3: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 4: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 5: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 6: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 7: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 8: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 9: std::cout << "launching option: " << opt[i] << std::endl;
break ;
case 10: std::cout << "launching option: " << opt[i] << std::endl;
break ;
default : std::cout << "Not launching option" << std::endl;
break ;
}
//mode_i() //mode_i()
//call option //call option
//switch ? if forest? map container ? 2 tab (name and function pointer) ? //switch ? if forest? map container ? 2 tab (name and function pointer) ?
@ -71,7 +144,7 @@ void MODE(std::string buffer, fdList &allFds, int userNbr)
{ {
if (find_channel(allFds, splitBuff[1]) == -1) //if true chan doesn't exist if (find_channel(allFds, splitBuff[1]) == -1) //if true chan doesn't exist
{ {
std::cout << "chan doesn't exist" << std::endl; std::cout << splitBuff[1] << ": No such channel" << std::endl;
// 403 ERR_NOSUCHCHANNEL // 403 ERR_NOSUCHCHANNEL
// "<nom de canal> :No such channel" // "<nom de canal> :No such channel"
return ; return ;
@ -82,6 +155,12 @@ void MODE(std::string buffer, fdList &allFds, int userNbr)
search_and_erase(splitBuff[2], "opsitnmlbvk"); search_and_erase(splitBuff[2], "opsitnmlbvk");
std::cout << "splitbuff[2] after = " << splitBuff[2] << std::endl; std::cout << "splitbuff[2] after = " << splitBuff[2] << std::endl;
if ((splitBuff[2].size() < 2) && (splitBuff[2][0] == '-' || splitBuff[2][0] == '+'))
{
std::cout << "Bad params" << std::endl;
return ;
}
do_chan_opt(allFds, userNbr, splitBuff[2]);
//do_option one by one here (do_chan_opt)? //do_option one by one here (do_chan_opt)?
return ; return ;
} }