mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2025-12-06 17:25:10 +08:00
Add FILE: line extraction logic to parse embedded C/C++ blocks from program.st
- Extract FILE: lines from program.st similar to DBG: line extraction - Write extracted files to ./core directory with proper path handling - Support subdirectories (e.g., FILE:test/abc.txt -> ./core/test/abc.txt) - Remove FILE: and DBG: lines from program.st before MatIEC compilation - No fallback .blank files needed for FILE: content Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import errno
|
||||
import time
|
||||
from threading import Thread, Lock
|
||||
from queue import Queue, Empty
|
||||
import os
|
||||
import os.path
|
||||
|
||||
intervals = (
|
||||
@@ -123,10 +124,18 @@ class runtime:
|
||||
combined_lines = combined_lines.split('\n')
|
||||
program_lines = []
|
||||
c_debug_lines = []
|
||||
file_lines = {}
|
||||
|
||||
for line in combined_lines:
|
||||
if line.startswith('(*DBG:') and line.endswith('*)'):
|
||||
c_debug_lines.append(line[6:-2])
|
||||
elif line.startswith('(*FILE:') and line.endswith('*)'):
|
||||
file_content = line[7:-2].strip()
|
||||
if ' ' in file_content:
|
||||
file_path, file_line = file_content.split(' ', 1)
|
||||
if file_path not in file_lines:
|
||||
file_lines[file_path] = []
|
||||
file_lines[file_path].append(file_line)
|
||||
else:
|
||||
program_lines.append(line)
|
||||
|
||||
@@ -148,6 +157,12 @@ class runtime:
|
||||
with open('./core/debug.cpp', "w") as f:
|
||||
f.write(c_debug)
|
||||
|
||||
for file_path, lines in file_lines.items():
|
||||
full_path = os.path.join('./core', file_path)
|
||||
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
||||
with open(full_path, "w") as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
# Start compilation
|
||||
try:
|
||||
a = subprocess.Popen(['./scripts/compile_program.sh', str(st_file)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
@@ -164,6 +179,12 @@ class runtime:
|
||||
with open('./core/debug.cpp', "w") as f:
|
||||
f.write(c_debug)
|
||||
|
||||
for file_path, lines in file_lines.items():
|
||||
full_path = os.path.join('./core', file_path)
|
||||
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
||||
with open(full_path, "w") as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
#Write program and debug files
|
||||
with open('./st_files/' + st_file, "w") as f:
|
||||
f.write(program)
|
||||
|
||||
Reference in New Issue
Block a user