paint: strip trailing whitespace in script
This commit is contained in:
@@ -325,6 +325,7 @@ void history_delete_material_group(node_group_t *group);
|
||||
void tab_scripts_set(char *s);
|
||||
char *tab_scripts_get();
|
||||
void tab_scripts_create(char *name);
|
||||
void tab_scripts_strip_trailing_whitespace();
|
||||
void tab_scripts_draw(ui_handle_t *htab);
|
||||
ui_text_coloring_t *tab_scripts_get_text_coloring();
|
||||
void tab_debug_draw(ui_handle_t *htab);
|
||||
|
||||
@@ -98,6 +98,7 @@ string_array_t *export_arm_fonts_to_files(char *project_path, slot_font_t_array_
|
||||
void export_arm_run_project() {
|
||||
|
||||
tab_timeline_prepare_save();
|
||||
tab_scripts_strip_trailing_whitespace();
|
||||
|
||||
workflow_t _workflow = g_config->workflow;
|
||||
g_config->workflow = WORKFLOW_PBR;
|
||||
|
||||
@@ -34,6 +34,42 @@ void tab_scripts_set(char *s) {
|
||||
tab_scripts_minimap_dirty = true;
|
||||
}
|
||||
|
||||
static void tab_scripts_strip_line_whitespace(char *s) {
|
||||
int len = string_length(s);
|
||||
int write = 0;
|
||||
int read = 0;
|
||||
while (read < len) {
|
||||
// Find end of the current line
|
||||
int line_end = read;
|
||||
while (line_end < len && s[line_end] != '\n') {
|
||||
++line_end;
|
||||
}
|
||||
// Trim trailing spaces/tabs
|
||||
int trimmed_end = line_end;
|
||||
while (trimmed_end > read && (s[trimmed_end - 1] == ' ' || s[trimmed_end - 1] == '\t')) {
|
||||
--trimmed_end;
|
||||
}
|
||||
for (int i = read; i < trimmed_end; ++i) {
|
||||
s[write++] = s[i];
|
||||
}
|
||||
if (line_end < len) { // Keep the newline
|
||||
s[write++] = '\n';
|
||||
}
|
||||
read = line_end + 1;
|
||||
}
|
||||
s[write] = '\0';
|
||||
}
|
||||
|
||||
void tab_scripts_strip_trailing_whitespace() {
|
||||
if (g_project->script_datas == NULL) {
|
||||
return;
|
||||
}
|
||||
for (i32 i = 0; i < g_project->script_datas->length; ++i) {
|
||||
g_project->script_datas->buffer[i] = string_copy(g_project->script_datas->buffer[i]);
|
||||
tab_scripts_strip_line_whitespace(g_project->script_datas->buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void tab_scripts_create(char *name) {
|
||||
tab_scripts_prepare();
|
||||
i32 i = string_array_index_of(g_project->script_names, name);
|
||||
|
||||
Reference in New Issue
Block a user