/* * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) * Copyright (c) 2019, 2020 Alex-David Denes * * uIRC 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 * any later version. * * uIRC 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 uIRC. If not, see . */ #include "../../assemblers/assemblers.h" // Assm_mesg() #include "../../tokenizers/tokenizers.h" // Tok_mesg() #include "../../types.h" // IRC_User #include "../common.h" // expect() #include // assert() #include // EXIT_SUCCESS int main(void) { const char* str[] = { ":buddy@hostnet.com PRIVMSG #general :login hunter12", "NOTICE * :nice cock bro", "@day=13;willtolive=0 PRIVMSG you :helo", ":mom!mother@localhost NOTICE #netadmin :johnny, your pizza is done" }; for (unsigned long i = 0; i < sizeof(str) / sizeof(*str); i++) { IRC_Message* m = NULL; if ((m = uirc_tokenizer_message(str[i])) == NULL) { printf("Failed to convert string to IRC_Message struct.\n"); return EXIT_FAILURE; } ssize_t ret; char buf[513]; if ((ret = uirc_assembler_message(buf, m, sizeof(buf) / sizeof(char))) <= 0) { printf("Failed to convert IRC_Message struct to a string. (%li)\n", ret); return EXIT_FAILURE; } size_t s1 = strlen(str[i]), s2 = strlen(buf); if (s1 != s2) { printf("String lenght doesn't match after parsing and assembly. Expected %li but got %li\n", s1, s2); return EXIT_FAILURE; } expect(buf, str[i]); print_irc_message(m); } return EXIT_SUCCESS; }