summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorDusan Durech <dusan@debian.debian>2009-04-14 23:21:40 +0200
committerDusan Durech <dusan@debian.debian>2009-04-14 23:21:40 +0200
commit75e3e2c04b1d2b324dc8d2314e570bcba215c93f (patch)
tree9922d9ece567409e7f2cb999b44bac882aebe1bc /src/base
parent5772138044d95f931f285bbaf76a1faf67864e1e (diff)
new path API ( need old path.h )
Diffstat (limited to 'src/base')
-rw-r--r--src/base/arenaFile.c7
-rw-r--r--src/base/modules.c6
-rw-r--r--src/base/my_path.c110
-rw-r--r--src/base/my_path.h27
4 files changed, 148 insertions, 2 deletions
diff --git a/src/base/arenaFile.c b/src/base/arenaFile.c
index 45ba4ac..36b172a 100644
--- a/src/base/arenaFile.c
+++ b/src/base/arenaFile.c
@@ -16,6 +16,7 @@
#include "modules.h"
#include "archive.h"
#include "homeDirector.h"
+#include "my_path.h"
#ifndef PUBLIC_SERVER
# include "configFile.h"
@@ -371,13 +372,17 @@ static void load_arenaFromDirector(char *director)
void arena_file_init()
{
+ char path[STR_PATH_SIZE];
+
#ifndef PUBLIC_SERVER
assert(image_is_inicialized() == TRUE);
#endif
isArenaFileInit = TRUE;
listArenaFile = list_new();
- load_arenaFromDirector(PATH_ARENA);
+ path_set_prefix(path, STR_PATH_SIZE, PATH_PREFIX_ARENA, "");
+
+ load_arenaFromDirector(path);
#ifndef PUBLIC_SERVER
load_arenaFromDirector(home_director_get());
diff --git a/src/base/modules.c b/src/base/modules.c
index 7b0b7c2..ea4d450 100644
--- a/src/base/modules.c
+++ b/src/base/modules.c
@@ -16,6 +16,7 @@
#include "arenaFile.h"
#include "proto.h"
#include "shareFunction.h"
+#include "my_path.h"
#ifndef PUBLIC_SERVER
# include "interface.h"
@@ -123,7 +124,10 @@ static void unmapImage(void *image)
static void setModulePath(char *name, char *path)
{
- sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux
+ path_set_prefix(path, STR_PATH_SIZE, PATH_PREFIX_MODULE, name);
+ strcat(path, ".so");
+
+ //sprintf(path, PATH_MODULES "%s" MODULE_TYPE_UNIX, name); // linux
#ifdef __WIN32__
sprintf(path, PATH_MODULES "%s" MODULE_TYPE_WIN, name); // windows
#endif
diff --git a/src/base/my_path.c b/src/base/my_path.c
new file mode 100644
index 0000000..2cf25f8
--- /dev/null
+++ b/src/base/my_path.c
@@ -0,0 +1,110 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "main.h"
+#include "homeDirector.h"
+#include "textFile.h"
+#include "path.h"
+#include "my_path.h"
+
+static char *path_prefix;
+
+int path_init()
+{
+#if 0
+ char str[STR_PATH_SIZE];
+ textFile_t *text_file;
+
+ sprintf(str, "%s/path", home_director_get());
+
+ text_file = text_file_load(str);
+
+ if( text_file == NULL )
+ {
+ fprintf(stderr, "I dont load path\n");
+ exit(-1);
+ }
+
+ if( text_file->text->count == 0 )
+ {
+ fprintf(stderr, "%s is empty\n", str);
+ exit(-1);
+ }
+
+ path_prefix = strdup(text_file->text->list[0]);
+
+ text_file_destroy(text_file);
+
+#endif
+
+ path_prefix = malloc((strlen(PREFIX)+1)* sizeof(char));
+ strcpy(path_prefix, PREFIX);
+ strcat(path_prefix, "/");
+
+ printf("use prefix:%s\n", path_prefix);
+
+ return 0;
+}
+
+char* path_get_prefix()
+{
+ return path_prefix;
+}
+
+int path_set_prefix(char *path, int size, const char *subpath, const char *name)
+{
+ char *prefix;
+ char *slash;
+ int len;
+
+ prefix = path_prefix;
+
+/*
+ printf("subpath = %s\n", subpath);
+ printf("name = %s\n", name);
+*/
+ if( isFillPath(name) )
+ {
+ snprintf(path, size, "%s", name);
+ //printf("%s\n", path);
+ return 1;
+ }
+
+ if( isFillPath(subpath) )
+ {
+ snprintf(path, size, "%s", subpath);
+ //printf("%s\n", path);
+ return 1;
+ }
+
+ len = strlen(subpath);
+
+ slash = "/";
+
+ if( subpath[len-1] == '/' )
+ {
+ slash = "";
+ }
+
+/*
+ printf("slash = %s\n", slash);
+ printf("prefix = %s\n", prefix);
+*/
+ snprintf(path, size, "%s%s%s%s", prefix, subpath, slash, name);
+ //printf("file %s\n", path);
+
+ return 1;
+}
+
+int path_quit()
+{
+ if( path_prefix != NULL )
+ {
+ free(path_prefix);
+ }
+
+ return 0;
+}
diff --git a/src/base/my_path.h b/src/base/my_path.h
new file mode 100644
index 0000000..18e2c92
--- /dev/null
+++ b/src/base/my_path.h
@@ -0,0 +1,27 @@
+
+#ifndef MY_PATH_H
+
+#define MY_PATH_H
+
+#ifdef PUBLIC_SERVER
+#define PATH_PREFIX "share/tuxanci-server"
+#define PATH_PREFIX_MODULE "lib/tuxanci-server"
+#endif
+
+#ifndef PUBLIC_SERVER
+#define PATH_PREFIX "share/tuxanci"
+#define PATH_PREFIX_MODULE "lib/tuxanci"
+#endif
+
+#define PATH_PREFIX_IMAGE PATH_PREFIX "/images"
+#define PATH_PREFIX_ARENA PATH_PREFIX "/arena"
+#define PATH_PREFIX_MUSIC PATH_PREFIX "/music"
+#define PATH_PREFIX_SOUND PATH_PREFIX "/sound"
+
+extern int path_init();
+extern char* path_get_prefix();
+extern int path_set_prefix(char *path, int size, const char *subpath, const char *name);
+extern int path_quit();
+
+#endif
+