2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2012-08-21 03:03:52 +02:00
|
|
|
gbi.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-08-03 17:38:01 +02:00
|
|
|
(c) 2000-2013 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-08-21 03:03:52 +02:00
|
|
|
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 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-08-21 03:03:52 +02:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-08-21 03:03:52 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-05-25 15:23:39 +02:00
|
|
|
#define __GBI_C
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "trunk_version.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2008-07-18 01:45:32 +02:00
|
|
|
#include <sys/wait.h>
|
2007-12-30 17:41:49 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2014-07-01 00:22:11 +02:00
|
|
|
#if defined(OS_LINUX) || defined(OS_GNU) || defined(OS_OPENBSD) || defined(OS_FREEBSD) || defined(OS_CYGWIN)
|
2007-12-30 17:41:49 +01:00
|
|
|
#define lt_dlinit() (0)
|
|
|
|
#define lt_dlhandle void *
|
|
|
|
#define lt_dlopenext(_path) dlopen(_path, RTLD_LAZY)
|
|
|
|
#define lt_dlsym(_handle, _symbol) dlsym(_handle, _symbol)
|
|
|
|
#define lt_dlclose(_handle) dlclose(_handle)
|
|
|
|
#define lt_dlerror() dlerror()
|
|
|
|
#else
|
|
|
|
#include <ltdl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "gb_component.h"
|
|
|
|
#include "gb_file.h"
|
|
|
|
#include "gb_str.h"
|
|
|
|
#include "gb_arch.h"
|
|
|
|
#include "gb_common_swap.h"
|
2009-01-21 02:25:13 +01:00
|
|
|
#include "gb_array.h"
|
2014-08-25 00:38:58 +02:00
|
|
|
#include "gb_table.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gambas.h"
|
|
|
|
|
2010-01-28 11:55:24 +01:00
|
|
|
static char _root[PATH_MAX + 1] = { 0 };
|
|
|
|
static char _lib_path[PATH_MAX + 1];
|
|
|
|
static char _info_path[PATH_MAX + 1];
|
|
|
|
static char _buffer[PATH_MAX + 1];
|
|
|
|
static char _env[PATH_MAX + 16];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static FILE *out_info;
|
|
|
|
static FILE *out_list;
|
|
|
|
static bool _verbose = FALSE;
|
|
|
|
static bool _format = FALSE;
|
|
|
|
static bool _nopreload = FALSE;
|
2008-07-18 01:45:32 +02:00
|
|
|
static bool _root_set = FALSE;
|
2009-01-03 23:24:02 +01:00
|
|
|
static bool _analyze = FALSE;
|
2012-10-28 15:35:31 +01:00
|
|
|
static bool _no_include_warning = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
static char **_components = NULL;
|
|
|
|
|
2014-08-25 00:38:58 +02:00
|
|
|
static TABLE *_classes = NULL;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void analyze(const char *comp, bool include);
|
|
|
|
|
2009-05-15 19:57:29 +02:00
|
|
|
#if HAVE_GETOPT_LONG
|
2007-12-30 17:41:49 +01:00
|
|
|
static struct option LongOptions[] =
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
{ "version", 0, NULL, 'V' },
|
|
|
|
{ "verbose", 0, NULL, 'v' },
|
|
|
|
{ "help", 0, NULL, 'h' },
|
2010-03-07 02:38:15 +01:00
|
|
|
{ "license", 0, NULL, 'L' },
|
2009-01-03 23:24:02 +01:00
|
|
|
{ "root", 1, NULL, 'r' },
|
|
|
|
{ 0 }
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
static int compare_components(char **a, char **b)
|
|
|
|
{
|
|
|
|
return strcmp(*a, *b);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void print(const char *fmt, ...)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
va_list args;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
va_start(args, fmt);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
vfprintf(out_info, fmt, args);
|
|
|
|
|
|
|
|
va_end(args);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void warning(const char *fmt, ...)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
va_list args;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "gbi" GAMBAS_VERSION_STRING ": warning: ");
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
va_start(args, fmt);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
|
|
|
|
putc('\n', stderr);
|
|
|
|
|
|
|
|
va_end(args);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void error(bool must_exit, const char *fmt, ...)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
va_list args;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "gbi" GAMBAS_VERSION_STRING ": ERROR: ");
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
va_start(args, fmt);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
|
|
|
|
putc('\n', stderr);
|
|
|
|
|
|
|
|
va_end(args);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (must_exit)
|
|
|
|
exit(1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static void error2(const char *msg, const char *msg2, bool must_exit)
|
|
|
|
// {
|
|
|
|
// fprintf(stderr, "gbi" GAMBAS_VERSION_STRING ": ERROR: %s: %s%s%s\n", msg, msg2, (errno != 0) ? ": " : "", (errno != 0) ? strerror(errno) : "");
|
|
|
|
// if (must_exit)
|
|
|
|
// exit(1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
static void init(void)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
const char *path;
|
2012-10-28 15:35:31 +01:00
|
|
|
char *env;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
/* chemin d'installation de Gambas */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (!_root[0])
|
|
|
|
{
|
2010-12-05 21:17:24 +01:00
|
|
|
const char *dir;
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
path = FILE_find_gambas();
|
2010-12-05 21:17:24 +01:00
|
|
|
dir = FILE_get_dir(FILE_get_dir(path));
|
|
|
|
if (dir)
|
|
|
|
strncpy(_root, dir, PATH_MAX);
|
2009-01-03 23:24:02 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
#ifdef OS_64BITS
|
|
|
|
strcpy(_lib_path, FILE_cat(_root, GAMBAS_LIB64_PATH, NULL));
|
|
|
|
if (access(FILE_cat(_lib_path, "gb.component", NULL), F_OK))
|
|
|
|
#endif
|
|
|
|
strcpy(_lib_path, FILE_cat(_root, GAMBAS_LIB_PATH, NULL));
|
|
|
|
|
|
|
|
strcpy(_info_path, FILE_cat(_root, "share/gambas" GAMBAS_VERSION_STRING "/info", NULL));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (lt_dlinit())
|
|
|
|
error(TRUE, "Cannot initialize plug-in management: %s", lt_dlerror());
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-10-28 15:35:31 +01:00
|
|
|
env = getenv("GBI_DEBUG");
|
|
|
|
if (env && *env && atoi(env))
|
|
|
|
_no_include_warning = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void newline()
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
print("\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static bool print_type(const char *type)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
switch (*type)
|
|
|
|
{
|
|
|
|
case 'b': print("Boolean"); break;
|
|
|
|
case 'i': print("Integer"); break;
|
|
|
|
case 's': print("String"); break;
|
|
|
|
case 'd': print("Date"); break;
|
|
|
|
case 'f': print("Float"); break;
|
|
|
|
case 'v': print("Variant"); break;
|
|
|
|
case 'o': print("Object"); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
while (*type && *type != ';')
|
|
|
|
{
|
|
|
|
print("%c", *type);
|
|
|
|
type++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void dump_symbol(GB_DESC *desc)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
const char *name;
|
2013-07-11 00:17:27 +02:00
|
|
|
const char *p;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
name = &desc->name[1];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
print("%s\n", name);
|
|
|
|
print("%c\n", *desc->name);
|
|
|
|
if (desc->val1)
|
|
|
|
print("%s", desc->val1);
|
|
|
|
newline();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (*desc->name == 'C')
|
2013-07-11 00:17:27 +02:00
|
|
|
{
|
|
|
|
switch(*(char *)desc->val1)
|
|
|
|
{
|
|
|
|
case 'i':
|
|
|
|
print("%d", desc->val2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
p = (const char *)desc->val2;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (*p == '\n')
|
|
|
|
print("\\n");
|
|
|
|
else if (*p == '\t')
|
|
|
|
print("\\t");
|
|
|
|
else
|
|
|
|
print("%c", *p);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
2013-07-19 13:02:32 +02:00
|
|
|
if (desc->val2)
|
|
|
|
print("T");
|
2013-07-11 00:17:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
print("%.15g", desc->val4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
print("?");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
else if (desc->val3)
|
|
|
|
print("%s", (char *)desc->val3);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
newline();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GB_DESC *_sort_symbol;
|
|
|
|
|
|
|
|
static int sort_symbol(const int *a, const int *b)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
return strcmp(_sort_symbol[*a].name, _sort_symbol[*b].name);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 01:31:59 +01:00
|
|
|
static void add_class(const char *name, bool has_static)
|
2014-08-25 00:38:58 +02:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (out_list)
|
|
|
|
{
|
|
|
|
if (!TABLE_add_symbol(_classes, name, strlen(name), &index))
|
2015-01-16 01:31:59 +01:00
|
|
|
{
|
|
|
|
fputs(name, out_list);
|
|
|
|
if (has_static)
|
|
|
|
fputc('!', out_list);
|
|
|
|
fputc('\n', out_list);
|
|
|
|
}
|
2014-08-25 00:38:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void analyze_class(GB_DESC *desc)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
const char *name = desc->name;
|
|
|
|
char *parent = NULL;
|
|
|
|
bool autocreate = FALSE;
|
|
|
|
bool nocreate = FALSE;
|
|
|
|
uintptr_t hook;
|
|
|
|
int nsymbol;
|
|
|
|
int *sort;
|
|
|
|
GB_DESC *p;
|
|
|
|
int i;
|
2015-01-16 01:31:59 +01:00
|
|
|
bool has_static = FALSE;
|
2009-01-03 23:24:02 +01:00
|
|
|
|
|
|
|
desc++;
|
|
|
|
|
|
|
|
while (desc->name)
|
|
|
|
{
|
|
|
|
hook = (uintptr_t)desc->name;
|
|
|
|
|
|
|
|
if (hook == (intptr_t)GB_INHERITS_ID)
|
|
|
|
parent = (char *)desc->val1;
|
2014-05-23 13:52:04 +02:00
|
|
|
else if (hook == (intptr_t)GB_NOT_CREATABLE_ID)
|
2009-01-03 23:24:02 +01:00
|
|
|
nocreate = TRUE;
|
|
|
|
else if (hook == (intptr_t)GB_AUTO_CREATABLE_ID)
|
|
|
|
autocreate = TRUE;
|
|
|
|
else if (hook > 16)
|
|
|
|
break;
|
|
|
|
|
|
|
|
desc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = desc;
|
|
|
|
nsymbol = 0;
|
|
|
|
while (p->name)
|
|
|
|
{
|
|
|
|
nsymbol++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_format)
|
|
|
|
{
|
|
|
|
print("CLASS %s\n", name);
|
|
|
|
if (parent) print("INHERITS %s\n", parent);
|
|
|
|
if (!nocreate) print("CREATABLE\n");
|
|
|
|
if (autocreate) print("AUTOCREATABLE\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print("#%s\n", name);
|
|
|
|
if (parent)
|
|
|
|
print("%s", parent);
|
|
|
|
newline();
|
|
|
|
if (!nocreate)
|
|
|
|
print("C");
|
|
|
|
if (autocreate)
|
|
|
|
print("A");
|
|
|
|
newline();
|
|
|
|
}
|
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC(&sort, sizeof(int) * nsymbol);
|
2009-01-03 23:24:02 +01:00
|
|
|
for (i = 0; i < nsymbol; i++)
|
|
|
|
sort[i] = i;
|
|
|
|
|
|
|
|
_sort_symbol = desc;
|
|
|
|
qsort(sort, nsymbol, sizeof(int), (int (*)(const void *, const void *))sort_symbol);
|
|
|
|
|
|
|
|
for (i = 0; i < nsymbol; i++)
|
2015-01-16 01:31:59 +01:00
|
|
|
{
|
|
|
|
p = &desc[sort[i]];
|
|
|
|
if (strchr("PCMR", *p->name) && p->name[1] != '_')
|
|
|
|
has_static = TRUE;
|
|
|
|
dump_symbol(p);
|
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&sort);
|
2009-01-03 23:24:02 +01:00
|
|
|
|
|
|
|
if (_format)
|
|
|
|
newline();
|
2015-01-16 01:31:59 +01:00
|
|
|
|
|
|
|
add_class(name, has_static);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GB_DESC **_sort_desc;
|
|
|
|
|
|
|
|
static int sort_desc(const int *a, const int *b)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
return strcmp(_sort_desc[*a]->name, _sort_desc[*b]->name);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
static void analyze_include(char *include_list)
|
|
|
|
{
|
|
|
|
char *includes[8];
|
|
|
|
int nincludes;
|
|
|
|
char *include;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
include_list = STR_copy(include_list);
|
|
|
|
|
|
|
|
if (_verbose)
|
|
|
|
fprintf(stderr, "Including %s\n", include_list);
|
|
|
|
|
2009-02-22 00:03:36 +01:00
|
|
|
nincludes = 0;
|
2009-01-21 02:25:13 +01:00
|
|
|
include = strtok(include_list, ",");
|
|
|
|
while (include && nincludes < 8)
|
|
|
|
{
|
|
|
|
includes[nincludes++] = include;
|
|
|
|
include = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nincludes; i++)
|
|
|
|
analyze(includes[i], TRUE);
|
|
|
|
|
|
|
|
STR_free(include_list);
|
|
|
|
}
|
|
|
|
|
[INTERPRETER]
* NEW: Add a new GB.Component.Declare() API, that allows a component to
dynamically register a class description.
[INFORMER]
* NEW: A component now can declare classes through a GB_OPTIONAL_CLASSES
public symbol. Theses classes are included into the information file,
but are not automatically loaded as the ones defined through the
GB_CLASSES symbol.
[GB.FORM.STATUSICON]
* NEW: This component has been removed and replaced by gb.dbus.trayicon.
* NEW: This component now provide TrayIcon and TrayIcons classes that have
exactly the same interface as the old ones.
[GB.DBUS]
* NEW: Remove the now useless DBusConnection.Raise(). The DBusConnection
Register() and Unregister() are kept for backward-compatibility reason.
* NEW: Add DBus.Raise() and DBus[].Raise() to raise signals. At the moment,
there is no difference between the two methods, as there no mean to
indicate the sender raising a signal. I don't know yet how DBus decides
which service sends a signal!
[GB.DBUS.TRAYICON]
* NEW: This component implements the tray icon DBus protocol. It is
automatically loaded by the GUI components.
[GB.GTK]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.GTK3]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the component name in deprecation warning messages.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.QT4]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
[GB.QT5]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
git-svn-id: svn://localhost/gambas/trunk@7154 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2015-06-29 03:46:51 +02:00
|
|
|
static void analyze_classes(GB_DESC **desc)
|
|
|
|
{
|
|
|
|
int nclass;
|
|
|
|
int *sort;
|
|
|
|
int i;
|
|
|
|
GB_DESC **p;
|
|
|
|
|
|
|
|
nclass = 0;
|
|
|
|
|
|
|
|
p = desc;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
nclass++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC(&sort, sizeof(int) * nclass);
|
|
|
|
for (i = 0; i < nclass; i++)
|
|
|
|
sort[i] = i;
|
|
|
|
|
|
|
|
_sort_desc = desc;
|
|
|
|
qsort(sort, nclass, sizeof(int), (int (*)(const void *, const void *))sort_desc);
|
|
|
|
|
|
|
|
for (i = 0; i < nclass; i++)
|
|
|
|
analyze_class(desc[sort[i]]);
|
|
|
|
|
|
|
|
FREE(&sort);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static bool analyze_native_component(const char *path)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
lt_dlhandle lib;
|
|
|
|
GB_DESC **desc;
|
[INTERPRETER]
* NEW: Add a new GB.Component.Declare() API, that allows a component to
dynamically register a class description.
[INFORMER]
* NEW: A component now can declare classes through a GB_OPTIONAL_CLASSES
public symbol. Theses classes are included into the information file,
but are not automatically loaded as the ones defined through the
GB_CLASSES symbol.
[GB.FORM.STATUSICON]
* NEW: This component has been removed and replaced by gb.dbus.trayicon.
* NEW: This component now provide TrayIcon and TrayIcons classes that have
exactly the same interface as the old ones.
[GB.DBUS]
* NEW: Remove the now useless DBusConnection.Raise(). The DBusConnection
Register() and Unregister() are kept for backward-compatibility reason.
* NEW: Add DBus.Raise() and DBus[].Raise() to raise signals. At the moment,
there is no difference between the two methods, as there no mean to
indicate the sender raising a signal. I don't know yet how DBus decides
which service sends a signal!
[GB.DBUS.TRAYICON]
* NEW: This component implements the tray icon DBus protocol. It is
automatically loaded by the GUI components.
[GB.GTK]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.GTK3]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the component name in deprecation warning messages.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.QT4]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
[GB.QT5]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
git-svn-id: svn://localhost/gambas/trunk@7154 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2015-06-29 03:46:51 +02:00
|
|
|
GB_DESC **desc_opt;
|
2009-01-03 23:24:02 +01:00
|
|
|
char **include;
|
|
|
|
bool ret = FALSE;
|
|
|
|
|
|
|
|
if (_verbose)
|
|
|
|
fprintf(stderr, "Loading native component: %s\n", path);
|
|
|
|
|
|
|
|
//lt_dlopen_flag = RTLD_LAZY; /* | RTLD_GLOBAL;*/
|
|
|
|
|
|
|
|
lib = lt_dlopenext(path);
|
|
|
|
if (!lib)
|
|
|
|
{
|
|
|
|
error(FALSE, "Cannot load shared library: %s", lt_dlerror());
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
include = lt_dlsym(lib, LIB_INCLUDE);
|
|
|
|
if (include)
|
2009-01-21 02:25:13 +01:00
|
|
|
analyze_include(*include);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
desc = lt_dlsym(lib, LIB_CLASS);
|
[INTERPRETER]
* NEW: Add a new GB.Component.Declare() API, that allows a component to
dynamically register a class description.
[INFORMER]
* NEW: A component now can declare classes through a GB_OPTIONAL_CLASSES
public symbol. Theses classes are included into the information file,
but are not automatically loaded as the ones defined through the
GB_CLASSES symbol.
[GB.FORM.STATUSICON]
* NEW: This component has been removed and replaced by gb.dbus.trayicon.
* NEW: This component now provide TrayIcon and TrayIcons classes that have
exactly the same interface as the old ones.
[GB.DBUS]
* NEW: Remove the now useless DBusConnection.Raise(). The DBusConnection
Register() and Unregister() are kept for backward-compatibility reason.
* NEW: Add DBus.Raise() and DBus[].Raise() to raise signals. At the moment,
there is no difference between the two methods, as there no mean to
indicate the sender raising a signal. I don't know yet how DBus decides
which service sends a signal!
[GB.DBUS.TRAYICON]
* NEW: This component implements the tray icon DBus protocol. It is
automatically loaded by the GUI components.
[GB.GTK]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.GTK3]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the component name in deprecation warning messages.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.QT4]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
[GB.QT5]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
git-svn-id: svn://localhost/gambas/trunk@7154 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2015-06-29 03:46:51 +02:00
|
|
|
desc_opt = lt_dlsym(lib, LIB_OPTIONAL);
|
2009-01-03 23:24:02 +01:00
|
|
|
|
|
|
|
if (desc)
|
|
|
|
{
|
[INTERPRETER]
* NEW: Add a new GB.Component.Declare() API, that allows a component to
dynamically register a class description.
[INFORMER]
* NEW: A component now can declare classes through a GB_OPTIONAL_CLASSES
public symbol. Theses classes are included into the information file,
but are not automatically loaded as the ones defined through the
GB_CLASSES symbol.
[GB.FORM.STATUSICON]
* NEW: This component has been removed and replaced by gb.dbus.trayicon.
* NEW: This component now provide TrayIcon and TrayIcons classes that have
exactly the same interface as the old ones.
[GB.DBUS]
* NEW: Remove the now useless DBusConnection.Raise(). The DBusConnection
Register() and Unregister() are kept for backward-compatibility reason.
* NEW: Add DBus.Raise() and DBus[].Raise() to raise signals. At the moment,
there is no difference between the two methods, as there no mean to
indicate the sender raising a signal. I don't know yet how DBus decides
which service sends a signal!
[GB.DBUS.TRAYICON]
* NEW: This component implements the tray icon DBus protocol. It is
automatically loaded by the GUI components.
[GB.GTK]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.GTK3]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the component name in deprecation warning messages.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.QT4]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
[GB.QT5]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
git-svn-id: svn://localhost/gambas/trunk@7154 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2015-06-29 03:46:51 +02:00
|
|
|
analyze_classes(desc);
|
|
|
|
if (desc_opt)
|
|
|
|
analyze_classes(desc_opt);
|
2009-01-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_verbose)
|
|
|
|
warning("cannot find '" LIB_CLASS "' symbol in shared library.");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
[INTERPRETER]
* NEW: Add a new GB.Component.Declare() API, that allows a component to
dynamically register a class description.
[INFORMER]
* NEW: A component now can declare classes through a GB_OPTIONAL_CLASSES
public symbol. Theses classes are included into the information file,
but are not automatically loaded as the ones defined through the
GB_CLASSES symbol.
[GB.FORM.STATUSICON]
* NEW: This component has been removed and replaced by gb.dbus.trayicon.
* NEW: This component now provide TrayIcon and TrayIcons classes that have
exactly the same interface as the old ones.
[GB.DBUS]
* NEW: Remove the now useless DBusConnection.Raise(). The DBusConnection
Register() and Unregister() are kept for backward-compatibility reason.
* NEW: Add DBus.Raise() and DBus[].Raise() to raise signals. At the moment,
there is no difference between the two methods, as there no mean to
indicate the sender raising a signal. I don't know yet how DBus decides
which service sends a signal!
[GB.DBUS.TRAYICON]
* NEW: This component implements the tray icon DBus protocol. It is
automatically loaded by the GUI components.
[GB.GTK]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.GTK3]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
* BUG: Fix the component name in deprecation warning messages.
* BUG: Fix the old TrayIcon implementation, so that it matches the QT one.
[GB.QT4]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
[GB.QT5]
* NEW: Load the 'gb.dbus' and 'gb.dbus.trayicon' components if the current
desktop is KDE >= 4. Otherwise, use the old TrayIcon implementation.
git-svn-id: svn://localhost/gambas/trunk@7154 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2015-06-29 03:46:51 +02:00
|
|
|
|
2014-08-25 00:38:58 +02:00
|
|
|
// Do not close shared libraries, except on openbsd that seems to feel better with
|
2008-07-18 01:45:32 +02:00
|
|
|
#ifdef OS_OPENBSD
|
|
|
|
lt_dlclose(lib);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
return ret;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool analyze_gambas_component(const char *path)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
ARCH *arch;
|
|
|
|
ARCH_FIND find;
|
2010-12-15 16:55:16 +01:00
|
|
|
bool ret = TRUE;
|
2015-01-05 21:51:21 +01:00
|
|
|
char *buffer;
|
|
|
|
char *line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (_verbose)
|
|
|
|
fprintf(stderr, "Loading gambas component: %s\n", path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
arch = ARCH_open(path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-01-05 21:51:21 +01:00
|
|
|
if (!ARCH_find(arch, ".component", 0, &find))
|
|
|
|
{
|
|
|
|
ALLOC(&buffer, find.len + 1);
|
|
|
|
memcpy(buffer, &arch->addr[find.pos], find.len);
|
|
|
|
buffer[find.len] = 0;
|
|
|
|
|
|
|
|
for (line = strtok(buffer, "\n"); line; line = strtok(NULL, "\n"))
|
|
|
|
{
|
|
|
|
if (strncmp(line, "Include=", 8))
|
|
|
|
continue;
|
|
|
|
analyze_include(&line[8]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(&buffer);
|
|
|
|
}
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (ARCH_find(arch, ".info", 0, &find))
|
|
|
|
{
|
2015-01-05 21:51:21 +01:00
|
|
|
warning("'.info' file not found in component archive.");
|
2010-12-15 16:55:16 +01:00
|
|
|
goto __RETURN;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
fwrite(&arch->addr[find.pos], 1, find.len, out_info);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (ARCH_find(arch, ".list", 0, &find))
|
|
|
|
{
|
2015-01-05 21:51:21 +01:00
|
|
|
warning("'.list' file not found in component archive.");
|
2010-12-15 16:55:16 +01:00
|
|
|
goto __RETURN;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-01-05 21:51:21 +01:00
|
|
|
ALLOC(&buffer, find.len + 1);
|
|
|
|
memcpy(buffer, &arch->addr[find.pos], find.len);
|
|
|
|
buffer[find.len] = 0;
|
2014-08-25 00:38:58 +02:00
|
|
|
|
2015-01-05 21:51:21 +01:00
|
|
|
for (line = strtok(buffer, "\n"); line; line = strtok(NULL, "\n"))
|
2015-01-16 01:31:59 +01:00
|
|
|
add_class(line, FALSE);
|
2014-08-25 00:38:58 +02:00
|
|
|
|
2015-01-05 21:51:21 +01:00
|
|
|
FREE(&buffer);
|
2014-08-25 00:38:58 +02:00
|
|
|
|
|
|
|
//fwrite(&arch->addr[find.pos], 1, find.len, out_list);
|
2010-12-15 16:55:16 +01:00
|
|
|
ret = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-15 16:55:16 +01:00
|
|
|
__RETURN:
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
ARCH_close(arch);
|
2010-12-15 16:55:16 +01:00
|
|
|
return ret;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-10-10 16:58:14 +02:00
|
|
|
#if 0
|
2007-12-30 17:41:49 +01:00
|
|
|
static void preload(char **argv, char *lib)
|
|
|
|
{
|
|
|
|
#if DO_PRELOADING
|
2009-01-03 23:24:02 +01:00
|
|
|
if (_nopreload || getenv("GB_PRELOAD") || !lib || !*lib)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
snprintf(_env, sizeof(_env), "LD_PRELOAD=%s", lib);
|
|
|
|
putenv(_env);
|
|
|
|
putenv("GB_PRELOAD=1");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
execvp(argv[0], argv);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
}
|
2012-10-10 16:58:14 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
static bool find_native_component(const char *name)
|
|
|
|
{
|
|
|
|
snprintf(_buffer, sizeof(_buffer), LIB_PATTERN, _lib_path, name);
|
|
|
|
return (access(_buffer, F_OK) == 0);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void analyze(const char *comp, bool include)
|
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
bool native, gambas;
|
|
|
|
char *name;
|
|
|
|
char *path_list = NULL;
|
|
|
|
char *path_info = NULL;
|
|
|
|
bool ok;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
name = STR_copy(comp);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
if (_verbose)
|
|
|
|
fprintf(stderr, "%s component %s\n", include ? "Including" : "Analyzing", name);
|
2009-01-27 14:39:38 +01:00
|
|
|
else if (!include)
|
2009-01-21 02:25:13 +01:00
|
|
|
puts(name);
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
native = find_native_component(name);
|
2008-07-18 01:45:32 +02:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
snprintf(_buffer, sizeof(_buffer), ARCH_PATTERN, _lib_path, name);
|
|
|
|
gambas = (access(_buffer, F_OK) == 0);
|
|
|
|
|
|
|
|
if (!native && !gambas)
|
|
|
|
{
|
2012-10-10 16:58:14 +02:00
|
|
|
if (!include || !_no_include_warning)
|
|
|
|
warning("component %s not found", name);
|
2009-01-03 23:24:02 +01:00
|
|
|
STR_free(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!include)
|
|
|
|
{
|
2007-12-30 17:41:49 +01:00
|
|
|
path_info = STR_cat(FILE_cat(_info_path, name, NULL), ".info", NULL);
|
|
|
|
path_list = STR_cat(FILE_cat(_info_path, name, NULL), ".list", NULL);
|
|
|
|
|
|
|
|
out_info = fopen(path_info, "w");
|
|
|
|
if (!out_info)
|
2008-03-26 02:31:20 +01:00
|
|
|
{
|
|
|
|
error(FALSE, "Cannot write file: %s", path_info);
|
|
|
|
return;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
out_list = fopen(path_list, "w");
|
|
|
|
if (!out_list)
|
2008-03-26 02:31:20 +01:00
|
|
|
{
|
|
|
|
error(FALSE, "Cannot write file: %s", path_list);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-25 00:38:58 +02:00
|
|
|
|
|
|
|
TABLE_create(&_classes, sizeof(SYMBOL), TF_IGNORE_CASE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
fflush(stdout);
|
|
|
|
ok = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-08-25 00:38:58 +02:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (native)
|
|
|
|
{
|
|
|
|
snprintf(_buffer, sizeof(_buffer), LIB_PATTERN, _lib_path, name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (analyze_native_component(_buffer))
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (gambas)
|
|
|
|
{
|
|
|
|
snprintf(_buffer, sizeof(_buffer), ARCH_PATTERN, _lib_path, name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (analyze_gambas_component(_buffer))
|
|
|
|
if (!native)
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!include)
|
|
|
|
{
|
2014-08-25 00:38:58 +02:00
|
|
|
TABLE_delete(&_classes);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
fclose(out_info);
|
|
|
|
fclose(out_list);
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
{
|
2011-03-29 02:24:15 +02:00
|
|
|
FILE_unlink(path_info);
|
|
|
|
FILE_unlink(path_list);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2009-02-21 01:00:35 +01:00
|
|
|
else if (_verbose)
|
|
|
|
{
|
2015-01-05 21:51:21 +01:00
|
|
|
fprintf(stderr, "Wrote %s\n", path_info);
|
|
|
|
fprintf(stderr, "Wrote %s\n", path_list);
|
2009-02-21 01:00:35 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
STR_free(path_info);
|
|
|
|
STR_free(path_list);
|
|
|
|
}
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
STR_free(name);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-07-18 01:45:32 +02:00
|
|
|
static void run_myself(const char *path, const char *name)
|
|
|
|
{
|
|
|
|
const char *argv[10];
|
|
|
|
int n = 0;
|
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
if (_verbose)
|
|
|
|
fprintf(stderr, "Running myself for component %s\n", name);
|
|
|
|
|
2008-07-18 01:45:32 +02:00
|
|
|
argv[n++] = path;
|
|
|
|
if (_verbose)
|
|
|
|
argv[n++] = "-v";
|
|
|
|
if (_nopreload)
|
|
|
|
argv[n++] = "-p";
|
|
|
|
if (_root_set)
|
|
|
|
{
|
|
|
|
argv[n++] = "-r";
|
|
|
|
argv[n++] = _root;
|
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
argv[n++] = "-a";
|
2008-07-18 01:45:32 +02:00
|
|
|
argv[n++] = name;
|
|
|
|
argv[n] = NULL;
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
if (find_native_component(name))
|
|
|
|
{
|
|
|
|
snprintf(_env, sizeof(_env), "LD_PRELOAD=%s", _buffer);
|
|
|
|
putenv(_env);
|
|
|
|
}
|
|
|
|
|
2008-07-18 01:45:32 +02:00
|
|
|
pid = fork();
|
|
|
|
switch (pid)
|
|
|
|
{
|
|
|
|
case 0:
|
2009-01-03 23:24:02 +01:00
|
|
|
execvp(path, (char **)argv);
|
2013-01-06 17:13:31 +01:00
|
|
|
error(FALSE, "Cannot run sub-process: %s", strerror(errno));
|
|
|
|
exit(1);
|
2008-07-18 01:45:32 +02:00
|
|
|
case -1:
|
2009-01-03 23:24:02 +01:00
|
|
|
error(FALSE, "Cannot run sub-process: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
default:
|
|
|
|
waitpid(pid, &status, 0);
|
2008-07-18 01:45:32 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
static void make_component_list()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-01-03 23:24:02 +01:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
const char *name;
|
2009-01-21 02:25:13 +01:00
|
|
|
|
|
|
|
dir = opendir(_lib_path);
|
|
|
|
if (dir == NULL)
|
|
|
|
error(TRUE, "Cannot read directory: %s", _lib_path);
|
|
|
|
|
|
|
|
//save_fd = dup(STDOUT_FILENO);
|
|
|
|
|
|
|
|
ARRAY_create(&_components);
|
|
|
|
|
|
|
|
while ((dirent = readdir(dir)) != NULL)
|
|
|
|
{
|
|
|
|
name = dirent->d_name;
|
|
|
|
if (strcmp(FILE_get_ext(name), "component"))
|
|
|
|
continue;
|
|
|
|
name = FILE_get_basename(name);
|
|
|
|
*((char **)ARRAY_add(&_components)) = STR_copy(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
qsort(_components, ARRAY_count(_components), sizeof(*_components), (int (*)(const void *, const void *))compare_components);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *name;
|
2009-01-03 23:24:02 +01:00
|
|
|
int opt;
|
|
|
|
int ind = 0;
|
|
|
|
|
|
|
|
/*#ifdef __FreeBSD__
|
|
|
|
optind = 1;
|
|
|
|
#else
|
|
|
|
optind = 0;
|
|
|
|
#endif*/
|
|
|
|
|
2011-10-16 21:24:01 +02:00
|
|
|
//dup(STDOUT_FILENO);
|
2009-01-21 02:25:13 +01:00
|
|
|
|
2009-02-22 00:03:36 +01:00
|
|
|
//_verbose = TRUE;
|
2009-02-21 01:00:35 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
2009-05-15 19:57:29 +02:00
|
|
|
#if HAVE_GETOPT_LONG
|
2010-03-07 02:38:15 +01:00
|
|
|
opt = getopt_long(argc, argv, "vVhLpar:", LongOptions, &ind);
|
2009-01-03 23:24:02 +01:00
|
|
|
#else
|
2010-03-07 02:38:15 +01:00
|
|
|
opt = getopt(argc, argv, "vVhLpar:");
|
2009-01-03 23:24:02 +01:00
|
|
|
#endif
|
|
|
|
if (opt < 0) break;
|
|
|
|
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case 'V':
|
2013-05-23 01:03:48 +02:00
|
|
|
#ifdef TRUNK_VERSION
|
|
|
|
printf(VERSION " r" TRUNK_VERSION "\n");
|
|
|
|
#else
|
2009-01-03 23:24:02 +01:00
|
|
|
printf(VERSION "\n");
|
2013-05-23 01:03:48 +02:00
|
|
|
#endif
|
2009-01-03 23:24:02 +01:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
_verbose = TRUE;
|
|
|
|
break;
|
2012-10-10 16:58:14 +02:00
|
|
|
#if DO_PRELOADING
|
2009-01-03 23:24:02 +01:00
|
|
|
case 'p':
|
|
|
|
_nopreload = TRUE;
|
|
|
|
break;
|
2012-10-10 16:58:14 +02:00
|
|
|
#endif
|
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
case 'r':
|
2010-01-28 11:55:24 +01:00
|
|
|
strncpy(_root, optarg, PATH_MAX);
|
2009-01-03 23:24:02 +01:00
|
|
|
_root_set = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
_analyze = TRUE;
|
|
|
|
break;
|
2010-03-07 02:38:15 +01:00
|
|
|
|
|
|
|
case 'L':
|
2009-01-03 23:24:02 +01:00
|
|
|
printf(
|
2012-08-21 03:03:52 +02:00
|
|
|
"\nGAMBAS Component Informer version " VERSION " " __DATE__ " " __TIME__ "\n"
|
2009-01-03 23:24:02 +01:00
|
|
|
COPYRIGHT
|
2010-03-07 02:38:15 +01:00
|
|
|
);
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
printf(
|
2012-08-21 03:03:52 +02:00
|
|
|
"\nGenerate component description files.\n"
|
|
|
|
"\nUsage: gbi" GAMBAS_VERSION_STRING " [options] [components]\n"
|
2015-01-12 00:41:41 +01:00
|
|
|
"\nOptions:"
|
2009-05-15 19:57:29 +02:00
|
|
|
#if HAVE_GETOPT_LONG
|
2009-01-03 23:24:02 +01:00
|
|
|
"\n"
|
2012-10-10 16:58:14 +02:00
|
|
|
#if DO_PRELOADING
|
2009-01-03 23:24:02 +01:00
|
|
|
" -p disable preloading\n"
|
2012-10-10 16:58:14 +02:00
|
|
|
#endif
|
2009-01-03 23:24:02 +01:00
|
|
|
" -r --root <directory> gives the gambas installation directory\n"
|
2012-08-21 03:03:52 +02:00
|
|
|
" -V --version display version\n"
|
|
|
|
" -L --license display license\n"
|
|
|
|
" -h --help display this help\n"
|
2009-01-03 23:24:02 +01:00
|
|
|
#else
|
|
|
|
" (no long options on this system)\n"
|
2012-10-10 16:58:14 +02:00
|
|
|
#if DO_PRELOADING
|
2009-01-03 23:24:02 +01:00
|
|
|
" -p disable preloading\n"
|
2012-10-10 16:58:14 +02:00
|
|
|
#endif
|
2009-01-03 23:24:02 +01:00
|
|
|
" -r <directory> gives the gambas installation directory\n"
|
2012-08-21 03:03:52 +02:00
|
|
|
" -V display version\n"
|
|
|
|
" -L display license\n"
|
|
|
|
" -h display this help\n"
|
2009-01-03 23:24:02 +01:00
|
|
|
#endif
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
if (_analyze)
|
|
|
|
{
|
|
|
|
if (_verbose)
|
2015-01-05 21:51:21 +01:00
|
|
|
{
|
|
|
|
char *env = getenv("LD_PRELOAD");
|
|
|
|
if (env)
|
|
|
|
fprintf(stderr, "LD_PRELOAD=%s\n", env);
|
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
|
|
|
|
analyze(argv[optind], FALSE);
|
2012-10-10 16:58:14 +02:00
|
|
|
/*if (strcmp(argv[optind], "gb.qt4") == 0)
|
|
|
|
analyze("gb.gui", FALSE);
|
|
|
|
else if (strcmp(argv[optind], "gb.qt4.opengl") == 0)
|
|
|
|
analyze("gb.gui.opengl", FALSE);*/
|
2009-01-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (optind == argc
|
|
|
|
#ifdef OS_SOLARIS /* solaris bug ? */
|
|
|
|
|| optind == 0
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2012-10-10 16:58:14 +02:00
|
|
|
/*preload(argv,
|
2009-01-03 23:24:02 +01:00
|
|
|
"libqt-mt.so.3 "
|
|
|
|
"libkdecore.so.4 "
|
2012-10-10 16:58:14 +02:00
|
|
|
);*/
|
2009-01-03 23:24:02 +01:00
|
|
|
|
|
|
|
if (_verbose)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "component path: %s\n", _lib_path);
|
|
|
|
fprintf(stderr, "info path: %s\n", _info_path);
|
|
|
|
}
|
2009-01-21 02:25:13 +01:00
|
|
|
|
|
|
|
make_component_list();
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count(_components); i++)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-01-21 02:25:13 +01:00
|
|
|
name = _components[i];
|
2009-01-03 23:24:02 +01:00
|
|
|
run_myself(argv[0], name);
|
2009-01-21 02:25:13 +01:00
|
|
|
STR_free(name);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2009-01-21 02:25:13 +01:00
|
|
|
|
2012-08-21 03:03:52 +02:00
|
|
|
ARRAY_delete(&_components);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
else
|
|
|
|
{
|
2010-03-05 14:12:15 +01:00
|
|
|
if (!getenv("GB_PRELOAD"))
|
2009-01-03 23:24:02 +01:00
|
|
|
{
|
|
|
|
for (ind = optind; ind < argc; ind++)
|
|
|
|
{
|
|
|
|
name = argv[ind];
|
2012-10-10 16:58:14 +02:00
|
|
|
/*if (strncmp(name, "gb.qt.kde", 9) == 0)
|
2009-01-03 23:24:02 +01:00
|
|
|
preload(argv, "libqt-mt.so.3 libkdecore.so.4");
|
|
|
|
else if (strcmp(name, "gb.qt") == 0 || strncmp(name, "gb.qt.", 6) == 0)
|
2012-10-10 16:58:14 +02:00
|
|
|
preload(argv, "libqt-mt.so.3");*/
|
2009-01-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ind = optind; ind < argc; ind++)
|
|
|
|
{
|
|
|
|
name = argv[ind];
|
|
|
|
//analyze(name, FALSE);
|
|
|
|
run_myself(argv[0], name);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2009-01-03 23:24:02 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-03 23:24:02 +01:00
|
|
|
exit(0);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|