diff options
Diffstat (limited to 'src')
98 files changed, 4059 insertions, 11522 deletions
diff --git a/src/admin/ladmin.cpp b/src/admin/ladmin.cpp index 9bbd710..307e13b 100644 --- a/src/admin/ladmin.cpp +++ b/src/admin/ladmin.cpp @@ -68,9 +68,9 @@ IP4Address login_ip = IP4_LOCALHOST; // IP of login-server static int login_port = 6900; // Port of login-server static -AccountPass admin_pass = stringish<AccountPass>("admin"); // Administration password +AccountPass admin_pass = stringish<AccountPass>("admin"_s); // Administration password static -AString ladmin_log_filename = "log/ladmin.log"; +AString ladmin_log_filename = "log/ladmin.log"_s; //------------------------------------------------------------------------- // LIST of COMMANDs that you can type at the prompt: // To use these commands you can only type only the first letters. @@ -267,7 +267,7 @@ int already_exit_function = 0; // sometimes, the exit function is called twice.. #pragma GCC diagnostic ignored "-Wmissing-noreturn" void SessionDeleter::operator()(SessionData *) { - assert(false && "ladmin does not have sessions"); + assert(false && "ladmin does not have sessions"_s); } #pragma GCC diagnostic pop @@ -289,9 +289,9 @@ static void delete_fromlogin(Session *) { { - PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n", + PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n"_fmt, login_ip, login_port); - LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n", + LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n"_fmt, login_ip, login_port); exit(0); } @@ -352,315 +352,315 @@ void display_help(ZString param) XString command = param.xislice_h(std::find(param.begin(), param.end(), ' ')); if (command.startswith('?')) - command = "help"; + command = "help"_s; - LADMIN_LOG("Displaying of the commands or a command.\n"); + LADMIN_LOG("Displaying of the commands or a command.\n"_fmt); - if (command == "help") + if (command == "help"_s) { - PRINTF("help/?\n"); - PRINTF(" Display the description of the commands\n"); - PRINTF("help/? [command]\n"); - PRINTF(" Display the description of the specified command\n"); + PRINTF("help/?\n"_fmt); + PRINTF(" Display the description of the commands\n"_fmt); + PRINTF("help/? [command]\n"_fmt); + PRINTF(" Display the description of the specified command\n"_fmt); } - else if (command == "add") + else if (command == "add"_s) { - PRINTF("add <account_name> <sex> <password>\n"); - PRINTF(" Create an account with the default email (a@a.com).\n"); - PRINTF(" Concerning the sex, only the first letter is used (F or M).\n"); - PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n"); - PRINTF(" When the password is omitted,\n"); - PRINTF(" the input is done without displaying of the pressed keys.\n"); - PRINTF(" <example> add testname Male testpass\n"); + PRINTF("add <account_name> <sex> <password>\n"_fmt); + PRINTF(" Create an account with the default email (a@a.com).\n"_fmt); + PRINTF(" Concerning the sex, only the first letter is used (F or M).\n"_fmt); + PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n"_fmt); + PRINTF(" When the password is omitted,\n"_fmt); + PRINTF(" the input is done without displaying of the pressed keys.\n"_fmt); + PRINTF(" <example> add testname Male testpass\n"_fmt); } - else if (command == "ban") + else if (command == "ban"_s) { - PRINTF("ban yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" Changes the final date of a banishment of an account.\n"); - PRINTF(" Like banset, but <account name> is at end.\n"); + PRINTF("ban yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" Changes the final date of a banishment of an account.\n"_fmt); + PRINTF(" Like banset, but <account name> is at end.\n"_fmt); } - else if (command == "banadd") + else if (command == "banadd"_s) { - PRINTF("banadd <account_name> <modifier>\n"); - PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n"); - PRINTF(" Modifier is done as follows:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - PRINTF("NOTE: If you modify the final date of a non-banished account,\n"); - PRINTF(" you fix the final date to (actual time +- adjustments)\n"); + PRINTF("banadd <account_name> <modifier>\n"_fmt); + PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n"_fmt); + PRINTF(" Modifier is done as follows:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + PRINTF("NOTE: If you modify the final date of a non-banished account,\n"_fmt); + PRINTF(" you fix the final date to (actual time +- adjustments)\n"_fmt); } - else if (command == "banset") + else if (command == "banset"_s) { - PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" Changes the final date of a banishment of an account.\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - PRINTF("banset <account_name> 0\n"); - PRINTF(" Set a non-banished account (0 = unbanished).\n"); + PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" Changes the final date of a banishment of an account.\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + PRINTF("banset <account_name> 0\n"_fmt); + PRINTF(" Set a non-banished account (0 = unbanished).\n"_fmt); } - else if (command == "block") + else if (command == "block"_s) { - PRINTF("block <account name>\n"); - PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n"); - PRINTF(" This command works like state <account_name> 5.\n"); + PRINTF("block <account name>\n"_fmt); + PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n"_fmt); + PRINTF(" This command works like state <account_name> 5.\n"_fmt); } - else if (command == "check") + else if (command == "check"_s) { - PRINTF("check <account_name> <password>\n"); - PRINTF(" Check the validity of a password for an account.\n"); - PRINTF(" NOTE: Server will never sends back a password.\n"); - PRINTF(" It's the only method you have to know if a password is correct.\n"); - PRINTF(" The other method is to have a ('physical') access to the accounts file.\n"); + PRINTF("check <account_name> <password>\n"_fmt); + PRINTF(" Check the validity of a password for an account.\n"_fmt); + PRINTF(" NOTE: Server will never sends back a password.\n"_fmt); + PRINTF(" It's the only method you have to know if a password is correct.\n"_fmt); + PRINTF(" The other method is to have a ('physical') access to the accounts file.\n"_fmt); } - else if (command == "create") + else if (command == "create"_s) { - PRINTF("create <account_name> <sex> <email> <password>\n"); - PRINTF(" Like the 'add' command, but with e-mail moreover.\n"); - PRINTF(" <example> create testname Male my@mail.com testpass\n"); + PRINTF("create <account_name> <sex> <email> <password>\n"_fmt); + PRINTF(" Like the 'add' command, but with e-mail moreover.\n"_fmt); + PRINTF(" <example> create testname Male my@mail.com testpass\n"_fmt); } - else if (command == "delete") + else if (command == "delete"_s) { - PRINTF("delete <account name>\n"); - PRINTF(" Remove an account.\n"); - PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n"); + PRINTF("delete <account name>\n"_fmt); + PRINTF(" Remove an account.\n"_fmt); + PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n"_fmt); } - else if (command == "email") + else if (command == "email"_s) { - PRINTF("email <account_name> <email>\n"); - PRINTF(" Modify the e-mail of an account.\n"); + PRINTF("email <account_name> <email>\n"_fmt); + PRINTF(" Modify the e-mail of an account.\n"_fmt); } - else if (command == "getcount") + else if (command == "getcount"_s) { - PRINTF("getcount\n"); - PRINTF(" Give the number of players online on all char-servers.\n"); + PRINTF("getcount\n"_fmt); + PRINTF(" Give the number of players online on all char-servers.\n"_fmt); } - else if (command == "gm") + else if (command == "gm"_s) { - PRINTF("gm <account_name> [GM_level]\n"); - PRINTF(" Modify the GM level of an account.\n"); - PRINTF(" Default value remove GM level (GM level = 0).\n"); - PRINTF(" <example> gm testname 80\n"); + PRINTF("gm <account_name> [GM_level]\n"_fmt); + PRINTF(" Modify the GM level of an account.\n"_fmt); + PRINTF(" Default value remove GM level (GM level = 0).\n"_fmt); + PRINTF(" <example> gm testname 80\n"_fmt); } - else if (command == "id") + else if (command == "id"_s) { - PRINTF("id <account name>\n"); - PRINTF(" Give the id of an account.\n"); + PRINTF("id <account name>\n"_fmt); + PRINTF(" Give the id of an account.\n"_fmt); } - else if (command == "info") + else if (command == "info"_s) { - PRINTF("info <account_id>\n"); - PRINTF(" Display complete information of an account.\n"); + PRINTF("info <account_id>\n"_fmt); + PRINTF(" Display complete information of an account.\n"_fmt); } - else if (command == "kami") + else if (command == "kami"_s) { - PRINTF("kami <message>\n"); - PRINTF(" Sends a broadcast message on all map-server (in yellow).\n"); + PRINTF("kami <message>\n"_fmt); + PRINTF(" Sends a broadcast message on all map-server (in yellow).\n"_fmt); } - else if (command == "kamib") + else if (command == "kamib"_s) { - PRINTF("kamib <message>\n"); - PRINTF(" Sends a broadcast message on all map-server (in blue).\n"); + PRINTF("kamib <message>\n"_fmt); + PRINTF(" Sends a broadcast message on all map-server (in blue).\n"_fmt); } - else if (command == "list") + else if (command == "list"_s) { - PRINTF("list/ls [start_id [end_id]]\n"); - PRINTF(" Display a list of accounts.\n"); - PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n"); - PRINTF(" Research by name is not possible with this command.\n"); - PRINTF(" <example> list 10 9999999\n"); + PRINTF("list/ls [start_id [end_id]]\n"_fmt); + PRINTF(" Display a list of accounts.\n"_fmt); + PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n"_fmt); + PRINTF(" Research by name is not possible with this command.\n"_fmt); + PRINTF(" <example> list 10 9999999\n"_fmt); } - else if (command == "itemfrob") + else if (command == "itemfrob"_s) { - PRINTF("itemfrob <source-id> <dest-id>\n"); - PRINTF(" Translates item IDs for all accounts.\n"); - PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n"); - PRINTF(" <example> itemfrob 500 700\n"); + PRINTF("itemfrob <source-id> <dest-id>\n"_fmt); + PRINTF(" Translates item IDs for all accounts.\n"_fmt); + PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n"_fmt); + PRINTF(" <example> itemfrob 500 700\n"_fmt); } - else if (command == "listban") + else if (command == "listban"_s) { - PRINTF("listban [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for accounts with state or banished.\n"); + PRINTF("listban [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for accounts with state or banished.\n"_fmt); } - else if (command == "listgm") + else if (command == "listgm"_s) { - PRINTF("listgm [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for GM accounts.\n"); + PRINTF("listgm [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for GM accounts.\n"_fmt); } - else if (command == "listok") + else if (command == "listok"_s) { - PRINTF("listok [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for accounts without state and not banished.\n"); + PRINTF("listok [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for accounts without state and not banished.\n"_fmt); } - else if (command == "memo") + else if (command == "memo"_s) { - PRINTF("memo <account_name> <memo>\n"); - PRINTF(" Modify the memo of an account.\n"); - PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n"); + PRINTF("memo <account_name> <memo>\n"_fmt); + PRINTF(" Modify the memo of an account.\n"_fmt); + PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n"_fmt); } - else if (command == "name") + else if (command == "name"_s) { - PRINTF("name <account_id>\n"); - PRINTF(" Give the name of an account.\n"); + PRINTF("name <account_id>\n"_fmt); + PRINTF(" Give the name of an account.\n"_fmt); } - else if (command == "password") + else if (command == "password"_s) { - PRINTF("password <account_name> <new_password>\n"); - PRINTF(" Change the password of an account.\n"); - PRINTF(" When new password is omitted,\n"); - PRINTF(" the input is done without displaying of the pressed keys.\n"); + PRINTF("password <account_name> <new_password>\n"_fmt); + PRINTF(" Change the password of an account.\n"_fmt); + PRINTF(" When new password is omitted,\n"_fmt); + PRINTF(" the input is done without displaying of the pressed keys.\n"_fmt); } - else if (command == "reloadgm") + else if (command == "reloadgm"_s) { - PRINTF("reloadGM\n"); - PRINTF(" Reload GM configuration file\n"); + PRINTF("reloadGM\n"_fmt); + PRINTF(" Reload GM configuration file\n"_fmt); } - else if (command == "search") + else if (command == "search"_s) { - PRINTF("search <expression>\n"); - PRINTF(" Seek accounts.\n"); - PRINTF(" Displays the accounts whose names correspond.\n"); + PRINTF("search <expression>\n"_fmt); + PRINTF(" Seek accounts.\n"_fmt); + PRINTF(" Displays the accounts whose names correspond.\n"_fmt); } - else if (command == "sex") + else if (command == "sex"_s) { - PRINTF("sex <account_name> <sex>\n"); - PRINTF(" Modify the sex of an account.\n"); - PRINTF(" <example> sex testname Male\n"); + PRINTF("sex <account_name> <sex>\n"_fmt); + PRINTF(" Modify the sex of an account.\n"_fmt); + PRINTF(" <example> sex testname Male\n"_fmt); } - else if (command == "state") + else if (command == "state"_s) { - PRINTF("state <account_name> <new_state> <error_message_#7>\n"); - PRINTF(" Change the state of an account.\n"); - PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n"); - PRINTF(" The possibilities are:\n"); - PRINTF(" 0 = Account ok\n"); - PRINTF(" 1 = Unregistered ID\n"); - PRINTF(" 2 = Incorrect Password\n"); - PRINTF(" 3 = This ID is expired\n"); - PRINTF(" 4 = Rejected from Server\n"); - PRINTF(" 5 = You have been blocked by the GM Team\n"); - PRINTF(" 6 = Your Game's EXE file is not the latest version\n"); - PRINTF(" 7 = You are Prohibited to log in until...\n"); - PRINTF(" 8 = Server is jammed due to over populated\n"); - PRINTF(" 9 = No MSG\n"); - PRINTF(" 100 = This ID has been totally erased\n"); - PRINTF(" all other values are 'No MSG', then use state 9 please.\n"); - PRINTF(" 'error_message_#7': message of the code error 6\n"); - PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n"); + PRINTF("state <account_name> <new_state> <error_message_#7>\n"_fmt); + PRINTF(" Change the state of an account.\n"_fmt); + PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n"_fmt); + PRINTF(" The possibilities are:\n"_fmt); + PRINTF(" 0 = Account ok\n"_fmt); + PRINTF(" 1 = Unregistered ID\n"_fmt); + PRINTF(" 2 = Incorrect Password\n"_fmt); + PRINTF(" 3 = This ID is expired\n"_fmt); + PRINTF(" 4 = Rejected from Server\n"_fmt); + PRINTF(" 5 = You have been blocked by the GM Team\n"_fmt); + PRINTF(" 6 = Your Game's EXE file is not the latest version\n"_fmt); + PRINTF(" 7 = You are Prohibited to log in until...\n"_fmt); + PRINTF(" 8 = Server is jammed due to over populated\n"_fmt); + PRINTF(" 9 = No MSG\n"_fmt); + PRINTF(" 100 = This ID has been totally erased\n"_fmt); + PRINTF(" all other values are 'No MSG', then use state 9 please.\n"_fmt); + PRINTF(" 'error_message_#7': message of the code error 6\n"_fmt); + PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n"_fmt); } - else if (command == "timeadd") + else if (command == "timeadd"_s) { - PRINTF("timeadd <account_name> <modifier>\n"); - PRINTF(" Adds or substracts time from the validity limit of an account.\n"); - PRINTF(" Modifier is done as follows:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - PRINTF("NOTE: You can not modify a unlimited validity limit.\n"); - PRINTF(" If you want modify it, you want probably create a limited validity limit.\n"); - PRINTF(" So, at first, you must set the validity limit to a date/time.\n"); + PRINTF("timeadd <account_name> <modifier>\n"_fmt); + PRINTF(" Adds or substracts time from the validity limit of an account.\n"_fmt); + PRINTF(" Modifier is done as follows:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + PRINTF("NOTE: You can not modify a unlimited validity limit.\n"_fmt); + PRINTF(" If you want modify it, you want probably create a limited validity limit.\n"_fmt); + PRINTF(" So, at first, you must set the validity limit to a date/time.\n"_fmt); } - else if (command == "timeadd") + else if (command == "timeadd"_s) { - PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" Changes the validity limit of an account.\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - PRINTF("timeset <account_name> 0\n"); - PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n"); + PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" Changes the validity limit of an account.\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + PRINTF("timeset <account_name> 0\n"_fmt); + PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n"_fmt); } - else if (command == "unban") + else if (command == "unban"_s) { - PRINTF("unban/unbanish <account name>\n"); - PRINTF(" Remove the banishment of an account.\n"); - PRINTF(" This command works like banset <account_name> 0.\n"); + PRINTF("unban/unbanish <account name>\n"_fmt); + PRINTF(" Remove the banishment of an account.\n"_fmt); + PRINTF(" This command works like banset <account_name> 0.\n"_fmt); } - else if (command == "unblock") + else if (command == "unblock"_s) { - PRINTF("unblock <account name>\n"); - PRINTF(" Set state 0 (Account ok) to an account.\n"); - PRINTF(" This command works like state <account_name> 0.\n"); + PRINTF("unblock <account name>\n"_fmt); + PRINTF(" Set state 0 (Account ok) to an account.\n"_fmt); + PRINTF(" This command works like state <account_name> 0.\n"_fmt); } - else if (command == "version") + else if (command == "version"_s) { - PRINTF("version\n"); - PRINTF(" Display the version of the login-server.\n"); + PRINTF("version\n"_fmt); + PRINTF(" Display the version of the login-server.\n"_fmt); } - else if (command == "who") + else if (command == "who"_s) { - PRINTF("who <account name>\n"); - PRINTF(" Displays complete information of an account.\n"); + PRINTF("who <account name>\n"_fmt); + PRINTF(" Displays complete information of an account.\n"_fmt); } - else if (command == "quit" - || command == "exit" - || command == "end") - { - PRINTF("quit/end/exit\n"); - PRINTF(" End of the program of administration.\n"); + else if (command == "quit"_s + || command == "exit"_s + || command == "end"_s) + { + PRINTF("quit/end/exit\n"_fmt); + PRINTF(" End of the program of administration.\n"_fmt); } else { if (command) - PRINTF("Unknown command [%s] for help. Displaying of all commands.\n", + PRINTF("Unknown command [%s] for help. Displaying of all commands.\n"_fmt, AString(command)); - PRINTF(" help/? -- Display this help\n"); - PRINTF(" help/? [command] -- Display the help of the command\n"); - PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n"); - PRINTF(" ban yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n"); - PRINTF(" banadd <account_name> <modifier> -- Add or substract time from the final\n"); - PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n"); - PRINTF(" banset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n"); - PRINTF(" banset <account_name> 0 -- Un-banish an account\n"); - PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n"); - PRINTF(" check <account_name> <password> -- Check the validity of a password\n"); - PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n"); - PRINTF(" delete <account name> -- Remove an account\n"); - PRINTF(" email <account_name> <email> -- Modify an email of an account\n"); - PRINTF(" getcount -- Give the number of players online\n"); - PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n"); - PRINTF(" id <account name> -- Give the id of an account\n"); - PRINTF(" info <account_id> -- Display all information of an account\n"); - PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n"); - PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n"); - PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n"); - PRINTF(" list [First_id [Last_id]] -- Display a list of accounts\n"); - PRINTF(" listban [First_id [Last_id] ] -- Display a list of accounts\n"); - PRINTF(" with state or banished\n"); - PRINTF(" listgm [First_id [Last_id]] -- Display a list of GM accounts\n"); - PRINTF(" listok [First_id [Last_id] ] -- Display a list of accounts\n"); - PRINTF(" without state and not banished\n"); - PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n"); - PRINTF(" name <account_id> -- Give the name of an account\n"); - PRINTF(" password <account_name> <new_password> -- Change the password of an account\n"); - PRINTF(" quit/end/exit -- End of the program of administation\n"); - PRINTF(" reloadGM -- Reload GM configuration file\n"); - PRINTF(" search <expression> -- Seek accounts\n"); - PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n"); - PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n"); - PRINTF(" timeadd <account_name> <modifier> -- Add or substract time from the\n"); - PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n"); - PRINTF(" timeset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n"); - PRINTF(" timeset <account_name> 0 -- Give a unlimited validity limit\n"); - PRINTF(" unban <account name> -- Remove the banishment of an account\n"); - PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n"); - PRINTF(" version -- Gives the version of the login-server\n"); - PRINTF(" who <account name> -- Display all information of an account\n"); - PRINTF(" who <account name> -- Display all information of an account\n"); - PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n"); + PRINTF(" help/? -- Display this help\n"_fmt); + PRINTF(" help/? [command] -- Display the help of the command\n"_fmt); + PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n"_fmt); + PRINTF(" ban yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n"_fmt); + PRINTF(" banadd <account_name> <modifier> -- Add or substract time from the final\n"_fmt); + PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n"_fmt); + PRINTF(" banset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n"_fmt); + PRINTF(" banset <account_name> 0 -- Un-banish an account\n"_fmt); + PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n"_fmt); + PRINTF(" check <account_name> <password> -- Check the validity of a password\n"_fmt); + PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n"_fmt); + PRINTF(" delete <account name> -- Remove an account\n"_fmt); + PRINTF(" email <account_name> <email> -- Modify an email of an account\n"_fmt); + PRINTF(" getcount -- Give the number of players online\n"_fmt); + PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n"_fmt); + PRINTF(" id <account name> -- Give the id of an account\n"_fmt); + PRINTF(" info <account_id> -- Display all information of an account\n"_fmt); + PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n"_fmt); + PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n"_fmt); + PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n"_fmt); + PRINTF(" list [First_id [Last_id]] -- Display a list of accounts\n"_fmt); + PRINTF(" listban [First_id [Last_id] ] -- Display a list of accounts\n"_fmt); + PRINTF(" with state or banished\n"_fmt); + PRINTF(" listgm [First_id [Last_id]] -- Display a list of GM accounts\n"_fmt); + PRINTF(" listok [First_id [Last_id] ] -- Display a list of accounts\n"_fmt); + PRINTF(" without state and not banished\n"_fmt); + PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n"_fmt); + PRINTF(" name <account_id> -- Give the name of an account\n"_fmt); + PRINTF(" password <account_name> <new_password> -- Change the password of an account\n"_fmt); + PRINTF(" quit/end/exit -- End of the program of administation\n"_fmt); + PRINTF(" reloadGM -- Reload GM configuration file\n"_fmt); + PRINTF(" search <expression> -- Seek accounts\n"_fmt); + PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n"_fmt); + PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n"_fmt); + PRINTF(" timeadd <account_name> <modifier> -- Add or substract time from the\n"_fmt); + PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n"_fmt); + PRINTF(" timeset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n"_fmt); + PRINTF(" timeset <account_name> 0 -- Give a unlimited validity limit\n"_fmt); + PRINTF(" unban <account name> -- Remove the banishment of an account\n"_fmt); + PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n"_fmt); + PRINTF(" version -- Gives the version of the login-server\n"_fmt); + PRINTF(" who <account name> -- Display all information of an account\n"_fmt); + PRINTF(" who <account name> -- Display all information of an account\n"_fmt); + PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n"_fmt); } } @@ -680,9 +680,9 @@ void addaccount(ZString param, int emailflag) // add command if (!qsplit(param, &name, &sex_, &password)) { - PRINTF("Please input an account name, a sex and a password.\n"); - PRINTF("<example> add testname Male testpass\n"); - LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n"); + PRINTF("Please input an account name, a sex and a password.\n"_fmt); + PRINTF("<example> add testname Male testpass\n"_fmt); + LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n"_fmt); return; } email_ = DEFAULT_EMAIL; @@ -692,9 +692,9 @@ void addaccount(ZString param, int emailflag) // 1: create command if (!qsplit(param, &name, &sex_, &email_, &password)) { - PRINTF("Please input an account name, a sex and a password.\n"); - PRINTF("<example> create testname Male my@mail.com testpass\n"); - LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n"); + PRINTF("Please input an account name, a sex and a password.\n"_fmt); + PRINTF("<example> create testname Male my@mail.com testpass\n"_fmt); + LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n"_fmt); return; } } @@ -702,18 +702,18 @@ void addaccount(ZString param, int emailflag) if (!name.is_print()) return; - if (!XString("MF").contains(sex)) + if (!"MF"_s.contains(sex)) { - PRINTF("Illegal gender [%c]. Please input M or F.\n", sex); - LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n", sex); + PRINTF("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); + LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); return; } if (!e_mail_check(email_)) { - PRINTF("Invalid email [%s]. Please input a valid e-mail.\n", + PRINTF("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); - LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n", + LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); return; } @@ -722,7 +722,7 @@ void addaccount(ZString param, int emailflag) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to create an account.\n"); + LADMIN_LOG("Request to login-server to create an account.\n"_fmt); WFIFOW(login_session, 0) = 0x7930; WFIFO_STRING(login_session, 2, name, 24); @@ -744,11 +744,11 @@ void banaddaccount(ZString param) if (!qsplit(param, &name, &modif)) { - PRINTF("Please input an account name and a modifier.\n"); - PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n"); + PRINTF("Please input an account name and a modifier.\n"_fmt); + PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n"_fmt); return; } if (!name.is_print()) @@ -756,23 +756,23 @@ void banaddaccount(ZString param) if (!modif) { - PRINTF("Please give an adjustment with this command:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n"); + PRINTF("Please give an adjustment with this command:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to modify a ban date/time.\n"); + LADMIN_LOG("Request to login-server to modify a ban date/time.\n"_fmt); WFIFOW(login_session, 0) = 0x794c; WFIFO_STRING(login_session, 2, name, 24); @@ -798,19 +798,19 @@ void bansetaccountsub(AccountName name, XString date, XString time_) if (!name.is_print()) return; - if (date != "0" + if (date != "0"_s && ((!extract(date, record<'/'>(&year, &month, &day)) && !extract(date, record<'-'>(&year, &month, &day)) && !extract(date, record<'.'>(&year, &month, &day))) || !extract(time_, record<':'>(&hour, &minute, &second)))) { - PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"); - PRINTF("You can imput 0 instead of if you use 'banset' command.\n"); - LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n"); + PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"_fmt); + PRINTF("You can imput 0 instead of if you use 'banset' command.\n"_fmt); + LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n"_fmt); return; } - if (date == "0") + if (date == "0"_s) { ban_until_time = TimeT(); } @@ -826,41 +826,41 @@ void bansetaccountsub(AccountName name, XString date, XString time_) } if (month < 1 || month > 12) { - PRINTF("Please give a correct value for the month (from 1 to 12).\n"); - LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the month (from 1 to 12).\n"_fmt); + LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n"_fmt); return; } month = month - 1; if (day < 1 || day > 31) { - PRINTF("Please give a correct value for the day (from 1 to 31).\n"); - LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the day (from 1 to 31).\n"_fmt); + LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n"_fmt); return; } if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) || (month == 1 && day > 29)) { - PRINTF("Please give a correct value for a day of this month (%d).\n", + PRINTF("Please give a correct value for a day of this month (%d).\n"_fmt, month); - LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n"); + LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n"_fmt); return; } if (hour < 0 || hour > 23) { - PRINTF("Please give a correct value for the hour (from 0 to 23).\n"); - LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the hour (from 0 to 23).\n"_fmt); + LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n"_fmt); return; } if (minute < 0 || minute > 59) { - PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"); - LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n"_fmt); return; } if (second < 0 || second > 59) { - PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"); - LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n"_fmt); return; } tmtime.tm_year = year; @@ -873,15 +873,15 @@ void bansetaccountsub(AccountName name, XString date, XString time_) ban_until_time = tmtime; if (ban_until_time.error()) { - PRINTF("Invalid date.\n"); - PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"); - PRINTF("You can imput 0 instead of if you use 'banset' command.\n"); - LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n"); + PRINTF("Invalid date.\n"_fmt); + PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"_fmt); + PRINTF("You can imput 0 instead of if you use 'banset' command.\n"_fmt); + LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to set a ban.\n"); + LADMIN_LOG("Request to login-server to set a ban.\n"_fmt); WFIFOW(login_session, 0) = 0x794a; WFIFO_STRING(login_session, 2, name, 24); @@ -902,18 +902,18 @@ void banaccount(ZString param) if (!qsplit(param, &date, &time_, &name)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"_fmt); return; } if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; bansetaccountsub(name, date, time_); } @@ -931,18 +931,18 @@ void bansetaccount(ZString param) if (!qsplit(param, &name, &date, &time_) && !qsplit(param, &name, &date)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"_fmt); return; } if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; bansetaccountsub(name, date, time_); } @@ -957,17 +957,17 @@ void unbanaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n"_fmt); return; } - bansetaccountsub(name, "0", ""); + bansetaccountsub(name, "0"_s, ""_s); } //--------------------------------------------------------- @@ -982,9 +982,9 @@ void checkaccount(ZString param) if (!qsplit(param, &name, &password)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> check testname password\n"); - LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> check testname password\n"_fmt); + LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n"_fmt); return; } @@ -994,7 +994,7 @@ void checkaccount(ZString param) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to check a password.\n"); + LADMIN_LOG("Request to login-server to check a password.\n"_fmt); WFIFOW(login_session, 0) = 0x793a; WFIFO_STRING(login_session, 2, name, 24); @@ -1013,9 +1013,9 @@ void delaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> delete testnametodelete\n"); - LADMIN_LOG("No name given to delete an account ('delete' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> delete testnametodelete\n"_fmt); + LADMIN_LOG("No name given to delete an account ('delete' command).\n"_fmt); return; } @@ -1025,7 +1025,7 @@ void delaccount(ZString param) char confirm; do { - PRINTF(SGR_BOLD SGR_CYAN " ** Are you really sure to DELETE account [%s]? (y/n) > " SGR_RESET, name); + PRINTF(SGR_BOLD SGR_CYAN " ** Are you really sure to DELETE account [%s]? (y/n) > " SGR_RESET ""_fmt, name); fflush(stdout); int seek = getchar(); confirm = seek; @@ -1035,16 +1035,16 @@ void delaccount(ZString param) while (seek != '\n' && seek != EOF) seek = getchar(); } - while (!XString("yn").contains(confirm)); + while (!"yn"_s.contains(confirm)); if (confirm == 'n') { - PRINTF("Deletion canceled.\n"); - LADMIN_LOG("Deletion canceled by user ('delete' command).\n"); + PRINTF("Deletion canceled.\n"_fmt); + LADMIN_LOG("Deletion canceled by user ('delete' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to delete an acount.\n"); + LADMIN_LOG("Request to login-server to delete an acount.\n"_fmt); WFIFOW(login_session, 0) = 0x7932; WFIFO_STRING(login_session, 2, name, 24); @@ -1062,9 +1062,9 @@ void changeemail(ZString param) XString email_; if (!qsplit(param, &name, &email_)) { - PRINTF("Please input an account name and an email.\n"); - PRINTF("<example> email testname newemail\n"); - LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n"); + PRINTF("Please input an account name and an email.\n"_fmt); + PRINTF("<example> email testname newemail\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n"_fmt); return; } @@ -1073,15 +1073,15 @@ void changeemail(ZString param) if (!e_mail_check(email_)) { - PRINTF("Invalid email [%s]. Please input a valid e-mail.\n", + PRINTF("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); - LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n", + LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); return; } AccountEmail email = stringish<AccountEmail>(email_); - LADMIN_LOG("Request to login-server to change an email.\n"); + LADMIN_LOG("Request to login-server to change an email.\n"_fmt); WFIFOW(login_session, 0) = 0x7940; WFIFO_STRING(login_session, 2, name, 24); @@ -1096,7 +1096,7 @@ void changeemail(ZString param) static void getlogincount(void) { - LADMIN_LOG("Request to login-server to obtain the # of online players.\n"); + LADMIN_LOG("Request to login-server to obtain the # of online players.\n"_fmt); WFIFOW(login_session, 0) = 0x7938; WFIFOSET(login_session, 2); @@ -1114,9 +1114,9 @@ void changegmlevel(ZString param) if (!qsplit(param, &name, &GM_level)) { - PRINTF("Please input an account name and a GM level.\n"); - PRINTF("<example> gm testname 80\n"); - LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n"); + PRINTF("Please input an account name and a GM level.\n"_fmt); + PRINTF("<example> gm testname 80\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n"_fmt); return; } @@ -1125,14 +1125,14 @@ void changegmlevel(ZString param) if (GM_level < 0 || GM_level > 99) { - PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n", + PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n"_fmt, GM_level); - LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n", + LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n"_fmt, GM_level); return; } - LADMIN_LOG("Request to login-server to change a GM level.\n"); + LADMIN_LOG("Request to login-server to change a GM level.\n"_fmt); WFIFOW(login_session, 0) = 0x793e; WFIFO_STRING(login_session, 2, name, 24); @@ -1151,9 +1151,9 @@ void idaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> id testname\n"); - LADMIN_LOG("No name given to search an account id ('id' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> id testname\n"_fmt); + LADMIN_LOG("No name given to search an account id ('id' command).\n"_fmt); return; } @@ -1162,7 +1162,7 @@ void idaccount(ZString param) return; } - LADMIN_LOG("Request to login-server to know an account id.\n"); + LADMIN_LOG("Request to login-server to know an account id.\n"_fmt); WFIFOW(login_session, 0) = 0x7944; WFIFO_STRING(login_session, 2, name, 24); @@ -1178,12 +1178,12 @@ void infoaccount(int account_id) { if (account_id < 0) { - PRINTF("Please input a positive value for the id.\n"); - LADMIN_LOG("Negative value was given to found the account.\n"); + PRINTF("Please input a positive value for the id.\n"_fmt); + LADMIN_LOG("Negative value was given to found the account.\n"_fmt); return; } - LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"); + LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"_fmt); WFIFOW(login_session, 0) = 0x7954; WFIFOL(login_session, 2) = account_id; @@ -1199,11 +1199,11 @@ void sendbroadcast(ZString message) { if (!message) { - PRINTF("Please input a message.\n"); + PRINTF("Please input a message.\n"_fmt); { - PRINTF("<example> kami a message\n"); + PRINTF("<example> kami a message\n"_fmt); } - LADMIN_LOG("The message is void ('kami' command).\n"); + LADMIN_LOG("The message is void ('kami' command).\n"_fmt); return; } @@ -1256,7 +1256,7 @@ void listaccount(ZString param, int type) list_last = 0; } - LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n", + LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n"_fmt, list_first, list_last); WFIFOW(login_session, 0) = 0x7920; @@ -1266,8 +1266,8 @@ void listaccount(ZString param, int type) bytes_to_read = 1; // 0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567 - Iprintf("account_id GM user_name sex count state\n"); - Iprintf("-------------------------------------------------------------------------------\n"); + Iprintf("account_id GM user_name sex count state\n"_fmt); + Iprintf("-------------------------------------------------------------------------------\n"_fmt); list_count = 0; } @@ -1281,7 +1281,7 @@ int itemfrob(ZString param) if (!extract(param, record<' '>(&source_id, &dest_id))) { - PRINTF("You must provide the source and destination item IDs.\n"); + PRINTF("You must provide the source and destination item IDs.\n"_fmt); return 1; } @@ -1305,9 +1305,9 @@ void changememo(ZString param) if (!qsplit(param, &name, &memo) && !qsplit(param, &name)) { - PRINTF("Please input an account name and a memo.\n"); - PRINTF("<example> memo testname new memo\n"); - LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n"); + PRINTF("Please input an account name and a memo.\n"_fmt); + PRINTF("<example> memo testname new memo\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n"_fmt); return; } @@ -1318,14 +1318,14 @@ void changememo(ZString param) size_t len1 = len + 1; if (len > 254) { - PRINTF("Memo is too long (%zu characters).\n", len); - PRINTF("Please input a memo of 254 bytes at the maximum.\n"); - LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n", + PRINTF("Memo is too long (%zu characters).\n"_fmt, len); + PRINTF("Please input a memo of 254 bytes at the maximum.\n"_fmt); + LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n"_fmt, len); return; } - LADMIN_LOG("Request to login-server to change a memo.\n"); + LADMIN_LOG("Request to login-server to change a memo.\n"_fmt); WFIFOW(login_session, 0) = 0x7942; WFIFO_STRING(login_session, 2, name, 24); @@ -1343,12 +1343,12 @@ void nameaccount(int id) { if (id < 0) { - PRINTF("Please input a positive value for the id.\n"); - LADMIN_LOG("Negativ id given to search an account name ('name' command).\n"); + PRINTF("Please input a positive value for the id.\n"_fmt); + LADMIN_LOG("Negativ id given to search an account name ('name' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to know an account name.\n"); + LADMIN_LOG("Request to login-server to know an account name.\n"_fmt); WFIFOW(login_session, 0) = 0x7946; WFIFOL(login_session, 2) = id; @@ -1368,9 +1368,9 @@ void changepasswd(ZString param) if (!qsplit(param, &name, &password)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> password testname newpassword\n"); - LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> password testname newpassword\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n"_fmt); return; } @@ -1382,7 +1382,7 @@ void changepasswd(ZString param) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to change a password.\n"); + LADMIN_LOG("Request to login-server to change a password.\n"_fmt); WFIFOW(login_session, 0) = 0x7934; WFIFO_STRING(login_session, 2, name, 24); @@ -1402,9 +1402,9 @@ void reloadGM(ZString params) WFIFOSET(login_session, 2); bytes_to_read = 0; - LADMIN_LOG("Request to reload the GM configuration file sended.\n"); - PRINTF("Request to reload the GM configuration file sended.\n"); - PRINTF("Check the actual GM accounts (after reloading):\n"); + LADMIN_LOG("Request to reload the GM configuration file sended.\n"_fmt); + PRINTF("Request to reload the GM configuration file sended.\n"_fmt); + PRINTF("Check the actual GM accounts (after reloading):\n"_fmt); listaccount(params, 1); // 1: to list only GM } @@ -1419,27 +1419,27 @@ void changesex(ZString param) if (!qsplit(param, &name, &sex_)) { - PRINTF("Please input an account name and a sex.\n"); - PRINTF("<example> sex testname Male\n"); - LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n"); + PRINTF("Please input an account name and a sex.\n"_fmt); + PRINTF("<example> sex testname Male\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n"_fmt); return; } char sex = sex_.front(); if (!name.is_print()) { - PRINTF("bad name\n"); + PRINTF("bad name\n"_fmt); return; } - if (!XString("MF").contains(sex)) + if (!"MF"_s.contains(sex)) { - PRINTF("Illegal gender [%c]. Please input M or F.\n", sex); - LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n", sex); + PRINTF("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); + LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); return; } - LADMIN_LOG("Request to login-server to change a sex.\n"); + LADMIN_LOG("Request to login-server to change a sex.\n"_fmt); WFIFOW(login_session, 0) = 0x793c; WFIFO_STRING(login_session, 2, name, 24); @@ -1457,18 +1457,18 @@ void changestatesub(AccountName name, int state, XString error_message) { if ((state < 0 || state > 9) && state != 100) { // Valid values: 0: ok, or value of the 0x006a packet + 1 - PRINTF("Please input one of these states:\n"); - PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n"); - PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n"); - PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n"); - PRINTF(" 3 = This ID is expired 9 = No MSG\n"); - PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n"); - PRINTF(" 5 = You have been blocked by the GM Team\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n"); + PRINTF("Please input one of these states:\n"_fmt); + PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n"_fmt); + PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n"_fmt); + PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n"_fmt); + PRINTF(" 3 = This ID is expired 9 = No MSG\n"_fmt); + PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n"_fmt); + PRINTF(" 5 = You have been blocked by the GM Team\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n"_fmt); return; } @@ -1477,25 +1477,25 @@ void changestatesub(AccountName name, int state, XString error_message) if (state != 7) { - error_message = "-"; + error_message = "-"_s; } else { if (error_message.size() < 1) { - PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n"); - LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n"); + PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n"_fmt); + LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n"_fmt); return; } if (error_message.size() > 19) { - PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n"); - LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n"); + PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n"_fmt); + LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to change a state.\n"); + LADMIN_LOG("Request to login-server to change a state.\n"_fmt); WFIFOW(login_session, 0) = 0x7936; WFIFO_STRING(login_session, 2, name, 24); @@ -1517,12 +1517,12 @@ void changestate(ZString param) if (!qsplit(param, &name, &state, &error_message) && !qsplit(param, &name, &state)) { - PRINTF("Please input an account name and a state.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n"); + PRINTF("Please input an account name and a state.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n"_fmt); return; } @@ -1539,16 +1539,16 @@ void unblockaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n"_fmt); return; } - changestatesub(name, 0, "-"); // state 0, no error message + changestatesub(name, 0, "-"_s); // state 0, no error message } //------------------------------------------- @@ -1561,16 +1561,16 @@ void blockaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n"_fmt); return; } - changestatesub(name, 5, "-"); // state 5, no error message + changestatesub(name, 5, "-"_s); // state 5, no error message } //--------------------------------------------------------------------- @@ -1584,11 +1584,11 @@ void timeaddaccount(ZString param) if (!qsplit(param, &name, &modif)) { - PRINTF("Please input an account name and a modifier.\n"); - PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n"); + PRINTF("Please input an account name and a modifier.\n"_fmt); + PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n"_fmt); return; } if (name.is_print()) @@ -1598,23 +1598,23 @@ void timeaddaccount(ZString param) if (!modif) { - PRINTF("Please give an adjustment with this command:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n"); + PRINTF("Please give an adjustment with this command:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to modify a time limit.\n"); + LADMIN_LOG("Request to login-server to modify a time limit.\n"_fmt); WFIFOW(login_session, 0) = 0x7950; WFIFO_STRING(login_session, 2, name, 24); @@ -1643,31 +1643,31 @@ void timesetaccount(ZString param) if (!qsplit(param, &name, &date, &time_) && !qsplit(param, &name, &date)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" timeset <account_name> 0 (0 = unlimited)\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" timeset <account_name> 0 (0 = unlimited)\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n"_fmt); return; } if (!name.is_print()) return; if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; - if (date != "0" + if (date != "0"_s && ((!extract(date, record<'/'>(&year, &month, &day)) && !extract(date, record<'-'>(&year, &month, &day)) && !extract(date, record<'.'>(&year, &month, &day))) || !extract(time_, record<':'>(&hour, &minute, &second)))) { - PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"); - LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n"); + PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"_fmt); + LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n"_fmt); return; } - if (date == "0") + if (date == "0"_s) { connect_until_time = TimeT(); } @@ -1683,41 +1683,41 @@ void timesetaccount(ZString param) } if (month < 1 || month > 12) { - PRINTF("Please give a correct value for the month (from 1 to 12).\n"); - LADMIN_LOG("Invalid month for the date ('timeset' command).\n"); + PRINTF("Please give a correct value for the month (from 1 to 12).\n"_fmt); + LADMIN_LOG("Invalid month for the date ('timeset' command).\n"_fmt); return; } month = month - 1; if (day < 1 || day > 31) { - PRINTF("Please give a correct value for the day (from 1 to 31).\n"); - LADMIN_LOG("Invalid day for the date ('timeset' command).\n"); + PRINTF("Please give a correct value for the day (from 1 to 31).\n"_fmt); + LADMIN_LOG("Invalid day for the date ('timeset' command).\n"_fmt); return; } if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) ||(month == 1 && day > 29)) { - PRINTF("Please give a correct value for a day of this month (%d).\n", + PRINTF("Please give a correct value for a day of this month (%d).\n"_fmt, month); - LADMIN_LOG("Invalid day for this month ('timeset' command).\n"); + LADMIN_LOG("Invalid day for this month ('timeset' command).\n"_fmt); return; } if (hour < 0 || hour > 23) { - PRINTF("Please give a correct value for the hour (from 0 to 23).\n"); - LADMIN_LOG("Invalid hour for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the hour (from 0 to 23).\n"_fmt); + LADMIN_LOG("Invalid hour for the time ('timeset' command).\n"_fmt); return; } if (minute < 0 || minute > 59) { - PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"); - LADMIN_LOG("Invalid minute for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid minute for the time ('timeset' command).\n"_fmt); return; } if (second < 0 || second > 59) { - PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"); - LADMIN_LOG("Invalid second for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid second for the time ('timeset' command).\n"_fmt); return; } tmtime.tm_year = year; @@ -1730,14 +1730,14 @@ void timesetaccount(ZString param) connect_until_time = tmtime; if (connect_until_time.error()) { - PRINTF("Invalid date.\n"); - PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"); - LADMIN_LOG("Invalid date. ('timeset' command).\n"); + PRINTF("Invalid date.\n"_fmt); + PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"_fmt); + LADMIN_LOG("Invalid date. ('timeset' command).\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to set a time limit.\n"); + LADMIN_LOG("Request to login-server to set a time limit.\n"_fmt); WFIFOW(login_session, 0) = 0x7948; WFIFO_STRING(login_session, 2, name, 24); @@ -1756,9 +1756,9 @@ void whoaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> who testname\n"); - LADMIN_LOG("No name was given to found the account.\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> who testname\n"_fmt); + LADMIN_LOG("No name was given to found the account.\n"_fmt); return; } if (!name.is_print()) @@ -1766,7 +1766,7 @@ void whoaccount(ZString param) return; } - LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n"); + LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n"_fmt); WFIFOW(login_session, 0) = 0x7952; WFIFO_STRING(login_session, 2, name, 24); @@ -1780,7 +1780,7 @@ void whoaccount(ZString param) static void checkloginversion(void) { - LADMIN_LOG("Request to login-server to obtain its version.\n"); + LADMIN_LOG("Request to login-server to obtain its version.\n"_fmt); WFIFOW(login_session, 0) = 0x7530; WFIFOSET(login_session, 2); @@ -1798,10 +1798,10 @@ void prompt(void) // while we don't wait new packets while (bytes_to_read == 0) { - Iprintf("\n"); - Iprintf(SGR_GREEN "To list the commands, type 'enter'." SGR_RESET "\n"); - Iprintf(SGR_CYAN "Ladmin-> " SGR_RESET); - Iprintf(SGR_BOLD); + Iprintf("\n"_fmt); + Iprintf(SGR_GREEN "To list the commands, type 'enter'." SGR_RESET "\n"_fmt); + Iprintf(SGR_CYAN "Ladmin-> " SGR_RESET ""_fmt); + Iprintf(SGR_BOLD ""_fmt); fflush(stdout); // get command and parameter @@ -1810,7 +1810,7 @@ void prompt(void) AString buf; cin->getline(buf); - Iprintf(SGR_RESET); + Iprintf(SGR_RESET ""_fmt); fflush(stdout); if (!cin->is_open()) @@ -1818,8 +1818,8 @@ void prompt(void) if (!buf.is_print()) { - printf("Cowardly refusing to execute a command that includes control or non-ascii characters\n"); - LADMIN_LOG("Cowardly refusing to execute a command that includes control or non-ascii characters\n"); + PRINTF("Cowardly refusing to execute a command that includes control or non-ascii characters\n"_fmt); + LADMIN_LOG("Cowardly refusing to execute a command that includes control or non-ascii characters\n"_fmt); continue; } @@ -1832,116 +1832,116 @@ void prompt(void) parameters = buf.xislice_t(space); if (!command || command.startswith('?')) - command = "help"; + command = "help"_s; if (!parameters) { - LADMIN_LOG("Command: '%s' (without parameters)\n", + LADMIN_LOG("Command: '%s' (without parameters)\n"_fmt, command); } else { // We don't want passwords in the log - Camel - if (command == "create" || command == "add" || command == "password") { + if (command == "create"_s || command == "add"_s || command == "password"_s) { AString name, email_, password; VString<1> sex_; if (qsplit(parameters, &name, &sex_, &email_, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s %s %s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s %s %s ***'\n"_fmt, command, name, sex_, email_); else if (qsplit(parameters, &name, &sex_, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s %s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s %s ***'\n"_fmt, command, name, sex_); else if (qsplit(parameters, &name, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s ***'\n"_fmt, command, name); else - LADMIN_LOG("Command: '%s' (invalid parameters)\n", command); + LADMIN_LOG("Command: '%s' (invalid parameters)\n"_fmt, command); } else { - LADMIN_LOG("Command: '%s', parameters: '%s'\n", + LADMIN_LOG("Command: '%s', parameters: '%s'\n"_fmt, command, parameters); } } // Analyse of the command - if (command == "help") + if (command == "help"_s) display_help(parameters); - else if (command == "add") + else if (command == "add"_s) addaccount(parameters, 0); // 0: no email - else if (command == "ban") + else if (command == "ban"_s) banaccount(parameters); - else if (command == "banadd") + else if (command == "banadd"_s) banaddaccount(parameters); - else if (command == "banset") + else if (command == "banset"_s) bansetaccount(parameters); - else if (command == "block") + else if (command == "block"_s) blockaccount(parameters); - else if (command == "check") + else if (command == "check"_s) checkaccount(parameters); - else if (command == "create") + else if (command == "create"_s) addaccount(parameters, 1); // 1: with email - else if (command == "delete") + else if (command == "delete"_s) delaccount(parameters); - else if (command == "email") + else if (command == "email"_s) changeemail(parameters); - else if (command == "getcount") + else if (command == "getcount"_s) getlogincount(); - else if (command == "gm") + else if (command == "gm"_s) changegmlevel(parameters); - else if (command == "id") + else if (command == "id"_s) idaccount(parameters); - else if (command == "info") + else if (command == "info"_s) infoaccount(atoi(parameters.c_str())); - else if (command == "kami") + else if (command == "kami"_s) sendbroadcast(parameters); // flag for normal - else if (command == "itemfrob") + else if (command == "itemfrob"_s) itemfrob(parameters); // 0: to list all - else if (command == "list") + else if (command == "list"_s) listaccount(parameters, 0); // 0: to list all - else if (command == "listban") + else if (command == "listban"_s) listaccount(parameters, 3); // 3: to list only accounts with state or bannished - else if (command == "listgm") + else if (command == "listgm"_s) listaccount(parameters, 1); // 1: to list only GM - else if (command == "listok") + else if (command == "listok"_s) listaccount(parameters, 4); // 4: to list only accounts without state and not bannished - else if (command == "memo") + else if (command == "memo"_s) changememo(parameters); - else if (command == "name") + else if (command == "name"_s) nameaccount(atoi(parameters.c_str())); - else if (command == "password") + else if (command == "password"_s) changepasswd(parameters); - else if (command == "reloadgm") + else if (command == "reloadgm"_s) reloadGM(parameters); - else if (command == "search") + else if (command == "search"_s) listaccount(parameters, 2); // 2: to list with pattern - else if (command == "sex") + else if (command == "sex"_s) changesex(parameters); - else if (command == "state") + else if (command == "state"_s) changestate(parameters); - else if (command == "timeadd") + else if (command == "timeadd"_s) timeaddaccount(parameters); - else if (command == "timeset") + else if (command == "timeset"_s) timesetaccount(parameters); - else if (command == "unban") + else if (command == "unban"_s) unbanaccount(parameters); - else if (command == "unblock") + else if (command == "unblock"_s) unblockaccount(parameters); - else if (command == "version") + else if (command == "version"_s) checkloginversion(); - else if (command == "who") + else if (command == "who"_s) whoaccount(parameters); - else if (command == "quit" - || command == "exit" - || command == "end") + else if (command == "quit"_s + || command == "exit"_s + || command == "end"_s) { - PRINTF("Bye.\n"); + PRINTF("Bye.\n"_fmt); exit(0); } else { - PRINTF("Unknown command [%s].\n", buf); - LADMIN_LOG("Unknown command [%s].\n", buf); + PRINTF("Unknown command [%s].\n"_fmt, buf); + LADMIN_LOG("Unknown command [%s].\n"_fmt, buf); } } } @@ -1952,8 +1952,6 @@ void prompt(void) static void parse_fromlogin(Session *s) { -// PRINTF("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0)); - while (RFIFOREST(s) >= 2) { switch (RFIFOW(s, 0)) @@ -1963,20 +1961,20 @@ void parse_fromlogin(Session *s) return; if (RFIFOB(s, 2) != 0) { - PRINTF("Error at login:\n"); - PRINTF(" - incorrect password,\n"); - PRINTF(" - administration system not activated, or\n"); - PRINTF(" - unauthorised IP.\n"); - LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n"); + PRINTF("Error at login:\n"_fmt); + PRINTF(" - incorrect password,\n"_fmt); + PRINTF(" - administration system not activated, or\n"_fmt); + PRINTF(" - unauthorised IP.\n"_fmt); + LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n"_fmt); s->set_eof(); //bytes_to_read = 1; // not stop at prompt } else { - Iprintf("Established connection.\n"); - LADMIN_LOG("Established connection.\n"); - Iprintf("Reading of the version of the login-server...\n"); - LADMIN_LOG("Reading of the version of the login-server...\n"); + Iprintf("Established connection.\n"_fmt); + LADMIN_LOG("Established connection.\n"_fmt); + Iprintf("Reading of the version of the login-server...\n"_fmt); + LADMIN_LOG("Reading of the version of the login-server...\n"_fmt); //bytes_to_read = 1; // unchanged checkloginversion(); } @@ -1987,11 +1985,11 @@ void parse_fromlogin(Session *s) if (RFIFOREST(s) < 10) return; { - Iprintf(" Login-Server [%s:%d]\n", + Iprintf(" Login-Server [%s:%d]\n"_fmt, login_ip, login_port); Version version; RFIFO_STRUCT(login_session, 2, version); - Iprintf(" tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n", + Iprintf(" tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n"_fmt, version.major, version.minor, version.patch, version.devel, @@ -2012,23 +2010,23 @@ void parse_fromlogin(Session *s) return; if (RFIFOW(s, 2) < 5) { - LADMIN_LOG(" Receiving of a void accounts list.\n"); + LADMIN_LOG(" Receiving of a void accounts list.\n"_fmt); if (list_count == 0) { - Iprintf("No account found.\n"); + Iprintf("No account found.\n"_fmt); } else if (list_count == 1) { - Iprintf("1 account found.\n"); + Iprintf("1 account found.\n"_fmt); } else - Iprintf("%d accounts found.\n", list_count); + Iprintf("%d accounts found.\n"_fmt, list_count); bytes_to_read = 0; } else { int i; - LADMIN_LOG(" Receiving of a accounts list.\n"); + LADMIN_LOG(" Receiving of a accounts list.\n"_fmt); for (i = 4; i < RFIFOW(s, 2); i += 38) { AccountName userid = stringish<AccountName>(RFIFO_STRING<24>(s, i + 5)); @@ -2041,63 +2039,63 @@ void parse_fromlogin(Session *s) || (list_type == 3 && RFIFOL(s, i + 34) != 0) || (list_type == 4 && RFIFOL(s, i + 34) == 0)) { - PRINTF("%10d ", RFIFOL(s, i)); + PRINTF("%10d "_fmt, RFIFOL(s, i)); if (RFIFOB(s, i + 4) == 0) - PRINTF(" "); + PRINTF(" "_fmt); else - PRINTF("%2d ", RFIFOB(s, i + 4)); - PRINTF("%-24s", userid); + PRINTF("%2d "_fmt, RFIFOB(s, i + 4)); + PRINTF("%-24s"_fmt, userid); if (RFIFOB(s, i + 29) == 0) - PRINTF("%-5s ", "Femal"); + PRINTF("%-5s "_fmt, "Femal"_s); else if (RFIFOB(s, i + 29) == 1) - PRINTF("%-5s ", "Male"); + PRINTF("%-5s "_fmt, "Male"_s); else - PRINTF("%-5s ", "Servr"); - PRINTF("%6d ", RFIFOL(s, i + 30)); + PRINTF("%-5s "_fmt, "Servr"_s); + PRINTF("%6d "_fmt, RFIFOL(s, i + 30)); switch (RFIFOL(s, i + 34)) { case 0: - PRINTF("%-27s\n", "Account OK"); + PRINTF("%-27s\n"_fmt, "Account OK"_s); break; case 1: - PRINTF("%-27s\n", "Unregistered ID"); + PRINTF("%-27s\n"_fmt, "Unregistered ID"_s); break; case 2: - PRINTF("%-27s\n", "Incorrect Password"); + PRINTF("%-27s\n"_fmt, "Incorrect Password"_s); break; case 3: - PRINTF("%-27s\n", "This ID is expired"); + PRINTF("%-27s\n"_fmt, "This ID is expired"_s); break; case 4: - PRINTF("%-27s\n", - "Rejected from Server"); + PRINTF("%-27s\n"_fmt, + "Rejected from Server"_s); break; case 5: - PRINTF("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team + PRINTF("%-27s\n"_fmt, "Blocked by the GM Team"_s); // You have been blocked by the GM Team break; case 6: - PRINTF("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version + PRINTF("%-27s\n"_fmt, "Your EXE file is too old"_s); // Your Game's EXE file is not the latest version break; case 7: - PRINTF("%-27s\n", "Banishement or"); - PRINTF(" Prohibited to login until...\n"); // You are Prohibited to log in until %s + PRINTF("%-27s\n"_fmt, "Banishement or"_s); + PRINTF(" Prohibited to login until...\n"_fmt); // You are Prohibited to log in until %s break; case 8: - PRINTF("%-27s\n", - "Server is over populated"); + PRINTF("%-27s\n"_fmt, + "Server is over populated"_s); break; case 9: - PRINTF("%-27s\n", "No MSG"); + PRINTF("%-27s\n"_fmt, "No MSG"_s); break; default: // 100 - PRINTF("%-27s\n", "This ID is totally erased"); // This ID has been totally erased + PRINTF("%-27s\n"_fmt, "This ID is totally erased"_s); // This ID has been totally erased break; } list_count++; } } // asking of the following acounts - LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n", + LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n"_fmt, list_first, list_last); WFIFOW(login_session, 0) = 0x7920; WFIFOL(login_session, 2) = list_first; @@ -2116,16 +2114,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] creation failed. Same account already exists.\n", + PRINTF("Account [%s] creation failed. Same account already exists.\n"_fmt, name); - LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n", + LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n"_fmt, name); } else { - PRINTF("Account [%s] is successfully created [id: %d].\n", + PRINTF("Account [%s] is successfully created [id: %d].\n"_fmt, name, accid); - LADMIN_LOG("Account [%s] is successfully created [id: %d].\n", + LADMIN_LOG("Account [%s] is successfully created [id: %d].\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2141,16 +2139,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] deletion failed. Account doesn't exist.\n", + PRINTF("Account [%s] deletion failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] is successfully DELETED.\n", + PRINTF("Account [%s][id: %d] is successfully DELETED.\n"_fmt, name, accid); - LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n", + LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2166,18 +2164,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] password changing failed.\n", + PRINTF("Account [%s] password changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist.\n", + PRINTF("Account [%s] doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n", + LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] password successfully changed.\n", + PRINTF("Account [%s][id: %d] password successfully changed.\n"_fmt, name, accid); - LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2194,57 +2192,57 @@ void parse_fromlogin(Session *s) int state = RFIFOL(s, 30); if (accid == -1) { - PRINTF("Account [%s] state changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] state changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n"_fmt, name); } else { MString tmpstr; tmpstr += STRPRINTF( - "Account [%s] state successfully changed in [", + "Account [%s] state successfully changed in ["_fmt, name); switch (state) { case 0: - tmpstr += "0: Account OK"; + tmpstr += "0: Account OK"_s; break; case 1: - tmpstr += "1: Unregistered ID"; + tmpstr += "1: Unregistered ID"_s; break; case 2: - tmpstr += "2: Incorrect Password"; + tmpstr += "2: Incorrect Password"_s; break; case 3: - tmpstr += "3: This ID is expired"; + tmpstr += "3: This ID is expired"_s; break; case 4: - tmpstr += "4: Rejected from Server"; + tmpstr += "4: Rejected from Server"_s; break; case 5: - tmpstr += "5: You have been blocked by the GM Team"; + tmpstr += "5: You have been blocked by the GM Team"_s; break; case 6: - tmpstr += "6: [Your Game's EXE file is not the latest version"; + tmpstr += "6: [Your Game's EXE file is not the latest version"_s; break; case 7: - tmpstr += "7: You are Prohibited to log in until..."; + tmpstr += "7: You are Prohibited to log in until..."_s; break; case 8: - tmpstr += "8: Server is jammed due to over populated"; + tmpstr += "8: Server is jammed due to over populated"_s; break; case 9: - tmpstr += "9: No MSG"; + tmpstr += "9: No MSG"_s; break; default: // 100 - tmpstr += "100: This ID is totally erased"; + tmpstr += "100: This ID is totally erased"_s; break; } tmpstr += ']'; AString tmpstr_ = AString(tmpstr); - PRINTF("%s\n", tmpstr_); - LADMIN_LOG("%s\n", tmpstr_); + PRINTF("%s\n"_fmt, tmpstr_); + LADMIN_LOG("%s\n"_fmt, tmpstr_); } bytes_to_read = 0; } @@ -2256,20 +2254,20 @@ void parse_fromlogin(Session *s) return; { // Get length of the received packet - LADMIN_LOG(" Receiving of the number of online players.\n"); + LADMIN_LOG(" Receiving of the number of online players.\n"_fmt); // Read information of the servers if (RFIFOW(s, 2) < 5) { - PRINTF(" No server is connected to the login-server.\n"); + PRINTF(" No server is connected to the login-server.\n"_fmt); } else { - PRINTF(" Number of online players (server: number).\n"); + PRINTF(" Number of online players (server: number).\n"_fmt); // Displaying of result for (int i = 4; i < RFIFOW(s, 2); i += 32) { ServerName name = stringish<ServerName>(RFIFO_STRING<20>(s, i + 6)); - PRINTF(" %-20s : %5d\n", name, + PRINTF(" %-20s : %5d\n"_fmt, name, RFIFOW(s, i + 26)); } } @@ -2286,16 +2284,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("The account [%s] doesn't exist or the password is incorrect.\n", + PRINTF("The account [%s] doesn't exist or the password is incorrect.\n"_fmt, name); - LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n", + LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n"_fmt, name); } else { - PRINTF("The proposed password is correct for the account [%s][id: %d].\n", + PRINTF("The proposed password is correct for the account [%s][id: %d].\n"_fmt, name, account_id); - LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n", + LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2311,18 +2309,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] sex changing failed.\n", + PRINTF("Account [%s] sex changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n", + PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n"_fmt, name); - LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n", + LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] sex successfully changed.\n", + PRINTF("Account [%s][id: %d] sex successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2338,19 +2336,19 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] GM level changing failed.\n", + PRINTF("Account [%s] GM level changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n", + PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n"_fmt, name); - PRINTF("or it's impossible to modify the GM accounts file.\n"); - LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n", + PRINTF("or it's impossible to modify the GM accounts file.\n"_fmt); + LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] GM level successfully changed.\n", + PRINTF("Account [%s][id: %d] GM level successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2366,18 +2364,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] e-mail changing failed.\n", + PRINTF("Account [%s] e-mail changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist.\n", + PRINTF("Account [%s] doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n", + LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] e-mail successfully changed.\n", + PRINTF("Account [%s][id: %d] e-mail successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2393,16 +2391,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] memo successfully changed.\n", + PRINTF("Account [%s][id: %d] memo successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2418,16 +2416,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n", + PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n", + LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("The account [%s] have the id: %d.\n", + PRINTF("The account [%s] have the id: %d.\n"_fmt, name, account_id); - LADMIN_LOG("The account [%s] have the id: %d.\n", + LADMIN_LOG("The account [%s] have the id: %d.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2443,16 +2441,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (!name) { - PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n", + PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n"_fmt, account_id); - LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n", + LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n"_fmt, account_id); } else { - PRINTF("The account [id: %d] have the name: %s.\n", + PRINTF("The account [id: %d] have the name: %s.\n"_fmt, account_id, name); - LADMIN_LOG("The account [id: %d] have the name: %s.\n", + LADMIN_LOG("The account [id: %d] have the name: %s.\n"_fmt, account_id, name); } bytes_to_read = 0; @@ -2468,9 +2466,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (RFIFOL(s, 2) == -1) { - PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2478,18 +2476,18 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", + PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n"_fmt, name, account_id); - LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", + LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2507,9 +2505,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2517,18 +2515,18 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, RFIFOL(s, 2), tmpstr); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, RFIFOL(s, 2), tmpstr); } @@ -2546,9 +2544,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2556,19 +2554,19 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2583,13 +2581,13 @@ void parse_fromlogin(Session *s) return; if (RFIFOW(s, 2) == static_cast<uint16_t>(-1)) { - PRINTF("Message sending failed. No online char-server.\n"); - LADMIN_LOG("Message sending failed. No online char-server.\n"); + PRINTF("Message sending failed. No online char-server.\n"_fmt); + LADMIN_LOG("Message sending failed. No online char-server.\n"_fmt); } else { - PRINTF("Message successfully sended to login-server.\n"); - LADMIN_LOG("Message successfully sended to login-server.\n"); + PRINTF("Message successfully sended to login-server.\n"_fmt); + LADMIN_LOG("Message successfully sended to login-server.\n"_fmt); } bytes_to_read = 0; RFIFOSKIP(s, 4); @@ -2603,9 +2601,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2613,21 +2611,21 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n", + PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n"_fmt, name, account_id); - PRINTF("The account have an unlimited validity limit or\n"); - PRINTF("the changing is impossible with the proposed adjustments.\n"); - LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n", + PRINTF("The account have an unlimited validity limit or\n"_fmt); + PRINTF("the changing is impossible with the proposed adjustments.\n"_fmt); + LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2657,107 +2655,107 @@ void parse_fromlogin(Session *s) AString memo = RFIFO_STRING(s, 150, RFIFOW(s, 148)); if (account_id == -1) { - PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n", + PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n"_fmt, userid); - LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n", + LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n"_fmt, userid); } else if (!userid) { - PRINTF("Unabled to find the account [id: %d]. Account doesn't exist.\n", + PRINTF("Unabled to find the account [id: %d]. Account doesn't exist.\n"_fmt, account_id); - LADMIN_LOG("Unabled to find the account [id: %d]. Account doesn't exist.\n", + LADMIN_LOG("Unabled to find the account [id: %d]. Account doesn't exist.\n"_fmt, account_id); } else { - LADMIN_LOG("Receiving information about an account.\n"); - PRINTF("The account is set with:\n"); + LADMIN_LOG("Receiving information about an account.\n"_fmt); + PRINTF("The account is set with:\n"_fmt); if (!gm) { - PRINTF(" Id: %d (non-GM)\n", account_id); + PRINTF(" Id: %d (non-GM)\n"_fmt, account_id); } else { - PRINTF(" Id: %d (GM level %d)\n", + PRINTF(" Id: %d (GM level %d)\n"_fmt, account_id, gm); } - PRINTF(" Name: '%s'\n", userid); + PRINTF(" Name: '%s'\n"_fmt, userid); if (sex == 0) - PRINTF(" Sex: Female\n"); + PRINTF(" Sex: Female\n"_fmt); else if (sex == 1) - PRINTF(" Sex: Male\n"); + PRINTF(" Sex: Male\n"_fmt); else - PRINTF(" Sex: Server\n"); - PRINTF(" E-mail: %s\n", email); + PRINTF(" Sex: Server\n"_fmt); + PRINTF(" E-mail: %s\n"_fmt, email); switch (state) { case 0: - PRINTF(" Statut: 0 [Account OK]\n"); + PRINTF(" Statut: 0 [Account OK]\n"_fmt); break; case 1: - PRINTF(" Statut: 1 [Unregistered ID]\n"); + PRINTF(" Statut: 1 [Unregistered ID]\n"_fmt); break; case 2: - PRINTF(" Statut: 2 [Incorrect Password]\n"); + PRINTF(" Statut: 2 [Incorrect Password]\n"_fmt); break; case 3: - PRINTF(" Statut: 3 [This ID is expired]\n"); + PRINTF(" Statut: 3 [This ID is expired]\n"_fmt); break; case 4: - PRINTF(" Statut: 4 [Rejected from Server]\n"); + PRINTF(" Statut: 4 [Rejected from Server]\n"_fmt); break; case 5: - PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n"); + PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n"_fmt); break; case 6: - PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n"); + PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n"_fmt); break; case 7: - PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n", + PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n"_fmt, error_message); break; case 8: - PRINTF(" Statut: 8 [Server is jammed due to over populated]\n"); + PRINTF(" Statut: 8 [Server is jammed due to over populated]\n"_fmt); break; case 9: - PRINTF(" Statut: 9 [No MSG]\n"); + PRINTF(" Statut: 9 [No MSG]\n"_fmt); break; default: // 100 - PRINTF(" Statut: %d [This ID is totally erased]\n", + PRINTF(" Statut: %d [This ID is totally erased]\n"_fmt, state); break; } if (!ban_until_time) { - PRINTF(" Banishment: not banished.\n"); + PRINTF(" Banishment: not banished.\n"_fmt); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, &ban_until_time); - PRINTF(" Banishment: until %s.\n", tmpstr); + PRINTF(" Banishment: until %s.\n"_fmt, tmpstr); } if (connections > 1) - PRINTF(" Count: %d connections.\n", + PRINTF(" Count: %d connections.\n"_fmt, connections); else - PRINTF(" Count: %d connection.\n", + PRINTF(" Count: %d connection.\n"_fmt, connections); - PRINTF(" Last connection at: %s (ip: %s)\n", + PRINTF(" Last connection at: %s (ip: %s)\n"_fmt, lastlogin, last_ip_); if (!connect_until_time) { - PRINTF(" Validity limit: unlimited.\n"); + PRINTF(" Validity limit: unlimited.\n"_fmt); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, &connect_until_time); - PRINTF(" Validity limit: until %s.\n", + PRINTF(" Validity limit: until %s.\n"_fmt, tmpstr); } - PRINTF(" Memo: '%s'\n", memo); + PRINTF(" Memo: '%s'\n"_fmt, memo); } } bytes_to_read = 0; @@ -2765,8 +2763,8 @@ void parse_fromlogin(Session *s) break; default: - PRINTF("Remote administration has been disconnected (unknown packet).\n"); - LADMIN_LOG("'End of connection, unknown packet.\n"); + PRINTF("Remote administration has been disconnected (unknown packet).\n"_fmt); + LADMIN_LOG("'End of connection, unknown packet.\n"_fmt); s->set_eof(); return; } @@ -2782,8 +2780,8 @@ void parse_fromlogin(Session *s) static int Connect_login_server(void) { - Iprintf("Attempt to connect to login-server...\n"); - LADMIN_LOG("Attempt to connect to login-server...\n"); + Iprintf("Attempt to connect to login-server...\n"_fmt); + LADMIN_LOG("Attempt to connect to login-server...\n"_fmt); login_session = make_connection(login_ip, login_port, SessionParsers{func_parse: parse_fromlogin, func_delete: delete_fromlogin}); @@ -2797,8 +2795,8 @@ int Connect_login_server(void) WFIFOSET(login_session, 28); bytes_to_read = 1; - Iprintf("Sending of the password...\n"); - LADMIN_LOG("Sending of the password...\n"); + Iprintf("Sending of the password...\n"_fmt); + LADMIN_LOG("Sending of the password...\n"_fmt); } return 0; @@ -2808,12 +2806,12 @@ static bool admin_confs(XString w1, ZString w2) { { - if (w1 == "login_ip") + if (w1 == "login_ip"_s) { struct hostent *h = gethostbyname(w2.c_str()); if (h != NULL) { - Iprintf("Login server IP address: %s -> %s\n", + Iprintf("Login server IP address: %s -> %s\n"_fmt, w2, login_ip); login_ip = IP4Address({ static_cast<uint8_t>(h->h_addr[0]), @@ -2823,21 +2821,21 @@ bool admin_confs(XString w1, ZString w2) }); } } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "admin_pass") + else if (w1 == "admin_pass"_s) { admin_pass = stringish<AccountPass>(w2); } - else if (w1 == "ladmin_log_filename") + else if (w1 == "ladmin_log_filename"_s) { ladmin_log_filename = w2; } else { - PRINTF("WARNING: unknown ladmin config key: %s\n", AString(w1)); + PRINTF("WARNING: unknown ladmin config key: %s\n"_fmt, AString(w1)); return false; } } @@ -2854,8 +2852,8 @@ void term_func(void) { delete_session(login_session); - Iprintf(SGR_RESET "----End of Ladmin (normal end with closing of all files).\n"); - LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n"); + Iprintf(SGR_RESET "----End of Ladmin (normal end with closing of all files).\n"_fmt); + LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n"_fmt); already_exit_function = 1; } @@ -2873,20 +2871,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -2898,24 +2896,24 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-admin.conf", admin_confs); + runflag &= load_config_file("conf/tmwa-admin.conf"_s, admin_confs); eathena_interactive_session = isatty(0); - LADMIN_LOG(""); - LADMIN_LOG("Configuration file readed.\n"); + LADMIN_LOG(""_fmt); + LADMIN_LOG("Configuration file readed.\n"_fmt); - Iprintf("EAthena login-server administration tool.\n"); + Iprintf("EAthena login-server administration tool.\n"_fmt); Version version = CURRENT_LOGIN_SERVER_VERSION; - Iprintf("for tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n", + Iprintf("for tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n"_fmt, version.major, version.minor, version.patch, version.devel, version.flags, version.which, version.vend); - LADMIN_LOG("Ladmin is ready.\n"); - Iprintf("Ladmin is " SGR_BOLD SGR_GREEN "ready" SGR_RESET ".\n\n"); + LADMIN_LOG("Ladmin is ready.\n"_fmt); + Iprintf("Ladmin is " SGR_BOLD SGR_GREEN "ready" SGR_RESET ".\n\n"_fmt); Connect_login_server(); diff --git a/src/char/char.cpp b/src/char/char.cpp index 8a3397d..477c699 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -91,7 +91,7 @@ AccountPass passwd; static ServerName server_name; static -CharName wisp_server_name = stringish<CharName>("Server"); +CharName wisp_server_name = stringish<CharName>("Server"_s); static IP4Address login_ip; static @@ -103,9 +103,9 @@ int char_port = 6121; static AString char_txt; static -CharName unknown_char_name = stringish<CharName>("Unknown"); +CharName unknown_char_name = stringish<CharName>("Unknown"_s); static -AString char_log_filename = "log/char.log"; +AString char_log_filename = "log/char.log"_s; //Added for lan support static IP4Address lan_map_ip = IP4_LOCALHOST; @@ -160,16 +160,16 @@ std::chrono::milliseconds autosave_time = DEFAULT_AUTOSAVE_INTERVAL; // Initial position (it's possible to set it in conf file) static -struct point start_point = { {"001-1.gat"}, 273, 354 }; +struct point start_point = { {"001-1.gat"_s}, 273, 354 }; static std::vector<GM_Account> gm_accounts; // online players by [Yor] static -AString online_txt_filename = "online.txt"; +AString online_txt_filename = "online.txt"_s; static -AString online_html_filename = "online.html"; +AString online_html_filename = "online.html"_s; static int online_sorting_option = 0; // sorting option to display online players in online files static @@ -192,7 +192,7 @@ static void delete_tologin(Session *sess) { assert (sess == login_session); - PRINTF("Char-server can't connect to login-server (connection #%d).\n", + PRINTF("Char-server can't connect to login-server (connection #%d).\n"_fmt, sess); login_session = nullptr; } @@ -207,7 +207,7 @@ void delete_frommap(Session *sess) auto it = std::find(server_session.begin(), server_session.end(), sess); assert (it != server_session.end()); int id = it - server_session.begin(); - PRINTF("Map-server %d (session #%d) has disconnected.\n", id, + PRINTF("Map-server %d (session #%d) has disconnected.\n"_fmt, id, sess); server[id] = mmo_map_server{}; server_session[id] = nullptr; @@ -317,7 +317,7 @@ AString mmo_char_tostr(struct CharPair *cp) "%d,%d,%d\t" "%d,%d,%d,%d,%d\t" "%s,%d,%d\t" - "%s,%d,%d,%d\t", + "%s,%d,%d,%d\t"_fmt, k->char_id, k->account_id, k->char_num, k->name, @@ -339,7 +339,7 @@ AString mmo_char_tostr(struct CharPair *cp) for (int i = 0; i < MAX_INVENTORY; i++) if (p->inventory[i].nameid) { - str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d "_fmt, p->inventory[i].id, p->inventory[i].nameid, p->inventory[i].amount, @@ -361,7 +361,7 @@ AString mmo_char_tostr(struct CharPair *cp) for (SkillID i : erange(SkillID(), MAX_SKILL)) if (p->skill[i].lv) { - str_p += STRPRINTF("%d,%d ", + str_p += STRPRINTF("%d,%d "_fmt, i, p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16)); } @@ -370,7 +370,7 @@ AString mmo_char_tostr(struct CharPair *cp) assert (p->global_reg_num < GLOBAL_REG_NUM); for (int i = 0; i < p->global_reg_num; i++) if (p->global_reg[i].str) - str_p += STRPRINTF("%s,%d ", + str_p += STRPRINTF("%s,%d "_fmt, p->global_reg[i].str, p->global_reg[i].value); str_p += '\t'; @@ -499,9 +499,9 @@ int mmo_char_init(void) io::ReadFile in(char_txt); if (!in.is_open()) { - PRINTF("Characters file not found: %s.\n", char_txt); - CHAR_LOG("Characters file not found: %s.\n", char_txt); - CHAR_LOG("Id for the next created character: %d.\n", + PRINTF("Characters file not found: %s.\n"_fmt, char_txt); + CHAR_LOG("Characters file not found: %s.\n"_fmt, char_txt); + CHAR_LOG("Id for the next created character: %d.\n"_fmt, char_id_count); return 0; } @@ -517,7 +517,7 @@ int mmo_char_init(void) { int i, j = 0; - if (SSCANF(line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0) + if (SSCANF(line, "%d\t%%newid%%%n"_fmt, &i, &j) == 1 && j > 0) { if (char_id_count < i) char_id_count = i; @@ -528,7 +528,7 @@ int mmo_char_init(void) CharPair cd; if (!extract(line, &cd)) { - CHAR_LOG("Char skipped\n%s", line); + CHAR_LOG("Char skipped\n%s"_fmt, line); continue; } if (cd.key.char_id >= char_id_count) @@ -537,12 +537,12 @@ int mmo_char_init(void) online_chars.push_back(nullptr); } - PRINTF("mmo_char_init: %zu characters read in %s.\n", + PRINTF("mmo_char_init: %zu characters read in %s.\n"_fmt, char_keys.size(), char_txt); - CHAR_LOG("mmo_char_init: %zu characters read in %s.\n", + CHAR_LOG("mmo_char_init: %zu characters read in %s.\n"_fmt, char_keys.size(), char_txt); - CHAR_LOG("Id for the next created character: %d.\n", + CHAR_LOG("Id for the next created character: %d.\n"_fmt, char_id_count); return 0; @@ -557,8 +557,8 @@ void mmo_char_sync(void) io::WriteLock fp(char_txt); if (!fp.is_open()) { - PRINTF("WARNING: Server can't not save characters.\n"); - CHAR_LOG("WARNING: Server can't not save characters.\n"); + PRINTF("WARNING: Server can't not save characters.\n"_fmt); + CHAR_LOG("WARNING: Server can't not save characters.\n"_fmt); return; } { @@ -568,7 +568,7 @@ void mmo_char_sync(void) AString line = mmo_char_tostr(&cd); fp.put_line(line); } - FPRINTF(fp, "%d\t%%newid%%\n", char_id_count); + FPRINTF(fp, "%d\t%%newid%%\n"_fmt, char_id_count); } } @@ -620,7 +620,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // remove control characters from the name if (!name.to__actual().is_print()) { - CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n", + CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n"_fmt, s, sd->account_id); return nullptr; } @@ -628,7 +628,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // Eliminate whitespace if (name.to__actual() != name.to__actual().strip()) { - CHAR_LOG("Make new char error (leading/trailing whitespace): (connection #%d, account: %d, name: '%s'.\n", + CHAR_LOG("Make new char error (leading/trailing whitespace): (connection #%d, account: %d, name: '%s'.\n"_fmt, s, sd->account_id, name); return nullptr; } @@ -636,7 +636,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // check lenght of character name if (name.to__actual().size() < 4) { - CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n", + CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n"_fmt, s, sd->account_id, name); return nullptr; } @@ -648,7 +648,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui for (uint8_t c : name.to__actual()) if (!char_name_letters[c]) { - CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n", + CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n"_fmt, s, sd->account_id, name, c); return nullptr; } @@ -659,7 +659,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui for (uint8_t c : name.to__actual()) if (char_name_letters[c]) { - CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n", + CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n"_fmt, s, sd->account_id, name, c); return nullptr; } @@ -671,7 +671,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui hair_style >= 20 || hair_color >= 12) { - CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n", + CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -684,7 +684,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui { if (stats[i] < 1 || stats[i] > 9) { - CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n", + CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -697,7 +697,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui { if (cd.key.name == name) { - CHAR_LOG("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, cd.key.name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -707,7 +707,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui if (cd.key.account_id == sd->account_id && cd.key.char_num == slot) { - CHAR_LOG("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, cd.key.name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -718,7 +718,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui if (wisp_server_name == name) { - CHAR_LOG("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name whisper server: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name whisper server: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, wisp_server_name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -728,7 +728,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui IP4Address ip = s->client_ip; - CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n", + CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -799,17 +799,17 @@ void create_online_files(void) timestamp_seconds_buffer timetemp; stamp_time(timetemp); // write heading - FPRINTF(fp2, "<HTML>\n"); - FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds - FPRINTF(fp2, " <HEAD>\n"); - FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n", + FPRINTF(fp2, "<HTML>\n"_fmt); + FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n"_fmt, online_refresh_html); // update on client explorer every x seconds + FPRINTF(fp2, " <HEAD>\n"_fmt); + FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n"_fmt, server_name); - FPRINTF(fp2, " </HEAD>\n"); - FPRINTF(fp2, " <BODY>\n"); - FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n", + FPRINTF(fp2, " </HEAD>\n"_fmt); + FPRINTF(fp2, " <BODY>\n"_fmt); + FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n"_fmt, server_name, timetemp); - FPRINTF(fp, "Online Players on %s (%s):\n", server_name, timetemp); - FPRINTF(fp, "\n"); + FPRINTF(fp, "Online Players on %s (%s):\n"_fmt, server_name, timetemp); + FPRINTF(fp, "\n"_fmt); int players = 0; // This used to be conditional on having any players, @@ -817,20 +817,20 @@ void create_online_files(void) //if (players > 0) { int j = 0; // count the number of characters for the txt version and to set the separate line - FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n"); - FPRINTF(fp2, " <tr>\n"); + FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n"_fmt); + FPRINTF(fp2, " <tr>\n"_fmt); { - FPRINTF(fp2, " <th>Name</th>\n"); + FPRINTF(fp2, " <th>Name</th>\n"_fmt); { - FPRINTF(fp, "Name "); // 30 + FPRINTF(fp, "Name "_fmt); // 30 j += 30; } } - FPRINTF(fp2, " </tr>\n"); - FPRINTF(fp, "\n"); + FPRINTF(fp2, " </tr>\n"_fmt); + FPRINTF(fp, "\n"_fmt); for (int k = 0; k < j; k++) - FPRINTF(fp, "-"); - FPRINTF(fp, "\n"); + FPRINTF(fp, "-"_fmt); + FPRINTF(fp, "\n"_fmt); // display each player. for (CharPair& cd : char_keys) @@ -838,55 +838,55 @@ void create_online_files(void) if (!server_for(&cd)) continue; players++; - FPRINTF(fp2, " <tr>\n"); + FPRINTF(fp2, " <tr>\n"_fmt); // displaying the character name { // without/with 'GM' display int gml = isGM(cd.key.account_id); { if (gml >= online_gm_display_min_level) - FPRINTF(fp, "%-24s (GM) ", cd.key.name); + FPRINTF(fp, "%-24s (GM) "_fmt, cd.key.name); else - FPRINTF(fp, "%-24s ", cd.key.name); + FPRINTF(fp, "%-24s "_fmt, cd.key.name); } // name of the character in the html (no < >, because that create problem in html code) - FPRINTF(fp2, " <td>"); + FPRINTF(fp2, " <td>"_fmt); if (gml >= online_gm_display_min_level) - FPRINTF(fp2, "<b>"); + FPRINTF(fp2, "<b>"_fmt); for (char c : cd.key.name.to__actual()) { switch (c) { case '&': - FPRINTF(fp2, "&"); + FPRINTF(fp2, "&"_fmt); break; case '<': - FPRINTF(fp2, "<"); + FPRINTF(fp2, "<"_fmt); break; case '>': - FPRINTF(fp2, ">"); + FPRINTF(fp2, ">"_fmt); break; default: - FPRINTF(fp2, "%c", c); + FPRINTF(fp2, "%c"_fmt, c); break; }; } if (gml >= online_gm_display_min_level) - FPRINTF(fp2, "</b> (GM)"); - FPRINTF(fp2, "</td>\n"); + FPRINTF(fp2, "</b> (GM)"_fmt); + FPRINTF(fp2, "</td>\n"_fmt); } - FPRINTF(fp, "\n"); - FPRINTF(fp2, " </tr>\n"); + FPRINTF(fp, "\n"_fmt); + FPRINTF(fp2, " </tr>\n"_fmt); } - FPRINTF(fp2, " </table>\n"); - FPRINTF(fp, "\n"); + FPRINTF(fp2, " </table>\n"_fmt); + FPRINTF(fp, "\n"_fmt); } // Displaying number of online players if (players == 0) { - FPRINTF(fp2, " <p>No user is online.</p>\n"); - FPRINTF(fp, "No user is online.\n"); + FPRINTF(fp2, " <p>No user is online.</p>\n"_fmt); + FPRINTF(fp, "No user is online.\n"_fmt); } else if (players == 1) { @@ -894,11 +894,11 @@ void create_online_files(void) } else { - FPRINTF(fp2, " <p>%d users are online.</p>\n", players); - FPRINTF(fp, "%d users are online.\n", players); + FPRINTF(fp2, " <p>%d users are online.</p>\n"_fmt, players); + FPRINTF(fp, "%d users are online.\n"_fmt, players); } - FPRINTF(fp2, " </BODY>\n"); - FPRINTF(fp2, "</HTML>\n"); + FPRINTF(fp2, " </BODY>\n"_fmt); + FPRINTF(fp2, "</HTML>\n"_fmt); } } @@ -1158,8 +1158,6 @@ void parse_tologin(Session *ls) while (RFIFOREST(ls) >= 2) { -// PRINTF("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(ls, 0)) { case 0x2711: @@ -1167,16 +1165,15 @@ void parse_tologin(Session *ls) return; if (RFIFOB(ls, 2)) { -// PRINTF("connect login server error : %d\n", RFIFOB(fd,2)); - PRINTF("Can not connect to login-server.\n"); - PRINTF("The server communication passwords (default s1/p1) is probably invalid.\n"); - PRINTF("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n"); - PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n"); + PRINTF("Can not connect to login-server.\n"_fmt); + PRINTF("The server communication passwords (default s1/p1) is probably invalid.\n"_fmt); + PRINTF("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n"_fmt); + PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n"_fmt); exit(1); } else { - PRINTF("Connected to login-server (connection #%d).\n", + PRINTF("Connected to login-server (connection #%d).\n"_fmt, ls); // if no map-server already connected, display a message... int i; @@ -1184,7 +1181,7 @@ void parse_tologin(Session *ls) if (server_session[i] && server[i].maps[0]) // if map-server online and at least 1 map break; if (i == MAX_MAP_SERVERS) - PRINTF("Awaiting maps from map-server.\n"); + PRINTF("Awaiting maps from map-server.\n"_fmt); } RFIFOSKIP(ls, 3); break; @@ -1192,7 +1189,6 @@ void parse_tologin(Session *ls) case 0x2713: if (RFIFOREST(ls) < 51) return; -// PRINTF("parse_tologin 2713 : %d\n", RFIFOB(fd,6)); for (io::FD i : iter_fds()) { Session *s2 = get_session(i); @@ -1210,10 +1206,6 @@ void parse_tologin(Session *ls) else if (max_connect_user == 0 || count_users() < max_connect_user) { -// if (max_connect_user == 0) -// PRINTF("max_connect_user (unlimited) -> accepted.\n"); -// else -// PRINTF("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user); sd->email = stringish<AccountEmail>(RFIFO_STRING<40>(ls, 7)); if (!e_mail_check(sd->email)) sd->email = DEFAULT_EMAIL; @@ -1224,7 +1216,6 @@ void parse_tologin(Session *ls) else { // refuse connection: too much online players -// PRINTF("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user); WFIFOW(s2, 0) = 0x6c; WFIFOB(s2, 2) = 0; WFIFOSET(s2, 3); @@ -1269,7 +1260,6 @@ void parse_tologin(Session *ls) WBUFL(buf, 2) = RFIFOL(ls, 2); // account WBUFL(buf, 6) = RFIFOL(ls, 6); // GM level mapif_sendall(buf, 10); -// PRINTF("parse_tologin: To become GM answer: char -> map.\n"); } RFIFOSKIP(ls, 10); break; @@ -1321,7 +1311,7 @@ void parse_tologin(Session *ls) || RFIFOREST(ls) < (8 + RFIFOL(ls, 4))) return; if (RFIFOL(ls, 4) < 1) - CHAR_LOG("Receiving a message for broadcast, but message is void.\n"); + CHAR_LOG("Receiving a message for broadcast, but message is void.\n"_fmt); else { int i; @@ -1330,18 +1320,18 @@ void parse_tologin(Session *ls) if (server_session[i]) break; if (i == MAX_MAP_SERVERS) - CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n"); + CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n"_fmt); else { size_t len = RFIFOL(ls, 4); AString message = RFIFO_STRING(ls, 8, len).to_print().lstrip(); // if message is only composed of spaces if (!message) - CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n"); + CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n"_fmt); // else send message to all map-servers else { - CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n", + CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n"_fmt, message); // send broadcast to all map-servers uint8_t buf[4 + len]; @@ -1377,7 +1367,6 @@ void parse_tologin(Session *ls) RFIFO_BUF_CLONE(ls, buf, len); WBUFW(buf, 0) = 0x2b11; mapif_sendall(buf, len); -// PRINTF("char: save_account_reg_reply\n"); } RFIFOSKIP(ls, RFIFOW(ls, 2)); break; @@ -1418,7 +1407,7 @@ void parse_tologin(Session *ls) FIX(s->storage_[j].nameid); #undef FIX if (changes) - CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n", + CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n"_fmt, source_id, dest_id, k->name, k->char_id, k->account_id, changes); @@ -1504,9 +1493,9 @@ void parse_tologin(Session *ls) { gm_accounts.push_back({static_cast<int>(RFIFOL(ls, i)), RFIFOB(ls, i + 4)}); } - PRINTF("From login-server: receiving of %zu GM accounts information.\n", + PRINTF("From login-server: receiving of %zu GM accounts information.\n"_fmt, gm_accounts.size()); - CHAR_LOG("From login-server: receiving of %zu GM accounts information.\n", + CHAR_LOG("From login-server: receiving of %zu GM accounts information.\n"_fmt, gm_accounts.size()); create_online_files(); // update online players files (perhaps some online players change of GM level) // send new gm acccounts level to map-servers @@ -1560,17 +1549,15 @@ void map_anti_freeze_system(TimerData *, tick_t) { int i; - //PRINTF("Entering in map_anti_freeze_system function to check freeze of servers.\n"); for (i = 0; i < MAX_MAP_SERVERS; i++) { if (server_session[i]) { // if map-server is online - //PRINTF("map_anti_freeze_system: server #%d, flag: %d.\n", i, server_freezeflag[i]); if (server_freezeflag[i]-- < 1) { // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed - PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n", + PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n"_fmt, i); - CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n", + CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n"_fmt, i); server_session[i]->set_eof(); } @@ -1593,8 +1580,6 @@ void parse_frommap(Session *ms) while (RFIFOREST(ms) >= 2) { -// PRINTF("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(ms, 0)) { // request from map-server to reload GM accounts. Transmission to login-server (by Yor) @@ -1621,10 +1606,10 @@ void parse_frommap(Session *ms) j++; } { - PRINTF("Map-Server %d connected: %d maps, from IP %s port %d.\n", + PRINTF("Map-Server %d connected: %d maps, from IP %s port %d.\n"_fmt, id, j, server[id].ip, server[id].port); - PRINTF("Map-server %d loading complete.\n", id); - CHAR_LOG("Map-Server %d connected: %d maps, from IP %s port %d. Map-server %d loading complete.\n", + PRINTF("Map-server %d loading complete.\n"_fmt, id); + CHAR_LOG("Map-Server %d connected: %d maps, from IP %s port %d. Map-server %d loading complete.\n"_fmt, id, j, server[id].ip, server[id].port, id); } @@ -1636,8 +1621,8 @@ void parse_frommap(Session *ms) unsigned char buf[16384]; if (j == 0) { - PRINTF("WARNING: Map-Server %d have NO map.\n", id); - CHAR_LOG("WARNING: Map-Server %d have NO map.\n", + PRINTF("WARNING: Map-Server %d have NO map.\n"_fmt, id); + CHAR_LOG("WARNING: Map-Server %d have NO map.\n"_fmt, id); // Transmitting maps information to the other map-servers } @@ -1686,7 +1671,6 @@ void parse_frommap(Session *ms) int login_id1 = RFIFOL(ms, 10); int login_id2 = RFIFOL(ms, 14); IP4Address ip = RFIFOIP(ms, 18); - //PRINTF("auth_fifo search: account: %d, char: %d, secure: %08x-%08x\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14)); for (AuthFifoEntry& afi : auth_fifo) { if (afi.account_id == account_id && @@ -1706,7 +1690,7 @@ void parse_frommap(Session *ms) break; } } - assert (cp && "uh-oh - deleted while in queue?"); + assert (cp && "uh-oh - deleted while in queue?"_s); CharKey *ck = &cp->key; CharData *cd = cp->data.get(); @@ -1720,12 +1704,11 @@ void parse_frommap(Session *ms) cd->sex = afi.sex; WFIFOW(ms, 16) = afi.packet_tmw_version; FPRINTF(stderr, - "From queue index %zd: recalling packet version %d\n", + "From queue index %zd: recalling packet version %d\n"_fmt, (&afi - &auth_fifo.front()), afi.packet_tmw_version); WFIFO_STRUCT(ms, 18, *ck); WFIFO_STRUCT(ms, 18 + sizeof(*ck), *cd); WFIFOSET(ms, WFIFOW(ms, 2)); - //PRINTF("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6)); goto x2afc_out; } } @@ -1733,7 +1716,7 @@ void parse_frommap(Session *ms) WFIFOW(ms, 0) = 0x2afe; WFIFOL(ms, 2) = account_id; WFIFOSET(ms, 6); - PRINTF("auth_fifo search error! account %d not authentified.\n", + PRINTF("auth_fifo search error! account %d not authentified.\n"_fmt, account_id); } } @@ -2070,7 +2053,7 @@ void parse_frommap(Session *ms) return; } // inter server処理でもない場合は切断 - PRINTF("char: unknown packet 0x%04x (%zu bytes to read in buffer)! (from map).\n", + PRINTF("char: unknown packet 0x%04x (%zu bytes to read in buffer)! (from map).\n"_fmt, RFIFOW(ms, 0), RFIFOREST(ms)); ms->set_eof(); return; @@ -2104,8 +2087,8 @@ int lan_ip_check(IP4Address addr) { bool lancheck = lan_subnet.covers(addr); - PRINTF("LAN test (result): %s.\n", - (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET); + PRINTF("LAN test (result): %s.\n"_fmt, + (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET ""_s : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET ""_s); return lancheck; } @@ -2127,7 +2110,7 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP CharKey *ck = &cp->key; CharData *cd = cp->data.get(); - CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n", + CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n"_fmt, sd->account_id, rfifob_2, ck->name, ip); // searching map server @@ -2144,7 +2127,7 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP { // change save point to one of map found on the server (the first) i = j; cd->last_point.map_ = server[j].maps[0]; - PRINTF("Map-server #%d found with a map: '%s'.\n", + PRINTF("Map-server #%d found with a map: '%s'.\n"_fmt, j, server[j].maps[0]); // coordonates are unknown break; @@ -2161,10 +2144,10 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP WFIFOW(s, 0) = 0x71; WFIFOL(s, 2) = ck->char_id; WFIFO_STRING(s, 6, cd->last_point.map_, 16); - PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n", + PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n"_fmt, ck->name, sd->account_id, ck->char_num, ip); - PRINTF("--Send IP of map-server. "); + PRINTF("--Send IP of map-server. "_fmt); if (lan_ip_check(ip)) WFIFOIP(s, 22) = lan_map_ip; else @@ -2206,9 +2189,6 @@ void parse_char(Session *s) while (RFIFOREST(s) >= 2) { -// if (RFIFOW(fd,0) < 30000) -// PRINTF("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(s, 0)) { case 0x20b: //20040622暗号化ragexe対応 @@ -2239,16 +2219,16 @@ void parse_char(Session *s) int account_id = RFIFOL(s, 2); int GM_value = isGM(account_id); if (GM_value) - PRINTF("Account Logged On; Account ID: %d (GM level %d).\n", + PRINTF("Account Logged On; Account ID: %d (GM level %d).\n"_fmt, account_id, GM_value); else - PRINTF("Account Logged On; Account ID: %d.\n", + PRINTF("Account Logged On; Account ID: %d.\n"_fmt, account_id); if (sd == NULL) { s->session_data = make_unique<char_session_data, SessionDeleter>(); sd = static_cast<char_session_data *>(s->session_data.get()); - sd->email = stringish<AccountEmail>("no mail"); // put here a mail without '@' to refuse deletion if we don't receive the e-mail + sd->email = stringish<AccountEmail>("no mail"_s); // put here a mail without '@' to refuse deletion if we don't receive the e-mail sd->connect_until_time = TimeT(); // unknow or illimited (not displaying on map-server) } sd->account_id = account_id; @@ -2602,7 +2582,7 @@ void check_connect_login_server(TimerData *, tick_t) { if (!login_session) { - PRINTF("Attempt to connect to login-server...\n"); + PRINTF("Attempt to connect to login-server...\n"_fmt); login_session = make_connection(login_ip, login_port, SessionParsers{func_parse: parse_tologin, func_delete: delete_tologin}); if (!login_session) @@ -2632,7 +2612,7 @@ bool char_lan_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "lan_map_ip") + if (w1 == "lan_map_ip"_s) { // Read map-server Lan IP Address h = gethostbyname(w2.c_str()); @@ -2647,20 +2627,20 @@ bool char_lan_config(XString w1, ZString w2) } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } - PRINTF("LAN IP of map-server: %s.\n", lan_map_ip); + PRINTF("LAN IP of map-server: %s.\n"_fmt, lan_map_ip); } - else if (w1 == "subnet" /*backward compatibility*/ - || w1 == "lan_subnet") + else if (w1 == "subnet"_s /*backward compatibility*/ + || w1 == "lan_subnet"_s) { if (!extract(w2, &lan_subnet)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } - PRINTF("Sub-network of the map-server: %s.\n", + PRINTF("Sub-network of the map-server: %s.\n"_fmt, lan_subnet); } else @@ -2676,10 +2656,10 @@ bool lan_check() { // sub-network check of the map-server { - PRINTF("LAN test of LAN IP of the map-server: "); + PRINTF("LAN test of LAN IP of the map-server: "_fmt); if (!lan_ip_check(lan_map_ip)) { - PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network." SGR_RESET "\n"); + PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network." SGR_RESET "\n"_fmt); return false; } } @@ -2693,21 +2673,21 @@ bool char_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "userid") + if (w1 == "userid"_s) userid = stringish<AccountName>(w2); - else if (w1 == "passwd") + else if (w1 == "passwd"_s) passwd = stringish<AccountPass>(w2); - else if (w1 == "server_name") + else if (w1 == "server_name"_s) { server_name = stringish<ServerName>(w2); - PRINTF("%s server has been intialized\n", w2); + PRINTF("%s server has been intialized\n"_fmt, w2); } - else if (w1 == "wisp_server_name") + else if (w1 == "wisp_server_name"_s) { if (w2.size() >= 4) wisp_server_name = stringish<CharName>(w2); } - else if (w1 == "login_ip") + else if (w1 == "login_ip"_s) { h = gethostbyname(w2.c_str()); if (h != NULL) @@ -2718,20 +2698,20 @@ bool char_config(XString w1, ZString w2) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Login server IP address : %s -> %s\n", + PRINTF("Login server IP address : %s -> %s\n"_fmt, w2, login_ip); } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "char_ip") + else if (w1 == "char_ip"_s) { h = gethostbyname(w2.c_str()); if (h != NULL) @@ -2742,56 +2722,56 @@ bool char_config(XString w1, ZString w2) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Character server IP address : %s -> %s\n", + PRINTF("Character server IP address : %s -> %s\n"_fmt, w2, char_ip); } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } } - else if (w1 == "char_port") + else if (w1 == "char_port"_s) { char_port = atoi(w2.c_str()); } - else if (w1 == "char_txt") + else if (w1 == "char_txt"_s) { char_txt = w2; } - else if (w1 == "max_connect_user") + else if (w1 == "max_connect_user"_s) { max_connect_user = atoi(w2.c_str()); if (max_connect_user < 0) max_connect_user = 0; // unlimited online players } - else if (w1 == "check_ip_flag") + else if (w1 == "check_ip_flag"_s) { check_ip_flag = config_switch(w2); } - else if (w1 == "autosave_time") + else if (w1 == "autosave_time"_s) { autosave_time = std::chrono::seconds(atoi(w2.c_str())); if (autosave_time <= std::chrono::seconds::zero()) autosave_time = DEFAULT_AUTOSAVE_INTERVAL; } - else if (w1 == "start_point") + else if (w1 == "start_point"_s) { extract(w2, &start_point); } - else if (w1 == "unknown_char_name") + else if (w1 == "unknown_char_name"_s) { unknown_char_name = stringish<CharName>(w2); } - else if (w1 == "char_log_filename") + else if (w1 == "char_log_filename"_s) { char_log_filename = w2; } - else if (w1 == "char_name_option") + else if (w1 == "char_name_option"_s) { char_name_option = atoi(w2.c_str()); } - else if (w1 == "char_name_letters") + else if (w1 == "char_name_letters"_s) { if (!w2) char_name_letters.reset(); @@ -2799,35 +2779,35 @@ bool char_config(XString w1, ZString w2) for (uint8_t c : w2) char_name_letters[c] = true; } - else if (w1 == "online_txt_filename") + else if (w1 == "online_txt_filename"_s) { online_txt_filename = w2; } - else if (w1 == "online_html_filename") + else if (w1 == "online_html_filename"_s) { online_html_filename = w2; } - else if (w1 == "online_sorting_option") + else if (w1 == "online_sorting_option"_s) { online_sorting_option = atoi(w2.c_str()); } - else if (w1 == "online_gm_display_min_level") + else if (w1 == "online_gm_display_min_level"_s) { // minimum GM level to display 'GM' when we want to display it online_gm_display_min_level = atoi(w2.c_str()); if (online_gm_display_min_level < 5) // send online file every 5 seconds to player is enough online_gm_display_min_level = 5; } - else if (w1 == "online_refresh_html") + else if (w1 == "online_refresh_html"_s) { online_refresh_html = atoi(w2.c_str()); if (online_refresh_html < 1) online_refresh_html = 1; } - else if (w1 == "anti_freeze_enable") + else if (w1 == "anti_freeze_enable"_s) { anti_freeze_enable = config_switch(w2); } - else if (w1 == "anti_freeze_interval") + else if (w1 == "anti_freeze_interval"_s) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), @@ -2858,7 +2838,7 @@ void term_func(void) delete_session(login_session); delete_session(char_session); - CHAR_LOG("----End of char-server (normal end with closing of all files).\n"); + CHAR_LOG("----End of char-server (normal end with closing of all files).\n"_fmt); } static @@ -2883,20 +2863,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -2908,11 +2888,11 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-char.conf", char_confs); + runflag &= load_config_file("conf/tmwa-char.conf"_s, char_confs); // a newline in the log... - CHAR_LOG(""); - CHAR_LOG("The char-server starting...\n"); + CHAR_LOG(""_fmt); + CHAR_LOG("The char-server starting...\n"_fmt); runflag &= lan_check(); @@ -2945,10 +2925,10 @@ int do_init(Slice<ZString> argv) ).detach(); } - CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n", + CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n"_fmt, char_port); - PRINTF("The char-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The char-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, char_port); return 0; diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index c9965dc..952788c 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -42,7 +42,7 @@ #include "../poison.hpp" -AString party_txt = "save/party.txt"; +AString party_txt = "save/party.txt"_s; static Map<int, struct party> party_db; @@ -64,7 +64,7 @@ AString inter_party_tostr(struct party *p) str += STRPRINTF( "%d\t" "%s\t" - "%d,%d\t", + "%d,%d\t"_fmt, p->party_id, p->name, p->exp, p->item); @@ -75,7 +75,7 @@ AString inter_party_tostr(struct party *p) continue; str += STRPRINTF( "%d,%d\t" - "%s\t", + "%s\t"_fmt, m->account_id, m->leader, m->name); } @@ -132,10 +132,10 @@ void party_check_deleted_init(struct party *p) const CharPair *c = search_character(p->member[i].name); if (!c || c->key.account_id != p->member[i].account_id) { - CHAR_LOG("WARNING: deleting obsolete party member %d %s of %d %s\n", + CHAR_LOG("WARNING: deleting obsolete party member %d %s of %d %s\n"_fmt, p->member[i].account_id, p->member[i].name, p->party_id, p->name); - PRINTF("WARNING: deleting obsolete party member %d %s of %d %s\n", + PRINTF("WARNING: deleting obsolete party member %d %s of %d %s\n"_fmt, p->member[i].account_id, p->member[i].name, p->party_id, p->name); p->member[i] = party_member{}; @@ -156,7 +156,7 @@ void inter_party_init(void) while (in.getline(line)) { int i, j = 0; - if (SSCANF(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 + if (SSCANF(line, "%d\t%%newid%%\n%n"_fmt, &i, &j) == 1 && j > 0 && party_newid <= i) { party_newid = i; @@ -174,7 +174,7 @@ void inter_party_init(void) } else { - PRINTF("int_party: broken data [%s] line %d\n", party_txt, + PRINTF("int_party: broken data [%s] line %d\n"_fmt, party_txt, c + 1); } c++; @@ -195,7 +195,7 @@ int inter_party_save(void) io::WriteLock fp(party_txt); if (!fp.is_open()) { - PRINTF("int_party: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_party: cant write [%s] !!! data is lost !!!\n"_fmt, party_txt); return 1; } @@ -251,10 +251,8 @@ int party_check_empty(struct party *p) { int i; -// PRINTF("party check empty %08X\n", (int)p); for (i = 0; i < MAX_PARTY; i++) { -// PRINTF("%d acc=%d\n", i, p->member[i].account_id); if (p->member[i].account_id > 0) { return 0; @@ -283,7 +281,7 @@ void party_check_conflict_sub(struct party *p, && p->member[i].name == nick) { // 別のパーティに偽の所属データがあるので脱退 - PRINTF("int_party: party conflict! %d %d %d\n", account_id, + PRINTF("int_party: party conflict! %d %d %d\n"_fmt, account_id, party_id, p->party_id); mapif_parse_PartyLeave(nullptr, p->party_id, account_id); } @@ -313,13 +311,13 @@ void mapif_party_created(Session *s, int account_id, struct party *p) WFIFOB(s, 6) = 0; WFIFOL(s, 7) = p->party_id; WFIFO_STRING(s, 11, p->name, 24); - PRINTF("int_party: created! %d %s\n", p->party_id, p->name); + PRINTF("int_party: created! %d %s\n"_fmt, p->party_id, p->name); } else { WFIFOB(s, 6) = 1; WFIFOL(s, 7) = 0; - WFIFO_STRING(s, 11, "error", 24); + WFIFO_STRING(s, 11, "error"_s, 24); } WFIFOSET(s, 35); } @@ -332,7 +330,7 @@ void mapif_party_noinfo(Session *s, int party_id) WFIFOW(s, 2) = 8; WFIFOL(s, 4) = party_id; WFIFOSET(s, 8); - PRINTF("int_party: info not found %d\n", party_id); + PRINTF("int_party: info not found %d\n"_fmt, party_id); } // パーティ情報まとめ送り @@ -348,7 +346,6 @@ void mapif_party_info(Session *s, struct party *p) mapif_sendall(buf, WBUFW(buf, 2)); else mapif_send(s, buf, WBUFW(buf, 2)); -// PRINTF("int_party: info %d %s\n", p->party_id, p->name); } // パーティメンバ追加可否 @@ -379,7 +376,7 @@ void mapif_party_optionchanged(Session *s, struct party *p, int account_id, mapif_sendall(buf, 15); else mapif_send(s, buf, 15); - PRINTF("int_party: option changed %d %d %d %d %d\n", p->party_id, + PRINTF("int_party: option changed %d %d %d %d %d\n"_fmt, p->party_id, account_id, p->exp, p->item, flag); } @@ -394,7 +391,7 @@ void mapif_party_leaved(int party_id, int account_id, CharName name) WBUFL(buf, 6) = account_id; WBUF_STRING(buf, 10, name.to__actual(), 24); mapif_sendall(buf, 34); - PRINTF("int_party: party leaved %d %d %s\n", party_id, account_id, name); + PRINTF("int_party: party leaved %d %d %s\n"_fmt, party_id, account_id, name); } // パーティマップ更新通知 @@ -421,8 +418,8 @@ void mapif_party_broken(int party_id, int flag) WBUFL(buf, 2) = party_id; WBUFB(buf, 6) = flag; mapif_sendall(buf, 7); - PRINTF("int_party: broken %d\n", party_id); - CHAR_LOG("int_party: broken %d\n", party_id); + PRINTF("int_party: broken %d\n"_fmt, party_id); + CHAR_LOG("int_party: broken %d\n"_fmt, party_id); } // パーティ内発言 @@ -451,7 +448,7 @@ void mapif_parse_CreateParty(Session *s, int account_id, PartyName name, CharNam { if (!name.is_print()) { - PRINTF("int_party: illegal party name [%s]\n", name); + PRINTF("int_party: illegal party name [%s]\n"_fmt, name); mapif_party_created(s, account_id, NULL); return; } @@ -459,7 +456,7 @@ void mapif_parse_CreateParty(Session *s, int account_id, PartyName name, CharNam if (search_partyname(name) != NULL) { - PRINTF("int_party: same name party exists [%s]\n", name); + PRINTF("int_party: same name party exists [%s]\n"_fmt, name); mapif_party_created(s, account_id, NULL); return; } diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index c7c1343..6021d54 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -43,7 +43,7 @@ // ファイル名のデフォルト // inter_config_read()で再設定される -AString storage_txt = "save/storage.txt"; +AString storage_txt = "save/storage.txt"_s; static Map<int, struct storage> storage_db; @@ -54,7 +54,7 @@ AString storage_tostr(struct storage *p) { MString str; str += STRPRINTF( - "%d,%d\t", + "%d,%d\t"_fmt, p->account_id, p->storage_amount); int f = 0; @@ -62,7 +62,7 @@ AString storage_tostr(struct storage *p) if (p->storage_[i].nameid && p->storage_[i].amount) { str += STRPRINTF( - "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d "_fmt, p->storage_[i].id, p->storage_[i].nameid, p->storage_[i].amount, @@ -106,7 +106,7 @@ bool extract(XString str, struct storage *p) std::copy(storage_items.begin(), storage_items.end(), p->storage_.begin()); if (p->storage_amount != storage_items.size()) - PRINTF("WARNING: storage desync for %d\n", p->account_id); + PRINTF("WARNING: storage desync for %d\n"_fmt, p->account_id); return true; } @@ -131,7 +131,7 @@ void inter_storage_init(void) io::ReadFile in(storage_txt); if (!in.is_open()) { - PRINTF("cant't read : %s\n", storage_txt); + PRINTF("cant't read : %s\n"_fmt, storage_txt); return; } @@ -145,7 +145,7 @@ void inter_storage_init(void) } else { - PRINTF("int_storage: broken data [%s] line %d\n", + PRINTF("int_storage: broken data [%s] line %d\n"_fmt, storage_txt, c); } c++; @@ -168,7 +168,7 @@ int inter_storage_save(void) if (!fp.is_open()) { - PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n"_fmt, storage_txt); return 1; } @@ -227,7 +227,7 @@ void mapif_parse_SaveStorage(Session *ss) int len = RFIFOW(ss, 2); if (sizeof(struct storage) != len - 8) { - PRINTF("inter storage: data size error %zu %d\n", + PRINTF("inter storage: data size error %zu %d\n"_fmt, sizeof(struct storage), len - 8); } else diff --git a/src/char/inter.cpp b/src/char/inter.cpp index 204a0e2..f7b3184 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -50,7 +50,7 @@ #include "../poison.hpp" static -AString accreg_txt = "save/accreg.txt"; +AString accreg_txt = "save/accreg.txt"_s; struct accreg { @@ -85,9 +85,9 @@ AString inter_accreg_tostr(struct accreg *reg) { assert(reg->reg_num < ACCOUNT_REG_NUM); MString str; - str += STRPRINTF("%d\t", reg->account_id); + str += STRPRINTF("%d\t"_fmt, reg->account_id); for (int j = 0; j < reg->reg_num; j++) - str += STRPRINTF("%s,%d ", reg->reg[j].str, reg->reg[j].value); + str += STRPRINTF("%s,%d "_fmt, reg->reg[j].str, reg->reg[j].value); return AString(str); } @@ -130,7 +130,7 @@ void inter_accreg_init(void) } else { - PRINTF("inter: accreg: broken data [%s] line %d\n", accreg_txt, + PRINTF("inter: accreg: broken data [%s] line %d\n"_fmt, accreg_txt, c); } c++; @@ -155,7 +155,7 @@ int inter_accreg_save(void) io::WriteLock fp(accreg_txt); if (!fp.is_open()) { - PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n"_fmt, accreg_txt); return 1; } @@ -168,19 +168,19 @@ int inter_accreg_save(void) bool inter_config(XString w1, ZString w2) { { - if (w1 == "storage_txt") + if (w1 == "storage_txt"_s) { storage_txt = w2; } - else if (w1 == "party_txt") + else if (w1 == "party_txt"_s) { party_txt = w2; } - else if (w1 == "accreg_txt") + else if (w1 == "accreg_txt"_s) { accreg_txt = w2; } - else if (w1 == "party_share_level") + else if (w1 == "party_share_level"_s) { party_share_level = atoi(w2.c_str()); if (party_share_level < 0) @@ -316,7 +316,7 @@ void mapif_parse_WisRequest(Session *sms) { if (RFIFOW(sms, 2) - 52 <= 0) { // normaly, impossible, but who knows... - PRINTF("inter: Wis message doesn't exist.\n"); + PRINTF("inter: Wis message doesn't exist.\n"_fmt); return; } diff --git a/src/generic/intern-pool_test.cpp b/src/generic/intern-pool_test.cpp index b72ab04..3207792 100644 --- a/src/generic/intern-pool_test.cpp +++ b/src/generic/intern-pool_test.cpp @@ -28,13 +28,13 @@ TEST(InternPool, whydoesthisalwaysneedasecondname) { InternPool p; EXPECT_EQ(0, p.size()); - EXPECT_EQ(0, p.intern("hello")); - EXPECT_EQ(0, p.intern("hello")); + EXPECT_EQ(0, p.intern("hello"_s)); + EXPECT_EQ(0, p.intern("hello"_s)); EXPECT_EQ(1, p.size()); - EXPECT_EQ(1, p.intern("world")); - EXPECT_EQ(0, p.intern("hello")); - EXPECT_EQ(1, p.intern("world")); + EXPECT_EQ(1, p.intern("world"_s)); + EXPECT_EQ(0, p.intern("hello"_s)); + EXPECT_EQ(1, p.intern("world"_s)); EXPECT_EQ(2, p.size()); - EXPECT_EQ("hello", p.outtern(0)); - EXPECT_EQ("world", p.outtern(1)); + EXPECT_EQ("hello"_s, p.outtern(0)); + EXPECT_EQ("world"_s, p.outtern(1)); } diff --git a/src/generic/md5_test.cpp b/src/generic/md5_test.cpp index f6a2324..047b082 100644 --- a/src/generic/md5_test.cpp +++ b/src/generic/md5_test.cpp @@ -38,11 +38,11 @@ VString<32> MD5(XString in) TEST(md5calc, rfc1321) { - EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", MD5("")); - EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661", MD5("a")); - EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72", MD5("abc")); - EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", MD5("message digest")); - EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b", MD5("abcdefghijklmnopqrstuvwxyz")); - EXPECT_EQ("d174ab98d277d9f5a5611c2c9f419d9f", MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")); - EXPECT_EQ("57edf4a22be3c955ac49da2e2107b67a", MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890")); + EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e"_s, MD5(""_s)); + EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661"_s, MD5("a"_s)); + EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72"_s, MD5("abc"_s)); + EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0"_s, MD5("message digest"_s)); + EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b"_s, MD5("abcdefghijklmnopqrstuvwxyz"_s)); + EXPECT_EQ("d174ab98d277d9f5a5611c2c9f419d9f"_s, MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"_s)); + EXPECT_EQ("57edf4a22be3c955ac49da2e2107b67a"_s, MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890"_s)); } diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index 66419df..a2faa18 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -192,7 +192,7 @@ namespace cxxstdio int print(T&& t, A&&... a) { constexpr static - const char *print_format = Format::print_format(); + const char *print_format = Format::print_format().format_string(); return do_print(std::forward<T>(t), print_format, decay_for_printf(convert_for_printf(std::forward<A>(a)))...); } @@ -207,7 +207,7 @@ namespace cxxstdio int scan(T&& t, A&&... a) { constexpr static - const char *scan_format = Format::scan_format(); + const char *scan_format = Format::scan_format().format_string(); return do_scan(std::forward<T>(t), scan_format, &convert_for_scanf(*a)...); } @@ -218,7 +218,7 @@ namespace cxxstdio struct format_impl \ { \ constexpr static \ - const char *print_format() { return fmt; } \ + FormatString print_format() { return fmt; } \ }; \ cxxstdio::PrintFormatter<format_impl>::print(out, ## __VA_ARGS__); \ }) @@ -228,7 +228,7 @@ namespace cxxstdio struct format_impl \ { \ constexpr static \ - const char *scan_format() { return fmt; } \ + FormatString scan_format() { return fmt; } \ }; \ cxxstdio::ScanFormatter<format_impl>::scan(out, ## __VA_ARGS__); \ }) diff --git a/src/io/line.cpp b/src/io/line.cpp index f7470a6..8451b87 100644 --- a/src/io/line.cpp +++ b/src/io/line.cpp @@ -36,26 +36,26 @@ namespace io { MString out; if (column) - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, filename, line, column, cat, msg); else - out += STRPRINTF("%s:%u: %s: %s\n", + out += STRPRINTF("%s:%u: %s: %s\n"_fmt, filename, line, cat, msg); - out += STRPRINTF("%s\n", text); - out += STRPRINTF("%*c\n", column, '^'); + out += STRPRINTF("%s\n"_fmt, text); + out += STRPRINTF("%*c\n"_fmt, column, '^'); return AString(out); } void Line::message(ZString cat, ZString msg) const { if (column) - FPRINTF(stderr, "%s:%u:%u: %s: %s\n", + FPRINTF(stderr, "%s:%u:%u: %s: %s\n"_fmt, filename, line, column, cat, msg); else - FPRINTF(stderr, "%s:%u: %s: %s\n", + FPRINTF(stderr, "%s:%u: %s: %s\n"_fmt, filename, line, cat, msg); - FPRINTF(stderr, "%s\n", text); - FPRINTF(stderr, "%*c\n", column, '^'); + FPRINTF(stderr, "%s\n"_fmt, text); + FPRINTF(stderr, "%*c\n"_fmt, column, '^'); } AString LineSpan::message_str(ZString cat, ZString msg) const @@ -67,24 +67,24 @@ namespace io MString out; if (begin.line == end.line) { - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, begin.filename, begin.line, begin.column, cat, msg); - out += STRPRINTF("%s\n", begin.text); - out += STRPRINTF("%*c", begin.column, '^'); + out += STRPRINTF("%s\n"_fmt, begin.text); + out += STRPRINTF("%*c"_fmt, begin.column, '^'); for (unsigned c = begin.column; c != end.column; ++c) out += '~'; out += '\n'; } else { - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, begin.filename, begin.line, begin.column, cat, msg); - out += STRPRINTF("%s\n", begin.text); - out += STRPRINTF("%*c", begin.column, '^'); + out += STRPRINTF("%s\n"_fmt, begin.text); + out += STRPRINTF("%*c"_fmt, begin.column, '^'); for (unsigned c = begin.column; c != begin.text.size(); ++c) out += '~'; - out += " ...\n"; - out += STRPRINTF("%s\n", end.text); + out += " ...\n"_s; + out += STRPRINTF("%s\n"_fmt, end.text); for (unsigned c = 0; c != end.column; ++c) out += '~'; out += '\n'; @@ -94,7 +94,7 @@ namespace io void LineSpan::message(ZString cat, ZString msg) const { - FPRINTF(stderr, "%s", message_str(cat, msg)); + FPRINTF(stderr, "%s"_fmt, message_str(cat, msg)); } LineReader::LineReader(ZString name) diff --git a/src/io/line.hpp b/src/io/line.hpp index a9e8944..bb002b8 100644 --- a/src/io/line.hpp +++ b/src/io/line.hpp @@ -42,9 +42,9 @@ namespace io AString message_str(ZString cat, ZString msg) const; void message(ZString cat, ZString msg) const; - void note(ZString msg) const { message("note", msg); } - void warning(ZString msg) const { message("warning", msg); } - void error(ZString msg) const { message("error", msg); } + void note(ZString msg) const { message("note"_s, msg); } + void warning(ZString msg) const { message("warning"_s, msg); } + void error(ZString msg) const { message("error"_s, msg); } }; // psst, don't tell anyone @@ -65,9 +65,9 @@ namespace io AString message_str(ZString cat, ZString msg) const; void message(ZString cat, ZString msg) const; - void note(ZString msg) const { message("note", msg); } - void warning(ZString msg) const { message("warning", msg); } - void error(ZString msg) const { message("error", msg); } + void note(ZString msg) const { message("note"_s, msg); } + void warning(ZString msg) const { message("warning"_s, msg); } + void error(ZString msg) const { message("error"_s, msg); } }; class LineReader diff --git a/src/io/line_test.cpp b/src/io/line_test.cpp index feee1fb..921e4c8 100644 --- a/src/io/line_test.cpp +++ b/src/io/line_test.cpp @@ -42,80 +42,80 @@ io::FD string_pipe(ZString sz) TEST(io, line1) { - io::LineReader lr("<string1>", string_pipe("Hello World\n")); + io::LineReader lr("<string1>"_s, string_pipe("Hello World\n"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello World"); - EXPECT_EQ(hi.filename, "<string1>"); + EXPECT_EQ(hi.text, "Hello World"_s); + EXPECT_EQ(hi.filename, "<string1>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line2) { - io::LineReader lr("<string2>", string_pipe("Hello\nWorld")); + io::LineReader lr("<string2>"_s, string_pipe("Hello\nWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string2>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string2>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string2>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string2>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line3) { - io::LineReader lr("<string3>", string_pipe("Hello\rWorld")); + io::LineReader lr("<string3>"_s, string_pipe("Hello\rWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string3>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string3>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string3>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string3>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line4) { - io::LineReader lr("<string4>", string_pipe("Hello\r\nWorld")); + io::LineReader lr("<string4>"_s, string_pipe("Hello\r\nWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string4>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string4>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string4>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string4>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line5) { - io::LineReader lr("<string5>", string_pipe("Hello\n\rWorld")); + io::LineReader lr("<string5>"_s, string_pipe("Hello\n\rWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, ""); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, ""_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 3); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); @@ -123,47 +123,47 @@ TEST(io, line5) TEST(io, linechar1) { - io::LineCharReader lr("<stringchar1>", string_pipe("Hi Wu\n")); + io::LineCharReader lr("<stringchar1>"_s, string_pipe("Hi Wu\n"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), ' '); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 4); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 5); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 6); lr.adv(); @@ -171,47 +171,47 @@ TEST(io, linechar1) } TEST(io, linechar2) { - io::LineCharReader lr("<stringchar2>", string_pipe("Hi\nWu")); + io::LineCharReader lr("<stringchar2>"_s, string_pipe("Hi\nWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -219,47 +219,47 @@ TEST(io, linechar2) } TEST(io, linechar3) { - io::LineCharReader lr("<stringchar3>", string_pipe("Hi\rWu")); + io::LineCharReader lr("<stringchar3>"_s, string_pipe("Hi\rWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -267,47 +267,47 @@ TEST(io, linechar3) } TEST(io, linechar4) { - io::LineCharReader lr("<stringchar4>", string_pipe("Hi\r\nWu")); + io::LineCharReader lr("<stringchar4>"_s, string_pipe("Hi\r\nWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -315,54 +315,54 @@ TEST(io, linechar4) } TEST(io, linechar5) { - io::LineCharReader lr("<stringchar5>", string_pipe("Hi\n\rWu")); + io::LineCharReader lr("<stringchar5>"_s, string_pipe("Hi\n\rWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, ""); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, ""_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 3); lr.adv(); @@ -371,7 +371,7 @@ TEST(io, linechar5) TEST(io, linespan) { - io::LineCharReader lr("<span>", string_pipe("Hello,\nWorld!\n")); + io::LineCharReader lr("<span>"_s, string_pipe("Hello,\nWorld!\n"_s)); io::LineSpan span; do { @@ -385,10 +385,10 @@ TEST(io, linespan) lr.adv(); } while (span.end.ch() != 'o'); - EXPECT_EQ(span.message_str("info", "meh"), + EXPECT_EQ(span.message_str("info"_s, "meh"_s), "<span>:1:2: info: meh\n" "Hello,\n" - " ^~~~\n" + " ^~~~\n"_s ); span.begin = span.end; do @@ -398,21 +398,21 @@ TEST(io, linespan) } while (span.end.ch() != 'r'); - EXPECT_EQ(span.begin.message_str("note", "foo"), + EXPECT_EQ(span.begin.message_str("note"_s, "foo"_s), "<span>:1:5: note: foo\n" "Hello,\n" - " ^\n" + " ^\n"_s ); - EXPECT_EQ(span.end.message_str("warning", "bar"), + EXPECT_EQ(span.end.message_str("warning"_s, "bar"_s), "<span>:2:3: warning: bar\n" "World!\n" - " ^\n" + " ^\n"_s ); - EXPECT_EQ(span.message_str("error", "qux"), + EXPECT_EQ(span.message_str("error"_s, "qux"_s), "<span>:1:5: error: qux\n" "Hello,\n" " ^~ ...\n" "World!\n" - "~~~\n" + "~~~\n"_s ); } diff --git a/src/io/lock.cpp b/src/io/lock.cpp index 96c3649..1342915 100644 --- a/src/io/lock.cpp +++ b/src/io/lock.cpp @@ -49,7 +49,7 @@ namespace io AString newfile; do { - newfile = STRPRINTF("%s_%d.tmp", filename, no++); + newfile = STRPRINTF("%s_%d.tmp"_fmt, filename, no++); fd = FD::open(newfile, O_WRONLY | O_CREAT | O_EXCL, 0666); } while (fd == FD() && errno == EEXIST); @@ -67,21 +67,21 @@ namespace io if (!WriteFile::close()) { // leave partial file - FPRINTF(stderr, "Warning: failed to write replacement for %s\n", filename); + FPRINTF(stderr, "Warning: failed to write replacement for %s\n"_fmt, filename); abort(); } int n = backup_count; - AString old_filename = STRPRINTF("%s.%d", filename, n); + AString old_filename = STRPRINTF("%s.%d"_fmt, filename, n); while (--n) { - AString newer_filename = STRPRINTF("%s.%d", filename, n); + AString newer_filename = STRPRINTF("%s.%d"_fmt, filename, n); rename(newer_filename.c_str(), old_filename.c_str()); old_filename = std::move(newer_filename); } rename(filename.c_str(), old_filename.c_str()); - AString tmpfile = STRPRINTF("%s_%d.tmp", filename, tmp_suffix); + AString tmpfile = STRPRINTF("%s_%d.tmp"_fmt, filename, tmp_suffix); rename(tmpfile.c_str(), filename.c_str()); } } // namespace io diff --git a/src/io/read.cpp b/src/io/read.cpp index 2ef35cc..61a6256 100644 --- a/src/io/read.cpp +++ b/src/io/read.cpp @@ -105,12 +105,12 @@ namespace io if (unhappy) { if (happy) - PRINTF("warning: file contains CR\n"); + PRINTF("warning: file contains CR\n"_fmt); else - PRINTF("warning: file contains bare CR\n"); + PRINTF("warning: file contains bare CR\n"_fmt); } else if (!happy && anything) - PRINTF("warning: file does not contain a trailing newline\n"); + PRINTF("warning: file does not contain a trailing newline\n"_fmt); line = AString(tmp); return anything; } diff --git a/src/io/read_test.cpp b/src/io/read_test.cpp index 87f95ba..398c01e 100644 --- a/src/io/read_test.cpp +++ b/src/io/read_test.cpp @@ -42,42 +42,42 @@ io::FD string_pipe(ZString sz) TEST(io, read1) { - io::ReadFile rf(string_pipe("Hello")); + io::ReadFile rf(string_pipe("Hello"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read2) { - io::ReadFile rf(string_pipe("Hello\n")); + io::ReadFile rf(string_pipe("Hello\n"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read3) { - io::ReadFile rf(string_pipe("Hello\r")); + io::ReadFile rf(string_pipe("Hello\r"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read4) { - io::ReadFile rf(string_pipe("Hello\r\n")); + io::ReadFile rf(string_pipe("Hello\r\n"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read5) { - io::ReadFile rf(string_pipe("Hello\n\r")); + io::ReadFile rf(string_pipe("Hello\n\r"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_TRUE(rf.getline(hi)); EXPECT_FALSE(hi); EXPECT_FALSE(rf.getline(hi)); diff --git a/src/io/write_test.cpp b/src/io/write_test.cpp index ae8eccd..5419501 100644 --- a/src/io/write_test.cpp +++ b/src/io/write_test.cpp @@ -65,7 +65,7 @@ public: if (rv == -1) { if (errno != EAGAIN) - return {"Error, read failed :("}; + return "Error, read failed :("_s; rv = 0; } if (rv == 0) @@ -81,11 +81,11 @@ TEST(io, write1) PipeWriter pw(false); io::WriteFile& wf = pw.wf; wf.really_put("Hello, ", 7); - EXPECT_EQ("", pw.slurp()); - wf.put_line("World!\n"); - EXPECT_EQ("", pw.slurp()); + EXPECT_EQ(""_s, pw.slurp()); + wf.put_line("World!\n"_s); + EXPECT_EQ(""_s, pw.slurp()); EXPECT_TRUE(wf.close()); - EXPECT_EQ("Hello, World!\n", pw.slurp()); + EXPECT_EQ("Hello, World!\n"_s, pw.slurp()); } TEST(io, write2) @@ -93,10 +93,10 @@ TEST(io, write2) PipeWriter pw(true); io::WriteFile& wf = pw.wf; wf.really_put("Hello, ", 7); - EXPECT_EQ("", pw.slurp()); - wf.put_line("World!"); + EXPECT_EQ(""_s, pw.slurp()); + wf.put_line("World!"_s); wf.really_put("XXX", 3); - EXPECT_EQ("Hello, World!\n", pw.slurp()); + EXPECT_EQ("Hello, World!\n"_s, pw.slurp()); EXPECT_TRUE(wf.close()); - EXPECT_EQ("XXX", pw.slurp()); + EXPECT_EQ("XXX"_s, pw.slurp()); } diff --git a/src/login/login.cpp b/src/login/login.cpp index a60b34e..f8be4ce 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -114,13 +114,13 @@ static ServerName main_server; static -AString account_filename = "save/account.txt"; +AString account_filename = "save/account.txt"_s; static -AString gm_account_filename = "save/gm_account.txt"; +AString gm_account_filename = "save/gm_account.txt"_s; static -AString login_log_filename = "log/login.log"; +AString login_log_filename = "log/login.log"_s; static -AString login_log_unknown_packets_filename = "log/login_unknown_packets.log"; +AString login_log_unknown_packets_filename = "log/login_unknown_packets.log"_s; static int save_unknown_packets = 0; static @@ -175,7 +175,7 @@ int check_ip_flag = 1; // It's to check IP of a player between login-ser #pragma GCC diagnostic ignored "-Wmissing-noreturn" void SessionDeleter::operator()(SessionData *) { - assert(false && "login server does not have sessions anymore"); + assert(false && "login server does not have sessions anymore"_s); } #pragma GCC diagnostic pop @@ -269,8 +269,8 @@ void delete_fromchar(Session *sess) assert (it != server_session.end()); int id = it - server_session.begin(); IP4Address ip = sess->client_ip; - PRINTF("Char-server '%s' has disconnected.\n", server[id].name); - LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n", + PRINTF("Char-server '%s' has disconnected.\n"_fmt, server[id].name); + LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n"_fmt, server[id].name, ip); server_session[id] = nullptr; server[id] = mmo_char_server{}; @@ -279,7 +279,7 @@ void delete_fromchar(Session *sess) static void delete_admin(Session *s) { - PRINTF("Remote administration has disconnected (session #%d).\n", + PRINTF("Remote administration has disconnected (session #%d).\n"_fmt, s); } @@ -313,12 +313,12 @@ int read_gm_account(void) io::ReadFile fp(gm_account_filename); if (!fp.is_open()) { - PRINTF("read_gm_account: GM accounts file [%s] not found.\n", + PRINTF("read_gm_account: GM accounts file [%s] not found.\n"_fmt, gm_account_filename); - PRINTF(" Actually, there is no GM accounts on the server.\n"); - LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n", + PRINTF(" Actually, there is no GM accounts on the server.\n"_fmt); + LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n"_fmt, gm_account_filename); - LOGIN_LOG(" Actually, there is no GM accounts on the server.\n"); + LOGIN_LOG(" Actually, there is no GM accounts on the server.\n"_fmt); return 1; } // limited to 4000, because we send information to char-servers (more than 4000 GM accounts???) @@ -330,48 +330,47 @@ int read_gm_account(void) continue; GM_Account p {}; if (!extract(line, record<' '>(&p.account_id, &p.level))) - PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format: '%s'\n", + PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format: '%s'\n"_fmt, gm_account_filename, line); else if (p.level <= 0) - PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n", + PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n"_fmt, gm_account_filename, c + 1, p.level); else { if (p.level > 99) { - PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n", + PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n"_fmt, gm_account_filename, c + 1, p.level); p.level = 99; } if ((GM_level = isGM(p.account_id)) > 0) { // if it's not a new account if (GM_level == p.level) - PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n", + PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n"_fmt, p.account_id, p.level); else - PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n", + PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n"_fmt, p.account_id, GM_level, p.level); } if (GM_level != p.level) { // if new account or new level gm_account_db.insert(p.account_id, p); - //PRINTF("GM account:%d, level: %d->%d\n", p.account_id, GM_level, p.level); if (GM_level == 0) { // if new account c++; if (c >= 4000) { - PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"); - LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"); + PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"_fmt); + LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"_fmt); } } } } } - PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n", + PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n"_fmt, gm_account_filename, c); - LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n", + LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n"_fmt, gm_account_filename, c); return 0; @@ -484,7 +483,7 @@ AString mmo_auth_tostr(const AuthData *p) "%lld\t" "%s\t" "%s\t" - "%lld\t", + "%lld\t"_fmt, p->account_id, p->userid, p->pass, @@ -502,7 +501,7 @@ AString mmo_auth_tostr(const AuthData *p) assert (p->account_reg2_num < ACCOUNT_REG2_NUM); for (int i = 0; i < p->account_reg2_num; i++) if (p->account_reg2[i].str) - str += STRPRINTF("%s,%d ", + str += STRPRINTF("%s,%d "_fmt, p->account_reg2[i].str, p->account_reg2[i].value); return AString(str); @@ -532,7 +531,7 @@ bool extract(XString line, AuthData *ad) vrec<' '>(&vars)))) return false; ad->last_ip = IP4Address(); - if (ip != "-" && !extract(ip, &ad->last_ip)) + if (ip != "-"_s && !extract(ip, &ad->last_ip)) return false; if (ad->account_id > END_ACCOUNT_NUM) return false; @@ -571,7 +570,7 @@ bool extract(XString line, AuthData *ad) if (!ad->error_message || ad->state != 7) // 7, because state is packet 0x006a value + 1 - ad->error_message = stringish<timestamp_seconds_buffer>("-"); + ad->error_message = stringish<timestamp_seconds_buffer>("-"_s); if (vars.size() > ACCOUNT_REG2_NUM) return false; @@ -594,7 +593,7 @@ int mmo_auth_init(void) { // no account file -> no account -> no login, including char-server (ERROR) // not anymore! :-) - PRINTF(SGR_BOLD SGR_RED "mmo_auth_init: Accounts file [%s] not found." SGR_RESET "\n", + PRINTF(SGR_BOLD SGR_RED "mmo_auth_init: Accounts file [%s] not found." SGR_RESET "\n"_fmt, account_filename); return 0; } @@ -613,11 +612,11 @@ int mmo_auth_init(void) if (!extract(line, &ad)) { int i = 0; - if (SSCANF(line, "%d\t%%newid%%\n%n", &ad.account_id, &i) == 1 + if (SSCANF(line, "%d\t%%newid%%\n%n"_fmt, &ad.account_id, &i) == 1 && i > 0 && ad.account_id > account_id_count) account_id_count = ad.account_id; else - LOGIN_LOG("Account skipped\n%s", line); + LOGIN_LOG("Account skipped\n%s"_fmt, line); continue; } @@ -630,10 +629,10 @@ int mmo_auth_init(void) account_id_count = ad.account_id + 1; } - AString str = STRPRINTF("%s has %zu accounts (%d GMs)\n", + AString str = STRPRINTF("%s has %zu accounts (%d GMs)\n"_fmt, account_filename, auth_data.size(), gm_count); - PRINTF("%s: %s\n", __PRETTY_FUNCTION__, str); - LOGIN_LOG("%s\n", line); + PRINTF("%s: %s\n"_fmt, __PRETTY_FUNCTION__, str); + LOGIN_LOG("%s\n"_fmt, line); return 0; } @@ -648,30 +647,30 @@ void mmo_auth_sync(void) if (!fp.is_open()) { - PRINTF("uh-oh - unable to save accounts\n"); + PRINTF("uh-oh - unable to save accounts\n"_fmt); return; } FPRINTF(fp, - "// Accounts file: here are saved all information about the accounts.\n"); + "// Accounts file: here are saved all information about the accounts.\n"_fmt); FPRINTF(fp, - "// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n"); - FPRINTF(fp, "// Some explanations:\n"); + "// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n"_fmt); + FPRINTF(fp, "// Some explanations:\n"_fmt); FPRINTF(fp, - "// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n"); - FPRINTF(fp, "// account password: between 4 to 23 char\n"); + "// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n"_fmt); + FPRINTF(fp, "// account password: between 4 to 23 char\n"_fmt); FPRINTF(fp, - "// sex : M or F for normal accounts, S for server accounts\n"); + "// sex : M or F for normal accounts, S for server accounts\n"_fmt); FPRINTF(fp, - "// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n"); + "// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n"_fmt); FPRINTF(fp, - "// email : between 3 to 39 char (a@a.com is like no email)\n"); + "// email : between 3 to 39 char (a@a.com is like no email)\n"_fmt); FPRINTF(fp, - "// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n"); + "// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n"_fmt); FPRINTF(fp, - "// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"); - FPRINTF(fp, "// memo field : max 254 char\n"); + "// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"_fmt); + FPRINTF(fp, "// memo field : max 254 char\n"_fmt); FPRINTF(fp, - "// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"); + "// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"_fmt); for (const AuthData& ad : auth_data) { if (ad.account_id < 0) @@ -680,7 +679,7 @@ void mmo_auth_sync(void) AString line = mmo_auth_tostr(&ad); fp.put_line(line); } - FPRINTF(fp, "%d\t%%newid%%\n", account_id_count); + FPRINTF(fp, "%d\t%%newid%%\n"_fmt, account_id_count); } // We want to sync the DB to disk as little as possible as it's fairly @@ -795,7 +794,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) ad.userid = account->userid; ad.pass = MD5_saltcrypt(account->passwd, make_salt()); - ad.lastlogin = stringish<timestamp_milliseconds_buffer>("-"); + ad.lastlogin = stringish<timestamp_milliseconds_buffer>("-"_s); ad.sex = sex; ad.logincount = 0; ad.state = 0; @@ -805,7 +804,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) else ad.email = email; - ad.error_message = stringish<timestamp_seconds_buffer>("-"); + ad.error_message = stringish<timestamp_seconds_buffer>("-"_s); ad.ban_until_time = TimeT(); if (start_limited_time < 0) @@ -820,7 +819,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) } ad.last_ip = IP4Address(); - ad.memo = "!"; + ad.memo = "!"_s; ad.account_reg2_num = 0; auth_data.push_back(ad); @@ -839,7 +838,7 @@ int mmo_auth(struct mmo_account *account, Session *s) // Account creation with _M/_F if (account->passwdenc == 0 - && (account->userid.endswith("_F") || account->userid.endswith("_M")) + && (account->userid.endswith("_F"_s) || account->userid.endswith("_M"_s)) && new_account == 1 && account_id_count <= END_ACCOUNT_NUM && (account->userid.size() - 2) >= 4 && account->passwd.size() >= 4) { @@ -855,14 +854,14 @@ int mmo_auth(struct mmo_account *account, Session *s) int encpasswdok = 0; if (new_account_sex) { - LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n", + LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n"_fmt, account->userid, new_account_sex, ip); return 9; // 9 = Account already exists } if ((!pass_ok(account->passwd, ad->pass)) && !encpasswdok) { if (account->passwdenc == 0) - LOGIN_LOG("Invalid password (account: %s, ip: %s)\n", + LOGIN_LOG("Invalid password (account: %s, ip: %s)\n"_fmt, account->userid, ip); return 1; // 1 = Incorrect Password @@ -870,7 +869,7 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->state) { - LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n"_fmt, account->userid, ad->state, ip); switch (ad->state) @@ -899,14 +898,14 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->ban_until_time > TimeT::now()) { // always banned - LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n"_fmt, account->userid, tmpstr, ip); return 6; // 6 = Your are Prohibited to log in until %s } else { // ban is finished - LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n", + LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n"_fmt, account->userid, tmpstr, ip); ad->ban_until_time = TimeT(); // reset the ban time } @@ -915,26 +914,26 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->connect_until_time && ad->connect_until_time < TimeT::now()) { - LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n"_fmt, account->userid, ip); return 2; // 2 = This ID is expired } - LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n", + LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n"_fmt, account->userid, ad->account_id, ip); } else { if (new_account_sex == '\0') { - LOGIN_LOG("Unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("Unknown account (account: %s, ip: %s)\n"_fmt, account->userid, ip); return 0; // 0 = Unregistered ID } else { int new_id = mmo_auth_new(account, sex_from_char(new_account_sex), DEFAULT_EMAIL); - LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n", + LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n"_fmt, account->userid, new_id, new_account_sex, ip); ad = &auth_data.back(); @@ -964,17 +963,15 @@ void char_anti_freeze_system(TimerData *, tick_t) { int i; - //PRINTF("Entering in char_anti_freeze_system function to check freeze of servers.\n"); for (i = 0; i < MAX_SERVERS; i++) { if (server_session[i]) { // if char-server is online - //PRINTF("char_anti_freeze_system: server #%d '%s', flag: %d.\n", i, server[i].name, server_freezeflag[i]); if (server_freezeflag[i]-- < 1) { // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed - PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n", + PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n"_fmt, i, server[i].name); - LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n", + LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n"_fmt, i, server[i].name); server_session[i]->set_eof(); } @@ -1003,14 +1000,14 @@ void parse_fromchar(Session *s) while (RFIFOREST(s) >= 2) { if (display_parse_fromchar == 2 || (display_parse_fromchar == 1 && RFIFOW(s, 0) != 0x2714)) // 0x2714 is done very often (number of players) - PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %zu bytes).\n", + PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %zu bytes).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); switch (RFIFOW(s, 0)) { // request from map-server via char-server to reload GM accounts (by Yor). case 0x2709: - LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n", + LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n"_fmt, server[id].name, ip); read_gm_account(); // send GM accounts to all char-servers @@ -1036,7 +1033,7 @@ void parse_fromchar(Session *s) { int p; auth_fifo[i].delflag = 1; - LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n", + LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n"_fmt, server[id].name, acc, ip); for (const AuthData& ad : auth_data) { @@ -1054,7 +1051,6 @@ void parse_fromchar(Session *s) } WFIFOW(s, 2) = p; WFIFOSET(s, p); -// PRINTF("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n"); WFIFOW(s, 0) = 0x2713; WFIFOL(s, 2) = acc; WFIFOB(s, 6) = 0; @@ -1070,7 +1066,7 @@ void parse_fromchar(Session *s) // authentification not found if (i == AUTH_FIFO_SIZE) { - LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n", + LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n"_fmt, server[id].name, acc, ip); WFIFOW(s, 0) = 0x2713; WFIFOL(s, 2) = acc; @@ -1086,7 +1082,6 @@ void parse_fromchar(Session *s) case 0x2714: if (RFIFOREST(s) < 6) return; - //PRINTF("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2)); server[id].users = RFIFOL(s, 2); if (anti_freeze_enable) server_freezeflag[id] = 5; // Char anti-freeze system. Counter. 5 ok, 4...0 freezed @@ -1101,7 +1096,7 @@ void parse_fromchar(Session *s) int acc = RFIFOL(s, 2); AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 6)); if (!e_mail_check(email)) - LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else { @@ -1111,12 +1106,12 @@ void parse_fromchar(Session *s) && (ad.email == DEFAULT_EMAIL || !ad.email)) { ad.email = email; - LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, email, ip); goto x2715_out; } } - LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } x2715_out: @@ -1130,12 +1125,11 @@ void parse_fromchar(Session *s) return; { int account_id = RFIFOL(s, 2); - //PRINTF("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2)); for (const AuthData& ad : auth_data) { if (ad.account_id == account_id) { - LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n", + LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n"_fmt, server[id].name, account_id, ip); WFIFOW(s, 0) = 0x2717; WFIFOL(s, 2) = account_id; @@ -1145,7 +1139,7 @@ void parse_fromchar(Session *s) goto x2716_end; } } - LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n", + LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n"_fmt, server[id].name, account_id, ip); } x2716_end: @@ -1159,7 +1153,6 @@ void parse_fromchar(Session *s) int acc; unsigned char buf[10]; acc = RFIFOL(s, 4); - //PRINTF("parse_fromchar: Request to become a GM acount from %d account.\n", acc); WBUFW(buf, 0) = 0x2721; WBUFL(buf, 2) = acc; WBUFL(buf, 6) = 0; @@ -1181,51 +1174,51 @@ void parse_fromchar(Session *s) timestamp_seconds_buffer tmpstr; stamp_time(tmpstr); FPRINTF(fp, - "\n// %s: @GM command on account %d\n%d %d\n", + "\n// %s: @GM command on account %d\n%d %d\n"_fmt, tmpstr, acc, acc, level_new_gm); if (!fp.close()) { - PRINTF("warning: didn't actually save GM file\n"); + PRINTF("warning: didn't actually save GM file\n"_fmt); } WBUFL(buf, 6) = level_new_gm; read_gm_account(); send_GM_accounts(); - PRINTF("GM Change of the account %d: level 0 -> %d.\n", + PRINTF("GM Change of the account %d: level 0 -> %d.\n"_fmt, acc, level_new_gm); - LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n", + LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n"_fmt, server[id].name, acc, level_new_gm, ip); } else { - PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n", + PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n", + PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n", + PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d, invalid password).\n", + PRINTF("Error of GM change (suggested account: %d, invalid password).\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n"_fmt, server[id].name, acc, ip); } charif_sendallwos(nullptr, buf, 10); @@ -1242,13 +1235,13 @@ void parse_fromchar(Session *s) AccountEmail actual_email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 6).to_print()); AccountEmail new_email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 46)); if (!e_mail_check(actual_email)) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else if (!e_mail_check(new_email)) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else if (new_email == DEFAULT_EMAIL) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else { @@ -1259,19 +1252,19 @@ void parse_fromchar(Session *s) if (ad.email == actual_email) { ad.email = new_email; - LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, ad.userid, new_email, ip); } else - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, ad.userid, ad.email, actual_email, ip); goto x2722_out; } } - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } } @@ -1293,7 +1286,7 @@ void parse_fromchar(Session *s) { if (ad.state != statut) { - LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); if (statut != 0) @@ -1311,13 +1304,13 @@ void parse_fromchar(Session *s) ad.state = statut; } else - LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); goto x2724_out; } } - LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); x2724_out: RFIFOSKIP(s, 10); @@ -1363,7 +1356,7 @@ void parse_fromchar(Session *s) timestamp_seconds_buffer tmpstr; if (timestamp) stamp_time(tmpstr, ×tamp); - LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %lld (%s), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %lld (%s), ip: %s).\n"_fmt, server[id].name, acc, timestamp, tmpstr, @@ -1380,7 +1373,7 @@ void parse_fromchar(Session *s) } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n"_fmt, server[id].name, acc, ip); } @@ -1388,19 +1381,19 @@ void parse_fromchar(Session *s) } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n"_fmt, server[id].name, acc, ip); } goto x2725_out; } } - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); x2725_out: RFIFOSKIP(s, 18); @@ -1424,7 +1417,7 @@ void parse_fromchar(Session *s) sex = SEX::MALE; else sex = SEX::FEMALE; - LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n"_fmt, server[id].name, acc, sex_to_char(sex), ip); @@ -1440,7 +1433,7 @@ void parse_fromchar(Session *s) goto x2727_out; } } - LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n"_fmt, server[id].name, acc, ip); x2727_out: RFIFOSKIP(s, 6); @@ -1457,7 +1450,7 @@ void parse_fromchar(Session *s) { if (ad.account_id == acc) { - LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); size_t len = RFIFOW(s, 2); int j; @@ -1474,11 +1467,10 @@ void parse_fromchar(Session *s) RFIFO_BUF_CLONE(s, buf, len); WBUFW(buf, 0) = 0x2729; charif_sendallwos(s, buf, WBUFW(buf, 2)); -// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc); goto x2728_out; } } - LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); } x2728_out: @@ -1497,18 +1489,18 @@ void parse_fromchar(Session *s) if (ad.ban_until_time) { ad.ban_until_time = TimeT(); - LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } else { - LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n"_fmt, server[id].name, acc, ip); } goto x272a_out; } } - LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); x272a_out: RFIFOSKIP(s, 6); @@ -1538,7 +1530,7 @@ void parse_fromchar(Session *s) { status = 1; ad.pass = MD5_saltcrypt(new_pass, make_salt()); - LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n", + LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n"_fmt, server[id].name, acc, ad.userid, ip); } @@ -1546,7 +1538,7 @@ void parse_fromchar(Session *s) else { status = 2; - LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n"_fmt, server[id].name, acc, ad.userid, ip); } @@ -1571,30 +1563,30 @@ void parse_fromchar(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; int i; for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB(s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB(s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -1602,19 +1594,19 @@ void parse_fromchar(Session *s) { for (int j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n", + PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n"_fmt, RFIFOW(s, 0)); s->set_eof(); - PRINTF("Char-server has been disconnected (unknown packet).\n"); + PRINTF("Char-server has been disconnected (unknown packet).\n"_fmt); return; } } @@ -1632,13 +1624,13 @@ void parse_admin(Session *s) while (RFIFOREST(s) >= 2) { if (display_parse_admin == 1) - PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %zu).\n", + PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %zu).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); switch (RFIFOW(s, 0)) { case 0x7530: // Request of the server version - LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n", + LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n"_fmt, ip); WFIFOW(s, 0) = 0x7531; WFIFO_STRUCT(s, 2, CURRENT_LOGIN_SERVER_VERSION); @@ -1647,7 +1639,7 @@ void parse_admin(Session *s) break; case 0x7532: // Request of end of connection - LOGIN_LOG("'ladmin': End of connection (ip: %s)\n", + LOGIN_LOG("'ladmin': End of connection (ip: %s)\n"_fmt, ip); RFIFOSKIP(s, 2); s->set_eof(); @@ -1666,7 +1658,7 @@ void parse_admin(Session *s) st = 0; if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0) ed = END_ACCOUNT_NUM; - LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n"_fmt, st, ed, ip); // Sending accounts information len = 4; @@ -1715,24 +1707,24 @@ void parse_admin(Session *s) struct mmo_account ma; ma.userid = stringish<AccountName>(RFIFO_STRING<24>(s, 2).to_print()); ma.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 26).to_print()); - ma.lastlogin = stringish<timestamp_milliseconds_buffer>("-"); + ma.lastlogin = stringish<timestamp_milliseconds_buffer>("-"_s); ma.sex = sex_from_char(RFIFOB(s, 50)); WFIFOW(s, 0) = 0x7931; WFIFOL(s, 2) = -1; WFIFO_STRING(s, 6, ma.userid, 24); if (ma.userid.size() < 4 || ma.passwd.size() < 4) { - LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n"_fmt, ip); } else if (ma.sex != SEX::FEMALE && ma.sex != SEX::MALE) { - LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n"_fmt, ma.userid, ip); } else if (account_id_count > END_ACCOUNT_NUM) { - LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n"_fmt, ma.userid, ma.sex, ip); } else @@ -1741,7 +1733,7 @@ void parse_admin(Session *s) { if (ad.userid == ma.userid) { - LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n"_fmt, ad.userid, ip); goto x7930_out; } @@ -1749,7 +1741,7 @@ void parse_admin(Session *s) { AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 51)); int new_id = mmo_auth_new(&ma, ma.sex, email); - LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n"_fmt, ma.userid, new_id, ma.sex, auth_data.back().email, ip); WFIFOL(s, 2) = new_id; @@ -1780,12 +1772,12 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; // save deleted account in log file - LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n", + LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n"_fmt, ad->userid, ad->account_id, ip); { AString buf2 = mmo_auth_tostr(ad); - LOGIN_LOG("%s\n", buf2); + LOGIN_LOG("%s\n"_fmt, buf2); } // delete account ad->userid = AccountName(); @@ -1794,7 +1786,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1816,13 +1808,13 @@ void parse_admin(Session *s) AccountPass plain = stringish<AccountPass>(RFIFO_STRING<24>(s, 26)); ad->pass = MD5_saltcrypt(plain, make_salt()); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n"_fmt, ad->userid, ad->pass, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1842,7 +1834,7 @@ void parse_admin(Session *s) if (statut != 7 || !error_message) { // 7: // 6 = Your are Prohibited to log in until %s - error_message = stringish<timestamp_seconds_buffer>("-"); + error_message = stringish<timestamp_seconds_buffer>("-"_s); } AuthData *ad = search_account(account_name); if (ad) @@ -1851,16 +1843,16 @@ void parse_admin(Session *s) WFIFOL(s, 2) = ad->account_id; if (ad->state == statut && ad->error_message == error_message) - LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n"_fmt, account_name, statut, ip); else { if (statut == 7) - LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n"_fmt, ad->userid, statut, error_message, ip); else - LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n"_fmt, ad->userid, statut, ip); if (ad->state == 0) { @@ -1882,7 +1874,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n"_fmt, account_name, statut, ip); } WFIFOL(s, 30) = statut; @@ -1892,7 +1884,7 @@ void parse_admin(Session *s) break; case 0x7938: // Request for servers list and # of online players - LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n", ip); + LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n"_fmt, ip); server_num = 0; for (int i = 0; i < MAX_SERVERS; i++) { @@ -1928,20 +1920,20 @@ void parse_admin(Session *s) if (pass_ok(pass, ad->pass)) { WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n"_fmt, ad->userid, ad->pass, ip); } else { - LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n"_fmt, ad->userid, pass.to_print(), ip); } } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1961,7 +1953,7 @@ void parse_admin(Session *s) SEX sex = sex_from_char(RFIFOB(s, 26)); if (sex != SEX::FEMALE && sex != SEX::MALE) { - LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n"_fmt, account_name, sex_to_char(sex), ip); } else @@ -1979,7 +1971,7 @@ void parse_admin(Session *s) ad->account_id) auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification) ad->sex = sex; - LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n"_fmt, ad->userid, sex_to_char(sex), ip); // send to all char-server the change WBUFW(buf, 0) = 0x2723; @@ -1989,13 +1981,13 @@ void parse_admin(Session *s) } else { - LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n"_fmt, ad->userid, sex_to_char(sex), ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n"_fmt, account_name, sex_to_char(sex), ip); } } @@ -2019,7 +2011,7 @@ void parse_admin(Session *s) new_gm_level = RFIFOB(s, 26); if (new_gm_level < 0 || new_gm_level > 99) { - LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n"_fmt, account_name, new_gm_level, ip); } else @@ -2058,7 +2050,7 @@ void parse_admin(Session *s) else if (new_gm_level == 0) { FPRINTF(fp2, - "// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n", + "// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n"_fmt, tmpstr, acc, ad->userid, @@ -2069,7 +2061,7 @@ void parse_admin(Session *s) else { FPRINTF(fp2, - "// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n", + "// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n"_fmt, tmpstr, acc, ad->userid, @@ -2081,40 +2073,40 @@ void parse_admin(Session *s) } if (modify_flag == 0) FPRINTF(fp2, - "// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n", + "// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n"_fmt, tmpstr, acc, ad->userid, acc, new_gm_level); } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } WFIFOL(s, 2) = acc; - LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); reread = true; } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n"_fmt, account_name, new_gm_level, ip); } @@ -2143,7 +2135,7 @@ void parse_admin(Session *s) AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 26)); if (!e_mail_check(email)) { - LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n"_fmt, account_name, ip); } else @@ -2154,12 +2146,12 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); ad->email = email; WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n"_fmt, ad->userid, email, ip); } else { - LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n"_fmt, account_name, email, ip); } } @@ -2181,10 +2173,10 @@ void parse_admin(Session *s) if (ad) { WFIFO_STRING(s, 6, ad->userid, 24); - ad->memo = ""; + ad->memo = ""_s; if (RFIFOW(s, 26) == 0) { - ad->memo = "!"; + ad->memo = "!"_s; } else { @@ -2194,13 +2186,13 @@ void parse_admin(Session *s) } ad->memo = ad->memo.to_print(); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n"_fmt, ad->userid, ad->memo, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -2220,14 +2212,14 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n"_fmt, ad->userid, ad->account_id, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -2248,14 +2240,14 @@ void parse_admin(Session *s) if (ad.account_id == account_id) { WFIFO_STRING(s, 6, ad.userid, 24); - LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n"_fmt, ad.userid, account_id, ip); goto x7946_out; } } - LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n"_fmt, account_id, ip); - WFIFO_STRING(s, 6, "", 24); + WFIFO_STRING(s, 6, ""_s, 24); x7946_out: WFIFOSET(s, 30); } @@ -2270,14 +2262,14 @@ void parse_admin(Session *s) WFIFOL(s, 2) = -1; AccountName account_name = stringish<AccountName>(RFIFO_STRING<24>(s, 2).to_print()); TimeT timestamp = static_cast<time_t>(RFIFOL(s, 26)); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); if (timestamp) stamp_time(tmpstr, ×tamp); AuthData *ad = search_account(account_name); if (ad) { WFIFO_STRING(s, 6, ad->userid, 24); - LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, timestamp, tmpstr, @@ -2288,7 +2280,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n"_fmt, account_name, timestamp, tmpstr, @@ -2310,7 +2302,7 @@ void parse_admin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 26)); if (timestamp <= TimeT::now()) timestamp = TimeT(); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (timestamp) stamp_time(tmpstr, ×tamp); AuthData *ad = search_account(account_name); @@ -2318,7 +2310,7 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n"_fmt, ad->userid, timestamp, tmpstr, ip); @@ -2343,7 +2335,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n"_fmt, account_name, timestamp, tmpstr, ip); @@ -2387,10 +2379,10 @@ void parse_admin(Session *s) { if (timestamp <= now) timestamp = TimeT(); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (timestamp) stamp_time(tmpstr, ×tamp); - LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, ban_diff.year, ban_diff.month, ban_diff.day, ban_diff.hour, @@ -2418,10 +2410,10 @@ void parse_admin(Session *s) } else { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (ad->ban_until_time) stamp_time(tmpstr, &ad->ban_until_time); - LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", + LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n"_fmt, ad->userid, ad->ban_until_time, tmpstr, @@ -2435,7 +2427,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOL(s, 30) = 0; } @@ -2452,7 +2444,7 @@ void parse_admin(Session *s) WFIFOW(s, 2) = -1; if (RFIFOL(s, 4) < 1) { - LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n"_fmt, ip); } else @@ -2461,7 +2453,7 @@ void parse_admin(Session *s) for (int i = 0; i < MAX_SERVERS; i++) if (server_session[i]) goto x794e_have_server; - LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n"_fmt, ip); goto x794e_have_no_server; { @@ -2471,7 +2463,7 @@ void parse_admin(Session *s) size_t len = RFIFOL(s, 4); AString message = RFIFO_STRING(s, 8, len).to_print(); - LOGIN_LOG("'ladmin': Receiving a message for broadcast (message: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast (message: %s, ip: %s)\n"_fmt, message, ip); // send same message to all char-servers (no answer) uint8_t buf[len + 8]; @@ -2499,7 +2491,7 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); if (add_to_unlimited_account == 0 && !ad->connect_until_time) { - LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n"_fmt, ad->userid, ip); WFIFOL(s, 30) = 0; } @@ -2521,13 +2513,13 @@ void parse_admin(Session *s) timestamp = tmtime; if (timestamp.okay()) { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); - timestamp_seconds_buffer tmpstr2 = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); + timestamp_seconds_buffer tmpstr2 = stringish<timestamp_seconds_buffer>("unlimited"_s); if (ad->connect_until_time) stamp_time(tmpstr, &ad->connect_until_time); if (timestamp) stamp_time(tmpstr2, ×tamp); - LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, ad->connect_until_time, tmpstr, @@ -2545,10 +2537,10 @@ void parse_admin(Session *s) } else { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); if (ad->connect_until_time) stamp_time(tmpstr, &ad->connect_until_time); - LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", + LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n"_fmt, ad->userid, ad->connect_until_time, tmpstr, @@ -2566,7 +2558,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOL(s, 30) = 0; } @@ -2600,7 +2592,7 @@ void parse_admin(Session *s) size_t len = ad->memo.size() + 1; WFIFOW(s, 148) = len; WFIFO_STRING(s, 150, ad->memo, len); - LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n"_fmt, ad->userid, ad->account_id, ip); WFIFOSET(s, 150 + len); @@ -2609,7 +2601,7 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 7, account_name, 24); WFIFOW(s, 148) = 0; - LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOSET(s, 150); } @@ -2629,7 +2621,7 @@ void parse_admin(Session *s) { if (ad.account_id == account_id) { - LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n"_fmt, ad.userid, RFIFOL(s, 2), ip); WFIFOB(s, 6) = isGM(ad.account_id); WFIFO_STRING(s, 7, ad.userid, 24); @@ -2650,9 +2642,9 @@ void parse_admin(Session *s) } } { - LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n"_fmt, RFIFOL(s, 2), ip); - WFIFO_STRING(s, 7, "", 24); + WFIFO_STRING(s, 7, ""_s, 24); WFIFOW(s, 148) = 0; WFIFOSET(s, 150); } @@ -2662,7 +2654,7 @@ void parse_admin(Session *s) break; case 0x7955: // Request to reload GM file (no answer) - LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n", + LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n"_fmt, ip); read_gm_account(); // send GM accounts to all char-servers @@ -2678,30 +2670,30 @@ void parse_admin(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; int i; for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB (s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB (s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -2709,19 +2701,19 @@ void parse_admin(Session *s) { for (int j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n", + LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n"_fmt, ip); s->set_eof(); - PRINTF("Remote administration has been disconnected (unknown packet).\n"); + PRINTF("Remote administration has been disconnected (unknown packet).\n"_fmt); return; } //WFIFOW(fd,0) = 0x791f; @@ -2738,7 +2730,7 @@ bool lan_ip_check(IP4Address p) { bool lancheck = lan_subnet.covers(p); - PRINTF("LAN test (result): %s.\n", + PRINTF("LAN test (result): %s.\n"_fmt, (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET); return lancheck; } @@ -2763,7 +2755,7 @@ void parse_login(Session *s) if (RFIFOREST(s) >= ((RFIFOW(s, 0) == 0x64) ? 55 : 47)) { AccountName account_name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), account: %s.\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), account: %s.\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s), account_name); } @@ -2773,13 +2765,13 @@ void parse_login(Session *s) if (RFIFOREST(s) >= 86) { ServerName server_name = stringish<ServerName>(RFIFO_STRING<20>(s, 60)); - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), server: %s.\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), server: %s.\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s), server_name); } } else - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu).\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); } @@ -2805,12 +2797,12 @@ void parse_login(Session *s) account.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 30).to_print()); account.passwdenc = 0; - LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n", + LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n"_fmt, account.userid, ip); if (!check_ip(ip)) { - LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n", + LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n"_fmt, ip); WFIFOW(s, 0) = 0x6a; WFIFOB(s, 2) = 0x03; @@ -2833,7 +2825,7 @@ void parse_login(Session *s) int gm_level = isGM(account.account_id); if (min_level_to_connect > gm_level) { - LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n", + LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n"_fmt, min_level_to_connect, account.userid, gm_level, ip); WFIFOW(s, 0) = 0x81; @@ -2845,10 +2837,10 @@ void parse_login(Session *s) // int version_2 = RFIFOB(fd, 54); // version 2 if (gm_level) - PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n", + PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n"_fmt, gm_level, account.userid); else - PRINTF("Connection of the account '%s' accepted.\n", + PRINTF("Connection of the account '%s' accepted.\n"_fmt, account.userid); /* @@ -2922,7 +2914,7 @@ void parse_login(Session *s) } else { - LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n", + LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n"_fmt, account.userid, ip); WFIFOW(s, 0) = 0x81; WFIFOB(s, 2) = 1; // 01 = Server closed @@ -2968,7 +2960,7 @@ void parse_login(Session *s) account.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 26).to_print()); account.passwdenc = 0; ServerName server_name = stringish<ServerName>(RFIFO_STRING<20>(s, 60).to_print()); - LOGIN_LOG("Connection request of the char-server '%s' @ %s:%d (ip: %s)\n", + LOGIN_LOG("Connection request of the char-server '%s' @ %s:%d (ip: %s)\n"_fmt, server_name, RFIFOIP(s, 54), RFIFOW(s, 58), ip); if (account.userid == userid && account.passwd == passwd) { @@ -2996,10 +2988,10 @@ void parse_login(Session *s) { x2710_okay: - LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n", + LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n"_fmt, server_name, account.userid, account.passwd, ip); - PRINTF("Connection of the char-server '%s' accepted.\n", + PRINTF("Connection of the char-server '%s' accepted.\n"_fmt, server_name); server[account.account_id] = mmo_char_server{}; server[account.account_id].ip = RFIFOIP(s, 54); @@ -3033,7 +3025,7 @@ void parse_login(Session *s) } { x2710_refused: - LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n", + LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n"_fmt, server_name, account.userid, account.passwd, ip); WFIFOW(s, 0) = 0x2711; @@ -3046,7 +3038,7 @@ void parse_login(Session *s) return; case 0x7530: // Request of the server version - LOGIN_LOG("Sending of the server version (ip: %s)\n", + LOGIN_LOG("Sending of the server version (ip: %s)\n"_fmt, ip); WFIFOW(s, 0) = 0x7531; { @@ -3059,7 +3051,7 @@ void parse_login(Session *s) break; case 0x7532: // Request to end connection - LOGIN_LOG("End of connection (ip: %s)\n", ip); + LOGIN_LOG("End of connection (ip: %s)\n"_fmt, ip); s->set_eof(); return; @@ -3071,7 +3063,7 @@ void parse_login(Session *s) WFIFOB(s, 2) = 1; if (!check_ladminip(s->client_ip)) { - LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n"_fmt, ip); } else @@ -3084,24 +3076,24 @@ void parse_login(Session *s) if ((admin_state == 1) && (password == admin_pass)) { - LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); - PRINTF("Connection of a remote administration accepted (non encrypted password).\n"); + PRINTF("Connection of a remote administration accepted (non encrypted password).\n"_fmt); WFIFOB(s, 2) = 0; s->set_parsers(SessionParsers{func_parse: parse_admin, func_delete: delete_admin}); } else if (admin_state != 1) - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); else - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); } else { // encrypted password { - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - encrypted login is disabled (ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - encrypted login is disabled (ip: %s)\n"_fmt, ip); } } @@ -3119,15 +3111,15 @@ void parse_login(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; @@ -3135,17 +3127,17 @@ void parse_login(Session *s) for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB(s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB(s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -3153,16 +3145,16 @@ void parse_login(Session *s) { for (j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - LOGIN_LOG("End of connection, unknown packet (ip: %s)\n", ip); + LOGIN_LOG("End of connection, unknown packet (ip: %s)\n"_fmt, ip); s->set_eof(); return; } @@ -3179,7 +3171,7 @@ bool login_lan_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "lan_char_ip") + if (w1 == "lan_char_ip"_s) { // Read Char-Server Lan IP Address h = gethostbyname(w2.c_str()); @@ -3194,20 +3186,20 @@ bool login_lan_config(XString w1, ZString w2) } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } - PRINTF("LAN IP of char-server: %s.\n", lan_char_ip); + PRINTF("LAN IP of char-server: %s.\n"_fmt, lan_char_ip); } - else if (w1 == "subnet" /*backward compatibility*/ - || w1 == "lan_subnet") + else if (w1 == "subnet"_s /*backward compatibility*/ + || w1 == "lan_subnet"_s) { if (!extract(w2, &lan_subnet)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } - PRINTF("Sub-network of the char-server: %s.\n", + PRINTF("Sub-network of the char-server: %s.\n"_fmt, lan_subnet); } else @@ -3222,18 +3214,18 @@ static bool lan_check() { // log the LAN configuration - LOGIN_LOG("The LAN configuration of the server is set:\n"); - LOGIN_LOG("- with LAN IP of char-server: %s.\n", lan_char_ip); - LOGIN_LOG("- with the sub-network of the char-server: %s.\n", + LOGIN_LOG("The LAN configuration of the server is set:\n"_fmt); + LOGIN_LOG("- with LAN IP of char-server: %s.\n"_fmt, lan_char_ip); + LOGIN_LOG("- with the sub-network of the char-server: %s.\n"_fmt, lan_subnet); // sub-network check of the char-server { - PRINTF("LAN test of LAN IP of the char-server: "); + PRINTF("LAN test of LAN IP of the char-server: "_fmt); if (!lan_ip_check(lan_char_ip)) { - PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network" SGR_RESET "\n"); - LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n"); + PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network"_fmt SGR_RESET "\n"); + LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n"_fmt); return false; } } @@ -3248,24 +3240,24 @@ static bool login_config(XString w1, ZString w2) { { - if (w1 == "admin_state") + if (w1 == "admin_state"_s) { admin_state = config_switch(w2); } - else if (w1 == "admin_pass") + else if (w1 == "admin_pass"_s) { admin_pass = stringish<AccountPass>(w2); } - else if (w1 == "ladminallowip") + else if (w1 == "ladminallowip"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_ladmin.clear(); } else { // a.b.c.d/0.0.0.0 (canonically, 0.0.0.0/0) covers all - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_ladmin.clear(); @@ -3280,104 +3272,104 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_ladmin.push_back(n); } } } - else if (w1 == "gm_pass") + else if (w1 == "gm_pass"_s) { gm_pass = w2; } - else if (w1 == "level_new_gm") + else if (w1 == "level_new_gm"_s) { level_new_gm = atoi(w2.c_str()); } - else if (w1 == "new_account") + else if (w1 == "new_account"_s) { new_account = config_switch(w2); } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "account_filename") + else if (w1 == "account_filename"_s) { account_filename = w2; } - else if (w1 == "gm_account_filename") + else if (w1 == "gm_account_filename"_s) { gm_account_filename = w2; } - else if (w1 == "gm_account_filename_check_timer") + else if (w1 == "gm_account_filename_check_timer"_s) { gm_account_filename_check_timer = std::chrono::seconds(atoi(w2.c_str())); } - else if (w1 == "login_log_filename") + else if (w1 == "login_log_filename"_s) { login_log_filename = w2; } - else if (w1 == "login_log_unknown_packets_filename") + else if (w1 == "login_log_unknown_packets_filename"_s) { login_log_unknown_packets_filename = w2; } - else if (w1 == "save_unknown_packets") + else if (w1 == "save_unknown_packets"_s) { save_unknown_packets = config_switch(w2); } - else if (w1 == "display_parse_login") + else if (w1 == "display_parse_login"_s) { display_parse_login = config_switch(w2); // 0: no, 1: yes } - else if (w1 == "display_parse_admin") + else if (w1 == "display_parse_admin"_s) { display_parse_admin = config_switch(w2); // 0: no, 1: yes } - else if (w1 == "display_parse_fromchar") + else if (w1 == "display_parse_fromchar"_s) { display_parse_fromchar = config_switch(w2); // 0: no, 1: yes (without packet 0x2714), 2: all packets } - else if (w1 == "min_level_to_connect") + else if (w1 == "min_level_to_connect"_s) { min_level_to_connect = atoi(w2.c_str()); } - else if (w1 == "add_to_unlimited_account") + else if (w1 == "add_to_unlimited_account"_s) { add_to_unlimited_account = config_switch(w2); } - else if (w1 == "start_limited_time") + else if (w1 == "start_limited_time"_s) { start_limited_time = atoi(w2.c_str()); } - else if (w1 == "check_ip_flag") + else if (w1 == "check_ip_flag"_s) { check_ip_flag = config_switch(w2); } - else if (w1 == "order") + else if (w1 == "order"_s) { - if (w2 == "deny,allow" || w2 == "deny, allow") + if (w2 == "deny,allow"_s || w2 == "deny, allow"_s) access_order = ACO::DENY_ALLOW; - else if (w2 == "allow,deny" || w2 == "allow, deny") + else if (w2 == "allow,deny"_s || w2 == "allow, deny"_s) access_order = ACO::ALLOW_DENY; - else if (w2 == "mutual-failture" || w2 == "mutual-failure") + else if (w2 == "mutual-failture"_s || w2 == "mutual-failure"_s) access_order = ACO::MUTUAL_FAILURE; else { - PRINTF("Bad order: %s\n", w2); + PRINTF("Bad order: %s\n"_fmt, w2); return false; } } - else if (w1 == "allow") + else if (w1 == "allow"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_allow.clear(); } else { - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_allow.clear(); @@ -3392,22 +3384,22 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_allow.push_back(n); } } } - else if (w1 == "deny") + else if (w1 == "deny"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_deny.clear(); } else { - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_deny.clear(); @@ -3422,36 +3414,36 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_deny.push_back(n); } } } - else if (w1 == "anti_freeze_enable") + else if (w1 == "anti_freeze_enable"_s) { anti_freeze_enable = config_switch(w2); } - else if (w1 == "anti_freeze_interval") + else if (w1 == "anti_freeze_interval"_s) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), std::chrono::seconds(5)); } - else if (w1 == "update_host") + else if (w1 == "update_host"_s) { update_host = w2; } - else if (w1 == "main_server") + else if (w1 == "main_server"_s) { main_server = stringish<ServerName>(w2); } - else if (w1 == "userid") + else if (w1 == "userid"_s) { userid = stringish<AccountName>(w2); } - else if (w1 == "passwd") + else if (w1 == "passwd"_s) { passwd = stringish<AccountPass>(w2); } @@ -3473,7 +3465,7 @@ bool display_conf_warnings(void) bool rv = true; if (admin_state != 0 && admin_state != 1) { - PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n"); + PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n"_fmt); admin_state = 0; rv = false; } @@ -3482,132 +3474,132 @@ bool display_conf_warnings(void) { if (!admin_pass) { - PRINTF("***WARNING: Administrator password is void (admin_pass).\n"); + PRINTF("***WARNING: Administrator password is void (admin_pass).\n"_fmt); rv = false; } - else if (admin_pass == stringish<AccountPass>("admin")) + else if (admin_pass == stringish<AccountPass>("admin"_s)) { - PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n"); - PRINTF(" We highly recommend that you change it.\n"); + PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n"_fmt); + PRINTF(" We highly recommend that you change it.\n"_fmt); } } if (!gm_pass) { - PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n"); - PRINTF(" We highly recommend that you set one password.\n"); + PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n"_fmt); + PRINTF(" We highly recommend that you set one password.\n"_fmt); rv = false; } - else if (gm_pass == "gm") + else if (gm_pass == "gm"_s) { - PRINTF("***WARNING: You are using the default GM password (gm_pass).\n"); - PRINTF(" We highly recommend that you change it.\n"); + PRINTF("***WARNING: You are using the default GM password (gm_pass).\n"_fmt); + PRINTF(" We highly recommend that you change it.\n"_fmt); } if (level_new_gm < 0 || level_new_gm > 99) { - PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n"); + PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n"_fmt); level_new_gm = 60; rv = false; } if (new_account != 0 && new_account != 1) { - PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n"); + PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n"_fmt); new_account = 0; rv = false; } if (login_port < 1024 || login_port > 65535) { - PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n"); + PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n"_fmt); login_port = 6900; rv = false; } if (gm_account_filename_check_timer.count() < 0) { - PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"); - PRINTF(" -> set to 15 sec (default).\n"); + PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); + PRINTF(" -> set to 15 sec (default).\n"_fmt); gm_account_filename_check_timer = std::chrono::seconds(15); rv = false; } else if (gm_account_filename_check_timer == std::chrono::seconds(1)) { - PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"); - PRINTF(" -> set to 2 sec (minimum value).\n"); + PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); + PRINTF(" -> set to 2 sec (minimum value).\n"_fmt); gm_account_filename_check_timer = std::chrono::seconds(2); rv = false; } if (save_unknown_packets != 0 && save_unknown_packets != 1) { - PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n"); + PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n"_fmt); save_unknown_packets = 0; rv = false; } if (display_parse_login != 0 && display_parse_login != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for display_parse_login parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_login parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_login = 0; rv = false; } if (display_parse_admin != 0 && display_parse_admin != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_admin = 0; rv = false; } if (display_parse_fromchar < 0 || display_parse_fromchar > 2) { // 0: no, 1: yes (without packet 0x2714), 2: all packets - PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_fromchar = 0; rv = false; } if (min_level_to_connect < 0) { // 0: all players, 1-99 at least gm level x - PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n", + PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n"_fmt, min_level_to_connect); - PRINTF(" -> set to 0 (any player).\n"); + PRINTF(" -> set to 0 (any player).\n"_fmt); min_level_to_connect = 0; rv = false; } else if (min_level_to_connect > 99) { // 0: all players, 1-99 at least gm level x - PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n", + PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n"_fmt, min_level_to_connect); - PRINTF(" -> set to 99 (only GM level 99).\n"); + PRINTF(" -> set to 99 (only GM level 99).\n"_fmt); min_level_to_connect = 99; rv = false; } if (add_to_unlimited_account != 0 && add_to_unlimited_account != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n"); - PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n"); + PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n"_fmt); + PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n"_fmt); add_to_unlimited_account = 0; rv = false; } if (start_limited_time < -1) { // -1: create unlimited account, 0 or more: additionnal sec from now to create limited time - PRINTF("***WARNING: Invalid value for start_limited_time parameter\n"); - PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n"); + PRINTF("***WARNING: Invalid value for start_limited_time parameter\n"_fmt); + PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n"_fmt); start_limited_time = -1; rv = false; } if (check_ip_flag != 0 && check_ip_flag != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n"); - PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n"); + PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n"_fmt); + PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n"_fmt); check_ip_flag = 1; rv = false; } @@ -3616,8 +3608,8 @@ bool display_conf_warnings(void) { if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n"); - PRINTF(" And you refuse ALL IP.\n"); + PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n"_fmt); + PRINTF(" And you refuse ALL IP.\n"_fmt); rv = false; } } @@ -3625,8 +3617,8 @@ bool display_conf_warnings(void) { if (access_allow.empty()) { - PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n"); - PRINTF(" But, NO IP IS AUTHORISED!\n"); + PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n"_fmt); + PRINTF(" But, NO IP IS AUTHORISED!\n"_fmt); rv = false; } } @@ -3635,16 +3627,16 @@ bool display_conf_warnings(void) // ACO::MUTUAL_FAILURE if (access_allow.empty()) { - PRINTF("***WARNING: The IP security order is 'mutual-failture'\n"); - PRINTF(" (allow if in the allow list and not in the deny list).\n"); - PRINTF(" But, NO IP IS AUTHORISED!\n"); + PRINTF("***WARNING: The IP security order is 'mutual-failture'\n"_fmt); + PRINTF(" (allow if in the allow list and not in the deny list).\n"_fmt); + PRINTF(" But, NO IP IS AUTHORISED!\n"_fmt); rv = false; } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - PRINTF("***WARNING: The IP security order is mutual-failture\n"); - PRINTF(" (allow if in the allow list and not in the deny list).\n"); - PRINTF(" But, you refuse ALL IP!\n"); + PRINTF("***WARNING: The IP security order is mutual-failture\n"_fmt); + PRINTF(" (allow if in the allow list and not in the deny list).\n"_fmt); + PRINTF(" But, you refuse ALL IP!\n"_fmt); rv = false; } } @@ -3658,168 +3650,168 @@ static void save_config_in_log(void) { // a newline in the log... - LOGIN_LOG(""); - LOGIN_LOG("The login-server starting...\n"); + LOGIN_LOG(""_fmt); + LOGIN_LOG("The login-server starting...\n"_fmt); // save configuration in log file - LOGIN_LOG("The configuration of the server is set:\n"); + LOGIN_LOG("The configuration of the server is set:\n"_fmt); if (admin_state != 1) - LOGIN_LOG("- with no remote administration.\n"); + LOGIN_LOG("- with no remote administration.\n"_fmt); else if (!admin_pass) - LOGIN_LOG("- with a remote administration with a VOID password.\n"); - else if (admin_pass == stringish<AccountPass>("admin")) - LOGIN_LOG("- with a remote administration with the DEFAULT password.\n"); + LOGIN_LOG("- with a remote administration with a VOID password.\n"_fmt); + else if (admin_pass == stringish<AccountPass>("admin"_s)) + LOGIN_LOG("- with a remote administration with the DEFAULT password.\n"_fmt); else - LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n", + LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n"_fmt, admin_pass.size()); if (access_ladmin.empty() || (access_ladmin.size() == 1 && access_ladmin.front().mask() == IP4Address())) { - LOGIN_LOG("- to accept any IP for remote administration\n"); + LOGIN_LOG("- to accept any IP for remote administration\n"_fmt); } else { - LOGIN_LOG("- to accept following IP for remote administration:\n"); + LOGIN_LOG("- to accept following IP for remote administration:\n"_fmt); for (const IP4Mask& ae : access_ladmin) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } if (!gm_pass) - LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n"); - else if (gm_pass == "gm") - LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n"); + LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n"_fmt); + else if (gm_pass == "gm"_s) + LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n"_fmt); else - LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %zu character(s).\n", + LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %zu character(s).\n"_fmt, gm_pass.size()); if (level_new_gm == 0) - LOGIN_LOG("- to refuse any creation of GM with @gm.\n"); + LOGIN_LOG("- to refuse any creation of GM with @gm.\n"_fmt); else - LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n", + LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n"_fmt, level_new_gm); if (new_account == 1) - LOGIN_LOG("- to ALLOW new users (with _F/_M).\n"); + LOGIN_LOG("- to ALLOW new users (with _F/_M).\n"_fmt); else - LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n"); - LOGIN_LOG("- with port: %d.\n", login_port); - LOGIN_LOG("- with the accounts file name: '%s'.\n", + LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n"_fmt); + LOGIN_LOG("- with port: %d.\n"_fmt, login_port); + LOGIN_LOG("- with the accounts file name: '%s'.\n"_fmt, account_filename); - LOGIN_LOG("- with the GM accounts file name: '%s'.\n", + LOGIN_LOG("- with the GM accounts file name: '%s'.\n"_fmt, gm_account_filename); if (gm_account_filename_check_timer == interval_t::zero()) - LOGIN_LOG("- to NOT check GM accounts file modifications.\n"); + LOGIN_LOG("- to NOT check GM accounts file modifications.\n"_fmt); else - LOGIN_LOG("- to check GM accounts file modifications every %lld seconds.\n", + LOGIN_LOG("- to check GM accounts file modifications every %lld seconds.\n"_fmt, maybe_cast<long long>(gm_account_filename_check_timer.count())); // not necessary to log the 'login_log_filename', we are inside :) - LOGIN_LOG("- with the unknown packets file name: '%s'.\n", + LOGIN_LOG("- with the unknown packets file name: '%s'.\n"_fmt, login_log_unknown_packets_filename); if (save_unknown_packets) - LOGIN_LOG("- to SAVE all unkown packets.\n"); + LOGIN_LOG("- to SAVE all unkown packets.\n"_fmt); else - LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n"); + LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n"_fmt); if (display_parse_login) - LOGIN_LOG("- to display normal parse packets on console.\n"); + LOGIN_LOG("- to display normal parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display normal parse packets on console.\n"); + LOGIN_LOG("- to NOT display normal parse packets on console.\n"_fmt); if (display_parse_admin) - LOGIN_LOG("- to display administration parse packets on console.\n"); + LOGIN_LOG("- to display administration parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display administration parse packets on console.\n"); + LOGIN_LOG("- to NOT display administration parse packets on console.\n"_fmt); if (display_parse_fromchar) - LOGIN_LOG("- to display char-server parse packets on console.\n"); + LOGIN_LOG("- to display char-server parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display char-server parse packets on console.\n"); + LOGIN_LOG("- to NOT display char-server parse packets on console.\n"_fmt); if (min_level_to_connect == 0) // 0: all players, 1-99 at least gm level x - LOGIN_LOG("- with no minimum level for connection.\n"); + LOGIN_LOG("- with no minimum level for connection.\n"_fmt); else if (min_level_to_connect == 99) - LOGIN_LOG("- to accept only GM with level 99.\n"); + LOGIN_LOG("- to accept only GM with level 99.\n"_fmt); else - LOGIN_LOG("- to accept only GM with level %d or more.\n", + LOGIN_LOG("- to accept only GM with level %d or more.\n"_fmt, min_level_to_connect); if (add_to_unlimited_account) - LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n"); + LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n"_fmt); else - LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n"); + LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n"_fmt); if (start_limited_time < 0) - LOGIN_LOG("- to create new accounts with an unlimited time.\n"); + LOGIN_LOG("- to create new accounts with an unlimited time.\n"_fmt); else if (start_limited_time == 0) - LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n"); + LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n"_fmt); else - LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n", + LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n"_fmt, start_limited_time); if (check_ip_flag) - LOGIN_LOG("- with control of players IP between login-server and char-server.\n"); + LOGIN_LOG("- with control of players IP between login-server and char-server.\n"_fmt); else - LOGIN_LOG("- to not check players IP between login-server and char-server.\n"); + LOGIN_LOG("- to not check players IP between login-server and char-server.\n"_fmt); if (access_order == ACO::DENY_ALLOW) { if (access_deny.empty()) { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n"_fmt); } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n"_fmt); } else { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n"_fmt); for (IP4Mask ae : access_deny) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } else if (access_order == ACO::ALLOW_DENY) { if (access_allow.empty()) { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n"_fmt); } else if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address()) { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n"_fmt); } else { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n"_fmt); for (IP4Mask ae : access_allow) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } else { // ACO_MUTUAL_FAILTURE - LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n"); + LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n"_fmt); if (access_allow.empty()) { - LOGIN_LOG(" But, NO IP IS AUTHORISED!\n"); + LOGIN_LOG(" But, NO IP IS AUTHORISED!\n"_fmt); } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - LOGIN_LOG(" But, you refuse ALL IP!\n"); + LOGIN_LOG(" But, you refuse ALL IP!\n"_fmt); } else { if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address()) { - LOGIN_LOG(" You authorise ALL IP.\n"); + LOGIN_LOG(" You authorise ALL IP.\n"_fmt); } else { - LOGIN_LOG(" Authorised IP are:\n"); + LOGIN_LOG(" Authorised IP are:\n"_fmt); for (IP4Mask ae : access_allow) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } - LOGIN_LOG(" Refused IP are:\n"); + LOGIN_LOG(" Refused IP are:\n"_fmt); for (IP4Mask ae : access_deny) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } } @@ -3841,7 +3833,7 @@ void term_func(void) } delete_session(login_session); - LOGIN_LOG("----End of login-server (normal end with closing of all files).\n"); + LOGIN_LOG("----End of login-server (normal end with closing of all files).\n"_fmt); } static @@ -3867,20 +3859,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -3892,7 +3884,7 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-login.conf", login_confs); + runflag &= load_config_file("conf/tmwa-login.conf"_s, login_confs); // not in login_config_read, because we can use 'import' option, and display same message twice or more // (why is that bad?) @@ -3934,10 +3926,10 @@ int do_init(Slice<ZString> argv) check_GM_file, j).detach(); - LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n", + LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n"_fmt, login_port); - PRINTF("The login-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The login-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, login_port); return 0; diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 240df8b..f721aaa 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -121,11 +121,11 @@ void atcommand_config_write(ZString cfgName) if (!out.is_open()) { - FPRINTF(stderr, "Failed to write atcommand config: %s\n", cfgName); + FPRINTF(stderr, "Failed to write atcommand config: %s\n"_fmt, cfgName); return; } - FPRINTF(out, "// Generated by %s\n", CURRENT_VERSION_STRING); + FPRINTF(out, "// Generated by %s\n"_fmt, CURRENT_VERSION_STRING); for (const auto& pair : atcommand_info) { // This XString is really a ZString, but not declared as one @@ -137,7 +137,7 @@ void atcommand_config_write(ZString cfgName) "\n" "// %s\n" "// Usage: @%s %s\n" - "%s: %d\n", + "%s: %d\n"_fmt, info.help, cmd, info.args, cmd, info.level); @@ -198,8 +198,8 @@ void log_atcommand(dumb_ptr<map_session_data> sd, ZString cmd) stamp_time(tmpstr); MapName map = (sd->bl_m ? sd->bl_m->name_ - : stringish<MapName>("undefined.gat")); - FPRINTF(*fp, "[%s] %s(%d,%d) %s(%d) : %s\n", + : stringish<MapName>("undefined.gat"_s)); + FPRINTF(*fp, "[%s] %s(%d,%d) %s(%d) : %s\n"_fmt, tmpstr, map, sd->bl_x, sd->bl_y, sd->status_key.name, sd->status_key.account_id, @@ -225,7 +225,7 @@ io::AppendFile *get_gm_log() return gm_logfile.get(); last_logfile_nr = logfile_nr; - AString fullname = STRPRINTF("%s.%04d-%02d", + AString fullname = STRPRINTF("%s.%04d-%02d"_fmt, gm_log, year, month); if (gm_logfile) @@ -259,14 +259,14 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, gmlvl = pc_isGM(sd); if (battle_config.atcommand_gm_only != 0 && !gmlvl) { - AString output = STRPRINTF("GM command is level 0, but this server disables level 0 commands: %s", + AString output = STRPRINTF("GM command is level 0, but this server disables level 0 commands: %s"_fmt, AString(command)); clif_displaymessage(s, output); return true; } if (!info) { - AString output = STRPRINTF("GM command not found: %s", + AString output = STRPRINTF("GM command not found: %s"_fmt, AString(command)); clif_displaymessage(s, output); return true; @@ -274,7 +274,7 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, } if (info->level > gmlvl) { - AString output = STRPRINTF("GM command is level %d, but you are level %d: %s", + AString output = STRPRINTF("GM command is level %d, but you are level %d: %s"_fmt, info->level, gmlvl, AString(command)); clif_displaymessage(s, output); @@ -292,17 +292,17 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, log_atcommand(sd, message); break; case ATCE::USAGE: - clif_displaymessage(s, "Command failed: usage error"); - clif_displaymessage(s, STRPRINTF("Usage: %s %s", AString(command), info->args)); + clif_displaymessage(s, "Command failed: usage error"_s); + clif_displaymessage(s, STRPRINTF("Usage: %s %s"_fmt, AString(command), info->args)); break; case ATCE::EXIST: - clif_displaymessage(s, "Command failed: something does not exist (or already exists)"); + clif_displaymessage(s, "Command failed: something does not exist (or already exists)"_s); break; case ATCE::RANGE: - clif_displaymessage(s, "Command failed: value out of range"); + clif_displaymessage(s, "Command failed: value out of range"_s); break; case ATCE::PERM: - clif_displaymessage(s, "Command failed: permission denied"); + clif_displaymessage(s, "Command failed: permission denied"_s); break; default: abort(); @@ -347,7 +347,7 @@ bool atcommand_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("At commands configuration file not found: %s\n", cfgName); + PRINTF("At commands configuration file not found: %s\n"_fmt, cfgName); return false; } @@ -361,7 +361,7 @@ bool atcommand_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } @@ -374,11 +374,11 @@ bool atcommand_config_read(ZString cfgName) else if (p->level < 0) p->level = 0; } - else if (w1 == "import") + else if (w1 == "import"_s) rv &= atcommand_config_read(w2); else { - PRINTF("%s: bad line: %s\n", cfgName, line); + PRINTF("%s: bad line: %s\n"_fmt, cfgName, line); rv = false; } } @@ -391,7 +391,7 @@ bool atcommand_config_read(ZString cfgName) static void atc_do_help(Session *s, const char *cmd, const AtCommandInfo& info) { - auto msg = STRPRINTF("\u2007\u2007%d: @%s %s", info.level, cmd, info.args); + auto msg = STRPRINTF("\u2007\u2007%d: @%s %s"_fmt, info.level, cmd, info.args); // manually padding because *space* size_t ll = 1; if (info.level >= 10) @@ -407,9 +407,9 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, { if (!message) { - clif_displaymessage(s, "There is too much help to display it all at once"); - clif_displaymessage(s, "Try @help <@command> or @help <category> or @help <level[-level]>"); - clif_displaymessage(s, "Right now the only category is 'all'"); + clif_displaymessage(s, "There is too much help to display it all at once"_s); + clif_displaymessage(s, "Try @help <@command> or @help <category> or @help <level[-level]>"_s); + clif_displaymessage(s, "Right now the only category is 'all'"_s); return ATCE::OKAY; } @@ -419,14 +419,14 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, const AtCommandInfo *info = atcommand_info.search(cmd); if (!info) return ATCE::EXIST; - clif_displaymessage(s, STRPRINTF("Usage: @%s %s", cmd, info->args)); + clif_displaymessage(s, STRPRINTF("Usage: @%s %s"_fmt, cmd, info->args)); clif_displaymessage(s, info->help); return ATCE::OKAY; } - if (message == "all") + if (message == "all"_s) { - clif_displaymessage(s, "Synopses of GM commands in category 'all':"); + clif_displaymessage(s, "Synopses of GM commands in category 'all':"_s); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); @@ -444,7 +444,7 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, if (low < 0 || high > 100 || low >= high) return ATCE::RANGE; - clif_displaymessage(s, STRPRINTF("Synopses of GM commands in level [%d, %d):", low, high)); + clif_displaymessage(s, STRPRINTF("Synopses of GM commands in level [%d, %d):"_fmt, low, high)); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); @@ -467,25 +467,25 @@ ATCE atcommand_setup(Session *s, dumb_ptr<map_session_data> sd, level--; AString buf; - buf = STRPRINTF("-255 %s", character); + buf = STRPRINTF("-255 %s"_fmt, character); atcommand_character_baselevel(s, sd, buf); - buf = STRPRINTF("%d %s", level, character); + buf = STRPRINTF("%d %s"_fmt, level, character); atcommand_character_baselevel(s, sd, buf); // Emote skill - buf = STRPRINTF("1 1 %s", character); + buf = STRPRINTF("1 1 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); // Trade skill - buf = STRPRINTF("2 1 %s", character); + buf = STRPRINTF("2 1 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); // Party skill - STRPRINTF("2 2 %s", character); + STRPRINTF("2 2 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); - STRPRINTF("018-1.gat 24 98 %s", character); + STRPRINTF("018-1.gat 24 98 %s"_fmt, character); atcommand_charwarp(s, sd, buf); return ATCE::OKAY; @@ -520,42 +520,42 @@ ATCE atcommand_charwarp(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp someone to this map."); + "You are not authorised to warp someone to this map."_s); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."_s); return ATCE::PERM; } if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) { - clif_displaymessage(pl_sd->sess, "Warped."); - clif_displaymessage(s, "Player warped (message sends to player too)."); + clif_displaymessage(pl_sd->sess, "Warped."_s); + clif_displaymessage(s, "Player warped (message sends to player too)."_s); } else { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -573,7 +573,7 @@ ATCE atcommand_warp(Session *s, dumb_ptr<map_session_data> sd, || !extract(message, record<' ', 1>(&map_name, &x, &y))) { clif_displaymessage(s, - "Please, enter a map (usage: @warp <mapname> <x> <y>)."); + "Please, enter a map (usage: @warp <mapname> <x> <y>)."_s); return ATCE::USAGE; } @@ -589,27 +589,27 @@ ATCE atcommand_warp(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to this map."); + "You are not authorised to warp you to this map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) - clif_displaymessage(s, "Warped."); + clif_displaymessage(s, "Warped."_s); else { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } @@ -630,14 +630,14 @@ ATCE atcommand_where(Session *s, dumb_ptr<map_session_data> sd, && (pc_isGM(pl_sd) > pc_isGM(sd)))) { // you can look only lower or same level - AString output = STRPRINTF("%s: %s (%d,%d)", + AString output = STRPRINTF("%s: %s (%d,%d)"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -653,7 +653,7 @@ ATCE atcommand_goto(Session *s, dumb_ptr<map_session_data> sd, if (!asplit(message, &character)) { clif_displaymessage(s, - "Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>)."); + "Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>)."_s); return ATCE::USAGE; } @@ -664,23 +664,23 @@ ATCE atcommand_goto(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to the map of this player."); + "You are not authorised to warp you to the map of this player."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %s", character); + AString output = STRPRINTF("Jump to %s"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -705,23 +705,23 @@ ATCE atcommand_jump(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to your actual map."); + "You are not authorised to warp you to your actual map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, sd->mapname_, x, y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %d %d", x, y); + AString output = STRPRINTF("Jump to %d %d"_fmt, x, y); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } @@ -761,12 +761,12 @@ ATCE atcommand_who(Session *s, dumb_ptr<map_session_data> sd, AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); else output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -777,12 +777,12 @@ ATCE atcommand_who(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -822,11 +822,11 @@ ATCE atcommand_whogroup(Session *s, dumb_ptr<map_session_data> sd, { // search with no case sensitive p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Party: '%s'", + "Name: %s (GM:%d) | Party: '%s'"_fmt, pl_sd->status_key.name, pl_GM_level, temp0); clif_displaymessage(s, output); count++; @@ -836,12 +836,12 @@ ATCE atcommand_whogroup(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -886,12 +886,12 @@ ATCE atcommand_whomap(Session *s, dumb_ptr<map_session_data> sd, AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); else output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -901,7 +901,7 @@ ATCE atcommand_whomap(Session *s, dumb_ptr<map_session_data> sd, } } - AString output = STRPRINTF("%d players found in map '%s'.", + AString output = STRPRINTF("%d players found in map '%s'."_fmt, count, map_id->name_); clif_displaymessage(s, output); @@ -945,13 +945,13 @@ ATCE atcommand_whomapgroup(Session *s, dumb_ptr<map_session_data> sd, if (pl_sd->bl_m == map_id) { p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); AString output; if (pl_GM_level > 0) - output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'", + output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'"_fmt, pl_sd->status_key.name, pl_GM_level, temp0); else - output = STRPRINTF("Name: %s | Party: '%s'", + output = STRPRINTF("Name: %s | Party: '%s'"_fmt, pl_sd->status_key.name, temp0); clif_displaymessage(s, output); count++; @@ -962,12 +962,12 @@ ATCE atcommand_whomapgroup(Session *s, dumb_ptr<map_session_data> sd, AString output; if (count == 0) - output = STRPRINTF("No player found in map '%s'.", map_id->name_); + output = STRPRINTF("No player found in map '%s'."_fmt, map_id->name_); else if (count == 1) - output = STRPRINTF("1 player found in map '%s'.", map_id->name_); + output = STRPRINTF("1 player found in map '%s'."_fmt, map_id->name_); else { - output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_); + output = STRPRINTF("%d players found in map '%s'."_fmt, count, map_id->name_); } clif_displaymessage(s, output); @@ -1010,20 +1010,20 @@ ATCE atcommand_whogm(Session *s, dumb_ptr<map_session_data> sd, // search with no case sensitive AString output; output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); output = STRPRINTF( - " BLvl: %d | Job: %s (Lvl: %d)", + " BLvl: %d | Job: %s (Lvl: %d)"_fmt, pl_sd->status.base_level, - "Novice/Human", + "Novice/Human"_s, pl_sd->status.job_level); clif_displaymessage(s, output); p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); output = STRPRINTF( - " Party: '%s'", + " Party: '%s'"_fmt, temp0); clif_displaymessage(s, output); count++; @@ -1034,12 +1034,12 @@ ATCE atcommand_whogm(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No GM found."); + clif_displaymessage(s, "No GM found."_s); else if (count == 1) - clif_displaymessage(s, "1 GM found."); + clif_displaymessage(s, "1 GM found."_s); else { - AString output = STRPRINTF("%d GMs found.", count); + AString output = STRPRINTF("%d GMs found."_fmt, count); clif_displaymessage(s, output); } @@ -1053,7 +1053,7 @@ ATCE atcommand_save(Session *s, dumb_ptr<map_session_data> sd, pc_setsavepoint(sd, sd->mapname_, sd->bl_x, sd->bl_y); pc_makesavestatus(sd); chrif_save(sd); - clif_displaymessage(s, "Character data respawn point saved."); + clif_displaymessage(s, "Character data respawn point saved."_s); return ATCE::OKAY; } @@ -1067,14 +1067,14 @@ ATCE atcommand_load(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to your save map."); + "You are not authorised to warp you to your save map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } @@ -1089,7 +1089,7 @@ ATCE atcommand_load(Session *s, dumb_ptr<map_session_data> sd, pc_setpos(sd, sd->status.save_point.map_, sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::GONE); } - clif_displaymessage(s, "Warping to respawn point."); + clif_displaymessage(s, "Warping to respawn point."_s); return ATCE::OKAY; } @@ -1101,7 +1101,7 @@ ATCE atcommand_speed(Session *s, dumb_ptr<map_session_data> sd, if (!message) { AString output = STRPRINTF( - "Please, enter a speed value (usage: @speed <%d-%d>).", + "Please, enter a speed value (usage: @speed <%d-%d>)."_fmt, static_cast<uint32_t>(MIN_WALK_SPEED.count()), static_cast<uint32_t>(MAX_WALK_SPEED.count())); clif_displaymessage(s, output); @@ -1115,12 +1115,12 @@ ATCE atcommand_speed(Session *s, dumb_ptr<map_session_data> sd, //sd->walktimer = x; //この文を追加 by れ clif_updatestatus(sd, SP::SPEED); - clif_displaymessage(s, "Speed changed."); + clif_displaymessage(s, "Speed changed."_s); } else { AString output = STRPRINTF( - "Please, enter a valid speed value (usage: @speed <%d-%d>).", + "Please, enter a valid speed value (usage: @speed <%d-%d>)."_fmt, static_cast<uint32_t>(MIN_WALK_SPEED.count()), static_cast<uint32_t>(MAX_WALK_SPEED.count())); clif_displaymessage(s, output); @@ -1138,14 +1138,14 @@ ATCE atcommand_storage(Session *s, dumb_ptr<map_session_data> sd, if (sd->state.storage_open) { - clif_displaymessage(s, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"_s); return ATCE::EXIST; } if ((stor = account2storage2(sd->status_key.account_id)) != NULL && stor->storage_status == 1) { - clif_displaymessage(s, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"_s); return ATCE::EXIST; } @@ -1171,7 +1171,7 @@ ATCE atcommand_option(Session *s, dumb_ptr<map_session_data> sd, clif_changeoption(sd); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Options changed."); + clif_displaymessage(s, "Options changed."_s); return ATCE::OKAY; } @@ -1183,12 +1183,12 @@ ATCE atcommand_hide(Session *s, dumb_ptr<map_session_data> sd, if (bool(sd->status.option & Option::HIDE)) { sd->status.option &= ~Option::HIDE; - clif_displaymessage(s, "Invisible: Off."); + clif_displaymessage(s, "Invisible: Off."_s); } else { sd->status.option |= Option::HIDE; - clif_displaymessage(s, "Invisible: On."); + clif_displaymessage(s, "Invisible: On."_s); } clif_changeoption(sd); @@ -1200,7 +1200,7 @@ ATCE atcommand_die(Session *s, dumb_ptr<map_session_data> sd, ZString) { pc_damage(NULL, sd, sd->status.hp + 1); - clif_displaymessage(s, "A pity! You've died."); + clif_displaymessage(s, "A pity! You've died."_s); return ATCE::OKAY; } @@ -1221,17 +1221,17 @@ ATCE atcommand_kill(Session *s, dumb_ptr<map_session_data> sd, { // you can kill only lower or same level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(s, "Character killed."); + clif_displaymessage(s, "Character killed."_s); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -1250,7 +1250,7 @@ ATCE atcommand_alive(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(s, "You've been revived! It's a miracle!"); + clif_displaymessage(s, "You've been revived! It's a miracle!"_s); return ATCE::OKAY; } @@ -1304,13 +1304,13 @@ ATCE atcommand_heal(Session *s, dumb_ptr<map_session_data> sd, { pc_heal(sd, hp, sp); if (hp >= 0 && sp >= 0) - clif_displaymessage(s, "HP, SP recovered."); + clif_displaymessage(s, "HP, SP recovered."_s); else - clif_displaymessage(s, "HP or/and SP modified."); + clif_displaymessage(s, "HP or/and SP modified."_s); } else { - clif_displaymessage(s, "HP and SP are already with the good value."); + clif_displaymessage(s, "HP and SP are already with the good value."_s); return ATCE::RANGE; } @@ -1329,7 +1329,7 @@ ATCE atcommand_item(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, record<' ', 1>(&item_name, &number))) { clif_displaymessage(s, - "Please, enter an item name/id (usage: @item <item name or ID> [quantity])."); + "Please, enter an item name/id (usage: @item <item name or ID> [quantity])."_s); return ATCE::USAGE; } @@ -1363,11 +1363,11 @@ ATCE atcommand_item(Session *s, dumb_ptr<map_session_data> sd, != PickupFail::OKAY) clif_additem(sd, 0, 0, flag); } - clif_displaymessage(s, "Item created."); + clif_displaymessage(s, "Item created."_s); } else { - clif_displaymessage(s, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."_s); return ATCE::EXIST; } @@ -1386,7 +1386,7 @@ ATCE atcommand_itemreset(Session *s, dumb_ptr<map_session_data> sd, && sd->status.inventory[i].equip == EPOS::ZERO) pc_delitem(sd, i, sd->status.inventory[i].amount, 0); } - clif_displaymessage(s, "All of your items have been removed."); + clif_displaymessage(s, "All of your items have been removed."_s); return ATCE::OKAY; } @@ -1409,7 +1409,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, &level) || !level) { clif_displaymessage(s, - "Please, enter a level adjustement (usage: @blvl <number of levels>)."); + "Please, enter a level adjustement (usage: @blvl <number of levels>)."_s); return ATCE::USAGE; } @@ -1417,7 +1417,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, { if (sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(s, "Base level can't go any higher."); + clif_displaymessage(s, "Base level can't go any higher."_s); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - sd->status.base_level)) @@ -1432,13 +1432,13 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); clif_misceffect(sd, 0); - clif_displaymessage(s, "Base level raised."); + clif_displaymessage(s, "Base level raised."_s); } else { if (sd->status.base_level == 1) { - clif_displaymessage(s, "Base level can't go any lower."); + clif_displaymessage(s, "Base level can't go any lower."_s); return ATCE::USAGE; } if (level < -battle_config.maximum_level || level < (1 - sd->status.base_level)) @@ -1458,7 +1458,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::BASELEVEL); clif_updatestatus(sd, SP::NEXTBASEEXP); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Base level lowered."); + clif_displaymessage(s, "Base level lowered."_s); } return ATCE::OKAY; @@ -1481,7 +1481,7 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, { if (sd->status.job_level == up_level) { - clif_displaymessage(s, "Job level can't go any higher."); + clif_displaymessage(s, "Job level can't go any higher."_s); return ATCE::RANGE; } if (level > up_level || level > (up_level - sd->status.job_level)) @@ -1494,13 +1494,13 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); clif_misceffect(sd, 1); - clif_displaymessage(s, "Job level raised."); + clif_displaymessage(s, "Job level raised."_s); } else { if (sd->status.job_level == 1) { - clif_displaymessage(s, "Job level can't go any lower."); + clif_displaymessage(s, "Job level can't go any lower."_s); return ATCE::RANGE; } if (level < -up_level || level < (1 - sd->status.job_level)) @@ -1518,7 +1518,7 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, } // to add: remove status points from skills pc_calcstatus(sd, 0); - clif_displaymessage(s, "Job level lowered."); + clif_displaymessage(s, "Job level lowered."_s); } return ATCE::OKAY; @@ -1534,7 +1534,7 @@ ATCE atcommand_gm(Session *s, dumb_ptr<map_session_data> sd, if (pc_isGM(sd)) { // a GM can not use this function. only a normal player (become gm is not for gm!) - clif_displaymessage(s, "You already have some GM powers."); + clif_displaymessage(s, "You already have some GM powers."_s); return ATCE::PERM; } else @@ -1550,7 +1550,7 @@ ATCE atcommand_pvpoff(Session *s, dumb_ptr<map_session_data> sd, if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(s, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."_s); return ATCE::EXIST; } @@ -1571,11 +1571,11 @@ ATCE atcommand_pvpoff(Session *s, dumb_ptr<map_session_data> sd, } } } - clif_displaymessage(s, "PvP: Off."); + clif_displaymessage(s, "PvP: Off."_s); } else { - clif_displaymessage(s, "PvP is already Off."); + clif_displaymessage(s, "PvP is already Off."_s); return ATCE::EXIST; } @@ -1589,7 +1589,7 @@ ATCE atcommand_pvpon(Session *s, dumb_ptr<map_session_data> sd, if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(s, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."_s); return ATCE::EXIST; } @@ -1614,11 +1614,11 @@ ATCE atcommand_pvpon(Session *s, dumb_ptr<map_session_data> sd, } } } - clif_displaymessage(s, "PvP: On."); + clif_displaymessage(s, "PvP: On."_s); } else { - clif_displaymessage(s, "PvP is already On."); + clif_displaymessage(s, "PvP is already On."_s); return ATCE::EXIST; } @@ -1642,7 +1642,7 @@ ATCE atcommand_model(Session *s, dumb_ptr<map_session_data> sd, pc_changelook(sd, LOOK::HAIR, hair_style); pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1664,7 +1664,7 @@ ATCE atcommand_dye(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1686,7 +1686,7 @@ ATCE atcommand_hair_style(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::HAIR, hair_style); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1708,7 +1708,7 @@ ATCE atcommand_hair_color(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1749,7 +1749,7 @@ ATCE atcommand_spawn(Session *s, dumb_ptr<map_session_data> sd, number = battle_config.atcommand_spawn_quantity_limit; if (battle_config.etc_log) - PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n", + PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n"_fmt, monster, mob_id, number, x, y); count = 0; @@ -1778,16 +1778,16 @@ ATCE atcommand_spawn(Session *s, dumb_ptr<map_session_data> sd, if (count != 0) if (number == count) - clif_displaymessage(s, "All monster summoned!"); + clif_displaymessage(s, "All monster summoned!"_s); else { - AString output = STRPRINTF("%d monster(s) summoned!", + AString output = STRPRINTF("%d monster(s) summoned!"_fmt, count); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Invalid monster ID or name."); + clif_displaymessage(s, "Invalid monster ID or name."_s); return ATCE::EXIST; } @@ -1813,7 +1813,7 @@ void atcommand_killmonster_sub(Session *s, dumb_ptr<map_session_data> sd, map_id->xs, map_id->ys, BL::MOB); - clif_displaymessage(s, "All monsters killed!"); + clif_displaymessage(s, "All monsters killed!"_s); } static @@ -1830,7 +1830,7 @@ void atlist_nearby_sub(dumb_ptr<block_list> bl, Session *s) { nullpo_retv(bl); - AString buf = STRPRINTF(" - \"%s\"", + AString buf = STRPRINTF(" - \"%s\""_fmt, bl->is_player()->status_key.name); clif_displaymessage(s, buf); } @@ -1839,7 +1839,7 @@ static ATCE atcommand_list_nearby(Session *s, dumb_ptr<map_session_data> sd, ZString) { - clif_displaymessage(s, "Nearby players:"); + clif_displaymessage(s, "Nearby players:"_s); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, s), sd->bl_m, sd->bl_x - 1, sd->bl_y - 1, @@ -1867,7 +1867,7 @@ ATCE atcommand_gat(Session *s, dumb_ptr<map_session_data> sd, for (y = 2; y >= -2; y--) { AString output = STRPRINTF( - "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", + "%s (x= %d, y= %d) %02X %02X %02X %02X %02X"_fmt, sd->bl_m->name_, sd->bl_x - 2, sd->bl_y + y, map_getcell(sd->bl_m, sd->bl_x - 2, sd->bl_y + y), map_getcell(sd->bl_m, sd->bl_x - 1, sd->bl_y + y), @@ -1916,7 +1916,7 @@ ATCE atcommand_statuspoint(Session *s, dumb_ptr<map_session_data> sd, { sd->status.status_point = new_status_point; clif_updatestatus(sd, SP::STATUSPOINT); - clif_displaymessage(s, "Number of status points changed!"); + clif_displaymessage(s, "Number of status points changed!"_s); } else return ATCE::RANGE; @@ -1945,7 +1945,7 @@ ATCE atcommand_skillpoint(Session *s, dumb_ptr<map_session_data> sd, { sd->status.skill_point = new_skill_point; clif_updatestatus(sd, SP::SKILLPOINT); - clif_displaymessage(s, "Number of skill points changed!"); + clif_displaymessage(s, "Number of skill points changed!"_s); } else return ATCE::RANGE; @@ -1974,7 +1974,7 @@ ATCE atcommand_zeny(Session *s, dumb_ptr<map_session_data> sd, { sd->status.zeny = new_zeny; clif_updatestatus(sd, SP::ZENY); - clif_displaymessage(s, "Number of zenys changed!"); + clif_displaymessage(s, "Number of zenys changed!"_s); } else return ATCE::RANGE; @@ -2006,7 +2006,7 @@ ATCE atcommand_param(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, attr_to_sp(attr)); clif_updatestatus(sd, attr_to_usp(attr)); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Stat changed."); + clif_displaymessage(s, "Stat changed."_s); } else return ATCE::RANGE; @@ -2047,7 +2047,7 @@ ATCE atcommand_all_stats(Session *s, dumb_ptr<map_session_data> sd, if (count > 0) // if at least 1 stat modified - clif_displaymessage(s, "All stats changed!"); + clif_displaymessage(s, "All stats changed!"_s); else return ATCE::RANGE; @@ -2073,29 +2073,29 @@ ATCE atcommand_recall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."_s); return ATCE::PERM; } pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); - AString output = STRPRINTF("%s recalled!", character); + AString output = STRPRINTF("%s recalled!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2121,11 +2121,11 @@ ATCE atcommand_revive(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::HP); clif_updatestatus(pl_sd, SP::SP); clif_resurrection(pl_sd, 1); - clif_displaymessage(s, "Character revived."); + clif_displaymessage(s, "Character revived."_s); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2145,38 +2145,38 @@ ATCE atcommand_character_stats(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { AString output; - output = STRPRINTF("'%s' stats:", pl_sd->status_key.name); + output = STRPRINTF("'%s' stats:"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); - output = STRPRINTF("Base Level - %d", pl_sd->status.base_level), + output = STRPRINTF("Base Level - %d"_fmt, pl_sd->status.base_level), clif_displaymessage(s, output); - output = STRPRINTF("Job - Novice/Human (level %d)", pl_sd->status.job_level); + output = STRPRINTF("Job - Novice/Human (level %d)"_fmt, pl_sd->status.job_level); clif_displaymessage(s, output); - output = STRPRINTF("Hp - %d", pl_sd->status.hp); + output = STRPRINTF("Hp - %d"_fmt, pl_sd->status.hp); clif_displaymessage(s, output); - output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp); + output = STRPRINTF("MaxHp - %d"_fmt, pl_sd->status.max_hp); clif_displaymessage(s, output); - output = STRPRINTF("Sp - %d", pl_sd->status.sp); + output = STRPRINTF("Sp - %d"_fmt, pl_sd->status.sp); clif_displaymessage(s, output); - output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp); + output = STRPRINTF("MaxSp - %d"_fmt, pl_sd->status.max_sp); clif_displaymessage(s, output); - output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]); + output = STRPRINTF("Str - %3d"_fmt, pl_sd->status.attrs[ATTR::STR]); clif_displaymessage(s, output); - output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]); + output = STRPRINTF("Agi - %3d"_fmt, pl_sd->status.attrs[ATTR::AGI]); clif_displaymessage(s, output); - output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]); + output = STRPRINTF("Vit - %3d"_fmt, pl_sd->status.attrs[ATTR::VIT]); clif_displaymessage(s, output); - output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]); + output = STRPRINTF("Int - %3d"_fmt, pl_sd->status.attrs[ATTR::INT]); clif_displaymessage(s, output); - output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]); + output = STRPRINTF("Dex - %3d"_fmt, pl_sd->status.attrs[ATTR::DEX]); clif_displaymessage(s, output); - output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]); + output = STRPRINTF("Luk - %3d"_fmt, pl_sd->status.attrs[ATTR::LUK]); clif_displaymessage(s, output); - output = STRPRINTF("Zeny - %d", pl_sd->status.zeny); + output = STRPRINTF("Zeny - %d"_fmt, pl_sd->status.zeny); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2200,19 +2200,19 @@ ATCE atcommand_character_stats_all(Session *s, dumb_ptr<map_session_data>, { AString gmlevel; if (pc_isGM(pl_sd) > 0) - gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd)); + gmlevel = STRPRINTF("| GM Lvl: %d"_fmt, pc_isGM(pl_sd)); else - gmlevel = " "; + gmlevel = " "_s; AString output; output = STRPRINTF( - "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d", + "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d"_fmt, pl_sd->status_key.name, pl_sd->status.base_level, pl_sd->status.job_level, pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp, pl_sd->status.max_sp); clif_displaymessage(s, output); - output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s", + output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s"_fmt, pl_sd->status.attrs[ATTR::STR], pl_sd->status.attrs[ATTR::AGI], pl_sd->status.attrs[ATTR::VIT], @@ -2222,18 +2222,18 @@ ATCE atcommand_character_stats_all(Session *s, dumb_ptr<map_session_data>, pl_sd->status.zeny, gmlevel); clif_displaymessage(s, output); - clif_displaymessage(s, "--------"); + clif_displaymessage(s, "--------"_s); count++; } } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -2263,17 +2263,17 @@ ATCE atcommand_character_option(Session *s, dumb_ptr<map_session_data> sd, clif_changeoption(pl_sd); pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's options changed."); + clif_displaymessage(s, "Character's options changed."_s); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2292,7 +2292,7 @@ ATCE atcommand_char_change_sex(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 5, HumanTimeDiff()); // type: 5 - changesex - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2310,7 +2310,7 @@ ATCE atcommand_char_block(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 1, HumanTimeDiff()); // type: 1 - block - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2330,7 +2330,7 @@ ATCE atcommand_char_ban(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 2, modif); // type: 2 - ban - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2349,7 +2349,7 @@ ATCE atcommand_char_unblock(Session *s, dumb_ptr<map_session_data> sd, // send answer to login server via char-server chrif_char_ask_name(sd->status_key.account_id, character, 3, HumanTimeDiff()); // type: 3 - unblock - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2368,7 +2368,7 @@ ATCE atcommand_char_unban(Session *s, dumb_ptr<map_session_data> sd, // send answer to login server via char-server chrif_char_ask_name(sd->status_key.account_id, character, 4, HumanTimeDiff()); // type: 4 - unban - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2395,7 +2395,7 @@ ATCE atcommand_character_save(Session *s, dumb_ptr<map_session_data> sd, map_local *m = map_mapname2mapid(map_name); if (m == nullptr) { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } else @@ -2404,22 +2404,22 @@ ATCE atcommand_character_save(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to set this map as a save map."); + "You are not authorised to set this map as a save map."_s); return ATCE::PERM; } pc_setsavepoint(pl_sd, map_name, x, y); - clif_displaymessage(s, "Character's respawn point changed."); + clif_displaymessage(s, "Character's respawn point changed."_s); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2442,10 +2442,10 @@ ATCE atcommand_doom(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -2466,10 +2466,10 @@ ATCE atcommand_doommap(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -2485,7 +2485,7 @@ void atcommand_raise_sub(dumb_ptr<map_session_data> sd) clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(sd->sess, "Mercy has been shown."); + clif_displaymessage(sd->sess, "Mercy has been shown."_s); } } @@ -2501,7 +2501,7 @@ ATCE atcommand_raise(Session *s, dumb_ptr<map_session_data>, dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(s2->session_data.get())); atcommand_raise_sub(pl_sd); } - clif_displaymessage(s, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."_s); return ATCE::OKAY; } @@ -2520,7 +2520,7 @@ ATCE atcommand_raisemap(Session *s, dumb_ptr<map_session_data> sd, && pl_sd->state.auth && sd->bl_m == pl_sd->bl_m) atcommand_raise_sub(pl_sd); } - clif_displaymessage(s, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."_s); return ATCE::OKAY; } @@ -2546,7 +2546,7 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, { if (pl_sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(s, "Character's base level can't go any higher."); + clif_displaymessage(s, "Character's base level can't go any higher."_s); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - pl_sd->status.base_level)) @@ -2564,13 +2564,13 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(pl_sd, 0); pc_heal(pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp); clif_misceffect(pl_sd, 0); - clif_displaymessage(s, "Character's base level raised."); + clif_displaymessage(s, "Character's base level raised."_s); } else { if (pl_sd->status.base_level == 1) { - clif_displaymessage(s, "Character's base level can't go any lower."); + clif_displaymessage(s, "Character's base level can't go any lower."_s); return ATCE::RANGE; } if (level < -battle_config.maximum_level || level < (1 - pl_sd->status.base_level)) @@ -2592,20 +2592,20 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::NEXTBASEEXP); clif_updatestatus(pl_sd, SP::BASEEXP); pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's base level lowered."); + clif_displaymessage(s, "Character's base level lowered."_s); } // Reset their stat points to prevent extra points from stacking atcommand_charstreset(s, sd, character.to__actual()); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2635,7 +2635,7 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, { if (pl_sd->status.job_level == max_level) { - clif_displaymessage(s, "Character's job level can't go any higher."); + clif_displaymessage(s, "Character's job level can't go any higher."_s); return ATCE::RANGE; } if (pl_sd->status.job_level + level > max_level) @@ -2647,13 +2647,13 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::SKILLPOINT); pc_calcstatus(pl_sd, 0); clif_misceffect(pl_sd, 1); - clif_displaymessage(s, "character's job level raised."); + clif_displaymessage(s, "character's job level raised."_s); } else { if (pl_sd->status.job_level == 1) { - clif_displaymessage(s, "Character's job level can't go any lower."); + clif_displaymessage(s, "Character's job level can't go any lower."_s); return ATCE::RANGE; } if (pl_sd->status.job_level + level < 1) @@ -2670,18 +2670,18 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, } // to add: remove status points from skills pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's job level lowered."); + clif_displaymessage(s, "Character's job level lowered."_s); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2705,13 +2705,13 @@ ATCE atcommand_kick(Session *s, dumb_ptr<map_session_data> sd, clif_GM_kick(sd, pl_sd, 1); else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2737,7 +2737,7 @@ ATCE atcommand_kickall(Session *s, dumb_ptr<map_session_data> sd, } } - clif_displaymessage(s, "All players have been kicked!"); + clif_displaymessage(s, "All players have been kicked!"_s); return ATCE::OKAY; } @@ -2758,23 +2758,23 @@ ATCE atcommand_questskill(Session *s, dumb_ptr<map_session_data> sd, if (pc_checkskill(sd, skill_id) == 0) { pc_skill(sd, skill_id, 1, 0); - clif_displaymessage(s, "You have learned the skill."); + clif_displaymessage(s, "You have learned the skill."_s); } else { - clif_displaymessage(s, "You already have this quest skill."); + clif_displaymessage(s, "You already have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2801,29 +2801,29 @@ ATCE atcommand_charquestskill(Session *s, dumb_ptr<map_session_data>, if (pc_checkskill(pl_sd, skill_id) == 0) { pc_skill(pl_sd, skill_id, 1, 0); - clif_displaymessage(s, "This player has learned the skill."); + clif_displaymessage(s, "This player has learned the skill."_s); } else { - clif_displaymessage(s, "This player already has this quest skill."); + clif_displaymessage(s, "This player already has this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2848,23 +2848,23 @@ ATCE atcommand_lostskill(Session *s, dumb_ptr<map_session_data> sd, sd->status.skill[skill_id].lv = 0; sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(sd); - clif_displaymessage(s, "You have forgotten the skill."); + clif_displaymessage(s, "You have forgotten the skill."_s); } else { - clif_displaymessage(s, "You don't have this quest skill."); + clif_displaymessage(s, "You don't have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2893,29 +2893,29 @@ ATCE atcommand_charlostskill(Session *s, dumb_ptr<map_session_data>, pl_sd->status.skill[skill_id].lv = 0; pl_sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(pl_sd); - clif_displaymessage(s, "This player has forgotten the skill."); + clif_displaymessage(s, "This player has forgotten the skill."_s); } else { - clif_displaymessage(s, "This player doesn't have this quest skill."); + clif_displaymessage(s, "This player doesn't have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2970,7 +2970,7 @@ ATCE atcommand_idsearch(Session *s, dumb_ptr<map_session_data>, if (!extract(message, &item_name) || !item_name) return ATCE::USAGE; - AString output = STRPRINTF("The reference result of '%s' (name: id):", item_name); + AString output = STRPRINTF("The reference result of '%s' (name: id):"_fmt, item_name); clif_displaymessage(s, output); match = 0; for (i = 0; i < 20000; i++) @@ -2979,11 +2979,11 @@ ATCE atcommand_idsearch(Session *s, dumb_ptr<map_session_data>, && item->jname.contains_seq(item_name)) { match++; - output = STRPRINTF("%s: %d", item->jname, item->nameid); + output = STRPRINTF("%s: %d"_fmt, item->jname, item->nameid); clif_displaymessage(s, output); } } - output = STRPRINTF("It is %d affair above.", match); + output = STRPRINTF("It is %d affair above."_fmt, match); clif_displaymessage(s, output); return ATCE::OKAY; @@ -3006,18 +3006,18 @@ ATCE atcommand_charskreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset skill points only lower or same gm level pc_resetskill(pl_sd); AString output = STRPRINTF( - "'%s' skill points reseted!", character); + "'%s' skill points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3041,19 +3041,19 @@ ATCE atcommand_charstreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset stats points only lower or same gm level pc_resetstate(pl_sd); AString output = STRPRINTF( - "'%s' stats points reseted!", + "'%s' stats points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3077,23 +3077,23 @@ ATCE atcommand_charreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset a character only for lower or same GM level pc_resetstate(pl_sd); pc_resetskill(pl_sd); - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"_s), 0); // [Fate] Reset magic quest variables - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"_s), 0); // [Fate] Reset magic experience AString output = STRPRINTF( - "'%s' skill and stats points reseted!", character); + "'%s' skill and stats points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3157,23 +3157,23 @@ ATCE atcommand_char_wipe(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(pl_sd, 0); pc_resetstate(pl_sd); pc_resetskill(pl_sd); - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"_s), 0); // [Fate] Reset magic quest variables - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"_s), 0); // [Fate] Reset magic experience - AString output = STRPRINTF("%s: wiped.", character); + AString output = STRPRINTF("%s: wiped."_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3201,7 +3201,7 @@ ATCE atcommand_charmodel(Session *s, dumb_ptr<map_session_data>, pc_changelook(pl_sd, LOOK::HAIR, hair_style); pc_changelook(pl_sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(pl_sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -3209,7 +3209,7 @@ ATCE atcommand_charmodel(Session *s, dumb_ptr<map_session_data>, } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3242,14 +3242,14 @@ ATCE atcommand_charskpoint(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.skill_point = new_skill_point; clif_updatestatus(pl_sd, SP::SKILLPOINT); - clif_displaymessage(s, "Character's number of skill points changed!"); + clif_displaymessage(s, "Character's number of skill points changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3282,14 +3282,14 @@ ATCE atcommand_charstpoint(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.status_point = new_status_point; clif_updatestatus(pl_sd, SP::STATUSPOINT); - clif_displaymessage(s, "Character's number of status points changed!"); + clif_displaymessage(s, "Character's number of status points changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3320,14 +3320,14 @@ ATCE atcommand_charzeny(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.zeny = new_zeny; clif_updatestatus(pl_sd, SP::ZENY); - clif_displaymessage(s, "Character's number of zenys changed!"); + clif_displaymessage(s, "Character's number of zenys changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3344,7 +3344,7 @@ ATCE atcommand_recallall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } @@ -3369,11 +3369,11 @@ ATCE atcommand_recallall(Session *s, dumb_ptr<map_session_data> sd, } } - clif_displaymessage(s, "All characters recalled!"); + clif_displaymessage(s, "All characters recalled!"_s); if (count) { AString output = STRPRINTF( - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled."_fmt, count); clif_displaymessage(s, output); } @@ -3396,7 +3396,7 @@ ATCE atcommand_partyrecall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } @@ -3422,19 +3422,19 @@ ATCE atcommand_partyrecall(Session *s, dumb_ptr<map_session_data> sd, pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); } } - AString output = STRPRINTF("All online characters of the %s party are near you.", p->name); + AString output = STRPRINTF("All online characters of the %s party are near you."_fmt, p->name); clif_displaymessage(s, output); if (count) { output = STRPRINTF( - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled."_fmt, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."_s); return ATCE::EXIST; } @@ -3447,7 +3447,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, { dumb_ptr<npc_data> nd = NULL; MapName map_name; - const char *direction = NULL; + LString direction = ""_s; int list = 0; extract(message, record<' '>(&list, &map_name)); @@ -3462,35 +3462,35 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, if (m_id != nullptr) return ATCE::EXIST; - clif_displaymessage(s, "------ Map Info ------"); - AString output = STRPRINTF("Map Name: %s", map_name); + clif_displaymessage(s, "------ Map Info ------"_s); + AString output = STRPRINTF("Map Name: %s"_fmt, map_name); clif_displaymessage(s, output); - output = STRPRINTF("Players In Map: %d", m_id->users); + output = STRPRINTF("Players In Map: %d"_fmt, m_id->users); clif_displaymessage(s, output); - output = STRPRINTF("NPCs In Map: %d", m_id->npc_num); + output = STRPRINTF("NPCs In Map: %d"_fmt, m_id->npc_num); clif_displaymessage(s, output); - clif_displaymessage(s, "------ Map Flags ------"); - output = STRPRINTF("Player vs Player: %s | No Party: %s", - (m_id->flag.get(MapFlag::PVP)) ? "True" : "False", - (m_id->flag.get(MapFlag::PVP_NOPARTY)) ? "True" : "False"); + clif_displaymessage(s, "------ Map Flags ------"_s); + output = STRPRINTF("Player vs Player: %s | No Party: %s"_fmt, + (m_id->flag.get(MapFlag::PVP)) ? "True"_s : "False"_s, + (m_id->flag.get(MapFlag::PVP_NOPARTY)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Penalty: %s", - (m_id->flag.get(MapFlag::NOPENALTY)) ? "True" : "False"); + output = STRPRINTF("No Penalty: %s"_fmt, + (m_id->flag.get(MapFlag::NOPENALTY)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Return: %s", - (m_id->flag.get(MapFlag::NORETURN)) ? "True" : "False"); + output = STRPRINTF("No Return: %s"_fmt, + (m_id->flag.get(MapFlag::NORETURN)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Save: %s", - (m_id->flag.get(MapFlag::NOSAVE)) ? "True" : "False"); + output = STRPRINTF("No Save: %s"_fmt, + (m_id->flag.get(MapFlag::NOSAVE)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("Re Save: %s", - (m_id->flag.get(MapFlag::RESAVE)) ? "True" : "False"); + output = STRPRINTF("Re Save: %s"_fmt, + (m_id->flag.get(MapFlag::RESAVE)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Teleport: %s", - (m_id->flag.get(MapFlag::NOTELEPORT)) ? "True" : "False"); + output = STRPRINTF("No Teleport: %s"_fmt, + (m_id->flag.get(MapFlag::NOTELEPORT)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Monster Teleport: %s", - (m_id->flag.get(MapFlag::MONSTER_NOTELEPORT)) ? "True" : "False"); + output = STRPRINTF("No Monster Teleport: %s"_fmt, + (m_id->flag.get(MapFlag::MONSTER_NOTELEPORT)) ? "True"_s : "False"_s); clif_displaymessage(s, output); switch (list) @@ -3499,7 +3499,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, // Do nothing. It's list 0, no additional display. break; case 1: - clif_displaymessage(s, "----- Players in Map -----"); + clif_displaymessage(s, "----- Players in Map -----"_s); for (io::FD i : iter_fds()) { Session *s2 = get_session(i); @@ -3510,54 +3510,54 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, && pl_sd->mapname_ == map_name) { output = STRPRINTF( - "Player '%s' (session #%d) | Location: %d,%d", + "Player '%s' (session #%d) | Location: %d,%d"_fmt, pl_sd->status_key.name, s2, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); } } break; case 2: - clif_displaymessage(s, "----- NPCs in Map -----"); + clif_displaymessage(s, "----- NPCs in Map -----"_s); for (int i = 0; i < m_id->npc_num;) { nd = m_id->npc[i]; switch (nd->dir) { case DIR::S: - direction = "North"; + direction = "North"_s; break; case DIR::SW: - direction = "North West"; + direction = "North West"_s; break; case DIR::W: - direction = "West"; + direction = "West"_s; break; case DIR::NW: - direction = "South West"; + direction = "South West"_s; break; case DIR::N: - direction = "South"; + direction = "South"_s; break; case DIR::NE: - direction = "South East"; + direction = "South East"_s; break; case DIR::E: - direction = "East"; + direction = "East"_s; break; case DIR::SE: - direction = "North East"; + direction = "North East"_s; break; #if 0 case 9: - direction = "North"; + direction = "North"_s; break; #endif default: - direction = "Unknown"; + direction = "Unknown"_s; break; } output = STRPRINTF( - "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d", + "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d"_fmt, ++i, nd->name, direction, nd->npc_class, nd->bl_x, nd->bl_y); clif_displaymessage(s, output); @@ -3566,7 +3566,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, default: // normally impossible to arrive here clif_displaymessage(s, - "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."); + "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."_s); return ATCE::USAGE; } @@ -3590,19 +3590,19 @@ ATCE atcommand_partyspy(Session *s, dumb_ptr<map_session_data> sd, if (sd->partyspy == p->party_id) { sd->partyspy = 0; - AString output = STRPRINTF("No longer spying on the %s party.", p->name); + AString output = STRPRINTF("No longer spying on the %s party."_fmt, p->name); clif_displaymessage(s, output); } else { sd->partyspy = p->party_id; - AString output = STRPRINTF("Spying on the %s party.", p->name); + AString output = STRPRINTF("Spying on the %s party."_fmt, p->name); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."_s); return ATCE::EXIST; } @@ -3621,11 +3621,11 @@ ATCE atcommand_enablenpc(Session *s, dumb_ptr<map_session_data>, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 1); - clif_displaymessage(s, "Npc Enabled."); + clif_displaymessage(s, "Npc Enabled."_s); } else { - clif_displaymessage(s, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."_s); return ATCE::EXIST; } @@ -3644,11 +3644,11 @@ ATCE atcommand_disablenpc(Session *s, dumb_ptr<map_session_data>, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 0); - clif_displaymessage(s, "Npc Disabled."); + clif_displaymessage(s, "Npc Disabled."_s); } else { - clif_displaymessage(s, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."_s); return ATCE::EXIST; } @@ -3661,7 +3661,7 @@ ATCE atcommand_servertime(Session *s, dumb_ptr<map_session_data>, { timestamp_seconds_buffer tsbuf; stamp_time(tsbuf); - AString temp = STRPRINTF("Server time: %s", tsbuf); + AString temp = STRPRINTF("Server time: %s"_fmt, tsbuf); clif_displaymessage(s, temp); return ATCE::OKAY; @@ -3707,37 +3707,37 @@ ATCE atcommand_chardelitem(Session *s, dumb_ptr<map_session_data> sd, // for next loop } AString output = STRPRINTF( - "%d item(s) removed by a GM.", + "%d item(s) removed by a GM."_fmt, count); clif_displaymessage(pl_sd->sess, output); if (number == count) - output = STRPRINTF("%d item(s) removed from the player.", count); + output = STRPRINTF("%d item(s) removed from the player."_fmt, count); else - output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number); + output = STRPRINTF("%d item(s) removed. Player had only %d on %d items."_fmt, count, count, number); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character does not have the item."); + clif_displaymessage(s, "Character does not have the item."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."_s); return ATCE::RANGE; } @@ -3751,7 +3751,7 @@ ATCE atcommand_broadcast(Session *, dumb_ptr<map_session_data> sd, if (!message) return ATCE::USAGE; - AString output = STRPRINTF("%s : %s", sd->status_key.name, message); + AString output = STRPRINTF("%s : %s"_fmt, sd->status_key.name, message); intif_GMmessage(output); return ATCE::OKAY; @@ -3764,7 +3764,7 @@ ATCE atcommand_localbroadcast(Session *, dumb_ptr<map_session_data> sd, if (!message) return ATCE::USAGE; - AString output = STRPRINTF("%s : %s", sd->status_key.name, message); + AString output = STRPRINTF("%s : %s"_fmt, sd->status_key.name, message); clif_GMmessage(sd, output, 1); @@ -3783,28 +3783,28 @@ ATCE atcommand_email(Session *s, dumb_ptr<map_session_data> sd, if (!e_mail_check(actual_email)) { - clif_displaymessage(s, "Invalid actual email. If you have default e-mail, type a@a.com."); + clif_displaymessage(s, "Invalid actual email. If you have default e-mail, type a@a.com."_s); return ATCE::RANGE; } else if (!e_mail_check(new_email)) { - clif_displaymessage(s, "Invalid new email. Please enter a real e-mail."); + clif_displaymessage(s, "Invalid new email. Please enter a real e-mail."_s); return ATCE::RANGE; } else if (new_email == DEFAULT_EMAIL) { - clif_displaymessage(s, "New email must be a real e-mail."); + clif_displaymessage(s, "New email must be a real e-mail."_s); return ATCE::RANGE; } else if (actual_email == new_email) { - clif_displaymessage(s, "New email must be different of the actual e-mail."); + clif_displaymessage(s, "New email must be different of the actual e-mail."_s); return ATCE::RANGE; } else { chrif_changeemail(sd->status_key.account_id, actual_email, new_email); - clif_displaymessage(s, "Information sended to login-server via char-server."); + clif_displaymessage(s, "Information sended to login-server via char-server."_s); } return ATCE::OKAY; @@ -3821,7 +3821,7 @@ ATCE atcommand_effect(Session *s, dumb_ptr<map_session_data> sd, if (flag <= 0) { clif_specialeffect(sd, type, flag); - clif_displaymessage(s, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."_s); } else { @@ -3834,7 +3834,7 @@ ATCE atcommand_effect(Session *s, dumb_ptr<map_session_data> sd, if (pl_sd && pl_sd->state.auth) { clif_specialeffect(pl_sd, type, flag); - clif_displaymessage(pl_sd->sess, "Your Effect Has Changed."); + clif_displaymessage(pl_sd->sess, "Your Effect Has Changed."_s); } } } @@ -3873,7 +3873,7 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, if (count == 1) { AString output = STRPRINTF( - "------ Items list of '%s' ------", + "------ Items list of '%s' ------"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); } @@ -3881,35 +3881,35 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, MString equipstr; if (bool(equip)) { - equipstr += "| equiped: "; + equipstr += "| equiped: "_s; if (bool(equip & EPOS::GLOVES)) - equipstr += "robe/gargment, "; + equipstr += "robe/gargment, "_s; if (bool(equip & EPOS::CAPE)) - equipstr += "left accessory, "; + equipstr += "left accessory, "_s; if (bool(equip & EPOS::MISC1)) - equipstr += "body/armor, "; + equipstr += "body/armor, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::WEAPON) - equipstr += "right hand, "; + equipstr += "right hand, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::SHIELD) - equipstr += "left hand, "; + equipstr += "left hand, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == (EPOS::WEAPON | EPOS::SHIELD)) - equipstr += "both hands, "; + equipstr += "both hands, "_s; if (bool(equip & EPOS::SHOES)) - equipstr += "feet, "; + equipstr += "feet, "_s; if (bool(equip & EPOS::MISC2)) - equipstr += "right accessory, "; + equipstr += "right accessory, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::LEGS) - equipstr += "lower head, "; + equipstr += "lower head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::HAT) - equipstr += "top head, "; + equipstr += "top head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::HAT | EPOS::LEGS)) - equipstr += "lower/top head, "; + equipstr += "lower/top head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::TORSO) - equipstr += "mid head, "; + equipstr += "mid head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::LEGS)) - equipstr += "lower/mid head, "; + equipstr += "lower/mid head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) - equipstr += "lower/mid/top head, "; + equipstr += "lower/mid/top head, "_s; // remove final ', ' equipstr.pop_back(2); } @@ -3918,7 +3918,7 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, AString output; if (true) - output = STRPRINTF("%d %s (%s, id: %d) %s", + output = STRPRINTF("%d %s (%s, id: %d) %s"_fmt, pl_sd->status.inventory[i].amount, item_data->name, item_data->jname, pl_sd->status.inventory[i].nameid, @@ -3929,24 +3929,24 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, } } if (count == 0) - clif_displaymessage(s, "No item found on this player."); + clif_displaymessage(s, "No item found on this player."_s); else { AString output = STRPRINTF( - "%d item(s) found in %d kind(s) of items.", + "%d item(s) found in %d kind(s) of items."_fmt, counter, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3986,13 +3986,13 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr<map_session_data> sd, if (count == 1) { AString output = STRPRINTF( - "------ Storage items list of '%s' ------", + "------ Storage items list of '%s' ------"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); } AString output; if (true) - output = STRPRINTF("%d %s (%s, id: %d)", + output = STRPRINTF("%d %s (%s, id: %d)"_fmt, stor->storage_[i].amount, item_data->name, item_data->jname, stor->storage_[i].nameid); @@ -4001,30 +4001,30 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) clif_displaymessage(s, - "No item found in the storage of this player."); + "No item found in the storage of this player."_s); else { AString output = STRPRINTF( - "%d item(s) found in %d kind(s) of items.", + "%d item(s) found in %d kind(s) of items."_fmt, counter, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "This player has no storage."); + clif_displaymessage(s, "This player has no storage."_s); return ATCE::OKAY; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4038,9 +4038,9 @@ ATCE atcommand_killer(Session *s, dumb_ptr<map_session_data> sd, sd->special_state.killer = !sd->special_state.killer; if (sd->special_state.killer) - clif_displaymessage(s, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."_s); else - clif_displaymessage(s, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."_s); return ATCE::OKAY; } @@ -4062,13 +4062,13 @@ ATCE atcommand_charkiller(Session *s, dumb_ptr<map_session_data>, if (pl_sd->special_state.killer) { - clif_displaymessage(s, "The player is now a killer"); - clif_displaymessage(pl_sd->sess, "You are now a killer"); + clif_displaymessage(s, "The player is now a killer"_s); + clif_displaymessage(pl_sd->sess, "You are now a killer"_s); } else { - clif_displaymessage(s, "The player is no longer a killer"); - clif_displaymessage(pl_sd->sess, "You are no longer a killer"); + clif_displaymessage(s, "The player is no longer a killer"_s); + clif_displaymessage(pl_sd->sess, "You are no longer a killer"_s); } return ATCE::OKAY; @@ -4081,9 +4081,9 @@ ATCE atcommand_killable(Session *s, dumb_ptr<map_session_data> sd, sd->special_state.killable = !sd->special_state.killable; if (sd->special_state.killable) - clif_displaymessage(s, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."_s); else - clif_displaymessage(s, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."_s); return ATCE::OKAY; } @@ -4104,9 +4104,9 @@ ATCE atcommand_charkillable(Session *s, dumb_ptr<map_session_data>, pl_sd->special_state.killable = !pl_sd->special_state.killable; if (pl_sd->special_state.killable) - clif_displaymessage(s, "The player is now killable"); + clif_displaymessage(s, "The player is now killable"_s); else - clif_displaymessage(s, "The player is no longer killable"); + clif_displaymessage(s, "The player is no longer killable"_s); return ATCE::OKAY; } @@ -4146,17 +4146,17 @@ ATCE atcommand_addwarp(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, record<' '>(&mapname, &x, &y))) return ATCE::USAGE; - AString w1 = STRPRINTF("%s,%d,%d", sd->mapname_, sd->bl_x, sd->bl_y); - AString w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl_x, sd->bl_y, x, y); - AString w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y); + AString w1 = STRPRINTF("%s,%d,%d"_fmt, sd->mapname_, sd->bl_x, sd->bl_y); + AString w3 = STRPRINTF("%s%d%d%d%d"_fmt, mapname, sd->bl_x, sd->bl_y, x, y); + AString w4 = STRPRINTF("1,1,%s.gat,%d,%d"_fmt, mapname, x, y); NpcName w3name = stringish<NpcName>(w3); - int ret = npc_parse_warp(w1, ZString("warp"), w3name, w4); + int ret = npc_parse_warp(w1, "warp"_s, w3name, w4); if (ret) // warp failed return ATCE::RANGE; - AString output = STRPRINTF("New warp NPC => %s", w3); + AString output = STRPRINTF("New warp NPC => %s"_fmt, w3); clif_displaymessage(s, output); return ATCE::OKAY; @@ -4177,7 +4177,7 @@ ATCE atcommand_chareffect(Session *s, dumb_ptr<map_session_data>, return ATCE::EXIST; clif_specialeffect(pl_sd, type, 0); - clif_displaymessage(s, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."_s); return ATCE::OKAY; } @@ -4220,9 +4220,8 @@ ATCE atcommand_chardropall(Session *s, dumb_ptr<map_session_data>, } } - clif_displaymessage(pl_sd->sess, "Ever play 52 card pickup?"); - clif_displaymessage(s, "It is done"); - //clif_displaymessage(s, "It is offical.. your a jerk"); + clif_displaymessage(pl_sd->sess, "Ever play 52 card pickup?"_s); + clif_displaymessage(s, "It is official.. you're a jerk."_s); return ATCE::OKAY; } @@ -4240,12 +4239,12 @@ ATCE atcommand_storeall(Session *s, dumb_ptr<map_session_data> sd, { case 2: //Try again - clif_displaymessage(s, "run this command again.."); + clif_displaymessage(s, "run this command again.."_s); return ATCE::OKAY; case 1: //Failure clif_displaymessage(s, - "You can't open the storage currently."); + "You can't open the storage currently."_s); return ATCE::EXIST; } } @@ -4260,7 +4259,7 @@ ATCE atcommand_storeall(Session *s, dumb_ptr<map_session_data> sd, } storage_storageclose(sd); - clif_displaymessage(s, "It is done"); + clif_displaymessage(s, "It is done"_s); return ATCE::OKAY; } @@ -4281,8 +4280,8 @@ ATCE atcommand_charstoreall(Session *s, dumb_ptr<map_session_data> sd, // TODO figure out what the hell this is talking about, // and especially why it's different from the other one. clif_displaymessage(s, - "Had to open the characters storage window..."); - clif_displaymessage(s, "run this command again.."); + "Had to open the characters storage window..."_s); + clif_displaymessage(s, "run this command again.."_s); return ATCE::OKAY; } for (int i = 0; i < MAX_INVENTORY; i++) @@ -4297,12 +4296,12 @@ ATCE atcommand_charstoreall(Session *s, dumb_ptr<map_session_data> sd, storage_storageclose(pl_sd); clif_displaymessage(pl_sd->sess, - "Everything you own has been put away for safe keeping."); + "Everything you own has been put away for safe keeping."_s); clif_displaymessage(pl_sd->sess, - "go to the nearest kafka to retrieve it.."); - clif_displaymessage(pl_sd->sess, " -- the management"); + "go to the nearest kafka to retrieve it.."_s); + clif_displaymessage(pl_sd->sess, " -- the management"_s); - clif_displaymessage(s, "It is done"); + clif_displaymessage(s, "It is done"_s); return ATCE::OKAY; } @@ -4425,7 +4424,7 @@ ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr<map_session_data>, if (!extract(message, record<' '>(&newlev, &cmd))) { - clif_displaymessage(s, "usage: @adjcmdlvl <lvl> <command>."); + clif_displaymessage(s, "usage: @adjcmdlvl <lvl> <command>."_s); return ATCE::USAGE; } @@ -4434,12 +4433,12 @@ ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr<map_session_data>, if (it) { it->level = newlev; - clif_displaymessage(s, "@command level changed."); + clif_displaymessage(s, "@command level changed."_s); return ATCE::OKAY; } } - clif_displaymessage(s, "@command not found."); + clif_displaymessage(s, "@command not found."_s); return ATCE::EXIST; } @@ -4453,7 +4452,7 @@ ATCE atcommand_adjgmlvl(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &newlev, &user) || newlev < 0 || newlev > 99) { - clif_displaymessage(s, "usage: @adjgmlvl <lvl> <user>."); + clif_displaymessage(s, "usage: @adjgmlvl <lvl> <user>."_s); return ATCE::USAGE; } @@ -4501,14 +4500,14 @@ constexpr size_t magic_skills_nr = sizeof(magic_skills) / sizeof(magic_skills[0]); static -ZString magic_skill_names[magic_skills_nr] = +LString magic_skill_names[magic_skills_nr] = { - {"magic"}, - {"life"}, - {"war"}, - {"transmute"}, - {"nature"}, - {"astral"}, + "magic"_s, + "life"_s, + "war"_s, + "transmute"_s, + "nature"_s, + "astral"_s, }; static @@ -4524,7 +4523,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, if (pl_sd) { AString buf = STRPRINTF( - "`%s' has the following magic skills:", + "`%s' has the following magic skills:"_fmt, character); clif_displaymessage(s, buf); @@ -4532,7 +4531,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, { SkillID sk = magic_skills[i]; buf = STRPRINTF( - "%d in %s", + "%d in %s"_fmt, pl_sd->status.skill[sk].lv, magic_skill_names[i]); if (pl_sd->status.skill[sk].lv) @@ -4542,7 +4541,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, return ATCE::OKAY; } - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4563,12 +4562,12 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &magic_type, &value, &character)) { clif_displaymessage(s, - "Usage: @setmagic <school> <value> <char-name>, where <school> is either `magic', one of the school names, or `all'."); + "Usage: @setmagic <school> <value> <char-name>, where <school> is either `magic', one of the school names, or `all'."_s); return ATCE::USAGE; } SkillID skill_index = SkillID::NEGATIVE; - if ("all" == magic_type) + if ("all"_s == magic_type) skill_index = SkillID::ZERO; else { @@ -4585,7 +4584,7 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, if (skill_index == SkillID::NEGATIVE) { clif_displaymessage(s, - "Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'."); + "Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'."_s); return ATCE::RANGE; } @@ -4602,7 +4601,7 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, return ATCE::OKAY; } - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4664,18 +4663,18 @@ ATCE atcommand_jump_iterate(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to the map of this player."); + "You are not authorised to warp you to the map of this player."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, pl_sd->bl_m->name_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %s", pl_sd->status_key.name); + AString output = STRPRINTF("Jump to %s"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); sd->followtarget = pl_sd->bl_id; @@ -4702,9 +4701,9 @@ ATCE atcommand_wgm(Session *s, dumb_ptr<map_session_data> sd, if (tmw_CheckChatSpam(sd, message)) return ATCE::OKAY; - tmw_GmHackMsg(STRPRINTF("[GM] %s: %s", sd->status_key.name, message)); + tmw_GmHackMsg(STRPRINTF("[GM] %s: %s"_fmt, sd->status_key.name, message)); if (!pc_isGM(sd)) - clif_displaymessage(s, "Message sent."); + clif_displaymessage(s, "Message sent."_s); return ATCE::OKAY; } @@ -4727,19 +4726,19 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, int i; AString buf = STRPRINTF( - "Active skills %d out of %d for %s:", + "Active skills %d out of %d for %s:"_fmt, pool_skills_nr, skill_pool_max(pl_sd), character); clif_displaymessage(s, buf); for (i = 0; i < pool_skills_nr; ++i) { - buf = STRPRINTF(" - %s [%d]: power %d", + buf = STRPRINTF(" - %s [%d]: power %d"_fmt, skill_name(pool_skills[i]), pool_skills[i], skill_power(pl_sd, pool_skills[i])); clif_displaymessage(s, buf); } - buf = STRPRINTF("Learned skills out of %d for %s:", + buf = STRPRINTF("Learned skills out of %d for %s:"_fmt, skill_pool_skills_size, character); clif_displaymessage(s, buf); @@ -4750,7 +4749,7 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, if (lvl) { - buf = STRPRINTF(" - %s [%d]: lvl %d", + buf = STRPRINTF(" - %s [%d]: lvl %d"_fmt, name, skill_pool_skills[i], lvl); clif_displaymessage(s, buf); } @@ -4759,7 +4758,7 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4775,7 +4774,7 @@ ATCE atcommand_skillpool_focus(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &skill, &character)) { - clif_displaymessage(s, "Usage: @sp-focus <skill-nr> <char_name>"); + clif_displaymessage(s, "Usage: @sp-focus <skill-nr> <char_name>"_s); return ATCE::USAGE; } @@ -4783,12 +4782,12 @@ ATCE atcommand_skillpool_focus(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { if (skill_pool_activate(pl_sd, skill)) - clif_displaymessage(s, "Activation failed."); + clif_displaymessage(s, "Activation failed."_s); else - clif_displaymessage(s, "Activation successful."); + clif_displaymessage(s, "Activation successful."_s); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4807,12 +4806,12 @@ ATCE atcommand_skillpool_unfocus(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { if (skill_pool_deactivate(pl_sd, skill)) - clif_displaymessage(s, "Deactivation failed."); + clif_displaymessage(s, "Deactivation failed."_s); else - clif_displaymessage(s, "Deactivation successful."); + clif_displaymessage(s, "Deactivation successful."_s); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4835,7 +4834,7 @@ ATCE atcommand_skill_learn(Session *s, dumb_ptr<map_session_data>, clif_skillinfoblock(pl_sd); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4852,7 +4851,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, dumb_ptr<map_session_data> pl_sd = map_nick2sd(character); if (pl_sd == NULL) { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4873,7 +4872,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, if (ip == pl_sd->get_ip()) { AString output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -4881,7 +4880,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, } } - clif_displaymessage(s, "End of list"); + clif_displaymessage(s, "End of list"_s); return ATCE::OKAY; } @@ -4902,10 +4901,10 @@ ATCE atcommand_doomspot(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -4915,13 +4914,13 @@ ATCE atcommand_source(Session *s, dumb_ptr<map_session_data>, ZString) { clif_displaymessage(s, - "This server code consists of Free Software under GPL3&AGPL3"); + "This server code consists of Free Software under GPL3&AGPL3"_s); clif_displaymessage(s, - "This is commit " VERSION_HASH ", also known as " VERSION_FULL); + "This is commit " VERSION_HASH ", also known as " VERSION_FULL ""_s); clif_displaymessage(s, - "The version is " VERSION_STRING); + "The version is " VERSION_STRING ""_s); clif_displaymessage(s, - "For source, see " VENDOR_SOURCE); + "For source, see " VENDOR_SOURCE ""_s); return ATCE::OKAY; } @@ -4931,424 +4930,424 @@ ATCE atcommand_source(Session *s, dumb_ptr<map_session_data>, // declared extern above Map<XString, AtCommandInfo> atcommand_info = { - {"help", {"[level[-level]|category|@command]", + {"help"_s, {"[level[-level]|category|@command]"_s, 0, atcommand_help, - "Show help"}}, - {"setup", {"<level> <charname>", + "Show help"_s}}, + {"setup"_s, {"<level> <charname>"_s, 40, atcommand_setup, - "Safely set a chars levels and warp them to a special place (for TAW)"}}, - {"charwarp", {"<mapname> <x> <y> <charname>", + "Safely set a chars levels and warp them to a special place (for TAW)"_s}}, + {"charwarp"_s, {"<mapname> <x> <y> <charname>"_s, 60, atcommand_charwarp, - "Warp a character to a point on another map"}}, - {"warp", {"<mapname> [x] [y]", + "Warp a character to a point on another map"_s}}, + {"warp"_s, {"<mapname> [x] [y]"_s, 40, atcommand_warp, - "Warp yourself to another map"}}, - {"where", {"[charname]", + "Warp yourself to another map"_s}}, + {"where"_s, {"[charname]"_s, 40, atcommand_where, - "Show location of a character or yourself"}}, - {"goto", {"<charname>", + "Show location of a character or yourself"_s}}, + {"goto"_s, {"<charname>"_s, 40, atcommand_goto, - "Warp yourself to another character"}}, - {"jump", {"[x] [y]", + "Warp yourself to another character"_s}}, + {"jump"_s, {"[x] [y]"_s, 40, atcommand_jump, - "Warp yourself within a map"}}, - {"who", {"[subsequence]", + "Warp yourself within a map"_s}}, + {"who"_s, {"[subsequence]"_s, 40, atcommand_who, - "List matching players online, with location info"}}, - {"whogroup", {"[subsequence]", + "List matching players online, with location info"_s}}, + {"whogroup"_s, {"[subsequence]"_s, 40, atcommand_whogroup, - "List matching players online, with party info"}}, - {"whomap", {"[mapname]", + "List matching players online, with party info"_s}}, + {"whomap"_s, {"[mapname]"_s, 40, atcommand_whomap, - "List all players on the map, with location info"}}, - {"whomapgroup", {"[mapname]", + "List all players on the map, with location info"_s}}, + {"whomapgroup"_s, {"[mapname]"_s, 40, atcommand_whomapgroup, - "List all players on the map, with party info"}}, - {"whogm", {"[subsequence]", + "List all players on the map, with party info"_s}}, + {"whogm"_s, {"[subsequence]"_s, 40, atcommand_whogm, - "List matching GM players, with location, level, and party info"}}, - {"save", {"", + "List matching GM players, with location, level, and party info"_s}}, + {"save"_s, {""_s, 40, atcommand_save, - "Set your respawn point to your current location"}}, - {"return", {"", + "Set your respawn point to your current location"_s}}, + {"return"_s, {""_s, 40, atcommand_load, - "Return to your respawn point"}}, - {"load", {"", + "Return to your respawn point"_s}}, + {"load"_s, {""_s, 40, atcommand_load, - "Return to your respawn point"}}, - {"speed", {"<rate>", + "Return to your respawn point"_s}}, + {"speed"_s, {"<rate>"_s, 60, atcommand_speed, - "Set walk rate"}}, - {"storage", {"", + "Set walk rate"_s}}, + {"storage"_s, {""_s, 99, atcommand_storage, - "Open your storage"}}, - {"option", {"<opt1> [opt2] [option]", + "Open your storage"_s}}, + {"option"_s, {"<opt1> [opt2] [option]"_s, 80, atcommand_option, - "Set your 'option' status flags"}}, - {"hide", {"", + "Set your 'option' status flags"_s}}, + {"hide"_s, {""_s, 40, atcommand_hide, - "Toggle invisibility from monsters and certain commands"}}, - {"die", {"", + "Toggle invisibility from monsters and certain commands"_s}}, + {"die"_s, {""_s, 40, atcommand_die, - "Cause fatal damage to yourself"}}, - {"kill", {"<charname>", + "Cause fatal damage to yourself"_s}}, + {"kill"_s, {"<charname>"_s, 60, atcommand_kill, - "Cause fatal damage to another player"}}, - {"alive", {"", + "Cause fatal damage to another player"_s}}, + {"alive"_s, {""_s, 60, atcommand_alive, - "Restore life to yourself"}}, - {"kami", {"<message ...>", + "Restore life to yourself"_s}}, + {"kami"_s, {"<message ...>"_s, 99, atcommand_kami, - "Send an anonymous broadcast"}}, - {"heal", {"[hp] [sp]", + "Send an anonymous broadcast"_s}}, + {"heal"_s, {"[hp] [sp]"_s, 40, atcommand_heal, - "Restore or destroy your health"}}, - {"item", {"<item-name-or-id> [count]", + "Restore or destroy your health"_s}}, + {"item"_s, {"<item-name-or-id> [count]"_s, 80, atcommand_item, - "Summon items out of the void"}}, - {"itemreset", {"", + "Summon items out of the void"_s}}, + {"itemreset"_s, {""_s, 40, atcommand_itemreset, - "Cast all of your itens into the void (why would you ever want this?)"}}, - {"itemcheck", {"", + "Cast all of your itens into the void (why would you ever want this?)"_s}}, + {"itemcheck"_s, {""_s, 80, atcommand_itemcheck, - "Perform an internal integrity check on your items"}}, - {"blvl", {"<delta>", + "Perform an internal integrity check on your items"_s}}, + {"blvl"_s, {"<delta>"_s, 60, atcommand_baselevelup, - "Adjust your level"}}, - {"jlvl", {"<delta>", + "Adjust your level"_s}}, + {"jlvl"_s, {"<delta>"_s, 60, atcommand_joblevelup, - "Adjust your job level"}}, - {"gm", {"<password>", + "Adjust your job level"_s}}, + {"gm"_s, {"<password>"_s, 100, atcommand_gm, - "Receive GM powers"}}, - {"pvpoff", {"", + "Receive GM powers"_s}}, + {"pvpoff"_s, {""_s, 60, atcommand_pvpoff, - "Enable PvP on your map"}}, - {"pvpon", {"", + "Enable PvP on your map"_s}}, + {"pvpon"_s, {""_s, 60, atcommand_pvpon, - "Disable PvP on your map"}}, - {"model", {"<style> [color] [dye]", + "Disable PvP on your map"_s}}, + {"model"_s, {"<style> [color] [dye]"_s, 99, atcommand_model, - "Change your hairstyle and hair color"}}, - {"spawn", {"<mob-name-or-id> [count] [x] [y]", + "Change your hairstyle and hair color"_s}}, + {"spawn"_s, {"<mob-name-or-id> [count] [x] [y]"_s, 50, atcommand_spawn, - "Spawn normal monsters at location."}}, - {"killmonster", {"[map]", + "Spawn normal monsters at location."_s}}, + {"killmonster"_s, {"[map]"_s, 60, atcommand_killmonster, - "Kill all monsters (with drops)"}}, - {"killmonster2", {"[map]", + "Kill all monsters (with drops)"_s}}, + {"killmonster2"_s, {"[map]"_s, 60, atcommand_killmonster2, - "Kill all monsters (no drops)"}}, - {"gat", {"", + "Kill all monsters (no drops)"_s}}, + {"gat"_s, {""_s, 99, atcommand_gat, - "Dump the local walkmap"}}, - {"packet", {"<type> <flag>", + "Dump the local walkmap"_s}}, + {"packet"_s, {"<type> <flag>"_s, 99, atcommand_packet, - "Force a status change"}}, - {"stpoint", {"<amount>", + "Force a status change"_s}}, + {"stpoint"_s, {"<amount>"_s, 60, atcommand_statuspoint, - "Increase your stat points"}}, - {"skpoint", {"<amount>", + "Increase your stat points"_s}}, + {"skpoint"_s, {"<amount>"_s, 60, atcommand_skillpoint, - "Increase your skill points"}}, - {"zeny", {"<amount>", + "Increase your skill points"_s}}, + {"zeny"_s, {"<amount>"_s, 80, atcommand_zeny, - "Change how much money you have"}}, - {"str", {"<delta>", + "Change how much money you have"_s}}, + {"str"_s, {"<delta>"_s, 60, atcommand_param<ATTR::STR>, - "Adjust your strength"}}, - {"agi", {"<delta>", + "Adjust your strength"_s}}, + {"agi"_s, {"<delta>"_s, 60, atcommand_param<ATTR::AGI>, - "Adjust your agility"}}, - {"vit", {"<delta>", + "Adjust your agility"_s}}, + {"vit"_s, {"<delta>"_s, 60, atcommand_param<ATTR::VIT>, - "Adjust your vitality"}}, - {"int", {"<delta>", + "Adjust your vitality"_s}}, + {"int"_s, {"<delta>"_s, 60, atcommand_param<ATTR::INT>, - "Adjust your intelligence\0(TODO make this work in real life, I'm lonely)"}}, - {"dex", {"<delta>", + "Adjust your intelligence\0(TODO make this work in real life, I'm lonely)"_s}}, + {"dex"_s, {"<delta>"_s, 60, atcommand_param<ATTR::DEX>, - "Adjust your dexterity"}}, - {"luk", {"<delta>", + "Adjust your dexterity"_s}}, + {"luk"_s, {"<delta>"_s, 60, atcommand_param<ATTR::LUK>, - "Adjust your luck"}}, - {"recall", {"<charname>", + "Adjust your luck"_s}}, + {"recall"_s, {"<charname>"_s, 60, atcommand_recall, - "Warp a player to you"}}, - {"revive", {"<charname>", + "Warp a player to you"_s}}, + {"revive"_s, {"<charname>"_s, 60, atcommand_revive, - "Restore a player to full health"}}, - {"charstats", {"<charname>", + "Restore a player to full health"_s}}, + {"charstats"_s, {"<charname>"_s, 40, atcommand_character_stats, - "Show a bunch of stats about a single user"}}, - {"charstatsall", {"", + "Show a bunch of stats about a single user"_s}}, + {"charstatsall"_s, {""_s, 60, atcommand_character_stats_all, - "Show a bunch of stats about all online users"}}, - {"charoption", {"<opt1> <opt2> <opt3> <charname>", + "Show a bunch of stats about all online users"_s}}, + {"charoption"_s, {"<opt1> <opt2> <opt3> <charname>"_s, 80, atcommand_character_option, - "Set option flags on another character"}}, - {"charsave", {"<map> <x> <y> <charname>", + "Set option flags on another character"_s}}, + {"charsave"_s, {"<map> <x> <y> <charname>"_s, 60, atcommand_character_save, - "Set another character's save point"}}, - {"doom", {"", + "Set another character's save point"_s}}, + {"doom"_s, {""_s, 80, atcommand_doom, - "Kill everyone on the server"}}, - {"doommap", {"", + "Kill everyone on the server"_s}}, + {"doommap"_s, {""_s, 80, atcommand_doommap, - "Kill everyone on your map"}}, - {"raise", {"", + "Kill everyone on your map"_s}}, + {"raise"_s, {""_s, 80, atcommand_raise, - "Resurrect all players on the server"}}, - {"raisemap", {"", + "Resurrect all players on the server"_s}}, + {"raisemap"_s, {""_s, 80, atcommand_raisemap, - "Resurrect all players on your map"}}, - {"charbaselvl", {"<delta> <charname>", + "Resurrect all players on your map"_s}}, + {"charbaselvl"_s, {"<delta> <charname>"_s, 60, atcommand_character_baselevel, - "Adjust another character's level"}}, - {"charjlvl", {"<delta> <charname>", + "Adjust another character's level"_s}}, + {"charjlvl"_s, {"<delta> <charname>"_s, 60, atcommand_character_joblevel, - "Adjust another character's job level"}}, - {"kick", {"<charname>", + "Adjust another character's job level"_s}}, + {"kick"_s, {"<charname>"_s, 40, atcommand_kick, - "Transiently kick a player off the server"}}, - {"kickall", {"", + "Transiently kick a player off the server"_s}}, + {"kickall"_s, {""_s, 99, atcommand_kickall, - "Transiently kick all players off the server"}}, - {"questskill", {"<skill-id>", + "Transiently kick all players off the server"_s}}, + {"questskill"_s, {"<skill-id>"_s, 99, atcommand_questskill, - "Give yourself a quest (?) skill"}}, - {"charquestskill", {"<skill-id> <charname>", + "Give yourself a quest (?) skill"_s}}, + {"charquestskill"_s, {"<skill-id> <charname>"_s, 99, atcommand_charquestskill, - "Give another player a quest (?) skill"}}, - {"lostskill", {"<skill-id>", + "Give another player a quest (?) skill"_s}}, + {"lostskill"_s, {"<skill-id>"_s, 80, atcommand_lostskill, - "Take away one of your quest (?) skills"}}, - {"charlostskill", {"<skill-id> <charname>", + "Take away one of your quest (?) skills"_s}}, + {"charlostskill"_s, {"<skill-id> <charname>"_s, 99, atcommand_charlostskill, - "Take away one of another player's quest (?) skills"}}, - {"party", {"<name>", + "Take away one of another player's quest (?) skills"_s}}, + {"party"_s, {"<name>"_s, 99, atcommand_party, - "Create a new party"}}, - {"mapexit", {"", + "Create a new party"_s}}, + {"mapexit"_s, {""_s, 99, atcommand_mapexit, - "Try to kill the server kindly"}}, - {"idsearch", {"<item-subseq>", + "Try to kill the server kindly"_s}}, + {"idsearch"_s, {"<item-subseq>"_s, 80, atcommand_idsearch, - "Search for some items that might match"}}, - {"mapmove", {"<mapname> [x] [y]", + "Search for some items that might match"_s}}, + {"mapmove"_s, {"<mapname> [x] [y]"_s, 40, atcommand_warp, - "Warp to a different map"}}, - {"broadcast", {"<message ...>", + "Warp to a different map"_s}}, + {"broadcast"_s, {"<message ...>"_s, 40, atcommand_broadcast, - "Broadcast a message from you"}}, - {"localbroadcast", {"<message ...>", + "Broadcast a message from you"_s}}, + {"localbroadcast"_s, {"<message ...>"_s, 40, atcommand_localbroadcast, - "Broadcast a message from you locally"}}, - {"recallall", {"", + "Broadcast a message from you locally"_s}}, + {"recallall"_s, {""_s, 80, atcommand_recallall, - "Warp every online player to your current map"}}, - {"charskreset", {"<charname>", + "Warp every online player to your current map"_s}}, + {"charskreset"_s, {"<charname>"_s, 60, atcommand_charskreset, - "Reset a player's skill points"}}, - {"charstreset", {"<charname>", + "Reset a player's skill points"_s}}, + {"charstreset"_s, {"<charname>"_s, 60, atcommand_charstreset, - "Reset a player's stat points"}}, - {"charreset", {"<charname>", + "Reset a player's stat points"_s}}, + {"charreset"_s, {"<charname>"_s, 60, atcommand_charreset, - "Reset a player's skills, stats, and magic"}}, - {"charmodel", {"<hairstyle> <hair-color> <dye> <charname>", + "Reset a player's skills, stats, and magic"_s}}, + {"charmodel"_s, {"<hairstyle> <hair-color> <dye> <charname>"_s, 99, atcommand_charmodel, - "Change another character's appearance"}}, - {"charskpoint", {"<amount> <charname>", + "Change another character's appearance"_s}}, + {"charskpoint"_s, {"<amount> <charname>"_s, 60, atcommand_charskpoint, - "Adjust another player's skill points"}}, - {"charstpoint", {"<amount> <charname>", + "Adjust another player's skill points"_s}}, + {"charstpoint"_s, {"<amount> <charname>"_s, 60, atcommand_charstpoint, - "Adjust another player's stat points"}}, - {"charzeny", {"<delta> <charname>", + "Adjust another player's stat points"_s}}, + {"charzeny"_s, {"<delta> <charname>"_s, 80, atcommand_charzeny, - "Adjust another player's money"}}, - {"mapinfo", {"<0-2> [map]", + "Adjust another player's money"_s}}, + {"mapinfo"_s, {"<0-2> [map]"_s, 99, atcommand_mapinfo, - "Show some stats for the map. 1 also shows players, 2 also shows NPCs"}}, - {"dye", {"<dye>", + "Show some stats for the map. 1 also shows players, 2 also shows NPCs"_s}}, + {"dye"_s, {"<dye>"_s, 40, atcommand_dye, - "Don't use"}}, - {"ccolor", {"<dye>", + "Don't use"_s}}, + {"ccolor"_s, {"<dye>"_s, 40, atcommand_dye, - "Don't use"}}, - {"hairstyle", {"<style>", + "Don't use"_s}}, + {"hairstyle"_s, {"<style>"_s, 40, atcommand_hair_style, - "Change your hairstyle"}}, - {"haircolor", {"<color>", + "Change your hairstyle"_s}}, + {"haircolor"_s, {"<color>"_s, 40, atcommand_hair_color, - "Change your hair color"}}, - {"allstats", {"[value]", + "Change your hair color"_s}}, + {"allstats"_s, {"[value]"_s, 60, atcommand_all_stats, - "Adjust all stats by value (or maximum)"}}, - {"charchangesex", {"<charname>", + "Adjust all stats by value (or maximum)"_s}}, + {"charchangesex"_s, {"<charname>"_s, 60, atcommand_char_change_sex, - "Flip a characters sex and disconnect them"}}, - {"block", {"<charname>", + "Flip a characters sex and disconnect them"_s}}, + {"block"_s, {"<charname>"_s, 60, atcommand_char_block, - "Permanently block a player's account from the server"}}, - {"unblock", {"<charname>", + "Permanently block a player's account from the server"_s}}, + {"unblock"_s, {"<charname>"_s, 60, atcommand_char_unblock, - "Remove a permanent block from a player's account"}}, - {"ban", {"<timedelta> <charname>", + "Remove a permanent block from a player's account"_s}}, + {"ban"_s, {"<timedelta> <charname>"_s, 60, atcommand_char_ban, - "Ban a player's account from the server for a limited time"}}, - {"unban", {"<timedelta> <charname>", + "Ban a player's account from the server for a limited time"_s}}, + {"unban"_s, {"<timedelta> <charname>"_s, 60, atcommand_char_unban, - "Remove a limited ban from a player's account"}}, - {"partyspy", {"<party-name-or-id>", + "Remove a limited ban from a player's account"_s}}, + {"partyspy"_s, {"<party-name-or-id>"_s, 99, atcommand_partyspy, - "Listen to all chat within a party"}}, - {"partyrecall", {"<party-name-or-id>", + "Listen to all chat within a party"_s}}, + {"partyrecall"_s, {"<party-name-or-id>"_s, 99, atcommand_partyrecall, - "Warp all members of a party to you"}}, - {"enablenpc", {"<npc-name>", + "Warp all members of a party to you"_s}}, + {"enablenpc"_s, {"<npc-name>"_s, 80, atcommand_enablenpc, - "Enable an NPC for visibility"}}, - {"disablenpc", {"<npc-name>", + "Enable an NPC for visibility"_s}}, + {"disablenpc"_s, {"<npc-name>"_s, 80, atcommand_disablenpc, - "Disable an NPC for visibility"}}, - {"servertime", {"", + "Disable an NPC for visibility"_s}}, + {"servertime"_s, {""_s, 0, atcommand_servertime, - "Print the server's idea of the current time"}}, - {"chardelitem", {"<item-name-or-id> <count> <charname>", + "Print the server's idea of the current time"_s}}, + {"chardelitem"_s, {"<item-name-or-id> <count> <charname>"_s, 60, atcommand_chardelitem, - "Delete items from a player's inventory"}}, - {"listnearby", {"", + "Delete items from a player's inventory"_s}}, + {"listnearby"_s, {""_s, 40, atcommand_list_nearby, - "Print name of all nearby players"}}, - {"email", {"<actual@email> <new@email>", + "Print name of all nearby players"_s}}, + {"email"_s, {"<actual@email> <new@email>"_s, 0, atcommand_email, - "Changed your account's email"}}, - {"effect", {"<type> <flag>", + "Changed your account's email"_s}}, + {"effect"_s, {"<type> <flag>"_s, 99, atcommand_effect, - "Apply a special effect to yourself (or everyone! wtf?)"}}, - {"charitemlist", {"<charname>", + "Apply a special effect to yourself (or everyone! wtf?)"_s}}, + {"charitemlist"_s, {"<charname>"_s, 99, atcommand_character_item_list, - "List a player's items"}}, - {"charstoragelist", {"<charname>", + "List a player's items"_s}}, + {"charstoragelist"_s, {"<charname>"_s, 99, atcommand_character_storage_list, - "List a player's storage"}}, - {"addwarp", {"<mapname> <x> <y>", + "List a player's storage"_s}}, + {"addwarp"_s, {"<mapname> <x> <y>"_s, 80, atcommand_addwarp, - "Create a new permanent warp"}}, - {"killer", {"", + "Create a new permanent warp"_s}}, + {"killer"_s, {""_s, 60, atcommand_killer, - "Toggle whether you are a killer"}}, - {"charkiller", {"<charname>", + "Toggle whether you are a killer"_s}}, + {"charkiller"_s, {"<charname>"_s, 60, atcommand_charkiller, - "Toggle whether a player is a killer"}}, - {"npcmove", {"<x> <y> <npc-name>", + "Toggle whether a player is a killer"_s}}, + {"npcmove"_s, {"<x> <y> <npc-name>"_s, 80, atcommand_npcmove, - "Force an NPC to move on the map"}}, - {"killable", {"", + "Force an NPC to move on the map"_s}}, + {"killable"_s, {""_s, 60, atcommand_killable, - "Toggle whether you are killable"}}, - {"charkillable", {"<charname>", + "Toggle whether you are killable"_s}}, + {"charkillable"_s, {"<charname>"_s, 60, atcommand_charkillable, - "Toggle whether a player is killable"}}, - {"chareffect", {"<type> <target>", + "Toggle whether a player is killable"_s}}, + {"chareffect"_s, {"<type> <target>"_s, 40, atcommand_chareffect, - "Apply effect type with arg 0 to a player"}}, - {"dropall", {"", + "Apply effect type with arg 0 to a player"_s}}, + {"dropall"_s, {""_s, 99, atcommand_dropall, - "Drop all of your items"}}, - {"chardropall", {"<charname>", + "Drop all of your items"_s}}, + {"chardropall"_s, {"<charname>"_s, 60, atcommand_chardropall, - "Force a player to drop all of their items"}}, - {"storeall", {"", + "Force a player to drop all of their items"_s}}, + {"storeall"_s, {""_s, 60, atcommand_storeall, - "Store all of your items"}}, - {"charstoreall", {"<charname>", + "Store all of your items"_s}}, + {"charstoreall"_s, {"<charname>"_s, 60, atcommand_charstoreall, - "Store all of a player's items"}}, - {"rain", {"", + "Store all of a player's items"_s}}, + {"rain"_s, {""_s, 99, atcommand_rain, - "Enable the rain mapflag"}}, - {"snow", {"", + "Enable the rain mapflag"_s}}, + {"snow"_s, {""_s, 99, atcommand_snow, - "Enable the snow mapflag"}}, - {"sakura", {"", + "Enable the snow mapflag"_s}}, + {"sakura"_s, {""_s, 99, atcommand_sakura, - "Enable the sakura mapflag"}}, - {"fog", {"", + "Enable the sakura mapflag"_s}}, + {"fog"_s, {""_s, 99, atcommand_fog, - "Enable the fog mapflag"}}, - {"leaves", {"", + "Enable the fog mapflag"_s}}, + {"leaves"_s, {""_s, 99, atcommand_leaves, - "Enable the leaves mapflag"}}, - {"summon", {"<mob-id-or-name>", + "Enable the leaves mapflag"_s}}, + {"summon"_s, {"<mob-id-or-name>"_s, 50, atcommand_summon, - "Summon a slave monster temporarily"}}, - {"adjgmlvl", {"<level> <cmd>", + "Summon a slave monster temporarily"_s}}, + {"adjgmlvl"_s, {"<level> <cmd>"_s, 99, atcommand_adjgmlvl, - "Temporarily adjust the GM level of a command"}}, - {"adjcmdlvl", {"<level> <charname>", + "Temporarily adjust the GM level of a command"_s}}, + {"adjcmdlvl"_s, {"<level> <charname>"_s, 99, atcommand_adjcmdlvl, - "Temporarily adjust the GM level of a player"}}, - {"trade", {"<charname>", + "Temporarily adjust the GM level of a player"_s}}, + {"trade"_s, {"<charname>"_s, 60, atcommand_trade, - "Initiate trade with a player anywhere"}}, - {"charwipe", {"<charname>", + "Initiate trade with a player anywhere"_s}}, + {"charwipe"_s, {"<charname>"_s, 60, atcommand_char_wipe, - "Reset a character almost completely"}}, - {"setmagic", {"<school> <value> <charname>", + "Reset a character almost completely"_s}}, + {"setmagic"_s, {"<school> <value> <charname>"_s, 80, atcommand_set_magic, - "Force magic skill level"}}, - {"magicinfo", {"<charname>", + "Force magic skill level"_s}}, + {"magicinfo"_s, {"<charname>"_s, 80, atcommand_magic_info, - "Show magic skills of a palyer"}}, - {"log", {"<message ...>", + "Show magic skills of a palyer"_s}}, + {"log"_s, {"<message ...>"_s, 40, atcommand_log, - "Write something directly to the log"}}, - {"l", {"<message ...>", + "Write something directly to the log"_s}}, + {"l"_s, {"<message ...>"_s, 40, atcommand_log, - "Write something directly to the log"}}, - {"tee", {"<message ...>", + "Write something directly to the log"_s}}, + {"tee"_s, {"<message ...>"_s, 40, atcommand_tee, - "Duplicate a message to the log and public chat"}}, - {"t", {"<message ...>", + "Duplicate a message to the log and public chat"_s}}, + {"t"_s, {"<message ...>"_s, 40, atcommand_tee, - "Duplicate a message to the log and public chat"}}, - {"invisible", {"", + "Duplicate a message to the log and public chat"_s}}, + {"invisible"_s, {""_s, 50, atcommand_invisible, - "Make yourself invisible to players"}}, - {"visible", {"", + "Make yourself invisible to players"_s}}, + {"visible"_s, {""_s, 50, atcommand_visible, - "Make yourself visible to players"}}, - {"hugo", {"", + "Make yourself visible to players"_s}}, + {"hugo"_s, {""_s, 60, atcommand_iterate_forward_over_players, - "Jump to the next player"}}, - {"linus", {"", + "Jump to the next player"_s}}, + {"linus"_s, {""_s, 60, atcommand_iterate_backwards_over_players, - "Jump to the previous player"}}, - {"sp-info", {"<charname>", + "Jump to the previous player"_s}}, + {"sp-info"_s, {"<charname>"_s, 40, atcommand_skillpool_info, - "Show info about pool skills"}}, - {"sp-focus", {"<skill-id> <charname>", + "Show info about pool skills"_s}}, + {"sp-focus"_s, {"<skill-id> <charname>"_s, 80, atcommand_skillpool_focus, - "Focus on a pool skill"}}, - {"sp-unfocus", {"<skill-id> <charname>", + "Focus on a pool skill"_s}}, + {"sp-unfocus"_s, {"<skill-id> <charname>"_s, 80, atcommand_skillpool_unfocus, - "Unfocus off of a pool skill"}}, - {"skill-learn", {"<skill-id> <level> <charname>", + "Unfocus off of a pool skill"_s}}, + {"skill-learn"_s, {"<skill-id> <level> <charname>"_s, 80, atcommand_skill_learn, - "Change a skill level"}}, - {"wgm", {"<message ...>", + "Change a skill level"_s}}, + {"wgm"_s, {"<message ...>"_s, 0, atcommand_wgm, - "Send a message to online GMs"}}, - {"ipcheck", {"<charname>", + "Send a message to online GMs"_s}}, + {"ipcheck"_s, {"<charname>"_s, 60, atcommand_ipcheck, - "List players on the same IP address"}}, - {"doomspot", {"", + "List players on the same IP address"_s}}, + {"doomspot"_s, {""_s, 60, atcommand_doomspot, - "Kill all players on the same tile"}}, - {"source", {"", + "Kill all players on the same tile"_s}}, + {"source"_s, {""_s, 0, atcommand_source, - "Legal information about source code (must be a level 0 command!)"}}, + "Legal information about source code (must be a level 0 command!)"_s}}, }; diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 8e4d435..f67414f 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -1965,7 +1965,7 @@ struct Damage battle_calc_attack(BF attack_type, flag); default: if (battle_config.error_log) - PRINTF("battle_calc_attack: unknwon attack type ! %d\n", + PRINTF("battle_calc_attack: unknwon attack type ! %d\n"_fmt, attack_type); break; } @@ -2040,7 +2040,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, wd.damage -= reduction; MAP_LOG_PC(target->is_player(), - "MAGIC-ABSORB-DMG %d", reduction); + "MAGIC-ABSORB-DMG %d"_fmt, reduction); } { @@ -2064,9 +2064,9 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) weapon = sd->inventory_data[weapon_index]->nameid; - MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d", + MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d"_fmt, sd->status_key.char_id, src->bl_m->name_, src->bl_x, src->bl_y, - (target->bl_type == BL::PC) ? "PC" : "MOB", + (target->bl_type == BL::PC) ? "PC"_s : "MOB"_s, (target->bl_type == BL::PC) ? target->is_player()-> status_key.char_id : target->bl_id, @@ -2077,9 +2077,9 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, if (target->bl_type == BL::PC) { dumb_ptr<map_session_data> sd2 = target->is_player(); - MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d", + MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d"_fmt, sd2->status_key.char_id, target->bl_m->name_, target->bl_x, target->bl_y, - (src->bl_type == BL::PC) ? "PC" : "MOB", + (src->bl_type == BL::PC) ? "PC"_s : "MOB"_s, (src->bl_type == BL::PC) ? src->is_player()->status_key.char_id : src->bl_id, @@ -2246,9 +2246,6 @@ int battle_check_target(dumb_ptr<block_list> src, dumb_ptr<block_list> target, return 0; } -//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->bl_id,src->bl_id,target->bl_id,flag,src->bl_type,target->bl_type); -//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g); - if (ss->bl_type == BL::PC && target->bl_type == BL::PC) { // 両方PVPモードなら否定(敵) if (ss->bl_m->flag.get(MapFlag::PVP) @@ -2430,17 +2427,17 @@ bool battle_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("file not found: %s\n", cfgName); + PRINTF("file not found: %s\n"_fmt, cfgName); return false; } AString line; while (in.getline(line)) { -#define BATTLE_CONFIG_VAR(name) {{#name}, &battle_config.name} +#define BATTLE_CONFIG_VAR(name) {#name##_s, &battle_config.name} const struct { - ZString str; + LString str; int *val; } data[] = { @@ -2550,12 +2547,12 @@ bool battle_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } - if (w1 == "import") + if (w1 == "import"_s) { battle_config_read(w2); continue; @@ -2568,7 +2565,7 @@ bool battle_config_read(ZString cfgName) goto continue_outer; } - PRINTF("WARNING: unknown battle conf key: %s\n", AString(w1)); + PRINTF("WARNING: unknown battle conf key: %s\n"_fmt, AString(w1)); rv = false; continue_outer: diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index fa95be7..64fd547 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -209,7 +209,7 @@ int chrif_recvmap(Session *s) map_setipport(map, ip, port); } if (battle_config.etc_log) - PRINTF("recv map on %s:%d (%d maps)\n", + PRINTF("recv map on %s:%d (%d maps)\n"_fmt, ip, port, j); return 0; @@ -270,7 +270,7 @@ int chrif_changemapserverack(Session *s) if (RFIFOL(s, 6) == 1) { if (battle_config.error_log) - PRINTF("map server change failed.\n"); + PRINTF("map server change failed.\n"_fmt); pc_authfail(sd->status_key.account_id); return 0; } @@ -293,21 +293,18 @@ int chrif_connectack(Session *s) { if (RFIFOB(s, 2)) { - PRINTF("Connected to char-server failed %d.\n", RFIFOB(s, 2)); + PRINTF("Connected to char-server failed %d.\n"_fmt, RFIFOB(s, 2)); exit(1); } - PRINTF("Connected to char-server (connection #%d).\n", s); + PRINTF("Connected to char-server (connection #%d).\n"_fmt, s); chrif_state = 1; chrif_sendmap(s); - PRINTF("chrif: OnCharIfInit event done. (%d events)\n", - npc_event_doall(stringish<ScriptLabel>("OnCharIfInit"))); - PRINTF("chrif: OnInterIfInit event done. (%d events)\n", - npc_event_doall(stringish<ScriptLabel>("OnInterIfInit"))); - - // <Agit> Run Event [AgitInit] -// PRINTF("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit")); + PRINTF("chrif: OnCharIfInit event done. (%d events)\n"_fmt, + npc_event_doall(stringish<ScriptLabel>("OnCharIfInit"_s))); + PRINTF("chrif: OnInterIfInit event done. (%d events)\n"_fmt, + npc_event_doall(stringish<ScriptLabel>("OnInterIfInit"_s))); return 0; } @@ -321,7 +318,7 @@ int chrif_sendmapack(Session *s) { if (RFIFOB(s, 2)) { - PRINTF("chrif : send map list to char server failed %d\n", + PRINTF("chrif : send map list to char server failed %d\n"_fmt, RFIFOB(s, 2)); exit(1); } @@ -408,7 +405,7 @@ int chrif_charselectreq(dumb_ptr<map_session_data> sd) void chrif_changegm(int id, ZString pass) { if (battle_config.etc_log) - PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass); + PRINTF("chrif_changegm: account: %d, password: '%s'.\n"_fmt, id, pass); size_t len = pass.size() + 1; WFIFOW(char_session, 0) = 0x2b0a; @@ -426,7 +423,7 @@ void chrif_changeemail(int id, AccountEmail actual_email, AccountEmail new_email) { if (battle_config.etc_log) - PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", + PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n"_fmt, id, actual_email, new_email); WFIFOW(char_session, 0) = 0x2b0c; @@ -456,7 +453,7 @@ void chrif_char_ask_name(int id, CharName character_name, short operation_type, WFIFOW(char_session, 30) = operation_type; // type of operation if (operation_type == 2) WFIFO_STRUCT(char_session, 32, modif); - PRINTF("chrif : sended 0x2b0e\n"); + PRINTF("chrif : sended 0x2b0e\n"_fmt); WFIFOSET(char_session, 44); } @@ -487,7 +484,7 @@ int chrif_char_ask_name_answer(Session *s) { AString output; if (RFIFOW(s, 32) == 1) // player not found - output = STRPRINTF("The player '%s' doesn't exist.", + output = STRPRINTF("The player '%s' doesn't exist."_fmt, player_name); else { @@ -498,18 +495,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to block the player '%s'.", + "Login-server has been asked to block the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to block the player '%s'.", + "Your GM level don't authorise you to block the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to block the the player '%s'.", + "Login-server is offline. Impossible to block the the player '%s'."_fmt, player_name); break; } @@ -519,18 +516,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to ban the player '%s'.", + "Login-server has been asked to ban the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to ban the player '%s'.", + "Your GM level don't authorise you to ban the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to ban the the player '%s'.", + "Login-server is offline. Impossible to ban the the player '%s'."_fmt, player_name); break; } @@ -540,18 +537,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to unblock the player '%s'.", + "Login-server has been asked to unblock the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to unblock the player '%s'.", + "Your GM level don't authorise you to unblock the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to unblock the the player '%s'.", + "Login-server is offline. Impossible to unblock the the player '%s'."_fmt, player_name); break; } @@ -561,18 +558,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to unban the player '%s'.", + "Login-server has been asked to unban the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to unban the player '%s'.", + "Your GM level don't authorise you to unban the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to unban the the player '%s'.", + "Login-server is offline. Impossible to unban the the player '%s'."_fmt, player_name); break; } @@ -582,18 +579,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to change the sex of the player '%s'.", + "Login-server has been asked to change the sex of the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to change the sex of the player '%s'.", + "Your GM level don't authorise you to change the sex of the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to change the sex of the the player '%s'.", + "Login-server is offline. Impossible to change the sex of the the player '%s'."_fmt, player_name); break; } @@ -604,7 +601,7 @@ int chrif_char_ask_name_answer(Session *s) clif_displaymessage(sd->sess, output); } else - PRINTF("chrif_char_ask_name_answer failed - player not online.\n"); + PRINTF("chrif_char_ask_name_answer failed - player not online.\n"_fmt); return 0; } @@ -625,14 +622,14 @@ void chrif_changedgm(Session *s) sd = map_id2sd(acc); if (battle_config.etc_log) - PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc, + PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n"_fmt, acc, level); if (sd != NULL) { if (level > 0) - clif_displaymessage(sd->sess, "GM modification success."); + clif_displaymessage(sd->sess, "GM modification success."_s); else - clif_displaymessage(sd->sess, "Failure of GM modification."); + clif_displaymessage(sd->sess, "Failure of GM modification."_s); } } @@ -649,7 +646,7 @@ void chrif_changedsex(Session *s) acc = RFIFOL(s, 2); SEX sex = static_cast<SEX>(RFIFOB(s, 6)); if (battle_config.etc_log) - PRINTF("chrif_changedsex %d.\n", acc); + PRINTF("chrif_changedsex %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -671,7 +668,7 @@ void chrif_changedsex(Session *s) sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters // do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it) clif_displaymessage(sd->sess, - "Your sex has been changed (need disconexion by the server)..."); + "Your sex has been changed (need disconexion by the server)..."_s); clif_setwaitclose(sd->sess); // forced to disconnect for the change } } @@ -679,7 +676,7 @@ void chrif_changedsex(Session *s) { if (sd != NULL) { - PRINTF("chrif_changedsex failed.\n"); + PRINTF("chrif_changedsex failed.\n"_fmt); } } } @@ -797,7 +794,7 @@ int chrif_accountdeletion(Session *s) acc = RFIFOL(s, 2); if (battle_config.etc_log) - PRINTF("chrif_accountdeletion %d.\n", acc); + PRINTF("chrif_accountdeletion %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -805,14 +802,14 @@ int chrif_accountdeletion(Session *s) { sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters clif_displaymessage(sd->sess, - "Your account has been deleted (disconnection)..."); + "Your account has been deleted (disconnection)..."_s); clif_setwaitclose(sd->sess); // forced to disconnect for the change } } else { if (sd != NULL) - PRINTF("chrif_accountdeletion failed - player not online.\n"); + PRINTF("chrif_accountdeletion failed - player not online.\n"_fmt); } return 0; @@ -830,7 +827,7 @@ int chrif_accountban(Session *s) acc = RFIFOL(s, 2); if (battle_config.etc_log) - PRINTF("chrif_accountban %d.\n", acc); + PRINTF("chrif_accountban %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -843,57 +840,58 @@ int chrif_accountban(Session *s) { // status or final date of a banishment case 1: // 0 = Unregistered ID clif_displaymessage(sd->sess, - "Your account has 'Unregistered'."); + "Your account has 'Unregistered'."_s); break; case 2: // 1 = Incorrect Password clif_displaymessage(sd->sess, - "Your account has an 'Incorrect Password'..."); + "Your account has an 'Incorrect Password'..."_s); break; case 3: // 2 = This ID is expired clif_displaymessage(sd->sess, - "Your account has expired."); + "Your account has expired."_s); break; case 4: // 3 = Rejected from Server clif_displaymessage(sd->sess, - "Your account has been rejected from server."); + "Your account has been rejected from server."_s); break; case 5: // 4 = You have been blocked by the GM Team clif_displaymessage(sd->sess, - "Your account has been blocked by the GM Team."); + "Your account has been blocked by the GM Team."_s); break; case 6: // 5 = Your Game's EXE file is not the latest version clif_displaymessage(sd->sess, - "Your Game's EXE file is not the latest version."); + "Your Game's EXE file is not the latest version."_s); break; case 7: // 6 = Your are Prohibited to log in until %s clif_displaymessage(sd->sess, - "Your account has been prohibited to log in."); + "Your account has been prohibited to log in."_s); break; case 8: // 7 = Server is jammed due to over populated clif_displaymessage(sd->sess, - "Server is jammed due to over populated."); + "Server is jammed due to over populated."_s); break; case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) clif_displaymessage(sd->sess, - "Your account has not more authorised."); + "Your account has not more authorised."_s); break; case 100: // 99 = This ID has been totally erased clif_displaymessage(sd->sess, - "Your account has been totally erased."); + "Your account has been totally erased."_s); break; default: clif_displaymessage(sd->sess, - "Your account has not more authorised."); + "Your account has not more authorised."_s); break; } } else if (RFIFOB(s, 6) == 1) { // 0: change of statut, 1: ban - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 7)); // status or final date of a banishment - char tmpstr[] = WITH_TIMESTAMP("Your account has been banished until "); - REPLACE_TIMESTAMP(tmpstr, timestamp); - clif_displaymessage(sd->sess, const_(tmpstr)); + const TimeT timestamp = static_cast<time_t>(RFIFOL(s, 7)); // status or final date of a banishment + timestamp_seconds_buffer buffer; + stamp_time(buffer, ×tamp); + AString tmpstr = STRPRINTF("Your account has been banished until %s"_fmt, buffer); + clif_displaymessage(sd->sess, tmpstr); } clif_setwaitclose(sd->sess); // forced to disconnect for the change } @@ -901,7 +899,7 @@ int chrif_accountban(Session *s) else { if (sd != NULL) - PRINTF("chrif_accountban failed - player not online.\n"); + PRINTF("chrif_accountban failed - player not online.\n"_fmt); } return 0; @@ -914,7 +912,7 @@ int chrif_accountban(Session *s) static int chrif_recvgmaccounts(Session *s) { - PRINTF("From login-server: receiving of %d GM accounts information.\n", + PRINTF("From login-server: receiving of %d GM accounts information.\n"_fmt, pc_read_gm_account(s)); return 0; @@ -1041,7 +1039,7 @@ static void chrif_delete(Session *s) { assert (s == char_session); - PRINTF("Map-server can't connect to char-server (connection #%d).\n", + PRINTF("Map-server can't connect to char-server (connection #%d).\n"_fmt, s); char_session = nullptr; } @@ -1161,7 +1159,7 @@ void chrif_parse(Session *s) default: if (battle_config.error_log) - PRINTF("chrif_parse : unknown packet %d %d\n", s, + PRINTF("chrif_parse : unknown packet %d %d\n"_fmt, s, RFIFOW(s, 0)); s->set_eof(); return; @@ -1214,7 +1212,7 @@ void check_connect_char_server(TimerData *, tick_t) { if (!char_session) { - PRINTF("Attempt to connect to char-server...\n"); + PRINTF("Attempt to connect to char-server...\n"_fmt); chrif_state = 0; char_session = make_connection(char_ip, char_port, SessionParsers{func_parse: chrif_parse, func_delete: chrif_delete}); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index eb008e4..3e57a6f 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -159,11 +159,11 @@ void clif_delete(Session *s) pc_logout(sd); clif_quitsave(s, sd); - PRINTF("Player [%s] has logged off your server.\n", sd->status_key.name); // Player logout display [Valaris] + PRINTF("Player [%s] has logged off your server.\n"_fmt, sd->status_key.name); // Player logout display [Valaris] } else if (sd) { // not authentified! (refused by char-server or disconnect before to be authentified) - PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl_id); // Player logout display [Yor] + PRINTF("Player with account [%d] has logged off your server (not auth account).\n"_fmt, sd->bl_id); // Player logout display [Yor] map_deliddb(sd); // account_id has been included in the DB before auth answer } } @@ -487,7 +487,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type default: if (battle_config.error_log) - PRINTF("clif_send まだ作ってないよー\n"); + PRINTF("clif_send まだ作ってないよー\n"_fmt); return -1; } @@ -1791,7 +1791,7 @@ int clif_updatestatus(dumb_ptr<map_session_data> sd, SP type) default: if (battle_config.error_log) - PRINTF("clif_updatestatus : make %d routine\n", + PRINTF("clif_updatestatus : make %d routine\n"_fmt, type); return 1; } @@ -2578,7 +2578,7 @@ void clif_getareachar(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd) break; default: if (battle_config.error_log) - PRINTF("get area char ??? %d\n", + PRINTF("get area char ??? %d\n"_fmt, bl->bl_type); break; } @@ -3091,8 +3091,6 @@ void clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag) nullpo_retv(p); -// if(battle_config.etc_log) -// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag); if (sd == NULL && flag == 0) { int i; @@ -3195,8 +3193,6 @@ int clif_party_xy(struct party *, dumb_ptr<map_session_data> sd) WBUFW(buf, 6) = sd->bl_x; WBUFW(buf, 8) = sd->bl_y; clif_send(buf, clif_parse_func_table[0x107].len, sd, SendWho::PARTY_SAMEMAP_WOS); -// if(battle_config.etc_log) -// PRINTF("clif_party_xy %d\n",sd->status_key.account_id); return 0; } @@ -3216,8 +3212,6 @@ int clif_party_hp(struct party *, dumb_ptr<map_session_data> sd) WBUFW(buf, 8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp; clif_send(buf, clif_parse_func_table[0x106].len, sd, SendWho::PARTY_AREA_WOS); -// if(battle_config.etc_log) -// PRINTF("clif_party_hp %d\n",sd->status_key.account_id); return 0; } @@ -3395,7 +3389,7 @@ void clif_parse_WantToConnection(Session *s, dumb_ptr<map_session_data> sd) if (sd) { if (battle_config.error_log) - PRINTF("clif_parse_WantToConnection : invalid request?\n"); + PRINTF("clif_parse_WantToConnection : invalid request?\n"_fmt); return; } @@ -3415,7 +3409,7 @@ void clif_parse_WantToConnection(Session *s, dumb_ptr<map_session_data> sd) { clif_authfail_fd(s, 2); // same id clif_authfail_fd(old_sd->sess, 2); // same id - PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n", + PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n"_fmt, account_id, s, old_sd->sess); } else @@ -3644,7 +3638,7 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) nullpo_retv(ssd); if (ssd->state.shroud_active) - WFIFO_STRING(s, 6, "", 24); + WFIFO_STRING(s, 6, ""_s, 24); else WFIFO_STRING(s, 6, ssd->status_key.name.to__actual(), 24); WFIFOSET(s, clif_parse_func_table[0x95].len); @@ -3666,9 +3660,9 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) WFIFOW(s, 0) = 0x195; WFIFOL(s, 2) = account_id; WFIFO_STRING(s, 6, party_name, 24); - WFIFO_STRING(s, 30, "", 24); - WFIFO_STRING(s, 54, "", 24); - WFIFO_STRING(s, 78, "", 24); // We send this value twice because the client expects it + WFIFO_STRING(s, 30, ""_s, 24); + WFIFO_STRING(s, 54, ""_s, 24); + WFIFO_STRING(s, 78, ""_s, 24); // We send this value twice because the client expects it WFIFOSET(s, clif_parse_func_table[0x195].len); } @@ -3710,7 +3704,7 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) break; default: if (battle_config.error_log) - PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n", + PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n"_fmt, bl->bl_type, account_id); break; } @@ -3731,7 +3725,7 @@ void clif_parse_GlobalMessage(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Global); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -3743,7 +3737,7 @@ void clif_parse_GlobalMessage(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -3996,7 +3990,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Whisper); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -4008,7 +4002,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -4027,7 +4021,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) /* Refuse messages addressed to self. */ if (dstsd->sess == s) { - ZString mes = "You cannot page yourself."; + ZString mes = "You cannot page yourself."_s; clif_wis_message(s, wisp_server_name, mes); } else @@ -4100,13 +4094,13 @@ void clif_parse_DropItem(Session *s, dumb_ptr<map_session_data> sd) } if (sd->bl_m->flag.get(MapFlag::NO_PLAYER_DROPS)) { - clif_displaymessage(sd->sess, "Can't drop items here."); + clif_displaymessage(sd->sess, "Can't drop items here."_s); return; } if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO) { - clif_displaymessage(sd->sess, "Can't drop items right now."); + clif_displaymessage(sd->sess, "Can't drop items right now."_s); return; } @@ -4593,7 +4587,7 @@ void clif_parse_PartyMessage(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Party); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -4603,7 +4597,7 @@ void clif_parse_PartyMessage(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -5223,7 +5217,7 @@ int clif_check_packet_flood(Session *s, int cmd) if (sd->packet_flood_in >= battle_config.packet_spam_flood) { - PRINTF("packet flood detected from %s [0x%x]\n", sd->status_key.name, cmd); + PRINTF("packet flood detected from %s [0x%x]\n"_fmt, sd->status_key.name, cmd); if (battle_config.packet_spam_kick) { s->set_eof(); @@ -5240,9 +5234,9 @@ int clif_check_packet_flood(Session *s, int cmd) } inline -void WARN_MALFORMED_MSG(dumb_ptr<map_session_data> sd, const char *msg) +void WARN_MALFORMED_MSG(dumb_ptr<map_session_data> sd, ZString msg) { - PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n", + PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n"_fmt, sd->status_key.name, sd->status_key.account_id, msg); } /** @@ -5287,14 +5281,14 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) /* The player just sent the header (2) and length (2) words. */ if (!msg_len) { - WARN_MALFORMED_MSG(sd, "no message sent"); + WARN_MALFORMED_MSG(sd, "no message sent"_s); return AString(); } /* The client sent (or claims to have sent) an empty message. */ if (msg_len == min_len) { - WARN_MALFORMED_MSG(sd, "empty message"); + WARN_MALFORMED_MSG(sd, "empty message"_s); return AString(); } @@ -5303,7 +5297,7 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) { /* Disallow malformed messages. */ clif_setwaitclose(s); - WARN_MALFORMED_MSG(sd, "illegal target name"); + WARN_MALFORMED_MSG(sd, "illegal target name"_s); return AString(); } @@ -5325,18 +5319,18 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) */ if (buf_len >= battle_config.chat_maxline) { - WARN_MALFORMED_MSG(sd, "exceeded maximum message length"); + WARN_MALFORMED_MSG(sd, "exceeded maximum message length"_s); return AString(); } if (type == ChatType::Global) { XString p = pbuf; - if (!(p.startswith(sd->status_key.name.to__actual()) && p.xslice_t(name_len).startswith(" : "))) + if (!(p.startswith(sd->status_key.name.to__actual()) && p.xslice_t(name_len).startswith(" : "_s))) { /* Disallow malformed/spoofed messages. */ clif_setwaitclose(s); - WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"); + WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"_s); return AString(); } /* Step beyond the separator. */ @@ -5443,32 +5437,32 @@ void clif_parse(Session *s) if (battle_config.error_log) { if (s) - PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n", + PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n"_fmt, s, cmd, packet_len); #ifdef DUMP_UNKNOWN_PACKET { int i; - ZString packet_txt = "save/packet.txt"; - PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); + ZString packet_txt = "save/packet.txt"_s; + PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"_fmt); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - PRINTF("\n%04X ", i); - PRINTF("%02X ", RFIFOB(s, i)); + PRINTF("\n%04X "_fmt, i); + PRINTF("%02X "_fmt, RFIFOB(s, i)); } if (sd && sd->state.auth) { - PRINTF("\nAccount ID %d, character ID %d, player name %s.\n", + PRINTF("\nAccount ID %d, character ID %d, player name %s.\n"_fmt, sd->status_key.account_id, sd->status_key.char_id, sd->status_key.name); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) - PRINTF("\nAccount ID %d.\n", sd->bl_id); + PRINTF("\nAccount ID %d.\n"_fmt, sd->bl_id); io::AppendFile fp(packet_txt); if (!fp.is_open()) { - PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n", + PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n"_fmt, packet_txt); return; } @@ -5479,25 +5473,25 @@ void clif_parse(Session *s) if (sd && sd->state.auth) { FPRINTF(fp, - "%s\nPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n", + "%s\nPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n"_fmt, now, sd->status_key.account_id, sd->status_key.char_id, sd->status_key.name); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) FPRINTF(fp, - "%s\nPlayer with account ID %d sent wrong packet:\n", + "%s\nPlayer with account ID %d sent wrong packet:\n"_fmt, now, sd->bl_id); FPRINTF(fp, - "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); + "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"_fmt); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - FPRINTF(fp, "\n\t%04X ", i); - FPRINTF(fp, "%02X ", RFIFOB(s, i)); + FPRINTF(fp, "\n\t%04X "_fmt, i); + FPRINTF(fp, "%02X "_fmt, RFIFOB(s, i)); } - FPRINTF(fp, "\n\n"); + FPRINTF(fp, "\n\n"_fmt); } } #endif diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp index c3d1e40..b03456c 100644 --- a/src/map/grfio.cpp +++ b/src/map/grfio.cpp @@ -50,7 +50,7 @@ bool load_resnametable(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - FPRINTF(stderr, "Missing %s\n", filename); + FPRINTF(stderr, "Missing %s\n"_fmt, filename); return false; } @@ -63,7 +63,7 @@ bool load_resnametable(ZString filename) if (!extract(line, record<'#'>(&key, &value))) { - PRINTF("Bad resnametable line: %s\n", line); + PRINTF("Bad resnametable line: %s\n"_fmt, line); rv = false; continue; } @@ -85,7 +85,7 @@ std::vector<uint8_t> grfio_reads(MapName rname) { MString lfname_; // TODO ... instead of here - lfname_ += "data/"; + lfname_ += "data/"_s; lfname_ += grfio_resnametable(rname); AString lfname = AString(lfname_); @@ -93,7 +93,7 @@ std::vector<uint8_t> grfio_reads(MapName rname) int fd = open(lfname.c_str(), O_RDONLY); if (fd == -1) { - FPRINTF(stderr, "Resource %s (file %s) not found\n", + FPRINTF(stderr, "Resource %s (file %s) not found\n"_fmt, rname, lfname); return {}; } diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 2cae2ad..3395974 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -85,7 +85,7 @@ void intif_wis_message(dumb_ptr<map_session_data> sd, CharName nick, ZString mes WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) - PRINTF("intif_wis_message from %s to %s)\n", + PRINTF("intif_wis_message from %s to %s)\n"_fmt, sd->status_key.name, nick); } @@ -99,7 +99,7 @@ void intif_wis_replay(int id, int flag) WFIFOSET(char_session, 7); if (battle_config.etc_log) - PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag); + PRINTF("intif_wis_replay: id: %d, flag:%d\n"_fmt, id, flag); } // The transmission of GM only Wisp/Page from server to inter-server @@ -114,7 +114,7 @@ void intif_wis_message_to_gm(CharName Wisp_name, int min_gm_level, ZString mes) WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) - PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", + PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n"_fmt, Wisp_name, min_gm_level, mes); } @@ -280,7 +280,7 @@ int intif_parse_WisMessage(Session *s) if (battle_config.etc_log) { - PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s\n", + PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s\n"_fmt, RFIFOL(s, 4), from, to); @@ -312,7 +312,7 @@ int intif_parse_WisEnd(Session *s) uint8_t flag = RFIFOB(s, 26); if (battle_config.etc_log) // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - PRINTF("intif_parse_wisend: player: %s, flag: %d\n", + PRINTF("intif_parse_wisend: player: %s, flag: %d\n"_fmt, name, flag); sd = map_nick2sd(name); if (sd != NULL) @@ -366,7 +366,6 @@ int intif_parse_AccountReg(Session *s) sd->status.account_reg[j].value = RFIFOL(s, p + 32); } sd->status.account_reg_num = j; -// PRINTF("intif: accountreg\n"); return 0; } @@ -382,7 +381,7 @@ int intif_parse_LoadStorage(Session *s) if (sd == NULL) { if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: user not found %d\n", + PRINTF("intif_parse_LoadStorage: user not found %d\n"_fmt, RFIFOL(s, 4)); return 1; } @@ -390,14 +389,14 @@ int intif_parse_LoadStorage(Session *s) if (stor->storage_status == 1) { // Already open.. lets ignore this update if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n"_fmt, sd->status_key.account_id, sd->status_key.char_id); return 1; } if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex] if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n"_fmt, sd->status_key.account_id, sd->status_key.char_id); return 1; } @@ -405,12 +404,12 @@ int intif_parse_LoadStorage(Session *s) if (RFIFOW(s, 2) - 8 != sizeof(struct storage)) { if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: data size error %d %zu\n", + PRINTF("intif_parse_LoadStorage: data size error %d %zu\n"_fmt, RFIFOW(s, 2) - 8, sizeof(struct storage)); return 1; } if (battle_config.save_log) - PRINTF("intif_openstorage: %d\n", RFIFOL(s, 4)); + PRINTF("intif_openstorage: %d\n"_fmt, RFIFOL(s, 4)); RFIFO_STRUCT(s, 8, *stor); stor->dirty = 0; stor->storage_status = 1; @@ -427,7 +426,7 @@ static void intif_parse_SaveStorage(Session *s) { if (battle_config.save_log) - PRINTF("intif_savestorage: done %d %d\n", RFIFOL(s, 2), + PRINTF("intif_savestorage: done %d %d\n"_fmt, RFIFOL(s, 2), RFIFOB(s, 6)); storage_storage_saved(RFIFOL(s, 2)); } @@ -437,7 +436,7 @@ static void intif_parse_PartyCreated(Session *s) { if (battle_config.etc_log) - PRINTF("intif: party created\n"); + PRINTF("intif: party created\n"_fmt); int account_id = RFIFOL(s, 2); int fail = RFIFOB(s, 6); int party_id = RFIFOL(s, 7); @@ -452,16 +451,15 @@ void intif_parse_PartyInfo(Session *s) if (RFIFOW(s, 2) == 8) { if (battle_config.error_log) - PRINTF("intif: party noinfo %d\n", RFIFOL(s, 4)); + PRINTF("intif: party noinfo %d\n"_fmt, RFIFOL(s, 4)); party_recv_noinfo(RFIFOL(s, 4)); return; } -// PRINTF("intif: party info %d\n",RFIFOL(fd,4)); if (RFIFOW(s, 2) != sizeof(struct party) + 4) { if (battle_config.error_log) - PRINTF("intif: party info : data size error %d %d %zu\n", + PRINTF("intif: party info : data size error %d %d %zu\n"_fmt, RFIFOL(s, 4), RFIFOW(s, 2), sizeof(struct party) + 4); } @@ -475,7 +473,7 @@ static void intif_parse_PartyMemberAdded(Session *s) { if (battle_config.etc_log) - PRINTF("intif: party member added %d %d %d\n", RFIFOL(s, 2), + PRINTF("intif: party member added %d %d %d\n"_fmt, RFIFOL(s, 2), RFIFOL(s, 6), RFIFOB(s, 10)); party_member_added(RFIFOL(s, 2), RFIFOL(s, 6), RFIFOB(s, 10)); } @@ -496,7 +494,7 @@ void intif_parse_PartyMemberLeaved(Session *s) int account_id = RFIFOL(s, 6); CharName name = stringish<CharName>(RFIFO_STRING<24>(s, 10)); if (battle_config.etc_log) - PRINTF("intif: party member leaved %d %d %s\n", + PRINTF("intif: party member leaved %d %d %s\n"_fmt, party_id, account_id, name); party_member_leaved(party_id, account_id, name); } @@ -553,8 +551,6 @@ int intif_parse(Session *s) return 2; packet_len = RFIFOW(s, 2); } -// if(battle_config.etc_log) -// PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd)); if (RFIFOREST(s) < packet_len) { return 2; @@ -612,7 +608,7 @@ int intif_parse(Session *s) break; default: if (battle_config.error_log) - PRINTF("intif_parse : unknown packet %d %x\n", s, + PRINTF("intif_parse : unknown packet %d %x\n"_fmt, s, RFIFOW(s, 0)); return 0; } diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 4ebb52c..2cc9e49 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -174,7 +174,7 @@ bool itemdb_readdb(ZString filename) if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -220,7 +220,7 @@ bool itemdb_readdb(ZString filename) ) ) { - PRINTF("%s:%d: error: bad item line: %s\n", + PRINTF("%s:%d: error: bad item line: %s\n"_fmt, filename, lines, line); rv = false; continue; @@ -254,7 +254,7 @@ bool itemdb_readdb(ZString filename) continue; id->equip_script = parse_script(tail_part, lines, true); } - PRINTF("read %s done (count=%d)\n", filename, ln); + PRINTF("read %s done (count=%d)\n"_fmt, filename, ln); } return rv; diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 42ff3a7..786f870 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -125,38 +125,38 @@ AString show_entity(dumb_ptr<block_list> entity) case BL::MOB: return entity->is_mob()->name; case BL::ITEM: - assert (0 && "There is no way this code did what it was supposed to do!"); + assert (0 && "There is no way this code did what it was supposed to do!"_s); /* Sorry about this one... */ // WTF? item_data is a struct item, not a struct item_data // return ((struct item_data *) (&entity->is_item()->item_data))->name; abort(); case BL::SPELL: - return {"%invocation(ERROR:this-should-not-be-an-entity)"}; + return "%invocation(ERROR:this-should-not-be-an-entity)"_s; default: - return {"%unknown-entity"}; + return "%unknown-entity"_s; } } static void stringify(val_t *v, int within_op) { - static earray<ZString, DIR, DIR::COUNT> dirs //= + static earray<LString, DIR, DIR::COUNT> dirs //= {{ - {"south"}, {"south-west"}, - {"west"}, {"north-west"}, - {"north"}, {"north-east"}, - {"east"}, {"south-east"}, + "south"_s, "south-west"_s, + "west"_s, "north-west"_s, + "north"_s, "north-east"_s, + "east"_s, "south-east"_s, }}; AString buf; switch (v->ty) { case TYPE::UNDEF: - buf = "UNDEF"; + buf = "UNDEF"_s; break; case TYPE::INT: - buf = STRPRINTF("%i", v->v.v_int); + buf = STRPRINTF("%i"_fmt, v->v.v_int); break; case TYPE::STRING: @@ -171,14 +171,14 @@ void stringify(val_t *v, int within_op) break; case TYPE::LOCATION: - buf = STRPRINTF("<\"%s\", %d, %d>", + buf = STRPRINTF("<\"%s\", %d, %d>"_fmt, v->v.v_location.m->name_, v->v.v_location.x, v->v.v_location.y); break; case TYPE::AREA: - buf = "%area"; + buf = "%area"_s; free_area(v->v.v_area); break; @@ -196,7 +196,7 @@ void stringify(val_t *v, int within_op) break; default: - FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n", + FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n"_fmt, v->ty); return; } @@ -590,7 +590,7 @@ void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, default: FPRINTF(stderr, - "Error: Trying to compute area of NE/SE/NW/SW-facing bar"); + "Error: Trying to compute area of NE/SE/NW/SW-facing bar"_fmt); *x = tx; *y = ty; *width = *height = 1; @@ -619,7 +619,7 @@ int magic_location_in_area(map_local *m, int x, int y, dumb_ptr<area_t> area) && (x < ax + awidth) && (y < ay + aheight)); } default: - FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n"); + FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n"_fmt); return 0; } } @@ -1034,7 +1034,7 @@ void magic_random_location(location_t *dest, dumb_ptr<area_t> area) } default: - FPRINTF(stderr, "Unknown area type %d\n", + FPRINTF(stderr, "Unknown area type %d\n"_fmt, area->ty); } } @@ -1282,89 +1282,89 @@ int fun_extract_healer_xp(dumb_ptr<env_t>, val_t *result, Slice<val_t> args) return 0; } -#define MAGIC_FUNCTION(name, args, ret, impl) {{name}, {{name}, {args}, ret, impl}} -#define MAGIC_FUNCTION1(name, args, ret) MAGIC_FUNCTION(#name, args, ret, fun_##name) -static +#define MAGIC_FUNCTION(name, args, ret, impl) {name, {name, args, ret, impl}} +#define MAGIC_FUNCTION1(name, args, ret) MAGIC_FUNCTION(#name##_s, args, ret, fun_##name) +static // should be LString, but no heterogenous lookup yet std::map<ZString, fun_t> functions = { - MAGIC_FUNCTION("+", "..", '.', fun_add), - MAGIC_FUNCTION("-", "ii", 'i', fun_sub), - MAGIC_FUNCTION("*", "ii", 'i', fun_mul), - MAGIC_FUNCTION("/", "ii", 'i', fun_div), - MAGIC_FUNCTION("%", "ii", 'i', fun_mod), - MAGIC_FUNCTION("||", "ii", 'i', fun_or), - MAGIC_FUNCTION("&&", "ii", 'i', fun_and), - MAGIC_FUNCTION("<", "..", 'i', fun_lt), - MAGIC_FUNCTION(">", "..", 'i', fun_gt), - MAGIC_FUNCTION("<=", "..", 'i', fun_lte), - MAGIC_FUNCTION(">=", "..", 'i', fun_gte), - MAGIC_FUNCTION("==", "..", 'i', fun_eq), - MAGIC_FUNCTION("!=", "..", 'i', fun_ne), - MAGIC_FUNCTION("|", "..", 'i', fun_bitor), - MAGIC_FUNCTION("&", "ii", 'i', fun_bitand), - MAGIC_FUNCTION("^", "ii", 'i', fun_bitxor), - MAGIC_FUNCTION("<<", "ii", 'i', fun_bitshl), - MAGIC_FUNCTION(">>", "ii", 'i', fun_bitshr), - MAGIC_FUNCTION1(not, "i", 'i'), - MAGIC_FUNCTION1(neg, "i", 'i'), - MAGIC_FUNCTION1(max, "ii", 'i'), - MAGIC_FUNCTION1(min, "ii", 'i'), - MAGIC_FUNCTION1(is_in, "la", 'i'), - MAGIC_FUNCTION1(if_then_else, "i__", '_'), - MAGIC_FUNCTION1(skill, "ei", 'i'), - MAGIC_FUNCTION("str", "e", 'i', fun_get_str), - MAGIC_FUNCTION("agi", "e", 'i', fun_get_agi), - MAGIC_FUNCTION("vit", "e", 'i', fun_get_vit), - MAGIC_FUNCTION("dex", "e", 'i', fun_get_dex), - MAGIC_FUNCTION("luk", "e", 'i', fun_get_luk), - MAGIC_FUNCTION("int", "e", 'i', fun_get_int), - MAGIC_FUNCTION("level", "e", 'i', fun_get_lv), - MAGIC_FUNCTION("mdef", "e", 'i', fun_get_mdef), - MAGIC_FUNCTION("def", "e", 'i', fun_get_def), - MAGIC_FUNCTION("hp", "e", 'i', fun_get_hp), - MAGIC_FUNCTION("max_hp", "e", 'i', fun_get_max_hp), - MAGIC_FUNCTION("sp", "e", 'i', fun_get_sp), - MAGIC_FUNCTION("max_sp", "e", 'i', fun_get_max_sp), - MAGIC_FUNCTION("dir", "e", 'd', fun_get_dir), - MAGIC_FUNCTION1(name_of, ".", 's'), - MAGIC_FUNCTION1(mob_id, "e", 'i'), - MAGIC_FUNCTION1(location, "e", 'l'), - MAGIC_FUNCTION1(random, "i", 'i'), - MAGIC_FUNCTION1(random_dir, "i", 'd'), - MAGIC_FUNCTION1(hash_entity, "e", 'i'), - MAGIC_FUNCTION1(is_married, "e", 'i'), - MAGIC_FUNCTION1(partner, "e", 'e'), - MAGIC_FUNCTION1(awayfrom, "ldi", 'l'), - MAGIC_FUNCTION1(failed, "_", 'i'), - MAGIC_FUNCTION1(pc, "s", 'e'), - MAGIC_FUNCTION1(npc, "s", 'e'), - MAGIC_FUNCTION1(distance, "ll", 'i'), - MAGIC_FUNCTION1(rdistance, "ll", 'i'), - MAGIC_FUNCTION1(anchor, "s", 'a'), - MAGIC_FUNCTION("random_location", "a", 'l', fun_pick_location), - MAGIC_FUNCTION("script_int", "es", 'i', fun_read_script_int), - MAGIC_FUNCTION("script_str", "es", 's', fun_read_script_str), - MAGIC_FUNCTION1(rbox, "li", 'a'), - MAGIC_FUNCTION1(count_item, "e.", 'i'), - MAGIC_FUNCTION1(line_of_sight, "ll", 'i'), - MAGIC_FUNCTION1(running_status_update, "ei", 'i'), - MAGIC_FUNCTION1(status_option, "ei", 'i'), - MAGIC_FUNCTION1(element, "e", 'i'), - MAGIC_FUNCTION1(element_level, "e", 'i'), - MAGIC_FUNCTION1(his_shroud, "e", 'i'), - MAGIC_FUNCTION1(is_equipped, "e.", 'i'), - MAGIC_FUNCTION1(is_exterior, "l", 'i'), - MAGIC_FUNCTION1(contains_string, "ss", 'i'), - MAGIC_FUNCTION1(strstr, "ss", 'i'), - MAGIC_FUNCTION1(strlen, "s", 'i'), - MAGIC_FUNCTION1(substr, "sii", 's'), - MAGIC_FUNCTION1(sqrt, "i", 'i'), - MAGIC_FUNCTION1(map_level, "l", 'i'), - MAGIC_FUNCTION1(map_nr, "l", 'i'), - MAGIC_FUNCTION1(dir_towards, "lli", 'd'), - MAGIC_FUNCTION1(is_dead, "e", 'i'), - MAGIC_FUNCTION1(is_pc, "e", 'i'), - MAGIC_FUNCTION("extract_healer_experience", "ei", 'i', fun_extract_healer_xp), + MAGIC_FUNCTION("+"_s, ".."_s, '.', fun_add), + MAGIC_FUNCTION("-"_s, "ii"_s, 'i', fun_sub), + MAGIC_FUNCTION("*"_s, "ii"_s, 'i', fun_mul), + MAGIC_FUNCTION("/"_s, "ii"_s, 'i', fun_div), + MAGIC_FUNCTION("%"_s, "ii"_s, 'i', fun_mod), + MAGIC_FUNCTION("||"_s, "ii"_s, 'i', fun_or), + MAGIC_FUNCTION("&&"_s, "ii"_s, 'i', fun_and), + MAGIC_FUNCTION("<"_s, ".."_s, 'i', fun_lt), + MAGIC_FUNCTION(">"_s, ".."_s, 'i', fun_gt), + MAGIC_FUNCTION("<="_s, ".."_s, 'i', fun_lte), + MAGIC_FUNCTION(">="_s, ".."_s, 'i', fun_gte), + MAGIC_FUNCTION("=="_s, ".."_s, 'i', fun_eq), + MAGIC_FUNCTION("!="_s, ".."_s, 'i', fun_ne), + MAGIC_FUNCTION("|"_s, ".."_s, 'i', fun_bitor), + MAGIC_FUNCTION("&"_s, "ii"_s, 'i', fun_bitand), + MAGIC_FUNCTION("^"_s, "ii"_s, 'i', fun_bitxor), + MAGIC_FUNCTION("<<"_s, "ii"_s, 'i', fun_bitshl), + MAGIC_FUNCTION(">>"_s, "ii"_s, 'i', fun_bitshr), + MAGIC_FUNCTION1(not, "i"_s, 'i'), + MAGIC_FUNCTION1(neg, "i"_s, 'i'), + MAGIC_FUNCTION1(max, "ii"_s, 'i'), + MAGIC_FUNCTION1(min, "ii"_s, 'i'), + MAGIC_FUNCTION1(is_in, "la"_s, 'i'), + MAGIC_FUNCTION1(if_then_else, "i__"_s, '_'), + MAGIC_FUNCTION1(skill, "ei"_s, 'i'), + MAGIC_FUNCTION("str"_s, "e"_s, 'i', fun_get_str), + MAGIC_FUNCTION("agi"_s, "e"_s, 'i', fun_get_agi), + MAGIC_FUNCTION("vit"_s, "e"_s, 'i', fun_get_vit), + MAGIC_FUNCTION("dex"_s, "e"_s, 'i', fun_get_dex), + MAGIC_FUNCTION("luk"_s, "e"_s, 'i', fun_get_luk), + MAGIC_FUNCTION("int"_s, "e"_s, 'i', fun_get_int), + MAGIC_FUNCTION("level"_s, "e"_s, 'i', fun_get_lv), + MAGIC_FUNCTION("mdef"_s, "e"_s, 'i', fun_get_mdef), + MAGIC_FUNCTION("def"_s, "e"_s, 'i', fun_get_def), + MAGIC_FUNCTION("hp"_s, "e"_s, 'i', fun_get_hp), + MAGIC_FUNCTION("max_hp"_s, "e"_s, 'i', fun_get_max_hp), + MAGIC_FUNCTION("sp"_s, "e"_s, 'i', fun_get_sp), + MAGIC_FUNCTION("max_sp"_s, "e"_s, 'i', fun_get_max_sp), + MAGIC_FUNCTION("dir"_s, "e"_s, 'd', fun_get_dir), + MAGIC_FUNCTION1(name_of, "."_s, 's'), + MAGIC_FUNCTION1(mob_id, "e"_s, 'i'), + MAGIC_FUNCTION1(location, "e"_s, 'l'), + MAGIC_FUNCTION1(random, "i"_s, 'i'), + MAGIC_FUNCTION1(random_dir, "i"_s, 'd'), + MAGIC_FUNCTION1(hash_entity, "e"_s, 'i'), + MAGIC_FUNCTION1(is_married, "e"_s, 'i'), + MAGIC_FUNCTION1(partner, "e"_s, 'e'), + MAGIC_FUNCTION1(awayfrom, "ldi"_s, 'l'), + MAGIC_FUNCTION1(failed, "_"_s, 'i'), + MAGIC_FUNCTION1(pc, "s"_s, 'e'), + MAGIC_FUNCTION1(npc, "s"_s, 'e'), + MAGIC_FUNCTION1(distance, "ll"_s, 'i'), + MAGIC_FUNCTION1(rdistance, "ll"_s, 'i'), + MAGIC_FUNCTION1(anchor, "s"_s, 'a'), + MAGIC_FUNCTION("random_location"_s, "a"_s, 'l', fun_pick_location), + MAGIC_FUNCTION("script_int"_s, "es"_s, 'i', fun_read_script_int), + MAGIC_FUNCTION("script_str"_s, "es"_s, 's', fun_read_script_str), + MAGIC_FUNCTION1(rbox, "li"_s, 'a'), + MAGIC_FUNCTION1(count_item, "e."_s, 'i'), + MAGIC_FUNCTION1(line_of_sight, "ll"_s, 'i'), + MAGIC_FUNCTION1(running_status_update, "ei"_s, 'i'), + MAGIC_FUNCTION1(status_option, "ei"_s, 'i'), + MAGIC_FUNCTION1(element, "e"_s, 'i'), + MAGIC_FUNCTION1(element_level, "e"_s, 'i'), + MAGIC_FUNCTION1(his_shroud, "e"_s, 'i'), + MAGIC_FUNCTION1(is_equipped, "e."_s, 'i'), + MAGIC_FUNCTION1(is_exterior, "l"_s, 'i'), + MAGIC_FUNCTION1(contains_string, "ss"_s, 'i'), + MAGIC_FUNCTION1(strstr, "ss"_s, 'i'), + MAGIC_FUNCTION1(strlen, "s"_s, 'i'), + MAGIC_FUNCTION1(substr, "sii"_s, 's'), + MAGIC_FUNCTION1(sqrt, "i"_s, 'i'), + MAGIC_FUNCTION1(map_level, "l"_s, 'i'), + MAGIC_FUNCTION1(map_nr, "l"_s, 'i'), + MAGIC_FUNCTION1(dir_towards, "lli"_s, 'd'), + MAGIC_FUNCTION1(is_dead, "e"_s, 'i'), + MAGIC_FUNCTION1(is_pc, "e"_s, 'i'), + MAGIC_FUNCTION("extract_healer_experience"_s, "ei"_s, 'i', fun_extract_healer_xp), }; fun_t *magic_get_fun(ZString name) @@ -1512,7 +1512,7 @@ dumb_ptr<area_t> eval_area(dumb_ptr<env_t> env, e_area_t& expr_) } default: - FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n", + FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n"_fmt, area->ty); area.delete_(); return NULL; @@ -1573,7 +1573,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, if (!ty_key) { FPRINTF(stderr, - "[magic-eval]: L%d:%d: Too many arguments (%zu) to %s `%s'\n", + "[magic-eval]: L%d:%d: Too many arguments (%zu) to %s `%s'\n"_fmt, line, column, args.size(), opname, funname); return 1; } @@ -1587,7 +1587,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, if (ty == TYPE::UNDEF) { FPRINTF(stderr, - "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n", + "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n"_fmt, line, column, i + 1, opname, funname); return 1; } @@ -1619,7 +1619,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, { /* Coercion failed? */ if (ty != TYPE::FAIL) FPRINTF(stderr, - "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n", + "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n"_fmt, line, column, i + 1, opname, funname, ty); return 1; @@ -1660,7 +1660,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) for (i = 0; i < args_nr; ++i) magic_eval(env, &arguments[i], expr->e.e_funapp.args[i]); - if (magic_signature_check("function", f->name, f->signature, Slice<val_t>(arguments, args_nr), + if (magic_signature_check("function"_s, f->name, f->signature, Slice<val_t>(arguments, args_nr), expr->e.e_funapp.line_nr, expr->e.e_funapp.column) || f->fun(env, dest, Slice<val_t>(arguments, args_nr))) dest->ty = TYPE::FAIL; @@ -1713,7 +1713,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) else { FPRINTF(stderr, - "[magic] Attempt to access field %s on non-spell\n", + "[magic] Attempt to access field %s on non-spell\n"_fmt, env->base_env->varv[id].name); dest->ty = TYPE::FAIL; } @@ -1722,7 +1722,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: Unknown expression type %d\n", + "[magic] INTERNAL ERROR: Unknown expression type %d\n"_fmt, expr->ty); break; } @@ -1747,7 +1747,7 @@ AString magic_eval_str(dumb_ptr<env_t> env, dumb_ptr<expr_t> expr) magic_eval(env, &result, expr); if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF) - return {"?"}; + return "?"_s; stringify(&result, 0); diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp index 58f6596..4d78bab 100644 --- a/src/map/magic-expr.hpp +++ b/src/map/magic-expr.hpp @@ -44,8 +44,8 @@ */ struct fun_t { - ZString name; - ZString signature; + LString name; + LString signature; char ret_ty; int (*fun)(dumb_ptr<env_t> env, val_t *result, Slice<val_t> arga); }; diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index d86f595..c734908 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -187,7 +187,7 @@ dumb_ptr<env_t> spell_create_env(magic_conf_t *conf, dumb_ptr<spell_t> spell, break; default: - FPRINTF(stderr, "Unexpected spellarg type %d\n", + FPRINTF(stderr, "Unexpected spellarg type %d\n"_fmt, spell->spellarg_ty); } @@ -370,7 +370,7 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, return NULL; default: - FPRINTF(stderr, "Unexpected spellguard type %d\n", + FPRINTF(stderr, "Unexpected spellguard type %d\n"_fmt, guard->ty); return NULL; } @@ -519,7 +519,7 @@ void spell_bind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocat { int *i = NULL; FPRINTF(stderr, - "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n", + "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n"_fmt, invocation->spell->name); *i = 1; return; diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index ba99409..ddadf03 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -58,19 +58,19 @@ void print_val(val_t *v) switch (v->ty) { case TYPE::UNDEF: - FPRINTF(stderr, "UNDEF"); + FPRINTF(stderr, "UNDEF"_fmt); break; case TYPE::INT: - FPRINTF(stderr, "%d", v->v.v_int); + FPRINTF(stderr, "%d"_fmt, v->v.v_int); break; case TYPE::DIR: - FPRINTF(stderr, "dir%d", v->v.v_int); + FPRINTF(stderr, "dir%d"_fmt, v->v.v_int); break; case TYPE::STRING: - FPRINTF(stderr, "`%s'", v->v.v_string); + FPRINTF(stderr, "`%s'"_fmt, v->v.v_string); break; default: - FPRINTF(stderr, "ty%d", v->ty); + FPRINTF(stderr, "ty%d"_fmt, v->ty); break; } } @@ -84,11 +84,11 @@ void dump_env(env_t *env) val_t *v = &env->vars[i]; val_t *bv = &env->base_env->vars[i]; - FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]); + FPRINTF(stderr, "%02x %30s "_fmt, i, env->base_env->var_name[i]); print_val(v); - FPRINTF(stderr, "\t("); + FPRINTF(stderr, "\t("_fmt); print_val(bv); - FPRINTF(stderr, ")\n"); + FPRINTF(stderr, ")\n"_fmt); } } #endif @@ -286,7 +286,7 @@ void magic_unshroud(dumb_ptr<map_session_data> other_char) other_char->state.shroud_active = 0; // Now warp the caster out of and back into here to refresh everyone's display char_update(other_char); - clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"); + clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"_s); // entity_effect(other_char, MAGIC_EFFECT_REVEAL); } @@ -304,7 +304,7 @@ dumb_ptr<npc_data> local_spell_effect(map_local *m, int x, int y, int effect, /* 1 minute should be enough for all interesting spell effects, I hope */ std::chrono::seconds delay = std::chrono::seconds(30); dumb_ptr<npc_data> effect_npc = npc_spawn_text(m, x, y, - INVISIBLE_NPC, NpcName(), "?"); + INVISIBLE_NPC, NpcName(), "?"_s); int effect_npc_id = effect_npc->bl_id; entity_effect(effect_npc, effect, tdelay); @@ -350,7 +350,7 @@ int op_instaheal(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<map_session_data> caster_pc = caster->is_player(); dumb_ptr<map_session_data> subject_pc = subject->is_player(); - MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d", + MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d"_fmt, subject_pc->status_key.char_id, ARGINT(1)); } @@ -770,18 +770,18 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) } static -const char *get_invocation_name(dumb_ptr<env_t> env) +ZString get_invocation_name(dumb_ptr<env_t> env) { dumb_ptr<invocation> invocation_; if (env->VAR(VAR_INVOCATION).ty != TYPE::INVOCATION) - return "?"; + return "?"_s; invocation_ = map_id_is_spell(env->VAR(VAR_INVOCATION).v.v_int); if (invocation_) - return invocation_->spell->name.c_str(); + return invocation_->spell->name; else - return "??"; + return "??"_s; } static @@ -824,7 +824,7 @@ int op_injure(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<mob_data> mob = target->is_mob(); - MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s", + MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s"_fmt, mob->bl_id, mob->mob_class, damage_caused, get_invocation_name(env)); } @@ -940,35 +940,35 @@ int op_gain_exp(dumb_ptr<env_t>, Slice<val_t> args) } #define MAGIC_OPERATION(name, args, impl) {{name}, {{name}, {args}, impl}} -#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name, args, op_##name) +#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name##_s, args, op_##name) static std::map<ZString, op_t> operations = { - MAGIC_OPERATION1(sfx, ".ii"), - MAGIC_OPERATION1(instaheal, "eii"), - MAGIC_OPERATION1(itemheal, "eii"), - MAGIC_OPERATION1(shroud, "ei"), - MAGIC_OPERATION("unshroud", "e", op_reveal), - MAGIC_OPERATION1(message, "es"), - MAGIC_OPERATION1(messenger_npc, "lissi"), - MAGIC_OPERATION1(move, "ed"), - MAGIC_OPERATION1(warp, "el"), - MAGIC_OPERATION1(banish, "e"), - MAGIC_OPERATION1(status_change, "eiiiiii"), - MAGIC_OPERATION1(stop_status_change, "ei"), - MAGIC_OPERATION1(override_attack, "eiiiiii"), - MAGIC_OPERATION1(create_item, "e.i"), - MAGIC_OPERATION1(aggravate, "eie"), - MAGIC_OPERATION1(spawn, "aeiiii"), - MAGIC_OPERATION1(injure, "eeii"), - MAGIC_OPERATION1(emote, "ei"), - MAGIC_OPERATION1(set_script_variable, "esi"), - MAGIC_OPERATION1(set_script_str, "ess"), - MAGIC_OPERATION1(set_hair_colour, "ei"), - MAGIC_OPERATION1(set_hair_style, "ei"), - MAGIC_OPERATION("drop_item", "l.ii", op_drop_item_for), - MAGIC_OPERATION1(drop_item_for, "l.iiei"), - MAGIC_OPERATION("gain_experience", "eiii", op_gain_exp), + MAGIC_OPERATION1(sfx, ".ii"_s), + MAGIC_OPERATION1(instaheal, "eii"_s), + MAGIC_OPERATION1(itemheal, "eii"_s), + MAGIC_OPERATION1(shroud, "ei"_s), + MAGIC_OPERATION("unshroud"_s, "e"_s, op_reveal), + MAGIC_OPERATION1(message, "es"_s), + MAGIC_OPERATION1(messenger_npc, "lissi"_s), + MAGIC_OPERATION1(move, "ed"_s), + MAGIC_OPERATION1(warp, "el"_s), + MAGIC_OPERATION1(banish, "e"_s), + MAGIC_OPERATION1(status_change, "eiiiiii"_s), + MAGIC_OPERATION1(stop_status_change, "ei"_s), + MAGIC_OPERATION1(override_attack, "eiiiiii"_s), + MAGIC_OPERATION1(create_item, "e.i"_s), + MAGIC_OPERATION1(aggravate, "eie"_s), + MAGIC_OPERATION1(spawn, "aeiiii"_s), + MAGIC_OPERATION1(injure, "eeii"_s), + MAGIC_OPERATION1(emote, "ei"_s), + MAGIC_OPERATION1(set_script_variable, "esi"_s), + MAGIC_OPERATION1(set_script_str, "ess"_s), + MAGIC_OPERATION1(set_hair_colour, "ei"_s), + MAGIC_OPERATION1(set_hair_style, "ei"_s), + MAGIC_OPERATION("drop_item"_s, "l.ii"_s, op_drop_item_for), + MAGIC_OPERATION1(drop_item_for, "l.iiei"_s), + MAGIC_OPERATION("gain_experience"_s, "eiii"_s, op_gain_exp), }; op_t *magic_get_op(ZString name) @@ -1004,7 +1004,7 @@ void spell_effect_report_termination(int invocation_id, int bl_id, dumb_ptr<block_list> entity = map_id2bl(bl_id); if (entity->bl_type == BL::PC) FPRINTF(stderr, - "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n", + "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n"_fmt, bl_id, sc_id); return; } @@ -1089,7 +1089,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n", + "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n"_fmt, invocation_->spell->name); return NULL; } @@ -1105,7 +1105,7 @@ cont_activation_record_t *add_stack_entry(dumb_ptr<invocation> invocation_, if (invocation_->stack_size >= MAX_STACK_SIZE) { FPRINTF(stderr, - "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n", + "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n"_fmt, invocation_->spell->name); invocation_->stack_size--; return NULL; @@ -1221,7 +1221,7 @@ dumb_ptr<effect_t> run_foreach(dumb_ptr<invocation> invocation, { magic_clear_var(&area); FPRINTF(stderr, - "[magic] Error in spell `%s': FOREACH loop over non-area\n", + "[magic] Error in spell `%s': FOREACH loop over non-area\n"_fmt, invocation->spell->name.c_str()); return return_location; } @@ -1271,7 +1271,7 @@ dumb_ptr<effect_t> run_for (dumb_ptr<invocation> invocation, magic_clear_var(&start); magic_clear_var(&stop); FPRINTF(stderr, - "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n", + "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n"_fmt, invocation->spell->name); return return_location; } @@ -1319,9 +1319,9 @@ void print_cfg(int i, effect_t *e) { int j; for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); - PRINTF("%p: ", e); + PRINTF("%p: "_fmt, e); if (!e) { @@ -1354,11 +1354,11 @@ void print_cfg(int i, effect_t *e) case EFFECT::IF: puts("IF"); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("THEN"); print_cfg(i + 1, e->e.e_if.true_branch); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("ELSE"); print_cfg(i + 1, e->e.e_if.false_branch); break; @@ -1395,7 +1395,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) #define REFRESH_INVOCATION invocation_ = map_id_is_spell(invocation_id); if (!invocation_) return interval_t::zero(); #ifdef DEBUG - FPRINTF(stderr, "Resuming execution: invocation of `%s'\n", + FPRINTF(stderr, "Resuming execution: invocation of `%s'\n"_fmt, invocation_->spell->name); print_cfg(1, invocation_->current_effect); #endif @@ -1406,7 +1406,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) int i; #ifdef DEBUG - FPRINTF(stderr, "Next step of type %d\n", e->ty); + FPRINTF(stderr, "Next step of type %d\n"_fmt, e->ty); dump_env(invocation_->env); #endif @@ -1464,9 +1464,9 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) ZString caster_name = (caster ? caster->status_key.name : CharName()).to__actual(); argrec_t arg[3] = { - {"@target", env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, - {"@caster", invocation_->caster}, - {"@caster_name$", caster_name}, + {"@target"_s, env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, + {"@caster"_s, invocation_->caster}, + {"@caster_name$"_s, caster_name}, }; int message_recipient = env->VAR(VAR_SCRIPTTARGET).ty == @@ -1516,7 +1516,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) for (i = 0; i < e->e.e_op.args_nr; i++) magic_eval(invocation_->env, &args[i], e->e.e_op.args[i]); - if (!magic_signature_check("effect", op->name, op->signature, + if (!magic_signature_check("effect"_s, op->name, op->signature, Slice<val_t>(args, e->e.e_op.args_nr), e->e.e_op.line_nr, e->e.e_op.column)) @@ -1535,7 +1535,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: Unknown effect %d\n", + "[magic] INTERNAL ERROR: Unknown effect %d\n"_fmt, e->ty); } diff --git a/src/map/magic-v2.cpp b/src/map/magic-v2.cpp index 41d29cd..20abc00 100644 --- a/src/map/magic-v2.cpp +++ b/src/map/magic-v2.cpp @@ -61,7 +61,7 @@ namespace magic_v2 if (zid != id) { FPRINTF(stderr, - "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", + "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n"_fmt, name, zid, id); } return zid == id; @@ -72,15 +72,15 @@ namespace magic_v2 { bool ok = true; - ok &= INTERN_ASSERT("min_casttime", VAR_MIN_CASTTIME); - ok &= INTERN_ASSERT("obscure_chance", VAR_OBSCURE_CHANCE); - ok &= INTERN_ASSERT("caster", VAR_CASTER); - ok &= INTERN_ASSERT("spellpower", VAR_SPELLPOWER); - ok &= INTERN_ASSERT("self_spell", VAR_SPELL); - ok &= INTERN_ASSERT("self_invocation", VAR_INVOCATION); - ok &= INTERN_ASSERT("target", VAR_TARGET); - ok &= INTERN_ASSERT("script_target", VAR_SCRIPTTARGET); - ok &= INTERN_ASSERT("location", VAR_LOCATION); + ok &= INTERN_ASSERT("min_casttime"_s, VAR_MIN_CASTTIME); + ok &= INTERN_ASSERT("obscure_chance"_s, VAR_OBSCURE_CHANCE); + ok &= INTERN_ASSERT("caster"_s, VAR_CASTER); + ok &= INTERN_ASSERT("spellpower"_s, VAR_SPELLPOWER); + ok &= INTERN_ASSERT("self_spell"_s, VAR_SPELL); + ok &= INTERN_ASSERT("self_invocation"_s, VAR_INVOCATION); + ok &= INTERN_ASSERT("target"_s, VAR_TARGET); + ok &= INTERN_ASSERT("script_target"_s, VAR_SCRIPTTARGET); + ok &= INTERN_ASSERT("location"_s, VAR_LOCATION); return ok; } @@ -91,7 +91,7 @@ namespace magic_v2 { if (!const_defm.insert({name, *val}).second) { - span.error(STRPRINTF("Redefinition of constant '%s'", name)); + span.error(STRPRINTF("Redefinition of constant '%s'"_fmt, name)); return false; } return true; @@ -184,14 +184,14 @@ namespace magic_v2 auto pair1 = magic_conf.spells_by_name.insert({spell->name, spell}); if (!pair1.second) { - span.error(STRPRINTF("Attempt to redefine spell '%s'", spell->name)); + span.error(STRPRINTF("Attempt to redefine spell '%s'"_fmt, spell->name)); return false; } auto pair2 = magic_conf.spells_by_invocation.insert({spell->invocation, spell}); if (!pair2.second) { - span.error(STRPRINTF("Attempt to redefine spell invocation '%s'", spell->invocation)); + span.error(STRPRINTF("Attempt to redefine spell invocation '%s'"_fmt, spell->invocation)); magic_conf.spells_by_name.erase(pair1.first); return false; } @@ -203,14 +203,14 @@ namespace magic_v2 auto pair1 = magic_conf.anchors_by_name.insert({anchor->name, anchor}); if (!pair1.second) { - span.error(STRPRINTF("Attempt to redefine teleport anchor '%s'", anchor->name)); + span.error(STRPRINTF("Attempt to redefine teleport anchor '%s'"_fmt, anchor->name)); return false; } auto pair2 = magic_conf.anchors_by_invocation.insert({anchor->name, anchor}); if (!pair2.second) { - span.error(STRPRINTF("Attempt to redefine anchor invocation '%s'", anchor->invocation)); + span.error(STRPRINTF("Attempt to redefine anchor invocation '%s'"_fmt, anchor->invocation)); magic_conf.anchors_by_name.erase(pair1.first); return false; } @@ -223,7 +223,7 @@ namespace magic_v2 RString name = proc->name; if (!procs.insert({name, std::move(*proc)}).second) { - span.error("procedure already exists"); + span.error("procedure already exists"_s); return false; } return true; @@ -234,7 +234,7 @@ namespace magic_v2 auto pi = procs.find(name); if (pi == procs.end()) { - span.error(STRPRINTF("Unknown procedure '%s'", name)); + span.error(STRPRINTF("Unknown procedure '%s'"_fmt, name)); return false; } @@ -242,7 +242,7 @@ namespace magic_v2 if (p->argv.size() != argvp->size()) { - span.error(STRPRINTF("Procedure %s/%zu invoked with %zu parameters", + span.error(STRPRINTF("Procedure %s/%zu invoked with %zu parameters"_fmt, name, p->argv.size(), argvp->size())); return false; } @@ -259,12 +259,12 @@ namespace magic_v2 op_t *op = magic_get_op(name); if (!op) { - span.error(STRPRINTF("Unknown operation '%s'", name)); + span.error(STRPRINTF("Unknown operation '%s'"_fmt, name)); return false; } if (op->signature.size() != argv.size()) { - span.error(STRPRINTF("Incorrect number of arguments to operation '%s': Expected %zu, found %zu", + span.error(STRPRINTF("Incorrect number of arguments to operation '%s': Expected %zu, found %zu"_fmt, name, op->signature.size(), argv.size())); return false; } @@ -295,12 +295,12 @@ namespace magic_v2 fun_t *fun = magic_get_fun(name); if (!fun) { - span.error(STRPRINTF("Unknown function '%s'", name)); + span.error(STRPRINTF("Unknown function '%s'"_fmt, name)); return false; } if (fun->signature.size() != argv.size()) { - span.error(STRPRINTF("Incorrect number of arguments to function '%s': Expected %zu, found %zu", + span.error(STRPRINTF("Incorrect number of arguments to function '%s': Expected %zu, found %zu"_fmt, name, fun->signature.size(), argv.size())); return false; } @@ -362,20 +362,20 @@ namespace magic_v2 return false; if (s._list[0]._type != sexpr::TOKEN) return false; - return s._list[0]._str == "DISABLED"; + return s._list[0]._str == "DISABLED"_s; } static bool parse_loc(const SExpr& s, e_location_t& loc) { if (s._type != sexpr::LIST) - return fail(s, "loc not list"); + return fail(s, "loc not list"_s); if (s._list.size() != 4) - return fail(s, "loc not 3 args"); + return fail(s, "loc not 3 args"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "loc cmd not tok"); - if (s._list[0]._str != "@") - return fail(s._list[0], "loc cmd not cmd"); + return fail(s._list[0], "loc cmd not tok"_s); + if (s._list[0]._str != "@"_s) + return fail(s._list[0], "loc cmd not cmd"_s); return parse_expression(s._list[1], loc.m) && parse_expression(s._list[2], loc.x) && parse_expression(s._list[3], loc.y); @@ -392,7 +392,7 @@ namespace magic_v2 val.ty = TYPE::INT; val.v.v_int = x._int; if (val.v.v_int != x._int) - return fail(x, "integer too large"); + return fail(x, "integer too large"_s); out = magic_new_expr(EXPR::VAL); out->e.e_val = val; @@ -410,9 +410,11 @@ namespace magic_v2 } case sexpr::TOKEN: { - ZString dirs[8] = { - ZString("S"), ZString("SW"), ZString("W"), ZString("NW"), ZString("N"), ZString("NE"), ZString("E"), ZString("SE"), - }; + earray<LString, DIR, DIR::COUNT> dirs //= + {{ + "S"_s, "SW"_s, "W"_s, "NW"_s, + "N"_s, "NE"_s, "E"_s, "SE"_s, + }}; auto begin = std::begin(dirs); auto end = std::end(dirs); auto it = std::find(begin, end, x._str); @@ -444,13 +446,13 @@ namespace magic_v2 break; case sexpr::LIST: if (x._list.empty()) - return fail(x, "empty list"); + return fail(x, "empty list"_s); { if (x._list[0]._type != sexpr::TOKEN) - return fail(x._list[0], "op not token"); + return fail(x._list[0], "op not token"_s); ZString op = x._list[0]._str; // area - if (op == "@") + if (op == "@"_s) { e_location_t loc; if (!parse_loc(x, loc)) @@ -460,7 +462,7 @@ namespace magic_v2 out->e.e_area.a.a_loc = loc; return true; } - if (op == "@+") + if (op == "@+"_s) { e_location_t loc; dumb_ptr<expr_t> width; @@ -478,7 +480,7 @@ namespace magic_v2 out->e.e_area.a.a_rect.height = height; return true; } - if (op == "TOWARDS") + if (op == "TOWARDS"_s) { e_location_t loc; dumb_ptr<expr_t> dir; @@ -500,33 +502,33 @@ namespace magic_v2 out->e.e_area.a.a_bar.depth = depth; return true; } - if (op == ".") + if (op == "."_s) { if (x._list.size() != 3) - return fail(x, ". not 2"); + return fail(x, ". not 2"_s); dumb_ptr<expr_t> expr; if (!parse_expression(x._list[1], expr)) return false; if (x._list[2]._type != sexpr::TOKEN) - return fail(x._list[2], ".elem not name"); + return fail(x._list[2], ".elem not name"_s); ZString elem = x._list[2]._str; out = dot_expr(expr, intern_id(elem)); return true; } - static + static // TODO LString std::set<ZString> ops = { - "<", ">", "<=", ">=", "==", "!=", - "+", "-", "*", "%", "/", - "&", "^", "|", "<<", ">>", - "&&", "||", + "<"_s, ">"_s, "<="_s, ">="_s, "=="_s, "!="_s, + "+"_s, "-"_s, "*"_s, "%"_s, "/"_s, + "&"_s, "^"_s, "|"_s, "<<"_s, ">>"_s, + "&&"_s, "||"_s, }; // TODO implement unary operators if (ops.count(op)) { // operators are n-ary and left-associative if (x._list.size() < 3) - return fail(x, "operator not at least 2 args"); + return fail(x, "operator not at least 2 args"_s); auto begin = x._list.begin() + 1; auto end = x._list.end(); if (!parse_expression(*begin, out)) @@ -565,23 +567,23 @@ namespace magic_v2 item_data *item = itemdb_searchname(s._str); if (!item) - return fail(s, "no such item"); + return fail(s, "no such item"_s); id = item->nameid; return true; } if (s._type != sexpr::LIST) - return fail(s, "item not string or list"); + return fail(s, "item not string or list"_s); if (s._list.size() != 2) - return fail(s, "item list is not pair"); + return fail(s, "item list is not pair"_s); if (s._list[0]._type != sexpr::INT) - return fail(s._list[0], "item pair first not int"); + return fail(s._list[0], "item pair first not int"_s); count = s._list[0]._int; if (s._list[1]._type != sexpr::STRING) - return fail(s._list[1], "item pair second not name"); + return fail(s._list[1], "item pair second not name"_s); item_data *item = itemdb_searchname(s._list[1]._str); if (!item) - return fail(s, "no such item"); + return fail(s, "no such item"_s); id = item->nameid; return true; } @@ -590,18 +592,18 @@ namespace magic_v2 bool parse_spellguard(const SExpr& s, dumb_ptr<spellguard_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "OR") + if (cmd == "OR"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); if (begin == end) - return fail(s, "missing arguments"); + return fail(s, "missing arguments"_s); if (!parse_spellguard(*begin, out)) return false; ++begin; @@ -617,14 +619,14 @@ namespace magic_v2 } return true; } - if (cmd == "GUARD") + if (cmd == "GUARD"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); while (is_comment(end[-1])) --end; if (begin == end) - return fail(s, "missing arguments"); + return fail(s, "missing arguments"_s); if (!parse_spellguard(end[-1], out)) return false; --end; @@ -639,10 +641,10 @@ namespace magic_v2 } return true; } - if (cmd == "REQUIRE") + if (cmd == "REQUIRE"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> condition; if (!parse_expression(s._list[1], condition)) return false; @@ -650,10 +652,10 @@ namespace magic_v2 out->s.s_condition = condition; return true; } - if (cmd == "MANA") + if (cmd == "MANA"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> mana; if (!parse_expression(s._list[1], mana)) return false; @@ -661,10 +663,10 @@ namespace magic_v2 out->s.s_mana = mana; return true; } - if (cmd == "CASTTIME") + if (cmd == "CASTTIME"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> casttime; if (!parse_expression(s._list[1], casttime)) return false; @@ -672,7 +674,7 @@ namespace magic_v2 out->s.s_casttime = casttime; return true; } - if (cmd == "CATALYSTS") + if (cmd == "CATALYSTS"_s) { dumb_ptr<component_t> items = nullptr; for (auto it = s._list.begin() + 1, end = s._list.end(); it != end; ++it) @@ -686,7 +688,7 @@ namespace magic_v2 out->s.s_catalysts = items; return true; } - if (cmd == "COMPONENTS") + if (cmd == "COMPONENTS"_s) { dumb_ptr<component_t> items = nullptr; for (auto it = s._list.begin() + 1, end = s._list.end(); it != end; ++it) @@ -700,7 +702,7 @@ namespace magic_v2 out->s.s_components = items; return true; } - return fail(s._list[0], "unknown guard"); + return fail(s._list[0], "unknown guard"_s); } static @@ -727,25 +729,25 @@ namespace magic_v2 bool parse_effect(const SExpr& s, dumb_ptr<effect_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "BLOCK") + if (cmd == "BLOCK"_s) { return build_effect_list(s._list.begin() + 1, s._list.end(), out); } - if (cmd == "SET") + if (cmd == "SET"_s) { if (s._list.size() != 3) - return fail(s, "not 2 args"); + return fail(s, "not 2 args"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "not token"); + return fail(s._list[1], "not token"_s); ZString name = s._list[1]._str; if (find_constant(name)) - return fail(s._list[1], "assigning to constant"); + return fail(s._list[1], "assigning to constant"_s); dumb_ptr<expr_t> expr; if (!parse_expression(s._list[2], expr)) return false; @@ -755,72 +757,72 @@ namespace magic_v2 out->e.e_assign.expr = expr; return true; } - if (cmd == "SCRIPT") + if (cmd == "SCRIPT"_s) { if (s._list.size() != 2) - return fail(s, "not 1 arg"); + return fail(s, "not 1 arg"_s); if (s._list[1]._type != sexpr::STRING) - return fail(s._list[1], "not string"); + return fail(s._list[1], "not string"_s); ZString body = s._list[1]._str; std::unique_ptr<const ScriptBuffer> script = parse_script(body, s._list[1]._span.begin.line, true); if (!script) - return fail(s._list[1], "script does not compile"); + return fail(s._list[1], "script does not compile"_s); out = new_effect(EFFECT::SCRIPT); out->e.e_script = dumb_ptr<const ScriptBuffer>(script.release()); return true; } - if (cmd == "SKIP") + if (cmd == "SKIP"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::SKIP); return true; } - if (cmd == "ABORT") + if (cmd == "ABORT"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::ABORT); return true; } - if (cmd == "END") + if (cmd == "END"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::END); return true; } - if (cmd == "BREAK") + if (cmd == "BREAK"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::BREAK); return true; } - if (cmd == "FOREACH") + if (cmd == "FOREACH"_s) { if (s._list.size() != 5) - return fail(s, "not 4 arg"); + return fail(s, "not 4 arg"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "foreach type not token"); + return fail(s._list[1], "foreach type not token"_s); ZString type = s._list[1]._str; FOREACH_FILTER filter; - if (type == "PC") + if (type == "PC"_s) filter = FOREACH_FILTER::PC; - else if (type == "MOB") + else if (type == "MOB"_s) filter = FOREACH_FILTER::MOB; - else if (type == "ENTITY") + else if (type == "ENTITY"_s) filter = FOREACH_FILTER::ENTITY; - else if (type == "SPELL") + else if (type == "SPELL"_s) filter = FOREACH_FILTER::SPELL; - else if (type == "TARGET") + else if (type == "TARGET"_s) filter = FOREACH_FILTER::TARGET; - else if (type == "NPC") + else if (type == "NPC"_s) filter = FOREACH_FILTER::NPC; else - return fail(s._list[1], "unknown foreach filter"); + return fail(s._list[1], "unknown foreach filter"_s); if (s._list[2]._type != sexpr::TOKEN) - return fail(s._list[2], "foreach var not token"); + return fail(s._list[2], "foreach var not token"_s); ZString var = s._list[2]._str; dumb_ptr<expr_t> area; dumb_ptr<effect_t> effect; @@ -835,12 +837,12 @@ namespace magic_v2 out->e.e_foreach.filter = filter; return true; } - if (cmd == "FOR") + if (cmd == "FOR"_s) { if (s._list.size() != 5) - return fail(s, "not 4 arg"); + return fail(s, "not 4 arg"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "for var not token"); + return fail(s._list[1], "for var not token"_s); ZString var = s._list[1]._str; dumb_ptr<expr_t> low; dumb_ptr<expr_t> high; @@ -858,10 +860,10 @@ namespace magic_v2 out->e.e_for.body = effect; return true; } - if (cmd == "IF") + if (cmd == "IF"_s) { if (s._list.size() != 3 && s._list.size() != 4) - return fail(s, "not 2 or 3 args"); + return fail(s, "not 2 or 3 args"_s); dumb_ptr<expr_t> cond; dumb_ptr<effect_t> if_true; dumb_ptr<effect_t> if_false; @@ -882,10 +884,10 @@ namespace magic_v2 out->e.e_if.false_branch = if_false; return true; } - if (cmd == "WAIT") + if (cmd == "WAIT"_s) { if (s._list.size() != 2) - return fail(s, "not 1 arg"); + return fail(s, "not 1 arg"_s); dumb_ptr<expr_t> expr; if (!parse_expression(s._list[1], expr)) return false; @@ -893,12 +895,12 @@ namespace magic_v2 out->e.e_sleep = expr; return true; } - if (cmd == "CALL") + if (cmd == "CALL"_s) { if (s._list.size() < 2) - return fail(s, "call what?"); + return fail(s, "call what?"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "call token please"); + return fail(s._list[1], "call token please"_s); ZString func = s._list[1]._str; auto argvp = dumb_ptr<std::vector<dumb_ptr<expr_t>>>::make(); for (auto it = s._list.begin() + 2, end = s._list.end(); it != end; ++it) @@ -925,16 +927,16 @@ namespace magic_v2 bool parse_spellbody(const SExpr& s, dumb_ptr<spellguard_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "=>") + if (cmd == "=>"_s) { if (s._list.size() != 3) - return fail(s, "list does not have exactly 2 arguments"); + return fail(s, "list does not have exactly 2 arguments"_s); dumb_ptr<spellguard_t> guard; if (!parse_spellguard(s._list[1], guard)) return false; @@ -944,10 +946,10 @@ namespace magic_v2 out = spellguard_implication(guard, body); return true; } - if (cmd == "|") + if (cmd == "|"_s) { if (s._list.size() == 1) - return fail(s, "spellbody choice empty"); + return fail(s, "spellbody choice empty"_s); auto begin = s._list.begin() + 1; auto end = s._list.end(); if (!parse_spellbody(*begin, out)) @@ -965,7 +967,7 @@ namespace magic_v2 } return true; } - if (cmd == "EFFECT") + if (cmd == "EFFECT"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); @@ -978,7 +980,7 @@ namespace magic_v2 --end; if (end[-1]._type == sexpr::LIST && !end[-1]._list.empty() && end[-1]._list[0]._type == sexpr::TOKEN - && end[-1]._list[0]._str == "ATEND") + && end[-1]._list[0]._str == "ATEND"_s) { auto atb = end[-1]._list.begin() + 1; auto ate = end[-1]._list.end(); @@ -995,7 +997,7 @@ namespace magic_v2 } if (end[-1]._type == sexpr::LIST && !end[-1]._list.empty() && end[-1]._list[0]._type == sexpr::TOKEN - && end[-1]._list[0]._str == "ATTRIGGER") + && end[-1]._list[0]._str == "ATTRIGGER"_s) { auto atb = end[-1]._list.begin() + 1; auto ate = end[-1]._list.end(); @@ -1015,20 +1017,20 @@ namespace magic_v2 out->s.s_effect.at_end = atend; return true; } - return fail(s._list[0], "unknown spellbody"); + return fail(s._list[0], "unknown spellbody"_s); } static bool parse_top_set(const std::vector<SExpr>& in) { if (in.size() != 3) - return fail(in[0], "not 2 arguments"); + return fail(in[0], "not 2 arguments"_s); ZString name = in[1]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[2], expr)) return false; if (find_constant(name)) - return fail(in[1], "assign constant"); + return fail(in[1], "assign constant"_s); size_t var_id = intern_id(name); magic_eval(dumb_ptr<env_t>(&magic_default_env), &magic_conf.varv[var_id].val, expr); return true; @@ -1037,9 +1039,9 @@ namespace magic_v2 bool parse_const(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() != 3) - return fail(in[0], "not 2 arguments"); + return fail(in[0], "not 2 arguments"_s); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "not token"); + return fail(in[1], "not token"_s); ZString name = in[1]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[2], expr)) @@ -1052,13 +1054,13 @@ namespace magic_v2 bool parse_anchor(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() != 4) - return fail(in[0], "not 3 arguments"); + return fail(in[0], "not 3 arguments"_s); auto anchor = dumb_ptr<teleport_anchor_t>::make(); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "not token"); + return fail(in[1], "not token"_s); anchor->name = in[1]._str; if (in[2]._type != sexpr::STRING) - return fail(in[2], "not string"); + return fail(in[2], "not string"_s); anchor->invocation = in[2]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[3], expr)) @@ -1070,17 +1072,17 @@ namespace magic_v2 bool parse_proc(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() < 4) - return fail(in[0], "not at least 3 arguments"); + return fail(in[0], "not at least 3 arguments"_s); auto proc = dumb_ptr<proc_t>::make(); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "name not token"); + return fail(in[1], "name not token"_s); proc->name = in[1]._str; if (in[2]._type != sexpr::LIST) - return fail(in[2], "args not list"); + return fail(in[2], "args not list"_s); for (const SExpr& arg : in[2]._list) { if (arg._type != sexpr::TOKEN) - return fail(arg, "arg not token"); + return fail(arg, "arg not token"_s); proc->argv.push_back(intern_id(arg._str)); } if (!build_effect_list(in.begin() + 3, in.end(), proc->body)) @@ -1091,37 +1093,37 @@ namespace magic_v2 bool parse_spell(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() < 6) - return fail(in[0], "not at least 5 arguments"); + return fail(in[0], "not at least 5 arguments"_s); if (in[1]._type != sexpr::LIST) - return fail(in[1], "flags not list"); + return fail(in[1], "flags not list"_s); auto spell = dumb_ptr<spell_t>::make(); for (const SExpr& s : in[1]._list) { if (s._type != sexpr::TOKEN) - return fail(s, "flag not token"); + return fail(s, "flag not token"_s); SPELL_FLAG flag = SPELL_FLAG::ZERO; - if (s._str == "LOCAL") + if (s._str == "LOCAL"_s) flag = SPELL_FLAG::LOCAL; - else if (s._str == "NONMAGIC") + else if (s._str == "NONMAGIC"_s) flag = SPELL_FLAG::NONMAGIC; - else if (s._str == "SILENT") + else if (s._str == "SILENT"_s) flag = SPELL_FLAG::SILENT; else - return fail(s, "unknown flag"); + return fail(s, "unknown flag"_s); if (bool(spell->flags & flag)) - return fail(s, "duplicate flag"); + return fail(s, "duplicate flag"_s); spell->flags |= flag; } if (in[2]._type != sexpr::TOKEN) - return fail(in[2], "name not token"); + return fail(in[2], "name not token"_s); spell->name = in[2]._str; if (in[3]._type != sexpr::STRING) - return fail(in[3], "invoc not string"); + return fail(in[3], "invoc not string"_s); spell->invocation = in[3]._str; if (in[4]._type != sexpr::LIST) - return fail(in[4], "spellarg not list"); + return fail(in[4], "spellarg not list"_s); if (in[4]._list.size() == 0) { spell->spellarg_ty = SPELLARG::NONE; @@ -1129,18 +1131,18 @@ namespace magic_v2 else { if (in[4]._list.size() != 2) - return fail(in[4], "spellarg not empty list or pair"); + return fail(in[4], "spellarg not empty list or pair"_s); if (in[4]._list[0]._type != sexpr::TOKEN) - return fail(in[4]._list[0], "spellarg type not token"); + return fail(in[4]._list[0], "spellarg type not token"_s); if (in[4]._list[1]._type != sexpr::TOKEN) - return fail(in[4]._list[1], "spellarg name not token"); + return fail(in[4]._list[1], "spellarg name not token"_s); ZString ty = in[4]._list[0]._str; - if (ty == "PC") + if (ty == "PC"_s) spell->spellarg_ty = SPELLARG::PC; - else if (ty == "STRING") + else if (ty == "STRING"_s) spell->spellarg_ty = SPELLARG::STRING; else - return fail(in[4]._list[0], "unknown spellarg type"); + return fail(in[4]._list[0], "unknown spellarg type"_s); ZString an = in[4]._list[1]._str; spell->arg = intern_id(an); } @@ -1148,19 +1150,19 @@ namespace magic_v2 for (;; ++it) { if (it == in.end()) - return fail(it[-1], "end of list scanning LET defs"); + return fail(it[-1], "end of list scanning LET defs"_s); if (is_comment(*it)) continue; if (it->_type != sexpr::LIST || it->_list.empty()) break; - if (it->_list[0]._type != sexpr::TOKEN || it->_list[0]._str != "LET") + if (it->_list[0]._type != sexpr::TOKEN || it->_list[0]._str != "LET"_s) break; if (it->_list[1]._type != sexpr::TOKEN) - return fail(it->_list[1], "let name not token"); + return fail(it->_list[1], "let name not token"_s); ZString name = it->_list[1]._str; if (find_constant(name)) - return fail(it->_list[1], "constant exists"); + return fail(it->_list[1], "constant exists"_s); dumb_ptr<expr_t> expr; if (!parse_expression(it->_list[2], expr)) return false; @@ -1170,7 +1172,7 @@ namespace magic_v2 spell->letdefv.push_back(let); } if (it + 1 != in.end()) - return fail(*it, "expected only one body entry besides LET"); + return fail(*it, "expected only one body entry besides LET"_s); // formally, 'guard' only refers to the first argument of '=>' // but internally, spellbodies use the same thing @@ -1186,23 +1188,23 @@ namespace magic_v2 { if (vs.empty()) { - span.error("Empty list at top"); + span.error("Empty list at top"_s); return false; } if (vs[0]._type != sexpr::TOKEN) - return fail(vs[0], "top not token"); + return fail(vs[0], "top not token"_s); ZString cmd = vs[0]._str; - if (cmd == "CONST") + if (cmd == "CONST"_s) return parse_const(span, vs); - if (cmd == "PROCEDURE") + if (cmd == "PROCEDURE"_s) return parse_proc(span, vs); - if (cmd == "SET") + if (cmd == "SET"_s) return parse_top_set(vs); - if (cmd == "SPELL") + if (cmd == "SPELL"_s) return parse_spell(span, vs); - if (cmd == "TELEPORT-ANCHOR") + if (cmd == "TELEPORT-ANCHOR"_s) return parse_anchor(span, vs); - return fail(vs[0], "Unknown top-level command"); + return fail(vs[0], "Unknown top-level command"_s); } static @@ -1214,14 +1216,14 @@ namespace magic_v2 if (is_comment(s)) continue; if (s._type != sexpr::LIST) - return fail(s, "top-level entity not a list or comment"); + return fail(s, "top-level entity not a list or comment"_s); if (!parse_top(s._span, s._list)) return false; } // handle low-level errors if (in.peek() != sexpr::TOK_EOF) { - in.span().error("parser gave up before end of file"); + in.span().error("parser gave up before end of file"_s); return false; } return true; @@ -1239,7 +1241,7 @@ bool load_magic_file_v2(ZString filename) bool rv = magic_v2::loop(in); if (!rv) { - in.span().error(STRPRINTF("next token: %s '%s'", sexpr::token_name(in.peek()), in.val_string())); + in.span().error(STRPRINTF("next token: %s '%s'"_fmt, sexpr::token_name(in.peek()), in.val_string())); } return rv; } diff --git a/src/map/magic.cpp b/src/map/magic.cpp index 9896b26..4ca5c4f 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -98,12 +98,12 @@ int magic_message(dumb_ptr<map_session_data> caster, XString source_invocation) effects = NULL; #ifdef DEBUG - FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_, + FPRINTF(stderr, "Found spell `%s', triggered = %d\n"_fmt, spell_, effects != NULL); #endif - MAP_LOG_PC(caster, "CAST %s %s", - spell->name, effects ? "SUCCESS" : "FAILURE"); + MAP_LOG_PC(caster, "CAST %s %s"_fmt, + spell->name, effects ? "SUCCESS"_s : "FAILURE"_s); if (effects) { diff --git a/src/map/map.cpp b/src/map/map.cpp index b49b225..7c14e9e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -100,9 +100,9 @@ int first_free_object_id = 0, last_object_id = 0; interval_t autosave_time = DEFAULT_AUTOSAVE_INTERVAL; int save_settings = 0xFFFF; -AString motd_txt = "conf/motd.txt"; +AString motd_txt = "conf/motd.txt"_s; -CharName wisp_server_name = stringish<CharName>("Server"); // can be modified in char-server configuration file +CharName wisp_server_name = stringish<CharName>("Server"_s); // can be modified in char-server configuration file static void map_delmap(MapName mapname); @@ -186,7 +186,7 @@ int map_addblock(dumb_ptr<block_list> bl) if (bl->bl_prev) { if (battle_config.error_log) - PRINTF("map_addblock error : bl->bl_prev!=NULL\n"); + PRINTF("map_addblock error : bl->bl_prev!=NULL\n"_fmt); return 0; } @@ -235,7 +235,7 @@ int map_delblock(dumb_ptr<block_list> bl) { // prevがNULLでnextがNULLでないのは有ってはならない if (battle_config.error_log) - PRINTF("map_delblock error : bl->bl_next!=NULL\n"); + PRINTF("map_delblock error : bl->bl_next!=NULL\n"_fmt); } return 0; } @@ -538,7 +538,7 @@ int map_addobject(dumb_ptr<block_list> bl) int i; if (!bl) { - PRINTF("map_addobject nullpo?\n"); + PRINTF("map_addobject nullpo?\n"_fmt); return 0; } if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM) @@ -549,7 +549,7 @@ int map_addobject(dumb_ptr<block_list> bl) if (i >= MAX_FLOORITEM) { if (battle_config.error_log) - PRINTF("no free object id\n"); + PRINTF("no free object id\n"_fmt); return 0; } first_free_object_id = i; @@ -573,7 +573,7 @@ int map_delobjectnofree(int id, BL type) if (object[id]->bl_type != type) { - FPRINTF(stderr, "Incorrect type: expected %d, got %d\n", + FPRINTF(stderr, "Incorrect type: expected %d, got %d\n"_fmt, type, object[id]->bl_type); abort(); @@ -1052,7 +1052,7 @@ int map_addnpc(map_local *m, dumb_ptr<npc_data> nd) if (i == MAX_NPC_PER_MAP) { if (battle_config.error_log) - PRINTF("too many NPCs in one map %s\n", m->name_); + PRINTF("too many NPCs in one map %s\n"_fmt, m->name_); return -1; } if (i == m->npc_num) @@ -1096,7 +1096,7 @@ void map_removenpc(void) } } } - PRINTF("%d NPCs removed.\n", n); + PRINTF("%d NPCs removed.\n"_fmt, n); } /*========================================== @@ -1244,7 +1244,7 @@ int map_setipport(MapName name, IP4Address ip, int port) // local -> check data if (ip != clif_getip() || port != clif_getport()) { - PRINTF("from char server : %s -> %s:%d\n", + PRINTF("from char server : %s -> %s:%d\n"_fmt, name, ip, port); return 1; } @@ -1275,7 +1275,7 @@ bool map_readmap(map_local *m, size_t num, MapName fn) int xs = m->xs = gat_v[0] | gat_v[1] << 8; int ys = m->ys = gat_v[2] | gat_v[3] << 8; - PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)", + PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)"_fmt, num, maps_db.size(), fn, xs, ys); fflush(stdout); @@ -1328,10 +1328,10 @@ bool map_readallmap(void) } } - PRINTF("\rMaps Loaded: %-65zu\n", maps_db.size()); + PRINTF("\rMaps Loaded: %-65zu\n"_fmt, maps_db.size()); if (maps_removed) { - PRINTF("Cowardly refusing to keep going after removing %d maps.\n", + PRINTF("Cowardly refusing to keep going after removing %d maps.\n"_fmt, maps_removed); return false; } @@ -1346,7 +1346,7 @@ bool map_readallmap(void) static void map_addmap(MapName mapname) { - if (mapname == "clear") + if (mapname == "clear"_s) { maps_db.clear(); return; @@ -1366,7 +1366,7 @@ void map_addmap(MapName mapname) */ void map_delmap(MapName mapname) { - if (mapname == "all") + if (mapname == "all"_s) { maps_db.clear(); return; @@ -1389,7 +1389,7 @@ void map_close_logfile(void) { if (map_logfile) { - AString filename = STRPRINTF("%s.%ld", map_logfile_name, map_logfile_index); + AString filename = STRPRINTF("%s.%ld"_fmt, map_logfile_name, map_logfile_index); const char *args[] = { "gzip", @@ -1416,7 +1416,7 @@ void map_start_logfile(long index) map_logfile_index = index; AString filename_buf = STRPRINTF( - "%s.%ld", + "%s.%ld"_fmt, map_logfile_name, map_logfile_index); map_logfile = make_unique<io::AppendFile>(filename_buf); @@ -1437,7 +1437,7 @@ void map_set_logfile(AString filename) map_start_logfile(tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT); - MAP_LOG("log-start v5"); + MAP_LOG("log-start v5"_fmt); } void map_log(XString line) @@ -1469,7 +1469,7 @@ bool map_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("Map configuration file not found at: %s\n", cfgName); + PRINTF("Map configuration file not found at: %s\n"_fmt, cfgName); return false; } @@ -1483,21 +1483,21 @@ bool map_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } - if (w1 == "userid") + if (w1 == "userid"_s) { AccountName name = stringish<AccountName>(w2); chrif_setuserid(name); } - else if (w1 == "passwd") + else if (w1 == "passwd"_s) { AccountPass pass = stringish<AccountPass>(w2); chrif_setpasswd(pass); } - else if (w1 == "char_ip") + else if (w1 == "char_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; @@ -1509,21 +1509,21 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Character server IP address : %s -> %s\n", + PRINTF("Character server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } chrif_setip(w2ip); } - else if (w1 == "char_port") + else if (w1 == "char_port"_s) { chrif_setport(atoi(w2.c_str())); } - else if (w1 == "map_ip") + else if (w1 == "map_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; @@ -1535,61 +1535,61 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Map server IP address : %s -> %s\n", + PRINTF("Map server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } clif_setip(w2ip); } - else if (w1 == "map_port") + else if (w1 == "map_port"_s) { clif_setport(atoi(w2.c_str())); } - else if (w1 == "map") + else if (w1 == "map"_s) { MapName name = VString<15>(w2); map_addmap(name); } - else if (w1 == "delmap") + else if (w1 == "delmap"_s) { MapName name = VString<15>(w2); map_delmap(name); } - else if (w1 == "npc") + else if (w1 == "npc"_s) { npc_addsrcfile(w2); } - else if (w1 == "delnpc") + else if (w1 == "delnpc"_s) { npc_delsrcfile(w2); } - else if (w1 == "autosave_time") + else if (w1 == "autosave_time"_s) { autosave_time = std::chrono::seconds(atoi(w2.c_str())); if (autosave_time <= interval_t::zero()) autosave_time = DEFAULT_AUTOSAVE_INTERVAL; } - else if (w1 == "motd_txt") + else if (w1 == "motd_txt"_s) { motd_txt = w2; } - else if (w1 == "mapreg_txt") + else if (w1 == "mapreg_txt"_s) { mapreg_txt = w2; } - else if (w1 == "gm_log") + else if (w1 == "gm_log"_s) { gm_log = std::move(w2); } - else if (w1 == "log_file") + else if (w1 == "log_file"_s) { map_set_logfile(w2); } - else if (w1 == "import") + else if (w1 == "import"_s) { rv &= map_config_read(w2); } @@ -1664,29 +1664,29 @@ int compare_item(struct item *a, struct item *b) static bool map_confs(XString key, ZString value) { - if (key == "map_conf") + if (key == "map_conf"_s) return map_config_read(value); - if (key == "battle_conf") + if (key == "battle_conf"_s) return battle_config_read(value); - if (key == "atcommand_conf") + if (key == "atcommand_conf"_s) return atcommand_config_read(value); - if (key == "item_db") + if (key == "item_db"_s) return itemdb_readdb(value); - if (key == "mob_db") + if (key == "mob_db"_s) return mob_readdb(value); - if (key == "mob_skill_db") + if (key == "mob_skill_db"_s) return mob_readskilldb(value); - if (key == "skill_db") + if (key == "skill_db"_s) return skill_readdb(value); - if (key == "magic_conf") + if (key == "magic_conf"_s) return load_magic_file_v2(value); - if (key == "resnametable") + if (key == "resnametable"_s) return load_resnametable(value); - if (key == "const_db") + if (key == "const_db"_s) return read_constdb(value); - PRINTF("unknown map conf key: %s\n", AString(key)); + PRINTF("unknown map conf key: %s\n"_fmt, AString(key)); return false; } @@ -1705,22 +1705,22 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } - else if (argvi == "--write-atcommand-config") + else if (argvi == "--write-atcommand-config"_s) { if (!argv) { - PRINTF("Missing argument\n"); + PRINTF("Missing argument\n"_fmt); exit(1); } ZString filename = argv.pop_front(); @@ -1729,7 +1729,7 @@ int do_init(Slice<ZString> argv) } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -1741,7 +1741,7 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-map.conf", map_confs); + runflag &= load_config_file("conf/tmwa-map.conf"_s, map_confs); battle_config_check(); runflag &= map_readallmap(); @@ -1758,9 +1758,9 @@ int do_init(Slice<ZString> argv) npc_event_do_oninit(); // npcのOnInitイベント実行 if (battle_config.pk_mode == 1) - PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"); + PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"_fmt); - PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, clif_getport()); return 0; diff --git a/src/map/map.hpp b/src/map/map.hpp index 0cec5e8..6d945d0 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -91,7 +91,7 @@ struct NpcEvent friend VString<49> convert_for_printf(NpcEvent ev) { - return STRNPRINTF(50, "%s::%s", ev.npc, ev.label); + return STRNPRINTF(50, "%s::%s"_fmt, ev.npc, ev.label); } }; bool extract(XString str, NpcEvent *ev); @@ -623,7 +623,7 @@ void map_log(XString line); # define MAP_LOG_PC(sd, fmt, ...) \ MAP_LOG("PC%d %s:%d,%d " fmt, \ - sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat")), sd->bl_x, sd->bl_y, ## __VA_ARGS__) + sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat"_s)), sd->bl_x, sd->bl_y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(TimerData *, tick_t, int); diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp index b73cbdd..59b6ff4 100644 --- a/src/map/map.t.hpp +++ b/src/map/map.t.hpp @@ -103,6 +103,8 @@ enum class NpcSubtype : uint8_t SHOP, SCRIPT, MESSAGE, + + COUNT, }; enum class mob_stat diff --git a/src/map/mapflag.cpp b/src/map/mapflag.cpp index 51af30a..65126d9 100644 --- a/src/map/mapflag.cpp +++ b/src/map/mapflag.cpp @@ -40,41 +40,41 @@ bool extract<MapFlag, void, void>(XString str, MapFlag *mf) { const struct { - ZString str; + LString str; MapFlag id; } flags[] = { - //{ZString("alias"), MapFlag::ALIAS}, - //{ZString("nomemo"), MapFlag::NOMEMO}, - {ZString("noteleport"), MapFlag::NOTELEPORT}, - {ZString("noreturn"), MapFlag::NORETURN}, - {ZString("monster_noteleport"), MapFlag::MONSTER_NOTELEPORT}, - {ZString("nosave"), MapFlag::NOSAVE}, - //{ZString("nobranch"), MapFlag::NOBRANCH}, - {ZString("nopenalty"), MapFlag::NOPENALTY}, - {ZString("pvp"), MapFlag::PVP}, - {ZString("pvp_noparty"), MapFlag::PVP_NOPARTY}, - //{ZString("pvp_noguild"), MapFlag::PVP_NOGUILD}, - //{ZString("pvp_nightmaredrop"), MapFlag::PVP_NIGHTMAREDROP}, - {ZString("pvp_nocalcrank"), MapFlag::PVP_NOCALCRANK}, - //{ZString("gvg"), MapFlag::GVG}, - //{ZString("gvg_noparty"), MapFlag::GVG_NOPARTY}, - //{ZString("nozenypenalty"), MapFlag::NOZENYPENALTY}, - //{ZString("notrade"), MapFlag::NOTRADE}, - //{ZString("noskill"), MapFlag::NOSKILL}, - {ZString("nowarp"), MapFlag::NOWARP}, - {ZString("nowarpto"), MapFlag::NOWARPTO}, - {ZString("nopvp"), MapFlag::NOPVP}, - //{ZString("noicewall"), MapFlag::NOICEWALL}, - {ZString("snow"), MapFlag::SNOW}, - {ZString("fog"), MapFlag::FOG}, - {ZString("sakura"), MapFlag::SAKURA}, - {ZString("leaves"), MapFlag::LEAVES}, - {ZString("rain"), MapFlag::RAIN}, - {ZString("no_player_drops"), MapFlag::NO_PLAYER_DROPS}, - {ZString("town"), MapFlag::TOWN}, - {ZString("outside"), MapFlag::OUTSIDE}, - {ZString("resave"), MapFlag::RESAVE}, + //{"alias"_s, MapFlag::ALIAS}, + //{"nomemo"_s, MapFlag::NOMEMO}, + {"noteleport"_s, MapFlag::NOTELEPORT}, + {"noreturn"_s, MapFlag::NORETURN}, + {"monster_noteleport"_s, MapFlag::MONSTER_NOTELEPORT}, + {"nosave"_s, MapFlag::NOSAVE}, + //{"nobranch"_s, MapFlag::NOBRANCH}, + {"nopenalty"_s, MapFlag::NOPENALTY}, + {"pvp"_s, MapFlag::PVP}, + {"pvp_noparty"_s, MapFlag::PVP_NOPARTY}, + //{"pvp_noguild"_s, MapFlag::PVP_NOGUILD}, + //{"pvp_nightmaredrop"_s, MapFlag::PVP_NIGHTMAREDROP}, + {"pvp_nocalcrank"_s, MapFlag::PVP_NOCALCRANK}, + //{"gvg"_s, MapFlag::GVG}, + //{"gvg_noparty"_s, MapFlag::GVG_NOPARTY}, + //{"nozenypenalty"_s, MapFlag::NOZENYPENALTY}, + //{"notrade"_s, MapFlag::NOTRADE}, + //{"noskill"_s, MapFlag::NOSKILL}, + {"nowarp"_s, MapFlag::NOWARP}, + {"nowarpto"_s, MapFlag::NOWARPTO}, + {"nopvp"_s, MapFlag::NOPVP}, + //{"noicewall"_s, MapFlag::NOICEWALL}, + {"snow"_s, MapFlag::SNOW}, + {"fog"_s, MapFlag::FOG}, + {"sakura"_s, MapFlag::SAKURA}, + {"leaves"_s, MapFlag::LEAVES}, + {"rain"_s, MapFlag::RAIN}, + {"no_player_drops"_s, MapFlag::NO_PLAYER_DROPS}, + {"town"_s, MapFlag::TOWN}, + {"outside"_s, MapFlag::OUTSIDE}, + {"resave"_s, MapFlag::RESAVE}, }; for (auto& pair : flags) if (str == pair.str) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index a96f829..2bf4ad1 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -322,7 +322,7 @@ int mob_gen_exp(mob_db_ *mob) * static_cast<double>(battle_config.base_exp_rate) / 100.); if (xp < 1) xp = 1; - PRINTF("Exp for mob '%s' generated: %d\n", mob->name, xp); + PRINTF("Exp for mob '%s' generated: %d\n"_fmt, mob->name, xp); return xp; } @@ -417,7 +417,7 @@ int mob_once_spawn(dumb_ptr<map_session_data> sd, } else if (x <= 0 || y <= 0) { - PRINTF("mob_once_spawn: ??\n"); + PRINTF("mob_once_spawn: ??\n"_fmt); } for (count = 0; count < amount; count++) @@ -948,7 +948,7 @@ void mob_timer(TimerData *, tick_t tick, int id, unsigned char data) break; default: if (battle_config.error_log == 1) - PRINTF("mob_timer : %d ?\n", + PRINTF("mob_timer : %d ?\n"_fmt, md->state.state); break; } @@ -1115,8 +1115,6 @@ int mob_spawn(int id) if (i >= 50) { - // if(battle_config.error_log==1) - // PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl_m].name); Timer(tick + std::chrono::seconds(5), std::bind(mob_delayspawn, ph::_1, ph::_2, id) @@ -1718,7 +1716,7 @@ int mob_randomwalk(dumb_ptr<mob_data> md, tick_t tick) if (md->move_fail_count > 1000) { if (battle_config.error_log == 1) - PRINTF("MOB cant move. random spawn %d, mob_class = %d\n", + PRINTF("MOB cant move. random spawn %d, mob_class = %d\n"_fmt, md->bl_id, md->mob_class); md->move_fail_count = 0; mob_spawn(md->bl_id); @@ -2358,12 +2356,10 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, mvp_sd = sd; } -// if(battle_config.battle_log) -// PRINTF("mob_damage %d %d %d\n",md->hp,max_hp,damage); if (md->bl_prev == NULL) { if (battle_config.error_log == 1) - PRINTF("mob_damage : BlockError!!\n"); + PRINTF("mob_damage : BlockError!!\n"_fmt); return 0; } @@ -2425,7 +2421,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, if (master_bl && master_bl->bl_type == BL::PC) { MAP_LOG_PC(master_bl->is_player(), - "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d", + "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d"_fmt, md2->bl_id, md2->mob_class, md->bl_id, md->mob_class, damage); } @@ -2461,7 +2457,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, return 0; } - MAP_LOG("MOB%d DEAD", md->bl_id); + MAP_LOG("MOB%d DEAD"_fmt, md->bl_id); // ----- ここから死亡処理 ----- @@ -2742,7 +2738,6 @@ void mob_warpslave_sub(dumb_ptr<block_list> bl, int id, int x, int y) static int mob_warpslave(dumb_ptr<mob_data> md, int x, int y) { -//PRINTF("warp slave\n"); map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl_id, md->bl_x, md->bl_y), md->bl_m, x - AREA_SIZE, y - AREA_SIZE, @@ -2808,7 +2803,7 @@ int mob_warp(dumb_ptr<mob_data> md, map_local *m, int x, int y, BeingRemoveWhy t else { if (battle_config.error_log == 1) - PRINTF("MOB %d warp failed, mob_class = %d\n", md->bl_id, md->mob_class); + PRINTF("MOB %d warp failed, mob_class = %d\n"_fmt, md->bl_id, md->mob_class); } md->target_id = 0; // タゲを解除する @@ -2821,7 +2816,7 @@ int mob_warp(dumb_ptr<mob_data> md, map_local *m, int x, int y, BeingRemoveWhy t && i == 1000) { if (battle_config.battle_log == 1) - PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl_id, x, y, + PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n"_fmt, md->bl_id, x, y, md->mob_class); } @@ -3015,7 +3010,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) return; if ((md = mbl->is_mob()) == NULL) { - PRINTF("mobskill_castend_id nullpo mbl->bl_id:%d\n", mbl->bl_id); + PRINTF("mobskill_castend_id nullpo mbl->bl_id:%d\n"_fmt, mbl->bl_id); return; } if (md->bl_type != BL::MOB || md->bl_prev == NULL) @@ -3029,7 +3024,6 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->bl_prev == NULL) { //スキルターゲットが存在しない - //PRINTF("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 return; } if (md->bl_m != bl->bl_m) @@ -3047,7 +3041,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + PRINTF("MOB skill castend skill=%d, mob_class = %d\n"_fmt, md->skillid, md->mob_class); mob_stop_walking(md, 0); @@ -3098,7 +3092,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id) md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + PRINTF("MOB skill castend skill=%d, mob_class = %d\n"_fmt, md->skillid, md->mob_class); mob_stop_walking(md, 0); } @@ -3148,7 +3142,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target, md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick(); if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n", + PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n"_fmt, target->bl_id, skill_id, skill_lv, static_cast<uint32_t>(casttime.count()), md->mob_class); @@ -3219,7 +3213,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md, md->state.skillcastcancel = ms->cancel; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n", + PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n"_fmt, skill_x, skill_y, skill_id, skill_lv, static_cast<uint32_t>(casttime.count()), md->mob_class); @@ -3384,8 +3378,8 @@ int mob_makedummymobdb(int mob_class) { int i; - SNPRINTF(mob_db[mob_class].name, 24, "mob%d", mob_class); - SNPRINTF(mob_db[mob_class].jname, 24, "mob%d", mob_class); + SNPRINTF(mob_db[mob_class].name, 24, "mob%d"_fmt, mob_class); + SNPRINTF(mob_db[mob_class].jname, 24, "mob%d"_fmt, mob_class); mob_db[mob_class].lv = 1; mob_db[mob_class].max_hp = 1000; mob_db[mob_class].max_sp = 1; @@ -3439,7 +3433,7 @@ bool mob_readdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("Unable to read mob db: %s\n", filename); + PRINTF("Unable to read mob db: %s\n"_fmt, filename); return false; } AString line; @@ -3517,7 +3511,7 @@ bool mob_readdb(ZString filename) if (!okay || mob_class <= 1000 || mob_class > 2000) { - PRINTF("bad mob line: %s\n", line); + PRINTF("bad mob line: %s\n"_fmt, line); rv = false; continue; } @@ -3570,7 +3564,7 @@ bool mob_readdb(ZString filename) if (mob_db[mob_class].base_exp == 0) mob_db[mob_class].base_exp = mob_gen_exp(&mob_db[mob_class]); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); } return rv; } @@ -3580,15 +3574,15 @@ bool extract<MobSkillCondition, void, void>(XString str, MobSkillCondition *msc) { const struct { - ZString str; + LString str; MobSkillCondition id; } cond1[] = { - {ZString("always"), MobSkillCondition::MSC_ALWAYS}, - {ZString("myhpltmaxrate"), MobSkillCondition::MSC_MYHPLTMAXRATE}, - {ZString("notintown"), MobSkillCondition::MSC_NOTINTOWN}, - {ZString("slavelt"), MobSkillCondition::MSC_SLAVELT}, - {ZString("slavele"), MobSkillCondition::MSC_SLAVELE}, + {"always"_s, MobSkillCondition::MSC_ALWAYS}, + {"myhpltmaxrate"_s, MobSkillCondition::MSC_MYHPLTMAXRATE}, + {"notintown"_s, MobSkillCondition::MSC_NOTINTOWN}, + {"slavelt"_s, MobSkillCondition::MSC_SLAVELT}, + {"slavele"_s, MobSkillCondition::MSC_SLAVELE}, }; for (auto& pair : cond1) if (str == pair.str) @@ -3604,14 +3598,14 @@ bool extract<MobSkillState, void, void>(XString str, MobSkillState *mss) { const struct { - ZString str; + LString str; MobSkillState id; } state[] = { - {ZString("any"), MobSkillState::ANY}, - {ZString("idle"), MobSkillState::MSS_IDLE}, - {ZString("walk"), MobSkillState::MSS_WALK}, - {ZString("attack"), MobSkillState::MSS_ATTACK}, + {"any"_s, MobSkillState::ANY}, + {"idle"_s, MobSkillState::MSS_IDLE}, + {"walk"_s, MobSkillState::MSS_WALK}, + {"attack"_s, MobSkillState::MSS_ATTACK}, }; for (auto& pair : state) if (str == pair.str) @@ -3627,12 +3621,12 @@ bool extract<MobSkillTarget, void, void>(XString str, MobSkillTarget *mst) { const struct { - ZString str; + LString str; MobSkillTarget id; } target[] = { - {ZString("target"), MobSkillTarget::MST_TARGET}, - {ZString("self"), MobSkillTarget::MST_SELF}, + {"target"_s, MobSkillTarget::MST_TARGET}, + {"self"_s, MobSkillTarget::MST_SELF}, }; for (auto& pair : target) if (str == pair.str) @@ -3650,7 +3644,7 @@ bool mob_readskilldb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } AString line; @@ -3662,7 +3656,7 @@ bool mob_readskilldb(ZString filename) continue; XString blah; - if (extract(line, record<','>(&mob_id, &blah)) && mob_id > 0 && blah == "clear") + if (extract(line, record<','>(&mob_id, &blah)) && mob_id > 0 && blah == "clear"_s) { mob_db[mob_id].skills.clear(); continue; @@ -3699,9 +3693,9 @@ bool mob_readskilldb(ZString filename) ) ) continue; - if (cancellable == "yes") + if (cancellable == "yes"_s) msv.cancel = true; - else if (cancellable == "no") + else if (cancellable == "no"_s) msv.cancel = false; else { @@ -3720,7 +3714,7 @@ bool mob_readskilldb(ZString filename) mob_db[mob_id].skills.push_back(std::move(msv)); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); } return rv; } diff --git a/src/map/mob.hpp b/src/map/mob.hpp index e7d81bd..570b5a9 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -34,9 +34,9 @@ # include "map.hpp" # include "skill.t.hpp" -# define ENGLISH_NAME stringish<MobName>("--en--") -# define JAPANESE_NAME stringish<MobName>("--ja--") -# define MOB_THIS_MAP stringish<MapName>("this") +# define ENGLISH_NAME stringish<MobName>("--en--"_s) +# define JAPANESE_NAME stringish<MobName>("--ja--"_s) +# define MOB_THIS_MAP stringish<MapName>("this"_s) struct mob_skill { diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 7fe13f1..3cef7c0 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -107,7 +107,7 @@ void npc_enable_sub(dumb_ptr<block_list> bl, dumb_ptr<npc_data> nd) NpcEvent aname; aname.npc = nd->name; - aname.label = stringish<ScriptLabel>("OnTouch"); + aname.label = stringish<ScriptLabel>("OnTouch"_s); if (sd->areanpc_id == nd->bl_id) return; sd->areanpc_id = nd->bl_id; @@ -120,7 +120,7 @@ int npc_enable(NpcName name, bool flag) dumb_ptr<npc_data> nd = npc_name2id(name); if (nd == NULL) { - PRINTF("npc_enable(%s, %s) failed.\n", name, flag ? "true" : "false"); + PRINTF("npc_enable(%s, %s) failed.\n"_fmt, name, flag ? "true"_s : "false"_s); return 0; } @@ -175,7 +175,7 @@ int npc_event_dequeue(dumb_ptr<map_session_data> sd) { if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueuel.front())) { - PRINTF("npc_event_dequeue(): Event timer is full.\n"); + PRINTF("npc_event_dequeue(): Event timer is full.\n"_fmt); return 0; } @@ -206,7 +206,7 @@ void npc_timer_event(NpcEvent eventname) if ((ev == NULL || (nd = ev->nd) == NULL)) { - PRINTF("npc_event: event not found [%s]\n", + PRINTF("npc_event: event not found [%s]\n"_fmt, eventname); return; } @@ -283,19 +283,19 @@ void npc_event_do_clock(TimerData *, tick_t) ScriptLabel buf; if (t.tm_min != ev_tm_b.tm_min) { - SNPRINTF(buf, 24, "OnMinute%02d", t.tm_min); + SNPRINTF(buf, 24, "OnMinute%02d"_fmt, t.tm_min); npc_event_doall(buf); - SNPRINTF(buf, 24, "OnClock%02d%02d", t.tm_hour, t.tm_min); + SNPRINTF(buf, 24, "OnClock%02d%02d"_fmt, t.tm_hour, t.tm_min); npc_event_doall(buf); } if (t.tm_hour != ev_tm_b.tm_hour) { - SNPRINTF(buf, 24, "OnHour%02d", t.tm_hour); + SNPRINTF(buf, 24, "OnHour%02d"_fmt, t.tm_hour); npc_event_doall(buf); } if (t.tm_mday != ev_tm_b.tm_mday) { - SNPRINTF(buf, 24, "OnDay%02d%02d", t.tm_mon + 1, t.tm_mday); + SNPRINTF(buf, 24, "OnDay%02d%02d"_fmt, t.tm_mon + 1, t.tm_mday); npc_event_doall(buf); } ev_tm_b = t; @@ -307,8 +307,8 @@ void npc_event_do_clock(TimerData *, tick_t) */ int npc_event_do_oninit(void) { - int c = npc_event_doall(stringish<ScriptLabel>("OnInit")); - PRINTF("npc: OnInit Event done. (%d npc)\n", c); + int c = npc_event_doall(stringish<ScriptLabel>("OnInit"_s)); + PRINTF("npc: OnInit Event done. (%d npc)\n"_fmt, c); Timer(gettick() + std::chrono::milliseconds(100), npc_event_do_clock, @@ -463,10 +463,10 @@ int npc_event(dumb_ptr<map_session_data> sd, NpcEvent eventname, if (sd == NULL) { - PRINTF("npc_event nullpo?\n"); + PRINTF("npc_event nullpo?\n"_fmt); } - if (ev == NULL && eventname.label == stringish<ScriptLabel>("OnTouch")) + if (ev == NULL && eventname.label == stringish<ScriptLabel>("OnTouch"_s)) return 1; if (ev == NULL || (nd = ev->nd) == NULL) @@ -480,7 +480,7 @@ int npc_event(dumb_ptr<map_session_data> sd, NpcEvent eventname, else { if (battle_config.error_log) - PRINTF("npc_event: event not found [%s]\n", + PRINTF("npc_event: event not found [%s]\n"_fmt, eventname); return 0; } @@ -521,7 +521,7 @@ static void npc_command_sub(NpcEvent key, struct event_data *ev, NpcName npcname, XString command) { if (ev->nd->name == npcname - && key.label.startswith("OnCommand")) + && key.label.startswith("OnCommand"_s)) { XString temp = key.label.xslice_t(9); @@ -567,7 +567,7 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) ys = m->npc[i]->is_warp()->warp.ys; break; case NpcSubtype::MESSAGE: - assert (0 && "I'm pretty sure these are never put on a map"); + assert (0 && "I'm pretty sure these are never put on a map"_s); xs = 0; ys = 0; break; @@ -589,7 +589,7 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) if (f) { if (battle_config.error_log) - PRINTF("npc_touch_areanpc : some bug \n"); + PRINTF("npc_touch_areanpc : some bug \n"_fmt); } return 1; } @@ -601,13 +601,13 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) m->npc[i]->is_warp()->warp.x, m->npc[i]->is_warp()->warp.y, BeingRemoveWhy::GONE); break; case NpcSubtype::MESSAGE: - assert (0 && "I'm pretty sure these NPCs are never put on a map."); + assert (0 && "I'm pretty sure these NPCs are never put on a map."_s); break; case NpcSubtype::SCRIPT: { NpcEvent aname; aname.npc = m->npc[i]->name; - aname.label = stringish<ScriptLabel>("OnTouch"); + aname.label = stringish<ScriptLabel>("OnTouch"_s); if (sd->areanpc_id == m->npc[i]->bl_id) return 1; @@ -666,7 +666,7 @@ int npc_click(dumb_ptr<map_session_data> sd, int id) if (sd->npc_id != 0) { if (battle_config.error_log) - PRINTF("npc_click: npc_id != 0\n"); + PRINTF("npc_click: npc_id != 0\n"_fmt); return 1; } @@ -751,7 +751,7 @@ int npc_buysellsel(dumb_ptr<map_session_data> sd, int id, int type) if (nd->npc_subtype != NpcSubtype::SHOP) { if (battle_config.error_log) - PRINTF("no such shop npc : %d\n", id); + PRINTF("no such shop npc : %d\n"_fmt, id); sd->npc_id = 0; return 1; } @@ -927,7 +927,7 @@ void npc_clearsrcfile(void) */ void npc_addsrcfile(AString name) { - if (name == "clear") + if (name == "clear"_s) { npc_clearsrcfile(); return; @@ -942,7 +942,7 @@ void npc_addsrcfile(AString name) */ void npc_delsrcfile(XString name) { - if (name == "all") + if (name == "all"_s) { npc_clearsrcfile(); return; @@ -961,19 +961,19 @@ void npc_delsrcfile(XString name) static void register_npc_name(dumb_ptr<npc_data> nd) { - ZString types[4] = - { - {"WARP"}, - {"SHOP"}, - {"SCRIPT"}, - {"MESSAGE"}, - }; + earray<LString, NpcSubtype, NpcSubtype::COUNT> types //= + {{ + "WARP"_s, + "SHOP"_s, + "SCRIPT"_s, + "MESSAGE"_s, + }}; if (!nd->name) { if (nd->npc_subtype == NpcSubtype::MESSAGE) return; - PRINTF("WARNING: npc with no name:\n%s @ %s,%d,%d\n", - types[static_cast<int>(nd->npc_subtype)], + PRINTF("WARNING: npc with no name:\n%s @ %s,%d,%d\n"_fmt, + types[nd->npc_subtype], nd->bl_m->name_, nd->bl_x, nd->bl_y); return; } @@ -982,12 +982,12 @@ void register_npc_name(dumb_ptr<npc_data> nd) if (nd->npc_subtype != NpcSubtype::WARP || nd_old->npc_subtype != NpcSubtype::WARP) { - PRINTF("WARNING: replacing npc with name: %s\n", nd->name); - PRINTF("old: %s @ %s,%d,%d\n", - types[static_cast<int>(nd_old->npc_subtype)], + PRINTF("WARNING: replacing npc with name: %s\n"_fmt, nd->name); + PRINTF("old: %s @ %s,%d,%d\n"_fmt, + types[nd_old->npc_subtype], nd_old->bl_m->name_, nd_old->bl_x, nd_old->bl_y); - PRINTF("new: %s @ %s,%d,%d\n", - types[static_cast<int>(nd->npc_subtype)], + PRINTF("new: %s @ %s,%d,%d\n"_fmt, + types[nd->npc_subtype], nd->bl_m->name_, nd->bl_x, nd->bl_y); } } @@ -1009,7 +1009,7 @@ int npc_parse_warp(XString w1, XString, NpcName w3, XString w4) if (!extract(w1, record<','>(&mapname, &x, &y)) || !extract(w4, record<','>(&xs, &ys, &to_mapname, &to_x, &to_y))) { - PRINTF("bad warp line : %s\n", w3); + PRINTF("bad warp line : %s\n"_fmt, w3); return 1; } @@ -1059,7 +1059,6 @@ int npc_parse_warp(XString w1, XString, NpcName w3, XString w4) } } -// PRINTF("warp npc %s %d read done\n",mapname,nd->bl_id); npc_warp++; nd->bl_type = BL::NPC; nd->npc_subtype = NpcSubtype::WARP; @@ -1116,7 +1115,7 @@ int npc_parse_shop(XString w1, XString, NpcName w3, ZString w4a) || (w4comma = std::find(w4a.begin(), w4a.end(), ',')) == w4a.end() || !extract(w4a.xislice_h(w4comma), &npc_class)) { - PRINTF("bad shop line : %s\n", w3); + PRINTF("bad shop line : %s\n"_fmt, w3); return 1; } dir = static_cast<DIR>(dir_); @@ -1127,8 +1126,8 @@ int npc_parse_shop(XString w1, XString, NpcName w3, ZString w4a) if (!extract(w4b, vrec<','>(&nd->shop_items))) { - PRINTF("bad shop items : %s\n", w3); - PRINTF(" somewhere --> %s\n", w4b); + PRINTF("bad shop items : %s\n"_fmt, w3); + PRINTF(" somewhere --> %s\n"_fmt, w4b); nd->shop_items.clear(); } @@ -1196,7 +1195,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, dumb_ptr<npc_data_script> nd; int evflag = 0; - if (w1 == "-") + if (w1 == "-"_s) { x = 0; y = 0; @@ -1207,16 +1206,16 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, int dir_; // TODO use enum directly in extract if (!extract(w1, record<','>(&mapname, &x, &y, &dir_)) || dir_ < 0 || dir_ >= 8 - || (w2 == "script" && !w4.contains(','))) + || (w2 == "script"_s && !w4.contains(','))) { - PRINTF("bad script line : %s\n", w3); + PRINTF("bad script line : %s\n"_fmt, w3); return 1; } dir = static_cast<DIR>(dir_); m = map_mapname2mapid(mapname); } - if (w2 == "script") + if (w2 == "script"_s) { // may be empty MString srcbuf; @@ -1255,7 +1254,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, } else { - assert(0 && "duplicate() is no longer supported!\n"); + assert(0 && "duplicate() is no longer supported!\n"_s); return 0; } @@ -1307,7 +1306,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, if (w3.contains(':')) { - assert(false && "feature removed"); + assert(false && "feature removed"_s); abort(); } { @@ -1329,7 +1328,6 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, nd->opt2 = Opt2::ZERO; nd->opt3 = Opt3::ZERO; - //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl_id,nd->class); npc_script++; nd->bl_type = BL::NPC; nd->npc_subtype = NpcSubtype::SCRIPT; @@ -1361,7 +1359,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, ScriptLabel lname = el.name; int pos = el.pos; - if (lname.startswith("On")) + if (lname.startswith("On"_s)) { struct event_data ev {}; ev.nd = nd; @@ -1380,7 +1378,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, int t_ = 0; ScriptLabel lname = el.name; int pos = el.pos; - if (lname.startswith("OnTimer") && extract(lname.xslice_t(7), &t_) && t_ > 0) + if (lname.startswith("OnTimer"_s) && extract(lname.xslice_t(7), &t_) && t_ > 0) { interval_t t = static_cast<interval_t>(t_); @@ -1469,7 +1467,7 @@ int npc_parse_mob(XString w1, XString, MobName w3, ZString w4) if (!extract(w1, record<',', 3>(&mapname, &x, &y, &xs, &ys)) || !extract(w4, record<',', 2>(&mob_class, &num, &delay1_, &delay2_, &eventname))) { - PRINTF("bad monster line : %s\n", w3); + PRINTF("bad monster line : %s\n"_fmt, w3); return 1; } interval_t delay1 = std::chrono::milliseconds(delay1_); @@ -1525,7 +1523,6 @@ int npc_parse_mob(XString w1, XString, MobName w3, ZString w4) npc_mob++; } - //PRINTF("warp npc %s %d read done\n",mapname,nd->bl_id); return 0; } @@ -1561,9 +1558,9 @@ int npc_parse_mapflag(XString w1, XString, XString w3, ZString w4) if (mf == MapFlag::NOSAVE) { - if (w4 == "SavePoint") + if (w4 == "SavePoint"_s) { - m->save.map_ = stringish<MapName>("SavePoint"); + m->save.map_ = stringish<MapName>("SavePoint"_s); m->save.x = -1; m->save.y = -1; } @@ -1679,11 +1676,11 @@ bool do_init_npc(void) io::ReadFile fp(nsl); if (!fp.is_open()) { - PRINTF("file not found : %s\n", nsl); + PRINTF("file not found : %s\n"_fmt, nsl); rv = false; continue; } - PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM, + PRINTF("\rLoading NPCs [%d]: %-54s"_fmt, npc_id - START_NPC_NUM, nsl); int lines = 0; AString zline; @@ -1698,7 +1695,7 @@ bool do_init_npc(void) if (!extract(zline, record<'|', 3>(&w1, &w2, &w3, &w4x)) || !w1 || !w2 || !w3) { - FPRINTF(stderr, "%s:%d: Broken script line: %s\n", nsl, lines, zline); + FPRINTF(stderr, "%s:%d: Broken script line: %s\n"_fmt, nsl, lines, zline); rv = false; continue; } @@ -1708,7 +1705,7 @@ bool do_init_npc(void) } assert(bool(w4x) == bool(w4z)); - if (w1 != "-" && w1 != "function") + if (w1 != "-"_s && w1 != "function"_s) { auto comma = std::find(w1.begin(), w1.end(), ','); MapName mapname = stringish<MapName>(w1.xislice_h(comma)); @@ -1716,24 +1713,24 @@ bool do_init_npc(void) if (m == nullptr) { // "mapname" is not assigned to this server - FPRINTF(stderr, "%s:%d: Map not found: %s\n", nsl, lines, mapname); + FPRINTF(stderr, "%s:%d: Map not found: %s\n"_fmt, nsl, lines, mapname); rv = false; continue; } } - if (w2 == "warp") + if (w2 == "warp"_s) { NpcName npcname = stringish<NpcName>(w3); npc_parse_warp(w1, w2, npcname, w4z); } - else if (w2 == "shop") + else if (w2 == "shop"_s) { NpcName npcname = stringish<NpcName>(w3); npc_parse_shop(w1, w2, npcname, w4z); } - else if (w2 == "script") + else if (w2 == "script"_s) { - if (w1 == "function") + if (w1 == "function"_s) { npc_parse_function(w1, w2, w3, w4z, w4x, fp, &lines); @@ -1745,29 +1742,29 @@ bool do_init_npc(void) w4x, fp, &lines); } } - else if (w2 == "monster") + else if (w2 == "monster"_s) { MobName mobname = stringish<MobName>(w3); npc_parse_mob(w1, w2, mobname, w4z); } - else if (w2 == "mapflag") + else if (w2 == "mapflag"_s) { npc_parse_mapflag(w1, w2, w3, w4z); } else { - PRINTF("odd script line: %s\n", zline); + PRINTF("odd script line: %s\n"_fmt, zline); script_errors++; } } fflush(stdout); } - PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d] %20s\n", - npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, ""); + PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d] %20s\n"_fmt, + npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, ""_s); if (script_errors) { - PRINTF("Cowardly refusing to continue after %d errors\n", script_errors); + PRINTF("Cowardly refusing to continue after %d errors\n"_fmt, script_errors); rv = false; } return rv; diff --git a/src/map/party.cpp b/src/map/party.cpp index 75c54cf..876e6bb 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -121,7 +121,7 @@ void party_created(int account_id, int fail, int party_id, PartyName name) struct party *p = party_db.search(party_id); if (p != NULL) { - PRINTF("party_created(): ID already exists!\n"); + PRINTF("party_created(): ID already exists!\n"_fmt); exit(1); } @@ -177,7 +177,7 @@ int party_check_member(struct party *p) { sd->status.party_id = 0; if (battle_config.error_log) - PRINTF("party: check_member %d[%s] is not member\n", + PRINTF("party: check_member %d[%s] is not member\n"_fmt, sd->status_key.account_id, sd->status_key.name); } } @@ -355,7 +355,7 @@ int party_member_added(int party_id, int account_id, int flag) if (flag == 0) { if (battle_config.error_log) - PRINTF("party: member added error %d is not online\n", + PRINTF("party: member added error %d is not online\n"_fmt, account_id); intif_party_leave(party_id, account_id); // キャラ側に登録できなかったため脱退要求を出す } @@ -367,7 +367,7 @@ int party_member_added(int party_id, int account_id, int flag) if (p == NULL) { - PRINTF("party_member_added: party %d not found.\n", party_id); + PRINTF("party_member_added: party %d not found.\n"_fmt, party_id); intif_party_leave(party_id, account_id); return 0; } @@ -537,7 +537,7 @@ void party_recv_movemap(int party_id, int account_id, MapName mapname, struct party_member *m = &p->member[i]; if (m == NULL) { - PRINTF("party_recv_movemap nullpo?\n"); + PRINTF("party_recv_movemap nullpo?\n"_fmt); return; } if (m->account_id == account_id) @@ -551,7 +551,7 @@ void party_recv_movemap(int party_id, int account_id, MapName mapname, if (i == MAX_PARTY) { if (battle_config.error_log) - PRINTF("party: not found member %d on %d[%s]", account_id, + PRINTF("party: not found member %d on %d[%s]"_fmt, account_id, party_id, p->name); return; } diff --git a/src/map/path.cpp b/src/map/path.cpp index f0204a4..5b7ea1f 100644 --- a/src/map/path.cpp +++ b/src/map/path.cpp @@ -60,7 +60,7 @@ void push_heap_path(int *heap, struct tmp_path *tp, int index) if (heap == NULL || tp == NULL) { - PRINTF("push_heap_path nullpo\n"); + PRINTF("push_heap_path nullpo\n"_fmt); return; } @@ -90,7 +90,7 @@ void update_heap_path(int *heap, struct tmp_path *tp, int index) break; if (h == heap[0]) { - FPRINTF(stderr, "update_heap_path bug\n"); + FPRINTF(stderr, "update_heap_path bug\n"_fmt); exit(1); } for (i = (h - 1) / 2; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 0256eff..eecaece 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -86,7 +86,7 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200; MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \ sd->status.base_level, sd->status.base_exp, \ sd->status.job_level, sd->status.job_exp, sd->status.skill_point, \ - sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount"))) + sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount"_s))) #define MAP_LOG_MAGIC(sd, suffix) \ MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \ @@ -96,8 +96,8 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200; sd->status.skill[SkillID::TMW_MAGIC_TRANSMUTE].lv, \ sd->status.skill[SkillID::TMW_MAGIC_NATURE].lv, \ sd->status.skill[SkillID::TMW_MAGIC_ETHER].lv, \ - pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) & 0xffff, \ - (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) >> 24) & 0xff) + pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) & 0xffff, \ + (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) >> 24) & 0xff) static //const int max_weight_base_0 = 20000; @@ -458,7 +458,7 @@ void pc_makesavestatus(dumb_ptr<map_session_data> sd) if (sd->bl_m->flag.get(MapFlag::NOSAVE)) { map_local *m = sd->bl_m; - if (m->save.map_ == "SavePoint") + if (m->save.map_ == "SavePoint"_s) sd->status.last_point = sd->status.save_point; else sd->status.last_point = m->save; @@ -662,9 +662,9 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, return 1; } - MAP_LOG_STATS(sd, "LOGIN"); - MAP_LOG_XP(sd, "LOGIN"); - MAP_LOG_MAGIC(sd, "LOGIN"); + MAP_LOG_STATS(sd, "LOGIN"_fmt); + MAP_LOG_XP(sd, "LOGIN"_fmt); + MAP_LOG_MAGIC(sd, "LOGIN"_fmt); really_memzero_this(&sd->state); // 基本的な初期化 @@ -702,7 +702,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // The above is no longer accurate now that we use <chrono>, but // I'm still not reverting this. // -o11c - sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK"); + sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK"_s); // アカウント変数の送信要求 intif_request_accountreg(sd); @@ -725,10 +725,10 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // This would leak information. // It's better to make it obvious that players can see you. if (false && bool(old_option & Option::INVISIBILITY)) - is_atcommand(sd->sess, sd, "@invisible", 0); + is_atcommand(sd->sess, sd, "@invisible"_s, 0); if (bool(old_option & Option::HIDE)) - is_atcommand(sd->sess, sd, "@hide", 0); + is_atcommand(sd->sess, sd, "@hide"_s, 0); // atcommand_hide might already send it, but also might not clif_changeoption(sd); } @@ -765,19 +765,19 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, map_addchariddb(sd->status_key.char_id, sd->status_key.name); //スパノビ用死にカウンターのスクリプト変数からの読み出しとsdへのセット - sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER")); + sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s)); // ステータス初期計算など pc_calcstatus(sd, 1); if (pc_isGM(sd)) { - PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n", + PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n"_fmt, sd->status_key.name, sd->status_key.account_id, pc_isGM(sd)); clif_updatestatus(sd, SP::GM); } else - PRINTF("Connection accepted: Character '%s' (account: %d).\n", + PRINTF("Connection accepted: Character '%s' (account: %d).\n"_fmt, sd->status_key.name, sd->status_key.account_id); sd->auto_ban_info.in_progress = 0; @@ -796,11 +796,11 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // message of the limited time of the account if (connect_until_time) { - // don't display if it's unlimited or unknow value - char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: "); - REPLACE_TIMESTAMP(tmpstr, connect_until_time); + timestamp_seconds_buffer buffer; + stamp_time(buffer, &connect_until_time); + AString tmpstr = STRPRINTF("Your account time limit is: %s"_fmt, buffer); - clif_wis_message(sd->sess, wisp_server_name, const_(tmpstr)); + clif_wis_message(sd->sess, wisp_server_name, tmpstr); } pc_calcstatus(sd, 1); @@ -817,7 +817,7 @@ void pc_show_motd(dumb_ptr<map_session_data> sd) // If you remove the sending of this message, // the license does not permit you to publicly use this software. - clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool"); + clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool"_s); sd->state.seen_motd = true; io::ReadFile in(motd_txt); @@ -1099,8 +1099,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), sd->bl_id, 0, @@ -1113,8 +1113,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) //二刀流武器以外 argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->watk += sd->inventory_data[index]->atk; @@ -1128,8 +1128,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->watk += sd->inventory_data[index]->atk; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), @@ -1155,8 +1155,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { //まだ属性が入っていない argrec_t arg[2] = { - {"@slotId", static_cast<int>(EQUIP::ARROW)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(EQUIP::ARROW)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->state.lr_flag = 2; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), @@ -1206,7 +1206,6 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) } dstr = str / 10; sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5; -//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5); sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5); sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7); if (sd->matk1 < sd->matk2) @@ -1731,7 +1730,7 @@ int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val) break; default: if (battle_config.error_log) - PRINTF("pc_bonus: unknown type %d %d !\n", + PRINTF("pc_bonus: unknown type %d %d !\n"_fmt, type, val); break; } @@ -1776,7 +1775,7 @@ int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val) #endif default: if (battle_config.error_log) - PRINTF("pc_bonus2: unknown type %d %d %d!\n", + PRINTF("pc_bonus2: unknown type %d %d %d!\n"_fmt, type, type2, val); break; } @@ -1794,7 +1793,7 @@ int pc_skill(dumb_ptr<map_session_data> sd, SkillID id, int level, int flag) if (level > MAX_SKILL_LEVEL) { if (battle_config.error_log) - PRINTF("support card skill only!\n"); + PRINTF("support card skill only!\n"_fmt); return 0; } if (!flag && (sd->status.skill[id].lv || level == 0)) @@ -1970,7 +1969,7 @@ PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data, struct item_data *data; int i, w; - MAP_LOG_PC(sd, "PICKUP %d %d", item_data->nameid, amount); + MAP_LOG_PC(sd, "PICKUP %d %d"_fmt, item_data->nameid, amount); nullpo_retr(PickupFail::BAD_ITEM, sd); nullpo_retr(PickupFail::BAD_ITEM, item_data); @@ -2314,7 +2313,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd, if (x || y) { if (battle_config.error_log) - PRINTF("stacked (%d,%d)\n", x, y); + PRINTF("stacked (%d,%d)\n"_fmt, x, y); } do { @@ -2915,7 +2914,7 @@ int pc_checkbaselevelup(dumb_ptr<map_session_data> sd) //レベルアップしたのでパーティー情報を更新する //(公平範囲チェック) party_send_movemap(sd); - MAP_LOG_XP(sd, "LEVELUP"); + MAP_LOG_XP(sd, "LEVELUP"_fmt); return 1; } @@ -2971,7 +2970,7 @@ int pc_checkjoblevelup(dumb_ptr<map_session_data> sd) clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); - MAP_LOG_PC(sd, "SKILLPOINTS-UP %d", sd->status.skill_point); + MAP_LOG_PC(sd, "SKILLPOINTS-UP %d"_fmt, sd->status.skill_point); if (sd->status.job_level < 250 && sd->status.job_level < sd->status.base_level * 2) @@ -2992,16 +2991,16 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp, if (sd->bl_prev == NULL || pc_isdead(sd)) return 0; - earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //= + earray<LString, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //= {{ - "KILLXP", - "HEALXP", - "SCRIPTXP", - "SHAREXP", + "KILLXP"_s, + "HEALXP"_s, + "SCRIPTXP"_s, + "SHAREXP"_s, /* Insert new types here */ - "UNKNOWNXP" + "UNKNOWNXP"_s }}; - MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp, reasons[reason]); + MAP_LOG_PC(sd, "GAINXP %d %d %s"_fmt, base_exp, job_exp, reasons[reason]); if (!battle_config.multi_level_up && pc_nextbaseafter(sd)) { @@ -3053,7 +3052,7 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp, if (battle_config.disp_experience) { AString output = STRPRINTF( - "Experienced Gained Base:%d Job:%d", + "Experienced Gained Base:%d Job:%d"_fmt, base_exp, job_exp); clif_displaymessage(sd->sess, output); } @@ -3181,7 +3180,7 @@ int pc_statusup(dumb_ptr<map_session_data> sd, SP type) pc_calcstatus(sd, 0); clif_statusupack(sd, type, 1, val); - MAP_LOG_STATS(sd, "STATUP"); + MAP_LOG_STATS(sd, "STATUP"_fmt); return 0; } @@ -3208,7 +3207,7 @@ int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val) clif_updatestatus(sd, type); pc_calcstatus(sd, 0); clif_statusupack(sd, type, 1, val); - MAP_LOG_STATS(sd, "STATUP2"); + MAP_LOG_STATS(sd, "STATUP2"_fmt); return 0; } @@ -3232,7 +3231,7 @@ int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num) clif_skillup(sd, skill_num); clif_updatestatus(sd, SP::SKILLPOINT); clif_skillinfoblock(sd); - MAP_LOG_PC(sd, "SKILLUP %d %d %d", + MAP_LOG_PC(sd, "SKILLUP %d %d %d"_fmt, skill_num, sd->status.skill[skill_num].lv, skill_power(sd, skill_num)); } @@ -3323,7 +3322,7 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type) clif_skillinfoblock(sd); pc_calcstatus(sd, 0); - MAP_LOG_STATS(sd, "STATRESET"); + MAP_LOG_STATS(sd, "STATRESET"_fmt); return 0; } @@ -3401,17 +3400,17 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, { if (src->bl_type == BL::PC) { - MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d", + MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d"_fmt, src->is_player()->status_key.char_id, damage); } else { - MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d", src->bl_id, damage); + MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d"_fmt, src->bl_id, damage); } } else - MAP_LOG_PC(sd, "INJURED-BY null FOR %d", damage); + MAP_LOG_PC(sd, "INJURED-BY null FOR %d"_fmt, damage); pc_stop_walking(sd, 3); // 演奏/ダンスの中断 @@ -3437,7 +3436,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, return 0; } - MAP_LOG_PC(sd, "DEAD%s", ""); + MAP_LOG_PC(sd, "DEAD%s"_fmt, ""_s); // Character is dead! @@ -3452,7 +3451,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, pc_stop_walking(sd, 0); skill_castcancel(sd, 0); // 詠唱の中止 clif_clearchar(sd, BeingRemoveWhy::DEAD); - pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"), ++sd->die_counter); //死にカウンター書き込み + pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s), ++sd->die_counter); //死にカウンター書き込み skill_status_change_clear(sd, 0); // ステータス異常を解除する clif_updatestatus(sd, SP::HP); pc_calcstatus(sd, 0); @@ -3544,14 +3543,14 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, // [Fate] PK death, trigger scripts argrec_t arg[3] = { - {"@killerrid", src->bl_id}, - {"@victimrid", sd->bl_id}, - {"@victimlvl", sd->status.base_level}, + {"@killerrid"_s, src->bl_id}, + {"@victimrid"_s, sd->bl_id}, + {"@victimlvl"_s, sd->status.base_level}, }; - npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"), sd->bl_id, arg); - npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"), src->bl_id, arg); + npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"_s), sd->bl_id, arg); + npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"_s), src->bl_id, arg); } - npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"), sd->bl_id, nullptr); + npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"_s), sd->bl_id, nullptr); return 0; } @@ -3762,9 +3761,6 @@ int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val) */ int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp) { -// if(battle_config.battle_log) -// PRINTF("heal %d %d\n",hp,sp); - nullpo_ret(sd); if (pc_checkoverhp(sd)) @@ -4139,7 +4135,7 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val) nullpo_ret(sd); //PC_DIE_COUNTERがスクリプトなどで変更された時の処理 - if (reg == stringish<VarName>("PC_DIE_COUNTER") && sd->die_counter != val) + if (reg == stringish<VarName>("PC_DIE_COUNTER"_s) && sd->die_counter != val) { sd->die_counter = val; pc_calcstatus(sd, 0); @@ -4175,7 +4171,7 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n", + PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n"_fmt, reg, GLOBAL_REG_NUM); return 1; @@ -4244,7 +4240,7 @@ int pc_setaccountreg(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n", + PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n"_fmt, reg, ACCOUNT_REG_NUM); return 1; @@ -4312,7 +4308,7 @@ int pc_setaccountreg2(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n", + PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n"_fmt, reg, ACCOUNT_REG2_NUM); return 1; @@ -4414,7 +4410,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) EPOS pos = pc_equippoint(sd, n); if (battle_config.battle_log) - PRINTF("equip %d (%d) %x:%x\n", + PRINTF("equip %d (%d) %x:%x\n"_fmt, nameid, n, id->equip, pos); if (!pc_isequip(sd, n) || pos == EPOS::ZERO) { @@ -4546,7 +4542,7 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) // -- moonsoul (if player is berserk then cannot unequip) // if (battle_config.battle_log) - PRINTF("unequip %d %x:%x\n", + PRINTF("unequip %d %x:%x\n"_fmt, n, pc_equippoint(sd, n), sd->status.inventory[n].equip); if (bool(sd->status.inventory[n].equip)) @@ -4804,7 +4800,7 @@ int pc_divorce(dumb_ptr<map_session_data> sd) if (p_sd->status.partner_id != sd->status_key.char_id || sd->status.partner_id != p_sd->status_key.char_id) { - PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n", + PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n"_fmt, sd->status.partner_id, p_sd->status.partner_id); return -1; } @@ -5265,13 +5261,13 @@ int pc_logout(dumb_ptr<map_session_data> sd) // [fate] Player logs out // Removed because it's buggy, see above. if (sd->cast_tick > tick) { - if (pc_setglobalreg(sd, "MAGIC_CAST_TICK", sd->cast_tick - tick)) + if (pc_setglobalreg(sd, "MAGIC_CAST_TICK"_s, sd->cast_tick - tick)) sd->status.sp = 1; } else #endif - pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"), 0); + pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"_s), 0); - MAP_LOG_STATS(sd, "LOGOUT"); + MAP_LOG_STATS(sd, "LOGOUT"_fmt); return 0; } diff --git a/src/map/script.cpp b/src/map/script.cpp index 93f9d31..0cb702b 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -93,7 +93,7 @@ static Map<SIR, RString> mapregstr_db; static int mapreg_dirty = -1; -AString mapreg_txt = "save/mapreg.txt"; +AString mapreg_txt = "save/mapreg.txt"_s; constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10); Map<ScriptLabel, int> scriptlabel_db; @@ -102,19 +102,19 @@ std::set<ScriptLabel> probable_labels; UPMap<RString, const ScriptBuffer> userfunc_db; static -Array<ZString, 11> pos_str //= +Array<LString, 11> pos_str //= {{ - ZString("Head"), - ZString("Body"), - ZString("Left hand"), - ZString("Right hand"), - ZString("Robe"), - ZString("Shoes"), - ZString("Accessory 1"), - ZString("Accessory 2"), - ZString("Head 2"), - ZString("Head 3"), - ZString("Not Equipped"), + "Head"_s, + "Body"_s, + "Left hand"_s, + "Right hand"_s, + "Robe"_s, + "Shoes"_s, + "Accessory 1"_s, + "Accessory 2"_s, + "Head 2"_s, + "Head 3"_s, + "Not Equipped"_s, }}; static @@ -150,8 +150,8 @@ void mapreg_setregstr(SIR num, XString str); struct BuiltinFunction { void (*func)(ScriptState *); - ZString name; - ZString arg; + LString name; + LString arg; }; // defined later extern BuiltinFunction builtin_functions[]; @@ -382,15 +382,15 @@ void disp_error_message(ZString mes, ZString::iterator pos_) ZString::iterator lineend = std::find(p, startptr.end(), '\n'); if (pos_ < lineend) { - PRINTF("\n%s\nline %d : ", mes, line); + PRINTF("\n%s\nline %d : "_fmt, mes, line); for (int i = 0; linestart + i != lineend; i++) { if (linestart + i != pos_) - PRINTF("%c", linestart[i]); + PRINTF("%c"_fmt, linestart[i]); else - PRINTF("\'%c\'", linestart[i]); + PRINTF("\'%c\'"_fmt, linestart[i]); } - PRINTF("\a\n"); + PRINTF("\a\n"_fmt); return; } p = lineend + 1; @@ -407,7 +407,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) if (*p == ';' || *p == ',') { - disp_error_message("unexpected expr end", p); + disp_error_message("unexpected expr end"_s, p); exit(1); } if (*p == '(') @@ -417,7 +417,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p = skip_space(p); if ((*p++) != ')') { - disp_error_message("unmatch ')'", p); + disp_error_message("unmatch ')'"_s, p); exit(1); } } @@ -438,14 +438,14 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p++; else if (*p == '\n') { - disp_error_message("unexpected newline @ string", p); + disp_error_message("unexpected newline @ string"_s, p); exit(1); } add_scriptb(*p++); } if (!*p) { - disp_error_message("unexpected eof @ string", p); + disp_error_message("unexpected eof @ string"_s, p); exit(1); } add_scriptb(0); @@ -457,35 +457,35 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) ZString::iterator p2 = skip_word(p); if (p2 == p) { - disp_error_message("unexpected character", p); + disp_error_message("unexpected character"_s, p); exit(1); } XString word(&*p, &*p2, nullptr); - if (word.startswith("On") || word.startswith("L_") || word.startswith("S_")) + if (word.startswith("On"_s) || word.startswith("L_"_s) || word.startswith("S_"_s)) probable_labels.insert(stringish<ScriptLabel>(word)); - if (parse_cmd_if && (word == "callsub" || word == "callfunc" || word == "return")) + if (parse_cmd_if && (word == "callsub"_s || word == "callfunc"_s || word == "return"_s)) { - disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement.", p); + disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement."_s, p); } str_data_t *ld = add_strp(word); parse_cmdp = ld; // warn_*_mismatch_paramnumのために必要 - // why not just check l->str == "if" or std::string(p, p2) == "if"? - if (ld == search_strp("if")) // warn_cmd_no_commaのために必要 + // why not just check l->str == "if"_s or std::string(p, p2) == "if"_s? + if (ld == search_strp("if"_s)) // warn_cmd_no_commaのために必要 parse_cmd_if++; p = p2; if (ld->type != ByteCode::FUNC_ && *p == '[') { // array(name[i] => getelementofarray(name,i) ) - add_scriptl(search_strp("getelementofarray")); + add_scriptl(search_strp("getelementofarray"_s)); add_scriptc(ByteCode::ARG); add_scriptl(ld); p = parse_subexpr(p + 1, -1); p = skip_space(p); if (*p != ']') { - disp_error_message("unmatch ']'", p); + disp_error_message("unmatch ']'"_s, p); exit(1); } p++; @@ -515,7 +515,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) ZString::iterator tmpp = skip_space(p + 1); if (*tmpp == ';' || *tmpp == ',') { - --script_errors; disp_error_message("deprecated: implicit 'next statement' label", p); + --script_errors; disp_error_message("deprecated: implicit 'next statement' label"_s, p); add_scriptl(&LABEL_NEXTLINE_); p++; return p; @@ -560,7 +560,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) if (funcp->type != ByteCode::FUNC_) { - disp_error_message("expect function", tmpp); + disp_error_message("expect function"_s, tmpp); exit(0); } @@ -574,7 +574,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) p++; else if (*p != ')' && script_config.warn_func_no_comma) { - disp_error_message("expect ',' or ')' at func params", + disp_error_message("expect ',' or ')' at func params"_s, p); } p = skip_space(p); @@ -583,7 +583,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) plist[i] = p; if (*p != ')') { - disp_error_message("func request '(' ')'", p); + disp_error_message("func request '(' ')'"_s, p); exit(1); } p++; @@ -598,7 +598,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) break; if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } } @@ -627,7 +627,7 @@ ZString::iterator ScriptBuffer::parse_expr(ZString::iterator p) case '[': case ']': case '}': - disp_error_message("unexpected char", p); + disp_error_message("unexpected char"_s, p); exit(1); } p = parse_subexpr(p, -1); @@ -657,21 +657,22 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) str_data_t *cmd = parse_cmdp; if (cmd->type != ByteCode::FUNC_) { - disp_error_message("expect command", p2); + disp_error_message("expect command"_s, p2); // exit(0); } { + // TODO should be LString, but no heterogenous lookup yet static std::set<ZString> terminators = { - "goto", - "return", - "close", - "menu", - "end", - "mapexit", - "shop", + "goto"_s, + "return"_s, + "close"_s, + "menu"_s, + "end"_s, + "mapexit"_s, + "shop"_s, }; *can_step = terminators.count(cmd->strs) == 0; } @@ -689,7 +690,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) else if (*p != ';' && script_config.warn_cmd_no_comma && parse_cmd_if * 2 <= i) { - disp_error_message("expect ',' or ';' at cmd params", p); + disp_error_message("expect ',' or ';' at cmd params"_s, p); } p = skip_space(p); i++; @@ -697,7 +698,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) plist[i] = p; if (*(p++) != ';') { - disp_error_message("need ';'", p); + disp_error_message("need ';'"_s, p); exit(1); } add_scriptc(ByteCode::FUNC_); @@ -712,7 +713,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) break; if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } } @@ -740,7 +741,7 @@ bool read_constdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -755,9 +756,9 @@ bool read_constdb(ZString filename) int val; int type = 0; // if not provided // TODO get rid of SSCANF - this is the last serious use - if (SSCANF(line, "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2) + if (SSCANF(line, "%m[A-Za-z0-9_] %i %i"_fmt, &name, &val, &type) < 2) { - PRINTF("Bad const line: %s\n", line); + PRINTF("Bad const line: %s\n"_fmt, line); rv = false; continue; } @@ -815,7 +816,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) p = skip_space(p); if (*p != '{') { - disp_error_message("not found '{'", p); + disp_error_message("not found '{'"_s, p); abort(); } for (p++; *p && *p != '}';) @@ -825,7 +826,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) { if (can_step) { - --script_errors; disp_error_message("deprecated: implicit fallthrough", p); + --script_errors; disp_error_message("deprecated: implicit fallthrough"_s, p); } can_step = true; @@ -838,7 +839,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) assert (e1 == e2 && e2 == e3); if (e3) { - disp_error_message("dup label ", p); + disp_error_message("dup label "_s, p); exit(1); } set_label(ld, script_buf.size()); @@ -849,7 +850,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (!can_step) { - --script_errors; disp_error_message("deprecated: unreachable statement", p); + --script_errors; disp_error_message("deprecated: unreachable statement"_s, p); } // 他は全部一緒くた p = parse_line(p, &can_step); @@ -864,7 +865,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (can_step && !implicit_end) { - --script_errors; disp_error_message("deprecated: implicit end", p); + --script_errors; disp_error_message("deprecated: implicit end"_s, p); } add_scriptc(ByteCode::NOP); @@ -893,17 +894,17 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (const auto& pair : scriptlabel_db) { ScriptLabel key = pair.first; - if (key.startswith("On")) + if (key.startswith("On"_s)) continue; - if (!(key.startswith("L_") || key.startswith("S_"))) - PRINTF("Warning: ugly label: %s\n", key); + if (!(key.startswith("L_"_s) || key.startswith("S_"_s))) + PRINTF("Warning: ugly label: %s\n"_fmt, key); else if (!probable_labels.count(key)) - PRINTF("Warning: unused label: %s\n", key); + PRINTF("Warning: unused label: %s\n"_fmt, key); } for (ScriptLabel used : probable_labels) { if (!scriptlabel_db.search(used)) - PRINTF("Warning: no such label: %s\n", used); + PRINTF("Warning: no such label: %s\n"_fmt, used); } probable_labels.clear(); @@ -912,12 +913,12 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (size_t i = 0; i < script_buf.size(); i++) { if ((i & 15) == 0) - PRINTF("%04zx : ", i); - PRINTF("%02x ", script_buf[i]); + PRINTF("%04zx : "_fmt, i); + PRINTF("%02x "_fmt, script_buf[i]); if ((i & 15) == 15) - PRINTF("\n"); + PRINTF("\n"_fmt); } - PRINTF("\n"); + PRINTF("\n"_fmt); } // @@ -943,7 +944,7 @@ dumb_ptr<map_session_data> script_rid2sd(ScriptState *st) dumb_ptr<map_session_data> sd = map_id2sd(st->rid); if (!sd) { - PRINTF("script_rid2sd: fatal error ! player not attached!\n"); + PRINTF("script_rid2sd: fatal error ! player not attached!\n"_fmt); } return sd; } @@ -958,7 +959,7 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) if (data->type == ByteCode::PARAM_) { if (sd == NULL) - PRINTF("get_val error param SP::%d\n", data->u.reg.sp()); + PRINTF("get_val error param SP::%d\n"_fmt, data->u.reg.sp()); data->type = ByteCode::INT; if (sd) data->u.numi = pc_readparam(sd, data->u.reg.sp()); @@ -973,7 +974,7 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) if (prefix != '$') { if (sd == NULL) - PRINTF("get_val error name?:%s\n", name); + PRINTF("get_val error name?:%s\n"_fmt, name); } if (postfix == '$') { @@ -990,11 +991,11 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) } else { - PRINTF("script: get_val: illegal scope string variable.\n"); - data->u.str = dumb_string::fake("!!ERROR!!"); + PRINTF("script: get_val: illegal scope string variable.\n"_fmt); + data->u.str = dumb_string::fake("!!ERROR!!"_s); } if (!data->u.str) - data->u.str = dumb_string::fake(""); + data->u.str = dumb_string::fake(""_s); } else { @@ -1085,7 +1086,7 @@ void set_reg(dumb_ptr<map_session_data> sd, ByteCode type, SIR reg, struct scrip } else { - PRINTF("script: set_reg: illegal scope string variable !"); + PRINTF("script: set_reg: illegal scope string variable !"_fmt); } } else @@ -1143,7 +1144,7 @@ dumb_string conv_str(ScriptState *st, struct script_data *data) assert (data->type != ByteCode::RETINFO); if (data->type == ByteCode::INT) { - AString buf = STRPRINTF("%d", data->u.numi); + AString buf = STRPRINTF("%d"_fmt, data->u.numi); data->type = ByteCode::STR; data->u.str = dumb_string::copys(buf); } @@ -1285,7 +1286,7 @@ void builtin_goto(ScriptState *st) { if (AARGO2(2).type != ByteCode::POS) { - PRINTF("script: goto: not label !\n"); + PRINTF("script: goto: not label !\n"_fmt); st->state = ScriptEndState::END; return; } @@ -1324,7 +1325,7 @@ void builtin_callfunc(ScriptState *st) } else { - PRINTF("script:callfunc: function not found! [%s]\n", str); + PRINTF("script:callfunc: function not found! [%s]\n"_fmt, str); st->state = ScriptEndState::END; } } @@ -1442,7 +1443,7 @@ void builtin_menu(ScriptState *st) // not just the displayed number that ends with the "". // (Would it be better to pop the stack before rerunning?) int menu_choices = (st->end - (st->start + 2)) / 2; - pc_setreg(sd, SIR::from(variable_names.intern("@menu")), sd->npc_menu); + pc_setreg(sd, SIR::from(variable_names.intern("@menu"_s)), sd->npc_menu); sd->state.menu_or_input = 0; if (sd->npc_menu > 0 && sd->npc_menu <= menu_choices) { @@ -1532,9 +1533,9 @@ void builtin_warp(ScriptState *st) MapName str = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); x = conv_num(st, &AARGO2(3)); y = conv_num(st, &AARGO2(4)); - if (str == "Random") + if (str == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); - else if (str == "SavePoint" or str == "Save") + else if (str == "SavePoint"_s or str == "Save"_s) { if (sd->bl_m->flag.get(MapFlag::NORETURN)) return; @@ -1554,7 +1555,7 @@ static void builtin_areawarp_sub(dumb_ptr<block_list> bl, MapName mapname, int x, int y) { dumb_ptr<map_session_data> sd = bl->is_player(); - if (mapname == "Random") + if (mapname == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); else pc_setpos(sd, mapname, x, y, BeingRemoveWhy::GONE); @@ -1762,7 +1763,7 @@ void builtin_setarray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_setarray: illegal scope !\n"); + PRINTF("builtin_setarray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1794,7 +1795,7 @@ void builtin_cleararray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_cleararray: illegal scope !\n"); + PRINTF("builtin_cleararray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1839,7 +1840,7 @@ void builtin_getarraysize(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_copyarray: illegal scope !\n"); + PRINTF("builtin_copyarray: illegal scope !\n"_fmt); return; } @@ -1858,7 +1859,7 @@ void builtin_getelementofarray(ScriptState *st) int i = conv_num(st, &AARGO2(3)); if (i > 255 || i < 0) { - PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n", + PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n"_fmt, i); push_int(st->stack, ByteCode::INT, 0); } @@ -1870,7 +1871,7 @@ void builtin_getelementofarray(ScriptState *st) } else { - PRINTF("script: getelementofarray (operator[]): param1 not name !\n"); + PRINTF("script: getelementofarray (operator[]): param1 not name !\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -1924,7 +1925,7 @@ void builtin_countitem(ScriptState *st) else { if (battle_config.error_log) - PRINTF("wrong item ID : countitem (%i)\n", nameid); + PRINTF("wrong item ID : countitem (%i)\n"_fmt, nameid); } push_int(st->stack, ByteCode::INT, count); @@ -2104,7 +2105,6 @@ void builtin_delitem(ScriptState *st) if (nameid < 500 || amount <= 0) { //by Lupus. Don't run FOR if u got wrong item ID or amount<=0 - //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount); return; } @@ -2231,12 +2231,12 @@ void builtin_strcharinfo(ScriptState *st) if (buf) push_str(st->stack, ByteCode::STR, buf); else - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } if (num == 2) { // was: guild name - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } } @@ -2273,7 +2273,7 @@ void builtin_getequipid(ScriptState *st) sd = script_rid2sd(st); if (sd == NULL) { - PRINTF("getequipid: sd == NULL\n"); + PRINTF("getequipid: sd == NULL\n"_fmt); return; } num = conv_num(st, &AARGO2(2)); @@ -2312,13 +2312,13 @@ void builtin_getequipname(ScriptState *st) { item = sd->inventory_data[i]; if (item) - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], item->jname); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], item->jname); else - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } else { - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } push_str(st->stack, ByteCode::STR, dumb_string::copys(buf)); @@ -2683,7 +2683,7 @@ void builtin_killmonster(ScriptState *st) MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); ZString event_ = ZString(conv_str(st, &AARGO2(3))); NpcEvent event; - if (event_ != "All") + if (event_ != "All"_s) extract(event_, &event); map_local *m = map_mapname2mapid(mapname); @@ -3151,7 +3151,7 @@ static void builtin_debugmes(ScriptState *st) { dumb_string mes = conv_str(st, &AARGO2(2)); - PRINTF("script debug : %d %d : %s\n", + PRINTF("script debug : %d %d : %s\n"_fmt, st->rid, st->oid, mes); } @@ -3464,7 +3464,7 @@ void builtin_getitemname(ScriptState *st) if (i_data) item_name = dumb_string::copys(i_data->jname); else - item_name = dumb_string::copys("Unknown Item"); + item_name = dumb_string::copys("Unknown Item"_s); push_str(st->stack, ByteCode::STR, item_name); } @@ -3476,7 +3476,7 @@ void builtin_getspellinvocation(ScriptState *st) AString invocation = magic_find_invocation(name.str()); if (!invocation) - invocation = "..."; + invocation = "..."_s; push_str(st->stack, ByteCode::STR, dumb_string::copys(invocation)); } @@ -3505,16 +3505,16 @@ void builtin_getinventorylist(ScriptState *st) if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0) { - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"_s), j), sd->status.inventory[i].nameid); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"_s), j), sd->status.inventory[i].amount); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"_s), j), static_cast<uint16_t>(sd->status.inventory[i].equip)); j++; } } - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count")), j); + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count"_s)), j); } static @@ -3534,18 +3534,18 @@ void builtin_getactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } @@ -3565,18 +3565,18 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv && !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } static @@ -3775,7 +3775,7 @@ void builtin_npcwarp(ScriptState *st) if (!nd) { - PRINTF("builtin_npcwarp: no such npc: %s\n", npc); + PRINTF("builtin_npcwarp: no such npc: %s\n"_fmt, npc); return; } @@ -3828,11 +3828,7 @@ void builtin_npctalk(ScriptState *st) if (nd) { - MString message; - message += nd->name; - message += " : "; - message += ZString(str); - clif_message(nd, AString(message)); + clif_message(nd, XString(str)); } } @@ -3988,7 +3984,7 @@ void builtin_shop(ScriptState *st) nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_shop: no such npc: %s\n", name); + PRINTF("builtin_shop: no such npc: %s\n"_fmt, name); return; } @@ -4021,7 +4017,7 @@ void builtin_fakenpcname(ScriptState *st) dumb_ptr<npc_data> nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_fakenpcname: no such npc: %s\n", name); + PRINTF("builtin_fakenpcname: no such npc: %s\n"_fmt, name); return; } nd->name = newname; @@ -4205,7 +4201,7 @@ void op_2str(ScriptState *st, ByteCode op, dumb_string s1_, dumb_string s2_) a = s1 <= s2; break; default: - PRINTF("illegal string operater\n"); + PRINTF("illegal string operater\n"_fmt); break; } @@ -4308,7 +4304,7 @@ void op_2(ScriptState *st, ByteCode op) else { // si,is => error - PRINTF("script: op_2: int&str, str&int not allow.\n"); + PRINTF("script: op_2: int&str, str&int not allow.\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -4351,7 +4347,7 @@ void run_func(ScriptState *st) if (start_sp == 0) { if (battle_config.error_log) - PRINTF("function not found\n"); + PRINTF("function not found\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4364,52 +4360,52 @@ void run_func(ScriptState *st) size_t func = st->stack->stack_datav[st->start].u.numi; if (st->stack->stack_datav[st->start].type != ByteCode::FUNC_REF) { - PRINTF("run_func: not function and command! \n"); + PRINTF("run_func: not function and command! \n"_fmt); st->state = ScriptEndState::END; return; } if (DEBUG_RUN && battle_config.etc_log) { - PRINTF("run_func : %s\n", + PRINTF("run_func : %s\n"_fmt, builtin_functions[func].name); - PRINTF("stack dump :"); + PRINTF("stack dump :"_fmt); for (script_data& d : st->stack->stack_datav) { switch (d.type) { case ByteCode::INT: - PRINTF(" int(%d)", d.u.numi); + PRINTF(" int(%d)"_fmt, d.u.numi); break; case ByteCode::RETINFO: - PRINTF(" retinfo(%p)", static_cast<const void *>(d.u.script)); + PRINTF(" retinfo(%p)"_fmt, static_cast<const void *>(d.u.script)); break; case ByteCode::PARAM_: - PRINTF(" param(%d)", d.u.reg.sp()); + PRINTF(" param(%d)"_fmt, d.u.reg.sp()); break; case ByteCode::VARIABLE: - PRINTF(" name(%s)[%d]", variable_names.outtern(d.u.reg.base()), d.u.reg.index()); + PRINTF(" name(%s)[%d]"_fmt, variable_names.outtern(d.u.reg.base()), d.u.reg.index()); break; case ByteCode::ARG: - PRINTF(" arg"); + PRINTF(" arg"_fmt); break; case ByteCode::POS: - PRINTF(" pos(%d)", d.u.numi); + PRINTF(" pos(%d)"_fmt, d.u.numi); break; case ByteCode::STR: - PRINTF(" str(%s)", d.u.str); + PRINTF(" str(%s)"_fmt, d.u.str); break; case ByteCode::CONSTSTR: - PRINTF(" cstr(%s)", d.u.str); + PRINTF(" cstr(%s)"_fmt, d.u.str); break; case ByteCode::FUNC_REF: - PRINTF(" func(%s)", builtin_functions[d.u.numi].name); + PRINTF(" func(%s)"_fmt, builtin_functions[d.u.numi].name); break; default: - PRINTF(" %d,%d", d.type, d.u.numi); + PRINTF(" %d,%d"_fmt, d.type, d.u.numi); } } - PRINTF("\n"); + PRINTF("\n"_fmt); } builtin_functions[func].func(st); @@ -4424,7 +4420,7 @@ void run_func(ScriptState *st) if (st->defsp < 4 || st->stack->stack_datav[st->defsp - 1].type != ByteCode::RETINFO) { - PRINTF("script:run_func (return) return without callfunc or callsub!\n"); + PRINTF("script:run_func (return) return without callfunc or callsub!\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4449,15 +4445,15 @@ void dump_script(const ScriptBuffer *script) ScriptPointer scriptp(script, 0); while (scriptp.pos < reinterpret_cast<const std::vector<ByteCode> *>(script)->size()) { - PRINTF("%6zu: ", scriptp.pos); + PRINTF("%6zu: "_fmt, scriptp.pos); switch (ByteCode c = get_com(&scriptp)) { case ByteCode::EOL: - PRINTF("EOL\n"); // extra newline between functions + PRINTF("EOL\n"_fmt); // extra newline between functions break; case ByteCode::INT: // synthesized! - PRINTF("INT %d", get_num(&scriptp)); + PRINTF("INT %d"_fmt, get_num(&scriptp)); break; case ByteCode::POS: @@ -4472,103 +4468,103 @@ void dump_script(const ScriptBuffer *script) switch(c) { case ByteCode::POS: - PRINTF("POS %d", arg); + PRINTF("POS %d"_fmt, arg); break; case ByteCode::VARIABLE: - PRINTF("VARIABLE %s", variable_names.outtern(arg)); + PRINTF("VARIABLE %s"_fmt, variable_names.outtern(arg)); break; case ByteCode::FUNC_REF: - PRINTF("FUNC_REF %s", builtin_functions[arg].name); + PRINTF("FUNC_REF %s"_fmt, builtin_functions[arg].name); break; case ByteCode::PARAM_: - PRINTF("PARAM SP::#%d (sorry)", arg); + PRINTF("PARAM SP::#%d (sorry)"_fmt, arg); break; } } break; case ByteCode::ARG: - PRINTF("ARG"); + PRINTF("ARG"_fmt); break; case ByteCode::STR: - PRINTF("STR \"%s\"", scriptp.pops()); + PRINTF("STR \"%s\""_fmt, scriptp.pops()); break; case ByteCode::FUNC_: - PRINTF("FUNC_"); + PRINTF("FUNC_"_fmt); break; case ByteCode::ADD: - PRINTF("ADD"); + PRINTF("ADD"_fmt); break; case ByteCode::SUB: - PRINTF("SUB"); + PRINTF("SUB"_fmt); break; case ByteCode::MUL: - PRINTF("MUL"); + PRINTF("MUL"_fmt); break; case ByteCode::DIV: - PRINTF("DIV"); + PRINTF("DIV"_fmt); break; case ByteCode::MOD: - PRINTF("MOD"); + PRINTF("MOD"_fmt); break; case ByteCode::EQ: - PRINTF("EQ"); + PRINTF("EQ"_fmt); break; case ByteCode::NE: - PRINTF("NE"); + PRINTF("NE"_fmt); break; case ByteCode::GT: - PRINTF("GT"); + PRINTF("GT"_fmt); break; case ByteCode::GE: - PRINTF("GE"); + PRINTF("GE"_fmt); break; case ByteCode::LT: - PRINTF("LT"); + PRINTF("LT"_fmt); break; case ByteCode::LE: - PRINTF("LE"); + PRINTF("LE"_fmt); break; case ByteCode::AND: - PRINTF("AND"); + PRINTF("AND"_fmt); break; case ByteCode::OR: - PRINTF("OR"); + PRINTF("OR"_fmt); break; case ByteCode::XOR: - PRINTF("XOR"); + PRINTF("XOR"_fmt); break; case ByteCode::LAND: - PRINTF("LAND"); + PRINTF("LAND"_fmt); break; case ByteCode::LOR: - PRINTF("LOR"); + PRINTF("LOR"_fmt); break; case ByteCode::R_SHIFT: - PRINTF("R_SHIFT"); + PRINTF("R_SHIFT"_fmt); break; case ByteCode::L_SHIFT: - PRINTF("L_SHIFT"); + PRINTF("L_SHIFT"_fmt); break; case ByteCode::NEG: - PRINTF("NEG"); + PRINTF("NEG"_fmt); break; case ByteCode::NOT: - PRINTF("NOT"); + PRINTF("NOT"_fmt); break; case ByteCode::LNOT: - PRINTF("LNOT"); + PRINTF("LNOT"_fmt); break; case ByteCode::NOP: - PRINTF("NOP"); + PRINTF("NOP"_fmt); break; default: - PRINTF("??? %d", c); + PRINTF("??? %d"_fmt, c); break; } - PRINTF("\n"); + PRINTF("\n"_fmt); } } @@ -4595,7 +4591,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) if (stack->stack_datav.size() != st->defsp) { if (battle_config.error_log) - PRINTF("stack.sp (%zu) != default (%d)\n", + PRINTF("stack.sp (%zu) != default (%d)\n"_fmt, stack->stack_datav.size(), st->defsp); stack->stack_datav.resize(st->defsp); @@ -4650,7 +4646,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) st->state = ScriptEndState::ZERO; if (gotocount > 0 && (--gotocount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4692,14 +4688,14 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) default: if (battle_config.error_log) - PRINTF("unknown command : %d @ %zu\n", + PRINTF("unknown command : %d @ %zu\n"_fmt, c, st->scriptp.pos); st->state = ScriptEndState::END; break; } if (cmdcount > 0 && (--cmdcount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4846,7 +4842,7 @@ void script_load_mapreg(void) else { borken: - PRINTF("%s: %s broken data !\n", mapreg_txt, AString(buf1)); + PRINTF("%s: %s broken data !\n"_fmt, mapreg_txt, AString(buf1)); continue; } } @@ -4865,9 +4861,9 @@ void script_save_mapreg_intsub(SIR key, int data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%d\n", name, data); + FPRINTF(fp, "%s\t%d\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%d\n", name, i, data); + FPRINTF(fp, "%s,%d\t%d\n"_fmt, name, i, data); } } @@ -4879,9 +4875,9 @@ void script_save_mapreg_strsub(SIR key, ZString data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%s\n", name, data); + FPRINTF(fp, "%s\t%s\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%s\n", name, i, data); + FPRINTF(fp, "%s,%d\t%s\n"_fmt, name, i, data); } } @@ -4933,128 +4929,128 @@ void do_init_script(void) } #define BUILTIN(func, args) \ -{builtin_##func, {#func}, {args}} +{builtin_##func, #func ## _s, {args}} BuiltinFunction builtin_functions[] = { - BUILTIN(mes, "s"), - BUILTIN(next, ""), - BUILTIN(close, ""), - BUILTIN(close2, ""), - BUILTIN(menu, "sL*"), - BUILTIN(goto, "L"), - BUILTIN(callsub, "L"), - BUILTIN(callfunc, "F"), - BUILTIN(return, ""), - BUILTIN(input, "N"), - BUILTIN(warp, "Mxy"), - BUILTIN(isat, "Mxy"), - BUILTIN(areawarp, "MxyxyMxy"), - BUILTIN(setlook, "ii"), - BUILTIN(set, "Ne"), - BUILTIN(setarray, "Ne*"), - BUILTIN(cleararray, "Nei"), - BUILTIN(getarraysize, "N"), - BUILTIN(getelementofarray, "Ni"), - BUILTIN(if, "iF*"), - BUILTIN(getitem, "Ii**"), - BUILTIN(makeitem, "IiMxy"), - BUILTIN(delitem, "Ii"), - BUILTIN(heal, "ii"), - BUILTIN(itemheal, "ii"), - BUILTIN(percentheal, "ii"), - BUILTIN(rand, "i*"), - BUILTIN(pow, "ii"), - BUILTIN(countitem, "I"), - BUILTIN(checkweight, "Ii"), - BUILTIN(readparam, "i*"), - BUILTIN(getcharid, "i*"), - BUILTIN(strcharinfo, "i"), - BUILTIN(getequipid, "i"), - BUILTIN(getequipname, "i"), - BUILTIN(statusup2, "ii"), - BUILTIN(bonus, "ii"), - BUILTIN(bonus2, "iii"), - BUILTIN(skill, "ii*"), - BUILTIN(setskill, "ii"), - BUILTIN(getskilllv, "i"), - BUILTIN(getgmlevel, ""), - BUILTIN(end, ""), - BUILTIN(getopt2, ""), - BUILTIN(setopt2, "i"), - BUILTIN(savepoint, "Mxy"), - BUILTIN(gettimetick, "i"), - BUILTIN(gettime, "i"), - BUILTIN(openstorage, "*"), - BUILTIN(monster, "Mxysmi*"), - BUILTIN(areamonster, "Mxyxysmi*"), - BUILTIN(killmonster, "ME"), - BUILTIN(killmonsterall, "M"), - BUILTIN(donpcevent, "E"), - BUILTIN(addtimer, "tE"), - BUILTIN(initnpctimer, ""), - BUILTIN(stopnpctimer, ""), - BUILTIN(startnpctimer, "*"), - BUILTIN(setnpctimer, "i"), - BUILTIN(getnpctimer, "i"), - BUILTIN(announce, "si"), - BUILTIN(mapannounce, "Msi"), - BUILTIN(getusers, "i"), - BUILTIN(getmapusers, "M"), - BUILTIN(getareausers, "Mxyxy*"), - BUILTIN(getareadropitem, "Mxyxyi*"), - BUILTIN(enablenpc, "s"), - BUILTIN(disablenpc, "s"), - BUILTIN(sc_start, "iTi*"), - BUILTIN(sc_end, "i"), - BUILTIN(sc_check, "i"), - BUILTIN(debugmes, "s"), - BUILTIN(resetstatus, ""), - BUILTIN(changesex, ""), - BUILTIN(attachrid, "i"), - BUILTIN(detachrid, ""), - BUILTIN(isloggedin, "i"), - BUILTIN(setmapflag, "Mi"), - BUILTIN(removemapflag, "Mi"), - BUILTIN(getmapflag, "Mi"), - BUILTIN(pvpon, "M"), - BUILTIN(pvpoff, "M"), - BUILTIN(emotion, "i"), - BUILTIN(marriage, "P"), - BUILTIN(divorce, ""), - BUILTIN(getitemname, "I"), - BUILTIN(getspellinvocation, "s"), - BUILTIN(getpartnerid2, ""), - BUILTIN(getexp, "ii"), - BUILTIN(getinventorylist, ""), - BUILTIN(getactivatedpoolskilllist, ""), - BUILTIN(getunactivatedpoolskilllist, ""), - BUILTIN(poolskill, "i"), - BUILTIN(unpoolskill, "i"), - BUILTIN(misceffect, "i*"), - BUILTIN(specialeffect, "i"), - BUILTIN(specialeffect2, "i"), - BUILTIN(nude, ""), - BUILTIN(mapwarp, "MMxy"), - BUILTIN(cmdothernpc, "ss"), - BUILTIN(gmcommand, "s"), - BUILTIN(npcwarp, "xys"), - BUILTIN(message, "Ps"), - BUILTIN(npctalk, "s"), - BUILTIN(mobcount, "ME"), - BUILTIN(getlook, "i"), - BUILTIN(getsavepoint, "i"), - BUILTIN(areatimer, "MxyxytE"), - BUILTIN(isin, "Mxyxy"), - BUILTIN(shop, "s"), - BUILTIN(isdead, ""), - BUILTIN(unequipbyid, "i"), - BUILTIN(fakenpcname, "ssi"), - BUILTIN(getx, ""), - BUILTIN(gety, ""), - BUILTIN(getmap, ""), - BUILTIN(mapexit, ""), - {nullptr, ZString(), ZString()}, + BUILTIN(mes, "s"_s), + BUILTIN(next, ""_s), + BUILTIN(close, ""_s), + BUILTIN(close2, ""_s), + BUILTIN(menu, "sL*"_s), + BUILTIN(goto, "L"_s), + BUILTIN(callsub, "L"_s), + BUILTIN(callfunc, "F"_s), + BUILTIN(return, ""_s), + BUILTIN(input, "N"_s), + BUILTIN(warp, "Mxy"_s), + BUILTIN(isat, "Mxy"_s), + BUILTIN(areawarp, "MxyxyMxy"_s), + BUILTIN(setlook, "ii"_s), + BUILTIN(set, "Ne"_s), + BUILTIN(setarray, "Ne*"_s), + BUILTIN(cleararray, "Nei"_s), + BUILTIN(getarraysize, "N"_s), + BUILTIN(getelementofarray, "Ni"_s), + BUILTIN(if, "iF*"_s), + BUILTIN(getitem, "Ii**"_s), + BUILTIN(makeitem, "IiMxy"_s), + BUILTIN(delitem, "Ii"_s), + BUILTIN(heal, "ii"_s), + BUILTIN(itemheal, "ii"_s), + BUILTIN(percentheal, "ii"_s), + BUILTIN(rand, "i*"_s), + BUILTIN(pow, "ii"_s), + BUILTIN(countitem, "I"_s), + BUILTIN(checkweight, "Ii"_s), + BUILTIN(readparam, "i*"_s), + BUILTIN(getcharid, "i*"_s), + BUILTIN(strcharinfo, "i"_s), + BUILTIN(getequipid, "i"_s), + BUILTIN(getequipname, "i"_s), + BUILTIN(statusup2, "ii"_s), + BUILTIN(bonus, "ii"_s), + BUILTIN(bonus2, "iii"_s), + BUILTIN(skill, "ii*"_s), + BUILTIN(setskill, "ii"_s), + BUILTIN(getskilllv, "i"_s), + BUILTIN(getgmlevel, ""_s), + BUILTIN(end, ""_s), + BUILTIN(getopt2, ""_s), + BUILTIN(setopt2, "i"_s), + BUILTIN(savepoint, "Mxy"_s), + BUILTIN(gettimetick, "i"_s), + BUILTIN(gettime, "i"_s), + BUILTIN(openstorage, "*"_s), + BUILTIN(monster, "Mxysmi*"_s), + BUILTIN(areamonster, "Mxyxysmi*"_s), + BUILTIN(killmonster, "ME"_s), + BUILTIN(killmonsterall, "M"_s), + BUILTIN(donpcevent, "E"_s), + BUILTIN(addtimer, "tE"_s), + BUILTIN(initnpctimer, ""_s), + BUILTIN(stopnpctimer, ""_s), + BUILTIN(startnpctimer, "*"_s), + BUILTIN(setnpctimer, "i"_s), + BUILTIN(getnpctimer, "i"_s), + BUILTIN(announce, "si"_s), + BUILTIN(mapannounce, "Msi"_s), + BUILTIN(getusers, "i"_s), + BUILTIN(getmapusers, "M"_s), + BUILTIN(getareausers, "Mxyxy*"_s), + BUILTIN(getareadropitem, "Mxyxyi*"_s), + BUILTIN(enablenpc, "s"_s), + BUILTIN(disablenpc, "s"_s), + BUILTIN(sc_start, "iTi*"_s), + BUILTIN(sc_end, "i"_s), + BUILTIN(sc_check, "i"_s), + BUILTIN(debugmes, "s"_s), + BUILTIN(resetstatus, ""_s), + BUILTIN(changesex, ""_s), + BUILTIN(attachrid, "i"_s), + BUILTIN(detachrid, ""_s), + BUILTIN(isloggedin, "i"_s), + BUILTIN(setmapflag, "Mi"_s), + BUILTIN(removemapflag, "Mi"_s), + BUILTIN(getmapflag, "Mi"_s), + BUILTIN(pvpon, "M"_s), + BUILTIN(pvpoff, "M"_s), + BUILTIN(emotion, "i"_s), + BUILTIN(marriage, "P"_s), + BUILTIN(divorce, ""_s), + BUILTIN(getitemname, "I"_s), + BUILTIN(getspellinvocation, "s"_s), + BUILTIN(getpartnerid2, ""_s), + BUILTIN(getexp, "ii"_s), + BUILTIN(getinventorylist, ""_s), + BUILTIN(getactivatedpoolskilllist, ""_s), + BUILTIN(getunactivatedpoolskilllist, ""_s), + BUILTIN(poolskill, "i"_s), + BUILTIN(unpoolskill, "i"_s), + BUILTIN(misceffect, "i*"_s), + BUILTIN(specialeffect, "i"_s), + BUILTIN(specialeffect2, "i"_s), + BUILTIN(nude, ""_s), + BUILTIN(mapwarp, "MMxy"_s), + BUILTIN(cmdothernpc, "ss"_s), + BUILTIN(gmcommand, "s"_s), + BUILTIN(npcwarp, "xys"_s), + BUILTIN(message, "Ps"_s), + BUILTIN(npctalk, "s"_s), + BUILTIN(mobcount, "ME"_s), + BUILTIN(getlook, "i"_s), + BUILTIN(getsavepoint, "i"_s), + BUILTIN(areatimer, "MxyxytE"_s), + BUILTIN(isin, "Mxyxy"_s), + BUILTIN(shop, "s"_s), + BUILTIN(isdead, ""_s), + BUILTIN(unequipbyid, "i"_s), + BUILTIN(fakenpcname, "ssi"_s), + BUILTIN(getx, ""_s), + BUILTIN(gety, ""_s), + BUILTIN(getmap, ""_s), + BUILTIN(mapexit, ""_s), + {nullptr, ""_s, ""_s}, }; void set_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e, int val) @@ -5079,7 +5075,7 @@ int get_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e) get_val(sd, &dat); if (dat.type == ByteCode::INT) return dat.u.numi; - PRINTF("Warning: you lied about the type and I'm too lazy to fix it!"); + PRINTF("Warning: you lied about the type and I'm too lazy to fix it!"_fmt); return 0; } ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) @@ -5092,6 +5088,6 @@ ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) get_val(sd, &dat); if (dat.type == ByteCode::CONSTSTR) return dat.u.str; - PRINTF("Warning: you lied about the type and I can't fix it!"); + PRINTF("Warning: you lied about the type and I can't fix it!"_fmt); return ZString(); } diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp index 6b46d79..49496bb 100644 --- a/src/map/skill-pools.cpp +++ b/src/map/skill-pools.cpp @@ -34,7 +34,7 @@ void skill_pool_register(SkillID id) if (skill_pool_skills_size + 1 >= MAX_POOL_SKILLS) { FPRINTF(stderr, - "Too many pool skills! Increase MAX_POOL_SKILLS and recompile."); + "Too many pool skills! Increase MAX_POOL_SKILLS and recompile."_fmt); return; } @@ -78,7 +78,7 @@ int skill_pool_activate(dumb_ptr<map_session_data> sd, SkillID skill_id) { sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED; pc_calcstatus(sd, 0); - MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d", + MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d"_fmt, skill_id, sd->status.skill[skill_id].lv, skill_power(sd, skill_id)); return 0; @@ -97,7 +97,7 @@ int skill_pool_deactivate(dumb_ptr<map_session_data> sd, SkillID skill_id) if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED; - MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", skill_id); + MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d"_fmt, skill_id); pc_calcstatus(sd, 0); return 0; } diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 37a3b44..5b8f2a3 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -54,34 +54,34 @@ struct skill_name_db skill_names[] = { - {SkillID::AC_OWL, "OWL", "Owl's_Eye"}, - - {SkillID::NPC_EMOTION, "EMOTION", "NPC_EMOTION"}, - {SkillID::NPC_POISON, "POISON", "NPC_POISON"}, - {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"}, - {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"}, - - {SkillID::NV_EMOTE, "EMOTE", "Emote_Skill"}, - {SkillID::NV_TRADE, "TRADE", "Trade_Skill"}, - {SkillID::NV_PARTY, "PARTY", "Party_Skill"}, - - {SkillID::TMW_MAGIC, "MAGIC", "General Magic"}, - {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE", "Life Magic"}, - {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR", "War Magic"}, - {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE", "Transmutation Magic"}, - {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE", "Nature Magic"}, - {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER", "Astral Magic"}, - {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK", "Dark Magic"}, - {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT", "Light Magic"}, - - {SkillID::TMW_BRAWLING, "BRAWLING", "Brawling"}, - {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER", "Lucky Counter"}, - {SkillID::TMW_SPEED, "SPEED", "Speed"}, - {SkillID::TMW_RESIST_POISON, "RESIST_POISON", "Resist Poison"}, - {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL", "Astral Soul"}, - {SkillID::TMW_RAGING, "RAGING", "Raging"}, - - {SkillID::ZERO, "", ""} + {SkillID::AC_OWL, "OWL"_s, "Owl's_Eye"_s}, + + {SkillID::NPC_EMOTION, "EMOTION"_s, "NPC_EMOTION"_s}, + {SkillID::NPC_POISON, "POISON"_s, "NPC_POISON"_s}, + {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION"_s, "Kabooooom!"_s}, + {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE"_s, "NPC_SUMMONSLAVE"_s}, + + {SkillID::NV_EMOTE, "EMOTE"_s, "Emote_Skill"_s}, + {SkillID::NV_TRADE, "TRADE"_s, "Trade_Skill"_s}, + {SkillID::NV_PARTY, "PARTY"_s, "Party_Skill"_s}, + + {SkillID::TMW_MAGIC, "MAGIC"_s, "General Magic"_s}, + {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE"_s, "Life Magic"_s}, + {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR"_s, "War Magic"_s}, + {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE"_s, "Transmutation Magic"_s}, + {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE"_s, "Nature Magic"_s}, + {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER"_s, "Astral Magic"_s}, + {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK"_s, "Dark Magic"_s}, + {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT"_s, "Light Magic"_s}, + + {SkillID::TMW_BRAWLING, "BRAWLING"_s, "Brawling"_s}, + {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER"_s, "Lucky Counter"_s}, + {SkillID::TMW_SPEED, "SPEED"_s, "Speed"_s}, + {SkillID::TMW_RESIST_POISON, "RESIST_POISON"_s, "Resist Poison"_s}, + {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL"_s, "Astral Soul"_s}, + {SkillID::TMW_RAGING, "RAGING"_s, "Raging"_s}, + + {SkillID::ZERO, ""_s, ""_s} }; earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db; @@ -690,7 +690,7 @@ int skill_status_change_active(dumb_ptr<block_list> bl, StatusChange type) if (bl->bl_type != BL::PC && bl->bl_type != BL::MOB) { if (battle_config.error_log) - PRINTF("skill_status_change_active: neither MOB nor PC !\n"); + PRINTF("skill_status_change_active: neither MOB nor PC !\n"_fmt); return 0; } @@ -715,7 +715,7 @@ void skill_status_change_end(dumb_ptr<block_list> bl, StatusChange type, TimerDa if (bl->bl_type != BL::PC && bl->bl_type != BL::MOB) { if (battle_config.error_log) - PRINTF("skill_status_change_end: neither MOB nor PC !\n"); + PRINTF("skill_status_change_end: neither MOB nor PC !\n"_fmt); return; } sc_data = battle_get_sc_data(bl); @@ -971,7 +971,7 @@ int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, else { if (battle_config.error_log) - PRINTF("skill_status_change_start: neither MOB nor PC !\n"); + PRINTF("skill_status_change_start: neither MOB nor PC !\n"_fmt); return 0; } @@ -1045,7 +1045,7 @@ int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, break; default: if (battle_config.error_log) - PRINTF("UnknownStatusChange [%d]\n", type); + PRINTF("UnknownStatusChange [%d]\n"_fmt, type); return 0; } @@ -1175,22 +1175,22 @@ void skill_unit_timer_sub_ondelete(dumb_ptr<block_list> bl, static SP scan_stat(XString statname) { - if (statname == "str") + if (statname == "str"_s) return SP::STR; - if (statname == "dex") + if (statname == "dex"_s) return SP::DEX; - if (statname == "agi") + if (statname == "agi"_s) return SP::AGI; - if (statname == "vit") + if (statname == "vit"_s) return SP::VIT; - if (statname == "int") + if (statname == "int"_s) return SP::INT; - if (statname == "luk") + if (statname == "luk"_s) return SP::LUK; - if (statname == "none") + if (statname == "none"_s) return SP::ZERO; - FPRINTF(stderr, "Unknown stat `%s'\n", AString(statname)); + FPRINTF(stderr, "Unknown stat `%s'\n"_fmt, AString(statname)); return SP::ZERO; } @@ -1199,7 +1199,7 @@ bool skill_readdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -1209,7 +1209,7 @@ bool skill_readdb(ZString filename) { // is_comment only works for whole-line comments // that could change once the Z dependency is dropped ... - XString comment = "//"; + LString comment = "//"_s; XString line = line_.xislice_h(std::search(line_.begin(), line_.end(), comment.begin(), comment.end())).rstrip(); if (!line) continue; @@ -1251,9 +1251,9 @@ bool skill_readdb(ZString filename) continue; } - if (castcancel == "yes") + if (castcancel == "yes"_s) skdb.castcancel = true; - else if (castcancel == "no") + else if (castcancel == "no"_s) skdb.castcancel = false; else { @@ -1261,17 +1261,17 @@ bool skill_readdb(ZString filename) continue; } - if (flags == "passive") + if (flags == "passive"_s) { skill_pool_register(i); skdb.poolflags = SkillFlags::POOL_FLAG; } - else if (flags == "active") + else if (flags == "active"_s) { skill_pool_register(i); skdb.poolflags = SkillFlags::POOL_FLAG | SkillFlags::POOL_ACTIVE; } - else if (flags == "no") + else if (flags == "no"_s) skdb.poolflags = SkillFlags::ZERO; else { @@ -1290,7 +1290,7 @@ bool skill_readdb(ZString filename) skill_db[i] = skdb; skill_lookup_by_id(i).desc = RString(tmp); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); return rv; } diff --git a/src/map/skill.hpp b/src/map/skill.hpp index 1a615c1..91fa070 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -61,11 +61,11 @@ earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db; struct skill_name_db { SkillID id; // skill id - RString name; // search strings + LString name; // search strings RString desc; // description that shows up for searches // this makes const char(&)[] not decay into const char * in {} - skill_name_db(SkillID i, RString n, RString d) + skill_name_db(SkillID i, LString n, LString d) : id(i), name(n), desc(d) {} }; diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 46128d1..7874e8e 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -91,7 +91,7 @@ int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, XString message) { sd->chat_lines_in = sd->chat_total_repeats = 0; - tmw_AutoBan(sd, "chat", battle_config.chat_spam_ban); + tmw_AutoBan(sd, "chat"_s, battle_config.chat_spam_ban); return 1; } @@ -100,8 +100,8 @@ int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, XString message) (sd->chat_lines_in >= battle_config.chat_spam_warn || sd->chat_total_repeats >= battle_config.chat_spam_warn)) { - clif_displaymessage(sd->sess, "WARNING: You are about to be automatically banned for spam!"); - clif_displaymessage(sd->sess, "WARNING: Please slow down, do not repeat, and do not SHOUT!"); + clif_displaymessage(sd->sess, "WARNING: You are about to be automatically banned for spam!"_s); + clif_displaymessage(sd->sess, "WARNING: Please slow down, do not repeat, and do not SHOUT!"_s); } return 0; @@ -114,16 +114,16 @@ void tmw_AutoBan(dumb_ptr<map_session_data> sd, ZString reason, int length) sd->auto_ban_info.in_progress = 1; - AString hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam", + AString hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam"_fmt, sd->status_key.name, reason); tmw_GmHackMsg(hack_msg); - AString fake_command = STRPRINTF("@autoban %s %dh (%s spam)", + AString fake_command = STRPRINTF("@autoban %s %dh (%s spam)"_fmt, sd->status_key.name, length, reason); log_atcommand(sd, fake_command); - AString anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.", + AString anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam."_fmt, reason); clif_displaymessage(sd->sess, anotherbuf); diff --git a/src/map/trade.cpp b/src/map/trade.cpp index c877d00..86d876f 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -348,7 +348,7 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) { - MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d", + MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d"_fmt, target_sd->status_key.char_id, sd->deal_zeny, target_sd->deal_zeny); if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1)) @@ -363,14 +363,14 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) { sd->deal_zeny = 0; trade_tradecancel(sd); - MAP_LOG_PC(sd, " TRADECANCEL"); + MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } if (target_sd->deal_zeny > target_sd->status.zeny) { target_sd->deal_zeny = 0; trade_tradecancel(sd); - MAP_LOG_PC(sd, " TRADECANCEL"); + MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } sd->trade_partner = 0; @@ -434,7 +434,7 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) target_sd->deal_locked = 0; clif_tradecompleted(sd, 0); clif_tradecompleted(target_sd, 0); - MAP_LOG_PC(sd, " TRADEOK"); + MAP_LOG_PC(sd, " TRADEOK"_fmt); } } } diff --git a/src/mmo/config_parse.cpp b/src/mmo/config_parse.cpp index b954e8b..a6dfd6e 100644 --- a/src/mmo/config_parse.cpp +++ b/src/mmo/config_parse.cpp @@ -30,7 +30,7 @@ bool is_comment(XString line) { - return not line or line.startswith("//"); + return not line or line.startswith("//"_s); } template<class ZS> @@ -72,7 +72,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) io::LineReader in(filename); if (!in.is_open()) { - PRINTF("Unable to open file: %s\n", filename); + PRINTF("Unable to open file: %s\n"_fmt, filename); return false; } io::Line line; @@ -85,16 +85,16 @@ bool load_config_file(ZString filename, ConfigItemParser slave) ZString value; if (!config_split(line.text, &key, &value)) { - line.error("Bad config line"); + line.error("Bad config line"_s); rv = false; continue; } - if (key == "import") + if (key == "import"_s) { rv &= load_config_file(value, slave); continue; } - else if (key == "version-lt") + else if (key == "version-lt"_s) { Version vers; if (!extract(value, &vers)) @@ -106,7 +106,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-le") + else if (key == "version-le"_s) { Version vers; if (!extract(value, &vers)) @@ -118,7 +118,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-gt") + else if (key == "version-gt"_s) { Version vers; if (!extract(value, &vers)) @@ -130,7 +130,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-ge") + else if (key == "version-ge"_s) { Version vers; if (!extract(value, &vers)) @@ -144,7 +144,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) } else if (!slave(key, value)) { - line.error("Bad config key or value"); + line.error("Bad config key or value"_s); rv = false; continue; } diff --git a/src/mmo/core.cpp b/src/mmo/core.cpp index 68b7823..8b3690a 100644 --- a/src/mmo/core.cpp +++ b/src/mmo/core.cpp @@ -107,7 +107,7 @@ int main(int argc, char **argv) if (!runflag) { - PRINTF("Fatal error during startup; exiting\n"); + PRINTF("Fatal error during startup; exiting\n"_fmt); return 1; } // set up exit handlers *after* the initialization has happened. diff --git a/src/mmo/extract_test.cpp b/src/mmo/extract_test.cpp index 60ab49e..c405de1 100644 --- a/src/mmo/extract_test.cpp +++ b/src/mmo/extract_test.cpp @@ -28,154 +28,154 @@ TEST(extract, record_int) { int x, y, z; x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' '>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); @@ -185,170 +185,170 @@ TEST(extract, record_int) TEST(extract, record_str) { XString x, y, z; - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("", record<' '>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(" "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(""_s, record<' '>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract(" ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(" "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(""_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract(" ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(" "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(""_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; } TEST(extract, mapname) { MapName map; - EXPECT_TRUE(extract("abc", &map)); - EXPECT_EQ(map, "abc"); - EXPECT_TRUE(extract("abc.gat", &map)); - EXPECT_EQ(map, "abc"); - EXPECT_TRUE(extract("abcdefghijklmno", &map)); - EXPECT_EQ(map, "abcdefghijklmno"); - EXPECT_TRUE(extract("abcdefghijklmno.gat", &map)); - EXPECT_EQ(map, "abcdefghijklmno"); + EXPECT_TRUE(extract("abc"_s, &map)); + EXPECT_EQ(map, "abc"_s); + EXPECT_TRUE(extract("abc.gat"_s, &map)); + EXPECT_EQ(map, "abc"_s); + EXPECT_TRUE(extract("abcdefghijklmno"_s, &map)); + EXPECT_EQ(map, "abcdefghijklmno"_s); + EXPECT_TRUE(extract("abcdefghijklmno.gat"_s, &map)); + EXPECT_EQ(map, "abcdefghijklmno"_s); } diff --git a/src/mmo/human_time_diff.hpp b/src/mmo/human_time_diff.hpp index 689b8d9..aace438 100644 --- a/src/mmo/human_time_diff.hpp +++ b/src/mmo/human_time_diff.hpp @@ -61,21 +61,21 @@ bool extract(XString str, HumanTimeDiff *iv) str = str.xislice_t(it2); short *ptr = nullptr; - if (suffix == "y" || suffix == "a") + if (suffix == "y"_s || suffix == "a"_s) ptr = &iv->year; - else if (suffix == "m") + else if (suffix == "m"_s) ptr = &iv->month; - else if (suffix == "j" || suffix == "d") + else if (suffix == "j"_s || suffix == "d"_s) ptr = &iv->day; - else if (suffix == "h") + else if (suffix == "h"_s) ptr = &iv->hour; - else if (suffix == "mn") + else if (suffix == "mn"_s) ptr = &iv->minute; - else if (suffix == "s") + else if (suffix == "s"_s) ptr = &iv->second; else return false; - if (number.startswith('+') && !number.startswith("+-")) + if (number.startswith('+') && !number.startswith("+-"_s)) number = number.xslice_t(1); if (*ptr || !extract(number, ptr)) return false; diff --git a/src/mmo/human_time_diff_test.cpp b/src/mmo/human_time_diff_test.cpp index 138849b..fb9522e 100644 --- a/src/mmo/human_time_diff_test.cpp +++ b/src/mmo/human_time_diff_test.cpp @@ -28,7 +28,7 @@ TEST(humantimediff, single) { HumanTimeDiff diff; - EXPECT_TRUE(extract("42y", &diff)); + EXPECT_TRUE(extract("42y"_s, &diff)); EXPECT_EQ(42, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -36,7 +36,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42m", &diff)); + EXPECT_TRUE(extract("42m"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(42, diff.month); EXPECT_EQ(0, diff.day); @@ -44,7 +44,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42d", &diff)); + EXPECT_TRUE(extract("42d"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(42, diff.day); @@ -52,7 +52,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42h", &diff)); + EXPECT_TRUE(extract("42h"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -60,7 +60,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42mn", &diff)); + EXPECT_TRUE(extract("42mn"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -68,7 +68,7 @@ TEST(humantimediff, single) EXPECT_EQ(42, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42s", &diff)); + EXPECT_TRUE(extract("42s"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -76,28 +76,28 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(42, diff.second); - EXPECT_TRUE(extract("+42y", &diff)); + EXPECT_TRUE(extract("+42y"_s, &diff)); EXPECT_EQ(42, diff.year); - EXPECT_TRUE(extract("-42y", &diff)); + EXPECT_TRUE(extract("-42y"_s, &diff)); EXPECT_EQ(-42, diff.year); - EXPECT_FALSE(extract("++42y", &diff)); - EXPECT_FALSE(extract("+-42y", &diff)); - EXPECT_FALSE(extract("-+42y", &diff)); - EXPECT_FALSE(extract("--42y", &diff)); - EXPECT_FALSE(extract("4+2y", &diff)); - EXPECT_FALSE(extract("42z", &diff)); + EXPECT_FALSE(extract("++42y"_s, &diff)); + EXPECT_FALSE(extract("+-42y"_s, &diff)); + EXPECT_FALSE(extract("-+42y"_s, &diff)); + EXPECT_FALSE(extract("--42y"_s, &diff)); + EXPECT_FALSE(extract("4+2y"_s, &diff)); + EXPECT_FALSE(extract("42z"_s, &diff)); } TEST(humantimediff, multiple) { HumanTimeDiff diff; - EXPECT_TRUE(extract("42y23m-2d", &diff)); + EXPECT_TRUE(extract("42y23m-2d"_s, &diff)); EXPECT_EQ(42, diff.year); EXPECT_EQ(23, diff.month); EXPECT_EQ(-2, diff.day); EXPECT_EQ(0, diff.hour); EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_FALSE(extract("1y2y", &diff)); + EXPECT_FALSE(extract("1y2y"_s, &diff)); } diff --git a/src/mmo/ip.cpp b/src/mmo/ip.cpp index 146734a..67d6435 100644 --- a/src/mmo/ip.cpp +++ b/src/mmo/ip.cpp @@ -104,11 +104,11 @@ bool extract(XString str, IP4Mask *rv) VString<15> convert_for_printf(IP4Address a_) { const uint8_t *a = a_.bytes(); - return STRNPRINTF(16, "%hhu.%hhu.%hhu.%hhu", a[0], a[1], a[2], a[3]); + return STRNPRINTF(16, "%hhu.%hhu.%hhu.%hhu"_fmt, a[0], a[1], a[2], a[3]); } VString<31> convert_for_printf(IP4Mask a) { - return STRNPRINTF(32, "%s/%s", + return STRNPRINTF(32, "%s/%s"_fmt, a.addr(), a.mask()); } diff --git a/src/mmo/ip_test.cpp b/src/mmo/ip_test.cpp index 8e50453..01f714e 100644 --- a/src/mmo/ip_test.cpp +++ b/src/mmo/ip_test.cpp @@ -66,32 +66,32 @@ TEST(ip4addr, cmp) TEST(ip4addr, str) { IP4Address a; - EXPECT_EQ("0.0.0.0", STRNPRINTF(17, "%s", a)); - EXPECT_EQ("127.0.0.1", STRNPRINTF(17, "%s", IP4_LOCALHOST)); - EXPECT_EQ("255.255.255.255", STRNPRINTF(17, "%s", IP4_BROADCAST)); + EXPECT_EQ("0.0.0.0"_s, STRNPRINTF(17, "%s"_fmt, a)); + EXPECT_EQ("127.0.0.1"_s, STRNPRINTF(17, "%s"_fmt, IP4_LOCALHOST)); + EXPECT_EQ("255.255.255.255"_s, STRNPRINTF(17, "%s"_fmt, IP4_BROADCAST)); } TEST(ip4addr, extract) { IP4Address a; - EXPECT_TRUE(extract("0.0.0.0", &a)); - EXPECT_EQ("0.0.0.0", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("127.0.0.1", &a)); - EXPECT_EQ("127.0.0.1", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("255.255.255.255", &a)); - EXPECT_EQ("255.255.255.255", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("1.2.3.4", &a)); - EXPECT_EQ("1.2.3.4", STRNPRINTF(16, "%s", a)); + EXPECT_TRUE(extract("0.0.0.0"_s, &a)); + EXPECT_EQ("0.0.0.0"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("127.0.0.1"_s, &a)); + EXPECT_EQ("127.0.0.1"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("255.255.255.255"_s, &a)); + EXPECT_EQ("255.255.255.255"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("1.2.3.4"_s, &a)); + EXPECT_EQ("1.2.3.4"_s, STRNPRINTF(16, "%s"_fmt, a)); - EXPECT_FALSE(extract("1.2.3.4.5", &a)); - EXPECT_FALSE(extract("1.2.3.4.", &a)); - EXPECT_FALSE(extract("1.2.3.", &a)); - EXPECT_FALSE(extract("1.2.3", &a)); - EXPECT_FALSE(extract("1.2.", &a)); - EXPECT_FALSE(extract("1.2", &a)); - EXPECT_FALSE(extract("1.", &a)); - EXPECT_FALSE(extract("1", &a)); - EXPECT_FALSE(extract("", &a)); + EXPECT_FALSE(extract("1.2.3.4.5"_s, &a)); + EXPECT_FALSE(extract("1.2.3.4."_s, &a)); + EXPECT_FALSE(extract("1.2.3."_s, &a)); + EXPECT_FALSE(extract("1.2.3"_s, &a)); + EXPECT_FALSE(extract("1.2."_s, &a)); + EXPECT_FALSE(extract("1.2"_s, &a)); + EXPECT_FALSE(extract("1."_s, &a)); + EXPECT_FALSE(extract("1"_s, &a)); + EXPECT_FALSE(extract(""_s, &a)); } @@ -108,139 +108,139 @@ TEST(ip4mask, body) TEST(ip4mask, str) { IP4Mask m; - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(33, "%s", m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(33, "%s"_fmt, m)); m = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(33, "%s", m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(33, "%s"_fmt, m)); } TEST(ip4mask, extract) { IP4Mask m; - EXPECT_FALSE(extract("9.8.7.6/33", &m)); - EXPECT_FALSE(extract("9.8.7.6.5", &m)); - EXPECT_FALSE(extract("9.8.7.6/", &m)); - EXPECT_FALSE(extract("9.8.7", &m)); - EXPECT_FALSE(extract("9.8", &m)); - EXPECT_FALSE(extract("9", &m)); + EXPECT_FALSE(extract("9.8.7.6/33"_s, &m)); + EXPECT_FALSE(extract("9.8.7.6.5"_s, &m)); + EXPECT_FALSE(extract("9.8.7.6/"_s, &m)); + EXPECT_FALSE(extract("9.8.7"_s, &m)); + EXPECT_FALSE(extract("9.8"_s, &m)); + EXPECT_FALSE(extract("9"_s, &m)); - EXPECT_TRUE(extract("127.0.0.1", &m)); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.0.1.", &m)); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.0.", &m)); - EXPECT_EQ("127.0.0.0/255.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.", &m)); - EXPECT_EQ("127.0.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.", &m)); - EXPECT_EQ("127.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("127.0.0.1"_s, &m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0.0.1."_s, &m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0.0."_s, &m)); + EXPECT_EQ("127.0.0.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0."_s, &m)); + EXPECT_EQ("127.0.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127."_s, &m)); + EXPECT_EQ("127.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("1.2.3.4/255.255.255.255", &m)); - EXPECT_EQ("1.2.3.4/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.3.0/255.255.255.0", &m)); - EXPECT_EQ("1.2.3.0/255.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.0.4/255.255.0.255", &m)); - EXPECT_EQ("1.2.0.4/255.255.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.0.0/255.255.0.0", &m)); - EXPECT_EQ("1.2.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.3.4/255.0.255.255", &m)); - EXPECT_EQ("1.0.3.4/255.0.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.3.0/255.0.255.0", &m)); - EXPECT_EQ("1.0.3.0/255.0.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.0.4/255.0.0.255", &m)); - EXPECT_EQ("1.0.0.4/255.0.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.0.0/255.0.0.0", &m)); - EXPECT_EQ("1.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.3.4/0.255.255.255", &m)); - EXPECT_EQ("0.2.3.4/0.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.3.0/0.255.255.0", &m)); - EXPECT_EQ("0.2.3.0/0.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.0.4/0.255.0.255", &m)); - EXPECT_EQ("0.2.0.4/0.255.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.0.0/0.255.0.0", &m)); - EXPECT_EQ("0.2.0.0/0.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.3.4/0.0.255.255", &m)); - EXPECT_EQ("0.0.3.4/0.0.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.3.0/0.0.255.0", &m)); - EXPECT_EQ("0.0.3.0/0.0.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.4/0.0.0.255", &m)); - EXPECT_EQ("0.0.0.4/0.0.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/0.0.0.0", &m)); - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("1.2.3.4/255.255.255.255"_s, &m)); + EXPECT_EQ("1.2.3.4/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.3.0/255.255.255.0"_s, &m)); + EXPECT_EQ("1.2.3.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.0.4/255.255.0.255"_s, &m)); + EXPECT_EQ("1.2.0.4/255.255.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.0.0/255.255.0.0"_s, &m)); + EXPECT_EQ("1.2.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.3.4/255.0.255.255"_s, &m)); + EXPECT_EQ("1.0.3.4/255.0.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.3.0/255.0.255.0"_s, &m)); + EXPECT_EQ("1.0.3.0/255.0.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.0.4/255.0.0.255"_s, &m)); + EXPECT_EQ("1.0.0.4/255.0.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.0.0/255.0.0.0"_s, &m)); + EXPECT_EQ("1.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.3.4/0.255.255.255"_s, &m)); + EXPECT_EQ("0.2.3.4/0.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.3.0/0.255.255.0"_s, &m)); + EXPECT_EQ("0.2.3.0/0.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.0.4/0.255.0.255"_s, &m)); + EXPECT_EQ("0.2.0.4/0.255.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.0.0/0.255.0.0"_s, &m)); + EXPECT_EQ("0.2.0.0/0.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.3.4/0.0.255.255"_s, &m)); + EXPECT_EQ("0.0.3.4/0.0.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.3.0/0.0.255.0"_s, &m)); + EXPECT_EQ("0.0.3.0/0.0.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.4/0.0.0.255"_s, &m)); + EXPECT_EQ("0.0.0.4/0.0.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/0.0.0.0"_s, &m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); // please don't do this - EXPECT_TRUE(extract("120.248.200.217/89.57.126.5", &m)); - EXPECT_EQ("88.56.72.1/89.57.126.5", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("120.248.200.217/89.57.126.5"_s, &m)); + EXPECT_EQ("88.56.72.1/89.57.126.5"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/32", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.255", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/32"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/31", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.254", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/30", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.252", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/29", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.248", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/28", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.240", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/27", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.224", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/26", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.192", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/25", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.128", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/24", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/31"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.254"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/30"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.252"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/29"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.248"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/28"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.240"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/27"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.224"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/26"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.192"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/25"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.128"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/24"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/23", &m)); - EXPECT_EQ("0.0.0.0/255.255.254.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/22", &m)); - EXPECT_EQ("0.0.0.0/255.255.252.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/21", &m)); - EXPECT_EQ("0.0.0.0/255.255.248.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/20", &m)); - EXPECT_EQ("0.0.0.0/255.255.240.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/19", &m)); - EXPECT_EQ("0.0.0.0/255.255.224.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/18", &m)); - EXPECT_EQ("0.0.0.0/255.255.192.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/17", &m)); - EXPECT_EQ("0.0.0.0/255.255.128.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/16", &m)); - EXPECT_EQ("0.0.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/23"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.254.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/22"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.252.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/21"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.248.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/20"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.240.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/19"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.224.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/18"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.192.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/17"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.128.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/16"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/15", &m)); - EXPECT_EQ("0.0.0.0/255.254.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/14", &m)); - EXPECT_EQ("0.0.0.0/255.252.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/13", &m)); - EXPECT_EQ("0.0.0.0/255.248.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/12", &m)); - EXPECT_EQ("0.0.0.0/255.240.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/11", &m)); - EXPECT_EQ("0.0.0.0/255.224.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/10", &m)); - EXPECT_EQ("0.0.0.0/255.192.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/9", &m)); - EXPECT_EQ("0.0.0.0/255.128.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/8", &m)); - EXPECT_EQ("0.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/15"_s, &m)); + EXPECT_EQ("0.0.0.0/255.254.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/14"_s, &m)); + EXPECT_EQ("0.0.0.0/255.252.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/13"_s, &m)); + EXPECT_EQ("0.0.0.0/255.248.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/12"_s, &m)); + EXPECT_EQ("0.0.0.0/255.240.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/11"_s, &m)); + EXPECT_EQ("0.0.0.0/255.224.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/10"_s, &m)); + EXPECT_EQ("0.0.0.0/255.192.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/9"_s, &m)); + EXPECT_EQ("0.0.0.0/255.128.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/8"_s, &m)); + EXPECT_EQ("0.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/7", &m)); - EXPECT_EQ("0.0.0.0/254.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/6", &m)); - EXPECT_EQ("0.0.0.0/252.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/5", &m)); - EXPECT_EQ("0.0.0.0/248.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/4", &m)); - EXPECT_EQ("0.0.0.0/240.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/3", &m)); - EXPECT_EQ("0.0.0.0/224.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/2", &m)); - EXPECT_EQ("0.0.0.0/192.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/1", &m)); - EXPECT_EQ("0.0.0.0/128.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/0", &m)); - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/7"_s, &m)); + EXPECT_EQ("0.0.0.0/254.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/6"_s, &m)); + EXPECT_EQ("0.0.0.0/252.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/5"_s, &m)); + EXPECT_EQ("0.0.0.0/248.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/4"_s, &m)); + EXPECT_EQ("0.0.0.0/240.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/3"_s, &m)); + EXPECT_EQ("0.0.0.0/224.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/2"_s, &m)); + EXPECT_EQ("0.0.0.0/192.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/1"_s, &m)); + EXPECT_EQ("0.0.0.0/128.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/0"_s, &m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); } TEST(ip4mask, cover) @@ -344,7 +344,7 @@ TEST(ip4mask, cover) EXPECT_FALSE(m.covers(IP4Address({192, 169, 0, 0}))); // OTOH this is crazy - EXPECT_TRUE(extract("120.248.200.217/89.57.126.5", &m)); + EXPECT_TRUE(extract("120.248.200.217/89.57.126.5"_s, &m)); EXPECT_TRUE(m.covers(IP4Address({120, 248, 200, 217}))); EXPECT_TRUE(m.covers(IP4Address({88, 56, 72, 1}))); EXPECT_FALSE(m.covers(IP4Address({88, 56, 72, 0}))); diff --git a/src/mmo/md5more.cpp b/src/mmo/md5more.cpp index 3fce5c7..cc17d37 100644 --- a/src/mmo/md5more.cpp +++ b/src/mmo/md5more.cpp @@ -103,7 +103,7 @@ AccountCrypt MD5_saltcrypt(AccountPass key, SaltString salt) VString<31> obuf; // This truncates the string, but we have to keep it like that for compatibility - SNPRINTF(obuf, 32, "!%s$%s", salt, tbuf3); + SNPRINTF(obuf, 32, "!%s$%s"_fmt, salt, tbuf3); return stringish<AccountCrypt>(obuf); } @@ -134,7 +134,7 @@ IP4Address MD5_ip(IP4Address ip) // MD5sum a secret + the IP address VString<31> ipbuf; - SNPRINTF(ipbuf, 32, "%s %s", ip, secret); + SNPRINTF(ipbuf, 32, "%s %s"_fmt, ip, secret); md5_binary obuf; MD5_to_bin(MD5_from_string(ipbuf), obuf); diff --git a/src/mmo/mmo.hpp b/src/mmo/mmo.hpp index c9d62ca..3fba7e6 100644 --- a/src/mmo/mmo.hpp +++ b/src/mmo/mmo.hpp @@ -85,7 +85,7 @@ struct ServerName : VString<19> {}; struct PartyName : VString<23> {}; struct VarName : VString<31> {}; -# define DEFAULT_EMAIL stringish<AccountEmail>("a@a.com") +# define DEFAULT_EMAIL stringish<AccountEmail>("a@a.com"_s) // It is decreed: a mapname shall not contain an extension class MapName : public strings::_crtp_string<MapName, MapName, strings::ZPair> diff --git a/src/mmo/socket.cpp b/src/mmo/socket.cpp index 1e294bd..2fec6c1 100644 --- a/src/mmo/socket.cpp +++ b/src/mmo/socket.cpp @@ -190,7 +190,7 @@ void connect_client(Session *ls) } if (fd.uncast_dammit() >= SOFT_LIMIT) { - FPRINTF(stderr, "softlimit reached, disconnecting : %d\n", fd.uncast_dammit()); + FPRINTF(stderr, "softlimit reached, disconnecting : %d\n"_fmt, fd.uncast_dammit()); fd.shutdown(SHUT_RDWR); fd.close(); return; @@ -403,12 +403,12 @@ void WFIFOSET(Session *s, size_t len) if (s->wdata_size + len + 16384 > s->max_wdata) { realloc_fifo(s, s->max_rdata, s->max_wdata << 1); - PRINTF("socket: %d wdata expanded to %zu bytes.\n", s, s->max_wdata); + PRINTF("socket: %d wdata expanded to %zu bytes.\n"_fmt, s, s->max_wdata); } if (s->wdata_size + len + 2048 < s->max_wdata) s->wdata_size += len; else - FPRINTF(stderr, "socket: %d wdata lost !!\n", s), abort(); + FPRINTF(stderr, "socket: %d wdata lost !!\n"_fmt, s), abort(); } void do_sendrecv(interval_t next_ms) @@ -429,7 +429,7 @@ void do_sendrecv(interval_t next_ms) { if (!has_timers()) { - PRINTF("Shutting down - nothing to do\n"); + PRINTF("Shutting down - nothing to do\n"_fmt); runflag = false; } return; @@ -474,7 +474,7 @@ void do_parsepacket(void) if (!s->connected && static_cast<time_t>(TimeT::now()) - static_cast<time_t>(s->created) > CONNECT_TIMEOUT) { - PRINTF("Session #%d timed out\n", s); + PRINTF("Session #%d timed out\n"_fmt, s); s->set_eof(); } if (s->rdata_size && !s->eof && s->func_parse) @@ -502,7 +502,7 @@ void RFIFOSKIP(Session *s, size_t len) if (s->rdata_size < s->rdata_pos) { - FPRINTF(stderr, "too many skip\n"); + FPRINTF(stderr, "too many skip\n"_fmt); abort(); } } diff --git a/src/mmo/utils.cpp b/src/mmo/utils.cpp index a1316d1..5765eaf 100644 --- a/src/mmo/utils.cpp +++ b/src/mmo/utils.cpp @@ -57,9 +57,9 @@ bool e_mail_check(XString email) return 0; if (hostname.front() == '.' || hostname.back() == '.') return 0; - if (hostname.contains_seq("..")) + if (hostname.contains_seq(".."_s)) return 0; - if (email.contains_any(" ;")) + if (email.contains_any(" ;"_s)) return 0; return email.is_print(); } @@ -70,18 +70,18 @@ bool e_mail_check(XString email) //------------------------------------------------- int config_switch(ZString str) { - if (str == "true" || str == "on" || str == "yes" - || str == "oui" || str == "ja" - || str == "si") + if (str == "true"_s || str == "on"_s || str == "yes"_s + || str == "oui"_s || str == "ja"_s + || str == "si"_s) return 1; - if (str == "false" || str == "off" || str == "no" - || str == "non" || str == "nein") + if (str == "false"_s || str == "off"_s || str == "no"_s + || str == "non"_s || str == "nein"_s) return 0; int rv; if (extract(str, &rv)) return rv; - FPRINTF(stderr, "Fatal: bad option value %s", str); + FPRINTF(stderr, "Fatal: bad option value %s"_fmt, str); abort(); } @@ -93,7 +93,7 @@ void stamp_time(timestamp_seconds_buffer& out, const TimeT *t) struct tm when = t ? *t : TimeT::now(); char buf[20]; strftime(buf, 20, "%Y-%m-%d %H:%M:%S", &when); - out = stringish<timestamp_seconds_buffer>(const_(buf)); + out = stringish<timestamp_seconds_buffer>(VString<19>(strings::really_construct_from_a_pointer, buf)); } void stamp_time(timestamp_milliseconds_buffer& out) { @@ -103,7 +103,7 @@ void stamp_time(timestamp_milliseconds_buffer& out) char buf[24]; strftime(buf, 20, "%Y-%m-%d %H:%M:%S", &when); sprintf(buf + 19, ".%03d", static_cast<int>(tv.tv_usec / 1000)); - out = stringish<timestamp_milliseconds_buffer>(const_(buf)); + out = stringish<timestamp_milliseconds_buffer>(VString<23>(strings::really_construct_from_a_pointer, buf)); } void log_with_timestamp(io::WriteFile& out, XString line) diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp index c882105..21d6065 100644 --- a/src/monitor/main.cpp +++ b/src/monitor/main.cpp @@ -39,10 +39,10 @@ #include "../poison.hpp" -#define LOGIN_SERVER "./login-server" -#define MAP_SERVER "./map-server" -#define CHAR_SERVER "./char-server" -#define CONFIG "conf/eathena-monitor.conf" +#define LOGIN_SERVER "./login-server"_s +#define MAP_SERVER "./map-server"_s +#define CHAR_SERVER "./char-server"_s +#define CONFIG "conf/eathena-monitor.conf"_s // initialiized to $HOME/tmwserver @@ -72,17 +72,17 @@ AString make_path(XString base, XString path) static bool parse_option(XString name, ZString value) { - if (name == "login_server") + if (name == "login_server"_s) login_server = value; - else if (name == "map_server") + else if (name == "map_server"_s) map_server = value; - else if (name == "char_server") + else if (name == "char_server"_s) char_server = value; - else if (name == "workdir") + else if (name == "workdir"_s) workdir = value; else { - FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' : '%s'\n", + FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' : '%s'\n"_fmt, AString(name), value); return false; } @@ -96,7 +96,7 @@ bool read_config(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - FPRINTF(stderr, "Monitor config file not found: %s\n", filename); + FPRINTF(stderr, "Monitor config file not found: %s\n"_fmt, filename); exit(1); } @@ -109,14 +109,14 @@ bool read_config(ZString filename) ZString value; if (!config_split(line, &name, &value)) { - PRINTF("Bad line: %s\n", line); + PRINTF("Bad line: %s\n"_fmt, line); rv = false; continue; } if (!parse_option(name, value)) { - PRINTF("Bad key/value: %s\n", line); + PRINTF("Bad key/value: %s\n"_fmt, line); rv = false; continue; } @@ -131,7 +131,7 @@ pid_t start_process(ZString exec) pid_t pid = fork(); if (pid == -1) { - FPRINTF(stderr, "Failed to fork"); + FPRINTF(stderr, "Failed to fork"_fmt); return 0; } if (pid == 0) @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) signal(SIGQUIT, stop_process); signal(SIGABRT, stop_process); - workdir = make_path(ZString(strings::really_construct_from_a_pointer, getenv("HOME"), nullptr), "tmwserver"); + workdir = make_path(ZString(strings::really_construct_from_a_pointer, getenv("HOME"), nullptr), "tmwserver"_s); ZString config = CONFIG; if (argc > 1) @@ -186,11 +186,11 @@ int main(int argc, char *argv[]) exit(1); } - PRINTF("Starting:\n"); - PRINTF("* workdir: %s\n", workdir); - PRINTF("* login_server: %s\n", login_server); - PRINTF("* char_server: %s\n", char_server); - PRINTF("* map_server: %s\n", map_server); + PRINTF("Starting:\n"_fmt); + PRINTF("* workdir: %s\n"_fmt, workdir); + PRINTF("* login_server: %s\n"_fmt, login_server); + PRINTF("* char_server: %s\n"_fmt, char_server); + PRINTF("* map_server: %s\n"_fmt, map_server); { //make sure all possible file descriptors are free for use by the servers //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem @@ -198,9 +198,9 @@ int main(int argc, char *argv[]) while ((fd = fd.prev()) > io::FD::stderr()) { if (fd.close() == 0) - FPRINTF(stderr, "close fd %d\n", fd.uncast_dammit()); + FPRINTF(stderr, "close fd %d\n"_fmt, fd.uncast_dammit()); } - fd = io::FD::open("/dev/null", O_RDWR); + fd = io::FD::open("/dev/null"_s, O_RDWR); if (fd == io::FD()) { perror("open /dev/null"); @@ -219,19 +219,19 @@ int main(int argc, char *argv[]) if (!pid_login) { pid_login = start_process(login_server); - FPRINTF(stderr, "[%s] forked login server: %lu\n", + FPRINTF(stderr, "[%s] forked login server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_login)); } if (!pid_char) { pid_char = start_process(char_server); - FPRINTF(stderr, "[%s] forked char server: %lu\n", + FPRINTF(stderr, "[%s] forked char server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_char)); } if (!pid_map) { pid_map = start_process(map_server); - FPRINTF(stderr, "[%s] forked map server: %lu\n", + FPRINTF(stderr, "[%s] forked map server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_map)); } pid_t dead = wait(NULL); diff --git a/src/sanity.hpp b/src/sanity.hpp index f29a7c3..70ee8fe 100644 --- a/src/sanity.hpp +++ b/src/sanity.hpp @@ -34,16 +34,17 @@ # if __GNUC__ == 4 // clang identifies as GCC 4.2, but is mostly okay. // Until a bug-free release of it happens, though, I won't recommend it. -// (patched) clang 3.1 would be the requirement -# if __GNUC_MINOR__ < 6 && !defined(__clang__) -# error "Please upgrade to at least GCC 4.6" -# endif // __GNUC_MINOR__ < 6 && !defined(__clang__) +// clang 3.2 is the minimum that the CI builds are using +# if __GNUC_MINOR__ < 7 && !defined(__clang__) +# error "Please upgrade to at least GCC 4.7" +# endif // __GNUC_MINOR__ < 7 && !defined(__clang__) # endif // __GNUC__ == 4 # if not defined(__i386__) and not defined(__x86_64__) // Known platform dependencies: // endianness for the [RW]FIFO.* macros // possibly, some signal-handling +// some integer sizes (partially fixed for the x32 ABI) # error "Unsupported platform, we use x86 / amd64 only" # endif // not __i386__ diff --git a/src/sexpr/lexer.cpp b/src/sexpr/lexer.cpp index 8c1c380..cc7087b 100644 --- a/src/sexpr/lexer.cpp +++ b/src/sexpr/lexer.cpp @@ -28,14 +28,14 @@ namespace sexpr { Lexeme Lexer::_adv() { - XString whitespace = " \t\n\r\v\f"; + LString whitespace = " \t\n\r\v\f"_s; while (true) { if (!_in.get(_span.begin)) { if (!_depth.empty()) { - _depth.back().error("Unmatched '('"); + _depth.back().error("Unmatched '('"_s); return TOK_ERROR; } return TOK_EOF; @@ -52,14 +52,14 @@ namespace sexpr switch (co) { case '(': - _string = "("; + _string = "("_s; _depth.push_back(_span.end); return TOK_OPEN; case ')': - _string = ")"; + _string = ")"_s; if (_depth.empty()) { - _span.end.error("Unmatched ')'"); + _span.end.error("Unmatched ')'"_s); return TOK_ERROR; } _depth.pop_back(); @@ -73,7 +73,7 @@ namespace sexpr { if (!_in.get(_span.end)) { - _span.error("EOF in string literal"); + _span.error("EOF in string literal"_s); return TOK_ERROR; } char ch = _span.end.ch(); @@ -89,7 +89,7 @@ namespace sexpr if (!_in.get(_span.end)) { - _span.end.error("EOF at backslash in string"); + _span.end.error("EOF at backslash in string"_s); return TOK_ERROR; } ch = _span.end.ch(); @@ -97,7 +97,7 @@ namespace sexpr switch (ch) { default: - _span.end.error("Unknown backslash sequence"); + _span.end.error("Unknown backslash sequence"_s); return TOK_ERROR; case 'a': collect += '\a'; break; case 'b': collect += '\b'; break; @@ -117,7 +117,7 @@ namespace sexpr tmp *= 16; if (!_in.get(_span.end)) { - _span.end.error("EOF after \\x in string"); + _span.end.error("EOF after \\x in string"_s); return TOK_ERROR; } char cx = _span.end.ch(); @@ -130,7 +130,7 @@ namespace sexpr tmp += cx - 'a' + 10; else { - _span.end.error("Non-hex char after \\x"); + _span.end.error("Non-hex char after \\x"_s); return TOK_ERROR; } } @@ -143,7 +143,7 @@ namespace sexpr } case '\'': case '\\': - _span.end.error("forbidden character"); + _span.end.error("forbidden character"_s); return TOK_ERROR; default: // this includes integers - they are differentiated in parsing @@ -168,7 +168,7 @@ namespace sexpr } _string = AString(collect); if (!_string.is_print()) - _span.error("String is not entirely printable"); + _span.error("String is not entirely printable"_s); return TOK_TOKEN; } } @@ -178,23 +178,23 @@ namespace sexpr { switch (c) { - case '\a': return {"\\a"}; - case '\b': return {"\\b"}; - case '\e': return {"\\e"}; - case '\f': return {"\\f"}; - //case '\n': return {"\\n"}; - case '\r': return {"\\r"}; - case '\t': return {"\\t"}; - case '\v': return {"\\v"}; - case '\\': return {"\\\\"}; - case '\"': return {"\\\""}; + case '\a': return "\\a"_s; + case '\b': return "\\b"_s; + case '\e': return "\\e"_s; + case '\f': return "\\f"_s; + //case '\n': return "\\n"_s; + case '\r': return "\\r"_s; + case '\t': return "\\t"_s; + case '\v': return "\\v"_s; + case '\\': return "\\\\"_s; + case '\"': return "\\\""_s; default: if (c == '\n') return c; if (' ' <= c && c <= '~') return c; else - return STRNPRINTF(5, "\\x%02x", static_cast<uint8_t>(c)); + return STRNPRINTF(5, "\\x%02x"_fmt, static_cast<uint8_t>(c)); } } AString escape(XString s) @@ -207,22 +207,22 @@ namespace sexpr return AString(m); } - ZString token_name(Lexeme tok) + LString token_name(Lexeme tok) { switch (tok) { case TOK_EOF: - return ZString("EOF"); + return "EOF"_s; case TOK_OPEN: - return ZString("OPEN"); + return "OPEN"_s; case TOK_CLOSE: - return ZString("CLOSE"); + return "CLOSE"_s; case TOK_STRING: - return ZString("STRING"); + return "STRING"_s; case TOK_TOKEN: - return ZString("TOKEN"); + return "TOKEN"_s; default: - return ZString("ERROR"); + return "ERROR"_s; } } } // namespace sexpr diff --git a/src/sexpr/lexer.hpp b/src/sexpr/lexer.hpp index 7bce620..84c9e1d 100644 --- a/src/sexpr/lexer.hpp +++ b/src/sexpr/lexer.hpp @@ -67,7 +67,7 @@ namespace sexpr VString<4> escape(char c); AString escape(XString s); - ZString token_name(Lexeme tok); + LString token_name(Lexeme tok); } // namespace sexpr #endif // TMWA_SEXPR_LEXER_HPP diff --git a/src/sexpr/lexer_test.cpp b/src/sexpr/lexer_test.cpp index ade79af..fbff0d8 100644 --- a/src/sexpr/lexer_test.cpp +++ b/src/sexpr/lexer_test.cpp @@ -40,69 +40,69 @@ io::FD string_pipe(ZString sz) TEST(sexpr, escape) { - EXPECT_EQ(sexpr::escape('\0'), "\\x00"); - EXPECT_EQ(sexpr::escape('\x1f'), "\\x1f"); - EXPECT_EQ(sexpr::escape('\x20'), " "); - EXPECT_EQ(sexpr::escape('\x7e'), "~"); - EXPECT_EQ(sexpr::escape('\x7f'), "\\x7f"); - EXPECT_EQ(sexpr::escape('\x80'), "\\x80"); - EXPECT_EQ(sexpr::escape('\xff'), "\\xff"); - EXPECT_EQ(sexpr::escape('\a'), "\\a"); - EXPECT_EQ(sexpr::escape('\b'), "\\b"); - EXPECT_EQ(sexpr::escape('\e'), "\\e"); - EXPECT_EQ(sexpr::escape('\f'), "\\f"); - //EXPECT_EQ(sexpr::escape('\n'), "\\n"); - EXPECT_EQ(sexpr::escape('\n'), "\n"); - EXPECT_EQ(sexpr::escape('\r'), "\\r"); - EXPECT_EQ(sexpr::escape('\t'), "\\t"); - EXPECT_EQ(sexpr::escape('\v'), "\\v"); - EXPECT_EQ(sexpr::escape('\\'), "\\\\"); - EXPECT_EQ(sexpr::escape('\"'), "\\\""); + EXPECT_EQ(sexpr::escape('\0'), "\\x00"_s); + EXPECT_EQ(sexpr::escape('\x1f'), "\\x1f"_s); + EXPECT_EQ(sexpr::escape('\x20'), " "_s); + EXPECT_EQ(sexpr::escape('\x7e'), "~"_s); + EXPECT_EQ(sexpr::escape('\x7f'), "\\x7f"_s); + EXPECT_EQ(sexpr::escape('\x80'), "\\x80"_s); + EXPECT_EQ(sexpr::escape('\xff'), "\\xff"_s); + EXPECT_EQ(sexpr::escape('\a'), "\\a"_s); + EXPECT_EQ(sexpr::escape('\b'), "\\b"_s); + EXPECT_EQ(sexpr::escape('\e'), "\\e"_s); + EXPECT_EQ(sexpr::escape('\f'), "\\f"_s); + //EXPECT_EQ(sexpr::escape('\n'), "\\n"_s); + EXPECT_EQ(sexpr::escape('\n'), "\n"_s); + EXPECT_EQ(sexpr::escape('\r'), "\\r"_s); + EXPECT_EQ(sexpr::escape('\t'), "\\t"_s); + EXPECT_EQ(sexpr::escape('\v'), "\\v"_s); + EXPECT_EQ(sexpr::escape('\\'), "\\\\"_s); + EXPECT_EQ(sexpr::escape('\"'), "\\\""_s); - EXPECT_EQ(sexpr::escape("\x1f\x20\x7e\x7f\x80\xff\a\b\e\f\r\t\v\\\""), - "\"\\x1f ~\\x7f\\x80\\xff\\a\\b\\e\\f\\r\\t\\v\\\\\\\"\""); + EXPECT_EQ(sexpr::escape("\x1f\x20\x7e\x7f\x80\xff\a\b\e\f\r\t\v\\\""_s), + "\"\\x1f ~\\x7f\\x80\\xff\\a\\b\\e\\f\\r\\t\\v\\\\\\\"\""_s); } TEST(sexpr, lexer) { io::LineSpan span; - sexpr::Lexer lexer("<lexer-test1>", string_pipe(" foo( ) 123\"\" \n")); + sexpr::Lexer lexer("<lexer-test1>"_s, string_pipe(" foo( ) 123\"\" \n"_s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_TOKEN); - EXPECT_EQ(lexer.val_string(), "foo"); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), "foo"_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:2: error: test\n" " foo( ) 123\"\" \n" - " ^~~\n" + " ^~~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_OPEN); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:5: error: test\n" " foo( ) 123\"\" \n" - " ^\n" + " ^\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_CLOSE); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:7: error: test\n" " foo( ) 123\"\" \n" - " ^\n" + " ^\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_TOKEN); - EXPECT_EQ(lexer.val_string(), "123"); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), "123"_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:9: error: test\n" " foo( ) 123\"\" \n" - " ^~~\n" + " ^~~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_STRING); - EXPECT_EQ(lexer.val_string(), ""); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), ""_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:12: error: test\n" " foo( ) 123\"\" \n" - " ^~\n" + " ^~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -112,22 +112,22 @@ TEST(sexpr, lexbad) { { io::LineSpan span; - sexpr::Lexer lexer("<lexer-bad>", string_pipe("(\n")); + sexpr::Lexer lexer("<lexer-bad>"_s, string_pipe("(\n"_s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_OPEN); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } for (ZString bad : { - ZString(")\n"), - ZString("\"\n"), - ZString("'\n"), - ZString("\\\n"), - ZString("\"\\"), - ZString("\"\\z\""), + ZString(")\n"_s), + ZString("\"\n"_s), + ZString("'\n"_s), + ZString("\\\n"_s), + ZString("\"\\"_s), + ZString("\"\\z\""_s), }) { io::LineSpan span; - sexpr::Lexer lexer("<lexer-bad>", string_pipe(bad)); + sexpr::Lexer lexer("<lexer-bad>"_s, string_pipe(bad)); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } } diff --git a/src/sexpr/main.cpp b/src/sexpr/main.cpp deleted file mode 100644 index 18cb8c2..0000000 --- a/src/sexpr/main.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// sexpr/main.cpp - Driver for new magic formatter. -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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/>. -#include <stack> -#include <map> - -#include "../io/cxxstdio.hpp" - -#include "lexer.hpp" -#include "parser.hpp" - -#include "../poison.hpp" - -enum Spacing -{ - LINES, - SIMPLE, - SPACES, - SPACES_1, - SPACES_2, - SPACES_3, - SPACES_4, -}; - -static -void do_spacing(bool& first, Spacing& sp, int depth) -{ - if (first) - { - first = false; - return; - } - switch (sp) - { - case LINES: - PRINTF("\n%*s", (depth - 1) * 4, ""); - return; - case SPACES: - case SIMPLE: - PRINTF(" "); - return; - case SPACES_1: - PRINTF(" "); - sp = LINES; - return; - case SPACES_2: - PRINTF(" "); - sp = SPACES_1; - return; - case SPACES_3: - PRINTF(" "); - sp = SPACES_2; - return; - case SPACES_4: - PRINTF(" "); - sp = SPACES_3; - return; - } -} - -static -void adjust_spacing(Spacing& sp, ZString val) -{ - std::map<ZString, Spacing> spaces = - { - {"BLOCK", LINES}, - {"GUARD", LINES}, - {"DISABLED", LINES}, - {"PROCEDURE", SPACES_2}, - {"SPELL", SPACES_4}, - {"IF", SPACES_1}, - {"set_script_variable", SPACES_2}, - }; - auto it = spaces.find(val); - if (it != spaces.end()) - sp = it->second; -} - -int main() -{ - if (1 == 1) - { - sexpr::Lexer lexer("/dev/stdin"); - sexpr::SExpr sexpr; - while (sexpr::parse(lexer, sexpr)) - { - PRINTF(""); - } - if (lexer.peek() != sexpr::TOK_EOF) - { - lexer.span().error(STRPRINTF("Incomplete: %s: %s\n", - sexpr::token_name(lexer.peek()), lexer.val_string())); - } - return 0; - } - - std::stack<Spacing> spacing; - spacing.push(LINES); - sexpr::Lexer lexer("/dev/stdin"); - bool first = true; - while (sexpr::Lexeme tok = lexer.peek()) - { - switch (tok) - { - case sexpr::TOK_OPEN: - if (spacing.top() == SIMPLE) - spacing.top() = LINES; - do_spacing(first, spacing.top(), spacing.size()); - PRINTF("("); - spacing.push(SIMPLE); - first = true; - break; - case sexpr::TOK_CLOSE: - PRINTF(")"); - spacing.pop(); - first = false; - break; - case sexpr::TOK_STRING: - do_spacing(first, spacing.top(), spacing.size()); - PRINTF("%s", sexpr::escape(lexer.val_string())); - break; - case sexpr::TOK_TOKEN: - do_spacing(first, spacing.top(), spacing.size()); - PRINTF("%s", lexer.val_string()); - adjust_spacing(spacing.top(), lexer.val_string()); - break; - default: - abort(); - } - lexer.adv(); - } - PRINTF("\n"); -} diff --git a/src/sexpr/parser_test.cpp b/src/sexpr/parser_test.cpp index d67d041..0be333b 100644 --- a/src/sexpr/parser_test.cpp +++ b/src/sexpr/parser_test.cpp @@ -42,11 +42,11 @@ TEST(sexpr, parser) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parser-test1>", string_pipe(" foo( ) 123\"\" \n")); + sexpr::Lexer lexer("<parser-test1>"_s, string_pipe(" foo( ) 123\"\" \n"_s)); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::TOKEN); - EXPECT_EQ(s._str, "foo"); + EXPECT_EQ(s._str, "foo"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); @@ -58,7 +58,7 @@ TEST(sexpr, parser) EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::STRING); - EXPECT_EQ(s._str, ""); + EXPECT_EQ(s._str, ""_s); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -67,19 +67,19 @@ TEST(sexpr, parser) TEST(sexpr, parselist) { sexpr::SExpr s; - sexpr::Lexer lexer("<parser-test1>", string_pipe("(foo)(bar)\n")); + sexpr::Lexer lexer("<parser-test1>"_s, string_pipe("(foo)(bar)\n"_s)); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); EXPECT_EQ(s._list.size(), 1); EXPECT_EQ(s._list[0]._type, sexpr::TOKEN); - EXPECT_EQ(s._list[0]._str, "foo"); + EXPECT_EQ(s._list[0]._str, "foo"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); EXPECT_EQ(s._list.size(), 1); EXPECT_EQ(s._list[0]._type, sexpr::TOKEN); - EXPECT_EQ(s._list[0]._str, "bar"); + EXPECT_EQ(s._list[0]._str, "bar"_s); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -87,22 +87,22 @@ TEST(sexpr, parselist) TEST(sexpr, parsebad) { - for (ZString bad : { - ZString("(\n"), - ZString(")\n"), - ZString("\"\n"), - ZString("'\n"), - ZString("\\\n"), - ZString("\"\\"), - ZString("\"\\z\""), - ZString("(()\n"), - ZString("((\n"), - ZString("((\"\n"), + for (LString bad : { + "(\n"_s, + ")\n"_s, + "\"_s\n"_s, + "'\n"_s, + "\\\n"_s, + "\"_s\\"_s, + "\"_s\\z\""_s, + "(()\n"_s, + "((\n"_s, + "((\"\n"_s, }) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parse-bad>", string_pipe(bad)); + sexpr::Lexer lexer("<parse-bad>"_s, string_pipe(bad)); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } diff --git a/src/spell-convert/ast.cpp b/src/spell-convert/ast.cpp deleted file mode 100644 index e9ec19c..0000000 --- a/src/spell-convert/ast.cpp +++ /dev/null @@ -1,280 +0,0 @@ -#include "ast.hpp" -// ast.cpp - Hacky converter between magic formats. -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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/>. - -#include "../io/cxxstdio.hpp" - -#include "../poison.hpp" - -void Constant::dump() -{ - PRINTF("(CONST %s\n", name); - body->show(); - PRINTF(")\n"); -} -void Teleport::dump() -{ - PRINTF("(TELEPORT-ANCHOR %s\n", name); - ident->show(); - body->show(); - PRINTF(")\n"); -} -void Procedure::dump() -{ - PRINTF("(PROCEDURE %s\n", name); - PRINTF("("); - for (RString& a : *args) - PRINTF(" %s ", a); - PRINTF(")\n"); - for (Effect *f : *body) - { - f->print(); - } - PRINTF(")\n"); -} -void Spell::dump() -{ - PRINTF("(SPELL \n"); - PRINTF("("); - for (RString fl : *flags) - PRINTF(" %s ", fl); - PRINTF(")"); - PRINTF("%s", name); - ident->show(); - PRINTF("( %s %s )", arg->vartype, arg->varname); - for (Assignment *a : *body->lets) - { - PRINTF("(LET %s ", a->name); - a->body->show(); - PRINTF(")\n"); - } - for (SpellBod *b : *body->body) - { - b->say(); - } - PRINTF(")\n"); -} -void Assignment::dump() -{ - PRINTF("(SET %s\n", name); - body->show(); - PRINTF(")\n"); -} - -void EffectList::print() -{ - PRINTF("(BLOCK\n"); - for (Effect *ef : *body) - ef->print(); - PRINTF(")\n"); -} -void SimpleEffect::print() -{ - PRINTF("( %s )", text); -} -void ScriptEffect::print() -{ - PRINTF("(SCRIPT %s )", text); -} -void Assignment::print() -{ - PRINTF("(SET %s\n", name); - body->show(); - PRINTF(")\n"); -} -void ForeachEffect::print() -{ - PRINTF("(FOREACH %s %s ", selection, var); - expr->show(); - PRINTF("\n"); - effect->print(); - PRINTF(")"); -} -void ForEffect::print() -{ - PRINTF("(FOR %s", var); - low->show(); - high->show(); - effect->print(); - PRINTF(")"); -} -void IfEffect::print() -{ - PRINTF("(IF "); - cond->show(); - if_true->print(); - if (if_false_maybe) - if_false_maybe->print(); - PRINTF(")"); -} -void ExplicitCallEffect::print() -{ - PRINTF("(CALL %s ", userfunc); - for (Expression *x : *args) - x->show(); - PRINTF(")"); -} -void SleepEffect::print() -{ - PRINTF("(WAIT "); - time_->show(); - PRINTF(")"); -} -void CallExpr::print() -{ - PRINTF("(%s ", func); - for (Expression *x : *args) - x->show(); - PRINTF(")"); -} - -void SimpleExpr::show() -{ - PRINTF(" %s ", content); -} -void BinExpr::show() -{ - PRINTF("(%s ", op); - left->show(); - right->show(); - PRINTF(")"); -} -void CallExpr::show() -{ - PRINTF("(%s ", func); - for (Expression *x : *args) - x->show(); - PRINTF(")"); -} -void AreaLoc::show() -{ - PRINTF("(@ "); - loc->map->show(); - loc->x->show(); - loc->y->show(); - PRINTF(")"); -} -void AreaRect::show() -{ - PRINTF("(@+ "); - AreaLoc{loc}.show(); - width->show(); - height->show(); - PRINTF(")"); -} -void AreaBar::show() -{ - PRINTF("(TOWARD "); - AreaLoc{loc}.show(); - dir->show(); - width->show(); - depth->show(); - PRINTF(")"); -} - -void SpellBodGuarded::say() -{ - PRINTF("(=> "); - guard->declare(); - body->say(); - PRINTF(")"); -} -void SpellBodList::say() -{ - PRINTF("(|\n"); - for (SpellBod *b : *body) - b->say(); - PRINTF(")"); -} -void SpellBodEffect::say() -{ - PRINTF("(EFFECT\n"); - for (Effect *f : *body) - f->print(); - if (maybe_trigger) - { - PRINTF("(ATTRIGGER\n"); - for (Effect *f : *maybe_trigger) - f->print(); - PRINTF(")"); - } - if (maybe_end) - { - PRINTF("(ATEND\n"); - for (Effect *f : *maybe_end) - f->print(); - PRINTF(")"); - } - PRINTF(")"); -} - -void SpellGuardOr::declare() -{ - PRINTF("(OR\n"); - for (SpellGuard *sg : *any) - sg->declare(); - PRINTF(")"); -} -void SpellGuardList::declare() -{ - PRINTF("(GUARD\n"); - for (SpellGuard *sg : *all) - sg->declare(); - PRINTF(")"); -} -void SpellGuardRequire::declare() -{ - PRINTF("(REQUIRE "); - expr->show(); - PRINTF(")"); -} -static -void do_item(Item *itm) -{ - if (itm->count) - PRINTF("( %s %s )", itm->count, itm->item); - else - PRINTF(" %s ", itm->item); -} -void SpellGuardCatalysts::declare() -{ - PRINTF("(CATALYSTS "); - for (Item *itm : *items) - do_item(itm); - PRINTF(")"); -} -void SpellGuardComponents::declare() -{ - PRINTF("(COMPONENTS "); - for (Item *itm : *items) - do_item(itm); - PRINTF(")"); -} -void SpellGuardMana::declare() -{ - PRINTF("(MANA "); - sp->show(); - PRINTF(")"); -} -void SpellGuardCasttime::declare() -{ - PRINTF("(CASTTIME "); - time_->show(); - PRINTF(")"); -} diff --git a/src/spell-convert/ast.hpp b/src/spell-convert/ast.hpp deleted file mode 100644 index 3d2f282..0000000 --- a/src/spell-convert/ast.hpp +++ /dev/null @@ -1,465 +0,0 @@ -#ifndef TMWA_SPELL_CONVERT_AST_HPP -#define TMWA_SPELL_CONVERT_AST_HPP -// ast.hpp - Hacky converter between magic formats. -// -// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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/>. - -# include "../sanity.hpp" - -# include <deque> -# include <vector> - -# include "../strings/rstring.hpp" - -# if __GNUC__ == 4 && __GNUC_MINOR__ == 6 -# define override -# endif - -// We just leak -# pragma GCC diagnostic ignored "-Wnon-virtual-dtor" - -struct TopLevel; -struct Constant; -struct Teleport; -struct Procedure; -struct Spell; -struct SpellArg; -struct Effect; -struct EffectList; -struct SimpleEffect; -struct ScriptEffect; -struct Assignment; -struct ForeachEffect; -struct ForEffect; -struct IfEffect; -struct ExplicitCallEffect; -struct SleepEffect; -struct SpellDef; -struct SpellBod; -struct SpellBodGuarded; -struct SpellBodList; -struct SpellBodEffect; -struct SpellGuard; -struct SpellGuardOr; -struct SpellGuardList; -struct SpellGuardRequire; -struct SpellGuardCatalysts; -struct SpellGuardComponents; -struct SpellGuardMana; -struct SpellGuardCasttime; -struct Item; -struct Expression; -struct SimpleExpr; -struct BinExpr; -struct CallExpr; -struct Location; -struct AreaLoc; -struct AreaRect; -struct AreaBar; - - -struct TopLevel -{ - virtual void dump() = 0; -}; - -struct Constant : TopLevel -{ - RString name; - Expression *body; - - Constant(RString n, Expression *b) - : name(n), body(b) - {} - - virtual void dump() override; -}; - -struct Teleport : TopLevel -{ - RString name; - Expression *ident; - Expression *body; - - Teleport(RString n, Expression *i, Expression *b) - : name(n), ident(i), body(b) - {} - - virtual void dump() override; -}; - -struct Procedure : TopLevel -{ - RString name; - std::vector<RString> *args; - std::deque<Effect *> *body; - - Procedure(RString n, std::vector<RString> *a, std::deque<Effect *> *b) - : name(n), args(a), body(b) - {} - - virtual void dump() override; -}; - -struct Spell : TopLevel -{ - std::vector<RString> *flags; - RString name; - SpellArg *arg; - Expression *ident; - SpellDef *body; - - Spell(std::vector<RString> *f, RString n, SpellArg *a, Expression *i, SpellDef *b) - : flags(f), name(n), arg(a), ident(i), body(b) - {} - - virtual void dump() override; -}; - -struct SpellArg -{ - RString varname; - RString vartype; - - SpellArg() : varname(), vartype() {} - SpellArg(RString n, RString t) : varname(n), vartype(t) {} -}; - -struct Effect -{ - virtual void print() = 0; -}; - -struct EffectList : Effect -{ - std::deque<Effect *> *body; - - EffectList(std::deque<Effect *> *b) - : body(b) - {} - - virtual void print() override; -}; -struct SimpleEffect : Effect -{ - RString text; - - SimpleEffect(RString t) : text(t) {} - - virtual void print() override; -}; -struct ScriptEffect : Effect -{ - RString text; - - ScriptEffect(RString t) : text(t) {} - - virtual void print() override; -}; - -struct Assignment : TopLevel, Effect -{ - RString name; - Expression *body; - - Assignment(RString n, Expression *b) - : name(n), body(b) - {} - - // toplevel - virtual void dump() override; - // effect - virtual void print() override; -}; - -struct ForeachEffect : Effect -{ - RString selection; - RString var; - Expression *expr; - Effect *effect; - - ForeachEffect(RString s, RString v, Expression *x, Effect *f) - : selection(s), var(v), expr(x), effect(f) - {} - - virtual void print() override; -}; - -struct ForEffect : Effect -{ - RString var; - Expression *low; - Expression *high; - Effect *effect; - - ForEffect(RString v, Expression *l, Expression *h, Effect *f) - : var(v), low(l), high(h), effect(f) - {} - - virtual void print() override; -}; - -struct IfEffect : Effect -{ - Expression *cond; - Effect *if_true; - Effect *if_false_maybe; - - IfEffect(Expression *c, Effect *t, Effect *f=nullptr) - : cond(c), if_true(t), if_false_maybe(f) - {} - - virtual void print() override; -}; - -struct ExplicitCallEffect : Effect -{ - RString userfunc; - std::vector<Expression *> *args; - - ExplicitCallEffect(RString f, std::vector<Expression *> *a) - : userfunc(f), args(a) - {} - - virtual void print() override; -}; - -struct SleepEffect : Effect -{ - Expression *time_; - - SleepEffect(Expression *t) - : time_(t) - {} - - virtual void print() override; -}; - -struct SpellDef -{ - std::vector<Assignment *> *lets; - std::vector<SpellBod *> *body; -}; - -struct SpellBod -{ - virtual void say() = 0; -}; - -struct SpellBodGuarded : SpellBod -{ - SpellGuard *guard; - SpellBod *body; - - SpellBodGuarded(SpellGuard *g, SpellBod *b) - : guard(g), body(b) - {} - - virtual void say() override; -}; - -struct SpellBodList : SpellBod -{ - std::vector<SpellBod *> *body; - - SpellBodList(std::vector<SpellBod *> *b) - : body(b) - {} - - virtual void say() override; -}; - -struct SpellBodEffect : SpellBod -{ - std::deque<Effect *> *body; - std::deque<Effect *> *maybe_trigger; - std::deque<Effect *> *maybe_end; - - SpellBodEffect(std::deque<Effect *> *b, std::deque<Effect *> *t, std::deque<Effect *> *e) - : body(b), maybe_trigger(t), maybe_end(e) - {} - - virtual void say() override; -}; - -struct SpellGuard -{ - virtual void declare() = 0; -}; - -struct SpellGuardOr : SpellGuard -{ - std::vector<SpellGuard *> *any; - - SpellGuardOr(std::vector<SpellGuard *> *a) : any(a) {} - SpellGuardOr(SpellGuard *left, SpellGuard *right) - : any(new std::vector<SpellGuard *>({left, right})) - {} - - virtual void declare() override; -}; -struct SpellGuardList : SpellGuard -{ - std::vector<SpellGuard *> *all; - - SpellGuardList(std::vector<SpellGuard *> *a) : all(a) {} - - virtual void declare() override; -}; -struct SpellGuardRequire : SpellGuard -{ - Expression *expr; - - SpellGuardRequire(Expression *x) : expr(x) {} - - virtual void declare() override; -}; -struct SpellGuardCatalysts : SpellGuard -{ - std::vector<Item *> *items; - - SpellGuardCatalysts(std::vector<Item *> *i) : items(i) {} - - virtual void declare() override; -}; -struct SpellGuardComponents : SpellGuard -{ - std::vector<Item *> *items; - - SpellGuardComponents(std::vector<Item *> *i) : items(i) {} - - virtual void declare() override; -}; -struct SpellGuardMana : SpellGuard -{ - Expression *sp; - - SpellGuardMana(Expression *x) : sp(x) {} - - virtual void declare() override; -}; -struct SpellGuardCasttime : SpellGuard -{ - Expression *time_; - - SpellGuardCasttime(Expression *x) : time_(x) {} - - virtual void declare() override; -}; - -struct Item -{ - RString count; - RString item; - - Item(RString c, RString i) : count(c), item(i) {} -}; - -struct Expression -{ - virtual void show() = 0; -}; - -struct SimpleExpr : Expression -{ - RString content; - - SimpleExpr(RString c) : content(c) {} - - virtual void show() override; -}; - -struct BinExpr : Expression -{ - Expression *left; - RString op; - Expression *right; - - BinExpr(Expression *l, RString o, Expression *r) - : left(l), op(o), right(r) - {} - - virtual void show() override; -}; - -struct CallExpr : Expression, Effect -{ - RString func; - std::vector<Expression *> *args; - - CallExpr(RString f, std::vector<Expression *> *a) - : func(f), args(a) - {} - - // expression - virtual void show() override; - // effect - virtual void print() override; -}; - -struct Location -{ - Expression *map; - Expression *x; - Expression *y; -}; - -struct AreaLoc : Expression -{ - Location *loc; - - AreaLoc(Location *l) - : loc(l) - {} - - virtual void show() override; -}; - -struct AreaRect : Expression -{ - Location *loc; - Expression *width; - Expression *height; - - AreaRect(Location *l, Expression *w, Expression *h) - : loc(l), width(w), height(h) - {} - - virtual void show() override; -}; - -struct AreaBar : Expression -{ - Location *loc; - Expression *dir; - Expression *width; - Expression *depth; - - AreaBar(Location *l, Expression *a, Expression *w, Expression *d) - : loc(l), dir(a), width(w), depth(d) - {} - - virtual void show() override; -}; - -# ifdef override -# undef override -# endif - -#endif // TMWA_SPELL_CONVERT_AST_HPP diff --git a/src/spell-convert/lexer.cpp b/src/spell-convert/lexer.cpp deleted file mode 100644 index e06817f..0000000 --- a/src/spell-convert/lexer.cpp +++ /dev/null @@ -1,2331 +0,0 @@ -#line 2 "src/spell-convert/lexer.cpp" - -#line 4 "src/spell-convert/lexer.cpp" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define yy_create_buffer spell_converter_create_buffer -#define yy_delete_buffer spell_converter_delete_buffer -#define yy_flex_debug spell_converter_flex_debug -#define yy_init_buffer spell_converter_init_buffer -#define yy_flush_buffer spell_converter_flush_buffer -#define yy_load_buffer_state spell_converter_load_buffer_state -#define yy_switch_to_buffer spell_converter_switch_to_buffer -#define yyin spell_converterin -#define yyleng spell_converterleng -#define yylex spell_converterlex -#define yylineno spell_converterlineno -#define yyout spell_converterout -#define yyrestart spell_converterrestart -#define yytext spell_convertertext -#define yywrap spell_converterwrap -#define yyalloc spell_converteralloc -#define yyrealloc spell_converterrealloc -#define yyfree spell_converterfree - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include <inttypes.h> -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE spell_converterrestart(spell_converterin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int spell_converterleng; - -extern FILE *spell_converterin, *spell_converterout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up spell_convertertext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up spell_convertertext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via spell_converterrestart()), so that the user can continue scanning by - * just pointing spell_converterin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when spell_convertertext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int spell_converterleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow spell_converterwrap()'s to do buffer switches - * instead of setting up a fresh spell_converterin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void spell_converterrestart (FILE *input_file ); -void spell_converter_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE spell_converter_create_buffer (FILE *file,int size ); -void spell_converter_delete_buffer (YY_BUFFER_STATE b ); -void spell_converter_flush_buffer (YY_BUFFER_STATE b ); -void spell_converterpush_buffer_state (YY_BUFFER_STATE new_buffer ); -void spell_converterpop_buffer_state (void ); - -static void spell_converterensure_buffer_stack (void ); -static void spell_converter_load_buffer_state (void ); -static void spell_converter_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER spell_converter_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE spell_converter_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE spell_converter_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE spell_converter_scan_bytes (yyconst char *bytes,int len ); - -void *spell_converteralloc (yy_size_t ); -void *spell_converterrealloc (void *,yy_size_t ); -void spell_converterfree (void * ); - -#define yy_new_buffer spell_converter_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - spell_converterensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - spell_converter_create_buffer(spell_converterin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - spell_converterensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - spell_converter_create_buffer(spell_converterin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define spell_converterwrap(n) 1 -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -FILE *spell_converterin = (FILE *) 0, *spell_converterout = (FILE *) 0; - -typedef int yy_state_type; - -extern int spell_converterlineno; - -int spell_converterlineno = 1; - -extern char *spell_convertertext; -#define yytext_ptr spell_convertertext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up spell_convertertext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - spell_converterleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 86 -#define YY_END_OF_BUFFER 87 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[240] = - { 0, - 0, 0, 87, 85, 84, 84, 85, 85, 85, 23, - 33, 17, 18, 21, 19, 28, 20, 35, 22, 79, - 79, 27, 26, 14, 9, 13, 29, 81, 81, 81, - 81, 7, 81, 81, 81, 81, 81, 5, 81, 81, - 81, 1, 81, 3, 31, 32, 34, 85, 30, 12, - 0, 78, 0, 0, 82, 24, 79, 0, 0, 36, - 16, 11, 10, 51, 15, 37, 81, 81, 81, 81, - 81, 81, 75, 81, 81, 81, 81, 70, 49, 81, - 81, 81, 81, 6, 81, 81, 4, 40, 65, 81, - 81, 8, 81, 81, 81, 81, 2, 81, 81, 81, - - 41, 81, 0, 0, 77, 25, 0, 78, 0, 0, - 83, 80, 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 50, 81, 74, 48, 81, 81, 67, - 81, 66, 81, 81, 81, 81, 81, 81, 81, 81, - 81, 81, 81, 0, 0, 77, 81, 81, 81, 81, - 39, 81, 81, 81, 81, 81, 72, 81, 81, 81, - 56, 81, 81, 81, 81, 58, 81, 81, 81, 81, - 71, 81, 76, 59, 62, 81, 60, 81, 81, 81, - 64, 81, 81, 81, 45, 81, 81, 81, 81, 47, - 81, 81, 81, 81, 81, 81, 81, 81, 61, 68, - - 81, 81, 81, 81, 44, 52, 69, 81, 81, 81, - 81, 81, 81, 73, 81, 81, 53, 81, 42, 81, - 57, 81, 81, 46, 81, 81, 63, 54, 81, 38, - 81, 55, 81, 81, 81, 81, 81, 43, 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 5, 6, 1, 7, 8, 1, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, - 22, 23, 1, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 34, 46, 34, 47, 34, - 48, 49, 50, 51, 52, 1, 53, 53, 53, 53, - - 53, 53, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 54, - 34, 34, 55, 56, 57, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[58] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, - 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, - 1, 2, 3, 2, 1, 1, 1 - } ; - -static yyconst flex_int16_t yy_base[248] = - { 0, - 0, 0, 289, 290, 290, 290, 266, 53, 284, 290, - 278, 290, 290, 290, 290, 290, 42, 290, 269, 44, - 46, 290, 290, 44, 46, 48, 290, 46, 242, 48, - 244, 44, 243, 0, 45, 47, 52, 49, 239, 52, - 251, 64, 80, 254, 290, 290, 290, 35, 222, 290, - 76, 290, 98, 274, 290, 290, 89, 273, 0, 290, - 290, 290, 290, 290, 290, 290, 0, 236, 56, 245, - 77, 77, 0, 243, 229, 83, 229, 0, 0, 226, - 242, 230, 241, 0, 228, 238, 0, 0, 0, 225, - 222, 0, 226, 228, 231, 217, 0, 216, 221, 227, - - 209, 221, 67, 93, 290, 290, 112, 113, 123, 250, - 290, 0, 210, 213, 208, 224, 212, 203, 221, 205, - 201, 214, 213, 0, 208, 211, 0, 214, 213, 0, - 200, 0, 209, 190, 205, 193, 196, 198, 199, 200, - 190, 202, 182, 73, 120, 80, 181, 196, 190, 187, - 0, 177, 184, 180, 174, 190, 0, 172, 190, 178, - 0, 188, 183, 178, 172, 0, 173, 170, 178, 166, - 0, 163, 0, 0, 0, 173, 0, 170, 155, 163, - 0, 156, 152, 171, 0, 145, 147, 132, 129, 0, - 140, 126, 129, 139, 135, 128, 121, 134, 0, 0, - - 128, 126, 113, 128, 0, 0, 0, 114, 112, 125, - 124, 108, 113, 0, 122, 106, 0, 102, 0, 103, - 0, 101, 99, 0, 112, 126, 0, 0, 96, 0, - 113, 0, 98, 108, 102, 94, 90, 0, 290, 177, - 180, 182, 185, 188, 191, 128, 194 - } ; - -static yyconst flex_int16_t yy_def[248] = - { 0, - 239, 1, 239, 239, 239, 239, 239, 240, 241, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 239, 239, 239, 243, 239, 239, - 240, 239, 244, 241, 239, 239, 239, 245, 246, 239, - 239, 239, 239, 239, 239, 239, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - - 242, 242, 243, 247, 239, 239, 240, 240, 244, 245, - 239, 246, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 243, 247, 243, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, - 242, 242, 242, 242, 242, 242, 242, 242, 0, 239, - 239, 239, 239, 239, 239, 239, 239 - } ; - -static yyconst flex_int16_t yy_nxt[348] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - 34, 34, 35, 34, 34, 36, 37, 38, 39, 40, - 34, 41, 42, 43, 34, 44, 34, 45, 4, 46, - 47, 4, 34, 34, 48, 49, 4, 52, 57, 57, - 57, 57, 57, 57, 60, 61, 62, 63, 64, 65, - 66, 68, 71, 74, 78, 80, 82, 84, 89, 75, - 52, 76, 79, 104, 114, 81, 72, 85, 86, 69, - 83, 105, 92, 90, 87, 103, 93, 59, 94, 115, - - 51, 53, 108, 95, 98, 57, 57, 96, 99, 97, - 124, 100, 117, 120, 121, 104, 52, 52, 101, 118, - 119, 104, 103, 105, 53, 51, 125, 108, 104, 105, - 112, 238, 237, 236, 235, 234, 105, 233, 232, 231, - 230, 145, 229, 228, 227, 226, 109, 225, 224, 146, - 223, 222, 221, 220, 219, 218, 217, 216, 215, 214, - 53, 53, 213, 212, 211, 210, 209, 208, 145, 207, - 206, 109, 205, 204, 203, 202, 146, 51, 51, 51, - 54, 54, 54, 67, 67, 103, 103, 103, 107, 107, - 107, 110, 110, 110, 144, 144, 144, 201, 200, 199, - - 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, - 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, - 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, - 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, - 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, - 148, 147, 111, 143, 142, 141, 140, 139, 138, 137, - 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, - 126, 123, 122, 116, 113, 111, 55, 106, 102, 91, - 88, 77, 73, 70, 58, 56, 55, 50, 239, 3, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239 - } ; - -static yyconst flex_int16_t yy_chk[348] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 8, 17, 17, - 20, 20, 21, 21, 24, 24, 24, 25, 25, 26, - 26, 28, 30, 32, 35, 36, 37, 38, 40, 32, - 51, 32, 35, 48, 69, 36, 30, 38, 38, 28, - 37, 48, 42, 40, 38, 104, 42, 20, 42, 69, - - 53, 8, 53, 42, 43, 57, 57, 42, 43, 42, - 76, 43, 71, 72, 72, 103, 107, 108, 43, 71, - 71, 144, 145, 103, 51, 109, 76, 109, 146, 144, - 246, 237, 236, 235, 234, 233, 146, 231, 229, 226, - 225, 104, 223, 222, 220, 218, 53, 216, 215, 104, - 213, 212, 211, 210, 209, 208, 204, 203, 202, 201, - 107, 108, 198, 197, 196, 195, 194, 193, 145, 192, - 191, 109, 189, 188, 187, 186, 145, 240, 240, 240, - 241, 241, 241, 242, 242, 243, 243, 243, 244, 244, - 244, 245, 245, 245, 247, 247, 247, 184, 183, 182, - - 180, 179, 178, 176, 172, 170, 169, 168, 167, 165, - 164, 163, 162, 160, 159, 158, 156, 155, 154, 153, - 152, 150, 149, 148, 147, 143, 142, 141, 140, 139, - 138, 137, 136, 135, 134, 133, 131, 129, 128, 126, - 125, 123, 122, 121, 120, 119, 118, 117, 116, 115, - 114, 113, 110, 102, 101, 100, 99, 98, 96, 95, - 94, 93, 91, 90, 86, 85, 83, 82, 81, 80, - 77, 75, 74, 70, 68, 58, 54, 49, 44, 41, - 39, 33, 31, 29, 19, 11, 9, 7, 3, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239, 239, 239, 239, - 239, 239, 239, 239, 239, 239, 239 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int spell_converter_flex_debug; -int spell_converter_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *spell_convertertext; -#line 1 "../src/spell-convert/lexer.lpp" -#line 2 "../src/spell-convert/lexer.lpp" -/* vim: set ft=lex: */ -//#include "lexer.hpp" - -#include "../strings/rstring.hpp" -#include "../strings/zstring.hpp" - -#include "../io/cxxstdio.hpp" - -#include "../sexpr/lexer.hpp" - -#include "parser.hpp" - -#define yylval spell_converterlval - -RString *str(const char *s) -{ - return new RString(ZString(strings::really_construct_from_a_pointer, s, nullptr)); -} -#define YY_NO_INPUT 1 -#line 657 "src/spell-convert/lexer.cpp" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include <unistd.h> -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int spell_converterlex_destroy (void ); - -int spell_converterget_debug (void ); - -void spell_converterset_debug (int debug_flag ); - -YY_EXTRA_TYPE spell_converterget_extra (void ); - -void spell_converterset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *spell_converterget_in (void ); - -void spell_converterset_in (FILE * in_str ); - -FILE *spell_converterget_out (void ); - -void spell_converterset_out (FILE * out_str ); - -int spell_converterget_leng (void ); - -char *spell_converterget_text (void ); - -int spell_converterget_lineno (void ); - -void spell_converterset_lineno (int line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int spell_converterwrap (void ); -#else -extern int spell_converterwrap (void ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( spell_convertertext, spell_converterleng, 1, spell_converterout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( spell_converterin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( spell_converterin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, spell_converterin))==0 && ferror(spell_converterin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(spell_converterin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int spell_converterlex (void); - -#define YY_DECL int spell_converterlex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after spell_convertertext and spell_converterleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 27 "../src/spell-convert/lexer.lpp" - - -#line 845 "src/spell-convert/lexer.cpp" - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! spell_converterin ) - spell_converterin = stdin; - - if ( ! spell_converterout ) - spell_converterout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - spell_converterensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - spell_converter_create_buffer(spell_converterin,YY_BUF_SIZE ); - } - - spell_converter_load_buffer_state( ); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of spell_convertertext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 290 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 29 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 30 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 31 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 32 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 33 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 34 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 35 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 36 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return DIR; } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 37 "../src/spell-convert/lexer.lpp" -{ return '='; } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 38 "../src/spell-convert/lexer.lpp" -{ return EQ; } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 39 "../src/spell-convert/lexer.lpp" -{ return NEQ; } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 40 "../src/spell-convert/lexer.lpp" -{ return NEQ; } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 41 "../src/spell-convert/lexer.lpp" -{ return '>'; } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 42 "../src/spell-convert/lexer.lpp" -{ return '<'; } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 43 "../src/spell-convert/lexer.lpp" -{ return GTE; } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 44 "../src/spell-convert/lexer.lpp" -{ return LTE; } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 45 "../src/spell-convert/lexer.lpp" -{ return '('; } - YY_BREAK -case 18: -YY_RULE_SETUP -#line 46 "../src/spell-convert/lexer.lpp" -{ return ')'; } - YY_BREAK -case 19: -YY_RULE_SETUP -#line 47 "../src/spell-convert/lexer.lpp" -{ return '+'; } - YY_BREAK -case 20: -YY_RULE_SETUP -#line 48 "../src/spell-convert/lexer.lpp" -{ return '-'; } - YY_BREAK -case 21: -YY_RULE_SETUP -#line 49 "../src/spell-convert/lexer.lpp" -{ return '*'; } - YY_BREAK -case 22: -YY_RULE_SETUP -#line 50 "../src/spell-convert/lexer.lpp" -{ return '/'; } - YY_BREAK -case 23: -YY_RULE_SETUP -#line 51 "../src/spell-convert/lexer.lpp" -{ return '%'; } - YY_BREAK -case 24: -YY_RULE_SETUP -#line 52 "../src/spell-convert/lexer.lpp" -{ return ANDAND; } - YY_BREAK -case 25: -YY_RULE_SETUP -#line 53 "../src/spell-convert/lexer.lpp" -{ return OROR; } - YY_BREAK -case 26: -YY_RULE_SETUP -#line 54 "../src/spell-convert/lexer.lpp" -{ return ';'; } - YY_BREAK -case 27: -YY_RULE_SETUP -#line 55 "../src/spell-convert/lexer.lpp" -{ return ':'; } - YY_BREAK -case 28: -YY_RULE_SETUP -#line 56 "../src/spell-convert/lexer.lpp" -{ return ','; } - YY_BREAK -case 29: -YY_RULE_SETUP -#line 57 "../src/spell-convert/lexer.lpp" -{ return '@'; } - YY_BREAK -case 30: -YY_RULE_SETUP -#line 58 "../src/spell-convert/lexer.lpp" -{ return '|'; } - YY_BREAK -case 31: -YY_RULE_SETUP -#line 59 "../src/spell-convert/lexer.lpp" -{ return '['; } - YY_BREAK -case 32: -YY_RULE_SETUP -#line 60 "../src/spell-convert/lexer.lpp" -{ return ']'; } - YY_BREAK -case 33: -YY_RULE_SETUP -#line 61 "../src/spell-convert/lexer.lpp" -{ return '&'; } - YY_BREAK -case 34: -YY_RULE_SETUP -#line 62 "../src/spell-convert/lexer.lpp" -{ return '^'; } - YY_BREAK -case 35: -YY_RULE_SETUP -#line 63 "../src/spell-convert/lexer.lpp" -{ return '.'; } - YY_BREAK -case 36: -YY_RULE_SETUP -#line 64 "../src/spell-convert/lexer.lpp" -{ return SHL; } - YY_BREAK -case 37: -YY_RULE_SETUP -#line 65 "../src/spell-convert/lexer.lpp" -{ return SHR; } - YY_BREAK -case 38: -YY_RULE_SETUP -#line 66 "../src/spell-convert/lexer.lpp" -{ return PROCEDURE; } - YY_BREAK -case 39: -YY_RULE_SETUP -#line 67 "../src/spell-convert/lexer.lpp" -{ return CALL; } - YY_BREAK -case 40: -YY_RULE_SETUP -#line 68 "../src/spell-convert/lexer.lpp" -{ return OR; } - YY_BREAK -case 41: -YY_RULE_SETUP -#line 69 "../src/spell-convert/lexer.lpp" -{ return TO; } - YY_BREAK -case 42: -YY_RULE_SETUP -#line 70 "../src/spell-convert/lexer.lpp" -{ return TOWARDS; } - YY_BREAK -case 43: -YY_RULE_SETUP -#line 71 "../src/spell-convert/lexer.lpp" -{ return TELEPORT_ANCHOR; } - YY_BREAK -case 44: -YY_RULE_SETUP -#line 72 "../src/spell-convert/lexer.lpp" -{ return SILENT; } - YY_BREAK -case 45: -YY_RULE_SETUP -#line 73 "../src/spell-convert/lexer.lpp" -{ return LOCAL; } - YY_BREAK -case 46: -YY_RULE_SETUP -#line 74 "../src/spell-convert/lexer.lpp" -{ return NONMAGIC; } - YY_BREAK -case 47: -YY_RULE_SETUP -#line 75 "../src/spell-convert/lexer.lpp" -{ return SPELL; } - YY_BREAK -case 48: -YY_RULE_SETUP -#line 76 "../src/spell-convert/lexer.lpp" -{ return LET; } - YY_BREAK -case 49: -YY_RULE_SETUP -#line 77 "../src/spell-convert/lexer.lpp" -{ return IN; } - YY_BREAK -case 50: -YY_RULE_SETUP -#line 78 "../src/spell-convert/lexer.lpp" -{ return END; } - YY_BREAK -case 51: -YY_RULE_SETUP -#line 79 "../src/spell-convert/lexer.lpp" -{ return DARROW; } - YY_BREAK -case 52: -YY_RULE_SETUP -#line 80 "../src/spell-convert/lexer.lpp" -{ return STRING_TY; } - YY_BREAK -case 53: -YY_RULE_SETUP -#line 81 "../src/spell-convert/lexer.lpp" -{ return REQUIRE; } - YY_BREAK -case 54: -YY_RULE_SETUP -#line 82 "../src/spell-convert/lexer.lpp" -{ return CATALYSTS; } - YY_BREAK -case 55: -YY_RULE_SETUP -#line 83 "../src/spell-convert/lexer.lpp" -{ return COMPONENTS; } - YY_BREAK -case 56: -YY_RULE_SETUP -#line 84 "../src/spell-convert/lexer.lpp" -{ return MANA; } - YY_BREAK -case 57: -YY_RULE_SETUP -#line 85 "../src/spell-convert/lexer.lpp" -{ return CASTTIME; } - YY_BREAK -case 58: -YY_RULE_SETUP -#line 86 "../src/spell-convert/lexer.lpp" -{ return SKIP; } - YY_BREAK -case 59: -YY_RULE_SETUP -#line 87 "../src/spell-convert/lexer.lpp" -{ return ABORT; } - YY_BREAK -case 60: -YY_RULE_SETUP -#line 88 "../src/spell-convert/lexer.lpp" -{ return BREAK; } - YY_BREAK -case 61: -YY_RULE_SETUP -#line 89 "../src/spell-convert/lexer.lpp" -{ return EFFECT_; } - YY_BREAK -case 62: -YY_RULE_SETUP -#line 90 "../src/spell-convert/lexer.lpp" -{ return ATEND; } - YY_BREAK -case 63: -YY_RULE_SETUP -#line 91 "../src/spell-convert/lexer.lpp" -{ return ATTRIGGER; } - YY_BREAK -case 64: -YY_RULE_SETUP -#line 92 "../src/spell-convert/lexer.lpp" -{ return CONST; } - YY_BREAK -case 65: -YY_RULE_SETUP -#line 93 "../src/spell-convert/lexer.lpp" -{ return PC_F; } - YY_BREAK -case 66: -YY_RULE_SETUP -#line 94 "../src/spell-convert/lexer.lpp" -{ return NPC_F; } - YY_BREAK -case 67: -YY_RULE_SETUP -#line 95 "../src/spell-convert/lexer.lpp" -{ return MOB_F; } - YY_BREAK -case 68: -YY_RULE_SETUP -#line 96 "../src/spell-convert/lexer.lpp" -{ return ENTITY_F; } - YY_BREAK -case 69: -YY_RULE_SETUP -#line 97 "../src/spell-convert/lexer.lpp" -{ return TARGET_F; } - YY_BREAK -case 70: -YY_RULE_SETUP -#line 98 "../src/spell-convert/lexer.lpp" -{ return IF; } - YY_BREAK -case 71: -YY_RULE_SETUP -#line 99 "../src/spell-convert/lexer.lpp" -{ return THEN; } - YY_BREAK -case 72: -YY_RULE_SETUP -#line 100 "../src/spell-convert/lexer.lpp" -{ return ELSE; } - YY_BREAK -case 73: -YY_RULE_SETUP -#line 101 "../src/spell-convert/lexer.lpp" -{ return FOREACH; } - YY_BREAK -case 74: -YY_RULE_SETUP -#line 102 "../src/spell-convert/lexer.lpp" -{ return FOR; } - YY_BREAK -case 75: -YY_RULE_SETUP -#line 103 "../src/spell-convert/lexer.lpp" -{ return DO; } - YY_BREAK -case 76: -YY_RULE_SETUP -#line 104 "../src/spell-convert/lexer.lpp" -{ return SLEEP; } - YY_BREAK -case 77: -/* rule 77 can match eol */ -YY_RULE_SETUP -#line 106 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return SCRIPT_DATA; } - YY_BREAK -case 78: -/* rule 78 can match eol */ -YY_RULE_SETUP -#line 107 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return STRING; } - YY_BREAK -case 79: -YY_RULE_SETUP -#line 108 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return INT; } - YY_BREAK -case 80: -YY_RULE_SETUP -#line 109 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return INT; } - YY_BREAK -case 81: -YY_RULE_SETUP -#line 110 "../src/spell-convert/lexer.lpp" -{ yylval.s = str(spell_convertertext); return ID; } - YY_BREAK -case 82: -*yy_cp = (yy_hold_char); /* undo effects of setting up spell_convertertext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up spell_convertertext again */ -YY_RULE_SETUP -#line 111 "../src/spell-convert/lexer.lpp" -{ PRINTF("%s\n", sexpr::escape(*str(spell_convertertext + 1))); } - YY_BREAK -case 83: -*yy_cp = (yy_hold_char); /* undo effects of setting up spell_convertertext */ -(yy_c_buf_p) = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up spell_convertertext again */ -YY_RULE_SETUP -#line 112 "../src/spell-convert/lexer.lpp" -{ PRINTF("%s\n", sexpr::escape(*str(spell_convertertext + 2))); } - YY_BREAK -case 84: -/* rule 84 can match eol */ -YY_RULE_SETUP -#line 113 "../src/spell-convert/lexer.lpp" -/* ignore whitespace */ - YY_BREAK -case 85: -YY_RULE_SETUP -#line 114 "../src/spell-convert/lexer.lpp" -{ abort(); } - YY_BREAK -case 86: -YY_RULE_SETUP -#line 116 "../src/spell-convert/lexer.lpp" -ECHO; - YY_BREAK -#line 1367 "src/spell-convert/lexer.cpp" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed spell_converterin at a new source and called - * spell_converterlex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = spell_converterin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( spell_converterwrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * spell_convertertext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of spell_converterlex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - spell_converterrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - spell_converterrestart(spell_converterin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) spell_converterrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 240 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 239); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - spell_converterrestart(spell_converterin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( spell_converterwrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve spell_convertertext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void spell_converterrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - spell_converterensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - spell_converter_create_buffer(spell_converterin,YY_BUF_SIZE ); - } - - spell_converter_init_buffer(YY_CURRENT_BUFFER,input_file ); - spell_converter_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void spell_converter_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * spell_converterpop_buffer_state(); - * spell_converterpush_buffer_state(new_buffer); - */ - spell_converterensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - spell_converter_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (spell_converterwrap()) processing, but the only time this flag - * is looked at is after spell_converterwrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void spell_converter_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - spell_converterin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE spell_converter_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) spell_converteralloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converter_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) spell_converteralloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converter_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - spell_converter_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with spell_converter_create_buffer() - * - */ - void spell_converter_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - spell_converterfree((void *) b->yy_ch_buf ); - - spell_converterfree((void *) b ); -} - -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a spell_converterrestart() or at EOF. - */ - static void spell_converter_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - spell_converter_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then spell_converter_init_buffer was _probably_ - * called from spell_converterrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void spell_converter_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - spell_converter_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void spell_converterpush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - spell_converterensure_buffer_stack(); - - /* This block is copied from spell_converter_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from spell_converter_switch_to_buffer. */ - spell_converter_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void spell_converterpop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - spell_converter_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - spell_converter_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void spell_converterensure_buffer_stack (void) -{ - int num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)spell_converteralloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converterensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)spell_converterrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converterensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE spell_converter_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) spell_converteralloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converter_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - spell_converter_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to spell_converterlex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * spell_converter_scan_bytes() instead. - */ -YY_BUFFER_STATE spell_converter_scan_string (yyconst char * yystr ) -{ - - return spell_converter_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to spell_converterlex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE spell_converter_scan_bytes (yyconst char * yybytes, int _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) spell_converteralloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in spell_converter_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = spell_converter_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in spell_converter_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up spell_convertertext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - spell_convertertext[spell_converterleng] = (yy_hold_char); \ - (yy_c_buf_p) = spell_convertertext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - spell_converterleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int spell_converterget_lineno (void) -{ - - return spell_converterlineno; -} - -/** Get the input stream. - * - */ -FILE *spell_converterget_in (void) -{ - return spell_converterin; -} - -/** Get the output stream. - * - */ -FILE *spell_converterget_out (void) -{ - return spell_converterout; -} - -/** Get the length of the current token. - * - */ -int spell_converterget_leng (void) -{ - return spell_converterleng; -} - -/** Get the current token. - * - */ - -char *spell_converterget_text (void) -{ - return spell_convertertext; -} - -/** Set the current line number. - * @param line_number - * - */ -void spell_converterset_lineno (int line_number ) -{ - - spell_converterlineno = line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param in_str A readable stream. - * - * @see spell_converter_switch_to_buffer - */ -void spell_converterset_in (FILE * in_str ) -{ - spell_converterin = in_str ; -} - -void spell_converterset_out (FILE * out_str ) -{ - spell_converterout = out_str ; -} - -int spell_converterget_debug (void) -{ - return spell_converter_flex_debug; -} - -void spell_converterset_debug (int bdebug ) -{ - spell_converter_flex_debug = bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from spell_converterlex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - spell_converterin = stdin; - spell_converterout = stdout; -#else - spell_converterin = (FILE *) 0; - spell_converterout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * spell_converterlex_init() - */ - return 0; -} - -/* spell_converterlex_destroy is for both reentrant and non-reentrant scanners. */ -int spell_converterlex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - spell_converter_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - spell_converterpop_buffer_state(); - } - - /* Destroy the stack itself. */ - spell_converterfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * spell_converterlex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *spell_converteralloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *spell_converterrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void spell_converterfree (void * ptr ) -{ - free( (char *) ptr ); /* see spell_converterrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 116 "../src/spell-convert/lexer.lpp" - - -// nothing to see here, move along - diff --git a/src/spell-convert/lexer.hpp b/src/spell-convert/lexer.hpp deleted file mode 100644 index 82c6ba2..0000000 --- a/src/spell-convert/lexer.hpp +++ /dev/null @@ -1,335 +0,0 @@ -#ifndef spell_converterHEADER_H -#define spell_converterHEADER_H 1 -#define spell_converterIN_HEADER 1 - -#line 6 "src/spell-convert/lexer.hpp" - -#line 8 "src/spell-convert/lexer.hpp" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include <inttypes.h> -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int spell_converterleng; - -extern FILE *spell_converterin, *spell_converterout; - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void spell_converterrestart (FILE *input_file ); -void spell_converter_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE spell_converter_create_buffer (FILE *file,int size ); -void spell_converter_delete_buffer (YY_BUFFER_STATE b ); -void spell_converter_flush_buffer (YY_BUFFER_STATE b ); -void spell_converterpush_buffer_state (YY_BUFFER_STATE new_buffer ); -void spell_converterpop_buffer_state (void ); - -YY_BUFFER_STATE spell_converter_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE spell_converter_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE spell_converter_scan_bytes (yyconst char *bytes,int len ); - -void *spell_converteralloc (yy_size_t ); -void *spell_converterrealloc (void *,yy_size_t ); -void spell_converterfree (void * ); - -/* Begin user sect3 */ - -#define spell_converterwrap(n) 1 -#define YY_SKIP_YYWRAP - -extern int spell_converterlineno; - -extern char *spell_convertertext; -#define yytext_ptr spell_convertertext - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include <unistd.h> -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int spell_converterlex_destroy (void ); - -int spell_converterget_debug (void ); - -void spell_converterset_debug (int debug_flag ); - -YY_EXTRA_TYPE spell_converterget_extra (void ); - -void spell_converterset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *spell_converterget_in (void ); - -void spell_converterset_in (FILE * in_str ); - -FILE *spell_converterget_out (void ); - -void spell_converterset_out (FILE * out_str ); - -int spell_converterget_leng (void ); - -char *spell_converterget_text (void ); - -int spell_converterget_lineno (void ); - -void spell_converterset_lineno (int line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int spell_converterwrap (void ); -#else -extern int spell_converterwrap (void ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int spell_converterlex (void); - -#define YY_DECL int spell_converterlex (void) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#line 116 "../src/spell-convert/lexer.lpp" - - -#line 334 "src/spell-convert/lexer.hpp" -#undef spell_converterIN_HEADER -#endif /* spell_converterHEADER_H */ diff --git a/src/spell-convert/lexer.lpp b/src/spell-convert/lexer.lpp deleted file mode 100644 index b6c6d76..0000000 --- a/src/spell-convert/lexer.lpp +++ /dev/null @@ -1,136 +0,0 @@ -%{ -/* vim: set ft=lex: */ -//#include "lexer.hpp" -// magic-interpreter-lexer.lpp - Old magic tokenizer -// -// Copyright © 2004-2011 The Mana World Development Team -// Copyright © 2011-2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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/>. - -#include "../strings/rstring.hpp" -#include "../strings/zstring.hpp" - -#include "../io/cxxstdio.hpp" - -#include "../sexpr/lexer.hpp" - -#include "parser.hpp" - -#define yylval spell_converterlval - -RString *str(const char *s) -{ - return new RString(ZString(strings::really_construct_from_a_pointer, s, nullptr)); -} -%} - -%option noyywrap -%option prefix="spell_converter" -%option nounput -%option noinput - -%% - -"S" { yylval.s = str(yytext); return DIR; } -"SW" { yylval.s = str(yytext); return DIR; } -"W" { yylval.s = str(yytext); return DIR; } -"NW" { yylval.s = str(yytext); return DIR; } -"N" { yylval.s = str(yytext); return DIR; } -"NE" { yylval.s = str(yytext); return DIR; } -"E" { yylval.s = str(yytext); return DIR; } -"SE" { yylval.s = str(yytext); return DIR; } -"=" { return '='; } -"==" { return EQ; } -"<>" { return NEQ; } -"!=" { return NEQ; } -">" { return '>'; } -"<" { return '<'; } -">=" { return GTE; } -"<=" { return LTE; } -"(" { return '('; } -")" { return ')'; } -"+" { return '+'; } -"-" { return '-'; } -"*" { return '*'; } -"/" { return '/'; } -"%" { return '%'; } -"&&" { return ANDAND; } -"||" { return OROR; } -";" { return ';'; } -":" { return ':'; } -"," { return ','; } -"@" { return '@'; } -"|" { return '|'; } -"[" { return '['; } -"]" { return ']'; } -"&" { return '&'; } -"^" { return '^'; } -"." { return '.'; } -"<<" { return SHL; } -">>" { return SHR; } -"PROCEDURE" { return PROCEDURE; } -"CALL" { return CALL; } -"OR" { return OR; } -"TO" { return TO; } -"TOWARDS" { return TOWARDS; } -"TELEPORT-ANCHOR" { return TELEPORT_ANCHOR; } -"SILENT" { return SILENT; } -"LOCAL" { return LOCAL; } -"NONMAGIC" { return NONMAGIC; } -"SPELL" { return SPELL; } -"LET" { return LET; } -"IN" { return IN; } -"END" { return END; } -"=>" { return DARROW; } -"STRING" { return STRING_TY; } -"REQUIRE" { return REQUIRE; } -"CATALYSTS" { return CATALYSTS; } -"COMPONENTS" { return COMPONENTS; } -"MANA" { return MANA; } -"CASTTIME" { return CASTTIME; } -"SKIP" { return SKIP; } -"ABORT" { return ABORT; } -"BREAK" { return BREAK; } -"EFFECT" { return EFFECT_; } -"ATEND" { return ATEND; } -"ATTRIGGER" { return ATTRIGGER; } -"CONST" { return CONST; } -"PC" { return PC_F; } -"NPC" { return NPC_F; } -"MOB" { return MOB_F; } -"ENTITY" { return ENTITY_F; } -"TARGET" { return TARGET_F; } -"IF" { return IF; } -"THEN" { return THEN; } -"ELSE" { return ELSE; } -"FOREACH" { return FOREACH; } -"FOR" { return FOR; } -"DO" { return DO; } -"WAIT" { return SLEEP; } - -\{([^\}]|\\.)*\} { yylval.s = str(yytext); return SCRIPT_DATA; } -\"([^\"]|\\.)*\" { yylval.s = str(yytext); return STRING; } -"-"?[0-9]+ { yylval.s = str(yytext); return INT; } -"0x"[0-9a-fA-F]+ { yylval.s = str(yytext); return INT; } -[a-zA-Z][-_a-zA-Z0-9]* { yylval.s = str(yytext); return ID; } -"#".*$ { PRINTF("%s\n", sexpr::escape(*str(yytext + 1))); } -"//".*$ { PRINTF("%s\n", sexpr::escape(*str(yytext + 2))); } -[ \n\t\r] /* ignore whitespace */ -. { abort(); } - -%% -// nothing to see here, move along diff --git a/src/spell-convert/parser.cpp b/src/spell-convert/parser.cpp deleted file mode 100644 index 0744630..0000000 --- a/src/spell-convert/parser.cpp +++ /dev/null @@ -1,2732 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - 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/>. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.0.2" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - - -/* Substitute the variable and function names. */ -#define yyparse spell_converterparse -#define yylex spell_converterlex -#define yyerror spell_convertererror -#define yydebug spell_converterdebug -#define yynerrs spell_converternerrs - -#define yylval spell_converterlval -#define yychar spell_converterchar - -/* Copy the first part of user declarations. */ - -#line 75 "src/spell-convert/parser.cpp" /* yacc.c:339 */ - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "parser.hpp". */ -#ifndef YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED -# define YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int spell_converterdebug; -#endif -/* "%code requires" blocks. */ -#line 2 "../src/spell-convert/parser.ypp" /* yacc.c:355 */ - -/* vim: set ft=yacc: */ -#include "../strings/rstring.hpp" - -#include "ast.hpp" - -#undef YYERROR_VERBOSE -#define YYERROR_VERBOSE 1 - -#line 115 "src/spell-convert/parser.cpp" /* yacc.c:355 */ - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - INT = 258, - STRING = 259, - ID = 260, - DIR = 261, - CONST = 262, - PROCEDURE = 263, - CALL = 264, - SILENT = 265, - LOCAL = 266, - NONMAGIC = 267, - SHL = 268, - SHR = 269, - EQ = 270, - NEQ = 271, - GTE = 272, - LTE = 273, - ANDAND = 274, - OROR = 275, - SCRIPT_DATA = 276, - TO = 277, - TOWARDS = 278, - TELEPORT_ANCHOR = 279, - SPELL = 280, - LET = 281, - IN = 282, - END = 283, - DARROW = 284, - STRING_TY = 285, - REQUIRE = 286, - CATALYSTS = 287, - COMPONENTS = 288, - MANA = 289, - CASTTIME = 290, - SKIP = 291, - ABORT = 292, - BREAK = 293, - EFFECT_ = 294, - ATEND = 295, - ATTRIGGER = 296, - PC_F = 297, - NPC_F = 298, - MOB_F = 299, - ENTITY_F = 300, - TARGET_F = 301, - IF = 302, - THEN = 303, - ELSE = 304, - FOREACH = 305, - FOR = 306, - DO = 307, - SLEEP = 308, - OR = 309 - }; -#endif - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; -union YYSTYPE -{ -#line 27 "../src/spell-convert/parser.ypp" /* yacc.c:355 */ - - RString *s; - std::vector<RString> *vs; - Effect *e; - std::deque<Effect *> *ve; - SpellDef *spelldef; - SpellArg *spellarg; - TopLevel *top; - Expression *expr; - std::vector<Expression *> *vx; - Location *loc; - Item *it; - std::vector<Item *> *vit; - Assignment *a; - std::vector<Assignment *> *va; - SpellBod *b; - std::vector<SpellBod *> *vb; - SpellGuard *g; - std::vector<SpellGuard *> *vg; - -#line 203 "src/spell-convert/parser.cpp" /* yacc.c:355 */ -}; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - -extern YYSTYPE spell_converterlval; - -int spell_converterparse (void); - -#endif /* !YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED */ - -/* Copy the second part of user declarations. */ - -#line 218 "src/spell-convert/parser.cpp" /* yacc.c:358 */ -/* Unqualified %code blocks. */ -#line 13 "../src/spell-convert/parser.ypp" /* yacc.c:359 */ - -//#include "parser.hpp" -#include "lexer.hpp" - -#include "../io/cxxstdio.hpp" - -#include "../sexpr/lexer.hpp" - -void yyerror(const char *msg) { FPRINTF(stderr, "Fatal: %s\n", msg); abort(); } - -#line 231 "src/spell-convert/parser.cpp" /* yacc.c:359 */ - -#ifdef short -# undef short -#endif - -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif - -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short int yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short int yytype_int16; -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif -#endif - -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - - -#if ! defined yyoverflow || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yytype_int16 yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 2 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 990 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 75 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 32 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 111 -/* YYNSTATES -- Number of states. */ -#define YYNSTATES 248 - -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 309 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 14, 23, 2, - 73, 74, 12, 10, 16, 11, 17, 13, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 18, 19, - 8, 7, 9, 2, 15, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 21, 2, 22, 24, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 20, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72 -}; - -#if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 167, 167, 171, 179, 183, 191, 195, 205, 211, - 222, 227, 232, 237, 242, 253, 257, 263, 269, 281, - 285, 295, 300, 310, 315, 320, 330, 335, 340, 345, - 350, 355, 360, 365, 370, 375, 380, 385, 390, 395, - 400, 405, 410, 415, 420, 425, 430, 436, 441, 446, - 451, 462, 466, 476, 482, 493, 503, 508, 513, 523, - 528, 538, 543, 554, 564, 570, 581, 586, 591, 602, - 606, 617, 621, 631, 636, 641, 651, 657, 668, 673, - 678, 683, 688, 698, 708, 714, 725, 730, 740, 745, - 755, 760, 765, 770, 775, 780, 790, 795, 800, 805, - 810, 815, 820, 825, 830, 835, 840, 845, 850, 856, - 867, 871 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE || 0 -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "INT", "STRING", "ID", "DIR", "'='", - "'<'", "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "'@'", "','", "'.'", - "':'", "';'", "'|'", "'['", "']'", "'&'", "'^'", "CONST", "PROCEDURE", - "CALL", "SILENT", "LOCAL", "NONMAGIC", "SHL", "SHR", "EQ", "NEQ", "GTE", - "LTE", "ANDAND", "OROR", "SCRIPT_DATA", "TO", "TOWARDS", - "TELEPORT_ANCHOR", "SPELL", "LET", "IN", "END", "DARROW", "STRING_TY", - "REQUIRE", "CATALYSTS", "COMPONENTS", "MANA", "CASTTIME", "SKIP", - "ABORT", "BREAK", "EFFECT_", "ATEND", "ATTRIGGER", "PC_F", "NPC_F", - "MOB_F", "ENTITY_F", "TARGET_F", "IF", "THEN", "ELSE", "FOREACH", "FOR", - "DO", "SLEEP", "OR", "'('", "')'", "$accept", "spellconf", "semicolons", - "proc_formals_list", "proc_formals_list_ne", "spellconf_option", - "spell_flags", "argopt", "arg_ty", "value", "expr", "arg_list", - "arg_list_ne", "location", "area", "spelldef", "defs", "def", - "spellbody_list", "spellbody", "maybe_trigger", "maybe_end", - "spellguard", "spellguard_list", "prereq", "items", "item_list", "item", - "item_name", "selection", "effect", "effect_list", YY_NULLPTR -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 61, 60, 62, - 43, 45, 42, 47, 37, 64, 44, 46, 58, 59, - 124, 91, 93, 38, 94, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 40, 41 -}; -# endif - -#define YYPACT_NINF -171 - -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-171))) - -#define YYTABLE_NINF -13 - -#define yytable_value_is_error(Yytable_value) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -171, 19, -171, 156, 17, -171, 46, 60, 64, -171, - 104, 91, 65, 2, 80, -171, -171, -171, 73, -171, - -171, 27, -171, 28, 91, -171, 780, 39, -171, 91, - 98, 91, 35, 91, 91, 230, 91, 91, 91, 91, - 91, 91, 91, 91, 111, 91, 91, 91, 91, 91, - 91, 91, 91, 91, 91, 91, 99, 91, 780, -171, - 49, 106, 812, 115, 107, 780, 50, 114, 556, -171, - -1, 937, 937, 958, 958, 184, 184, 184, -171, -1, - -1, -1, -1, -1, 937, 937, 937, 937, 907, 876, - 68, 588, 142, 145, 91, 134, 91, -171, 91, 91, - 91, 81, 163, -171, 484, 14, 844, 780, 620, 652, - 91, -2, 148, -171, 136, 138, 139, 140, 91, 123, - 160, 91, 163, -171, -171, -171, -171, 93, 6, 91, - 91, 684, 91, 91, 96, -171, -171, -171, -171, 462, - -171, -171, -171, -171, -171, -171, 166, 165, 716, 100, - 124, -171, -171, 91, 152, 152, 91, 91, 163, 87, - -171, 157, -171, -25, -171, 262, 306, 91, 748, 102, - 91, 163, 149, 91, -171, -171, -171, 177, 3, 780, - 11, -171, -171, 780, 780, 141, -13, -25, -14, 172, - 172, 62, -171, -171, 338, -171, 180, 129, 143, 91, - 522, 198, 172, -171, 194, -171, 48, -171, -171, 163, - 153, -171, 62, -171, 172, -171, -171, 62, -171, -171, - -171, 193, 163, 382, 91, 91, 157, 177, 63, 11, - -171, -171, 163, -171, 154, 154, -171, -171, 163, 422, - 780, -171, -171, -171, -171, -171, 163, -171 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 2, 4, 1, 15, 0, 5, 0, 0, 0, 3, - 0, 0, 0, 0, 0, 18, 16, 17, 0, 24, - 25, 27, 23, 0, 0, 26, 10, 56, 28, 0, - 6, 0, 19, 51, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 11, 8, - 0, 7, 0, 0, 0, 53, 0, 52, 0, 49, - 46, 34, 35, 29, 30, 31, 33, 32, 50, 38, - 36, 37, 39, 40, 45, 47, 42, 41, 43, 44, - 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, - 0, 0, 110, 9, 46, 0, 0, 54, 0, 0, - 0, 0, 0, 108, 0, 0, 0, 0, 0, 0, - 0, 0, 110, 4, 13, 22, 21, 0, 0, 0, - 0, 0, 0, 51, 0, 99, 97, 98, 100, 0, - 93, 90, 95, 91, 92, 94, 0, 0, 0, 0, - 110, 20, 4, 0, 0, 0, 0, 0, 110, 0, - 14, 59, 64, 0, 73, 0, 0, 0, 0, 0, - 51, 0, 0, 0, 106, 96, 111, 61, 0, 78, - 0, 79, 80, 81, 82, 69, 0, 76, 0, 0, - 0, 0, 55, 57, 0, 101, 0, 0, 105, 0, - 0, 0, 0, 4, 89, 88, 0, 84, 87, 110, - 71, 67, 0, 75, 0, 65, 66, 0, 74, 58, - 107, 0, 0, 0, 0, 0, 60, 62, 0, 0, - 83, 70, 110, 68, 77, 76, 109, 104, 0, 0, - 63, 89, 86, 85, 72, 102, 0, 103 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -171, -171, -119, -171, -171, -171, -171, -171, -171, -171, - -11, -84, -171, -171, -171, -171, -171, -171, -125, -108, - -171, -171, -86, -171, -171, 72, -171, -9, 5, -171, - -170, -105 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 1, 3, 60, 61, 9, 10, 64, 127, 25, - 65, 66, 67, 27, 28, 160, 178, 203, 186, 162, - 210, 233, 163, 188, 164, 181, 206, 207, 208, 146, - 123, 124 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 26, 198, 212, 161, 150, 132, 36, 189, 201, 19, - 20, 21, 22, 35, 204, 205, 44, 149, 58, 2, - 62, 23, 190, 68, 11, 70, 71, 72, 73, 74, - 75, 76, 77, 177, 79, 80, 81, 82, 83, 84, - 85, 86, 87, 88, 89, 176, 91, 191, 202, 169, - 152, 12, 237, 185, 56, 153, 154, 155, 156, 157, - 213, 211, 125, 158, 229, 13, 241, 205, 245, 14, - 230, 133, 29, 187, 126, 30, 247, 226, 32, 159, - 57, 215, 216, 104, 227, 106, 197, 107, 108, 109, - 19, 20, 21, 22, 19, 20, 21, 22, 31, 131, - 33, 34, 23, 59, 231, 218, 23, 139, 63, 90, - 148, 153, 154, 155, 156, 157, 78, 70, 165, 166, - 95, 168, 93, 92, 97, 96, 234, 244, 187, 111, - 98, 235, 15, 16, 17, 217, 153, 154, 155, 156, - 157, 100, 179, 5, 158, 183, 184, 18, 35, 102, - 103, 112, 105, 134, 110, 135, 194, 136, 137, 138, - 159, 4, 200, 113, 24, 147, 140, 151, 111, 170, - 114, 172, 173, 180, 175, 5, 196, 189, 115, 116, - 117, 6, 7, 141, 142, 143, 144, 145, 223, 118, - 112, 36, 119, 120, 199, 121, 5, 122, 8, 220, - 209, 44, 113, 221, 45, 225, 228, 46, 47, 114, - 222, 232, 236, 239, 240, 48, 49, 115, 116, 117, - 243, 153, 154, 155, 156, 157, 191, 182, 118, 158, - 0, 119, 120, 242, 121, 0, 122, 36, 37, 38, - 39, 40, 41, 42, 43, 214, 0, 44, 0, 0, - 45, 0, 0, 46, 47, 0, 0, 0, 0, 0, - 0, 48, 49, 50, 51, 52, 53, 54, 55, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 0, 48, 49, 50, 51, 52, 53, 54, - 55, 0, 0, 0, 69, 0, 0, 0, 0, 0, - 0, 0, 0, 36, 37, 38, 39, 40, 41, 42, - 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, - 47, 0, 0, 0, 0, 0, 192, 48, 49, 50, - 51, 52, 53, 54, 55, 36, 37, 38, 39, 40, - 41, 42, 43, 0, 0, 44, 0, 0, 45, 0, - 0, 46, 47, 0, 0, 0, 0, 0, 0, 48, - 49, 50, 51, 52, 53, 54, 55, 0, 0, 0, - 193, 0, 0, 0, 0, 0, 0, 0, 0, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 219, 48, 49, 50, 51, 52, 53, 54, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 238, 48, 49, 50, 51, 52, 53, 54, - 55, 0, 0, 0, 0, 0, 0, 0, 0, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, -12, 46, 47, 0, 0, -12, - 0, 36, 246, 48, 49, 50, 51, 52, 53, 54, - 55, 44, 0, -12, 0, 0, 0, 0, 0, -12, - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -12, -12, 171, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 0, 48, 49, 50, 51, 52, 53, 54, - 55, 0, 224, 36, 37, 38, 39, 40, 41, 42, - 43, 0, 99, 44, 0, 0, 45, 0, 0, 46, - 47, 0, 0, 0, 0, 0, 0, 48, 49, 50, - 51, 52, 53, 54, 55, 36, 37, 38, 39, 40, - 41, 42, 43, 0, 0, 44, 101, 0, 45, 0, - 0, 46, 47, 0, 0, 0, 0, 0, 0, 48, - 49, 50, 51, 52, 53, 54, 55, 36, 37, 38, - 39, 40, 41, 42, 43, 0, 129, 44, 0, 0, - 45, 0, 0, 46, 47, 0, 0, 0, 0, 0, - 0, 48, 49, 50, 51, 52, 53, 54, 55, 36, - 37, 38, 39, 40, 41, 42, 43, 0, 130, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 0, 48, 49, 50, 51, 52, 53, 54, - 55, 36, 37, 38, 39, 40, 41, 42, 43, 0, - 167, 44, 0, 0, 45, 0, 0, 46, 47, 0, - 0, 0, 0, 0, 0, 48, 49, 50, 51, 52, - 53, 54, 55, 36, 37, 38, 39, 40, 41, 42, - 43, 0, 0, 44, 0, 174, 45, 0, 0, 46, - 47, 0, 0, 0, 0, 0, 0, 48, 49, 50, - 51, 52, 53, 54, 55, 36, 37, 38, 39, 40, - 41, 42, 43, 0, 0, 44, 0, 195, 45, 0, - 0, 46, 47, 0, 0, 0, 0, 0, 0, 48, - 49, 50, 51, 52, 53, 54, 55, 36, 37, 38, - 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, - 45, 0, 0, 46, 47, 0, 0, 0, 0, 0, - 0, 48, 49, 50, 51, 52, 53, 54, 55, 94, - 37, 38, 39, 40, 41, 42, 43, 0, 0, 44, - 0, 0, 45, 0, 0, 46, 47, 0, 0, 0, - 0, 0, 0, 48, 49, 50, 51, 52, 53, 54, - 55, 128, 37, 38, 39, 40, 41, 42, 43, 0, - 0, 44, 0, 0, 45, 0, 0, 46, 47, 0, - 0, 0, 0, 0, 0, 48, 49, 50, 51, 52, - 53, 54, 55, 36, 37, 38, 39, 40, 41, 42, - 43, 0, 0, 44, 0, 0, 45, 0, 0, 46, - 47, 0, 0, 0, 0, 0, 0, 48, 49, 50, - 51, 52, 53, 54, 36, 37, 38, 39, 40, 41, - 42, 43, 0, 0, 44, 0, 0, 45, 0, 0, - 46, 47, 0, 0, 0, 0, 0, 0, 48, 49, - 50, 51, 52, 53, 36, 0, 0, 39, 40, 41, - 42, 43, 0, 0, 44, 0, 0, 45, 0, 0, - 46, 47, 0, 0, 0, 36, 0, 0, 48, 49, - 41, 42, 43, 0, 0, 44, 0, 0, 45, 0, - 0, 46, 47, 0, 0, 0, 0, 0, 0, 48, - 49 -}; - -static const yytype_int16 yycheck[] = -{ - 11, 171, 16, 128, 123, 7, 7, 20, 5, 3, - 4, 5, 6, 24, 3, 4, 17, 122, 29, 0, - 31, 15, 47, 34, 7, 36, 37, 38, 39, 40, - 41, 42, 43, 152, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 150, 57, 72, 45, 133, - 44, 5, 222, 158, 15, 49, 50, 51, 52, 53, - 74, 74, 48, 57, 16, 5, 3, 4, 238, 5, - 22, 73, 7, 159, 60, 73, 246, 202, 5, 73, - 41, 189, 190, 94, 203, 96, 170, 98, 99, 100, - 3, 4, 5, 6, 3, 4, 5, 6, 18, 110, - 73, 73, 15, 5, 209, 191, 15, 118, 73, 10, - 121, 49, 50, 51, 52, 53, 5, 128, 129, 130, - 5, 132, 16, 74, 74, 18, 212, 232, 214, 5, - 16, 217, 28, 29, 30, 73, 49, 50, 51, 52, - 53, 73, 153, 19, 57, 156, 157, 43, 159, 7, - 5, 27, 18, 5, 73, 19, 167, 19, 19, 19, - 73, 5, 173, 39, 73, 5, 43, 74, 5, 73, - 46, 5, 7, 21, 74, 19, 74, 20, 54, 55, - 56, 25, 26, 60, 61, 62, 63, 64, 199, 65, - 27, 7, 68, 69, 45, 71, 19, 73, 42, 19, - 59, 17, 39, 74, 20, 7, 12, 23, 24, 46, - 67, 58, 19, 224, 225, 31, 32, 54, 55, 56, - 229, 49, 50, 51, 52, 53, 72, 155, 65, 57, - -1, 68, 69, 228, 71, -1, 73, 7, 8, 9, - 10, 11, 12, 13, 14, 73, -1, 17, -1, -1, - 20, -1, -1, 23, 24, -1, -1, -1, -1, -1, - -1, 31, 32, 33, 34, 35, 36, 37, 38, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, -1, 31, 32, 33, 34, 35, 36, 37, - 38, -1, -1, -1, 74, -1, -1, -1, -1, -1, - -1, -1, -1, 7, 8, 9, 10, 11, 12, 13, - 14, -1, -1, 17, -1, -1, 20, -1, -1, 23, - 24, -1, -1, -1, -1, -1, 74, 31, 32, 33, - 34, 35, 36, 37, 38, 7, 8, 9, 10, 11, - 12, 13, 14, -1, -1, 17, -1, -1, 20, -1, - -1, 23, 24, -1, -1, -1, -1, -1, -1, 31, - 32, 33, 34, 35, 36, 37, 38, -1, -1, -1, - 74, -1, -1, -1, -1, -1, -1, -1, -1, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, 74, 31, 32, 33, 34, 35, 36, 37, - 38, -1, -1, -1, -1, -1, -1, -1, -1, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, 70, 31, 32, 33, 34, 35, 36, 37, - 38, -1, -1, -1, -1, -1, -1, -1, -1, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, 0, 23, 24, -1, -1, 5, - -1, 7, 70, 31, 32, 33, 34, 35, 36, 37, - 38, 17, -1, 19, -1, -1, -1, -1, -1, 25, - 26, -1, 28, 29, 30, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 42, 43, 66, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, -1, 31, 32, 33, 34, 35, 36, 37, - 38, -1, 40, 7, 8, 9, 10, 11, 12, 13, - 14, -1, 16, 17, -1, -1, 20, -1, -1, 23, - 24, -1, -1, -1, -1, -1, -1, 31, 32, 33, - 34, 35, 36, 37, 38, 7, 8, 9, 10, 11, - 12, 13, 14, -1, -1, 17, 18, -1, 20, -1, - -1, 23, 24, -1, -1, -1, -1, -1, -1, 31, - 32, 33, 34, 35, 36, 37, 38, 7, 8, 9, - 10, 11, 12, 13, 14, -1, 16, 17, -1, -1, - 20, -1, -1, 23, 24, -1, -1, -1, -1, -1, - -1, 31, 32, 33, 34, 35, 36, 37, 38, 7, - 8, 9, 10, 11, 12, 13, 14, -1, 16, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, -1, 31, 32, 33, 34, 35, 36, 37, - 38, 7, 8, 9, 10, 11, 12, 13, 14, -1, - 16, 17, -1, -1, 20, -1, -1, 23, 24, -1, - -1, -1, -1, -1, -1, 31, 32, 33, 34, 35, - 36, 37, 38, 7, 8, 9, 10, 11, 12, 13, - 14, -1, -1, 17, -1, 19, 20, -1, -1, 23, - 24, -1, -1, -1, -1, -1, -1, 31, 32, 33, - 34, 35, 36, 37, 38, 7, 8, 9, 10, 11, - 12, 13, 14, -1, -1, 17, -1, 19, 20, -1, - -1, 23, 24, -1, -1, -1, -1, -1, -1, 31, - 32, 33, 34, 35, 36, 37, 38, 7, 8, 9, - 10, 11, 12, 13, 14, -1, -1, 17, -1, -1, - 20, -1, -1, 23, 24, -1, -1, -1, -1, -1, - -1, 31, 32, 33, 34, 35, 36, 37, 38, 7, - 8, 9, 10, 11, 12, 13, 14, -1, -1, 17, - -1, -1, 20, -1, -1, 23, 24, -1, -1, -1, - -1, -1, -1, 31, 32, 33, 34, 35, 36, 37, - 38, 7, 8, 9, 10, 11, 12, 13, 14, -1, - -1, 17, -1, -1, 20, -1, -1, 23, 24, -1, - -1, -1, -1, -1, -1, 31, 32, 33, 34, 35, - 36, 37, 38, 7, 8, 9, 10, 11, 12, 13, - 14, -1, -1, 17, -1, -1, 20, -1, -1, 23, - 24, -1, -1, -1, -1, -1, -1, 31, 32, 33, - 34, 35, 36, 37, 7, 8, 9, 10, 11, 12, - 13, 14, -1, -1, 17, -1, -1, 20, -1, -1, - 23, 24, -1, -1, -1, -1, -1, -1, 31, 32, - 33, 34, 35, 36, 7, -1, -1, 10, 11, 12, - 13, 14, -1, -1, 17, -1, -1, 20, -1, -1, - 23, 24, -1, -1, -1, 7, -1, -1, 31, 32, - 12, 13, 14, -1, -1, 17, -1, -1, 20, -1, - -1, 23, 24, -1, -1, -1, -1, -1, -1, 31, - 32 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 76, 0, 77, 5, 19, 25, 26, 42, 80, - 81, 7, 5, 5, 5, 28, 29, 30, 43, 3, - 4, 5, 6, 15, 73, 84, 85, 88, 89, 7, - 73, 18, 5, 73, 73, 85, 7, 8, 9, 10, - 11, 12, 13, 14, 17, 20, 23, 24, 31, 32, - 33, 34, 35, 36, 37, 38, 15, 41, 85, 5, - 78, 79, 85, 73, 82, 85, 86, 87, 85, 74, - 85, 85, 85, 85, 85, 85, 85, 85, 5, 85, - 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, - 10, 85, 74, 16, 7, 5, 18, 74, 16, 16, - 73, 18, 7, 5, 85, 18, 85, 85, 85, 85, - 73, 5, 27, 39, 46, 54, 55, 56, 65, 68, - 69, 71, 73, 105, 106, 48, 60, 83, 7, 16, - 16, 85, 7, 73, 5, 19, 19, 19, 19, 85, - 43, 60, 61, 62, 63, 64, 104, 5, 85, 106, - 77, 74, 44, 49, 50, 51, 52, 53, 57, 73, - 90, 93, 94, 97, 99, 85, 85, 16, 85, 86, - 73, 66, 5, 7, 19, 74, 106, 77, 91, 85, - 21, 100, 100, 85, 85, 106, 93, 97, 98, 20, - 47, 72, 74, 74, 85, 19, 74, 86, 105, 45, - 85, 5, 45, 92, 3, 4, 101, 102, 103, 59, - 95, 74, 16, 74, 73, 94, 94, 73, 97, 74, - 19, 74, 67, 85, 40, 7, 93, 77, 12, 16, - 22, 106, 58, 96, 97, 97, 19, 105, 70, 85, - 85, 3, 103, 102, 106, 105, 70, 105 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 75, 76, 76, 77, 77, 78, 78, 79, 79, - 80, 80, 80, 80, 80, 81, 81, 81, 81, 82, - 82, 83, 83, 84, 84, 84, 85, 85, 85, 85, - 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, - 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, - 85, 86, 86, 87, 87, 88, 89, 89, 89, 90, - 90, 91, 91, 92, 93, 93, 94, 94, 94, 95, - 95, 96, 96, 97, 97, 97, 98, 98, 99, 99, - 99, 99, 99, 100, 101, 101, 102, 102, 103, 103, - 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, - 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - 106, 106 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 0, 3, 0, 2, 0, 1, 1, 3, - 3, 4, 6, 7, 8, 0, 2, 2, 2, 0, - 5, 1, 1, 1, 1, 1, 1, 1, 1, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, - 3, 0, 1, 1, 3, 8, 1, 8, 9, 1, - 4, 1, 3, 3, 1, 3, 3, 3, 4, 0, - 2, 0, 2, 1, 3, 3, 1, 3, 2, 2, - 2, 2, 2, 3, 1, 3, 3, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 3, 2, 2, 2, - 2, 4, 7, 8, 6, 4, 3, 5, 1, 6, - 0, 3 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - - -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ - -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -{ - FILE *yyo = yyoutput; - YYUSE (yyo); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); -} - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -{ - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) -{ - unsigned long int yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; - int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -{ - YYUSE (yyvaluep); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - - - -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; -/* Number of syntax errors so far. */ -int yynerrs; - - -/*----------. -| yyparse. | -`----------*/ - -int -yyparse (void) -{ - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; - - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (); - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 3: -#line 172 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyvsp[0].top)->dump(); -} -#line 1633 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 6: -#line 191 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = new std::vector<RString>(); -} -#line 1641 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 7: -#line 196 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = (yyvsp[0].vs); -} -#line 1649 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 8: -#line 206 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = new std::vector<RString>(); - (yyval.vs)->push_back(*(yyvsp[0].s)); -} -#line 1658 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 9: -#line 212 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = (yyvsp[-2].vs); - (yyval.vs)->push_back(*(yyvsp[0].s)); -} -#line 1667 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 10: -#line 223 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.top) = new Assignment{*(yyvsp[-2].s), (yyvsp[0].expr)}; -} -#line 1675 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 11: -#line 228 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.top) = new Constant{*(yyvsp[-2].s), (yyvsp[0].expr)}; -} -#line 1683 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 12: -#line 233 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.top) = new Teleport{*(yyvsp[-4].s), (yyvsp[-2].expr), (yyvsp[0].expr)}; -} -#line 1691 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 13: -#line 238 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.top) = new Procedure{*(yyvsp[-5].s), (yyvsp[-3].vs), (yyvsp[0].ve)}; -} -#line 1699 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 14: -#line 243 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.top) = new Spell{(yyvsp[-7].vs), *(yyvsp[-5].s), (yyvsp[-4].spellarg), (yyvsp[-2].expr), (yyvsp[0].spelldef)}; -} -#line 1707 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 15: -#line 253 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = new std::vector<RString>(); -} -#line 1715 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 16: -#line 258 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = (yyvsp[-1].vs); - (yyval.vs)->push_back("LOCAL"); -} -#line 1724 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 17: -#line 264 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = (yyvsp[-1].vs); - (yyval.vs)->push_back("NONMAGIC"); -} -#line 1733 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 18: -#line 270 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vs) = (yyvsp[-1].vs); - (yyval.vs)->push_back("SILENT"); -} -#line 1742 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 19: -#line 281 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.spellarg) = new SpellArg{}; -} -#line 1750 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 20: -#line 286 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.spellarg) = new SpellArg{*(yyvsp[-3].s), *(yyvsp[-1].s)}; -} -#line 1758 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 21: -#line 296 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString("PC"); -} -#line 1766 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 22: -#line 301 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString("STRING"); -} -#line 1774 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 23: -#line 311 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = (yyvsp[0].s); -} -#line 1782 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 24: -#line 316 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = (yyvsp[0].s); -} -#line 1790 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 25: -#line 321 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = (yyvsp[0].s); -} -#line 1798 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 26: -#line 331 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new SimpleExpr{*(yyvsp[0].s)}; -} -#line 1806 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 27: -#line 336 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new SimpleExpr{*(yyvsp[0].s)}; -} -#line 1814 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 28: -#line 341 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = (yyvsp[0].expr); -} -#line 1822 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 29: -#line 346 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "+", (yyvsp[0].expr)}; -} -#line 1830 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 30: -#line 351 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "-", (yyvsp[0].expr)}; -} -#line 1838 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 31: -#line 356 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "*", (yyvsp[0].expr)}; -} -#line 1846 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 32: -#line 361 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "%", (yyvsp[0].expr)}; -} -#line 1854 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 33: -#line 366 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "/", (yyvsp[0].expr)}; -} -#line 1862 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 34: -#line 371 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "<", (yyvsp[0].expr)}; -} -#line 1870 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 35: -#line 376 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), ">", (yyvsp[0].expr)}; -} -#line 1878 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 36: -#line 381 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "&", (yyvsp[0].expr)}; -} -#line 1886 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 37: -#line 386 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "^", (yyvsp[0].expr)}; -} -#line 1894 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 38: -#line 391 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "|", (yyvsp[0].expr)}; -} -#line 1902 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 39: -#line 396 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "<<", (yyvsp[0].expr)}; -} -#line 1910 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 40: -#line 401 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), ">>", (yyvsp[0].expr)}; -} -#line 1918 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 41: -#line 406 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "<=", (yyvsp[0].expr)}; -} -#line 1926 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 42: -#line 411 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), ">=", (yyvsp[0].expr)}; -} -#line 1934 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 43: -#line 416 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "&&", (yyvsp[0].expr)}; -} -#line 1942 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 44: -#line 421 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "||", (yyvsp[0].expr)}; -} -#line 1950 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 45: -#line 426 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "==", (yyvsp[0].expr)}; -} -#line 1958 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 46: -#line 431 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - // convert to == - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "==", (yyvsp[0].expr)}; -} -#line 1967 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 47: -#line 437 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), "!=", (yyvsp[0].expr)}; -} -#line 1975 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 48: -#line 442 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new CallExpr{*(yyvsp[-3].s), (yyvsp[-1].vx)}; -} -#line 1983 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 49: -#line 447 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = (yyvsp[-1].expr); -} -#line 1991 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 50: -#line 452 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new BinExpr{(yyvsp[-2].expr), ".", new SimpleExpr(*(yyvsp[0].s))}; -} -#line 1999 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 51: -#line 462 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vx) = new std::vector<Expression *>(); -} -#line 2007 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 52: -#line 467 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vx) = (yyvsp[0].vx); -} -#line 2015 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 53: -#line 477 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vx) = new std::vector<Expression *>(); - (yyval.vx)->push_back((yyvsp[0].expr)); -} -#line 2024 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 54: -#line 483 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vx) = (yyvsp[-2].vx); - (yyval.vx)->push_back((yyvsp[0].expr)); -} -#line 2033 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 55: -#line 494 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.loc) = new Location{(yyvsp[-5].expr), (yyvsp[-3].expr), (yyvsp[-1].expr)}; -} -#line 2041 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 56: -#line 504 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new AreaLoc{(yyvsp[0].loc)}; -} -#line 2049 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 57: -#line 509 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new AreaRect{(yyvsp[-7].loc), (yyvsp[-3].expr), (yyvsp[-1].expr)}; -} -#line 2057 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 58: -#line 514 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.expr) = new AreaBar{(yyvsp[-8].loc), (yyvsp[-6].expr), (yyvsp[-3].expr), (yyvsp[-1].expr)}; -} -#line 2065 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 59: -#line 524 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.spelldef) = new SpellDef{new std::vector<Assignment *>{}, (yyvsp[0].vb)}; -} -#line 2073 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 60: -#line 529 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.spelldef) = new SpellDef{(yyvsp[-2].va), (yyvsp[0].vb)}; -} -#line 2081 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 61: -#line 539 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.va) = new std::vector<Assignment *>(); -} -#line 2089 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 62: -#line 544 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.va) = (yyvsp[-2].va); - (yyval.va)->push_back((yyvsp[-1].a)); -} -#line 2098 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 63: -#line 555 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.a) = new Assignment{*(yyvsp[-2].s), (yyvsp[0].expr)}; -} -#line 2106 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 64: -#line 565 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vb) = new std::vector<SpellBod *>(); - (yyval.vb)->push_back((yyvsp[0].b)); -} -#line 2115 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 65: -#line 571 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vb) = (yyvsp[-2].vb); - (yyval.vb)->push_back((yyvsp[0].b)); -} -#line 2124 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 66: -#line 582 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.b) = new SpellBodGuarded{(yyvsp[-2].g), (yyvsp[0].b)}; -} -#line 2132 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 67: -#line 587 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.b) = new SpellBodList{(yyvsp[-1].vb)}; -} -#line 2140 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 68: -#line 592 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.b) = new SpellBodEffect{(yyvsp[-2].ve), (yyvsp[-1].ve), (yyvsp[0].ve)}; -} -#line 2148 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 69: -#line 602 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.ve) = nullptr; -} -#line 2156 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 70: -#line 607 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.ve) = (yyvsp[0].ve); -} -#line 2164 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 71: -#line 617 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.ve) = nullptr; -} -#line 2172 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 72: -#line 622 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.ve) = (yyvsp[0].ve); -} -#line 2180 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 73: -#line 632 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = (yyvsp[0].g); -} -#line 2188 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 74: -#line 637 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardOr((yyvsp[-2].g), (yyvsp[0].g)); -} -#line 2196 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 75: -#line 642 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardList{(yyvsp[-1].vg)}; -} -#line 2204 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 76: -#line 652 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vg) = new std::vector<SpellGuard *>(); - (yyval.vg)->push_back((yyvsp[0].g)); -} -#line 2213 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 77: -#line 658 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vg) = (yyvsp[-2].vg); - (yyval.vg)->push_back((yyvsp[0].g)); -} -#line 2222 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 78: -#line 669 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardRequire{(yyvsp[0].expr)}; -} -#line 2230 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 79: -#line 674 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardCatalysts{(yyvsp[0].vit)}; -} -#line 2238 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 80: -#line 679 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardComponents{(yyvsp[0].vit)}; -} -#line 2246 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 81: -#line 684 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardMana{(yyvsp[0].expr)}; -} -#line 2254 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 82: -#line 689 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.g) = new SpellGuardCasttime{(yyvsp[0].expr)}; -} -#line 2262 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 83: -#line 699 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vit) = (yyvsp[-1].vit); -} -#line 2270 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 84: -#line 709 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vit) = new std::vector<Item *>(); - (yyval.vit)->push_back((yyvsp[0].it)); -} -#line 2279 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 85: -#line 715 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.vit) = (yyvsp[-2].vit); - (yyval.vit)->push_back((yyvsp[0].it)); -} -#line 2288 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 86: -#line 726 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.it) = new Item{*(yyvsp[-2].s), *(yyvsp[0].s)}; -} -#line 2296 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 87: -#line 731 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.it) = new Item{RString(), *(yyvsp[0].s)}; -} -#line 2304 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 88: -#line 741 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = (yyvsp[0].s); -} -#line 2312 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 89: -#line 746 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = (yyvsp[0].s); -} -#line 2320 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 90: -#line 756 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"PC"}; -} -#line 2328 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 91: -#line 761 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"MOB"}; -} -#line 2336 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 92: -#line 766 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"ENTITY"}; -} -#line 2344 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 93: -#line 771 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"SPELL"}; -} -#line 2352 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 94: -#line 776 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"TARGET"}; -} -#line 2360 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 95: -#line 781 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.s) = new RString{"NPC"}; -} -#line 2368 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 96: -#line 791 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new EffectList{(yyvsp[-1].ve)}; -} -#line 2376 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 97: -#line 796 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new SimpleEffect{"SKIP"}; -} -#line 2384 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 98: -#line 801 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new SimpleEffect{"ABORT"}; -} -#line 2392 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 99: -#line 806 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new SimpleEffect{"END"}; -} -#line 2400 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 100: -#line 811 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new SimpleEffect{"BREAK"}; -} -#line 2408 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 101: -#line 816 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new Assignment(*(yyvsp[-3].s), (yyvsp[-1].expr)); -} -#line 2416 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 102: -#line 821 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new ForeachEffect{*(yyvsp[-5].s), *(yyvsp[-4].s), (yyvsp[-2].expr), (yyvsp[0].e)}; -} -#line 2424 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 103: -#line 826 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new ForEffect{*(yyvsp[-6].s), (yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].e)}; -} -#line 2432 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 104: -#line 831 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new IfEffect{(yyvsp[-4].expr), (yyvsp[-2].e), (yyvsp[0].e)}; -} -#line 2440 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 105: -#line 836 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new IfEffect{(yyvsp[-2].expr), (yyvsp[0].e)}; -} -#line 2448 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 106: -#line 841 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new SleepEffect{(yyvsp[-1].expr)}; -} -#line 2456 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 107: -#line 846 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new CallExpr{*(yyvsp[-4].s), (yyvsp[-2].vx)}; -} -#line 2464 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 108: -#line 851 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - AString tmp = sexpr::escape(*(yyvsp[0].s)); - (yyval.e) = new ScriptEffect{RString(tmp)}; -} -#line 2473 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 109: -#line 857 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.e) = new ExplicitCallEffect{*(yyvsp[-4].s), (yyvsp[-2].vx)}; -} -#line 2481 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 110: -#line 867 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - (yyval.ve) = new std::deque<Effect *>(); -} -#line 2489 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - case 111: -#line 872 "../src/spell-convert/parser.ypp" /* yacc.c:1646 */ - { - // because of grammar problems, doing this right generates reduce/reduce conflicts - (yyval.ve) = (yyvsp[0].ve); - (yyval.ve)->push_front((yyvsp[-2].e)); -} -#line 2499 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - break; - - -#line 2503 "src/spell-convert/parser.cpp" /* yacc.c:1646 */ - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now 'shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*--------------------------------------. -| yyerrlab -- here on detecting error. | -`--------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - yystos[yystate], yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - } - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - return yyresult; -} -#line 881 "../src/spell-convert/parser.ypp" /* yacc.c:1906 */ - -// Nothing to see here, move along diff --git a/src/spell-convert/parser.hpp b/src/spell-convert/parser.hpp deleted file mode 100644 index 889f2bb..0000000 --- a/src/spell-convert/parser.hpp +++ /dev/null @@ -1,152 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.0.2. */ - -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - 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/>. */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -#ifndef YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED -# define YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int spell_converterdebug; -#endif -/* "%code requires" blocks. */ -#line 2 "../src/spell-convert/parser.ypp" /* yacc.c:1909 */ - -/* vim: set ft=yacc: */ -#include "../strings/rstring.hpp" - -#include "ast.hpp" - -#undef YYERROR_VERBOSE -#define YYERROR_VERBOSE 1 - -#line 54 "src/spell-convert/parser.hpp" /* yacc.c:1909 */ - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - INT = 258, - STRING = 259, - ID = 260, - DIR = 261, - CONST = 262, - PROCEDURE = 263, - CALL = 264, - SILENT = 265, - LOCAL = 266, - NONMAGIC = 267, - SHL = 268, - SHR = 269, - EQ = 270, - NEQ = 271, - GTE = 272, - LTE = 273, - ANDAND = 274, - OROR = 275, - SCRIPT_DATA = 276, - TO = 277, - TOWARDS = 278, - TELEPORT_ANCHOR = 279, - SPELL = 280, - LET = 281, - IN = 282, - END = 283, - DARROW = 284, - STRING_TY = 285, - REQUIRE = 286, - CATALYSTS = 287, - COMPONENTS = 288, - MANA = 289, - CASTTIME = 290, - SKIP = 291, - ABORT = 292, - BREAK = 293, - EFFECT_ = 294, - ATEND = 295, - ATTRIGGER = 296, - PC_F = 297, - NPC_F = 298, - MOB_F = 299, - ENTITY_F = 300, - TARGET_F = 301, - IF = 302, - THEN = 303, - ELSE = 304, - FOREACH = 305, - FOR = 306, - DO = 307, - SLEEP = 308, - OR = 309 - }; -#endif - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE YYSTYPE; -union YYSTYPE -{ -#line 27 "../src/spell-convert/parser.ypp" /* yacc.c:1909 */ - - RString *s; - std::vector<RString> *vs; - Effect *e; - std::deque<Effect *> *ve; - SpellDef *spelldef; - SpellArg *spellarg; - TopLevel *top; - Expression *expr; - std::vector<Expression *> *vx; - Location *loc; - Item *it; - std::vector<Item *> *vit; - Assignment *a; - std::vector<Assignment *> *va; - SpellBod *b; - std::vector<SpellBod *> *vb; - SpellGuard *g; - std::vector<SpellGuard *> *vg; - -#line 142 "src/spell-convert/parser.hpp" /* yacc.c:1909 */ -}; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - -extern YYSTYPE spell_converterlval; - -int spell_converterparse (void); - -#endif /* !YY_SPELL_CONVERTER_SRC_SPELL_CONVERT_PARSER_HPP_INCLUDED */ diff --git a/src/spell-convert/parser.ypp b/src/spell-convert/parser.ypp deleted file mode 100644 index 8a40543..0000000 --- a/src/spell-convert/parser.ypp +++ /dev/null @@ -1,902 +0,0 @@ -%code requires -{ -/* vim: set ft=yacc: */ -// magic-interpreter-parser.ypp - Old magic tokenizer -// -// Copyright © 2004-2011 The Mana World Development Team -// Copyright © 2011-2014 Ben Longbons <b.r.longbons@gmail.com> -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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/>. - -#include "../strings/rstring.hpp" - -#include "ast.hpp" - -#undef YYERROR_VERBOSE -#define YYERROR_VERBOSE 1 -} // %code requires - -%code -{ -//#include "parser.hpp" -#include "lexer.hpp" - -#include "../io/cxxstdio.hpp" - -#include "../sexpr/lexer.hpp" - -void yyerror(const char *msg) { FPRINTF(stderr, "Fatal: %s\n", msg); abort(); } -} // %code - -%name-prefix "spell_converter" - -%union -{ - RString *s; - std::vector<RString> *vs; - Effect *e; - std::deque<Effect *> *ve; - SpellDef *spelldef; - SpellArg *spellarg; - TopLevel *top; - Expression *expr; - std::vector<Expression *> *vx; - Location *loc; - Item *it; - std::vector<Item *> *vit; - Assignment *a; - std::vector<Assignment *> *va; - SpellBod *b; - std::vector<SpellBod *> *vb; - SpellGuard *g; - std::vector<SpellGuard *> *vg; -} // %union - -%expect 7 - -%token <s> INT -%token <s> STRING -%token <s> ID -%token <s> DIR - -%token '=' -%token '<' -%token '>' -%token '+' -%token '-' -%token '*' -%token '/' -%token '%' -%token '@' -%token ',' -%token '.' -%token ':' -%token ';' -%token '|' -%token '[' -%token ']' -%token '&' -%token '^' - -%token CONST -%token PROCEDURE -%token CALL -%token SILENT -%token LOCAL -%token NONMAGIC -%token SHL -%token SHR -%token EQ -%token NEQ -%token GTE -%token LTE -%token ANDAND -%token OROR -%token <s> SCRIPT_DATA -%token TO -%token TOWARDS -%token TELEPORT_ANCHOR -%token SPELL -%token LET -%token IN -%token END -%token DARROW -%token STRING_TY -%token REQUIRE -%token CATALYSTS -%token COMPONENTS -%token MANA -%token CASTTIME -%token SKIP -%token ABORT -%token BREAK -%token EFFECT_ -%token ATEND -%token ATTRIGGER -%token PC_F -%token NPC_F -%token MOB_F -%token ENTITY_F -%token TARGET_F -%token IF -%token THEN -%token ELSE -%token FOREACH -%token FOR -%token DO -%token SLEEP - -%type <s> value -%type <loc> location -%type <expr> area -%type <vx> arg_list -%type <vx> arg_list_ne -%type <va> defs -%type <spelldef> spelldef -%type <spellarg> argopt -%type <a> def -%type <vb> spellbody_list -%type <b> spellbody -%type <g> spellguard -%type <vg> spellguard_list -%type <g> prereq -%type <it> item -%type <vit> items -%type <vit> item_list -%type <s> item_name -%type <s> selection; -%type <e> effect -%type <ve> effect_list -%type <ve> maybe_trigger -%type <ve> maybe_end -%type <vs> spell_flags; - -%type <expr> expr -%type <s> arg_ty -%type <vs> proc_formals_list -%type <vs> proc_formals_list_ne - -%type <top> spellconf_option - -%left OROR -%left ANDAND -%left '<' '>' GTE LTE NEQ EQ -%left '+' '-' -%left '*' '/' '%' -%left SHL SHR '&' '^' '|' -%right '=' -%left OR -%left DARROW -%left '.' - -%% - -spellconf - -: /* empty */ - -| spellconf semicolons spellconf_option -{ - $3->dump(); -} - -; - - -semicolons - -: /* empty */ - -| semicolons ';' - -; - - -proc_formals_list - -: /* empty */ -{ - $$ = new std::vector<RString>(); -} - -| proc_formals_list_ne -{ - $$ = $1; -} - -; - - -proc_formals_list_ne - -: ID -{ - $$ = new std::vector<RString>(); - $$->push_back(*$1); -} - -| proc_formals_list_ne ',' ID -{ - $$ = $1; - $$->push_back(*$3); -} - -; - - -spellconf_option - -: ID '=' expr -{ - $$ = new Assignment{*$1, $3}; -} - -| CONST ID '=' expr -{ - $$ = new Constant{*$2, $4}; -} - -| TELEPORT_ANCHOR ID ':' expr '=' expr -{ - $$ = new Teleport{*$2, $4, $6}; -} - -| PROCEDURE ID '(' proc_formals_list ')' '=' effect_list -{ - $$ = new Procedure{*$2, $4, $7}; -} - -| spell_flags SPELL ID argopt ':' expr '=' spelldef -{ - $$ = new Spell{$1, *$3, $4, $6, $8}; -} - -; - - -spell_flags - -: /* empty */ -{ - $$ = new std::vector<RString>(); -} - -| spell_flags LOCAL -{ - $$ = $1; - $$->push_back("LOCAL"); -} - -| spell_flags NONMAGIC -{ - $$ = $1; - $$->push_back("NONMAGIC"); -} - -| spell_flags SILENT -{ - $$ = $1; - $$->push_back("SILENT"); -} - -; - - -argopt - -: /* empty */ -{ - $$ = new SpellArg{}; -} - -| '(' ID ':' arg_ty ')' -{ - $$ = new SpellArg{*$2, *$4}; -} - -; - - -arg_ty - -: PC_F -{ - $$ = new RString("PC"); -} - -| STRING_TY -{ - $$ = new RString("STRING"); -} - -; - - -value - -: DIR -{ - $$ = $1; -} - -| INT -{ - $$ = $1; -} - -| STRING -{ - $$ = $1; -} - -; - - -expr - -: value -{ - $$ = new SimpleExpr{*$1}; -} - -| ID -{ - $$ = new SimpleExpr{*$1}; -} - -| area -{ - $$ = $1; -} - -| expr '+' expr -{ - $$ = new BinExpr{$1, "+", $3}; -} - -| expr '-' expr -{ - $$ = new BinExpr{$1, "-", $3}; -} - -| expr '*' expr -{ - $$ = new BinExpr{$1, "*", $3}; -} - -| expr '%' expr -{ - $$ = new BinExpr{$1, "%", $3}; -} - -| expr '/' expr -{ - $$ = new BinExpr{$1, "/", $3}; -} - -| expr '<' expr -{ - $$ = new BinExpr{$1, "<", $3}; -} - -| expr '>' expr -{ - $$ = new BinExpr{$1, ">", $3}; -} - -| expr '&' expr -{ - $$ = new BinExpr{$1, "&", $3}; -} - -| expr '^' expr -{ - $$ = new BinExpr{$1, "^", $3}; -} - -| expr '|' expr -{ - $$ = new BinExpr{$1, "|", $3}; -} - -| expr SHL expr -{ - $$ = new BinExpr{$1, "<<", $3}; -} - -| expr SHR expr -{ - $$ = new BinExpr{$1, ">>", $3}; -} - -| expr LTE expr -{ - $$ = new BinExpr{$1, "<=", $3}; -} - -| expr GTE expr -{ - $$ = new BinExpr{$1, ">=", $3}; -} - -| expr ANDAND expr -{ - $$ = new BinExpr{$1, "&&", $3}; -} - -| expr OROR expr -{ - $$ = new BinExpr{$1, "||", $3}; -} - -| expr EQ expr -{ - $$ = new BinExpr{$1, "==", $3}; -} - -| expr '=' expr -{ - // convert to == - $$ = new BinExpr{$1, "==", $3}; -} - -| expr NEQ expr -{ - $$ = new BinExpr{$1, "!=", $3}; -} - -| ID '(' arg_list ')' -{ - $$ = new CallExpr{*$1, $3}; -} - -| '(' expr ')' -{ - $$ = $2; -} - -| expr '.' ID -{ - $$ = new BinExpr{$1, ".", new SimpleExpr(*$3)}; -} - -; - - -arg_list - -: /* empty */ -{ - $$ = new std::vector<Expression *>(); -} - -| arg_list_ne -{ - $$ = $1; -} - -; - - -arg_list_ne - -: expr -{ - $$ = new std::vector<Expression *>(); - $$->push_back($1); -} - -| arg_list_ne ',' expr -{ - $$ = $1; - $$->push_back($3); -} - -; - - -location - -: '@' '(' expr ',' expr ',' expr ')' -{ - $$ = new Location{$3, $5, $7}; -} - -; - - -area - -: location -{ - $$ = new AreaLoc{$1}; -} - -| location '@' '+' '(' expr ',' expr ')' -{ - $$ = new AreaRect{$1, $5, $7}; -} - -| location TOWARDS expr ':' '(' expr ',' expr ')' -{ - $$ = new AreaBar{$1, $3, $6, $8}; -} - -; - - -spelldef - -: spellbody_list -{ - $$ = new SpellDef{new std::vector<Assignment *>{}, $1}; -} - -| LET defs IN spellbody_list -{ - $$ = new SpellDef{$2, $4}; -} - -; - - -defs - -: semicolons -{ - $$ = new std::vector<Assignment *>(); -} - -| defs def semicolons -{ - $$ = $1; - $$->push_back($2); -} - -; - - -def - -: ID '=' expr -{ - $$ = new Assignment{*$1, $3}; -} - -; - - -spellbody_list - -: spellbody -{ - $$ = new std::vector<SpellBod *>(); - $$->push_back($1); -} - -| spellbody_list '|' spellbody -{ - $$ = $1; - $$->push_back($3); -} - -; - - -spellbody - -: spellguard DARROW spellbody -{ - $$ = new SpellBodGuarded{$1, $3}; -} - -| '(' spellbody_list ')' -{ - $$ = new SpellBodList{$2}; -} - -| EFFECT_ effect_list maybe_trigger maybe_end -{ - $$ = new SpellBodEffect{$2, $3, $4}; -} - -; - - -maybe_trigger - -: /* empty */ -{ - $$ = nullptr; -} - -| ATTRIGGER effect_list -{ - $$ = $2; -} - -; - - -maybe_end - -: /* empty */ -{ - $$ = nullptr; -} - -| ATEND effect_list -{ - $$ = $2; -} - -; - - -spellguard - -: prereq -{ - $$ = $1; -} - -| spellguard OR spellguard -{ - $$ = new SpellGuardOr($1, $3); -} - -| '(' spellguard_list ')' -{ - $$ = new SpellGuardList{$2}; -} - -; - - -spellguard_list - -: spellguard -{ - $$ = new std::vector<SpellGuard *>(); - $$->push_back($1); -} - -| spellguard_list ',' spellguard -{ - $$ = $1; - $$->push_back($3); -} - -; - - -prereq - -: REQUIRE expr -{ - $$ = new SpellGuardRequire{$2}; -} - -| CATALYSTS items -{ - $$ = new SpellGuardCatalysts{$2}; -} - -| COMPONENTS items -{ - $$ = new SpellGuardComponents{$2}; -} - -| MANA expr -{ - $$ = new SpellGuardMana{$2}; -} - -| CASTTIME expr -{ - $$ = new SpellGuardCasttime{$2}; -} - -; - - -items - -: '[' item_list ']' -{ - $$ = $2; -} - -; - - -item_list - -: item -{ - $$ = new std::vector<Item *>(); - $$->push_back($1); -} - -| item_list ',' item -{ - $$ = $1; - $$->push_back($3); -} - -; - - -item - -: INT '*' item_name -{ - $$ = new Item{*$1, *$3}; -} - -| item_name -{ - $$ = new Item{RString(), *$1}; -} - -; - - -item_name - -: STRING -{ - $$ = $1; -} - -| INT -{ - $$ = $1; -} - -; - - -selection - -: PC_F -{ - $$ = new RString{"PC"}; -} - -| MOB_F -{ - $$ = new RString{"MOB"}; -} - -| ENTITY_F -{ - $$ = new RString{"ENTITY"}; -} - -| SPELL -{ - $$ = new RString{"SPELL"}; -} - -| TARGET_F -{ - $$ = new RString{"TARGET"}; -} - -| NPC_F -{ - $$ = new RString{"NPC"}; -} - -; - - -effect - -: '(' effect_list ')' -{ - $$ = new EffectList{$2}; -} - -| SKIP ';' -{ - $$ = new SimpleEffect{"SKIP"}; -} - -| ABORT ';' -{ - $$ = new SimpleEffect{"ABORT"}; -} - -| END ';' -{ - $$ = new SimpleEffect{"END"}; -} - -| BREAK ';' -{ - $$ = new SimpleEffect{"BREAK"}; -} - -| ID '=' expr ';' -{ - $$ = new Assignment(*$1, $3); -} - -| FOREACH selection ID IN expr DO effect -{ - $$ = new ForeachEffect{*$2, *$3, $5, $7}; -} - -| FOR ID '=' expr TO expr DO effect -{ - $$ = new ForEffect{*$2, $4, $6, $8}; -} - -| IF expr THEN effect ELSE effect -{ - $$ = new IfEffect{$2, $4, $6}; -} - -| IF expr THEN effect -{ - $$ = new IfEffect{$2, $4}; -} - -| SLEEP expr ';' -{ - $$ = new SleepEffect{$2}; -} - -| ID '(' arg_list ')' ';' -{ - $$ = new CallExpr{*$1, $3}; -} - -| SCRIPT_DATA -{ - AString tmp = sexpr::escape(*$1); - $$ = new ScriptEffect{RString(tmp)}; -} - -| CALL ID '(' arg_list ')' ';' -{ - $$ = new ExplicitCallEffect{*$2, $4}; -} - -; - - -effect_list - -: /* empty */ -{ - $$ = new std::deque<Effect *>(); -} - -| effect semicolons effect_list -{ - // because of grammar problems, doing this right generates reduce/reduce conflicts - $$ = $3; - $$->push_front($1); -} - -; - - -%% -// Nothing to see here, move along diff --git a/src/strings/astring.cpp b/src/strings/astring.cpp index f1e9030..0906584 100644 --- a/src/strings/astring.cpp +++ b/src/strings/astring.cpp @@ -156,6 +156,13 @@ namespace strings special = 255 - x.size(); } } + AString::AString(LString l) + : data{}, special() + { + new(r_ptr()) RString(); + special = 255; + *this = XString(l); + } AString::iterator AString::begin() const { diff --git a/src/strings/astring.hpp b/src/strings/astring.hpp index aab14cf..b0fb196 100644 --- a/src/strings/astring.hpp +++ b/src/strings/astring.hpp @@ -49,12 +49,6 @@ namespace strings explicit AString(const MString& s); - template<size_t n> - AString(char (&s)[n]) = delete; - - template<size_t n> - AString(const char (&s)[n]); - template<class It> AString(It b, It e); @@ -66,6 +60,7 @@ namespace strings AString(XString); template<uint8_t n> AString(const VString<n>& v); + AString(LString s); iterator begin() const; iterator end() const; diff --git a/src/strings/astring.tcc b/src/strings/astring.tcc index ed07bd9..f9606d8 100644 --- a/src/strings/astring.tcc +++ b/src/strings/astring.tcc @@ -21,23 +21,6 @@ namespace strings { - template<size_t n> - AString::AString(const char (&s)[n]) - : data{}, special() - { - XPair x = s; - if (x.size() > 255 || x.size() == 0) - { - new(r_ptr()) RString(x); - special = 255; - } - else - { - *std::copy(x.begin(), x.end(), data) = '\0'; - special = 255 - x.size(); - } - } - template<class It> AString::AString(It b, It e) : data{}, special() diff --git a/src/strings/base_test.cpp b/src/strings/base_test.cpp index 52c44dc..524450d 100644 --- a/src/strings/base_test.cpp +++ b/src/strings/base_test.cpp @@ -31,18 +31,18 @@ using namespace strings; struct _test : VString<1> {}; struct _test2 : VString<1> {}; -static_assert(string_comparison_allowed<_test, _test>::value, "tt"); -static_assert(string_comparison_allowed<VString<1>, VString<1>>::value, "vv"); -static_assert(!string_comparison_allowed<_test, XString>::value, "tx"); -static_assert(!string_comparison_allowed<_test, VString<1>>::value, "tv"); -static_assert(!string_comparison_allowed<_test, _test2>::value, "t2"); -static_assert(string_comparison_allowed<VString<1>, XString>::value, "vx"); -static_assert(string_comparison_allowed<XString, XString>::value, "xx"); -static_assert(string_comparison_allowed<XString, RString>::value, "xf"); +static_assert(string_comparison_allowed<_test, _test>::value, "tt"_s); +static_assert(string_comparison_allowed<VString<1>, VString<1>>::value, "vv"_s); +static_assert(!string_comparison_allowed<_test, XString>::value, "tx"_s); +static_assert(!string_comparison_allowed<_test, VString<1>>::value, "tv"_s); +static_assert(!string_comparison_allowed<_test, _test2>::value, "t2"_s); +static_assert(string_comparison_allowed<VString<1>, XString>::value, "vx"_s); +static_assert(string_comparison_allowed<XString, XString>::value, "xx"_s); +static_assert(string_comparison_allowed<XString, RString>::value, "xf"_s); TEST(strings, contains) { - XString hi = "Hello"; - EXPECT_TRUE(hi.contains_any("Hi")); - EXPECT_FALSE(hi.contains_any("hi")); + XString hi = "Hello"_s; + EXPECT_TRUE(hi.contains_any("Hi"_s)); + EXPECT_FALSE(hi.contains_any("hi"_s)); } diff --git a/src/strings/fwd.hpp b/src/strings/fwd.hpp index 4c58e03..0e824c8 100644 --- a/src/strings/fwd.hpp +++ b/src/strings/fwd.hpp @@ -21,6 +21,7 @@ # include "../sanity.hpp" +# include <cstddef> # include <cstdint> // It is a common mistake to assume that one string class for everything. @@ -40,12 +41,18 @@ namespace strings class XString; // semi-owning + class LString; + class FormatString; template<uint8_t len> class VString; // refactor this into a function? enum _type_that_just_has_a_name_to_fix_linkage { really_construct_from_a_pointer }; + + LString operator "" _s(const char *, size_t); + constexpr + FormatString operator "" _fmt(const char *, size_t); } // namespace strings using strings::MString; @@ -57,6 +64,11 @@ using strings::SString; using strings::ZString; using strings::XString; +using strings::LString; +using strings::FormatString; using strings::VString; +using strings::operator "" _s; +using strings::operator "" _fmt; + #endif // TMWA_STRINGS_FWD_HPP diff --git a/src/spell-convert/main.cpp b/src/strings/literal.cpp index 0c0d04e..974a8bd 100644 --- a/src/spell-convert/main.cpp +++ b/src/strings/literal.cpp @@ -1,4 +1,5 @@ -// spell-convert/main.cpp - Hacky magic conversion driver. +#include "literal.hpp" +// strings/literal.cpp - A string stored in the readonly data segment. // // Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> // @@ -17,12 +18,39 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -#include "lexer.hpp" -#include "parser.hpp" - #include "../poison.hpp" -int main() +namespace strings { - spell_converterparse(); -} + LString::LString(const char *b, const char *e) + : _b(b), _e(e) + {} + + LString::iterator LString::begin() const + { + return _b; + } + LString::iterator LString::end() const + { + return _e; + } + const RString *LString::base() const + { + return nullptr; + } + const char *LString::c_str() const + { + return &*begin(); + } + + const char *decay_for_printf(const LString& zs) + { + return zs.c_str(); + } + + __attribute__((format(scanf, 2, 0))) + int do_vscan(LString in, const char *fmt, va_list ap) + { + return vsscanf(in.c_str(), fmt, ap); + } +} // namespace strings diff --git a/src/strings/literal.hpp b/src/strings/literal.hpp new file mode 100644 index 0000000..c5b9938 --- /dev/null +++ b/src/strings/literal.hpp @@ -0,0 +1,82 @@ +#ifndef TMWA_STRINGS_LITERAL_HPP +#define TMWA_STRINGS_LITERAL_HPP +// strings/literal.hpp - A string stored in the readonly data segment. +// +// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// 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/>. + +# include "../sanity.hpp" + +# include <cstring> + +# include "base.hpp" + +namespace strings +{ + /// A statically owned string that is guaranteed to be NUL-terminated. + /// This is a more permissive lifetime than anybody else has. + class LString : public _crtp_string<LString, AString, LPair> + { + iterator _b, _e; + // optional + const RString *_base; + private: + LString(const char *b, const char *e); + friend LString operator "" _s(const char *, size_t); + public: + + iterator begin() const; + iterator end() const; + const RString *base() const; + const char *c_str() const; + }; + + class FormatString + { + const char *_format; + + friend constexpr FormatString operator "" _fmt(const char *, size_t); + constexpr explicit + FormatString(const char *f) : _format(f) {} + public: + constexpr + const char *format_string() { return _format; } + }; + + + // cxxstdio helpers + // I think the conversion will happen automatically. TODO test this. + // Nope, it doesn't, since there's a template + // Actually, it might now. + const char *decay_for_printf(const LString& zs); + + __attribute__((format(scanf, 2, 0))) + int do_vscan(LString in, const char *fmt, va_list ap); + + inline + LString operator "" _s(const char *s, size_t) + { + return LString(s, s + __builtin_strlen(s)); + } + constexpr + FormatString operator "" _fmt(const char *s, size_t) + { + return FormatString(s); + } +} // namespace strings + +#endif // TMWA_STRINGS_LSTRING_HPP diff --git a/src/strings/pair.hpp b/src/strings/pair.hpp index a592a91..24537de 100644 --- a/src/strings/pair.hpp +++ b/src/strings/pair.hpp @@ -2,7 +2,7 @@ #define TMWA_STRINGS_PAIR_HPP // strings/pair.hpp - Internal contiguous range. // -// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com> +// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com> // // This file is part of The Mana World (Athena server) // @@ -40,12 +40,6 @@ namespace strings XPair(const char *b, const char *e) : _begin(b), _end(e) {} - template<size_t n> - XPair(char (&arr)[n]) = delete; - template<size_t n> - XPair(const char (&arr)[n]) - : _begin(arr), _end(arr + strlen(arr)) - {} const char *begin() const { return _begin; } const char *end() const { return _end; } @@ -59,11 +53,14 @@ namespace strings ZPair(const char *b, const char *e) : XPair(b, e) {} - template<size_t n> - ZPair(char (&arr)[n]) = delete; - template<size_t n> - ZPair(const char (&arr)[n]) - : XPair(arr) + }; + struct LPair : ZPair + { + typedef LString TailSlice; + typedef XString FullSlice; + + LPair(const char *b, const char *e) + : ZPair(b, e) {} }; } // namespace strings diff --git a/src/strings/rstring.cpp b/src/strings/rstring.cpp index c0e231e..671e7b0 100644 --- a/src/strings/rstring.cpp +++ b/src/strings/rstring.cpp @@ -125,6 +125,11 @@ namespace strings else _assign(x.begin(), x.end()); } + RString::RString(LString l) + : owned(nullptr) + { + *this = XString(l); + } RString::iterator RString::begin() const { diff --git a/src/strings/rstring.hpp b/src/strings/rstring.hpp index 7cb19d6..1de4db0 100644 --- a/src/strings/rstring.hpp +++ b/src/strings/rstring.hpp @@ -56,12 +56,6 @@ namespace strings explicit RString(const MString& s); - template<size_t n> - RString(char (&s)[n]) = delete; - - template<size_t n> - RString(const char (&s)[n]); - template<class It> RString(It b, It e); @@ -73,6 +67,7 @@ namespace strings RString(XString); template<uint8_t n> RString(const VString<n>& v); + RString(LString s); iterator begin() const; iterator end() const; diff --git a/src/strings/rstring.tcc b/src/strings/rstring.tcc index 8b4c0c0..6bfc7b0 100644 --- a/src/strings/rstring.tcc +++ b/src/strings/rstring.tcc @@ -47,12 +47,6 @@ namespace strings owned->body[diff] = '\0'; } - template<size_t n> - RString::RString(const char (&s)[n]) - { - _assign(s, s + strlen(s)); - } - template<class It> RString::RString(It b, It e) { diff --git a/src/strings/sstring.cpp b/src/strings/sstring.cpp index 76f0994..8de8655 100644 --- a/src/strings/sstring.cpp +++ b/src/strings/sstring.cpp @@ -54,6 +54,10 @@ namespace strings else *this = RString(x); } + SString::SString(const LString& l) + { + *this = XString(l); + } SString::SString(RString r, size_t b, size_t e) : _s(std::move(r)), _b(b), _e(e) diff --git a/src/strings/sstring.hpp b/src/strings/sstring.hpp index 7166e94..0594499 100644 --- a/src/strings/sstring.hpp +++ b/src/strings/sstring.hpp @@ -42,10 +42,7 @@ namespace strings SString(const XString&); template<uint8_t n> SString(const VString<n>& v); - template<size_t n> - SString(char (&s)[n]) = delete; - template<size_t n> - SString(const char (&s)[n]); + SString(const LString&); //template<class It> //SString(It b, It e) : _s(b, e), _b(0), _e(_s.size()) {} SString(RString f, size_t b, size_t e); diff --git a/src/strings/sstring.tcc b/src/strings/sstring.tcc index 4be33dd..89effbc 100644 --- a/src/strings/sstring.tcc +++ b/src/strings/sstring.tcc @@ -25,9 +25,4 @@ namespace strings SString::SString(const VString<n>& v) : _s(v), _b(0), _e(_s.size()) {} - - template<size_t n> - SString::SString(const char (&s)[n]) - : _s(s), _b(0), _e(_s.size()) - {} } // namespace strings diff --git a/src/strings/strings2_test.cpp b/src/strings/strings2_test.cpp index e5d5281..8c4a343 100644 --- a/src/strings/strings2_test.cpp +++ b/src/strings/strings2_test.cpp @@ -25,23 +25,23 @@ TEST(StringTests, traits2) { - ZString print_non = "\t\e"; - ZString print_mix = "n\t"; - RString print_all = "n "; + ZString print_non = "\t\e"_s; + ZString print_mix = "n\t"_s; + RString print_all = "n "_s; EXPECT_FALSE(print_non.has_print()); EXPECT_TRUE(print_mix.has_print()); EXPECT_TRUE(print_all.has_print()); EXPECT_FALSE(print_non.is_print()); EXPECT_FALSE(print_mix.is_print()); EXPECT_TRUE(print_all.is_print()); - EXPECT_EQ("__", print_non.to_print()); - EXPECT_EQ("n_", print_mix.to_print()); - EXPECT_EQ("n ", print_all.to_print()); + EXPECT_EQ("__"_s, print_non.to_print()); + EXPECT_EQ("n_"_s, print_mix.to_print()); + EXPECT_EQ("n "_s, print_all.to_print()); EXPECT_EQ(print_all.begin(), print_all.to_print().begin()); - ZString graph_non = " \e"; - ZString graph_mix = "n "; - RString graph_all = "n."; + ZString graph_non = " \e"_s; + ZString graph_mix = "n "_s; + RString graph_all = "n."_s; EXPECT_FALSE(graph_non.has_graph()); EXPECT_TRUE(graph_mix.has_graph()); EXPECT_TRUE(graph_all.has_graph()); @@ -49,37 +49,37 @@ TEST(StringTests, traits2) EXPECT_FALSE(graph_mix.is_graph()); EXPECT_TRUE(graph_all.is_graph()); - ZString lower_non = "0A"; - ZString lower_mix = "Oa"; - RString lower_all = "oa"; + ZString lower_non = "0A"_s; + ZString lower_mix = "Oa"_s; + RString lower_all = "oa"_s; EXPECT_FALSE(lower_non.has_lower()); EXPECT_TRUE(lower_mix.has_lower()); EXPECT_TRUE(lower_all.has_lower()); EXPECT_FALSE(lower_non.is_lower()); EXPECT_FALSE(lower_mix.is_lower()); EXPECT_TRUE(lower_all.is_lower()); - EXPECT_EQ("0a", lower_non.to_lower()); - EXPECT_EQ("oa", lower_mix.to_lower()); - EXPECT_EQ("oa", lower_all.to_lower()); + EXPECT_EQ("0a"_s, lower_non.to_lower()); + EXPECT_EQ("oa"_s, lower_mix.to_lower()); + EXPECT_EQ("oa"_s, lower_all.to_lower()); EXPECT_EQ(lower_all.begin(), lower_all.to_lower().begin()); - ZString upper_non = "0a"; - ZString upper_mix = "oA"; - RString upper_all = "OA"; + ZString upper_non = "0a"_s; + ZString upper_mix = "oA"_s; + RString upper_all = "OA"_s; EXPECT_FALSE(upper_non.has_upper()); EXPECT_TRUE(upper_mix.has_upper()); EXPECT_TRUE(upper_all.has_upper()); EXPECT_FALSE(upper_non.is_upper()); EXPECT_FALSE(upper_mix.is_upper()); EXPECT_TRUE(upper_all.is_upper()); - EXPECT_EQ("0A", upper_non.to_upper()); - EXPECT_EQ("OA", upper_mix.to_upper()); - EXPECT_EQ("OA", upper_all.to_upper()); + EXPECT_EQ("0A"_s, upper_non.to_upper()); + EXPECT_EQ("OA"_s, upper_mix.to_upper()); + EXPECT_EQ("OA"_s, upper_all.to_upper()); EXPECT_EQ(upper_all.begin(), upper_all.to_upper().begin()); - ZString alpha_non = " 0"; - ZString alpha_mix = "n "; - RString alpha_all = "nA"; + ZString alpha_non = " 0"_s; + ZString alpha_mix = "n "_s; + RString alpha_all = "nA"_s; EXPECT_FALSE(alpha_non.has_alpha()); EXPECT_TRUE(alpha_mix.has_alpha()); EXPECT_TRUE(alpha_all.has_alpha()); @@ -87,9 +87,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(alpha_mix.is_alpha()); EXPECT_TRUE(alpha_all.is_alpha()); - ZString digit2_non = "a9"; - ZString digit2_mix = "20"; - RString digit2_all = "01"; + ZString digit2_non = "a9"_s; + ZString digit2_mix = "20"_s; + RString digit2_all = "01"_s; EXPECT_FALSE(digit2_non.has_digit2()); EXPECT_TRUE(digit2_mix.has_digit2()); EXPECT_TRUE(digit2_all.has_digit2()); @@ -97,9 +97,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit2_mix.is_digit2()); EXPECT_TRUE(digit2_all.is_digit2()); - ZString digit8_non = "a9"; - ZString digit8_mix = "80"; - RString digit8_all = "37"; + ZString digit8_non = "a9"_s; + ZString digit8_mix = "80"_s; + RString digit8_all = "37"_s; EXPECT_FALSE(digit8_non.has_digit8()); EXPECT_TRUE(digit8_mix.has_digit8()); EXPECT_TRUE(digit8_all.has_digit8()); @@ -107,9 +107,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit8_mix.is_digit8()); EXPECT_TRUE(digit8_all.is_digit8()); - ZString digit10_non = "az"; - ZString digit10_mix = "a9"; - RString digit10_all = "42"; + ZString digit10_non = "az"_s; + ZString digit10_mix = "a9"_s; + RString digit10_all = "42"_s; EXPECT_FALSE(digit10_non.has_digit10()); EXPECT_TRUE(digit10_mix.has_digit10()); EXPECT_TRUE(digit10_all.has_digit10()); @@ -117,9 +117,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit10_mix.is_digit10()); EXPECT_TRUE(digit10_all.is_digit10()); - ZString digit16_non = "gz"; - ZString digit16_mix = "ao"; - RString digit16_all = "be"; + ZString digit16_non = "gz"_s; + ZString digit16_mix = "ao"_s; + RString digit16_all = "be"_s; EXPECT_FALSE(digit16_non.has_digit16()); EXPECT_TRUE(digit16_mix.has_digit16()); EXPECT_TRUE(digit16_all.has_digit16()); @@ -127,9 +127,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit16_mix.is_digit16()); EXPECT_TRUE(digit16_all.is_digit16()); - ZString alnum_non = " ."; - ZString alnum_mix = "n "; - RString alnum_all = "n0"; + ZString alnum_non = " ."_s; + ZString alnum_mix = "n "_s; + RString alnum_all = "n0"_s; EXPECT_FALSE(alnum_non.has_alnum()); EXPECT_TRUE(alnum_mix.has_alnum()); EXPECT_TRUE(alnum_all.has_alnum()); @@ -140,7 +140,7 @@ TEST(StringTests, traits2) TEST(StringTests, rempty) { - const char empty_text[] = ""; + LString empty_text = ""_s; RString r = empty_text; EXPECT_EQ(r.size(), 0); AString a = empty_text; @@ -166,7 +166,7 @@ TEST(StringTests, rempty) } TEST(StringTests, rshort) { - const char short_text[] = "0123456789"; + LString short_text = "0123456789"_s; RString r = short_text; EXPECT_EQ(r.size(), 10); AString a = short_text; @@ -193,13 +193,13 @@ TEST(StringTests, rshort) TEST(StringTests, rlong) { - const char long_text[] = + LString long_text = "01234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345 100" "01234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345 200" "01234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345 300"; + "0123456789012345678901234567890123456789012345 300"_s; RString r = long_text; EXPECT_EQ(r.size(), 300); AString a = long_text; diff --git a/src/strings/strings_test.cpp b/src/strings/strings_test.cpp index dca463d..3abb5e1 100644 --- a/src/strings/strings_test.cpp +++ b/src/strings/strings_test.cpp @@ -32,10 +32,10 @@ TYPED_TEST_CASE_P(StringTest); TYPED_TEST_P(StringTest, basic) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); - const char hi2[] = "Hello\0random garbage"; + LString hi2 = "Hello\0random garbage"_s; EXPECT_EQ(hi, hi2); TypeParam hi0; EXPECT_EQ(0, hi0.size()); @@ -47,9 +47,9 @@ TYPED_TEST_P(StringTest, basic) TYPED_TEST_P(StringTest, order) { TypeParam a; - TypeParam b("Hello"); - TypeParam c("Hello,"); - TypeParam d("World!"); + TypeParam b("Hello"_s); + TypeParam c("Hello,"_s); + TypeParam d("World!"_s); // not using EXPECT_LT, etc. for better visibility @@ -158,7 +158,7 @@ TYPED_TEST_P(StringTest, order) TYPED_TEST_P(StringTest, iterators) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(hi.begin(), hi.begin()); EXPECT_NE(hi.begin(), hi.end()); EXPECT_EQ(5, std::distance(hi.begin(), hi.end())); @@ -168,19 +168,19 @@ TYPED_TEST_P(StringTest, iterators) TYPED_TEST_P(StringTest, xslice) { - TypeParam hi("Hello, World!"); - EXPECT_EQ(" World!", hi.xslice_t(6)); - EXPECT_EQ("Hello,", hi.xslice_h(6)); - EXPECT_EQ("World!", hi.xrslice_t(6)); - EXPECT_EQ("Hello, ", hi.xrslice_h(6)); + TypeParam hi("Hello, World!"_s); + EXPECT_EQ(" World!"_s, hi.xslice_t(6)); + EXPECT_EQ("Hello,"_s, hi.xslice_h(6)); + EXPECT_EQ("World!"_s, hi.xrslice_t(6)); + EXPECT_EQ("Hello, "_s, hi.xrslice_h(6)); typename TypeParam::iterator it = std::find(hi.begin(), hi.end(), ' '); - EXPECT_EQ(" World!", hi.xislice_t(it)); - EXPECT_EQ("Hello,", hi.xislice_h(it)); - EXPECT_EQ("World", hi.xlslice(7, 5)); - EXPECT_EQ("World", hi.xpslice(7, 12)); - EXPECT_EQ("World", hi.xislice(hi.begin() + 7, hi.begin() + 12)); - EXPECT_TRUE(hi.startswith("Hello")); - EXPECT_TRUE(hi.endswith("World!")); + EXPECT_EQ(" World!"_s, hi.xislice_t(it)); + EXPECT_EQ("Hello,"_s, hi.xislice_h(it)); + EXPECT_EQ("World"_s, hi.xlslice(7, 5)); + EXPECT_EQ("World"_s, hi.xpslice(7, 12)); + EXPECT_EQ("World"_s, hi.xislice(hi.begin() + 7, hi.begin() + 12)); + EXPECT_TRUE(hi.startswith("Hello"_s)); + EXPECT_TRUE(hi.endswith("World!"_s)); } TYPED_TEST_P(StringTest, convert) @@ -188,15 +188,15 @@ TYPED_TEST_P(StringTest, convert) constexpr bool is_zstring = std::is_same<TypeParam, ZString>::value; typedef typename std::conditional<is_zstring, TString, SString>::type Sstring; typedef typename std::conditional<is_zstring, ZString, XString>::type Xstring; - RString r = "r"; - AString a = "a"; - TString t = "t"; - Sstring s = "s"; - ZString z = "z"; - Xstring x = "x"; - VString<255> v = "v"; - const char l[] = "l"; - VString<5> hi = "hello"; + RString r = "r"_s; + AString a = "a"_s; + TString t = "t"_s; + Sstring s = "s"_s; + ZString z = "z"_s; + Xstring x = "x"_s; + VString<255> v = "v"_s; + LString l = "l"_s; + VString<5> hi = "hello"_s; TypeParam r2 = r; TypeParam a2 = a; @@ -270,7 +270,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(StringStuff, StringTest, MostStringTypes); TEST(VStringTest, basic) { - VString<5> hi = "Hello"; + VString<5> hi = "Hello"_s; EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); // truncation @@ -278,7 +278,7 @@ TEST(VStringTest, basic) EXPECT_EQ(5, hi2.size()); EXPECT_EQ(hi, hi2); // short - hi = "hi"; + hi = "hi"_s; EXPECT_EQ(2, hi.size()); VString<5> hi0; EXPECT_EQ(0, hi0.size()); @@ -292,7 +292,7 @@ TYPED_TEST_CASE_P(NulStringTest); TYPED_TEST_P(NulStringTest, basic) { - TypeParam hi("hello"); + TypeParam hi("hello"_s); EXPECT_EQ(hi.size(), strlen(hi.c_str())); EXPECT_STREQ("hello", hi.c_str()); } diff --git a/src/strings/tstring.cpp b/src/strings/tstring.cpp index 5f463ca..27e8052 100644 --- a/src/strings/tstring.cpp +++ b/src/strings/tstring.cpp @@ -67,6 +67,10 @@ namespace strings else *this = RString(x); } + TString::TString(const LString& l) + { + *this = XString(l); + } TString::TString(XPair p) : _s(p), _o(0) diff --git a/src/strings/tstring.hpp b/src/strings/tstring.hpp index 7003d37..38f41cd 100644 --- a/src/strings/tstring.hpp +++ b/src/strings/tstring.hpp @@ -43,10 +43,7 @@ namespace strings TString(const XString&); template<uint8_t n> TString(const VString<n>& v); - template<size_t n> - TString(char (&s)[n]) = delete; - template<size_t n> - TString(const char (&s)[n]); + TString(const LString&); //template<class It> //TString(It b, It e) : _s(b, e), _o(0) {} TString(XPair p); diff --git a/src/strings/tstring.tcc b/src/strings/tstring.tcc index 4eba13f..c62987b 100644 --- a/src/strings/tstring.tcc +++ b/src/strings/tstring.tcc @@ -25,8 +25,4 @@ namespace strings TString::TString(const VString<n>& v) : _s(v), _o(0) {} - template<size_t n> - TString::TString(const char (&s)[n]) - : _s(s), _o(0) - {} } // namespace strings diff --git a/src/strings/vstring.hpp b/src/strings/vstring.hpp index 9952ff9..33dfb10 100644 --- a/src/strings/vstring.hpp +++ b/src/strings/vstring.hpp @@ -40,10 +40,7 @@ namespace strings VString(ZString z); template<uint8_t m> VString(VString<m> v); - template<size_t m> - VString(char (&s)[m]) = delete; - template<size_t m> - VString(const char (&s)[m]); + VString(LString l); VString(decltype(really_construct_from_a_pointer) e, const char *s); VString(char c); VString(); diff --git a/src/strings/vstring.tcc b/src/strings/vstring.tcc index 1aa163d..ac3dc19 100644 --- a/src/strings/vstring.tcc +++ b/src/strings/vstring.tcc @@ -76,11 +76,9 @@ namespace strings *this = XString(v); } template<uint8_t n> - template<size_t m> - VString<n>::VString(const char (&s)[m]) + VString<n>::VString(LString l) { - static_assert(m <= n + 1, "string would truncate"); - *this = XString(s); + *this = XString(l); } template<uint8_t n> VString<n>::VString(decltype(really_construct_from_a_pointer) e, const char *s) @@ -143,7 +141,7 @@ namespace strings char buffer[len + 1]; vsnprintf(buffer, len + 1, fmt, ap); - out = const_(buffer); + out = VString<len>(strings::really_construct_from_a_pointer, buffer); return len; } } // namespace strings diff --git a/src/strings/xstring.cpp b/src/strings/xstring.cpp index 0808104..5312445 100644 --- a/src/strings/xstring.cpp +++ b/src/strings/xstring.cpp @@ -40,6 +40,9 @@ namespace strings XString::XString(const ZString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) {} + XString::XString(const LString& s) + : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) + {} XString::XString(const char *b, const char *e, const RString *base_) : _b(b), _e(e), _base(base_) diff --git a/src/strings/xstring.hpp b/src/strings/xstring.hpp index 8f6eac5..ad7c40d 100644 --- a/src/strings/xstring.hpp +++ b/src/strings/xstring.hpp @@ -22,6 +22,7 @@ # include "../sanity.hpp" # include "base.hpp" +# include "literal.hpp" namespace strings { @@ -44,10 +45,7 @@ namespace strings XString(const ZString& s); template<uint8_t n> XString(const VString<n>& s); - template<size_t n> - XString(char (&s)[n]) = delete; - template<size_t n> - XString(const char (&s)[n]); + XString(const LString& s); // mostly internal XString(const char *b, const char *e, const RString *base_); XString(decltype(really_construct_from_a_pointer) e, const char *s, const RString *base_); diff --git a/src/strings/xstring.tcc b/src/strings/xstring.tcc index aee87f8..8115d23 100644 --- a/src/strings/xstring.tcc +++ b/src/strings/xstring.tcc @@ -25,8 +25,4 @@ namespace strings XString::XString(const VString<n>& s) : _b(&*s.begin()), _e(&*s.end()), _base(nullptr) {} - template<size_t n> - XString::XString(const char (&s)[n]) - : _b(s), _e(s + strlen(s)), _base(nullptr) - {} } // namespace strings diff --git a/src/strings/zstring.cpp b/src/strings/zstring.cpp index e2a763f..323ba5f 100644 --- a/src/strings/zstring.cpp +++ b/src/strings/zstring.cpp @@ -26,7 +26,7 @@ namespace strings { ZString::ZString() { - *this = ZString(""); + *this = ZString(""_s); } ZString::ZString(const RString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) @@ -37,6 +37,9 @@ namespace strings ZString::ZString(const TString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) {} + ZString::ZString(const LString& s) + : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) + {} ZString::ZString(const char *b, const char *e, const RString *base_) : _b(b), _e(e), _base(base_) {} diff --git a/src/strings/zstring.hpp b/src/strings/zstring.hpp index 717da88..c75c7c9 100644 --- a/src/strings/zstring.hpp +++ b/src/strings/zstring.hpp @@ -24,6 +24,7 @@ # include <cstring> # include "base.hpp" +# include "literal.hpp" namespace strings { @@ -45,13 +46,10 @@ namespace strings ZString(const XString&) = delete; template<uint8_t n> ZString(const VString<n>& s); + ZString(const LString& s); // dangerous ZString(const char *b, const char *e, const RString *base_); ZString(decltype(really_construct_from_a_pointer), const char *s, const RString *base_); - template<size_t n> - ZString(char (&s)[n]) = delete; - template<size_t n> - ZString(const char (&s)[n], const RString *base_=nullptr); iterator begin() const; iterator end() const; diff --git a/src/strings/zstring.tcc b/src/strings/zstring.tcc index fe0e9f3..3ff7374 100644 --- a/src/strings/zstring.tcc +++ b/src/strings/zstring.tcc @@ -27,9 +27,4 @@ namespace strings ZString::ZString(const VString<n>& s) : _b(&*s.begin()), _e(&*s.end()), _base(nullptr) {} - - template<size_t n> - ZString::ZString(const char (&s)[n], const RString *base_) - : _b(s), _e(s + strlen(s)), _base(base_) - {} } // namespace strings |