code generation: only use scanf/printf on newline('\n') terminated strings

This commit is contained in:
Michael Sippel 2025-05-14 10:20:55 +02:00
parent 692a34c257
commit 7dd6352760
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -25,15 +25,15 @@ pub fn generate_lib(
if let Ok(_) = laddertypes::subtype_unify(
&inst.ty.src_type,
&dict.parse("<Seq~<ValueTerminated 0> Char~Ascii~native.UInt8>").expect("")
&dict.parse("<Seq~<ValueTerminated '\\n'> Char~Ascii~native.UInt8>").expect("")
) {
c_source.push_str("scanf(\"%s\", bufIn);");
c_source.push_str("scanf(\"%s\", bufIn);\n");
} else {
c_source.push_str("read(0, bufIn, sizeof(bufIn));");
c_source.push_str("read(0, bufIn, sizeof(bufIn));\n");
}
c_source.push_str(
&format!(r#"FUSE( {}, (void const*)bufIn, (void*)bufOut );"#,
&format!(r#"FUSE( {}, (void const*)bufIn, (void*)bufOut );\n"#,
inst.instantiated_symbol_name(dict, &HashMap::new()))
);
@ -41,9 +41,9 @@ pub fn generate_lib(
&inst.ty.dst_type,
&dict.parse("<Seq~<ValueTerminated 0> native.UInt8>").expect("")
) {
c_source.push_str("printf(\"%s\\n\", bufOut);");
c_source.push_str("printf(\"%s\\n\", bufOut);\n");
} else {
c_source.push_str("write(1, bufOut, sizeof(bufOut));");
c_source.push_str("write(1, bufOut, sizeof(bufOut));\n");
}
c_source.push_str("
return 0;