|
|
@@ -679,7 +679,7 @@ static bool swd_apscan_test(AppFSM* const ctx, uint32_t ap) {
|
|
|
static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* format, ...) {
|
|
|
bool commandline = false;
|
|
|
ScriptContext* cur = ctx;
|
|
|
- char buffer[256];
|
|
|
+ FuriString* buffer = furi_string_alloc();
|
|
|
va_list argp;
|
|
|
va_start(argp, format);
|
|
|
|
|
|
@@ -704,17 +704,19 @@ static void swd_script_log(ScriptContext* ctx, FuriLogLevel level, const char* f
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- strcpy(buffer, prefix);
|
|
|
- size_t pos = strlen(buffer);
|
|
|
- vsnprintf(&buffer[pos], sizeof(buffer) - pos - 2, format, argp);
|
|
|
- strcat(buffer, "\n");
|
|
|
- if(!usb_uart_tx_data(ctx->app->uart, (uint8_t*)buffer, strlen(buffer))) {
|
|
|
+ furi_string_cat_str(buffer, prefix);
|
|
|
+ furi_string_cat_printf(buffer, format, argp);
|
|
|
+ furi_string_cat_str(buffer, "\n");
|
|
|
+
|
|
|
+ if(!usb_uart_tx_data(
|
|
|
+ ctx->app->uart, (uint8_t*)furi_string_get_cstr(buffer), furi_string_size(buffer))) {
|
|
|
DBGS("Sending via USB failed");
|
|
|
}
|
|
|
} else {
|
|
|
- LOG(buffer);
|
|
|
+ LOG(furi_string_get_cstr(buffer));
|
|
|
}
|
|
|
va_end(argp);
|
|
|
+ furi_string_free(buffer);
|
|
|
}
|
|
|
|
|
|
/* read characters until newline was read */
|
|
|
@@ -939,41 +941,44 @@ static bool swd_scriptfunc_goto(ScriptContext* ctx) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+#include <toolbox/path.h>
|
|
|
+
|
|
|
static bool swd_scriptfunc_call(ScriptContext* ctx) {
|
|
|
DBGS("call");
|
|
|
|
|
|
swd_script_skip_whitespace(ctx);
|
|
|
|
|
|
/* fetch previous file directory */
|
|
|
- char filename[MAX_FILE_LENGTH];
|
|
|
- strncpy(filename, ctx->filename, sizeof(filename));
|
|
|
- char* path = strrchr(filename, '/');
|
|
|
- path[1] = '\000';
|
|
|
+ FuriString* filepath = furi_string_alloc();
|
|
|
+ path_extract_dirname(ctx->filename, filepath);
|
|
|
+ // strncpy(filename, ctx->filename, sizeof(filename));
|
|
|
|
|
|
- /* append filename */
|
|
|
- if(!swd_script_get_string(ctx, &path[1], sizeof(filename) - strlen(path))) {
|
|
|
- swd_script_log(ctx, FuriLogLevelError, "failed to parse filename");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- swd_script_seek_newline(ctx);
|
|
|
+ char filename[MAX_FILE_LENGTH] = {};
|
|
|
+ bool success = false;
|
|
|
+ do {
|
|
|
+ /* append filename */
|
|
|
+ if(!swd_script_get_string(ctx, filename, sizeof(filename))) {
|
|
|
+ swd_script_log(ctx, FuriLogLevelError, "failed to parse filename");
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- /* append extension */
|
|
|
- if(strlen(filename) + 5 >= sizeof(filename)) {
|
|
|
- swd_script_log(ctx, FuriLogLevelError, "name too long");
|
|
|
- return false;
|
|
|
- }
|
|
|
+ swd_script_seek_newline(ctx);
|
|
|
+ /* append extension */
|
|
|
+ furi_string_cat_str(filepath, ".swd");
|
|
|
|
|
|
- strcat(filename, ".swd");
|
|
|
+ bool ret = swd_execute_script(ctx->app, furi_string_get_cstr(filepath));
|
|
|
|
|
|
- bool ret = swd_execute_script(ctx->app, filename);
|
|
|
+ if(!ret) {
|
|
|
+ swd_script_log(
|
|
|
+ ctx, FuriLogLevelError, "failed to exec '%s'", furi_string_get_cstr(filepath));
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if(!ret) {
|
|
|
- swd_script_log(ctx, FuriLogLevelError, "failed to exec '%s'", filename);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ success = true;
|
|
|
+ } while(false);
|
|
|
+ furi_string_free(filepath);
|
|
|
|
|
|
- return true;
|
|
|
+ return success;
|
|
|
}
|
|
|
|
|
|
static bool swd_scriptfunc_status(ScriptContext* ctx) {
|