compiles and works
This commit is contained in:
104
bs/init.c
104
bs/init.c
@@ -19,6 +19,10 @@ Command commands[] = {
|
||||
{NULL, NULL}};
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jtag_core/jtag_core.h"
|
||||
#include "config/version.h"
|
||||
#include "script/env.h"
|
||||
@@ -31,55 +35,99 @@ void jprint(jtag_core *jc, const char *msg)
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
jtag_core *bsexp_init(void)
|
||||
int script_print(script_ctx *sctx, enum MSGTYPE typ, char *string, ...)
|
||||
{
|
||||
jtag_core *jc = NULL;
|
||||
script_ctx *sctx;
|
||||
int ret = 0;
|
||||
char msg[64] = {0};
|
||||
va_list args;
|
||||
|
||||
/* initialize the JTAG library */
|
||||
jc = jtagcore_init();
|
||||
switch (typ)
|
||||
{
|
||||
case MSG_DEBUG:
|
||||
strcpy(msg, "DEBUG :");
|
||||
break;
|
||||
case MSG_INFO_1:
|
||||
strcpy(msg, "INFO :");
|
||||
break;
|
||||
case MSG_WARNING:
|
||||
strcpy(msg, "WARNING :");
|
||||
break;
|
||||
case MSG_ERROR:
|
||||
strcpy(msg, "ERROR :");
|
||||
break;
|
||||
case MSG_INFO_0:
|
||||
default:
|
||||
strcpy(msg, "");
|
||||
break;
|
||||
}
|
||||
|
||||
if (NULL == jc)
|
||||
va_start(args, string);
|
||||
ret = printf(msg);
|
||||
ret += vprintf(string, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bsexp_init(jtag_core **jc, script_ctx **sctx)
|
||||
{
|
||||
// JTAG core initialization
|
||||
*jc = jtagcore_init();
|
||||
if (NULL == *jc)
|
||||
goto end;
|
||||
|
||||
jc->envvar = (void *)initEnv(NULL, NULL);
|
||||
// Environment initialization
|
||||
(*jc)->envvar = (void *)initEnv(NULL, NULL);
|
||||
if (NULL == (*jc)->envvar) {
|
||||
jtagcore_deinit(*jc);
|
||||
*jc = NULL;
|
||||
goto end;
|
||||
}
|
||||
jtagcore_setEnvVar(*jc, "VERSION", "v" APP_VER_STR(APP_VER));
|
||||
|
||||
jtagcore_setEnvVar(jc, "VERSION", "v" LIB_JTAG_CORE_VERSION);
|
||||
|
||||
sctx = jtagcore_initScript(jc);
|
||||
|
||||
execute_ram_script(sctx, config_script, config_script_len);
|
||||
|
||||
execute_file_script(sctx, "config.script");
|
||||
// Scripts initialization
|
||||
*sctx = jtagcore_initScript(*jc);
|
||||
if (NULL == *sctx) {
|
||||
deinitEnv((*jc)->envvar);
|
||||
jtagcore_deinit(*jc);
|
||||
*jc = NULL;
|
||||
goto end;
|
||||
}
|
||||
setOutputFunc_script(*sctx, script_print);
|
||||
execute_ram_script(*sctx, config_script, config_script_len);
|
||||
execute_file_script(*sctx, "config.script");
|
||||
|
||||
/* Log printing callback */
|
||||
if (jtagcore_set_logs_callback(jc, jprint) < 0)
|
||||
if (jtagcore_set_logs_callback(*jc, jprint) < 0)
|
||||
{
|
||||
printf("Impossible to define the logs callback!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILTER_LEVEL", NULL))
|
||||
{
|
||||
jtagcore_set_logs_level(jc, jtagcore_getEnvVarValue(jc, "LOG_MESSAGES_FILTER_LEVEL"));
|
||||
jtagcore_set_logs_level(*jc, jtagcore_getEnvVarValue(*jc, "LOG_MESSAGES_FILTER_LEVEL"));
|
||||
}
|
||||
|
||||
if (jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
|
||||
if (jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL))
|
||||
{
|
||||
jtagcore_set_logs_file(jc, jtagcore_getEnvVar(jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
|
||||
jtagcore_set_logs_file(*jc, jtagcore_getEnvVar(*jc, "LOG_MESSAGES_FILE_OUTPUT", NULL));
|
||||
}
|
||||
}
|
||||
deinit_script(sctx);
|
||||
|
||||
end:
|
||||
return jc;
|
||||
return;
|
||||
}
|
||||
|
||||
void bsexp_deinit(jtag_core *jc)
|
||||
void bsexp_deinit(jtag_core *jc, script_ctx *sctx)
|
||||
{
|
||||
if (NULL == jc) return;
|
||||
envvar_entry *env = NULL;
|
||||
|
||||
envvar_entry *env = jc->envvar;
|
||||
deinitEnv(env);
|
||||
jtagcore_deinit(jc);
|
||||
if (NULL != jc)
|
||||
{
|
||||
deinit_script(sctx);
|
||||
}
|
||||
if (NULL != jc)
|
||||
{
|
||||
env = jc->envvar;
|
||||
deinitEnv(env);
|
||||
jtagcore_deinit(jc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user