diff options
| author | trystan trystan@31f1291d-b8d6-0310-a050-a5561fc1590b <trystan trystan@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2005-02-06 19:18:15 +0000 |
|---|---|---|
| committer | trystan trystan@31f1291d-b8d6-0310-a050-a5561fc1590b <trystan trystan@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2005-02-06 19:18:15 +0000 |
| commit | 9b3a357193a020c53624b29f84e0bca4795722f0 (patch) | |
| tree | be1a500c8a469dad8164a72d1266780ac8c28510 /include | |
| parent | f8ac398b86ea6a26dba62064d9810796466e4118 (diff) | |
BUILD : 1.7.8 (565) BUGS : 293 NOTES : Merge of Win32 branch into the main, support for Unreal +I, German language updated, fixed bug vidents not updating, Setting and Removal of sqlines on forbid or drop
git-svn-id: svn://svn.anope.org/anope/trunk@567 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@417 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'include')
| -rw-r--r-- | include/commands.h | 4 | ||||
| -rw-r--r-- | include/datafiles.h | 2 | ||||
| -rw-r--r-- | include/extern.h | 28 | ||||
| -rw-r--r-- | include/makefile.win32 | 25 | ||||
| -rw-r--r-- | include/modules.h | 133 | ||||
| -rw-r--r-- | include/resource.h | 20 | ||||
| -rw-r--r-- | include/services.h | 65 | ||||
| -rw-r--r-- | include/sockets.h | 47 | ||||
| -rw-r--r-- | include/sysconf.h.win32 | 51 | ||||
| -rw-r--r-- | include/threads.h | 67 | ||||
| -rw-r--r-- | include/version.sh.c | 215 |
11 files changed, 598 insertions, 59 deletions
diff --git a/include/commands.h b/include/commands.h index 703842690..ec08a44a9 100644 --- a/include/commands.h +++ b/include/commands.h @@ -27,8 +27,8 @@ extern void help_cmd(char *service, User *u, Command *list, char *name); extern void do_run_cmd(char *service, User * u, Command *c,const char *cmd); extern void do_help_cmd(char *service, User * u, Command *c,const char *cmd); -extern void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); -extern void mod_run_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); +extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); +extern MDE void mod_run_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); extern char *mod_current_module_name; /*************************************************************************/ diff --git a/include/datafiles.h b/include/datafiles.h index 32f168ca1..e25b3416a 100644 --- a/include/datafiles.h +++ b/include/datafiles.h @@ -15,7 +15,9 @@ #ifndef DATAFILES_H #define DATAFILES_H +#ifndef _WIN32 #include <sys/param.h> +#endif /*************************************************************************/ diff --git a/include/extern.h b/include/extern.h index 410236363..40e275da2 100644 --- a/include/extern.h +++ b/include/extern.h @@ -17,7 +17,15 @@ #include "slist.h" +#ifndef _WIN32 #define E extern +#else +#ifndef MODULE_COMPILE +#define E extern __declspec(dllexport) +#else +#define E extern __declspec(dllimport) +#endif +#endif E char *uplink; @@ -200,7 +208,9 @@ E char *strerror(int errnum); #if !HAVE_STRSIGNAL char *strsignal(int signum); #endif - +#ifdef _WIN32 +char *sockstrerror(int error); +#endif /**** config.c ****/ @@ -660,7 +670,7 @@ E int process_numlist(const char *numstr, int *count_ret, range_callback_t callback, User * u, ...); E int isValidHost(const char *host, int type); -E int isvalidchar(char c); +E int isvalidchar(const char c); E char *myStrGetToken(const char *str, const char dilim, int token_number); E char *myStrGetOnlyToken(const char *str, const char dilim, @@ -877,14 +887,14 @@ E int32 total_read, total_written; E int32 read_buffer_len(void); E int32 write_buffer_len(void); -E int sgetc(int s); -E char *sgets(char *buf, int len, int s); -E char *sgets2(char *buf, int len, int s); -E int sread(int s, char *buf, int len); -E int sputs(char *str, int s); -E int sockprintf(int s, char *fmt, ...); +E int sgetc(ano_socket_t s); +E char *sgets(char *buf, int len, ano_socket_t s); +E char *sgets2(char *buf, int len, ano_socket_t s); +E int sread(ano_socket_t s, char *buf, int len); +E int sputs(char *str, ano_socket_t s); +E int sockprintf(ano_socket_t s, char *fmt, ...); E int conn(const char *host, int port, const char *lhost, int lport); -E void disconn(int s); +E void disconn(ano_socket_t s); /**** users.c ****/ diff --git a/include/makefile.win32 b/include/makefile.win32 new file mode 100644 index 000000000..b186c578c --- /dev/null +++ b/include/makefile.win32 @@ -0,0 +1,25 @@ +# Make file for Win32 +# +# (C) 2003-2005 Anope Team +# Contact us at info@anope.org +# +# Please read COPYING and README for further details. +# +# Based on the original code of Epona by Lara. +# Based on the original code of Services by Andy Church. +# +# $Id:$ +# + +########################################################################### + +clean: + -@erase language.h + +spotless: clean + -@erase sysconf.h version.h + +distclean: spotless + + +FRC: diff --git a/include/modules.h b/include/modules.h index 2a3025586..91bdb7a88 100644 --- a/include/modules.h +++ b/include/modules.h @@ -18,6 +18,34 @@ #include "services.h" #include <stdio.h> +/* Cross OS compatibility macros */ +#ifdef _WIN32 +typedef HMODULE ano_module_t; + +#define ano_modopen(file) LoadLibrary(file) +/* ano_moderr in modules.c */ +#define ano_modsym(file, symbol) (void *)GetProcAddress(file, symbol) +#define ano_modclose(file) FreeLibrary(file) ? 0 : 1 +#define ano_modclearerr() SetLastError(0) +#define MODULE_EXT ".dll" + +#else +typedef void * ano_module_t; + +#ifdef HAS_RTLD_LOCAL +#define ano_modopen(file) dlopen(file, RTLD_LAZY|RTLD_LOCAL) +#else +#define ano_modopen(file) dlopen(file, RTLD_LAZY) +#endif +#define ano_moderr() dlerror() +#define ano_modsym(file, symbol) dlsym(file, DL_PREFIX symbol) +#define ano_modclose(file) dlclose(file) +#define ano_modclearerr() errno = 0 +#define MODULE_EXT ".so" + +#endif + + /*************************************************************************/ #define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */ #define MAX_CMD_HASH 1024 @@ -53,7 +81,18 @@ #define MOD_ERR_NOSERVICE 12 #define MOD_ERR_NO_MOD_NAME 13 - /*************************************************************************/ +/*************************************************************************/ +/* Macros to export the Module API functions/variables */ +#ifndef _WIN32 +#define MDE +#else +#ifndef MODULE_COMPILE +#define MDE __declspec(dllexport) +#else +#define MDE __declspec(dllimport) +#endif +#endif +/*************************************************************************/ /* Structure for information about a *Serv command. */ @@ -66,14 +105,14 @@ typedef struct MessageHash_ MessageHash; typedef struct ModuleCallBack_ ModuleCallBack; -extern CommandHash *HOSTSERV[MAX_CMD_HASH]; -extern CommandHash *BOTSERV[MAX_CMD_HASH]; -extern CommandHash *MEMOSERV[MAX_CMD_HASH]; -extern CommandHash *NICKSERV[MAX_CMD_HASH]; -extern CommandHash *CHANSERV[MAX_CMD_HASH]; -extern CommandHash *HELPSERV[MAX_CMD_HASH]; -extern CommandHash *OPERSERV[MAX_CMD_HASH]; -extern MessageHash *IRCD[MAX_CMD_HASH]; +extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH]; +extern MDE CommandHash *BOTSERV[MAX_CMD_HASH]; +extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH]; +extern MDE CommandHash *NICKSERV[MAX_CMD_HASH]; +extern MDE CommandHash *CHANSERV[MAX_CMD_HASH]; +extern MDE CommandHash *HELPSERV[MAX_CMD_HASH]; +extern MDE CommandHash *OPERSERV[MAX_CMD_HASH]; +extern MDE MessageHash *IRCD[MAX_CMD_HASH]; struct Module_ { char *name; @@ -173,62 +212,62 @@ Module *findModule(char *name); /* Find a module */ int loadModule(Module *m,User *u); /* Load the given module into the program */ int unloadModule(Module *m, User *u); /* Unload the given module from the pro */ int prepForUnload(Module *m); /* Prepare the module for unload */ -void moduleAddVersion(char *version); -void moduleAddAuthor(char *author); +MDE void moduleAddVersion(char *version); +MDE void moduleAddAuthor(char *author); void modules_init(void); void modules_delayed_init(void); void moduleCallBackPrepForUnload(char *mod_name); -void moduleCallBackDeleteEntry(ModuleCallBack * prev); -char *moduleGetLastBuffer(void); -void moduleSetHelpHelp(void (*func) (User * u)); -void moduleDisplayHelp(int service, User *u); -void moduleSetHostHelp(void (*func) (User * u)); -void moduleSetOperHelp(void (*func) (User * u)); -void moduleSetBotHelp(void (*func) (User * u)); -void moduleSetMemoHelp(void (*func) (User * u)); -void moduleSetChanHelp(void (*func) (User * u)); -void moduleSetNickHelp(void (*func) (User * u)); -int moduleAddHelp(Command * c, int (*func) (User * u)); -int moduleAddRegHelp(Command * c, int (*func) (User * u)); -int moduleAddOperHelp(Command * c, int (*func) (User * u)); -int moduleAddAdminHelp(Command * c, int (*func) (User * u)); -int moduleAddRootHelp(Command * c, int (*func) (User * u)); +MDE void moduleCallBackDeleteEntry(ModuleCallBack * prev); +MDE char *moduleGetLastBuffer(void); +MDE void moduleSetHelpHelp(void (*func) (User * u)); +MDE void moduleDisplayHelp(int service, User *u); +MDE void moduleSetHostHelp(void (*func) (User * u)); +MDE void moduleSetOperHelp(void (*func) (User * u)); +MDE void moduleSetBotHelp(void (*func) (User * u)); +MDE void moduleSetMemoHelp(void (*func) (User * u)); +MDE void moduleSetChanHelp(void (*func) (User * u)); +MDE void moduleSetNickHelp(void (*func) (User * u)); +MDE int moduleAddHelp(Command * c, int (*func) (User * u)); +MDE int moduleAddRegHelp(Command * c, int (*func) (User * u)); +MDE int moduleAddOperHelp(Command * c, int (*func) (User * u)); +MDE int moduleAddAdminHelp(Command * c, int (*func) (User * u)); +MDE int moduleAddRootHelp(Command * c, int (*func) (User * u)); /*************************************************************************/ /*************************************************************************/ /* Command Managment Functions */ -Command *createCommand(const char *name,int (*func)(User *u),int (*has_priv)(User *u),int help_all, int help_reg, int help_oper, int help_admin,int help_root); -int destroyCommand(Command *c); /* destroy a command */ -int addCoreCommand(CommandHash *cmdTable[], Command *c); /* Add a command to a command table */ -int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos); -int addCommand(CommandHash *cmdTable[], Command *c,int pos); -int delCommand(CommandHash *cmdTable[], Command *c,char *mod_name); /* Del a command from a cmd table */ -int moduleDelCommand(CommandHash *cmdTable[],char *name); /* Del a command from a cmd table */ +MDE Command *createCommand(const char *name,int (*func)(User *u),int (*has_priv)(User *u),int help_all, int help_reg, int help_oper, int help_admin,int help_root); +MDE int destroyCommand(Command *c); /* destroy a command */ +MDE int addCoreCommand(CommandHash *cmdTable[], Command *c); /* Add a command to a command table */ +MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos); +MDE int addCommand(CommandHash *cmdTable[], Command *c,int pos); +MDE int delCommand(CommandHash *cmdTable[], Command *c,char *mod_name); /* Del a command from a cmd table */ +MDE int moduleDelCommand(CommandHash *cmdTable[],char *name); /* Del a command from a cmd table */ Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */ /*************************************************************************/ /*************************************************************************/ /* Message Managment Functions */ -Message *createMessage(char *name,int (*func)(char *source, int ac, char **av)); +MDE Message *createMessage(char *name,int (*func)(char *source, int ac, char **av)); Message *findMessage(MessageHash *msgTable[], const char *name); /* Find a Message */ -int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */ +MDE int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */ int addCoreMessage(MessageHash *msgTable[], Message *m); /* Add a Message to a Message table */ -int moduleAddMessage(Message *m, int pos); +MDE int moduleAddMessage(Message *m, int pos); int delMessage(MessageHash *msgTable[], Message *m, char *mod_name); /* Del a Message from a msg table */ -int moduleDelMessage(char *name); +MDE int moduleDelMessage(char *name); int destroyMessage(Message *m); /* destroy a Message*/ Message *findMessage(MessageHash *msgTable[], const char *name); /*************************************************************************/ -int moduleAddCallback(char *name,time_t when,int (*func)(int argc, char *argv[]),int argc, char **argv); -void moduleDelCallback(char *name); -void moduleCallBackRun(void); - -char *moduleGetData(ModuleData **md, char *key); /* Get the value for this key from this struct */ -int moduleAddData(ModuleData **md, char *key, char *value); /* Set the value for this key for this struct */ -void moduleDelData(ModuleData **md, char *key); /* Delete this key/value pair */ -void moduleDelAllData(ModuleData **md); /* Delete all key/value pairs for this module for this struct */ -void moduleCleanStruct(ModuleData **moduleData); /* Clean a moduleData hash */ +MDE int moduleAddCallback(char *name,time_t when,int (*func)(int argc, char *argv[]),int argc, char **argv); +MDE void moduleDelCallback(char *name); +MDE void moduleCallBackRun(void); + +MDE char *moduleGetData(ModuleData **md, char *key); /* Get the value for this key from this struct */ +MDE int moduleAddData(ModuleData **md, char *key, char *value); /* Set the value for this key for this struct */ +MDE void moduleDelData(ModuleData **md, char *key); /* Delete this key/value pair */ +MDE void moduleDelAllData(ModuleData **md); /* Delete all key/value pairs for this module for this struct */ +MDE void moduleCleanStruct(ModuleData **moduleData); /* Clean a moduleData hash */ void moduleDelAllDataMod(Module *m); /* remove all module data from all structs for this module */ int moduleDataDebug(ModuleData **md); /* Allow for debug output of a moduleData struct */ -boolean moduleMinVersion(int major,int minor,int patch,int build); /* Checks if the current version of anope is before or after a given verison */ +MDE boolean moduleMinVersion(int major,int minor,int patch,int build); /* Checks if the current version of anope is before or after a given verison */ /*************************************************************************/ diff --git a/include/resource.h b/include/resource.h new file mode 100644 index 000000000..2f3b54bfc --- /dev/null +++ b/include/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Win32GUI.rc +// +#define VER_ANOPE 1 +#define MANIFEST_RESOURCE_ID 2 +#define ICON_APP 129 + + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 152 +#define _APS_NEXT_COMMAND_VALUE 40061 +#define _APS_NEXT_CONTROL_VALUE 1167 +#define _APS_NEXT_SYMED_VALUE 104 +#endif +#endif diff --git a/include/services.h b/include/services.h index 4523e2e34..730c04f3d 100644 --- a/include/services.h +++ b/include/services.h @@ -37,24 +37,60 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> + +/* Windows does not have: + * unistd.h, grp.h, + * netdb.h, netinet/in.h, + * sys/socket.h, sys/time.h + * Windows requires: + * winsock.h + * -- codemastr + */ + +#ifndef _WIN32 #include <unistd.h> +#endif + #include <signal.h> #include <time.h> #include <errno.h> + +#ifndef _WIN32 #include <grp.h> +#endif + #include <limits.h> + +#ifndef _WIN32 #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/socket.h> +#else +#include <winsock.h> +#include <windows.h> +#endif + #include <sys/stat.h> /* for umask() on some systems */ #include <sys/types.h> + +#ifndef _WIN32 #include <sys/time.h> +#endif + +#ifdef _WIN32 +#include <sys/timeb.h> +#include <direct.h> +#include <io.h> +#endif + #include <fcntl.h> +#ifndef _WIN32 #ifdef HAVE_BACKTRACE #include <execinfo.h> #endif +#endif #ifdef USE_RDB # define MAX_SQL_BUF 4096 @@ -81,9 +117,14 @@ #endif #ifdef USE_THREADS -# include <pthread.h> + #ifndef _WIN32 + #include <pthread.h> + #endif +#include "threads.h" #endif +#include "sockets.h" + #ifdef _AIX /* Some AIX boxes seem to have bogus includes that don't have these * prototypes. */ @@ -119,6 +160,14 @@ extern int toupper(char), tolower(char); #define encrypt encrypt_ +#ifdef __WINS__ +#ifndef BKCHECK +#define BKCHECK + extern "C" void __pfnBkCheck() {} +#endif +#endif + + #if INTTYPE_WORKAROUND # undef int16 # undef int32 @@ -162,7 +211,20 @@ typedef struct uid_ Uid; /*************************************************************************/ +/* Windows defines a boolean type as an + * unsigned char. It does however need + * true/false. -- codemastr + */ +#ifndef _WIN32 typedef enum { false, true } boolean; +#else + #ifndef true + #define true 1 + #endif + #ifndef false + #define false 0 + #endif +#endif /* _WIN32 */ /*************************************************************************/ @@ -263,6 +325,7 @@ struct ircdvars_ { int invitemode; /* +I */ int sjoinbanchar; /* use single quotes to define it */ int sjoinexchar; /* use single quotes to define it */ + int sjoininvchar; /* use single quotes to define it */ int svsmode_ucmode; /* Can remove User Channel Modes with SVSMODE */ int sglineenforce; char *vhostchar; /* char used for vhosting */ diff --git a/include/sockets.h b/include/sockets.h new file mode 100644 index 000000000..e5ae27c58 --- /dev/null +++ b/include/sockets.h @@ -0,0 +1,47 @@ +/* + * + * (C) 2004 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef SOCKETS_H +#define SOCKETS_H + +#ifdef _WIN32 +typedef SOCKET ano_socket_t; +#define ano_sockread(fd, buf, len) recv(fd, buf, len, 0) +#define ano_sockwrite(fd, buf, len) send(fd, buf, len, 0) +#define ano_sockclose(fd) closesocket(fd) +#define ano_sockgeterr() WSAGetLastError() +#define ano_sockseterr(err) WSASetLastError(err) +/* ano_sockstrerror in sockutil.c */ +/* ano_socksetnonb in sockutil.c */ +#define ano_sockerrnonb(err) (err == WSAEINPROGRESS || err == WSAEWOULDBLOCK) +#define SOCKERR_EBADF WSAENOTSOCK +#define SOCKERR_EINTR WSAEINTR +#define SOCKERR_EINVAL WSAEINVAL +#define SOCKERR_EINPROGRESS WSAEINPROGRESS +#else +typedef int ano_socket_t; +#define ano_sockread(fd, buf, len) read(fd, buf, len) +#define ano_sockwrite(fd, buf, len) write(fd, buf, len) +#define ano_sockclose(fd) close(fd) +#define ano_sockgeterr() errno +#define ano_sockseterr(err) errno = err +#define ano_sockstrerror(err) strerror(err) +#define ano_socksetnonb(fd) fcntl(fd, F_SETFL, O_NONBLOCK) +#define ano_sockerrnonb(err) (err == EINPROGRESS) +#define SOCKERR_EBADF EBADF +#define SOCKERR_EINTR EINTR +#define SOCKERR_EINVAL EINVAL +#define SOCKERR_EINPROGRESS EINPROGRESS +#endif + +#endif diff --git a/include/sysconf.h.win32 b/include/sysconf.h.win32 new file mode 100644 index 000000000..e408f463f --- /dev/null +++ b/include/sysconf.h.win32 @@ -0,0 +1,51 @@ +
+#define SERVICES_DIR "data"
+#define SERVICES_BIN "services.exe"
+
+typedef signed __int16 int16;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16;
+typedef unsigned __int16 u_int16_t;
+typedef signed __int32 int32;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32;
+typedef unsigned __int32 u_int32_t;
+typedef unsigned __int8 u_int8_t;
+
+#define HAVE_STRINGS_H 0
+#define HAVE_SYS_SELECT_H 0
+#define HAVE_SYS_SYSPROTO_H 0
+
+#define HAVE_STRERROR 1
+#define HAVE_SYS_ERRLIST 0
+#define HAVE_SNPRINTF 1
+#define BAD_SNPRINTF 0
+#define HAVE_STRICMP 1
+#define HAVE_STRCASECMP 0
+#define HAVE_STRDUP 1
+#define HAVE_STRSPN 1
+#define HAVE_STRSIGNAL 0
+#define HAVE_GETTIMEOFDAY 0
+#define HAVE_SETGRENT 0
+#define HAVE_UMASK 0
+#define HAVE_FORK 0
+#define HAVE_GETHOSTBYNAME 1
+#define HAVE_BACKTRACE 0
+
+/* Enable Module support */
+#define USE_MODULES
+#define MODULE_PATH ".\\modules\\"
+
+/* Windows/MSVC likes to name things differently */
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define popen _popen
+#define pclose _pclose
+#define ftruncate _chsize
+#define PATH_MAX MAX_PATH
+#define MAXPATHLEN MAX_PATH
+#define bzero(buf, size) memset(buf, 0, size)
+#define strcasecmp stricmp
+#define sleep(x) Sleep(x*1000)
+
+
diff --git a/include/threads.h b/include/threads.h new file mode 100644 index 000000000..90694a625 --- /dev/null +++ b/include/threads.h @@ -0,0 +1,67 @@ +/* + * + * (C) 2004 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ + +#ifndef THREADS_H +#define THREADS_H + +#ifdef _WIN32 +typedef long ano_thread_t; +typedef HANDLE ano_mutex_t; +typedef HANDLE ano_cond_t; +typedef unsigned (__stdcall *ano_thread_start) (void *); +typedef struct +{ + ano_thread_start func; + void *arg; +} ano_cleanup_t; + +extern ano_thread_start __declspec(thread) cleanup_func; + +#define ano_thread_create(thread,start,arg) !_beginthreadex(NULL, 0, (ano_thread_start)start, arg, 0, &thread) +#define ano_thread_self() GetCurrentThreadId() +#define ano_thread_detach(thread) 0 +#define ano_mutex_lock(mutex) WaitForSingleObject(mutex, INFINITE) +#define ano_mutex_unlock(mutex) ReleaseMutex(mutex) + +/* ano_cond_wait is in compat.c */ +#define ano_cond_signal(cond) SetEvent(cond) + +/* very minimalistic implementation */ +#define ano_cleanup_push(func, arg) cleanup_func = (ano_thread_start)func +#define ano_cleanup_pop(execute) cleanup_func(NULL) + +#else + +typedef pthread_t ano_thread_t; +typedef pthread_mutex_t ano_mutex_t; +typedef pthread_cond_t ano_cond_t; +typedef void *(*ano_thread_start) (void *); + +#define ano_thread_create(thread,start,arg) pthread_create(&thread, NULL, start, arg) +#define ano_thread_self() pthread_self() +#define ano_thread_detach(thread) pthread_detach(thread) + +#define ano_mutex_lock(mutex) pthread_mutex_lock(&mutex) +#define ano_mutex_unlock(mutex) pthread_mutex_unlock(&mutex) + +#define ano_cond_wait(cond, mutex) pthread_cond_wait(&cond, &mutex) +#define ano_cond_signal(cond) pthread_cond_signal(&cond) + +#define ano_cleanup_push(func, arg) pthread_cleanup_push(func, arg) +#define ano_cleanup_pop(execute) pthread_cleanup_pop(execute) + +#define ano_thread_cancel(thread) pthread_cancel(thread) + +#endif + +#endif diff --git a/include/version.sh.c b/include/version.sh.c new file mode 100644 index 000000000..0332fddfe --- /dev/null +++ b/include/version.sh.c @@ -0,0 +1,215 @@ +/* version file handler for win32. + * + * (C) 2003 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * Written by Dominick Meglio <codemastr@unrealircd.com> + * + */ + +/* Needed due to Windows lack of a decent interpreter */ + +#include <stdio.h> +#include <string.h> + +#define CTRL "version.log" + +long version_major, version_minor, version_patch, version_build, build; +char *version_extra; +char version[1024]; + + +void load_ctrl(FILE *); +long get_value(char *); +char *get_value_str(char *); +char *strip(char *); +void parse_version(FILE *); +void write_version(FILE *); +void parse_line(FILE *, char *); + +int main() +{ + FILE *fd = fopen(CTRL, "r"); + + + if (!fd) { + fprintf(stderr, "Error: Unable to find control file: " CTRL "\n"); + exit(0); + } + + load_ctrl(fd); + fclose(fd); + + _snprintf(version, 1024, "%d.%d.%d%s", version_major, version_minor, + version_patch, version_extra ? version_extra : ""); + + + fd = fopen("version.h", "r"); + + if (fd) { + parse_version(fd); + fclose(fd); + } else + build = 1; + + + fd = fopen("version.h", "w"); + write_version(fd); + fclose(fd); +} + +void load_ctrl(FILE * fd) +{ + char buf[512]; + while (fgets(buf, 511, fd)) { + char *var; + + strip(buf); + + var = strtok(buf, "="); + if (!var) + continue; + if (!strcmp(var, "VERSION_MAJOR")) + version_major = get_value(strtok(NULL, "")); + else if (!strcmp(var, "VERSION_MINOR")) + version_minor = get_value(strtok(NULL, "")); + else if (!strcmp(var, "VERSION_PATCH")) + version_patch = get_value(strtok(NULL, "")); + else if (!strcmp(var, "VERSION_BUILD")) + version_build = get_value(strtok(NULL, "")); + else if (!strcmp(var, "VERSION_EXTRA")) + version_extra = get_value_str(strtok(NULL, "")); + + } +} + +char *strip(char *str) +{ + char *c; + if ((c = strchr(str, '\n'))) + *c = 0; + if ((c = strchr(str, '\r'))) + *c = 0; + return str; +} + +long get_value(char *string) +{ + return atol(get_value_str(string)); +} + +char *get_value_str(char *string) +{ + int len; + + if (*string == '"') + string++; + + len = strlen(string); + + if (string[len - 1] == '"') + string[len - 1] = 0; + if (!*string) + return NULL; + return string; +} + +void parse_version(FILE * fd) +{ + char buf[1024]; + + while (fgets(buf, 1023, fd)) { + char *para1; + + strip(buf); + para1 = strtok(buf, " \t"); + + if (!para1) + continue; + + if (!strcmp(para1, "#define")) { + char *para2 = strtok(NULL, " \t"); + + if (!para2) + continue; + + if (!strcmp(para2, "BUILD")) { + char *value = strtok(NULL, ""); + build = get_value(value); + build++; + return; + } + } + } + build = 1; +} + +void write_version(FILE * fd) +{ + FILE *fdin = fopen("include\\version.sh", "r"); + char buf[1024]; + short until_eof = 0; + + while (fgets(buf, 1023, fdin)) { + strip(buf); + + if (until_eof) + if (!strcmp(buf, "EOF")) + break; + else + parse_line(fd, buf); + + if (!strcmp(buf, "cat >version.h <<EOF")) + until_eof = 1; + } + +} + +void parse_line(FILE * fd, char *line) +{ + char *c; + for (c = line; *c; c++) { + /* It's a variable, find out which */ + if (*c == '$') { + char *var, *varbegin; + + if (*(c + 1)) + c++; + else + continue; + for (var = varbegin = c; var; var++) { + if (!isalnum(*var) && *var != '_') + break; + } + if (var != varbegin) { + char tmp = *var; + + *var = 0; + if (!strcmp(varbegin, "VERSION_MAJOR")) + fprintf(fd, "%d", version_major); + else if (!strcmp(varbegin, "VERSION_MINOR")) + fprintf(fd, "%d", version_minor); + else if (!strcmp(varbegin, "VERSION_PATCH")) + fprintf(fd, "%d", version_patch); + else if (!strcmp(varbegin, "VERSION_EXTRA")) { + if (version_extra) + fprintf(fd, "%s", version_extra); + } else if (!strcmp(varbegin, "VERSION_BUILD")) + fprintf(fd, "%d", version_build); + else if (!strcmp(varbegin, "BUILD")) + fprintf(fd, "%d", build); + else if (!strcmp(varbegin, "VERSION")) + fprintf(fd, "%s", version); + fputc(tmp, fd); + } + c = var; + } else + fputc(*c, fd); + } + fprintf(fd, "\r\n"); +} |
