Skip to content

Instantly share code, notes, and snippets.

@chuckwagoncomputing
Created October 31, 2025 10:35
Show Gist options
  • Select an option

  • Save chuckwagoncomputing/0ec62449e7b49b90c9d175255b74da36 to your computer and use it in GitHub Desktop.

Select an option

Save chuckwagoncomputing/0ec62449e7b49b90c9d175255b74da36 to your computer and use it in GitHub Desktop.
TunerStudio .msq to rusefi struct-setting C code
(defun rusefi-xml-to-c (struct)
"Convert msq xml to c code which sets values in STRUCT."
(interactive "sStruct:")
(let* ((d (libxml-parse-xml-region (region-beginning) (region-end)))
(n (rusefi-get-param 'name d))
(n
(if n
n
1))
(r (rusefi-get-param 'rows d))
(r
(if r
(string-to-number r)
1))
(c (rusefi-get-param 'cols d))
(c
(if c
(string-to-number c)
1))
(v (nth 2 d))
(s '()))
(with-temp-buffer
(insert (replace-regexp-in-string "^[ \t]*\n" "" v))
(beginning-of-buffer)
(dotimes (i r)
(setq s
(append
s
(rusefi-process-config-line
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))
n i (> r 1) c)))
(forward-line 1)))
(kill-new
(seq-reduce
(lambda (x y) (concat x "\n" struct "->" y ";")) s ""))))
(defun rusefi-get-param (n p)
(cdr (car (seq-filter (lambda (x) (equal (car x) n)) (cadr p)))))
(defun rusefi-process-config-line (ln n i rp c)
(let ((l (string-trim ln))
(s '()))
(dotimes (ii c)
(push (rusefi-process-config-val
(nth ii (split-string l " ")) n i ii rp (> c 1))
s))
s))
(defun rusefi-process-config-val (v n r c rp cp)
(concat
n
(if rp
(concat "[" (number-to-string r) "]"))
(if cp
(concat "[" (number-to-string c) "]"))
" = " v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment