jsketcher/web/tcl.html
2023-02-04 07:02:26 +00:00

50 lines
No EOL
1.3 KiB
HTML

<style>
textarea {
width: calc(50% - 10px);
height: calc(100% - 50px);
}
</style>
<h3>TCL to JSketcher OCC API converter</h3>
<textarea id="tclIn" oninput="convertIt();"></textarea>
<textarea id="jsOut"></textarea>
<script>
async function convertIt() {
var lines = document.getElementById("tclIn").value.split('\n');
const out = document.getElementById("jsOut");
out.value = "";
for (var i = 0; i < lines.length; i++) {
out.value += await words(lines[i]) + '\n';
}
//alert("done");
}
async function words(inputLine) {
inputLine = inputLine.trim();
if (inputLine == "") return "";
var words = inputLine.trim().split(" ")
if (words[0].startsWith("#")) return "//" + inputLine;
var returnLine = "oci." + words[0];
returnLine += "(";
for (var i = 1; i < words.length; i++) {
//eliminate trailing commas.
if (words[i].trim() !== "") {
if (i == words.length - 1) {
returnLine += `"` + words[i] + `"`;
} else {
returnLine += `"` + words[i] + `",`;
}
}
}
returnLine += ");";
//console.log(returnLine);
return returnLine
}
</script>