From 1f2baa2e7b90ea83c5a0c93598e22e5063fc6d95 Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 9 May 2012 11:47:38 +0200 Subject: [PATCH] added Makefile --- Makefile.am | 32 ++++++++++++++++ configure.ac | 69 ++++++++++++++++++++++++++++++++++ src/ConfigParser.c | 2 +- src/ConfigParser.h | 10 ++--- src/IOEngine_select.c | 2 +- src/IOHandler.c | 42 +++++++++++---------- src/IOHandler.h | 18 ++++----- src/ServerSocket.c | 24 ++++++------ src/UserClient.c | 26 +++++++++---- src/overall.h | 57 ++++++++++++++++++++++++++++ src/tools.c | 42 +++++++++++++++++++++ src/tools.h | 25 +++++++++++++ src/version.h | 32 ++++++++++++++++ src/version.sh | 86 +++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 410 insertions(+), 57 deletions(-) create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 src/tools.c create mode 100644 src/tools.h create mode 100644 src/version.h create mode 100644 src/version.sh diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..edd0e47 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,32 @@ +AUTOMAKE_OPTIONS = foreign +AM_CFLAGS = $(MYSQL_CFLAGS) + +BUILT_SOURCES = version.c +version.c: checkversion +checkversion: + cd src && chmod +x version.sh && ./version.sh && cd .. + +noinst_PROGRAMS = transirc + +transirc_SOURCES = src/version.c \ + src/ConfigParser.c \ + src/IOHandler.c \ + src/IOEngine_select.c \ + src/main.c \ + src/ServerSocket.c \ + src/tools.c \ + src/UserClient.c + +transirc_LDADD = $(MYSQL_LIBS) $(SYSTEM_LIBS) + +install-exec-local: + $(INSTALL) -d -m 755 $(prefix) + $(INSTALL) -m 644 $(srcdir)/AUTHORS $(prefix) + $(INSTALL) -m 644 $(srcdir)/COPYING $(prefix) + $(INSTALL) -m 644 $(srcdir)/INSTALL $(prefix) + $(INSTALL) -m 644 $(srcdir)/VERSION $(prefix) + $(INSTALL) -m 744 ./transirc $(prefix) + @echo + @echo TransparentIRC-$(VERSION) has been installed to $(prefix) + @echo Edit the transirc.example.conf and save it as transirc.conf before you start! + @echo diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..61224de --- /dev/null +++ b/configure.ac @@ -0,0 +1,69 @@ +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.67]) +AC_INIT([TransparentIRC], [0.1], [bugs@pk910.de], [transirc], [http://no.url]) +AC_PREFIX_DEFAULT([~/transirc]) +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE([foreign subdir-objects]) +AM_SILENT_RULES([yes]) +AC_CONFIG_HEADERS([config.h]) + +LT_INIT([disable-static]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_AWK + +# Checks for libraries. +# Get MySQL library and include locations +AC_ARG_WITH([mysql], + [AS_HELP_STRING([--with-mysql=DIR], + [location of the MySQL headers, defaults to /usr/include/mysql])], + [MYSQL_CFLAGS="-I$withval"], + [MYSQL_CFLAGS='-I/usr/include/mysql']) +AC_SUBST([MYSQL_CFLAGS]) + +AC_ARG_WITH([mysql-lib], + [AS_HELP_STRING([--with-mysql-lib=DIR], [location of the MySQL libraries])], + [MYSQL_LIBS="-L$withval -lmysqlclient"], + [MYSQL_LIBS='-lmysqlclient']) +AC_SUBST([MYSQL_LIBS]) + +AC_ARG_WITH([winsock], + [AS_HELP_STRING([--with-winsock], [use winsock (WIN32 systems)])], + [SYSTEM_LIBS='-lws2_32'], + [SYSTEM_LIBS='-ldl']) +AC_SUBST([SYSTEM_LIBS]) + +do_have_ssl="no"; +AC_CHECK_LIB(ssl, SSL_read, [ + AC_CHECK_LIB(crypto, X509_new, [ + AC_CHECK_HEADERS(openssl/ssl.h openssl/err.h openssl/rand.h, [ + do_have_ssl="yes"; + ]) + ]) +]) + +if test x"$do_have_ssl" = xyes; then + LIBS="$LIBS -lssl -lcrypto" + AC_DEFINE([HAVE_SSL], 1, [Define if you are using SSL]) +fi + +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug], [debug mode (compile using -O0 -Wall -Wshadow -Werror)])], + [CFLAGS='-g -O0 -Wall -Wshadow -Werror'], + [CFLAGS='-g -O2']) + +CFLAGS="$CFLAGS -D_GNU_SOURCE" + +# Checks for header files. +AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h windows.h winsock2.h]) + +# Checks for typedefs, structures, and compiler characteristics. + +# Checks for library functions. +AC_FUNC_MALLOC +AC_CHECK_FUNCS([gethostbyname memset select socket strchr strdup strstr]) + +AC_CONFIG_FILES(Makefile) +AC_OUTPUT \ No newline at end of file diff --git a/src/ConfigParser.c b/src/ConfigParser.c index 03eccaf..32b1d8c 100644 --- a/src/ConfigParser.c +++ b/src/ConfigParser.c @@ -14,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include "ConfigParser.h" +#include "tools.h" #define ENTRYTYPE_BLOCK 1 #define ENTRYTYPE_STRING 2 diff --git a/src/ConfigParser.h b/src/ConfigParser.h index 0f2776d..f4853b5 100644 --- a/src/ConfigParser.h +++ b/src/ConfigParser.h @@ -1,4 +1,4 @@ -/* ConfigParser.h - NeonServ v5.4 +/* ConfigParser.h - TransparentIRC 0.1 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -17,13 +17,11 @@ #ifndef _ConfigParser_h #define _ConfigParser_h -#include "main.h" +#include "overall.h" -#ifndef DND_FUNCTIONS int loadConfig(const char *filename); -/* MODULAR ACCESSIBLE */ int get_int_field(char *field_path); -/* MODULAR ACCESSIBLE */ char *get_string_field(char *field_path); +int get_int_field(char *field_path); +char *get_string_field(char *field_path); char **get_all_fieldnames(char *block_path); void free_loaded_config(); #endif -#endif diff --git a/src/IOEngine_select.c b/src/IOEngine_select.c index af919c2..dabe2e6 100644 --- a/src/IOEngine_select.c +++ b/src/IOEngine_select.c @@ -70,7 +70,7 @@ static void engine_select_loop(struct timeval *timeout) { tdiff.tv_sec--; tdiff.tv_usec += 1000000; //1 sec } - if(timeval_is_smaler(&tdiff, timeout)) { + if(timeval_is_smaler((&tdiff), timeout)) { timeout->tv_sec = tdiff.tv_sec; timeout->tv_usec = tdiff.tv_usec; } diff --git a/src/IOHandler.c b/src/IOHandler.c index 127a99e..b276272 100644 --- a/src/IOHandler.c +++ b/src/IOHandler.c @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include "IOHandler.h" +#include "IOEngine.h" struct IODescriptor *first_descriptor = NULL; @@ -25,16 +27,16 @@ struct IOEngine *engine = NULL; static void iohandler_init_engine() { //try other engines - if(engine) + if(engine) { //found an useable IO engine - else if (engine_select.init()) + } else if (engine_select.init()) engine = &engine_select; else { //STDERR: found no useable IO engine } } -struct IODescriptor *iohandler_add(int sockfd, IOType type, iohandler_callback *callback) { +struct IODescriptor *iohandler_add(int sockfd, enum IOType type, iohandler_callback *callback) { //just add a new IODescriptor struct IODescriptor *descriptor = calloc(1, sizeof(*descriptor)); if(!descriptor) return NULL; @@ -43,12 +45,12 @@ struct IODescriptor *iohandler_add(int sockfd, IOType type, iohandler_callback * descriptor->state = IO_CLOSED; descriptor->callback = callback; if(type != IOTYPE_TIMER) { - descriptor->readbuf.buffer = malloc(IOREADBUFLEN + 2); + descriptor->readbuf.buffer = malloc(IO_READ_BUFLEN + 2); descriptor->readbuf.bufpos = 0; - descriptor->readbuf.buflen = IOREADBUFLEN; - descriptor->writebuf.buffer = malloc(IOREADBUFLEN + 2); + descriptor->readbuf.buflen = IO_READ_BUFLEN; + descriptor->writebuf.buffer = malloc(IO_READ_BUFLEN + 2); descriptor->writebuf.bufpos = 0; - descriptor->writebuf.buflen = IOREADBUFLEN; + descriptor->writebuf.buflen = IO_READ_BUFLEN; } if(!engine) { @@ -62,7 +64,8 @@ struct IODescriptor *iohandler_add(int sockfd, IOType type, iohandler_callback * //add IODescriptor to the list descriptor->prev = NULL; descriptor->next = first_descriptor; - first_descriptor->prev = descriptor; + if(first_descriptor) + first_descriptor->prev = descriptor; first_descriptor = descriptor; return descriptor; @@ -93,7 +96,7 @@ static void iohandler_increase_iobuf(struct IOBuffer *iobuf, size_t required) { } } -struct IODescriptor *iohandler_timer(timeval timeout, iohandler_callback *callback) { +struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback *callback) { struct IODescriptor *descriptor; descriptor = iohandler_add(-1, IOTYPE_TIMER, callback); if(!descriptor) return NULL; @@ -102,7 +105,7 @@ struct IODescriptor *iohandler_timer(timeval timeout, iohandler_callback *callba return descriptor; } -struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, const char *bind, iohandler_callback *callback) { +struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, const char *bindhost, iohandler_callback *callback) { //non-blocking connect int sockfd; struct addrinfo hints, *res, *freeres; @@ -141,7 +144,7 @@ struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, ip6->sin6_port = htons(port); struct sockaddr_in6 *ip6vhost = NULL; - if (bind && !getaddrinfo(bind, NULL, &hints, &res)) { + if (bindhost && !getaddrinfo(bindhost, NULL, &hints, &res)) { while (res) { switch (res->ai_family) { case AF_INET6: @@ -168,7 +171,7 @@ struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, ip4->sin_port = htons(port); struct sockaddr_in *ip4vhost = NULL; - if (bind && !getaddrinfo(bind, NULL, &hints, &res)) { + if (bindhost && !getaddrinfo(bindhost, NULL, &hints, &res)) { while (res) { switch (res->ai_family) { case AF_INET: @@ -199,7 +202,6 @@ struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, /* I hope you're using the Win32 backend or something else that * automatically marks the file descriptor non-blocking... */ - (void)flags; #endif descriptor = iohandler_add(sockfd, IOTYPE_CLIENT, callback); if(!descriptor) { @@ -210,6 +212,7 @@ struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, descriptor->state = IO_CONNECTING; descriptor->read_lines = 1; engine->update(descriptor); + return descriptor; } struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, iohandler_callback *callback) { @@ -275,7 +278,6 @@ struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, i /* I hope you're using the Win32 backend or something else that * automatically marks the file descriptor non-blocking... */ - (void)flags; #endif descriptor = iohandler_add(sockfd, IOTYPE_SERVER, callback); if(!descriptor) { @@ -285,6 +287,7 @@ struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, i listen(sockfd, 1); descriptor->state = IO_LISTENING; engine->update(descriptor); + return descriptor; } void iohandler_write(struct IODescriptor *iofd, const char *line) { @@ -300,6 +303,7 @@ void iohandler_send(struct IODescriptor *iofd, const char *data, size_t datalen) return; } memcpy(iofd->writebuf.buffer + iofd->writebuf.bufpos, data, datalen); + iofd->writebuf.bufpos += datalen; engine->update(iofd); } @@ -366,9 +370,9 @@ void iohandler_events(struct IODescriptor *iofd, int readable, int writeable) { if(readable) { //could not connect callback_event.type = IOEVENT_NOTCONNECTED; socklen_t arglen; - arglen = sizeof(callback_event.errno); - if (getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &callback_event.errno, &arglen) < 0) - callback_event.data.errno = errno; + arglen = sizeof(callback_event.data.errid); + if (getsockopt(iofd->fd, SOL_SOCKET, SO_ERROR, &callback_event.data.errid, &arglen) < 0) + callback_event.data.errid = errno; iofd->state = IO_CLOSED; } else if(writeable) { callback_event.type = IOEVENT_CONNECTED; @@ -383,10 +387,10 @@ void iohandler_events(struct IODescriptor *iofd, int readable, int writeable) { if(bytes <= 0) { if (errno != EAGAIN) { callback_event.type = IOEVENT_CLOSED; - callback_event.data.errno = errno; + callback_event.data.errid = errno; } } else { - int i, used_bytes = 0, buffer_offset = 0; + int i, used_bytes = 0; iofd->readbuf.bufpos += bytes; callback_event.type = IOEVENT_RECV; for(i = 0; i < iofd->readbuf.bufpos; i++) { diff --git a/src/IOHandler.h b/src/IOHandler.h index 34e49d4..7d33ce2 100644 --- a/src/IOHandler.h +++ b/src/IOHandler.h @@ -44,21 +44,21 @@ enum IOEventType { IOEVENT_READABLE, /* socket is readable - not read anything yet, could also be disconnect notification */ IOEVENT_RECV, /* client socket received something (recv_str valid) */ IOEVENT_CONNECTED, /* client socket connected successful */ - IOEVENT_NOTCONNECTED, /* client socket could not connect (errno valid) */ - IOEVENT_CLOSED, /* client socket lost connection (errno valid) */ + IOEVENT_NOTCONNECTED, /* client socket could not connect (errid valid) */ + IOEVENT_CLOSED, /* client socket lost connection (errid valid) */ IOEVENT_ACCEPT, /* server socket accepted new connection (accept_fd valid) */ IOEVENT_TIMEOUT /* timer timed out */ }; struct IOBuffer { - char buffer; + char *buffer; size_t bufpos, buflen; }; struct IODescriptor { int fd; - IOType type; - IOStatus state; + enum IOType type; + enum IOStatus state; struct timeval timeout; iohandler_callback *callback; struct IOBuffer readbuf; @@ -70,17 +70,17 @@ struct IODescriptor { }; struct IOEvent { - IOEventType type; + enum IOEventType type; struct IODescriptor *iofd; union { char *recv_str; int accept_fd; - int errno; + int errid; } data; }; -struct IODescriptor *iohandler_add(int sockfd, IOType type, iohandler_callback *callback); -struct IODescriptor *iohandler_timer(timeval timeout, iohandler_callback *callback); +struct IODescriptor *iohandler_add(int sockfd, enum IOType type, iohandler_callback *callback); +struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback *callback); struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, const char *bind, iohandler_callback *callback); struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, iohandler_callback *callback); void iohandler_write(struct IODescriptor *iofd, const char *line); diff --git a/src/ServerSocket.c b/src/ServerSocket.c index 0bdec2c..b09e36c 100644 --- a/src/ServerSocket.c +++ b/src/ServerSocket.c @@ -25,13 +25,16 @@ static void serversocket_callback(struct IOEvent *event); static struct ServerSocket *serversocket_create(struct IODescriptor *iofd) { struct ServerSocket *sock = malloc(sizeof(*sock)); sock->iofd = iofd; + iofd->data = sock; sock->clientcount = 0; //add ServerSocket to the list sock->prev = NULL; sock->next = serversockets; - serversockets->prev = sock; + if(serversockets) + serversockets->prev = sock; serversockets = sock; + return sock; } static void serversocket_delete(struct ServerSocket *server) { @@ -46,11 +49,9 @@ static void serversocket_delete(struct ServerSocket *server) { struct ServerSocket *serversocket_listen(char *hostname, int port) { struct IODescriptor *iofd = iohandler_listen(hostname, port, serversocket_callback); - if(iofd) { - struct ServerSocket *server = serversocket_create(iofd); - return server; - } - return NULL; + if(!iofd) return NULL; + struct ServerSocket *server = serversocket_create(iofd); + return server; } void serversocket_close(struct ServerSocket *server, int keep_clients) { @@ -60,15 +61,12 @@ void serversocket_close(struct ServerSocket *server, int keep_clients) { } static void serversocket_callback(struct IOEvent *event) { + struct ServerSocket *server = event->iofd->data; switch(event->type) { case IOEVENT_ACCEPT: - struct ServerSocket *server = NULL; - for(server = serversockets; server; server = server->next) { - if(server->iofd == event->iofd) - break; - } - if(server) - userclient_accepted(server, event->accept_fd) + userclient_accepted(server, event->data.accept_fd); + break; + default: break; } } diff --git a/src/UserClient.c b/src/UserClient.c index c0d3af5..fccf56b 100644 --- a/src/UserClient.c +++ b/src/UserClient.c @@ -14,8 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "UserClient.c" +#include "UserClient.h" #include "IOHandler.h" +#include "ServerSocket.h" static void userclient_callback(struct IOEvent *event); @@ -30,14 +31,16 @@ void userclient_accepted(struct ServerSocket *server, int sockfd) { iohandler_update(iofd); client = malloc(sizeof(*client)); client->iofd = iofd; + iofd->data = client; client->server = server; server->clientcount++; //add UserClient to the list - sock->prev = NULL; - sock->next = serversockets; - serversockets->prev = sock; - serversockets = sock; + client->prev = NULL; + client->next = userclients; + if(userclients) + userclients->prev = client; + userclients = client; //let's say hello to the client iohandler_printf(iofd, "NOTICE AUTH :*** TransparentIRC " TRANSIRC_VERSION " (use /quote transirc for more information)"); @@ -58,6 +61,7 @@ void userclient_close(struct UserClient *client) { void userclient_close_server(struct ServerSocket *server, int keep_clients) { struct UserClient *client, *next_client; for(client = userclients; client; client = next_client) { + next_client = client->next; if(client->server == server) { if(keep_clients) client->server = NULL; @@ -67,14 +71,20 @@ void userclient_close_server(struct ServerSocket *server, int keep_clients) { } } +static void userclient_recv(struct UserClient *client, char *line) { + iohandler_printf(client->iofd, "reply: %s", line); +} + static void userclient_callback(struct IOEvent *event) { + struct UserClient *client = event->iofd->data; switch(event->type) { case IOEVENT_RECV: - char *line = event->data.recv_str; - iohandler_printf(event->iofd, "reply: %s", line); + userclient_recv(client, event->data.recv_str); break; case IOEVENT_CLOSED: - userclient_close(event->iofd); + userclient_close(client); + break; + default: break; } } diff --git a/src/overall.h b/src/overall.h index 8797932..7345c79 100644 --- a/src/overall.h +++ b/src/overall.h @@ -20,11 +20,68 @@ #include "../config.h" #define TRANSIRC_VERSION "0.1" +#define VERSION_PATCHLEVEL 0 #define IO_READ_BUFLEN 1024 #define IO_MAX_TIMEOUT 10 #define LINELEN 512 +#include +#include +#include +#include +#ifdef WIN32 +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#include +#include +#include +#include +#include +#include + +#if __GNUC__ +#define PRINTF_LIKE(M,N) __attribute__((format (printf, M, N))) +#else +#define PRINTF_LIKE(M,N) +#endif + +#if __GNUC__ >= 2 +#define UNUSED_ARG(ARG) ARG __attribute__((unused)) +#elif defined(S_SPLINT_S) +#define UNUSED_ARG(ARG) /*@unused@*/ ARG +#define const /*@observer@*/ /*@temp@*/ +#else +#define UNUSED_ARG(ARG) ARG +#endif + +#define STRINGIFY_(x) #x +#define STRINGIFY(x) STRINGIFY_(x) + +#if defined(__GNUC__) +#if defined(__GNUC_PATCHLEVEL__) +#define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) "." STRINGIFY(__GNUC_PATCHLEVEL__) +#else +#define COMPILER "GCC" " " STRINGIFY(__GNUC__) "." STRINGIFY(__GNUC_MINOR__) +#endif +#elif defined (__IMAGECRAFT__) +#define COMPILER "ICCAVR" +#else +#define COMPILER "Unknown" +#endif + #define timeval_is_bigger(x,y) ((x->tv_sec > y->tv_sec) || (x->tv_sec == y->tv_sec && x->tv_usec > y->tv_usec)) #define timeval_is_smaler(x,y) ((x->tv_sec < y->tv_sec) || (x->tv_sec == y->tv_sec && x->tv_usec < y->tv_usec)) diff --git a/src/tools.c b/src/tools.c new file mode 100644 index 0000000..6478279 --- /dev/null +++ b/src/tools.c @@ -0,0 +1,42 @@ +/* tools.c - TransparentIRC 0.1 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * 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 . + */ +#include "tools.h" + +int stricmp(const char *s1, const char *s2) { + if (s1 == NULL) return s2 == NULL ? 0 : -(*s2); + if (s2 == NULL) return *s1; + char c1, c2; + while ((c1 = tolower (*s1)) == (c2 = tolower (*s2))) { + if (*s1 == '\0') break; + ++s1; ++s2; + } + return c1 - c2; +} + +int stricmplen(const char *s1, const char *s2, int len) { + if (s1 == NULL) return s2 == NULL ? 0 : -(*s2); + if (s2 == NULL) return *s1; + char c1, c2; + int i = 0; + while ((c1 = tolower (*s1)) == (c2 = tolower (*s2))) { + i++; + if (*s1 == '\0') break; + ++s1; ++s2; + if(i == len) break; + } + return c1 - c2; +} \ No newline at end of file diff --git a/src/tools.h b/src/tools.h new file mode 100644 index 0000000..4f4d11e --- /dev/null +++ b/src/tools.h @@ -0,0 +1,25 @@ +/* tools.h - TransparentIRC 0.1 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * 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 . + */ + +#ifndef _tools_h +#define _tools_h +#include "overall.h" + +int stricmp(const char *s1, const char *s2); +int stricmplen(const char *s1, const char *s2, int len); + +#endif diff --git a/src/version.h b/src/version.h new file mode 100644 index 0000000..3cb06be --- /dev/null +++ b/src/version.h @@ -0,0 +1,32 @@ +/* version.h - TransparentIRC 0.1 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * 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 . + */ +#ifndef _version_h +#define _version_h +#include "overall.h" + +extern const char *compilation; +extern const char *creation; +extern const char *revision; +extern const char *codelines; +extern const int patchlevel; + +const char *get_compilation(); +const char *get_creation(); +const char *get_revision(); +const char *get_codelines(); +const int get_patchlevel(); +#endif diff --git a/src/version.sh b/src/version.sh new file mode 100644 index 0000000..6cfa2a0 --- /dev/null +++ b/src/version.sh @@ -0,0 +1,86 @@ +#! /bin/sh +echo "Extracting version.c ..." + +if test -r version.c +then + compilation=`sed -n 's/^const char \*compilation = \"\(.*\)\";/\1/p' < version.c` + if test ! "$compilation" ; then compilation=0; fi +else + compilation=0 +fi + +compilation=`expr $compilation + 1` + +creation=`date | \ +awk '{if (NF == 6) \ + { print $1 " " $2 " " $3 " " $6 " at " $4 " " $5 } \ +else \ + { print $1 " " $2 " " $3 " " $7 " at " $4 " " $5 " " $6 }}'` + +codelines=`find . -type f -regex '\./.*\.h' -or -regex '\./.*\.c' |xargs cat|wc -l` + +svn_revision=`svn info | grep Revision | grep -o -E '[0-9]+'` +git_commitcount=0 +if test "x$svn_revision" = "x" ; then + svn_revision=`git log -n 1 --pretty="format:%h"` + if test "x$svn_revision" = "x" ; then + svn_revision="0" + else + git_commitcount=`git log --pretty=oneline --no-merges --first-parent | wc -l | sed "s/[ \t]//g"` + svn_revision="git-$git_commitcount-$svn_revision" + fi +else + svn_revision="svn-$svn_revision" +fi + + +/bin/cat > version.c <. + */ +//Auto generated file! + +#include "version.h" + +const char *compilation = "$compilation"; +const char *creation = "$creation"; +const char *revision = "$svn_revision"; +const char *codelines = "$codelines"; + +const int patchlevel = ($git_commitcount ? ($git_commitcount - VERSION_PATCHLEVEL) : 0); + +const char *get_compilation() { + return compilation; +} + +const char *get_creation() { + return creation; +} + +const char *get_revision() { + return revision; +} + +const char *get_codelines() { + return codelines; +} + +const int get_patchlevel() { + return patchlevel; +} + +!SUB!THIS! + -- 2.20.1