summaryrefslogtreecommitdiff
path: root/plugins/ao
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-05-07 11:22:41 +0200
committerGravatar waker <wakeroid@gmail.com>2011-05-07 11:22:41 +0200
commitda5345e0386a9f6fa182545a4334b03cf8ccc33c (patch)
tree57d9a2cc78ea6eb24f00f4c179bc70890aec9c6f /plugins/ao
parente773e777343ce971d80c55522b293d83cddae478 (diff)
ao: fixed reading aux psf libs from archives
Diffstat (limited to 'plugins/ao')
-rwxr-xr-xplugins/ao/ao.h2
-rw-r--r--plugins/ao/eng_dsf/eng_dsf.c14
-rw-r--r--plugins/ao/eng_psf/eng_psf.c45
-rw-r--r--plugins/ao/eng_psf/eng_psf2.c14
-rw-r--r--plugins/ao/eng_qsf/eng_qsf.c14
-rw-r--r--plugins/ao/eng_ssf/eng_ssf.c14
-rw-r--r--plugins/ao/main.c18
-rw-r--r--plugins/ao/plugin.c2
8 files changed, 36 insertions, 87 deletions
diff --git a/plugins/ao/ao.h b/plugins/ao/ao.h
index 87a1b00c..a737efa6 100755
--- a/plugins/ao/ao.h
+++ b/plugins/ao/ao.h
@@ -226,4 +226,6 @@ int ao_decode (uint32 type, void *handle, int16 *buffer, uint32 size);
int ao_command (uint32 type, void *handle, int32 command, int32 param);
+void ao_getlibpath (const char *path, const char *libname, char *libpath, int size);
+
#endif // AO_H
diff --git a/plugins/ao/eng_dsf/eng_dsf.c b/plugins/ao/eng_dsf/eng_dsf.c
index 6cab9509..af814dc0 100644
--- a/plugins/ao/eng_dsf/eng_dsf.c
+++ b/plugins/ao/eng_dsf/eng_dsf.c
@@ -69,19 +69,7 @@ void *dsf_start(const char *path, uint8 *buffer, uint32 length)
{
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, libfile);
- }
- else {
- strcpy (libpath, libfile);
- }
+ ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath));
#if DEBUG_LOADER
printf("Loading library: %s\n", libpath);
diff --git a/plugins/ao/eng_psf/eng_psf.c b/plugins/ao/eng_psf/eng_psf.c
index 8b12c777..268c8968 100644
--- a/plugins/ao/eng_psf/eng_psf.c
+++ b/plugins/ao/eng_psf/eng_psf.c
@@ -64,6 +64,23 @@ static void spu_update (unsigned char* pSound,long lBytes,void *data)
memcpy(s->spu_pOutput, pSound, lBytes);
}
+void
+ao_getlibpath (const char *path, const char *libname, char *libpath, int size) {
+ const char *e = strrchr (path, ':');
+ if (!e) {
+ e = strrchr (path, '/');
+ }
+ if (e) {
+ e++;
+ memcpy (libpath, path, e-path);
+ libpath[e-path] = 0;
+ strcat (libpath, libname);
+ }
+ else {
+ strcpy (libpath, libname);
+ }
+}
+
void *psf_start(const char *path, uint8 *buffer, uint32 length)
{
psf_synth_t *s = malloc (sizeof (psf_synth_t));
@@ -126,19 +143,7 @@ void *psf_start(const char *path, uint8 *buffer, uint32 length)
{
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, s->c->lib);
- }
- else {
- strcpy (libpath, s->c->lib);
- }
+ ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath));
if (ao_get_lib(libpath, &lib_raw_file, &tmp_length) != AO_SUCCESS)
{
@@ -228,19 +233,7 @@ void *psf_start(const char *path, uint8 *buffer, uint32 length)
{
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, s->c->libaux[i]);
- }
- else {
- strcpy (libpath, s->c->libaux[i]);
- }
+ ao_getlibpath (path, s->c->libaux[i], libpath, sizeof (libpath));
if (ao_get_lib(libpath, &lib_raw_file, &tmp_length) != AO_SUCCESS)
{
diff --git a/plugins/ao/eng_psf/eng_psf2.c b/plugins/ao/eng_psf/eng_psf2.c
index de9e5148..525ad3f7 100644
--- a/plugins/ao/eng_psf/eng_psf2.c
+++ b/plugins/ao/eng_psf/eng_psf2.c
@@ -497,19 +497,7 @@ void *psf2_start(const char *path, uint8 *buffer, uint32 length)
{
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, s->c->lib);
- }
- else {
- strcpy (libpath, s->c->lib);
- }
+ ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath));
#if DEBUG_LOADER
printf("Loading library: %s\n", s->c->lib);
diff --git a/plugins/ao/eng_qsf/eng_qsf.c b/plugins/ao/eng_qsf/eng_qsf.c
index 130b5d2c..57d18147 100644
--- a/plugins/ao/eng_qsf/eng_qsf.c
+++ b/plugins/ao/eng_qsf/eng_qsf.c
@@ -207,19 +207,7 @@ void *qsf_start(const char *path, uint8 *buffer, uint32 length)
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, s->c->lib);
- }
- else {
- strcpy (libpath, s->c->lib);
- }
+ ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath));
#if DEBUG_LOADER
printf("Loading library: %s\n", libpath);
diff --git a/plugins/ao/eng_ssf/eng_ssf.c b/plugins/ao/eng_ssf/eng_ssf.c
index 9b1b5714..f15eb114 100644
--- a/plugins/ao/eng_ssf/eng_ssf.c
+++ b/plugins/ao/eng_ssf/eng_ssf.c
@@ -121,19 +121,7 @@ void *ssf_start(const char *path, uint8 *buffer, uint32 length)
uint64 tmp_length;
char libpath[PATH_MAX];
- const char *e = path + strlen(path);
- while (e > path && *e != '/') {
- e--;
- }
- if (*e == '/') {
- e++;
- memcpy (libpath, path, e-path);
- libpath[e-path] = 0;
- strcat (libpath, libfile);
- }
- else {
- strcpy (libpath, libfile);
- }
+ ao_getlibpath (path, s->c->lib, libpath, sizeof (libpath));
#if DEBUG_LOADER
printf("Loading library: %s\n", c->lib);
#endif
diff --git a/plugins/ao/main.c b/plugins/ao/main.c
index a3c7bdc4..18067410 100644
--- a/plugins/ao/main.c
+++ b/plugins/ao/main.c
@@ -27,12 +27,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <deadbeef/deadbeef.h>
#include "ao.h"
#include "eng_protos.h"
//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
#define trace(fmt,...)
+extern DB_functions_t *deadbeef;
/* file types */
static uint32 type;
@@ -63,30 +65,30 @@ int ao_get_lib(char *filename, uint8 **buffer, uint64 *length)
{
uint8 *filebuf;
uint32 size;
- FILE *auxfile;
+ DB_FILE *auxfile;
- auxfile = fopen(filename, "rb");
+ auxfile = deadbeef->fopen(filename);
if (!auxfile)
{
fprintf(stderr, "Unable to find auxiliary file %s\n", filename);
return AO_FAIL;
}
- fseek(auxfile, 0, SEEK_END);
- size = ftell(auxfile);
- fseek(auxfile, 0, SEEK_SET);
+ deadbeef->fseek(auxfile, 0, SEEK_END);
+ size = deadbeef->ftell(auxfile);
+ deadbeef->fseek(auxfile, 0, SEEK_SET);
filebuf = malloc(size);
if (!filebuf)
{
- fclose(auxfile);
+ deadbeef->fclose(auxfile);
printf("ERROR: could not allocate %d bytes of memory\n", size);
return AO_FAIL;
}
- fread(filebuf, size, 1, auxfile);
- fclose(auxfile);
+ deadbeef->fread(filebuf, size, 1, auxfile);
+ deadbeef->fclose(auxfile);
*buffer = filebuf;
*length = (uint64)size;
diff --git a/plugins/ao/plugin.c b/plugins/ao/plugin.c
index 8d5e6acb..cd53c8a7 100644
--- a/plugins/ao/plugin.c
+++ b/plugins/ao/plugin.c
@@ -18,7 +18,7 @@
*/
#include <stdlib.h>
#include <string.h>
-#include "../../deadbeef.h"
+#include <deadbeef/deadbeef.h>
#include "ao.h"
#include "eng_protos.h"