Add list and fix some stuff

This commit is contained in:
Alex D. 2021-01-07 11:49:06 +00:00
parent b669fc1e54
commit 619c2e4125
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
5 changed files with 94 additions and 33 deletions

View File

@ -1,28 +1,65 @@
cmake_minimum_required(VERSION 3.16)
project(irc-toolkit LANGUAGES C)
project(
irc-toolkit
VERSION 2021.01.07
DESCRIPTION "IRC Protocol helpers"
LANGUAGES C
)
include(GNUInstallDirs)
OPTION(CODE_ANALYZER "Analyze the code statically" OFF)
OPTION(CODE_COVERAGE "Build with coverage tools" OFF)
find_library(UIRC_PATH NAMES uirc REQUIRED)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Wformat-overflow=2 -Wformat-security -Winit-self -Wstrict-overflow=2 -Wstringop-overflow=2 -Walloc-zero -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wparentheses -pedantic -fanalyzer -fstack-check)
add_compile_options(
-Wall
-Wextra
-Wformat-overflow=2
-Wformat-security
-Winit-self
-Wstrict-overflow=2
-Wstringop-overflow=2
-Walloc-zero
-Wduplicated-branches
-Wduplicated-cond
-Wtrampolines
-Wfloat-equal
-Wshadow
-Wunsafe-loop-optimizations
-Wparentheses
-fstack-check
-pedantic
)
if (CODE_ANALYZER)
add_compile_options(-fanalyzer)
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Weverything -pedantic -Wno-padded -Wno-disabled-macro-expansion)
add_compile_options(
-Weverything
-Wno-padded
-Wno-disabled-macro-expansion
-pedantic
)
if (CODE_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
endif()
if (CODE_ANALYZER)
add_compile_options(--analyze)
endif()
endif()
OPTION(CMAKE_BUILD_TYPE "Debug")
if (CMAKE_BUILD_TYPE EQUAL "Debug")
set(COMPILE_OPTIONS "${COMPILE_OPTIONS} -Og")
elseif (CMAKE_BUILD_TYPE EQUAL "Release")
set(COMPILE_OPTIONS "${COMPILE_OPTIONS} -O2 -Werror")
endif()
find_library(UIRC_PATH NAMES uirc libuirc REQUIRED)
macro(buildtool source)
add_executable(${source} ${source}.c common.c)
target_link_libraries(${source} ${UIRC_PATH})
set_property(TARGET ${source} PROPERTY C_STANDARD 99)
install(TARGETS ${source} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS ${source} RUNTIME)
endmacro()
buildtool(formatirc)
buildtool(joinpart)
buildtool(irc-list)
buildtool(irc-events)
buildtool(irc-messages)

View File

@ -5,8 +5,7 @@
#include <time.h>
#define UIRC_IRCV3
#include "uirc/functions.h"
#include "uirc/types.h"
#include "uirc/uirc.h"
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
@ -15,9 +14,6 @@
#define ANSI_COLOR_GRAY "\x1b[90m"
#define ANSI_COLOR_RESET "\x1b[0m"
#define UIRC_IRCV3
#include "uirc/types.h"
extern char* mIRC_COLORS[16];
ssize_t get_buffer_line(char* buf, IRC_Message* parsed);
void print_local_time(const char* irc_time);

View File

@ -4,10 +4,6 @@
#include <unistd.h>
#include "common.h"
#define UIRC_IRCV3
#include "uirc/functions.h"
#include "uirc/mappings.h"
#include "uirc/types.h"
int main(void)
{

35
irc-list.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
int main(void)
{
ssize_t bread = 1, tok;
size_t pos = 0;
char buffer[513];
IRC_Message out;
for (; bread > 0;) {
if ((tok = get_buffer_line(buffer, &out)) > 0) {
if (out.cmd == RPL_LISTSTART || out.cmd == RPL_LIST) {
printf(ANSI_COLOR_YELLOW "%s" ANSI_COLOR_RESET "\nTopic: %s\nUsers: %s\n", out.args[1], out.args[3], out.args[2]);
print_local_time(out.tags.time.value);
putchar('\n');
} else if (out.cmd == RPL_LISTEND) {
printf(ANSI_COLOR_RED "----- END" ANSI_COLOR_RESET "\n");
}
for (long unsigned int x = 0; x < sizeof(buffer) && *(buffer + tok + x); x++) *(buffer + x) = *(buffer + x + tok);
pos -= (unsigned long)tok;
*(buffer + pos) = '\0';
memset(&out, '\0', sizeof(out));
continue;
}
if ((bread = read(0, buffer + pos, sizeof(buffer) - 1 - pos)) > 0) {
pos += (size_t)bread;
buffer[pos] = '\0';
}
}
return 0;
}

View File

@ -4,10 +4,6 @@
#include <unistd.h>
#include "common.h"
#define UIRC_IRCV3
#include "uirc/functions.h"
#include "uirc/mappings.h"
#include "uirc/types.h"
int main(void)
{
@ -18,13 +14,14 @@ int main(void)
for (; bread > 0;) {
if ((tok = get_buffer_line(buffer, &out)) > 0) {
if (out.cmd == PRIVMSG || out.cmd == NOTICE) {
printf((out.name.nick != NULL) ? ANSI_COLOR_RED "%s" ANSI_COLOR_RESET : ANSI_COLOR_GRAY "%s" ANSI_COLOR_RESET,
(out.name.nick != NULL) ? out.name.nick : "unknown");
putchar('/');
if (out.args[0] != NULL) {
printf(ANSI_COLOR_YELLOW "%s" ANSI_COLOR_RESET,
printf(strchr("#+&!", *out.args[0]) != NULL ? ANSI_COLOR_YELLOW "%s" ANSI_COLOR_RESET
: ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET,
strchr("#+&!", *out.args[0]) != NULL ? out.args[0] : "direct");
}
putchar('/');
printf((out.name.nick != NULL) ? ANSI_COLOR_RED "%s" ANSI_COLOR_RESET : ANSI_COLOR_GRAY "%s" ANSI_COLOR_RESET,
(out.name.nick != NULL) ? out.name.nick : "unknown");
if (out.args[1] != NULL) printf(": %s", out.args[1]);
print_local_time(out.tags.time.value);
putchar('\n');