summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt70
-rw-r--r--src/engine.c3
-rw-r--r--src/fs.c6
-rw-r--r--src/librcc.c7
-rw-r--r--src/lng.c3
-rw-r--r--src/lngconfig.c4
-rw-r--r--src/rccconfig.c6
-rw-r--r--src/rccexternal.c40
-rw-r--r--src/rcciconv.c6
-rw-r--r--src/rcclocale.c15
-rw-r--r--src/rccmutex.c17
-rw-r--r--src/rccstring.c4
-rw-r--r--src/rcctranslate.c4
-rw-r--r--src/rccxml.c9
-rw-r--r--src/recode.c4
15 files changed, 186 insertions, 12 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..7477fd9
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,70 @@
+if (NOT WIN32)
+# SET(BUILD_SHARED_LIBS ON)
+endif (NOT WIN32)
+
+SET(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
+
+SET(HEADERS
+ librcc.h
+)
+
+SET(INTERNAL_HEADERS
+ internal.h
+ curconfig.h
+ engine.h
+ fs.h
+ lng.h
+ lngconfig.h
+ lngrecode.h
+ opt.h
+ plugin.h
+ rccconfig.h
+ rccdb4.h
+ rccenca.h
+ rccexternal.h
+ rcchome.h
+ rcciconv.h
+ rcclist.h
+ rcclocale.h
+ rcclock.h
+ rccmutex.h
+ rccspell.h
+ rccstring.h
+ rcctranslate.h
+ rccxml.h
+ recode.h
+)
+
+SET(rcc_SRCS
+ librcc.c
+ curconfig.c
+ engine.c
+ fs.c
+ lng.c
+ lngconfig.c
+ lngrecode.c
+ opt.c
+ plugin.c
+ rccconfig.c
+ rccdb4.c
+ rccenca.c
+ rccexternal.c
+ rcchome.c
+ rcciconv.c
+ rcclist.c
+ rcclocale.c
+ rcclock.c
+ rccmutex.c
+ rccspell.c
+ rccstring.c
+ rcctranslate.c
+ rccxml.c
+ recode.c
+ ${INTERNAL_HEADERS}
+ ${HEADERS}
+)
+
+ADD_LIBRARY(rcc ${rcc_SRCS})
+TARGET_LINK_LIBRARIES(rcc ${LIBXML2_LIBRARY} ${ICONV_LIBRARY} ${ENCA_LIBRARY} ${LIBRCD_LIBRARY} ${ZLIB_LIBRARY} ${WSOCK_LIBRARY})
diff --git a/src/engine.c b/src/engine.c
index caa1376..4d0add5 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -19,6 +19,9 @@
#include <stdio.h>
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "internal.h"
#include "plugin.h"
diff --git a/src/fs.c b/src/fs.c
index 182a217..2a63302 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -83,7 +83,13 @@ static char *rccCreateFullName(const char *path, const char *filename) {
static int rccIsFile(const char *filename) {
struct stat st;
+#ifdef HAVE_SYS_STAT_H
+# ifdef S_ISREG
if ((!stat(filename,&st))&&(S_ISREG(st.st_mode))) return 1;
+# else /* S_ISREG */
+ if (!stat(filename,&st)) return 1;
+# endif /* S_ISREG */
+#endif /* HAVE_SYS_STAT_H */
return 0;
}
diff --git a/src/librcc.c b/src/librcc.c
index c501b16..ec6aeb4 100644
--- a/src/librcc.c
+++ b/src/librcc.c
@@ -18,11 +18,16 @@
*/
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
+
#include "../config.h"
#ifdef HAVE_UNISTD_H
diff --git a/src/lng.c b/src/lng.c
index e1c5ea0..df9b2e9 100644
--- a/src/lng.c
+++ b/src/lng.c
@@ -19,6 +19,9 @@
#include <stdio.h>
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "internal.h"
#include "rccconfig.h"
diff --git a/src/lngconfig.c b/src/lngconfig.c
index ce7a7fb..aeb9636 100644
--- a/src/lngconfig.c
+++ b/src/lngconfig.c
@@ -20,7 +20,11 @@
#include <stdio.h>
#include <stdlib.h>
+
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "../config.h"
diff --git a/src/rccconfig.c b/src/rccconfig.c
index 5934e56..1f52ac3 100644
--- a/src/rccconfig.c
+++ b/src/rccconfig.c
@@ -18,7 +18,11 @@
*/
#include <stdio.h>
-#include <strings.h>
+
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "internal.h"
#include "rccconfig.h"
diff --git a/src/rccexternal.c b/src/rccexternal.c
index f1e8fba..aee6797 100644
--- a/src/rccexternal.c
+++ b/src/rccexternal.c
@@ -64,14 +64,19 @@
#define RCC_EXT_PROG_NAME "rccexternal"
#define RCC_EXTERNAL_TIMEOUT 250 /* 100us */
+#ifdef HAVE_UNISTD_H
static pid_t pid = (pid_t)-1;
static char *addr = NULL;
+#endif /* HAVE_UNISTD_H */
int rccExternalInit() {
-#ifdef HAVE_SIGNAL_H
+#ifdef HAVE_UNISTD_H
+# ifdef HAVE_SIGNAL_H
struct sigaction act;
+# endif /* HAVE_SIGNAL_H */
+# ifdef HAVE_SYS_STAT_H
struct stat st;
-#endif /* HAVE_SIGNAL_H */
+# endif /* HAVE_SYS_STAT_H */
if (pid != (pid_t)-1) return 0;
@@ -85,25 +90,32 @@ int rccExternalInit() {
if (pid == (pid_t)-1) return -1;
sprintf(addr,"%s/.rcc/comm/%lu.sock", rcc_home_dir, (unsigned long)pid);
-#ifdef HAVE_SIGNAL_H
+# ifdef HAVE_SIGNAL_H
act.sa_handler = SIG_IGN;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGPIPE,&act,NULL);
-#endif /* HAVE_SIGNAL_H */
+# endif /* HAVE_SIGNAL_H */
return 0;
}
/*if ((!stat("../external/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
execl ("../external/" RCC_EXT_PROG_NAME, RCC_EXT_PROG_NAME, NULL);
- } else*/ if ((!stat(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
+ } else*/
+# ifdef HAVE_SYS_STAT_H
+ if ((!stat(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
+# endif /* HAVE_SYS_STAT_H */
execl(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, RCC_EXT_PROG_NAME, NULL);
+# ifdef HAVE_SYS_STAT_H
}
+# endif /* HAVE_SYS_STAT_H */
+#endif /* HAVE_UNISTD_H */
exit(1);
}
void rccExternalFree() {
+#ifdef HAVE_UNISTD_H
int retry;
pid_t res;
struct timespec timeout = { 0, 5000000 };
@@ -122,9 +134,10 @@ void rccExternalFree() {
pid = (pid_t)-1;
if (addr) free(addr);
-
+#endif /* HAVE_UNISTD_H */
}
+#ifdef HAVE_SYS_SELECT_H
static int rccExternalSetDeadline(struct timeval *tv, unsigned long timeout) {
/*
gettimeofday(tv, NULL);
@@ -135,8 +148,10 @@ static int rccExternalSetDeadline(struct timeval *tv, unsigned long timeout) {
tv->tv_usec = (timeout + RCC_EXTERNAL_TIMEOUT) % 1000000;
return 0;
}
+#endif /* HAVE_SYS_SELECT_H */
size_t rccExternalWrite(int s, const char *buffer, ssize_t size, unsigned long timeout) {
+#ifdef HAVE_SYS_SELECT_H
int err;
unsigned char connected = 1;
ssize_t writed, res = 0;
@@ -158,9 +173,13 @@ size_t rccExternalWrite(int s, const char *buffer, ssize_t size, unsigned long t
}
return size - writed;
+#else /* HAVE_SYS_SELECT_H */
+ return -1;
+#endif /* HAVE_SYS_SELECT_H */
}
size_t rccExternalRead(int s, char *buffer, ssize_t size, unsigned long timeout) {
+#ifdef HAVE_SYS_SELECT_H
int err;
unsigned char connected = 1;
ssize_t readed, res = 0;
@@ -182,9 +201,13 @@ size_t rccExternalRead(int s, char *buffer, ssize_t size, unsigned long timeout)
}
return size - readed;
+#else /* HAVE_SYS_SELECT_H */
+ return -1;
+#endif /* HAVE_SYS_SELECT_H */
}
int rccExternalConnect(unsigned char module) {
+#ifdef HAVE_SYS_SOCKET_H
int err;
int retries = 10;
int sock;
@@ -241,14 +264,19 @@ again:
}
return sock;
+#else /* HAVE_SYS_SOCKET_H */
+ return -1;
+#endif /* HAVE_SYS_SOCKET_H */
}
void rccExternalClose(int s) {
+#ifdef HAVE_SYS_SOCKET_H
unsigned char cmd = 0;
if (s != -1) {
write(s, &cmd, 1);
close(s);
}
+#endif /* HAVE_SYS_SOCKET_H */
}
int rccExternalAllowOfflineMode() {
diff --git a/src/rcciconv.c b/src/rcciconv.c
index 28713fb..40c5b11 100644
--- a/src/rcciconv.c
+++ b/src/rcciconv.c
@@ -19,10 +19,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <errno.h>
#include <iconv.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
#include "internal.h"
#include "rcciconv.h"
diff --git a/src/rcclocale.c b/src/rcclocale.c
index fcd9a6d..b514e80 100644
--- a/src/rcclocale.c
+++ b/src/rcclocale.c
@@ -19,9 +19,14 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <locale.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
+
#include "../config.h"
#ifdef HAVE_LIBCHARSET
@@ -35,11 +40,17 @@
#include "rccconfig.h"
int rccLocaleGetClassByName(const char *locale) {
+#ifdef LC_CTYPE
if (!locale) return LC_CTYPE;
-
+
if (!strcmp(locale, "LC_CTYPE")) return LC_CTYPE;
+#endif /* LC_CTYPE */
+#ifdef LC_MESSAGES
if (!strcmp(locale, "LC_MESSAGES")) return LC_MESSAGES;
+#endif /* LC_MESSAGES */
+#ifdef LC_COLLATE
if (!strcmp(locale, "LC_COLLATE")) return LC_COLLATE;
+#endif /* LC_COLLATE */
/*
if (!strcmp(locale, "LC_ALL")) return LC_ALL;
if (!strcmp(locale, "LC_NUMERIC")) return LC_NUMERIC;
diff --git a/src/rccmutex.c b/src/rccmutex.c
index dce817a..5df962a 100644
--- a/src/rccmutex.c
+++ b/src/rccmutex.c
@@ -20,8 +20,17 @@
#include <stdlib.h>
#include <time.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#ifdef WIN32
+# include <windows.h>
+#endif /* WIN32 */
+
#include "rccmutex.h"
+
#define RCC_MUTEX_SLEEP 500
rcc_mutex rccMutexCreate() {
@@ -49,7 +58,9 @@ void rccMutexFree(rcc_mutex mutex) {
int rccMutexLock(rcc_mutex mutex) {
#ifndef HAVE_PTHREAD
+# ifdef HAVE_NANOSLEEP
struct timespec ts;
+# endif /* HAVE_NANOSLEEP */
#endif /* !HAVE_PTHREAD */
if (!mutex) return -1;
@@ -58,9 +69,15 @@ int rccMutexLock(rcc_mutex mutex) {
return pthread_mutex_lock(&mutex->mutex);
#else
while (mutex->mutex) {
+# if defined(HAVE_NANOSLEEP)
ts.tv_sec = RCC_MUTEX_SLEEP / 1000000;
ts.tv_nsec = (RCC_MUTEX_SLEEP % 1000000)*1000;
nanosleep(&ts, NULL);
+# elif defined (HAVE_USLEEP)
+ usleep(RCC_MUTEX_SLEEP);
+# elif defined (WIN32)
+ Sleep((RCC_MUTEX_SLEEP<1000)?1:RCC_MUTEX_SLEEP/1000);
+# endif /* HAVE_NANOSLEEP */
}
mutex->mutex = 1;
diff --git a/src/rccstring.c b/src/rccstring.c
index eee2ac2..e56c45d 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -19,7 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
+
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "../config.h"
diff --git a/src/rcctranslate.c b/src/rcctranslate.c
index cce76e1..aee027f 100644
--- a/src/rcctranslate.c
+++ b/src/rcctranslate.c
@@ -19,7 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
+
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "internal.h"
#include "rccconfig.h"
diff --git a/src/rccxml.c b/src/rccxml.c
index 1db5788..cc07fa9 100644
--- a/src/rccxml.c
+++ b/src/rccxml.c
@@ -18,9 +18,13 @@
*/
#include <stdio.h>
-#include <string.h>
#include <stdarg.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+
#include "../config.h"
#ifdef HAVE_UNISTD_H
@@ -467,7 +471,10 @@ clear:
}
xmlFreeDoc(doc);
}
+
+#ifdef HAVE_FSYNC
fsync(fd);
+#endif /* HAVE_FSYNC */
#if defined(HAVE_FLOCK)
flock(fd, LOCK_UN);
diff --git a/src/recode.c b/src/recode.c
index e1929b5..5529e42 100644
--- a/src/recode.c
+++ b/src/recode.c
@@ -19,7 +19,11 @@
#include <stdio.h>
#include <stdlib.h>
+
#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include "../config.h"