2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
gbx_project.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
|
|
|
|
2013-01-29 01:53:21 +01: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
|
|
|
|
2013-01-29 01:53:21 +01: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
|
|
|
|
2013-01-29 01:53:21 +01: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
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_PROJECT_C
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_common_case.h"
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gb_buffer.h"
|
|
|
|
#include "gb_file.h"
|
|
|
|
#include "gbx_stream.h"
|
|
|
|
#include "gbx_archive.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
#include "gb_component.h"
|
|
|
|
#include "gbx_component.h"
|
|
|
|
|
|
|
|
#include "gbx_project.h"
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *PROJECT_path = NULL;
|
|
|
|
char *PROJECT_exec_path = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *PROJECT_name = NULL;
|
|
|
|
char *PROJECT_title = NULL;
|
|
|
|
char *PROJECT_startup = NULL;
|
|
|
|
char *PROJECT_version = NULL;
|
|
|
|
CLASS *PROJECT_class = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
int PROJECT_argc = 0;
|
|
|
|
char **PROJECT_argv = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
char *PROJECT_oldcwd = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-08-02 23:57:49 +02:00
|
|
|
bool PROJECT_run_httpd = FALSE;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static char *project_buffer;
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
//static char *project_ptr;
|
2007-12-30 17:41:49 +01:00
|
|
|
static int project_line;
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
static char *_home = NULL;
|
|
|
|
static uid_t _uid = 0;
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
static const char *_last_component = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void raise_error(const char *msg)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
char line[16];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
snprintf(line, sizeof(line), "%d", project_line);
|
|
|
|
THROW(E_PROJECT, line, msg);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void project_title(char *name, int len)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
name[len] = 0;
|
|
|
|
PROJECT_title = name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void project_version(char *name, int len)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
name[len] = 0;
|
|
|
|
PROJECT_version = name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
static void project_component(char *name, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
_last_component = name;
|
|
|
|
|
|
|
|
name[len] = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-08-21 04:27:16 +02:00
|
|
|
COMPONENT_create(name);
|
2013-01-29 01:53:21 +01:00
|
|
|
|
2013-08-02 23:57:49 +02:00
|
|
|
// If 'gb.httpd' is set explicitely, then always run through it.
|
|
|
|
|
|
|
|
if (strcmp(name, "gb.httpd") == 0)
|
|
|
|
PROJECT_run_httpd = TRUE;
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
_last_component = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
static void project_startup(char *name, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
if (len == 0)
|
|
|
|
raise_error("Project startup class name is void");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
name[len] = 0;
|
|
|
|
PROJECT_startup = name;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void project_stack(char *name, int len)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
int size;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
name[len] = 0;
|
|
|
|
size = atoi(name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (size >= 1 && size <= 64)
|
|
|
|
STACK_size = size * 1024L * sizeof(VALUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
static void project_stacktrace(char *name, int len)
|
2008-03-11 14:29:47 +01:00
|
|
|
{
|
2010-06-15 08:54:38 +02:00
|
|
|
//ERROR_backtrace = !(len == 1 && *name == '0');
|
|
|
|
// Backtrace is always printed now.
|
2008-03-11 14:29:47 +01:00
|
|
|
}
|
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
#if 0
|
2008-01-17 22:39:26 +01:00
|
|
|
static void project_command(char *line, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
static PROJECT_COMMAND command[] = {
|
|
|
|
{ "PROJECT", NULL },
|
|
|
|
{ "TITLE", project_title },
|
|
|
|
{ "LIBRARY", project_component },
|
|
|
|
{ "COMPONENT", project_component },
|
|
|
|
{ "STARTUP", project_startup },
|
|
|
|
{ "STACK", project_stack },
|
|
|
|
{ "VERSION", project_version },
|
|
|
|
{ "STACKTRACE", project_stacktrace },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
PROJECT_COMMAND *pc;
|
|
|
|
char cmd[32];
|
|
|
|
int len_cmd;
|
|
|
|
|
|
|
|
for (len_cmd = 0; len_cmd < len; len_cmd++)
|
|
|
|
{
|
|
|
|
if (line[len_cmd] == '=')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len_cmd >= len || len_cmd >= sizeof(cmd) || len_cmd == 0)
|
|
|
|
raise_error("Syntax error");
|
|
|
|
|
|
|
|
strncpy(cmd, line, len_cmd);
|
|
|
|
|
|
|
|
for (pc = command; ; pc++)
|
|
|
|
{
|
|
|
|
if (pc->command == NULL)
|
|
|
|
break;
|
|
|
|
/*raise_error("Unknown command");*/
|
|
|
|
|
|
|
|
if (strncasecmp(pc->command, cmd, len_cmd) == 0)
|
|
|
|
{
|
|
|
|
if (pc->func)
|
|
|
|
(*pc->func)(&line[len_cmd + 1], len - len_cmd - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-04-17 12:18:25 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
static void check_after_analyze()
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
if (!PROJECT_name || PROJECT_name[0] == 0)
|
|
|
|
raise_error("No project name");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (!PROJECT_startup || PROJECT_startup[0] == 0)
|
|
|
|
raise_error("No startup class");
|
2008-04-17 12:18:25 +02:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (!PROJECT_title || PROJECT_title[0] == 0)
|
|
|
|
PROJECT_title = PROJECT_name;
|
2008-04-17 12:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2008-01-17 22:39:26 +01:00
|
|
|
static void project_analyze(char *addr, int len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
char *end = &addr[len];
|
|
|
|
char c;
|
|
|
|
char *start;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
project_ptr = addr;
|
|
|
|
project_line = 1;
|
|
|
|
start = project_ptr;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (project_ptr >= end)
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
c = *project_ptr++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
project_line++;
|
|
|
|
start = project_ptr;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (c == '#')
|
|
|
|
{
|
|
|
|
while ((project_ptr < end) && c != '\n')
|
|
|
|
c = *project_ptr++;
|
|
|
|
project_ptr--;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (c <= ' ')
|
|
|
|
continue;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
project_ptr--;
|
|
|
|
start = project_ptr;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
while ((project_ptr < end) && (c != '\n'))
|
|
|
|
c = *project_ptr++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
project_command(start, project_ptr - start - 1);
|
|
|
|
project_ptr--;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
check_after_analyze();
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
static bool get_line(char **addr, const char *end, char **start, int *len)
|
|
|
|
{
|
|
|
|
char *p = *addr;
|
|
|
|
|
|
|
|
if (p >= end)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (p < end && *p && *p != '\n')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
*start = *addr;
|
|
|
|
*len = p - *start;
|
|
|
|
*addr = p + 1;
|
|
|
|
|
|
|
|
return (*len > 0);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-08-21 04:27:16 +02:00
|
|
|
void PROJECT_analyze_startup(char *addr, int len, PROJECT_COMPONENT_CALLBACK cb)
|
2008-04-17 12:18:25 +02:00
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
char *end = &addr[len];
|
2008-04-17 12:18:25 +02:00
|
|
|
char *p;
|
2011-08-21 04:27:16 +02:00
|
|
|
int l, i;
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
{
|
|
|
|
if (get_line(&addr, end, &p, &l))
|
|
|
|
project_startup(p, l);
|
|
|
|
if (get_line(&addr, end, &p, &l))
|
|
|
|
project_title(p, l);
|
|
|
|
if (get_line(&addr, end, &p, &l))
|
|
|
|
project_stack(p, l);
|
|
|
|
if (get_line(&addr, end, &p, &l))
|
|
|
|
project_stacktrace(p, l);
|
|
|
|
if (get_line(&addr, end, &p, &l))
|
|
|
|
project_version(p, l);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 1; i <= 5; i++)
|
|
|
|
get_line(&addr, end, &p, &l);
|
|
|
|
}
|
2008-04-17 12:18:25 +02:00
|
|
|
|
|
|
|
while (get_line(&addr, end, &p, &l));
|
|
|
|
|
2011-08-21 04:27:16 +02:00
|
|
|
if (!cb)
|
|
|
|
{
|
|
|
|
while (get_line(&addr, end, &p, &l))
|
|
|
|
project_component(p, l);
|
2008-04-17 12:18:25 +02:00
|
|
|
|
2011-08-21 04:27:16 +02:00
|
|
|
check_after_analyze();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (get_line(&addr, end, &p, &l))
|
|
|
|
{
|
|
|
|
p[l] = 0;
|
|
|
|
(*cb)(p);
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
char *PROJECT_get_home(void)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
struct passwd *info;
|
2008-03-19 15:32:30 +01:00
|
|
|
uid_t uid = getuid();
|
|
|
|
|
|
|
|
if (!_home || _uid != uid)
|
|
|
|
{
|
|
|
|
STRING_free(&_home);
|
|
|
|
info = getpwuid(uid);
|
|
|
|
if (info)
|
2010-06-05 01:48:53 +02:00
|
|
|
_home = STRING_new_zero(info->pw_dir);
|
2008-03-19 15:32:30 +01:00
|
|
|
_uid = uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _home;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
void PROJECT_init(const char *file)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
int len;
|
|
|
|
const char *path;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
/* Save the working directory */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
PROJECT_oldcwd = STRING_new_zero(FILE_getcwd(NULL));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
/* Gambas installation path */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
path = FILE_find_gambas();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
PROJECT_exec_path = STRING_new_zero(FILE_get_dir(FILE_get_dir(path)));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* Component paths */
|
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
#ifdef OS_64BITS
|
2013-01-29 01:53:21 +01:00
|
|
|
COMPONENT_path = STRING_new_zero(FILE_cat(PROJECT_exec_path, GAMBAS_LIB64_PATH, NULL));
|
|
|
|
if (access(COMPONENT_path, F_OK))
|
|
|
|
{
|
|
|
|
STRING_free(&COMPONENT_path);
|
|
|
|
COMPONENT_path = STRING_new_zero(FILE_cat(PROJECT_exec_path, GAMBAS_LIB_PATH, NULL));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
COMPONENT_path = STRING_new_zero(FILE_cat(PROJECT_exec_path, GAMBAS_LIB_PATH, NULL));
|
2008-02-24 17:29:02 +01:00
|
|
|
#endif
|
2013-01-29 01:53:21 +01:00
|
|
|
|
|
|
|
//STRING_new(&COMPONENT_user_path, FILE_cat(PROJECT_get_home(), ".local", GAMBAS_LIB_PATH, NULL), 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
/* Project path & name*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!file)
|
|
|
|
{
|
2010-04-05 03:44:43 +02:00
|
|
|
// "gbx3 -e" case
|
2010-06-05 01:48:53 +02:00
|
|
|
PROJECT_path = STRING_new("", 0);
|
|
|
|
PROJECT_name = STRING_new("", 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (EXEC_arch)
|
|
|
|
{
|
2010-11-03 21:28:54 +01:00
|
|
|
if (FILE_is_absolute(file))
|
|
|
|
{
|
|
|
|
path = FILE_get_dir(file);
|
|
|
|
FILE_chdir(path);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
path = FILE_getcwd(NULL);
|
|
|
|
if (path == NULL)
|
|
|
|
goto _PANIC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*file == '/')
|
|
|
|
{
|
|
|
|
path = file;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*file == '.' && file[1] == '/')
|
|
|
|
file += 2;
|
|
|
|
|
|
|
|
path = FILE_getcwd(file);
|
|
|
|
if (path == NULL)
|
|
|
|
goto _PANIC;
|
|
|
|
|
|
|
|
if (!chdir(path))
|
2010-02-03 16:48:37 +01:00
|
|
|
{
|
|
|
|
path = FILE_getcwd(NULL);
|
|
|
|
if (path == NULL)
|
|
|
|
goto _PANIC;
|
|
|
|
}
|
2013-01-29 01:53:21 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
len = strlen(path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
while (len > 1)
|
|
|
|
{
|
|
|
|
if (path[len - 1] != '/')
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
len--;
|
|
|
|
/*path[len] = 0;*/
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
PROJECT_path = STRING_new(path, len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
FILE_chdir(PROJECT_path);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
/* Project name */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
if (EXEC_arch)
|
|
|
|
PROJECT_name = STRING_new_zero(FILE_get_basename(file));
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
2013-01-29 01:53:21 +01:00
|
|
|
PROJECT_name = STRING_new_zero(FILE_get_name(PROJECT_path));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* Main archive creation */
|
|
|
|
|
|
|
|
ARCHIVE_create_main(EXEC_arch ? FILE_get_name(file) : NULL);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
_PANIC:
|
2013-01-29 01:53:21 +01:00
|
|
|
ERROR_panic("Cannot initialize project: %s", strerror(errno));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
void PROJECT_load()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
const char *file;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Project file analyze */
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
STACK_init();
|
|
|
|
|
|
|
|
if (EXEC_arch)
|
|
|
|
file = ".startup";
|
|
|
|
else
|
|
|
|
file = FILE_cat(PROJECT_path, ".startup", NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-04-17 12:18:25 +02:00
|
|
|
TRY
|
|
|
|
{
|
2010-01-20 01:37:00 +01:00
|
|
|
STREAM_load(file, &project_buffer, &len);
|
2008-04-17 12:18:25 +02:00
|
|
|
}
|
2010-01-20 01:37:00 +01:00
|
|
|
CATCH
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
ERROR_fatal("unable to find startup file");
|
2010-01-20 01:37:00 +01:00
|
|
|
}
|
|
|
|
END_TRY
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
TRY
|
|
|
|
{
|
|
|
|
PROJECT_analyze_startup(project_buffer, len, NULL);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
if (_last_component)
|
|
|
|
ERROR_fatal("unable to load component: %s", _last_component);
|
|
|
|
else
|
|
|
|
ERROR_fatal("unable to analyze startup file");
|
|
|
|
}
|
|
|
|
END_TRY
|
2010-01-20 01:37:00 +01:00
|
|
|
|
2012-09-27 22:52:08 +02:00
|
|
|
// Loads all component
|
2007-12-30 17:41:49 +01:00
|
|
|
COMPONENT_load_all();
|
2012-09-27 22:52:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PROJECT_load_finish(void)
|
|
|
|
{
|
|
|
|
// Load exported class of components written in Gambas
|
|
|
|
COMPONENT_load_all_finish();
|
|
|
|
|
|
|
|
// Loads main archive
|
2007-12-30 17:41:49 +01:00
|
|
|
ARCHIVE_load_main();
|
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
// Startup class
|
|
|
|
PROJECT_class = CLASS_find(PROJECT_startup);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PROJECT_exit(void)
|
|
|
|
{
|
2013-01-29 01:53:21 +01:00
|
|
|
if (project_buffer)
|
2013-03-30 00:33:01 +01:00
|
|
|
FREE(&project_buffer);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-04-25 12:46:57 +02:00
|
|
|
STRING_free(&PROJECT_name);
|
|
|
|
STRING_free(&PROJECT_path);
|
2010-04-05 03:44:43 +02:00
|
|
|
|
2013-01-29 01:53:21 +01:00
|
|
|
STRING_free(&PROJECT_oldcwd);
|
|
|
|
STRING_free(&PROJECT_exec_path);
|
|
|
|
STRING_free(&_home);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|